Switch to a background thread pool

 Bug: 5019676
 Use a shared thread pool
 Eliminate some unnecessary use of AsyncTask (which has extra
 overhead compared to using a thread pool)

Change-Id: I01d6c84816a9c9705216c8fdb8ed8c990265626a
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index 2023ee6..8461d30 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -22,7 +22,6 @@
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
 import android.os.Build;
-import android.os.Looper;
 import android.os.Message;
 import android.preference.PreferenceManager;
 import android.provider.Browser;
@@ -104,10 +103,6 @@
     private AutofillHandler mAutofillHandler;
     private WeakHashMap<WebSettings, String> mCustomUserAgents;
     private static boolean sInitialized = false;
-    // Looper shared between some lightweight background operations
-    // Specifically, this is created on the thread that initializes browser settings
-    // and is then reused by CrashRecoveryHandler
-    private Looper mBackgroundLooper;
 
     // Cached values
     private int mPageCacheCapacity = 1;
@@ -134,7 +129,7 @@
         mCustomUserAgents = new WeakHashMap<WebSettings, String>();
         mPrefs.registerOnSharedPreferenceChangeListener(this);
         mAutofillHandler.asyncLoadFromDb();
-        new Thread(mSetupAndLoop, "BackgroundLooper").start();
+        BackgroundHandler.execute(mSetup);
     }
 
     public void setController(Controller controller) {
@@ -146,11 +141,6 @@
         }
     }
 
-    public Looper getBackgroundLooper() {
-        requireInitialization();
-        return mBackgroundLooper;
-    }
-
     public void startManagingSettings(WebSettings settings) {
         synchronized (mManagedSettings) {
             syncStaticSettings(settings);
@@ -159,7 +149,7 @@
         }
     }
 
-    private Runnable mSetupAndLoop = new Runnable() {
+    private Runnable mSetup = new Runnable() {
 
         @Override
         public void run() {
@@ -208,13 +198,10 @@
                     BrowserProvider.getClientId(mContext.getContentResolver()));
             }
 
-            Looper.prepare();
-            mBackgroundLooper = Looper.myLooper();
             synchronized (BrowserSettings.class) {
                 sInitialized = true;
                 BrowserSettings.class.notifyAll();
             }
-            Looper.loop();
         }
     };
 
@@ -525,6 +512,10 @@
         return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
     }
 
+    public SharedPreferences getPreferences() {
+        return mPrefs;
+    }
+
     // -----------------------------
     // getter/setters for accessibility_preferences.xml
     // -----------------------------