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

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

Merge "Do nothing when choosing file transfer when in accessory mode"

parents e8fa7462 3251a04b
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -115,7 +115,8 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
    public void onRadioButtonClicked(RadioButtonPreference preference) {
        final long function = UsbBackend.usbFunctionsFromString(preference.getKey());
        final long previousFunction = mUsbBackend.getCurrentFunctions();
        if (function != previousFunction && !Utils.isMonkeyRunning()) {
        if (function != previousFunction && !Utils.isMonkeyRunning()
                && !shouldIgnoreClickEvent(function, previousFunction)) {
            mPreviousFunction = previousFunction;

            //Update the UI in advance to make it looks smooth
@@ -138,6 +139,11 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
        }
    }

    private boolean shouldIgnoreClickEvent(long function, long previousFunction) {
        return previousFunction == UsbManager.FUNCTION_ACCESSORY
                && function == UsbManager.FUNCTION_MTP;
    }

    @Override
    public boolean isAvailable() {
        return !Utils.isMonkeyRunning();
+12 −0
Original line number Diff line number Diff line
@@ -263,6 +263,18 @@ public class UsbDetailsFunctionsControllerTest {
                UsbManager.FUNCTION_MTP);
    }

    @Test
    public void onRadioButtonClicked_functionMtp_inAccessoryMode_doNothing() {
        mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_MTP));
        doReturn(UsbManager.FUNCTION_ACCESSORY).when(mUsbBackend).getCurrentFunctions();

        mDetailsFunctionsController.mPreviousFunction = UsbManager.FUNCTION_ACCESSORY;
        mDetailsFunctionsController.onRadioButtonClicked(mRadioButtonPreference);

        assertThat(mDetailsFunctionsController.mPreviousFunction).isEqualTo(
                UsbManager.FUNCTION_ACCESSORY);
    }

    @Test
    public void onRadioButtonClicked_clickSameButton_doNothing() {
        mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_PTP));