Merge changes from topic "211677613"

* changes:
  Add Vts test for enableUsbDataWhileDocked interface
  Add fields to infer UsbPortStatus and allow enabling usb while docked
This commit is contained in:
Badhri Jagan Sridharan
2022-01-24 19:19:25 +00:00
committed by Android (Google) Code Review
13 changed files with 266 additions and 3 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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,
}

View File

@@ -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,
}

View File

@@ -48,6 +48,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

View File

@@ -62,6 +62,16 @@ oneway interface IUsbCallback {
void notifyEnableUsbDataStatus(in String portName, boolean enable, in Status retval,
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.
*

View File

@@ -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;
}

View File

@@ -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,
}

View File

@@ -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
}

View File

@@ -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",

View File

@@ -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;

View File

@@ -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;
@@ -423,6 +437,42 @@ TEST_P(UsbAidlTest, enableUsbData) {
ALOGI("UsbAidlTest enableUsbData end");
}
/*
* 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.