From f87292fa523bf59e32331c4333aa01d9f85c69d1 Mon Sep 17 00:00:00 2001 From: Malcolm Chen Date: Mon, 23 Sep 2019 14:06:19 -0700 Subject: [PATCH 1/2] Replace getPhoneCount with getMaxPhoneCount upon object allocation. As first step for smooth single SIM to DSDS switch, for DSDS capable deviced we always allocate objects as if it's in DSDS mode. For example there will be two Phone objects. Later we'll evaluate to make the allocations dynamic to save memory. Bug: 141388730 Test: unittest and manual Change-Id: I3064eb616371f60776a2930c113582562d206123 Merged-In: I3064eb616371f60776a2930c113582562d206123 --- .../com/android/server/TelephonyRegistry.java | 2 +- .../android/telephony/SubscriptionManager.java | 17 +++++++++++++++-- .../android/telephony/TelephonyManager.java | 6 +++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java index 52eb45f819f16..6114441537919 100644 --- a/services/core/java/com/android/server/TelephonyRegistry.java +++ b/services/core/java/com/android/server/TelephonyRegistry.java @@ -382,7 +382,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { mContext = context; mBatteryStats = BatteryStatsService.getService(); - int numPhones = TelephonyManager.getDefault().getPhoneCount(); + int numPhones = TelephonyManager.getDefault().getMaxPhoneCount(); if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones); mNumPhones = numPhones; mCallState = new int[numPhones]; diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 519a954063120..003dc4b117be6 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -2085,13 +2085,26 @@ public class SubscriptionManager { /** @hide */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) public static boolean isValidSlotIndex(int slotIndex) { - return slotIndex >= 0 && slotIndex < TelephonyManager.getDefault().getSimCount(); + return slotIndex >= 0 && slotIndex < TelephonyManager.getDefault().getMaxPhoneCount(); } /** @hide */ @UnsupportedAppUsage public static boolean isValidPhoneId(int phoneId) { - return phoneId >= 0 && phoneId < TelephonyManager.getDefault().getPhoneCount(); + return phoneId >= 0 && phoneId < TelephonyManager.getDefault().getMaxPhoneCount(); + } + + /** + * When getPhoneCount and getMaxPhoneCount return different value, isValidPhoneId being true + * doesn't mean the phoneId has a corresponding active slot / logical modem. If a DSDS capable + * device is in single SIM mode, phoneId=1 is valid but not active. + * + * TODO: b/139642279 combine with SubscriptionManager#isValidPhoneId when phone objects + * are dynamically allocated instead of always based on getMaxPhoneCount. + * @hide + */ + public static boolean isActivePhoneId(int slotIndex) { + return slotIndex < TelephonyManager.getDefault().getPhoneCount(); } /** @hide */ diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 020fe2e6c9dcc..57ebc685d747e 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -404,7 +404,7 @@ public class TelephonyManager { * TODO: b/139642279 publicize and rename. * @hide */ - public static int getMaxPhoneCount() { + public 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. @@ -413,9 +413,9 @@ public class TelephonyManager { if (rebootRequired.equals("false")) { // If no reboot is required, return max possible active modems. return SystemProperties.getInt( - TelephonyProperties.PROPERTY_MAX_ACTIVE_MODEMS, getDefault().getPhoneCount()); + TelephonyProperties.PROPERTY_MAX_ACTIVE_MODEMS, getPhoneCount()); } else { - return getDefault().getPhoneCount(); + return getPhoneCount(); } } From de64f7197a4b3eebd817177a316000d968232c78 Mon Sep 17 00:00:00 2001 From: Malcolm Chen Date: Mon, 23 Sep 2019 16:04:51 -0700 Subject: [PATCH 2/2] In CarrierTextController replace getPhoneCount with getMaxPhoneCount. As first step for smooth single SIM to DSDS switch, for DSDS capable deviced we always allocate objects as if it's in DSDS mode. Bug: 141388730 Test: unittest and manual Change-Id: I141689fc55063d87f4f7e5c605a461517beeabe4 Merged-In: I141689fc55063d87f4f7e5c605a461517beeabe4 --- .../src/com/android/keyguard/CarrierTextController.java | 2 +- .../src/com/android/keyguard/CarrierTextControllerTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java b/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java index 209074812d7a0..5d78cc833f56c 100644 --- a/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java +++ b/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java @@ -172,7 +172,7 @@ public class CarrierTextController { mSeparator = separator; mWakefulnessLifecycle = Dependency.get(WakefulnessLifecycle.class); mSimSlotsNumber = ((TelephonyManager) context.getSystemService( - Context.TELEPHONY_SERVICE)).getPhoneCount(); + Context.TELEPHONY_SERVICE)).getMaxPhoneCount(); mSimErrorState = new boolean[mSimSlotsNumber]; updateDisplayOpportunisticSubscriptionCarrierText(SystemProperties.getBoolean( TelephonyProperties.DISPLAY_OPPORTUNISTIC_SUBSCRIPTION_CARRIER_TEXT_PROPERTY_NAME, diff --git a/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextControllerTest.java index db45ad788bfcd..24d508cc29d1c 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextControllerTest.java @@ -112,7 +112,7 @@ public class CarrierTextControllerTest extends SysuiTestCase { mCarrierTextCallbackInfo = new CarrierTextController.CarrierTextCallbackInfo("", new CharSequence[]{}, false, new int[]{}); - when(mTelephonyManager.getPhoneCount()).thenReturn(3); + when(mTelephonyManager.getMaxPhoneCount()).thenReturn(3); mCarrierTextController = new TestCarrierTextController(mContext, SEPARATOR, true, true, mKeyguardUpdateMonitor);