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

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

Issue 929603002: [Android] Add PIE support for ICS devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
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=unused-argument 9 # pylint: disable=unused-argument
10 10
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 should_install = bool(self._GetChangedFilesImpl(apk_path, device_path)) 405 should_install = bool(self._GetChangedFilesImpl(apk_path, device_path))
406 if should_install and not reinstall: 406 if should_install and not reinstall:
407 self.adb.Uninstall(package_name) 407 self.adb.Uninstall(package_name)
408 else: 408 else:
409 should_install = True 409 should_install = True
410 if should_install: 410 if should_install:
411 self.adb.Install(apk_path, reinstall=reinstall) 411 self.adb.Install(apk_path, reinstall=reinstall)
412 412
413 @decorators.WithTimeoutAndRetriesFromInstance() 413 @decorators.WithTimeoutAndRetriesFromInstance()
414 def RunShellCommand(self, cmd, check_return=False, cwd=None, env=None, 414 def RunShellCommand(self, cmd, check_return=False, cwd=None, env=None,
415 as_root=False, single_line=False, 415 as_root=False, with_pie=False, single_line=False,
perezju 2015/02/16 10:25:23 Do we expect many clients needing this option? If
jbudorick 2015/02/17 15:15:10 I don't, though I do anticipate it being more than
perezju 2015/02/17 16:04:26 I'm not crazy about this. We're adding this option
jbudorick 2015/02/17 16:14:18 I suppose it makes sense to hold off on adding thi
416 timeout=None, retries=None): 416 timeout=None, retries=None):
417 """Run an ADB shell command. 417 """Run an ADB shell command.
418 418
419 The command to run |cmd| should be a sequence of program arguments or else 419 The command to run |cmd| should be a sequence of program arguments or else
420 a single string. 420 a single string.
421 421
422 When |cmd| is a sequence, it is assumed to contain the name of the command 422 When |cmd| is a sequence, it is assumed to contain the name of the command
423 to run followed by its arguments. In this case, arguments are passed to the 423 to run followed by its arguments. In this case, arguments are passed to the
424 command exactly as given, without any further processing by the shell. This 424 command exactly as given, without any further processing by the shell. This
425 allows to easily pass arguments containing spaces or special characters 425 allows to easily pass arguments containing spaces or special characters
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 try: 472 try:
473 return self.adb.Shell(cmd) 473 return self.adb.Shell(cmd)
474 except device_errors.AdbCommandFailedError as exc: 474 except device_errors.AdbCommandFailedError as exc:
475 if check_return: 475 if check_return:
476 raise 476 raise
477 else: 477 else:
478 return exc.output 478 return exc.output
479 479
480 if not isinstance(cmd, basestring): 480 if not isinstance(cmd, basestring):
481 cmd = ' '.join(cmd_helper.SingleQuote(s) for s in cmd) 481 cmd = ' '.join(cmd_helper.SingleQuote(s) for s in cmd)
482 if with_pie and (self.build_version_sdk <
483 constants.ANDROID_SDK_VERSION_CODES.JELLY_BEAN):
484 cmd = '%s %s' % (self.GetDevicePieWrapper(), cmd)
482 if env: 485 if env:
483 env = ' '.join(env_quote(k, v) for k, v in env.iteritems()) 486 env = ' '.join(env_quote(k, v) for k, v in env.iteritems())
484 cmd = '%s %s' % (env, cmd) 487 cmd = '%s %s' % (env, cmd)
485 if cwd: 488 if cwd:
486 cmd = 'cd %s && %s' % (cmd_helper.SingleQuote(cwd), cmd) 489 cmd = 'cd %s && %s' % (cmd_helper.SingleQuote(cwd), cmd)
487 if as_root and self.NeedsSU(): 490 if as_root and self.NeedsSU():
488 # "su -c sh -c" allows using shell features in |cmd| 491 # "su -c sh -c" allows using shell features in |cmd|
489 cmd = 'su -c sh -c %s' % cmd_helper.SingleQuote(cmd) 492 cmd = 'su -c sh -c %s' % cmd_helper.SingleQuote(cmd)
490 if timeout is None: 493 if timeout is None:
491 timeout = self._default_timeout 494 timeout = self._default_timeout
(...skipping 13 matching lines...) Expand all
505 return '' 508 return ''
506 elif len(output) == 1: 509 elif len(output) == 1:
507 return output[0] 510 return output[0]
508 else: 511 else:
509 msg = 'one line of output was expected, but got: %s' 512 msg = 'one line of output was expected, but got: %s'
510 raise device_errors.CommandFailedError(msg % output, str(self)) 513 raise device_errors.CommandFailedError(msg % output, str(self))
511 else: 514 else:
512 return output 515 return output
513 516
514 @decorators.WithTimeoutAndRetriesFromInstance() 517 @decorators.WithTimeoutAndRetriesFromInstance()
518 def GetDevicePieWrapper(self, timeout=None, retries=None):
jbudorick 2015/02/14 00:48:54 Maybe this should be done as a property, wdyt?
perezju 2015/02/16 10:25:23 I would lean a bit towards "No". I would reserve p
jbudorick 2015/02/17 15:15:10 Acknowledged.
519 """Gets the absolute path to the run_pie wrapper on the device.
520
521 We have to build our device executables to be PIE, but they need to be able
522 to run on versions of android that don't support PIE (i.e. ICS and below).
523 To do so, we push a wrapper to the device that lets older android versions
524 run PIE executables. This method pushes that wrapper to the device if
525 necessary and returns the path to it.
526
527 This is exposed publicly to allow clients to write scripts using run_pie
528 (e.g. md5sum.CalculateDeviceMd5Sum). However, in most cases,
529 RunShellCommand(..., with_pie=True) should suffice.
530
531 Args:
532 timeout: timeout in seconds
533 retries: number of retries
534
535 Returns:
536 The path to the PIE wrapper on the device, or an empty string if the
537 device does not require the wrapper.
538 """
539 if 'run_pie' not in self._cache:
540 pie = ''
541 if (self.build_version_sdk <
542 constants.ANDROID_SDK_VERSION_CODES.JELLY_BEAN):
543 host_pie_path = os.path.join(constants.GetOutDirectory(), 'run_pie')
544 if not os.path.exists(host_pie_path):
545 raise device_errors.CommandFailedError('Please build run_pie')
546 pie = '%s/run_pie' % constants.TEST_EXECUTABLE_DIR
547 self.adb.Push(host_pie_path, pie)
548
549 self._cache['run_pie'] = pie
550
551 return self._cache['run_pie']
552
553 @decorators.WithTimeoutAndRetriesFromInstance()
515 def KillAll(self, process_name, signum=9, as_root=False, blocking=False, 554 def KillAll(self, process_name, signum=9, as_root=False, blocking=False,
516 timeout=None, retries=None): 555 timeout=None, retries=None):
517 """Kill all processes with the given name on the device. 556 """Kill all processes with the given name on the device.
518 557
519 Args: 558 Args:
520 process_name: A string containing the name of the process to kill. 559 process_name: A string containing the name of the process to kill.
521 signum: An integer containing the signal number to send to kill. Defaults 560 signum: An integer containing the signal number to send to kill. Defaults
522 to 9 (SIGKILL). 561 to 9 (SIGKILL).
523 as_root: A boolean indicating whether the kill should be executed with 562 as_root: A boolean indicating whether the kill should be executed with
524 root privileges. 563 root privileges.
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 Returns: 1405 Returns:
1367 A Parallelizer operating over |devices|. 1406 A Parallelizer operating over |devices|.
1368 """ 1407 """
1369 if not devices: 1408 if not devices:
1370 devices = adb_wrapper.AdbWrapper.GetDevices() 1409 devices = adb_wrapper.AdbWrapper.GetDevices()
1371 devices = [d if isinstance(d, cls) else cls(d) for d in devices] 1410 devices = [d if isinstance(d, cls) else cls(d) for d in devices]
1372 if async: 1411 if async:
1373 return parallelizer.Parallelizer(devices) 1412 return parallelizer.Parallelizer(devices)
1374 else: 1413 else:
1375 return parallelizer.SyncParallelizer(devices) 1414 return parallelizer.SyncParallelizer(devices)
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/device/device_utils_test.py » ('j') | build/android/pylib/device/device_utils_test.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698