Merge "Persist user enable/disable setting through reboot." into mnc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 8e3638a..cddbc1a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -46,6 +46,11 @@
     <protected-broadcast android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />
     <protected-broadcast android:name="android.provider.Telephony.SMS_CB_RECEIVED" />
     <protected-broadcast android:name="android.provider.Telephony.SMS_EMERGENCY_CB_RECEIVED" />
+    <protected-broadcast android:name= "android.intent.action.stk.command" />
+    <protected-broadcast android:name= "android.intent.action.stk.session_end" />
+    <protected-broadcast android:name= "android.intent.action.stk.icc_status_change" />
+    <protected-broadcast android:name= "android.intent.action.stk.alpha_notify" />
+
 
     <uses-permission android:name="android.permission.BROADCAST_STICKY" />
     <uses-permission android:name="android.permission.CALL_PHONE" />
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e8dac11..ab074e4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -160,25 +160,6 @@
 
     <!-- Title for setting to select Wi-Fi call manager account -->
     <string name="wifi_calling">Wi-Fi calling</string>
-    <!-- Indication for option to not use a Wi-Fi call manager -->
-    <string name="wifi_calling_do_not_use">Do not use Wi-Fi calling</string>
-    <!-- Indication for option to not use a call assistant. -->
-    <string name="wifi_calling_do_not_use_call_assistant">Do not use call assistant</string>
-    <!-- Indication for option to not use a call assistant. -->
-    <string name="wifi_calling_call_assistant_none">None</string>
-    <!-- Label for selected Wi-Fi call manager -->
-    <string name="wifi_calling_call_assistant">Call assistant</string>
-    <!-- Label for switch setting to enable/disable the use of SIM call managers. -->
-    <string name="wifi_calling_use_call_assistant">Use call assistant</string>
-    <!-- Label for selectecting a Wi-Fi call manager -->
-    <string name="wifi_calling_select_call_assistant">Choose call assistant</string>
-    <!-- Summary for the label of a setting to select the SIM call managers to use.-->
-    <string name="wifi_calling_select_call_assistant_summary">Manage the networks used for calls with</string>
-    <!-- Summary for the label of a switch setting to enable/disable the use of SIM call managers. -->
-    <string name="wifi_calling_use_call_assistant_summary">Let apps or services manage networks used for calls</string>
-    <!-- Label for setting to configure the selected call assistant. -->
-    <string name="wifi_calling_call_assistant_configure">Configure</string>
-
     <!-- Built-in label for the default connection service setting. -->
     <string name="connection_service_default_label">Built-in connection service</string>
     <!-- Call settings screen, setting option name -->
@@ -1301,4 +1282,9 @@
        data was received.) [CHAR LIMIT=none] -->
     <string name="message_decode_error">There was an error while decoding the message.</string>
 
+    <!-- Call failure reason: SIM card and roaming capabilities have already been activated. [CHAR LIMIT=NONE]-->
+    <string name="callFailed_cdma_activation_">
+        A SIM card has activated your service and updated your phone\'s roaming capabilities.
+    </string>
+
 </resources>
diff --git a/res/xml/phone_account_settings.xml b/res/xml/phone_account_settings.xml
index f0458cd..27da54c 100644
--- a/res/xml/phone_account_settings.xml
+++ b/res/xml/phone_account_settings.xml
@@ -43,24 +43,6 @@
     </PreferenceCategory>
 
     <PreferenceCategory
-        android:key="phone_accounts_call_assistant_settings_category_key"
-        android:title="@string/wifi_calling_call_assistant"
-        android:persistent="false">
-
-        <com.android.phone.settings.AccountSelectionPreference
-            android:key="wifi_calling_call_assistant_preference"
-            android:title="@string/wifi_calling_call_assistant"
-            android:summary="@string/wifi_calling_call_assistant_none"
-            android:persistent="false" />
-
-        <Preference
-            android:key="wifi_calling_configure_call_assistant_preference"
-            android:title="@string/wifi_calling_call_assistant_configure"
-            android:persistent="false" />
-
-    </PreferenceCategory>
-
-    <PreferenceCategory
         android:key="phone_accounts_sip_settings_category_key"
         android:title="@string/sip_settings"
         android:persistent="false">
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index d3d9dcf..6a4034e 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -25,6 +25,8 @@
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
 import android.os.Bundle;
 import android.os.PersistableBundle;
 import android.os.UserHandle;
@@ -101,6 +103,7 @@
 
     private Phone mPhone;
     private SubscriptionInfoHelper mSubscriptionInfoHelper;
+    private TelecomManager mTelecomManager;
 
     private CheckBoxPreference mButtonAutoRetry;
     private PreferenceScreen mVoicemailSettingsScreen;
@@ -179,6 +182,7 @@
         mSubscriptionInfoHelper.setActionBarTitle(
                 getActionBar(), getResources(), R.string.call_settings_with_label);
         mPhone = mSubscriptionInfoHelper.getPhone();
+        mTelecomManager = TelecomManager.from(this);
     }
 
     @Override
@@ -192,12 +196,11 @@
 
         addPreferencesFromResource(R.xml.call_feature_setting);
 
-        TelecomManager telecomManager = TelecomManager.from(this);
         TelephonyManager telephonyManager =
                 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
 
         Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
-        if (telephonyManager.isMultiSimEnabled() || (telecomManager.getSimCallManagers().isEmpty()
+        if (telephonyManager.isMultiSimEnabled() || (mTelecomManager.getSimCallManagers().isEmpty()
                     && !SipUtil.isVoipSupported(mPhone.getContext()))) {
             getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
         }
@@ -243,7 +246,7 @@
                     prefSet.removePreference(fdnButton);
 
                     if (!carrierConfig.getBoolean(
-                            CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_BOOL)) {
+                            CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) {
                         addPreferencesFromResource(R.xml.cdma_call_privacy);
                     }
                 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
@@ -280,7 +283,29 @@
 
         Preference wifiCallingSettings = findPreference(
                 getResources().getString(R.string.wifi_calling_settings_key));
-        if (!ImsManager.isWfcEnabledByPlatform(mPhone.getContext())) {
+
+        final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManager();
+        String simCallManagerPackage = simCallManager != null
+                && simCallManager.getComponentName() != null
+                        ? simCallManager.getComponentName().getPackageName()
+                        : null;
+
+        if (!TextUtils.isEmpty(simCallManagerPackage)) {
+            final Intent intent = new Intent(TelecomManager.ACTION_CONNECTION_SERVICE_CONFIGURE)
+                    .addCategory(Intent.CATEGORY_DEFAULT)
+                    .setPackage(simCallManagerPackage);
+
+            // Check whether the configuration intent is supported.
+            PackageManager pm = getPackageManager();
+            List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
+            if (resolutions.size() > 0) {
+                wifiCallingSettings.setTitle(R.string.wifi_calling);
+                wifiCallingSettings.setSummary(null);
+                wifiCallingSettings.setIntent(intent);
+            } else {
+                prefSet.removePreference(wifiCallingSettings);
+            }
+        } else if (!ImsManager.isWfcEnabledByPlatform(mPhone.getContext())) {
             prefSet.removePreference(wifiCallingSettings);
         } else {
             int resId = com.android.internal.R.string.wifi_calling_off_summary;
diff --git a/src/com/android/phone/CdmaCallOptions.java b/src/com/android/phone/CdmaCallOptions.java
index 9131ad6..4a5f229 100644
--- a/src/com/android/phone/CdmaCallOptions.java
+++ b/src/com/android/phone/CdmaCallOptions.java
@@ -59,7 +59,7 @@
             carrierConfig = PhoneGlobals.getInstance().getCarrierConfig();
         }
         if (subInfoHelper.getPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_CDMA
-                || carrierConfig.getBoolean(CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_BOOL)) {
+                || carrierConfig.getBoolean(CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) {
             // disable the entire screen
             getPreferenceScreen().setEnabled(false);
         }
diff --git a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
index 86036ce..112610b 100644
--- a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
+++ b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
@@ -1,17 +1,12 @@
 package com.android.phone.settings;
 
-import android.content.ActivityNotFoundException;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
-import android.graphics.Bitmap;
-import android.graphics.PorterDuff;
-import android.graphics.drawable.Drawable;
 import android.graphics.drawable.Icon;
 import android.net.sip.SipManager;
 import android.os.Bundle;
-import android.os.UserHandle;
 import android.preference.CheckBoxPreference;
 import android.preference.ListPreference;
 import android.preference.Preference;
@@ -23,7 +18,6 @@
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
-import android.util.Log;
 
 import com.android.internal.telephony.Phone;
 import com.android.phone.PhoneUtils;
@@ -41,7 +35,6 @@
 
 public class PhoneAccountSettingsFragment extends PreferenceFragment
         implements Preference.OnPreferenceChangeListener,
-                Preference.OnPreferenceClickListener,
                 AccountSelectionPreference.AccountSelectionListener {
 
     private static final String ACCOUNTS_LIST_CATEGORY_KEY =
@@ -50,13 +43,6 @@
     private static final String DEFAULT_OUTGOING_ACCOUNT_KEY = "default_outgoing_account";
     private static final String ALL_CALLING_ACCOUNTS_KEY = "phone_account_all_calling_accounts";
 
-    private static final String CONFIGURE_CALL_ASSISTANT_PREF_KEY =
-            "wifi_calling_configure_call_assistant_preference";
-    private static final String CALL_ASSISTANT_CATEGORY_PREF_KEY =
-            "phone_accounts_call_assistant_settings_category_key";
-    private static final String SELECT_CALL_ASSISTANT_PREF_KEY =
-            "wifi_calling_call_assistant_preference";
-
     private static final String SIP_SETTINGS_CATEGORY_PREF_KEY =
             "phone_accounts_sip_settings_category_key";
     private static final String USE_SIP_PREF_KEY = "use_sip_calling_options_key";
@@ -79,8 +65,6 @@
     private PreferenceCategory mAccountList;
 
     private AccountSelectionPreference mDefaultOutgoingAccount;
-    private AccountSelectionPreference mSelectCallAssistant;
-    private Preference mConfigureCallAssistant;
 
     private ListPreference mUseSipCalling;
     private CheckBoxPreference mSipReceiveCallsPreference;
@@ -161,27 +145,6 @@
             getPreferenceScreen().removePreference(mAccountList);
         }
 
-        List<PhoneAccountHandle> simCallManagers = mTelecomManager.getSimCallManagers();
-        PreferenceCategory callAssistantCategory = (PreferenceCategory)
-                getPreferenceScreen().findPreference(CALL_ASSISTANT_CATEGORY_PREF_KEY);
-        if (simCallManagers.isEmpty()) {
-            getPreferenceScreen().removePreference(callAssistantCategory);
-        } else {
-            // Display a list of call assistants. Choosing an item from the list enables the
-            // corresponding call assistant.
-            mSelectCallAssistant = (AccountSelectionPreference)
-                    getPreferenceScreen().findPreference(SELECT_CALL_ASSISTANT_PREF_KEY);
-            mSelectCallAssistant.setListener(this);
-            mSelectCallAssistant.setDialogTitle(
-                    R.string.wifi_calling_select_call_assistant_summary);
-            updateCallAssistantModel();
-
-            mConfigureCallAssistant =
-                    getPreferenceScreen().findPreference(CONFIGURE_CALL_ASSISTANT_PREF_KEY);
-            mConfigureCallAssistant.setOnPreferenceClickListener(this);
-            updateConfigureCallAssistant();
-        }
-
         if (SipUtil.isVoipSupported(getActivity())) {
             mSipSharedPreferences = new SipSharedPreferences(getActivity());
 
@@ -243,30 +206,8 @@
         return false;
     }
 
-    @Override
-    public boolean onPreferenceClick(Preference pref) {
-        if (pref == mConfigureCallAssistant) {
-            Intent intent = getConfigureCallAssistantIntent();
-            if (intent != null) {
-                PhoneAccountHandle handle = mTelecomManager.getSimCallManager();
-                UserHandle userHandle = handle.getUserHandle();
-                try {
-                    if (userHandle != null) {
-                        getActivity().startActivityAsUser(intent, userHandle);
-                    } else {
-                        startActivity(intent);
-                    }
-                } catch (ActivityNotFoundException e) {
-                    Log.d(LOG_TAG, "Could not resolve call assistant configure intent: " + intent);
-                }
-            }
-            return true;
-        }
-        return false;
-    }
-
     /**
-     * Handles a phone account selection, namely when a call assistant has been selected.
+     * Handles a phone account selection for the default outgoing phone account.
      *
      * @param pref The account selection preference which triggered the account selected event.
      * @param account The account selected.
@@ -277,9 +218,6 @@
         if (pref == mDefaultOutgoingAccount) {
             mTelecomManager.setUserSelectedOutgoingPhoneAccount(account);
             return true;
-        } else if (pref == mSelectCallAssistant) {
-            mTelecomManager.setSimCallManager(account);
-            return true;
         }
         return false;
     }
@@ -293,21 +231,11 @@
     public void onAccountSelectionDialogShow(AccountSelectionPreference pref) {
         if (pref == mDefaultOutgoingAccount) {
             updateDefaultOutgoingAccountsModel();
-        } else if (pref == mSelectCallAssistant) {
-            updateCallAssistantModel();
-            updateConfigureCallAssistant();
         }
     }
 
-    /**
-     * Update the configure preference summary when the call assistant changes.
-     */
     @Override
-    public void onAccountChanged(AccountSelectionPreference pref) {
-        if (pref == mSelectCallAssistant) {
-            updateConfigureCallAssistant();
-        }
-    }
+    public void onAccountChanged(AccountSelectionPreference pref) {}
 
     private synchronized void handleSipReceiveCallsOption(boolean isEnabled) {
         Context context = getActivity();
@@ -337,34 +265,6 @@
                 getString(R.string.phone_accounts_ask_every_time));
     }
 
-    /**
-     * Queries the telecomm manager to update the account selection preference with the list of
-     * call assistants, and the currently selected call assistant.
-     */
-    public void updateCallAssistantModel() {
-        mSelectCallAssistant.setModel(
-                mTelecomManager, mTelecomManager.getSimCallManagers(),
-                mTelecomManager.getSimCallManager(),
-                getString(R.string.wifi_calling_call_assistant_none));
-    }
-
-    /**
-     * Shows or hides the "configure call assistant" preference.
-     */
-    private void updateConfigureCallAssistant() {
-        Intent intent = getConfigureCallAssistantIntent();
-        boolean shouldShow = intent != null && !getActivity().getPackageManager()
-            .queryIntentActivities(intent, 0).isEmpty();
-
-        PreferenceCategory callAssistantCategory = (PreferenceCategory)
-                getPreferenceScreen().findPreference(CALL_ASSISTANT_CATEGORY_PREF_KEY);
-        if (shouldShow) {
-            callAssistantCategory.addPreference(mConfigureCallAssistant);
-        } else {
-            callAssistantCategory.removePreference(mConfigureCallAssistant);
-        }
-    }
-
     private void initAccountList(List<PhoneAccountHandle> enabledAccounts) {
 
         boolean isMultiSimDevice = mTelephonyManager.isMultiSimEnabled();
@@ -478,19 +378,6 @@
         }
     }
 
-    private Intent getConfigureCallAssistantIntent() {
-        PhoneAccountHandle handle = mTelecomManager.getSimCallManager();
-        if (handle != null) {
-            String packageName = handle.getComponentName().getPackageName();
-            if (packageName != null) {
-                return new Intent(TelecomManager.ACTION_CONNECTION_SERVICE_CONFIGURE)
-                        .addCategory(Intent.CATEGORY_DEFAULT)
-                        .setPackage(packageName);
-            }
-        }
-        return null;
-    }
-
     private boolean shouldShowConnectionServiceList(List<PhoneAccountHandle> allNonSimAccounts) {
         return mTelephonyManager.isMultiSimEnabled() || allNonSimAccounts.size() > 0;
     }
diff --git a/src/com/android/phone/settings/VoicemailSettingsActivity.java b/src/com/android/phone/settings/VoicemailSettingsActivity.java
index 3e9a613..149cf0a 100644
--- a/src/com/android/phone/settings/VoicemailSettingsActivity.java
+++ b/src/com/android/phone/settings/VoicemailSettingsActivity.java
@@ -31,6 +31,8 @@
 import android.preference.SwitchPreference;
 import android.provider.ContactsContract.CommonDataKinds;
 import android.telephony.TelephonyManager;
+import android.text.BidiFormatter;
+import android.text.TextDirectionHeuristics;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.MenuItem;
@@ -1015,7 +1017,8 @@
             mSubMenuVoicemailSettings.setSummary(getString(R.string.voicemail_number_not_set));
         } else {
             mSubMenuVoicemailSettings.setPhoneNumber(mOldVmNumber);
-            mSubMenuVoicemailSettings.setSummary(mOldVmNumber);
+            mSubMenuVoicemailSettings.setSummary(BidiFormatter.getInstance().unicodeWrap(
+                    mOldVmNumber, TextDirectionHeuristics.LTR));
         }
     }
 
diff --git a/src/com/android/services/telephony/ImsConferenceController.java b/src/com/android/services/telephony/ImsConferenceController.java
index f445dcb..7dcb97e 100644
--- a/src/com/android/services/telephony/ImsConferenceController.java
+++ b/src/com/android/services/telephony/ImsConferenceController.java
@@ -317,7 +317,7 @@
 
         // Create conference and add to telecom
         ImsConference conference = new ImsConference(mConnectionService, conferenceHostConnection);
-        conference.setState(connection.getState());
+        conference.setState(conferenceHostConnection.getState());
         conference.addListener(mConferenceListener);
         conference.updateConferenceParticipantsAfterCreation();
         mConnectionService.addConference(conference);
diff --git a/src/com/android/services/telephony/TelecomAccountRegistry.java b/src/com/android/services/telephony/TelecomAccountRegistry.java
index 4b5096b..483b33f 100644
--- a/src/com/android/services/telephony/TelecomAccountRegistry.java
+++ b/src/com/android/services/telephony/TelecomAccountRegistry.java
@@ -70,7 +70,7 @@
         AccountEntry(Phone phone, boolean isEmergency, boolean isDummy) {
             mPhone = phone;
             mAccount = registerPstnPhoneAccount(isEmergency, isDummy);
-            Log.d(this, "Registered phoneAccount: %s with handle: %s",
+            Log.i(this, "Registered phoneAccount: %s with handle: %s",
                     mAccount, mAccount.getAccountHandle());
             mIncomingCallNotifier = new PstnIncomingCallNotifier((PhoneProxy) mPhone);
             mPhoneCapabilitiesNotifier = new PstnPhoneCapabilitiesNotifier((PhoneProxy) mPhone,
@@ -371,11 +371,12 @@
     private void cleanupPhoneAccounts() {
         ComponentName telephonyComponentName =
                 new ComponentName(mContext, TelephonyConnectionService.class);
-        List<PhoneAccountHandle> accountHandles = mTelecomManager.getAllPhoneAccountHandles();
+        List<PhoneAccountHandle> accountHandles =
+                mTelecomManager.getCallCapablePhoneAccounts(true /* includeDisabled */);
         for (PhoneAccountHandle handle : accountHandles) {
             if (telephonyComponentName.equals(handle.getComponentName()) &&
                     !hasAccountEntryForPhoneAccount(handle)) {
-                Log.d(this, "Unregistering phone account %s.", handle);
+                Log.i(this, "Unregistering phone account %s.", handle);
                 mTelecomManager.unregisterPhoneAccount(handle);
             }
         }