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
Merged-In: I1749c6c43d2a192e4ce1bf1ae5343ff8deafbe48
(cherry picked from commit 3251a04ba3)
This commit is contained in:
Hugh Chen
2020-09-28 14:58:34 +08:00
parent 91ed63124c
commit e8dc7bc283
2 changed files with 19 additions and 1 deletions

View File

@@ -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();

View File

@@ -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));