Merge "Fix battery detail issues with "Android OS"" into mnc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 3b99168..1fef233 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2548,6 +2548,8 @@
                 <action android:name="android.settings.action.MANAGE_WRITE_SETTINGS" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
+            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+                android:value="com.android.settings.applications.ManageApplications" />
         </activity>
 
     </application>
diff --git a/res/drawable-hdpi/setup_illustration_lock_screen.jpg b/res/drawable-hdpi/setup_illustration_lock_screen.jpg
index 0bf53fc..263d33e 100644
--- a/res/drawable-hdpi/setup_illustration_lock_screen.jpg
+++ b/res/drawable-hdpi/setup_illustration_lock_screen.jpg
Binary files differ
diff --git a/res/drawable-mdpi/setup_illustration_lock_screen.jpg b/res/drawable-mdpi/setup_illustration_lock_screen.jpg
index 9ab9117..004fa9e 100644
--- a/res/drawable-mdpi/setup_illustration_lock_screen.jpg
+++ b/res/drawable-mdpi/setup_illustration_lock_screen.jpg
Binary files differ
diff --git a/res/drawable-sw600dp-hdpi/setup_illustration_lock_screen.jpg b/res/drawable-sw600dp-hdpi/setup_illustration_lock_screen.jpg
index 26cff1d..933e986 100644
--- a/res/drawable-sw600dp-hdpi/setup_illustration_lock_screen.jpg
+++ b/res/drawable-sw600dp-hdpi/setup_illustration_lock_screen.jpg
Binary files differ
diff --git a/res/drawable-sw600dp-mdpi/setup_illustration_lock_screen.jpg b/res/drawable-sw600dp-mdpi/setup_illustration_lock_screen.jpg
index 386fc8d..57e0385 100644
--- a/res/drawable-sw600dp-mdpi/setup_illustration_lock_screen.jpg
+++ b/res/drawable-sw600dp-mdpi/setup_illustration_lock_screen.jpg
Binary files differ
diff --git a/res/drawable-sw600dp-xhdpi/setup_illustration_lock_screen.jpg b/res/drawable-sw600dp-xhdpi/setup_illustration_lock_screen.jpg
index 54362e7..e329a96 100644
--- a/res/drawable-sw600dp-xhdpi/setup_illustration_lock_screen.jpg
+++ b/res/drawable-sw600dp-xhdpi/setup_illustration_lock_screen.jpg
Binary files differ
diff --git a/res/drawable-sw600dp-xxhdpi/setup_illustration_lock_screen.jpg b/res/drawable-sw600dp-xxhdpi/setup_illustration_lock_screen.jpg
index 4f62b84..7934e8a 100644
--- a/res/drawable-sw600dp-xxhdpi/setup_illustration_lock_screen.jpg
+++ b/res/drawable-sw600dp-xxhdpi/setup_illustration_lock_screen.jpg
Binary files differ
diff --git a/res/drawable-sw600dp-xxxhdpi/setup_illustration_lock_screen.jpg b/res/drawable-sw600dp-xxxhdpi/setup_illustration_lock_screen.jpg
index 2c6b57e..ab61328 100644
--- a/res/drawable-sw600dp-xxxhdpi/setup_illustration_lock_screen.jpg
+++ b/res/drawable-sw600dp-xxxhdpi/setup_illustration_lock_screen.jpg
Binary files differ
diff --git a/res/drawable-xhdpi/setup_illustration_lock_screen.jpg b/res/drawable-xhdpi/setup_illustration_lock_screen.jpg
index ddad6d5..b78a59d 100644
--- a/res/drawable-xhdpi/setup_illustration_lock_screen.jpg
+++ b/res/drawable-xhdpi/setup_illustration_lock_screen.jpg
Binary files differ
diff --git a/res/drawable-xxhdpi/setup_illustration_lock_screen.jpg b/res/drawable-xxhdpi/setup_illustration_lock_screen.jpg
index 5b0a7a7..875e55e 100644
--- a/res/drawable-xxhdpi/setup_illustration_lock_screen.jpg
+++ b/res/drawable-xxhdpi/setup_illustration_lock_screen.jpg
Binary files differ
diff --git a/res/drawable-xxxhdpi/setup_illustration_lock_screen.jpg b/res/drawable-xxxhdpi/setup_illustration_lock_screen.jpg
index 5be34fd..8ac85a4 100644
--- a/res/drawable-xxxhdpi/setup_illustration_lock_screen.jpg
+++ b/res/drawable-xxxhdpi/setup_illustration_lock_screen.jpg
Binary files differ
diff --git a/res/layout/setup_encryption_interstitial.xml b/res/layout/setup_encryption_interstitial.xml
new file mode 100644
index 0000000..8a36e30
--- /dev/null
+++ b/res/layout/setup_encryption_interstitial.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2015 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
+-->
+
+<com.android.setupwizardlib.SetupWizardLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:settings="http://schemas.android.com/apk/res-auto"
+    android:id="@+id/setup_wizard_layout"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    settings:suwBackgroundTile="@drawable/setup_illustration_tile"
+    settings:suwHeaderText="@string/encryption_interstitial_header"
+    settings:suwIllustrationHorizontalTile="@drawable/setup_illustration_horizontal_tile"
+    settings:suwIllustrationImage="@drawable/setup_illustration_lock_screen">
+
+    <LinearLayout
+        style="@style/SuwContentFrame"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:orientation="vertical">
+
+        <TextView
+            android:id="@+id/encryption_message"
+            style="@style/SuwDescription"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content" />
+
+        <RadioGroup
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="16dp"
+            android:checkedButton="@+id/encrypt_require_password">
+
+            <RadioButton
+                android:id="@+id/encrypt_require_password"
+                style="@style/SuwRadioButton"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content" />
+
+            <RadioButton
+                android:id="@+id/encrypt_dont_require_password"
+                style="@style/SuwRadioButton"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content" />
+
+        </RadioGroup>
+
+    </LinearLayout>
+
+</com.android.setupwizardlib.SetupWizardLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 72af8b9..b8a3401 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6868,7 +6868,7 @@
     <string name="accessibility_lock_screen_progress"><xliff:g id="count" example="1">%1$d</xliff:g> of <xliff:g id="count" example="1">%2$d</xliff:g> characters used</string>
 
     <!-- System Alert Window settings -->
-    <!-- Title of Draw Overlay preference item [CHAR LIMIT=45] -->
+    <!-- Title of Draw Overlay preference item [CHAR LIMIT=55] -->
     <string name="draw_overlay_title">Apps that can draw over other apps</string>
     <!-- Title of draw overlay screen [CHAR LIMIT=30] -->
     <string name="draw_overlay">Draw over other apps</string>
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index 14c829a..01f3ba5 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -60,11 +60,6 @@
         android:summary="@string/runningservices_settings_summary"
         android:fragment="com.android.settings.applications.RunningServices" />
 
-    <SwitchPreference
-        android:key="tuner_ui"
-        android:persistent="false"
-        android:title="@string/system_ui_settings" />
-
     <PreferenceCategory android:key="debug_debugging_category"
             android:title="@string/debug_debugging_category">
 
diff --git a/src/com/android/settings/ApnEditor.java b/src/com/android/settings/ApnEditor.java
index 7142fb6..8299c67 100644
--- a/src/com/android/settings/ApnEditor.java
+++ b/src/com/android/settings/ApnEditor.java
@@ -758,7 +758,7 @@
         if (pref != null) {
             if (pref.equals(mPassword)){
                 pref.setSummary(starify(sharedPreferences.getString(key, "")));
-            } else if (pref.equals(mCarrierEnabled)) {
+            } else if (pref.equals(mCarrierEnabled) || pref.equals(mBearerMulti)) {
                 // do nothing
             } else {
                 pref.setSummary(checkNull(sharedPreferences.getString(key, "")));
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index f20728a..4a4c51d 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -101,9 +101,6 @@
      */
     public static final String PREF_SHOW = "show";
 
-    private static final ComponentName SYSUI_TUNER = new ComponentName("com.android.systemui",
-            "com.android.systemui.tuner.TunerActivity");
-
     private static final String ENABLE_ADB = "enable_adb";
     private static final String CLEAR_ADB_KEYS = "clear_adb_keys";
     private static final String ENABLE_TERMINAL = "enable_terminal";
@@ -270,8 +267,6 @@
     private Dialog mAdbKeysDialog;
     private boolean mUnavailable;
 
-    private SwitchPreference mTunerUiPref;
-
     @Override
     protected int getMetricsCategory() {
         return MetricsLogger.DEVELOPMENT;
@@ -407,8 +402,6 @@
         mAllPrefs.add(mShowAllANRs);
         mResetSwitchPrefs.add(mShowAllANRs);
 
-        mTunerUiPref = findAndInitSwitchPref(TUNER_UI_KEY);
-
         Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY);
         if (hdcpChecking != null) {
             mAllPrefs.add(hdcpChecking);
@@ -608,7 +601,6 @@
         updateMobileDataAlwaysOnOptions();
         updateSimulateColorSpace();
         updateUSBAudioOptions();
-        updateTweakUi();
     }
 
     private void resetDangerousOptions() {
@@ -1153,21 +1145,6 @@
         }
     }
 
-    private void updateTweakUi() {
-        updateSwitchPreference(mTunerUiPref, getActivity().getPackageManager()
-                .getComponentEnabledSetting(SYSUI_TUNER)
-                == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
-        mTunerUiPref.setOnPreferenceChangeListener(this);
-    }
-
-    private void writeTweakUi(Object newValue) {
-        Boolean enabled = (Boolean) newValue;
-        getActivity().getPackageManager().setComponentEnabledSetting(SYSUI_TUNER,
-                enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
-                        : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
-                        PackageManager.DONT_KILL_APP);
-    }
-
     private void updateUSBAudioOptions() {
         updateSwitchPreference(mUSBAudio, Settings.Secure.getInt(getContentResolver(),
                 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, 0) != 0);
@@ -1766,9 +1743,6 @@
         } else if (preference == mSimulateColorSpace) {
             writeSimulateColorSpace(newValue);
             return true;
-        } else if (preference == mTunerUiPref) {
-            writeTweakUi(newValue);
-            return true;
         }
         return false;
     }
diff --git a/src/com/android/settings/EncryptionInterstitial.java b/src/com/android/settings/EncryptionInterstitial.java
index 73d8257..1bef99a 100644
--- a/src/com/android/settings/EncryptionInterstitial.java
+++ b/src/com/android/settings/EncryptionInterstitial.java
@@ -87,8 +87,12 @@
         @Override
         public View onCreateView(LayoutInflater inflater, ViewGroup container,
                 Bundle savedInstanceState) {
-            final int layoutId = R.layout.encryption_interstitial;
-            View view = inflater.inflate(layoutId, container, false);
+            return inflater.inflate(R.layout.encryption_interstitial, container, false);
+        }
+
+        @Override
+        public void onViewCreated(View view, Bundle savedInstanceState) {
+            super.onViewCreated(view, savedInstanceState);
             mRequirePasswordToDecryptButton =
                     (RadioButton) view.findViewById(R.id.encrypt_require_password);
             mDontRequirePasswordToDecryptButton =
@@ -135,7 +139,6 @@
 
             setRequirePasswordState(getActivity().getIntent().getBooleanExtra(
                     EXTRA_REQUIRE_PASSWORD, true));
-            return view;
         }
 
         @Override
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index bf091f6..6e679b6 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -791,6 +791,16 @@
                 result.add(data);
             }
 
+            // Fingerprint
+            FingerprintManager fpm =
+                    (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
+            if (fpm.isHardwareDetected()) {
+                data = new SearchIndexableRaw(context);
+                data.title = res.getString(R.string.security_settings_fingerprint_preference_title);
+                data.screenTitle = screenTitle;
+                result.add(data);
+            }
+
             // Credential storage
             final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
 
diff --git a/src/com/android/settings/SetupEncryptionInterstitial.java b/src/com/android/settings/SetupEncryptionInterstitial.java
index 4605ca1..27d7e0c 100644
--- a/src/com/android/settings/SetupEncryptionInterstitial.java
+++ b/src/com/android/settings/SetupEncryptionInterstitial.java
@@ -72,22 +72,24 @@
         @Override
         public View onCreateView(LayoutInflater inflater, ViewGroup container,
                 Bundle savedInstanceState) {
-            final SetupWizardLayout layout = new SetupWizardLayout(inflater.getContext());
-            layout.setIllustration(R.drawable.setup_illustration_lock_screen,
-                    R.drawable.setup_illustration_horizontal_tile);
-            layout.setBackgroundTile(R.drawable.setup_illustration_tile);
-            layout.setHeaderText(R.string.encryption_interstitial_header);
+            return inflater.inflate(R.layout.setup_encryption_interstitial, container, false);
+        }
 
-            View content = super.onCreateView(inflater, layout, savedInstanceState);
-            layout.addView(content);
-            layout.getNavigationBar().setNavigationBarListener(this);
+        @Override
+        public void onViewCreated(View view, Bundle savedInstanceState) {
+            super.onViewCreated(view, savedInstanceState);
+
+            final SetupWizardLayout layout =
+                    (SetupWizardLayout) view.findViewById(R.id.setup_wizard_layout);
+
+            final NavigationBar navigationBar = layout.getNavigationBar();
+            navigationBar.setNavigationBarListener(this);
 
             Activity activity = getActivity();
             if (activity != null) {
                 activity.setTitle(R.string.encryption_interstitial_header);
                 SetupWizardUtils.setImmersiveMode(activity);
             }
-            return layout;
         }
 
         @Override
diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java
index 32d50bf..8cc98cc 100644
--- a/src/com/android/settings/WirelessSettings.java
+++ b/src/com/android/settings/WirelessSettings.java
@@ -237,11 +237,7 @@
         mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
         mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
 
-        if (ImsManager.isWfcEnabledByPlatform(activity)) {
-            mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
-        } else {
-            removePreference(KEY_WFC_SETTINGS);
-        }
+        mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
 
         // Remove NSD checkbox by default
         getPreferenceScreen().removePreference(nsd);
@@ -373,10 +369,15 @@
             mNsdEnabler.resume();
         }
 
+        // update WFC setting
         final Context context = getActivity();
         if (ImsManager.isWfcEnabledByPlatform(context)) {
+            getPreferenceScreen().addPreference(mButtonWfc);
+
             mButtonWfc.setSummary(WifiCallingSettings.getWfcModeSummary(
                     context, ImsManager.getWfcMode(context)));
+        } else {
+            removePreference(KEY_WFC_SETTINGS);
         }
     }
 
diff --git a/src/com/android/settings/applications/AppStateWriteSettingsBridge.java b/src/com/android/settings/applications/AppStateWriteSettingsBridge.java
index 4ab737f..e43b5f5 100644
--- a/src/com/android/settings/applications/AppStateWriteSettingsBridge.java
+++ b/src/com/android/settings/applications/AppStateWriteSettingsBridge.java
@@ -60,15 +60,12 @@
         return super.getNumPackagesAllowedByAppOps();
     }
 
-    public static class WriteSettingsState {
-        PermissionState mPermissionState;
-
+    public static class WriteSettingsState extends AppStateAppOpsBridge.PermissionState {
         public WriteSettingsState(PermissionState permissionState) {
-            mPermissionState = permissionState;
-        }
-
-        public boolean canWrite() {
-            return mPermissionState.isPermissible();
+            super(permissionState.packageName, permissionState.userHandle);
+            this.packageInfo = permissionState.packageInfo;
+            this.appOpMode = permissionState.appOpMode;
+            this.permissionDeclared = permissionState.permissionDeclared;
         }
     }
 
diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java
index 3820123..ce2dbe0 100644
--- a/src/com/android/settings/applications/ManageApplications.java
+++ b/src/com/android/settings/applications/ManageApplications.java
@@ -152,8 +152,10 @@
     // This is the actual mapping to filters from FILTER_ constants above, the order must
     // be kept in sync.
     public static final AppFilter[] FILTERS = new AppFilter[] {
-        AppStatePowerBridge.FILTER_POWER_WHITELISTED,     // High power whitelist, on
-        ApplicationsState.FILTER_PERSONAL,    // All apps label, but personal filter
+        new CompoundFilter(AppStatePowerBridge.FILTER_POWER_WHITELISTED,
+                ApplicationsState.FILTER_ALL_ENABLED),     // High power whitelist, on
+        new CompoundFilter(ApplicationsState.FILTER_PERSONAL,
+                ApplicationsState.FILTER_ALL_ENABLED),     // All apps label, but personal filter
         ApplicationsState.FILTER_EVERYTHING,  // All apps
         ApplicationsState.FILTER_ALL_ENABLED, // Enabled
         ApplicationsState.FILTER_DISABLED,    // Disabled
@@ -617,6 +619,9 @@
     }
 
     public void setHasDisabled(boolean hasDisabledApps) {
+        if (mListType == LIST_TYPE_HIGH_POWER) {
+            return;
+        }
         mFilterAdapter.setFilterEnabled(FILTER_APPS_ENABLED, hasDisabledApps);
         mFilterAdapter.setFilterEnabled(FILTER_APPS_DISABLED, hasDisabledApps);
     }
diff --git a/src/com/android/settings/applications/WriteSettingsDetails.java b/src/com/android/settings/applications/WriteSettingsDetails.java
index eeee90c..30533c6 100644
--- a/src/com/android/settings/applications/WriteSettingsDetails.java
+++ b/src/com/android/settings/applications/WriteSettingsDetails.java
@@ -23,7 +23,6 @@
 import android.content.Intent;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
 import android.os.Bundle;
 import android.os.UserHandle;
 import android.preference.Preference;
@@ -36,6 +35,7 @@
 import com.android.internal.logging.MetricsLogger;
 import com.android.settings.InstrumentedFragment;
 import com.android.settings.R;
+import com.android.settings.applications.AppStateAppOpsBridge.PermissionState;
 import com.android.settings.applications.AppStateWriteSettingsBridge.WriteSettingsState;
 import com.android.settingslib.applications.ApplicationsState;
 import com.android.settingslib.applications.ApplicationsState.AppEntry;
@@ -98,7 +98,7 @@
                 try {
                     getActivity().startActivityAsUser(mSettingsIntent, new UserHandle(mUserId));
                 } catch (ActivityNotFoundException e) {
-                    Log.w(TAG, "Unable to launch write system settings " + mSettingsIntent, e);
+                    Log.w(LOG_TAG, "Unable to launch write system settings " + mSettingsIntent, e);
                 }
             }
             return true;
@@ -109,8 +109,9 @@
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         if (preference == mSwitchPref) {
-            if (mWriteSettingsState != null && (Boolean) newValue != mWriteSettingsState.canWrite()) {
-                setCanWriteSettings(!mWriteSettingsState.canWrite());
+            if (mWriteSettingsState != null && (Boolean) newValue != mWriteSettingsState
+                    .isPermissible()) {
+                setCanWriteSettings(!mWriteSettingsState.isPermissible());
                 refreshUi();
             }
             return true;
@@ -122,7 +123,6 @@
         mAppOpsManager.setMode(AppOpsManager.OP_WRITE_SETTINGS,
                 mPackageInfo.applicationInfo.uid, mPackageName, newState
                 ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_ERRORED);
-        canWriteSettings(mPackageName);
     }
 
     private boolean canWriteSettings(String pkgName) {
@@ -140,17 +140,10 @@
         mWriteSettingsState = mAppBridge.getWriteSettingsInfo(mPackageName,
                 mPackageInfo.applicationInfo.uid);
 
-        boolean canWrite = mWriteSettingsState.canWrite();
+        boolean canWrite = mWriteSettingsState.isPermissible();
         mSwitchPref.setChecked(canWrite);
         mWriteSettingsPrefs.setEnabled(canWrite);
-
-        ResolveInfo resolveInfo = mPm.resolveActivityAsUser(mSettingsIntent,
-                PackageManager.GET_META_DATA, mUserId);
-        if (resolveInfo == null) {
-            if (findPreference(KEY_APP_OPS_SETTINGS_PREFS) != null) {
-                getPreferenceScreen().removePreference(mWriteSettingsPrefs);
-            }
-        }
+        getPreferenceScreen().removePreference(mWriteSettingsPrefs);
 
         return true;
     }
@@ -166,9 +159,20 @@
     }
 
     public static CharSequence getSummary(Context context, AppEntry entry) {
+        if (entry.extraInfo != null) {
+            return getSummary(context, new WriteSettingsState((PermissionState)entry
+                    .extraInfo));
+        }
+
+        // fallback if entry.extrainfo is null - although this should not happen
         return getSummary(context, entry.info.packageName);
     }
 
+    public static CharSequence getSummary(Context context, WriteSettingsState writeSettingsState) {
+        return context.getString(writeSettingsState.isPermissible() ? R.string.write_settings_on :
+                R.string.write_settings_off);
+    }
+
     public static CharSequence getSummary(Context context, String pkg) {
         // first check if pkg is a system pkg
         boolean isSystem = false;
@@ -180,8 +184,8 @@
             }
         } catch (PackageManager.NameNotFoundException e) {
             // pkg doesn't even exist?
-            Log.w(TAG, "Package " + pkg + " not found", e);
-            return context.getString(R.string.system_alert_window_off);
+            Log.w(LOG_TAG, "Package " + pkg + " not found", e);
+            return context.getString(R.string.write_settings_off);
         }
 
         AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context
@@ -189,7 +193,7 @@
         List<AppOpsManager.PackageOps> packageOps = appOpsManager.getPackagesForOps(
                 APP_OPS_OP_CODE);
         if (packageOps == null) {
-            return context.getString(R.string.system_alert_window_off);
+            return context.getString(R.string.write_settings_off);
         }
 
         int uid = isSystem ? 0 : -1;
@@ -201,7 +205,7 @@
         }
 
         if (uid == -1) {
-            return context.getString(R.string.system_alert_window_off);
+            return context.getString(R.string.write_settings_off);
         }
 
         int mode = appOpsManager.noteOpNoThrow(AppOpsManager.OP_WRITE_SETTINGS, uid, pkg);
diff --git a/src/com/android/settings/deviceinfo/PublicVolumeSettings.java b/src/com/android/settings/deviceinfo/PublicVolumeSettings.java
index 4c77d21..c9b4beb 100644
--- a/src/com/android/settings/deviceinfo/PublicVolumeSettings.java
+++ b/src/com/android/settings/deviceinfo/PublicVolumeSettings.java
@@ -16,6 +16,7 @@
 
 package com.android.settings.deviceinfo;
 
+import android.app.ActivityManager;
 import android.content.Context;
 import android.content.Intent;
 import android.net.Uri;
@@ -81,7 +82,8 @@
 
         final Context context = getActivity();
 
-        mIsPermittedToAdopt = UserManager.get(context).isAdminUser();
+        mIsPermittedToAdopt = UserManager.get(context).isAdminUser()
+                && !ActivityManager.isUserAMonkey();
 
         mStorageManager = context.getSystemService(StorageManager.class);
 
diff --git a/src/com/android/settings/deviceinfo/StorageWizardInit.java b/src/com/android/settings/deviceinfo/StorageWizardInit.java
index 284e67d..c3c2430 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardInit.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardInit.java
@@ -16,6 +16,7 @@
 
 package com.android.settings.deviceinfo;
 
+import android.app.ActivityManager;
 import android.content.Intent;
 import android.os.Bundle;
 import android.os.UserManager;
@@ -42,7 +43,8 @@
         }
         setContentView(R.layout.storage_wizard_init);
 
-        mIsPermittedToAdopt = UserManager.get(this).isAdminUser();
+        mIsPermittedToAdopt = UserManager.get(this).isAdminUser()
+                && !ActivityManager.isUserAMonkey();
 
         setIllustrationInternal(true);
         setHeaderText(R.string.storage_wizard_init_title, mDisk.getDescription());
diff --git a/src/com/android/settings/fingerprint/FingerprintEnrollEnrolling.java b/src/com/android/settings/fingerprint/FingerprintEnrollEnrolling.java
index b8ac040..5d4edbd 100644
--- a/src/com/android/settings/fingerprint/FingerprintEnrollEnrolling.java
+++ b/src/com/android/settings/fingerprint/FingerprintEnrollEnrolling.java
@@ -214,9 +214,9 @@
 
     private void launchFinish(byte[] token) {
         Intent intent = getFinishIntent();
+        intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
         intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
         startActivity(intent);
-        setResult(RESULT_FINISHED);
         finish();
     }
 
diff --git a/src/com/android/settings/fingerprint/FingerprintEnrollFindSensor.java b/src/com/android/settings/fingerprint/FingerprintEnrollFindSensor.java
index 552ed71..1d9d1c5 100644
--- a/src/com/android/settings/fingerprint/FingerprintEnrollFindSensor.java
+++ b/src/com/android/settings/fingerprint/FingerprintEnrollFindSensor.java
@@ -16,6 +16,7 @@
 
 package com.android.settings.fingerprint;
 
+import android.content.Context;
 import android.content.Intent;
 import android.hardware.fingerprint.FingerprintManager;
 import android.os.Bundle;
@@ -75,6 +76,14 @@
             if (resultCode == RESULT_FINISHED) {
                 setResult(RESULT_FINISHED);
                 finish();
+            } else {
+                FingerprintManager fpm = getSystemService(FingerprintManager.class);
+                int enrolled = fpm.getEnrolledFingerprints().size();
+                int max = getResources().getInteger(
+                        com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser);
+                if (enrolled >= max) {
+                    finish();
+                }
             }
         } else {
             super.onActivityResult(requestCode, resultCode, data);
diff --git a/src/com/android/settings/fingerprint/FingerprintEnrollFinish.java b/src/com/android/settings/fingerprint/FingerprintEnrollFinish.java
index 7e4d656..7ce340d 100644
--- a/src/com/android/settings/fingerprint/FingerprintEnrollFinish.java
+++ b/src/com/android/settings/fingerprint/FingerprintEnrollFinish.java
@@ -55,6 +55,7 @@
 
     @Override
     protected void onNextButtonClick() {
+        setResult(RESULT_FINISHED);
         finish();
     }
 
diff --git a/src/com/android/settings/fingerprint/FingerprintSettings.java b/src/com/android/settings/fingerprint/FingerprintSettings.java
index 89c6e1b..f065bff 100644
--- a/src/com/android/settings/fingerprint/FingerprintSettings.java
+++ b/src/com/android/settings/fingerprint/FingerprintSettings.java
@@ -104,7 +104,7 @@
     }
 
     public static class FingerprintSettingsFragment extends SettingsPreferenceFragment
-        implements OnPreferenceChangeListener, Indexable {
+        implements OnPreferenceChangeListener {
         private static final int MAX_RETRY_ATTEMPTS = 20;
         private static final int RESET_HIGHLIGHT_DELAY_MS = 500;