| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2007 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 |  | 
| Yabin Cui | aed3c61 | 2015-09-22 15:52:57 -0700 | [diff] [blame] | 17 | #define TRACE_TAG SERVICES | 
| Dan Albert | 3313426 | 2015-03-19 15:21:08 -0700 | [diff] [blame] | 18 |  | 
|  | 19 | #include "sysdeps.h" | 
|  | 20 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 21 | #include <errno.h> | 
| Dan Albert | 7664901 | 2015-02-24 15:51:19 -0800 | [diff] [blame] | 22 | #include <stddef.h> | 
|  | 23 | #include <stdio.h> | 
|  | 24 | #include <stdlib.h> | 
|  | 25 | #include <string.h> | 
|  | 26 |  | 
| Josh Gao | e1dacfc | 2017-04-12 17:00:49 -0700 | [diff] [blame] | 27 | #include <thread> | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 28 |  | 
| Elliott Hughes | 4f71319 | 2015-12-04 22:00:26 -0800 | [diff] [blame] | 29 | #include <android-base/stringprintf.h> | 
|  | 30 | #include <android-base/strings.h> | 
| Elliott Hughes | 381cfa9 | 2015-07-23 17:12:58 -0700 | [diff] [blame] | 31 | #include <cutils/sockets.h> | 
| Elliott Hughes | 6c34bba | 2015-04-17 20:11:08 -0700 | [diff] [blame] | 32 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 33 | #include "adb.h" | 
| Dan Albert | cc731cc | 2015-02-24 21:26:58 -0800 | [diff] [blame] | 34 | #include "adb_io.h" | 
| Josh Gao | 73a5ee4 | 2018-07-25 16:51:59 -0700 | [diff] [blame] | 35 | #include "adb_unique_fd.h" | 
| Elliott Hughes | 3d5f60d | 2015-07-18 12:21:30 -0700 | [diff] [blame] | 36 | #include "adb_utils.h" | 
| David Pursell | 70ef7b4 | 2015-09-30 13:35:42 -0700 | [diff] [blame] | 37 | #include "services.h" | 
| Josh Gao | cfb2141 | 2016-08-24 18:38:44 -0700 | [diff] [blame] | 38 | #include "socket_spec.h" | 
| Josh Gao | 0985547 | 2016-02-19 10:42:40 -0800 | [diff] [blame] | 39 | #include "sysdeps.h" | 
| Dan Albert | 7664901 | 2015-02-24 15:51:19 -0800 | [diff] [blame] | 40 | #include "transport.h" | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 41 |  | 
| Luis Hector Chavez | 095792c | 2018-07-18 19:40:12 -0700 | [diff] [blame] | 42 | namespace { | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 43 |  | 
| Josh Gao | 73a5ee4 | 2018-07-25 16:51:59 -0700 | [diff] [blame] | 44 | void service_bootstrap_func(std::string service_name, std::function<void(unique_fd)> func, | 
|  | 45 | unique_fd fd) { | 
| Luis Hector Chavez | 095792c | 2018-07-18 19:40:12 -0700 | [diff] [blame] | 46 | adb_thread_setname(android::base::StringPrintf("%s svc %d", service_name.c_str(), fd.get())); | 
|  | 47 | func(std::move(fd)); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 48 | } | 
|  | 49 |  | 
| Josh Gao | 997cfac | 2018-07-25 18:15:52 -0700 | [diff] [blame] | 50 | }  // namespace | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 51 |  | 
| Josh Gao | 73a5ee4 | 2018-07-25 16:51:59 -0700 | [diff] [blame] | 52 | unique_fd create_service_thread(const char* service_name, std::function<void(unique_fd)> func) { | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 53 | int s[2]; | 
| Dan Albert | bac3474 | 2015-02-25 17:51:28 -0800 | [diff] [blame] | 54 | if (adb_socketpair(s)) { | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 55 | printf("cannot create service socket pair\n"); | 
| Josh Gao | 73a5ee4 | 2018-07-25 16:51:59 -0700 | [diff] [blame] | 56 | return unique_fd(); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 57 | } | 
| Yabin Cui | 7a3f8d6 | 2015-09-02 17:44:28 -0700 | [diff] [blame] | 58 | D("socketpair: (%d,%d)", s[0], s[1]); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 59 |  | 
| Jerry Zhang | 2f8c60b | 2017-02-10 17:45:27 -0800 | [diff] [blame] | 60 | #if !ADB_HOST | 
| Luis Hector Chavez | 095792c | 2018-07-18 19:40:12 -0700 | [diff] [blame] | 61 | if (strcmp(service_name, "sync") == 0) { | 
| Jerry Zhang | 2f8c60b | 2017-02-10 17:45:27 -0800 | [diff] [blame] | 62 | // Set file sync service socket to maximum size | 
|  | 63 | int max_buf = LINUX_MAX_SOCKET_SIZE; | 
|  | 64 | adb_setsockopt(s[0], SOL_SOCKET, SO_SNDBUF, &max_buf, sizeof(max_buf)); | 
|  | 65 | adb_setsockopt(s[1], SOL_SOCKET, SO_SNDBUF, &max_buf, sizeof(max_buf)); | 
|  | 66 | } | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 67 | #endif  // !ADB_HOST | 
| Jerry Zhang | 2f8c60b | 2017-02-10 17:45:27 -0800 | [diff] [blame] | 68 |  | 
| Josh Gao | 73a5ee4 | 2018-07-25 16:51:59 -0700 | [diff] [blame] | 69 | std::thread(service_bootstrap_func, service_name, func, unique_fd(s[1])).detach(); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 70 |  | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 71 | D("service thread started, %d:%d", s[0], s[1]); | 
| Josh Gao | 73a5ee4 | 2018-07-25 16:51:59 -0700 | [diff] [blame] | 72 | return unique_fd(s[0]); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 73 | } | 
|  | 74 |  | 
| Josh Gao | 74ccdf9 | 2019-01-23 15:36:42 -0800 | [diff] [blame] | 75 | unique_fd service_to_fd(std::string_view name, atransport* transport) { | 
| Cody Schuffelen | af0e220 | 2019-01-02 14:17:29 -0800 | [diff] [blame] | 76 | unique_fd ret; | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 77 |  | 
| Josh Gao | cfb2141 | 2016-08-24 18:38:44 -0700 | [diff] [blame] | 78 | if (is_socket_spec(name)) { | 
|  | 79 | std::string error; | 
| Cody Schuffelen | af0e220 | 2019-01-02 14:17:29 -0800 | [diff] [blame] | 80 | if (!socket_spec_connect(&ret, name, nullptr, nullptr, &error)) { | 
| Josh Gao | cfb2141 | 2016-08-24 18:38:44 -0700 | [diff] [blame] | 81 | LOG(ERROR) << "failed to connect to socket '" << name << "': " << error; | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 82 | } | 
| Josh Gao | 997cfac | 2018-07-25 18:15:52 -0700 | [diff] [blame] | 83 | } else { | 
| Benoit Goby | 9470c2f | 2013-02-20 15:04:53 -0800 | [diff] [blame] | 84 | #if !ADB_HOST | 
| Cody Schuffelen | af0e220 | 2019-01-02 14:17:29 -0800 | [diff] [blame] | 85 | ret = daemon_service_to_fd(name, transport); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 86 | #endif | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 87 | } | 
| Josh Gao | 997cfac | 2018-07-25 18:15:52 -0700 | [diff] [blame] | 88 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 89 | if (ret >= 0) { | 
| Josh Gao | 74ccdf9 | 2019-01-23 15:36:42 -0800 | [diff] [blame] | 90 | close_on_exec(ret.get()); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 91 | } | 
| Josh Gao | 74ccdf9 | 2019-01-23 15:36:42 -0800 | [diff] [blame] | 92 | return ret; | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 93 | } | 
|  | 94 |  | 
|  | 95 | #if ADB_HOST | 
|  | 96 | struct state_info { | 
| Elliott Hughes | 3bd73c1 | 2015-05-05 13:10:43 -0700 | [diff] [blame] | 97 | TransportType transport_type; | 
| Leo Sartre | 1fbc9db | 2015-11-27 18:56:48 +0100 | [diff] [blame] | 98 | std::string serial; | 
| Josh Gao | b122b17 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 99 | TransportId transport_id; | 
| Dan Albert | dcd78a1 | 2015-05-18 16:43:57 -0700 | [diff] [blame] | 100 | ConnectionState state; | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 101 | }; | 
|  | 102 |  | 
| Josh Gao | 74ccdf9 | 2019-01-23 15:36:42 -0800 | [diff] [blame] | 103 | static void wait_for_state(int fd, state_info* sinfo) { | 
| Yabin Cui | 7a3f8d6 | 2015-09-02 17:44:28 -0700 | [diff] [blame] | 104 | D("wait_for_state %d", sinfo->state); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 105 |  | 
| Elliott Hughes | 8d28e19 | 2015-10-07 14:55:10 -0700 | [diff] [blame] | 106 | while (true) { | 
|  | 107 | bool is_ambiguous = false; | 
|  | 108 | std::string error = "unknown error"; | 
| Yi Kong | aed415c | 2018-07-13 18:15:16 -0700 | [diff] [blame] | 109 | const char* serial = sinfo->serial.length() ? sinfo->serial.c_str() : nullptr; | 
| Josh Gao | b122b17 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 110 | atransport* t = acquire_one_transport(sinfo->transport_type, serial, sinfo->transport_id, | 
|  | 111 | &is_ambiguous, &error); | 
| Josh Gao | 1e9e471 | 2019-02-22 14:01:36 -0800 | [diff] [blame] | 112 | if (sinfo->state == kCsOffline) { | 
|  | 113 | // wait-for-disconnect uses kCsOffline, we don't actually want to wait for 'offline'. | 
|  | 114 | if (t == nullptr) { | 
|  | 115 | SendOkay(fd); | 
|  | 116 | break; | 
|  | 117 | } | 
|  | 118 | } else if (t != nullptr && | 
|  | 119 | (sinfo->state == kCsAny || sinfo->state == t->GetConnectionState())) { | 
| Elliott Hughes | 8d28e19 | 2015-10-07 14:55:10 -0700 | [diff] [blame] | 120 | SendOkay(fd); | 
|  | 121 | break; | 
| Josh Gao | 1e9e471 | 2019-02-22 14:01:36 -0800 | [diff] [blame] | 122 | } | 
|  | 123 |  | 
|  | 124 | if (!is_ambiguous) { | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 125 | adb_pollfd pfd = {.fd = fd, .events = POLLIN}; | 
| Josh Gao | 1e9e471 | 2019-02-22 14:01:36 -0800 | [diff] [blame] | 126 | int rc = adb_poll(&pfd, 1, 100); | 
| Josh Gao | 0985547 | 2016-02-19 10:42:40 -0800 | [diff] [blame] | 127 | if (rc < 0) { | 
|  | 128 | SendFail(fd, error); | 
|  | 129 | break; | 
|  | 130 | } else if (rc > 0 && (pfd.revents & POLLHUP) != 0) { | 
|  | 131 | // The other end of the socket is closed, probably because the other side was | 
|  | 132 | // terminated, bail out. | 
|  | 133 | break; | 
|  | 134 | } | 
|  | 135 |  | 
| Elliott Hughes | 8d28e19 | 2015-10-07 14:55:10 -0700 | [diff] [blame] | 136 | // Try again... | 
|  | 137 | } else { | 
|  | 138 | SendFail(fd, error); | 
|  | 139 | break; | 
|  | 140 | } | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 141 | } | 
|  | 142 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 143 | adb_close(fd); | 
| Yabin Cui | 7a3f8d6 | 2015-09-02 17:44:28 -0700 | [diff] [blame] | 144 | D("wait_for_state is done"); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 145 | } | 
| Benoit Goby | 1c45ee9 | 2013-03-29 18:22:36 -0700 | [diff] [blame] | 146 |  | 
| Elliott Hughes | e67f1f8 | 2015-04-30 17:32:03 -0700 | [diff] [blame] | 147 | void connect_emulator(const std::string& port_spec, std::string* response) { | 
|  | 148 | std::vector<std::string> pieces = android::base::Split(port_spec, ","); | 
|  | 149 | if (pieces.size() != 2) { | 
|  | 150 | *response = android::base::StringPrintf("unable to parse '%s' as <console port>,<adb port>", | 
|  | 151 | port_spec.c_str()); | 
| Benoit Goby | 1c45ee9 | 2013-03-29 18:22:36 -0700 | [diff] [blame] | 152 | return; | 
|  | 153 | } | 
|  | 154 |  | 
| Yi Kong | aed415c | 2018-07-13 18:15:16 -0700 | [diff] [blame] | 155 | int console_port = strtol(pieces[0].c_str(), nullptr, 0); | 
|  | 156 | int adb_port = strtol(pieces[1].c_str(), nullptr, 0); | 
| Elliott Hughes | e67f1f8 | 2015-04-30 17:32:03 -0700 | [diff] [blame] | 157 | if (console_port <= 0 || adb_port <= 0) { | 
|  | 158 | *response = android::base::StringPrintf("Invalid port numbers: %s", port_spec.c_str()); | 
| Benoit Goby | 1c45ee9 | 2013-03-29 18:22:36 -0700 | [diff] [blame] | 159 | return; | 
|  | 160 | } | 
|  | 161 |  | 
| Elliott Hughes | e67f1f8 | 2015-04-30 17:32:03 -0700 | [diff] [blame] | 162 | // Check if the emulator is already known. | 
|  | 163 | // Note: There's a small but harmless race condition here: An emulator not | 
|  | 164 | // present just yet could be registered by another invocation right | 
|  | 165 | // after doing this check here. However, local_connect protects | 
|  | 166 | // against double-registration too. From here, a better error message | 
|  | 167 | // can be produced. In the case of the race condition, the very specific | 
|  | 168 | // error message won't be shown, but the data doesn't get corrupted. | 
| Benoit Goby | 1c45ee9 | 2013-03-29 18:22:36 -0700 | [diff] [blame] | 169 | atransport* known_emulator = find_emulator_transport_by_adb_port(adb_port); | 
| Elliott Hughes | e67f1f8 | 2015-04-30 17:32:03 -0700 | [diff] [blame] | 170 | if (known_emulator != nullptr) { | 
|  | 171 | *response = android::base::StringPrintf("Emulator already registered on port %d", adb_port); | 
| Benoit Goby | 1c45ee9 | 2013-03-29 18:22:36 -0700 | [diff] [blame] | 172 | return; | 
|  | 173 | } | 
|  | 174 |  | 
| Elliott Hughes | e67f1f8 | 2015-04-30 17:32:03 -0700 | [diff] [blame] | 175 | // Preconditions met, try to connect to the emulator. | 
| Elliott Hughes | 381cfa9 | 2015-07-23 17:12:58 -0700 | [diff] [blame] | 176 | std::string error; | 
|  | 177 | if (!local_connect_arbitrary_ports(console_port, adb_port, &error)) { | 
| Elliott Hughes | e67f1f8 | 2015-04-30 17:32:03 -0700 | [diff] [blame] | 178 | *response = android::base::StringPrintf("Connected to emulator on ports %d,%d", | 
|  | 179 | console_port, adb_port); | 
| Benoit Goby | 1c45ee9 | 2013-03-29 18:22:36 -0700 | [diff] [blame] | 180 | } else { | 
| Elliott Hughes | 381cfa9 | 2015-07-23 17:12:58 -0700 | [diff] [blame] | 181 | *response = android::base::StringPrintf("Could not connect to emulator on ports %d,%d: %s", | 
|  | 182 | console_port, adb_port, error.c_str()); | 
| Benoit Goby | 1c45ee9 | 2013-03-29 18:22:36 -0700 | [diff] [blame] | 183 | } | 
|  | 184 | } | 
|  | 185 |  | 
| Josh Gao | 73a5ee4 | 2018-07-25 16:51:59 -0700 | [diff] [blame] | 186 | static void connect_service(unique_fd fd, std::string host) { | 
| Elliott Hughes | e67f1f8 | 2015-04-30 17:32:03 -0700 | [diff] [blame] | 187 | std::string response; | 
| Luis Hector Chavez | 095792c | 2018-07-18 19:40:12 -0700 | [diff] [blame] | 188 | if (!strncmp(host.c_str(), "emu:", 4)) { | 
|  | 189 | connect_emulator(host.c_str() + 4, &response); | 
| Benoit Goby | 1c45ee9 | 2013-03-29 18:22:36 -0700 | [diff] [blame] | 190 | } else { | 
| Luis Hector Chavez | 095792c | 2018-07-18 19:40:12 -0700 | [diff] [blame] | 191 | connect_device(host.c_str(), &response); | 
| Benoit Goby | 1c45ee9 | 2013-03-29 18:22:36 -0700 | [diff] [blame] | 192 | } | 
|  | 193 |  | 
|  | 194 | // Send response for emulator and device | 
| Luis Hector Chavez | 095792c | 2018-07-18 19:40:12 -0700 | [diff] [blame] | 195 | SendProtocolString(fd.get(), response); | 
| Benoit Goby | 1c45ee9 | 2013-03-29 18:22:36 -0700 | [diff] [blame] | 196 | } | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 197 | #endif | 
|  | 198 |  | 
|  | 199 | #if ADB_HOST | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 200 | asocket* host_service_to_socket(std::string_view name, std::string_view serial, | 
|  | 201 | TransportId transport_id) { | 
|  | 202 | if (name == "track-devices") { | 
| Josh Gao | b0c1802 | 2017-08-14 18:57:54 -0700 | [diff] [blame] | 203 | return create_device_tracker(false); | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 204 | } else if (name == "track-devices-l") { | 
| Josh Gao | b0c1802 | 2017-08-14 18:57:54 -0700 | [diff] [blame] | 205 | return create_device_tracker(true); | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 206 | } else if (ConsumePrefix(&name, "wait-for-")) { | 
| Josh Gao | 74ccdf9 | 2019-01-23 15:36:42 -0800 | [diff] [blame] | 207 | std::shared_ptr<state_info> sinfo = std::make_shared<state_info>(); | 
| Leo Sartre | 1fbc9db | 2015-11-27 18:56:48 +0100 | [diff] [blame] | 208 | if (sinfo == nullptr) { | 
|  | 209 | fprintf(stderr, "couldn't allocate state_info: %s", strerror(errno)); | 
|  | 210 | return nullptr; | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 211 | } | 
|  | 212 |  | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 213 | sinfo->serial = serial; | 
| Josh Gao | b122b17 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 214 | sinfo->transport_id = transport_id; | 
| Leo Sartre | 1fbc9db | 2015-11-27 18:56:48 +0100 | [diff] [blame] | 215 |  | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 216 | if (ConsumePrefix(&name, "local")) { | 
| Leo Sartre | 1fbc9db | 2015-11-27 18:56:48 +0100 | [diff] [blame] | 217 | sinfo->transport_type = kTransportLocal; | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 218 | } else if (ConsumePrefix(&name, "usb")) { | 
| Leo Sartre | 1fbc9db | 2015-11-27 18:56:48 +0100 | [diff] [blame] | 219 | sinfo->transport_type = kTransportUsb; | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 220 | } else if (ConsumePrefix(&name, "any")) { | 
| Leo Sartre | 1fbc9db | 2015-11-27 18:56:48 +0100 | [diff] [blame] | 221 | sinfo->transport_type = kTransportAny; | 
|  | 222 | } else { | 
|  | 223 | return nullptr; | 
|  | 224 | } | 
|  | 225 |  | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 226 | if (name == "-device") { | 
| Leo Sartre | 1fbc9db | 2015-11-27 18:56:48 +0100 | [diff] [blame] | 227 | sinfo->state = kCsDevice; | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 228 | } else if (name == "-recovery") { | 
| Leo Sartre | 1fbc9db | 2015-11-27 18:56:48 +0100 | [diff] [blame] | 229 | sinfo->state = kCsRecovery; | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 230 | } else if (name == "-sideload") { | 
| Leo Sartre | 1fbc9db | 2015-11-27 18:56:48 +0100 | [diff] [blame] | 231 | sinfo->state = kCsSideload; | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 232 | } else if (name == "-bootloader") { | 
| Leo Sartre | 1fbc9db | 2015-11-27 18:56:48 +0100 | [diff] [blame] | 233 | sinfo->state = kCsBootloader; | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 234 | } else if (name == "-any") { | 
| Josh Gao | 86441c3 | 2016-04-13 12:18:58 -0700 | [diff] [blame] | 235 | sinfo->state = kCsAny; | 
| Josh Gao | 1e9e471 | 2019-02-22 14:01:36 -0800 | [diff] [blame] | 236 | } else if (name == "-disconnect") { | 
|  | 237 | sinfo->state = kCsOffline; | 
| Leo Sartre | 1fbc9db | 2015-11-27 18:56:48 +0100 | [diff] [blame] | 238 | } else { | 
|  | 239 | return nullptr; | 
|  | 240 | } | 
|  | 241 |  | 
| Josh Gao | 74ccdf9 | 2019-01-23 15:36:42 -0800 | [diff] [blame] | 242 | unique_fd fd = create_service_thread("wait", [sinfo](int fd) { | 
|  | 243 | wait_for_state(fd, sinfo.get()); | 
|  | 244 | }); | 
|  | 245 | return create_local_socket(std::move(fd)); | 
| Josh Gao | 0ecc402 | 2019-02-22 13:41:55 -0800 | [diff] [blame] | 246 | } else if (ConsumePrefix(&name, "connect:")) { | 
|  | 247 | std::string host(name); | 
| Josh Gao | 74ccdf9 | 2019-01-23 15:36:42 -0800 | [diff] [blame] | 248 | unique_fd fd = create_service_thread( | 
|  | 249 | "connect", std::bind(connect_service, std::placeholders::_1, host)); | 
|  | 250 | return create_local_socket(std::move(fd)); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 251 | } | 
| Yi Kong | aed415c | 2018-07-13 18:15:16 -0700 | [diff] [blame] | 252 | return nullptr; | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 253 | } | 
|  | 254 | #endif /* ADB_HOST */ |