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

Side by Side Diff: build/android/pylib/android_commands.py

Issue 10824227: Organize adb install cmds and reboot on failure (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « build/android/adb_install_content_shell ('k') | build/android/pylib/test_package_apk.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 """Reboots the device and waits for the package manager to return. 279 """Reboots the device and waits for the package manager to return.
280 280
281 Args: 281 Args:
282 full_reboot: Whether to fully reboot the device or just restart the shell. 282 full_reboot: Whether to fully reboot the device or just restart the shell.
283 """ 283 """
284 # TODO(torne): hive can't reboot the device either way without breaking the 284 # TODO(torne): hive can't reboot the device either way without breaking the
285 # connection; work out if we can handle this better 285 # connection; work out if we can handle this better
286 if os.environ.get('USING_HIVE'): 286 if os.environ.get('USING_HIVE'):
287 logging.warning('Ignoring reboot request as we are on hive') 287 logging.warning('Ignoring reboot request as we are on hive')
288 return 288 return
289 if full_reboot: 289 if full_reboot or not self.IsRootEnabled():
290 self._adb.SendCommand('reboot') 290 self._adb.SendCommand('reboot')
291 timeout = 300
291 else: 292 else:
292 self.RestartShell() 293 self.RestartShell()
294 timeout = 120
293 self.WaitForDevicePm() 295 self.WaitForDevicePm()
294 self.StartMonitoringLogcat(timeout=120) 296 self.StartMonitoringLogcat(timeout=timeout)
295 self.WaitForLogMatch(BOOT_COMPLETE_RE, None) 297 self.WaitForLogMatch(BOOT_COMPLETE_RE, None)
296 298
297 def Uninstall(self, package): 299 def Uninstall(self, package):
298 """Uninstalls the specified package from the device. 300 """Uninstalls the specified package from the device.
299 301
300 Args: 302 Args:
301 package: Name of the package to remove. 303 package: Name of the package to remove.
302 304
303 Returns: 305 Returns:
304 A status string returned by adb uninstall 306 A status string returned by adb uninstall
305 """ 307 """
306 uninstall_command = 'uninstall %s' % package 308 uninstall_command = 'uninstall %s' % package
307 309
308 logging.info('>>> $' + uninstall_command) 310 logging.info('>>> $' + uninstall_command)
309 return self._adb.SendCommand(uninstall_command, timeout_time=60) 311 return self._adb.SendCommand(uninstall_command, timeout_time=60)
310 312
311 def Install(self, package_file_path): 313 def Install(self, package_file_path, reinstall=False):
312 """Installs the specified package to the device. 314 """Installs the specified package to the device.
313 315
314 Args: 316 Args:
315 package_file_path: Path to .apk file to install. 317 package_file_path: Path to .apk file to install.
318 reinstall: Whether to reinstall over existing package
316 319
317 Returns: 320 Returns:
318 A status string returned by adb install 321 A status string returned by adb install
319 """ 322 """
320 assert os.path.isfile(package_file_path) 323 assert os.path.isfile(package_file_path)
321 324
322 install_command = 'install %s' % package_file_path 325 if reinstall:
326 install_cmd = 'install -r %s'
327 else:
328 install_cmd = 'install %s'
323 329
324 logging.info('>>> $' + install_command) 330 return self._adb.SendCommand(install_cmd % package_file_path,
325 return self._adb.SendCommand(install_command, timeout_time=2*60) 331 timeout_time=2*60, cmd_logger=logging,
bulach 2012/08/10 11:47:07 nit: remove cmd_logger? also, spaces: 2 * 60
Isaac (away) 2012/08/17 04:41:49 removed cmd_logger. as far as spacing, would rath
332 retry_count=0)
333
334 def ManagedInstall(self, apk_path, keep_data, package_name=None,
335 reboots_on_failure=2):
336 """Installs the specified package to the device. Reboots the device on
337 package manager timeouts.
338
339 Args:
340 apk_path: Path to .apk file to install.
341 keep_data: Whether to keep data if package already exists
342 package_name: Package name (only needed if keep_data=False)
343 reboots_on_failure: number of time to reboot if package manager is frozen.
344
345 Returns:
346 A status string returned by adb install
347 """
348 reboots_left = reboots_on_failure
349 while True:
350 try:
351 if not keep_data:
352 self.Uninstall(package_name)
353 install_status = self.Install(apk_path, keep_data)
354 if 'Success' in install_status:
355 return install_status
356 except errors.WaitForResponseTimedOutError:
357 logging.info('Timout on installing %s' % apk_path)
358
359 if reboots_left <= 0:
360 raise Exception('Install failure')
361
362 # Force a hard reboot on last attempt
363 self.Reboot(full_reboot=(reboots_left == 1))
364 reboots_left -= 1
326 365
327 def MakeSystemFolderWritable(self): 366 def MakeSystemFolderWritable(self):
328 """Remounts the /system folder rw. """ 367 """Remounts the /system folder rw. """
329 out = self._adb.SendCommand('remount') 368 out = self._adb.SendCommand('remount')
330 if out.strip() != 'remount succeeded': 369 if out.strip() != 'remount succeeded':
331 raise errors.MsgException('Remount failed: %s' % out) 370 raise errors.MsgException('Remount failed: %s' % out)
332 371
333 def RestartAdbServer(self): 372 def RestartAdbServer(self):
334 """Restart the adb server.""" 373 """Restart the adb server."""
335 self.KillAdbServer() 374 self.KillAdbServer()
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 timeout_time: Number of seconds to wait for command to respond before 449 timeout_time: Number of seconds to wait for command to respond before
411 retrying, used by AdbInterface.SendShellCommand. 450 retrying, used by AdbInterface.SendShellCommand.
412 log_result: Boolean to indicate whether we should log the result of the 451 log_result: Boolean to indicate whether we should log the result of the
413 shell command. 452 shell command.
414 453
415 Returns: 454 Returns:
416 list containing the lines of output received from running the command 455 list containing the lines of output received from running the command
417 """ 456 """
418 logging.info('>>> $' + command) 457 logging.info('>>> $' + command)
419 if "'" in command: logging.warning(command + " contains ' quotes") 458 if "'" in command: logging.warning(command + " contains ' quotes")
420 result = self._adb.SendShellCommand("'%s'" % command, 459 result = self._adb.SendShellCommand(
421 timeout_time).splitlines() 460 "'%s'" % command, timeout_time).splitlines()
461 if ['error: device not found'] == result:
462 raise errors.DeviceUnresponsiveError('device not found')
422 if log_result: 463 if log_result:
423 logging.info('\n>>> '.join(result)) 464 logging.info('\n>>> '.join(result))
424 return result 465 return result
425 466
426 def KillAll(self, process): 467 def KillAll(self, process):
427 """Android version of killall, connected via adb. 468 """Android version of killall, connected via adb.
428 469
429 Args: 470 Args:
430 process: name of the process to kill off 471 process: name of the process to kill off
431 472
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 elif isinstance(value, int): 514 elif isinstance(value, int):
474 cmd += ' --ei' 515 cmd += ' --ei'
475 else: 516 else:
476 raise NotImplementedError( 517 raise NotImplementedError(
477 'Need to teach StartActivity how to pass %s extras' % type(value)) 518 'Need to teach StartActivity how to pass %s extras' % type(value))
478 cmd += ' %s %s' % (key, value) 519 cmd += ' %s %s' % (key, value)
479 if trace_file_name: 520 if trace_file_name:
480 cmd += ' --start-profiler ' + trace_file_name 521 cmd += ' --start-profiler ' + trace_file_name
481 self.RunShellCommand(cmd) 522 self.RunShellCommand(cmd)
482 523
483
484 def CloseApplication(self, package): 524 def CloseApplication(self, package):
485 """Attempt to close down the application, using increasing violence. 525 """Attempt to close down the application, using increasing violence.
486 526
487 Args: 527 Args:
488 package: Name of the process to kill off, e.g. 528 package: Name of the process to kill off, e.g.
489 com.google.android.apps.chrome 529 com.google.android.apps.chrome
490 """ 530 """
491 self.RunShellCommand('am force-stop ' + package) 531 self.RunShellCommand('am force-stop ' + package)
492 532
493 def ClearApplicationState(self, package): 533 def ClearApplicationState(self, package):
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 if len(process_results) <= 8: 985 if len(process_results) <= 8:
946 continue 986 continue
947 # Column 0 is the executable name 987 # Column 0 is the executable name
948 # Column 1 is the pid 988 # Column 1 is the pid
949 # Column 8 is the Inode in use 989 # Column 8 is the Inode in use
950 if process_results[8] == socket_name: 990 if process_results[8] == socket_name:
951 pids.append( (int(process_results[1]), process_results[0]) ) 991 pids.append( (int(process_results[1]), process_results[0]) )
952 break 992 break
953 logging.info('PidsUsingDevicePort: %s', pids) 993 logging.info('PidsUsingDevicePort: %s', pids)
954 return pids 994 return pids
OLDNEW
« no previous file with comments | « build/android/adb_install_content_shell ('k') | build/android/pylib/test_package_apk.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698