diff options
author | Badhri Jagan Sridharan <badhri@google.com> | 2022-01-24 19:19:25 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2022-01-24 19:19:25 +0000 |
commit | cd1ec4f7e78decfc14ad2663d603f003eea15ee9 (patch) | |
tree | aef3a32490db6f09f329183b3f1f15f4ad4d4d85 /usb | |
parent | 395e94b74b6f3157ec78c304c83a9b444df8eaa6 (diff) | |
parent | f883235915244d50bdbe59fa6317ed71094a3fe9 (diff) |
Merge changes from topic "211677613"
* changes:
Add Vts test for enableUsbDataWhileDocked interface
Add fields to infer UsbPortStatus and allow enabling usb while docked
Diffstat (limited to 'usb')
13 files changed, 266 insertions, 3 deletions
diff --git a/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/IUsb.aidl b/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/IUsb.aidl index 73c7b825e2..4ba9ff8dff 100644 --- a/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/IUsb.aidl +++ b/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/IUsb.aidl @@ -36,6 +36,7 @@ package android.hardware.usb; interface IUsb { oneway void enableContaminantPresenceDetection(in String portName, in boolean enable, long transactionId); oneway void enableUsbData(in String portName, boolean enable, long transactionId); + oneway void enableUsbDataWhileDocked(in String portName, long transactionId); oneway void queryPortStatus(long transactionId); oneway void setCallback(in android.hardware.usb.IUsbCallback callback); oneway void switchRole(in String portName, in android.hardware.usb.PortRole role, long transactionId); diff --git a/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/IUsbCallback.aidl b/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/IUsbCallback.aidl index 85861e9d41..57f02c548c 100644 --- a/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/IUsbCallback.aidl +++ b/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/IUsbCallback.aidl @@ -37,6 +37,7 @@ interface IUsbCallback { oneway void notifyPortStatusChange(in android.hardware.usb.PortStatus[] currentPortStatus, in android.hardware.usb.Status retval); oneway void notifyRoleSwitchStatus(in String portName, in android.hardware.usb.PortRole newRole, in android.hardware.usb.Status retval, long transactionId); oneway void notifyEnableUsbDataStatus(in String portName, boolean enable, in android.hardware.usb.Status retval, long transactionId); + oneway void notifyEnableUsbDataWhileDockedStatus(in String portName, in android.hardware.usb.Status retval, long transactionId); oneway void notifyContaminantEnabledStatus(in String portName, boolean enable, in android.hardware.usb.Status retval, long transactionId); oneway void notifyQueryPortStatus(in String portName, in android.hardware.usb.Status retval, long transactionId); oneway void notifyLimitPowerTransferStatus(in String portName, boolean limit, in android.hardware.usb.Status retval, long transactionId); diff --git a/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/PortStatus.aidl b/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/PortStatus.aidl index 14bb90fd15..dfd99fb249 100644 --- a/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/PortStatus.aidl +++ b/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/PortStatus.aidl @@ -47,6 +47,7 @@ parcelable PortStatus { android.hardware.usb.ContaminantProtectionStatus contaminantProtectionStatus = android.hardware.usb.ContaminantProtectionStatus.NONE; boolean supportsEnableContaminantPresenceDetection; android.hardware.usb.ContaminantDetectionStatus contaminantDetectionStatus = android.hardware.usb.ContaminantDetectionStatus.NOT_SUPPORTED; - boolean usbDataEnabled; + android.hardware.usb.UsbDataStatus[] usbDataStatus; boolean powerTransferLimited; + android.hardware.usb.PowerBrickStatus powerBrickStatus; } diff --git a/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/PowerBrickStatus.aidl b/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/PowerBrickStatus.aidl new file mode 100644 index 0000000000..01d2fdd9f7 --- /dev/null +++ b/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/PowerBrickStatus.aidl @@ -0,0 +1,40 @@ +/* + * 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. + */ +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m <name>-update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package android.hardware.usb; +@VintfStability +enum PowerBrickStatus { + UNKNOWN = 0, + CONNECTED = 1, + NOT_CONNECTED = 2, +} diff --git a/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/UsbDataStatus.aidl b/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/UsbDataStatus.aidl new file mode 100644 index 0000000000..e2c0cfbef1 --- /dev/null +++ b/usb/aidl/aidl_api/android.hardware.usb/current/android/hardware/usb/UsbDataStatus.aidl @@ -0,0 +1,44 @@ +/* + * 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. + */ +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m <name>-update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package android.hardware.usb; +@VintfStability +enum UsbDataStatus { + UNKNOWN = 0, + ENABLED = 1, + DISABLED_OVERHEAT = 2, + DISABLED_CONTAMINANT = 3, + DISABLED_DOCK = 4, + DISABLED_FORCE = 5, + DISABLED_DEBUG = 6, +} diff --git a/usb/aidl/android/hardware/usb/IUsb.aidl b/usb/aidl/android/hardware/usb/IUsb.aidl index 1596d9ada5..d296fbb209 100644 --- a/usb/aidl/android/hardware/usb/IUsb.aidl +++ b/usb/aidl/android/hardware/usb/IUsb.aidl @@ -49,6 +49,15 @@ oneway interface IUsb { void enableUsbData(in String portName, boolean enable, long transactionId); /** + * This function is used to enable USB controller if and when the controller + * disabled due to docking event. + * + * @param portName Name of the port. + * @param transactionId ID to be used when invoking the callback. + */ + void enableUsbDataWhileDocked(in String portName, long transactionId); + + /** * This functions is used to request the hal for the current status * status of the Type-C ports. The result of the query would be sent * through the IUsbCallback object's notifyRoleSwitchStatus diff --git a/usb/aidl/android/hardware/usb/IUsbCallback.aidl b/usb/aidl/android/hardware/usb/IUsbCallback.aidl index b733fede3b..e33672aa2b 100644 --- a/usb/aidl/android/hardware/usb/IUsbCallback.aidl +++ b/usb/aidl/android/hardware/usb/IUsbCallback.aidl @@ -63,6 +63,16 @@ oneway interface IUsbCallback { long transactionId); /** + * Used to notify the result of enableUsbDataWhileDocked call to the caller. + * + * @param portName name of the port for which the enableUsbDataWhileDocked is requested. + * @param retval SUCCESS if current request succeeded. FAILURE otherwise. + * @param transactionId transactionId sent during enableUsbDataWhileDocked request. + */ + void notifyEnableUsbDataWhileDockedStatus(in String portName, in Status retval, + long transactionId); + + /** * Used to notify the result of enableContaminantPresenceDetection. * * @param portName name of the port for which contaminant detection is enabled/disabled. diff --git a/usb/aidl/android/hardware/usb/PortStatus.aidl b/usb/aidl/android/hardware/usb/PortStatus.aidl index fb979e5f62..51bee71389 100644 --- a/usb/aidl/android/hardware/usb/PortStatus.aidl +++ b/usb/aidl/android/hardware/usb/PortStatus.aidl @@ -22,6 +22,8 @@ import android.hardware.usb.ContaminantProtectionStatus; import android.hardware.usb.PortDataRole; import android.hardware.usb.PortMode; import android.hardware.usb.PortPowerRole; +import android.hardware.usb.PowerBrickStatus; +import android.hardware.usb.UsbDataStatus; @VintfStability parcelable PortStatus { @@ -102,10 +104,15 @@ parcelable PortStatus { ContaminantDetectionStatus contaminantDetectionStatus = ContaminantDetectionStatus.NOT_SUPPORTED; /** * UsbData status of the port. + * Lists reasons for USB data being disabled. */ - boolean usbDataEnabled; + UsbDataStatus[] usbDataStatus; /** * Denoted whether power transfer is limited in the port. */ boolean powerTransferLimited; + /** + * Denotes whether Power brick is connected. + */ + PowerBrickStatus powerBrickStatus; } diff --git a/usb/aidl/android/hardware/usb/PowerBrickStatus.aidl b/usb/aidl/android/hardware/usb/PowerBrickStatus.aidl new file mode 100644 index 0000000000..620fb25922 --- /dev/null +++ b/usb/aidl/android/hardware/usb/PowerBrickStatus.aidl @@ -0,0 +1,33 @@ +/* + * 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; + +@VintfStability +enum PowerBrickStatus { + /** + * Status not known. + */ + UNKNOWN = 0, + /** + * Port partner is power brick. + */ + CONNECTED = 1, + /** + * Port partner is not power brick. + */ + NOT_CONNECTED = 2, +} diff --git a/usb/aidl/android/hardware/usb/UsbDataStatus.aidl b/usb/aidl/android/hardware/usb/UsbDataStatus.aidl new file mode 100644 index 0000000000..4b6a41a01e --- /dev/null +++ b/usb/aidl/android/hardware/usb/UsbDataStatus.aidl @@ -0,0 +1,49 @@ +/* + * 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; + +@VintfStability +enum UsbDataStatus { + /** + * USB data status not known. + */ + UNKNOWN = 0, + /** + * USB data is enabled. + */ + ENABLED = 1, + /** + * USB data is disabled as the port is hot. + */ + DISABLED_OVERHEAT = 2, + /** + * USB data is disabled as port is contaminated. + */ + DISABLED_CONTAMINANT = 3, + /** + * USB data is disabled due to dock. + */ + DISABLED_DOCK = 4, + /** + * USB data is disabled by USB Service. + */ + DISABLED_FORCE = 5, + /** + * USB data disabled for debug. + */ + DISABLED_DEBUG = 6 +} diff --git a/usb/aidl/default/Usb.cpp b/usb/aidl/default/Usb.cpp index 0624963883..92b09a2b44 100644 --- a/usb/aidl/default/Usb.cpp +++ b/usb/aidl/default/Usb.cpp @@ -74,6 +74,22 @@ ScopedAStatus Usb::enableUsbData(const string& in_portName, bool in_enable, int6 return ScopedAStatus::ok(); } +ScopedAStatus Usb::enableUsbDataWhileDocked(const string& in_portName, int64_t in_transactionId) { + + pthread_mutex_lock(&mLock); + if (mCallback != NULL) { + ScopedAStatus ret = mCallback->notifyEnableUsbDataWhileDockedStatus( + in_portName, Status::NOT_SUPPORTED, in_transactionId); + if (!ret.isOk()) + ALOGE("notifyEnableUsbDataWhileDockedStatus error %s", ret.getDescription().c_str()); + } else { + ALOGE("Not notifying the userspace. Callback is not set"); + } + pthread_mutex_unlock(&mLock); + + return ScopedAStatus::ok(); +} + Status queryMoistureDetectionStatus(std::vector<PortStatus> *currentPortStatus) { string enabled, status, path, DetectedPath; @@ -473,7 +489,7 @@ Status getPortStatusHelper(std::vector<PortStatus> *currentPortStatus) { port.second ? canSwitchRoleHelper(port.first) : false; (*currentPortStatus)[i].supportedModes.push_back(PortMode::DRP); - (*currentPortStatus)[i].usbDataEnabled = true; + (*currentPortStatus)[i].usbDataStatus.push_back(UsbDataStatus::ENABLED); ALOGI("%d:%s connected:%d canChangeMode:%d canChagedata:%d canChangePower:%d " "usbDataEnabled:%d", diff --git a/usb/aidl/default/Usb.h b/usb/aidl/default/Usb.h index 71ec938a56..7e8422e39b 100644 --- a/usb/aidl/default/Usb.h +++ b/usb/aidl/default/Usb.h @@ -54,6 +54,8 @@ struct Usb : public BnUsb { int64_t in_transactionId) override; ScopedAStatus enableUsbData(const string& in_portName, bool in_enable, int64_t in_transactionId) override; + ScopedAStatus enableUsbDataWhileDocked(const string& in_portName, + int64_t in_transactionId) override; ScopedAStatus limitPowerTransfer(const std::string& in_portName, bool in_limit, int64_t in_transactionId)override; diff --git a/usb/aidl/vts/VtsAidlUsbTargetTest.cpp b/usb/aidl/vts/VtsAidlUsbTargetTest.cpp index bab5a3af59..ed3bd6e7db 100644 --- a/usb/aidl/vts/VtsAidlUsbTargetTest.cpp +++ b/usb/aidl/vts/VtsAidlUsbTargetTest.cpp @@ -112,6 +112,17 @@ class UsbAidlTest : public testing::TestWithParam<std::string> { return ScopedAStatus::ok(); } + // Callback method for the status of enableUsbData operation + ScopedAStatus notifyEnableUsbDataWhileDockedStatus(const string& /*portName*/, + Status /*retval*/, + int64_t transactionId) override { + parent_.last_transactionId = transactionId; + parent_.usb_last_cookie = cookie; + parent_.enable_usb_data_while_docked_done = true; + parent_.notify(); + return ScopedAStatus::ok(); + } + // Callback method for the status of enableContaminantPresenceDetection ScopedAStatus notifyContaminantEnabledStatus(const string& /*portName*/, bool /*enable*/, Status /*retval*/, int64_t transactionId) override { @@ -206,6 +217,9 @@ class UsbAidlTest : public testing::TestWithParam<std::string> { // Flag to indicate the invocation of notifyEnableUsbDataStatus callback. bool enable_usb_data_done; + // Flag to indicate the invocation of notifyEnableUsbDataWhileDockedStatus callback. + bool enable_usb_data_while_docked_done; + // Flag to indicate the invocation of notifyLimitPowerTransferStatus callback. bool limit_power_transfer_done; @@ -424,6 +438,42 @@ TEST_P(UsbAidlTest, enableUsbData) { } /* + * Test enabling Usb data while being docked. + * Test case queries the usb ports present in device. + * If there is at least one usb port, enabling Usb data while docked + * is attempted for the port. + * The callback parameters are checked to see if transaction id + * matches. + */ +TEST_P(UsbAidlTest, enableUsbDataWhileDocked) { + ALOGI("UsbAidlTest enableUsbDataWhileDocked start"); + int64_t transactionId = rand() % 10000; + const auto& ret = usb->queryPortStatus(transactionId); + ASSERT_TRUE(ret.isOk()); + EXPECT_EQ(std::cv_status::no_timeout, wait()); + EXPECT_EQ(2, usb_last_cookie); + EXPECT_EQ(transactionId, last_transactionId); + + if (!usb_last_port_status.portName.empty()) { + ALOGI("portname:%s", usb_last_port_status.portName.c_str()); + enable_usb_data_while_docked_done = false; + transactionId = rand() % 10000; + const auto& ret = usb->enableUsbDataWhileDocked(usb_last_port_status.portName, transactionId); + ASSERT_TRUE(ret.isOk()); + + std::cv_status waitStatus = wait(); + while (waitStatus == std::cv_status::no_timeout && + enable_usb_data_while_docked_done == false) + waitStatus = wait(); + + EXPECT_EQ(std::cv_status::no_timeout, waitStatus); + EXPECT_EQ(2, usb_last_cookie); + EXPECT_EQ(transactionId, last_transactionId); + } + ALOGI("UsbAidlTest enableUsbDataWhileDocked end"); +} + +/* * Test enabling Usb data of the port. * Test case queries the usb ports present in device. * If there is at least one usb port, relaxing limit power transfer |