Loading Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -751,6 +751,7 @@ java_defaults { "android.hardware.tv.input-V1.0-java-constants", "android.hardware.usb-V1.0-java-constants", "android.hardware.usb-V1.1-java-constants", "android.hardware.usb-V1.2-java-constants", "android.hardware.vibrator-V1.0-java", "android.hardware.vibrator-V1.1-java", "android.hardware.vibrator-V1.2-java", Loading core/java/android/hardware/usb/IUsbManager.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -120,6 +120,9 @@ interface IUsbManager /* Sets the port's current role. */ void setPortRoles(in String portId, int powerRole, int dataRole); /* Enable/disable contaminant detection */ void enableContaminantDetection(in String portId, boolean enable); /* Sets USB device connection handler. */ void setUsbDeviceConnectionHandler(in ComponentName usbDeviceConnectionHandler); } core/java/android/hardware/usb/ParcelableUsbPort.java +30 −4 Original line number Diff line number Diff line Loading @@ -31,10 +31,21 @@ import com.android.internal.annotations.Immutable; public final class ParcelableUsbPort implements Parcelable { private final @NonNull String mId; private final int mSupportedModes; private final int mSupportedContaminantProtectionModes; private final boolean mSupportsEnableContaminantPresenceProtection; private final boolean mSupportsEnableContaminantPresenceDetection; private ParcelableUsbPort(@NonNull String id, int supportedModes) { private ParcelableUsbPort(@NonNull String id, int supportedModes, int supportedContaminantProtectionModes, boolean supportsEnableContaminantPresenceProtection, boolean supportsEnableContaminantPresenceDetection) { mId = id; mSupportedModes = supportedModes; mSupportedContaminantProtectionModes = supportedContaminantProtectionModes; mSupportsEnableContaminantPresenceProtection = supportsEnableContaminantPresenceProtection; mSupportsEnableContaminantPresenceDetection = supportsEnableContaminantPresenceDetection; } /** Loading @@ -45,7 +56,10 @@ public final class ParcelableUsbPort implements Parcelable { * @return The parcelable version of the port */ public static @NonNull ParcelableUsbPort of(@NonNull UsbPort port) { return new ParcelableUsbPort(port.getId(), port.getSupportedModes()); return new ParcelableUsbPort(port.getId(), port.getSupportedModes(), port.getSupportedContaminantProtectionModes(), port.supportsEnableContaminantPresenceProtection(), port.supportsEnableContaminantPresenceDetection()); } /** Loading @@ -56,7 +70,9 @@ public final class ParcelableUsbPort implements Parcelable { * @return The UsbPort for this object */ public @NonNull UsbPort getUsbPort(@NonNull UsbManager usbManager) { return new UsbPort(usbManager, mId, mSupportedModes); return new UsbPort(usbManager, mId, mSupportedModes, mSupportedContaminantProtectionModes, mSupportsEnableContaminantPresenceProtection, mSupportsEnableContaminantPresenceDetection); } @Override Loading @@ -68,6 +84,9 @@ public final class ParcelableUsbPort implements Parcelable { public void writeToParcel(Parcel dest, int flags) { dest.writeString(mId); dest.writeInt(mSupportedModes); dest.writeInt(mSupportedContaminantProtectionModes); dest.writeBoolean(mSupportsEnableContaminantPresenceProtection); dest.writeBoolean(mSupportsEnableContaminantPresenceDetection); } public static final Creator<ParcelableUsbPort> CREATOR = Loading @@ -76,7 +95,14 @@ public final class ParcelableUsbPort implements Parcelable { public ParcelableUsbPort createFromParcel(Parcel in) { String id = in.readString(); int supportedModes = in.readInt(); return new ParcelableUsbPort(id, supportedModes); int supportedContaminantProtectionModes = in.readInt(); boolean supportsEnableContaminantPresenceProtection = in.readBoolean(); boolean supportsEnableContaminantPresenceDetection = in.readBoolean(); return new ParcelableUsbPort(id, supportedModes, supportedContaminantProtectionModes, supportsEnableContaminantPresenceProtection, supportsEnableContaminantPresenceDetection); } @Override Loading core/java/android/hardware/usb/UsbManager.java +14 −0 Original line number Diff line number Diff line Loading @@ -853,6 +853,20 @@ public class UsbManager { } } /** * Enables USB port contaminant detection algorithm. * * @hide */ @RequiresPermission(Manifest.permission.MANAGE_USB) void enableContaminantDetection(@NonNull UsbPort port, boolean enable) { try { mService.enableContaminantDetection(port.getId(), enable); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Sets the component that will handle USB device connection. * <p> Loading core/java/android/hardware/usb/UsbPort.java +74 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,10 @@ package android.hardware.usb; import static android.hardware.usb.UsbPortStatus.CONTAMINANT_DETECTION_DETECTED; import static android.hardware.usb.UsbPortStatus.CONTAMINANT_DETECTION_DISABLED; import static android.hardware.usb.UsbPortStatus.CONTAMINANT_DETECTION_NOT_DETECTED; import static android.hardware.usb.UsbPortStatus.CONTAMINANT_DETECTION_NOT_SUPPORTED; import static android.hardware.usb.UsbPortStatus.DATA_ROLE_DEVICE; import static android.hardware.usb.UsbPortStatus.DATA_ROLE_HOST; import static android.hardware.usb.UsbPortStatus.DATA_ROLE_NONE; Loading Loading @@ -48,16 +52,21 @@ public final class UsbPort { private final String mId; private final int mSupportedModes; private final UsbManager mUsbManager; private final int mSupportedContaminantProtectionModes; private final boolean mSupportsEnableContaminantPresenceProtection; private final boolean mSupportsEnableContaminantPresenceDetection; 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(@NonNull UsbManager usbManager, @NonNull String id, int supportedModes) { public UsbPort(@NonNull UsbManager usbManager, @NonNull String id, int supportedModes, int supportedContaminantProtectionModes, boolean supportsEnableContaminantPresenceProtection, boolean supportsEnableContaminantPresenceDetection) { Preconditions.checkNotNull(id); Preconditions.checkFlagsArgument(supportedModes, MODE_DFP | MODE_UFP | MODE_AUDIO_ACCESSORY | MODE_DEBUG_ACCESSORY); Loading @@ -65,6 +74,11 @@ public final class UsbPort { mUsbManager = usbManager; mId = id; mSupportedModes = supportedModes; mSupportedContaminantProtectionModes = supportedContaminantProtectionModes; mSupportsEnableContaminantPresenceProtection = supportsEnableContaminantPresenceProtection; mSupportsEnableContaminantPresenceDetection = supportsEnableContaminantPresenceDetection; } /** Loading Loading @@ -93,6 +107,36 @@ public final class UsbPort { return mSupportedModes; } /** * Gets the supported port proctection modes when the port is contaminated. * <p> * The actual mode of the port is decided by the hardware * </p> * * @hide */ public int getSupportedContaminantProtectionModes() { return mSupportedContaminantProtectionModes; } /** * Tells if UsbService can enable/disable contaminant presence protection. * * @hide */ public boolean supportsEnableContaminantPresenceProtection() { return mSupportsEnableContaminantPresenceProtection; } /** * Tells if UsbService can enable/disable contaminant presence detection. * * @hide */ public boolean supportsEnableContaminantPresenceDetection() { return mSupportsEnableContaminantPresenceDetection; } /** * Gets the status of this USB port. * Loading Loading @@ -130,6 +174,12 @@ public final class UsbPort { mUsbManager.setPortRoles(this, powerRole, dataRole); } /** * @hide **/ public void enableContaminantDetection(boolean enable) { mUsbManager.enableContaminantDetection(this, enable); } /** * Combines one power and one data role together into a unique value with * exactly one bit set. This can be used to efficiently determine whether Loading Loading @@ -205,6 +255,22 @@ public final class UsbPort { } } /** @hide */ public static String contaminantPresenceStatusToString(int contaminantPresenceStatus) { switch (contaminantPresenceStatus) { case CONTAMINANT_DETECTION_NOT_SUPPORTED: return "not-supported"; case CONTAMINANT_DETECTION_DISABLED: return "disabled"; case CONTAMINANT_DETECTION_DETECTED: return "detected"; case CONTAMINANT_DETECTION_NOT_DETECTED: return "not detected"; default: return Integer.toString(contaminantPresenceStatus); } } /** @hide */ public static String roleCombinationsToString(int combo) { StringBuilder result = new StringBuilder(); Loading Loading @@ -264,6 +330,11 @@ public final class UsbPort { @Override public String toString() { return "UsbPort{id=" + mId + ", supportedModes=" + modeToString(mSupportedModes) + "}"; return "UsbPort{id=" + mId + ", supportedModes=" + modeToString(mSupportedModes) + "supportedContaminantProtectionModes=" + mSupportedContaminantProtectionModes + "supportsEnableContaminantPresenceProtection=" + mSupportsEnableContaminantPresenceProtection + "supportsEnableContaminantPresenceDetection=" + mSupportsEnableContaminantPresenceDetection; } } Loading
Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -751,6 +751,7 @@ java_defaults { "android.hardware.tv.input-V1.0-java-constants", "android.hardware.usb-V1.0-java-constants", "android.hardware.usb-V1.1-java-constants", "android.hardware.usb-V1.2-java-constants", "android.hardware.vibrator-V1.0-java", "android.hardware.vibrator-V1.1-java", "android.hardware.vibrator-V1.2-java", Loading
core/java/android/hardware/usb/IUsbManager.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -120,6 +120,9 @@ interface IUsbManager /* Sets the port's current role. */ void setPortRoles(in String portId, int powerRole, int dataRole); /* Enable/disable contaminant detection */ void enableContaminantDetection(in String portId, boolean enable); /* Sets USB device connection handler. */ void setUsbDeviceConnectionHandler(in ComponentName usbDeviceConnectionHandler); }
core/java/android/hardware/usb/ParcelableUsbPort.java +30 −4 Original line number Diff line number Diff line Loading @@ -31,10 +31,21 @@ import com.android.internal.annotations.Immutable; public final class ParcelableUsbPort implements Parcelable { private final @NonNull String mId; private final int mSupportedModes; private final int mSupportedContaminantProtectionModes; private final boolean mSupportsEnableContaminantPresenceProtection; private final boolean mSupportsEnableContaminantPresenceDetection; private ParcelableUsbPort(@NonNull String id, int supportedModes) { private ParcelableUsbPort(@NonNull String id, int supportedModes, int supportedContaminantProtectionModes, boolean supportsEnableContaminantPresenceProtection, boolean supportsEnableContaminantPresenceDetection) { mId = id; mSupportedModes = supportedModes; mSupportedContaminantProtectionModes = supportedContaminantProtectionModes; mSupportsEnableContaminantPresenceProtection = supportsEnableContaminantPresenceProtection; mSupportsEnableContaminantPresenceDetection = supportsEnableContaminantPresenceDetection; } /** Loading @@ -45,7 +56,10 @@ public final class ParcelableUsbPort implements Parcelable { * @return The parcelable version of the port */ public static @NonNull ParcelableUsbPort of(@NonNull UsbPort port) { return new ParcelableUsbPort(port.getId(), port.getSupportedModes()); return new ParcelableUsbPort(port.getId(), port.getSupportedModes(), port.getSupportedContaminantProtectionModes(), port.supportsEnableContaminantPresenceProtection(), port.supportsEnableContaminantPresenceDetection()); } /** Loading @@ -56,7 +70,9 @@ public final class ParcelableUsbPort implements Parcelable { * @return The UsbPort for this object */ public @NonNull UsbPort getUsbPort(@NonNull UsbManager usbManager) { return new UsbPort(usbManager, mId, mSupportedModes); return new UsbPort(usbManager, mId, mSupportedModes, mSupportedContaminantProtectionModes, mSupportsEnableContaminantPresenceProtection, mSupportsEnableContaminantPresenceDetection); } @Override Loading @@ -68,6 +84,9 @@ public final class ParcelableUsbPort implements Parcelable { public void writeToParcel(Parcel dest, int flags) { dest.writeString(mId); dest.writeInt(mSupportedModes); dest.writeInt(mSupportedContaminantProtectionModes); dest.writeBoolean(mSupportsEnableContaminantPresenceProtection); dest.writeBoolean(mSupportsEnableContaminantPresenceDetection); } public static final Creator<ParcelableUsbPort> CREATOR = Loading @@ -76,7 +95,14 @@ public final class ParcelableUsbPort implements Parcelable { public ParcelableUsbPort createFromParcel(Parcel in) { String id = in.readString(); int supportedModes = in.readInt(); return new ParcelableUsbPort(id, supportedModes); int supportedContaminantProtectionModes = in.readInt(); boolean supportsEnableContaminantPresenceProtection = in.readBoolean(); boolean supportsEnableContaminantPresenceDetection = in.readBoolean(); return new ParcelableUsbPort(id, supportedModes, supportedContaminantProtectionModes, supportsEnableContaminantPresenceProtection, supportsEnableContaminantPresenceDetection); } @Override Loading
core/java/android/hardware/usb/UsbManager.java +14 −0 Original line number Diff line number Diff line Loading @@ -853,6 +853,20 @@ public class UsbManager { } } /** * Enables USB port contaminant detection algorithm. * * @hide */ @RequiresPermission(Manifest.permission.MANAGE_USB) void enableContaminantDetection(@NonNull UsbPort port, boolean enable) { try { mService.enableContaminantDetection(port.getId(), enable); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Sets the component that will handle USB device connection. * <p> Loading
core/java/android/hardware/usb/UsbPort.java +74 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,10 @@ package android.hardware.usb; import static android.hardware.usb.UsbPortStatus.CONTAMINANT_DETECTION_DETECTED; import static android.hardware.usb.UsbPortStatus.CONTAMINANT_DETECTION_DISABLED; import static android.hardware.usb.UsbPortStatus.CONTAMINANT_DETECTION_NOT_DETECTED; import static android.hardware.usb.UsbPortStatus.CONTAMINANT_DETECTION_NOT_SUPPORTED; import static android.hardware.usb.UsbPortStatus.DATA_ROLE_DEVICE; import static android.hardware.usb.UsbPortStatus.DATA_ROLE_HOST; import static android.hardware.usb.UsbPortStatus.DATA_ROLE_NONE; Loading Loading @@ -48,16 +52,21 @@ public final class UsbPort { private final String mId; private final int mSupportedModes; private final UsbManager mUsbManager; private final int mSupportedContaminantProtectionModes; private final boolean mSupportsEnableContaminantPresenceProtection; private final boolean mSupportsEnableContaminantPresenceDetection; 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(@NonNull UsbManager usbManager, @NonNull String id, int supportedModes) { public UsbPort(@NonNull UsbManager usbManager, @NonNull String id, int supportedModes, int supportedContaminantProtectionModes, boolean supportsEnableContaminantPresenceProtection, boolean supportsEnableContaminantPresenceDetection) { Preconditions.checkNotNull(id); Preconditions.checkFlagsArgument(supportedModes, MODE_DFP | MODE_UFP | MODE_AUDIO_ACCESSORY | MODE_DEBUG_ACCESSORY); Loading @@ -65,6 +74,11 @@ public final class UsbPort { mUsbManager = usbManager; mId = id; mSupportedModes = supportedModes; mSupportedContaminantProtectionModes = supportedContaminantProtectionModes; mSupportsEnableContaminantPresenceProtection = supportsEnableContaminantPresenceProtection; mSupportsEnableContaminantPresenceDetection = supportsEnableContaminantPresenceDetection; } /** Loading Loading @@ -93,6 +107,36 @@ public final class UsbPort { return mSupportedModes; } /** * Gets the supported port proctection modes when the port is contaminated. * <p> * The actual mode of the port is decided by the hardware * </p> * * @hide */ public int getSupportedContaminantProtectionModes() { return mSupportedContaminantProtectionModes; } /** * Tells if UsbService can enable/disable contaminant presence protection. * * @hide */ public boolean supportsEnableContaminantPresenceProtection() { return mSupportsEnableContaminantPresenceProtection; } /** * Tells if UsbService can enable/disable contaminant presence detection. * * @hide */ public boolean supportsEnableContaminantPresenceDetection() { return mSupportsEnableContaminantPresenceDetection; } /** * Gets the status of this USB port. * Loading Loading @@ -130,6 +174,12 @@ public final class UsbPort { mUsbManager.setPortRoles(this, powerRole, dataRole); } /** * @hide **/ public void enableContaminantDetection(boolean enable) { mUsbManager.enableContaminantDetection(this, enable); } /** * Combines one power and one data role together into a unique value with * exactly one bit set. This can be used to efficiently determine whether Loading Loading @@ -205,6 +255,22 @@ public final class UsbPort { } } /** @hide */ public static String contaminantPresenceStatusToString(int contaminantPresenceStatus) { switch (contaminantPresenceStatus) { case CONTAMINANT_DETECTION_NOT_SUPPORTED: return "not-supported"; case CONTAMINANT_DETECTION_DISABLED: return "disabled"; case CONTAMINANT_DETECTION_DETECTED: return "detected"; case CONTAMINANT_DETECTION_NOT_DETECTED: return "not detected"; default: return Integer.toString(contaminantPresenceStatus); } } /** @hide */ public static String roleCombinationsToString(int combo) { StringBuilder result = new StringBuilder(); Loading Loading @@ -264,6 +330,11 @@ public final class UsbPort { @Override public String toString() { return "UsbPort{id=" + mId + ", supportedModes=" + modeToString(mSupportedModes) + "}"; return "UsbPort{id=" + mId + ", supportedModes=" + modeToString(mSupportedModes) + "supportedContaminantProtectionModes=" + mSupportedContaminantProtectionModes + "supportsEnableContaminantPresenceProtection=" + mSupportsEnableContaminantPresenceProtection + "supportsEnableContaminantPresenceDetection=" + mSupportsEnableContaminantPresenceDetection; } }