OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Provides an interface to communicate with the device via the adb command. | 5 """Provides an interface to communicate with the device via the adb command. |
6 | 6 |
7 Assumes adb binary is currently on system path. | 7 Assumes adb binary is currently on system path. |
8 """ | 8 """ |
9 | 9 |
10 import collections | 10 import collections |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 | 312 |
313 logging.info('>>> $' + install_command) | 313 logging.info('>>> $' + install_command) |
314 return self._adb.SendCommand(install_command, timeout_time=2*60) | 314 return self._adb.SendCommand(install_command, timeout_time=2*60) |
315 | 315 |
316 def MakeSystemFolderWritable(self): | 316 def MakeSystemFolderWritable(self): |
317 """Remounts the /system folder rw. """ | 317 """Remounts the /system folder rw. """ |
318 out = self._adb.SendCommand('remount') | 318 out = self._adb.SendCommand('remount') |
319 if out.strip() != 'remount succeeded': | 319 if out.strip() != 'remount succeeded': |
320 raise errors.MsgException('Remount failed: %s' % out) | 320 raise errors.MsgException('Remount failed: %s' % out) |
321 | 321 |
| 322 def RestartAdbServer(self): |
| 323 """Restart the adb server.""" |
| 324 self.KillAdbServer() |
| 325 self.StartAdbServer() |
| 326 |
| 327 def KillAdbServer(self): |
| 328 """Kill adb server.""" |
| 329 adb_cmd = ['adb', 'kill-server'] |
| 330 return cmd_helper.RunCmd(adb_cmd) |
| 331 |
| 332 def StartAdbServer(self): |
| 333 """Start adb server.""" |
| 334 adb_cmd = ['adb', 'start-server'] |
| 335 return cmd_helper.RunCmd(adb_cmd) |
| 336 |
| 337 def WaitForSystemBootCompleted(self, wait_time): |
| 338 """Waits for targeted system's boot_completed flag to be set. |
| 339 |
| 340 Args: |
| 341 wait_time: time in seconds to wait |
| 342 |
| 343 Raises: |
| 344 WaitForResponseTimedOutError if wait_time elapses and flag still not |
| 345 set. |
| 346 """ |
| 347 logging.info('Waiting for system boot completed...') |
| 348 self._adb.SendCommand('wait-for-device') |
| 349 # Now the device is there, but system not boot completed. |
| 350 # Query the sys.boot_completed flag with a basic command |
| 351 boot_completed = False |
| 352 attempts = 0 |
| 353 wait_period = 5 |
| 354 while not boot_completed and (attempts * wait_period) < wait_time: |
| 355 output = self._adb.SendShellCommand('getprop sys.boot_completed', |
| 356 retry_count=1) |
| 357 output = output.strip() |
| 358 if output == '1': |
| 359 boot_completed = True |
| 360 else: |
| 361 # If 'error: xxx' returned when querying the flag, it means |
| 362 # adb server lost the connection to the emulator, so restart the adb |
| 363 # server. |
| 364 if 'error:' in output: |
| 365 self.RestartAdbServer() |
| 366 time.sleep(wait_period) |
| 367 attempts += 1 |
| 368 if not boot_completed: |
| 369 raise errors.WaitForResponseTimedOutError( |
| 370 'sys.boot_completed flag was not set after %s seconds' % wait_time) |
| 371 |
322 def WaitForSdCardReady(self, timeout_time): | 372 def WaitForSdCardReady(self, timeout_time): |
323 """Wait for the SD card ready before pushing data into it.""" | 373 """Wait for the SD card ready before pushing data into it.""" |
324 logging.info('Waiting for SD card ready...') | 374 logging.info('Waiting for SD card ready...') |
325 sdcard_ready = False | 375 sdcard_ready = False |
326 attempts = 0 | 376 attempts = 0 |
327 wait_period = 5 | 377 wait_period = 5 |
328 while not sdcard_ready and attempts * wait_period < timeout_time: | 378 while not sdcard_ready and attempts * wait_period < timeout_time: |
329 output = self.RunShellCommand('ls /sdcard/') | 379 output = self.RunShellCommand('ls /sdcard/') |
330 if len(output) > 0: | 380 if len(output) > 0: |
331 sdcard_ready = True | 381 sdcard_ready = True |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 if len(process_results) <= 8: | 934 if len(process_results) <= 8: |
885 continue | 935 continue |
886 # Column 0 is the executable name | 936 # Column 0 is the executable name |
887 # Column 1 is the pid | 937 # Column 1 is the pid |
888 # Column 8 is the Inode in use | 938 # Column 8 is the Inode in use |
889 if process_results[8] == socket_name: | 939 if process_results[8] == socket_name: |
890 pids.append( (int(process_results[1]), process_results[0]) ) | 940 pids.append( (int(process_results[1]), process_results[0]) ) |
891 break | 941 break |
892 logging.info('PidsUsingDevicePort: %s', pids) | 942 logging.info('PidsUsingDevicePort: %s', pids) |
893 return pids | 943 return pids |
OLD | NEW |