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

Commit b6fb6dc8 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use carrier config to exempt data switch ping test" into udc-dev

parents c2f7a134 56159626
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -319,6 +319,8 @@ public class DataConfigManager extends Handler {
    private @NonNull final List<HandoverRule> mHandoverRuleList = new ArrayList<>();
    /** {@code True} keep IMS network in case of moving to non VOPS area; {@code false} otherwise.*/
    private boolean mShouldKeepNetworkUpInNonVops = false;
    /** {@code True} requires ping test before switching preferred modem; {@code false} otherwise.*/
    private boolean mPingTestBeforeDataSwitch = true;

    /**
     * Constructor
@@ -472,6 +474,7 @@ public class DataConfigManager extends Handler {
        updateMeteredApnTypes();
        updateSingleDataNetworkTypeAndCapabilityExemption();
        updateVopsConfig();
        updateDataSwitchConfig();
        updateUnmeteredNetworkTypes();
        updateBandwidths();
        updateTcpBuffers();
@@ -692,6 +695,16 @@ public class DataConfigManager extends Handler {
        }
    }

    /**
     * Update preferred modem switch(opportunistic network or visible subscription) carrier config.
     */
    private void updateDataSwitchConfig() {
        synchronized (this) {
            mPingTestBeforeDataSwitch = mCarrierConfig.getBoolean(CarrierConfigManager
                    .KEY_PING_TEST_BEFORE_DATA_SWITCH_BOOL, true);
        }
    }

    /**
     * @return The list of {@link NetworkType} that only supports single data networks
     */
@@ -712,6 +725,11 @@ public class DataConfigManager extends Handler {
        return mShouldKeepNetworkUpInNonVops;
    }

    /** {@code True} keep IMS network in case of moving to non VOPS area; {@code false} otherwise.*/
    public boolean requirePingTestBeforeDataSwitch() {
        return mPingTestBeforeDataSwitch;
    }

    /**
     * @return Whether {@link NetworkCapabilities#NET_CAPABILITY_TEMPORARILY_NOT_METERED}
     * is supported by the carrier.
@@ -1344,6 +1362,7 @@ public class DataConfigManager extends Handler {
                .stream().map(DataUtils::networkCapabilityToString)
                .collect(Collectors.joining(",")));
        pw.println("mShouldKeepNetworkUpInNoVops=" + mShouldKeepNetworkUpInNonVops);
        pw.println("mPingTestBeforeDataSwitch=" + mPingTestBeforeDataSwitch);
        pw.println("Unmetered network types=" + String.join(",", mUnmeteredNetworkTypes));
        pw.println("Roaming unmetered network types="
                + String.join(",", mRoamingUnmeteredNetworkTypes));
+34 −9
Original line number Diff line number Diff line
@@ -298,7 +298,13 @@ public class PhoneSwitcher extends Handler {
        @Override
        public void onDeviceConfigChanged() {
            log("onDeviceConfigChanged");
            PhoneSwitcher.this.updateConfig();
            PhoneSwitcher.this.updateDeviceConfig();
        }

        @Override
        public void onCarrierConfigChanged() {
            log("onCarrierConfigChanged");
            PhoneSwitcher.this.updateCarrierConfig();
        }
    };

@@ -361,6 +367,12 @@ public class PhoneSwitcher extends Handler {

    private List<Set<CommandException.Error>> mCurrentDdsSwitchFailure;

    /**
     * {@code true} if requires ping test before switching preferred data modem; otherwise, switch
     * even if ping test fails.
     */
    private boolean mRequirePingTestBeforeDataSwitch = true;

    /**
     * Time threshold in ms to define a internet connection status to be stable(e.g. out of service,
     * in service, wifi is the default active network.etc), while -1 indicates auto switch
@@ -932,15 +944,15 @@ public class PhoneSwitcher extends Handler {
        if (phone != null) {
            DataConfigManager dataConfig = phone.getDataNetworkController().getDataConfigManager();
            dataConfig.registerCallback(mDataConfigManagerCallback);
            updateConfig();
            updateDeviceConfig();
            sendEmptyMessage(EVENT_EVALUATE_AUTO_SWITCH);
        }
    }

    /**
     * Update data config.
     * Update device config.
     */
    private void updateConfig() {
    private void updateDeviceConfig() {
        Phone phone = getPhoneBySubId(mPrimaryDataSubId);
        if (phone != null) {
            DataConfigManager dataConfig = phone.getDataNetworkController().getDataConfigManager();
@@ -951,6 +963,17 @@ public class PhoneSwitcher extends Handler {
        }
    }

    /**
     * Update carrier config.
     */
    private void updateCarrierConfig() {
        Phone phone = getPhoneBySubId(mPrimaryDataSubId);
        if (phone != null) {
            DataConfigManager dataConfig = phone.getDataNetworkController().getDataConfigManager();
            mRequirePingTestBeforeDataSwitch = dataConfig.requirePingTestBeforeDataSwitch();
        }
    }

    private synchronized void onMultiSimConfigChanged(int activeModemCount) {
        // No change.
        if (mActiveModemCount == activeModemCount) return;
@@ -1158,7 +1181,7 @@ public class PhoneSwitcher extends Handler {

            int candidateSubId = getAutoSwitchTargetSubIdIfExists();
            if (candidateSubId != INVALID_SUBSCRIPTION_ID) {
                startAutoDataSwitchStabilityCheck(candidateSubId, true);
                startAutoDataSwitchStabilityCheck(candidateSubId, mRequirePingTestBeforeDataSwitch);
            } else {
                cancelPendingAutoDataSwitch();
            }
@@ -1193,7 +1216,8 @@ public class PhoneSwitcher extends Handler {

            if (isInService(mPhoneStates[primaryPhoneId])) {
                // primary becomes available
                startAutoDataSwitchStabilityCheck(DEFAULT_SUBSCRIPTION_ID, true);
                startAutoDataSwitchStabilityCheck(DEFAULT_SUBSCRIPTION_ID,
                        mRequirePingTestBeforeDataSwitch);
                return;
            }

@@ -2067,8 +2091,8 @@ public class PhoneSwitcher extends Handler {
     * @param reason The switching reason.
     */
    private void logDataSwitchEvent(int subId, int state, int reason) {
        logl("Data switch event. subId=" + subId + ", state=" + switchStateToString(state)
                + ", reason=" + switchReasonToString(reason));
        logl("Data switch state=" + switchStateToString(state) + " due to reason="
                + switchReasonToString(reason) + " on subId " + subId);
        DataSwitch dataSwitch = new DataSwitch();
        dataSwitch.state = state;
        dataSwitch.reason = reason;
@@ -2141,6 +2165,7 @@ public class PhoneSwitcher extends Handler {
        pw.println("mAutoDataSwitchAvailabilityStabilityTimeThreshold="
                + mAutoDataSwitchAvailabilityStabilityTimeThreshold);
        pw.println("mAutoDataSwitchValidationMaxRetry=" + mAutoDataSwitchValidationMaxRetry);
        pw.println("mRequirePingTestBeforeDataSwitch=" + mRequirePingTestBeforeDataSwitch);
        pw.println("mLastSwitchPreferredDataReason="
                + switchReasonToString(mLastSwitchPreferredDataReason));
        pw.println("mDisplayedAutoSwitchNotification=" + mDisplayedAutoSwitchNotification);
+53 −7
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ public class PhoneSwitcherTest extends TelephonyTest {
    private Messenger mNetworkProviderMessenger = null;
    private Map<Integer, DataSettingsManager.DataSettingsManagerCallback>
            mDataSettingsManagerCallbacks;
    private DataConfigManager.DataConfigManagerCallback mDataConfigManagerCallback;
    private int mDefaultDataSub = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    private int[][] mSlotIndexToSubId;
    private boolean[] mDataAllowed;
@@ -562,7 +563,7 @@ public class PhoneSwitcherTest extends TelephonyTest {

    @Test
    @SmallTest
    public void testAutoDataSwitchRetry() throws Exception {
    public void testAutoDataSwitch_retry() throws Exception {
        initialize();
        // Phone 0 has sub 1, phone 1 has sub 2.
        // Sub 1 is default data sub.
@@ -590,7 +591,7 @@ public class PhoneSwitcherTest extends TelephonyTest {

    @Test
    @SmallTest
    public void testAutoDataSwitchSetNotification() throws Exception {
    public void testAutoDataSwitch_setNotification() throws Exception {
        SubscriptionInfo mockedInfo = mock(SubscriptionInfo.class);
        doReturn(false).when(mockedInfo).isOpportunistic();
        doReturn(mockedInfo).when(mSubscriptionController).getSubscriptionInfo(anyInt());
@@ -636,6 +637,41 @@ public class PhoneSwitcherTest extends TelephonyTest {
        }
    }

    @Test
    @SmallTest
    public void testAutoDataSwitch_exemptPingTest() throws Exception {
        initialize();
        // Phone 0 has sub 1, phone 1 has sub 2.
        // Sub 1 is default data sub.
        setSlotIndexToSubId(0, 1);
        setSlotIndexToSubId(1, 2);
        setDefaultDataSubId(1);

        doReturn(false).when(mDataConfigManager).requirePingTestBeforeDataSwitch();
        mDataConfigManagerCallback.onCarrierConfigChanged();

        //1. Attempting to switch to nDDS, switch even if validation failed
        prepareIdealAutoSwitchCondition();
        processAllFutureMessages();

        verify(mCellularNetworkValidator).validate(eq(2), anyLong(), eq(false),
                eq(mPhoneSwitcherUT.mValidationCallback));
        mPhoneSwitcherUT.mValidationCallback.onValidationDone(false, 2);
        processAllMessages();

        assertEquals(2, mPhoneSwitcherUT.getActiveDataSubId()); // switch succeeds

        //2. Attempting to switch back to DDS, switch even if validation failed
        serviceStateChanged(0, NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING);
        processAllFutureMessages();
        verify(mCellularNetworkValidator).validate(eq(1), anyLong(), eq(false),
                eq(mPhoneSwitcherUT.mValidationCallback));
        mPhoneSwitcherUT.mValidationCallback.onValidationDone(false, 1);
        processAllMessages();

        assertEquals(1, mPhoneSwitcherUT.getActiveDataSubId()); // switch succeeds
    }

    /**
     * Test a multi-sim case with limited active phones:
     * - lose default via default sub change
@@ -1964,7 +2000,6 @@ public class PhoneSwitcherTest extends TelephonyTest {
        initializeConnManagerMock();

        mPhoneSwitcherUT = new PhoneSwitcher(mMaxDataAttachModemCount, mContext, Looper.myLooper());
        processAllMessages();

        Field field = PhoneSwitcher.class.getDeclaredField("mDataSettingsManagerCallbacks");
        field.setAccessible(true);
@@ -1972,11 +2007,22 @@ public class PhoneSwitcherTest extends TelephonyTest {
                (Map<Integer, DataSettingsManager.DataSettingsManagerCallback>)
                        field.get(mPhoneSwitcherUT);

        int deviceConfigValue = 10000;
        field = PhoneSwitcher.class.getDeclaredField(
                "mAutoDataSwitchAvailabilityStabilityTimeThreshold");
        field = PhoneSwitcher.class.getDeclaredField("mDataConfigManagerCallback");
        field.setAccessible(true);
        field.setInt(mPhoneSwitcherUT, deviceConfigValue);
        mDataConfigManagerCallback =
                (DataConfigManager.DataConfigManagerCallback) field.get(mPhoneSwitcherUT);

        doReturn(mDataNetworkController).when(mPhone).getDataNetworkController();
        doReturn(mDataConfigManager).when(mDataNetworkController).getDataConfigManager();
        doReturn(1000L).when(mDataConfigManager)
                .getAutoDataSwitchAvailabilityStabilityTimeThreshold();
        doReturn(7).when(mDataConfigManager).getAutoDataSwitchValidationMaxRetry();
        doReturn(true).when(mDataConfigManager).requirePingTestBeforeDataSwitch();

        mDataConfigManagerCallback.onCarrierConfigChanged();
        mDataConfigManagerCallback.onDeviceConfigChanged();

        processAllMessages();

        verify(mTelephonyRegistryManager).addOnSubscriptionsChangedListener(any(), any());
    }