From 4c18a3a5a68e0cae2c0755fdf20a7ae6c3017d73 Mon Sep 17 00:00:00 2001 From: Meng Wang Date: Mon, 9 Dec 2019 17:00:01 -0800 Subject: [PATCH] Remove hidden API usage PhoneConstants.SUBSCRIPTION_KEY/SLOT_KEY The two constants are hidden APIs and used as extra keys for a few legacy broadcasts. No new external users are expected. So making a local copy of them to keep backward compatibility, until the broadcasts are removed in the future. Also move ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED constant out of PhoneConstants since it's only used in TelephonyRegistry for backward compatibility. Bug: 140908357 Test: make Change-Id: Ic7f15851377dcba5353dc6dade61b1dec96bcea5 --- .../com/android/server/TelephonyRegistry.java | 30 +++++++++++++------ .../internal/telephony/PhoneConstants.java | 4 --- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java index 226a363badba3..9fad7ceb81e68 100644 --- a/services/core/java/com/android/server/TelephonyRegistry.java +++ b/services/core/java/com/android/server/TelephonyRegistry.java @@ -2185,6 +2185,16 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { // the legacy intent broadcasting // + // Legacy intent action. + /** Fired when a subscription's phone state changes. */ + private static final String ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED = + "android.intent.action.SUBSCRIPTION_PHONE_STATE"; + + // Legacy intent extra keys, copied from PhoneConstants. + // Used in legacy intents sent here, for backward compatibility. + private static final String PHONE_CONSTANTS_SLOT_KEY = "slot"; + private static final String PHONE_CONSTANTS_SUBSCRIPTION_KEY = "subscription"; + private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) { long ident = Binder.clearCallingIdentity(); try { @@ -2201,9 +2211,10 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { state.fillInNotifierBundle(data); intent.putExtras(data); // Pass the subscription along with the intent. - intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId); + intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId); intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId); - intent.putExtra(PhoneConstants.SLOT_KEY, phoneId); + intent.putExtra(PHONE_CONSTANTS_SLOT_KEY, phoneId); + intent.putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, phoneId); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); } @@ -2222,8 +2233,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { Bundle data = new Bundle(); signalStrength.fillInNotifierBundle(data); intent.putExtras(data); - intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId); - intent.putExtra(PhoneConstants.SLOT_KEY, phoneId); + intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId); + intent.putExtra(PHONE_CONSTANTS_SLOT_KEY, phoneId); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); } @@ -2258,13 +2269,14 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { // 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); + intent.setAction(ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED); + intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId); intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId); } // If the phoneId is invalid, the broadcast is for overall call state. if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) { - intent.putExtra(PhoneConstants.SLOT_KEY, phoneId); + intent.putExtra(PHONE_CONSTANTS_SLOT_KEY, phoneId); + intent.putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, phoneId); } // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast. @@ -2324,14 +2336,14 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { intent.putExtra(PhoneConstants.DATA_APN_KEY, apn); intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType); - intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId); + intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); } private void broadcastDataConnectionFailed(String apnType, int subId) { Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED); intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType); - intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId); + intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); } diff --git a/telephony/java/com/android/internal/telephony/PhoneConstants.java b/telephony/java/com/android/internal/telephony/PhoneConstants.java index e4397cdf1254a..05e2ed9acb332 100644 --- a/telephony/java/com/android/internal/telephony/PhoneConstants.java +++ b/telephony/java/com/android/internal/telephony/PhoneConstants.java @@ -189,10 +189,6 @@ public class PhoneConstants { public static final String SLOT_KEY = "slot"; - /** Fired when a subscriptions phone state changes. */ - public static final String ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED = - "android.intent.action.SUBSCRIPTION_PHONE_STATE"; - // FIXME: This is used to pass a subId via intents, we need to look at its usage, which is // FIXME: extensive, and see if this should be an array of all active subId's or ...? /**