Merge remote-tracking branch 'goog/stage-aosp-master' into HEAD

Change-Id: I78a5ee131f28eca25d8e6c5879bec4e1c97cd43a
diff --git a/sip/res/values-bn/strings.xml b/sip/res/values-bn/strings.xml
index 17c698d..fc238ea 100644
--- a/sip/res/values-bn/strings.xml
+++ b/sip/res/values-bn/strings.xml
@@ -20,7 +20,7 @@
     <string name="sip_accounts" msgid="85559497282185405">"SIP অ্যাকাউন্টগুলি"</string>
     <string name="sip_accounts_title" msgid="2082527045326874519">"অ্যাকাউন্টগুলি"</string>
     <string name="sip_receive_calls" msgid="426678617137462173">"আগত কলগুলি গ্রহণ করুন"</string>
-    <string name="sip_receive_calls_summary" msgid="946161517528227523">"আরও বেশি ব্যাটারি লাইফ ব্যবহার করে"</string>
+    <string name="sip_receive_calls_summary" msgid="946161517528227523">"আরো বেশি ব্যাটারি লাইফ ব্যবহার করে"</string>
     <string name="sip_call_options_title" msgid="8421210494703869806">"SIP কলিং ব্যবহার করুন"</string>
     <string name="sip_call_options_wifi_only_title" msgid="5112579243580893890">"SIP কলিং ব্যবহার করুন (শুধুমাত্র ওয়াই-ফাই)"</string>
     <string name="sip_call_options_entry_1" msgid="7217659161237099900">"যখন ডেটা নেটওয়ার্ক উপলব্ধ তখন সব কলের জন্য"</string>
@@ -31,7 +31,7 @@
     <string name="sip_account_list" msgid="5610858485304821480">"SIP অ্যাকাউন্টগুলি"</string>
     <string name="saving_account" msgid="5336529880235177448">"অ্যাকাউন্টটি সংরক্ষণ করা হচ্ছে ..."</string>
     <string name="removing_account" msgid="5537351356808985756">"অ্যাকাউন্টটি সরানো হচ্ছে…"</string>
-    <string name="sip_menu_save" msgid="7882219814563869225">"সেভ করুন"</string>
+    <string name="sip_menu_save" msgid="7882219814563869225">"সংরক্ষণ করুন"</string>
     <string name="sip_menu_discard" msgid="2350421645423888438">"খারিজ করুন"</string>
     <string name="alert_dialog_close" msgid="1326011828713435134">"প্রোফাইলটি বন্ধ করুন"</string>
     <string name="alert_dialog_ok" msgid="4752048404605388940">"ঠিক আছে"</string>
@@ -45,13 +45,13 @@
     <string name="registration_status_not_running" msgid="514205414303796800">"অ্যাকাউন্টের নিবন্ধন অসফল হয়েছে৷"</string>
     <string name="registration_status_done" msgid="3264961069247314253">"কলগুলি গ্রহণ করা হচ্ছে৷"</string>
     <string name="registration_status_failed_try_later" msgid="2199970021756384317">"অ্যাকাউন্টের নিবন্ধন অসফল হয়েছে: (<xliff:g id="REGISTRATION_ERROR_MESSAGE">%s</xliff:g>); পরে আবার চেষ্টা করা হবে"</string>
-    <string name="registration_status_invalid_credentials" msgid="8406872554323334182">"অ্যাকাউন্টের নিবন্ধন অসফল হয়েছে: ভুল ইউজারনেম বা পাসওয়ার্ড৷"</string>
+    <string name="registration_status_invalid_credentials" msgid="8406872554323334182">"অ্যাকাউন্টের নিবন্ধন অসফল হয়েছে: ভুল ব্যবহারকারী নাম বা পাসওয়ার্ড৷"</string>
     <string name="registration_status_server_unreachable" msgid="7710275557045148634">"অ্যাকাউন্টের নিবন্ধন অসফল হয়েছে: সার্ভারের নাম পরীক্ষা করুন৷"</string>
     <string name="third_party_account_summary" msgid="9041060473615403041">"এই অ্যাকাউন্টটি বর্তমানে <xliff:g id="ACCOUNT_OWNER">%s</xliff:g> অ্যাপ্লিকেশানের দ্বারা ব্যবহৃত হচ্ছে৷"</string>
     <string name="sip_edit_title" msgid="1967247832635750410">"SIP অ্যাকাউন্টের বিবরণ"</string>
     <string name="sip_edit_new_title" msgid="266414118302574305">"SIP অ্যাকাউন্টের বিবরণ"</string>
     <string name="domain_address_title" msgid="1968479941328225423">"সার্ভার"</string>
-    <string name="username_title" msgid="6770064611005663470">"ইউজারনেম"</string>
+    <string name="username_title" msgid="6770064611005663470">"ব্যবহারকারীর নাম"</string>
     <string name="password_title" msgid="5289013731515564295">"পাসওয়ার্ড"</string>
     <string name="display_name_title" msgid="579241787583079773">"প্রদর্শন নাম"</string>
     <string name="proxy_address_title" msgid="6890163365640631841">"বহির্গামী প্রক্সি ঠিকানা"</string>
@@ -59,8 +59,8 @@
     <string name="transport_title" msgid="889155457465372527">"পরিবহনের ধরন"</string>
     <string name="send_keepalive_title" msgid="599627072150501159">"সক্রিয়-রাখুন অনুরোধ পাঠান"</string>
     <string name="advanced_settings" msgid="6622996380747040711">"ঐচ্ছিক সেটিংস"</string>
-    <string name="auth_username_title" msgid="8262491689004708265">"প্রমাণীকরণের ইউজারনেম"</string>
-    <string name="auth_username_summary" msgid="941160241371436473">"প্রমাণীকরণের জন্য ব্যবহৃত ইউজারনেম"</string>
+    <string name="auth_username_title" msgid="8262491689004708265">"প্রমাণীকরণের ব্যবহারকারীর নাম"</string>
+    <string name="auth_username_summary" msgid="941160241371436473">"প্রমাণীকরণের জন্য ব্যবহৃত ব্যবহারকারী নাম"</string>
     <string name="default_preference_summary_username" msgid="8404717434312826082">"&lt;সেট করা নেই&gt;"</string>
     <string name="default_preference_summary_password" msgid="4464464672997027904">"&lt;সেট করা নেই&gt;"</string>
     <string name="default_preference_summary_domain_address" msgid="4871971710197441673">"&lt;সেট করা নেই&gt;"</string>
diff --git a/sip/res/values-in/strings.xml b/sip/res/values-in/strings.xml
index 1c59a30..c2f40b7 100644
--- a/sip/res/values-in/strings.xml
+++ b/sip/res/values-in/strings.xml
@@ -76,5 +76,5 @@
     <string name="no_voip" msgid="3038021971231952704">"Panggilan SIP tidak didukung"</string>
     <string name="sip_system_decide" msgid="5577696249416700671">"Otomatis"</string>
     <string name="sip_always_send_keepalive" msgid="4773022409239823318">"Selalu kirim"</string>
-    <string name="sip_connection_service_label" msgid="6935325004265884453">"Panggilan SIP built-in"</string>
+    <string name="sip_connection_service_label" msgid="6935325004265884453">"Panggilan SIP bawaan"</string>
 </resources>
diff --git a/sip/res/values-sk/strings.xml b/sip/res/values-sk/strings.xml
index a410294..872edcb 100644
--- a/sip/res/values-sk/strings.xml
+++ b/sip/res/values-sk/strings.xml
@@ -22,7 +22,7 @@
     <string name="sip_receive_calls" msgid="426678617137462173">"Prijímať prichádzajúce hovory"</string>
     <string name="sip_receive_calls_summary" msgid="946161517528227523">"Viac vybíja batériu"</string>
     <string name="sip_call_options_title" msgid="8421210494703869806">"Používanie volania SIP"</string>
-    <string name="sip_call_options_wifi_only_title" msgid="5112579243580893890">"Používanie volania SIP (iba Wi‑Fi)"</string>
+    <string name="sip_call_options_wifi_only_title" msgid="5112579243580893890">"Používanie volania SIP (iba Wi-Fi)"</string>
     <string name="sip_call_options_entry_1" msgid="7217659161237099900">"Pre všetky hovory, pokiaľ je k dispozícii dátová sieť"</string>
     <string name="sip_call_options_entry_2" msgid="1815335903940609729">"Iba pre hovory SIP"</string>
     <string name="sip_call_options_wifi_only_entry_1" msgid="1358513095551847314">"Pre všetky hovory"</string>
@@ -41,7 +41,7 @@
     <string name="registration_status_still_trying" msgid="7648151061205513458">"Prebiehajú ďalšie pokusy..."</string>
     <string name="registration_status_not_receiving" msgid="7620333886153361090">"Hovory sa neprijímajú."</string>
     <string name="registration_status_no_data" msgid="2541999976218192413">"Registrácia účtu bola zastavená, pretože pripojenie k internetu nie je k dispozícii."</string>
-    <string name="registration_status_no_wifi_data" msgid="9154717387473039546">"Registrácia účtu bola zastavená, pretože pripojenie Wi‑Fi nie je k dispozícii."</string>
+    <string name="registration_status_no_wifi_data" msgid="9154717387473039546">"Registrácia účtu bola zastavená, pretože pripojenie Wi-Fi nie je k dispozícii."</string>
     <string name="registration_status_not_running" msgid="514205414303796800">"Registrácia účtu nebola úspešná."</string>
     <string name="registration_status_done" msgid="3264961069247314253">"Príjem hovorov."</string>
     <string name="registration_status_failed_try_later" msgid="2199970021756384317">"Registrácia účtu nebola úspešná: (<xliff:g id="REGISTRATION_ERROR_MESSAGE">%s</xliff:g>); skúsime to neskôr"</string>
@@ -72,7 +72,7 @@
     <string name="empty_alert" msgid="6659484914371384024">"Pole <xliff:g id="INPUT_FIELD_NAME">%s</xliff:g> je povinné a nemôže zostať prázdne."</string>
     <string name="not_a_valid_port" msgid="7931422555587011830">"Číslo portu by malo byť od 1 000 do 65 534."</string>
     <string name="no_internet_available" msgid="5523747991760017298">"Ak chcete uskutočniť hovor SIP, najprv skontrolujte svoje internetové pripojenie."</string>
-    <string name="no_wifi_available" msgid="1955023904229673488">"Uskutočnenie hovorov SIP vyžaduje pripojenie k sieti Wi‑Fi (použite nastavenia bezdrôtovej siete)."</string>
+    <string name="no_wifi_available" msgid="1955023904229673488">"Uskutočnenie hovorov SIP vyžaduje pripojenie k sieti Wi-Fi (použite nastavenia bezdrôtovej siete)."</string>
     <string name="no_voip" msgid="3038021971231952704">"Volanie SIP nie je podporované"</string>
     <string name="sip_system_decide" msgid="5577696249416700671">"Automaticky"</string>
     <string name="sip_always_send_keepalive" msgid="4773022409239823318">"Vždy odoslať"</string>
diff --git a/src/com/android/phone/CarrierConfigLoader.java b/src/com/android/phone/CarrierConfigLoader.java
index a26e3d8..cbc2984 100644
--- a/src/com/android/phone/CarrierConfigLoader.java
+++ b/src/com/android/phone/CarrierConfigLoader.java
@@ -18,8 +18,6 @@
 
 import static android.Manifest.permission.READ_PHONE_STATE;
 import static android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE;
-import static android.service.carrier.CarrierService.ICarrierServiceWrapper.KEY_CONFIG_BUNDLE;
-import static android.service.carrier.CarrierService.ICarrierServiceWrapper.RESULT_ERROR;
 
 import android.annotation.NonNull;
 import android.app.ActivityManager;
@@ -34,13 +32,10 @@
 import android.content.pm.PackageManager;
 import android.os.Binder;
 import android.os.Build;
-import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.Message;
 import android.os.PersistableBundle;
-import android.os.RemoteException;
-import android.os.ResultReceiver;
 import android.os.ServiceManager;
 import android.os.UserHandle;
 import android.preference.PreferenceManager;
@@ -111,14 +106,14 @@
     private static final int EVENT_CONNECTED_TO_DEFAULT = 3;
     // Has connected to carrier app.
     private static final int EVENT_CONNECTED_TO_CARRIER = 4;
-    // Config has been loaded from default app (or cache).
-    private static final int EVENT_FETCH_DEFAULT_DONE = 5;
-    // Config has been loaded from carrier app (or cache).
-    private static final int EVENT_FETCH_CARRIER_DONE = 6;
+    // Config has been loaded from default app.
+    private static final int EVENT_LOADED_FROM_DEFAULT = 5;
+    // Config has been loaded from carrier app.
+    private static final int EVENT_LOADED_FROM_CARRIER = 6;
     // Attempt to fetch from default app or read from XML.
-    private static final int EVENT_DO_FETCH_DEFAULT = 7;
+    private static final int EVENT_FETCH_DEFAULT = 7;
     // Attempt to fetch from carrier app or read from XML.
-    private static final int EVENT_DO_FETCH_CARRIER = 8;
+    private static final int EVENT_FETCH_CARRIER = 8;
     // A package has been installed, uninstalled, or updated.
     private static final int EVENT_PACKAGE_CHANGED = 9;
     // Bind timed out for the default app.
@@ -129,10 +124,6 @@
     private static final int EVENT_CHECK_SYSTEM_UPDATE = 12;
     // Rerun carrier config binding after system is unlocked.
     private static final int EVENT_SYSTEM_UNLOCKED = 13;
-    // Fetching config timed out from the default app.
-    private static final int EVENT_FETCH_DEFAULT_TIMEOUT = 14;
-    // Fetching config timed out from a carrier app.
-    private static final int EVENT_FETCH_CARRIER_TIMEOUT = 15;
 
     private static final int BIND_TIMEOUT_MILLIS = 30000;
 
@@ -147,8 +138,8 @@
     // Handler to process various events.
     //
     // For each phoneId, the event sequence should be:
-    //     fetch default, connected to default, fetch default (async), fetch default done,
-    //     fetch carrier, connected to carrier, fetch carrier (async), fetch carrier done.
+    //     fetch default, connected to default, loaded from default,
+    //     fetch carrier, connected to carrier, loaded from carrier.
     //
     // If there is a saved config file for either the default app or the carrier app, we skip
     // binding to the app and go straight from fetch to loaded.
@@ -161,41 +152,52 @@
     // 2. loading from default app if there is no carrier app (even if read from a file)
     // 3. clearing config (e.g. due to sim removal)
     // 4. encountering bind or IPC error
-    private class ConfigHandler extends Handler {
-        @Override
+    private Handler mHandler = new Handler() {
+            @Override
         public void handleMessage(Message msg) {
-            final int phoneId = msg.arg1;
+            int phoneId = msg.arg1;
             log("mHandler: " + msg.what + " phoneId: " + phoneId);
+            String iccid;
+            CarrierIdentifier carrierId;
+            String carrierPackageName;
+            CarrierServiceConnection conn;
+            PersistableBundle config;
             switch (msg.what) {
                 case EVENT_CLEAR_CONFIG:
-                {
-                    if (mConfigFromDefaultApp[phoneId] == null
-                            && mConfigFromCarrierApp[phoneId] == null) break;
+
+                    /* Ignore clear configuration request if device is being shutdown. */
+                    Phone phone = PhoneFactory.getPhone(phoneId);
+                    if (phone != null) {
+                        if (phone.isShuttingDown()) {
+                            break;
+                        }
+                    }
+
+                    if (mConfigFromDefaultApp[phoneId] == null &&
+                        mConfigFromCarrierApp[phoneId] == null)
+                        break;
+
                     mConfigFromDefaultApp[phoneId] = null;
                     mConfigFromCarrierApp[phoneId] = null;
                     mServiceConnection[phoneId] = null;
                     broadcastConfigChangedIntent(phoneId);
                     break;
-                }
 
                 case EVENT_SYSTEM_UNLOCKED:
-                {
                     for (int i = 0; i < TelephonyManager.from(mContext).getPhoneCount(); ++i) {
-                        // When user unlock device, we should only try to send broadcast again if we
-                        // have sent it before unlock. This will avoid we try to load carrier config
-                        // when SIM is still loading when unlock happens.
+                        // When user unlock device, we should only try to send broadcast again if
+                        // we have sent it before unlock. This will avoid we try to load carrier
+                        // config when SIM is still loading when unlock happens.
                         if (mHasSentConfigChange[i]) {
                             updateConfigForPhoneId(i);
                         }
                     }
                     break;
-                }
 
                 case EVENT_PACKAGE_CHANGED:
-                {
-                    final String carrierPackageName = (String) msg.obj;
-                    // Only update if there are cached config removed to avoid updating config for
-                    // unrelated packages.
+                    carrierPackageName = (String) msg.obj;
+                    // Only update if there are cached config removed to avoid updating config
+                    // for unrelated packages.
                     if (clearCachedConfigForPackage(carrierPackageName)) {
                         int numPhones = TelephonyManager.from(mContext).getPhoneCount();
                         for (int i = 0; i < numPhones; ++i) {
@@ -203,228 +205,132 @@
                         }
                     }
                     break;
-                }
 
-                case EVENT_DO_FETCH_DEFAULT:
-                {
-                    final String iccid = getIccIdForPhoneId(phoneId);
-                    final PersistableBundle config =
-                            restoreConfigFromXml(mPlatformCarrierConfigPackage, iccid);
+                case EVENT_FETCH_DEFAULT:
+                    iccid = getIccIdForPhoneId(phoneId);
+                    config = restoreConfigFromXml(mPlatformCarrierConfigPackage, iccid);
                     if (config != null) {
-                        log(
-                                "Loaded config from XML. package="
-                                        + mPlatformCarrierConfigPackage
-                                        + " phoneId="
-                                        + phoneId);
+                        log("Loaded config from XML. package=" + mPlatformCarrierConfigPackage
+                                + " phoneId=" + phoneId);
                         mConfigFromDefaultApp[phoneId] = config;
-                        Message newMsg = obtainMessage(EVENT_FETCH_DEFAULT_DONE, phoneId, -1);
+                        Message newMsg = obtainMessage(EVENT_LOADED_FROM_DEFAULT, phoneId, -1);
                         newMsg.getData().putBoolean("loaded_from_xml", true);
                         mHandler.sendMessage(newMsg);
                     } else {
-                        // No cached config, so fetch it from the default app.
-                        if (bindToConfigPackage(
-                                mPlatformCarrierConfigPackage,
-                                phoneId,
-                                EVENT_CONNECTED_TO_DEFAULT)) {
-                            sendMessageDelayed(
-                                    obtainMessage(EVENT_BIND_DEFAULT_TIMEOUT, phoneId, -1),
+                        if (bindToConfigPackage(mPlatformCarrierConfigPackage,
+                                phoneId, EVENT_CONNECTED_TO_DEFAULT)) {
+                            sendMessageDelayed(obtainMessage(EVENT_BIND_DEFAULT_TIMEOUT, phoneId, -1),
                                     BIND_TIMEOUT_MILLIS);
                         } else {
-                            // Send broadcast if bind fails.
+                            // Send bcast if bind fails
                             broadcastConfigChangedIntent(phoneId);
-                            // TODO: We *must* call unbindService even if bindService returns false.
-                            // (And possibly if SecurityException was thrown.)
                         }
                     }
                     break;
-                }
 
                 case EVENT_CONNECTED_TO_DEFAULT:
-                {
                     removeMessages(EVENT_BIND_DEFAULT_TIMEOUT);
-                    final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
+                    carrierId = getCarrierIdForPhoneId(phoneId);
+                    conn = (CarrierServiceConnection) msg.obj;
                     // If new service connection has been created, unbind.
                     if (mServiceConnection[phoneId] != conn || conn.service == null) {
                         mContext.unbindService(conn);
                         break;
                     }
-                    final CarrierIdentifier carrierId = getCarrierIdForPhoneId(phoneId);
-                    final String iccid = getIccIdForPhoneId(phoneId);
-                    // ResultReceiver callback will execute in this Handler's thread.
-                    final ResultReceiver resultReceiver =
-                            new ResultReceiver(this) {
-                                @Override
-                                public void onReceiveResult(int resultCode, Bundle resultData) {
-                                    mContext.unbindService(conn);
-                                    // If new service connection has been created, this is stale.
-                                    if (mServiceConnection[phoneId] != conn) {
-                                        loge("Received response for stale request.");
-                                        return;
-                                    }
-                                    removeMessages(EVENT_FETCH_DEFAULT_TIMEOUT);
-                                    if (resultCode == RESULT_ERROR || resultData == null) {
-                                        // On error, abort config fetching.
-                                        loge("Failed to get carrier config");
-                                        broadcastConfigChangedIntent(phoneId);
-                                        return;
-                                    }
-                                    PersistableBundle config =
-                                            resultData.getParcelable(KEY_CONFIG_BUNDLE);
-                                    saveConfigToXml(
-                                            mPlatformCarrierConfigPackage, iccid, config);
-                                    mConfigFromDefaultApp[phoneId] = config;
-                                    sendMessage(
-                                            obtainMessage(
-                                                    EVENT_FETCH_DEFAULT_DONE, phoneId, -1));
-                                }
-                            };
-                    // Now fetch the config asynchronously from the ICarrierService.
                     try {
-                        ICarrierService carrierService =
-                                ICarrierService.Stub.asInterface(conn.service);
-                        carrierService.getCarrierConfig(carrierId, resultReceiver);
-                    } catch (RemoteException e) {
-                        loge("Failed to get carrier config: " + e.toString());
-                        mContext.unbindService(conn);
-                        break; // So we don't set a timeout.
+                        ICarrierService carrierService = ICarrierService.Stub
+                                .asInterface(conn.service);
+                        config = carrierService.getCarrierConfig(carrierId);
+                        iccid = getIccIdForPhoneId(phoneId);
+                        saveConfigToXml(mPlatformCarrierConfigPackage, iccid, config);
+                        mConfigFromDefaultApp[phoneId] = config;
+                        sendMessage(obtainMessage(EVENT_LOADED_FROM_DEFAULT, phoneId, -1));
+                    } catch (Exception ex) {
+                        // The bound app could throw exceptions that binder will pass to us.
+                        loge("Failed to get carrier config: " + ex.toString());
+                    } finally {
+                        mContext.unbindService(mServiceConnection[phoneId]);
                     }
-                    sendMessageDelayed(
-                            obtainMessage(EVENT_FETCH_DEFAULT_TIMEOUT, phoneId, -1),
-                            BIND_TIMEOUT_MILLIS);
                     break;
-                }
 
                 case EVENT_BIND_DEFAULT_TIMEOUT:
-                case EVENT_FETCH_DEFAULT_TIMEOUT:
-                {
-                    // If a ResponseReceiver callback is in the queue when this happens, we will
-                    // unbind twice and throw an exception.
                     mContext.unbindService(mServiceConnection[phoneId]);
-                    removeMessages(EVENT_FETCH_DEFAULT_TIMEOUT);
                     broadcastConfigChangedIntent(phoneId);
                     break;
-                }
 
-                case EVENT_FETCH_DEFAULT_DONE:
-                {
+                case EVENT_LOADED_FROM_DEFAULT:
                     // If we attempted to bind to the app, but the service connection is null, then
                     // config was cleared while we were waiting and we should not continue.
                     if (!msg.getData().getBoolean("loaded_from_xml", false)
                             && mServiceConnection[phoneId] == null) {
                         break;
                     }
-                    final String carrierPackageName = getCarrierPackageForPhoneId(phoneId);
+                    carrierPackageName = getCarrierPackageForPhoneId(phoneId);
                     if (carrierPackageName != null) {
                         log("Found carrier config app: " + carrierPackageName);
-                        sendMessage(obtainMessage(EVENT_DO_FETCH_CARRIER, phoneId));
+                        sendMessage(obtainMessage(EVENT_FETCH_CARRIER, phoneId));
                     } else {
                         broadcastConfigChangedIntent(phoneId);
                     }
                     break;
-                }
 
-                case EVENT_DO_FETCH_CARRIER:
-                {
-                    final String carrierPackageName = getCarrierPackageForPhoneId(phoneId);
-                    final String iccid = getIccIdForPhoneId(phoneId);
-                    final PersistableBundle config =
-                            restoreConfigFromXml(carrierPackageName, iccid);
+                case EVENT_FETCH_CARRIER:
+                    carrierPackageName = getCarrierPackageForPhoneId(phoneId);
+                    iccid = getIccIdForPhoneId(phoneId);
+                    config = restoreConfigFromXml(carrierPackageName, iccid);
                     if (config != null) {
-                        log(
-                                "Loaded config from XML. package="
-                                        + carrierPackageName
-                                        + " phoneId="
-                                        + phoneId);
+                        log("Loaded config from XML. package=" + carrierPackageName + " phoneId="
+                                + phoneId);
                         mConfigFromCarrierApp[phoneId] = config;
-                        Message newMsg = obtainMessage(EVENT_FETCH_CARRIER_DONE, phoneId, -1);
+                        Message newMsg = obtainMessage(EVENT_LOADED_FROM_CARRIER, phoneId, -1);
                         newMsg.getData().putBoolean("loaded_from_xml", true);
                         sendMessage(newMsg);
                     } else {
-                        // No cached config, so fetch it from a carrier app.
                         if (carrierPackageName != null
-                                && bindToConfigPackage(
-                                        carrierPackageName,
-                                        phoneId,
-                                        EVENT_CONNECTED_TO_CARRIER)) {
-                            sendMessageDelayed(
-                                    obtainMessage(EVENT_BIND_CARRIER_TIMEOUT, phoneId, -1),
+                            && bindToConfigPackage(carrierPackageName, phoneId,
+                                    EVENT_CONNECTED_TO_CARRIER)) {
+                            sendMessageDelayed(obtainMessage(EVENT_BIND_CARRIER_TIMEOUT, phoneId, -1),
                                     BIND_TIMEOUT_MILLIS);
                         } else {
-                            // Send broadcast if bind fails.
+                            // Send bcast if bind fails
                             broadcastConfigChangedIntent(phoneId);
                         }
                     }
                     break;
-                }
 
                 case EVENT_CONNECTED_TO_CARRIER:
-                {
                     removeMessages(EVENT_BIND_CARRIER_TIMEOUT);
-                    final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
+                    carrierId = getCarrierIdForPhoneId(phoneId);
+                    conn = (CarrierServiceConnection) msg.obj;
                     // If new service connection has been created, unbind.
-                    if (mServiceConnection[phoneId] != conn || conn.service == null) {
+                    if (mServiceConnection[phoneId] != conn ||
+                            conn.service == null) {
                         mContext.unbindService(conn);
                         break;
                     }
-                    final CarrierIdentifier carrierId = getCarrierIdForPhoneId(phoneId);
-                    final String iccid = getIccIdForPhoneId(phoneId);
-                    // ResultReceiver callback will execute in this Handler's thread.
-                    final ResultReceiver resultReceiver =
-                            new ResultReceiver(this) {
-                                @Override
-                                public void onReceiveResult(int resultCode, Bundle resultData) {
-                                    mContext.unbindService(conn);
-                                    // If new service connection has been created, this is stale.
-                                    if (mServiceConnection[phoneId] != conn) {
-                                        loge("Received response for stale request.");
-                                        return;
-                                    }
-                                    removeMessages(EVENT_FETCH_CARRIER_TIMEOUT);
-                                    if (resultCode == RESULT_ERROR || resultData == null) {
-                                        // On error, abort config fetching.
-                                        loge("Failed to get carrier config");
-                                        broadcastConfigChangedIntent(phoneId);
-                                        return;
-                                    }
-                                    PersistableBundle config =
-                                            resultData.getParcelable(KEY_CONFIG_BUNDLE);
-                                    saveConfigToXml(
-                                            mPlatformCarrierConfigPackage, iccid, config);
-                                    mConfigFromCarrierApp[phoneId] = config;
-                                    sendMessage(
-                                            obtainMessage(
-                                                    EVENT_FETCH_CARRIER_DONE, phoneId, -1));
-                                }
-                            };
-                    // Now fetch the config asynchronously from the ICarrierService.
                     try {
-                        ICarrierService carrierService =
-                                ICarrierService.Stub.asInterface(conn.service);
-                        carrierService.getCarrierConfig(carrierId, resultReceiver);
-                    } catch (RemoteException e) {
-                        loge("Failed to get carrier config: " + e.toString());
-                        mContext.unbindService(conn);
-                        break; // So we don't set a timeout.
+                        ICarrierService carrierService = ICarrierService.Stub
+                                .asInterface(conn.service);
+                        config = carrierService.getCarrierConfig(carrierId);
+                        carrierPackageName = getCarrierPackageForPhoneId(phoneId);
+                        iccid = getIccIdForPhoneId(phoneId);
+                        saveConfigToXml(carrierPackageName, iccid, config);
+                        mConfigFromCarrierApp[phoneId] = config;
+                        sendMessage(obtainMessage(EVENT_LOADED_FROM_CARRIER, phoneId, -1));
+                    } catch (Exception ex) {
+                        // The bound app could throw exceptions that binder will pass to us.
+                        loge("Failed to get carrier config: " + ex.toString());
+                    } finally {
+                        mContext.unbindService(mServiceConnection[phoneId]);
                     }
-                    sendMessageDelayed(
-                            obtainMessage(EVENT_FETCH_CARRIER_TIMEOUT, phoneId, -1),
-                            BIND_TIMEOUT_MILLIS);
                     break;
-                }
 
                 case EVENT_BIND_CARRIER_TIMEOUT:
-                case EVENT_FETCH_CARRIER_TIMEOUT:
-                {
-                    // If a ResponseReceiver callback is in the queue when this happens, we will
-                    // unbind twice and throw an exception.
                     mContext.unbindService(mServiceConnection[phoneId]);
-                    removeMessages(EVENT_FETCH_CARRIER_TIMEOUT);
                     broadcastConfigChangedIntent(phoneId);
                     break;
-                }
 
-                case EVENT_FETCH_CARRIER_DONE:
-                {
+                case EVENT_LOADED_FROM_CARRIER:
                     // If we attempted to bind to the app, but the service connection is null, then
                     // config was cleared while we were waiting and we should not continue.
                     if (!msg.getData().getBoolean("loaded_from_xml", false)
@@ -433,32 +339,21 @@
                     }
                     broadcastConfigChangedIntent(phoneId);
                     break;
-                }
 
                 case EVENT_CHECK_SYSTEM_UPDATE:
-                {
                     SharedPreferences sharedPrefs =
                             PreferenceManager.getDefaultSharedPreferences(mContext);
                     final String lastFingerprint = sharedPrefs.getString(KEY_FINGERPRINT, null);
                     if (!Build.FINGERPRINT.equals(lastFingerprint)) {
-                        log(
-                                "Build fingerprint changed. old: "
-                                        + lastFingerprint
-                                        + " new: "
-                                        + Build.FINGERPRINT);
+                        log("Build fingerprint changed. old: "
+                                + lastFingerprint + " new: " + Build.FINGERPRINT);
                         clearCachedConfigForPackage(null);
-                        sharedPrefs
-                                .edit()
-                                .putString(KEY_FINGERPRINT, Build.FINGERPRINT)
-                                .apply();
+                        sharedPrefs.edit().putString(KEY_FINGERPRINT, Build.FINGERPRINT).apply();
                     }
                     break;
-                }
             }
         }
-    }
-
-    private final Handler mHandler;
+    };
 
     /**
      * Constructs a CarrierConfigLoader, registers it as a service, and registers a broadcast
@@ -468,7 +363,6 @@
         mContext = context;
         mPlatformCarrierConfigPackage =
                 mContext.getString(R.string.platform_carrier_config_package);
-        mHandler = new ConfigHandler();
 
         IntentFilter bootFilter = new IntentFilter();
         bootFilter.addAction(Intent.ACTION_BOOT_COMPLETED);
@@ -746,8 +640,7 @@
         }
     }
 
-    /**
-     * Read up to date config.
+    /** Read up to date config.
      *
      * This reads config bundles for the given phoneId. That means getting the latest bundle from
      * the default app and a privileged carrier app, if present. This will not bind to an app if we
@@ -760,7 +653,7 @@
                 getCarrierPackageForPhoneId(phoneId) == null) {
             mConfigFromCarrierApp[phoneId] = null;
         }
-        mHandler.sendMessage(mHandler.obtainMessage(EVENT_DO_FETCH_DEFAULT, phoneId, -1));
+        mHandler.sendMessage(mHandler.obtainMessage(EVENT_FETCH_DEFAULT, phoneId, -1));
     }
 
     @Override public
diff --git a/src/com/android/phone/GsmUmtsOptions.java b/src/com/android/phone/GsmUmtsOptions.java
index a68b1cb..f08aa06 100644
--- a/src/com/android/phone/GsmUmtsOptions.java
+++ b/src/com/android/phone/GsmUmtsOptions.java
@@ -21,7 +21,6 @@
 import android.preference.Preference;
 import android.preference.PreferenceFragment;
 import android.preference.PreferenceScreen;
-import android.preference.TwoStatePreference;
 import android.provider.Settings;
 import android.telephony.CarrierConfigManager;
 
diff --git a/src/com/android/phone/PhoneSearchIndexablesProvider.java b/src/com/android/phone/PhoneSearchIndexablesProvider.java
index ed3c7df..1cee227 100644
--- a/src/com/android/phone/PhoneSearchIndexablesProvider.java
+++ b/src/com/android/phone/PhoneSearchIndexablesProvider.java
@@ -102,7 +102,7 @@
         if (!mUserManager.isAdminUser()) {
             final String[] values = new String[]{"preferred_network_mode_key", "button_roaming_key",
                     "cdma_lte_data_service_key", "enabled_networks_key", "enhanced_4g_lte",
-                    "button_apn_key", "button_network_select_key", "carrier_settings_key",
+                    "button_apn_key", "button_carrier_sel_key", "carrier_settings_key",
                     "cdma_system_select_key", "esim_list_profile"};
             for (String nik : values) {
                 cursor.addRow(createNonIndexableRow(nik));