2011-03-16 23:57:42 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TRANSPORT_H
|
|
|
|
#define __TRANSPORT_H
|
|
|
|
|
2015-02-19 03:03:26 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
#include <atomic>
|
2016-06-30 02:42:01 +02:00
|
|
|
#include <deque>
|
2016-10-27 23:01:08 +02:00
|
|
|
#include <functional>
|
2015-08-29 00:09:44 +02:00
|
|
|
#include <list>
|
2016-08-19 07:00:12 +02:00
|
|
|
#include <memory>
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
#include <mutex>
|
2015-04-17 07:54:44 +02:00
|
|
|
#include <string>
|
2015-05-18 22:06:53 +02:00
|
|
|
#include <unordered_set>
|
2015-02-25 00:51:19 +01:00
|
|
|
|
2015-04-17 07:54:44 +02:00
|
|
|
#include "adb.h"
|
2014-11-25 08:34:35 +01:00
|
|
|
|
2016-06-30 02:42:01 +02:00
|
|
|
#include <openssl/rsa.h>
|
|
|
|
|
2015-05-18 22:06:53 +02:00
|
|
|
typedef std::unordered_set<std::string> FeatureSet;
|
|
|
|
|
|
|
|
const FeatureSet& supported_features();
|
|
|
|
|
2015-09-22 19:43:08 +02:00
|
|
|
// Encodes and decodes FeatureSet objects into human-readable strings.
|
|
|
|
std::string FeatureSetToString(const FeatureSet& features);
|
|
|
|
FeatureSet StringToFeatureSet(const std::string& features_string);
|
|
|
|
|
2015-09-30 22:35:42 +02:00
|
|
|
// Returns true if both local features and |feature_set| support |feature|.
|
|
|
|
bool CanUseFeature(const FeatureSet& feature_set, const std::string& feature);
|
|
|
|
|
2015-09-22 19:43:08 +02:00
|
|
|
// Do not use any of [:;=,] in feature strings, they have special meaning
|
|
|
|
// in the connection banner.
|
2015-11-04 01:53:08 +01:00
|
|
|
extern const char* const kFeatureShell2;
|
|
|
|
// The 'cmd' command is available
|
|
|
|
extern const char* const kFeatureCmd;
|
2016-12-06 02:11:34 +01:00
|
|
|
extern const char* const kFeatureStat2;
|
2017-02-23 02:07:01 +01:00
|
|
|
// The server is running with libusb enabled.
|
|
|
|
extern const char* const kFeatureLibusb;
|
2015-08-31 19:42:13 +02:00
|
|
|
|
2015-05-18 22:06:53 +02:00
|
|
|
class atransport {
|
|
|
|
public:
|
|
|
|
// TODO(danalbert): We expose waaaaaaay too much stuff because this was
|
|
|
|
// historically just a struct, but making the whole thing a more idiomatic
|
|
|
|
// class in one go is a very large change. Given how bad our testing is,
|
|
|
|
// it's better to do this piece by piece.
|
|
|
|
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
atransport(ConnectionState state = kCsOffline) : connection_state_(state) {
|
2015-05-18 22:06:53 +02:00
|
|
|
transport_fde = {};
|
|
|
|
protocol_version = A_VERSION;
|
|
|
|
max_payload = MAX_PAYLOAD;
|
|
|
|
}
|
|
|
|
virtual ~atransport() {}
|
|
|
|
|
|
|
|
int (*read_from_remote)(apacket* p, atransport* t) = nullptr;
|
|
|
|
void (*close)(atransport* t) = nullptr;
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
|
|
|
|
void SetWriteFunction(int (*write_func)(apacket*, atransport*)) { write_func_ = write_func; }
|
2016-04-18 20:22:34 +02:00
|
|
|
void SetKickFunction(void (*kick_func)(atransport*)) {
|
|
|
|
kick_func_ = kick_func;
|
|
|
|
}
|
|
|
|
bool IsKicked() {
|
|
|
|
return kicked_;
|
|
|
|
}
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
int Write(apacket* p);
|
2016-04-18 20:22:34 +02:00
|
|
|
void Kick();
|
2015-05-18 22:06:53 +02:00
|
|
|
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
// ConnectionState can be read by all threads, but can only be written in the main thread.
|
|
|
|
ConnectionState GetConnectionState() const;
|
|
|
|
void SetConnectionState(ConnectionState state);
|
|
|
|
|
2015-05-18 22:06:53 +02:00
|
|
|
int fd = -1;
|
|
|
|
int transport_socket = -1;
|
|
|
|
fdevent transport_fde;
|
2015-08-27 21:03:11 +02:00
|
|
|
size_t ref_count = 0;
|
2015-05-18 22:06:53 +02:00
|
|
|
uint32_t sync_token = 0;
|
|
|
|
bool online = false;
|
|
|
|
TransportType type = kTransportAny;
|
|
|
|
|
|
|
|
// USB handle or socket fd as needed.
|
|
|
|
usb_handle* usb = nullptr;
|
|
|
|
int sfd = -1;
|
|
|
|
|
|
|
|
// Used to identify transports for clients.
|
|
|
|
char* serial = nullptr;
|
|
|
|
char* product = nullptr;
|
|
|
|
char* model = nullptr;
|
|
|
|
char* device = nullptr;
|
|
|
|
char* devpath = nullptr;
|
2016-04-30 01:53:52 +02:00
|
|
|
void SetLocalPortForEmulator(int port) {
|
|
|
|
CHECK_EQ(local_port_for_emulator_, -1);
|
|
|
|
local_port_for_emulator_ = port;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetLocalPortForEmulator(int* port) const {
|
|
|
|
if (type == kTransportLocal && local_port_for_emulator_ != -1) {
|
|
|
|
*port = local_port_for_emulator_;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsTcpDevice() const {
|
|
|
|
return type == kTransportLocal && local_port_for_emulator_ == -1;
|
|
|
|
}
|
2015-05-18 22:06:53 +02:00
|
|
|
|
2016-10-06 04:02:29 +02:00
|
|
|
#if ADB_HOST
|
2016-08-19 07:00:12 +02:00
|
|
|
std::shared_ptr<RSA> NextKey();
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
bool SetSendConnectOnError();
|
2016-10-06 04:02:29 +02:00
|
|
|
#endif
|
2016-06-30 02:42:01 +02:00
|
|
|
|
2016-10-06 22:31:44 +02:00
|
|
|
char token[TOKEN_SIZE] = {};
|
2015-05-18 22:06:53 +02:00
|
|
|
size_t failed_auth_attempts = 0;
|
|
|
|
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
const std::string serial_name() const { return serial ? serial : "<unknown>"; }
|
2015-12-03 00:14:31 +01:00
|
|
|
const std::string connection_state_name() const;
|
2015-05-18 22:06:53 +02:00
|
|
|
|
|
|
|
void update_version(int version, size_t payload);
|
|
|
|
int get_protocol_version() const;
|
|
|
|
size_t get_max_payload() const;
|
|
|
|
|
2015-09-22 19:43:08 +02:00
|
|
|
const FeatureSet& features() const {
|
2015-05-18 22:06:53 +02:00
|
|
|
return features_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool has_feature(const std::string& feature) const;
|
2015-09-22 19:43:08 +02:00
|
|
|
|
|
|
|
// Loads the transport's feature set from the given string.
|
|
|
|
void SetFeatures(const std::string& features_string);
|
2015-05-18 22:06:53 +02:00
|
|
|
|
2015-08-29 00:09:44 +02:00
|
|
|
void AddDisconnect(adisconnect* disconnect);
|
|
|
|
void RemoveDisconnect(adisconnect* disconnect);
|
|
|
|
void RunDisconnects();
|
|
|
|
|
2016-03-01 17:58:26 +01:00
|
|
|
// Returns true if |target| matches this transport. A matching |target| can be any of:
|
|
|
|
// * <serial>
|
|
|
|
// * <devpath>
|
|
|
|
// * product:<product>
|
|
|
|
// * model:<model>
|
|
|
|
// * device:<device>
|
|
|
|
//
|
|
|
|
// If this is a local transport, serial will also match [tcp:|udp:]<hostname>[:port] targets.
|
|
|
|
// For example, serial "100.100.100.100:5555" would match any of:
|
|
|
|
// * 100.100.100.100
|
|
|
|
// * tcp:100.100.100.100
|
|
|
|
// * udp:100.100.100.100:5555
|
|
|
|
// This is to make it easier to use the same network target for both fastboot and adb.
|
|
|
|
bool MatchesTarget(const std::string& target) const;
|
|
|
|
|
2015-05-18 22:06:53 +02:00
|
|
|
private:
|
2016-04-30 01:53:52 +02:00
|
|
|
int local_port_for_emulator_ = -1;
|
2016-04-18 20:22:34 +02:00
|
|
|
bool kicked_ = false;
|
|
|
|
void (*kick_func_)(atransport*) = nullptr;
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
int (*write_func_)(apacket*, atransport*) = nullptr;
|
2016-04-18 20:22:34 +02:00
|
|
|
|
2015-05-18 22:06:53 +02:00
|
|
|
// A set of features transmitted in the banner with the initial connection.
|
|
|
|
// This is stored in the banner as 'features=feature0,feature1,etc'.
|
|
|
|
FeatureSet features_;
|
|
|
|
int protocol_version;
|
|
|
|
size_t max_payload;
|
|
|
|
|
2015-08-29 00:09:44 +02:00
|
|
|
// A list of adisconnect callbacks called when the transport is kicked.
|
|
|
|
std::list<adisconnect*> disconnects_;
|
|
|
|
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
std::atomic<ConnectionState> connection_state_;
|
2016-10-06 04:02:29 +02:00
|
|
|
#if ADB_HOST
|
2016-08-19 07:00:12 +02:00
|
|
|
std::deque<std::shared_ptr<RSA>> keys_;
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
std::mutex write_msg_lock_;
|
|
|
|
bool has_send_connect_on_error_ = false;
|
2016-10-06 04:02:29 +02:00
|
|
|
#endif
|
2016-06-30 02:42:01 +02:00
|
|
|
|
2015-05-18 22:06:53 +02:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(atransport);
|
|
|
|
};
|
|
|
|
|
2015-02-25 00:51:19 +01:00
|
|
|
/*
|
|
|
|
* Obtain a transport from the available transports.
|
2015-10-07 23:55:10 +02:00
|
|
|
* If serial is non-null then only the device with that serial will be chosen.
|
|
|
|
* If multiple devices/emulators would match, *is_ambiguous (if non-null)
|
|
|
|
* is set to true and nullptr returned.
|
|
|
|
* If no suitable transport is found, error is set and nullptr returned.
|
2015-02-25 00:51:19 +01:00
|
|
|
*/
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
atransport* acquire_one_transport(TransportType type, const char* serial, bool* is_ambiguous,
|
|
|
|
std::string* error_out, bool accept_any_state = false);
|
2015-02-25 00:51:19 +01:00
|
|
|
void kick_transport(atransport* t);
|
|
|
|
void update_transports(void);
|
|
|
|
|
|
|
|
void init_transport_registration(void);
|
2016-06-23 23:19:37 +02:00
|
|
|
void init_mdns_transport_discovery(void);
|
2015-05-01 02:32:03 +02:00
|
|
|
std::string list_transports(bool long_listing);
|
2015-02-25 00:51:19 +01:00
|
|
|
atransport* find_transport(const char* serial);
|
2015-08-27 21:03:11 +02:00
|
|
|
void kick_all_tcp_devices();
|
2015-02-25 00:51:19 +01:00
|
|
|
|
|
|
|
void register_usb_transport(usb_handle* h, const char* serial,
|
|
|
|
const char* devpath, unsigned writeable);
|
|
|
|
|
2016-06-23 23:19:37 +02:00
|
|
|
/* Connect to a network address and register it as a device */
|
|
|
|
void connect_device(const std::string& address, std::string* response);
|
|
|
|
|
2015-02-25 00:51:19 +01:00
|
|
|
/* cause new transports to be init'd and added to the list */
|
|
|
|
int register_socket_transport(int s, const char* serial, int port, int local);
|
|
|
|
|
2015-05-19 01:43:57 +02:00
|
|
|
// This should only be used for transports with connection_state == kCsNoPerm.
|
2015-02-25 00:51:19 +01:00
|
|
|
void unregister_usb_transport(usb_handle* usb);
|
|
|
|
|
2015-07-13 20:12:28 +02:00
|
|
|
int check_header(apacket* p, atransport* t);
|
2015-02-25 00:51:19 +01:00
|
|
|
int check_data(apacket* p);
|
|
|
|
|
|
|
|
void close_usb_devices();
|
2016-10-27 23:01:08 +02:00
|
|
|
void close_usb_devices(std::function<bool(const atransport*)> predicate);
|
2015-02-25 00:51:19 +01:00
|
|
|
|
|
|
|
void send_packet(apacket* p, atransport* t);
|
|
|
|
|
|
|
|
asocket* create_device_tracker(void);
|
|
|
|
|
2011-03-16 23:57:42 +01:00
|
|
|
#endif /* __TRANSPORT_H */
|