Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 80fe541d authored by Malcolm Chen's avatar Malcolm Chen Committed by Xiangyu/Malcolm Chen
Browse files

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
parent a80a7ac6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -370,7 +370,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];
+15 −2
Original line number Diff line number Diff line
@@ -2096,13 +2096,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 */
+3 −3
Original line number Diff line number Diff line
@@ -403,7 +403,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.
@@ -412,9 +412,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();
        }
    }