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

Commit 1659954b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Stop usb tethering when user cancel it" into rvc-dev am: 53c6c9a6

Change-Id: If3e0b046e04df06b44c692ba4869623fa39b7f38
parents 17deddb4 53c6c9a6
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -89,6 +89,9 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
    @Override
    protected void refresh(boolean connected, long functions, int powerRole, int dataRole) {
        if (!connected || dataRole != DATA_ROLE_DEVICE) {
            if (mPreviousFunction == UsbManager.FUNCTION_RNDIS) {
                mConnectivityManager.stopTethering(TETHERING_USB);
            }
            mProfilesContainer.setEnabled(false);
        } else {
            // Functions are only available in device mode
@@ -129,6 +132,9 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
                mConnectivityManager.startTethering(TETHERING_USB, true /* showProvisioningUi */,
                        mOnStartTetheringCallback);
            } else {
                if (mPreviousFunction == UsbManager.FUNCTION_RNDIS) {
                    mConnectivityManager.stopTethering(TETHERING_USB);
                }
                mUsbBackend.setCurrentFunctions(function);
            }
        }
+38 −0
Original line number Diff line number Diff line
@@ -270,4 +270,42 @@ public class UsbDetailsFunctionsControllerTest {

        verify(mUsbBackend).setCurrentFunctions(UsbManager.FUNCTION_PTP);
    }

    @Test
    public void refresh_previousFunctionIsRndis_stopTethering() {
        mDetailsFunctionsController.mPreviousFunction = UsbManager.FUNCTION_RNDIS;

        mDetailsFunctionsController.refresh(false, 0, 0, 0);

        verify(mConnectivityManager).stopTethering(TETHERING_USB);
    }

    @Test
    public void refresh_previousFunctionIsNotRndis_doNothing() {
        mDetailsFunctionsController.mPreviousFunction = UsbManager.FUNCTION_MIDI;

        mDetailsFunctionsController.refresh(false, 0, 0, 0);

        verify(mConnectivityManager, never()).stopTethering(TETHERING_USB);
    }

    @Test
    public void onRadioButtonClicked_previousFunctionIsRndis_stopTethering() {
        mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_PTP));
        doReturn(UsbManager.FUNCTION_RNDIS).when(mUsbBackend).getCurrentFunctions();

        mDetailsFunctionsController.onRadioButtonClicked(mRadioButtonPreference);

        verify(mConnectivityManager).stopTethering(TETHERING_USB);
    }

    @Test
    public void onRadioButtonClicked_previousFunctionIsNotRndis_doNothing() {
        mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_PTP));
        doReturn(UsbManager.FUNCTION_MIDI).when(mUsbBackend).getCurrentFunctions();

        mDetailsFunctionsController.onRadioButtonClicked(mRadioButtonPreference);

        verify(mConnectivityManager, never()).stopTethering(TETHERING_USB);
    }
}