Revert "Migrate IUsbGadget implementation to AIDL"

This reverts commit bbcd013c41.

Reason for revert: Increase the boot time to cause the below bug.
b/261027750 | P0 | Broken test: v2/android-perfetto-dev-team/apct/perfetto/perfetto_integrationtests on git_master on oriole_hwasan-userdebug at 9355690

Change-Id: Idba7322ca86e70cf5d8e170936696586caa8c1c2
This commit is contained in:
Chien Kun Niu 2022-12-07 00:32:18 +00:00 committed by TreeHugger Robot
parent a381b21dfc
commit 3507989979
8 changed files with 156 additions and 179 deletions

View file

@ -27,11 +27,10 @@ package {
cc_binary { cc_binary {
name: "android.hardware.usb.gadget-service.gs101", name: "android.hardware.usb.gadget-service.gs101",
relative_install_path: "hw", relative_install_path: "hw",
init_rc: ["android.hardware.usb.gadget-service.rc"], init_rc: ["android.hardware.usb.gadget-service.gs101.rc"],
vintf_fragments: [ vintf_fragments: [
"android.hardware.usb.gadget-service.xml", "android.hardware.usb.gadget@1.2-service.gs101.xml",
], ],
vendor: true,
srcs: ["service_gadget.cpp", "UsbGadget.cpp"], srcs: ["service_gadget.cpp", "UsbGadget.cpp"],
cflags: ["-Wall", "-Werror"], cflags: ["-Wall", "-Werror"],
shared_libs: [ shared_libs: [
@ -41,16 +40,13 @@ cc_binary {
"liblog", "liblog",
"libutils", "libutils",
"libhardware", "libhardware",
"android.hardware.usb.gadget-V1-ndk", "android.hardware.usb.gadget@1.0",
"android.frameworks.stats-V1-ndk", "android.hardware.usb.gadget@1.1",
"android.hardware.usb.gadget@1.2",
"libcutils", "libcutils",
"libbinder_ndk",
], ],
static_libs: [ static_libs: [
"libpixelusb", "libpixelusb",
], ],
proprietary: true, proprietary: true,
export_shared_lib_headers: [
"android.frameworks.stats-V1-ndk",
],
} }

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#define LOG_TAG "android.hardware.usb.gadget.aidl-service" #define LOG_TAG "android.hardware.usb.gadget@1.2-service.gs101"
#include "UsbGadget.h" #include "UsbGadget.h"
#include <dirent.h> #include <dirent.h>
@ -26,13 +26,12 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <aidl/android/frameworks/stats/IStats.h>
namespace aidl {
namespace android { namespace android {
namespace hardware { namespace hardware {
namespace usb { namespace usb {
namespace gadget { namespace gadget {
namespace V1_2 {
namespace implementation {
string enabledPath; string enabledPath;
constexpr char kHsi2cPath[] = "/sys/devices/platform/10d50000.hsi2c"; constexpr char kHsi2cPath[] = "/sys/devices/platform/10d50000.hsi2c";
@ -47,7 +46,7 @@ UsbGadget::UsbGadget() : mGadgetIrqPath("") {
} }
} }
Status UsbGadget::getUsbGadgetIrqPath() { V1_0::Status UsbGadget::getUsbGadgetIrqPath() {
std::string irqs; std::string irqs;
size_t read_pos = 0; size_t read_pos = 0;
size_t found_pos = 0; size_t found_pos = 0;
@ -94,20 +93,17 @@ void currentFunctionsAppliedCallback(bool functionsApplied, void *payload) {
gadget->mCurrentUsbFunctionsApplied = functionsApplied; gadget->mCurrentUsbFunctionsApplied = functionsApplied;
} }
ScopedAStatus UsbGadget::getCurrentUsbFunctions(const shared_ptr<IUsbGadgetCallback> &callback, Return<void> UsbGadget::getCurrentUsbFunctions(const sp<V1_0::IUsbGadgetCallback> &callback) {
int64_t in_transactionId) { Return<void> ret = callback->getCurrentUsbFunctionsCb(
ScopedAStatus ret = callback->getCurrentUsbFunctionsCb(
mCurrentUsbFunctions, mCurrentUsbFunctions,
mCurrentUsbFunctionsApplied ? Status::FUNCTIONS_APPLIED : Status::FUNCTIONS_NOT_APPLIED, mCurrentUsbFunctionsApplied ? Status::FUNCTIONS_APPLIED : Status::FUNCTIONS_NOT_APPLIED);
in_transactionId);
if (!ret.isOk()) if (!ret.isOk())
ALOGE("Call to getCurrentUsbFunctionsCb failed %s", ret.getDescription().c_str()); ALOGE("Call to getCurrentUsbFunctionsCb failed %s", ret.description().c_str());
return ScopedAStatus::ok(); return Void();
} }
ScopedAStatus UsbGadget::getUsbSpeed(const shared_ptr<IUsbGadgetCallback> &callback, Return<void> UsbGadget::getUsbSpeed(const sp<V1_2::IUsbGadgetCallback> &callback) {
int64_t in_transactionId) {
std::string current_speed; std::string current_speed;
if (ReadFileToString(SPEED_PATH, &current_speed)) { if (ReadFileToString(SPEED_PATH, &current_speed)) {
current_speed = Trim(current_speed); current_speed = Trim(current_speed);
@ -125,26 +121,25 @@ ScopedAStatus UsbGadget::getUsbSpeed(const shared_ptr<IUsbGadgetCallback> &callb
else if (current_speed == "UNKNOWN") else if (current_speed == "UNKNOWN")
mUsbSpeed = UsbSpeed::UNKNOWN; mUsbSpeed = UsbSpeed::UNKNOWN;
else else
mUsbSpeed = UsbSpeed::UNKNOWN; mUsbSpeed = UsbSpeed::RESERVED_SPEED;
} else { } else {
ALOGE("Fail to read current speed"); ALOGE("Fail to read current speed");
mUsbSpeed = UsbSpeed::UNKNOWN; mUsbSpeed = UsbSpeed::UNKNOWN;
} }
if (callback) { if (callback) {
ScopedAStatus ret = callback->getUsbSpeedCb(mUsbSpeed, in_transactionId); Return<void> ret = callback->getUsbSpeedCb(mUsbSpeed);
if (!ret.isOk()) if (!ret.isOk())
ALOGE("Call to getUsbSpeedCb failed %s", ret.getDescription().c_str()); ALOGE("Call to getUsbSpeedCb failed %s", ret.description().c_str());
} }
return ScopedAStatus::ok(); return Void();
} }
Status UsbGadget::tearDownGadget() { V1_0::Status UsbGadget::tearDownGadget() {
if (Status(resetGadget()) != Status::SUCCESS){ if (resetGadget() != Status::SUCCESS)
return Status::ERROR; return Status::ERROR;
}
if (monitorFfs.isMonitorRunning()) { if (monitorFfs.isMonitorRunning()) {
monitorFfs.reset(); monitorFfs.reset();
@ -154,152 +149,139 @@ Status UsbGadget::tearDownGadget() {
return Status::SUCCESS; return Status::SUCCESS;
} }
static Status validateAndSetVidPid(uint64_t functions) { static V1_0::Status validateAndSetVidPid(uint64_t functions) {
Status ret = Status::SUCCESS; V1_0::Status ret = Status::SUCCESS;
std::string vendorFunctions = getVendorFunctions(); std::string vendorFunctions = getVendorFunctions();
switch (functions) { switch (functions) {
case GadgetFunction::MTP: case static_cast<uint64_t>(GadgetFunction::MTP):
if (!(vendorFunctions == "user" || vendorFunctions == "")) { if (!(vendorFunctions == "user" || vendorFunctions == "")) {
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status::CONFIGURATION_NOT_SUPPORTED; ret = Status::CONFIGURATION_NOT_SUPPORTED;
} else { } else {
ret = Status(setVidPid("0x18d1", "0x4ee1")); ret = setVidPid("0x18d1", "0x4ee1");
} }
break; break;
case GadgetFunction::ADB | case GadgetFunction::ADB | GadgetFunction::MTP:
GadgetFunction::MTP:
if (!(vendorFunctions == "user" || vendorFunctions == "")) { if (!(vendorFunctions == "user" || vendorFunctions == "")) {
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status::CONFIGURATION_NOT_SUPPORTED; ret = Status::CONFIGURATION_NOT_SUPPORTED;
} else { } else {
ret = Status(setVidPid("0x18d1", "0x4ee2")); ret = setVidPid("0x18d1", "0x4ee2");
} }
break; break;
case GadgetFunction::RNDIS: case static_cast<uint64_t>(GadgetFunction::RNDIS):
case GadgetFunction::RNDIS | case GadgetFunction::RNDIS | GadgetFunction::NCM:
GadgetFunction::NCM:
if (!(vendorFunctions == "user" || vendorFunctions == "")) { if (!(vendorFunctions == "user" || vendorFunctions == "")) {
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status::CONFIGURATION_NOT_SUPPORTED; ret = Status::CONFIGURATION_NOT_SUPPORTED;
} else { } else {
ret = Status(setVidPid("0x18d1", "0x4ee3")); ret = setVidPid("0x18d1", "0x4ee3");
} }
break; break;
case GadgetFunction::ADB | case GadgetFunction::ADB | GadgetFunction::RNDIS:
GadgetFunction::RNDIS: case GadgetFunction::ADB | GadgetFunction::RNDIS | GadgetFunction::NCM:
case GadgetFunction::ADB |
GadgetFunction::RNDIS |
GadgetFunction::NCM:
if (vendorFunctions == "dm") { if (vendorFunctions == "dm") {
ret = Status(setVidPid("0x04e8", "0x6862")); ret = setVidPid("0x04e8", "0x6862");
} else { } else {
if (!(vendorFunctions == "user" || vendorFunctions == "")) { if (!(vendorFunctions == "user" || vendorFunctions == "")) {
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status::CONFIGURATION_NOT_SUPPORTED; ret = Status::CONFIGURATION_NOT_SUPPORTED;
} else { } else {
ret = Status(setVidPid("0x18d1", "0x4ee4")); ret = setVidPid("0x18d1", "0x4ee4");
} }
} }
break; break;
case GadgetFunction::PTP: case static_cast<uint64_t>(GadgetFunction::PTP):
if (!(vendorFunctions == "user" || vendorFunctions == "")) { if (!(vendorFunctions == "user" || vendorFunctions == "")) {
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status::CONFIGURATION_NOT_SUPPORTED; ret = Status::CONFIGURATION_NOT_SUPPORTED;
} else { } else {
ret = Status(setVidPid("0x18d1", "0x4ee5")); ret = setVidPid("0x18d1", "0x4ee5");
} }
break; break;
case GadgetFunction::ADB | case GadgetFunction::ADB | GadgetFunction::PTP:
GadgetFunction::PTP:
if (!(vendorFunctions == "user" || vendorFunctions == "")) { if (!(vendorFunctions == "user" || vendorFunctions == "")) {
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status::CONFIGURATION_NOT_SUPPORTED; ret = Status::CONFIGURATION_NOT_SUPPORTED;
} else { } else {
ret = Status(setVidPid("0x18d1", "0x4ee6")); ret = setVidPid("0x18d1", "0x4ee6");
} }
break; break;
case GadgetFunction::ADB: case static_cast<uint64_t>(GadgetFunction::ADB):
if (vendorFunctions == "dm") { if (vendorFunctions == "dm") {
ret = Status(setVidPid("0x04e8", "0x6862")); ret = setVidPid("0x04e8", "0x6862");
} else if (vendorFunctions == "etr_miu") { } else if (vendorFunctions == "etr_miu") {
ret = Status(setVidPid("0x18d1", "0x4ee2")); ret = setVidPid("0x18d1", "0x4ee2");
} else if (vendorFunctions == "uwb_acm"){ } else if (vendorFunctions == "uwb_acm"){
ret = Status(setVidPid("0x18d1", "0x4ee2")); ret = setVidPid("0x18d1", "0x4ee2");
} else { } else {
if (!(vendorFunctions == "user" || vendorFunctions == "")) { if (!(vendorFunctions == "user" || vendorFunctions == "")) {
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status::CONFIGURATION_NOT_SUPPORTED; ret = Status::CONFIGURATION_NOT_SUPPORTED;
} else { } else {
ret = Status(setVidPid("0x18d1", "0x4ee7")); ret = setVidPid("0x18d1", "0x4ee7");
} }
} }
break; break;
case GadgetFunction::MIDI: case static_cast<uint64_t>(GadgetFunction::MIDI):
if (!(vendorFunctions == "user" || vendorFunctions == "")) { if (!(vendorFunctions == "user" || vendorFunctions == "")) {
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status::CONFIGURATION_NOT_SUPPORTED; ret = Status::CONFIGURATION_NOT_SUPPORTED;
} else { } else {
ret = Status(setVidPid("0x18d1", "0x4ee8")); ret = setVidPid("0x18d1", "0x4ee8");
} }
break; break;
case GadgetFunction::ADB | case GadgetFunction::ADB | GadgetFunction::MIDI:
GadgetFunction::MIDI:
if (!(vendorFunctions == "user" || vendorFunctions == "")) { if (!(vendorFunctions == "user" || vendorFunctions == "")) {
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status::CONFIGURATION_NOT_SUPPORTED; ret = Status::CONFIGURATION_NOT_SUPPORTED;
} else { } else {
ret = Status(setVidPid("0x18d1", "0x4ee9")); ret = setVidPid("0x18d1", "0x4ee9");
} }
break; break;
case GadgetFunction::ACCESSORY: case static_cast<uint64_t>(GadgetFunction::ACCESSORY):
if (!(vendorFunctions == "user" || vendorFunctions == "")) if (!(vendorFunctions == "user" || vendorFunctions == ""))
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status(setVidPid("0x18d1", "0x2d00")); ret = setVidPid("0x18d1", "0x2d00");
break; break;
case GadgetFunction::ADB | case GadgetFunction::ADB | GadgetFunction::ACCESSORY:
GadgetFunction::ACCESSORY:
if (!(vendorFunctions == "user" || vendorFunctions == "")) if (!(vendorFunctions == "user" || vendorFunctions == ""))
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status(setVidPid("0x18d1", "0x2d01")); ret = setVidPid("0x18d1", "0x2d01");
break; break;
case GadgetFunction::AUDIO_SOURCE: case static_cast<uint64_t>(GadgetFunction::AUDIO_SOURCE):
if (!(vendorFunctions == "user" || vendorFunctions == "")) if (!(vendorFunctions == "user" || vendorFunctions == ""))
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status(setVidPid("0x18d1", "0x2d02")); ret = setVidPid("0x18d1", "0x2d02");
break; break;
case GadgetFunction::ADB | case GadgetFunction::ADB | GadgetFunction::AUDIO_SOURCE:
GadgetFunction::AUDIO_SOURCE:
if (!(vendorFunctions == "user" || vendorFunctions == "")) if (!(vendorFunctions == "user" || vendorFunctions == ""))
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status(setVidPid("0x18d1", "0x2d03")); ret = setVidPid("0x18d1", "0x2d03");
break; break;
case GadgetFunction::ACCESSORY | case GadgetFunction::ACCESSORY | GadgetFunction::AUDIO_SOURCE:
GadgetFunction::AUDIO_SOURCE:
if (!(vendorFunctions == "user" || vendorFunctions == "")) if (!(vendorFunctions == "user" || vendorFunctions == ""))
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status(setVidPid("0x18d1", "0x2d04")); ret = setVidPid("0x18d1", "0x2d04");
break; break;
case GadgetFunction::ADB | case GadgetFunction::ADB | GadgetFunction::ACCESSORY | GadgetFunction::AUDIO_SOURCE:
GadgetFunction::ACCESSORY |
GadgetFunction::AUDIO_SOURCE:
if (!(vendorFunctions == "user" || vendorFunctions == "")) if (!(vendorFunctions == "user" || vendorFunctions == ""))
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status(setVidPid("0x18d1", "0x2d05")); ret = setVidPid("0x18d1", "0x2d05");
break; break;
case GadgetFunction::NCM: case static_cast<uint64_t>(GadgetFunction::NCM):
if (!(vendorFunctions == "user" || vendorFunctions == "")) if (!(vendorFunctions == "user" || vendorFunctions == ""))
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status(setVidPid("0x18d1", "0x4eeb")); ret = setVidPid("0x18d1", "0x4eeb");
break; break;
case GadgetFunction::ADB | case GadgetFunction::ADB | GadgetFunction::NCM:
GadgetFunction::NCM:
if (vendorFunctions == "dm") { if (vendorFunctions == "dm") {
ret = Status(setVidPid("0x04e8", "0x6862")); ret = setVidPid("0x04e8", "0x6862");
} else { } else {
if (!(vendorFunctions == "user" || vendorFunctions == "")) if (!(vendorFunctions == "user" || vendorFunctions == ""))
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
ret = Status(setVidPid("0x18d1", "0x4eec")); ret = setVidPid("0x18d1", "0x4eec");
} }
break; break;
default: default:
@ -309,33 +291,31 @@ static Status validateAndSetVidPid(uint64_t functions) {
return ret; return ret;
} }
ScopedAStatus UsbGadget::reset() { Return<Status> UsbGadget::reset() {
ALOGI("USB Gadget reset"); ALOGI("USB Gadget reset");
if (!WriteStringToFile("none", PULLUP_PATH)) { if (!WriteStringToFile("none", PULLUP_PATH)) {
ALOGI("Gadget cannot be pulled down"); ALOGI("Gadget cannot be pulled down");
return ScopedAStatus::fromServiceSpecificErrorWithMessage( return Status::ERROR;
-1, "Gadget cannot be pulled down");
} }
usleep(kDisconnectWaitUs); usleep(kDisconnectWaitUs);
if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) { if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) {
ALOGI("Gadget cannot be pulled up"); ALOGI("Gadget cannot be pulled up");
return ScopedAStatus::fromServiceSpecificErrorWithMessage( return Status::ERROR;
-1, "Gadget cannot be pulled up");
} }
return ScopedAStatus::ok(); return Status::SUCCESS;
} }
Status UsbGadget::setupFunctions(long functions, V1_0::Status UsbGadget::setupFunctions(uint64_t functions,
const shared_ptr<IUsbGadgetCallback> &callback, uint64_t timeout, const sp<V1_0::IUsbGadgetCallback> &callback,
int64_t in_transactionId) { uint64_t timeout) {
bool ffsEnabled = false; bool ffsEnabled = false;
int i = 0; int i = 0;
if (Status(addGenericAndroidFunctions(&monitorFfs, functions, &ffsEnabled, &i)) != if (addGenericAndroidFunctions(&monitorFfs, functions, &ffsEnabled, &i) !=
Status::SUCCESS) Status::SUCCESS)
return Status::ERROR; return Status::ERROR;
@ -366,7 +346,7 @@ Status UsbGadget::setupFunctions(long functions,
if ((functions & GadgetFunction::ADB) != 0) { if ((functions & GadgetFunction::ADB) != 0) {
ffsEnabled = true; ffsEnabled = true;
if (Status(addAdb(&monitorFfs, &i)) != Status::SUCCESS) if (addAdb(&monitorFfs, &i) != Status::SUCCESS)
return Status::ERROR; return Status::ERROR;
} }
@ -382,7 +362,7 @@ Status UsbGadget::setupFunctions(long functions,
return Status::ERROR; return Status::ERROR;
mCurrentUsbFunctionsApplied = true; mCurrentUsbFunctionsApplied = true;
if (callback) if (callback)
callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId); callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS);
return Status::SUCCESS; return Status::SUCCESS;
} }
@ -397,13 +377,12 @@ Status UsbGadget::setupFunctions(long functions,
if (callback) { if (callback) {
bool pullup = monitorFfs.waitForPullUp(timeout); bool pullup = monitorFfs.waitForPullUp(timeout);
ScopedAStatus ret = callback->setCurrentUsbFunctionsCb( Return<void> ret = callback->setCurrentUsbFunctionsCb(
functions, pullup ? Status::SUCCESS : Status::ERROR, in_transactionId); functions, pullup ? Status::SUCCESS : Status::ERROR);
if (!ret.isOk()) { if (!ret.isOk())
ALOGE("setCurrentUsbFunctionsCb error %s", ret.getDescription().c_str()); ALOGE("setCurrentUsbFunctionsCb error %s", ret.description().c_str());
return Status::ERROR;
}
} }
return Status::SUCCESS; return Status::SUCCESS;
} }
@ -430,10 +409,9 @@ Status getI2cBusHelper(string *name) {
return Status::ERROR; return Status::ERROR;
} }
ScopedAStatus UsbGadget::setCurrentUsbFunctions(long functions, Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
const shared_ptr<IUsbGadgetCallback> &callback, const sp<V1_0::IUsbGadgetCallback> &callback,
int64_t timeout, uint64_t timeout) {
int64_t in_transactionId) {
std::unique_lock<std::mutex> lk(mLockSetCurrentFunction); std::unique_lock<std::mutex> lk(mLockSetCurrentFunction);
std::string current_usb_power_operation_mode, current_usb_type; std::string current_usb_power_operation_mode, current_usb_type;
std::string usb_limit_sink_enable; std::string usb_limit_sink_enable;
@ -452,7 +430,7 @@ ScopedAStatus UsbGadget::setCurrentUsbFunctions(long functions,
getUsbGadgetIrqPath(); getUsbGadgetIrqPath();
// Unlink the gadget and stop the monitor if running. // Unlink the gadget and stop the monitor if running.
Status status = tearDownGadget(); V1_0::Status status = tearDownGadget();
if (status != Status::SUCCESS) { if (status != Status::SUCCESS) {
goto error; goto error;
} }
@ -462,15 +440,13 @@ ScopedAStatus UsbGadget::setCurrentUsbFunctions(long functions,
// Leave the gadget pulled down to give time for the host to sense disconnect. // Leave the gadget pulled down to give time for the host to sense disconnect.
usleep(kDisconnectWaitUs); usleep(kDisconnectWaitUs);
if (functions == GadgetFunction::NONE) { if (functions == static_cast<uint64_t>(GadgetFunction::NONE)) {
if (callback == NULL) if (callback == NULL)
return ScopedAStatus::fromServiceSpecificErrorWithMessage( return Void();
-1, "callback == NULL"); Return<void> ret = callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS);
ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId);
if (!ret.isOk()) if (!ret.isOk())
ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.getDescription().c_str()); ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.description().c_str());
return ScopedAStatus::fromServiceSpecificErrorWithMessage( return Void();
-1, "Error while calling setCurrentUsbFunctionsCb");
} }
status = validateAndSetVidPid(functions); status = validateAndSetVidPid(functions);
@ -479,7 +455,7 @@ ScopedAStatus UsbGadget::setCurrentUsbFunctions(long functions,
goto error; goto error;
} }
status = setupFunctions(functions, callback, timeout, in_transactionId); status = setupFunctions(functions, callback, timeout);
if (status != Status::SUCCESS) { if (status != Status::SUCCESS) {
goto error; goto error;
} }
@ -519,23 +495,20 @@ ScopedAStatus UsbGadget::setCurrentUsbFunctions(long functions,
} }
ALOGI("Usb Gadget setcurrent functions called successfully"); ALOGI("Usb Gadget setcurrent functions called successfully");
return ScopedAStatus::fromServiceSpecificErrorWithMessage( return Void();
-1, "Usb Gadget setcurrent functions called successfully");
error: error:
ALOGI("Usb Gadget setcurrent functions failed"); ALOGI("Usb Gadget setcurrent functions failed");
if (callback == NULL) if (callback == NULL)
return ScopedAStatus::fromServiceSpecificErrorWithMessage( return Void();
-1, "Usb Gadget setcurrent functions failed"); Return<void> ret = callback->setCurrentUsbFunctionsCb(functions, status);
ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions, status, in_transactionId);
if (!ret.isOk()) if (!ret.isOk())
ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.getDescription().c_str()); ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.description().c_str());
return ScopedAStatus::fromServiceSpecificErrorWithMessage( return Void();
-1, "Error while calling setCurrentUsbFunctionsCb");
} }
} // namespace implementation
} // namespace V1_2
} // namespace gadget } // namespace gadget
} // namespace usb } // namespace usb
} // namespace hardware } // namespace hardware
} // namespace android } // namespace android
} // aidl

View file

@ -21,13 +21,11 @@
#include <android-base/unique_fd.h> #include <android-base/unique_fd.h>
#include <android-base/parseint.h> #include <android-base/parseint.h>
#include <android-base/strings.h> #include <android-base/strings.h>
#include <aidl/android/hardware/usb/gadget/BnUsbGadget.h> #include <android/hardware/usb/gadget/1.2/IUsbGadget.h>
#include <aidl/android/hardware/usb/gadget/BnUsbGadgetCallback.h> #include <android/hardware/usb/gadget/1.2/types.h>
#include <aidl/android/hardware/usb/gadget/GadgetFunction.h> #include <hidl/MQDescriptor.h>
#include <aidl/android/hardware/usb/gadget/IUsbGadget.h> #include <hidl/Status.h>
#include <aidl/android/hardware/usb/gadget/IUsbGadgetCallback.h> #include <pixelusb/UsbGadgetCommon.h>
#include <pixelusb/UsbGadgetAidlCommon.h>
#include <sched.h>
#include <sys/epoll.h> #include <sys/epoll.h>
#include <sys/eventfd.h> #include <sys/eventfd.h>
#include <utils/Log.h> #include <utils/Log.h>
@ -37,17 +35,14 @@
#include <string> #include <string>
#include <thread> #include <thread>
namespace aidl {
namespace android { namespace android {
namespace hardware { namespace hardware {
namespace usb { namespace usb {
namespace gadget { namespace gadget {
namespace V1_2 {
namespace implementation {
using ::aidl::android::hardware::usb::gadget::GadgetFunction; using ::android::sp;
using ::aidl::android::hardware::usb::gadget::IUsbGadgetCallback;
using ::aidl::android::hardware::usb::gadget::IUsbGadget;
using ::aidl::android::hardware::usb::gadget::Status;
using ::aidl::android::hardware::usb::gadget::UsbSpeed;
using ::android::base::GetProperty; using ::android::base::GetProperty;
using ::android::base::SetProperty; using ::android::base::SetProperty;
using ::android::base::ParseUint; using ::android::base::ParseUint;
@ -55,6 +50,12 @@ using ::android::base::unique_fd;
using ::android::base::ReadFileToString; using ::android::base::ReadFileToString;
using ::android::base::Trim; using ::android::base::Trim;
using ::android::base::WriteStringToFile; using ::android::base::WriteStringToFile;
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::google::pixel::usb::addAdb; using ::android::hardware::google::pixel::usb::addAdb;
using ::android::hardware::google::pixel::usb::addEpollFd; using ::android::hardware::google::pixel::usb::addEpollFd;
using ::android::hardware::google::pixel::usb::getVendorFunctions; using ::android::hardware::google::pixel::usb::getVendorFunctions;
@ -65,8 +66,10 @@ using ::android::hardware::google::pixel::usb::MonitorFfs;
using ::android::hardware::google::pixel::usb::resetGadget; using ::android::hardware::google::pixel::usb::resetGadget;
using ::android::hardware::google::pixel::usb::setVidPid; using ::android::hardware::google::pixel::usb::setVidPid;
using ::android::hardware::google::pixel::usb::unlinkFunctions; using ::android::hardware::google::pixel::usb::unlinkFunctions;
using ::ndk::ScopedAStatus; using ::android::hardware::usb::gadget::V1_0::Status;
using ::std::shared_ptr; using ::android::hardware::usb::gadget::V1_0::IUsbGadgetCallback;
using ::android::hardware::usb::gadget::V1_2::IUsbGadget;
using ::android::hardware::usb::gadget::V1_2::GadgetFunction;
using ::std::string; using ::std::string;
constexpr char kGadgetName[] = "11110000.dwc3"; constexpr char kGadgetName[] = "11110000.dwc3";
@ -90,39 +93,36 @@ static MonitorFfs monitorFfs(kGadgetName);
#define CURRENT_USB_TYPE_PATH POWER_SUPPLY_PATH "usb_type" #define CURRENT_USB_TYPE_PATH POWER_SUPPLY_PATH "usb_type"
#define CURRENT_USB_POWER_OPERATION_MODE_PATH USB_PORT0_PATH "power_operation_mode" #define CURRENT_USB_POWER_OPERATION_MODE_PATH USB_PORT0_PATH "power_operation_mode"
struct UsbGadget : public BnUsbGadget { struct UsbGadget : public IUsbGadget {
UsbGadget(); UsbGadget();
// Makes sure that only one request is processed at a time. // Makes sure that only one request is processed at a time.
std::mutex mLockSetCurrentFunction; std::mutex mLockSetCurrentFunction;
std::string mGadgetIrqPath; std::string mGadgetIrqPath;
long mCurrentUsbFunctions; uint64_t mCurrentUsbFunctions;
bool mCurrentUsbFunctionsApplied; bool mCurrentUsbFunctionsApplied;
UsbSpeed mUsbSpeed; UsbSpeed mUsbSpeed;
ScopedAStatus setCurrentUsbFunctions(long functions, Return<void> setCurrentUsbFunctions(uint64_t functions,
const shared_ptr<IUsbGadgetCallback> &callback, const sp<V1_0::IUsbGadgetCallback> &callback,
int64_t timeout, int64_t in_transactionId) override; uint64_t timeout) override;
ScopedAStatus getCurrentUsbFunctions(const shared_ptr<IUsbGadgetCallback> &callback, Return<void> getCurrentUsbFunctions(const sp<V1_0::IUsbGadgetCallback> &callback) override;
int64_t in_transactionId) override;
ScopedAStatus reset() override; Return<Status> reset() override;
ScopedAStatus getUsbSpeed(const shared_ptr<IUsbGadgetCallback> &callback, Return<void> getUsbSpeed(const sp<V1_2::IUsbGadgetCallback> &callback) override;
int64_t in_transactionId) override;
ScopedAStatus setVidPid(const char *vid,const char *pid);
private: private:
Status tearDownGadget(); Status tearDownGadget();
Status getUsbGadgetIrqPath(); Status getUsbGadgetIrqPath();
Status setupFunctions(long functions, const shared_ptr<IUsbGadgetCallback> &callback, Status setupFunctions(uint64_t functions, const sp<V1_0::IUsbGadgetCallback> &callback,
uint64_t timeout, int64_t in_transactionId); uint64_t timeout);
}; };
} // namespace implementation
} // namespace V1_2
} // namespace gadget } // namespace gadget
} // namespace usb } // namespace usb
} // namespace hardware } // namespace hardware
} // namespace android } // namespace android
} // aidl

View file

@ -1,4 +1,4 @@
service vendor.usb-gadget-hal /vendor/bin/hw/android.hardware.usb.gadget-service.gs101 service vendor.usb-gadget-hal-1-2 /vendor/bin/hw/android.hardware.usb.gadget-service.gs101
class hal class hal
user system user system
group system shell mtp wakelock group system shell mtp wakelock

View file

@ -1,7 +1,8 @@
<manifest version="1.0" type="device"> <manifest version="1.0" type="device">
<hal format="aidl"> <hal format="hidl">
<name>android.hardware.usb.gadget</name> <name>android.hardware.usb.gadget</name>
<version>1</version> <transport>hwbinder</transport>
<version>1.2</version>
<interface> <interface>
<name>IUsbGadget</name> <name>IUsbGadget</name>
<instance>default</instance> <instance>default</instance>

View file

@ -16,27 +16,35 @@
#define LOG_TAG "android.hardware.usb.gadget-service.gs101" #define LOG_TAG "android.hardware.usb.gadget-service.gs101"
#include <android-base/logging.h> #include <hidl/HidlTransportSupport.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <utils/Log.h>
#include "UsbGadget.h" #include "UsbGadget.h"
using android::OK;
using android::sp; using android::sp;
// libhwbinder:
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
// Generated HIDL files
using android::hardware::usb::gadget::V1_2::IUsbGadget;
using android::hardware::usb::gadget::V1_2::implementation::UsbGadget;
using android::OK;
using android::status_t; using android::status_t;
using aidl::android::hardware::usb::gadget::UsbGadget;
int main() { int main() {
ABinderProcess_setThreadPoolMaxThreadCount(0); android::sp<IUsbGadget> service = new UsbGadget();
std::shared_ptr<UsbGadget> usbgadget = ndk::SharedRefBase::make<UsbGadget>(); configureRpcThreadpool(2, true /*callerWillJoin*/);
status_t status = service->registerAsService();
const std::string instance = std::string() + UsbGadget::descriptor + "/default"; if (status != OK) {
binder_status_t status = AServiceManager_addService(usbgadget->asBinder().get(), instance.c_str()); ALOGE("Cannot register USB Gadget HAL service");
CHECK(status == STATUS_OK); return 1;
}
ALOGV("AIDL USB Gadget HAL about to start");
ABinderProcess_joinThreadPool(); ALOGI("USB gadget HAL Ready.");
return -1; // Should never be reached joinRpcThreadpool();
// Under noraml cases, execution will not reach this line.
ALOGI("USB gadget HAL failed to join thread pool.");
return 1;
} }

View file

@ -44,7 +44,6 @@ cc_binary {
"android.hardware.thermal@2.0", "android.hardware.thermal@2.0",
"android.hardware.usb.gadget@1.0", "android.hardware.usb.gadget@1.0",
"android.hardware.usb-V2-ndk", "android.hardware.usb-V2-ndk",
"android.hardware.usb.gadget-V1-ndk",
"libcutils", "libcutils",
"android.frameworks.stats-V1-ndk", "android.frameworks.stats-V1-ndk",
"pixelatoms-cpp", "pixelatoms-cpp",

View file

@ -39,7 +39,7 @@
#include "Usb.h" #include "Usb.h"
#include <aidl/android/frameworks/stats/IStats.h> #include <aidl/android/frameworks/stats/IStats.h>
#include <pixelusb/UsbGadgetAidlCommon.h> #include <pixelusb/UsbGadgetCommon.h>
#include <pixelstats/StatsHelper.h> #include <pixelstats/StatsHelper.h>
using aidl::android::frameworks::stats::IStats; using aidl::android::frameworks::stats::IStats;