Merge "Add condition to check case of accessory combinations"
This commit is contained in:
committed by
Android (Google) Code Review
commit
ccdf18ccee
@@ -22,6 +22,7 @@ import static android.net.ConnectivityManager.TETHERING_USB;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.hardware.usb.UsbManager;
|
import android.hardware.usb.UsbManager;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.PreferenceCategory;
|
import androidx.preference.PreferenceCategory;
|
||||||
@@ -40,6 +41,9 @@ import java.util.Map;
|
|||||||
public class UsbDetailsFunctionsController extends UsbDetailsController
|
public class UsbDetailsFunctionsController extends UsbDetailsController
|
||||||
implements RadioButtonPreference.OnClickListener {
|
implements RadioButtonPreference.OnClickListener {
|
||||||
|
|
||||||
|
private static final String TAG = "UsbFunctionsCtrl";
|
||||||
|
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||||
|
|
||||||
static final Map<Long, Integer> FUNCTIONS_MAP = new LinkedHashMap<>();
|
static final Map<Long, Integer> FUNCTIONS_MAP = new LinkedHashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -88,6 +92,10 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void refresh(boolean connected, long functions, int powerRole, int dataRole) {
|
protected void refresh(boolean connected, long functions, int powerRole, int dataRole) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "refresh() connected : " + connected + ", functions : " + functions
|
||||||
|
+ ", powerRole : " + powerRole + ", dataRole : " + dataRole);
|
||||||
|
}
|
||||||
if (!connected || dataRole != DATA_ROLE_DEVICE) {
|
if (!connected || dataRole != DATA_ROLE_DEVICE) {
|
||||||
mProfilesContainer.setEnabled(false);
|
mProfilesContainer.setEnabled(false);
|
||||||
} else {
|
} else {
|
||||||
@@ -100,7 +108,7 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
|
|||||||
pref = getProfilePreference(UsbBackend.usbFunctionsToString(option), title);
|
pref = getProfilePreference(UsbBackend.usbFunctionsToString(option), title);
|
||||||
// Only show supported options
|
// Only show supported options
|
||||||
if (mUsbBackend.areFunctionsSupported(option)) {
|
if (mUsbBackend.areFunctionsSupported(option)) {
|
||||||
if (functions == UsbManager.FUNCTION_ACCESSORY) {
|
if (isAccessoryMode(functions)) {
|
||||||
pref.setChecked(UsbManager.FUNCTION_MTP == option);
|
pref.setChecked(UsbManager.FUNCTION_MTP == option);
|
||||||
} else {
|
} else {
|
||||||
pref.setChecked(functions == option);
|
pref.setChecked(functions == option);
|
||||||
@@ -115,6 +123,12 @@ 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 (DEBUG) {
|
||||||
|
Log.d(TAG, "onRadioButtonClicked() function : " + function + ", toString() : "
|
||||||
|
+ UsbManager.usbFunctionsToString(function) + ", previousFunction : "
|
||||||
|
+ previousFunction + ", toString() : "
|
||||||
|
+ UsbManager.usbFunctionsToString(previousFunction));
|
||||||
|
}
|
||||||
if (function != previousFunction && !Utils.isMonkeyRunning()
|
if (function != previousFunction && !Utils.isMonkeyRunning()
|
||||||
&& !shouldIgnoreClickEvent(function, previousFunction)) {
|
&& !shouldIgnoreClickEvent(function, previousFunction)) {
|
||||||
mPreviousFunction = previousFunction;
|
mPreviousFunction = previousFunction;
|
||||||
@@ -140,8 +154,11 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldIgnoreClickEvent(long function, long previousFunction) {
|
private boolean shouldIgnoreClickEvent(long function, long previousFunction) {
|
||||||
return previousFunction == UsbManager.FUNCTION_ACCESSORY
|
return isAccessoryMode(previousFunction) && function == UsbManager.FUNCTION_MTP;
|
||||||
&& function == UsbManager.FUNCTION_MTP;
|
}
|
||||||
|
|
||||||
|
private boolean isAccessoryMode(long function) {
|
||||||
|
return (function & UsbManager.FUNCTION_ACCESSORY) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -275,6 +275,18 @@ public class UsbDetailsFunctionsControllerTest {
|
|||||||
UsbManager.FUNCTION_ACCESSORY);
|
UsbManager.FUNCTION_ACCESSORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onRadioButtonClicked_functionMtp_inAccessoryCombinationsMode_doNothing() {
|
||||||
|
final long function = UsbManager.FUNCTION_ACCESSORY | UsbManager.FUNCTION_AUDIO_SOURCE;
|
||||||
|
mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_MTP));
|
||||||
|
doReturn(UsbManager.FUNCTION_ACCESSORY).when(mUsbBackend).getCurrentFunctions();
|
||||||
|
|
||||||
|
mDetailsFunctionsController.mPreviousFunction = function;
|
||||||
|
mDetailsFunctionsController.onRadioButtonClicked(mRadioButtonPreference);
|
||||||
|
|
||||||
|
assertThat(mDetailsFunctionsController.mPreviousFunction).isEqualTo(function);
|
||||||
|
}
|
||||||
|
|
||||||
@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));
|
||||||
|
Reference in New Issue
Block a user