Merge "Set LinkMovementMethod in LinkTextView" into nyc-dev
diff --git a/res/drawable-nodpi/work_challenge_background.png b/res/drawable-nodpi/work_challenge_background.png
index d38668f..50f0c76 100644
--- a/res/drawable-nodpi/work_challenge_background.png
+++ b/res/drawable-nodpi/work_challenge_background.png
Binary files differ
diff --git a/res/values/ids.xml b/res/values/ids.xml
index 2fbf70b..f9334e4 100644
--- a/res/values/ids.xml
+++ b/res/values/ids.xml
@@ -18,4 +18,10 @@
 -->
 <resources>
     <item type="id" name="preference_highlight_key" />
+
+    <item type="id" name="lock_none" />
+    <item type="id" name="lock_pin" />
+    <item type="id" name="lock_password" />
+
+    <item type="id" name="encrypt_dont_require_password" />
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2350e55..95a7749 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1967,10 +1967,20 @@
     <string-array name="wifi_calling_mode_choices">
         <item>Wi-Fi preferred</item>
         <item>Cellular preferred</item>
+        <item>Wi-Fi only</item>
     </string-array>
     <string-array name="wifi_calling_mode_values">
         <item>"2"</item>
         <item>"1"</item>
+        <item>"0"</item>
+    </string-array>
+    <string-array name="wifi_calling_mode_choices_without_wifi_only">
+        <item>Wi-Fi preferred</item>
+        <item>Cellular preferred</item>
+    </string-array>
+    <string-array name="wifi_calling_mode_values_without_wifi_only">
+        <item>"2"</item>
+        <item>"1"</item>
     </string-array>
     <!-- Wi-Fi Calling settings. Text displayed when Wi-Fi Calling is off -->
     <string name="wifi_calling_off_explanation">When Wi-Fi calling is on, your phone can route calls via Wi-Fi networks or your carrier\u2019s network, depending on your preference and which signal is stronger. Before turning on this feature, check with your carrier regarding fees and other details.</string>
@@ -3063,22 +3073,22 @@
 
     <!-- Message to be used to explain the user that he needs to enter his pattern to continue a
          particular operation. [CHAR LIMIT=70]-->
-    <string name="lockpassword_confirm_your_pattern_generic">Use your device pattern to continue.</string>
+    <string name="lockpassword_confirm_your_pattern_generic">Use your device pattern to continue</string>
     <!-- Message to be used to explain the user that he needs to enter his PIN to continue a
          particular operation. [CHAR LIMIT=70]-->
-    <string name="lockpassword_confirm_your_pin_generic">Enter your device PIN to continue.</string>
+    <string name="lockpassword_confirm_your_pin_generic">Enter your device PIN to continue</string>
     <!-- Message to be used to explain the user that he needs to enter his password to continue a
          particular operation. [CHAR LIMIT=70]-->
-    <string name="lockpassword_confirm_your_password_generic">Enter your device password to continue.</string>
+    <string name="lockpassword_confirm_your_password_generic">Enter your device password to continue</string>
     <!-- Message to be used to explain the user that he needs to enter his work pattern to continue a
          particular operation. [CHAR LIMIT=70]-->
-    <string name="lockpassword_confirm_your_pattern_generic_profile">Use your work pattern to continue.</string>
+    <string name="lockpassword_confirm_your_pattern_generic_profile">Use your work pattern to continue</string>
     <!-- Message to be used to explain the user that he needs to enter his work PIN to continue a
          particular operation. [CHAR LIMIT=70]-->
-    <string name="lockpassword_confirm_your_pin_generic_profile">Enter your work PIN to continue.</string>
+    <string name="lockpassword_confirm_your_pin_generic_profile">Enter your work PIN to continue</string>
     <!-- Message to be used to explain the user that he needs to enter his work password to continue a
          particular operation. [CHAR LIMIT=70]-->
-    <string name="lockpassword_confirm_your_password_generic_profile">Enter your work password to continue.</string>
+    <string name="lockpassword_confirm_your_password_generic_profile">Enter your work password to continue</string>
 
     <!-- Security & location settings screen, change security method screen instruction if user
          enters incorrect PIN [CHAR LIMIT=30] -->
@@ -5874,7 +5884,7 @@
     <string name="zen_mode_automation_settings_title">Automatic rules</string>
 
     <!--  Do not disturb: Title for the zen mode automation option Suggestion. [CHAR LIMIT=30] -->
-    <string name="zen_mode_automation_suggestion_title">Set Do Not Disturb Schedule</string>
+    <string name="zen_mode_automation_suggestion_title">Set Do Not Disturb schedule</string>
 
     <!--  Do not disturb: Summary for the zen mode automation option Suggestion. [CHAR LIMIT=30] -->
     <string name="zen_mode_automation_suggestion_summary">Silence your device at certain times</string>
diff --git a/res/xml/security_settings_misc.xml b/res/xml/security_settings_misc.xml
index b225682..2577b6c 100644
--- a/res/xml/security_settings_misc.xml
+++ b/res/xml/security_settings_misc.xml
@@ -72,7 +72,7 @@
                 android:persistent="false"
                 android:fragment="com.android.settings.TrustedCredentialsSettings"/>
 
-        <Preference android:key="user_credentials"
+        <com.android.settingslib.RestrictedPreference android:key="user_credentials"
                 android:title="@string/user_credentials"
                 android:summary="@string/user_credentials_summary"
                 android:persistent="false"
diff --git a/src/com/android/settings/ApnEditor.java b/src/com/android/settings/ApnEditor.java
index 102d6cc..3163b63 100644
--- a/src/com/android/settings/ApnEditor.java
+++ b/src/com/android/settings/ApnEditor.java
@@ -453,11 +453,7 @@
             return null;
         } else {
             String[] values = mRes.getStringArray(R.array.mvno_type_entries);
-            if (values[mvnoIndex].equals("None")) {
-                mMvnoMatchData.setEnabled(false);
-            } else {
-                mMvnoMatchData.setEnabled(true);
-            }
+            mMvnoMatchData.setEnabled(mvnoIndex != 0);
             if (newValue != null && newValue.equals(oldValue) == false) {
                 if (values[mvnoIndex].equals("SPN")) {
                     mMvnoMatchData.setText(mTelephonyManager.getSimOperatorName());
diff --git a/src/com/android/settings/ChooseLockGeneric.java b/src/com/android/settings/ChooseLockGeneric.java
index bb597a6..5eb17b2 100644
--- a/src/com/android/settings/ChooseLockGeneric.java
+++ b/src/com/android/settings/ChooseLockGeneric.java
@@ -350,6 +350,11 @@
 
         protected void addPreferences() {
             addPreferencesFromResource(R.xml.security_settings_picker);
+
+            // Used for testing purposes
+            findPreference(KEY_UNLOCK_SET_NONE).setViewId(R.id.lock_none);
+            findPreference(KEY_UNLOCK_SET_PIN).setViewId(R.id.lock_pin);
+            findPreference(KEY_UNLOCK_SET_PASSWORD).setViewId(R.id.lock_password);
         }
 
         private void updatePreferenceText() {
diff --git a/src/com/android/settings/ChooseLockPassword.java b/src/com/android/settings/ChooseLockPassword.java
index 0e542e6..b3826b7 100644
--- a/src/com/android/settings/ChooseLockPassword.java
+++ b/src/com/android/settings/ChooseLockPassword.java
@@ -135,7 +135,7 @@
     }
 
     @Override
-    public void onCreate(Bundle savedInstanceState) {
+    protected void onCreate(Bundle savedInstanceState) {
         // TODO: Fix on phones
         // Disable IME on our window since we provide our own keyboard
         //getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
diff --git a/src/com/android/settings/ChooseLockPattern.java b/src/com/android/settings/ChooseLockPattern.java
index 1b71685..2e9f767 100644
--- a/src/com/android/settings/ChooseLockPattern.java
+++ b/src/com/android/settings/ChooseLockPattern.java
@@ -108,7 +108,7 @@
     }
 
     @Override
-    public void onCreate(Bundle savedInstanceState) {
+    protected void onCreate(Bundle savedInstanceState) {
         // requestWindowFeature(Window.FEATURE_NO_TITLE);
         super.onCreate(savedInstanceState);
         CharSequence msg = getText(R.string.lockpassword_choose_your_pattern_header);
diff --git a/src/com/android/settings/ConfirmDeviceCredentialBaseActivity.java b/src/com/android/settings/ConfirmDeviceCredentialBaseActivity.java
index e6dd5e0..c56a956 100644
--- a/src/com/android/settings/ConfirmDeviceCredentialBaseActivity.java
+++ b/src/com/android/settings/ConfirmDeviceCredentialBaseActivity.java
@@ -31,7 +31,6 @@
     private boolean mDark;
     private boolean mEnterAnimationPending;
     private boolean mFirstTimeVisible = true;
-    private final Handler mHandler = new Handler();
 
     @Override
     protected void onCreate(Bundle savedState) {
@@ -76,7 +75,6 @@
             mFirstTimeVisible = false;
             prepareEnterAnimation();
             mEnterAnimationPending = true;
-            mHandler.postDelayed(mEnterAnimationCompleteTimeoutRunnable, 1000);
         }
     }
 
@@ -92,7 +90,6 @@
     public void onEnterAnimationComplete() {
         super.onEnterAnimationComplete();
         if (mEnterAnimationPending) {
-            mHandler.removeCallbacks(mEnterAnimationCompleteTimeoutRunnable);
             startEnterAnimation();
             mEnterAnimationPending = false;
         }
@@ -105,15 +102,4 @@
     public void startEnterAnimation() {
         getFragment().startEnterAnimation();
     }
-
-    /**
-     * Workaround for a bug in window manager which results that onEnterAnimationComplete doesn't
-     * get called in all cases.
-     */
-    private final Runnable mEnterAnimationCompleteTimeoutRunnable = new Runnable() {
-        @Override
-        public void run() {
-            onEnterAnimationComplete();
-        }
-    };
 }
diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java
index 594cd38..1b37066 100644
--- a/src/com/android/settings/CryptKeeper.java
+++ b/src/com/android/settings/CryptKeeper.java
@@ -799,8 +799,6 @@
         // Asynchronously throw up the IME, since there are issues with requesting it to be shown
         // immediately.
         if (mLockPatternView == null && !mCooldown) {
-            getWindow().setSoftInputMode(
-                                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
             mHandler.postDelayed(new Runnable() {
                 @Override public void run() {
                     imm.showSoftInputUnchecked(0, null);
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index 1b20eb0..75ad35d 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -339,9 +339,7 @@
         mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
 
         setIfOnlyAvailableForAdmins(true);
-        if (isUiRestricted()
-                || Settings.Global.getInt(getActivity().getContentResolver(),
-                        Settings.Global.DEVICE_PROVISIONED, 0) == 0) {
+        if (isUiRestricted() || !Utils.isDeviceProvisioned(getActivity())) {
             // Block access to developer options if the user is not the owner, if user policy
             // restricts it, or if the device has not been provisioned
             mUnavailable = true;
diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/DeviceInfoSettings.java
index 0f51011..ff7334b 100644
--- a/src/com/android/settings/DeviceInfoSettings.java
+++ b/src/com/android/settings/DeviceInfoSettings.java
@@ -231,8 +231,7 @@
             if (!mUm.isAdminUser()) return true;
 
             // Don't enable developer options until device has been provisioned
-            if (Settings.Global.getInt(getActivity().getContentResolver(),
-                    Settings.Global.DEVICE_PROVISIONED, 0) == 0) {
+            if (!Utils.isDeviceProvisioned(getActivity())) {
                 return true;
             }
 
diff --git a/src/com/android/settings/EncryptionInterstitial.java b/src/com/android/settings/EncryptionInterstitial.java
index 16c5a55..89eba7c 100644
--- a/src/com/android/settings/EncryptionInterstitial.java
+++ b/src/com/android/settings/EncryptionInterstitial.java
@@ -90,6 +90,10 @@
 
             addPreferencesFromResource(R.xml.security_settings_encryption_interstitial);
 
+            // Used for testing purposes
+            findPreference(KEY_ENCRYPT_DONT_REQUIRE_PASSWORD)
+                    .setViewId(R.id.encrypt_dont_require_password);
+
             mRequirePasswordToDecrypt = findPreference(KEY_ENCRYPT_REQUIRE_PASSWORD);
             mDontRequirePasswordToDecrypt = findPreference(KEY_ENCRYPT_DONT_REQUIRE_PASSWORD);
             boolean forFingerprint = getActivity().getIntent().getBooleanExtra(
diff --git a/src/com/android/settings/MasterClearConfirm.java b/src/com/android/settings/MasterClearConfirm.java
index d521ded..393b76a 100644
--- a/src/com/android/settings/MasterClearConfirm.java
+++ b/src/com/android/settings/MasterClearConfirm.java
@@ -68,8 +68,7 @@
                     getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
 
             if (pdbManager != null && !pdbManager.getOemUnlockEnabled() &&
-                    Settings.Global.getInt(getActivity().getContentResolver(),
-                            Settings.Global.DEVICE_PROVISIONED, 0) != 0) {
+                    Utils.isDeviceProvisioned(getActivity())) {
                 // if OEM unlock is enabled, this will be wiped during FR process. If disabled, it
                 // will be wiped here, unless the device is still being provisioned, in which case
                 // the persistent data block will be preserved.
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 333f6b8..e046175 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -104,6 +104,7 @@
     private static final String KEY_SIM_LOCK = "sim_lock";
     private static final String KEY_SHOW_PASSWORD = "show_password";
     private static final String KEY_CREDENTIAL_STORAGE_TYPE = "credential_storage_type";
+    private static final String KEY_USER_CREDENTIALS = "user_credentials";
     private static final String KEY_RESET_CREDENTIALS = "credentials_reset";
     private static final String KEY_CREDENTIALS_INSTALL = "credentials_install";
     private static final String KEY_TOGGLE_INSTALL_APPLICATIONS = "toggle_install_applications";
@@ -315,6 +316,10 @@
 
         if (!RestrictedLockUtils.hasBaseUserRestriction(getActivity(),
                 UserManager.DISALLOW_CONFIG_CREDENTIALS, MY_USER_ID)) {
+            RestrictedPreference userCredentials = (RestrictedPreference) root.findPreference(
+                    KEY_USER_CREDENTIALS);
+            userCredentials.checkRestrictionAndSetDisabled(
+                    UserManager.DISALLOW_CONFIG_CREDENTIALS);
             RestrictedPreference credentialStorageType = (RestrictedPreference) root.findPreference(
                     KEY_CREDENTIAL_STORAGE_TYPE);
             credentialStorageType.checkRestrictionAndSetDisabled(
@@ -336,6 +341,7 @@
             credentialsManager.removePreference(root.findPreference(KEY_RESET_CREDENTIALS));
             credentialsManager.removePreference(root.findPreference(KEY_CREDENTIALS_INSTALL));
             credentialsManager.removePreference(root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE));
+            credentialsManager.removePreference(root.findPreference(KEY_USER_CREDENTIALS));
         }
 
 
diff --git a/src/com/android/settings/SetupChooseLockGeneric.java b/src/com/android/settings/SetupChooseLockGeneric.java
index 8aaca25..bc3a2ec 100644
--- a/src/com/android/settings/SetupChooseLockGeneric.java
+++ b/src/com/android/settings/SetupChooseLockGeneric.java
@@ -32,6 +32,7 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Button;
+import android.widget.LinearLayout;
 
 import com.android.internal.widget.LockPatternUtils;
 import com.android.settings.fingerprint.SetupSkipDialog;
@@ -66,6 +67,13 @@
         super.onApplyThemeResource(theme, resid, first);
     }
 
+    @Override
+    protected void onCreate(Bundle savedInstance) {
+        super.onCreate(savedInstance);
+        LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent);
+        layout.setFitsSystemWindows(false);
+    }
+
     public static class SetupChooseLockGenericFragment extends ChooseLockGenericFragment
             implements NavigationBar.NavigationBarListener {
 
diff --git a/src/com/android/settings/SetupChooseLockPassword.java b/src/com/android/settings/SetupChooseLockPassword.java
index 00c30bc..d483d8f 100644
--- a/src/com/android/settings/SetupChooseLockPassword.java
+++ b/src/com/android/settings/SetupChooseLockPassword.java
@@ -25,6 +25,7 @@
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.LinearLayout;
 
 import com.android.setupwizardlib.SetupWizardLayout;
 import com.android.setupwizardlib.util.SystemBarHelper;
@@ -78,6 +79,13 @@
     }
 
     @Override
+    protected void onCreate(Bundle savedInstance) {
+        super.onCreate(savedInstance);
+        LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent);
+        layout.setFitsSystemWindows(false);
+    }
+
+    @Override
     protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
         resid = SetupWizardUtils.getTheme(getIntent());
         super.onApplyThemeResource(theme, resid, first);
diff --git a/src/com/android/settings/SetupChooseLockPattern.java b/src/com/android/settings/SetupChooseLockPattern.java
index a5eab11..8a7842d 100644
--- a/src/com/android/settings/SetupChooseLockPattern.java
+++ b/src/com/android/settings/SetupChooseLockPattern.java
@@ -27,6 +27,7 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Button;
+import android.widget.LinearLayout;
 
 import com.android.setupwizardlib.SetupWizardLayout;
 import com.android.setupwizardlib.view.NavigationBar;
@@ -73,6 +74,13 @@
     }
 
     @Override
+    protected void onCreate(Bundle savedInstance) {
+        super.onCreate(savedInstance);
+        LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent);
+        layout.setFitsSystemWindows(false);
+    }
+
+    @Override
     protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
         resid = SetupWizardUtils.getTheme(getIntent());
         super.onApplyThemeResource(theme, resid, first);
diff --git a/src/com/android/settings/SetupEncryptionInterstitial.java b/src/com/android/settings/SetupEncryptionInterstitial.java
index 702a5c9..39c8af1 100644
--- a/src/com/android/settings/SetupEncryptionInterstitial.java
+++ b/src/com/android/settings/SetupEncryptionInterstitial.java
@@ -26,6 +26,7 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Button;
+import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import com.android.setupwizardlib.SetupWizardLayout;
@@ -70,6 +71,13 @@
         super.onApplyThemeResource(theme, resid, first);
     }
 
+    @Override
+    protected void onCreate(Bundle savedInstance) {
+        super.onCreate(savedInstance);
+        LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent);
+        layout.setFitsSystemWindows(false);
+    }
+
     public static class SetupEncryptionInterstitialFragment extends EncryptionInterstitialFragment
             implements NavigationBar.NavigationBarListener {
 
diff --git a/src/com/android/settings/SetupRedactionInterstitial.java b/src/com/android/settings/SetupRedactionInterstitial.java
index 354016d..e487a50 100644
--- a/src/com/android/settings/SetupRedactionInterstitial.java
+++ b/src/com/android/settings/SetupRedactionInterstitial.java
@@ -25,6 +25,7 @@
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.LinearLayout;
 
 import com.android.settings.notification.RedactionInterstitial;
 import com.android.setupwizardlib.SetupWizardLayout;
@@ -58,6 +59,13 @@
         super.onApplyThemeResource(theme, resid, first);
     }
 
+    @Override
+    protected void onCreate(Bundle savedInstance) {
+        super.onCreate(savedInstance);
+        LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent);
+        layout.setFitsSystemWindows(false);
+    }
+
     public static class SetupRedactionInterstitialFragment extends RedactionInterstitialFragment
             implements NavigationBar.NavigationBarListener {
 
diff --git a/src/com/android/settings/UserCredentialsSettings.java b/src/com/android/settings/UserCredentialsSettings.java
index 96ef8e9..6438764 100644
--- a/src/com/android/settings/UserCredentialsSettings.java
+++ b/src/com/android/settings/UserCredentialsSettings.java
@@ -27,6 +27,8 @@
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.os.RemoteException;
+import android.os.UserHandle;
+import android.os.UserManager;
 import android.security.Credentials;
 import android.security.IKeyChainService;
 import android.security.KeyChain;
@@ -43,6 +45,8 @@
 import android.widget.TextView;
 
 import com.android.internal.logging.MetricsProto.MetricsEvent;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
 
 import java.util.EnumSet;
 import java.util.SortedMap;
@@ -116,19 +120,34 @@
                     new Credential[] {item}).getView(0, null, null);
             infoContainer.addView(view);
 
-            return new AlertDialog.Builder(getActivity())
+            UserManager userManager
+                    = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
+
+            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
                     .setView(root)
                     .setTitle(R.string.user_credential_title)
-                    .setPositiveButton(R.string.done, null)
-                    .setNegativeButton(R.string.trusted_credentials_remove_label,
-                            new DialogInterface.OnClickListener() {
-                                @Override public void onClick(DialogInterface dialog, int id) {
-                                    new RemoveCredentialsTask(getContext(), getTargetFragment())
-                                            .execute(item.alias);
-                                    dialog.dismiss();
-                                }
-                            })
-                    .create();
+                    .setPositiveButton(R.string.done, null);
+
+            final String restriction = UserManager.DISALLOW_CONFIG_CREDENTIALS;
+            final int myUserId = UserHandle.myUserId();
+            if (!RestrictedLockUtils.hasBaseUserRestriction(getContext(), restriction, myUserId)) {
+                DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
+                    @Override public void onClick(DialogInterface dialog, int id) {
+                        final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(
+                                getContext(), restriction, myUserId);
+                        if (admin != null) {
+                            RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(),
+                                    admin);
+                        } else {
+                            new RemoveCredentialsTask(getContext(), getTargetFragment())
+                                    .execute(item.alias);
+                        }
+                        dialog.dismiss();
+                    }
+                };
+                builder.setNegativeButton(R.string.trusted_credentials_remove_label, listener);
+            }
+            return builder.create();
         }
 
         private class RemoveCredentialsTask extends AsyncTask<String, Void, Void> {
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 60973e1..84bb2dd 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -63,6 +63,7 @@
 import android.provider.ContactsContract.Data;
 import android.provider.ContactsContract.Profile;
 import android.provider.ContactsContract.RawContacts;
+import android.provider.Settings;
 import android.service.persistentdata.PersistentDataBlockManager;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceGroup;
@@ -1100,5 +1101,10 @@
             }
         }
     }
+
+    public static boolean isDeviceProvisioned(Context context) {
+        return Settings.Global.getInt(context.getContentResolver(),
+                Settings.Global.DEVICE_PROVISIONED, 0) != 0;
+    }
 }
 
diff --git a/src/com/android/settings/WifiCallingSettings.java b/src/com/android/settings/WifiCallingSettings.java
index da83cad..3602295 100644
--- a/src/com/android/settings/WifiCallingSettings.java
+++ b/src/com/android/settings/WifiCallingSettings.java
@@ -168,12 +168,20 @@
 
         CarrierConfigManager configManager = (CarrierConfigManager)
                 getSystemService(Context.CARRIER_CONFIG_SERVICE);
+        boolean isWifiOnlySupported = true;
         if (configManager != null) {
             PersistableBundle b = configManager.getConfig();
             if (b != null) {
                 mEditableWfcMode = b.getBoolean(CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL);
+                isWifiOnlySupported = b.getBoolean(
+                        CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, true);
             }
         }
+
+        if (!isWifiOnlySupported) {
+            mButtonWfcMode.setEntries(R.array.wifi_calling_mode_choices_without_wifi_only);
+            mButtonWfcMode.setEntryValues(R.array.wifi_calling_mode_values_without_wifi_only);
+        }
     }
 
     @Override
diff --git a/src/com/android/settings/applications/AppStateNotificationBridge.java b/src/com/android/settings/applications/AppStateNotificationBridge.java
index e8db2aa..b936351 100644
--- a/src/com/android/settings/applications/AppStateNotificationBridge.java
+++ b/src/com/android/settings/applications/AppStateNotificationBridge.java
@@ -70,6 +70,9 @@
 
         @Override
         public boolean filterApp(AppEntry info) {
+            if (info == null || info.extraInfo == null) {
+                return false;
+            }
             if (info.extraInfo instanceof AppRow) {
                 AppRow row = (AppRow) info.extraInfo;
                 return row.banned;
@@ -85,7 +88,7 @@
 
         @Override
         public boolean filterApp(AppEntry info) {
-            if (info == null) {
+            if (info == null || info.extraInfo == null) {
                 return false;
             }
             AppRow row = (AppRow) info.extraInfo;
@@ -101,7 +104,10 @@
 
         @Override
         public boolean filterApp(AppEntry info) {
-            return info.extraInfo != null && ((AppRow) info.extraInfo).appBypassDnd;
+            if (info == null || info.extraInfo == null) {
+                return false;
+            }
+            return ((AppRow) info.extraInfo).appBypassDnd;
         }
     };
 
@@ -112,7 +118,10 @@
 
         @Override
         public boolean filterApp(AppEntry info) {
-            return info.extraInfo != null && ((AppRow) info.extraInfo).lockScreenSecure
+            if (info == null || info.extraInfo == null) {
+                return false;
+            }
+            return ((AppRow) info.extraInfo).lockScreenSecure
                     && ((AppRow) info.extraInfo).appVisOverride == Notification.VISIBILITY_PRIVATE;
         }
     };
@@ -124,7 +133,10 @@
 
         @Override
         public boolean filterApp(AppEntry info) {
-            return info.extraInfo != null && ((AppRow) info.extraInfo).lockScreenSecure
+            if (info == null || info.extraInfo == null) {
+                return false;
+            }
+            return ((AppRow) info.extraInfo).lockScreenSecure
                     && ((AppRow) info.extraInfo).appVisOverride == Notification.VISIBILITY_SECRET;
         }
     };
diff --git a/src/com/android/settings/dashboard/SuggestionsChecks.java b/src/com/android/settings/dashboard/SuggestionsChecks.java
index 3ea815c..a206122 100644
--- a/src/com/android/settings/dashboard/SuggestionsChecks.java
+++ b/src/com/android/settings/dashboard/SuggestionsChecks.java
@@ -100,7 +100,7 @@
         IBinder b = ServiceManager.getService(Context.WALLPAPER_SERVICE);
         IWallpaperManager service = Stub.asInterface(b);
         try {
-            return service.getWallpaper(mCallback, WallpaperManager.FLAG_SET_SYSTEM,
+            return service.getWallpaper(mCallback, WallpaperManager.FLAG_SYSTEM,
                     new Bundle(), mContext.getUserId()) != null;
         } catch (RemoteException e) {
         }
diff --git a/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java b/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java
index b666318..03e97ff 100644
--- a/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java
+++ b/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java
@@ -121,8 +121,6 @@
     @Override
     public void onPause() {
         super.onPause();
-        // Clear all subtypes of all IMEs to make sure
-        updateImplicitlyEnabledSubtypes(null /* targetImiId */, false /* check */);
         InputMethodAndSubtypeUtil.saveInputMethodSubtypeList(this, getContentResolver(),
                 mInputMethodInfoList, mHaveHardKeyboard);
     }
diff --git a/src/com/android/settings/inputmethod/InputMethodAndSubtypeUtil.java b/src/com/android/settings/inputmethod/InputMethodAndSubtypeUtil.java
index dfa1634..b79f44d 100644
--- a/src/com/android/settings/inputmethod/InputMethodAndSubtypeUtil.java
+++ b/src/com/android/settings/inputmethod/InputMethodAndSubtypeUtil.java
@@ -209,7 +209,12 @@
                         needsToResetSelectedSubtype = true;
                         subtypePrefFound = true;
                     }
-                    if (subtypePref.isChecked()) {
+                    // Checking <code>subtypePref.isEnabled()</code> is insufficient to determine
+                    // whether the user manually enabled this subtype or not.  Implicitly-enabled
+                    // subtypes are also checked just as an indicator to users.  We also need to
+                    // check <code>subtypePref.isEnabled()</code> so that only manually enabled
+                    // subtypes can be saved here.
+                    if (subtypePref.isEnabled() && subtypePref.isChecked()) {
                         subtypesSet.add(subtypeHashCodeStr);
                         if (isCurrentInputMethod) {
                             if (selectedInputMethodSubtype == subtype.hashCode()) {
diff --git a/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java b/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java
index 80870b4..7f590a1 100644
--- a/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java
+++ b/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java
@@ -16,6 +16,8 @@
 
 package com.android.settings.inputmethod;
 
+import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.app.Activity;
 import android.app.LoaderManager;
 import android.content.AsyncTaskLoader;
@@ -33,11 +35,13 @@
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.Preference.OnPreferenceChangeListener;
 import android.support.v7.preference.PreferenceCategory;
-import android.util.Pair;
+import android.support.v7.preference.PreferenceScreen;
+import android.text.TextUtils;
 import android.view.InputDevice;
 import android.view.inputmethod.InputMethodInfo;
 import android.view.inputmethod.InputMethodManager;
 import android.view.inputmethod.InputMethodSubtype;
+
 import com.android.internal.inputmethod.InputMethodUtils;
 import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.android.internal.util.Preconditions;
@@ -45,27 +49,33 @@
 import com.android.settings.Settings;
 import com.android.settings.SettingsPreferenceFragment;
 
+import libcore.util.Objects;
+
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.HashSet;
 
 public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
-        implements LoaderManager.LoaderCallbacks<PhysicalKeyboardFragment.Keyboards>,
-        InputManager.InputDeviceListener {
+        implements InputManager.InputDeviceListener {
 
     private static final int USER_SYSTEM = 0;
     private static final String KEYBOARD_ASSISTANCE_CATEGORY = "keyboard_assistance_category";
     private static final String SHOW_VIRTUAL_KEYBOARD_SWITCH = "show_virtual_keyboard_switch";
     private static final String IM_SUBTYPE_MODE_KEYBOARD = "keyboard";
 
-    private final HashMap<Integer, Pair<InputDeviceIdentifier, PreferenceCategory>> mLoaderReference
-            = new HashMap<>();
-    private final Map<InputMethodInfo, List<InputMethodSubtype>> mImiSubtypes = new HashMap<>();
+    @NonNull
+    private final ArrayList<HardKeyboardDeviceInfo> mLastHardKeyboards = new ArrayList<>();
+
+    @NonNull
+    private final HashSet<Integer> mLoaderIDs = new HashSet<>();
+    private int mNextLoaderId = 0;
+
     private InputManager mIm;
-    private InputMethodManager mImm;
+    @NonNull
     private PreferenceCategory mKeyboardAssistanceCategory;
+    @NonNull
     private SwitchPreference mShowVirtualKeyboardSwitch;
+    @NonNull
     private InputMethodUtils.InputMethodSettings mSettings;
 
     @Override
@@ -73,12 +83,11 @@
         Activity activity = Preconditions.checkNotNull(getActivity());
         addPreferencesFromResource(R.xml.physical_keyboard_settings);
         mIm = Preconditions.checkNotNull(activity.getSystemService(InputManager.class));
-        mImm = Preconditions.checkNotNull(activity.getSystemService(InputMethodManager.class));
         mSettings = new InputMethodUtils.InputMethodSettings(
                 activity.getResources(),
                 getContentResolver(),
-                new HashMap<String, InputMethodInfo>(),
-                new ArrayList<InputMethodInfo>(),
+                new HashMap<>(),
+                new ArrayList<>(),
                 USER_SYSTEM,
                 false /* copyOnWrite */);
         mKeyboardAssistanceCategory = Preconditions.checkNotNull(
@@ -91,6 +100,8 @@
     @Override
     public void onResume() {
         super.onResume();
+        clearLoader();
+        mLastHardKeyboards.clear();
         updateHardKeyboards();
         mIm.registerInputDeviceListener(this, null);
         mShowVirtualKeyboardSwitch.setOnPreferenceChangeListener(
@@ -101,26 +112,23 @@
     @Override
     public void onPause() {
         super.onPause();
-        clearHardKeyboardsData();
+        clearLoader();
+        mLastHardKeyboards.clear();
         mIm.unregisterInputDeviceListener(this);
         mShowVirtualKeyboardSwitch.setOnPreferenceChangeListener(null);
         unregisterShowVirtualKeyboardSettingsObserver();
     }
 
-    @Override
-    public Loader<Keyboards> onCreateLoader(int id, Bundle args) {
-        final InputDeviceIdentifier deviceId = mLoaderReference.get(id).first;
-        return new KeyboardLayoutLoader(
-                getActivity().getBaseContext(), mIm, mImiSubtypes, deviceId);
-    }
+    public void onLoadFinishedInternal(final int loaderId, @NonNull final Keyboards data,
+            @NonNull final PreferenceCategory preferenceCategory) {
+        if (!mLoaderIDs.remove(loaderId)) {
+            // Already destroyed loader.  Ignore.
+            return;
+        }
 
-    @Override
-    public void onLoadFinished(Loader<Keyboards> loader, Keyboards data) {
-        // TODO: Investigate why this is being called twice.
-        final InputDeviceIdentifier deviceId = mLoaderReference.get(loader.getId()).first;
-        final PreferenceCategory category = mLoaderReference.get(loader.getId()).second;
-        category.removeAll();
-        for (Keyboards.KeyboardInfo info : data.mInfos) {
+        final InputDeviceIdentifier deviceId = data.mInputDeviceIdentifier;
+        preferenceCategory.removeAll();
+        for (Keyboards.KeyboardInfo info : data.mKeyboardInfoList) {
             Preference pref = new Preference(getPrefContext(), null);
             final InputMethodInfo imi = info.mImi;
             final InputMethodSubtype imSubtype = info.mImSubtype;
@@ -130,22 +138,16 @@
                 if (layout != null) {
                     pref.setSummary(layout.getLabel());
                 }
-                pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
-                    @Override
-                    public boolean onPreferenceClick(Preference preference) {
-                        showKeyboardLayoutScreen(deviceId, imi, imSubtype);
-                        return true;
-                    }
+                pref.setOnPreferenceClickListener(preference -> {
+                    showKeyboardLayoutScreen(deviceId, imi, imSubtype);
+                    return true;
                 });
-                category.addPreference(pref);
+                preferenceCategory.addPreference(pref);
             }
         }
     }
 
     @Override
-    public void onLoaderReset(Loader<Keyboards> loader) {}
-
-    @Override
     public void onInputDeviceAdded(int deviceId) {
         updateHardKeyboards();
     }
@@ -165,27 +167,42 @@
         return MetricsEvent.PHYSICAL_KEYBOARDS;
     }
 
-    private void updateHardKeyboards() {
-        clearHardKeyboardsData();
-        loadInputMethodInfoSubtypes();
-        final int[] devices = InputDevice.getDeviceIds();
-        for (int deviceIndex = 0; deviceIndex < devices.length; deviceIndex++) {
-            InputDevice device = InputDevice.getDevice(devices[deviceIndex]);
-            if (device != null
-                    && !device.isVirtual()
-                    && device.isFullKeyboard()) {
-                final PreferenceCategory category = new PreferenceCategory(getPrefContext(), null);
-                category.setTitle(device.getName());
-                category.setOrder(0);
-                mLoaderReference.put(deviceIndex, new Pair(device.getIdentifier(), category));
-                getPreferenceScreen().addPreference(category);
+    @NonNull
+    private static ArrayList<HardKeyboardDeviceInfo> getHardKeyboards() {
+        final ArrayList<HardKeyboardDeviceInfo> keyboards = new ArrayList<>();
+        final int[] devicesIds = InputDevice.getDeviceIds();
+        for (int deviceId : devicesIds) {
+            final InputDevice device = InputDevice.getDevice(deviceId);
+            if (device != null && !device.isVirtual() && device.isFullKeyboard()) {
+                keyboards.add(new HardKeyboardDeviceInfo(device.getName(), device.getIdentifier()));
             }
         }
-        mKeyboardAssistanceCategory.setOrder(1);
-        getPreferenceScreen().addPreference(mKeyboardAssistanceCategory);
+        return keyboards;
+    }
 
-        for (int deviceIndex : mLoaderReference.keySet()) {
-            getLoaderManager().initLoader(deviceIndex, null, this);
+    private void updateHardKeyboards() {
+        final ArrayList<HardKeyboardDeviceInfo> newHardKeyboards = getHardKeyboards();
+        if (!Objects.equal(newHardKeyboards, mLastHardKeyboards)) {
+            clearLoader();
+            final PreferenceScreen preferenceScreen = getPreferenceScreen();
+            preferenceScreen.removeAll();
+            mLastHardKeyboards.clear();
+            mLastHardKeyboards.addAll(newHardKeyboards);
+            final int N = newHardKeyboards.size();
+            for (int i = 0; i < N; ++i) {
+                final HardKeyboardDeviceInfo deviceInfo = newHardKeyboards.get(i);
+                final PreferenceCategory category = new PreferenceCategory(getPrefContext(), null);
+                category.setTitle(deviceInfo.mDeviceName);
+                category.setOrder(0);
+                getLoaderManager().initLoader(mNextLoaderId, null,
+                        new Callbacks(getContext(), this, deviceInfo.mDeviceIdentifier, category));
+                mLoaderIDs.add(mNextLoaderId);
+                ++mNextLoaderId;
+                preferenceScreen.addPreference(category);
+            }
+            mKeyboardAssistanceCategory.setOrder(1);
+            preferenceScreen.addPreference(mKeyboardAssistanceCategory);
+
         }
         updateShowVirtualKeyboardSwitch();
     }
@@ -203,27 +220,11 @@
         startActivity(intent);
     }
 
-    private void clearHardKeyboardsData() {
-        getPreferenceScreen().removeAll();
-        for (int index = 0; index < mLoaderReference.size(); index++) {
-            getLoaderManager().destroyLoader(index);
+    private void clearLoader() {
+        for (final int loaderId : mLoaderIDs) {
+            getLoaderManager().destroyLoader(loaderId);
         }
-        mLoaderReference.clear();
-    }
-
-    private void loadInputMethodInfoSubtypes() {
-        mImiSubtypes.clear();
-        final List<InputMethodInfo> imis = mImm.getEnabledInputMethodList();
-        for (InputMethodInfo imi : imis) {
-            final List<InputMethodSubtype> subtypes = new ArrayList<>();
-            for (InputMethodSubtype subtype : mImm.getEnabledInputMethodSubtypeList(
-                    imi, true /* allowsImplicitlySelectedSubtypes */)) {
-                if (IM_SUBTYPE_MODE_KEYBOARD.equalsIgnoreCase(subtype.getMode())) {
-                    subtypes.add(subtype);
-                }
-            }
-            mImiSubtypes.put(imi, subtypes);
-        }
+        mLoaderIDs.clear();
     }
 
     private void registerShowVirtualKeyboardSettingsObserver() {
@@ -260,44 +261,84 @@
         }
     };
 
+    @NonNull
     static String getDisplayName(
-            Context context, InputMethodInfo imi, InputMethodSubtype imSubtype) {
-        CharSequence imSubtypeName =  imSubtype.getDisplayName(
-                context, imi.getPackageName(),
-                imi.getServiceInfo().applicationInfo);
-        CharSequence imeName = imi.loadLabel(context.getPackageManager());
+            @NonNull Context context, @NonNull InputMethodInfo imi,
+            @NonNull InputMethodSubtype imSubtype) {
+        final CharSequence imSubtypeName = imSubtype.getDisplayName(
+                context, imi.getPackageName(), imi.getServiceInfo().applicationInfo);
+        final CharSequence imeName = imi.loadLabel(context.getPackageManager());
         return String.format(
                 context.getString(R.string.physical_device_title), imSubtypeName, imeName);
     }
 
-    private static final class KeyboardLayoutLoader extends AsyncTaskLoader<Keyboards> {
+    private static final class Callbacks
+            implements LoaderManager.LoaderCallbacks<PhysicalKeyboardFragment.Keyboards> {
+        @NonNull
+        final Context mContext;
+        @NonNull
+        final PhysicalKeyboardFragment mPhysicalKeyboardFragment;
+        @NonNull
+        final InputDeviceIdentifier mInputDeviceIdentifier;
+        @NonNull
+        final PreferenceCategory mPreferenceCategory;
+        public Callbacks(
+                @NonNull Context context,
+                @NonNull PhysicalKeyboardFragment physicalKeyboardFragment,
+                @NonNull InputDeviceIdentifier inputDeviceIdentifier,
+                @NonNull PreferenceCategory preferenceCategory) {
+            mContext = context;
+            mPhysicalKeyboardFragment = physicalKeyboardFragment;
+            mInputDeviceIdentifier = inputDeviceIdentifier;
+            mPreferenceCategory = preferenceCategory;
+        }
 
-        private final Map<InputMethodInfo, List<InputMethodSubtype>> mImiSubtypes;
+        @Override
+        public Loader<Keyboards> onCreateLoader(int id, Bundle args) {
+            return new KeyboardLayoutLoader(mContext, mInputDeviceIdentifier);
+        }
+
+        @Override
+        public void onLoadFinished(Loader<Keyboards> loader, Keyboards data) {
+            mPhysicalKeyboardFragment.onLoadFinishedInternal(loader.getId(), data,
+                    mPreferenceCategory);
+        }
+
+        @Override
+        public void onLoaderReset(Loader<Keyboards> loader) {
+        }
+    }
+
+    private static final class KeyboardLayoutLoader extends AsyncTaskLoader<Keyboards> {
+        @NonNull
         private final InputDeviceIdentifier mInputDeviceIdentifier;
-        private final InputManager mIm;
 
         public KeyboardLayoutLoader(
-                Context context,
-                InputManager im,
-                Map<InputMethodInfo, List<InputMethodSubtype>> imiSubtypes,
-                InputDeviceIdentifier inputDeviceIdentifier) {
+                @NonNull Context context,
+                @NonNull InputDeviceIdentifier inputDeviceIdentifier) {
             super(context);
-            mIm = Preconditions.checkNotNull(im);
             mInputDeviceIdentifier = Preconditions.checkNotNull(inputDeviceIdentifier);
-            mImiSubtypes = new HashMap<>(imiSubtypes);
         }
 
         @Override
         public Keyboards loadInBackground() {
-            final Keyboards keyboards = new Keyboards();
-            for (InputMethodInfo imi : mImiSubtypes.keySet()) {
-                for (InputMethodSubtype subtype : mImiSubtypes.get(imi)) {
-                    final KeyboardLayout layout = mIm.getKeyboardLayoutForInputDevice(
-                            mInputDeviceIdentifier, imi, subtype);
-                    keyboards.mInfos.add(new Keyboards.KeyboardInfo(imi, subtype, layout));
+            final ArrayList<Keyboards.KeyboardInfo> keyboardInfoList = new ArrayList<>();
+            final InputMethodManager imm = getContext().getSystemService(InputMethodManager.class);
+            final InputManager im = getContext().getSystemService(InputManager.class);
+            if (imm != null && im != null) {
+                for (InputMethodInfo imi : imm.getEnabledInputMethodList()) {
+                    for (InputMethodSubtype subtype : imm.getEnabledInputMethodSubtypeList(
+                            imi, true /* allowsImplicitlySelectedSubtypes */)) {
+                        if (!IM_SUBTYPE_MODE_KEYBOARD.equalsIgnoreCase(subtype.getMode())) {
+                            continue;
+                        }
+                        final KeyboardLayout layout = im.getKeyboardLayoutForInputDevice(
+                                mInputDeviceIdentifier, imi, subtype);
+                        keyboardInfoList.add(new Keyboards.KeyboardInfo(imi, subtype, layout));
+                    }
                 }
             }
-            return keyboards;
+            return new Keyboards(mInputDeviceIdentifier, keyboardInfoList);
         }
 
         @Override
@@ -313,18 +354,70 @@
         }
     }
 
-    public static final class Keyboards {
+    public static final class HardKeyboardDeviceInfo {
+        @NonNull
+        public final String mDeviceName;
+        @NonNull
+        public final InputDeviceIdentifier mDeviceIdentifier;
 
-        public final ArrayList<KeyboardInfo> mInfos = new ArrayList<>();
+        public HardKeyboardDeviceInfo(
+                @Nullable final String deviceName,
+                @NonNull final InputDeviceIdentifier deviceIdentifier) {
+            mDeviceName = deviceName != null ? deviceName : "";
+            mDeviceIdentifier = deviceIdentifier;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (o == this) return true;
+            if (o == null) return false;
+
+            if (!(o instanceof HardKeyboardDeviceInfo)) return false;
+
+            final HardKeyboardDeviceInfo that = (HardKeyboardDeviceInfo) o;
+            if (!TextUtils.equals(mDeviceName, that.mDeviceName)) {
+                return false;
+            }
+            if (mDeviceIdentifier.getVendorId() != that.mDeviceIdentifier.getVendorId()) {
+                return false;
+            }
+            if (mDeviceIdentifier.getProductId() != that.mDeviceIdentifier.getProductId()) {
+                return false;
+            }
+            if (!TextUtils.equals(mDeviceIdentifier.getDescriptor(),
+                    that.mDeviceIdentifier.getDescriptor())) {
+                return false;
+            }
+
+            return true;
+        }
+    }
+
+    public static final class Keyboards {
+        @NonNull
+        public final InputDeviceIdentifier mInputDeviceIdentifier;
+        @NonNull
+        public final ArrayList<KeyboardInfo> mKeyboardInfoList;
+
+        public Keyboards(
+                @NonNull final InputDeviceIdentifier inputDeviceIdentifier,
+                @NonNull final ArrayList<KeyboardInfo> keyboardInfoList) {
+            mInputDeviceIdentifier = inputDeviceIdentifier;
+            mKeyboardInfoList = keyboardInfoList;
+        }
 
         public static final class KeyboardInfo {
-
+            @NonNull
             public final InputMethodInfo mImi;
+            @NonNull
             public final InputMethodSubtype mImSubtype;
+            @NonNull
             public final KeyboardLayout mLayout;
 
             public KeyboardInfo(
-                    InputMethodInfo imi, InputMethodSubtype imSubtype, KeyboardLayout layout) {
+                    @NonNull final InputMethodInfo imi,
+                    @NonNull final InputMethodSubtype imSubtype,
+                    @NonNull final KeyboardLayout layout) {
                 mImi = imi;
                 mImSubtype = imSubtype;
                 mLayout = layout;
diff --git a/src/com/android/settings/notification/ZenModePrioritySettings.java b/src/com/android/settings/notification/ZenModePrioritySettings.java
index 61bf7fc..a61be96 100644
--- a/src/com/android/settings/notification/ZenModePrioritySettings.java
+++ b/src/com/android/settings/notification/ZenModePrioritySettings.java
@@ -175,7 +175,7 @@
         mEvents.setChecked(isPriorityCategoryEnabled(Policy.PRIORITY_CATEGORY_EVENTS));
         mRepeatCallers.setChecked(
                 isPriorityCategoryEnabled(Policy.PRIORITY_CATEGORY_REPEAT_CALLERS));
-        mRepeatCallers.setEnabled(!isPriorityCategoryEnabled(Policy.PRIORITY_CATEGORY_CALLS)
+        mRepeatCallers.setVisible(!isPriorityCategoryEnabled(Policy.PRIORITY_CATEGORY_CALLS)
                 || mPolicy.priorityCallSenders != Policy.PRIORITY_SENDERS_ANY);
         mDisableListeners = false;
     }
diff --git a/src/com/android/settings/sim/SimSelectNotification.java b/src/com/android/settings/sim/SimSelectNotification.java
index 29da205..67e423b 100644
--- a/src/com/android/settings/sim/SimSelectNotification.java
+++ b/src/com/android/settings/sim/SimSelectNotification.java
@@ -32,6 +32,7 @@
 import com.android.internal.telephony.IccCardConstants;
 import com.android.settings.R;
 import com.android.settings.Settings.SimSettingsActivity;
+import com.android.settings.Utils;
 
 import java.util.List;
 
@@ -45,11 +46,9 @@
                 context.getSystemService(Context.TELEPHONY_SERVICE);
         final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
         final int numSlots = telephonyManager.getSimCount();
-        final boolean isInProvisioning = Settings.Global.getInt(context.getContentResolver(),
-                Settings.Global.DEVICE_PROVISIONED, 0) == 0;
 
-        // Do not create notifications on single SIM devices or when provisiong i.e. Setup Wizard.
-        if (numSlots < 2 || isInProvisioning) {
+        // Do not create notifications on single SIM devices or when provisioning i.e. Setup Wizard.
+        if (numSlots < 2 || !Utils.isDeviceProvisioned(context)) {
             return;
         }
 
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index e47a36e..eb74c4b 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -224,7 +224,7 @@
         }
         mAddUser = (DimmableIconPreference) findPreference(KEY_ADD_USER);
         // Determine if add user/profile button should be visible
-        if (mUserCaps.mCanAddUser) {
+        if (mUserCaps.mCanAddUser && Utils.isDeviceProvisioned(getActivity())) {
             mAddUser.setOnPreferenceClickListener(this);
             // change label to only mention user, if restricted profiles are not supported
             if (!mUserCaps.mCanAddRestrictedProfile) {
@@ -829,7 +829,8 @@
         }
 
         // Append Add user to the end of the list
-        if (mUserCaps.mCanAddUser || mUserCaps.mDisallowAddUserSetByAdmin) {
+        if ((mUserCaps.mCanAddUser || mUserCaps.mDisallowAddUserSetByAdmin) &&
+                Utils.isDeviceProvisioned(getActivity())) {
             boolean moreUsers = mUserManager.canAddMoreUsers();
             mAddUser.setOrder(Preference.DEFAULT_ORDER);
             preferenceScreen.addPreference(mAddUser);