Update summary and title strings for Settings Suggestions

Setting Suggestion messages have new strings for NDR.

Change-Id: I5e76e669fac91b61a2207bb2937c107c952768c0
Fixes: 30067406
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 3a3f567..cd988b0 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1708,7 +1708,7 @@
             <meta-data android:name="com.android.settings.require_feature"
                 android:value="android.hardware.fingerprint" />
             <meta-data android:name="com.android.settings.title"
-                android:resource="@string/suggested_lock_settings_title" />
+                android:resource="@string/suggested_fingerprint_lock_settings_title" />
             <meta-data android:name="com.android.settings.summary"
                 android:resource="@string/suggested_fingerprint_lock_settings_summary" />
         </activity>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b8b4273..5a4827e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -988,11 +988,14 @@
     <!-- Security Picker --><skip />
 
     <!-- Title for suggested actions for screen lock -->
-    <string name="suggested_lock_settings_title">Screen lock</string>
+    <string name="suggested_lock_settings_title">Set screen lock</string>
 
     <!-- Summary for suggested actions for screen lock -->
     <string name="suggested_lock_settings_summary">Protect your device</string>
 
+    <!-- Title for suggested actions for settings up a fingerprint lock -->
+    <string name="suggested_fingerprint_lock_settings_title">Use fingerprint</string>
+
     <!-- Summary for suggested actions for settings up a fingerprint lock -->
     <string name="suggested_fingerprint_lock_settings_summary">Unlock with your fingerprint</string>
 
@@ -7399,7 +7402,7 @@
     <string name="suggestion_additional_fingerprints">Add another fingerprint</string>
 
     <!-- Summary for suggestion adding more fingerprints [CHAR LIMIT=60] -->
-    <string name="suggestion_additional_fingerprints_summary">Unlock with a different fingerprint</string>
+    <string name="suggestion_additional_fingerprints_summary">Unlock with a different finger</string>
 
     <!-- Summary of battery saver when on [CHAR LIMIT=NONE] -->
     <string name="battery_saver_on_summary">On / <xliff:g name="automatic_state" example="Never turn on automatically">%1$s</xliff:g></string>
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/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);