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

Commit 3251a04b authored by Hugh Chen's avatar Hugh Chen
Browse files

Do nothing when choosing file transfer when in accessory mode

- Before this CL, the device will be disconnected and reconnected
  to accessory mode when choosing "File transfer/Android Auto" in
  accessory mode. Because the USB menu didn't check state of
  function, it should do nothing when choosing
  "File transfer/Android Auto" in accessory mode.

  This CL add condition to check state of function, it will do
  nothing when choosing "File transfer/Android Auto" in
  accessory mode.

Bug: 162451162
Test: make -j42 RunSettingsRoboTests
Change-Id: I1749c6c43d2a192e4ce1bf1ae5343ff8deafbe48
parent c39bf6fd
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -115,7 +115,8 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
    public void onRadioButtonClicked(RadioButtonPreference preference) {
    public void onRadioButtonClicked(RadioButtonPreference preference) {
        final long function = UsbBackend.usbFunctionsFromString(preference.getKey());
        final long function = UsbBackend.usbFunctionsFromString(preference.getKey());
        final long previousFunction = mUsbBackend.getCurrentFunctions();
        final long previousFunction = mUsbBackend.getCurrentFunctions();
        if (function != previousFunction && !Utils.isMonkeyRunning()) {
        if (function != previousFunction && !Utils.isMonkeyRunning()
                && !shouldIgnoreClickEvent(function, previousFunction)) {
            mPreviousFunction = previousFunction;
            mPreviousFunction = previousFunction;


            //Update the UI in advance to make it looks smooth
            //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
    @Override
    public boolean isAvailable() {
    public boolean isAvailable() {
        return !Utils.isMonkeyRunning();
        return !Utils.isMonkeyRunning();
+12 −0
Original line number Original line Diff line number Diff line
@@ -263,6 +263,18 @@ public class UsbDetailsFunctionsControllerTest {
                UsbManager.FUNCTION_MTP);
                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
    @Test
    public void onRadioButtonClicked_clickSameButton_doNothing() {
    public void onRadioButtonClicked_clickSameButton_doNothing() {
        mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_PTP));
        mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_PTP));