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

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

Merge "Fixed handover issue on connecting data connection"

parents 3c212d75 ce85ca8e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -419,7 +419,8 @@ public class DataConnection extends StateMachine {
        return getCurrentState() == mDisconnectingState;
    }

    boolean isActive() {
    @VisibleForTesting
    public boolean isActive() {
        return getCurrentState() == mActiveState;
    }

+3 −3
Original line number Diff line number Diff line
@@ -347,16 +347,16 @@ public class TelephonyNetworkFactory extends NetworkFactory {
                if (dcTracker != null) {
                    DataConnection dc = dcTracker.getDataConnectionByApnType(
                            ApnSetting.getApnTypeString(apnType));
                    if (dc != null && (dc.isActive() || dc.isActivating())) {
                    if (dc != null && (dc.isActive())) {
                        Message onCompleteMsg = mInternalHandler.obtainMessage(
                                EVENT_DATA_HANDOVER_COMPLETED);
                        onCompleteMsg.getData().putParcelable(
                                DcTracker.DATA_COMPLETE_MSG_EXTRA_NETWORK_REQUEST, networkRequest);
                        mPendingHandovers.put(onCompleteMsg, handoverParams);
                        // TODO: Need to handle the case that the request is there, but there is no
                        // actual data connections established.
                        requestNetworkInternal(networkRequest, DcTracker.REQUEST_TYPE_HANDOVER,
                                targetTransport, onCompleteMsg);
                        log("Requested handover " + ApnSetting.getApnTypeString(apnType) + " to "
                                + AccessNetworkConstants.transportTypeToString(targetTransport));
                        handoverPending = true;
                    } else {
                        // Request is there, but no actual data connection. In this case, just move
+42 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.net.NetworkCapabilities;
@@ -57,6 +58,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;

import java.lang.reflect.Field;
import java.util.ArrayList;
@@ -72,6 +74,9 @@ public class TelephonyNetworkFactoryTest extends TelephonyTest {
    @Mock
    private RadioConfig mMockRadioConfig;

    @Mock
    private DataConnection mDataConnection;

    private String mTestName = "";

    private final ArrayList<NetworkRequest> mNetworkRequestList = new ArrayList<>();
@@ -346,4 +351,41 @@ public class TelephonyNetworkFactoryTest extends TelephonyTest {
        h.sendMessage(h.obtainMessage(5, ar));
        processAllMessages();
    }

    /**
     * Test handover when the data connection is being connected.
     */
    @Test
    @SmallTest
    public void testHandoverActivatingData() throws Exception {
        createMockedTelephonyComponents();
        doReturn(0).when(mSubscriptionController).getSubIdUsingPhoneId(0);
        mTelephonyNetworkFactoryUT.mInternalHandler.sendEmptyMessage(
                TelephonyNetworkFactory.EVENT_SUBSCRIPTION_CHANGED);

        activatePhoneInPhoneSwitcher(0, true);
        makeDefaultInternetRequest();

        makeSubSpecificMmsRequest(0);
        processAllMessages();

        Field f = TelephonyNetworkFactory.class.getDeclaredField("mInternalHandler");
        f.setAccessible(true);
        Handler h = (Handler) f.get(mTelephonyNetworkFactoryUT);

        HandoverCallback handoverCallback = mock(HandoverCallback.class);
        Mockito.reset(mDcTracker);
        doReturn(mDataConnection).when(mDcTracker).getDataConnectionByApnType(anyString());
        doReturn(false).when(mDataConnection).isActive();

        HandoverParams hp = new HandoverParams(ApnSetting.TYPE_MMS,
                AccessNetworkConstants.TRANSPORT_TYPE_WLAN, handoverCallback);
        AsyncResult ar = new AsyncResult(null, hp, null);
        h.sendMessage(h.obtainMessage(5, ar));
        processAllMessages();

        verify(mDcTracker, times(1)).releaseNetwork(any(), eq(1));
        verify(mDcTracker, times(1)).requestNetwork(any(), eq(1), any());
    }

}