From b577571fd907de3bacfe4be14c47ce50d608b39e Mon Sep 17 00:00:00 2001 From: Badhri Jagan Sridharan Date: Fri, 18 Jan 2019 00:39:47 -0800 Subject: [PATCH] USB V1.2 interface Supports reporting and userspace control of USB contamination presence. Bug: 117330206 Bug: 77606903 Bug: 119642987 Test: USB HAL V1.2 HIDL tests. Change-Id: I70219641cdd48d59d217334dbd6d4ed8a8ce4927 --- .../compatibility_matrix.current.xml | 2 +- usb/1.2/Android.bp | 29 +++++ usb/1.2/IUsb.hal | 65 ++++++++++ usb/1.2/IUsbCallback.hal | 42 ++++++ usb/1.2/types.hal | 120 ++++++++++++++++++ 5 files changed, 257 insertions(+), 1 deletion(-) create mode 100644 usb/1.2/Android.bp create mode 100644 usb/1.2/IUsb.hal create mode 100644 usb/1.2/IUsbCallback.hal create mode 100644 usb/1.2/types.hal diff --git a/compatibility_matrices/compatibility_matrix.current.xml b/compatibility_matrices/compatibility_matrix.current.xml index 0dd174aa99..94ffe80aab 100644 --- a/compatibility_matrices/compatibility_matrix.current.xml +++ b/compatibility_matrices/compatibility_matrix.current.xml @@ -443,7 +443,7 @@ android.hardware.usb - 1.0-1 + 1.0-2 IUsb default diff --git a/usb/1.2/Android.bp b/usb/1.2/Android.bp new file mode 100644 index 0000000000..55ffad06b1 --- /dev/null +++ b/usb/1.2/Android.bp @@ -0,0 +1,29 @@ +// This file is autogenerated by hidl-gen -Landroidbp. + +hidl_interface { + name: "android.hardware.usb@1.2", + root: "android.hardware", + vndk: { + enabled: true, + }, + srcs: [ + "types.hal", + "IUsb.hal", + "IUsbCallback.hal", + ], + interfaces: [ + "android.hardware.usb@1.0", + "android.hardware.usb@1.1", + "android.hidl.base@1.0", + ], + types: [ + "ContaminantDetectionStatus", + "ContaminantProtectionMode", + "ContaminantProtectionStatus", + "PortStatus", + "Status", + ], + gen_java: true, + gen_java_constants: true, +} + diff --git a/usb/1.2/IUsb.hal b/usb/1.2/IUsb.hal new file mode 100644 index 0000000000..ecc911ebf2 --- /dev/null +++ b/usb/1.2/IUsb.hal @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2018 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@1.2; + +import android.hardware.usb@1.1::IUsb; + +/** + * The setCallback function in V1_0 is used to register the V1_2 + * IUsbCallback object as well. The implementation can use the + * castFrom method to cast the IUsbCallback object. + */ +interface IUsb extends @1.1::IUsb { + /** + * When supportsEnableContaminantPresenceDetection is true, + * enableContaminantPresenceDetection enables/disables contaminant + * presence detection algorithm. Calling enableContaminantPresenceDetection + * when supportsEnableContaminantPresenceDetection is false does + * not have any effect. + * Change in contantaminant presence status should notify should + * be notified to the client via notifyPortStatusChange_1_2 through + * PortStatus. + * + * @param portName name of the port. + * @param enable true Enable contaminant presence detection algorithm. + * false Disable contaminant presence detection algorithm. + */ + oneway enableContaminantPresenceDetection(string portName, bool enable); + + /** + * When supportsEnableContaminantPresenceProtection is true, + * enableContaminantPresenceProtection enables/disables contaminant + * presence protection algorithm. Calling + * enableContaminantPresenceProtection + * when supportsEnableContaminantPresenceProtection is false does + * not have any effect. + * Used to enable/disable contaminant presence protection algorithm. + * Enabling port protection algoritm must make the lower layers to autonomously + * act on taking the corresponding preventive measure mentioned at + * ContaminantProtectionModes when contaminant is detected on the USB Port. + * Calling this method with enable set to true must set to contaminantProtectionEnabled + * to true upon success and vice versa. + * currentContaminantProtectionMode should be updated whenever there is a + * change in the status of contaminant presence protection algorithm. + * + * @param portName name of the port. + * @param enable true Reduce capabilities of the port to protect port + * from damage due to contaminant presence. + * false No action is taken upon contaminant presence. + */ + oneway enableContaminantPresenceProtection(string portName, bool enable); +}; diff --git a/usb/1.2/IUsbCallback.hal b/usb/1.2/IUsbCallback.hal new file mode 100644 index 0000000000..8cc16df10c --- /dev/null +++ b/usb/1.2/IUsbCallback.hal @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2018 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@1.2; + +import android.hardware.usb@1.1::IUsbCallback; +import android.hardware.usb@1.0::Status; + +/** + * Callback object used for all the IUsb async methods which expects a result. + * Caller is expected to register the callback object using setCallback method + * to receive updates on the PortStatus. + */ +interface IUsbCallback extends @1.1::IUsbCallback { + /** + * Used to convey the current port status to the caller. + * Must be called either when PortState changes due to the port partner or + * when caller requested for the PortStatus update through queryPortStatus. + * + * @param currentPortStatus vector object of current status(PortStatus + * of all the typeC ports in the device. + * @param retval SUCCESS when the required information was enquired form + * kernel and the PortStatus_1_2 object was built. + * ERROR otherwise. + */ + oneway notifyPortStatusChange_1_2(vec currentPortStatus, + @1.0::Status retval); +}; + diff --git a/usb/1.2/types.hal b/usb/1.2/types.hal new file mode 100644 index 0000000000..081a64391b --- /dev/null +++ b/usb/1.2/types.hal @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2018 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@1.2; + +import android.hardware.usb@1.1::PortStatus_1_1; +import android.hardware.usb@1.0::Status; + +enum Status : @1.0::Status { + /** + * Error value returned when the operation is not supported. + */ + NOT_SUPPORTED = 4, +}; + +@export +enum ContaminantDetectionStatus : uint32_t { + /** + * Contaminant presence detection is not supported. + */ + NOT_SUPPORTED = 0, + + /** + * Contaminant presence detection is supported but disabled. + */ + DISABLED = 1, + + /** + * Contaminant presence detection is enabled and contaminant not detected. + */ + NOT_DETECTED = 2, + + /** + * Contaminant presence detection is enabled and contaminant detected. + */ + DETECTED = 3, +}; + +@export +enum ContaminantProtectionMode : uint32_t { + /** + * No action performed upon detection of contaminant presence. + */ + NONE = 0, + + /** + * Upon detection of contaminant presence, Port is forced to sink only + * mode where a port shall only detect chargers until contaminant presence + * is no longer detected. + */ + FORCE_SINK = 1 << 0, + + /** + * Upon detection of contaminant presence, Port is forced to source only + * mode where a port shall only detect usb accessories such as headsets + * until contaminant presence is no longer detected. + */ + FORCE_SOURCE = 1 << 1, + + /** + * Upon detection of contaminant presence, port is disabled until contaminant + * presence is no longer detected. In the disabled state port will + * not respond to connection of chargers or usb accessories. + */ + FORCE_DISABLE = 1 << 2, +}; + +@export +enum ContaminantProtectionStatus : ContaminantProtectionMode { + /** + * Client disabled cotaminant protection by calling + * enableContaminantPresencePortProtection set to false. Low level drivers should + * not autmomously take any corrective action when contaminant presence is detected. + */ + DISABLED = 1 << 3, +}; + +struct PortStatus { + PortStatus_1_1 status_1_1; + + /** + * Contaminant presence protection modes supported by the port. + */ + bitfield supportedContaminantProtectionModes; + + /** + * Client can enable/disable contaminant presence protection through + * enableContaminantPresenceProtection when true. + */ + bool supportsEnableContaminantPresenceProtection; + + /** + * Contaminant presence protection modes currently active for the port. + */ + ContaminantProtectionStatus contaminantProtectionStatus; + + /** + * Client can enable/disable contaminant presence detection through + * enableContaminantPresenceDetection when true. + */ + bool supportsEnableContaminantPresenceDetection; + + /** + * Current status of contaminant detection algorithm. + */ + ContaminantDetectionStatus contaminantDetectionStatus; +};