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

Commit a77c6978 authored by Wang Han's avatar Wang Han Committed by Rashed Abdel-Tawab
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
(cherry picked from commit b4468d81)
parent 23e67465
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -159,6 +159,30 @@ public class UsbBackend {
                && 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) {
        // TODO replace with UsbManager.usbFunctionsToString once supported by Roboelectric
        return Long.toBinaryString(functions);
+2 −1
Original line number Diff line number Diff line
@@ -113,7 +113,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
@@ -123,7 +123,8 @@ public class UsbDetailsPowerRoleController extends UsbDetailsController

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

    @Override