Merge "Import translations. DO NOT MERGE" into oc-dev
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 9a149c3..678a63b 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -102,6 +102,8 @@
     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 int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
     private static final int CHANGE_TRUST_AGENT_SETTINGS = 126;
@@ -930,7 +932,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);
 
@@ -952,6 +954,14 @@
                 keys.add(KEY_ENTERPRISE_PRIVACY);
             }
 
+            // Duplicate in special app access
+            keys.add(KEY_MANAGE_DEVICE_ADMIN);
+            // Duplicates between parent-child
+            keys.add((new LocationPreferenceController(context)).getPreferenceKey());
+            keys.add(KEY_ENCRYPTION_AND_CREDENTIALS);
+            keys.add(KEY_SCREEN_PINNING);
+            keys.add(KEY_LOCATION_SCANNING);
+
             return keys;
         }
     }
diff --git a/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragment.java b/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragment.java
index 73f4bbe..a08711c 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragment.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragment.java
@@ -23,6 +23,7 @@
 import android.app.Fragment;
 import android.content.Context;
 import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
 import android.os.Bundle;
 import android.text.TextUtils;
 
@@ -76,7 +77,9 @@
 
     protected ConfirmationDialogFragment newConfirmationDialogFragment(String selectedKey,
             CharSequence confirmationMessage) {
-        return ConfirmationDialogFragment.newInstance(this, selectedKey, confirmationMessage);
+        final ConfirmationDialogFragment fragment = new ConfirmationDialogFragment();
+        fragment.init(this, selectedKey, confirmationMessage);
+        return fragment;
     }
 
     protected CharSequence getConfirmationMessage(CandidateInfo info) {
@@ -90,33 +93,29 @@
         public static final String EXTRA_KEY = "extra_key";
         public static final String EXTRA_MESSAGE = "extra_message";
 
-        private final DialogInterface.OnClickListener mCancelListener;
-
-        private ConfirmationDialogFragment(DialogInterface.OnClickListener cancelListener) {
-            mCancelListener = cancelListener;
-        }
+        private DialogInterface.OnClickListener mCancelListener;
 
         @Override
         public int getMetricsCategory() {
             return MetricsProto.MetricsEvent.DEFAULT_APP_PICKER_CONFIRMATION_DIALOG;
         }
 
-        public static ConfirmationDialogFragment newInstance(DefaultAppPickerFragment parent,
-                String key, CharSequence message) {
-            return newInstance(parent, key, message, null);
-        }
-
-        // TODO: add test case for cancelListener
-        public static ConfirmationDialogFragment newInstance(DefaultAppPickerFragment parent,
-                String key, CharSequence message, DialogInterface.OnClickListener cancelListener) {
-            final ConfirmationDialogFragment fragment = new ConfirmationDialogFragment(
-                    cancelListener);
+        /**
+         * Initializes the fragment.
+         *
+         * <p>Should be called after it's constructed.
+         */
+        public void init(DefaultAppPickerFragment parent, String key, CharSequence message) {
             final Bundle argument = new Bundle();
             argument.putString(EXTRA_KEY, key);
             argument.putCharSequence(EXTRA_MESSAGE, message);
-            fragment.setArguments(argument);
-            fragment.setTargetFragment(parent, 0);
-            return fragment;
+            setArguments(argument);
+            setTargetFragment(parent, 0);
+        }
+
+        // TODO: add test case for cancelListener
+        public void setCancelListener(DialogInterface.OnClickListener cancelListener) {
+            this.mCancelListener = cancelListener;
         }
 
         @Override
diff --git a/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java b/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java
index 6dcf7b8..d674522 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java
@@ -18,6 +18,7 @@
 
 import android.Manifest;
 import android.app.Activity;
+import android.app.Dialog;
 import android.content.ComponentName;
 import android.content.ContentResolver;
 import android.content.Context;
@@ -60,7 +61,7 @@
     /**
      * Set when the fragment is implementing ACTION_REQUEST_SET_AUTOFILL_SERVICE.
      */
-    public DialogInterface.OnClickListener mCancelListener;
+    private DialogInterface.OnClickListener mCancelListener;
     private final Handler mHandler = new Handler();
 
     @Override
@@ -75,15 +76,33 @@
             };
         }
 
-        mSettingsPackageMonitor.register(getActivity(), getActivity().getMainLooper(), false);
+        mSettingsPackageMonitor.register(activity, activity.getMainLooper(), false);
         update();
     }
 
     @Override
     protected ConfirmationDialogFragment newConfirmationDialogFragment(String selectedKey,
             CharSequence confirmationMessage) {
-        return ConfirmationDialogFragment.newInstance(this, selectedKey, confirmationMessage,
-                mCancelListener);
+        final AutofillPickerConfirmationDialogFragment fragment =
+                new AutofillPickerConfirmationDialogFragment();
+        fragment.init(this, selectedKey, confirmationMessage);
+        return fragment;
+    }
+
+    /**
+     * Custom dialog fragment that has a cancel listener used to propagate the result back to
+     * caller (for the cases where the picker is launched by
+     * {@code android.settings.REQUEST_SET_AUTOFILL_SERVICE}.
+     */
+    public static class AutofillPickerConfirmationDialogFragment
+            extends ConfirmationDialogFragment {
+
+        @Override
+        public void onCreate(Bundle savedInstanceState) {
+            final DefaultAutofillPicker target = (DefaultAutofillPicker) getTargetFragment();
+            setCancelListener(target.mCancelListener);
+            super.onCreate(savedInstanceState);
+        }
     }
 
     @Override
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;
+    }
+}