summaryrefslogtreecommitdiffstats
path: root/tools/android
diff options
context:
space:
mode:
authorqsr <qsr@chromium.org>2015-01-29 04:53:27 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-29 12:54:27 +0000
commit5900a7dfb155ac6987efd83083047cbf2b19e025 (patch)
treecf667e0a342d0a09e19598145acbd9b758796f36 /tools/android
parent7d13c2a6ae3115e65daf2561254753dbc79f63dd (diff)
downloadchromium_src-5900a7dfb155ac6987efd83083047cbf2b19e025.zip
chromium_src-5900a7dfb155ac6987efd83083047cbf2b19e025.tar.gz
chromium_src-5900a7dfb155ac6987efd83083047cbf2b19e025.tar.bz2
Add option to pass path to adb to host_forwarder.
R=digit@chromium.org Review URL: https://codereview.chromium.org/882373002 Cr-Commit-Position: refs/heads/master@{#313693}
Diffstat (limited to 'tools/android')
-rw-r--r--tools/android/forwarder2/host_forwarder_main.cc45
1 files changed, 29 insertions, 16 deletions
diff --git a/tools/android/forwarder2/host_forwarder_main.cc b/tools/android/forwarder2/host_forwarder_main.cc
index 47f2252..a94a97b 100644
--- a/tools/android/forwarder2/host_forwarder_main.cc
+++ b/tools/android/forwarder2/host_forwarder_main.cc
@@ -98,7 +98,8 @@ class HostControllersManager {
FROM_HERE, controllers_.release());
}
- void HandleRequest(const std::string& device_serial,
+ void HandleRequest(const std::string& adb_path,
+ const std::string& device_serial,
int device_port,
int host_port,
scoped_ptr<Socket> client_socket) {
@@ -106,10 +107,9 @@ class HostControllersManager {
InitOnce();
thread_->message_loop_proxy()->PostTask(
FROM_HERE,
- base::Bind(
- &HostControllersManager::HandleRequestOnInternalThread,
- base::Unretained(this), device_serial, device_port, host_port,
- base::Passed(&client_socket)));
+ base::Bind(&HostControllersManager::HandleRequestOnInternalThread,
+ base::Unretained(this), adb_path, device_serial, device_port,
+ host_port, base::Passed(&client_socket)));
}
bool has_failed() const { return has_failed_; }
@@ -152,11 +152,12 @@ class HostControllersManager {
manager->controllers_.get());
}
- void HandleRequestOnInternalThread(const std::string& device_serial,
+ void HandleRequestOnInternalThread(const std::string& adb_path,
+ const std::string& device_serial,
int device_port,
int host_port,
scoped_ptr<Socket> client_socket) {
- const int adb_port = GetAdbPortForDevice(device_serial);
+ const int adb_port = GetAdbPortForDevice(adb_path, device_serial);
if (adb_port < 0) {
SendMessage(
"ERROR: could not get adb port for device. You might need to add "
@@ -174,7 +175,7 @@ class HostControllersManager {
!controller_did_exist ? "ERROR: could not unmap port" : "OK",
client_socket.get());
- RemoveAdbPortForDeviceIfNeeded(device_serial);
+ RemoveAdbPortForDeviceIfNeeded(adb_path, device_serial);
return;
}
if (host_port < 0) {
@@ -217,7 +218,8 @@ class HostControllersManager {
linked_ptr<HostController>(host_controller.release())));
}
- void RemoveAdbPortForDeviceIfNeeded(const std::string& device_serial) {
+ void RemoveAdbPortForDeviceIfNeeded(const std::string& adb_path,
+ const std::string& device_serial) {
base::hash_map<std::string, int>::const_iterator it =
device_serial_to_adb_port_map_.find(device_serial);
if (it == device_serial_to_adb_port_map_.end())
@@ -238,7 +240,8 @@ class HostControllersManager {
const std::string serial_part = device_serial.empty() ?
std::string() : std::string("-s ") + device_serial;
const std::string command = base::StringPrintf(
- "adb %s forward --remove tcp:%d",
+ "%s %s forward --remove tcp:%d",
+ adb_path.c_str(),
serial_part.c_str(),
port);
const int ret = system(command.c_str());
@@ -260,7 +263,8 @@ class HostControllersManager {
}
}
- int GetAdbPortForDevice(const std::string& device_serial) {
+ int GetAdbPortForDevice(const std::string adb_path,
+ const std::string& device_serial) {
base::hash_map<std::string, int>::const_iterator it =
device_serial_to_adb_port_map_.find(device_serial);
if (it != device_serial_to_adb_port_map_.end())
@@ -272,7 +276,8 @@ class HostControllersManager {
const std::string serial_part = device_serial.empty() ?
std::string() : std::string("-s ") + device_serial;
const std::string command = base::StringPrintf(
- "adb %s forward tcp:%d localabstract:chrome_device_forwarder",
+ "%s %s forward tcp:%d localabstract:chrome_device_forwarder",
+ adb_path.c_str(),
serial_part.c_str(),
port);
LOG(INFO) << command;
@@ -301,7 +306,8 @@ class HostControllersManager {
class ServerDelegate : public Daemon::ServerDelegate {
public:
- ServerDelegate() : has_failed_(false) {}
+ ServerDelegate(const std::string& adb_path)
+ : adb_path_(adb_path), has_failed_(false) {}
bool has_failed() const {
return has_failed_ || controllers_manager_.has_failed();
@@ -338,11 +344,12 @@ class ServerDelegate : public Daemon::ServerDelegate {
int host_port;
if (!pickle_it.ReadInt(&host_port))
host_port = -1;
- controllers_manager_.HandleRequest(
- device_serial, device_port, host_port, client_socket.Pass());
+ controllers_manager_.HandleRequest(adb_path_, device_serial, device_port,
+ host_port, client_socket.Pass());
}
private:
+ std::string adb_path_;
bool has_failed_;
HostControllersManager controllers_manager_;
@@ -390,6 +397,7 @@ void ExitWithUsage() {
" --serial-id=[0-9A-Z]{16}]\n"
" --map DEVICE_PORT HOST_PORT\n"
" --unmap DEVICE_PORT\n"
+ " --adb PATH_TO_ADB\n"
" --kill-server\n";
exit(1);
}
@@ -408,6 +416,7 @@ int PortToInt(const std::string& s) {
int RunHostForwarder(int argc, char** argv) {
base::CommandLine::Init(argc, argv);
const base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess();
+ std::string adb_path = "adb";
bool kill_server = false;
Pickle pickle;
@@ -432,11 +441,15 @@ int RunHostForwarder(int argc, char** argv) {
ExitWithUsage();
}
+ if (cmd_line.HasSwitch("adb")) {
+ adb_path = cmd_line.GetSwitchValueASCII("adb");
+ }
+
if (kill_server && args.size() > 0)
ExitWithUsage();
ClientDelegate client_delegate(pickle);
- ServerDelegate daemon_delegate;
+ ServerDelegate daemon_delegate(adb_path);
Daemon daemon(
kLogFilePath, kDaemonIdentifier, &client_delegate, &daemon_delegate,
&GetExitNotifierFD);