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

Commit 2298118d authored by Youming Ye's avatar Youming Ye Committed by Xiangyu/Malcolm Chen
Browse files

Check user data enabled on phone and add listener

Check phone#isUserDataEnabled() before trying to set it as preferred
data phone. PhoneSwitch now also listens to data enable change, and
re-evaluate DDS when events are received.

Bug: 126769655
Test: Build
Change-Id: I599bea363f24a3de0e102c2e32cad132dcc0bbec
Merged-In: I599bea363f24a3de0e102c2e32cad132dcc0bbec
(cherry picked from commit 86d02753)
parent 15affa4d
Loading
Loading
Loading
Loading
+30 −6
Original line number Diff line number Diff line
@@ -147,6 +147,7 @@ public class PhoneSwitcher extends Handler {
    private static final int EVENT_REMOVE_DEFAULT_NETWORK_CHANGE_CALLBACK = 111;
    private static final int EVENT_MODEM_COMMAND_DONE             = 112;
    private static final int EVENT_MODEM_COMMAND_RETRY            = 113;
    private static final int EVENT_DATA_ENABLED_CHANGED           = 114;

    // Depending on version of IRadioConfig, we need to send either RIL_REQUEST_ALLOW_DATA if it's
    // 1.0, or RIL_REQUEST_SET_PREFERRED_DATA if it's 1.1 or later. So internally mHalCommandToUse
@@ -264,6 +265,21 @@ public class PhoneSwitcher extends Handler {
                if (mPhoneIdInVoiceCall != oldPhoneIdInVoiceCall) {
                    log("mPhoneIdInVoiceCall changed from" + oldPhoneIdInVoiceCall
                            + " to " + mPhoneIdInVoiceCall);

                    // Switches and listens to the updated voice phone.
                    Phone dataPhone = findPhoneById(mPhoneIdInVoiceCall);
                    if (dataPhone != null && dataPhone.getDataEnabledSettings() != null) {
                        dataPhone.getDataEnabledSettings()
                                .registerForDataEnabledChanged(getInstance(),
                                        EVENT_DATA_ENABLED_CHANGED, null);
                    }

                    Phone oldDataPhone = findPhoneById(oldPhoneIdInVoiceCall);
                    if (oldDataPhone != null && oldDataPhone.getDataEnabledSettings() != null) {
                        oldDataPhone.getDataEnabledSettings()
                                .unregisterForDataEnabledChanged(getInstance());
                    }

                    Message msg = PhoneSwitcher.this.obtainMessage(EVENT_PHONE_IN_CALL_CHANGED);
                    msg.sendToTarget();
                }
@@ -397,7 +413,9 @@ public class PhoneSwitcher extends Handler {
                onEvaluate(REQUESTS_UNCHANGED, "EVENT_RADIO_AVAILABLE");
                break;
            }
            case EVENT_PHONE_IN_CALL_CHANGED: {
            // fall through
            case EVENT_DATA_ENABLED_CHANGED:
            case EVENT_PHONE_IN_CALL_CHANGED:
                if (onEvaluate(REQUESTS_UNCHANGED, "EVENT_PHONE_IN_CALL_CHANGED")) {
                    logDataSwitchEvent(mOpptDataSubId,
                            TelephonyEvent.EventState.EVENT_STATE_START,
@@ -405,7 +423,6 @@ public class PhoneSwitcher extends Handler {
                    registerDefaultNetworkChangeCallback();
                }
                break;
            }
            case EVENT_NETWORK_VALIDATION_DONE: {
                int subId = msg.arg1;
                boolean passed = (msg.arg2 == 1);
@@ -770,15 +787,15 @@ public class PhoneSwitcher extends Handler {
        }
    }

    // This updates mPreferredDataPhoneId which decides which phone should
    // handle default network requests.
    // This updates mPreferredDataPhoneId which decides which phone should handle default network
    // requests.
    private void updatePreferredDataPhoneId() {
        if (SubscriptionManager.isValidPhoneId(mPhoneIdInVoiceCall)) {
        Phone voicePhone = findPhoneById(mPhoneIdInVoiceCall);
        if (voicePhone != null && voicePhone.isUserDataEnabled()) {
            // If a phone is in call and user enabled its mobile data, we
            // should switch internet connection to it. Because the other modem
            // will lose data connection anyway.
            // TODO: validate network first.

            mPreferredDataPhoneId = mPhoneIdInVoiceCall;
        } else {
            int subId = getSubIdForDefaultNetworkRequests();
@@ -799,6 +816,13 @@ public class PhoneSwitcher extends Handler {
        mPreferredDataSubId = mSubscriptionController.getSubIdUsingPhoneId(mPreferredDataPhoneId);
    }

    private Phone findPhoneById(final int phoneId) {
        if (phoneId < 0 || phoneId >= mNumPhones) {
            return null;
        }
        return mPhones[phoneId];
    }

    public boolean shouldApplyNetworkRequest(NetworkRequest networkRequest, int phoneId) {
        validatePhoneId(phoneId);

+1 −0
Original line number Diff line number Diff line
@@ -566,6 +566,7 @@ public class PhoneSwitcherTest extends TelephonyTest {
        mSlotIndexToSubId = new int[numPhones][];
        doReturn(0).when(mPhone).getPhoneId();
        doReturn(1).when(mPhone2).getPhoneId();
        doReturn(true).when(mPhone2).isUserDataEnabled();
        for (int i = 0; i < numPhones; i++) {
            mSlotIndexToSubId[i] = new int[1];
            mSlotIndexToSubId[i][0] = SubscriptionManager.INVALID_SUBSCRIPTION_ID;