Check if InputMethodService is Direct Boot aware
am: 4e44a5ec8e

Change-Id: I53c8f33eeb6f02664a06a7b24e29e54f63725507
diff --git a/res/layout/dashboard_tile.xml b/res/layout/dashboard_tile.xml
index 1ec1730..0e06d18 100644
--- a/res/layout/dashboard_tile.xml
+++ b/res/layout/dashboard_tile.xml
@@ -19,7 +19,7 @@
     android:id="@+id/dashboard_tile"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:background="?android:attr/selectableItemBackground"
+    android:background="@drawable/selectable_card"
     android:gravity="center_vertical"
     android:minHeight="@dimen/dashboard_tile_minimum_height"
     android:clickable="true"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0e516f0..68691de 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -786,7 +786,7 @@
     <!-- Button text shown in fingerprint dialog that allows the user to delete the fingerprint template [CHAR LIMIT=22] -->
     <string name="security_settings_fingerprint_enroll_dialog_delete">Delete</string>
     <!-- Title shown in fingerprint enrollment dialog to begin enrollment [CHAR LIMIT=29]-->
-    <string name="security_settings_fingerprint_enroll_start_title">Let\u2019s start!</string>
+    <string name="security_settings_fingerprint_enroll_start_title">Let\u2019s start</string>
     <!-- Message shown in fingerprint enrollment dialog to begin enrollment [CHAR LIMIT=NONE] -->
     <string name="security_settings_fingerprint_enroll_start_message">Put your finger on the sensor and lift after you feel a vibration</string>
     <!-- Title shown in fingerprint enrollment dialog to repeat touching the fingerprint sensor [CHAR LIMIT=29] -->
@@ -1013,7 +1013,7 @@
     <string name="setup_lock_settings_picker_title" product="default">Protect your phone</string>
 
     <!-- Title for screen in setup wizard, prompting user to choose the their backup screen lock method [CHAR LIMIT=NONE] -->
-    <string name="setup_lock_settings_picker_fingerprint_message">Your fingerprint may be less secure than a strong pattern, PIN, or password. For added security, set up a backup screen lock.</string>
+    <string name="setup_lock_settings_picker_fingerprint_message">For added security, set up a backup screen lock.</string>
 
     <!-- Description text for screen in setup wizard asking user to set up screen lock, explaining to the user how setting up a screen lock protect them from losing data. (tablet) [CHAR LIMIT=NONE] -->
     <string name="setup_lock_settings_picker_message" product="tablet">Prevent others from using this tablet without your permission by activating device protection features. Choose the screen lock you want to use.</string>
diff --git a/src/com/android/settings/applications/ManageAssist.java b/src/com/android/settings/applications/ManageAssist.java
index 6fe966d..02875b6 100644
--- a/src/com/android/settings/applications/ManageAssist.java
+++ b/src/com/android/settings/applications/ManageAssist.java
@@ -76,7 +76,7 @@
         if (preference == mContextPref) {
             Settings.Secure.putInt(getContentResolver(), Settings.Secure.ASSIST_STRUCTURE_ENABLED,
                     (boolean) newValue ? 1 : 0);
-            postUpdateUi();
+            postGuardScreenshotPref();
             return true;
         }
         if (preference == mScreenshotPref) {
@@ -101,15 +101,23 @@
         return false;
     }
 
-    private void postUpdateUi() {
+    private void postGuardScreenshotPref() {
         mHandler.post(new Runnable() {
             @Override
             public void run() {
-                updateUi();
+                guardScreenshotPref();
             }
         });
     }
 
+    private void guardScreenshotPref() {
+        boolean isChecked = mContextPref.isChecked();
+        boolean screenshotPrefWasSet = Settings.Secure.getInt(
+                getContentResolver(), Settings.Secure.ASSIST_SCREENSHOT_ENABLED, 1) != 0;
+        mScreenshotPref.setEnabled(isChecked);
+        mScreenshotPref.setChecked(isChecked && screenshotPrefWasSet);
+    }
+
     private void updateUi() {
         mDefaultAssitPref.refreshAssistApps();
         mVoiceInputPref.refreshVoiceInputs();
@@ -131,9 +139,7 @@
             mVoiceInputPref.setAssistRestrict(currentAssist);
         }
 
-        mScreenshotPref.setEnabled(mContextPref.isChecked());
-        mScreenshotPref.setChecked(mContextPref.isChecked() && Settings.Secure.getInt(
-                getContentResolver(), Settings.Secure.ASSIST_SCREENSHOT_ENABLED, 1) != 0);
+        guardScreenshotPref();
     }
 
     private boolean isCurrentAssistVoiceService() {
diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java
index ca09e51..ecf6497 100644
--- a/src/com/android/settings/dashboard/DashboardAdapter.java
+++ b/src/com/android/settings/dashboard/DashboardAdapter.java
@@ -33,6 +33,7 @@
 import android.view.ViewGroup;
 import android.widget.ImageView;
 import android.widget.TextView;
+
 import com.android.internal.logging.MetricsLogger;
 import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.android.internal.util.ArrayUtils;
@@ -46,7 +47,6 @@
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
 
 public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.DashboardItemHolder>
         implements View.OnClickListener {
@@ -186,7 +186,6 @@
                         NS_SUGGESTION);
             }
         }
-        countItem(null, R.layout.dashboard_spacer, true, NS_SPACER);
         resetCount();
         for (int i = 0; mCategories != null && i < mCategories.size(); i++) {
             DashboardCategory category = mCategories.get(i);
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)));