mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 05:49:27 +00:00
Merge changes from topic "resetUsbPort"
* changes: Implement VTS for resetUsbPort and notifyResetUsbPort Add resetUsbPort in USB HAL interface
This commit is contained in:
committed by
Android (Google) Code Review
commit
79d54bc5c2
@@ -41,4 +41,5 @@ interface IUsb {
|
||||
oneway void setCallback(in android.hardware.usb.IUsbCallback callback);
|
||||
oneway void switchRole(in String portName, in android.hardware.usb.PortRole role, long transactionId);
|
||||
oneway void limitPowerTransfer(in String portName, boolean limit, long transactionId);
|
||||
oneway void resetUsbPort(in String portName,long transactionId);
|
||||
}
|
||||
|
||||
@@ -41,4 +41,5 @@ interface IUsbCallback {
|
||||
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);
|
||||
oneway void notifyResetUsbPortStatus(in String portName, in android.hardware.usb.Status retval, long transactionId);
|
||||
}
|
||||
|
||||
@@ -104,4 +104,13 @@ oneway interface IUsb {
|
||||
* @param transactionId ID to be used when invoking the callback.
|
||||
*/
|
||||
void limitPowerTransfer(in String portName, boolean limit, long transactionId);
|
||||
|
||||
/**
|
||||
* This function is used to reset the port role of a specific port.
|
||||
* For instance, when data transfer through the port fails.
|
||||
*
|
||||
* @param portName name of the port that is being reset
|
||||
* @param transactionId ID to be used when invoking the callback.
|
||||
*/
|
||||
void resetUsbPort(in String portName, long transactionId);
|
||||
}
|
||||
|
||||
@@ -105,4 +105,13 @@ oneway interface IUsbCallback {
|
||||
* @param transactionId ID sent during limitPowerTransfer request.
|
||||
*/
|
||||
void notifyLimitPowerTransferStatus(in String portName, boolean limit, in Status retval, long transactionId);
|
||||
|
||||
/**
|
||||
* Used to notify the result of requesting resetUsbPort.
|
||||
*
|
||||
* @param portName name of the port that was being reset.
|
||||
* @param retval SUCCESS if current request succeeded. FAILURE otherwise.
|
||||
* @param transactionId current transactionId sent during resetUsbPort request.
|
||||
*/
|
||||
void notifyResetUsbPortStatus(in String portName, in Status retval, long transactionId);
|
||||
}
|
||||
|
||||
@@ -90,6 +90,22 @@ ScopedAStatus Usb::enableUsbDataWhileDocked(const string& in_portName, int64_t i
|
||||
return ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ScopedAStatus Usb::resetUsbPort(const string& in_portName, int64_t in_transactionId) {
|
||||
|
||||
pthread_mutex_lock(&mLock);
|
||||
if (mCallback != NULL) {
|
||||
ScopedAStatus ret = mCallback->notifyResetUsbPortStatus(
|
||||
in_portName, Status::NOT_SUPPORTED, in_transactionId);
|
||||
if (!ret.isOk())
|
||||
ALOGE("notifyResetUsbPortStatus 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;
|
||||
|
||||
|
||||
@@ -58,6 +58,8 @@ struct Usb : public BnUsb {
|
||||
int64_t in_transactionId) override;
|
||||
ScopedAStatus limitPowerTransfer(const std::string& in_portName, bool in_limit,
|
||||
int64_t in_transactionId)override;
|
||||
ScopedAStatus resetUsbPort(const std::string& in_portName,
|
||||
int64_t in_transactionId)override;
|
||||
|
||||
shared_ptr<IUsbCallback> mCallback;
|
||||
// Protects mCallback variable
|
||||
|
||||
@@ -150,6 +150,17 @@ class UsbAidlTest : public testing::TestWithParam<std::string> {
|
||||
parent_.notify();
|
||||
return ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
// Callback method for the status of resetUsbPortStatus operation
|
||||
ScopedAStatus notifyResetUsbPortStatus(const string& /*portName*/, Status /*retval*/,
|
||||
int64_t transactionId) override {
|
||||
ALOGI("enter notifyResetUsbPortStatus");
|
||||
parent_.last_transactionId = transactionId;
|
||||
parent_.usb_last_cookie = cookie;
|
||||
parent_.reset_usb_port_done = true;
|
||||
parent_.notify();
|
||||
return ScopedAStatus::ok();
|
||||
}
|
||||
};
|
||||
|
||||
virtual void SetUp() override {
|
||||
@@ -223,6 +234,9 @@ class UsbAidlTest : public testing::TestWithParam<std::string> {
|
||||
// Flag to indicate the invocation of notifyLimitPowerTransferStatus callback.
|
||||
bool limit_power_transfer_done;
|
||||
|
||||
// Flag to indicate the invocation of notifyResetUsbPort callback.
|
||||
bool reset_usb_port_done;
|
||||
|
||||
// Stores the cookie of the last invoked usb callback object.
|
||||
int usb_last_cookie;
|
||||
|
||||
@@ -509,6 +523,43 @@ TEST_P(UsbAidlTest, limitPowerTransfer) {
|
||||
ALOGI("UsbAidlTest limitPowerTransfer end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Test reset Usb data of the port.
|
||||
* Test case queries the usb ports present in device.
|
||||
* If there is at least one usb port, reset Usb data for the port.
|
||||
* The callback parameters are checked to see if transaction id
|
||||
* matches.
|
||||
*/
|
||||
TEST_P(UsbAidlTest, DISABLED_resetUsbPort) {
|
||||
ALOGI("UsbAidlTest resetUsbPort 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());
|
||||
reset_usb_port_done = false;
|
||||
transactionId = rand() % 10000;
|
||||
const auto& ret = usb->resetUsbPort(usb_last_port_status.portName, transactionId);
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
ALOGI("UsbAidlTest resetUsbPort ret.isOk");
|
||||
|
||||
std::cv_status waitStatus = wait();
|
||||
while (waitStatus == std::cv_status::no_timeout &&
|
||||
reset_usb_port_done == false)
|
||||
waitStatus = wait();
|
||||
|
||||
ALOGI("UsbAidlTest resetUsbPort wait()");
|
||||
EXPECT_EQ(std::cv_status::no_timeout, waitStatus);
|
||||
EXPECT_EQ(2, usb_last_cookie);
|
||||
EXPECT_EQ(transactionId, last_transactionId);
|
||||
}
|
||||
ALOGI("UsbAidlTest resetUsbPort end");
|
||||
}
|
||||
|
||||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(UsbAidlTest);
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
PerInstance, UsbAidlTest,
|
||||
|
||||
Reference in New Issue
Block a user