Trigger PhoneAccount registration from SUBINFO_RECORD_UPDATED

...instead of SIM_STATE_CHANGE.

1) TelecommAccountRegistry registers Phones with valid subId
2) Phones use SubscriptionController to get their subId
3) TelecommAccountRegistry was trying to reregister Phones when it
   received a SIM_STATE_CHANGE intent.

The problem is that SubscriptionController also listens to the same
intent to update it's entries. So, due to this race between
SubscriptionController and TelecommAccountRegistry, Phone's subId
wouldn't yet be updated when it was needed for registering phone
accounts.

Solution: Listen to an intent that indicates the SubscriptionController
has updated its entries instead.

Bug: 16526102
Change-Id: I5abd32fcd8b6bef0bac679cd61406076ff9aba63
diff --git a/src/com/android/services/telephony/TelecommAccountRegistry.java b/src/com/android/services/telephony/TelecommAccountRegistry.java
index 78aa057..2b42d0f 100644
--- a/src/com/android/services/telephony/TelecommAccountRegistry.java
+++ b/src/com/android/services/telephony/TelecommAccountRegistry.java
@@ -25,6 +25,7 @@
 import android.telecomm.PhoneAccount;
 import android.telecomm.PhoneAccountHandle;
 import android.telecomm.TelecommManager;
+import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
 
 import com.android.internal.telephony.Phone;
@@ -78,7 +79,10 @@
             if (line1Number == null) {
                 line1Number = "";
             }
-            String subNumber = isEmergency ? "" : mPhone.getPhoneSubInfo().getLine1Number();
+            String subNumber = mPhone.getPhoneSubInfo().getLine1Number();
+            if (subNumber == null) {
+                subNumber = "";
+            }
             String label = isEmergency
                     ? "Emergency calls"
                     : dummyPrefix + "SIM " + slotId;
@@ -106,9 +110,14 @@
         @Override
         public void onReceive(Context context, Intent intent) {
             String action = intent.getAction();
-            if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) {
-                Log.d(this, "SIM_STATE_CHANGED - rerun setup");
-                // Anytime the SIM state changes...rerun the setup.
+            if (TelephonyIntents.ACTION_SUBINFO_RECORD_UPDATED.equals(action)) {
+                int status = intent.getIntExtra(
+                        SubscriptionManager.INTENT_KEY_DETECT_STATUS,
+                        SubscriptionManager.EXTRA_VALUE_NOCHANGE);
+                Log.i(this, "SUBINFO_RECORD_UPDATED : %d.", status);
+                // Anytime the SIM state changes...rerun the setup
+                // We rely on this notification even when the status is EXTRA_VALUE_NOCHANGE,
+                // so we explicitly do not check for that here.
                 tearDownAccounts();
                 setupAccounts();
             }
@@ -138,7 +147,7 @@
      */
     void setupOnBoot() {
         IntentFilter intentFilter =
-            new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
+            new IntentFilter(TelephonyIntents.ACTION_SUBINFO_RECORD_UPDATED);
         mContext.registerReceiver(mReceiver, intentFilter);
 
         setupAccounts();