123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #define LOG_TAG "usbd"
- #include <string>
- #include <android-base/logging.h>
- #include <android-base/properties.h>
- #include <android/hardware/usb/gadget/1.0/IUsbGadget.h>
- #include <hidl/HidlTransportSupport.h>
- using android::base::GetProperty;
- using android::base::SetProperty;
- using android::hardware::configureRpcThreadpool;
- using android::hardware::usb::gadget::V1_0::GadgetFunction;
- using android::hardware::usb::gadget::V1_0::IUsbGadget;
- using android::hardware::Return;
- int main(int , char** ) {
- if (GetProperty("ro.bootmode", "") == "charger") exit(0);
- configureRpcThreadpool(1, true );
- android::sp<IUsbGadget> gadget = IUsbGadget::getService();
- Return<void> ret;
- if (gadget != nullptr) {
- LOG(INFO) << "Usb HAL found.";
- std::string function = GetProperty("persist.sys.usb.config", "");
- if (function == "adb") {
- LOG(INFO) << "peristent prop is adb";
- SetProperty("ctl.start", "adbd");
- ret = gadget->setCurrentUsbFunctions(static_cast<uint64_t>(GadgetFunction::ADB),
- nullptr, 0);
- } else {
- LOG(INFO) << "Signal MTP to enable default functions";
- ret = gadget->setCurrentUsbFunctions(static_cast<uint64_t>(GadgetFunction::MTP),
- nullptr, 0);
- }
- if (!ret.isOk()) LOG(ERROR) << "Error while invoking usb hal";
- } else {
- LOG(INFO) << "Usb HAL not found";
- }
- exit(0);
- }
|