From 118b02f61b1a8346eedbf61667b32ea0f8b8cf4c Mon Sep 17 00:00:00 2001 From: Malcolm Chen Date: Wed, 4 Sep 2019 16:10:34 -0700 Subject: [PATCH 1/3] Remove permission check for LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE Bug: 140020981 Test: sanity Change-Id: I060511af068bfbbc9fea5c5d27a5d04eb2924fda Merged-In: I060511af068bfbbc9fea5c5d27a5d04eb2924fda --- .../com/android/server/TelephonyRegistry.java | 24 ++++--------------- .../android/telephony/PhoneStateListener.java | 5 ---- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java index cfd2503506d1a..77e52fa6ab468 100644 --- a/services/core/java/com/android/server/TelephonyRegistry.java +++ b/services/core/java/com/android/server/TelephonyRegistry.java @@ -79,7 +79,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; -import java.util.stream.Collectors; /** * Since phone process can be restarted, this class provides a centralized place @@ -863,10 +862,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { } } if ((events & PhoneStateListener - .LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE) != 0 - && TelephonyPermissions.checkReadPhoneStateOnAnyActiveSub( - r.context, r.callerPid, r.callerUid, r.callingPackage, - "listen_active_data_subid_change")) { + .LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE) != 0) { try { r.callback.onActiveDataSubIdChanged(mActiveDataSubId); } catch (RemoteException ex) { @@ -1845,23 +1841,11 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { log("notifyActiveDataSubIdChanged: activeDataSubId=" + activeDataSubId); } - // Create a copy to prevent the IPC call while checking carrier privilege under the lock. - List copiedRecords; - synchronized (mRecords) { - copiedRecords = new ArrayList<>(mRecords); - } mActiveDataSubId = activeDataSubId; - - // Filter the record that does not listen to this change or does not have the permission. - copiedRecords = copiedRecords.stream().filter(r -> r.matchPhoneStateListenerEvent( - PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE) - && TelephonyPermissions.checkReadPhoneStateOnAnyActiveSub( - mContext, r.callerPid, r.callerUid, r.callingPackage, - "notifyActiveDataSubIdChanged")).collect(Collectors.toCollection(ArrayList::new)); - synchronized (mRecords) { - for (Record r : copiedRecords) { - if (mRecords.contains(r)) { + for (Record r : mRecords) { + if (r.matchPhoneStateListenerEvent( + PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE)) { try { r.callback.onActiveDataSubIdChanged(activeDataSubId); } catch (RemoteException ex) { diff --git a/telephony/java/android/telephony/PhoneStateListener.java b/telephony/java/android/telephony/PhoneStateListener.java index 2c4d59d189164..1e1e3daff3ec3 100644 --- a/telephony/java/android/telephony/PhoneStateListener.java +++ b/telephony/java/android/telephony/PhoneStateListener.java @@ -302,11 +302,6 @@ public class PhoneStateListener { * it could be the current active opportunistic subscription in use, or the * subscription user selected as default data subscription in DSDS mode. * - * Requires Permission: No permission is required to listen, but notification requires - * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} or the calling - * app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}) - * on any active subscription. - * * @see #onActiveDataSubscriptionIdChanged */ public static final int LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE = 0x00400000; From f6da74661c9249de75574df9d759a89af2209663 Mon Sep 17 00:00:00 2001 From: Malcolm Chen Date: Mon, 16 Sep 2019 18:27:11 -0700 Subject: [PATCH 2/3] Combine getPhoneCount, getSimCount and isMultiSimEnabled. Bug: 141023026 Test: build Change-Id: I9007978bc577a24083e0108d02c8b59fd16ae81f Merged-In: I9007978bc577a24083e0108d02c8b59fd16ae81f --- .../java/android/telephony/TelephonyManager.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 7e6e8f4024d9e..ee254d7d2b9fb 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -271,9 +271,6 @@ public class TelephonyManager { private SubscriptionManager mSubscriptionManager; private TelephonyScanManager mTelephonyScanManager; - private static String multiSimConfig = - SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); - /** Enum indicating multisim variants * DSDS - Dual SIM Dual Standby * DSDA - Dual SIM Dual Active @@ -433,8 +430,7 @@ public class TelephonyManager { /** {@hide} */ @UnsupportedAppUsage public boolean isMultiSimEnabled() { - return (multiSimConfig.equals("dsds") || multiSimConfig.equals("dsda") || - multiSimConfig.equals("tsts")); + return getPhoneCount() > 1; } // @@ -6550,11 +6546,7 @@ public class TelephonyManager { public int getSimCount() { // FIXME Need to get it from Telephony Dev Controller when that gets implemented! // and then this method shouldn't be used at all! - if(isMultiSimEnabled()) { - return getPhoneCount(); - } else { - return 1; - } + return getPhoneCount(); } /** From 793928c33896ab153585497466d3aee81f327daa Mon Sep 17 00:00:00 2001 From: Malcolm Chen Date: Tue, 17 Sep 2019 12:02:19 -0700 Subject: [PATCH 3/3] Add APIs to return max possible active phones. This is first step towards reboot free single SIM to DSDS switch. As getPhoneCount returns active phone count based on current configuration, getMaxPhoneCount (subject to renaming) will return max possible active phones(logical modems). Bug: 141023026 Test: manual Change-Id: Icc6e7da7c065eb3f72ec85a99ccc148639c574da Merged-In: Icc6e7da7c065eb3f72ec85a99ccc148639c574da --- .../android/telephony/TelephonyManager.java | 26 ++++++++++++++++++- .../telephony/TelephonyProperties.java | 7 +++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index ee254d7d2b9fb..020fe2e6c9dcc 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -362,7 +362,6 @@ public class TelephonyManager { } } - /** * Returns the number of phones available. * Returns 0 if none of voice, sms, data is not supported @@ -395,6 +394,31 @@ public class TelephonyManager { return phoneCount; } + /** + * + * Return how many phone / logical modem can be active simultaneously, in terms of device + * capability. + * For example, for a dual-SIM capable device, it always returns 2, even if only one logical + * modem / SIM is active (aka in single SIM mode). + * + * TODO: b/139642279 publicize and rename. + * @hide + */ + public static int getMaxPhoneCount() { + // TODO: b/139642279 when turning on this feature, remove dependency of + // PROPERTY_REBOOT_REQUIRED_ON_MODEM_CHANGE and always return result based on + // PROPERTY_MAX_ACTIVE_MODEMS. + String rebootRequired = SystemProperties.get( + TelephonyProperties.PROPERTY_REBOOT_REQUIRED_ON_MODEM_CHANGE); + if (rebootRequired.equals("false")) { + // If no reboot is required, return max possible active modems. + return SystemProperties.getInt( + TelephonyProperties.PROPERTY_MAX_ACTIVE_MODEMS, getDefault().getPhoneCount()); + } else { + return getDefault().getPhoneCount(); + } + } + /** {@hide} */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) public static TelephonyManager from(Context context) { diff --git a/telephony/java/com/android/internal/telephony/TelephonyProperties.java b/telephony/java/com/android/internal/telephony/TelephonyProperties.java index dd9b2421a333b..bf5c0a18cc964 100644 --- a/telephony/java/com/android/internal/telephony/TelephonyProperties.java +++ b/telephony/java/com/android/internal/telephony/TelephonyProperties.java @@ -231,4 +231,11 @@ public interface TelephonyProperties String DISPLAY_OPPORTUNISTIC_SUBSCRIPTION_CARRIER_TEXT_PROPERTY_NAME = "persist.radio.display_opportunistic_carrier"; + /** + * How many logical modems can be active simultaneously. For example, if a device is dual-SIM + * capable but currently only one SIM slot and one logical modem is active, this value is still + * two. + * Type: int + */ + static final String PROPERTY_MAX_ACTIVE_MODEMS = "ro.telephony.max.active.modems"; }