Merge pi-qpr1-release PQ1A.181105.017.A1 to pi-platform-release

Change-Id: I543f5e0c6944f66d07716511d41127f6c9af344a
diff --git a/res/values-da/strings.xml b/res/values-da/strings.xml
index f0dcb67..c71dc81 100644
--- a/res/values-da/strings.xml
+++ b/res/values-da/strings.xml
@@ -417,7 +417,7 @@
     <string name="menu_add" msgid="1882023737425114762">"Tilføj kontakt"</string>
     <string name="menu_edit" msgid="7143003705504672374">"Rediger kontakt"</string>
     <string name="menu_delete" msgid="3977150783449642851">"Slet kontakt"</string>
-    <string name="menu_dial" msgid="3223106222819685808">"Ring til kontaktperson"</string>
+    <string name="menu_dial" msgid="3223106222819685808">"Ring til kontakt"</string>
     <string name="get_pin2" msgid="8204677063922225311">"Angiv PIN2-kode"</string>
     <string name="name" msgid="7329028332786872378">"Navn"</string>
     <string name="number" msgid="7905950798349903858">"Nummer"</string>
@@ -596,9 +596,9 @@
     <string name="voicemail_number_not_set" msgid="6724904736891087856">"&lt;Ikke angivet&gt;"</string>
     <string name="other_settings" msgid="3672912580359716394">"Andre indstillinger for opkald"</string>
     <string name="calling_via_template" msgid="4839419581866928142">"Opkald via <xliff:g id="PROVIDER_NAME">%s</xliff:g>"</string>
-    <string name="contactPhoto" msgid="4713193418046639466">"billede af kontaktperson"</string>
+    <string name="contactPhoto" msgid="4713193418046639466">"billede af kontakt"</string>
     <string name="goPrivate" msgid="865837794424530980">"gør privat"</string>
-    <string name="selectContact" msgid="781975788478987237">"vælg kontaktperson"</string>
+    <string name="selectContact" msgid="781975788478987237">"vælg kontakt"</string>
     <string name="not_voice_capable" msgid="2739898841461577811">"Taleopkald understøttes ikke"</string>
     <string name="description_dial_button" msgid="7459705245418435351">"ring op"</string>
     <string name="voicemail_visual_voicemail_switch_title" msgid="5012622186976275457">"Visuel telefonsvarer"</string>
diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml
index 1701244..0b36431 100644
--- a/res/values-de/strings.xml
+++ b/res/values-de/strings.xml
@@ -376,9 +376,9 @@
     <item msgid="176474317493999285">"Nur Heimatnetz"</item>
     <item msgid="1205664026446156265">"Automatisch"</item>
   </string-array>
-    <string name="cdma_subscription_title" msgid="1162564010076763284">"CDMA-Abonnement"</string>
+    <string name="cdma_subscription_title" msgid="1162564010076763284">"CDMA-Abo"</string>
     <string name="cdma_subscription_summary" msgid="2530890766115781140">"Zwischen RUIM/SIM und NV wechseln"</string>
-    <string name="cdma_subscription_dialogtitle" msgid="2699527950523333110">"Abonnement"</string>
+    <string name="cdma_subscription_dialogtitle" msgid="2699527950523333110">"Abo"</string>
   <string-array name="cdma_subscription_choices">
     <item msgid="2258014151300708431">"RUIM/SIM"</item>
     <item msgid="5127722015571873880">"NV"</item>
diff --git a/res/values-gl/strings.xml b/res/values-gl/strings.xml
index 75b42f5..236362f 100644
--- a/res/values-gl/strings.xml
+++ b/res/values-gl/strings.xml
@@ -327,8 +327,8 @@
   </string-array>
     <string name="list_language_dtitle" msgid="5442908726538951934">"Idiomas"</string>
     <string name="enable_disable_local_weather" msgid="986967454867219114">"Tempo local"</string>
-    <string name="local_weather_enable" msgid="6199315114382448922">"Información meteorolóxica local activada"</string>
-    <string name="local_weather_disable" msgid="2510158089142626480">"Información meteorolóxica local desactivada"</string>
+    <string name="local_weather_enable" msgid="6199315114382448922">"O tempo local activado"</string>
+    <string name="local_weather_disable" msgid="2510158089142626480">"O tempo local desactivado"</string>
     <string name="enable_disable_atr" msgid="8339572391278872343">"Informes de tráfico de zona"</string>
     <string name="atr_enable" msgid="5541757457789181799">"Informes de tráfico de zona activados"</string>
     <string name="atr_disable" msgid="7085558154727596455">"Informes de tráfico de zona desactivados"</string>
diff --git a/res/values-hi/strings.xml b/res/values-hi/strings.xml
index eeeef06..8f41e8f 100644
--- a/res/values-hi/strings.xml
+++ b/res/values-hi/strings.xml
@@ -532,7 +532,7 @@
     <string name="hac_mode_summary" msgid="6833851160514929341">"श्रवण सहायक साधन संगतता चालू करें"</string>
     <string name="rtt_mode_title" msgid="6954652435543570121">"(आरटीटी) कॉल से रीयल-टाइम में मैसेज भेजें"</string>
     <string name="rtt_mode_summary" msgid="5146344277246544580">"वॉइस कॉल में मैसेज भेजने की अनुमति दें"</string>
-    <string name="rtt_mode_more_information" msgid="6080420780730383030">"आरटीटी उन कॉल करने वालों की मदद करता है, जो बधिर हैं, ऊंचा सुनते हैं, जिन्हें बोलने में दिक्कत है या जिनके लिए सिर्फ़ आवाज़ काफ़ी नहीं होती.&lt;br&gt; &lt;a href=<xliff:g id="URL">http://support.google.com/mobile?p=telephony_rtt</xliff:g>&gt;अधिक जानें&lt;/a&gt;\n       &lt;br&gt;&lt;br&gt; - आरटीटी कॉल, मैसेज लेख के रूप में सेव किए जाते हैं\n       &lt;br&gt; - वीडियो कॉल के लिए आरटीटी उपलब्ध नहीं है"</string>
+    <string name="rtt_mode_more_information" msgid="6080420780730383030">"आरटीटी उन कॉल करने वालों की मदद करता है, जो सुन नहीं सकते हैं, ऊंचा सुनते हैं, जिन्हें बोलने में दिक्कत है या जिनके लिए सिर्फ़ आवाज़ काफ़ी नहीं होती.&lt;br&gt; &lt;a href=<xliff:g id="URL">http://support.google.com/mobile?p=telephony_rtt</xliff:g>&gt;ज़्यादा  जानें&lt;/a&gt;\n       &lt;br&gt;&lt;br&gt; - आरटीटी कॉल, मैसेज लेख के रूप में सेव किए जाते हैं\n       &lt;br&gt; - वीडियो कॉल के लिए आरटीटी उपलब्ध नहीं है"</string>
   <string-array name="tty_mode_entries">
     <item msgid="512950011423868021">"TTY बंद"</item>
     <item msgid="3971695875449640648">"TTY पूर्ण"</item>
diff --git a/res/values-ne/strings.xml b/res/values-ne/strings.xml
index 6d473ce..6d6abe0 100644
--- a/res/values-ne/strings.xml
+++ b/res/values-ne/strings.xml
@@ -136,7 +136,7 @@
     <string name="close_dialog" msgid="2365884406356986917">"ठिक छ"</string>
     <string name="enable" msgid="7248657275000173526">"सकृय पार्नुहोस्"</string>
     <string name="disable" msgid="4678348128118573672">"निस्कृय पार्नुहोस्"</string>
-    <string name="change_num" msgid="239476305819844391">"अपडेट गर्नुहोस्"</string>
+    <string name="change_num" msgid="239476305819844391">"अद्यावधिक गर्नुहोस्"</string>
   <string-array name="clir_display_values">
     <item msgid="5560134294467334594">"नेटवर्क पूर्वनिर्धारित"</item>
     <item msgid="7876195870037833661">"सङ्ख्या लुकाउनुहोस्"</item>
diff --git a/res/values-sw/strings.xml b/res/values-sw/strings.xml
index 8e07fe3..6062313 100644
--- a/res/values-sw/strings.xml
+++ b/res/values-sw/strings.xml
@@ -90,7 +90,7 @@
     <string name="sum_loading_settings" msgid="1826692909391168620">"Mipangilio inapakia..."</string>
     <string name="sum_hide_caller_id" msgid="1071407020290873782">"Nambari imefichwa kwa simu unayopiga"</string>
     <string name="sum_show_caller_id" msgid="6768534125447290401">"Namba inaonekana kwa simu zinazopigwa"</string>
-    <string name="sum_default_caller_id" msgid="1954518825510901365">"Tumia mipangilio ya kiendesha chaguo msingi kuonyesha namba kwa simu zinazopigwa"</string>
+    <string name="sum_default_caller_id" msgid="1954518825510901365">"Tumia mipangilio ya kiendesha chaguomsingi kuonyesha namba kwa simu zinazopigwa"</string>
     <string name="labelCW" msgid="6120513814915920200">"Simu inayosubiri kupokewa"</string>
     <string name="sum_cw_enabled" msgid="8083061901633671397">"Wakati ninapokea simu, niarifu kuhusu simu zingine zinazoingia"</string>
     <string name="sum_cw_disabled" msgid="3648693907300104575">"Wakati ninapokea simu, niarifu kuhusu simu zingine zinazoingia"</string>
@@ -138,7 +138,7 @@
     <string name="disable" msgid="4678348128118573672">"Zima"</string>
     <string name="change_num" msgid="239476305819844391">"Sasisha"</string>
   <string-array name="clir_display_values">
-    <item msgid="5560134294467334594">"Chaguo msingi la mtandao"</item>
+    <item msgid="5560134294467334594">"Chaguomsingi la mtandao"</item>
     <item msgid="7876195870037833661">"Ficha nambari"</item>
     <item msgid="1108394741608734023">"Onyesha nambari"</item>
   </string-array>
diff --git a/sip/res/values-iw/strings.xml b/sip/res/values-iw/strings.xml
index edd8d64..2204e0a 100644
--- a/sip/res/values-iw/strings.xml
+++ b/sip/res/values-iw/strings.xml
@@ -26,7 +26,7 @@
     <string name="sip_call_options_entry_1" msgid="7217659161237099900">"לכל השיחות כאשר רשת הנתונים זמינה"</string>
     <string name="sip_call_options_entry_2" msgid="1815335903940609729">"‏עבור שיחות SIP בלבד"</string>
     <string name="sip_call_options_wifi_only_entry_1" msgid="1358513095551847314">"לכל השיחות"</string>
-    <string name="add_sip_account" msgid="800843669753980091">"הוסף חשבון"</string>
+    <string name="add_sip_account" msgid="800843669753980091">"חשבון חדש"</string>
     <string name="remove_sip_account" msgid="1367664438506503690">"הסר חשבון"</string>
     <string name="sip_account_list" msgid="5610858485304821480">"‏חשבונות SIP"</string>
     <string name="saving_account" msgid="5336529880235177448">"שומר את החשבון..."</string>
diff --git a/src/com/android/phone/CarrierConfigLoader.java b/src/com/android/phone/CarrierConfigLoader.java
index 0424a03..f216b79 100644
--- a/src/com/android/phone/CarrierConfigLoader.java
+++ b/src/com/android/phone/CarrierConfigLoader.java
@@ -72,6 +72,7 @@
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.lang.Math;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -137,6 +138,9 @@
 
     private static final int BIND_TIMEOUT_MILLIS = 30000;
 
+    // Length limit of gid1 for naming config file.
+    private static final int GID1_LENGTH_LIMIT = 20;
+
     // Tags used for saving and restoring XML documents.
     private static final String TAG_DOCUMENT = "carrier_config";
     private static final String TAG_VERSION = "package_version";
@@ -218,8 +222,9 @@
                 case EVENT_DO_FETCH_DEFAULT:
                 {
                     final String iccid = getIccIdForPhoneId(phoneId);
+                    final String gid1 = getGid1ForPhoneId(phoneId);
                     final PersistableBundle config =
-                            restoreConfigFromXml(mPlatformCarrierConfigPackage, iccid);
+                            restoreConfigFromXml(mPlatformCarrierConfigPackage, iccid, gid1);
                     if (config != null) {
                         log(
                                 "Loaded config from XML. package="
@@ -260,6 +265,7 @@
                     }
                     final CarrierIdentifier carrierId = getCarrierIdForPhoneId(phoneId);
                     final String iccid = getIccIdForPhoneId(phoneId);
+                    final String gid1 = getGid1ForPhoneId(phoneId);
                     // ResultReceiver callback will execute in this Handler's thread.
                     final ResultReceiver resultReceiver =
                             new ResultReceiver(this) {
@@ -280,8 +286,8 @@
                                     }
                                     PersistableBundle config =
                                             resultData.getParcelable(KEY_CONFIG_BUNDLE);
-                                    saveConfigToXml(
-                                            mPlatformCarrierConfigPackage, iccid, config);
+                                    saveConfigToXml(mPlatformCarrierConfigPackage,
+                                            iccid, gid1, config);
                                     mConfigFromDefaultApp[phoneId] = config;
                                     sendMessage(
                                             obtainMessage(
@@ -337,8 +343,9 @@
                 {
                     final String carrierPackageName = getCarrierPackageForPhoneId(phoneId);
                     final String iccid = getIccIdForPhoneId(phoneId);
+                    final String gid1 = getGid1ForPhoneId(phoneId);
                     final PersistableBundle config =
-                            restoreConfigFromXml(carrierPackageName, iccid);
+                            restoreConfigFromXml(carrierPackageName, iccid, gid1);
                     if (config != null) {
                         log(
                                 "Loaded config from XML. package="
@@ -378,6 +385,7 @@
                     }
                     final CarrierIdentifier carrierId = getCarrierIdForPhoneId(phoneId);
                     final String iccid = getIccIdForPhoneId(phoneId);
+                    final String gid1 = getGid1ForPhoneId(phoneId);
                     // ResultReceiver callback will execute in this Handler's thread.
                     final ResultReceiver resultReceiver =
                             new ResultReceiver(this) {
@@ -398,8 +406,8 @@
                                     }
                                     PersistableBundle config =
                                             resultData.getParcelable(KEY_CONFIG_BUNDLE);
-                                    saveConfigToXml(
-                                            getCarrierPackageForPhoneId(phoneId), iccid, config);
+                                    saveConfigToXml(getCarrierPackageForPhoneId(phoneId),
+                                            iccid, gid1, config);
                                     mConfigFromCarrierApp[phoneId] = config;
                                     sendMessage(
                                             obtainMessage(
@@ -601,6 +609,21 @@
         return phone.getIccSerialNumber();
     }
 
+    private String getGid1ForPhoneId(int phoneId) {
+        if (!SubscriptionManager.isValidPhoneId(phoneId)) {
+            return null;
+        }
+        Phone phone = PhoneFactory.getPhone(phoneId);
+        if (phone == null) {
+            return null;
+        }
+        String gid1 = phone.getGroupIdLevel1();
+        if (gid1 == null) {
+            return null;
+        }
+        return gid1.substring(0, Math.min(gid1.length(), GID1_LENGTH_LIMIT));
+    }
+
     /**
      * Writes a bundle to an XML file.
      *
@@ -612,9 +635,12 @@
      *
      * @param packageName the name of the package from which we fetched this bundle.
      * @param iccid the ICCID of the subscription for which this bundle was fetched.
+     * @param extras First 20 characters of gid1 of the subscription for which the bundle
+     *               was fetched.
      * @param config the bundle to be written. Null will be treated as an empty bundle.
      */
-    private void saveConfigToXml(String packageName, String iccid, PersistableBundle config) {
+    private void saveConfigToXml(String packageName, String iccid, String extras,
+            PersistableBundle config) {
         if (packageName == null || iccid == null) {
             loge("Cannot save config with null packageName or iccid.");
             return;
@@ -637,7 +663,8 @@
         FileOutputStream outFile = null;
         try {
             outFile = new FileOutputStream(
-                    new File(mContext.getFilesDir(), getFilenameForConfig(packageName, iccid)));
+                    new File(mContext.getFilesDir(), getFilenameForConfig(packageName,
+                            iccid, extras)));
             FastXmlSerializer out = new FastXmlSerializer();
             out.setOutput(outFile, "utf-8");
             out.startDocument("utf-8", true);
@@ -672,10 +699,13 @@
      *
      * @param packageName the name of the package from which we fetched this bundle.
      * @param iccid the ICCID of the subscription for which this bundle was fetched.
+     * @param extras First 20 characters of gid1 of the subscription for which the bundle
+     *               was fetched.
      * @return the bundle from the XML file. Returns null if there is no saved config, the saved
      *         version does not match, or reading config fails.
      */
-    private PersistableBundle restoreConfigFromXml(String packageName, String iccid) {
+    private PersistableBundle restoreConfigFromXml(String packageName, String iccid,
+            String extras) {
         final String version = getPackageVersion(packageName);
         if (version == null) {
             loge("Failed to get package version for: " + packageName);
@@ -690,7 +720,8 @@
         FileInputStream inFile = null;
         try {
             inFile = new FileInputStream(
-                    new File(mContext.getFilesDir(), getFilenameForConfig(packageName, iccid)));
+                    new File(mContext.getFilesDir(), getFilenameForConfig(packageName, iccid,
+                            extras)));
             XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
             parser.setInput(inFile, "utf-8");
 
@@ -753,7 +784,11 @@
     }
 
     /** Builds a canonical file name for a config file. */
-    private String getFilenameForConfig(@NonNull String packageName, @NonNull String iccid) {
+    private String getFilenameForConfig(@NonNull String packageName, @NonNull String iccid,
+            String extras) {
+        if (extras != null) {
+            return "carrierconfig-" + packageName + "-" + iccid + "-" + extras + ".xml";
+        }
         return "carrierconfig-" + packageName + "-" + iccid + ".xml";
     }
 
diff --git a/src/com/android/phone/GsmUmtsAdditionalCallOptions.java b/src/com/android/phone/GsmUmtsAdditionalCallOptions.java
index 082eaa9..b79cdd8 100644
--- a/src/com/android/phone/GsmUmtsAdditionalCallOptions.java
+++ b/src/com/android/phone/GsmUmtsAdditionalCallOptions.java
@@ -2,8 +2,10 @@
 
 import android.app.ActionBar;
 import android.os.Bundle;
+import android.os.PersistableBundle;
 import android.preference.Preference;
 import android.preference.PreferenceScreen;
+import android.telephony.CarrierConfigManager;
 import android.util.Log;
 import android.view.MenuItem;
 
@@ -26,6 +28,9 @@
     private Phone mPhone;
     private SubscriptionInfoHelper mSubscriptionInfoHelper;
 
+    private boolean mShowCLIRButton;
+    private boolean mShowCWButton;
+
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
@@ -41,24 +46,60 @@
         mCLIRButton = (CLIRListPreference) prefSet.findPreference(BUTTON_CLIR_KEY);
         mCWButton = (CallWaitingSwitchPreference) prefSet.findPreference(BUTTON_CW_KEY);
 
-        mPreferences.add(mCLIRButton);
-        mPreferences.add(mCWButton);
-
-        if (icicle == null) {
-            if (DBG) Log.d(LOG_TAG, "start to init ");
-            mCLIRButton.init(this, false, mPhone);
+        PersistableBundle b = null;
+        if (mSubscriptionInfoHelper.hasSubId()) {
+            b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
+                    mSubscriptionInfoHelper.getSubId());
         } else {
-            if (DBG) Log.d(LOG_TAG, "restore stored states");
-            mInitIndex = mPreferences.size();
-            mCLIRButton.init(this, true, mPhone);
-            mCWButton.init(this, true, mPhone);
-            int[] clirArray = icicle.getIntArray(mCLIRButton.getKey());
-            if (clirArray != null) {
-                if (DBG) Log.d(LOG_TAG, "onCreate:  clirArray[0]="
-                        + clirArray[0] + ", clirArray[1]=" + clirArray[1]);
-                mCLIRButton.handleGetCLIRResult(clirArray);
+            b = PhoneGlobals.getInstance().getCarrierConfig();
+        }
+
+        if (b != null) {
+            mShowCLIRButton = b.getBoolean(
+                    CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALLER_ID_VISIBILITY_BOOL);
+            mShowCWButton = b.getBoolean(
+                    CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALL_WAITING_VISIBILITY_BOOL);
+        }
+
+        if (mCLIRButton != null) {
+            if (mShowCLIRButton) {
+                mPreferences.add(mCLIRButton);
             } else {
-                mCLIRButton.init(this, false, mPhone);
+                prefSet.removePreference(mCLIRButton);
+            }
+        }
+
+        if (mCWButton != null) {
+            if (mShowCWButton) {
+                mPreferences.add(mCWButton);
+            } else {
+                prefSet.removePreference(mCWButton);
+            }
+        }
+
+        if (mPreferences.size() != 0) {
+            if (icicle == null) {
+                if (DBG) Log.d(LOG_TAG, "start to init ");
+                doPreferenceInit(mInitIndex);
+            } else {
+                if (DBG) Log.d(LOG_TAG, "restore stored states");
+                mInitIndex = mPreferences.size();
+                if (mShowCWButton) {
+                    mCWButton.init(this, true, mPhone);
+                }
+                if (mShowCLIRButton) {
+                    mCLIRButton.init(this, true, mPhone);
+                    int[] clirArray = icicle.getIntArray(mCLIRButton.getKey());
+                    if (clirArray != null) {
+                        if (DBG) {
+                            Log.d(LOG_TAG, "onCreate:  clirArray[0]="
+                                    + clirArray[0] + ", clirArray[1]=" + clirArray[1]);
+                        }
+                        mCLIRButton.handleGetCLIRResult(clirArray);
+                    } else {
+                        mCLIRButton.init(this, false, mPhone);
+                    }
+                }
             }
         }
 
@@ -73,7 +114,7 @@
     protected void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
 
-        if (mCLIRButton.clirArray != null) {
+        if (mShowCLIRButton && mCLIRButton.clirArray != null) {
             outState.putIntArray(mCLIRButton.getKey(), mCLIRButton.clirArray);
         }
     }
@@ -82,10 +123,7 @@
     public void onFinished(Preference preference, boolean reading) {
         if (mInitIndex < mPreferences.size()-1 && !isFinishing()) {
             mInitIndex++;
-            Preference pref = mPreferences.get(mInitIndex);
-            if (pref instanceof CallWaitingSwitchPreference) {
-                ((CallWaitingSwitchPreference) pref).init(this, false, mPhone);
-            }
+            doPreferenceInit(mInitIndex);
         }
         super.onFinished(preference, reading);
     }
@@ -99,4 +137,15 @@
         }
         return super.onOptionsItemSelected(item);
     }
+
+    private void doPreferenceInit(int index) {
+        if (mPreferences.size() != 0) {
+            Preference pref = mPreferences.get(index);
+            if (pref instanceof CallWaitingSwitchPreference) {
+                ((CallWaitingSwitchPreference) pref).init(this, false, mPhone);
+            } else if (pref instanceof CLIRListPreference) {
+                ((CLIRListPreference) pref).init(this, false, mPhone);
+            }
+        }
+    }
 }
diff --git a/src/com/android/phone/GsmUmtsCallOptions.java b/src/com/android/phone/GsmUmtsCallOptions.java
index 3b27d28..ab44b54 100644
--- a/src/com/android/phone/GsmUmtsCallOptions.java
+++ b/src/com/android/phone/GsmUmtsCallOptions.java
@@ -18,14 +18,12 @@
 
 import android.os.Bundle;
 import android.os.PersistableBundle;
-import android.preference.CheckBoxPreference;
 import android.preference.Preference;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceScreen;
 import android.telephony.CarrierConfigManager;
 import android.view.MenuItem;
 
-import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
 
 public class GsmUmtsCallOptions extends PreferenceActivity {
@@ -64,25 +62,45 @@
     }
 
     public static void init(PreferenceScreen prefScreen, SubscriptionInfoHelper subInfoHelper) {
-        Preference callForwardingPref = prefScreen.findPreference(CALL_FORWARDING_KEY);
-        callForwardingPref.setIntent(subInfoHelper.getIntent(GsmUmtsCallForwardOptions.class));
-
-        Preference additionalGsmSettingsPref =
-                prefScreen.findPreference(ADDITIONAL_GSM_SETTINGS_KEY);
-        additionalGsmSettingsPref.setIntent(
-                subInfoHelper.getIntent(GsmUmtsAdditionalCallOptions.class));
-
-        Preference callBarringPref = prefScreen.findPreference(CALL_BARRING_KEY);
         PersistableBundle b = null;
         if (subInfoHelper.hasSubId()) {
             b = PhoneGlobals.getInstance().getCarrierConfigForSubId(subInfoHelper.getSubId());
         } else {
             b = PhoneGlobals.getInstance().getCarrierConfig();
         }
-        if (b != null && b.getBoolean(CarrierConfigManager.KEY_CALL_BARRING_VISIBILITY_BOOL)) {
-            callBarringPref.setIntent(subInfoHelper.getIntent(GsmUmtsCallBarringOptions.class));
-        } else {
-            prefScreen.removePreference(callBarringPref);
+
+        Preference callForwardingPref = prefScreen.findPreference(CALL_FORWARDING_KEY);
+        if (callForwardingPref != null) {
+            if (b != null && b.getBoolean(
+                    CarrierConfigManager.KEY_CALL_FORWARDING_VISIBILITY_BOOL)) {
+                callForwardingPref.setIntent(
+                        subInfoHelper.getIntent(GsmUmtsCallForwardOptions.class));
+            } else {
+                prefScreen.removePreference(callForwardingPref);
+            }
+        }
+
+        Preference additionalGsmSettingsPref =
+                prefScreen.findPreference(ADDITIONAL_GSM_SETTINGS_KEY);
+        if (additionalGsmSettingsPref != null) {
+            if (b != null && (b.getBoolean(
+                    CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALL_WAITING_VISIBILITY_BOOL)
+                    || b.getBoolean(
+                    CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALLER_ID_VISIBILITY_BOOL))) {
+                additionalGsmSettingsPref.setIntent(
+                        subInfoHelper.getIntent(GsmUmtsAdditionalCallOptions.class));
+            } else {
+                prefScreen.removePreference(additionalGsmSettingsPref);
+            }
+        }
+
+        Preference callBarringPref = prefScreen.findPreference(CALL_BARRING_KEY);
+        if (callBarringPref != null) {
+            if (b != null && b.getBoolean(CarrierConfigManager.KEY_CALL_BARRING_VISIBILITY_BOOL)) {
+                callBarringPref.setIntent(subInfoHelper.getIntent(GsmUmtsCallBarringOptions.class));
+            } else {
+                prefScreen.removePreference(callBarringPref);
+            }
         }
     }
 }
diff --git a/src/com/android/phone/MobileNetworkSettings.java b/src/com/android/phone/MobileNetworkSettings.java
index 691d9ff..6a26f76 100644
--- a/src/com/android/phone/MobileNetworkSettings.java
+++ b/src/com/android/phone/MobileNetworkSettings.java
@@ -788,13 +788,6 @@
             int max = mSubscriptionManager.getActiveSubscriptionInfoCountMax();
             mActiveSubInfos = new ArrayList<SubscriptionInfo>(max);
 
-            IntentFilter intentFilter = new IntentFilter(
-                    TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
-            activity.registerReceiver(mPhoneChangeReceiver, intentFilter);
-
-            activity.getContentResolver().registerContentObserver(ENFORCE_MANAGED_URI, false,
-                    mDpcEnforcedContentObserver);
-
             Log.i(LOG_TAG, "onCreate:-");
         }
 
@@ -822,6 +815,10 @@
             @Override
             public void onReceive(Context context, Intent intent) {
                 Log.i(LOG_TAG, "onReceive:");
+                if (getActivity() == null || getContext() == null) {
+                    // Received broadcast and activity is in the process of being torn down.
+                    return;
+                }
                 // When the radio changes (ex: CDMA->GSM), refresh all options.
                 updateBody();
             }
@@ -835,6 +832,10 @@
             @Override
             public void onChange(boolean selfChange) {
                 Log.i(LOG_TAG, "DPC enforced onChange:");
+                if (getActivity() == null || getContext() == null) {
+                    // Received content change and activity is in the process of being torn down.
+                    return;
+                }
                 updateBody();
             }
         }
@@ -843,11 +844,6 @@
         public void onDestroy() {
             unbindNetworkQueryService();
             super.onDestroy();
-            if (getActivity() != null) {
-                getActivity().unregisterReceiver(mPhoneChangeReceiver);
-                getActivity().getContentResolver().unregisterContentObserver(
-                        mDpcEnforcedContentObserver);
-            }
         }
 
         @Override
@@ -884,6 +880,13 @@
 
             mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener);
 
+            final Context context = getActivity();
+            IntentFilter intentFilter = new IntentFilter(
+                    TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
+            context.registerReceiver(mPhoneChangeReceiver, intentFilter);
+            context.getContentResolver().registerContentObserver(ENFORCE_MANAGED_URI, false,
+                    mDpcEnforcedContentObserver);
+
             Log.i(LOG_TAG, "onResume:-");
 
         }
@@ -1220,6 +1223,10 @@
 
             mSubscriptionManager
                     .removeOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener);
+
+            final Context context = getActivity();
+            context.unregisterReceiver(mPhoneChangeReceiver);
+            context.getContentResolver().unregisterContentObserver(mDpcEnforcedContentObserver);
             if (DBG) log("onPause:-");
         }
 
diff --git a/src/com/android/phone/NetworkSelectListPreference.java b/src/com/android/phone/NetworkSelectListPreference.java
index 71a9dab..341ac8d 100644
--- a/src/com/android/phone/NetworkSelectListPreference.java
+++ b/src/com/android/phone/NetworkSelectListPreference.java
@@ -105,7 +105,8 @@
         new AsyncTask<Void, Void, List<String>>() {
             @Override
             protected List<String> doInBackground(Void... voids) {
-                return Arrays.asList(telephonyManager.getForbiddenPlmns());
+                String[] forbiddenPlmns = telephonyManager.getForbiddenPlmns();
+                return forbiddenPlmns != null ? Arrays.asList(forbiddenPlmns) : null;
             }
 
             @Override
diff --git a/src/com/android/phone/NetworkSelectSetting.java b/src/com/android/phone/NetworkSelectSetting.java
index 71162bb..0655a2e 100644
--- a/src/com/android/phone/NetworkSelectSetting.java
+++ b/src/com/android/phone/NetworkSelectSetting.java
@@ -160,7 +160,8 @@
         new AsyncTask<Void, Void, List<String>>() {
             @Override
             protected List<String> doInBackground(Void... voids) {
-                return Arrays.asList(mTelephonyManager.getForbiddenPlmns());
+                String[] forbiddenPlmns = mTelephonyManager.getForbiddenPlmns();
+                return forbiddenPlmns != null ? Arrays.asList(forbiddenPlmns) : null;
             }
 
             @Override
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index ae3ec4e..a327d88 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -1716,6 +1716,10 @@
         // registered cell info, so return a NULL country instead.
         final long identity = Binder.clearCallingIdentity();
         try {
+            if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
+                // Get default phone in this case.
+                phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
+            }
             final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
             // Todo: fix this when we can get the actual cellular network info when the device
             // is on IWLAN.
@@ -2745,15 +2749,6 @@
     }
 
     /**
-     * @return true if the IMS resolver is busy resolving a binding and should not be considered
-     * available, false if the IMS resolver is idle.
-     */
-    public boolean isResolvingImsBinding() {
-        enforceModifyPermission();
-        return PhoneFactory.getImsResolver().isResolvingBinding();
-    }
-
-    /**
      * Sets the ImsService Package Name that Telephony will bind to.
      *
      * @param slotId the slot ID that the ImsService should bind for.
@@ -3683,7 +3678,7 @@
         synchronized (mLastModemActivityInfo) {
             ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
                     null);
-            if (info != null) {
+            if (isModemActivityInfoValid(info)) {
                 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
                 for (int i = 0; i < mergedTxTimeMs.length; i++) {
                     mergedTxTimeMs[i] =
@@ -3712,6 +3707,25 @@
         result.send(0, bundle);
     }
 
+    // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
+    // less than total activity duration.
+    private boolean isModemActivityInfoValid(ModemActivityInfo info) {
+        if (info == null) {
+            return false;
+        }
+        int activityDurationMs =
+            (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
+        int totalTxTimeMs = 0;
+        for (int i = 0; i < info.getTxTimeMillis().length; i++) {
+            totalTxTimeMs += info.getTxTimeMillis()[i];
+        }
+        return (info.isValid()
+            && (info.getSleepTimeMillis() <= activityDurationMs)
+            && (info.getIdleTimeMillis() <= activityDurationMs)
+            && (info.getRxTimeMillis() <= activityDurationMs)
+            && (totalTxTimeMs <= activityDurationMs));
+    }
+
     /**
      * {@hide}
      * Returns the service state information on specified subscription.
diff --git a/src/com/android/services/telephony/TelecomAccountRegistry.java b/src/com/android/services/telephony/TelecomAccountRegistry.java
index 6c8dcaa..642af85 100644
--- a/src/com/android/services/telephony/TelecomAccountRegistry.java
+++ b/src/com/android/services/telephony/TelecomAccountRegistry.java
@@ -107,9 +107,31 @@
         }
 
         /**
+         * Trigger re-registration of this account.
+         */
+        public void reRegisterPstnPhoneAccount() {
+            PhoneAccount newAccount = buildPstnPhoneAccount(mIsEmergency, mIsDummy);
+            if (!newAccount.equals(mAccount)) {
+                Log.i(this, "reRegisterPstnPhoneAccount: subId: " + getSubId()
+                        + " - re-register due to account change.");
+                mTelecomManager.registerPhoneAccount(newAccount);
+                mAccount = newAccount;
+            } else {
+                Log.i(this, "reRegisterPstnPhoneAccount: subId: " + getSubId() + " - no change");
+            }
+        }
+
+        private PhoneAccount registerPstnPhoneAccount(boolean isEmergency, boolean isDummyAccount) {
+            PhoneAccount account = buildPstnPhoneAccount(mIsEmergency, mIsDummy);
+            // Register with Telecom and put into the account entry.
+            mTelecomManager.registerPhoneAccount(account);
+            return account;
+        }
+
+        /**
          * Registers the specified account with Telecom as a PhoneAccountHandle.
          */
-        private PhoneAccount registerPstnPhoneAccount(boolean isEmergency, boolean isDummyAccount) {
+        private PhoneAccount buildPstnPhoneAccount(boolean isEmergency, boolean isDummyAccount) {
             String dummyPrefix = isDummyAccount ? "Dummy " : "";
 
             // Build the Phone account handle.
@@ -312,9 +334,6 @@
                     .setGroupId(groupId)
                     .build();
 
-            // Register with Telecom and put into the account entry.
-            mTelecomManager.registerPhoneAccount(account);
-
             return account;
         }
 
@@ -322,6 +341,10 @@
             return mAccount != null ? mAccount.getAccountHandle() : null;
         }
 
+        public int getSubId() {
+            return mPhone.getSubId();
+        }
+
         /**
          * Determines from carrier configuration whether pausing of IMS video calls is supported.
          *
@@ -579,19 +602,27 @@
         }
     };
 
-    private final BroadcastReceiver mUserSwitchedReceiver = new BroadcastReceiver() {
+    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
-            Log.i(this, "User changed, re-registering phone accounts.");
+            if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
+                Log.i(this, "User changed, re-registering phone accounts.");
 
-            int userHandleId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
-            UserHandle currentUserHandle = new UserHandle(userHandleId);
-            mIsPrimaryUser = UserManager.get(mContext).getPrimaryUser().getUserHandle()
-                    .equals(currentUserHandle);
+                int userHandleId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
+                UserHandle currentUserHandle = new UserHandle(userHandleId);
+                mIsPrimaryUser = UserManager.get(mContext).getPrimaryUser().getUserHandle()
+                        .equals(currentUserHandle);
 
-            // Any time the user changes, re-register the accounts.
-            tearDownAccounts();
-            setupAccounts();
+                // Any time the user changes, re-register the accounts.
+                tearDownAccounts();
+                setupAccounts();
+            } else if (CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED.equals(
+                    intent.getAction())) {
+                Log.i(this, "Carrier-config changed, checking for phone account updates.");
+                int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
+                        SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+                handleCarrierConfigChange(subId);
+            }
         }
     };
 
@@ -814,8 +845,10 @@
 
         // Listen for user switches.  When the user switches, we need to ensure that if the current
         // use is not the primary user we disable video calling.
-        mContext.registerReceiver(mUserSwitchedReceiver,
-                new IntentFilter(Intent.ACTION_USER_SWITCHED));
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(Intent.ACTION_USER_SWITCHED);
+        filter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
+        mContext.registerReceiver(mReceiver, filter);
 
         // Listen to the RTT system setting so that we update it when the user flips it.
         ContentObserver rttUiSettingObserver = new ContentObserver(
@@ -951,4 +984,27 @@
             mAccounts.clear();
         }
     }
+
+    /**
+     * Handles changes to the carrier configuration which may impact a phone account.  There are
+     * some extras defined in the {@link PhoneAccount} which are based on carrier config options.
+     * Only checking for carrier config changes when the subscription is configured runs the risk of
+     * missing carrier config changes which happen later.
+     * @param subId The subid the carrier config changed for, if applicable.  Will be
+     *              {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} if not specified.
+     */
+    private void handleCarrierConfigChange(int subId) {
+        if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+            return;
+        }
+        synchronized (mAccountsLock) {
+            for (AccountEntry entry : mAccounts) {
+                if (entry.getSubId() == subId) {
+                    Log.d(this, "handleCarrierConfigChange: subId=%d, accountSubId=%d", subId,
+                            entry.getSubId());
+                    entry.reRegisterPstnPhoneAccount();
+                }
+            }
+        }
+    }
 }
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index d6fb3ad..db4cc10 100644
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -538,6 +538,7 @@
         @Override
         public void onRttModifyResponseReceived(int status) {
             updateConnectionProperties();
+            refreshConferenceSupported();
             if (status == RttModifyStatus.SESSION_MODIFY_REQUEST_SUCCESS) {
                 sendRttInitiationSuccess();
             } else {
@@ -554,7 +555,12 @@
 
         @Override
         public void onRttInitiated() {
-            updateConnectionProperties();
+            if (mOriginalConnection != null) {
+                // if mOriginalConnection is null, the properties will get set when
+                // mOriginalConnection gets set.
+                updateConnectionProperties();
+                refreshConferenceSupported();
+            }
             sendRttInitiationSuccess();
         }
 
@@ -563,6 +569,12 @@
             updateConnectionProperties();
             sendRttSessionRemotelyTerminated();
         }
+
+        @Override
+        public void onOriginalConnectionReplaced(
+                com.android.internal.telephony.Connection newConnection) {
+            setOriginalConnection(newConnection);
+        }
     };
 
     protected com.android.internal.telephony.Connection mOriginalConnection;
@@ -2117,6 +2129,9 @@
         if (mTreatAsEmergencyCall) {
             isConferenceSupported = false;
             Log.d(this, "refreshConferenceSupported = false; emergency call");
+        } else if (isRtt()) {
+            isConferenceSupported = false;
+            Log.d(this, "refreshConferenceSupported = false; rtt call");
         } else if (!isConferencingSupported || isIms && !isImsConferencingSupported) {
             isConferenceSupported = false;
             Log.d(this, "refreshConferenceSupported = false; carrier doesn't support conf.");