| 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 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 """Attempt to close down the application, using increasing violence. | 634 """Attempt to close down the application, using increasing violence. |
| 635 | 635 |
| 636 Args: | 636 Args: |
| 637 package: Name of the process to kill off, e.g. | 637 package: Name of the process to kill off, e.g. |
| 638 com.google.android.apps.chrome | 638 com.google.android.apps.chrome |
| 639 """ | 639 """ |
| 640 self.RunShellCommand('am force-stop ' + package) | 640 self.RunShellCommand('am force-stop ' + package) |
| 641 | 641 |
| 642 def ClearApplicationState(self, package): | 642 def ClearApplicationState(self, package): |
| 643 """Closes and clears all state for the given |package|.""" | 643 """Closes and clears all state for the given |package|.""" |
| 644 self.CloseApplication(package) | 644 # Check that the package exists before clearing it. Necessary because |
| 645 self.RunShellCommand('su -c rm -r /data/data/%s/app_*' % package) | 645 # calling pm clear on a package that doesn't exist may never return. |
| 646 self.RunShellCommand('su -c rm -r /data/data/%s/cache/*' % package) | 646 pm_path_output = self.RunShellCommand('pm path ' + package) |
| 647 self.RunShellCommand('su -c rm -r /data/data/%s/files/*' % package) | 647 # The path output only contains anything if and only if the package exists. |
| 648 self.RunShellCommand('su -c rm -r /data/data/%s/shared_prefs/*' % package) | 648 if pm_path_output: |
| 649 self.CloseApplication(package) |
| 650 self.RunShellCommand('pm clear ' + package) |
| 649 | 651 |
| 650 def SendKeyEvent(self, keycode): | 652 def SendKeyEvent(self, keycode): |
| 651 """Sends keycode to the device. | 653 """Sends keycode to the device. |
| 652 | 654 |
| 653 Args: | 655 Args: |
| 654 keycode: Numeric keycode to send (see "enum" at top of file). | 656 keycode: Numeric keycode to send (see "enum" at top of file). |
| 655 """ | 657 """ |
| 656 self.RunShellCommand('input keyevent %d' % keycode) | 658 self.RunShellCommand('input keyevent %d' % keycode) |
| 657 | 659 |
| 658 def PushIfNeeded(self, local_path, device_path): | 660 def PushIfNeeded(self, local_path, device_path): |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 """ | 1220 """ |
| 1219 def __init__(self, output): | 1221 def __init__(self, output): |
| 1220 self._output = output | 1222 self._output = output |
| 1221 | 1223 |
| 1222 def write(self, data): | 1224 def write(self, data): |
| 1223 data = data.replace('\r\r\n', '\n') | 1225 data = data.replace('\r\r\n', '\n') |
| 1224 self._output.write(data) | 1226 self._output.write(data) |
| 1225 | 1227 |
| 1226 def flush(self): | 1228 def flush(self): |
| 1227 self._output.flush() | 1229 self._output.flush() |
| OLD | NEW |