blob: 1105376ad90fb8595cd961fa118adc7433a1d19a [file] [log] [blame]
Badhri Jagan Sridharanb9f69ea2021-10-19 13:09:44 -07001/*
2 * Copyright (C) 2021 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
17#define LOG_TAG "android.hardware.usb.aidl-service"
18
19#include <aidl/android/hardware/usb/PortRole.h>
20#include <android-base/logging.h>
21#include <android-base/properties.h>
22#include <android-base/strings.h>
23#include <assert.h>
24#include <dirent.h>
25#include <pthread.h>
26#include <stdio.h>
27#include <sys/types.h>
28#include <unistd.h>
29#include <chrono>
30#include <regex>
31#include <thread>
32#include <unordered_map>
33
34#include <cutils/uevent.h>
35#include <sys/epoll.h>
36#include <utils/Errors.h>
37#include <utils/StrongPointer.h>
38
39#include "Usb.h"
40
41using android::base::GetProperty;
42using android::base::Trim;
43
44namespace aidl {
45namespace android {
46namespace hardware {
47namespace usb {
48
49constexpr char kTypecPath[] = "/sys/class/typec/";
50constexpr char kDataRoleNode[] = "/data_role";
51constexpr char kPowerRoleNode[] = "/power_role";
52
53// Set by the signal handler to destroy the thread
54volatile bool destroyThread;
55
56void queryVersionHelper(android::hardware::usb::Usb *usb,
57 std::vector<PortStatus> *currentPortStatus);
58
59ScopedAStatus Usb::enableUsbData(const string& in_portName, bool in_enable, int64_t in_transactionId) {
60 std::vector<PortStatus> currentPortStatus;
61
62 pthread_mutex_lock(&mLock);
63 if (mCallback != NULL) {
64 ScopedAStatus ret = mCallback->notifyEnableUsbDataStatus(
65 in_portName, true, in_enable ? Status::SUCCESS : Status::ERROR, in_transactionId);
66 if (!ret.isOk())
67 ALOGE("notifyEnableUsbDataStatus error %s", ret.getDescription().c_str());
68 } else {
69 ALOGE("Not notifying the userspace. Callback is not set");
70 }
71 pthread_mutex_unlock(&mLock);
72 queryVersionHelper(this, &currentPortStatus);
73
74 return ScopedAStatus::ok();
75}
76
77Status queryMoistureDetectionStatus(std::vector<PortStatus> *currentPortStatus) {
78 string enabled, status, path, DetectedPath;
79
80 for (int i = 0; i < currentPortStatus->size(); i++) {
81 (*currentPortStatus)[i].supportedContaminantProtectionModes
82 .push_back(ContaminantProtectionMode::NONE);
83 (*currentPortStatus)[i].contaminantProtectionStatus
84 = ContaminantProtectionStatus::NONE;
85 (*currentPortStatus)[i].contaminantDetectionStatus
86 = ContaminantDetectionStatus::NOT_SUPPORTED;
87 (*currentPortStatus)[i].supportsEnableContaminantPresenceDetection = false;
88 (*currentPortStatus)[i].supportsEnableContaminantPresenceProtection = false;
89 }
90
91 return Status::SUCCESS;
92}
93
94string appendRoleNodeHelper(const string &portName, PortRole::Tag tag) {
95 string node(kTypecPath + portName);
96
97 switch (tag) {
98 case PortRole::dataRole:
99 return node + kDataRoleNode;
100 case PortRole::powerRole:
101 return node + kPowerRoleNode;
102 case PortRole::mode:
103 return node + "/port_type";
104 default:
105 return "";
106 }
107}
108
109string convertRoletoString(PortRole role) {
110 if (role.getTag() == PortRole::powerRole) {
111 if (role.get<PortRole::powerRole>() == PortPowerRole::SOURCE)
112 return "source";
113 else if (role.get<PortRole::powerRole>() == PortPowerRole::SINK)
114 return "sink";
115 } else if (role.getTag() == PortRole::dataRole) {
116 if (role.get<PortRole::dataRole>() == PortDataRole::HOST)
117 return "host";
118 if (role.get<PortRole::dataRole>() == PortDataRole::DEVICE)
119 return "device";
120 } else if (role.getTag() == PortRole::mode) {
121 if (role.get<PortRole::mode>() == PortMode::UFP)
122 return "sink";
123 if (role.get<PortRole::mode>() == PortMode::DFP)
124 return "source";
125 }
126 return "none";
127}
128
129void extractRole(string *roleName) {
130 std::size_t first, last;
131
132 first = roleName->find("[");
133 last = roleName->find("]");
134
135 if (first != string::npos && last != string::npos) {
136 *roleName = roleName->substr(first + 1, last - first - 1);
137 }
138}
139
140void switchToDrp(const string &portName) {
141 string filename = appendRoleNodeHelper(string(portName.c_str()), PortRole::mode);
142 FILE *fp;
143
144 if (filename != "") {
145 fp = fopen(filename.c_str(), "w");
146 if (fp != NULL) {
147 int ret = fputs("dual", fp);
148 fclose(fp);
149 if (ret == EOF)
150 ALOGE("Fatal: Error while switching back to drp");
151 } else {
152 ALOGE("Fatal: Cannot open file to switch back to drp");
153 }
154 } else {
155 ALOGE("Fatal: invalid node type");
156 }
157}
158
159bool switchMode(const string &portName, const PortRole &in_role, struct Usb *usb) {
160 string filename = appendRoleNodeHelper(string(portName.c_str()), in_role.getTag());
161 string written;
162 FILE *fp;
163 bool roleSwitch = false;
164
165 if (filename == "") {
166 ALOGE("Fatal: invalid node type");
167 return false;
168 }
169
170 fp = fopen(filename.c_str(), "w");
171 if (fp != NULL) {
172 // Hold the lock here to prevent loosing connected signals
173 // as once the file is written the partner added signal
174 // can arrive anytime.
175 pthread_mutex_lock(&usb->mPartnerLock);
176 usb->mPartnerUp = false;
177 int ret = fputs(convertRoletoString(in_role).c_str(), fp);
178 fclose(fp);
179
180 if (ret != EOF) {
181 struct timespec to;
182 struct timespec now;
183
184 wait_again:
185 clock_gettime(CLOCK_MONOTONIC, &now);
186 to.tv_sec = now.tv_sec + PORT_TYPE_TIMEOUT;
187 to.tv_nsec = now.tv_nsec;
188
189 int err = pthread_cond_timedwait(&usb->mPartnerCV, &usb->mPartnerLock, &to);
190 // There are no uevent signals which implies role swap timed out.
191 if (err == ETIMEDOUT) {
192 ALOGI("uevents wait timedout");
193 // Validity check.
194 } else if (!usb->mPartnerUp) {
195 goto wait_again;
196 // Role switch succeeded since usb->mPartnerUp is true.
197 } else {
198 roleSwitch = true;
199 }
200 } else {
201 ALOGI("Role switch failed while wrting to file");
202 }
203 pthread_mutex_unlock(&usb->mPartnerLock);
204 }
205
206 if (!roleSwitch)
207 switchToDrp(string(portName.c_str()));
208
209 return roleSwitch;
210}
211
212Usb::Usb()
213 : mLock(PTHREAD_MUTEX_INITIALIZER),
214 mRoleSwitchLock(PTHREAD_MUTEX_INITIALIZER),
215 mPartnerLock(PTHREAD_MUTEX_INITIALIZER),
216 mPartnerUp(false)
217{
218 pthread_condattr_t attr;
219 if (pthread_condattr_init(&attr)) {
220 ALOGE("pthread_condattr_init failed: %s", strerror(errno));
221 abort();
222 }
223 if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC)) {
224 ALOGE("pthread_condattr_setclock failed: %s", strerror(errno));
225 abort();
226 }
227 if (pthread_cond_init(&mPartnerCV, &attr)) {
228 ALOGE("pthread_cond_init failed: %s", strerror(errno));
229 abort();
230 }
231 if (pthread_condattr_destroy(&attr)) {
232 ALOGE("pthread_condattr_destroy failed: %s", strerror(errno));
233 abort();
234 }
235}
236
237ScopedAStatus Usb::switchRole(const string& in_portName,
238 const PortRole& in_role, int64_t in_transactionId) {
239 string filename = appendRoleNodeHelper(string(in_portName.c_str()), in_role.getTag());
240 string written;
241 FILE *fp;
242 bool roleSwitch = false;
243
244 if (filename == "") {
245 ALOGE("Fatal: invalid node type");
246 return ScopedAStatus::ok();
247 }
248
249 pthread_mutex_lock(&mRoleSwitchLock);
250
251 ALOGI("filename write: %s role:%s", filename.c_str(), convertRoletoString(in_role).c_str());
252
253 if (in_role.getTag() == PortRole::mode) {
254 roleSwitch = switchMode(in_portName, in_role, this);
255 } else {
256 fp = fopen(filename.c_str(), "w");
257 if (fp != NULL) {
258 int ret = fputs(convertRoletoString(in_role).c_str(), fp);
259 fclose(fp);
260 if ((ret != EOF) && ReadFileToString(filename, &written)) {
261 written = Trim(written);
262 extractRole(&written);
263 ALOGI("written: %s", written.c_str());
264 if (written == convertRoletoString(in_role)) {
265 roleSwitch = true;
266 } else {
267 ALOGE("Role switch failed");
268 }
269 } else {
270 ALOGE("failed to update the new role");
271 }
272 } else {
273 ALOGE("fopen failed");
274 }
275 }
276
277 pthread_mutex_lock(&mLock);
278 if (mCallback != NULL) {
279 ScopedAStatus ret = mCallback->notifyRoleSwitchStatus(
280 in_portName, in_role, roleSwitch ? Status::SUCCESS : Status::ERROR, in_transactionId);
281 if (!ret.isOk())
282 ALOGE("RoleSwitchStatus error %s", ret.getDescription().c_str());
283 } else {
284 ALOGE("Not notifying the userspace. Callback is not set");
285 }
286 pthread_mutex_unlock(&mLock);
287 pthread_mutex_unlock(&mRoleSwitchLock);
288
289 return ScopedAStatus::ok();
290}
291
292Status getAccessoryConnected(const string &portName, string *accessory) {
293 string filename = kTypecPath + portName + "-partner/accessory_mode";
294
295 if (!ReadFileToString(filename, accessory)) {
296 ALOGE("getAccessoryConnected: Failed to open filesystem node: %s", filename.c_str());
297 return Status::ERROR;
298 }
299 *accessory = Trim(*accessory);
300
301 return Status::SUCCESS;
302}
303
304Status getCurrentRoleHelper(const string &portName, bool connected, PortRole *currentRole) {
305 string filename;
306 string roleName;
307 string accessory;
308
309 // Mode
310
311 if (currentRole->getTag() == PortRole::powerRole) {
312 filename = kTypecPath + portName + kPowerRoleNode;
313 currentRole->set<PortRole::powerRole>(PortPowerRole::NONE);
314 } else if (currentRole->getTag() == PortRole::dataRole) {
315 filename = kTypecPath + portName + kDataRoleNode;
316 currentRole->set<PortRole::dataRole>(PortDataRole::NONE);
317 } else if (currentRole->getTag() == PortRole::mode) {
318 filename = kTypecPath + portName + kDataRoleNode;
319 currentRole->set<PortRole::mode>(PortMode::NONE);
320 } else {
321 return Status::ERROR;
322 }
323
324 if (!connected)
325 return Status::SUCCESS;
326
327 if (currentRole->getTag() == PortRole::mode) {
328 if (getAccessoryConnected(portName, &accessory) != Status::SUCCESS) {
329 return Status::ERROR;
330 }
331 if (accessory == "analog_audio") {
332 currentRole->set<PortRole::mode>(PortMode::AUDIO_ACCESSORY);
333 return Status::SUCCESS;
334 } else if (accessory == "debug") {
335 currentRole->set<PortRole::mode>(PortMode::DEBUG_ACCESSORY);
336 return Status::SUCCESS;
337 }
338 }
339
340 if (!ReadFileToString(filename, &roleName)) {
341 ALOGE("getCurrentRole: Failed to open filesystem node: %s", filename.c_str());
342 return Status::ERROR;
343 }
344
345 roleName = Trim(roleName);
346 extractRole(&roleName);
347
348 if (roleName == "source") {
349 currentRole->set<PortRole::powerRole>(PortPowerRole::SOURCE);
350 } else if (roleName == "sink") {
351 currentRole->set<PortRole::powerRole>(PortPowerRole::SINK);
352 } else if (roleName == "host") {
353 if (currentRole->getTag() == PortRole::dataRole)
354 currentRole->set<PortRole::dataRole>(PortDataRole::HOST);
355 else
356 currentRole->set<PortRole::mode>(PortMode::DFP);
357 } else if (roleName == "device") {
358 if (currentRole->getTag() == PortRole::dataRole)
359 currentRole->set<PortRole::dataRole>(PortDataRole::DEVICE);
360 else
361 currentRole->set<PortRole::mode>(PortMode::UFP);
362 } else if (roleName != "none") {
363 /* case for none has already been addressed.
364 * so we check if the role isn't none.
365 */
366 return Status::UNRECOGNIZED_ROLE;
367 }
368
369 return Status::SUCCESS;
370}
371
372Status getTypeCPortNamesHelper(std::unordered_map<string, bool> *names) {
373 DIR *dp;
374
375 dp = opendir(kTypecPath);
376 if (dp != NULL) {
377 struct dirent *ep;
378
379 while ((ep = readdir(dp))) {
380 if (ep->d_type == DT_LNK) {
381 if (string::npos == string(ep->d_name).find("-partner")) {
382 std::unordered_map<string, bool>::const_iterator portName =
383 names->find(ep->d_name);
384 if (portName == names->end()) {
385 names->insert({ep->d_name, false});
386 }
387 } else {
388 (*names)[std::strtok(ep->d_name, "-")] = true;
389 }
390 }
391 }
392 closedir(dp);
393 return Status::SUCCESS;
394 }
395
396 ALOGE("Failed to open /sys/class/typec");
397 return Status::ERROR;
398}
399
400bool canSwitchRoleHelper(const string &portName) {
401 string filename = kTypecPath + portName + "-partner/supports_usb_power_delivery";
402 string supportsPD;
403
404 if (ReadFileToString(filename, &supportsPD)) {
405 supportsPD = Trim(supportsPD);
406 if (supportsPD == "yes") {
407 return true;
408 }
409 }
410
411 return false;
412}
413
414Status getPortStatusHelper(std::vector<PortStatus> *currentPortStatus) {
415 std::unordered_map<string, bool> names;
416 Status result = getTypeCPortNamesHelper(&names);
417 int i = -1;
418
419 if (result == Status::SUCCESS) {
420 currentPortStatus->resize(names.size());
421 for (std::pair<string, bool> port : names) {
422 i++;
423 ALOGI("%s", port.first.c_str());
424 (*currentPortStatus)[i].portName = port.first;
425
426 PortRole currentRole;
427 currentRole.set<PortRole::powerRole>(PortPowerRole::NONE);
428 if (getCurrentRoleHelper(port.first, port.second, &currentRole) == Status::SUCCESS){
429 (*currentPortStatus)[i].currentPowerRole = currentRole.get<PortRole::powerRole>();
430 } else {
431 ALOGE("Error while retrieving portNames");
432 goto done;
433 }
434
435 currentRole.set<PortRole::dataRole>(PortDataRole::NONE);
436 if (getCurrentRoleHelper(port.first, port.second, &currentRole) == Status::SUCCESS) {
437 (*currentPortStatus)[i].currentDataRole = currentRole.get<PortRole::dataRole>();
438 } else {
439 ALOGE("Error while retrieving current port role");
440 goto done;
441 }
442
443 currentRole.set<PortRole::mode>(PortMode::NONE);
444 if (getCurrentRoleHelper(port.first, port.second, &currentRole) == Status::SUCCESS) {
445 (*currentPortStatus)[i].currentMode = currentRole.get<PortRole::mode>();
446 } else {
447 ALOGE("Error while retrieving current data role");
448 goto done;
449 }
450
451 (*currentPortStatus)[i].canChangeMode = true;
452 (*currentPortStatus)[i].canChangeDataRole =
453 port.second ? canSwitchRoleHelper(port.first) : false;
454 (*currentPortStatus)[i].canChangePowerRole =
455 port.second ? canSwitchRoleHelper(port.first) : false;
456
457 (*currentPortStatus)[i].supportedModes.push_back(PortMode::DRP);
458 (*currentPortStatus)[i].usbDataEnabled = true;
459
460 ALOGI("%d:%s connected:%d canChangeMode:%d canChagedata:%d canChangePower:%d "
461 "usbDataEnabled:%d",
462 i, port.first.c_str(), port.second,
463 (*currentPortStatus)[i].canChangeMode,
464 (*currentPortStatus)[i].canChangeDataRole,
465 (*currentPortStatus)[i].canChangePowerRole, 0);
466 }
467
468 return Status::SUCCESS;
469 }
470done:
471 return Status::ERROR;
472}
473
474void queryVersionHelper(android::hardware::usb::Usb *usb,
475 std::vector<PortStatus> *currentPortStatus) {
476 Status status;
477 pthread_mutex_lock(&usb->mLock);
478 status = getPortStatusHelper(currentPortStatus);
479 queryMoistureDetectionStatus(currentPortStatus);
480 if (usb->mCallback != NULL) {
481 ScopedAStatus ret = usb->mCallback->notifyPortStatusChange(*currentPortStatus,
482 status);
483 if (!ret.isOk())
484 ALOGE("queryPortStatus error %s", ret.getDescription().c_str());
485 } else {
486 ALOGI("Notifying userspace skipped. Callback is NULL");
487 }
488 pthread_mutex_unlock(&usb->mLock);
489}
490
491ScopedAStatus Usb::queryPortStatus(int64_t in_transactionId) {
492 std::vector<PortStatus> currentPortStatus;
493
494 queryVersionHelper(this, &currentPortStatus);
495 pthread_mutex_lock(&mLock);
496 if (mCallback != NULL) {
497 ScopedAStatus ret = mCallback->notifyQueryPortStatus(
498 "all", Status::SUCCESS, in_transactionId);
499 if (!ret.isOk())
500 ALOGE("notifyQueryPortStatus error %s", ret.getDescription().c_str());
501 } else {
502 ALOGE("Not notifying the userspace. Callback is not set");
503 }
504 pthread_mutex_unlock(&mLock);
505
506 return ScopedAStatus::ok();
507}
508
509ScopedAStatus Usb::enableContaminantPresenceDetection(const string& in_portName,
510 bool /*in_enable*/, int64_t in_transactionId) {
511 std::vector<PortStatus> currentPortStatus;
512
513 pthread_mutex_lock(&mLock);
514 if (mCallback != NULL) {
515 ScopedAStatus ret = mCallback->notifyContaminantEnabledStatus(
516 in_portName, false, Status::ERROR, in_transactionId);
517 if (!ret.isOk())
518 ALOGE("enableContaminantPresenceDetection error %s", ret.getDescription().c_str());
519 } else {
520 ALOGE("Not notifying the userspace. Callback is not set");
521 }
522 pthread_mutex_unlock(&mLock);
523
524 queryVersionHelper(this, &currentPortStatus);
525 return ScopedAStatus::ok();
526}
527
528
529struct data {
530 int uevent_fd;
531 ::aidl::android::hardware::usb::Usb *usb;
532};
533
534static void uevent_event(uint32_t /*epevents*/, struct data *payload) {
535 char msg[UEVENT_MSG_LEN + 2];
536 char *cp;
537 int n;
538
539 n = uevent_kernel_multicast_recv(payload->uevent_fd, msg, UEVENT_MSG_LEN);
540 if (n <= 0)
541 return;
542 if (n >= UEVENT_MSG_LEN) /* overflow -- discard */
543 return;
544
545 msg[n] = '\0';
546 msg[n + 1] = '\0';
547 cp = msg;
548
549 while (*cp) {
550 if (std::regex_match(cp, std::regex("(add)(.*)(-partner)"))) {
551 ALOGI("partner added");
552 pthread_mutex_lock(&payload->usb->mPartnerLock);
553 payload->usb->mPartnerUp = true;
554 pthread_cond_signal(&payload->usb->mPartnerCV);
555 pthread_mutex_unlock(&payload->usb->mPartnerLock);
556 } else if (!strncmp(cp, "DEVTYPE=typec_", strlen("DEVTYPE=typec_"))) {
557 std::vector<PortStatus> currentPortStatus;
558 queryVersionHelper(payload->usb, &currentPortStatus);
559
560 // Role switch is not in progress and port is in disconnected state
561 if (!pthread_mutex_trylock(&payload->usb->mRoleSwitchLock)) {
562 for (unsigned long i = 0; i < currentPortStatus.size(); i++) {
563 DIR *dp =
564 opendir(string(kTypecPath +
565 string(currentPortStatus[i].portName.c_str()) +
566 "-partner").c_str());
567 if (dp == NULL) {
568 switchToDrp(currentPortStatus[i].portName);
569 } else {
570 closedir(dp);
571 }
572 }
573 pthread_mutex_unlock(&payload->usb->mRoleSwitchLock);
574 }
575 break;
576 } /* advance to after the next \0 */
577 while (*cp++) {
578 }
579 }
580}
581
582void *work(void *param) {
583 int epoll_fd, uevent_fd;
584 struct epoll_event ev;
585 int nevents = 0;
586 struct data payload;
587
588 uevent_fd = uevent_open_socket(UEVENT_MAX_EVENTS * UEVENT_MSG_LEN, true);
589
590 if (uevent_fd < 0) {
591 ALOGE("uevent_init: uevent_open_socket failed\n");
592 return NULL;
593 }
594
595 payload.uevent_fd = uevent_fd;
596 payload.usb = (::aidl::android::hardware::usb::Usb *)param;
597
598 fcntl(uevent_fd, F_SETFL, O_NONBLOCK);
599
600 ev.events = EPOLLIN;
601 ev.data.ptr = (void *)uevent_event;
602
603 epoll_fd = epoll_create(UEVENT_MAX_EVENTS);
604 if (epoll_fd == -1) {
605 ALOGE("epoll_create failed; errno=%d", errno);
606 goto error;
607 }
608
609 if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, uevent_fd, &ev) == -1) {
610 ALOGE("epoll_ctl failed; errno=%d", errno);
611 goto error;
612 }
613
614 while (!destroyThread) {
615 struct epoll_event events[UEVENT_MAX_EVENTS];
616
617 nevents = epoll_wait(epoll_fd, events, UEVENT_MAX_EVENTS, -1);
618 if (nevents == -1) {
619 if (errno == EINTR)
620 continue;
621 ALOGE("usb epoll_wait failed; errno=%d", errno);
622 break;
623 }
624
625 for (int n = 0; n < nevents; ++n) {
626 if (events[n].data.ptr)
627 (*(void (*)(int, struct data *payload))events[n].data.ptr)(events[n].events,
628 &payload);
629 }
630 }
631
632 ALOGI("exiting worker thread");
633error:
634 close(uevent_fd);
635
636 if (epoll_fd >= 0)
637 close(epoll_fd);
638
639 return NULL;
640}
641
642void sighandler(int sig) {
643 if (sig == SIGUSR1) {
644 destroyThread = true;
645 ALOGI("destroy set");
646 return;
647 }
648 signal(SIGUSR1, sighandler);
649}
650
651ScopedAStatus Usb::setCallback(
652 const shared_ptr<IUsbCallback>& in_callback) {
653
654 pthread_mutex_lock(&mLock);
655 if ((mCallback == NULL && in_callback == NULL) ||
656 (mCallback != NULL && in_callback != NULL)) {
657 mCallback = in_callback;
658 pthread_mutex_unlock(&mLock);
659 return ScopedAStatus::ok();
660 }
661
662 mCallback = in_callback;
663 ALOGI("registering callback");
664
665 if (mCallback == NULL) {
666 if (!pthread_kill(mPoll, SIGUSR1)) {
667 pthread_join(mPoll, NULL);
668 ALOGI("pthread destroyed");
669 }
670 pthread_mutex_unlock(&mLock);
671 return ScopedAStatus::ok();
672 }
673
674 destroyThread = false;
675 signal(SIGUSR1, sighandler);
676
677 /*
678 * Create a background thread if the old callback value is NULL
679 * and being updated with a new value.
680 */
681 if (pthread_create(&mPoll, NULL, work, this)) {
682 ALOGE("pthread creation failed %d", errno);
683 mCallback = NULL;
684 }
685
686 pthread_mutex_unlock(&mLock);
687 return ScopedAStatus::ok();
688}
689
690} // namespace usb
691} // namespace hardware
692} // namespace android
693} // aidl