Add list of accounts in Phone Account Settings.

+ Add new constants to define SubId/SubLabels on intent which opens
the call settings.
+ Add an "accounts" preference category to phone account settings.
+ Add preferences to this new performance category for each
subscription.
+ Configure these preferences to launch an intent to start call
settings, containing the id and label of the subscription.

Bug: 18114923
Change-Id: I989bf3480418c9ac003dce677ec7b3585e82a551
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index b7f2d55..b207c77 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -114,6 +114,13 @@
     // to trigger its configuration UI
     public static final String ACTION_CONFIGURE_VOICEMAIL =
             "com.android.phone.CallFeaturesSetting.CONFIGURE_VOICEMAIL";
+    // Extra on intent to Call Settings containing the id of the subscription to modify.
+    public static final String SUB_ID_EXTRA =
+            "com.android.phone.CallFeaturesSetting.SubscriptionId";
+    // Extra on intent to Call Settings containing the label of the subscription to modify.
+    public static final String SUB_LABEL_EXTRA =
+            "com.android.phone.CallFeaturesSetting.SubscriptionLabel";
+
     // Extra put in the return from VM provider config containing voicemail number to set
     public static final String VM_NUMBER_EXTRA = "com.android.phone.VoicemailNumber";
     // Extra put in the return from VM provider config containing call forwarding number to set
@@ -123,10 +130,6 @@
     // If the VM provider returns non null value in this extra we will force the user to
     // choose another VM provider
     public static final String SIGNOUT_EXTRA = "com.android.phone.Signout";
-    //Information about logical "up" Activity
-    private static final String UP_ACTIVITY_PACKAGE = "com.android.dialer";
-    private static final String UP_ACTIVITY_CLASS =
-            "com.android.dialer.DialtactsActivity";
 
     // Suffix appended to provider key for storing vm number
     public static final String VM_NUMBER_TAG = "#VMNumber";
@@ -810,7 +813,7 @@
             mNewFwdSettings = VoicemailProviderSettings.NO_FORWARDING;
         }
 
-        //Throw a warning if the voicemail is the same and we did not change forwarding.
+        // Throw a warning if the voicemail is the same and we did not change forwarding.
         if (mNewVMNumber.equals(mOldVmNumber)
                 && mNewFwdSettings == VoicemailProviderSettings.NO_FORWARDING) {
             showVMDialog(MSG_VM_NOCHANGE);
diff --git a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
index ba6871c..20fc108 100644
--- a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
+++ b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
@@ -8,12 +8,17 @@
 import android.preference.CheckBoxPreference;
 import android.preference.ListPreference;
 import android.preference.Preference;
+import android.preference.PreferenceCategory;
 import android.preference.PreferenceFragment;
 import android.telecom.PhoneAccountHandle;
 import android.telecom.TelecomManager;
+import android.telephony.SubInfoRecord;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
 import android.util.Log;
 
 import com.android.phone.R;
+import com.android.phone.CallFeaturesSetting;
 import com.android.services.telephony.sip.SipAccountRegistry;
 import com.android.services.telephony.sip.SipSharedPreferences;
 import com.android.services.telephony.sip.SipUtil;
@@ -29,6 +34,9 @@
             new Intent(TelecomManager.ACTION_CONNECTION_SERVICE_CONFIGURE)
                     .addCategory(Intent.CATEGORY_DEFAULT);
 
+    private static final String ACCOUNTS_LIST_CATEGORY_KEY =
+            "phone_accounts_accounts_list_category_key";
+
     private static final String DEFAULT_OUTGOING_ACCOUNT_KEY = "default_outgoing_account";
 
     private static final String CONFIGURE_CALL_ASSISTANT_PREF_KEY =
@@ -48,6 +56,8 @@
     private TelecomManager mTelecomManager;
     private Context mApplicationContext;
 
+    private PreferenceCategory mAccountList;
+
     private AccountSelectionPreference mDefaultOutgoingAccount;
     private AccountSelectionPreference mSelectCallAssistant;
     private Preference mConfigureCallAssistant;
@@ -74,6 +84,16 @@
 
         addPreferencesFromResource(com.android.phone.R.xml.phone_account_settings);
 
+        TelephonyManager telephonyManager =
+                (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
+        mAccountList = (PreferenceCategory) getPreferenceScreen().findPreference(
+                ACCOUNTS_LIST_CATEGORY_KEY);
+        if (telephonyManager.getPhoneCount() > 1) {
+            initAccountList();
+        } else {
+            getPreferenceScreen().removePreference(mAccountList);
+        }
+
         mDefaultOutgoingAccount = (AccountSelectionPreference)
                 getPreferenceScreen().findPreference(DEFAULT_OUTGOING_ACCOUNT_KEY);
         if (mTelecomManager.getAllPhoneAccountsCount() > 1) {
@@ -269,4 +289,19 @@
             mConfigureCallAssistant.setEnabled(true);
         }
     }
+
+    private void initAccountList() {
+        List<SubInfoRecord> subscriptions = SubscriptionManager.getActiveSubInfoList();
+        for (int i = 0; i < subscriptions.size(); i++) {
+            String label = subscriptions.get(i).getLabel();
+            Intent intent = new Intent(TelecomManager.ACTION_SHOW_CALL_SETTINGS);
+            intent.putExtra(CallFeaturesSetting.SUB_ID_EXTRA, subscriptions.get(i).subId);
+            intent.putExtra(CallFeaturesSetting.SUB_LABEL_EXTRA, label);
+
+            Preference accountPreference = new Preference(mApplicationContext);
+            accountPreference.setTitle(label);
+            accountPreference.setIntent(intent);
+            mAccountList.addPreference(accountPreference);
+        }
+    }
 }