diff --git a/res/values/strings.xml b/res/values/strings.xml index 8b69d79f322..ba9c94a0d9c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -11542,6 +11542,25 @@ Learn more + + + + Financed device info + + Types of information your device administrator can see + + Data associated with your account, such as email and calendar info + + Changes made by your device administrator + + Device administrator can lock this device and reset password + + Device administrator can delete all device data + + Failed password attempts before deleting device data + + Your credit provider can change settings and install software on this device.\n\nTo learn more, contact your creditor provider. + diff --git a/res/xml/financed_privacy_settings.xml b/res/xml/financed_privacy_settings.xml new file mode 100644 index 00000000000..742d7e1e9eb --- /dev/null +++ b/res/xml/financed_privacy_settings.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/android/settings/enterprise/EnterprisePrivacySettings.java b/src/com/android/settings/enterprise/EnterprisePrivacySettings.java index dd0a9ce8793..1aad54448f6 100644 --- a/src/com/android/settings/enterprise/EnterprisePrivacySettings.java +++ b/src/com/android/settings/enterprise/EnterprisePrivacySettings.java @@ -20,16 +20,13 @@ import android.app.settings.SettingsEnums; import android.content.Context; import android.provider.SearchIndexableResource; -import com.android.settings.R; +import com.android.internal.annotations.VisibleForTesting; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.overlay.FeatureFactory; import com.android.settings.search.BaseSearchIndexProvider; -import com.android.settings.widget.PreferenceCategoryController; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.search.SearchIndexable; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; @SearchIndexable @@ -37,6 +34,23 @@ public class EnterprisePrivacySettings extends DashboardFragment { static final String TAG = "EnterprisePrivacySettings"; + @VisibleForTesting + PrivacySettingsPreference mPrivacySettingsPreference; + + @Override + public void onAttach(Context context) { + mPrivacySettingsPreference = + PrivacySettingsPreferenceFactory.createPrivacySettingsPreference(context); + + super.onAttach(context); + } + + @Override + public void onDetach() { + mPrivacySettingsPreference = null; + super.onDetach(); + } + @Override public int getMetricsCategory() { return SettingsEnums.ENTERPRISE_PRIVACY_SETTINGS; @@ -49,47 +63,12 @@ public class EnterprisePrivacySettings extends DashboardFragment { @Override protected int getPreferenceScreenResId() { - return R.xml.enterprise_privacy_settings; + return mPrivacySettingsPreference.getPreferenceScreenResId(); } @Override protected List createPreferenceControllers(Context context) { - return buildPreferenceControllers(context, true /* async */); - } - - private static List buildPreferenceControllers(Context context, - boolean async) { - final List controllers = new ArrayList<>(); - controllers.add(new NetworkLogsPreferenceController(context)); - controllers.add(new BugReportsPreferenceController(context)); - controllers.add(new SecurityLogsPreferenceController(context)); - final List exposureChangesCategoryControllers = - new ArrayList<>(); - exposureChangesCategoryControllers.add(new EnterpriseInstalledPackagesPreferenceController( - context, async)); - exposureChangesCategoryControllers.add( - new AdminGrantedLocationPermissionsPreferenceController(context, async)); - exposureChangesCategoryControllers.add( - new AdminGrantedMicrophonePermissionPreferenceController(context, async)); - exposureChangesCategoryControllers.add(new AdminGrantedCameraPermissionPreferenceController( - context, async)); - exposureChangesCategoryControllers.add(new EnterpriseSetDefaultAppsPreferenceController( - context)); - exposureChangesCategoryControllers.add(new AlwaysOnVpnCurrentUserPreferenceController( - context)); - exposureChangesCategoryControllers.add(new AlwaysOnVpnManagedProfilePreferenceController( - context)); - exposureChangesCategoryControllers.add(new ImePreferenceController(context)); - exposureChangesCategoryControllers.add(new GlobalHttpProxyPreferenceController(context)); - exposureChangesCategoryControllers.add(new CaCertsCurrentUserPreferenceController(context)); - exposureChangesCategoryControllers.add(new CaCertsManagedProfilePreferenceController( - context)); - controllers.addAll(exposureChangesCategoryControllers); - controllers.add(new PreferenceCategoryController(context, "exposure_changes_category") - .setChildren(exposureChangesCategoryControllers)); - controllers.add(new FailedPasswordWipeCurrentUserPreferenceController(context)); - controllers.add(new FailedPasswordWipeManagedProfilePreferenceController(context)); - return controllers; + return mPrivacySettingsPreference.createPreferenceControllers(true /* async */); } public static boolean isPageEnabled(Context context) { @@ -99,17 +78,32 @@ public class EnterprisePrivacySettings extends DashboardFragment { } public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = - new BaseSearchIndexProvider(R.xml.enterprise_privacy_settings) { + new BaseSearchIndexProvider() { + + private PrivacySettingsPreference mPrivacySettingsPreference; + @Override protected boolean isPageSearchEnabled(Context context) { return isPageEnabled(context); } + @Override + public List getXmlResourcesToIndex(Context context, + boolean enabled) { + mPrivacySettingsPreference = + PrivacySettingsPreferenceFactory.createPrivacySettingsPreference( + context); + return mPrivacySettingsPreference.getXmlResourcesToIndex(); + } @Override public List createPreferenceControllers( Context context) { - return buildPreferenceControllers(context, false /* async */); + mPrivacySettingsPreference = + PrivacySettingsPreferenceFactory.createPrivacySettingsPreference( + context); + return mPrivacySettingsPreference.createPreferenceControllers( + false /* async */); } }; } diff --git a/src/com/android/settings/enterprise/PrivacySettingsEnterprisePreference.java b/src/com/android/settings/enterprise/PrivacySettingsEnterprisePreference.java new file mode 100644 index 00000000000..19556a13e5c --- /dev/null +++ b/src/com/android/settings/enterprise/PrivacySettingsEnterprisePreference.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2021 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.provider.SearchIndexableResource; + +import com.android.settings.R; +import com.android.settings.widget.PreferenceCategoryController; +import com.android.settingslib.core.AbstractPreferenceController; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** Privacy Settings preferences for an Enterprise device. */ +public class PrivacySettingsEnterprisePreference implements PrivacySettingsPreference { + private static final String KEY_EXPOSURE_CHANGES_CATEGORY = "exposure_changes_category"; + + private final Context mContext; + + public PrivacySettingsEnterprisePreference(Context context) { + mContext = context.getApplicationContext(); + } + + /** + * Returns the XML Res Id that is used for an Enterprise device in the Privacy Settings screen. + */ + @Override + public int getPreferenceScreenResId() { + return R.xml.enterprise_privacy_settings; + } + + /** + * Returns the Enterprise XML resources to index for an Enterprise device. + */ + @Override + public List getXmlResourcesToIndex() { + final SearchIndexableResource sir = new SearchIndexableResource(mContext); + sir.xmlResId = getPreferenceScreenResId(); + return Collections.singletonList(sir); + } + + /** + * Returns the preference controllers used to populate the privacy preferences in the Privacy + * Settings screen for Enterprise devices. + */ + @Override + public List createPreferenceControllers(boolean async) { + final List controllers = new ArrayList<>(); + controllers.add(new NetworkLogsPreferenceController(mContext)); + controllers.add(new BugReportsPreferenceController(mContext)); + controllers.add(new SecurityLogsPreferenceController(mContext)); + final List exposureChangesCategoryControllers = + new ArrayList<>(); + exposureChangesCategoryControllers.add(new EnterpriseInstalledPackagesPreferenceController( + mContext, async)); + exposureChangesCategoryControllers.add( + new AdminGrantedLocationPermissionsPreferenceController(mContext, async)); + exposureChangesCategoryControllers.add( + new AdminGrantedMicrophonePermissionPreferenceController(mContext, async)); + exposureChangesCategoryControllers.add(new AdminGrantedCameraPermissionPreferenceController( + mContext, async)); + exposureChangesCategoryControllers.add(new EnterpriseSetDefaultAppsPreferenceController( + mContext)); + exposureChangesCategoryControllers.add(new AlwaysOnVpnCurrentUserPreferenceController( + mContext)); + exposureChangesCategoryControllers.add(new AlwaysOnVpnManagedProfilePreferenceController( + mContext)); + exposureChangesCategoryControllers.add(new ImePreferenceController(mContext)); + exposureChangesCategoryControllers.add(new GlobalHttpProxyPreferenceController(mContext)); + exposureChangesCategoryControllers.add(new CaCertsCurrentUserPreferenceController( + mContext)); + exposureChangesCategoryControllers.add(new CaCertsManagedProfilePreferenceController( + mContext)); + controllers.addAll(exposureChangesCategoryControllers); + controllers.add(new PreferenceCategoryController(mContext, KEY_EXPOSURE_CHANGES_CATEGORY) + .setChildren(exposureChangesCategoryControllers)); + controllers.add(new FailedPasswordWipeCurrentUserPreferenceController(mContext)); + controllers.add(new FailedPasswordWipeManagedProfilePreferenceController(mContext)); + return controllers; + } +} diff --git a/src/com/android/settings/enterprise/PrivacySettingsFinancedPreference.java b/src/com/android/settings/enterprise/PrivacySettingsFinancedPreference.java new file mode 100644 index 00000000000..12901a63c15 --- /dev/null +++ b/src/com/android/settings/enterprise/PrivacySettingsFinancedPreference.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2021 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.provider.SearchIndexableResource; + +import com.android.settings.R; +import com.android.settings.widget.PreferenceCategoryController; +import com.android.settingslib.core.AbstractPreferenceController; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** Privacy Settings preferences for a financed device. */ +public class PrivacySettingsFinancedPreference implements PrivacySettingsPreference { + private static final String KEY_EXPOSURE_CHANGES_CATEGORY = "exposure_changes_category"; + + private final Context mContext; + + public PrivacySettingsFinancedPreference(Context context) { + mContext = context.getApplicationContext(); + } + + /** + * Returns the XML Res Id that is used for financed devices in the Privacy Settings screen. + */ + @Override + public int getPreferenceScreenResId() { + return R.xml.financed_privacy_settings; + } + + /** + * Returns the XML resources to index for a financed device. + */ + @Override + public List getXmlResourcesToIndex() { + final SearchIndexableResource sir = new SearchIndexableResource(mContext); + sir.xmlResId = getPreferenceScreenResId(); + return Collections.singletonList(sir); + } + + /** + * Returns the preference controllers used to populate the privacy preferences in the Privacy + * Settings screen for a financed device. + */ + @Override + public List createPreferenceControllers(boolean async) { + final List controllers = new ArrayList<>(); + controllers.add(new NetworkLogsPreferenceController(mContext)); + controllers.add(new BugReportsPreferenceController(mContext)); + controllers.add(new SecurityLogsPreferenceController(mContext)); + final List exposureChangesCategoryControllers = + new ArrayList<>(); + exposureChangesCategoryControllers.add(new EnterpriseInstalledPackagesPreferenceController( + mContext, async)); + controllers.addAll(exposureChangesCategoryControllers); + controllers.add(new PreferenceCategoryController(mContext, KEY_EXPOSURE_CHANGES_CATEGORY) + .setChildren(exposureChangesCategoryControllers)); + controllers.add(new FailedPasswordWipeCurrentUserPreferenceController(mContext)); + return controllers; + } +} diff --git a/src/com/android/settings/enterprise/PrivacySettingsPreference.java b/src/com/android/settings/enterprise/PrivacySettingsPreference.java new file mode 100644 index 00000000000..4310f5e58cc --- /dev/null +++ b/src/com/android/settings/enterprise/PrivacySettingsPreference.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021 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.provider.SearchIndexableResource; + +import com.android.settingslib.core.AbstractPreferenceController; + +import java.util.List; + +/** Interface for configuring what is displayed on the Privacy Settings. */ +public interface PrivacySettingsPreference { + + /** + * Returns the XML Res Id that is used in the Privacy Settings screen. + */ + int getPreferenceScreenResId(); + + /** + * Returns the XML resources to index. + */ + List getXmlResourcesToIndex(); + + /** + * Returns the preference controllers used to populate the privacy preferences. + */ + List createPreferenceControllers(boolean async); +} diff --git a/src/com/android/settings/enterprise/PrivacySettingsPreferenceFactory.java b/src/com/android/settings/enterprise/PrivacySettingsPreferenceFactory.java new file mode 100644 index 00000000000..0ec2498177e --- /dev/null +++ b/src/com/android/settings/enterprise/PrivacySettingsPreferenceFactory.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2021 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 static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED; + +import android.app.admin.DevicePolicyManager; +import android.content.Context; + +/** Factory for creating the privacy settings preference for a managed device. */ +public class PrivacySettingsPreferenceFactory { + + /** + * Determines which preference to use in the Privacy Settings based off of the type of managed + * device. + */ + public static PrivacySettingsPreference createPrivacySettingsPreference(Context context) { + if (isFinancedDevice(context)) { + return createPrivacySettingsFinancedPreference(context); + } else { + return createPrivacySettingsEnterprisePreference(context); + } + } + + private static PrivacySettingsEnterprisePreference createPrivacySettingsEnterprisePreference( + Context context) { + return new PrivacySettingsEnterprisePreference(context); + } + + private static PrivacySettingsFinancedPreference createPrivacySettingsFinancedPreference( + Context context) { + return new PrivacySettingsFinancedPreference(context); + } + + private static boolean isFinancedDevice(Context context) { + final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class); + return dpm.isDeviceManaged() && dpm.getDeviceOwnerType( + dpm.getDeviceOwnerComponentOnAnyUser()) == DEVICE_OWNER_TYPE_FINANCED; + } +} diff --git a/tests/robotests/src/com/android/settings/enterprise/BasePrivacySettingsPreferenceTest.java b/tests/robotests/src/com/android/settings/enterprise/BasePrivacySettingsPreferenceTest.java new file mode 100644 index 00000000000..fdf005dd602 --- /dev/null +++ b/tests/robotests/src/com/android/settings/enterprise/BasePrivacySettingsPreferenceTest.java @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2021 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 static com.google.common.truth.Truth.assertThat; + +import android.content.Context; +import android.provider.SearchIndexableResource; + +import androidx.test.core.app.ApplicationProvider; + +import com.android.settings.R; +import com.android.settings.widget.PreferenceCategoryController; +import com.android.settingslib.core.AbstractPreferenceController; + +import org.junit.Before; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; + +import java.util.List; + +@RunWith(RobolectricTestRunner.class) +public abstract class BasePrivacySettingsPreferenceTest { + + protected Context mContext; + + @Before + public void setUp() { + mContext = ApplicationProvider.getApplicationContext(); + } + + protected static void verifyEnterpriseSearchIndexableResources( + List searchIndexableResources) { + assertThat(searchIndexableResources).isNotEmpty(); + assertThat(searchIndexableResources.size()).isEqualTo(1); + assertThat(searchIndexableResources.get(0).xmlResId) + .isEqualTo(R.xml.enterprise_privacy_settings); + } + + protected static void verifyEnterprisePreferenceControllers( + List controllers) { + assertThat(controllers).isNotNull(); + assertThat(controllers.size()).isEqualTo(17); + int position = 0; + assertThat(controllers.get(position++)).isInstanceOf(NetworkLogsPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf(BugReportsPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + SecurityLogsPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + EnterpriseInstalledPackagesPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + AdminGrantedLocationPermissionsPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + AdminGrantedMicrophonePermissionPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + AdminGrantedCameraPermissionPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + EnterpriseSetDefaultAppsPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + AlwaysOnVpnCurrentUserPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + AlwaysOnVpnManagedProfilePreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf(ImePreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + GlobalHttpProxyPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + CaCertsCurrentUserPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + CaCertsManagedProfilePreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + PreferenceCategoryController.class); + assertThat(controllers.get(position++)).isInstanceOf( + FailedPasswordWipeCurrentUserPreferenceController.class); + assertThat(controllers.get(position)).isInstanceOf( + FailedPasswordWipeManagedProfilePreferenceController.class); + } + + protected static void verifyFinancedSearchIndexableResources( + List searchIndexableResources) { + assertThat(searchIndexableResources).isNotEmpty(); + assertThat(searchIndexableResources.size()).isEqualTo(1); + assertThat(searchIndexableResources.get(0).xmlResId) + .isEqualTo(R.xml.financed_privacy_settings); + } + + protected static void verifyFinancedPreferenceControllers( + List controllers) { + assertThat(controllers).isNotNull(); + assertThat(controllers.size()).isEqualTo(6); + int position = 0; + assertThat(controllers.get(position++)).isInstanceOf(NetworkLogsPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf(BugReportsPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + SecurityLogsPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + EnterpriseInstalledPackagesPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + PreferenceCategoryController.class); + assertThat(controllers.get(position)).isInstanceOf( + FailedPasswordWipeCurrentUserPreferenceController.class); + } +} diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java index 2d4ba6295e5..eb7074911bb 100644 --- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java +++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java @@ -16,47 +16,70 @@ package com.android.settings.enterprise; +import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_DEFAULT; + import static com.google.common.truth.Truth.assertThat; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; -import android.content.Context; +import android.app.admin.DevicePolicyManager; +import android.content.ComponentName; +import android.provider.SearchIndexableResource; + +import androidx.test.core.app.ApplicationProvider; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; import com.android.settings.testutils.FakeFeatureFactory; -import com.android.settings.widget.PreferenceCategoryController; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.drawer.CategoryKey; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Answers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; +import java.util.ArrayList; import java.util.List; @RunWith(RobolectricTestRunner.class) -public class EnterprisePrivacySettingsTest { +public class EnterprisePrivacySettingsTest extends BasePrivacySettingsPreferenceTest { + private static final ComponentName DEVICE_OWNER_COMPONENT = + new ComponentName("com.android.foo", "bar"); - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private Context mContext; + @Mock + private DevicePolicyManager mDevicePolicyManager; + @Mock + private PrivacySettingsPreference mPrivacySettingsPreference; private FakeFeatureFactory mFeatureFactory; private EnterprisePrivacySettings mSettings; + @Override @Before public void setUp() { MockitoAnnotations.initMocks(this); + mContext = spy(ApplicationProvider.getApplicationContext()); mFeatureFactory = FakeFeatureFactory.setupForTest(); mSettings = new EnterprisePrivacySettings(); + mSettings.mPrivacySettingsPreference = mPrivacySettingsPreference; + + when(mContext.getSystemService(DevicePolicyManager.class)).thenReturn(mDevicePolicyManager); + when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true); + when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()) + .thenReturn(DEVICE_OWNER_COMPONENT); + when(mDevicePolicyManager.getDeviceOwnerType(DEVICE_OWNER_COMPONENT)) + .thenReturn(DEVICE_OWNER_TYPE_DEFAULT); } @Test public void verifyConstants() { + when(mPrivacySettingsPreference.getPreferenceScreenResId()) + .thenReturn(R.xml.enterprise_privacy_settings); + assertThat(mSettings.getMetricsCategory()) .isEqualTo(MetricsEvent.ENTERPRISE_PRIVACY_SETTINGS); assertThat(mSettings.getLogTag()).isEqualTo("EnterprisePrivacySettings"); @@ -76,6 +99,7 @@ public class EnterprisePrivacySettingsTest { @Test public void isPageEnabled_noDeviceOwner_shouldReturnFalse() { + when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false); when(mFeatureFactory.enterprisePrivacyFeatureProvider.hasDeviceOwner()) .thenReturn(false); @@ -85,53 +109,35 @@ public class EnterprisePrivacySettingsTest { @Test public void getPreferenceControllers() { - final List controllers = - mSettings.createPreferenceControllers(RuntimeEnvironment.application); - verifyPreferenceControllers(controllers); + final List controllers = new ArrayList<>(); + controllers.add(new NetworkLogsPreferenceController(mContext)); + when(mPrivacySettingsPreference.createPreferenceControllers(anyBoolean())) + .thenReturn(controllers); + + final List privacyControllers = + mSettings.createPreferenceControllers(mContext); + + assertThat(privacyControllers).isNotNull(); + assertThat(privacyControllers.size()).isEqualTo(1); + assertThat(controllers.get(0)).isInstanceOf(NetworkLogsPreferenceController.class); } @Test - public void getSearchIndexProviderPreferenceControllers() { + public void + getSearchIndexProviderPreferenceControllers_returnsEnterpriseSearchIndexPreferenceControllers() { final List controllers = EnterprisePrivacySettings.SEARCH_INDEX_DATA_PROVIDER - .getPreferenceControllers(RuntimeEnvironment.application); - verifyPreferenceControllers(controllers); + .getPreferenceControllers(mContext); + + verifyEnterprisePreferenceControllers(controllers); } - private void verifyPreferenceControllers(List controllers) { - assertThat(controllers).isNotNull(); - assertThat(controllers.size()).isEqualTo(17); - int position = 0; - assertThat(controllers.get(position++)).isInstanceOf(NetworkLogsPreferenceController.class); - assertThat(controllers.get(position++)).isInstanceOf(BugReportsPreferenceController.class); - assertThat(controllers.get(position++)).isInstanceOf( - SecurityLogsPreferenceController.class); - assertThat(controllers.get(position++)).isInstanceOf( - EnterpriseInstalledPackagesPreferenceController.class); - assertThat(controllers.get(position++)).isInstanceOf( - AdminGrantedLocationPermissionsPreferenceController.class); - assertThat(controllers.get(position++)).isInstanceOf( - AdminGrantedMicrophonePermissionPreferenceController.class); - assertThat(controllers.get(position++)).isInstanceOf( - AdminGrantedCameraPermissionPreferenceController.class); - assertThat(controllers.get(position++)).isInstanceOf( - EnterpriseSetDefaultAppsPreferenceController.class); - assertThat(controllers.get(position++)).isInstanceOf( - AlwaysOnVpnCurrentUserPreferenceController.class); - assertThat(controllers.get(position++)).isInstanceOf( - AlwaysOnVpnManagedProfilePreferenceController.class); - assertThat(controllers.get(position++)).isInstanceOf(ImePreferenceController.class); - assertThat(controllers.get(position++)).isInstanceOf( - GlobalHttpProxyPreferenceController.class); - assertThat(controllers.get(position++)).isInstanceOf( - CaCertsCurrentUserPreferenceController.class); - assertThat(controllers.get(position++)).isInstanceOf( - CaCertsManagedProfilePreferenceController.class); - assertThat(controllers.get(position++)).isInstanceOf( - PreferenceCategoryController.class); - assertThat(controllers.get(position++)).isInstanceOf( - FailedPasswordWipeCurrentUserPreferenceController.class); - assertThat(controllers.get(position)).isInstanceOf( - FailedPasswordWipeManagedProfilePreferenceController.class); + @Test + public void getXmlResourcesToIndex_returnsEnterpriseXmlResources() { + final List searchIndexableResources = + EnterprisePrivacySettings.SEARCH_INDEX_DATA_PROVIDER + .getXmlResourcesToIndex(mContext, true); + + verifyEnterpriseSearchIndexableResources(searchIndexableResources); } } diff --git a/tests/robotests/src/com/android/settings/enterprise/PrivacySettingsEnterprisePreferenceTest.java b/tests/robotests/src/com/android/settings/enterprise/PrivacySettingsEnterprisePreferenceTest.java new file mode 100644 index 00000000000..68e37fc7792 --- /dev/null +++ b/tests/robotests/src/com/android/settings/enterprise/PrivacySettingsEnterprisePreferenceTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2021 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 static com.google.common.truth.Truth.assertThat; + +import android.provider.SearchIndexableResource; + +import com.android.settings.R; +import com.android.settingslib.core.AbstractPreferenceController; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; + +import java.util.List; + +@RunWith(RobolectricTestRunner.class) +public class PrivacySettingsEnterprisePreferenceTest extends BasePrivacySettingsPreferenceTest { + + private PrivacySettingsEnterprisePreference mPrivacySettingsEnterprisePreference; + + @Override + @Before + public void setUp() { + super.setUp(); + mPrivacySettingsEnterprisePreference = new PrivacySettingsEnterprisePreference(mContext); + } + + @Test + public void getPreferenceScreenResId() { + assertThat(mPrivacySettingsEnterprisePreference.getPreferenceScreenResId()) + .isEqualTo(R.xml.enterprise_privacy_settings); + } + + @Test + public void getXmlResourcesToIndex() { + final List searchIndexableResources = + mPrivacySettingsEnterprisePreference.getXmlResourcesToIndex(); + + verifyEnterpriseSearchIndexableResources(searchIndexableResources); + } + + @Test + public void getPreferenceControllers() { + final List controllers = + mPrivacySettingsEnterprisePreference.createPreferenceControllers(true); + + verifyEnterprisePreferenceControllers(controllers); + } +} diff --git a/tests/robotests/src/com/android/settings/enterprise/PrivacySettingsFinancedPreferenceTest.java b/tests/robotests/src/com/android/settings/enterprise/PrivacySettingsFinancedPreferenceTest.java new file mode 100644 index 00000000000..fe7b214c851 --- /dev/null +++ b/tests/robotests/src/com/android/settings/enterprise/PrivacySettingsFinancedPreferenceTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2021 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 static com.google.common.truth.Truth.assertThat; + +import android.provider.SearchIndexableResource; + +import com.android.settings.R; +import com.android.settingslib.core.AbstractPreferenceController; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; + +import java.util.List; + +@RunWith(RobolectricTestRunner.class) +public class PrivacySettingsFinancedPreferenceTest extends BasePrivacySettingsPreferenceTest { + + private PrivacySettingsFinancedPreference mPrivacySettingsFinancedPreference; + + @Override + @Before + public void setUp() { + super.setUp(); + mPrivacySettingsFinancedPreference = new PrivacySettingsFinancedPreference(mContext); + } + + @Test + public void getPreferenceScreenResId() { + assertThat(mPrivacySettingsFinancedPreference.getPreferenceScreenResId()) + .isEqualTo(R.xml.financed_privacy_settings); + } + + @Test + public void getXmlResourcesToIndex() { + final List searchIndexableResources = + mPrivacySettingsFinancedPreference.getXmlResourcesToIndex(); + + verifyFinancedSearchIndexableResources(searchIndexableResources); + } + + @Test + public void getPreferenceControllers() { + final List controllers = + mPrivacySettingsFinancedPreference.createPreferenceControllers(true); + + verifyFinancedPreferenceControllers(controllers); + } +}