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: [
|
vintf_fragments: [
|
||||||
"android.hardware.usb.gadget-service.xml",
|
"android.hardware.usb.gadget-service.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: [
|
||||||
"libbase",
|
"libbase",
|
||||||
"libhidlbase",
|
|
||||||
"liblog",
|
"liblog",
|
||||||
"libutils",
|
"libutils",
|
||||||
"libhardware",
|
"android.frameworks.stats-V1-ndk",
|
||||||
"android.hardware.usb.gadget@1.0",
|
"android.hardware.usb.gadget-V1-ndk",
|
||||||
"android.hardware.usb.gadget@1.1",
|
|
||||||
"android.hardware.usb.gadget@1.2",
|
|
||||||
"libcutils",
|
"libcutils",
|
||||||
|
"libbinder_ndk",
|
||||||
],
|
],
|
||||||
static_libs: ["libpixelusb"],
|
static_libs: ["libpixelusb-aidl"],
|
||||||
proprietary: true,
|
proprietary: true,
|
||||||
|
export_shared_lib_headers: [
|
||||||
|
"android.frameworks.stats-V1-ndk",
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* 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 "UsbGadget.h"
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
@ -26,12 +26,19 @@
|
||||||
#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;
|
||||||
|
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("") {
|
UsbGadget::UsbGadget() : mGadgetIrqPath("") {
|
||||||
if (access(OS_DESC_PATH, R_OK) != 0) {
|
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;
|
std::string irqs;
|
||||||
size_t read_pos = 0;
|
size_t read_pos = 0;
|
||||||
size_t found_pos = 0;
|
size_t found_pos = 0;
|
||||||
|
@ -87,17 +94,20 @@ void currentFunctionsAppliedCallback(bool functionsApplied, void *payload) {
|
||||||
gadget->mCurrentUsbFunctionsApplied = functionsApplied;
|
gadget->mCurrentUsbFunctionsApplied = functionsApplied;
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> UsbGadget::getCurrentUsbFunctions(const sp<V1_0::IUsbGadgetCallback> &callback) {
|
ScopedAStatus UsbGadget::getCurrentUsbFunctions(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||||
Return<void> ret = callback->getCurrentUsbFunctionsCb(
|
int64_t in_transactionId) {
|
||||||
|
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.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;
|
std::string current_speed;
|
||||||
if (ReadFileToString(SPEED_PATH, ¤t_speed)) {
|
if (ReadFileToString(SPEED_PATH, ¤t_speed)) {
|
||||||
current_speed = Trim(current_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")
|
else if (current_speed == "UNKNOWN")
|
||||||
mUsbSpeed = UsbSpeed::UNKNOWN;
|
mUsbSpeed = UsbSpeed::UNKNOWN;
|
||||||
else
|
else
|
||||||
mUsbSpeed = UsbSpeed::RESERVED_SPEED;
|
mUsbSpeed = UsbSpeed::UNKNOWN;
|
||||||
} else {
|
} else {
|
||||||
ALOGE("Fail to read current speed");
|
ALOGE("Fail to read current speed");
|
||||||
mUsbSpeed = UsbSpeed::UNKNOWN;
|
mUsbSpeed = UsbSpeed::UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
Return<void> ret = callback->getUsbSpeedCb(mUsbSpeed);
|
ScopedAStatus ret = callback->getUsbSpeedCb(mUsbSpeed, in_transactionId);
|
||||||
|
|
||||||
if (!ret.isOk())
|
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() {
|
Status UsbGadget::tearDownGadget() {
|
||||||
if (resetGadget() != Status::SUCCESS)
|
if (Status(resetGadget()) != Status::SUCCESS){
|
||||||
return Status::ERROR;
|
return Status::ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
if (monitorFfs.isMonitorRunning()) {
|
if (monitorFfs.isMonitorRunning()) {
|
||||||
monitorFfs.reset();
|
monitorFfs.reset();
|
||||||
|
@ -143,137 +154,152 @@ V1_0::Status UsbGadget::tearDownGadget() {
|
||||||
return Status::SUCCESS;
|
return Status::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static V1_0::Status validateAndSetVidPid(uint64_t functions) {
|
static Status validateAndSetVidPid(uint64_t functions) {
|
||||||
V1_0::Status ret = Status::SUCCESS;
|
Status ret = Status::SUCCESS;
|
||||||
std::string vendorFunctions = getVendorFunctions();
|
std::string vendorFunctions = getVendorFunctions();
|
||||||
|
|
||||||
switch (functions) {
|
switch (functions) {
|
||||||
case static_cast<uint64_t>(GadgetFunction::MTP):
|
case 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 = setVidPid("0x18d1", "0x4ee1");
|
ret = Status(setVidPid("0x18d1", "0x4ee1"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GadgetFunction::ADB | GadgetFunction::MTP:
|
case GadgetFunction::ADB |
|
||||||
|
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 = setVidPid("0x18d1", "0x4ee2");
|
ret = Status(setVidPid("0x18d1", "0x4ee2"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case static_cast<uint64_t>(GadgetFunction::RNDIS):
|
case GadgetFunction::RNDIS:
|
||||||
|
case GadgetFunction::RNDIS |
|
||||||
|
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 = setVidPid("0x18d1", "0x4ee3");
|
ret = Status(setVidPid("0x18d1", "0x4ee3"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GadgetFunction::ADB | GadgetFunction::RNDIS:
|
case GadgetFunction::ADB |
|
||||||
|
GadgetFunction::RNDIS:
|
||||||
|
case GadgetFunction::ADB |
|
||||||
|
GadgetFunction::RNDIS |
|
||||||
|
GadgetFunction::NCM:
|
||||||
if (vendorFunctions == "dm") {
|
if (vendorFunctions == "dm") {
|
||||||
ret = setVidPid("0x04e8", "0x6862");
|
ret = Status(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 = setVidPid("0x18d1", "0x4ee4");
|
ret = Status(setVidPid("0x18d1", "0x4ee4"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case static_cast<uint64_t>(GadgetFunction::PTP):
|
case 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 = setVidPid("0x18d1", "0x4ee5");
|
ret = Status(setVidPid("0x18d1", "0x4ee5"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GadgetFunction::ADB | GadgetFunction::PTP:
|
case GadgetFunction::ADB |
|
||||||
|
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 = setVidPid("0x18d1", "0x4ee6");
|
ret = Status(setVidPid("0x18d1", "0x4ee6"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case static_cast<uint64_t>(GadgetFunction::ADB):
|
case GadgetFunction::ADB:
|
||||||
if (vendorFunctions == "dm") {
|
if (vendorFunctions == "dm") {
|
||||||
ret = setVidPid("0x04e8", "0x6862");
|
ret = Status(setVidPid("0x04e8", "0x6862"));
|
||||||
} else if (vendorFunctions == "etr_miu") {
|
} else if (vendorFunctions == "etr_miu") {
|
||||||
ret = setVidPid("0x18d1", "0x4ee2");
|
ret = Status(setVidPid("0x18d1", "0x4ee2"));
|
||||||
} else if (vendorFunctions == "uwb_acm") {
|
} else if (vendorFunctions == "uwb_acm"){
|
||||||
ret = setVidPid("0x18d1", "0x4ee2");
|
ret = Status(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 = setVidPid("0x18d1", "0x4ee7");
|
ret = Status(setVidPid("0x18d1", "0x4ee7"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case static_cast<uint64_t>(GadgetFunction::MIDI):
|
case 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 = setVidPid("0x18d1", "0x4ee8");
|
ret = Status(setVidPid("0x18d1", "0x4ee8"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GadgetFunction::ADB | GadgetFunction::MIDI:
|
case GadgetFunction::ADB |
|
||||||
|
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 = setVidPid("0x18d1", "0x4ee9");
|
ret = Status(setVidPid("0x18d1", "0x4ee9"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case static_cast<uint64_t>(GadgetFunction::ACCESSORY):
|
case 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 = setVidPid("0x18d1", "0x2d00");
|
ret = Status(setVidPid("0x18d1", "0x2d00"));
|
||||||
break;
|
break;
|
||||||
case GadgetFunction::ADB | GadgetFunction::ACCESSORY:
|
case GadgetFunction::ADB |
|
||||||
|
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 = setVidPid("0x18d1", "0x2d01");
|
ret = Status(setVidPid("0x18d1", "0x2d01"));
|
||||||
break;
|
break;
|
||||||
case static_cast<uint64_t>(GadgetFunction::AUDIO_SOURCE):
|
case 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 = setVidPid("0x18d1", "0x2d02");
|
ret = Status(setVidPid("0x18d1", "0x2d02"));
|
||||||
break;
|
break;
|
||||||
case GadgetFunction::ADB | GadgetFunction::AUDIO_SOURCE:
|
case GadgetFunction::ADB |
|
||||||
|
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 = setVidPid("0x18d1", "0x2d03");
|
ret = Status(setVidPid("0x18d1", "0x2d03"));
|
||||||
break;
|
break;
|
||||||
case GadgetFunction::ACCESSORY | GadgetFunction::AUDIO_SOURCE:
|
case 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 = setVidPid("0x18d1", "0x2d04");
|
ret = Status(setVidPid("0x18d1", "0x2d04"));
|
||||||
break;
|
break;
|
||||||
case GadgetFunction::ADB | GadgetFunction::ACCESSORY | GadgetFunction::AUDIO_SOURCE:
|
case GadgetFunction::ADB |
|
||||||
|
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 = setVidPid("0x18d1", "0x2d05");
|
ret = Status(setVidPid("0x18d1", "0x2d05"));
|
||||||
break;
|
break;
|
||||||
case static_cast<uint64_t>(GadgetFunction::NCM):
|
case 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 = setVidPid("0x18d1", "0x4eeb");
|
ret = Status(setVidPid("0x18d1", "0x4eeb"));
|
||||||
break;
|
break;
|
||||||
case GadgetFunction::ADB | GadgetFunction::NCM:
|
case GadgetFunction::ADB |
|
||||||
|
GadgetFunction::NCM:
|
||||||
if (vendorFunctions == "dm") {
|
if (vendorFunctions == "dm") {
|
||||||
ret = setVidPid("0x04e8", "0x6862");
|
ret = Status(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 = setVidPid("0x18d1", "0x4eec");
|
ret = Status(setVidPid("0x18d1", "0x4eec"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -283,31 +309,40 @@ static V1_0::Status validateAndSetVidPid(uint64_t functions) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Status> UsbGadget::reset() {
|
ScopedAStatus UsbGadget::reset(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||||
|
int64_t in_transactionId) {
|
||||||
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 Status::ERROR;
|
if (callback)
|
||||||
|
callback->resetCb(Status::ERROR, in_transactionId);
|
||||||
|
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||||
|
-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 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 Status::SUCCESS;
|
return ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
V1_0::Status UsbGadget::setupFunctions(uint64_t functions,
|
Status UsbGadget::setupFunctions(long functions,
|
||||||
const sp<V1_0::IUsbGadgetCallback> &callback,
|
const shared_ptr<IUsbGadgetCallback> &callback, uint64_t timeout,
|
||||||
uint64_t timeout) {
|
int64_t in_transactionId) {
|
||||||
bool ffsEnabled = false;
|
bool ffsEnabled = false;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (addGenericAndroidFunctions(&monitorFfs, functions, &ffsEnabled, &i) !=
|
if (Status(addGenericAndroidFunctions(&monitorFfs, functions, &ffsEnabled, &i)) !=
|
||||||
Status::SUCCESS)
|
Status::SUCCESS)
|
||||||
return Status::ERROR;
|
return Status::ERROR;
|
||||||
|
|
||||||
|
@ -343,7 +378,7 @@ V1_0::Status UsbGadget::setupFunctions(uint64_t functions,
|
||||||
|
|
||||||
if ((functions & GadgetFunction::ADB) != 0) {
|
if ((functions & GadgetFunction::ADB) != 0) {
|
||||||
ffsEnabled = true;
|
ffsEnabled = true;
|
||||||
if (addAdb(&monitorFfs, &i) != Status::SUCCESS)
|
if (Status(addAdb(&monitorFfs, &i)) != Status::SUCCESS)
|
||||||
return Status::ERROR;
|
return Status::ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,7 +393,7 @@ V1_0::Status UsbGadget::setupFunctions(uint64_t functions,
|
||||||
return Status::ERROR;
|
return Status::ERROR;
|
||||||
mCurrentUsbFunctionsApplied = true;
|
mCurrentUsbFunctionsApplied = true;
|
||||||
if (callback)
|
if (callback)
|
||||||
callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS);
|
callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId);
|
||||||
return Status::SUCCESS;
|
return Status::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,29 +408,62 @@ V1_0::Status UsbGadget::setupFunctions(uint64_t functions,
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
bool pullup = monitorFfs.waitForPullUp(timeout);
|
bool pullup = monitorFfs.waitForPullUp(timeout);
|
||||||
Return<void> ret = callback->setCurrentUsbFunctionsCb(
|
ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(
|
||||||
functions, pullup ? Status::SUCCESS : Status::ERROR);
|
functions, pullup ? Status::SUCCESS : Status::ERROR, in_transactionId);
|
||||||
if (!ret.isOk())
|
if (!ret.isOk()) {
|
||||||
ALOGE("setCurrentUsbFunctionsCb error %s", ret.description().c_str());
|
ALOGE("setCurrentUsbFunctionsCb error %s", ret.getDescription().c_str());
|
||||||
|
return Status::ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Status::SUCCESS;
|
return Status::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
|
Status getI2cBusHelper(string *name) {
|
||||||
const sp<V1_0::IUsbGadgetCallback> &callback,
|
DIR *dp;
|
||||||
uint64_t timeout) {
|
|
||||||
|
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::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;
|
mCurrentUsbFunctions = functions;
|
||||||
mCurrentUsbFunctionsApplied = false;
|
mCurrentUsbFunctionsApplied = false;
|
||||||
|
|
||||||
|
getI2cBusHelper(&path);
|
||||||
|
accessoryCurrentLimitPath = kI2CPath + path + "/" + kAccessoryLimitCurrent;
|
||||||
|
accessoryCurrentLimitEnablePath = kI2CPath + path + "/" + kAccessoryLimitCurrentEnable;
|
||||||
|
|
||||||
// Get the gadget IRQ number before tearDownGadget()
|
// Get the gadget IRQ number before tearDownGadget()
|
||||||
if (mGadgetIrqPath.empty())
|
if (mGadgetIrqPath.empty())
|
||||||
getUsbGadgetIrqPath();
|
getUsbGadgetIrqPath();
|
||||||
|
|
||||||
// Unlink the gadget and stop the monitor if running.
|
// Unlink the gadget and stop the monitor if running.
|
||||||
V1_0::Status status = tearDownGadget();
|
Status status = tearDownGadget();
|
||||||
if (status != Status::SUCCESS) {
|
if (status != Status::SUCCESS) {
|
||||||
goto error;
|
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.
|
// Leave the gadget pulled down to give time for the host to sense disconnect.
|
||||||
usleep(kDisconnectWaitUs);
|
usleep(kDisconnectWaitUs);
|
||||||
|
|
||||||
if (functions == static_cast<uint64_t>(GadgetFunction::NONE)) {
|
if (functions == GadgetFunction::NONE) {
|
||||||
if (callback == NULL)
|
if (callback == NULL)
|
||||||
return Void();
|
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||||
Return<void> ret = callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS);
|
-1, "callback == NULL");
|
||||||
|
ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId);
|
||||||
if (!ret.isOk())
|
if (!ret.isOk())
|
||||||
ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.description().c_str());
|
ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.getDescription().c_str());
|
||||||
return Void();
|
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||||
|
-1, "Error while calling setCurrentUsbFunctionsCb");
|
||||||
}
|
}
|
||||||
|
|
||||||
status = validateAndSetVidPid(functions);
|
status = validateAndSetVidPid(functions);
|
||||||
|
@ -420,7 +490,7 @@ Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = setupFunctions(functions, callback, timeout);
|
status = setupFunctions(functions, callback, timeout, in_transactionId);
|
||||||
if (status != Status::SUCCESS) {
|
if (status != Status::SUCCESS) {
|
||||||
goto error;
|
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");
|
ALOGI("Usb Gadget setcurrent functions called successfully");
|
||||||
return Void();
|
return ScopedAStatus::ok();
|
||||||
|
|
||||||
error:
|
error:
|
||||||
ALOGI("Usb Gadget setcurrent functions failed");
|
ALOGI("Usb Gadget setcurrent functions failed");
|
||||||
if (callback == NULL)
|
if (callback == NULL)
|
||||||
return Void();
|
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||||
Return<void> ret = callback->setCurrentUsbFunctionsCb(functions, status);
|
-1, "Usb Gadget setcurrent functions failed");
|
||||||
|
ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions, status, in_transactionId);
|
||||||
if (!ret.isOk())
|
if (!ret.isOk())
|
||||||
ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.description().c_str());
|
ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.getDescription().c_str());
|
||||||
return Void();
|
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||||
|
-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
|
||||||
|
|
|
@ -21,11 +21,13 @@
|
||||||
#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 <android/hardware/usb/gadget/1.2/IUsbGadget.h>
|
#include <aidl/android/hardware/usb/gadget/BnUsbGadget.h>
|
||||||
#include <android/hardware/usb/gadget/1.2/types.h>
|
#include <aidl/android/hardware/usb/gadget/BnUsbGadgetCallback.h>
|
||||||
#include <hidl/MQDescriptor.h>
|
#include <aidl/android/hardware/usb/gadget/GadgetFunction.h>
|
||||||
#include <hidl/Status.h>
|
#include <aidl/android/hardware/usb/gadget/IUsbGadget.h>
|
||||||
#include <pixelusb/UsbGadgetCommon.h>
|
#include <aidl/android/hardware/usb/gadget/IUsbGadgetCallback.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>
|
||||||
|
@ -35,14 +37,17 @@
|
||||||
#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 ::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::GetProperty;
|
||||||
using ::android::base::SetProperty;
|
using ::android::base::SetProperty;
|
||||||
using ::android::base::ParseUint;
|
using ::android::base::ParseUint;
|
||||||
|
@ -50,12 +55,6 @@ 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;
|
||||||
|
@ -66,10 +65,8 @@ 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 ::android::hardware::usb::gadget::V1_0::Status;
|
using ::ndk::ScopedAStatus;
|
||||||
using ::android::hardware::usb::gadget::V1_0::IUsbGadgetCallback;
|
using ::std::shared_ptr;
|
||||||
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[] = "11210000.dwc3";
|
constexpr char kGadgetName[] = "11210000.dwc3";
|
||||||
|
@ -86,36 +83,47 @@ static MonitorFfs monitorFfs(kGadgetName);
|
||||||
#define BIG_CORE "8"
|
#define BIG_CORE "8"
|
||||||
#define MEDIUM_CORE "4"
|
#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();
|
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;
|
||||||
uint64_t mCurrentUsbFunctions;
|
long mCurrentUsbFunctions;
|
||||||
bool mCurrentUsbFunctionsApplied;
|
bool mCurrentUsbFunctionsApplied;
|
||||||
UsbSpeed mUsbSpeed;
|
UsbSpeed mUsbSpeed;
|
||||||
|
|
||||||
Return<void> setCurrentUsbFunctions(uint64_t functions,
|
ScopedAStatus setCurrentUsbFunctions(long functions,
|
||||||
const sp<V1_0::IUsbGadgetCallback> &callback,
|
const shared_ptr<IUsbGadgetCallback> &callback,
|
||||||
uint64_t timeout) override;
|
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:
|
private:
|
||||||
Status tearDownGadget();
|
Status tearDownGadget();
|
||||||
Status getUsbGadgetIrqPath();
|
Status getUsbGadgetIrqPath();
|
||||||
Status setupFunctions(uint64_t functions, const sp<V1_0::IUsbGadgetCallback> &callback,
|
Status setupFunctions(long functions, const shared_ptr<IUsbGadgetCallback> &callback,
|
||||||
uint64_t timeout);
|
uint64_t timeout, int64_t in_transactionId);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace implementation
|
|
||||||
} // namespace V1_2
|
|
||||||
} // namespace gadget
|
} // namespace gadget
|
||||||
} // namespace usb
|
} // namespace usb
|
||||||
} // namespace hardware
|
} // namespace hardware
|
||||||
} // namespace android
|
} // 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
|
class hal
|
||||||
user system
|
user system
|
||||||
group system shell mtp
|
group system shell mtp
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
<manifest version="1.0" type="device">
|
<manifest version="1.0" type="device">
|
||||||
<hal format="hidl">
|
<hal format="aidl">
|
||||||
<name>android.hardware.usb.gadget</name>
|
<name>android.hardware.usb.gadget</name>
|
||||||
<transport>hwbinder</transport>
|
<version>1</version>
|
||||||
<version>1.2</version>
|
|
||||||
<interface>
|
<interface>
|
||||||
<name>IUsbGadget</name>
|
<name>IUsbGadget</name>
|
||||||
<instance>default</instance>
|
<instance>default</instance>
|
||||||
|
|
|
@ -16,35 +16,27 @@
|
||||||
|
|
||||||
#define LOG_TAG "android.hardware.usb.gadget-service"
|
#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"
|
#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::OK;
|
||||||
|
using android::sp;
|
||||||
using android::status_t;
|
using android::status_t;
|
||||||
|
|
||||||
|
using aidl::android::hardware::usb::gadget::UsbGadget;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
android::sp<IUsbGadget> service = new UsbGadget();
|
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||||
configureRpcThreadpool(2, true /*callerWillJoin*/);
|
std::shared_ptr<UsbGadget> usbgadget = ndk::SharedRefBase::make<UsbGadget>();
|
||||||
status_t status = service->registerAsService();
|
|
||||||
|
|
||||||
if (status != OK) {
|
const std::string instance = std::string() + UsbGadget::descriptor + "/default";
|
||||||
ALOGE("Cannot register USB Gadget HAL service");
|
binder_status_t status = AServiceManager_addService(usbgadget->asBinder().get(), instance.c_str());
|
||||||
return 1;
|
CHECK(status == STATUS_OK);
|
||||||
}
|
|
||||||
|
|
||||||
ALOGI("USB gadget HAL Ready.");
|
ALOGV("AIDL USB Gadget HAL about to start");
|
||||||
joinRpcThreadpool();
|
ABinderProcess_joinThreadPool();
|
||||||
// Under noraml cases, execution will not reach this line.
|
return -1; // Should never be reached
|
||||||
ALOGI("USB gadget HAL failed to join thread pool.");
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ cc_binary {
|
||||||
"android.hardware.thermal-V1-ndk",
|
"android.hardware.thermal-V1-ndk",
|
||||||
"android.hardware.usb.gadget@1.0",
|
"android.hardware.usb.gadget@1.0",
|
||||||
"android.hardware.usb-V1-ndk",
|
"android.hardware.usb-V1-ndk",
|
||||||
|
"android.hardware.usb.gadget-V1-ndk",
|
||||||
"libcutils",
|
"libcutils",
|
||||||
"android.frameworks.stats-V1-ndk",
|
"android.frameworks.stats-V1-ndk",
|
||||||
"pixelatoms-cpp",
|
"pixelatoms-cpp",
|
||||||
|
@ -54,7 +55,7 @@ cc_binary {
|
||||||
|
|
||||||
],
|
],
|
||||||
static_libs: [
|
static_libs: [
|
||||||
"libpixelusb",
|
"libpixelusb-aidl",
|
||||||
"libpixelstats",
|
"libpixelstats",
|
||||||
"libthermalutils",
|
"libthermalutils",
|
||||||
],
|
],
|
||||||
|
|
|
@ -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/UsbGadgetCommon.h>
|
#include <pixelusb/UsbGadgetAidlCommon.h>
|
||||||
#include <pixelstats/StatsHelper.h>
|
#include <pixelstats/StatsHelper.h>
|
||||||
|
|
||||||
using aidl::android::frameworks::stats::IStats;
|
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/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-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-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-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-6/i2c-max77759tcpc/usb_limit_sink_current
|
||||||
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_sink_enable
|
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/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-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-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-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-6/i2c-max77759tcpc/usb_limit_sink_current
|
||||||
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_sink_enable
|
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