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

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

Issue 15930002: [Android] Force stop test app before launch (start -S) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit addressed Created 7 years, 7 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 | « no previous file | build/android/pylib/gtest/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 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 647
648 def CloseApplication(self, package): 648 def CloseApplication(self, package):
649 """Attempt to close down the application, using increasing violence. 649 """Attempt to close down the application, using increasing violence.
650 650
651 Args: 651 Args:
652 package: Name of the process to kill off, e.g. 652 package: Name of the process to kill off, e.g.
653 com.google.android.apps.chrome 653 com.google.android.apps.chrome
654 """ 654 """
655 self.RunShellCommand('am force-stop ' + package) 655 self.RunShellCommand('am force-stop ' + package)
656 656
657 def GetApplicationPath(self, package):
658 """Get the installed apk path on the device for the given package.
659
660 Args:
661 package: Name of the package.
662
663 Returns:
664 Path to the apk on the device if it exists, None otherwise.
665 """
666 pm_path_output = self.RunShellCommand('pm path ' + package)
667 # The path output contains anything if and only if the package
668 # exists.
669 if pm_path_output:
670 # pm_path_output is of the form: "package:/path/to/foo.apk"
671 return pm_path_output[0].split(':')[1]
672 else:
673 return None
674
657 def ClearApplicationState(self, package): 675 def ClearApplicationState(self, package):
658 """Closes and clears all state for the given |package|.""" 676 """Closes and clears all state for the given |package|."""
659 # Check that the package exists before clearing it. Necessary because 677 # Check that the package exists before clearing it. Necessary because
660 # calling pm clear on a package that doesn't exist may never return. 678 # calling pm clear on a package that doesn't exist may never return.
661 pm_path_output = self.RunShellCommand('pm path ' + package) 679 pm_path_output = self.RunShellCommand('pm path ' + package)
662 # The path output only contains anything if and only if the package exists. 680 # The path output only contains anything if and only if the package exists.
663 if pm_path_output: 681 if pm_path_output:
664 self.CloseApplication(package)
665 self.RunShellCommand('pm clear ' + package) 682 self.RunShellCommand('pm clear ' + package)
666 683
667 def SendKeyEvent(self, keycode): 684 def SendKeyEvent(self, keycode):
668 """Sends keycode to the device. 685 """Sends keycode to the device.
669 686
670 Args: 687 Args:
671 keycode: Numeric keycode to send (see "enum" at top of file). 688 keycode: Numeric keycode to send (see "enum" at top of file).
672 """ 689 """
673 self.RunShellCommand('input keyevent %d' % keycode) 690 self.RunShellCommand('input keyevent %d' % keycode)
674 691
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 """ 1329 """
1313 def __init__(self, output): 1330 def __init__(self, output):
1314 self._output = output 1331 self._output = output
1315 1332
1316 def write(self, data): 1333 def write(self, data):
1317 data = data.replace('\r\r\n', '\n') 1334 data = data.replace('\r\r\n', '\n')
1318 self._output.write(data) 1335 self._output.write(data)
1319 1336
1320 def flush(self): 1337 def flush(self):
1321 self._output.flush() 1338 self._output.flush()
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/gtest/test_package_apk.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698