Merge "Revert "Fix the duplicated info of SIM cards after Hot-plug." This reverts commit caca9048f86c5d954277f5bedd781fae604ae4e0." am: eab5a73279
am: efdb79e419

Change-Id: I0a9a071ab072eba6d5a2c469855235583a155160
diff --git a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
index d891da9..670f98d 100644
--- a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
+++ b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
@@ -18,7 +18,6 @@
 import android.telecom.TelecomManager;
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
-import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 import android.util.Log;
@@ -77,15 +76,6 @@
     private SwitchPreference mSipReceiveCallsPreference;
     private SipPreferences mSipPreferences;
 
-    private final SubscriptionManager.OnSubscriptionsChangedListener
-            mOnSubscriptionsChangeListener =
-            new SubscriptionManager.OnSubscriptionsChangedListener() {
-        @Override
-        public void onSubscriptionsChanged() {
-            updateAccounts();
-        }
-    };
-
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
@@ -132,8 +122,34 @@
          */
         mAccountList = (PreferenceCategory) getPreferenceScreen().findPreference(
                 ACCOUNTS_LIST_CATEGORY_KEY);
+        List<PhoneAccountHandle> allNonSimAccounts =
+                getCallingAccounts(false /* includeSims */, true /* includeDisabled */);
+        // Check to see if we should show the entire section at all.
+        if (shouldShowConnectionServiceList(allNonSimAccounts)) {
+            List<PhoneAccountHandle> enabledAccounts =
+                    getCallingAccounts(true /* includeSims */, false /* includeDisabled */);
+            // Initialize the account list with the set of enabled & SIM accounts.
+            initAccountList(enabledAccounts);
 
-        updateAccounts();
+            mDefaultOutgoingAccount = (AccountSelectionPreference)
+                    getPreferenceScreen().findPreference(DEFAULT_OUTGOING_ACCOUNT_KEY);
+            mDefaultOutgoingAccount.setListener(this);
+
+            // Only show the 'Make Calls With..." option if there are multiple accounts.
+            if (enabledAccounts.size() > 1) {
+                updateDefaultOutgoingAccountsModel();
+            } else {
+                mAccountList.removePreference(mDefaultOutgoingAccount);
+            }
+
+            Preference allAccounts = getPreferenceScreen().findPreference(ALL_CALLING_ACCOUNTS_KEY);
+            // If there are no third party (nonSim) accounts, then don't show enable/disable dialog.
+            if (allNonSimAccounts.isEmpty() && allAccounts != null) {
+                mAccountList.removePreference(allAccounts);
+            }
+        } else {
+            getPreferenceScreen().removePreference(mAccountList);
+        }
 
         if (isPrimaryUser() && SipUtil.isVoipSupported(getActivity())) {
             mSipPreferences = new SipPreferences(getActivity());
@@ -167,16 +183,6 @@
             getPreferenceScreen().removePreference(
                     getPreferenceScreen().findPreference(SIP_SETTINGS_CATEGORY_PREF_KEY));
         }
-
-        SubscriptionManager.from(getActivity()).addOnSubscriptionsChangedListener(
-                mOnSubscriptionsChangeListener);
-    }
-
-    @Override
-    public void onPause() {
-        SubscriptionManager.from(getActivity()).removeOnSubscriptionsChangedListener(
-                mOnSubscriptionsChangeListener);
-        super.onPause();
     }
 
     /**
@@ -385,40 +391,6 @@
         return mTelephonyManager.isMultiSimEnabled() || allNonSimAccounts.size() > 0;
     }
 
-    private void updateAccounts() {
-        if (mAccountList != null) {
-            mAccountList.removeAll();
-            List<PhoneAccountHandle> allNonSimAccounts =
-                    getCallingAccounts(false /* includeSims */, true /* includeDisabled */);
-            // Check to see if we should show the entire section at all.
-            if (shouldShowConnectionServiceList(allNonSimAccounts)) {
-                List<PhoneAccountHandle> enabledAccounts =
-                        getCallingAccounts(true /* includeSims */, false /* includeDisabled */);
-                // Initialize the account list with the set of enabled & SIM accounts.
-                initAccountList(enabledAccounts);
-
-                mDefaultOutgoingAccount = (AccountSelectionPreference)
-                        getPreferenceScreen().findPreference(DEFAULT_OUTGOING_ACCOUNT_KEY);
-                mDefaultOutgoingAccount.setListener(this);
-
-                // Only show the 'Make Calls With..." option if there are multiple accounts.
-                if (enabledAccounts.size() > 1) {
-                    updateDefaultOutgoingAccountsModel();
-                } else {
-                    mAccountList.removePreference(mDefaultOutgoingAccount);
-                }
-
-                Preference allAccounts = getPreferenceScreen().findPreference(ALL_CALLING_ACCOUNTS_KEY);
-                // If there are no third party (nonSim) accounts, then don't show enable/disable dialog.
-                if (allNonSimAccounts.isEmpty() && allAccounts != null) {
-                    mAccountList.removePreference(allAccounts);
-                }
-            } else {
-                getPreferenceScreen().removePreference(mAccountList);
-            }
-        }
-    }
-
     private List<PhoneAccountHandle> getCallingAccounts(
             boolean includeSims, boolean includeDisabledAccounts) {
         PhoneAccountHandle emergencyAccountHandle = getEmergencyPhoneAccount();