Merge "Add Enterprise Privacy page to Settings"

This commit is contained in:
Bartosz Fabianowski
2016-11-14 15:01:24 +00:00
committed by Android (Google) Code Review
18 changed files with 440 additions and 1 deletions

View File

@@ -158,6 +158,7 @@ public class Settings extends SettingsActivity {
public static class TestingSettingsActivity extends SettingsActivity { /* empty */ }
public static class WifiAPITestActivity extends SettingsActivity { /* empty */ }
public static class WifiInfoActivity extends SettingsActivity { /* empty */ }
public static class EnterprisePrivacySettingsActivity extends SettingsActivity { /* empty */ }
// Categories.
public static class WirelessSettings extends SettingsActivity { /* empty */ }

View File

@@ -94,6 +94,8 @@ import com.android.settings.deviceinfo.Status;
import com.android.settings.deviceinfo.StorageDashboardFragment;
import com.android.settings.deviceinfo.StorageSettings;
import com.android.settings.display.NightDisplaySettings;
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
import com.android.settings.enterprise.EnterprisePrivacySettings;
import com.android.settings.fuelgauge.BatterySaverSettings;
import com.android.settings.fuelgauge.PowerUsageDetail;
import com.android.settings.fuelgauge.PowerUsageSummary;
@@ -277,6 +279,7 @@ public class SettingsActivity extends SettingsDrawerActivity
Settings.AccessibilitySettingsActivity.class.getName(),
Settings.PrintSettingsActivity.class.getName(),
Settings.PaymentSettingsActivity.class.getName(),
Settings.EnterprisePrivacySettingsActivity.class.getName(),
// New IA
// Home page
@@ -416,6 +419,7 @@ public class SettingsActivity extends SettingsDrawerActivity
ConnectedDeviceDashboardFragment.class.getName(),
AppAndNotificationDashboardFragment.class.getName(),
UserAndAccountDashboardFragment.class.getName(),
EnterprisePrivacySettings.class.getName(),
};
@@ -1219,6 +1223,11 @@ public class SettingsActivity extends SettingsDrawerActivity
setTileEnabled(new ComponentName(packageName,
BackupSettingsActivity.class.getName()), hasBackupActivity, isAdmin, pm);
setTileEnabled(new ComponentName(packageName,
Settings.EnterprisePrivacySettingsActivity.class.getName()),
FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
.hasDeviceOwner(), isAdmin, pm);
}
private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,

View File

@@ -35,4 +35,4 @@ public class WallOfTextPreference extends DividerPreference {
final TextView summary = (TextView) view.findViewById(android.R.id.summary);
summary.setMaxLines(20);
}
}
}

View File

@@ -0,0 +1,27 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.enterprise;
import android.content.ComponentName;
// This interface replicates a subset of the android.app.admin.DevicePolicyManager (DPM). The
// interface exists so that we can use a thin wrapper around the DPM in production code and a mock
// in tests. We cannot directly mock or shadow the DPM, because some of the methods we rely on are
// newer than the API version supported by Robolectric.
public interface DevicePolicyManagerWrapper {
public ComponentName getDeviceOwnerComponentOnAnyUser();
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.enterprise;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
public class DevicePolicyManagerWrapperImpl implements DevicePolicyManagerWrapper {
private final DevicePolicyManager mDpm;
public DevicePolicyManagerWrapperImpl(DevicePolicyManager dpm) {
mDpm = dpm;
}
public ComponentName getDeviceOwnerComponentOnAnyUser() {
return mDpm.getDeviceOwnerComponentOnAnyUser();
}
}

View File

@@ -0,0 +1,21 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.enterprise;
public interface EnterprisePrivacyFeatureProvider {
boolean hasDeviceOwner();
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.enterprise;
import android.content.pm.PackageManager;
import android.content.Context;
public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFeatureProvider {
private final Context mContext;
private final DevicePolicyManagerWrapper mDpm;
public EnterprisePrivacyFeatureProviderImpl(Context context, DevicePolicyManagerWrapper dpm) {
mContext = context.getApplicationContext();
mDpm = dpm;
}
@Override
public boolean hasDeviceOwner() {
if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN)) {
return false;
}
return mDpm.getDeviceOwnerComponentOnAnyUser() != null;
}
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.enterprise;
import android.content.Context;
import android.os.Bundle;
import android.provider.SearchIndexableResource;
import com.android.settings.R;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import java.util.Arrays;
import java.util.List;
public class EnterprisePrivacySettings extends DashboardFragment {
static final String TAG = "EnterprisePrivacySettings";
@Override
public int getMetricsCategory() {
return MetricsEvent.ENTERPRISE_PRIVACY_SETTINGS;
}
@Override
protected String getCategoryKey() {
return null;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.enterprise_privacy_settings;
}
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
return null;
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.enterprise_privacy_settings;
return Arrays.asList(sir);
}
};
}

View File

@@ -24,6 +24,7 @@ import com.android.settings.R;
import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.localepicker.LocaleFeatureProvider;
@@ -76,6 +77,8 @@ public abstract class FeatureFactory {
public abstract LocaleFeatureProvider getLocaleFeatureProvider();
public abstract EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(
Context context);
public static final class FactoryNotFoundException extends RuntimeException {
public FactoryNotFoundException(Throwable throwable) {

View File

@@ -16,6 +16,7 @@
package com.android.settings.overlay;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.support.annotation.Keep;
@@ -25,6 +26,9 @@ import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.core.instrumentation.MetricsFeatureProviderImpl;
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.DashboardFeatureProviderImpl;
import com.android.settings.enterprise.DevicePolicyManagerWrapperImpl;
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
import com.android.settings.enterprise.EnterprisePrivacyFeatureProviderImpl;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.localepicker.LocaleFeatureProvider;
import com.android.settings.localepicker.LocaleFeatureProviderImpl;
@@ -39,6 +43,7 @@ public final class FeatureFactoryImpl extends FeatureFactory {
private MetricsFeatureProvider mMetricsFeatureProvider;
private DashboardFeatureProviderImpl mDashboardFeatureProvider;
private LocaleFeatureProvider mLocaleFeatureProvider;
private EnterprisePrivacyFeatureProvider mEnterprisePrivacyFeatureProvider;
@Override
public SupportFeatureProvider getSupportFeatureProvider(Context context) {
@@ -81,4 +86,14 @@ public final class FeatureFactoryImpl extends FeatureFactory {
}
return mLocaleFeatureProvider;
}
@Override
public EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(Context context) {
if (mEnterprisePrivacyFeatureProvider == null) {
mEnterprisePrivacyFeatureProvider = new EnterprisePrivacyFeatureProviderImpl(context,
new DevicePolicyManagerWrapperImpl((DevicePolicyManager)context
.getSystemService(Context.DEVICE_POLICY_SERVICE)));
}
return mEnterprisePrivacyFeatureProvider;
}
}

View File

@@ -37,6 +37,7 @@ import com.android.settings.datausage.DataUsageSummary;
import com.android.settings.deviceinfo.StorageDashboardFragment;
import com.android.settings.deviceinfo.StorageSettings;
import com.android.settings.display.ScreenZoomSettings;
import com.android.settings.enterprise.EnterprisePrivacySettings;
import com.android.settings.fuelgauge.BatterySaverSettings;
import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.gestures.GestureSettings;
@@ -170,6 +171,7 @@ public final class Ranking {
// Privacy
sRankMap.put(PrivacySettings.class.getName(), RANK_PRIVACY);
sRankMap.put(EnterprisePrivacySettings.class.getName(), RANK_PRIVACY);
// Date / Time
sRankMap.put(DateTimeSettings.class.getName(), RANK_DATE_TIME);

View File

@@ -38,6 +38,7 @@ import com.android.settings.datausage.DataUsageSummary;
import com.android.settings.deviceinfo.StorageDashboardFragment;
import com.android.settings.deviceinfo.StorageSettings;
import com.android.settings.display.ScreenZoomSettings;
import com.android.settings.enterprise.EnterprisePrivacySettings;
import com.android.settings.fuelgauge.BatterySaverSettings;
import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.gestures.GestureSettings;
@@ -335,12 +336,20 @@ public final class SearchIndexableResources {
NO_DATA_RES_ID,
SystemDashboardFragment.class.getName(),
R.drawable.ic_settings_about));
sResMap.put(StorageDashboardFragment.class.getName(),
new SearchIndexableResource(
Ranking.getRankForClassName(StorageDashboardFragment.class.getName()),
NO_DATA_RES_ID,
StorageDashboardFragment.class.getName(),
R.drawable.ic_settings_storage));
sResMap.put(EnterprisePrivacySettings.class.getName(),
new SearchIndexableResource(
Ranking.getRankForClassName(EnterprisePrivacySettings.class.getName()),
NO_DATA_RES_ID,
EnterprisePrivacySettings.class.getName(),
R.drawable.ic_settings_about));
}
private SearchIndexableResources() {