From 2e34a64a55665e40bea7b23b075be103afde7e4f Mon Sep 17 00:00:00 2001 From: Matthew Fritze Date: Thu, 11 May 2017 11:56:27 -0700 Subject: [PATCH] Remove duplicates in Security Settings Duplicates: - Location - Scanning - Encryption and Credentials - Screen Pinning - Device Admin Apps Merge for ag/2247508 Bug: 33701673 Test: make RunSettingsRoboTests Change-Id: I91566b8fb7fdb3b39c8833a6fa8e52bbbf6507b6 --- res/xml/encryption_and_credential.xml | 3 +- res/xml/location_scanning.xml | 3 +- .../android/settings/SecuritySettings.java | 13 ++++++- .../settings/SecuritySettingsTest.java | 38 ++++++++++++++----- .../shadow/ShadowLockPatternUtils.java | 30 +++++++++++++++ 5 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 tests/robotests/src/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java diff --git a/res/xml/encryption_and_credential.xml b/res/xml/encryption_and_credential.xml index a84c2a11fc9..be643b16ff4 100644 --- a/res/xml/encryption_and_credential.xml +++ b/res/xml/encryption_and_credential.xml @@ -15,7 +15,8 @@ --> + android:title="@string/encryption_and_credential_settings_title" + android:key="encryption_and_credentials_screen"> + android:title="@string/location_scanning_screen_title" + android:key="scanning_screen"> getNonIndexableKeys(Context context) { - final List keys = new ArrayList(); + final List keys = super.getNonIndexableKeys(context); LockPatternUtils lockPatternUtils = new LockPatternUtils(context); @@ -961,6 +964,14 @@ public class SecuritySettings extends SettingsPreferenceFragment keys.add(KEY_ENTERPRISE_PRIVACY); } + // Duplicate in special app access + keys.add(KEY_MANAGE_DEVICE_ADMIN); + // Duplicates between parent-child + keys.add(KEY_LOCATION); + keys.add(KEY_ENCRYPTION_AND_CREDENTIALS); + keys.add(KEY_SCREEN_PINNING); + keys.add(KEY_LOCATION_SCANNING); + return keys; } } diff --git a/tests/robotests/src/com/android/settings/SecuritySettingsTest.java b/tests/robotests/src/com/android/settings/SecuritySettingsTest.java index c63674874f6..e28a59468b4 100644 --- a/tests/robotests/src/com/android/settings/SecuritySettingsTest.java +++ b/tests/robotests/src/com/android/settings/SecuritySettingsTest.java @@ -21,8 +21,7 @@ import android.content.Context; import android.content.IContentProvider; import android.content.pm.PackageManager; import android.hardware.fingerprint.FingerprintManager; -import android.os.Bundle; -import android.provider.Settings; +import android.os.UserManager; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceGroup; import android.support.v7.preference.PreferenceScreen; @@ -31,33 +30,30 @@ import com.android.internal.widget.LockPatternUtils; import com.android.settings.dashboard.SummaryLoader; import com.android.settings.notification.LockScreenNotificationPreferenceController; import com.android.settings.testutils.FakeFeatureFactory; -import com.android.settings.testutils.shadow.ShadowSecureSettings; +import com.android.settings.testutils.XmlTestUtils; +import com.android.settings.testutils.shadow.ShadowLockPatternUtils; import com.android.settingslib.drawer.DashboardCategory; -import com.android.settingslib.drawer.Tile; -import com.android.settingslib.drawer.TileUtils; - 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.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; import org.robolectric.shadows.ShadowApplication; import org.robolectric.util.ReflectionHelpers; +import java.util.List; import java.util.Map; -import org.robolectric.util.ReflectionHelpers; import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.isNull; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; @@ -182,4 +178,26 @@ public class SecuritySettingsTest { securitySettings.setLockscreenPreferencesSummary(group); verify(preference).setSummary(1234); } + + @Test + @Config (shadows = { + ShadowLockPatternUtils.class, + }) + public void testNonIndexableKeys_existInXmlLayout() { + final Context context = spy(RuntimeEnvironment.application); + UserManager manager = mock(UserManager.class); + when(manager.isAdminUser()).thenReturn(false); + doReturn(manager).when(context).getSystemService(Context.USER_SERVICE); + final List niks = SecuritySettings.SEARCH_INDEX_DATA_PROVIDER + .getNonIndexableKeys(context); + + final List keys = XmlTestUtils.getKeysFromPreferenceXml(context, + R.xml.security_settings_misc); + keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, + R.xml.location_settings)); + keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, + R.xml.encryption_and_credential)); + + assertThat(keys).containsAllIn(niks); + } } diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java new file mode 100644 index 00000000000..b1419ba8e39 --- /dev/null +++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2017 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.testutils.shadow; + +import com.android.internal.widget.LockPatternUtils; +import org.robolectric.annotation.Implementation; +import org.robolectric.annotation.Implements; + +@Implements(LockPatternUtils.class) +public class ShadowLockPatternUtils { + + @Implementation + public boolean isSecure(int id) { + return true; + } +}