Merge "Back out of Home settings when penultimate home app is uninstalled" into klp-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 960f1c9..437fa14 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3631,7 +3631,7 @@
     <!-- Suggestion for exploring application info to stop or uninstall -->
     <string name="battery_sugg_apps_info">Stop or uninstall the app</string>
     <!-- [CHAR LIMIT=100] Suggestion for getting apps to consume less power due to GPS-->
-    <string name="battery_sugg_apps_gps">"Manually control GPS to prevent app from using it"</string>
+    <string name="battery_sugg_apps_gps">Select battery-saving mode</string>
     <!-- Suggestion for getting apps to consume less power -->
     <string name="battery_sugg_apps_settings">The app may offer settings to reduce battery use</string>
 
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 87feab7..eb98fec 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -523,8 +523,10 @@
      */
     @Override
     public void onBuildHeaders(List<Header> headers) {
-        loadHeadersFromResource(R.xml.settings_headers, headers);
-        updateHeaderList(headers);
+        if (!onIsHidingHeaders()) {
+            loadHeadersFromResource(R.xml.settings_headers, headers);
+            updateHeaderList(headers);
+        }
     }
 
     private void updateHeaderList(List<Header> target) {
@@ -662,6 +664,7 @@
                 }
             }
             accountHeaders.add(accHeader);
+            mAuthenticatorHelper.preloadDrawableForType(this, accountType);
         }
 
         // Sort by label
diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java
index 756705d..6724cc1 100644
--- a/src/com/android/settings/WirelessSettings.java
+++ b/src/com/android/settings/WirelessSettings.java
@@ -247,12 +247,7 @@
 
     private boolean isSmsSupported() {
         // Some tablet has sim card but could not do telephony operations. Skip those.
-        if (mTm.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
-            return false;
-        }
-        int simState = mTm.getSimState();
-        return simState != TelephonyManager.SIM_STATE_ABSENT &&
-                simState != TelephonyManager.SIM_STATE_UNKNOWN;
+        return (mTm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE);
     }
 
     @Override
diff --git a/src/com/android/settings/accounts/AuthenticatorHelper.java b/src/com/android/settings/accounts/AuthenticatorHelper.java
index eba785b..a164b8b 100644
--- a/src/com/android/settings/accounts/AuthenticatorHelper.java
+++ b/src/com/android/settings/accounts/AuthenticatorHelper.java
@@ -23,6 +23,7 @@
 import android.content.pm.PackageManager;
 import android.content.res.Resources;
 import android.graphics.drawable.Drawable;
+import android.os.AsyncTask;
 import android.util.Log;
 
 import java.util.ArrayList;
@@ -45,6 +46,16 @@
         return mEnabledAccountTypes.toArray(new String[mEnabledAccountTypes.size()]);
     }
 
+    public void preloadDrawableForType(final Context context, final String accountType) {
+        new AsyncTask<Void, Void, Void>() {
+            @Override
+            protected Void doInBackground(Void... params) {
+                getDrawableForType(context, accountType);
+                return null;
+            }
+        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
+    }
+
     /**
      * Gets an icon associated with a particular account type. If none found, return null.
      * @param accountType the type of account
@@ -52,15 +63,19 @@
      */
     public Drawable getDrawableForType(Context context, final String accountType) {
         Drawable icon = null;
-        if (mAccTypeIconCache.containsKey(accountType)) {
-            return mAccTypeIconCache.get(accountType);
+        synchronized (mAccTypeIconCache) {
+            if (mAccTypeIconCache.containsKey(accountType)) {
+                return mAccTypeIconCache.get(accountType);
+            }
         }
         if (mTypeToAuthDescription.containsKey(accountType)) {
             try {
                 AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType);
                 Context authContext = context.createPackageContext(desc.packageName, 0);
                 icon = authContext.getResources().getDrawable(desc.iconId);
-                mAccTypeIconCache.put(accountType, icon);
+                synchronized (mAccTypeIconCache) {
+                    mAccTypeIconCache.put(accountType, icon);
+                }
             } catch (PackageManager.NameNotFoundException e) {
             } catch (Resources.NotFoundException e) {
             }
diff --git a/src/com/android/settings/print/PrintJobSettingsFragment.java b/src/com/android/settings/print/PrintJobSettingsFragment.java
index 99499c8..b4d517d 100644
--- a/src/com/android/settings/print/PrintJobSettingsFragment.java
+++ b/src/com/android/settings/print/PrintJobSettingsFragment.java
@@ -153,10 +153,12 @@
 
         if (mPrintJob == null) {
             finish();
+            return;
         }
 
         if (mPrintJob.isCancelled() || mPrintJob.isCompleted()) {
             finish();
+            return;
         }
 
         PrintJobInfo info = mPrintJob.getInfo();