Update fingerprint strings
am: fcd3abd244

Change-Id: If605afa35dd4256f1b1374e3908842d10925a727
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 56d717a..68691de 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2139,7 +2139,11 @@
     <!-- Night display screen, setting option name to enable night display (renamed "Night Light" with title caps). [CHAR LIMIT=30] -->
     <string name="night_display_title">Night Light</string>
     <!-- Night display screen, description of night display feature (renamed "Night Light" with title caps). [CHAR LIMIT=NONE] -->
-    <string name="night_display_text">Night Light tints your screen red at night. This makes it easier to look at your screen or read in dim light, and may help you fall asleep more easily.</string>
+    <string name="night_display_text">Night Light tints your screen red. This makes it easier to look at your screen or read in dim light, and may help you fall asleep more easily.</string>
+    <!-- Night display screen, category title for settings to schedule when night display activates automatically. [CHAR LIMIT=30] -->
+    <string name="night_display_category_schedule">Schedule</string>
+    <!-- Night display screen, category title for settings to manually activate night display. [CHAR LIMIT=30] -->
+    <string name="night_display_category_status">Status</string>
     <!-- Night display screen, setting option name to configure whether night display turn on/off automatically. [CHAR LIMIT=30] -->
     <string name="night_display_auto_mode_title">Turn on automatically</string>
     <!-- Night display screen, setting option value for night display to *never* turn on/off automatically. [CHAR LIMIT=30] -->
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index a89d687..6f55982 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -36,6 +36,7 @@
                 android:key="night_display"
                 android:title="@string/night_display_title"
                 android:fragment="com.android.settings.display.NightDisplaySettings"
+                android:widgetLayout="@null"
                 settings:keywords="@string/keywords_display_night_display" />
 
         <!-- Hide night mode for now
diff --git a/res/xml/night_display_settings.xml b/res/xml/night_display_settings.xml
index 531f606..76b9323 100644
--- a/res/xml/night_display_settings.xml
+++ b/res/xml/night_display_settings.xml
@@ -19,19 +19,32 @@
         xmlns:settings="http://schemas.android.com/apk/res-auto"
         android:title="@string/night_display_title">
 
-    <DropDownPreference
-            android:key="night_display_auto_mode"
-            android:title="@string/night_display_auto_mode_title"
-            android:persistent="false"
-            android:summary="%s" />
+    <PreferenceCategory
+            android:title="@string/night_display_category_schedule">
 
-    <Preference
-            android:key="night_display_start_time"
-            android:title="@string/night_display_start_time_title" />
+        <DropDownPreference
+                android:key="night_display_auto_mode"
+                android:title="@string/night_display_auto_mode_title"
+                android:summary="%s" />
 
-    <Preference
-            android:key="night_display_end_time"
-            android:title="@string/night_display_end_time_title" />
+        <Preference
+                android:key="night_display_start_time"
+                android:title="@string/night_display_start_time_title" />
+
+        <Preference
+                android:key="night_display_end_time"
+                android:title="@string/night_display_end_time_title" />
+
+    </PreferenceCategory>
+
+    <PreferenceCategory
+            android:title="@string/night_display_category_status">
+
+        <com.android.settings.display.NightDisplayPreference
+                android:key="night_display_activated"
+                android:title="@string/night_display_title" />
+
+    </PreferenceCategory>
 
     <com.android.settings.fuelgauge.WallOfTextPreference
             android:summary="@string/night_display_text"
diff --git a/src/com/android/settings/CustomListPreference.java b/src/com/android/settings/CustomListPreference.java
index ae83013..e7c7600 100644
--- a/src/com/android/settings/CustomListPreference.java
+++ b/src/com/android/settings/CustomListPreference.java
@@ -18,8 +18,13 @@
 
 import android.app.AlertDialog;
 import android.app.Dialog;
+import android.app.DialogFragment;
+import android.app.Fragment;
+import android.app.FragmentTransaction;
 import android.content.Context;
 import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+import android.content.Intent;
 import android.os.Bundle;
 import android.support.v14.preference.ListPreferenceDialogFragment;
 import android.support.v7.preference.ListPreference;
@@ -50,6 +55,18 @@
         return true;
     }
 
+    /**
+     * Called when a user is about to choose the given value, to determine if we
+     * should show a confirmation dialog.
+     *
+     * @param value the value the user is about to choose
+     * @return the message to show in a confirmation dialog, or {@code null} to
+     *         not request confirmation
+     */
+    protected CharSequence getConfirmationMessage(String value) {
+        return null;
+    }
+
     protected void onDialogStateRestored(Dialog dialog, Bundle savedInstanceState) {
     }
 
@@ -82,9 +99,7 @@
                 builder.setPositiveButton(R.string.okay, new DialogInterface.OnClickListener() {
                     @Override
                     public void onClick(DialogInterface dialog, int which) {
-                        CustomListPreferenceDialogFragment.this.onClick(dialog,
-                                DialogInterface.BUTTON_POSITIVE);
-                        dialog.dismiss();
+                        onItemChosen();
                     }
                 });
             }
@@ -115,18 +130,11 @@
 
         protected DialogInterface.OnClickListener getOnItemClickListener() {
             return new DialogInterface.OnClickListener() {
+                @Override
                 public void onClick(DialogInterface dialog, int which) {
                     setClickedDialogEntryIndex(which);
-
-
                     if (getCustomizablePreference().isAutoClosePreference()) {
-                        /*
-                         * Clicking on an item simulates the positive button
-                         * click, and dismisses the dialog.
-                         */
-                        CustomListPreferenceDialogFragment.this.onClick(dialog,
-                                DialogInterface.BUTTON_POSITIVE);
-                        dialog.dismiss();
+                        onItemChosen();
                     }
                 }
             };
@@ -136,17 +144,74 @@
             mClickedDialogEntryIndex = which;
         }
 
+        private String getValue() {
+            final ListPreference preference = getCustomizablePreference();
+            if (mClickedDialogEntryIndex >= 0 && preference.getEntryValues() != null) {
+                return preference.getEntryValues()[mClickedDialogEntryIndex].toString();
+            } else {
+                return null;
+            }
+        }
+
+        /**
+         * Called when user has made a concrete item choice, but we might need
+         * to make a quick detour to confirm that choice with a second dialog.
+         */
+        protected void onItemChosen() {
+            final CharSequence message = getCustomizablePreference()
+                    .getConfirmationMessage(getValue());
+            if (message != null) {
+                final Fragment f = new ConfirmDialogFragment();
+                final Bundle args = new Bundle();
+                args.putCharSequence(Intent.EXTRA_TEXT, message);
+                f.setArguments(args);
+                f.setTargetFragment(CustomListPreferenceDialogFragment.this, 0);
+                final FragmentTransaction ft = getFragmentManager().beginTransaction();
+                ft.add(f, getTag() + "-Confirm");
+                ft.commitAllowingStateLoss();
+            } else {
+                onItemConfirmed();
+            }
+        }
+
+        /**
+         * Called when user has made a concrete item choice and we've fully
+         * confirmed they want to move forward (if we took a detour above).
+         */
+        protected void onItemConfirmed() {
+            onClick(getDialog(), DialogInterface.BUTTON_POSITIVE);
+            getDialog().dismiss();
+        }
+
         @Override
         public void onDialogClosed(boolean positiveResult) {
             getCustomizablePreference().onDialogClosed(positiveResult);
             final ListPreference preference = getCustomizablePreference();
-            if (positiveResult && mClickedDialogEntryIndex >= 0 &&
-                    preference.getEntryValues() != null) {
-                String value = preference.getEntryValues()[mClickedDialogEntryIndex].toString();
+            final String value = getValue();
+            if (positiveResult && value != null) {
                 if (preference.callChangeListener(value)) {
                     preference.setValue(value);
                 }
             }
         }
     }
+
+    public static class ConfirmDialogFragment extends DialogFragment {
+        @Override
+        public Dialog onCreateDialog(Bundle savedInstanceState) {
+            return new AlertDialog.Builder(getActivity())
+                    .setMessage(getArguments().getCharSequence(Intent.EXTRA_TEXT))
+                    .setPositiveButton(android.R.string.ok, new OnClickListener() {
+                        @Override
+                        public void onClick(DialogInterface dialog, int which) {
+                            final Fragment f = getTargetFragment();
+                            if (f != null) {
+                                ((CustomListPreferenceDialogFragment) f).onItemConfirmed();
+                            }
+                        }
+                    })
+                    .setNegativeButton(android.R.string.cancel, null)
+                    .create();
+        }
+    }
 }
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 90dd9e0..0725386 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -1150,5 +1150,14 @@
         }
         return false;
     }
-}
 
+    public static boolean isPackageDirectBootAware(Context context, String packageName) {
+        try {
+            final ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
+                    packageName, 0);
+            return ai.isDirectBootAware() || ai.isPartiallyDirectBootAware();
+        } catch (NameNotFoundException ignored) {
+        }
+        return false;
+    }
+}
diff --git a/src/com/android/settings/applications/DefaultEmergencyPreference.java b/src/com/android/settings/applications/DefaultEmergencyPreference.java
index f0a97b1..dd4dc2e 100644
--- a/src/com/android/settings/applications/DefaultEmergencyPreference.java
+++ b/src/com/android/settings/applications/DefaultEmergencyPreference.java
@@ -16,7 +16,6 @@
 
 package com.android.settings.applications;
 
-import android.content.ComponentName;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
@@ -30,9 +29,11 @@
 import android.text.TextUtils;
 import android.util.ArraySet;
 import android.util.AttributeSet;
-import com.android.internal.telephony.SmsApplication;
+
 import com.android.settings.AppListPreference;
+import com.android.settings.R;
 import com.android.settings.SelfAvailablePreference;
+import com.android.settings.Utils;
 
 import java.util.List;
 import java.util.Objects;
@@ -57,6 +58,12 @@
     }
 
     @Override
+    protected CharSequence getConfirmationMessage(String value) {
+        return Utils.isPackageDirectBootAware(getContext(), value) ? null
+                : getContext().getText(R.string.direct_boot_unaware_dialog_message);
+    }
+
+    @Override
     protected boolean persistString(String value) {
         String previousValue = Settings.Secure.getString(mContentResolver,
                 Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION);
diff --git a/src/com/android/settings/applications/DefaultPhonePreference.java b/src/com/android/settings/applications/DefaultPhonePreference.java
index fdaf7ad..5689c83 100644
--- a/src/com/android/settings/applications/DefaultPhonePreference.java
+++ b/src/com/android/settings/applications/DefaultPhonePreference.java
@@ -24,23 +24,28 @@
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 import android.util.AttributeSet;
+
 import com.android.settings.AppListPreference;
+import com.android.settings.R;
 import com.android.settings.SelfAvailablePreference;
+import com.android.settings.Utils;
 
 import java.util.List;
 import java.util.Objects;
 
 public class DefaultPhonePreference extends AppListPreference implements SelfAvailablePreference {
-    private final Context mContext;
-
     public DefaultPhonePreference(Context context, AttributeSet attrs) {
         super(context, attrs);
-
-        mContext = context.getApplicationContext();
         loadDialerApps();
     }
 
     @Override
+    protected CharSequence getConfirmationMessage(String value) {
+        return Utils.isPackageDirectBootAware(getContext(), value) ? null
+                : getContext().getText(R.string.direct_boot_unaware_dialog_message);
+    }
+
+    @Override
     protected boolean persistString(String value) {
         if (!TextUtils.isEmpty(value) && !Objects.equals(value, getDefaultPackage())) {
             DefaultDialerManager.setDefaultDialerApplication(getContext(), value, mUserId);
diff --git a/src/com/android/settings/applications/DefaultSmsPreference.java b/src/com/android/settings/applications/DefaultSmsPreference.java
index 9315102..96ac9a2 100644
--- a/src/com/android/settings/applications/DefaultSmsPreference.java
+++ b/src/com/android/settings/applications/DefaultSmsPreference.java
@@ -22,19 +22,20 @@
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 import android.util.AttributeSet;
+
 import com.android.internal.telephony.SmsApplication;
 import com.android.internal.telephony.SmsApplication.SmsApplicationData;
 import com.android.settings.AppListPreference;
+import com.android.settings.R;
 import com.android.settings.SelfAvailablePreference;
+import com.android.settings.Utils;
 
 import java.util.Collection;
 import java.util.Objects;
 
 public class DefaultSmsPreference extends AppListPreference implements SelfAvailablePreference {
-
     public DefaultSmsPreference(Context context, AttributeSet attrs) {
         super(context, attrs);
-
         loadSmsApps();
     }
 
@@ -60,6 +61,12 @@
     }
 
     @Override
+    protected CharSequence getConfirmationMessage(String value) {
+        return Utils.isPackageDirectBootAware(getContext(), value) ? null
+                : getContext().getText(R.string.direct_boot_unaware_dialog_message);
+    }
+
+    @Override
     protected boolean persistString(String value) {
         if (!TextUtils.isEmpty(value) && !Objects.equals(value, getDefaultPackage())) {
             SmsApplication.setDefaultApplication(value, getContext());
diff --git a/src/com/android/settings/dashboard/SupportItemAdapter.java b/src/com/android/settings/dashboard/SupportItemAdapter.java
index c5ff2a6..4ee28c6 100644
--- a/src/com/android/settings/dashboard/SupportItemAdapter.java
+++ b/src/com/android/settings/dashboard/SupportItemAdapter.java
@@ -23,6 +23,7 @@
 import android.app.DialogFragment;
 import android.content.Context;
 import android.content.Intent;
+import android.content.pm.PackageManager;
 import android.os.Bundle;
 import android.support.v7.widget.RecyclerView;
 import android.text.TextUtils;
@@ -136,7 +137,8 @@
     public void onItemClicked(int position) {
         if (position >= 0 && position < mSupportData.size()) {
             final SupportData data = mSupportData.get(position);
-            if (data.intent != null) {
+            if (data.intent != null &&
+                    mActivity.getPackageManager().resolveActivity(data.intent, 0) != null) {
                 if (data.metricsEvent >= 0) {
                     MetricsLogger.action(mActivity, data.metricsEvent);
                 }
@@ -283,18 +285,25 @@
 
     private void addMoreHelpItems() {
         mSupportData.add(new SupportData.Builder(mActivity, TYPE_SUPPORT_TILE_SPACER).build());
-        mSupportData.add(new SupportData.Builder(mActivity, TYPE_SUPPORT_TILE)
-                .setIcon(R.drawable.ic_help_24dp)
-                .setTileTitle(R.string.support_help_feedback_title)
-                .setIntent(mSupportFeatureProvider.getHelpIntent(mActivity))
-                .setMetricsEvent(MetricsProto.MetricsEvent.ACTION_SUPPORT_HELP_AND_FEEDBACK)
-                .build());
-        mSupportData.add(new SupportData.Builder(mActivity, TYPE_SUPPORT_TILE)
-                .setIcon(R.drawable.ic_lightbulb_outline_24)
-                .setTileTitle(R.string.support_tips_and_tricks_title)
-                .setIntent(mSupportFeatureProvider.getTipsAndTricksIntent(mActivity))
-                .setMetricsEvent(MetricsProto.MetricsEvent.ACTION_SUPPORT_TIPS_AND_TRICKS)
-                .build());
+        PackageManager packageManager = mActivity.getPackageManager();
+        Intent intent = mSupportFeatureProvider.getHelpIntent(mActivity);
+        if (packageManager.resolveActivity(intent, 0) != null) {
+            mSupportData.add(new SupportData.Builder(mActivity, TYPE_SUPPORT_TILE)
+                    .setIcon(R.drawable.ic_help_24dp)
+                    .setTileTitle(R.string.support_help_feedback_title)
+                    .setIntent(intent)
+                    .setMetricsEvent(MetricsProto.MetricsEvent.ACTION_SUPPORT_HELP_AND_FEEDBACK)
+                    .build());
+        }
+        intent = mSupportFeatureProvider.getTipsAndTricksIntent(mActivity);
+        if (packageManager.resolveActivity(intent, 0) != null) {
+            mSupportData.add(new SupportData.Builder(mActivity, TYPE_SUPPORT_TILE)
+                    .setIcon(R.drawable.ic_lightbulb_outline_24)
+                    .setTileTitle(R.string.support_tips_and_tricks_title)
+                    .setIntent(intent)
+                    .setMetricsEvent(MetricsProto.MetricsEvent.ACTION_SUPPORT_TIPS_AND_TRICKS)
+                    .build());
+        }
     }
 
     private void bindEscalationOptions(ViewHolder holder, EscalationData data) {
diff --git a/src/com/android/settings/dashboard/conditional/Condition.java b/src/com/android/settings/dashboard/conditional/Condition.java
index 1d48d5d..758632e 100644
--- a/src/com/android/settings/dashboard/conditional/Condition.java
+++ b/src/com/android/settings/dashboard/conditional/Condition.java
@@ -38,6 +38,12 @@
     // All conditions must live in this package.
     Condition(ConditionManager manager) {
         mManager = manager;
+        Class<?> receiverClass = getReceiverClass();
+        if (receiverClass != null && shouldAlwaysListenToBroadcast()) {
+            PackageManager pm = mManager.getContext().getPackageManager();
+            pm.setComponentEnabledSetting(new ComponentName(mManager.getContext(), receiverClass),
+                    PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0 /* flag */);
+        }
     }
 
     void restoreState(PersistableBundle bundle) {
@@ -93,6 +99,10 @@
     }
 
     private void onSilenceChanged(boolean silenced) {
+        if (shouldAlwaysListenToBroadcast()) {
+            // Don't try to disable BroadcastReceiver if we want it always on.
+            return;
+        }
         Class<?> clz = getReceiverClass();
         if (clz == null) {
             return;
@@ -109,6 +119,10 @@
         return null;
     }
 
+    protected boolean shouldAlwaysListenToBroadcast() {
+        return false;
+    }
+
     public boolean shouldShow() {
         return isActive() && !isSilenced();
     }
diff --git a/src/com/android/settings/dashboard/conditional/DndCondition.java b/src/com/android/settings/dashboard/conditional/DndCondition.java
index 2a5aa8a..dcab279 100644
--- a/src/com/android/settings/dashboard/conditional/DndCondition.java
+++ b/src/com/android/settings/dashboard/conditional/DndCondition.java
@@ -26,6 +26,7 @@
 import android.provider.Settings;
 import android.provider.Settings.Global;
 import android.service.notification.ZenModeConfig;
+
 import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.android.settings.R;
 
@@ -143,4 +144,9 @@
             }
         }
     }
+
+    @Override
+    protected boolean shouldAlwaysListenToBroadcast() {
+        return true;
+    }
 }
diff --git a/src/com/android/settings/deviceinfo/ImeiInformation.java b/src/com/android/settings/deviceinfo/ImeiInformation.java
index 7145212..9ea54ea 100644
--- a/src/com/android/settings/deviceinfo/ImeiInformation.java
+++ b/src/com/android/settings/deviceinfo/ImeiInformation.java
@@ -21,8 +21,13 @@
 import android.support.v7.preference.PreferenceScreen;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
+import android.text.Spannable;
+import android.text.SpannableString;
+import android.text.SpannableStringBuilder;
+import android.text.Spanned;
 import android.text.TextUtils;
 
+import android.text.style.TtsSpan;
 import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
@@ -80,7 +85,7 @@
                 if (phone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE) {
                     // Show ICC ID and IMEI for LTE device
                     setSummaryText(KEY_ICC_ID, phone.getIccSerialNumber());
-                    setSummaryText(KEY_IMEI, phone.getImei());
+                    setSummaryTextAsDigit(KEY_IMEI, phone.getImei());
                 } else {
                     // device is not GSM/UMTS, do not display GSM/UMTS features
                     // check Null in case no specified preference in overlay xml
@@ -88,8 +93,8 @@
                     removePreferenceFromScreen(KEY_ICC_ID);
                 }
             } else {
-                setSummaryText(KEY_IMEI, phone.getImei());
-                setSummaryText(KEY_IMEI_SV, phone.getDeviceSvn());
+                setSummaryTextAsDigit(KEY_IMEI, phone.getImei());
+                setSummaryTextAsDigit(KEY_IMEI_SV, phone.getDeviceSvn());
                 // device is not CDMA, do not display CDMA features
                 // check Null in case no specified preference in overlay xml
                 removePreferenceFromScreen(KEY_PRL_VERSION);
@@ -128,10 +133,23 @@
     }
 
     private void setSummaryText(String key, String text) {
+        setSummaryText(key, text, false /* forceDigit */);
+    }
+
+    private void setSummaryTextAsDigit(String key, String text) {
+        setSummaryText(key, text, true /* forceDigit */);
+    }
+
+    private void setSummaryText(String key, CharSequence text, boolean forceDigit) {
         final Preference preference = findPreference(key);
 
         if (TextUtils.isEmpty(text)) {
             text = getResources().getString(R.string.device_info_default);
+        } else if (forceDigit && TextUtils.isDigitsOnly(text)) {
+            final Spannable spannable = new SpannableStringBuilder(text);
+            final TtsSpan span = new TtsSpan.DigitsBuilder(text.toString()).build();
+            spannable.setSpan(span, 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+            text = spannable;
         }
 
         if (preference != null) {
diff --git a/src/com/android/settings/deviceinfo/StorageSettings.java b/src/com/android/settings/deviceinfo/StorageSettings.java
index 8f0e91b..532c720 100644
--- a/src/com/android/settings/deviceinfo/StorageSettings.java
+++ b/src/com/android/settings/deviceinfo/StorageSettings.java
@@ -109,7 +109,9 @@
         mStorageManager = context.getSystemService(StorageManager.class);
         mStorageManager.registerListener(mStorageListener);
 
-        sTotalInternalStorage = mStorageManager.getPrimaryStorageSize();
+        if (sTotalInternalStorage <= 0) {
+            sTotalInternalStorage = mStorageManager.getPrimaryStorageSize();
+        }
 
         addPreferencesFromResource(R.xml.device_info_storage);
 
@@ -169,8 +171,11 @@
                 if (vol.isMountedReadable()) {
                     final File path = vol.getPath();
                     privateUsedBytes += path.getTotalSpace() - path.getFreeSpace();
-                    privateTotalBytes += sTotalInternalStorage > 0
-                            ? sTotalInternalStorage : path.getTotalSpace();
+                    if (sTotalInternalStorage > 0) {
+                        privateTotalBytes = sTotalInternalStorage;
+                    } else {
+                        privateTotalBytes += path.getTotalSpace();
+                    }
                 }
             } else if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
                 mExternalCategory.addPreference(
@@ -215,7 +220,6 @@
                 result.value, result.units));
         mInternalSummary.setSummary(getString(R.string.storage_volume_used_total,
                 Formatter.formatFileSize(context, privateTotalBytes)));
-
         if (mInternalCategory.getPreferenceCount() > 0) {
             getPreferenceScreen().addPreference(mInternalCategory);
         }
@@ -483,9 +487,12 @@
 
         private void updateSummary() {
             // TODO: Register listener.
-            StorageManager storageManager = mContext.getSystemService(StorageManager.class);
+            final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
+            if (sTotalInternalStorage <= 0) {
+                sTotalInternalStorage = storageManager.getPrimaryStorageSize();
+            }
             final List<VolumeInfo> volumes = storageManager.getVolumes();
-            long privateUsedBytes = 0;
+            long privateFreeBytes = 0;
             long privateTotalBytes = 0;
             for (VolumeInfo info : volumes) {
                 if (info.getType() != VolumeInfo.TYPE_PUBLIC
@@ -496,13 +503,14 @@
                 if (path == null) {
                     continue;
                 }
-                privateUsedBytes += path.getTotalSpace() - path.getFreeSpace();
                 if (info.getType() == VolumeInfo.TYPE_PRIVATE && sTotalInternalStorage > 0) {
                     privateTotalBytes = sTotalInternalStorage;
                 } else {
                     privateTotalBytes += path.getTotalSpace();
                 }
+                privateFreeBytes += path.getFreeSpace();
             }
+            long privateUsedBytes = privateTotalBytes - privateFreeBytes;
             mLoader.setSummary(this, mContext.getString(R.string.storage_summary,
                     Formatter.formatFileSize(mContext, privateUsedBytes),
                     Formatter.formatFileSize(mContext, privateTotalBytes)));
diff --git a/src/com/android/settings/display/NightDisplayPreference.java b/src/com/android/settings/display/NightDisplayPreference.java
index 73ecf49..38b57a2 100644
--- a/src/com/android/settings/display/NightDisplayPreference.java
+++ b/src/com/android/settings/display/NightDisplayPreference.java
@@ -15,7 +15,7 @@
 package com.android.settings.display;
 
 import android.content.Context;
-import android.support.v7.preference.Preference;
+import android.support.v14.preference.SwitchPreference;
 import android.util.AttributeSet;
 
 import com.android.internal.app.NightDisplayController;
@@ -25,7 +25,8 @@
 import java.util.Calendar;
 import java.util.TimeZone;
 
-public class NightDisplayPreference extends Preference implements NightDisplayController.Callback {
+public class NightDisplayPreference extends SwitchPreference
+        implements NightDisplayController.Callback {
 
     private NightDisplayController mController;
     private DateFormat mTimeFormatter;
diff --git a/src/com/android/settings/display/NightDisplaySettings.java b/src/com/android/settings/display/NightDisplaySettings.java
index 5048272..7eb1217 100644
--- a/src/com/android/settings/display/NightDisplaySettings.java
+++ b/src/com/android/settings/display/NightDisplaySettings.java
@@ -22,15 +22,13 @@
 import android.os.Bundle;
 import android.support.v7.preference.DropDownPreference;
 import android.support.v7.preference.Preference;
-import android.widget.Switch;
+import android.support.v7.preference.TwoStatePreference;
 import android.widget.TimePicker;
 
 import com.android.internal.app.NightDisplayController;
 import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.android.settings.R;
-import com.android.settings.SettingsActivity;
 import com.android.settings.SettingsPreferenceFragment;
-import com.android.settings.widget.SwitchBar;
 
 import java.text.DateFormat;
 import java.util.Calendar;
@@ -39,14 +37,13 @@
 /**
  * Settings screen for Night display.
  */
-public class NightDisplaySettings extends SettingsPreferenceFragment implements
-        NightDisplayController.Callback,
-        Preference.OnPreferenceChangeListener,
-        SwitchBar.OnSwitchChangeListener {
+public class NightDisplaySettings extends SettingsPreferenceFragment
+        implements NightDisplayController.Callback, Preference.OnPreferenceChangeListener {
 
     private static final String KEY_NIGHT_DISPLAY_AUTO_MODE = "night_display_auto_mode";
     private static final String KEY_NIGHT_DISPLAY_START_TIME = "night_display_start_time";
     private static final String KEY_NIGHT_DISPLAY_END_TIME = "night_display_end_time";
+    private static final String KEY_NIGHT_DISPLAY_ACTIVATED = "night_display_activated";
 
     private static final int DIALOG_START_TIME = 0;
     private static final int DIALOG_END_TIME = 1;
@@ -57,8 +54,7 @@
     private DropDownPreference mAutoModePreference;
     private Preference mStartTimePreference;
     private Preference mEndTimePreference;
-
-    private SwitchBar mSwitchBar;
+    private TwoStatePreference mActivatedPreference;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -81,6 +77,7 @@
         mAutoModePreference = (DropDownPreference) findPreference(KEY_NIGHT_DISPLAY_AUTO_MODE);
         mStartTimePreference = findPreference(KEY_NIGHT_DISPLAY_START_TIME);
         mEndTimePreference = findPreference(KEY_NIGHT_DISPLAY_END_TIME);
+        mActivatedPreference = (TwoStatePreference) findPreference(KEY_NIGHT_DISPLAY_ACTIVATED);
 
         mAutoModePreference.setEntries(new CharSequence[] {
                 getString(R.string.night_display_auto_mode_never),
@@ -93,15 +90,7 @@
                 String.valueOf(NightDisplayController.AUTO_MODE_TWILIGHT)
         });
         mAutoModePreference.setOnPreferenceChangeListener(this);
-    }
-
-    @Override
-    public void onActivityCreated(Bundle savedInstanceState) {
-        super.onActivityCreated(savedInstanceState);
-
-        mSwitchBar = ((SettingsActivity) getActivity()).getSwitchBar();
-        mSwitchBar.addOnSwitchChangeListener(this);
-        mSwitchBar.show();
+        mActivatedPreference.setOnPreferenceChangeListener(this);
     }
 
     @Override
@@ -168,7 +157,7 @@
 
     @Override
     public void onActivated(boolean activated) {
-        mSwitchBar.setChecked(activated);
+        mActivatedPreference.setChecked(activated);
     }
 
     @Override
@@ -201,20 +190,11 @@
     }
 
     @Override
-    public void onSwitchChanged(Switch switchView, boolean isChecked) {
-        // Attempt to update the NIGHT_DISPLAY_ACTIVATED setting if necessary.
-        final boolean isActivated = mController.isActivated();
-        if (isActivated != isChecked) {
-            if (mController.setActivated(isChecked)) {
-                switchView.setChecked(isActivated);
-            }
-        }
-    }
-
-    @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         if (preference == mAutoModePreference) {
             return mController.setAutoMode(Integer.parseInt((String) newValue));
+        } else if (preference == mActivatedPreference) {
+            return mController.setActivated((Boolean) newValue);
         }
         return false;
     }
diff --git a/src/com/android/settings/inputmethod/InputMethodPreference.java b/src/com/android/settings/inputmethod/InputMethodPreference.java
index 1d4fa67..2c27700 100755
--- a/src/com/android/settings/inputmethod/InputMethodPreference.java
+++ b/src/com/android/settings/inputmethod/InputMethodPreference.java
@@ -35,6 +35,7 @@
 
 import com.android.internal.inputmethod.InputMethodUtils;
 import com.android.settings.R;
+import com.android.settings.Utils;
 import com.android.settingslib.RestrictedLockUtils;
 import com.android.settingslib.RestrictedSwitchPreference;
 
@@ -142,18 +143,22 @@
         }
         if (isChecked()) {
             // Disable this IME.
-            setChecked(false);
-            mOnSaveListener.onSaveInputMethodPreference(this);
+            setCheckedInternal(false);
             return false;
         }
         if (InputMethodUtils.isSystemIme(mImi)) {
-            // Enable a system IME. No need to show a security warning dialog.
-            setChecked(true);
-            mOnSaveListener.onSaveInputMethodPreference(this);
-            return false;
+            // Enable a system IME. No need to show a security warning dialog,
+            // but we might need to prompt if it's not Direct Boot aware.
+            if (Utils.isPackageDirectBootAware(getContext(), mImi.getPackageName())) {
+                setCheckedInternal(true);
+            } else {
+                showDirectBootWarnDialog();
+            }
+        } else {
+            // Once security is confirmed, we might prompt if the IME isn't
+            // Direct Boot aware.
+            showSecurityWarnDialog();
         }
-        // Enable a 3rd party IME.
-        showSecurityWarnDialog(mImi);
         return false;
     }
 
@@ -218,7 +223,13 @@
                 subtypes, getContext(), mImi);
     }
 
-    private void showSecurityWarnDialog(final InputMethodInfo imi) {
+    private void setCheckedInternal(boolean checked) {
+        super.setChecked(checked);
+        mOnSaveListener.onSaveInputMethodPreference(InputMethodPreference.this);
+        notifyChanged();
+    }
+
+    private void showSecurityWarnDialog() {
         if (mDialog != null && mDialog.isShowing()) {
             mDialog.dismiss();
         }
@@ -226,25 +237,50 @@
         final AlertDialog.Builder builder = new AlertDialog.Builder(context);
         builder.setCancelable(true /* cancelable */);
         builder.setTitle(android.R.string.dialog_alert_title);
-        final CharSequence label = imi.getServiceInfo().applicationInfo.loadLabel(
+        final CharSequence label = mImi.getServiceInfo().applicationInfo.loadLabel(
                 context.getPackageManager());
         builder.setMessage(context.getString(R.string.ime_security_warning, label));
         builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
             @Override
             public void onClick(final DialogInterface dialog, final int which) {
-                // The user confirmed to enable a 3rd party IME.
-                setChecked(true);
-                mOnSaveListener.onSaveInputMethodPreference(InputMethodPreference.this);
-                notifyChanged();
+                // The user confirmed to enable a 3rd party IME, but we might
+                // need to prompt if it's not Direct Boot aware.
+                if (Utils.isPackageDirectBootAware(getContext(), mImi.getPackageName())) {
+                    setCheckedInternal(true);
+                } else {
+                    showDirectBootWarnDialog();
+                }
             }
         });
         builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
             @Override
             public void onClick(final DialogInterface dialog, final int which) {
                 // The user canceled to enable a 3rd party IME.
-                setChecked(false);
-                mOnSaveListener.onSaveInputMethodPreference(InputMethodPreference.this);
-                notifyChanged();
+                setCheckedInternal(false);
+            }
+        });
+        mDialog = builder.create();
+        mDialog.show();
+    }
+
+    private void showDirectBootWarnDialog() {
+        if (mDialog != null && mDialog.isShowing()) {
+            mDialog.dismiss();
+        }
+        final Context context = getContext();
+        final AlertDialog.Builder builder = new AlertDialog.Builder(context);
+        builder.setCancelable(true /* cancelable */);
+        builder.setMessage(context.getText(R.string.direct_boot_unaware_dialog_message));
+        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(final DialogInterface dialog, final int which) {
+                setCheckedInternal(true);
+            }
+        });
+        builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(final DialogInterface dialog, final int which) {
+                setCheckedInternal(false);
             }
         });
         mDialog = builder.create();