Settings: Hide unsupported USB modes automatically

* The roles are advertised by USB HAL so we can check for their status

Change-Id: I5933d1a03f573af08b00039850173329b293448a
This commit is contained in:
Wang Han
2018-09-09 11:27:15 +08:00
committed by Michael Bestas
parent f13e716b6f
commit 29ce275eb5
3 changed files with 28 additions and 2 deletions

View File

@@ -165,6 +165,30 @@ public class UsbBackend {
&& mPortStatus.isRoleCombinationSupported(POWER_ROLE_SOURCE, DATA_ROLE_HOST); && mPortStatus.isRoleCombinationSupported(POWER_ROLE_SOURCE, DATA_ROLE_HOST);
} }
public boolean isSingleDataRoleSupported() {
return mPort != null && mPortStatus != null
&& ((!mPortStatus
.isRoleCombinationSupported(POWER_ROLE_SINK, DATA_ROLE_HOST)
&& !mPortStatus
.isRoleCombinationSupported(POWER_ROLE_SOURCE, DATA_ROLE_HOST))
|| (!mPortStatus
.isRoleCombinationSupported(POWER_ROLE_SINK, DATA_ROLE_DEVICE)
&& !mPortStatus
.isRoleCombinationSupported(POWER_ROLE_SOURCE, DATA_ROLE_DEVICE)));
}
public boolean isSinglePowerRoleSupported() {
return mPort != null && mPortStatus != null
&& ((!mPortStatus
.isRoleCombinationSupported(POWER_ROLE_SINK, DATA_ROLE_DEVICE)
&& !mPortStatus
.isRoleCombinationSupported(POWER_ROLE_SINK, DATA_ROLE_HOST))
|| (!mPortStatus
.isRoleCombinationSupported(POWER_ROLE_SOURCE, DATA_ROLE_DEVICE)
&& !mPortStatus
.isRoleCombinationSupported(POWER_ROLE_SOURCE, DATA_ROLE_HOST)));
}
public static String usbFunctionsToString(long functions) { public static String usbFunctionsToString(long functions) {
// TODO replace with UsbManager.usbFunctionsToString once supported by Roboelectric // TODO replace with UsbManager.usbFunctionsToString once supported by Roboelectric
return Long.toBinaryString(functions); return Long.toBinaryString(functions);

View File

@@ -115,7 +115,8 @@ public class UsbDetailsDataRoleController extends UsbDetailsController
@Override @Override
public boolean isAvailable() { public boolean isAvailable() {
return !Utils.isMonkeyRunning(); return !Utils.isMonkeyRunning()
&& !mUsbBackend.isSingleDataRoleSupported();
} }
@Override @Override

View File

@@ -126,7 +126,8 @@ public class UsbDetailsPowerRoleController extends UsbDetailsController
@Override @Override
public boolean isAvailable() { public boolean isAvailable() {
return !Utils.isMonkeyRunning(); return !Utils.isMonkeyRunning()
&& !mUsbBackend.isSinglePowerRoleSupported();
} }
@Override @Override