Loading core/api/module-lib-current.txt +2 −0 Original line number Diff line number Diff line Loading @@ -100,10 +100,12 @@ package android.hardware.usb { field public static final int USB_DATA_TRANSFER_RATE_LOW_SPEED = 2; // 0x2 field public static final int USB_DATA_TRANSFER_RATE_UNKNOWN = -1; // 0xffffffff field public static final int USB_HAL_NOT_SUPPORTED = -1; // 0xffffffff field public static final int USB_HAL_RETRY = -2; // 0xfffffffe field public static final int USB_HAL_V1_0 = 10; // 0xa field public static final int USB_HAL_V1_1 = 11; // 0xb field public static final int USB_HAL_V1_2 = 12; // 0xc field public static final int USB_HAL_V1_3 = 13; // 0xd field public static final int USB_HAL_V2_0 = 20; // 0x14 } } Loading core/api/system-current.txt +6 −0 Original line number Diff line number Diff line Loading @@ -4169,8 +4169,14 @@ package android.hardware.usb { } public final class UsbPort { method @CheckResult @RequiresPermission(android.Manifest.permission.MANAGE_USB) public int enableUsbData(boolean); method @Nullable @RequiresPermission(android.Manifest.permission.MANAGE_USB) public android.hardware.usb.UsbPortStatus getStatus(); method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public void setRoles(int, int); field public static final int ENABLE_USB_DATA_ERROR_INTERNAL = 1; // 0x1 field public static final int ENABLE_USB_DATA_ERROR_NOT_SUPPORTED = 2; // 0x2 field public static final int ENABLE_USB_DATA_ERROR_OTHER = 4; // 0x4 field public static final int ENABLE_USB_DATA_ERROR_PORT_MISMATCH = 3; // 0x3 field public static final int ENABLE_USB_DATA_SUCCESS = 0; // 0x0 } public final class UsbPortStatus implements android.os.Parcelable { Loading core/java/android/hardware/usb/IUsbManager.aidl +4 −3 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.hardware.usb; import android.app.PendingIntent; import android.content.ComponentName; import android.hardware.usb.IUsbOperationInternal; import android.hardware.usb.UsbAccessory; import android.hardware.usb.UsbDevice; import android.hardware.usb.ParcelableUsbPort; Loading Loading @@ -136,7 +137,7 @@ interface IUsbManager void resetUsbGadget(); /* Set USB data on or off */ boolean enableUsbDataSignal(boolean enable); boolean enableUsbData(in String portId, boolean enable, int operationId, in IUsbOperationInternal callback); /* Gets the USB Hal Version. */ int getUsbHalVersion(); Loading core/java/android/hardware/usb/IUsbOperationInternal.aidl 0 → 100644 +24 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.hardware.usb; /** * @hide */ oneway interface IUsbOperationInternal { void onOperationComplete(in int status); } core/java/android/hardware/usb/UsbManager.java +61 −5 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.hardware.usb.gadget.V1_0.GadgetFunction; import android.hardware.usb.gadget.V1_2.UsbSpeed; import android.hardware.usb.IUsbOperationInternal; import android.hardware.usb.UsbPort; import android.os.Build; import android.os.Bundle; import android.os.ParcelFileDescriptor; Loading @@ -48,6 +50,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.StringJoiner; /** Loading Loading @@ -515,6 +518,14 @@ public class UsbManager { @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) public static final int USB_DATA_TRANSFER_RATE_40G = 40 * 1024; /** * Returned when the client has to retry querying the version. * * @hide */ @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) public static final int USB_HAL_RETRY = -2; /** * The Value for USB hal is not presented. * Loading Loading @@ -555,6 +566,14 @@ public class UsbManager { @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) public static final int USB_HAL_V1_3 = 13; /** * Value for USB Hal Version v2.0. * * @hide */ @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) public static final int USB_HAL_V2_0 = 20; /** * Code for the charging usb function. Passed into {@link #setCurrentFunctions(long)} * {@hide} Loading Loading @@ -664,6 +683,7 @@ public class UsbManager { USB_HAL_V1_1, USB_HAL_V1_2, USB_HAL_V1_3, USB_HAL_V2_0, }) public @interface UsbHalVersion {} Loading Loading @@ -1168,8 +1188,9 @@ public class UsbManager { /** * Enable/Disable the USB data signaling. * <p> * Enables/Disables USB data path in all the USB ports. * Enables/Disables USB data path of the first port.. * It will force to stop or restore USB data signaling. * Call UsbPort API if the device has more than one UsbPort. * </p> * * @param enable enable or disable USB data signaling Loading @@ -1180,11 +1201,11 @@ public class UsbManager { */ @RequiresPermission(Manifest.permission.MANAGE_USB) public boolean enableUsbDataSignal(boolean enable) { try { return mService.enableUsbDataSignal(enable); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); List<UsbPort> usbPorts = getPorts(); if (usbPorts.size() == 1) { return usbPorts.get(0).enableUsbData(enable) == UsbPort.ENABLE_USB_DATA_SUCCESS; } return false; } /** Loading Loading @@ -1269,6 +1290,41 @@ public class UsbManager { } } /** * Should only be called by {@link UsbPort#enableUsbData}. * <p> * Enables or disables USB data on the specific port. * * @param port USB port for which USB data needs to be enabled or disabled. * @param enable Enable USB data when true. * Disable USB data when false. * @param operationId operationId for the request. * @param callback callback object to be invoked when the operation is complete. * @return True when the operation is asynchronous. The caller must therefore call * {@link UsbOperationInternal#waitForOperationComplete} for processing * the result. * False when the operation is synchronous. Caller can proceed reading the result * through {@link UsbOperationInternal#getStatus} * @hide */ @RequiresPermission(Manifest.permission.MANAGE_USB) boolean enableUsbData(@NonNull UsbPort port, boolean enable, int operationId, IUsbOperationInternal callback) { Objects.requireNonNull(port, "enableUsbData: port must not be null. opId:" + operationId); try { return mService.enableUsbData(port.getId(), enable, operationId, callback); } catch (RemoteException e) { Log.e(TAG, "enableUsbData: failed. opId:" + operationId, e); try { callback.onOperationComplete(UsbOperationInternal.USB_OPERATION_ERROR_INTERNAL); } catch (RemoteException r) { Log.e(TAG, "enableUsbData: failed to call onOperationComplete. opId:" + operationId, r); } throw e.rethrowFromSystemServer(); } } /** * Sets the component that will handle USB device connection. * <p> Loading Loading
core/api/module-lib-current.txt +2 −0 Original line number Diff line number Diff line Loading @@ -100,10 +100,12 @@ package android.hardware.usb { field public static final int USB_DATA_TRANSFER_RATE_LOW_SPEED = 2; // 0x2 field public static final int USB_DATA_TRANSFER_RATE_UNKNOWN = -1; // 0xffffffff field public static final int USB_HAL_NOT_SUPPORTED = -1; // 0xffffffff field public static final int USB_HAL_RETRY = -2; // 0xfffffffe field public static final int USB_HAL_V1_0 = 10; // 0xa field public static final int USB_HAL_V1_1 = 11; // 0xb field public static final int USB_HAL_V1_2 = 12; // 0xc field public static final int USB_HAL_V1_3 = 13; // 0xd field public static final int USB_HAL_V2_0 = 20; // 0x14 } } Loading
core/api/system-current.txt +6 −0 Original line number Diff line number Diff line Loading @@ -4169,8 +4169,14 @@ package android.hardware.usb { } public final class UsbPort { method @CheckResult @RequiresPermission(android.Manifest.permission.MANAGE_USB) public int enableUsbData(boolean); method @Nullable @RequiresPermission(android.Manifest.permission.MANAGE_USB) public android.hardware.usb.UsbPortStatus getStatus(); method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public void setRoles(int, int); field public static final int ENABLE_USB_DATA_ERROR_INTERNAL = 1; // 0x1 field public static final int ENABLE_USB_DATA_ERROR_NOT_SUPPORTED = 2; // 0x2 field public static final int ENABLE_USB_DATA_ERROR_OTHER = 4; // 0x4 field public static final int ENABLE_USB_DATA_ERROR_PORT_MISMATCH = 3; // 0x3 field public static final int ENABLE_USB_DATA_SUCCESS = 0; // 0x0 } public final class UsbPortStatus implements android.os.Parcelable { Loading
core/java/android/hardware/usb/IUsbManager.aidl +4 −3 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.hardware.usb; import android.app.PendingIntent; import android.content.ComponentName; import android.hardware.usb.IUsbOperationInternal; import android.hardware.usb.UsbAccessory; import android.hardware.usb.UsbDevice; import android.hardware.usb.ParcelableUsbPort; Loading Loading @@ -136,7 +137,7 @@ interface IUsbManager void resetUsbGadget(); /* Set USB data on or off */ boolean enableUsbDataSignal(boolean enable); boolean enableUsbData(in String portId, boolean enable, int operationId, in IUsbOperationInternal callback); /* Gets the USB Hal Version. */ int getUsbHalVersion(); Loading
core/java/android/hardware/usb/IUsbOperationInternal.aidl 0 → 100644 +24 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.hardware.usb; /** * @hide */ oneway interface IUsbOperationInternal { void onOperationComplete(in int status); }
core/java/android/hardware/usb/UsbManager.java +61 −5 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.hardware.usb.gadget.V1_0.GadgetFunction; import android.hardware.usb.gadget.V1_2.UsbSpeed; import android.hardware.usb.IUsbOperationInternal; import android.hardware.usb.UsbPort; import android.os.Build; import android.os.Bundle; import android.os.ParcelFileDescriptor; Loading @@ -48,6 +50,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.StringJoiner; /** Loading Loading @@ -515,6 +518,14 @@ public class UsbManager { @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) public static final int USB_DATA_TRANSFER_RATE_40G = 40 * 1024; /** * Returned when the client has to retry querying the version. * * @hide */ @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) public static final int USB_HAL_RETRY = -2; /** * The Value for USB hal is not presented. * Loading Loading @@ -555,6 +566,14 @@ public class UsbManager { @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) public static final int USB_HAL_V1_3 = 13; /** * Value for USB Hal Version v2.0. * * @hide */ @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) public static final int USB_HAL_V2_0 = 20; /** * Code for the charging usb function. Passed into {@link #setCurrentFunctions(long)} * {@hide} Loading Loading @@ -664,6 +683,7 @@ public class UsbManager { USB_HAL_V1_1, USB_HAL_V1_2, USB_HAL_V1_3, USB_HAL_V2_0, }) public @interface UsbHalVersion {} Loading Loading @@ -1168,8 +1188,9 @@ public class UsbManager { /** * Enable/Disable the USB data signaling. * <p> * Enables/Disables USB data path in all the USB ports. * Enables/Disables USB data path of the first port.. * It will force to stop or restore USB data signaling. * Call UsbPort API if the device has more than one UsbPort. * </p> * * @param enable enable or disable USB data signaling Loading @@ -1180,11 +1201,11 @@ public class UsbManager { */ @RequiresPermission(Manifest.permission.MANAGE_USB) public boolean enableUsbDataSignal(boolean enable) { try { return mService.enableUsbDataSignal(enable); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); List<UsbPort> usbPorts = getPorts(); if (usbPorts.size() == 1) { return usbPorts.get(0).enableUsbData(enable) == UsbPort.ENABLE_USB_DATA_SUCCESS; } return false; } /** Loading Loading @@ -1269,6 +1290,41 @@ public class UsbManager { } } /** * Should only be called by {@link UsbPort#enableUsbData}. * <p> * Enables or disables USB data on the specific port. * * @param port USB port for which USB data needs to be enabled or disabled. * @param enable Enable USB data when true. * Disable USB data when false. * @param operationId operationId for the request. * @param callback callback object to be invoked when the operation is complete. * @return True when the operation is asynchronous. The caller must therefore call * {@link UsbOperationInternal#waitForOperationComplete} for processing * the result. * False when the operation is synchronous. Caller can proceed reading the result * through {@link UsbOperationInternal#getStatus} * @hide */ @RequiresPermission(Manifest.permission.MANAGE_USB) boolean enableUsbData(@NonNull UsbPort port, boolean enable, int operationId, IUsbOperationInternal callback) { Objects.requireNonNull(port, "enableUsbData: port must not be null. opId:" + operationId); try { return mService.enableUsbData(port.getId(), enable, operationId, callback); } catch (RemoteException e) { Log.e(TAG, "enableUsbData: failed. opId:" + operationId, e); try { callback.onOperationComplete(UsbOperationInternal.USB_OPERATION_ERROR_INTERNAL); } catch (RemoteException r) { Log.e(TAG, "enableUsbData: failed to call onOperationComplete. opId:" + operationId, r); } throw e.rethrowFromSystemServer(); } } /** * Sets the component that will handle USB device connection. * <p> Loading