Use a separate intent action for subscription phone state changes.

Global phone state changes and subscription phone state changes
are aliased to the same intent. As a result, apps can't distinguish
between the two types of updates.

This change teases the two apart by using a different intent action
for each type of phone state change. This will break carrier apps
that depend on subscription phone state changes, but will fix state
inconsistencies in non-carrier apps.

Bug: 20309009
Change-Id: Ie81c37247917573a3ef5d957fda1087c16736e85
diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java
index 4ee6657..ac87377 100644
--- a/services/core/java/com/android/server/TelephonyRegistry.java
+++ b/services/core/java/com/android/server/TelephonyRegistry.java
@@ -678,7 +678,7 @@
             handleRemoveListLocked();
         }
         broadcastCallStateChanged(state, incomingNumber,
-                SubscriptionManager.DEFAULT_SUBSCRIPTION_ID);
+                SubscriptionManager.INVALID_SUBSCRIPTION_ID);
     }
 
     public void notifyCallStateForSubscriber(int subId, int state, String incomingNumber) {
@@ -1372,6 +1372,12 @@
         mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
     }
 
+    /**
+     * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
+     * a valid subId, in which case this function fires a subId-specific intent, or it
+     * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
+     * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
+     */
     private void broadcastCallStateChanged(int state, String incomingNumber, int subId) {
         long ident = Binder.clearCallingIdentity();
         try {
@@ -1392,7 +1398,14 @@
         if (!TextUtils.isEmpty(incomingNumber)) {
             intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
         }
-        intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
+
+        // If a valid subId was specified, we should fire off a subId-specific state
+        // change intent and include the subId.
+        if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+            intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
+            intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
+        }
+
         mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
                 android.Manifest.permission.READ_PHONE_STATE,
                 AppOpsManager.OP_READ_PHONE_STATE);