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

Commit 8accd0ad authored by Willy Hu's avatar Willy Hu
Browse files

[DSRM] Refine the Recovery Action Skip Mechanism

Update the next action between the timer(3 mins) if users perform the mobile data on/off or radio restart.

- Update the next action when receiving the mobile data enabled changed
- Update the next action when receiving the radio state changed
- Add unit test

Doc: go/dsrm-improve
Bug: 303182709
Test: Local test passed.
Change-Id: I6542797a4ecef6157ed87f26150a79c29feb21f4
parent 51f404dd
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -372,6 +372,7 @@ public class DataStallRecoveryManager extends Handler {
                                    0) != 0) {
                        mIsAirPlaneModeEnableDuringDataStall = true;
                    }
                    setRecoveryAction(mLastAction);
                }
                break;
            case EVENT_CONTENT_DSRM_ENABLED_ACTIONS_CHANGED:
@@ -527,6 +528,7 @@ public class DataStallRecoveryManager extends Handler {
        // during data stalled.
        if (mDataStalled && enabled) {
            mMobileDataChangedToEnabledDuringDataStall = true;
            setRecoveryAction(mLastAction);
        }
    }

+69 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.testing.TestableLooper;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyTest;
import com.android.internal.telephony.data.DataNetworkController.DataNetworkControllerCallback;
import com.android.internal.telephony.data.DataSettingsManager.DataSettingsManagerCallback;
import com.android.internal.telephony.data.DataStallRecoveryManager.DataStallRecoveryManagerCallback;

import org.junit.After;
@@ -145,6 +146,17 @@ public class DataStallRecoveryManagerTest extends TelephonyTest {
        dataNetworkControllerCallback.onInternetDataNetworkValidationStatusChanged(status);
    }

    private void sendDataEabledCallback(boolean isEnabled) {
        ArgumentCaptor<DataSettingsManagerCallback> dataSettingsManagerCallbackCaptor =
                ArgumentCaptor.forClass(DataSettingsManagerCallback.class);
        verify(mDataSettingsManager).registerCallback(dataSettingsManagerCallbackCaptor.capture());

        // Data enabled
        doReturn(isEnabled).when(mDataSettingsManager).isDataEnabled();
        dataSettingsManagerCallbackCaptor.getValue().onDataEnabledChanged(isEnabled,
                TelephonyManager.DATA_ENABLED_REASON_USER, "");
    }

    private void sendOnInternetDataNetworkCallback(boolean isConnected) {
        ArgumentCaptor<DataNetworkControllerCallback> dataNetworkControllerCallbackCaptor =
                ArgumentCaptor.forClass(DataNetworkControllerCallback.class);
@@ -257,7 +269,8 @@ public class DataStallRecoveryManagerTest extends TelephonyTest {
        moveTimeForward(15000);
        processAllMessages();

        assertThat(mDataStallRecoveryManager.getRecoveryAction()).isEqualTo(3);
        // should not change the recovery action due to there is an active call.
        assertThat(mDataStallRecoveryManager.getRecoveryAction()).isEqualTo(1);
    }

    @Test
@@ -510,4 +523,59 @@ public class DataStallRecoveryManagerTest extends TelephonyTest {
        // Check if predict waiting millis is 0
        assertThat(field.get(mDataStallRecoveryManager)).isEqualTo(0L);
    }

    @Test
    public void testRecoveryActionAfterDataEnabled() throws Exception {
        sendDataEabledCallback(true);
        sendOnInternetDataNetworkCallback(true);
        sendValidationStatusCallback(NetworkAgent.VALIDATION_STATUS_VALID);
        mDataStallRecoveryManager.setRecoveryAction(0);
        doReturn(PhoneConstants.State.IDLE).when(mPhone).getState();
        doReturn(3).when(mSignalStrength).getLevel();
        doReturn(mSignalStrength).when(mPhone).getSignalStrength();
        logd("Sending validation failed callback");

        assertThat(mDataStallRecoveryManager.getRecoveryAction()).isEqualTo(0);
        sendValidationStatusCallback(NetworkAgent.VALIDATION_STATUS_NOT_VALID);
        processAllMessages();
        moveTimeForward(101);
        assertThat(mDataStallRecoveryManager.getRecoveryAction()).isEqualTo(1);

        // test mobile data off/on
        sendDataEabledCallback(false);
        sendDataEabledCallback(true);

        // recovery action will jump to next action if user doing the mobile data off/on.
        assertThat(mDataStallRecoveryManager.getRecoveryAction()).isEqualTo(3);
    }

    @Test
    public void testJumpToRecoveryActionRadioRestart() throws Exception {
        sendDataEabledCallback(true);
        sendOnInternetDataNetworkCallback(true);
        sendValidationStatusCallback(NetworkAgent.VALIDATION_STATUS_VALID);
        mDataStallRecoveryManager.setRecoveryAction(0);

        doReturn(PhoneConstants.State.IDLE).when(mPhone).getState();
        doReturn(3).when(mSignalStrength).getLevel();
        doReturn(mSignalStrength).when(mPhone).getSignalStrength();
        doReturn(TelephonyManager.RADIO_POWER_ON).when(mPhone).getRadioPowerState();
        assertThat(mDataStallRecoveryManager.getRecoveryAction()).isEqualTo(0);

        sendValidationStatusCallback(NetworkAgent.VALIDATION_STATUS_NOT_VALID);
        moveTimeForward(200);
        processAllMessages();
        moveTimeForward(200);
        mDataStallRecoveryManager.sendMessageDelayed(
                mDataStallRecoveryManager.obtainMessage(3), 1000);
        processAllMessages();
        sendValidationStatusCallback(NetworkAgent.VALIDATION_STATUS_NOT_VALID);
        moveTimeForward(200);
        sendValidationStatusCallback(NetworkAgent.VALIDATION_STATUS_NOT_VALID);
        processAllMessages();
        moveTimeForward(200);

        // recovery action will jump to modem reset action if user doing the radio restart.
        assertThat(mDataStallRecoveryManager.getRecoveryAction()).isEqualTo(4);
    }
}