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

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

Issue 1317453004: [Android] Fix date setting + su on M. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « build/android/provision_devices.py ('k') | build/android/pylib/device/device_utils_test.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 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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 (e.g. because the device has a user build), or not needed (because adbd 270 (e.g. because the device has a user build), or not needed (because adbd
271 already has root privileges). 271 already has root privileges).
272 272
273 Raises: 273 Raises:
274 CommandTimeoutError on timeout. 274 CommandTimeoutError on timeout.
275 DeviceUnreachableError on missing device. 275 DeviceUnreachableError on missing device.
276 """ 276 """
277 if 'needs_su' not in self._cache: 277 if 'needs_su' not in self._cache:
278 try: 278 try:
279 self.RunShellCommand( 279 self.RunShellCommand(
280 'su -c ls /root && ! ls /root', check_return=True, 280 '%s && ! ls /root' % self._Su('ls /root'), check_return=True,
281 timeout=self._default_timeout if timeout is DEFAULT else timeout, 281 timeout=self._default_timeout if timeout is DEFAULT else timeout,
282 retries=self._default_retries if retries is DEFAULT else retries) 282 retries=self._default_retries if retries is DEFAULT else retries)
283 self._cache['needs_su'] = True 283 self._cache['needs_su'] = True
284 except device_errors.AdbCommandFailedError: 284 except device_errors.AdbCommandFailedError:
285 self._cache['needs_su'] = False 285 self._cache['needs_su'] = False
286 return self._cache['needs_su'] 286 return self._cache['needs_su']
287 287
288 def _Su(self, command):
289 if (self.build_version_sdk
290 >= constants.ANDROID_SDK_VERSION_CODES.MARSHMALLOW):
291 return 'su 0 %s' % command
292 return 'su -c %s' % command
288 293
289 @decorators.WithTimeoutAndRetriesFromInstance() 294 @decorators.WithTimeoutAndRetriesFromInstance()
290 def EnableRoot(self, timeout=None, retries=None): 295 def EnableRoot(self, timeout=None, retries=None):
291 """Restarts adbd with root privileges. 296 """Restarts adbd with root privileges.
292 297
293 Args: 298 Args:
294 timeout: timeout in seconds 299 timeout: timeout in seconds
295 retries: number of retries 300 retries: number of retries
296 301
297 Raises: 302 Raises:
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 722
718 if not isinstance(cmd, basestring): 723 if not isinstance(cmd, basestring):
719 cmd = ' '.join(cmd_helper.SingleQuote(s) for s in cmd) 724 cmd = ' '.join(cmd_helper.SingleQuote(s) for s in cmd)
720 if env: 725 if env:
721 env = ' '.join(env_quote(k, v) for k, v in env.iteritems()) 726 env = ' '.join(env_quote(k, v) for k, v in env.iteritems())
722 cmd = '%s %s' % (env, cmd) 727 cmd = '%s %s' % (env, cmd)
723 if cwd: 728 if cwd:
724 cmd = 'cd %s && %s' % (cmd_helper.SingleQuote(cwd), cmd) 729 cmd = 'cd %s && %s' % (cmd_helper.SingleQuote(cwd), cmd)
725 if as_root and self.NeedsSU(): 730 if as_root and self.NeedsSU():
726 # "su -c sh -c" allows using shell features in |cmd| 731 # "su -c sh -c" allows using shell features in |cmd|
727 cmd = 'su -c sh -c %s' % cmd_helper.SingleQuote(cmd) 732 cmd = self._Su('sh -c %s' % cmd_helper.SingleQuote(cmd))
728 733
729 output = handle_large_output(cmd, large_output).splitlines() 734 output = handle_large_output(cmd, large_output).splitlines()
730 735
731 if single_line: 736 if single_line:
732 if not output: 737 if not output:
733 return '' 738 return ''
734 elif len(output) == 1: 739 elif len(output) == 1:
735 return output[0] 740 return output[0]
736 else: 741 else:
737 msg = 'one line of output was expected, but got: %s' 742 msg = 'one line of output was expected, but got: %s'
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() 1896 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices()
1892 if not blacklisted(adb)] 1897 if not blacklisted(adb)]
1893 1898
1894 @decorators.WithTimeoutAndRetriesFromInstance() 1899 @decorators.WithTimeoutAndRetriesFromInstance()
1895 def RestartAdbd(self, timeout=None, retries=None): 1900 def RestartAdbd(self, timeout=None, retries=None):
1896 logging.info('Restarting adbd on device.') 1901 logging.info('Restarting adbd on device.')
1897 with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script: 1902 with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script:
1898 self.WriteFile(script.name, _RESTART_ADBD_SCRIPT) 1903 self.WriteFile(script.name, _RESTART_ADBD_SCRIPT)
1899 self.RunShellCommand(['source', script.name], as_root=True) 1904 self.RunShellCommand(['source', script.name], as_root=True)
1900 self.adb.WaitForDevice() 1905 self.adb.WaitForDevice()
OLDNEW
« no previous file with comments | « build/android/provision_devices.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