Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1691)

Side by Side Diff: chrome/test/chromedriver/chrome/adb_impl.cc

Issue 2375613002: Fix Chromedriver Issue 749
Patch Set: Bug Fix for chromedriver issue 749 Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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,
johnchen 2017/07/12 21:54:43 This doesn't work correctly for WebView apps. The
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 // The code that generates this file is in the unix_seq_show() function in
243 // net/unix/af_unix.c in the kernel source. Looking at include/net/af_unix.h
244 // is also helpful, to see the data structures in use.
245 //
246 // The socket path is always the last column in the output, and
247 // the Android Kernel source matches the stock kernel in this respect.
248 std::string response;
249 Status status = ExecuteHostShellCommand(device_serial,
250 "cat /proc/net/unix", &response);
251 std::string kDevToolsSocketSuffix = "_devtools_remote";
252 if (!status.IsOk())
253 return status;
254 for (const base::StringPiece& line :
255 base::SplitStringPiece(response, "\n", base::KEEP_WHITESPACE,
256 base::SPLIT_WANT_NONEMPTY)) {
257 std::vector<std::string> fields =
258 base::SplitString(line, " \r", base::KEEP_WHITESPACE,
259 base::SPLIT_WANT_NONEMPTY);
260 if (fields.size() < 8)
261 continue;
262 // We are looking for sockets accepting connections and there is no TCP
263 // connection established. Below values are defined in
264 // the kernel for reference
265 // fields[3] (Flags) != __SO_ACCEPTCON (include/uapi/net.h)
266 // fields[5] (State) != TCP_ESTABLISHED (include/net/tcp_states.h)
267 if (fields[3] != "00010000" || fields[5] != "01")
268 continue;
269 std::string path_field = fields[7];
270 if (path_field.size() < 1 || path_field[0] != '@')
271 continue;
272 size_t socket_name_pos = path_field.find(kDevToolsSocketSuffix);
273 if (socket_name_pos == std::string::npos)
274 continue;
275
276 std::string socket_name = path_field.substr(1, socket_name_pos - 1);
277 if (socket_name.compare(process_name) == 0) {
278 *device_socket = path_field.substr(1);
279 }
280 }
281
282 // We could not find a device socket for the expected process name
283 if (device_socket->empty()) {
284 return Status(kUnknownError,
285 "Failed to find remote devtools socket for: " + process_name);
286 }
287 return Status(kOk);
288 }
289
229 Status AdbImpl::ExecuteCommand( 290 Status AdbImpl::ExecuteCommand(
230 const std::string& command, std::string* response) { 291 const std::string& command, std::string* response) {
231 scoped_refptr<ResponseBuffer> response_buffer = new ResponseBuffer; 292 scoped_refptr<ResponseBuffer> response_buffer = new ResponseBuffer;
232 VLOG(1) << "Sending adb command: " << command; 293 VLOG(1) << "Sending adb command: " << command;
233 io_task_runner_->PostTask( 294 io_task_runner_->PostTask(
234 FROM_HERE, 295 FROM_HERE,
235 base::Bind(&ExecuteCommandOnIOThread, command, response_buffer, port_)); 296 base::Bind(&ExecuteCommandOnIOThread, command, response_buffer, port_));
236 Status status = response_buffer->GetResponse( 297 Status status = response_buffer->GetResponse(
237 response, base::TimeDelta::FromSeconds(30)); 298 response, base::TimeDelta::FromSeconds(30));
238 if (status.IsOk()) { 299 if (status.IsOk()) {
(...skipping 11 matching lines...) Expand all
250 311
251 Status AdbImpl::ExecuteHostShellCommand( 312 Status AdbImpl::ExecuteHostShellCommand(
252 const std::string& device_serial, 313 const std::string& device_serial,
253 const std::string& shell_command, 314 const std::string& shell_command,
254 std::string* response) { 315 std::string* response) {
255 return ExecuteCommand( 316 return ExecuteCommand(
256 "host:transport:" + device_serial + "|shell:" + shell_command, 317 "host:transport:" + device_serial + "|shell:" + shell_command,
257 response); 318 response);
258 } 319 }
259 320
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/chrome/adb_impl.h ('k') | chrome/test/chromedriver/chrome/device_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698