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

Commit d9793989 authored by Badhri Jagan Sridharan's avatar Badhri Jagan Sridharan Committed by Android (Google) Code Review
Browse files

Merge "Refactor UsbPortManager to use the binderised USB HAL"

parents 454a9777 823287d2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -537,6 +537,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \
    framework-protos                                    \
    android.hardware.thermal@1.0-java-constants         \
    android.hardware.health@1.0-java-constants          \
    android.hardware.usb@1.0-java-constants             \

LOCAL_PROTOC_OPTIMIZE_TYPE := stream
LOCAL_PROTOC_FLAGS := \
+52 −17
Original line number Diff line number Diff line
@@ -16,11 +16,12 @@

package android.hardware.usb;

import com.android.internal.util.Preconditions;

import android.hardware.usb.V1_0.Constants;
import android.os.Parcel;
import android.os.Parcelable;

import com.android.internal.util.Preconditions;

/**
 * Represents a physical USB port and describes its characteristics.
 * <p>
@@ -33,6 +34,7 @@ public final class UsbPort implements Parcelable {
    private final String mId;
    private final int mSupportedModes;

    public static final int MODE_NONE = Constants.PortMode.NONE;
    /**
     * Mode bit: This USB port can act as a downstream facing port (host).
     * <p>
@@ -40,7 +42,7 @@ public final class UsbPort implements Parcelable {
     * combination of roles (and possibly others as well).
     * </p>
     */
    public static final int MODE_DFP = 1 << 0;
    public static final int MODE_DFP = Constants.PortMode.DFP;

    /**
     * Mode bit: This USB port can act as an upstream facing port (device).
@@ -49,7 +51,7 @@ public final class UsbPort implements Parcelable {
     * combination of roles (and possibly others as well).
     * </p>
     */
    public static final int MODE_UFP = 1 << 1;
    public static final int MODE_UFP = Constants.PortMode.UFP;

    /**
     * Mode bit: This USB port can act either as an downstream facing port (host) or as
@@ -60,29 +62,43 @@ public final class UsbPort implements Parcelable {
     * combination of roles (and possibly others as well).
     * </p>
     */
    public static final int MODE_DUAL = MODE_DFP | MODE_UFP;
    public static final int MODE_DUAL = Constants.PortMode.DRP;

    /**
     * Power role: This USB port does not have a power role.
     */
    public static final int POWER_ROLE_NONE = Constants.PortPowerRole.NONE;

    /**
     * Power role: This USB port can act as a source (provide power).
     */
    public static final int POWER_ROLE_SOURCE = 1;
    public static final int POWER_ROLE_SOURCE = Constants.PortPowerRole.SOURCE;

    /**
     * Power role: This USB port can act as a sink (receive power).
     */
    public static final int POWER_ROLE_SINK = 2;
    public static final int POWER_ROLE_SINK = Constants.PortPowerRole.SINK;

    /**
     * Power role: This USB port does not have a data role.
     */
    public static final int DATA_ROLE_NONE = Constants.PortDataRole.NONE;

    /**
     * Data role: This USB port can act as a host (access data services).
     */
    public static final int DATA_ROLE_HOST = 1;
    public static final int DATA_ROLE_HOST = Constants.PortDataRole.HOST;

    /**
     * Data role: This USB port can act as a device (offer data services).
     */
    public static final int DATA_ROLE_DEVICE = 2;
    public static final int DATA_ROLE_DEVICE = Constants.PortDataRole.DEVICE;

    private static final int NUM_DATA_ROLES = 3;
    private static final int NUM_DATA_ROLES = Constants.PortDataRole.NUM_DATA_ROLES;
    /**
     * Points to the first power role in the IUsb HAL.
     */
    private static final int POWER_ROLE_OFFSET = Constants.PortPowerRole.NONE;

    /** @hide */
    public UsbPort(String id, int supportedModes) {
@@ -126,14 +142,14 @@ public final class UsbPort implements Parcelable {
     */
    public static int combineRolesAsBit(int powerRole, int dataRole) {
        checkRoles(powerRole, dataRole);
        final int index = powerRole * NUM_DATA_ROLES + dataRole;
        final int index = ((powerRole - POWER_ROLE_OFFSET) * NUM_DATA_ROLES) + dataRole;
        return 1 << index;
    }

    /** @hide */
    public static String modeToString(int mode) {
        switch (mode) {
            case 0:
            case MODE_NONE:
                return "none";
            case MODE_DFP:
                return "dfp";
@@ -149,7 +165,7 @@ public final class UsbPort implements Parcelable {
    /** @hide */
    public static String powerRoleToString(int role) {
        switch (role) {
            case 0:
            case POWER_ROLE_NONE:
                return "no-power";
            case POWER_ROLE_SOURCE:
                return "source";
@@ -163,7 +179,7 @@ public final class UsbPort implements Parcelable {
    /** @hide */
    public static String dataRoleToString(int role) {
        switch (role) {
            case 0:
            case DATA_ROLE_NONE:
                return "no-data";
            case DATA_ROLE_HOST:
                return "host";
@@ -183,7 +199,7 @@ public final class UsbPort implements Parcelable {
        while (combo != 0) {
            final int index = Integer.numberOfTrailingZeros(combo);
            combo &= ~(1 << index);
            final int powerRole = index / NUM_DATA_ROLES;
            final int powerRole = (index / NUM_DATA_ROLES + POWER_ROLE_OFFSET);
            final int dataRole = index % NUM_DATA_ROLES;
            if (first) {
                first = false;
@@ -199,10 +215,29 @@ public final class UsbPort implements Parcelable {
        return result.toString();
    }

    /** @hide */
    public static void checkMode(int powerRole) {
        Preconditions.checkArgumentInRange(powerRole, Constants.PortMode.NONE,
                Constants.PortMode.NUM_MODES - 1, "portMode");
    }

    /** @hide */
    public static void checkPowerRole(int dataRole) {
        Preconditions.checkArgumentInRange(dataRole, Constants.PortPowerRole.NONE,
                Constants.PortPowerRole.NUM_POWER_ROLES - 1, "powerRole");
    }

    /** @hide */
    public static void checkDataRole(int mode) {
        Preconditions.checkArgumentInRange(mode, Constants.PortDataRole.NONE,
                Constants.PortDataRole.NUM_DATA_ROLES - 1, "powerRole");
    }

    /** @hide */
    public static void checkRoles(int powerRole, int dataRole) {
        Preconditions.checkArgumentInRange(powerRole, 0, POWER_ROLE_SINK, "powerRole");
        Preconditions.checkArgumentInRange(dataRole, 0, DATA_ROLE_DEVICE, "dataRole");
        Preconditions.checkArgumentInRange(powerRole, POWER_ROLE_NONE, POWER_ROLE_SINK,
                "powerRole");
        Preconditions.checkArgumentInRange(dataRole, DATA_ROLE_NONE, DATA_ROLE_DEVICE, "dataRole");
    }

    @Override
+2 −0
Original line number Diff line number Diff line
@@ -8,5 +8,7 @@ LOCAL_SRC_FILES += \
      $(call all-java-files-under,java)

LOCAL_JAVA_LIBRARIES := services.core
LOCAL_STATIC_JAVA_LIBRARIES := android.hardware.usb@1.0-java-static \
android.hidl.manager@1.0-java-static

include $(BUILD_STATIC_JAVA_LIBRARY)
+294 −257

File changed.

Preview size limit exceeded, changes collapsed.