blob: 5a750eea1a9a267eb32bb075a43fb770d19e5386 [file] [log] [blame]
JP Abgrall408fa572011-03-16 15:57:42 -07001/*
2 * Copyright (C) 2011 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#ifndef __TRANSPORT_H
18#define __TRANSPORT_H
19
Dan Alberte9fca142015-02-18 18:03:26 -080020#include <sys/types.h>
21
Yabin Cuib5e11412017-03-10 16:01:01 -080022#include <atomic>
Luis Hector Chavez56fe7532018-04-17 14:25:04 -070023#include <chrono>
Josh Gao0bbf69c2018-02-16 13:24:58 -080024#include <condition_variable>
Elliott Hughes0aeb5052016-06-29 17:42:01 -070025#include <deque>
Josh Gao22d2b3e2016-10-27 14:01:08 -070026#include <functional>
Yabin Cuib3298242015-08-28 15:09:44 -070027#include <list>
Josh Gao2e671202016-08-18 22:00:12 -070028#include <memory>
Yabin Cuib5e11412017-03-10 16:01:01 -080029#include <mutex>
Elliott Hughes7be29c82015-04-16 22:54:44 -070030#include <string>
Cody Schuffelena05b64d2019-01-04 18:51:11 -080031#include <string_view>
Josh Gao0bbf69c2018-02-16 13:24:58 -080032#include <thread>
Dan Albert1792c232015-05-18 13:06:53 -070033#include <unordered_set>
Dan Albert76649012015-02-24 15:51:19 -080034
Luis Hector Chavez56fe7532018-04-17 14:25:04 -070035#include <android-base/macros.h>
Josh Gaoc251ec52018-04-03 12:55:18 -070036#include <android-base/thread_annotations.h>
Elliott Hughes0aeb5052016-06-29 17:42:01 -070037#include <openssl/rsa.h>
38
Josh Gaob800d882018-01-28 20:32:46 -080039#include "adb.h"
40#include "adb_unique_fd.h"
Josh Gao607fd542019-12-09 15:44:57 -080041#include "types.h"
Josh Gaoce5ce872018-12-11 13:11:52 -080042#include "usb.h"
Josh Gaob800d882018-01-28 20:32:46 -080043
Dan Albert1792c232015-05-18 13:06:53 -070044typedef std::unordered_set<std::string> FeatureSet;
45
46const FeatureSet& supported_features();
47
David Pursell4e2fd362015-09-22 10:43:08 -070048// Encodes and decodes FeatureSet objects into human-readable strings.
49std::string FeatureSetToString(const FeatureSet& features);
50FeatureSet StringToFeatureSet(const std::string& features_string);
51
David Pursell70ef7b42015-09-30 13:35:42 -070052// Returns true if both local features and |feature_set| support |feature|.
53bool CanUseFeature(const FeatureSet& feature_set, const std::string& feature);
54
David Pursell4e2fd362015-09-22 10:43:08 -070055// Do not use any of [:;=,] in feature strings, they have special meaning
56// in the connection banner.
Todd Kennedy6fa848a2015-11-03 16:53:08 -080057extern const char* const kFeatureShell2;
58// The 'cmd' command is available
59extern const char* const kFeatureCmd;
Josh Gao5a1e3fd2016-12-05 17:11:34 -080060extern const char* const kFeatureStat2;
Josh Gao34a478f2019-08-07 14:23:17 -070061extern const char* const kFeatureLs2;
Josh Gao5d1756c2017-02-22 17:07:01 -080062// The server is running with libusb enabled.
63extern const char* const kFeatureLibusb;
Josh Gaofb085102018-10-22 13:00:05 -070064// adbd supports `push --sync`.
Dan Albert5176df82017-05-23 14:30:00 -070065extern const char* const kFeaturePushSync;
Josh Gaofb085102018-10-22 13:00:05 -070066// adbd supports installing .apex packages.
Dario Freni29814de2018-10-04 16:26:40 +010067extern const char* const kFeatureApex;
Josh Gaofb085102018-10-22 13:00:05 -070068// adbd has b/110953234 fixed.
69extern const char* const kFeatureFixedPushMkdir;
Alex Buynytskyy7ea92d82019-09-13 14:19:01 -070070// adbd supports android binder bridge (abb) in interactive mode using shell protocol.
Alex Buynytskyy01a65ee2019-01-17 13:13:56 -080071extern const char* const kFeatureAbb;
Alex Buynytskyy7ea92d82019-09-13 14:19:01 -070072// adbd supports abb using raw pipe.
73extern const char* const kFeatureAbbExec;
Josh Gao7b1cb662019-02-20 13:01:40 -080074// adbd properly updates symlink timestamps on push.
75extern const char* const kFeatureFixedPushSymlinkTimestamp;
Josh Gao8c2198c2019-07-11 14:15:32 -070076extern const char* const kFeatureRemountShell;
David Pursell0955c662015-08-31 10:42:13 -070077
Josh Gaob122b172017-08-16 16:57:01 -070078TransportId NextTransportId();
79
Josh Gao0bbf69c2018-02-16 13:24:58 -080080// Abstraction for a non-blocking packet transport.
Josh Gaob800d882018-01-28 20:32:46 -080081struct Connection {
82 Connection() = default;
Josh Gaob800d882018-01-28 20:32:46 -080083 virtual ~Connection() = default;
84
Josh Gao0bbf69c2018-02-16 13:24:58 -080085 void SetTransportName(std::string transport_name) {
86 transport_name_ = std::move(transport_name);
87 }
88
89 using ReadCallback = std::function<bool(Connection*, std::unique_ptr<apacket>)>;
90 void SetReadCallback(ReadCallback callback) {
91 CHECK(!read_callback_);
92 read_callback_ = callback;
93 }
94
95 // Called after the Connection has terminated, either by an error or because Stop was called.
96 using ErrorCallback = std::function<void(Connection*, const std::string&)>;
97 void SetErrorCallback(ErrorCallback callback) {
98 CHECK(!error_callback_);
99 error_callback_ = callback;
100 }
101
102 virtual bool Write(std::unique_ptr<apacket> packet) = 0;
103
104 virtual void Start() = 0;
105 virtual void Stop() = 0;
106
Josh Gao3705b342019-03-28 15:47:44 -0700107 // Stop, and reset the device if it's a USB connection.
108 virtual void Reset();
109
Josh Gao0bbf69c2018-02-16 13:24:58 -0800110 std::string transport_name_;
111 ReadCallback read_callback_;
112 ErrorCallback error_callback_;
Josh Gao6082e7d2018-04-05 16:16:04 -0700113
114 static std::unique_ptr<Connection> FromFd(unique_fd fd);
Josh Gao0bbf69c2018-02-16 13:24:58 -0800115};
116
117// Abstraction for a blocking packet transport.
118struct BlockingConnection {
119 BlockingConnection() = default;
120 BlockingConnection(const BlockingConnection& copy) = delete;
121 BlockingConnection(BlockingConnection&& move) = delete;
122
123 // Destroy a BlockingConnection. Formerly known as 'Close' in atransport.
124 virtual ~BlockingConnection() = default;
125
Josh Gaob800d882018-01-28 20:32:46 -0800126 // Read/Write a packet. These functions are concurrently called from a transport's reader/writer
127 // threads.
128 virtual bool Read(apacket* packet) = 0;
129 virtual bool Write(apacket* packet) = 0;
130
131 // Terminate a connection.
132 // This method must be thread-safe, and must cause concurrent Reads/Writes to terminate.
133 // Formerly known as 'Kick' in atransport.
134 virtual void Close() = 0;
Josh Gao3705b342019-03-28 15:47:44 -0700135
136 // Terminate a connection, and reset it.
137 virtual void Reset() = 0;
Josh Gaob800d882018-01-28 20:32:46 -0800138};
139
Josh Gao0bbf69c2018-02-16 13:24:58 -0800140struct BlockingConnectionAdapter : public Connection {
141 explicit BlockingConnectionAdapter(std::unique_ptr<BlockingConnection> connection);
142
143 virtual ~BlockingConnectionAdapter();
144
145 virtual bool Write(std::unique_ptr<apacket> packet) override final;
146
147 virtual void Start() override final;
148 virtual void Stop() override final;
149
Josh Gao3705b342019-03-28 15:47:44 -0700150 virtual void Reset() override final;
151
Josh Gaoc251ec52018-04-03 12:55:18 -0700152 bool started_ GUARDED_BY(mutex_) = false;
153 bool stopped_ GUARDED_BY(mutex_) = false;
Josh Gao0bbf69c2018-02-16 13:24:58 -0800154
155 std::unique_ptr<BlockingConnection> underlying_;
Josh Gaoc251ec52018-04-03 12:55:18 -0700156 std::thread read_thread_ GUARDED_BY(mutex_);
157 std::thread write_thread_ GUARDED_BY(mutex_);
Josh Gao0bbf69c2018-02-16 13:24:58 -0800158
Josh Gaoc251ec52018-04-03 12:55:18 -0700159 std::deque<std::unique_ptr<apacket>> write_queue_ GUARDED_BY(mutex_);
Josh Gao0bbf69c2018-02-16 13:24:58 -0800160 std::mutex mutex_;
161 std::condition_variable cv_;
162
163 std::once_flag error_flag_;
164};
165
166struct FdConnection : public BlockingConnection {
Josh Gaob800d882018-01-28 20:32:46 -0800167 explicit FdConnection(unique_fd fd) : fd_(std::move(fd)) {}
168
169 bool Read(apacket* packet) override final;
170 bool Write(apacket* packet) override final;
171
172 void Close() override;
Josh Gao3705b342019-03-28 15:47:44 -0700173 virtual void Reset() override final { Close(); }
Josh Gaob800d882018-01-28 20:32:46 -0800174
175 private:
176 unique_fd fd_;
177};
178
Josh Gao0bbf69c2018-02-16 13:24:58 -0800179struct UsbConnection : public BlockingConnection {
Josh Gaob800d882018-01-28 20:32:46 -0800180 explicit UsbConnection(usb_handle* handle) : handle_(handle) {}
181 ~UsbConnection();
182
183 bool Read(apacket* packet) override final;
184 bool Write(apacket* packet) override final;
185
186 void Close() override final;
Josh Gao3705b342019-03-28 15:47:44 -0700187 virtual void Reset() override final;
Josh Gaob800d882018-01-28 20:32:46 -0800188
189 usb_handle* handle_;
190};
191
Luis Hector Chavez56fe7532018-04-17 14:25:04 -0700192// Waits for a transport's connection to be not pending. This is a separate
193// object so that the transport can be destroyed and another thread can be
194// notified of it in a race-free way.
195class ConnectionWaitable {
196 public:
197 ConnectionWaitable() = default;
198 ~ConnectionWaitable() = default;
199
200 // Waits until the first CNXN packet has been received by the owning
201 // atransport, or the specified timeout has elapsed. Can be called from any
202 // thread.
203 //
204 // Returns true if the CNXN packet was received in a timely fashion, false
205 // otherwise.
206 bool WaitForConnection(std::chrono::milliseconds timeout);
207
208 // Can be called from any thread when the connection stops being pending.
209 // Only the first invocation will be acknowledged, the rest will be no-ops.
210 void SetConnectionEstablished(bool success);
211
212 private:
213 bool connection_established_ GUARDED_BY(mutex_) = false;
214 bool connection_established_ready_ GUARDED_BY(mutex_) = false;
215 std::mutex mutex_;
216 std::condition_variable cv_;
217
218 DISALLOW_COPY_AND_ASSIGN(ConnectionWaitable);
219};
220
Josh Gaofc2e56f2018-08-30 11:37:00 -0700221enum class ReconnectResult {
222 Retry,
223 Success,
224 Abort,
225};
226
Josh Gao607fd542019-12-09 15:44:57 -0800227class atransport : public enable_weak_from_this<atransport> {
Josh Gaob122b172017-08-16 16:57:01 -0700228 public:
Dan Albert1792c232015-05-18 13:06:53 -0700229 // TODO(danalbert): We expose waaaaaaay too much stuff because this was
230 // historically just a struct, but making the whole thing a more idiomatic
231 // class in one go is a very large change. Given how bad our testing is,
232 // it's better to do this piece by piece.
233
Josh Gaofc2e56f2018-08-30 11:37:00 -0700234 using ReconnectCallback = std::function<ReconnectResult(atransport*)>;
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700235
236 atransport(ReconnectCallback reconnect, ConnectionState state)
Luis Hector Chavez56fe7532018-04-17 14:25:04 -0700237 : id(NextTransportId()),
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700238 kicked_(false),
Luis Hector Chavez56fe7532018-04-17 14:25:04 -0700239 connection_state_(state),
Luis Hector Chavez9a388d52018-04-25 08:56:41 -0700240 connection_waitable_(std::make_shared<ConnectionWaitable>()),
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700241 connection_(nullptr),
242 reconnect_(std::move(reconnect)) {
Tim Murrayde471942017-12-07 11:40:00 -0800243 // Initialize protocol to min version for compatibility with older versions.
244 // Version will be updated post-connect.
245 protocol_version = A_VERSION_MIN;
Dan Albert1792c232015-05-18 13:06:53 -0700246 max_payload = MAX_PAYLOAD;
247 }
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700248 atransport(ConnectionState state = kCsOffline)
Josh Gaofc2e56f2018-08-30 11:37:00 -0700249 : atransport([](atransport*) { return ReconnectResult::Abort; }, state) {}
Josh Gao607fd542019-12-09 15:44:57 -0800250 ~atransport();
Dan Albert1792c232015-05-18 13:06:53 -0700251
Yabin Cuib5e11412017-03-10 16:01:01 -0800252 int Write(apacket* p);
Josh Gao3705b342019-03-28 15:47:44 -0700253 void Reset();
Yabin Cui7f274902016-04-18 11:22:34 -0700254 void Kick();
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700255 bool kicked() const { return kicked_; }
Dan Albert1792c232015-05-18 13:06:53 -0700256
Yabin Cuib5e11412017-03-10 16:01:01 -0800257 // ConnectionState can be read by all threads, but can only be written in the main thread.
258 ConnectionState GetConnectionState() const;
259 void SetConnectionState(ConnectionState state);
260
Luis Hector Chavez9a388d52018-04-25 08:56:41 -0700261 void SetConnection(std::unique_ptr<Connection> connection);
262 std::shared_ptr<Connection> connection() {
263 std::lock_guard<std::mutex> lock(mutex_);
264 return connection_;
265 }
266
Josh Gaoce5ce872018-12-11 13:11:52 -0800267 void SetUsbHandle(usb_handle* h) { usb_handle_ = h; }
268 usb_handle* GetUsbHandle() { return usb_handle_; }
269
Josh Gaob122b172017-08-16 16:57:01 -0700270 const TransportId id;
Josh Gao9a8366b2019-12-09 13:45:31 -0800271
Dan Albert1792c232015-05-18 13:06:53 -0700272 bool online = false;
273 TransportType type = kTransportAny;
274
Dan Albert1792c232015-05-18 13:06:53 -0700275 // Used to identify transports for clients.
Luis Hector Chavez6150a372018-07-18 21:18:27 -0700276 std::string serial;
277 std::string product;
278 std::string model;
279 std::string device;
280 std::string devpath;
Yabin Cuib74c6492016-04-29 16:53:52 -0700281
Josh Gao27523262019-10-22 12:30:39 -0700282#if !ADB_HOST
Michael Groover7eeda6b2019-04-25 18:33:35 -0700283 // Used to provide the key to the framework.
284 std::string auth_key;
Josh Gao27523262019-10-22 12:30:39 -0700285 uint64_t auth_id;
286#endif
Michael Groover7eeda6b2019-04-25 18:33:35 -0700287
Josh Gaob800d882018-01-28 20:32:46 -0800288 bool IsTcpDevice() const { return type == kTransportLocal; }
Dan Albert1792c232015-05-18 13:06:53 -0700289
Josh Gao3bd28792016-10-05 19:02:29 -0700290#if ADB_HOST
Josh Gao2e671202016-08-18 22:00:12 -0700291 std::shared_ptr<RSA> NextKey();
Josh Gao4414e4c2018-12-04 01:07:50 -0800292 void ResetKeys();
Josh Gao3bd28792016-10-05 19:02:29 -0700293#endif
Elliott Hughes0aeb5052016-06-29 17:42:01 -0700294
Josh Gao06d61d42016-10-06 13:31:44 -0700295 char token[TOKEN_SIZE] = {};
Dan Albert1792c232015-05-18 13:06:53 -0700296 size_t failed_auth_attempts = 0;
297
Luis Hector Chavez6150a372018-07-18 21:18:27 -0700298 std::string serial_name() const { return !serial.empty() ? serial : "<unknown>"; }
Josh Gaoffbd3362018-02-28 14:44:23 -0800299 std::string connection_state_name() const;
Dan Albert1792c232015-05-18 13:06:53 -0700300
301 void update_version(int version, size_t payload);
302 int get_protocol_version() const;
303 size_t get_max_payload() const;
304
David Pursell4e2fd362015-09-22 10:43:08 -0700305 const FeatureSet& features() const {
Dan Albert1792c232015-05-18 13:06:53 -0700306 return features_;
307 }
308
309 bool has_feature(const std::string& feature) const;
David Pursell4e2fd362015-09-22 10:43:08 -0700310
311 // Loads the transport's feature set from the given string.
312 void SetFeatures(const std::string& features_string);
Dan Albert1792c232015-05-18 13:06:53 -0700313
Yabin Cuib3298242015-08-28 15:09:44 -0700314 void AddDisconnect(adisconnect* disconnect);
315 void RemoveDisconnect(adisconnect* disconnect);
316 void RunDisconnects();
317
David Pursell3f902aa2016-03-01 08:58:26 -0800318 // Returns true if |target| matches this transport. A matching |target| can be any of:
319 // * <serial>
320 // * <devpath>
321 // * product:<product>
322 // * model:<model>
323 // * device:<device>
324 //
325 // If this is a local transport, serial will also match [tcp:|udp:]<hostname>[:port] targets.
326 // For example, serial "100.100.100.100:5555" would match any of:
327 // * 100.100.100.100
328 // * tcp:100.100.100.100
329 // * udp:100.100.100.100:5555
330 // This is to make it easier to use the same network target for both fastboot and adb.
331 bool MatchesTarget(const std::string& target) const;
332
Luis Hector Chavez56fe7532018-04-17 14:25:04 -0700333 // Notifies that the atransport is no longer waiting for the connection
334 // being established.
335 void SetConnectionEstablished(bool success);
336
337 // Gets a shared reference to the ConnectionWaitable.
338 std::shared_ptr<ConnectionWaitable> connection_waitable() { return connection_waitable_; }
339
Josh Gaofc2e56f2018-08-30 11:37:00 -0700340 // Attempts to reconnect with the underlying Connection.
341 ReconnectResult Reconnect();
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700342
Luis Hector Chavez56fe7532018-04-17 14:25:04 -0700343 private:
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700344 std::atomic<bool> kicked_;
Yabin Cui7f274902016-04-18 11:22:34 -0700345
Dan Albert1792c232015-05-18 13:06:53 -0700346 // A set of features transmitted in the banner with the initial connection.
347 // This is stored in the banner as 'features=feature0,feature1,etc'.
348 FeatureSet features_;
349 int protocol_version;
350 size_t max_payload;
351
Yabin Cuib3298242015-08-28 15:09:44 -0700352 // A list of adisconnect callbacks called when the transport is kicked.
353 std::list<adisconnect*> disconnects_;
354
Yabin Cuib5e11412017-03-10 16:01:01 -0800355 std::atomic<ConnectionState> connection_state_;
Josh Gao3bd28792016-10-05 19:02:29 -0700356#if ADB_HOST
Josh Gao2e671202016-08-18 22:00:12 -0700357 std::deque<std::shared_ptr<RSA>> keys_;
Josh Gao3bd28792016-10-05 19:02:29 -0700358#endif
Elliott Hughes0aeb5052016-06-29 17:42:01 -0700359
Luis Hector Chavez56fe7532018-04-17 14:25:04 -0700360 // A sharable object that can be used to wait for the atransport's
361 // connection to be established.
362 std::shared_ptr<ConnectionWaitable> connection_waitable_;
363
Luis Hector Chavez9a388d52018-04-25 08:56:41 -0700364 // The underlying connection object.
365 std::shared_ptr<Connection> connection_ GUARDED_BY(mutex_);
366
Josh Gaoce5ce872018-12-11 13:11:52 -0800367 // USB handle for the connection, if available.
368 usb_handle* usb_handle_ = nullptr;
369
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700370 // A callback that will be invoked when the atransport needs to reconnect.
371 ReconnectCallback reconnect_;
372
Luis Hector Chavez9a388d52018-04-25 08:56:41 -0700373 std::mutex mutex_;
374
Dan Albert1792c232015-05-18 13:06:53 -0700375 DISALLOW_COPY_AND_ASSIGN(atransport);
376};
377
Dan Albert76649012015-02-24 15:51:19 -0800378/*
379 * Obtain a transport from the available transports.
Elliott Hughes8d28e192015-10-07 14:55:10 -0700380 * If serial is non-null then only the device with that serial will be chosen.
Josh Gaob122b172017-08-16 16:57:01 -0700381 * If transport_id is non-zero then only the device with that transport ID will be chosen.
Elliott Hughes8d28e192015-10-07 14:55:10 -0700382 * If multiple devices/emulators would match, *is_ambiguous (if non-null)
383 * is set to true and nullptr returned.
384 * If no suitable transport is found, error is set and nullptr returned.
Dan Albert76649012015-02-24 15:51:19 -0800385 */
Josh Gaob122b172017-08-16 16:57:01 -0700386atransport* acquire_one_transport(TransportType type, const char* serial, TransportId transport_id,
387 bool* is_ambiguous, std::string* error_out,
388 bool accept_any_state = false);
Josh Gao3705b342019-03-28 15:47:44 -0700389void kick_transport(atransport* t, bool reset = false);
Dan Albert76649012015-02-24 15:51:19 -0800390void update_transports(void);
391
Josh Gaofd713e52017-05-03 22:37:10 -0700392// Iterates across all of the current and pending transports.
393// Stops iteration and returns false if fn returns false, otherwise returns true.
394bool iterate_transports(std::function<bool(const atransport*)> fn);
395
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700396void init_reconnect_handler(void);
Dan Albert76649012015-02-24 15:51:19 -0800397void init_transport_registration(void);
Casey Dahlin13a269e2016-06-23 14:19:37 -0700398void init_mdns_transport_discovery(void);
Elliott Hughese67f1f82015-04-30 17:32:03 -0700399std::string list_transports(bool long_listing);
Dan Albert76649012015-02-24 15:51:19 -0800400atransport* find_transport(const char* serial);
Yabin Cuif4b99282015-08-27 12:03:11 -0700401void kick_all_tcp_devices();
Josh Gao01b7bc42017-05-09 13:43:35 -0700402void kick_all_transports();
Dan Albert76649012015-02-24 15:51:19 -0800403
Josh Gaoc51726c2018-10-11 16:33:05 -0700404void register_transport(atransport* transport);
Dan Albert76649012015-02-24 15:51:19 -0800405void register_usb_transport(usb_handle* h, const char* serial,
406 const char* devpath, unsigned writeable);
407
Casey Dahlin13a269e2016-06-23 14:19:37 -0700408/* Connect to a network address and register it as a device */
409void connect_device(const std::string& address, std::string* response);
410
Dan Albert76649012015-02-24 15:51:19 -0800411/* cause new transports to be init'd and added to the list */
Josh Gao362e6962018-08-08 16:20:14 -0700412bool register_socket_transport(unique_fd s, std::string serial, int port, int local,
413 atransport::ReconnectCallback reconnect, int* error = nullptr);
Dan Albert76649012015-02-24 15:51:19 -0800414
Dan Albertdcd78a12015-05-18 16:43:57 -0700415// This should only be used for transports with connection_state == kCsNoPerm.
Dan Albert76649012015-02-24 15:51:19 -0800416void unregister_usb_transport(usb_handle* usb);
417
Josh Gao36dadca2017-05-16 15:02:45 -0700418bool check_header(apacket* p, atransport* t);
Dan Albert76649012015-02-24 15:51:19 -0800419
Josh Gao3705b342019-03-28 15:47:44 -0700420void close_usb_devices(bool reset = false);
421void close_usb_devices(std::function<bool(const atransport*)> predicate, bool reset = false);
Dan Albert76649012015-02-24 15:51:19 -0800422
423void send_packet(apacket* p, atransport* t);
424
Josh Gaob0c18022017-08-14 18:57:54 -0700425asocket* create_device_tracker(bool long_output);
Dan Albert76649012015-02-24 15:51:19 -0800426
Josh Gao776c2ec2019-01-22 19:36:15 -0800427#if !ADB_HOST
Jason Jeremy Iman8bde1912019-07-19 12:44:39 +0900428unique_fd adb_listen(std::string_view addr, std::string* error);
429void server_socket_thread(std::function<unique_fd(std::string_view, std::string*)> listen_func,
430 std::string_view addr);
Josh Gao776c2ec2019-01-22 19:36:15 -0800431
432#if defined(__ANDROID__)
Jason Jeremy Iman8bde1912019-07-19 12:44:39 +0900433void qemu_socket_thread(std::string_view addr);
Josh Gao776c2ec2019-01-22 19:36:15 -0800434bool use_qemu_goldfish();
435#endif
436
437#endif
438
JP Abgrall408fa572011-03-16 15:57:42 -0700439#endif /* __TRANSPORT_H */