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

Commit 98a66848 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 5733735 from c107ab88 to qt-c2f2-release

Change-Id: I426bc281c0955718a6f8aa174e33f19913203cd4
parents 8c5902e2 c107ab88
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -1131,12 +1131,17 @@ public class PhoneSwitcher extends Handler {
            return;
        }

        // Remove EVENT_NETWORK_VALIDATION_DONE. Don't handle validation result of previously subId
        // if queued.
        removeMessages(EVENT_NETWORK_VALIDATION_DONE);

        int subIdToValidate = (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)
                ? mPrimaryDataSubId : subId;

        if (mValidator.isValidating()
                && (!needValidation || subIdToValidate != mValidator.getSubIdInValidation())) {
        if (mValidator.isValidating()) {
            mValidator.stopValidation();
            sendSetOpptCallbackHelper(mSetOpptSubCallback, SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED);
            mSetOpptSubCallback = null;
        }

        if (subId == mOpptDataSubId) {
+49 −2
Original line number Diff line number Diff line
@@ -18,14 +18,18 @@ package com.android.internal.telephony.dataconnection;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.data.ApnSetting;
import android.telephony.data.ApnSetting.ApnType;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.SubscriptionController;
import com.android.internal.telephony.dataconnection.DataEnabledOverride.OverrideConditions.Condition;

@@ -52,7 +56,9 @@ public class DataEnabledOverride {
     */
    private static final OverrideRule OVERRIDE_RULE_ALLOW_DATA_DURING_VOICE_CALL =
            new OverrideRule(ApnSetting.TYPE_ALL, OverrideConditions.CONDITION_IN_VOICE_CALL
                    | OverrideConditions.CONDITION_NON_DEFAULT);
                    | OverrideConditions.CONDITION_NON_DEFAULT
                    | OverrideConditions.CONDITION_DEFAULT_DATA_ENABLED
                    | OverrideConditions.CONDITION_DSDS_ENABLED);

    /**
     * The rule for always allowing mms. Without adding any condition to the rule, any condition can
@@ -157,6 +163,12 @@ public class DataEnabledOverride {
        /** Enable data only when device has ongoing voice call */
        static final int CONDITION_IN_VOICE_CALL = 1 << 1;

        /** Enable data only when default data is on */
        static final int CONDITION_DEFAULT_DATA_ENABLED = 1 << 2;

        /** Enable data only when device is in DSDS mode */
        static final int CONDITION_DSDS_ENABLED = 1 << 3;

        /** Enable data unconditionally in string format */
        static final String CONDITION_UNCONDITIONALLY_STRING = "unconditionally";

@@ -166,10 +178,18 @@ public class DataEnabledOverride {
        /** Enable data only when device has ongoing voice call in string format */
        static final String CONDITION_VOICE_CALL_STRING = "inVoiceCall";

        /** Enable data only when default data is on in string format */
        static final String CONDITION_DEFAULT_DATA_ENABLED_STRING = "DefaultDataOn";

        /** Enable data only when device is in DSDS mode in string format */
        static final String CONDITION_DSDS_ENABLED_STRING = "dsdsEnabled";

        /** @hide */
        @IntDef(flag = true, prefix = { "OVERRIDE_CONDITION_" }, value = {
                CONDITION_NON_DEFAULT,
                CONDITION_IN_VOICE_CALL,
                CONDITION_DEFAULT_DATA_ENABLED,
                CONDITION_DSDS_ENABLED
        })
        @Retention(RetentionPolicy.SOURCE)
        public @interface Condition {}
@@ -182,6 +202,10 @@ public class DataEnabledOverride {
                    CONDITION_NON_DEFAULT_STRING);
            OVERRIDE_CONDITION_INT_MAP.put(CONDITION_IN_VOICE_CALL,
                    CONDITION_VOICE_CALL_STRING);
            OVERRIDE_CONDITION_INT_MAP.put(CONDITION_DEFAULT_DATA_ENABLED,
                    CONDITION_DEFAULT_DATA_ENABLED_STRING);
            OVERRIDE_CONDITION_INT_MAP.put(CONDITION_DSDS_ENABLED,
                    CONDITION_DSDS_ENABLED_STRING);

            OVERRIDE_CONDITION_STRING_MAP.put(CONDITION_UNCONDITIONALLY_STRING,
                    CONDITION_UNCONDITIONALLY);
@@ -189,6 +213,10 @@ public class DataEnabledOverride {
                    CONDITION_NON_DEFAULT);
            OVERRIDE_CONDITION_STRING_MAP.put(CONDITION_VOICE_CALL_STRING,
                    CONDITION_IN_VOICE_CALL);
            OVERRIDE_CONDITION_STRING_MAP.put(CONDITION_DEFAULT_DATA_ENABLED_STRING,
                    CONDITION_DEFAULT_DATA_ENABLED);
            OVERRIDE_CONDITION_STRING_MAP.put(CONDITION_DSDS_ENABLED_STRING,
                    CONDITION_DSDS_ENABLED);
        }

        private final @Condition int mConditions;
@@ -353,9 +381,28 @@ public class DataEnabledOverride {
                conditions |= OverrideConditions.CONDITION_IN_VOICE_CALL;
            }

            if (phone.getSubId() != SubscriptionController.getInstance().getDefaultDataSubId()) {
            int defaultDataSubId = SubscriptionController.getInstance().getDefaultDataSubId();

            if (phone.getSubId() != defaultDataSubId) {
                conditions |= OverrideConditions.CONDITION_NON_DEFAULT;
            }

            if (defaultDataSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
                int phoneId = SubscriptionController.getInstance().getPhoneId(defaultDataSubId);
                try {
                    Phone defaultDataPhone = PhoneFactory.getPhone(phoneId);
                    if (defaultDataPhone != null && defaultDataPhone.isUserDataEnabled()) {
                        conditions |= OverrideConditions.CONDITION_DEFAULT_DATA_ENABLED;
                    }
                } catch (IllegalStateException e) {
                    //ignore the exception and do not add the condition
                    Log.d("DataEnabledOverride", e.getMessage());
                }
            }

            if (TelephonyManager.from(phone.getContext()).isMultiSimEnabled()) {
                conditions |= OverrideConditions.CONDITION_DSDS_ENABLED;
            }
        }

        return conditions;
+109 −0
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

package com.android.internal.telephony;

import static android.telephony.TelephonyManager.SET_OPPORTUNISTIC_SUB_INACTIVE_SUBSCRIPTION;
import static android.telephony.TelephonyManager.SET_OPPORTUNISTIC_SUB_SUCCESS;
import static android.telephony.TelephonyManager.SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED;

import static com.android.internal.telephony.PhoneSwitcher.EVENT_DATA_ENABLED_CHANGED;
import static com.android.internal.telephony.PhoneSwitcher.EVENT_PRECISE_CALL_STATE_CHANGED;

@@ -94,6 +98,10 @@ public class PhoneSwitcherTest extends TelephonyTest {
    private GsmCdmaCall mHoldingCall;
    @Mock
    private GsmCdmaCall mInactiveCall;
    @Mock
    private ISetOpportunisticDataCallback mSetOpptDataCallback1;
    @Mock
    private ISetOpportunisticDataCallback mSetOpptDataCallback2;

    // The thread that mPhoneSwitcher will handle events in.
    private HandlerThread mHandlerThread;
@@ -870,6 +878,107 @@ public class PhoneSwitcherTest extends TelephonyTest {
        mHandlerThread.quit();
    }

    @Test
    @SmallTest
    public void testSetPreferredDataCallback() throws Exception {
        final int numPhones = 2;
        final int maxActivePhones = 1;
        doReturn(true).when(mMockRadioConfig).isSetPreferredDataCommandSupported();
        initialize(numPhones, maxActivePhones);

        // Mark sub 2 as opportunistic.
        doReturn(true).when(mSubscriptionController).isOpportunistic(2);
        // Phone 0 has sub 1, phone 1 has sub 2.
        // Sub 1 is default data sub.
        // Both are active subscriptions are active sub, as they are in both active slots.
        setSlotIndexToSubId(0, 1);
        setSlotIndexToSubId(1, 2);
        setDefaultDataSubId(1);
        waitABit();

        // Validating on sub 10 which is inactive.
        mPhoneSwitcher.trySetOpportunisticDataSubscription(10, true, mSetOpptDataCallback1);
        waitABit();
        verify(mSetOpptDataCallback1).onComplete(SET_OPPORTUNISTIC_SUB_INACTIVE_SUBSCRIPTION);

        // Switch to active subId without validating. Should always succeed.
        mPhoneSwitcher.trySetOpportunisticDataSubscription(2, false, mSetOpptDataCallback1);
        waitABit();
        verify(mSetOpptDataCallback1).onComplete(SET_OPPORTUNISTIC_SUB_SUCCESS);

        // Validating on sub 1 and fails.
        clearInvocations(mSetOpptDataCallback1);
        mPhoneSwitcher.trySetOpportunisticDataSubscription(1, true, mSetOpptDataCallback1);
        waitABit();
        mPhoneSwitcher.mValidationCallback.onValidationResult(false, 1);
        waitABit();
        verify(mSetOpptDataCallback1).onComplete(SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED);

        // Validating on sub 2 and succeeds.
        mPhoneSwitcher.trySetOpportunisticDataSubscription(2, true, mSetOpptDataCallback2);
        waitABit();
        mPhoneSwitcher.mValidationCallback.onValidationResult(true, 2);
        waitABit();
        verify(mSetOpptDataCallback2).onComplete(SET_OPPORTUNISTIC_SUB_SUCCESS);

        // Switching data back to primary and validation fails.
        clearInvocations(mSetOpptDataCallback2);
        mPhoneSwitcher.trySetOpportunisticDataSubscription(
                SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, true, mSetOpptDataCallback2);
        waitABit();
        mPhoneSwitcher.mValidationCallback.onValidationResult(false, 1);
        waitABit();
        verify(mSetOpptDataCallback1).onComplete(SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED);

        // Switching data back to primary and succeeds.
        clearInvocations(mSetOpptDataCallback2);
        mPhoneSwitcher.trySetOpportunisticDataSubscription(
                SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, true, mSetOpptDataCallback2);
        waitABit();
        mPhoneSwitcher.mValidationCallback.onValidationResult(true, 1);
        waitABit();
        verify(mSetOpptDataCallback2).onComplete(SET_OPPORTUNISTIC_SUB_SUCCESS);

        // Back to back call on same subId.
        clearInvocations(mSetOpptDataCallback1);
        clearInvocations(mSetOpptDataCallback2);
        mPhoneSwitcher.trySetOpportunisticDataSubscription(2, true, mSetOpptDataCallback1);
        waitABit();
        verify(mCellularNetworkValidator).validate(eq(2), anyInt(), eq(false),
                eq(mPhoneSwitcher.mValidationCallback));
        doReturn(true).when(mCellularNetworkValidator).isValidating();
        mPhoneSwitcher.trySetOpportunisticDataSubscription(2, true, mSetOpptDataCallback2);
        waitABit();
        verify(mSetOpptDataCallback1).onComplete(SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED);
        verify(mSetOpptDataCallback2, never()).onComplete(anyInt());
        // Validation succeeds.
        doReturn(false).when(mCellularNetworkValidator).isValidating();
        mPhoneSwitcher.mValidationCallback.onValidationResult(true, 2);
        waitABit();
        verify(mSetOpptDataCallback2).onComplete(SET_OPPORTUNISTIC_SUB_SUCCESS);

        mPhoneSwitcher.trySetOpportunisticDataSubscription(
                SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, false, null);
        waitABit();
        clearInvocations(mSetOpptDataCallback1);
        clearInvocations(mSetOpptDataCallback2);
        clearInvocations(mCellularNetworkValidator);
        // Back to back call, call 1 to switch to subId 2, call 2 to switch back.
        mPhoneSwitcher.trySetOpportunisticDataSubscription(2, true, mSetOpptDataCallback1);
        waitABit();
        verify(mCellularNetworkValidator).validate(eq(2), anyInt(), eq(false),
                eq(mPhoneSwitcher.mValidationCallback));
        doReturn(true).when(mCellularNetworkValidator).isValidating();
        mPhoneSwitcher.trySetOpportunisticDataSubscription(
                SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, true, mSetOpptDataCallback2);
        waitABit();
        // Call 1 should be cancelled and failed. Call 2 return success immediately as there's no
        // change.
        verify(mSetOpptDataCallback1).onComplete(SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED);
        verify(mSetOpptDataCallback2).onComplete(SET_OPPORTUNISTIC_SUB_SUCCESS);
        mHandlerThread.quit();
    }

    /* Private utility methods start here */

    private void setAllPhonesInactive() {
+2 −3
Original line number Diff line number Diff line
@@ -210,10 +210,9 @@ public class DataEnabledOverrideTest extends TelephonyTest {
        doReturn(2).when(mSubscriptionController).getDefaultSmsSubId();

        doReturn(PhoneConstants.State.OFFHOOK).when(mPhone).getState();
        assertTrue(deo.getRules(), deo.shouldOverrideDataEnabledSettings(mPhone,
                ApnSetting.TYPE_DEFAULT));
        deo.setDataAllowedInVoiceCall(false);
        assertFalse(deo.shouldOverrideDataEnabledSettings(mPhone, ApnSetting.TYPE_DEFAULT));
        assertFalse(deo.getRules(), deo.shouldOverrideDataEnabledSettings(
                mPhone, ApnSetting.TYPE_DEFAULT));
        assertFalse(deo.isDataAllowedInVoiceCall());
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ public class DataEnabledSettingsTest extends TelephonyTest {
        ArgumentCaptor<String> stringCaptor = ArgumentCaptor.forClass(String.class);
        verify(mSubscriptionController).setDataEnabledOverrideRules(anyInt(),
                stringCaptor.capture());
        assertEquals("*=nonDefault&inVoiceCall", stringCaptor.getValue());
        assertEquals("*=nonDefault&inVoiceCall&DefaultDataOn&dsdsEnabled", stringCaptor.getValue());

        clearInvocations(mSubscriptionController);