Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/chromedriver/chrome/adb_impl.h" | 5 #include "chrome/test/chromedriver/chrome/adb_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 } else { | 219 } else { |
| 220 break; | 220 break; |
| 221 } | 221 } |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 | 224 |
| 225 return Status(kUnknownError, | 225 return Status(kUnknownError, |
| 226 "Failed to get PID for the following process: " + process_name); | 226 "Failed to get PID for the following process: " + process_name); |
| 227 } | 227 } |
| 228 | 228 |
| 229 Status AdbImpl::GetDevtoolsRemoteSocket(const std::string& device_serial, | |
| 230 const std::string& process_name, | |
| 231 std::string* device_socket) { | |
| 232 // Parse 'cat /proc/net/unix' output which on Android looks like this: | |
| 233 // | |
| 234 // Num RefCount Protocol Flags Type St Inode Path | |
| 235 // 00000000: 00000002 00000000 00010000 0001 01 331813 /dev/socket/zygote | |
| 236 // 00000000: 00000002 00000000 00010000 0001 01 358606 @xxx_devtools_remote | |
| 237 // 00000000: 00000002 00000000 00010000 0001 01 347300 @yyy_devtools_remote | |
| 238 // | |
| 239 // We need to find records with paths starting from '@' (abstract socket) | |
| 240 // and containing the channel pattern ("_devtools_remote"). | |
| 241 | |
| 242 std::string response; | |
| 243 Status status = ExecuteHostShellCommand(device_serial, "cat /proc/net/unix", & response); | |
|
samuong
2016/10/03 18:50:40
this line is too long (>80 chars)
Rahul Kavalapara
2016/10/05 08:06:42
Done.
| |
| 244 if (!status.IsOk()) | |
| 245 return status; | |
| 246 for (const base::StringPiece& line : | |
| 247 base::SplitStringPiece(response, "\n", base::KEEP_WHITESPACE, | |
| 248 base::SPLIT_WANT_NONEMPTY)) { | |
| 249 std::vector<std::string> fields = | |
| 250 base::SplitString(line, " \r", base::KEEP_WHITESPACE, | |
| 251 base::SPLIT_WANT_NONEMPTY); | |
| 252 if (fields.size() < 8) | |
| 253 continue; | |
| 254 if (fields[3] != "00010000" || fields[5] != "01") | |
|
samuong
2016/10/03 18:50:40
it's not really clear to me what these magic numbe
Rahul Kavalapara
2016/10/03 22:15:52
Please check MapSocketsToProcesses function.
https
Rahul Kavalapara
2016/10/04 01:18:04
I did some more digging, Similar question was post
samuong
2016/10/05 17:29:49
Thanks for digging that up. I was mostly curious a
Rahul Kavalapara
2016/10/05 18:41:53
This code is essentially exercised targeting andro
samuong
2016/10/12 05:18:35
OK, that makes sense. However I'd still like to ma
Rahul Kavalapara
2016/10/12 08:23:04
Fixed.
| |
| 255 continue; | |
| 256 std::string path_field = fields[7]; | |
| 257 if (path_field.size() < 1 || path_field[0] != '@') | |
| 258 continue; | |
| 259 if (path_field.find(process_name) == std::string::npos) | |
|
samuong
2016/10/03 18:50:40
what if there are two processes, where one of the
Rahul Kavalapara
2016/10/03 22:15:52
This is the adaptation from devtools code. That wo
samuong
2016/10/05 17:29:49
I think we should know the full socket name that w
Rahul Kavalapara
2016/10/05 18:41:53
I am sending back the entire name when trying to c
| |
| 260 continue; | |
| 261 | |
| 262 *device_socket = path_field.substr(1); | |
| 263 } | |
| 264 | |
| 265 // We could not find a device socket for the expected process name | |
| 266 if (device_socket->empty()) { | |
| 267 return Status(kUnknownError, | |
| 268 "Failed to find the remote devtools socket for the following pro cess: " + process_name); | |
|
samuong
2016/10/03 18:50:40
this line is too long (>80 chars)
Rahul Kavalapara
2016/10/05 08:06:42
Done.
| |
| 269 } | |
| 270 return Status(kOk); | |
| 271 } | |
| 272 | |
| 229 Status AdbImpl::ExecuteCommand( | 273 Status AdbImpl::ExecuteCommand( |
| 230 const std::string& command, std::string* response) { | 274 const std::string& command, std::string* response) { |
| 231 scoped_refptr<ResponseBuffer> response_buffer = new ResponseBuffer; | 275 scoped_refptr<ResponseBuffer> response_buffer = new ResponseBuffer; |
| 232 VLOG(1) << "Sending adb command: " << command; | 276 VLOG(1) << "Sending adb command: " << command; |
| 233 io_task_runner_->PostTask( | 277 io_task_runner_->PostTask( |
| 234 FROM_HERE, | 278 FROM_HERE, |
| 235 base::Bind(&ExecuteCommandOnIOThread, command, response_buffer, port_)); | 279 base::Bind(&ExecuteCommandOnIOThread, command, response_buffer, port_)); |
| 236 Status status = response_buffer->GetResponse( | 280 Status status = response_buffer->GetResponse( |
| 237 response, base::TimeDelta::FromSeconds(30)); | 281 response, base::TimeDelta::FromSeconds(30)); |
| 238 if (status.IsOk()) { | 282 if (status.IsOk()) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 250 | 294 |
| 251 Status AdbImpl::ExecuteHostShellCommand( | 295 Status AdbImpl::ExecuteHostShellCommand( |
| 252 const std::string& device_serial, | 296 const std::string& device_serial, |
| 253 const std::string& shell_command, | 297 const std::string& shell_command, |
| 254 std::string* response) { | 298 std::string* response) { |
| 255 return ExecuteCommand( | 299 return ExecuteCommand( |
| 256 "host:transport:" + device_serial + "|shell:" + shell_command, | 300 "host:transport:" + device_serial + "|shell:" + shell_command, |
| 257 response); | 301 response); |
| 258 } | 302 } |
| 259 | 303 |
| OLD | NEW |