Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 17 | #define LOG_TAG "android.hardware.usb.gadget.aidl-service" |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 18 | |
| 19 | #include "UsbGadget.h" |
| 20 | #include <dirent.h> |
| 21 | #include <fcntl.h> |
| 22 | #include <stdio.h> |
| 23 | #include <sys/inotify.h> |
| 24 | #include <sys/mount.h> |
| 25 | #include <sys/stat.h> |
| 26 | #include <sys/types.h> |
| 27 | #include <unistd.h> |
| 28 | |
Avichal Rakesh | eafdae6 | 2023-01-06 02:47:19 -0800 | [diff] [blame] | 29 | #include <android-base/properties.h> |
| 30 | |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 31 | #include <aidl/android/frameworks/stats/IStats.h> |
| 32 | |
| 33 | namespace aidl { |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 34 | namespace android { |
| 35 | namespace hardware { |
| 36 | namespace usb { |
| 37 | namespace gadget { |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 38 | |
Ricky Niu | ebd7fca | 2022-05-09 10:14:20 +0800 | [diff] [blame] | 39 | string enabledPath; |
| 40 | constexpr char kHsi2cPath[] = "/sys/devices/platform/10d50000.hsi2c"; |
| 41 | constexpr char kI2CPath[] = "/sys/devices/platform/10d50000.hsi2c/i2c-"; |
| 42 | constexpr char kAccessoryLimitCurrent[] = "i2c-max77759tcpc/usb_limit_accessory_current"; |
| 43 | constexpr char kAccessoryLimitCurrentEnable[] = "i2c-max77759tcpc/usb_limit_accessory_enable"; |
Amit Sunil Dhamne | ed62285 | 2023-09-12 17:53:45 -0700 | [diff] [blame^] | 44 | constexpr char kUpdateSdpEnumTimeout[] = "i2c-max77759tcpc/update_sdp_enum_timeout"; |
Ricky Niu | ebd7fca | 2022-05-09 10:14:20 +0800 | [diff] [blame] | 45 | |
Avichal Rakesh | eafdae6 | 2023-01-06 02:47:19 -0800 | [diff] [blame] | 46 | using ::android::base::GetBoolProperty; |
| 47 | using ::android::hardware::google::pixel::usb::kUvcEnabled; |
| 48 | |
Amit Sunil Dhamne | ed62285 | 2023-09-12 17:53:45 -0700 | [diff] [blame^] | 49 | Status getI2cBusHelper(string *name) { |
| 50 | DIR *dp; |
| 51 | |
| 52 | dp = opendir(kHsi2cPath); |
| 53 | if (dp != NULL) { |
| 54 | struct dirent *ep; |
| 55 | |
| 56 | while ((ep = readdir(dp))) { |
| 57 | if (ep->d_type == DT_DIR) { |
| 58 | if (string::npos != string(ep->d_name).find("i2c-")) { |
| 59 | std::strtok(ep->d_name, "-"); |
| 60 | *name = std::strtok(NULL, "-"); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | closedir(dp); |
| 65 | return Status::SUCCESS; |
| 66 | } |
| 67 | |
| 68 | ALOGE("Failed to open %s", kHsi2cPath); |
| 69 | return Status::ERROR; |
| 70 | } |
| 71 | |
Ray Chi | ba3dc9b | 2022-03-01 21:57:03 +0800 | [diff] [blame] | 72 | UsbGadget::UsbGadget() : mGadgetIrqPath("") { |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 73 | if (access(OS_DESC_PATH, R_OK) != 0) { |
| 74 | ALOGE("configfs setup not done yet"); |
| 75 | abort(); |
| 76 | } |
| 77 | } |
| 78 | |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 79 | Status UsbGadget::getUsbGadgetIrqPath() { |
Ray Chi | ba3dc9b | 2022-03-01 21:57:03 +0800 | [diff] [blame] | 80 | std::string irqs; |
| 81 | size_t read_pos = 0; |
| 82 | size_t found_pos = 0; |
| 83 | |
| 84 | if (!ReadFileToString(kProcInterruptsPath, &irqs)) { |
| 85 | ALOGE("cannot read all interrupts"); |
| 86 | return Status::ERROR; |
| 87 | } |
| 88 | |
| 89 | while (true) { |
| 90 | found_pos = irqs.find_first_of("\n", read_pos); |
| 91 | if (found_pos == std::string::npos) { |
| 92 | ALOGI("the string of all interrupts is unexpected"); |
| 93 | return Status::ERROR; |
| 94 | } |
| 95 | |
| 96 | std::string single_irq = irqs.substr(read_pos, found_pos - read_pos); |
| 97 | |
| 98 | if (single_irq.find("dwc3", 0) != std::string::npos) { |
| 99 | unsigned int dwc3_irq_number; |
| 100 | size_t dwc3_pos = single_irq.find_first_of(":"); |
| 101 | if (!ParseUint(single_irq.substr(0, dwc3_pos), &dwc3_irq_number)) { |
| 102 | ALOGI("unknown IRQ strings"); |
| 103 | return Status::ERROR; |
| 104 | } |
| 105 | |
| 106 | mGadgetIrqPath = kProcIrqPath + single_irq.substr(0, dwc3_pos) + kSmpAffinityList; |
| 107 | break; |
| 108 | } |
| 109 | |
| 110 | if (found_pos == irqs.npos) { |
| 111 | ALOGI("USB gadget doesn't start"); |
| 112 | return Status::ERROR; |
| 113 | } |
| 114 | |
| 115 | read_pos = found_pos + 1; |
| 116 | } |
| 117 | |
| 118 | return Status::SUCCESS; |
| 119 | } |
| 120 | |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 121 | void currentFunctionsAppliedCallback(bool functionsApplied, void *payload) { |
| 122 | UsbGadget *gadget = (UsbGadget *)payload; |
| 123 | gadget->mCurrentUsbFunctionsApplied = functionsApplied; |
Amit Sunil Dhamne | ed62285 | 2023-09-12 17:53:45 -0700 | [diff] [blame^] | 124 | gadget->updateSdpEnumTimeout(); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 125 | } |
| 126 | |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 127 | ScopedAStatus UsbGadget::getCurrentUsbFunctions(const shared_ptr<IUsbGadgetCallback> &callback, |
| 128 | int64_t in_transactionId) { |
| 129 | ScopedAStatus ret = callback->getCurrentUsbFunctionsCb( |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 130 | mCurrentUsbFunctions, |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 131 | mCurrentUsbFunctionsApplied ? Status::FUNCTIONS_APPLIED : Status::FUNCTIONS_NOT_APPLIED, |
| 132 | in_transactionId); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 133 | if (!ret.isOk()) |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 134 | ALOGE("Call to getCurrentUsbFunctionsCb failed %s", ret.getDescription().c_str()); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 135 | |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 136 | return ScopedAStatus::ok(); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 137 | } |
| 138 | |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 139 | ScopedAStatus UsbGadget::getUsbSpeed(const shared_ptr<IUsbGadgetCallback> &callback, |
| 140 | int64_t in_transactionId) { |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 141 | std::string current_speed; |
| 142 | if (ReadFileToString(SPEED_PATH, ¤t_speed)) { |
| 143 | current_speed = Trim(current_speed); |
| 144 | ALOGI("current USB speed is %s", current_speed.c_str()); |
| 145 | if (current_speed == "low-speed") |
| 146 | mUsbSpeed = UsbSpeed::LOWSPEED; |
| 147 | else if (current_speed == "full-speed") |
| 148 | mUsbSpeed = UsbSpeed::FULLSPEED; |
| 149 | else if (current_speed == "high-speed") |
| 150 | mUsbSpeed = UsbSpeed::HIGHSPEED; |
| 151 | else if (current_speed == "super-speed") |
| 152 | mUsbSpeed = UsbSpeed::SUPERSPEED; |
| 153 | else if (current_speed == "super-speed-plus") |
| 154 | mUsbSpeed = UsbSpeed::SUPERSPEED_10Gb; |
| 155 | else if (current_speed == "UNKNOWN") |
| 156 | mUsbSpeed = UsbSpeed::UNKNOWN; |
| 157 | else |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 158 | mUsbSpeed = UsbSpeed::UNKNOWN; |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 159 | } else { |
| 160 | ALOGE("Fail to read current speed"); |
| 161 | mUsbSpeed = UsbSpeed::UNKNOWN; |
| 162 | } |
| 163 | |
| 164 | if (callback) { |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 165 | ScopedAStatus ret = callback->getUsbSpeedCb(mUsbSpeed, in_transactionId); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 166 | |
| 167 | if (!ret.isOk()) |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 168 | ALOGE("Call to getUsbSpeedCb failed %s", ret.getDescription().c_str()); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 169 | } |
| 170 | |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 171 | return ScopedAStatus::ok(); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 172 | } |
| 173 | |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 174 | Status UsbGadget::tearDownGadget() { |
| 175 | if (Status(resetGadget()) != Status::SUCCESS){ |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 176 | return Status::ERROR; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 177 | } |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 178 | |
| 179 | if (monitorFfs.isMonitorRunning()) { |
| 180 | monitorFfs.reset(); |
| 181 | } else { |
| 182 | ALOGI("mMonitor not running"); |
| 183 | } |
| 184 | return Status::SUCCESS; |
| 185 | } |
| 186 | |
Avichal Rakesh | eafdae6 | 2023-01-06 02:47:19 -0800 | [diff] [blame] | 187 | static Status validateAndSetVidPid(int64_t functions) { |
| 188 | Status ret; |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 189 | std::string vendorFunctions = getVendorFunctions(); |
| 190 | |
| 191 | switch (functions) { |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 192 | case GadgetFunction::MTP: |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 193 | if (!(vendorFunctions == "user" || vendorFunctions == "")) { |
| 194 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
| 195 | ret = Status::CONFIGURATION_NOT_SUPPORTED; |
| 196 | } else { |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 197 | ret = Status(setVidPid("0x18d1", "0x4ee1")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 198 | } |
| 199 | break; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 200 | case GadgetFunction::ADB | |
| 201 | GadgetFunction::MTP: |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 202 | if (!(vendorFunctions == "user" || vendorFunctions == "")) { |
| 203 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
| 204 | ret = Status::CONFIGURATION_NOT_SUPPORTED; |
| 205 | } else { |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 206 | ret = Status(setVidPid("0x18d1", "0x4ee2")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 207 | } |
| 208 | break; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 209 | case GadgetFunction::RNDIS: |
| 210 | case GadgetFunction::RNDIS | |
| 211 | GadgetFunction::NCM: |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 212 | if (!(vendorFunctions == "user" || vendorFunctions == "")) { |
| 213 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
| 214 | ret = Status::CONFIGURATION_NOT_SUPPORTED; |
| 215 | } else { |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 216 | ret = Status(setVidPid("0x18d1", "0x4ee3")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 217 | } |
| 218 | break; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 219 | case GadgetFunction::ADB | |
| 220 | GadgetFunction::RNDIS: |
| 221 | case GadgetFunction::ADB | |
| 222 | GadgetFunction::RNDIS | |
| 223 | GadgetFunction::NCM: |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 224 | if (vendorFunctions == "dm") { |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 225 | ret = Status(setVidPid("0x04e8", "0x6862")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 226 | } else { |
| 227 | if (!(vendorFunctions == "user" || vendorFunctions == "")) { |
| 228 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
| 229 | ret = Status::CONFIGURATION_NOT_SUPPORTED; |
| 230 | } else { |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 231 | ret = Status(setVidPid("0x18d1", "0x4ee4")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | break; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 235 | case GadgetFunction::PTP: |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 236 | if (!(vendorFunctions == "user" || vendorFunctions == "")) { |
| 237 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
| 238 | ret = Status::CONFIGURATION_NOT_SUPPORTED; |
| 239 | } else { |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 240 | ret = Status(setVidPid("0x18d1", "0x4ee5")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 241 | } |
| 242 | break; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 243 | case GadgetFunction::ADB | |
| 244 | GadgetFunction::PTP: |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 245 | if (!(vendorFunctions == "user" || vendorFunctions == "")) { |
| 246 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
| 247 | ret = Status::CONFIGURATION_NOT_SUPPORTED; |
| 248 | } else { |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 249 | ret = Status(setVidPid("0x18d1", "0x4ee6")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 250 | } |
| 251 | break; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 252 | case GadgetFunction::ADB: |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 253 | if (vendorFunctions == "dm") { |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 254 | ret = Status(setVidPid("0x04e8", "0x6862")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 255 | } else if (vendorFunctions == "etr_miu") { |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 256 | ret = Status(setVidPid("0x18d1", "0x4ee2")); |
Puma Hsu | fbcb7ad | 2021-08-19 19:36:51 +0800 | [diff] [blame] | 257 | } else if (vendorFunctions == "uwb_acm"){ |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 258 | ret = Status(setVidPid("0x18d1", "0x4ee2")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 259 | } else { |
| 260 | if (!(vendorFunctions == "user" || vendorFunctions == "")) { |
| 261 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
| 262 | ret = Status::CONFIGURATION_NOT_SUPPORTED; |
| 263 | } else { |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 264 | ret = Status(setVidPid("0x18d1", "0x4ee7")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | break; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 268 | case GadgetFunction::MIDI: |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 269 | if (!(vendorFunctions == "user" || vendorFunctions == "")) { |
| 270 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
| 271 | ret = Status::CONFIGURATION_NOT_SUPPORTED; |
| 272 | } else { |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 273 | ret = Status(setVidPid("0x18d1", "0x4ee8")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 274 | } |
| 275 | break; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 276 | case GadgetFunction::ADB | |
| 277 | GadgetFunction::MIDI: |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 278 | if (!(vendorFunctions == "user" || vendorFunctions == "")) { |
| 279 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
| 280 | ret = Status::CONFIGURATION_NOT_SUPPORTED; |
| 281 | } else { |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 282 | ret = Status(setVidPid("0x18d1", "0x4ee9")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 283 | } |
| 284 | break; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 285 | case GadgetFunction::ACCESSORY: |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 286 | if (!(vendorFunctions == "user" || vendorFunctions == "")) |
| 287 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 288 | ret = Status(setVidPid("0x18d1", "0x2d00")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 289 | break; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 290 | case GadgetFunction::ADB | |
| 291 | GadgetFunction::ACCESSORY: |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 292 | if (!(vendorFunctions == "user" || vendorFunctions == "")) |
| 293 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 294 | ret = Status(setVidPid("0x18d1", "0x2d01")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 295 | break; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 296 | case GadgetFunction::AUDIO_SOURCE: |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 297 | if (!(vendorFunctions == "user" || vendorFunctions == "")) |
| 298 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 299 | ret = Status(setVidPid("0x18d1", "0x2d02")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 300 | break; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 301 | case GadgetFunction::ADB | |
| 302 | GadgetFunction::AUDIO_SOURCE: |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 303 | if (!(vendorFunctions == "user" || vendorFunctions == "")) |
| 304 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 305 | ret = Status(setVidPid("0x18d1", "0x2d03")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 306 | break; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 307 | case GadgetFunction::ACCESSORY | |
| 308 | GadgetFunction::AUDIO_SOURCE: |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 309 | if (!(vendorFunctions == "user" || vendorFunctions == "")) |
| 310 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 311 | ret = Status(setVidPid("0x18d1", "0x2d04")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 312 | break; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 313 | case GadgetFunction::ADB | |
| 314 | GadgetFunction::ACCESSORY | |
| 315 | GadgetFunction::AUDIO_SOURCE: |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 316 | if (!(vendorFunctions == "user" || vendorFunctions == "")) |
| 317 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 318 | ret = Status(setVidPid("0x18d1", "0x2d05")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 319 | break; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 320 | case GadgetFunction::NCM: |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 321 | if (!(vendorFunctions == "user" || vendorFunctions == "")) |
| 322 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 323 | ret = Status(setVidPid("0x18d1", "0x4eeb")); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 324 | break; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 325 | case GadgetFunction::ADB | |
| 326 | GadgetFunction::NCM: |
Ricky Niu | 48b3e5d | 2021-11-24 17:26:38 +0800 | [diff] [blame] | 327 | if (vendorFunctions == "dm") { |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 328 | ret = Status(setVidPid("0x04e8", "0x6862")); |
Ricky Niu | 48b3e5d | 2021-11-24 17:26:38 +0800 | [diff] [blame] | 329 | } else { |
| 330 | if (!(vendorFunctions == "user" || vendorFunctions == "")) |
| 331 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 332 | ret = Status(setVidPid("0x18d1", "0x4eec")); |
Ricky Niu | 48b3e5d | 2021-11-24 17:26:38 +0800 | [diff] [blame] | 333 | } |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 334 | break; |
Avichal Rakesh | eafdae6 | 2023-01-06 02:47:19 -0800 | [diff] [blame] | 335 | case GadgetFunction::UVC: |
| 336 | if (!(vendorFunctions == "user" || vendorFunctions == "")) { |
| 337 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
| 338 | ret = Status::CONFIGURATION_NOT_SUPPORTED; |
| 339 | } else if (!GetBoolProperty(kUvcEnabled, false)) { |
| 340 | ALOGE("UVC function not enabled by config"); |
| 341 | ret = Status::CONFIGURATION_NOT_SUPPORTED; |
| 342 | } else { |
| 343 | ret = Status(setVidPid("0x18d1", "0x4eed")); |
| 344 | } |
| 345 | break; |
| 346 | case GadgetFunction::ADB | GadgetFunction::UVC: |
| 347 | if (!(vendorFunctions == "user" || vendorFunctions == "")) { |
| 348 | ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); |
| 349 | ret = Status::CONFIGURATION_NOT_SUPPORTED; |
| 350 | } else if (!GetBoolProperty(kUvcEnabled, false)) { |
| 351 | ALOGE("UVC function not enabled by config"); |
| 352 | ret = Status::CONFIGURATION_NOT_SUPPORTED; |
| 353 | } else { |
| 354 | ret = Status(setVidPid("0x18d1", "0x4eee")); |
| 355 | } |
| 356 | break; |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 357 | default: |
| 358 | ALOGE("Combination not supported"); |
| 359 | ret = Status::CONFIGURATION_NOT_SUPPORTED; |
| 360 | } |
| 361 | return ret; |
| 362 | } |
| 363 | |
Ricky Niu | 744f214 | 2023-01-31 18:01:06 +0800 | [diff] [blame] | 364 | ScopedAStatus UsbGadget::reset(const shared_ptr<IUsbGadgetCallback> &callback, |
| 365 | int64_t in_transactionId) { |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 366 | ALOGI("USB Gadget reset"); |
| 367 | |
| 368 | if (!WriteStringToFile("none", PULLUP_PATH)) { |
| 369 | ALOGI("Gadget cannot be pulled down"); |
Ricky Niu | 744f214 | 2023-01-31 18:01:06 +0800 | [diff] [blame] | 370 | if (callback) |
| 371 | callback->resetCb(Status::ERROR, in_transactionId); |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 372 | return ScopedAStatus::fromServiceSpecificErrorWithMessage( |
| 373 | -1, "Gadget cannot be pulled down"); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | usleep(kDisconnectWaitUs); |
| 377 | |
| 378 | if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) { |
| 379 | ALOGI("Gadget cannot be pulled up"); |
Ricky Niu | 744f214 | 2023-01-31 18:01:06 +0800 | [diff] [blame] | 380 | if (callback) |
| 381 | callback->resetCb(Status::ERROR, in_transactionId); |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 382 | return ScopedAStatus::fromServiceSpecificErrorWithMessage( |
| 383 | -1, "Gadget cannot be pulled up"); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 384 | } |
Ricky Niu | 744f214 | 2023-01-31 18:01:06 +0800 | [diff] [blame] | 385 | if (callback) |
| 386 | callback->resetCb(Status::SUCCESS, in_transactionId); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 387 | |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 388 | return ScopedAStatus::ok(); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 389 | } |
| 390 | |
Amit Sunil Dhamne | ed62285 | 2023-09-12 17:53:45 -0700 | [diff] [blame^] | 391 | void UsbGadget::updateSdpEnumTimeout() { |
| 392 | string i2c_node, update_sdp_enum_timeout_path; |
| 393 | |
| 394 | Status status = getI2cBusHelper(&i2c_node); |
| 395 | if (status != Status::SUCCESS) { |
| 396 | ALOGE("%s: Unable to locate i2c bus node", __func__); |
| 397 | } |
| 398 | |
| 399 | update_sdp_enum_timeout_path = kI2CPath + i2c_node + "/" + kUpdateSdpEnumTimeout; |
| 400 | if (!WriteStringToFile("1", update_sdp_enum_timeout_path)) { |
| 401 | ALOGE("%s: Unable to write to %s.", __func__, update_sdp_enum_timeout_path.c_str()); |
| 402 | } else { |
| 403 | ALOGI("%s: Updated SDP enumeration timeout value.", __func__); |
| 404 | } |
| 405 | } |
| 406 | |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 407 | Status UsbGadget::setupFunctions(long functions, |
| 408 | const shared_ptr<IUsbGadgetCallback> &callback, uint64_t timeout, |
| 409 | int64_t in_transactionId) { |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 410 | bool ffsEnabled = false; |
| 411 | int i = 0; |
| 412 | |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 413 | if (Status(addGenericAndroidFunctions(&monitorFfs, functions, &ffsEnabled, &i)) != |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 414 | Status::SUCCESS) |
| 415 | return Status::ERROR; |
| 416 | |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 417 | std::string vendorFunctions = getVendorFunctions(); |
| 418 | |
| 419 | if (vendorFunctions == "dm") { |
| 420 | ALOGI("enable usbradio debug functions"); |
Maciej Żenczykowski | e0ccd8f | 2020-12-27 19:58:32 -0800 | [diff] [blame] | 421 | if ((functions & GadgetFunction::RNDIS) != 0) { |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 422 | if (linkFunction("acm.gs6", i++)) |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 423 | return Status::ERROR; |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 424 | if (linkFunction("dm.gs7", i++)) |
| 425 | return Status::ERROR; |
| 426 | } else { |
| 427 | if (linkFunction("dm.gs7", i++)) |
| 428 | return Status::ERROR; |
| 429 | if (linkFunction("acm.gs6", i++)) |
| 430 | return Status::ERROR; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 431 | } |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 432 | } else if (vendorFunctions == "etr_miu") { |
| 433 | ALOGI("enable etr_miu functions"); |
| 434 | if (linkFunction("etr_miu.gs11", i++)) |
| 435 | return Status::ERROR; |
Puma Hsu | fbcb7ad | 2021-08-19 19:36:51 +0800 | [diff] [blame] | 436 | } else if (vendorFunctions == "uwb_acm") { |
| 437 | ALOGI("enable uwb acm function"); |
| 438 | if (linkFunction("acm.uwb0", i++)) |
| 439 | return Status::ERROR; |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 440 | } |
| 441 | |
Maciej Żenczykowski | e0ccd8f | 2020-12-27 19:58:32 -0800 | [diff] [blame] | 442 | if ((functions & GadgetFunction::ADB) != 0) { |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 443 | ffsEnabled = true; |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 444 | if (Status(addAdb(&monitorFfs, &i)) != Status::SUCCESS) |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 445 | return Status::ERROR; |
| 446 | } |
| 447 | |
Maciej Żenczykowski | e0ccd8f | 2020-12-27 19:58:32 -0800 | [diff] [blame] | 448 | if ((functions & GadgetFunction::NCM) != 0) { |
| 449 | ALOGI("setCurrentUsbFunctions ncm"); |
| 450 | if (linkFunction("ncm.gs9", i++)) |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 451 | return Status::ERROR; |
| 452 | } |
| 453 | |
| 454 | // Pull up the gadget right away when there are no ffs functions. |
| 455 | if (!ffsEnabled) { |
| 456 | if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) |
| 457 | return Status::ERROR; |
| 458 | mCurrentUsbFunctionsApplied = true; |
| 459 | if (callback) |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 460 | callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId); |
Amit Sunil Dhamne | ed62285 | 2023-09-12 17:53:45 -0700 | [diff] [blame^] | 461 | updateSdpEnumTimeout(); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 462 | return Status::SUCCESS; |
| 463 | } |
| 464 | |
| 465 | monitorFfs.registerFunctionsAppliedCallback(¤tFunctionsAppliedCallback, this); |
| 466 | // Monitors the ffs paths to pull up the gadget when descriptors are written. |
| 467 | // Also takes of the pulling up the gadget again if the userspace process |
| 468 | // dies and restarts. |
| 469 | monitorFfs.startMonitor(); |
| 470 | |
| 471 | if (kDebug) |
| 472 | ALOGI("Mainthread in Cv"); |
| 473 | |
| 474 | if (callback) { |
| 475 | bool pullup = monitorFfs.waitForPullUp(timeout); |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 476 | ScopedAStatus ret = callback->setCurrentUsbFunctionsCb( |
| 477 | functions, pullup ? Status::SUCCESS : Status::ERROR, in_transactionId); |
| 478 | if (!ret.isOk()) { |
| 479 | ALOGE("setCurrentUsbFunctionsCb error %s", ret.getDescription().c_str()); |
| 480 | return Status::ERROR; |
| 481 | } |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 482 | } |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 483 | return Status::SUCCESS; |
| 484 | } |
| 485 | |
Ricky Niu | ebd7fca | 2022-05-09 10:14:20 +0800 | [diff] [blame] | 486 | |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 487 | ScopedAStatus UsbGadget::setCurrentUsbFunctions(long functions, |
| 488 | const shared_ptr<IUsbGadgetCallback> &callback, |
| 489 | int64_t timeout, |
| 490 | int64_t in_transactionId) { |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 491 | std::unique_lock<std::mutex> lk(mLockSetCurrentFunction); |
Ricky Niu | ebd7fca | 2022-05-09 10:14:20 +0800 | [diff] [blame] | 492 | std::string current_usb_power_operation_mode, current_usb_type; |
| 493 | std::string usb_limit_sink_enable; |
| 494 | |
| 495 | string accessoryCurrentLimitEnablePath, accessoryCurrentLimitPath, path; |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 496 | |
| 497 | mCurrentUsbFunctions = functions; |
| 498 | mCurrentUsbFunctionsApplied = false; |
| 499 | |
Ricky Niu | ebd7fca | 2022-05-09 10:14:20 +0800 | [diff] [blame] | 500 | getI2cBusHelper(&path); |
| 501 | accessoryCurrentLimitPath = kI2CPath + path + "/" + kAccessoryLimitCurrent; |
| 502 | accessoryCurrentLimitEnablePath = kI2CPath + path + "/" + kAccessoryLimitCurrentEnable; |
| 503 | |
Ray Chi | ba3dc9b | 2022-03-01 21:57:03 +0800 | [diff] [blame] | 504 | // Get the gadget IRQ number before tearDownGadget() |
| 505 | if (mGadgetIrqPath.empty()) |
| 506 | getUsbGadgetIrqPath(); |
| 507 | |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 508 | // Unlink the gadget and stop the monitor if running. |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 509 | Status status = tearDownGadget(); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 510 | if (status != Status::SUCCESS) { |
| 511 | goto error; |
| 512 | } |
| 513 | |
| 514 | ALOGI("Returned from tearDown gadget"); |
| 515 | |
| 516 | // Leave the gadget pulled down to give time for the host to sense disconnect. |
| 517 | usleep(kDisconnectWaitUs); |
| 518 | |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 519 | if (functions == GadgetFunction::NONE) { |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 520 | if (callback == NULL) |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 521 | return ScopedAStatus::fromServiceSpecificErrorWithMessage( |
| 522 | -1, "callback == NULL"); |
| 523 | ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 524 | if (!ret.isOk()) |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 525 | ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.getDescription().c_str()); |
| 526 | return ScopedAStatus::fromServiceSpecificErrorWithMessage( |
| 527 | -1, "Error while calling setCurrentUsbFunctionsCb"); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | status = validateAndSetVidPid(functions); |
| 531 | |
| 532 | if (status != Status::SUCCESS) { |
| 533 | goto error; |
| 534 | } |
| 535 | |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 536 | status = setupFunctions(functions, callback, timeout, in_transactionId); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 537 | if (status != Status::SUCCESS) { |
| 538 | goto error; |
| 539 | } |
| 540 | |
Maciej Żenczykowski | a24469c | 2021-06-25 11:42:01 -0700 | [diff] [blame] | 541 | if (functions & GadgetFunction::NCM) { |
Ray Chi | ba3dc9b | 2022-03-01 21:57:03 +0800 | [diff] [blame] | 542 | if (!mGadgetIrqPath.empty()) { |
| 543 | if (!WriteStringToFile(BIG_CORE, mGadgetIrqPath)) |
| 544 | ALOGI("Cannot move gadget IRQ to big core, path:%s", mGadgetIrqPath.c_str()); |
| 545 | } |
Maciej Żenczykowski | a24469c | 2021-06-25 11:42:01 -0700 | [diff] [blame] | 546 | } else { |
Ray Chi | ba3dc9b | 2022-03-01 21:57:03 +0800 | [diff] [blame] | 547 | if (!mGadgetIrqPath.empty()) { |
| 548 | if (!WriteStringToFile(MEDIUM_CORE, mGadgetIrqPath)) |
| 549 | ALOGI("Cannot move gadget IRQ to medium core, path:%s", mGadgetIrqPath.c_str()); |
| 550 | } |
Maciej Żenczykowski | a24469c | 2021-06-25 11:42:01 -0700 | [diff] [blame] | 551 | } |
| 552 | |
Ricky Niu | ebd7fca | 2022-05-09 10:14:20 +0800 | [diff] [blame] | 553 | if (ReadFileToString(CURRENT_USB_TYPE_PATH, ¤t_usb_type)) |
| 554 | current_usb_type = Trim(current_usb_type); |
| 555 | |
| 556 | if (ReadFileToString(CURRENT_USB_POWER_OPERATION_MODE_PATH, ¤t_usb_power_operation_mode)) |
| 557 | current_usb_power_operation_mode = Trim(current_usb_power_operation_mode); |
| 558 | |
| 559 | if (functions & GadgetFunction::ACCESSORY && |
| 560 | current_usb_type == "Unknown SDP [CDP] DCP" && |
| 561 | (current_usb_power_operation_mode == "default" || |
| 562 | current_usb_power_operation_mode == "1.5A")) { |
| 563 | if (!WriteStringToFile("1300000", accessoryCurrentLimitPath)) { |
| 564 | ALOGI("Write 1.3A to limit current fail"); |
| 565 | } else { |
| 566 | if (!WriteStringToFile("1", accessoryCurrentLimitEnablePath)) { |
| 567 | ALOGI("Enable limit current fail"); |
| 568 | } |
| 569 | } |
| 570 | } else { |
| 571 | if (!WriteStringToFile("0", accessoryCurrentLimitEnablePath)) |
| 572 | ALOGI("unvote accessory limit current failed"); |
| 573 | } |
| 574 | |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 575 | ALOGI("Usb Gadget setcurrent functions called successfully"); |
Ricky Niu | b77191c | 2023-02-01 19:40:22 +0800 | [diff] [blame] | 576 | return ScopedAStatus::ok(); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 577 | |
| 578 | error: |
| 579 | ALOGI("Usb Gadget setcurrent functions failed"); |
| 580 | if (callback == NULL) |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 581 | return ScopedAStatus::fromServiceSpecificErrorWithMessage( |
| 582 | -1, "Usb Gadget setcurrent functions failed"); |
| 583 | ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions, status, in_transactionId); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 584 | if (!ret.isOk()) |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 585 | ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.getDescription().c_str()); |
| 586 | return ScopedAStatus::fromServiceSpecificErrorWithMessage( |
| 587 | -1, "Error while calling setCurrentUsbFunctionsCb"); |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 588 | } |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 589 | } // namespace gadget |
| 590 | } // namespace usb |
| 591 | } // namespace hardware |
| 592 | } // namespace android |
Ricky Niu | d6d0b7d | 2022-07-06 20:57:02 +0800 | [diff] [blame] | 593 | } // aidl |