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

Side by Side Diff: build/android/pylib/device/device_utils.py

Issue 723343002: Update from https://crrev.com/304121 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 a variety of device interactions based on adb. 5 """Provides a variety of device interactions based on adb.
6 6
7 Eventually, this will be based on adb_wrapper. 7 Eventually, this will be based on adb_wrapper.
8 """ 8 """
9 # pylint: disable=W0613 9 # pylint: disable=W0613
10 10
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 retries: number of retries 208 retries: number of retries
209 209
210 Returns: 210 Returns:
211 The device's path to its SD card. 211 The device's path to its SD card.
212 212
213 Raises: 213 Raises:
214 CommandFailedError if the external storage path could not be determined. 214 CommandFailedError if the external storage path could not be determined.
215 CommandTimeoutError on timeout. 215 CommandTimeoutError on timeout.
216 DeviceUnreachableError on missing device. 216 DeviceUnreachableError on missing device.
217 """ 217 """
218 return self._GetExternalStoragePathImpl()
219
220 def _GetExternalStoragePathImpl(self):
221 if 'external_storage' in self._cache: 218 if 'external_storage' in self._cache:
222 return self._cache['external_storage'] 219 return self._cache['external_storage']
223 220
224 value = self.RunShellCommand('echo $EXTERNAL_STORAGE', 221 value = self.RunShellCommand('echo $EXTERNAL_STORAGE',
225 single_line=True, 222 single_line=True,
226 check_return=True) 223 check_return=True)
227 if not value: 224 if not value:
228 raise device_errors.CommandFailedError('$EXTERNAL_STORAGE is not set', 225 raise device_errors.CommandFailedError('$EXTERNAL_STORAGE is not set',
229 str(self)) 226 str(self))
230 self._cache['external_storage'] = value 227 self._cache['external_storage'] = value
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 def pm_ready(): 275 def pm_ready():
279 try: 276 try:
280 return self.GetApplicationPath('android') 277 return self.GetApplicationPath('android')
281 except device_errors.CommandFailedError: 278 except device_errors.CommandFailedError:
282 return False 279 return False
283 280
284 def boot_completed(): 281 def boot_completed():
285 return self.GetProp('sys.boot_completed') == '1' 282 return self.GetProp('sys.boot_completed') == '1'
286 283
287 def wifi_enabled(): 284 def wifi_enabled():
288 return 'Wi-Fi is enabled' in self.RunShellCommand(['dumpsys', 'wifi']) 285 return 'Wi-Fi is enabled' in self.RunShellCommand(['dumpsys', 'wifi'],
286 check_return=False)
289 287
290 self.adb.WaitForDevice() 288 self.adb.WaitForDevice()
291 timeout_retry.WaitFor(sd_card_ready) 289 timeout_retry.WaitFor(sd_card_ready)
292 timeout_retry.WaitFor(pm_ready) 290 timeout_retry.WaitFor(pm_ready)
293 timeout_retry.WaitFor(boot_completed) 291 timeout_retry.WaitFor(boot_completed)
294 if wifi: 292 if wifi:
295 timeout_retry.WaitFor(wifi_enabled) 293 timeout_retry.WaitFor(wifi_enabled)
296 294
297 REBOOT_DEFAULT_TIMEOUT = 10 * _DEFAULT_TIMEOUT 295 REBOOT_DEFAULT_TIMEOUT = 10 * _DEFAULT_TIMEOUT
298 REBOOT_DEFAULT_RETRIES = _DEFAULT_RETRIES 296 REBOOT_DEFAULT_RETRIES = _DEFAULT_RETRIES
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 cmd = 'su -c %s' % cmd 433 cmd = 'su -c %s' % cmd
436 if env: 434 if env:
437 env = ' '.join(env_quote(k, v) for k, v in env.iteritems()) 435 env = ' '.join(env_quote(k, v) for k, v in env.iteritems())
438 cmd = '%s %s' % (env, cmd) 436 cmd = '%s %s' % (env, cmd)
439 if cwd: 437 if cwd:
440 cmd = 'cd %s && %s' % (cmd_helper.SingleQuote(cwd), cmd) 438 cmd = 'cd %s && %s' % (cmd_helper.SingleQuote(cwd), cmd)
441 if timeout is None: 439 if timeout is None:
442 timeout = self._default_timeout 440 timeout = self._default_timeout
443 441
444 try: 442 try:
445 output = self.adb.Shell(cmd, expect_rc=0) 443 output = self.adb.Shell(cmd)
446 except device_errors.AdbShellCommandFailedError as e: 444 except device_errors.AdbShellCommandFailedError as e:
447 if check_return: 445 if check_return:
448 raise 446 raise
449 else: 447 else:
450 output = e.output 448 output = e.output
451 449
452 output = output.splitlines() 450 output = output.splitlines()
453 if single_line: 451 if single_line:
454 if not output: 452 if not output:
455 return '' 453 return ''
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 output = self.old_interface.StartActivity( 522 output = self.old_interface.StartActivity(
525 intent.package, intent.activity, wait_for_completion=blocking, 523 intent.package, intent.activity, wait_for_completion=blocking,
526 action=intent.action, category=single_category, data=intent.data, 524 action=intent.action, category=single_category, data=intent.data,
527 extras=intent.extras, trace_file_name=trace_file_name, 525 extras=intent.extras, trace_file_name=trace_file_name,
528 force_stop=force_stop, flags=intent.flags) 526 force_stop=force_stop, flags=intent.flags)
529 for l in output: 527 for l in output:
530 if l.startswith('Error:'): 528 if l.startswith('Error:'):
531 raise device_errors.CommandFailedError(l, device=str(self)) 529 raise device_errors.CommandFailedError(l, device=str(self))
532 530
533 @decorators.WithTimeoutAndRetriesFromInstance() 531 @decorators.WithTimeoutAndRetriesFromInstance()
532 def StartInstrumentation(self, component, finish=True, raw=False,
533 extras=None, timeout=None, retries=None):
534 if extras is None:
535 extras = {}
536
537 cmd = ['am', 'instrument']
538 if finish:
539 cmd.append('-w')
540 if raw:
541 cmd.append('-r')
542 for k, v in extras.iteritems():
543 cmd.extend(['-e', k, v])
544 cmd.append(component)
545 return self.RunShellCommand(cmd, check_return=True)
546
547 @decorators.WithTimeoutAndRetriesFromInstance()
534 def BroadcastIntent(self, intent, timeout=None, retries=None): 548 def BroadcastIntent(self, intent, timeout=None, retries=None):
535 """Send a broadcast intent. 549 """Send a broadcast intent.
536 550
537 Args: 551 Args:
538 intent: An Intent to broadcast. 552 intent: An Intent to broadcast.
539 timeout: timeout in seconds 553 timeout: timeout in seconds
540 retries: number of retries 554 retries: number of retries
541 555
542 Raises: 556 Raises:
543 CommandTimeoutError on timeout. 557 CommandTimeoutError on timeout.
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 if not files: 775 if not files:
762 return 776 return
763 777
764 with tempfile.NamedTemporaryFile(suffix='.zip') as zip_file: 778 with tempfile.NamedTemporaryFile(suffix='.zip') as zip_file:
765 zip_proc = multiprocessing.Process( 779 zip_proc = multiprocessing.Process(
766 target=DeviceUtils._CreateDeviceZip, 780 target=DeviceUtils._CreateDeviceZip,
767 args=(zip_file.name, files)) 781 args=(zip_file.name, files))
768 zip_proc.start() 782 zip_proc.start()
769 zip_proc.join() 783 zip_proc.join()
770 784
771 zip_on_device = '%s/tmp.zip' % self._GetExternalStoragePathImpl() 785 zip_on_device = '%s/tmp.zip' % self.GetExternalStoragePath()
772 try: 786 try:
773 self.adb.Push(zip_file.name, zip_on_device) 787 self.adb.Push(zip_file.name, zip_on_device)
774 self.RunShellCommand( 788 self.RunShellCommand(
775 ['unzip', zip_on_device], 789 ['unzip', zip_on_device],
776 as_root=True, 790 as_root=True,
777 env={'PATH': '$PATH:%s' % install_commands.BIN_DIR}, 791 env={'PATH': '$PATH:%s' % install_commands.BIN_DIR},
778 check_return=True) 792 check_return=True)
779 finally: 793 finally:
780 if zip_proc.is_alive(): 794 if zip_proc.is_alive():
781 zip_proc.terminate() 795 zip_proc.terminate()
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 Returns: 1166 Returns:
1153 A Parallelizer operating over |devices|. 1167 A Parallelizer operating over |devices|.
1154 """ 1168 """
1155 if not devices or len(devices) == 0: 1169 if not devices or len(devices) == 0:
1156 devices = pylib.android_commands.GetAttachedDevices() 1170 devices = pylib.android_commands.GetAttachedDevices()
1157 parallelizer_type = (parallelizer.Parallelizer if async 1171 parallelizer_type = (parallelizer.Parallelizer if async
1158 else parallelizer.SyncParallelizer) 1172 else parallelizer.SyncParallelizer)
1159 return parallelizer_type([ 1173 return parallelizer_type([
1160 d if isinstance(d, DeviceUtils) else DeviceUtils(d) 1174 d if isinstance(d, DeviceUtils) else DeviceUtils(d)
1161 for d in devices]) 1175 for d in devices])
OLDNEW
« no previous file with comments | « build/android/pylib/device/adb_wrapper.py ('k') | build/android/pylib/device/device_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698