diff options
18 files changed, 440 insertions, 1 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 9219ca1a93..4fb17f7172 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1580,6 +1580,20 @@ android:value="true" /> </activity> + <activity android:name="Settings$EnterprisePrivacySettingsActivity" + android:label="@string/enterprise_privacy_settings_title" + android:icon="@drawable/ic_settings_about" + android:taskAffinity="com.android.settings" + android:parentActivityName="Settings"> + <intent-filter android:priority="-1"> + <action android:name="com.android.settings.action.SETTINGS" /> + </intent-filter> + <meta-data android:name="com.android.settings.category" + android:value="com.android.settings.category.device" /> + <meta-data android:name="com.android.settings.FRAGMENT_CLASS" + android:value="com.android.settings.enterprise.EnterprisePrivacySettings" /> + </activity> + <!-- Second and third-level settings --> <!-- Lock screen settings --> @@ -3435,6 +3449,18 @@ android:value="true"/> </activity-alias> + <!-- Alias for enterprise privacy setting in new IA. Should merge into TargetActivity when launch --> + <activity-alias android:name="EnterprisePrivacyDashboardAlias" + android:targetActivity="Settings$EnterprisePrivacySettingsActivity"> + <intent-filter android:priority="-1"> + <action android:name="com.android.settings.action.SETTINGS" /> + </intent-filter> + <meta-data android:name="com.android.settings.category" + android:value="com.android.settings.category.ia.system" /> + <meta-data android:name="com.android.settings.FRAGMENT_CLASS" + android:value="com.android.settings.enterprise.EnterprisePrivacySettings" /> + </activity-alias> + <!-- End of information architecture host activities --> <service diff --git a/res/values/strings.xml b/res/values/strings.xml index fd64db0e02..4ca87fb68d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -7974,4 +7974,12 @@ <!-- Switch label to enable auto sync work account [CHAR LIMIT=30] --> <string name="auto_sync_work_account_title">Auto sync work account data</string> + <!-- Enterprise Privacy --> <skip /> + + <!-- Title of setting on main settings screen. This will take the user to a screen with information about his/her privacy on a managed device. Shown on enterprise-managed devices only. --> + <string name="enterprise_privacy_settings">Privacy</string> + <!-- Enterprise Privacy settings activity title --> + <string name="enterprise_privacy_settings_title">Privacy</string> + <!-- Enterprise Privacy settings activity header, summarizing the powers that the admin has. [CHAR LIMIT=NONE] --> + <string name="enterprise_privacy_header">To provide access to your work data, your organization may change settings and install software on your device, which could cause some of your personal content to be visible to your admin. Contact your organization\'s admin for more details.</string> </resources> diff --git a/res/xml/enterprise_privacy_settings.xml b/res/xml/enterprise_privacy_settings.xml new file mode 100644 index 0000000000..26cc6a8aeb --- /dev/null +++ b/res/xml/enterprise_privacy_settings.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> + +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" + android:key="enterprise_privacy_settings" + android:title="@string/enterprise_privacy_settings_title"> + + <!-- Header --> + <Preference android:key="enterprise_privacy_header" + android:summary="@string/enterprise_privacy_header" + android:selectable="false"/> +</PreferenceScreen> diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index 85fb334a8e..06941d0949 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -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 */ } diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java index 949b6b74e9..f67f73f712 100644 --- a/src/com/android/settings/SettingsActivity.java +++ b/src/com/android/settings/SettingsActivity.java @@ -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, diff --git a/src/com/android/settings/fuelgauge/WallOfTextPreference.java b/src/com/android/settings/WallOfTextPreference.java index 6b2974269a..4cc2f673e1 100644 --- a/src/com/android/settings/fuelgauge/WallOfTextPreference.java +++ b/src/com/android/settings/WallOfTextPreference.java @@ -35,4 +35,4 @@ public class WallOfTextPreference extends DividerPreference { final TextView summary = (TextView) view.findViewById(android.R.id.summary); summary.setMaxLines(20); } -}
\ No newline at end of file +} diff --git a/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java b/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java new file mode 100644 index 0000000000..3e45de00fd --- /dev/null +++ b/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java @@ -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(); +} diff --git a/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java b/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java new file mode 100644 index 0000000000..87adcd67e0 --- /dev/null +++ b/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java @@ -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(); + } +} diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java new file mode 100644 index 0000000000..e2fb0a3bc3 --- /dev/null +++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java @@ -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(); +} diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java new file mode 100644 index 0000000000..3d35c23fad --- /dev/null +++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java @@ -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; + } +} diff --git a/src/com/android/settings/enterprise/EnterprisePrivacySettings.java b/src/com/android/settings/enterprise/EnterprisePrivacySettings.java new file mode 100644 index 0000000000..a2d1a308e0 --- /dev/null +++ b/src/com/android/settings/enterprise/EnterprisePrivacySettings.java @@ -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); + } + }; +} diff --git a/src/com/android/settings/overlay/FeatureFactory.java b/src/com/android/settings/overlay/FeatureFactory.java index 515975b816..55ea4bb1ab 100644 --- a/src/com/android/settings/overlay/FeatureFactory.java +++ b/src/com/android/settings/overlay/FeatureFactory.java @@ -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) { diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.java b/src/com/android/settings/overlay/FeatureFactoryImpl.java index 934021d996..ec0ff463ce 100644 --- a/src/com/android/settings/overlay/FeatureFactoryImpl.java +++ b/src/com/android/settings/overlay/FeatureFactoryImpl.java @@ -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; + } } diff --git a/src/com/android/settings/search/Ranking.java b/src/com/android/settings/search/Ranking.java index e9ceb85d08..10702008df 100644 --- a/src/com/android/settings/search/Ranking.java +++ b/src/com/android/settings/search/Ranking.java @@ -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); diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java index 1b8e0befec..7888c0f2aa 100644 --- a/src/com/android/settings/search/SearchIndexableResources.java +++ b/src/com/android/settings/search/SearchIndexableResources.java @@ -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() { diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java new file mode 100644 index 0000000000..afcd4840b1 --- /dev/null +++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java @@ -0,0 +1,70 @@ +/* + * 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; +import android.content.Context; +import android.content.pm.PackageManager; + +import com.android.settings.SettingsRobolectricTestRunner; +import com.android.settings.TestConfig; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.annotation.Config; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.when; + +/** + * Tests for {@link EnterprisePrivacyFeatureProviderImpl}. + */ +@RunWith(SettingsRobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) +public final class EnterprisePrivacyFeatureProviderImplTest { + + private final ComponentName DEVICE_OWNER = new ComponentName("dummy", "component"); + + private @Mock PackageManager mPackageManager; + private @Mock Context mContext; + private @Mock DevicePolicyManagerWrapper mDevicePolicyManager; + + private EnterprisePrivacyFeatureProvider mProvider; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + + when(mContext.getApplicationContext()).thenReturn(mContext); + when(mContext.getPackageManager()).thenReturn(mPackageManager); + when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN)) + .thenReturn(true); + + mProvider = new EnterprisePrivacyFeatureProviderImpl(mContext, mDevicePolicyManager); + } + + @Test + public void testHasDeviceOwner() { + when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(null); + assertThat(mProvider.hasDeviceOwner()).isFalse(); + + when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(DEVICE_OWNER); + assertThat(mProvider.hasDeviceOwner()).isTrue(); + } +} diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java new file mode 100644 index 0000000000..20393eef62 --- /dev/null +++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java @@ -0,0 +1,72 @@ +/* + * 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 com.android.internal.logging.nano.MetricsProto.MetricsEvent; +import com.android.settings.R; +import com.android.settings.SettingsRobolectricTestRunner; +import com.android.settings.TestConfig; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.annotation.Config; +import org.robolectric.shadows.ShadowApplication; + +import static com.google.common.truth.Truth.assertThat; + +/** + * Tests for {@link EnterprisePrivacySettings}. + */ +@RunWith(SettingsRobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) +public final class EnterprisePrivacySettingsTest { + + private EnterprisePrivacySettings mSettings; + + @Before + public void setUp() { + mSettings = new EnterprisePrivacySettings(); + } + + @Test + public void testGetMetricsCategory() { + assertThat(mSettings.getMetricsCategory()) + .isEqualTo(MetricsEvent.ENTERPRISE_PRIVACY_SETTINGS); + } + + @Test + public void testGetCategoryKey() { + assertThat(mSettings.getCategoryKey()).isNull(); + } + + @Test + public void testGetLogTag() { + assertThat(mSettings.getLogTag()).isEqualTo("EnterprisePrivacySettings"); + } + + @Test + public void testGetPreferenceScreenResId() { + assertThat(mSettings.getPreferenceScreenResId()) + .isEqualTo(R.xml.enterprise_privacy_settings); + } + + @Test + public void getPreferenceControllers() { + assertThat(mSettings.getPreferenceControllers( + ShadowApplication.getInstance().getApplicationContext())).isNull(); + } +} diff --git a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java index 8241352d35..35288630ac 100644 --- a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java +++ b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java @@ -20,6 +20,7 @@ import android.content.Context; 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; import com.android.settings.overlay.FeatureFactory; @@ -41,6 +42,7 @@ public class FakeFeatureFactory extends FeatureFactory { public final DashboardFeatureProvider dashboardFeatureProvider; public final LocaleFeatureProvider localeFeatureProvider; public final ApplicationFeatureProvider applicationFeatureProvider; + public final EnterprisePrivacyFeatureProvider enterprisePrivacyFeatureProvider; /** * Call this in {@code @Before} method of the test class to use fake factory. @@ -69,6 +71,7 @@ public class FakeFeatureFactory extends FeatureFactory { dashboardFeatureProvider = mock(DashboardFeatureProvider.class); localeFeatureProvider = mock(LocaleFeatureProvider.class); applicationFeatureProvider = mock(ApplicationFeatureProvider.class); + enterprisePrivacyFeatureProvider = mock(EnterprisePrivacyFeatureProvider.class); } @Override @@ -100,4 +103,9 @@ public class FakeFeatureFactory extends FeatureFactory { public LocaleFeatureProvider getLocaleFeatureProvider() { return localeFeatureProvider; } + + @Override + public EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(Context context) { + return enterprisePrivacyFeatureProvider; + } } |