Merge "Log when the storage manager is toggled on and off." into nyc-mr1-dev
diff --git a/res/layout-land/fingerprint_enroll_find_sensor.xml b/res/layout-land/fingerprint_enroll_find_sensor.xml
index 1d923fa..0a3a33f 100644
--- a/res/layout-land/fingerprint_enroll_find_sensor.xml
+++ b/res/layout-land/fingerprint_enroll_find_sensor.xml
@@ -20,37 +20,62 @@
     android:id="@+id/setup_wizard_layout"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:layout="@layout/suw_glif_blank_template"
     style="?attr/fingerprint_layout_theme">
 
     <LinearLayout
-        style="@style/SuwContentFrame"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:orientation="horizontal"
         android:clipToPadding="false"
-        android:clipChildren="false"
-        android:paddingBottom="0dp">
+        android:clipChildren="false">
 
         <LinearLayout
             android:layout_width="0dp"
             android:layout_weight="1"
-            android:layout_height="wrap_content"
-            android:layout_gravity="center_vertical"
+            android:layout_height="match_parent"
+            android:layout_marginStart="?attr/suwMarginSides"
+            android:layout_marginBottom="@dimen/suw_content_frame_padding_bottom"
             android:orientation="vertical">
 
-            <TextView
-                style="@style/TextAppearance.FingerprintMessage"
+            <LinearLayout
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:text="@string/security_settings_fingerprint_enroll_find_sensor_message"/>
+                android:orientation="vertical">
 
-            <Button
-                style="@style/SetupWizardButton.Positive"
-                android:id="@+id/next_button"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_marginTop="8dp"
-                android:text="@string/fingerprint_enroll_button_next" />
+                <ImageView
+                    android:id="@+id/suw_layout_icon"
+                    style="@style/SuwGlifIcon"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginStart="0dp"
+                    android:layout_marginEnd="0dp"
+                    android:src="@drawable/ic_lock" />
+
+                <TextView
+                    android:id="@+id/suw_layout_title"
+                    style="@style/SuwGlifHeaderTitle"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_marginStart="0dp"
+                    android:layout_marginEnd="0dp" />
+
+                <TextView
+                    style="@style/TextAppearance.FingerprintMessage"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:text="@string/security_settings_fingerprint_enroll_find_sensor_message"/>
+
+                <Button
+                    style="@style/SetupWizardButton.Positive"
+                    android:id="@+id/next_button"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginTop="8dp"
+                    android:text="@string/fingerprint_enroll_button_next" />
+
+            </LinearLayout>
+
         </LinearLayout>
 
         <FrameLayout
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b8b4273..8c3532d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2207,7 +2207,7 @@
     <!-- [CHAR LIMIT=30] Display settings screen, setting option name to change whether the ambient display feature is enabled. -->
     <string name="doze_title">Ambient display</string>
     <!-- [CHAR LIMIT=NONE] Display settings screen, setting description for the ambient display feature. -->
-    <string name="doze_summary">Wake screen when you pick up device or receive notifications</string>
+    <string name="doze_summary">Wake screen when you double-tap it or get new notifications. See how</string>
     <!-- [CHAR LIMIT=30] Sound & display settings screen, setting option name to change font size -->
     <string name="title_font_size">Font size</string>
     <!-- Summary for Font size. Lets the user know that this will make text larger or smaller. Appears in the accessibility portion of setup wizard. [CHAR LIMIT=NONE] -->
@@ -7696,19 +7696,19 @@
     <string name="double_twist_for_camera_mode_title">Flip camera</string>
 
     <!-- Summary text for double twist for camera mode  [CHAR LIMIT=160]-->
-    <string name="double_twist_for_camera_mode_summary">To switch between front and back cameras, double-twist</string>
+    <string name="double_twist_for_camera_mode_summary"></string>
 
     <!-- Title text for ambient display [CHAR LIMIT=60]-->
     <string name="ambient_display_title">Quick screen check</string>
 
     <!-- Summary text for ambient display [CHAR LIMIT=160]-->
-    <string name="ambient_display_summary">To check your phone without waking it up, double-tap the screen or raise the device</string>
+    <string name="ambient_display_summary">To check your phone without waking it up fully, double-tap it or pick it up</string>
 
     <!-- Title text for fingerprint swipe for notifications [CHAR LIMIT=60]-->
     <string name="fingerprint_swipe_for_notifications_title">Swipe for notifications</string>
 
     <!-- Summary text for fingerprint swipe for notifications [CHAR LIMIT=160]-->
-    <string name="fingerprint_swipe_for_notifications_summary">To check your notifications from any screen, swipe down on the fingerprint sensor</string>
+    <string name="fingerprint_swipe_for_notifications_summary">To check your notifications, swipe down on the fingerprint sensor on the back of your phone</string>
 
     <!-- Switch text for each gesture setting state -->
     <string name="gesture_setting_on">On</string>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index cc6dc30..87da4b3 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -286,15 +286,18 @@
         <item name="android:singleLine">true</item>
     </style>
 
-    <style name="SetupWizardButton.Negative" parent="@android:style/TextAppearance.Widget.TextView">
-        <item name="android:background">@null</item>
+    <style name="SetupWizardButton.Negative" parent="@android:style/Widget.Material.Button.Borderless.Colored">
         <item name="android:minWidth">0dp</item>
         <item name="android:textAllCaps">false</item>
-        <item name="android:textColor">?android:attr/colorControlActivated</item>
+        <item name="android:theme">@style/AccentColorHighlightBorderlessButton</item>
     </style>
 
     <style name="SetupWizardButton.Positive" parent="@android:style/Widget.Material.Button.Colored" />
 
+    <style name="AccentColorHighlightBorderlessButton">
+        <item name="android:colorControlHighlight">?android:attr/colorAccent</item>
+    </style>
+
     <style name="vpn_label">
         <item name="android:layout_width">match_parent</item>
         <item name="android:layout_height">wrap_content</item>
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index 0630b55..e96a050 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -81,7 +81,7 @@
         <PreferenceScreen
                 android:key="doze"
                 android:title="@string/doze_title"
-                android:summary="@string/ambient_display_summary"
+                android:summary="@string/doze_summary"
                 android:fragment="com.android.settings.gestures.GestureSettings" >
                 <extra android:name="gesture_scroll_to_preference"
                        android:value="gesture_pick_up_and_nudge" />
diff --git a/res/xml/gesture_settings.xml b/res/xml/gesture_settings.xml
index 78f65a6..55189e5 100644
--- a/res/xml/gesture_settings.xml
+++ b/res/xml/gesture_settings.xml
@@ -32,15 +32,15 @@
         settings:animation="@raw/gesture_twist"/>
 
     <com.android.settings.gestures.GesturePreference
-        android:key="gesture_swipe_down_fingerprint"
-        android:title="@string/fingerprint_swipe_for_notifications_title"
-        android:summary="@string/fingerprint_swipe_for_notifications_summary"
-        settings:animation="@raw/gesture_fingerprint_swipe"/>
-
-    <com.android.settings.gestures.GesturePreference
         android:key="gesture_pick_up_and_nudge"
         android:title="@string/ambient_display_title"
         android:summary="@string/ambient_display_summary"
         settings:animation="@raw/gesture_ambient_tap"/>
 
+    <com.android.settings.gestures.GesturePreference
+        android:key="gesture_swipe_down_fingerprint"
+        android:title="@string/fingerprint_swipe_for_notifications_title"
+        android:summary="@string/fingerprint_swipe_for_notifications_summary"
+        settings:animation="@raw/gesture_fingerprint_swipe"/>
+
 </PreferenceScreen>
\ No newline at end of file
diff --git a/src/com/android/settings/AppListPreference.java b/src/com/android/settings/AppListPreference.java
index 61b4260..1ebeeaa 100644
--- a/src/com/android/settings/AppListPreference.java
+++ b/src/com/android/settings/AppListPreference.java
@@ -32,6 +32,7 @@
 import android.os.RemoteException;
 import android.os.UserHandle;
 import android.os.UserManager;
+import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -265,6 +266,24 @@
         }
     }
 
+    /**
+     * Sets app label as summary if there is only 1 app applicable to this preference.
+     */
+    protected void setSoleAppLabelAsSummary() {
+        final CharSequence soleLauncherLabel = getSoleAppLabel();
+        if (!TextUtils.isEmpty(soleLauncherLabel)) {
+            setSummary(soleLauncherLabel);
+        }
+    }
+
+    /**
+     * Returns app label if there is only 1 app applicable to this preference.
+     */
+    protected CharSequence getSoleAppLabel() {
+        // Intentionally left empty so subclasses can override with necessary logic.
+        return null;
+    }
+
     private static class SavedState implements Parcelable {
 
         public final CharSequence[] entryValues;
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index db6a373b..4697f43 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -1016,16 +1016,12 @@
             mEnableOemUnlock.setDisabledByAdmin(null);
             mEnableOemUnlock.setEnabled(enableOemUnlockPreference());
             if (mEnableOemUnlock.isEnabled()) {
-                // mEnableOemUnlock is enabled as device's flash lock is unlocked.
-                if (RestrictedLockUtils.hasBaseUserRestriction(getActivity(),
-                        UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId())) {
-                    // Set mEnableOemUnlock to disabled as restriction is set, but not by admin.
-                    mEnableOemUnlock.setEnabled(false);
-                } else {
-                    // Check restriction, disable mEnableOemUnlock and apply policy transparency.
-                    mEnableOemUnlock
-                            .checkRestrictionAndSetDisabled(UserManager.DISALLOW_FACTORY_RESET);
-                }
+                // Check restriction, disable mEnableOemUnlock and apply policy transparency.
+                mEnableOemUnlock.checkRestrictionAndSetDisabled(UserManager.DISALLOW_FACTORY_RESET);
+            }
+            if (mEnableOemUnlock.isEnabled()) {
+                // Check restriction, disable mEnableOemUnlock and apply policy transparency.
+                mEnableOemUnlock.checkRestrictionAndSetDisabled(UserManager.DISALLOW_OEM_UNLOCK);
             }
         }
     }
@@ -2175,8 +2171,8 @@
             } else if (isSimLockedDevice()) {
                 oemUnlockSummary = R.string.oem_unlock_enable_disabled_summary_sim_locked_device;
             } else if (!isOemUnlockAllowed()) {
-                // If the device isn't SIM-locked but OEM unlock is disabled by Global setting, this
-                // means the device hasn't been able to confirm whether SIM-lock or any other
+                // If the device isn't SIM-locked but OEM unlock is disabled by user restriction,
+                // this means the device hasn't been able to confirm whether SIM-lock or any other
                 // restrictions apply (or hasn't been able to apply such restrictions yet). Ask the
                 // user to connect to the internet in order to retrieve all restrictions.
                 oemUnlockSummary = R.string.oem_unlock_enable_disabled_summary_connectivity;
@@ -2209,11 +2205,13 @@
     }
 
     /**
-     * Returns {@code true} if OEM unlock is not disabled by Global policy. Otherwise, returns
-     * {@code false}.
+     * Returns {@code true} if OEM unlock is disallowed by user restriction
+     * {@link UserManager#DISALLOW_FACTORY_RESET} or {@link UserManager#DISALLOW_OEM_UNLOCK}.
+     * Otherwise, returns {@code false}.
      */
     private boolean isOemUnlockAllowed() {
-        return Settings.Global.getInt(getActivity().getContentResolver(),
-                Settings.Global.OEM_UNLOCK_DISALLOWED, 0) == 0;
+        UserHandle userHandle = UserHandle.of(UserHandle.myUserId());
+        return !(mUm.hasBaseUserRestriction(UserManager.DISALLOW_OEM_UNLOCK, userHandle)
+                || mUm.hasBaseUserRestriction(UserManager.DISALLOW_FACTORY_RESET, userHandle));
     }
 }
diff --git a/src/com/android/settings/applications/DefaultBrowserPreference.java b/src/com/android/settings/applications/DefaultBrowserPreference.java
index d25e224..9d84e1e 100644
--- a/src/com/android/settings/applications/DefaultBrowserPreference.java
+++ b/src/com/android/settings/applications/DefaultBrowserPreference.java
@@ -26,6 +26,7 @@
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.util.Log;
+
 import com.android.internal.content.PackageMonitor;
 import com.android.settings.AppListPreference;
 import com.android.settings.R;
@@ -36,12 +37,16 @@
 public class DefaultBrowserPreference extends AppListPreference {
 
     private static final String TAG = "DefaultBrowserPref";
+    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
 
     private static final long DELAY_UPDATE_BROWSER_MILLIS = 500;
+    private static final Intent BROWSE_PROBE = new Intent()
+            .setAction(Intent.ACTION_VIEW)
+            .addCategory(Intent.CATEGORY_BROWSABLE)
+            .setData(Uri.parse("http:"));
 
     private final Handler mHandler = new Handler();
-
-    final private PackageManager mPm;
+    private final PackageManager mPm;
 
     public DefaultBrowserPreference(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -65,11 +70,7 @@
 
     @Override
     protected boolean persistString(String newValue) {
-
-        if (newValue == null) {
-            return false;
-        }
-        final CharSequence packageName = (CharSequence) newValue;
+        final CharSequence packageName = newValue;
         if (TextUtils.isEmpty(packageName)) {
             return false;
         }
@@ -95,13 +96,10 @@
         String packageName = pm.getDefaultBrowserPackageNameAsUser(mUserId);
         if (!TextUtils.isEmpty(packageName)) {
             // Check if the default Browser package is still there
-            Intent intent = new Intent();
-            intent.setPackage(packageName);
-            intent.setAction(Intent.ACTION_VIEW);
-            intent.addCategory(Intent.CATEGORY_BROWSABLE);
-            intent.setData(Uri.parse("http:"));
+            final Intent intent = new Intent(BROWSE_PROBE)
+                    .setPackage(packageName);
 
-            ResolveInfo info = mPm.resolveActivityAsUser(intent, 0, mUserId);
+            final ResolveInfo info = mPm.resolveActivityAsUser(intent, 0, mUserId);
             if (info != null) {
                 setValue(packageName);
                 setSummary("%s");
@@ -109,26 +107,20 @@
                 setSummary(R.string.default_browser_title_none);
             }
         } else {
-            setSummary(R.string.default_browser_title_none);
-            Log.d(TAG, "Cannot set empty default Browser value!");
+            if (DEBUG) Log.d(TAG, "No default browser app.");
+            setSoleAppLabelAsSummary();
         }
     }
 
     private List<String> resolveBrowserApps() {
         List<String> result = new ArrayList<>();
 
-        // Create an Intent that will match ALL Browser Apps
-        Intent intent = new Intent();
-        intent.setAction(Intent.ACTION_VIEW);
-        intent.addCategory(Intent.CATEGORY_BROWSABLE);
-        intent.setData(Uri.parse("http:"));
-
         // Resolve that intent and check that the handleAllWebDataURI boolean is set
-        List<ResolveInfo> list = mPm.queryIntentActivitiesAsUser(intent, PackageManager.MATCH_ALL,
-                mUserId);
+        List<ResolveInfo> list = mPm.queryIntentActivitiesAsUser(BROWSE_PROBE,
+                PackageManager.MATCH_ALL, mUserId);
 
         final int count = list.size();
-        for (int i=0; i<count; i++) {
+        for (int i = 0; i < count; i++) {
             ResolveInfo info = list.get(i);
             if (info.activityInfo == null || result.contains(info.activityInfo.packageName)
                     || !info.handleAllWebDataURI) {
@@ -141,6 +133,17 @@
         return result;
     }
 
+    @Override
+    protected CharSequence getSoleAppLabel() {
+        // Resolve that intent and check that the handleAllWebDataURI boolean is set
+        List<ResolveInfo> list = mPm.queryIntentActivitiesAsUser(BROWSE_PROBE,
+                PackageManager.MATCH_ALL, mUserId);
+        if (list.size() == 1) {
+            return list.get(0).loadLabel(mPm);
+        }
+        return null;
+    }
+
     private final Runnable mUpdateRunnable = new Runnable() {
         @Override
         public void run() {
diff --git a/src/com/android/settings/applications/DefaultHomePreference.java b/src/com/android/settings/applications/DefaultHomePreference.java
index 9f4a913..46fba66 100644
--- a/src/com/android/settings/applications/DefaultHomePreference.java
+++ b/src/com/android/settings/applications/DefaultHomePreference.java
@@ -26,6 +26,7 @@
 import android.os.Build;
 import android.os.UserManager;
 import android.util.AttributeSet;
+
 import com.android.settings.AppListPreference;
 import com.android.settings.R;
 
@@ -36,9 +37,11 @@
 
     private final ArrayList<ComponentName> mAllHomeComponents = new ArrayList<>();
     private final IntentFilter mHomeFilter;
+    private final String mPackageName;
 
     public DefaultHomePreference(Context context, AttributeSet attrs) {
         super(context, attrs);
+        mPackageName = getContext().getPackageName();
         mHomeFilter = new IntentFilter(Intent.ACTION_MAIN);
         mHomeFilter.addCategory(Intent.CATEGORY_HOME);
         mHomeFilter.addCategory(Intent.CATEGORY_DEFAULT);
@@ -59,26 +62,44 @@
                     IntentFilter.MATCH_CATEGORY_EMPTY,
                     mAllHomeComponents.toArray(new ComponentName[0]), component);
             setSummary(getEntry());
+        } else {
+            // If there is only 1 launcher, use its label as summary text.
+            setSoleAppLabelAsSummary();
         }
         return super.persistString(value);
     }
 
+    @Override
+    protected CharSequence getSoleAppLabel() {
+        final PackageManager pm = getContext().getPackageManager();
+        final List<ResolveInfo> homeActivities = new ArrayList<>();
+        final List<CharSequence> appLabels = new ArrayList<>();
+
+        pm.getHomeActivities(homeActivities);
+        for (ResolveInfo candidate : homeActivities) {
+            final ActivityInfo info = candidate.activityInfo;
+            if (info.packageName.equals(mPackageName)) {
+                continue;
+            }
+            appLabels.add(info.loadLabel(pm));
+        }
+        return appLabels.size() == 1 ? appLabels.get(0) : null;
+    }
+
     public void refreshHomeOptions() {
-        final String myPkg = getContext().getPackageName();
-        ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
+        ArrayList<ResolveInfo> homeActivities = new ArrayList<>();
         PackageManager pm = getContext().getPackageManager();
-        ComponentName currentDefaultHome  = pm.getHomeActivities(homeActivities);
+        ComponentName currentDefaultHome = pm.getHomeActivities(homeActivities);
         ArrayList<ComponentName> components = new ArrayList<>();
         mAllHomeComponents.clear();
         List<CharSequence> summaries = new ArrayList<>();
 
         boolean mustSupportManagedProfile = hasManagedProfile();
-        for (int i = 0; i < homeActivities.size(); i++) {
-            final ResolveInfo candidate = homeActivities.get(i);
+        for (ResolveInfo candidate : homeActivities) {
             final ActivityInfo info = candidate.activityInfo;
             ComponentName activityName = new ComponentName(info.packageName, info.name);
             mAllHomeComponents.add(activityName);
-            if (info.packageName.equals(myPkg)) {
+            if (info.packageName.equals(mPackageName)) {
                 continue;
             }
             components.add(activityName);
diff --git a/src/com/android/settings/dashboard/SuggestionsChecks.java b/src/com/android/settings/dashboard/SuggestionsChecks.java
index 5f140ba..5b8638a 100644
--- a/src/com/android/settings/dashboard/SuggestionsChecks.java
+++ b/src/com/android/settings/dashboard/SuggestionsChecks.java
@@ -21,6 +21,7 @@
 import android.app.KeyguardManager;
 import android.app.NotificationManager;
 import android.app.WallpaperManager;
+import android.app.admin.DevicePolicyManager;
 import android.content.Context;
 import android.hardware.fingerprint.FingerprintManager;
 import android.os.Bundle;
@@ -59,10 +60,11 @@
         } else if (className.equals(WifiCallingSuggestionActivity.class.getName())) {
             return isWifiCallingUnavailableOrEnabled();
         } else if (className.equals(FingerprintSuggestionActivity.class.getName())) {
-            return isNotSingleFingerprintEnrolled();
-        } else if (className.equals(ScreenLockSuggestionActivity.class.getName())
-                || className.equals(FingerprintEnrollSuggestionActivity.class.getName())) {
+            return isNotSingleFingerprintEnrolled() || !isFingerprintEnabled();
+        } else if (className.equals(ScreenLockSuggestionActivity.class.getName())) {
             return isDeviceSecured();
+        } else if (className.equals(FingerprintEnrollSuggestionActivity.class.getName())) {
+            return isDeviceSecured() || !isFingerprintEnabled();
         }
         return false;
     }
@@ -108,6 +110,14 @@
         return false;
     }
 
+    private boolean isFingerprintEnabled() {
+        DevicePolicyManager dpManager =
+                (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
+        final int dpmFlags = dpManager.getKeyguardDisabledFeatures(null, /* admin */
+                mContext.getUserId());
+        return (dpmFlags & DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT) == 0;
+    }
+
     private final IWallpaperManagerCallback mCallback = new IWallpaperManagerCallback.Stub() {
         @Override
         public void onWallpaperChanged() throws RemoteException {
diff --git a/src/com/android/settings/dashboard/SupportItemAdapter.java b/src/com/android/settings/dashboard/SupportItemAdapter.java
index 52440e9..1d4e99a 100644
--- a/src/com/android/settings/dashboard/SupportItemAdapter.java
+++ b/src/com/android/settings/dashboard/SupportItemAdapter.java
@@ -89,7 +89,7 @@
         } else {
             mSelectedCountry = mSupportFeatureProvider.getCurrentCountryCodeIfHasConfig(PHONE);
         }
-        setAccount(mSupportFeatureProvider.getSupportEligibleAccount(mActivity));
+        mAccount = mSupportFeatureProvider.getSupportEligibleAccount(mActivity);
         refreshData();
     }
 
@@ -155,6 +155,7 @@
     public void setAccount(Account account) {
         if (!Objects.equals(mAccount, account)) {
             mAccount = account;
+            mSupportFeatureProvider.refreshOperationRules();
             refreshData();
         }
     }
diff --git a/src/com/android/settings/overlay/SupportFeatureProvider.java b/src/com/android/settings/overlay/SupportFeatureProvider.java
index 4d8e3d6..45713e4 100644
--- a/src/com/android/settings/overlay/SupportFeatureProvider.java
+++ b/src/com/android/settings/overlay/SupportFeatureProvider.java
@@ -52,6 +52,11 @@
     boolean isSupportTypeEnabled(Context context, @SupportType int type);
 
     /**
+     * Refreshes all operation rules.
+     */
+    void refreshOperationRules();
+
+    /**
      * Whether or not a support type is in operation 24/7. If country is null, use
      * current country.
      */