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

Commit b4468d81 authored by Wang Han's avatar Wang Han Committed by Bruno Martins
Browse files

Settings: Hide unsupported USB modes automatically

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

Change-Id: I5933d1a03f573af08b00039850173329b293448a
parent ab5e43f0
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -153,6 +153,30 @@ public class UsbBackend {
                .isRoleCombinationSupported(UsbPort.POWER_ROLE_SOURCE, UsbPort.DATA_ROLE_HOST);
    }

    public boolean isSingleDataRoleSupported() {
        return mPort != null && mPortStatus != null
                && ((!mPortStatus
                .isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_HOST)
                && !mPortStatus
                .isRoleCombinationSupported(UsbPort.POWER_ROLE_SOURCE, UsbPort.DATA_ROLE_HOST))
                || (!mPortStatus
                .isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE)
                && !mPortStatus
                .isRoleCombinationSupported(UsbPort.POWER_ROLE_SOURCE, UsbPort.DATA_ROLE_DEVICE)));
    }

    public boolean isSinglePowerRoleSupported() {
        return mPort != null && mPortStatus != null
                && ((!mPortStatus
                .isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE)
                && !mPortStatus
                .isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_HOST))
                || (!mPortStatus
                .isRoleCombinationSupported(UsbPort.POWER_ROLE_SOURCE, UsbPort.DATA_ROLE_DEVICE)
                && !mPortStatus
                .isRoleCombinationSupported(UsbPort.POWER_ROLE_SOURCE, UsbPort.DATA_ROLE_HOST)));
    }

    public static String usbFunctionsToString(long functions) {
        // TODO replace with UsbManager.usbFunctionsToString once supported by Roboelectric
        return Long.toBinaryString(functions);
+2 −1
Original line number Diff line number Diff line
@@ -109,7 +109,8 @@ public class UsbDetailsDataRoleController extends UsbDetailsController

    @Override
    public boolean isAvailable() {
        return !Utils.isMonkeyRunning();
        return !Utils.isMonkeyRunning()
                && !mUsbBackend.isSingleDataRoleSupported();
    }

    @Override
+2 −1
Original line number Diff line number Diff line
@@ -118,7 +118,8 @@ public class UsbDetailsPowerRoleController extends UsbDetailsController

    @Override
    public boolean isAvailable() {
        return !Utils.isMonkeyRunning();
        return !Utils.isMonkeyRunning()
                && !mUsbBackend.isSinglePowerRoleSupported();
    }

    @Override