Merge "Update Privacy Settings text for a financed device" into sc-dev am: d85317e4e5

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/13879465

Change-Id: I4c4c00f7709c86669824cc18667c39c825f93726
This commit is contained in:
Rajeev Kumar
2021-03-24 01:24:16 +00:00
committed by Automerger Merge Worker
11 changed files with 713 additions and 91 deletions

View File

@@ -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<SearchIndexableResource> 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<AbstractPreferenceController> 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<SearchIndexableResource> 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<AbstractPreferenceController> 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);
}
}

View File

@@ -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<AbstractPreferenceController> controllers =
mSettings.createPreferenceControllers(RuntimeEnvironment.application);
verifyPreferenceControllers(controllers);
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new NetworkLogsPreferenceController(mContext));
when(mPrivacySettingsPreference.createPreferenceControllers(anyBoolean()))
.thenReturn(controllers);
final List<AbstractPreferenceController> 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<AbstractPreferenceController> controllers =
EnterprisePrivacySettings.SEARCH_INDEX_DATA_PROVIDER
.getPreferenceControllers(RuntimeEnvironment.application);
verifyPreferenceControllers(controllers);
.getPreferenceControllers(mContext);
verifyEnterprisePreferenceControllers(controllers);
}
private void verifyPreferenceControllers(List<AbstractPreferenceController> 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<SearchIndexableResource> searchIndexableResources =
EnterprisePrivacySettings.SEARCH_INDEX_DATA_PROVIDER
.getXmlResourcesToIndex(mContext, true);
verifyEnterpriseSearchIndexableResources(searchIndexableResources);
}
}

View File

@@ -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<SearchIndexableResource> searchIndexableResources =
mPrivacySettingsEnterprisePreference.getXmlResourcesToIndex();
verifyEnterpriseSearchIndexableResources(searchIndexableResources);
}
@Test
public void getPreferenceControllers() {
final List<AbstractPreferenceController> controllers =
mPrivacySettingsEnterprisePreference.createPreferenceControllers(true);
verifyEnterprisePreferenceControllers(controllers);
}
}

View File

@@ -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<SearchIndexableResource> searchIndexableResources =
mPrivacySettingsFinancedPreference.getXmlResourcesToIndex();
verifyFinancedSearchIndexableResources(searchIndexableResources);
}
@Test
public void getPreferenceControllers() {
final List<AbstractPreferenceController> controllers =
mPrivacySettingsFinancedPreference.createPreferenceControllers(true);
verifyFinancedPreferenceControllers(controllers);
}
}