Merge changes If0925a61,I9d6624cb,I7cc7070d,I2c1091aa into udc-dev
* changes: Fix up open bugs from gs201 AIDL migration Add resetCb Migrate IUsbGadget implementation to AIDL usb: limit the current to 1.3A when connect to accessory
This commit is contained in:
commit
7946bd55e7
9 changed files with 260 additions and 157 deletions
|
@ -29,19 +29,21 @@ cc_binary {
|
|||
vintf_fragments: [
|
||||
"android.hardware.usb.gadget-service.xml",
|
||||
],
|
||||
vendor: true,
|
||||
srcs: ["service_gadget.cpp", "UsbGadget.cpp"],
|
||||
cflags: ["-Wall", "-Werror"],
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libhidlbase",
|
||||
"liblog",
|
||||
"libutils",
|
||||
"libhardware",
|
||||
"android.hardware.usb.gadget@1.0",
|
||||
"android.hardware.usb.gadget@1.1",
|
||||
"android.hardware.usb.gadget@1.2",
|
||||
"android.frameworks.stats-V1-ndk",
|
||||
"android.hardware.usb.gadget-V1-ndk",
|
||||
"libcutils",
|
||||
"libbinder_ndk",
|
||||
],
|
||||
static_libs: ["libpixelusb"],
|
||||
static_libs: ["libpixelusb-aidl"],
|
||||
proprietary: true,
|
||||
export_shared_lib_headers: [
|
||||
"android.frameworks.stats-V1-ndk",
|
||||
],
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "android.hardware.usb.gadget@1.2-service.zuma"
|
||||
#define LOG_TAG "android.hardware.usb.gadget.aidl-service"
|
||||
|
||||
#include "UsbGadget.h"
|
||||
#include <dirent.h>
|
||||
|
@ -26,12 +26,19 @@
|
|||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <aidl/android/frameworks/stats/IStats.h>
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace usb {
|
||||
namespace gadget {
|
||||
namespace V1_2 {
|
||||
namespace implementation {
|
||||
|
||||
string enabledPath;
|
||||
constexpr char kHsi2cPath[] = "/sys/devices/platform/10d50000.hsi2c";
|
||||
constexpr char kI2CPath[] = "/sys/devices/platform/10d50000.hsi2c/i2c-";
|
||||
constexpr char kAccessoryLimitCurrent[] = "i2c-max77759tcpc/usb_limit_accessory_current";
|
||||
constexpr char kAccessoryLimitCurrentEnable[] = "i2c-max77759tcpc/usb_limit_accessory_enable";
|
||||
|
||||
UsbGadget::UsbGadget() : mGadgetIrqPath("") {
|
||||
if (access(OS_DESC_PATH, R_OK) != 0) {
|
||||
|
@ -40,7 +47,7 @@ UsbGadget::UsbGadget() : mGadgetIrqPath("") {
|
|||
}
|
||||
}
|
||||
|
||||
V1_0::Status UsbGadget::getUsbGadgetIrqPath() {
|
||||
Status UsbGadget::getUsbGadgetIrqPath() {
|
||||
std::string irqs;
|
||||
size_t read_pos = 0;
|
||||
size_t found_pos = 0;
|
||||
|
@ -87,17 +94,20 @@ void currentFunctionsAppliedCallback(bool functionsApplied, void *payload) {
|
|||
gadget->mCurrentUsbFunctionsApplied = functionsApplied;
|
||||
}
|
||||
|
||||
Return<void> UsbGadget::getCurrentUsbFunctions(const sp<V1_0::IUsbGadgetCallback> &callback) {
|
||||
Return<void> ret = callback->getCurrentUsbFunctionsCb(
|
||||
ScopedAStatus UsbGadget::getCurrentUsbFunctions(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
int64_t in_transactionId) {
|
||||
ScopedAStatus ret = callback->getCurrentUsbFunctionsCb(
|
||||
mCurrentUsbFunctions,
|
||||
mCurrentUsbFunctionsApplied ? Status::FUNCTIONS_APPLIED : Status::FUNCTIONS_NOT_APPLIED);
|
||||
mCurrentUsbFunctionsApplied ? Status::FUNCTIONS_APPLIED : Status::FUNCTIONS_NOT_APPLIED,
|
||||
in_transactionId);
|
||||
if (!ret.isOk())
|
||||
ALOGE("Call to getCurrentUsbFunctionsCb failed %s", ret.description().c_str());
|
||||
ALOGE("Call to getCurrentUsbFunctionsCb failed %s", ret.getDescription().c_str());
|
||||
|
||||
return Void();
|
||||
return ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
Return<void> UsbGadget::getUsbSpeed(const sp<V1_2::IUsbGadgetCallback> &callback) {
|
||||
ScopedAStatus UsbGadget::getUsbSpeed(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
int64_t in_transactionId) {
|
||||
std::string current_speed;
|
||||
if (ReadFileToString(SPEED_PATH, ¤t_speed)) {
|
||||
current_speed = Trim(current_speed);
|
||||
|
@ -115,25 +125,26 @@ Return<void> UsbGadget::getUsbSpeed(const sp<V1_2::IUsbGadgetCallback> &callback
|
|||
else if (current_speed == "UNKNOWN")
|
||||
mUsbSpeed = UsbSpeed::UNKNOWN;
|
||||
else
|
||||
mUsbSpeed = UsbSpeed::RESERVED_SPEED;
|
||||
mUsbSpeed = UsbSpeed::UNKNOWN;
|
||||
} else {
|
||||
ALOGE("Fail to read current speed");
|
||||
mUsbSpeed = UsbSpeed::UNKNOWN;
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
Return<void> ret = callback->getUsbSpeedCb(mUsbSpeed);
|
||||
ScopedAStatus ret = callback->getUsbSpeedCb(mUsbSpeed, in_transactionId);
|
||||
|
||||
if (!ret.isOk())
|
||||
ALOGE("Call to getUsbSpeedCb failed %s", ret.description().c_str());
|
||||
ALOGE("Call to getUsbSpeedCb failed %s", ret.getDescription().c_str());
|
||||
}
|
||||
|
||||
return Void();
|
||||
return ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
V1_0::Status UsbGadget::tearDownGadget() {
|
||||
if (resetGadget() != Status::SUCCESS)
|
||||
Status UsbGadget::tearDownGadget() {
|
||||
if (Status(resetGadget()) != Status::SUCCESS){
|
||||
return Status::ERROR;
|
||||
}
|
||||
|
||||
if (monitorFfs.isMonitorRunning()) {
|
||||
monitorFfs.reset();
|
||||
|
@ -143,137 +154,152 @@ V1_0::Status UsbGadget::tearDownGadget() {
|
|||
return Status::SUCCESS;
|
||||
}
|
||||
|
||||
static V1_0::Status validateAndSetVidPid(uint64_t functions) {
|
||||
V1_0::Status ret = Status::SUCCESS;
|
||||
static Status validateAndSetVidPid(uint64_t functions) {
|
||||
Status ret = Status::SUCCESS;
|
||||
std::string vendorFunctions = getVendorFunctions();
|
||||
|
||||
switch (functions) {
|
||||
case static_cast<uint64_t>(GadgetFunction::MTP):
|
||||
case GadgetFunction::MTP:
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == "")) {
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = Status::CONFIGURATION_NOT_SUPPORTED;
|
||||
} else {
|
||||
ret = setVidPid("0x18d1", "0x4ee1");
|
||||
ret = Status(setVidPid("0x18d1", "0x4ee1"));
|
||||
}
|
||||
break;
|
||||
case GadgetFunction::ADB | GadgetFunction::MTP:
|
||||
case GadgetFunction::ADB |
|
||||
GadgetFunction::MTP:
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == "")) {
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = Status::CONFIGURATION_NOT_SUPPORTED;
|
||||
} else {
|
||||
ret = setVidPid("0x18d1", "0x4ee2");
|
||||
ret = Status(setVidPid("0x18d1", "0x4ee2"));
|
||||
}
|
||||
break;
|
||||
case static_cast<uint64_t>(GadgetFunction::RNDIS):
|
||||
case GadgetFunction::RNDIS:
|
||||
case GadgetFunction::RNDIS |
|
||||
GadgetFunction::NCM:
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == "")) {
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = Status::CONFIGURATION_NOT_SUPPORTED;
|
||||
} else {
|
||||
ret = setVidPid("0x18d1", "0x4ee3");
|
||||
ret = Status(setVidPid("0x18d1", "0x4ee3"));
|
||||
}
|
||||
break;
|
||||
case GadgetFunction::ADB | GadgetFunction::RNDIS:
|
||||
case GadgetFunction::ADB |
|
||||
GadgetFunction::RNDIS:
|
||||
case GadgetFunction::ADB |
|
||||
GadgetFunction::RNDIS |
|
||||
GadgetFunction::NCM:
|
||||
if (vendorFunctions == "dm") {
|
||||
ret = setVidPid("0x04e8", "0x6862");
|
||||
ret = Status(setVidPid("0x04e8", "0x6862"));
|
||||
} else {
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == "")) {
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = Status::CONFIGURATION_NOT_SUPPORTED;
|
||||
} else {
|
||||
ret = setVidPid("0x18d1", "0x4ee4");
|
||||
ret = Status(setVidPid("0x18d1", "0x4ee4"));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case static_cast<uint64_t>(GadgetFunction::PTP):
|
||||
case GadgetFunction::PTP:
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == "")) {
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = Status::CONFIGURATION_NOT_SUPPORTED;
|
||||
} else {
|
||||
ret = setVidPid("0x18d1", "0x4ee5");
|
||||
ret = Status(setVidPid("0x18d1", "0x4ee5"));
|
||||
}
|
||||
break;
|
||||
case GadgetFunction::ADB | GadgetFunction::PTP:
|
||||
case GadgetFunction::ADB |
|
||||
GadgetFunction::PTP:
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == "")) {
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = Status::CONFIGURATION_NOT_SUPPORTED;
|
||||
} else {
|
||||
ret = setVidPid("0x18d1", "0x4ee6");
|
||||
ret = Status(setVidPid("0x18d1", "0x4ee6"));
|
||||
}
|
||||
break;
|
||||
case static_cast<uint64_t>(GadgetFunction::ADB):
|
||||
case GadgetFunction::ADB:
|
||||
if (vendorFunctions == "dm") {
|
||||
ret = setVidPid("0x04e8", "0x6862");
|
||||
ret = Status(setVidPid("0x04e8", "0x6862"));
|
||||
} else if (vendorFunctions == "etr_miu") {
|
||||
ret = setVidPid("0x18d1", "0x4ee2");
|
||||
ret = Status(setVidPid("0x18d1", "0x4ee2"));
|
||||
} else if (vendorFunctions == "uwb_acm"){
|
||||
ret = setVidPid("0x18d1", "0x4ee2");
|
||||
ret = Status(setVidPid("0x18d1", "0x4ee2"));
|
||||
} else {
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == "")) {
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = Status::CONFIGURATION_NOT_SUPPORTED;
|
||||
} else {
|
||||
ret = setVidPid("0x18d1", "0x4ee7");
|
||||
ret = Status(setVidPid("0x18d1", "0x4ee7"));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case static_cast<uint64_t>(GadgetFunction::MIDI):
|
||||
case GadgetFunction::MIDI:
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == "")) {
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = Status::CONFIGURATION_NOT_SUPPORTED;
|
||||
} else {
|
||||
ret = setVidPid("0x18d1", "0x4ee8");
|
||||
ret = Status(setVidPid("0x18d1", "0x4ee8"));
|
||||
}
|
||||
break;
|
||||
case GadgetFunction::ADB | GadgetFunction::MIDI:
|
||||
case GadgetFunction::ADB |
|
||||
GadgetFunction::MIDI:
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == "")) {
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = Status::CONFIGURATION_NOT_SUPPORTED;
|
||||
} else {
|
||||
ret = setVidPid("0x18d1", "0x4ee9");
|
||||
ret = Status(setVidPid("0x18d1", "0x4ee9"));
|
||||
}
|
||||
break;
|
||||
case static_cast<uint64_t>(GadgetFunction::ACCESSORY):
|
||||
case GadgetFunction::ACCESSORY:
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == ""))
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = setVidPid("0x18d1", "0x2d00");
|
||||
ret = Status(setVidPid("0x18d1", "0x2d00"));
|
||||
break;
|
||||
case GadgetFunction::ADB | GadgetFunction::ACCESSORY:
|
||||
case GadgetFunction::ADB |
|
||||
GadgetFunction::ACCESSORY:
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == ""))
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = setVidPid("0x18d1", "0x2d01");
|
||||
ret = Status(setVidPid("0x18d1", "0x2d01"));
|
||||
break;
|
||||
case static_cast<uint64_t>(GadgetFunction::AUDIO_SOURCE):
|
||||
case GadgetFunction::AUDIO_SOURCE:
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == ""))
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = setVidPid("0x18d1", "0x2d02");
|
||||
ret = Status(setVidPid("0x18d1", "0x2d02"));
|
||||
break;
|
||||
case GadgetFunction::ADB | GadgetFunction::AUDIO_SOURCE:
|
||||
case GadgetFunction::ADB |
|
||||
GadgetFunction::AUDIO_SOURCE:
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == ""))
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = setVidPid("0x18d1", "0x2d03");
|
||||
ret = Status(setVidPid("0x18d1", "0x2d03"));
|
||||
break;
|
||||
case GadgetFunction::ACCESSORY | GadgetFunction::AUDIO_SOURCE:
|
||||
case GadgetFunction::ACCESSORY |
|
||||
GadgetFunction::AUDIO_SOURCE:
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == ""))
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = setVidPid("0x18d1", "0x2d04");
|
||||
ret = Status(setVidPid("0x18d1", "0x2d04"));
|
||||
break;
|
||||
case GadgetFunction::ADB | GadgetFunction::ACCESSORY | GadgetFunction::AUDIO_SOURCE:
|
||||
case GadgetFunction::ADB |
|
||||
GadgetFunction::ACCESSORY |
|
||||
GadgetFunction::AUDIO_SOURCE:
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == ""))
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = setVidPid("0x18d1", "0x2d05");
|
||||
ret = Status(setVidPid("0x18d1", "0x2d05"));
|
||||
break;
|
||||
case static_cast<uint64_t>(GadgetFunction::NCM):
|
||||
case GadgetFunction::NCM:
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == ""))
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = setVidPid("0x18d1", "0x4eeb");
|
||||
ret = Status(setVidPid("0x18d1", "0x4eeb"));
|
||||
break;
|
||||
case GadgetFunction::ADB | GadgetFunction::NCM:
|
||||
case GadgetFunction::ADB |
|
||||
GadgetFunction::NCM:
|
||||
if (vendorFunctions == "dm") {
|
||||
ret = setVidPid("0x04e8", "0x6862");
|
||||
ret = Status(setVidPid("0x04e8", "0x6862"));
|
||||
} else {
|
||||
if (!(vendorFunctions == "user" || vendorFunctions == ""))
|
||||
ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
|
||||
ret = setVidPid("0x18d1", "0x4eec");
|
||||
ret = Status(setVidPid("0x18d1", "0x4eec"));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -283,31 +309,40 @@ static V1_0::Status validateAndSetVidPid(uint64_t functions) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
Return<Status> UsbGadget::reset() {
|
||||
ScopedAStatus UsbGadget::reset(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
int64_t in_transactionId) {
|
||||
ALOGI("USB Gadget reset");
|
||||
|
||||
if (!WriteStringToFile("none", PULLUP_PATH)) {
|
||||
ALOGI("Gadget cannot be pulled down");
|
||||
return Status::ERROR;
|
||||
if (callback)
|
||||
callback->resetCb(Status::ERROR, in_transactionId);
|
||||
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||
-1, "Gadget cannot be pulled down");
|
||||
}
|
||||
|
||||
usleep(kDisconnectWaitUs);
|
||||
|
||||
if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) {
|
||||
ALOGI("Gadget cannot be pulled up");
|
||||
return Status::ERROR;
|
||||
if (callback)
|
||||
callback->resetCb(Status::ERROR, in_transactionId);
|
||||
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||
-1, "Gadget cannot be pulled up");
|
||||
}
|
||||
if (callback)
|
||||
callback->resetCb(Status::SUCCESS, in_transactionId);
|
||||
|
||||
return ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
return Status::SUCCESS;
|
||||
}
|
||||
|
||||
V1_0::Status UsbGadget::setupFunctions(uint64_t functions,
|
||||
const sp<V1_0::IUsbGadgetCallback> &callback,
|
||||
uint64_t timeout) {
|
||||
Status UsbGadget::setupFunctions(long functions,
|
||||
const shared_ptr<IUsbGadgetCallback> &callback, uint64_t timeout,
|
||||
int64_t in_transactionId) {
|
||||
bool ffsEnabled = false;
|
||||
int i = 0;
|
||||
|
||||
if (addGenericAndroidFunctions(&monitorFfs, functions, &ffsEnabled, &i) !=
|
||||
if (Status(addGenericAndroidFunctions(&monitorFfs, functions, &ffsEnabled, &i)) !=
|
||||
Status::SUCCESS)
|
||||
return Status::ERROR;
|
||||
|
||||
|
@ -343,7 +378,7 @@ V1_0::Status UsbGadget::setupFunctions(uint64_t functions,
|
|||
|
||||
if ((functions & GadgetFunction::ADB) != 0) {
|
||||
ffsEnabled = true;
|
||||
if (addAdb(&monitorFfs, &i) != Status::SUCCESS)
|
||||
if (Status(addAdb(&monitorFfs, &i)) != Status::SUCCESS)
|
||||
return Status::ERROR;
|
||||
}
|
||||
|
||||
|
@ -358,7 +393,7 @@ V1_0::Status UsbGadget::setupFunctions(uint64_t functions,
|
|||
return Status::ERROR;
|
||||
mCurrentUsbFunctionsApplied = true;
|
||||
if (callback)
|
||||
callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS);
|
||||
callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId);
|
||||
return Status::SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -373,29 +408,62 @@ V1_0::Status UsbGadget::setupFunctions(uint64_t functions,
|
|||
|
||||
if (callback) {
|
||||
bool pullup = monitorFfs.waitForPullUp(timeout);
|
||||
Return<void> ret = callback->setCurrentUsbFunctionsCb(
|
||||
functions, pullup ? Status::SUCCESS : Status::ERROR);
|
||||
if (!ret.isOk())
|
||||
ALOGE("setCurrentUsbFunctionsCb error %s", ret.description().c_str());
|
||||
ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(
|
||||
functions, pullup ? Status::SUCCESS : Status::ERROR, in_transactionId);
|
||||
if (!ret.isOk()) {
|
||||
ALOGE("setCurrentUsbFunctionsCb error %s", ret.getDescription().c_str());
|
||||
return Status::ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return Status::SUCCESS;
|
||||
}
|
||||
|
||||
Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
|
||||
const sp<V1_0::IUsbGadgetCallback> &callback,
|
||||
uint64_t timeout) {
|
||||
Status getI2cBusHelper(string *name) {
|
||||
DIR *dp;
|
||||
|
||||
dp = opendir(kHsi2cPath);
|
||||
if (dp != NULL) {
|
||||
struct dirent *ep;
|
||||
|
||||
while ((ep = readdir(dp))) {
|
||||
if (ep->d_type == DT_DIR) {
|
||||
if (string::npos != string(ep->d_name).find("i2c-")) {
|
||||
std::strtok(ep->d_name, "-");
|
||||
*name = std::strtok(NULL, "-");
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
return Status::SUCCESS;
|
||||
}
|
||||
|
||||
ALOGE("Failed to open %s", kHsi2cPath);
|
||||
return Status::ERROR;
|
||||
}
|
||||
|
||||
ScopedAStatus UsbGadget::setCurrentUsbFunctions(long functions,
|
||||
const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
int64_t timeout,
|
||||
int64_t in_transactionId) {
|
||||
std::unique_lock<std::mutex> lk(mLockSetCurrentFunction);
|
||||
std::string current_usb_power_operation_mode, current_usb_type;
|
||||
std::string usb_limit_sink_enable;
|
||||
|
||||
string accessoryCurrentLimitEnablePath, accessoryCurrentLimitPath, path;
|
||||
|
||||
mCurrentUsbFunctions = functions;
|
||||
mCurrentUsbFunctionsApplied = false;
|
||||
|
||||
getI2cBusHelper(&path);
|
||||
accessoryCurrentLimitPath = kI2CPath + path + "/" + kAccessoryLimitCurrent;
|
||||
accessoryCurrentLimitEnablePath = kI2CPath + path + "/" + kAccessoryLimitCurrentEnable;
|
||||
|
||||
// Get the gadget IRQ number before tearDownGadget()
|
||||
if (mGadgetIrqPath.empty())
|
||||
getUsbGadgetIrqPath();
|
||||
|
||||
// Unlink the gadget and stop the monitor if running.
|
||||
V1_0::Status status = tearDownGadget();
|
||||
Status status = tearDownGadget();
|
||||
if (status != Status::SUCCESS) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -405,13 +473,15 @@ Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
|
|||
// Leave the gadget pulled down to give time for the host to sense disconnect.
|
||||
usleep(kDisconnectWaitUs);
|
||||
|
||||
if (functions == static_cast<uint64_t>(GadgetFunction::NONE)) {
|
||||
if (functions == GadgetFunction::NONE) {
|
||||
if (callback == NULL)
|
||||
return Void();
|
||||
Return<void> ret = callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS);
|
||||
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||
-1, "callback == NULL");
|
||||
ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId);
|
||||
if (!ret.isOk())
|
||||
ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.description().c_str());
|
||||
return Void();
|
||||
ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.getDescription().c_str());
|
||||
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||
-1, "Error while calling setCurrentUsbFunctionsCb");
|
||||
}
|
||||
|
||||
status = validateAndSetVidPid(functions);
|
||||
|
@ -420,7 +490,7 @@ Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
|
|||
goto error;
|
||||
}
|
||||
|
||||
status = setupFunctions(functions, callback, timeout);
|
||||
status = setupFunctions(functions, callback, timeout, in_transactionId);
|
||||
if (status != Status::SUCCESS) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -437,21 +507,44 @@ Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
|
|||
}
|
||||
}
|
||||
|
||||
if (ReadFileToString(CURRENT_USB_TYPE_PATH, ¤t_usb_type))
|
||||
current_usb_type = Trim(current_usb_type);
|
||||
|
||||
if (ReadFileToString(CURRENT_USB_POWER_OPERATION_MODE_PATH, ¤t_usb_power_operation_mode))
|
||||
current_usb_power_operation_mode = Trim(current_usb_power_operation_mode);
|
||||
|
||||
if (functions & GadgetFunction::ACCESSORY &&
|
||||
current_usb_type == "Unknown SDP [CDP] DCP" &&
|
||||
(current_usb_power_operation_mode == "default" ||
|
||||
current_usb_power_operation_mode == "1.5A")) {
|
||||
if (!WriteStringToFile("1300000", accessoryCurrentLimitPath)) {
|
||||
ALOGI("Write 1.3A to limit current fail");
|
||||
} else {
|
||||
if (!WriteStringToFile("1", accessoryCurrentLimitEnablePath)) {
|
||||
ALOGI("Enable limit current fail");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!WriteStringToFile("0", accessoryCurrentLimitEnablePath))
|
||||
ALOGI("unvote accessory limit current failed");
|
||||
}
|
||||
|
||||
ALOGI("Usb Gadget setcurrent functions called successfully");
|
||||
return Void();
|
||||
return ScopedAStatus::ok();
|
||||
|
||||
error:
|
||||
ALOGI("Usb Gadget setcurrent functions failed");
|
||||
if (callback == NULL)
|
||||
return Void();
|
||||
Return<void> ret = callback->setCurrentUsbFunctionsCb(functions, status);
|
||||
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||
-1, "Usb Gadget setcurrent functions failed");
|
||||
ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions, status, in_transactionId);
|
||||
if (!ret.isOk())
|
||||
ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.description().c_str());
|
||||
return Void();
|
||||
ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.getDescription().c_str());
|
||||
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||
-1, "Error while calling setCurrentUsbFunctionsCb");
|
||||
}
|
||||
} // namespace implementation
|
||||
} // namespace V1_2
|
||||
} // namespace gadget
|
||||
} // namespace usb
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // aidl
|
||||
|
|
|
@ -21,11 +21,13 @@
|
|||
#include <android-base/unique_fd.h>
|
||||
#include <android-base/parseint.h>
|
||||
#include <android-base/strings.h>
|
||||
#include <android/hardware/usb/gadget/1.2/IUsbGadget.h>
|
||||
#include <android/hardware/usb/gadget/1.2/types.h>
|
||||
#include <hidl/MQDescriptor.h>
|
||||
#include <hidl/Status.h>
|
||||
#include <pixelusb/UsbGadgetCommon.h>
|
||||
#include <aidl/android/hardware/usb/gadget/BnUsbGadget.h>
|
||||
#include <aidl/android/hardware/usb/gadget/BnUsbGadgetCallback.h>
|
||||
#include <aidl/android/hardware/usb/gadget/GadgetFunction.h>
|
||||
#include <aidl/android/hardware/usb/gadget/IUsbGadget.h>
|
||||
#include <aidl/android/hardware/usb/gadget/IUsbGadgetCallback.h>
|
||||
#include <pixelusb/UsbGadgetAidlCommon.h>
|
||||
#include <sched.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <utils/Log.h>
|
||||
|
@ -35,14 +37,17 @@
|
|||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace usb {
|
||||
namespace gadget {
|
||||
namespace V1_2 {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::sp;
|
||||
using ::aidl::android::hardware::usb::gadget::GadgetFunction;
|
||||
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::SetProperty;
|
||||
using ::android::base::ParseUint;
|
||||
|
@ -50,12 +55,6 @@ using ::android::base::unique_fd;
|
|||
using ::android::base::ReadFileToString;
|
||||
using ::android::base::Trim;
|
||||
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::addEpollFd;
|
||||
using ::android::hardware::google::pixel::usb::getVendorFunctions;
|
||||
|
@ -66,10 +65,8 @@ using ::android::hardware::google::pixel::usb::MonitorFfs;
|
|||
using ::android::hardware::google::pixel::usb::resetGadget;
|
||||
using ::android::hardware::google::pixel::usb::setVidPid;
|
||||
using ::android::hardware::google::pixel::usb::unlinkFunctions;
|
||||
using ::android::hardware::usb::gadget::V1_0::Status;
|
||||
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 ::ndk::ScopedAStatus;
|
||||
using ::std::shared_ptr;
|
||||
using ::std::string;
|
||||
|
||||
constexpr char kGadgetName[] = "11210000.dwc3";
|
||||
|
@ -86,36 +83,47 @@ static MonitorFfs monitorFfs(kGadgetName);
|
|||
#define BIG_CORE "8"
|
||||
#define MEDIUM_CORE "4"
|
||||
|
||||
struct UsbGadget : public IUsbGadget {
|
||||
#define POWER_SUPPLY_PATH "/sys/class/power_supply/usb/"
|
||||
#define USB_PORT0_PATH "/sys/class/typec/port0/"
|
||||
|
||||
#define CURRENT_MAX_PATH POWER_SUPPLY_PATH "current_max"
|
||||
#define CURRENT_USB_TYPE_PATH POWER_SUPPLY_PATH "usb_type"
|
||||
#define CURRENT_USB_POWER_OPERATION_MODE_PATH USB_PORT0_PATH "power_operation_mode"
|
||||
|
||||
struct UsbGadget : public BnUsbGadget {
|
||||
UsbGadget();
|
||||
|
||||
// Makes sure that only one request is processed at a time.
|
||||
std::mutex mLockSetCurrentFunction;
|
||||
std::string mGadgetIrqPath;
|
||||
uint64_t mCurrentUsbFunctions;
|
||||
long mCurrentUsbFunctions;
|
||||
bool mCurrentUsbFunctionsApplied;
|
||||
UsbSpeed mUsbSpeed;
|
||||
|
||||
Return<void> setCurrentUsbFunctions(uint64_t functions,
|
||||
const sp<V1_0::IUsbGadgetCallback> &callback,
|
||||
uint64_t timeout) override;
|
||||
ScopedAStatus setCurrentUsbFunctions(long functions,
|
||||
const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
int64_t timeout, int64_t in_transactionId) override;
|
||||
|
||||
Return<void> getCurrentUsbFunctions(const sp<V1_0::IUsbGadgetCallback> &callback) override;
|
||||
ScopedAStatus getCurrentUsbFunctions(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
int64_t in_transactionId) override;
|
||||
|
||||
Return<Status> reset() override;
|
||||
ScopedAStatus reset(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
int64_t in_transactionId) override;
|
||||
|
||||
Return<void> getUsbSpeed(const sp<V1_2::IUsbGadgetCallback> &callback) override;
|
||||
ScopedAStatus getUsbSpeed(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
int64_t in_transactionId) override;
|
||||
|
||||
ScopedAStatus setVidPid(const char *vid,const char *pid);
|
||||
|
||||
private:
|
||||
Status tearDownGadget();
|
||||
Status getUsbGadgetIrqPath();
|
||||
Status setupFunctions(uint64_t functions, const sp<V1_0::IUsbGadgetCallback> &callback,
|
||||
uint64_t timeout);
|
||||
Status setupFunctions(long functions, const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
uint64_t timeout, int64_t in_transactionId);
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_2
|
||||
} // namespace gadget
|
||||
} // namespace usb
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // aidl
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
service vendor.usb-gadget-hal-1-2 /vendor/bin/hw/android.hardware.usb.gadget-service
|
||||
service vendor.usb-gadget-hal /vendor/bin/hw/android.hardware.usb.gadget-service
|
||||
class hal
|
||||
user system
|
||||
group system shell mtp
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
<manifest version="1.0" type="device">
|
||||
<hal format="hidl">
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.usb.gadget</name>
|
||||
<transport>hwbinder</transport>
|
||||
<version>1.2</version>
|
||||
<version>1</version>
|
||||
<interface>
|
||||
<name>IUsbGadget</name>
|
||||
<instance>default</instance>
|
||||
|
|
|
@ -16,35 +16,27 @@
|
|||
|
||||
#define LOG_TAG "android.hardware.usb.gadget-service"
|
||||
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <android/binder_manager.h>
|
||||
#include <android/binder_process.h>
|
||||
#include <utils/Log.h>
|
||||
#include "UsbGadget.h"
|
||||
|
||||
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::sp;
|
||||
using android::status_t;
|
||||
|
||||
using aidl::android::hardware::usb::gadget::UsbGadget;
|
||||
|
||||
int main() {
|
||||
android::sp<IUsbGadget> service = new UsbGadget();
|
||||
configureRpcThreadpool(2, true /*callerWillJoin*/);
|
||||
status_t status = service->registerAsService();
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
std::shared_ptr<UsbGadget> usbgadget = ndk::SharedRefBase::make<UsbGadget>();
|
||||
|
||||
if (status != OK) {
|
||||
ALOGE("Cannot register USB Gadget HAL service");
|
||||
return 1;
|
||||
}
|
||||
const std::string instance = std::string() + UsbGadget::descriptor + "/default";
|
||||
binder_status_t status = AServiceManager_addService(usbgadget->asBinder().get(), instance.c_str());
|
||||
CHECK(status == STATUS_OK);
|
||||
|
||||
ALOGI("USB gadget HAL Ready.");
|
||||
joinRpcThreadpool();
|
||||
// Under noraml cases, execution will not reach this line.
|
||||
ALOGI("USB gadget HAL failed to join thread pool.");
|
||||
return 1;
|
||||
ALOGV("AIDL USB Gadget HAL about to start");
|
||||
ABinderProcess_joinThreadPool();
|
||||
return -1; // Should never be reached
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ cc_binary {
|
|||
"android.hardware.thermal-V1-ndk",
|
||||
"android.hardware.usb.gadget@1.0",
|
||||
"android.hardware.usb-V1-ndk",
|
||||
"android.hardware.usb.gadget-V1-ndk",
|
||||
"libcutils",
|
||||
"android.frameworks.stats-V1-ndk",
|
||||
"pixelatoms-cpp",
|
||||
|
@ -54,7 +55,7 @@ cc_binary {
|
|||
|
||||
],
|
||||
static_libs: [
|
||||
"libpixelusb",
|
||||
"libpixelusb-aidl",
|
||||
"libpixelstats",
|
||||
"libthermalutils",
|
||||
],
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
#include "Usb.h"
|
||||
|
||||
#include <aidl/android/frameworks/stats/IStats.h>
|
||||
#include <pixelusb/UsbGadgetCommon.h>
|
||||
#include <pixelusb/UsbGadgetAidlCommon.h>
|
||||
#include <pixelstats/StatsHelper.h>
|
||||
|
||||
using aidl::android::frameworks::stats::IStats;
|
||||
|
|
|
@ -10,6 +10,10 @@ on post-fs
|
|||
chown root system /sys/class/typec/port0/port_type
|
||||
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/contaminant_detection
|
||||
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/contaminant_detection
|
||||
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_accessory_current
|
||||
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/usb_limit_accessory_current
|
||||
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_accessory_enable
|
||||
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/usb_limit_accessory_enable
|
||||
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_sink_current
|
||||
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/usb_limit_sink_current
|
||||
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_sink_enable
|
||||
|
@ -28,6 +32,10 @@ on post-fs
|
|||
chmod 664 /sys/devices/platform/11110000.usb/usb_data_enabled
|
||||
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/contaminant_detection
|
||||
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/contaminant_detection
|
||||
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_accessory_current
|
||||
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/usb_limit_accessory_current
|
||||
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_accessory_enable
|
||||
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/usb_limit_accessory_enable
|
||||
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_sink_current
|
||||
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/usb_limit_sink_current
|
||||
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_sink_enable
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue