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
diff --git a/res/xml/encryption_and_credential.xml b/res/xml/encryption_and_credential.xml
index a84c2a1..be643b1 100644
--- a/res/xml/encryption_and_credential.xml
+++ b/res/xml/encryption_and_credential.xml
@@ -15,7 +15,8 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
- android:title="@string/encryption_and_credential_settings_title">
+ android:title="@string/encryption_and_credential_settings_title"
+ android:key="encryption_and_credentials_screen">
<PreferenceCategory android:key="credentials_management"
android:title="@string/credentials_title"
diff --git a/res/xml/location_scanning.xml b/res/xml/location_scanning.xml
index f82500b..5e7bd24 100644
--- a/res/xml/location_scanning.xml
+++ b/res/xml/location_scanning.xml
@@ -15,7 +15,8 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
- android:title="@string/location_scanning_screen_title">
+ android:title="@string/location_scanning_screen_title"
+ android:key="scanning_screen">
<SwitchPreference
android:title="@string/location_scanning_wifi_always_scanning_title"
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index ec57ed1..736b85c 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -106,6 +106,9 @@
private static final String KEY_UNIFICATION = "unification";
@VisibleForTesting
static final String KEY_LOCKSCREEN_PREFERENCES = "lockscreen_preferences";
+ private static final String KEY_ENCRYPTION_AND_CREDENTIALS = "encryption_and_credential";
+ private static final String KEY_LOCATION_SCANNING = "location_scanning";
+ private static final String KEY_LOCATION = "location";
private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
private static final int CHANGE_TRUST_AGENT_SETTINGS = 126;
@@ -939,7 +942,7 @@
@Override
public List<String> getNonIndexableKeys(Context context) {
- final List<String> keys = new ArrayList<String>();
+ final List<String> keys = super.getNonIndexableKeys(context);
LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
@@ -961,6 +964,14 @@
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 c636748..e28a594 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.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.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 @@
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<String> niks = SecuritySettings.SEARCH_INDEX_DATA_PROVIDER
+ .getNonIndexableKeys(context);
+
+ final List<String> 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 0000000..b1419ba
--- /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;
+ }
+}