blob: dae438ce5323f2a4ec3f40b66644bcec693640ab [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 Gaoce5ce872018-12-11 13:11:52 -080041#include "usb.h"
Josh Gaob800d882018-01-28 20:32:46 -080042
Dan Albert1792c232015-05-18 13:06:53 -070043typedef std::unordered_set<std::string> FeatureSet;
44
45const FeatureSet& supported_features();
46
David Pursell4e2fd362015-09-22 10:43:08 -070047// Encodes and decodes FeatureSet objects into human-readable strings.
48std::string FeatureSetToString(const FeatureSet& features);
49FeatureSet StringToFeatureSet(const std::string& features_string);
50
David Pursell70ef7b42015-09-30 13:35:42 -070051// Returns true if both local features and |feature_set| support |feature|.
52bool CanUseFeature(const FeatureSet& feature_set, const std::string& feature);
53
David Pursell4e2fd362015-09-22 10:43:08 -070054// Do not use any of [:;=,] in feature strings, they have special meaning
55// in the connection banner.
Todd Kennedy6fa848a2015-11-03 16:53:08 -080056extern const char* const kFeatureShell2;
57// The 'cmd' command is available
58extern const char* const kFeatureCmd;
Josh Gao5a1e3fd2016-12-05 17:11:34 -080059extern const char* const kFeatureStat2;
Josh Gao5d1756c2017-02-22 17:07:01 -080060// The server is running with libusb enabled.
61extern const char* const kFeatureLibusb;
Josh Gaofb085102018-10-22 13:00:05 -070062// adbd supports `push --sync`.
Dan Albert5176df82017-05-23 14:30:00 -070063extern const char* const kFeaturePushSync;
Josh Gaofb085102018-10-22 13:00:05 -070064// adbd supports installing .apex packages.
Dario Freni29814de2018-10-04 16:26:40 +010065extern const char* const kFeatureApex;
Josh Gaofb085102018-10-22 13:00:05 -070066// adbd has b/110953234 fixed.
67extern const char* const kFeatureFixedPushMkdir;
Alex Buynytskyy7ea92d82019-09-13 14:19:01 -070068// adbd supports android binder bridge (abb) in interactive mode using shell protocol.
Alex Buynytskyy01a65ee2019-01-17 13:13:56 -080069extern const char* const kFeatureAbb;
Alex Buynytskyy7ea92d82019-09-13 14:19:01 -070070// adbd supports abb using raw pipe.
71extern const char* const kFeatureAbbExec;
Josh Gao7b1cb662019-02-20 13:01:40 -080072// adbd properly updates symlink timestamps on push.
73extern const char* const kFeatureFixedPushSymlinkTimestamp;
Josh Gao8c2198c2019-07-11 14:15:32 -070074extern const char* const kFeatureRemountShell;
David Pursell0955c662015-08-31 10:42:13 -070075
Josh Gaob122b172017-08-16 16:57:01 -070076TransportId NextTransportId();
77
Josh Gao0bbf69c2018-02-16 13:24:58 -080078// Abstraction for a non-blocking packet transport.
Josh Gaob800d882018-01-28 20:32:46 -080079struct Connection {
80 Connection() = default;
Josh Gaob800d882018-01-28 20:32:46 -080081 virtual ~Connection() = default;
82
Josh Gao0bbf69c2018-02-16 13:24:58 -080083 void SetTransportName(std::string transport_name) {
84 transport_name_ = std::move(transport_name);
85 }
86
87 using ReadCallback = std::function<bool(Connection*, std::unique_ptr<apacket>)>;
88 void SetReadCallback(ReadCallback callback) {
89 CHECK(!read_callback_);
90 read_callback_ = callback;
91 }
92
93 // Called after the Connection has terminated, either by an error or because Stop was called.
94 using ErrorCallback = std::function<void(Connection*, const std::string&)>;
95 void SetErrorCallback(ErrorCallback callback) {
96 CHECK(!error_callback_);
97 error_callback_ = callback;
98 }
99
100 virtual bool Write(std::unique_ptr<apacket> packet) = 0;
101
102 virtual void Start() = 0;
103 virtual void Stop() = 0;
104
Josh Gao3705b342019-03-28 15:47:44 -0700105 // Stop, and reset the device if it's a USB connection.
106 virtual void Reset();
107
Josh Gao0bbf69c2018-02-16 13:24:58 -0800108 std::string transport_name_;
109 ReadCallback read_callback_;
110 ErrorCallback error_callback_;
Josh Gao6082e7d2018-04-05 16:16:04 -0700111
112 static std::unique_ptr<Connection> FromFd(unique_fd fd);
Josh Gao0bbf69c2018-02-16 13:24:58 -0800113};
114
115// Abstraction for a blocking packet transport.
116struct BlockingConnection {
117 BlockingConnection() = default;
118 BlockingConnection(const BlockingConnection& copy) = delete;
119 BlockingConnection(BlockingConnection&& move) = delete;
120
121 // Destroy a BlockingConnection. Formerly known as 'Close' in atransport.
122 virtual ~BlockingConnection() = default;
123
Josh Gaob800d882018-01-28 20:32:46 -0800124 // Read/Write a packet. These functions are concurrently called from a transport's reader/writer
125 // threads.
126 virtual bool Read(apacket* packet) = 0;
127 virtual bool Write(apacket* packet) = 0;
128
129 // Terminate a connection.
130 // This method must be thread-safe, and must cause concurrent Reads/Writes to terminate.
131 // Formerly known as 'Kick' in atransport.
132 virtual void Close() = 0;
Josh Gao3705b342019-03-28 15:47:44 -0700133
134 // Terminate a connection, and reset it.
135 virtual void Reset() = 0;
Josh Gaob800d882018-01-28 20:32:46 -0800136};
137
Josh Gao0bbf69c2018-02-16 13:24:58 -0800138struct BlockingConnectionAdapter : public Connection {
139 explicit BlockingConnectionAdapter(std::unique_ptr<BlockingConnection> connection);
140
141 virtual ~BlockingConnectionAdapter();
142
143 virtual bool Write(std::unique_ptr<apacket> packet) override final;
144
145 virtual void Start() override final;
146 virtual void Stop() override final;
147
Josh Gao3705b342019-03-28 15:47:44 -0700148 virtual void Reset() override final;
149
Josh Gaoc251ec52018-04-03 12:55:18 -0700150 bool started_ GUARDED_BY(mutex_) = false;
151 bool stopped_ GUARDED_BY(mutex_) = false;
Josh Gao0bbf69c2018-02-16 13:24:58 -0800152
153 std::unique_ptr<BlockingConnection> underlying_;
Josh Gaoc251ec52018-04-03 12:55:18 -0700154 std::thread read_thread_ GUARDED_BY(mutex_);
155 std::thread write_thread_ GUARDED_BY(mutex_);
Josh Gao0bbf69c2018-02-16 13:24:58 -0800156
Josh Gaoc251ec52018-04-03 12:55:18 -0700157 std::deque<std::unique_ptr<apacket>> write_queue_ GUARDED_BY(mutex_);
Josh Gao0bbf69c2018-02-16 13:24:58 -0800158 std::mutex mutex_;
159 std::condition_variable cv_;
160
161 std::once_flag error_flag_;
162};
163
164struct FdConnection : public BlockingConnection {
Josh Gaob800d882018-01-28 20:32:46 -0800165 explicit FdConnection(unique_fd fd) : fd_(std::move(fd)) {}
166
167 bool Read(apacket* packet) override final;
168 bool Write(apacket* packet) override final;
169
170 void Close() override;
Josh Gao3705b342019-03-28 15:47:44 -0700171 virtual void Reset() override final { Close(); }
Josh Gaob800d882018-01-28 20:32:46 -0800172
173 private:
174 unique_fd fd_;
175};
176
Josh Gao0bbf69c2018-02-16 13:24:58 -0800177struct UsbConnection : public BlockingConnection {
Josh Gaob800d882018-01-28 20:32:46 -0800178 explicit UsbConnection(usb_handle* handle) : handle_(handle) {}
179 ~UsbConnection();
180
181 bool Read(apacket* packet) override final;
182 bool Write(apacket* packet) override final;
183
184 void Close() override final;
Josh Gao3705b342019-03-28 15:47:44 -0700185 virtual void Reset() override final;
Josh Gaob800d882018-01-28 20:32:46 -0800186
187 usb_handle* handle_;
188};
189
Luis Hector Chavez56fe7532018-04-17 14:25:04 -0700190// Waits for a transport's connection to be not pending. This is a separate
191// object so that the transport can be destroyed and another thread can be
192// notified of it in a race-free way.
193class ConnectionWaitable {
194 public:
195 ConnectionWaitable() = default;
196 ~ConnectionWaitable() = default;
197
198 // Waits until the first CNXN packet has been received by the owning
199 // atransport, or the specified timeout has elapsed. Can be called from any
200 // thread.
201 //
202 // Returns true if the CNXN packet was received in a timely fashion, false
203 // otherwise.
204 bool WaitForConnection(std::chrono::milliseconds timeout);
205
206 // Can be called from any thread when the connection stops being pending.
207 // Only the first invocation will be acknowledged, the rest will be no-ops.
208 void SetConnectionEstablished(bool success);
209
210 private:
211 bool connection_established_ GUARDED_BY(mutex_) = false;
212 bool connection_established_ready_ GUARDED_BY(mutex_) = false;
213 std::mutex mutex_;
214 std::condition_variable cv_;
215
216 DISALLOW_COPY_AND_ASSIGN(ConnectionWaitable);
217};
218
Josh Gaofc2e56f2018-08-30 11:37:00 -0700219enum class ReconnectResult {
220 Retry,
221 Success,
222 Abort,
223};
224
Dan Albert1792c232015-05-18 13:06:53 -0700225class atransport {
Josh Gaob122b172017-08-16 16:57:01 -0700226 public:
Dan Albert1792c232015-05-18 13:06:53 -0700227 // TODO(danalbert): We expose waaaaaaay too much stuff because this was
228 // historically just a struct, but making the whole thing a more idiomatic
229 // class in one go is a very large change. Given how bad our testing is,
230 // it's better to do this piece by piece.
231
Josh Gaofc2e56f2018-08-30 11:37:00 -0700232 using ReconnectCallback = std::function<ReconnectResult(atransport*)>;
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700233
234 atransport(ReconnectCallback reconnect, ConnectionState state)
Luis Hector Chavez56fe7532018-04-17 14:25:04 -0700235 : id(NextTransportId()),
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700236 kicked_(false),
Luis Hector Chavez56fe7532018-04-17 14:25:04 -0700237 connection_state_(state),
Luis Hector Chavez9a388d52018-04-25 08:56:41 -0700238 connection_waitable_(std::make_shared<ConnectionWaitable>()),
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700239 connection_(nullptr),
240 reconnect_(std::move(reconnect)) {
Tim Murrayde471942017-12-07 11:40:00 -0800241 // Initialize protocol to min version for compatibility with older versions.
242 // Version will be updated post-connect.
243 protocol_version = A_VERSION_MIN;
Dan Albert1792c232015-05-18 13:06:53 -0700244 max_payload = MAX_PAYLOAD;
245 }
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700246 atransport(ConnectionState state = kCsOffline)
Josh Gaofc2e56f2018-08-30 11:37:00 -0700247 : atransport([](atransport*) { return ReconnectResult::Abort; }, state) {}
Luis Hector Chavez56fe7532018-04-17 14:25:04 -0700248 virtual ~atransport();
Dan Albert1792c232015-05-18 13:06:53 -0700249
Yabin Cuib5e11412017-03-10 16:01:01 -0800250 int Write(apacket* p);
Josh Gao3705b342019-03-28 15:47:44 -0700251 void Reset();
Yabin Cui7f274902016-04-18 11:22:34 -0700252 void Kick();
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700253 bool kicked() const { return kicked_; }
Dan Albert1792c232015-05-18 13:06:53 -0700254
Yabin Cuib5e11412017-03-10 16:01:01 -0800255 // ConnectionState can be read by all threads, but can only be written in the main thread.
256 ConnectionState GetConnectionState() const;
257 void SetConnectionState(ConnectionState state);
258
Luis Hector Chavez9a388d52018-04-25 08:56:41 -0700259 void SetConnection(std::unique_ptr<Connection> connection);
260 std::shared_ptr<Connection> connection() {
261 std::lock_guard<std::mutex> lock(mutex_);
262 return connection_;
263 }
264
Josh Gaoce5ce872018-12-11 13:11:52 -0800265 void SetUsbHandle(usb_handle* h) { usb_handle_ = h; }
266 usb_handle* GetUsbHandle() { return usb_handle_; }
267
Josh Gaob122b172017-08-16 16:57:01 -0700268 const TransportId id;
Josh Gaoe48ecce2017-09-13 13:40:57 -0700269 size_t ref_count = 0;
Dan Albert1792c232015-05-18 13:06:53 -0700270 bool online = false;
271 TransportType type = kTransportAny;
272
Dan Albert1792c232015-05-18 13:06:53 -0700273 // Used to identify transports for clients.
Luis Hector Chavez6150a372018-07-18 21:18:27 -0700274 std::string serial;
275 std::string product;
276 std::string model;
277 std::string device;
278 std::string devpath;
Yabin Cuib74c6492016-04-29 16:53:52 -0700279
Josh Gao27523262019-10-22 12:30:39 -0700280#if !ADB_HOST
Michael Groover7eeda6b2019-04-25 18:33:35 -0700281 // Used to provide the key to the framework.
282 std::string auth_key;
Josh Gao27523262019-10-22 12:30:39 -0700283 uint64_t auth_id;
284#endif
Michael Groover7eeda6b2019-04-25 18:33:35 -0700285
Josh Gaob800d882018-01-28 20:32:46 -0800286 bool IsTcpDevice() const { return type == kTransportLocal; }
Dan Albert1792c232015-05-18 13:06:53 -0700287
Josh Gao3bd28792016-10-05 19:02:29 -0700288#if ADB_HOST
Josh Gao2e671202016-08-18 22:00:12 -0700289 std::shared_ptr<RSA> NextKey();
Josh Gao4414e4c2018-12-04 01:07:50 -0800290 void ResetKeys();
Josh Gao3bd28792016-10-05 19:02:29 -0700291#endif
Elliott Hughes0aeb5052016-06-29 17:42:01 -0700292
Josh Gao06d61d42016-10-06 13:31:44 -0700293 char token[TOKEN_SIZE] = {};
Dan Albert1792c232015-05-18 13:06:53 -0700294 size_t failed_auth_attempts = 0;
295
Luis Hector Chavez6150a372018-07-18 21:18:27 -0700296 std::string serial_name() const { return !serial.empty() ? serial : "<unknown>"; }
Josh Gaoffbd3362018-02-28 14:44:23 -0800297 std::string connection_state_name() const;
Dan Albert1792c232015-05-18 13:06:53 -0700298
299 void update_version(int version, size_t payload);
300 int get_protocol_version() const;
301 size_t get_max_payload() const;
302
David Pursell4e2fd362015-09-22 10:43:08 -0700303 const FeatureSet& features() const {
Dan Albert1792c232015-05-18 13:06:53 -0700304 return features_;
305 }
306
307 bool has_feature(const std::string& feature) const;
David Pursell4e2fd362015-09-22 10:43:08 -0700308
309 // Loads the transport's feature set from the given string.
310 void SetFeatures(const std::string& features_string);
Dan Albert1792c232015-05-18 13:06:53 -0700311
Yabin Cuib3298242015-08-28 15:09:44 -0700312 void AddDisconnect(adisconnect* disconnect);
313 void RemoveDisconnect(adisconnect* disconnect);
314 void RunDisconnects();
315
David Pursell3f902aa2016-03-01 08:58:26 -0800316 // Returns true if |target| matches this transport. A matching |target| can be any of:
317 // * <serial>
318 // * <devpath>
319 // * product:<product>
320 // * model:<model>
321 // * device:<device>
322 //
323 // If this is a local transport, serial will also match [tcp:|udp:]<hostname>[:port] targets.
324 // For example, serial "100.100.100.100:5555" would match any of:
325 // * 100.100.100.100
326 // * tcp:100.100.100.100
327 // * udp:100.100.100.100:5555
328 // This is to make it easier to use the same network target for both fastboot and adb.
329 bool MatchesTarget(const std::string& target) const;
330
Luis Hector Chavez56fe7532018-04-17 14:25:04 -0700331 // Notifies that the atransport is no longer waiting for the connection
332 // being established.
333 void SetConnectionEstablished(bool success);
334
335 // Gets a shared reference to the ConnectionWaitable.
336 std::shared_ptr<ConnectionWaitable> connection_waitable() { return connection_waitable_; }
337
Josh Gaofc2e56f2018-08-30 11:37:00 -0700338 // Attempts to reconnect with the underlying Connection.
339 ReconnectResult Reconnect();
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700340
Luis Hector Chavez56fe7532018-04-17 14:25:04 -0700341 private:
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700342 std::atomic<bool> kicked_;
Yabin Cui7f274902016-04-18 11:22:34 -0700343
Dan Albert1792c232015-05-18 13:06:53 -0700344 // A set of features transmitted in the banner with the initial connection.
345 // This is stored in the banner as 'features=feature0,feature1,etc'.
346 FeatureSet features_;
347 int protocol_version;
348 size_t max_payload;
349
Yabin Cuib3298242015-08-28 15:09:44 -0700350 // A list of adisconnect callbacks called when the transport is kicked.
351 std::list<adisconnect*> disconnects_;
352
Yabin Cuib5e11412017-03-10 16:01:01 -0800353 std::atomic<ConnectionState> connection_state_;
Josh Gao3bd28792016-10-05 19:02:29 -0700354#if ADB_HOST
Josh Gao2e671202016-08-18 22:00:12 -0700355 std::deque<std::shared_ptr<RSA>> keys_;
Josh Gao3bd28792016-10-05 19:02:29 -0700356#endif
Elliott Hughes0aeb5052016-06-29 17:42:01 -0700357
Luis Hector Chavez56fe7532018-04-17 14:25:04 -0700358 // A sharable object that can be used to wait for the atransport's
359 // connection to be established.
360 std::shared_ptr<ConnectionWaitable> connection_waitable_;
361
Luis Hector Chavez9a388d52018-04-25 08:56:41 -0700362 // The underlying connection object.
363 std::shared_ptr<Connection> connection_ GUARDED_BY(mutex_);
364
Josh Gaoce5ce872018-12-11 13:11:52 -0800365 // USB handle for the connection, if available.
366 usb_handle* usb_handle_ = nullptr;
367
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700368 // A callback that will be invoked when the atransport needs to reconnect.
369 ReconnectCallback reconnect_;
370
Luis Hector Chavez9a388d52018-04-25 08:56:41 -0700371 std::mutex mutex_;
372
Dan Albert1792c232015-05-18 13:06:53 -0700373 DISALLOW_COPY_AND_ASSIGN(atransport);
374};
375
Dan Albert76649012015-02-24 15:51:19 -0800376/*
377 * Obtain a transport from the available transports.
Elliott Hughes8d28e192015-10-07 14:55:10 -0700378 * If serial is non-null then only the device with that serial will be chosen.
Josh Gaob122b172017-08-16 16:57:01 -0700379 * If transport_id is non-zero then only the device with that transport ID will be chosen.
Elliott Hughes8d28e192015-10-07 14:55:10 -0700380 * If multiple devices/emulators would match, *is_ambiguous (if non-null)
381 * is set to true and nullptr returned.
382 * If no suitable transport is found, error is set and nullptr returned.
Dan Albert76649012015-02-24 15:51:19 -0800383 */
Josh Gaob122b172017-08-16 16:57:01 -0700384atransport* acquire_one_transport(TransportType type, const char* serial, TransportId transport_id,
385 bool* is_ambiguous, std::string* error_out,
386 bool accept_any_state = false);
Josh Gao3705b342019-03-28 15:47:44 -0700387void kick_transport(atransport* t, bool reset = false);
Dan Albert76649012015-02-24 15:51:19 -0800388void update_transports(void);
389
Josh Gaofd713e52017-05-03 22:37:10 -0700390// Iterates across all of the current and pending transports.
391// Stops iteration and returns false if fn returns false, otherwise returns true.
392bool iterate_transports(std::function<bool(const atransport*)> fn);
393
Luis Hector Chavez454bc7c2018-04-20 10:31:29 -0700394void init_reconnect_handler(void);
Dan Albert76649012015-02-24 15:51:19 -0800395void init_transport_registration(void);
Casey Dahlin13a269e2016-06-23 14:19:37 -0700396void init_mdns_transport_discovery(void);
Elliott Hughese67f1f82015-04-30 17:32:03 -0700397std::string list_transports(bool long_listing);
Dan Albert76649012015-02-24 15:51:19 -0800398atransport* find_transport(const char* serial);
Yabin Cuif4b99282015-08-27 12:03:11 -0700399void kick_all_tcp_devices();
Josh Gao01b7bc42017-05-09 13:43:35 -0700400void kick_all_transports();
Dan Albert76649012015-02-24 15:51:19 -0800401
Josh Gaoc51726c2018-10-11 16:33:05 -0700402void register_transport(atransport* transport);
Dan Albert76649012015-02-24 15:51:19 -0800403void register_usb_transport(usb_handle* h, const char* serial,
404 const char* devpath, unsigned writeable);
405
Casey Dahlin13a269e2016-06-23 14:19:37 -0700406/* Connect to a network address and register it as a device */
407void connect_device(const std::string& address, std::string* response);
408
Dan Albert76649012015-02-24 15:51:19 -0800409/* cause new transports to be init'd and added to the list */
Josh Gao362e6962018-08-08 16:20:14 -0700410bool register_socket_transport(unique_fd s, std::string serial, int port, int local,
411 atransport::ReconnectCallback reconnect, int* error = nullptr);
Dan Albert76649012015-02-24 15:51:19 -0800412
Dan Albertdcd78a12015-05-18 16:43:57 -0700413// This should only be used for transports with connection_state == kCsNoPerm.
Dan Albert76649012015-02-24 15:51:19 -0800414void unregister_usb_transport(usb_handle* usb);
415
Josh Gao36dadca2017-05-16 15:02:45 -0700416bool check_header(apacket* p, atransport* t);
Dan Albert76649012015-02-24 15:51:19 -0800417
Josh Gao3705b342019-03-28 15:47:44 -0700418void close_usb_devices(bool reset = false);
419void close_usb_devices(std::function<bool(const atransport*)> predicate, bool reset = false);
Dan Albert76649012015-02-24 15:51:19 -0800420
421void send_packet(apacket* p, atransport* t);
422
Josh Gaob0c18022017-08-14 18:57:54 -0700423asocket* create_device_tracker(bool long_output);
Dan Albert76649012015-02-24 15:51:19 -0800424
Josh Gao776c2ec2019-01-22 19:36:15 -0800425#if !ADB_HOST
Jason Jeremy Iman8bde1912019-07-19 12:44:39 +0900426unique_fd adb_listen(std::string_view addr, std::string* error);
427void server_socket_thread(std::function<unique_fd(std::string_view, std::string*)> listen_func,
428 std::string_view addr);
Josh Gao776c2ec2019-01-22 19:36:15 -0800429
430#if defined(__ANDROID__)
Jason Jeremy Iman8bde1912019-07-19 12:44:39 +0900431void qemu_socket_thread(std::string_view addr);
Josh Gao776c2ec2019-01-22 19:36:15 -0800432bool use_qemu_goldfish();
433#endif
434
435#endif
436
JP Abgrall408fa572011-03-16 15:57:42 -0700437#endif /* __TRANSPORT_H */