diff options
author | jbudorick@chromium.org <jbudorick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-16 18:59:30 +0000 |
---|---|---|
committer | jbudorick@chromium.org <jbudorick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-16 18:59:30 +0000 |
commit | f0f4b9730e547189baa999f657179d3756297d0c (patch) | |
tree | 2c7ab002938b40f6650d9d1cee573642dcd66b37 | |
parent | 4c0bb96313936a342a73705c64b6b929abd5c185 (diff) | |
download | chromium_src-f0f4b9730e547189baa999f657179d3756297d0c.zip chromium_src-f0f4b9730e547189baa999f657179d3756297d0c.tar.gz chromium_src-f0f4b9730e547189baa999f657179d3756297d0c.tar.bz2 |
[Android] Switch to DeviceUtils version of RunShellCommand.
BUG=267773
Review URL: https://codereview.chromium.org/333933003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277508 0039d316-1c4b-4281-b951-d872f2087c98
36 files changed, 176 insertions, 125 deletions
diff --git a/build/android/enable_asserts.py b/build/android/enable_asserts.py index 34f8e3c..8dd44f1 100755 --- a/build/android/enable_asserts.py +++ b/build/android/enable_asserts.py @@ -30,8 +30,8 @@ def main(argv): if device.old_interface.SetJavaAssertsEnabled(options.set_asserts): # TODO(jbudorick) How to best do shell restarts after the # android_commands refactor? - device.old_interface.RunShellCommand('stop') - device.old_interface.RunShellCommand('start') + device.RunShellCommand('stop') + device.RunShellCommand('start') if __name__ == '__main__': diff --git a/build/android/gyp/util/build_device.py b/build/android/gyp/util/build_device.py index 8d694c1..a5b0dd5 100644 --- a/build/android/gyp/util/build_device.py +++ b/build/android/gyp/util/build_device.py @@ -31,7 +31,7 @@ class BuildDevice(object): self.device = device_utils.DeviceUtils(self.id) def RunShellCommand(self, *args, **kwargs): - return self.device.old_interface.RunShellCommand(*args, **kwargs) + return self.device.RunShellCommand(*args, **kwargs) def PushIfNeeded(self, *args, **kwargs): return self.device.old_interface.PushIfNeeded(*args, **kwargs) @@ -61,7 +61,7 @@ def GetConfigurationForDevice(device_id): is_online = device.IsOnline() if is_online: cmd = 'ls -l /data/app; getprop ro.build.description' - cmd_output = device.old_interface.RunShellCommand(cmd) + cmd_output = device.RunShellCommand(cmd) has_root = not 'Permission denied' in cmd_output[0] if not has_root: # Disable warning log messages from EnableRoot() @@ -73,7 +73,7 @@ def GetConfigurationForDevice(device_id): has_root = False finally: logging.getLogger().disabled = False - cmd_output = device.old_interface.RunShellCommand(cmd) + cmd_output = device.RunShellCommand(cmd) configuration = { 'id': device_id, diff --git a/build/android/host_heartbeat.py b/build/android/host_heartbeat.py index 4231069..429fca9 100755 --- a/build/android/host_heartbeat.py +++ b/build/android/host_heartbeat.py @@ -22,7 +22,7 @@ def main(): try: devices = android_commands.GetAttachedDevices() for device_serial in devices: - device_utils.DeviceUtils(device_serial).old_interface.RunShellCommand( + device_utils.DeviceUtils(device_serial).RunShellCommand( 'touch /sdcard/host_heartbeat') except: # Keep the heatbeat running bypassing all errors. diff --git a/build/android/provision_devices.py b/build/android/provision_devices.py index ea6d807..859fcbbe 100755 --- a/build/android/provision_devices.py +++ b/build/android/provision_devices.py @@ -84,8 +84,9 @@ def _ConfigureLocalProperties(device): constants.DEVICE_LOCAL_PROPERTIES_PATH, '\n'.join(local_props)) # Android will not respect the local props file if it is world writable. - device.old_interface.RunShellCommandWithSU( - 'chmod 644 %s' % constants.DEVICE_LOCAL_PROPERTIES_PATH) + device.RunShellCommand( + 'chmod 644 %s' % constants.DEVICE_LOCAL_PROPERTIES_PATH, + root=True) # LOCAL_PROPERTIES_PATH = '/data/local.prop' @@ -105,23 +106,23 @@ def WipeDeviceData(device): device_authorized = device.old_interface.FileExistsOnDevice( constants.ADB_KEYS_FILE) if device_authorized: - adb_keys = device.old_interface.RunShellCommandWithSU( - 'cat %s' % constants.ADB_KEYS_FILE) - device.old_interface.RunShellCommandWithSU('wipe data') + adb_keys = device.RunShellCommand('cat %s' % constants.ADB_KEYS_FILE, + root=True) + device.RunShellCommand('wipe data', root=True) if device_authorized: path_list = constants.ADB_KEYS_FILE.split('/') dir_path = '/'.join(path_list[:len(path_list)-1]) - device.old_interface.RunShellCommandWithSU('mkdir -p %s' % dir_path) - device.old_interface.RunShellCommand('echo %s > %s' % - (adb_keys[0], constants.ADB_KEYS_FILE)) + device.RunShellCommand('mkdir -p %s' % dir_path, root=True) + device.RunShellCommand('echo %s > %s' % + (adb_keys[0], constants.ADB_KEYS_FILE)) for adb_key in adb_keys[1:]: - device.old_interface.RunShellCommand( + device.RunShellCommand( 'echo %s >> %s' % (adb_key, constants.ADB_KEYS_FILE)) def ProvisionDevices(options): # TODO(jbudorick): Parallelize provisioning of all attached devices after - # swithcing from AndroidCommands. + # switching from AndroidCommands. if options.device is not None: devices = [options.device] else: @@ -134,7 +135,7 @@ def ProvisionDevices(options): device.old_interface.EnableAdbRoot() WipeDeviceData(device) try: - device_utils.DeviceUtils.parallel(devices).old_interface.Reboot(True) + device_utils.DeviceUtils.parallel(devices).Reboot(True) except errors.DeviceUnresponsiveError: pass for device_serial in devices: @@ -173,7 +174,7 @@ def ProvisionDevices(options): battery_info.get('level', 0)) time.sleep(60) battery_info = device.old_interface.GetBatteryInfo() - device.old_interface.RunShellCommandWithSU('date -u %f' % time.time()) + device.RunShellCommand('date -u %f' % time.time(), root=True) try: device_utils.DeviceUtils.parallel(devices).Reboot(True) except errors.DeviceUnresponsiveError: diff --git a/build/android/pylib/android_commands.py b/build/android/pylib/android_commands.py index f7264b0..3212143 100644 --- a/build/android/pylib/android_commands.py +++ b/build/android/pylib/android_commands.py @@ -656,12 +656,10 @@ class AndroidCommands(object): preferred_apis = { 'getprop': 'system_properties[<PROPERTY>]', 'setprop': 'system_properties[<PROPERTY>]', - 'su': 'RunShellCommandWithSU()', } # A dict of commands to methods that may call them. whitelisted_callers = { - 'su': 'RunShellCommandWithSU', 'getprop': 'ProvisionDevices', } diff --git a/build/android/pylib/content_settings.py b/build/android/pylib/content_settings.py index 11bc5fd..54cedfe 100644 --- a/build/android/pylib/content_settings.py +++ b/build/android/pylib/content_settings.py @@ -40,8 +40,8 @@ class ContentSettings(dict): def iteritems(self): # Example row: # 'Row: 0 _id=13, name=logging_id2, value=-1fccbaa546705b05' - for row in self._device.old_interface.RunShellCommandWithSU( - 'content query --uri content://%s' % self._table): + for row in self._device.RunShellCommand( + 'content query --uri content://%s' % self._table, root=True): fields = row.split(', ') key = None value = None @@ -55,28 +55,31 @@ class ContentSettings(dict): yield key, value def __getitem__(self, key): - return self._device.old_interface.RunShellCommandWithSU( + return self._device.RunShellCommand( 'content query --uri content://%s --where "name=\'%s\'" ' - '--projection value' % (self._table, key)).strip() + '--projection value' % (self._table, key), root=True).strip() def __setitem__(self, key, value): if key in self: - self._device.old_interface.RunShellCommandWithSU( + self._device.RunShellCommand( 'content update --uri content://%s ' '--bind value:%s:%s --where "name=\'%s\'"' % ( self._table, - self._GetTypeBinding(value), value, key)) + self._GetTypeBinding(value), value, key), + root=True) else: - self._device.old_interface.RunShellCommandWithSU( + self._device.RunShellCommand( 'content insert --uri content://%s ' '--bind name:%s:%s --bind value:%s:%s' % ( self._table, self._GetTypeBinding(key), key, - self._GetTypeBinding(value), value)) + self._GetTypeBinding(value), value), + root=True) def __delitem__(self, key): - self._device.old_interface.RunShellCommandWithSU( + self._device.RunShellCommand( 'content delete --uri content://%s ' '--bind name:%s:%s' % ( self._table, - self._GetTypeBinding(key), key)) + self._GetTypeBinding(key), key), + root=True) diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py index 9701923..0fee10a 100644 --- a/build/android/pylib/device/device_utils.py +++ b/build/android/pylib/device/device_utils.py @@ -99,6 +99,17 @@ class DeviceUtils(object): Returns: True if adbd has root privileges, False otherwise. """ + return self._HasRootImpl() + + def _HasRootImpl(self): + """ Implementation of HasRoot. + + This is split from HasRoot to allow other DeviceUtils methods to call + HasRoot without spawning a new timeout thread. + + Returns: + Same as for |HasRoot|. + """ return self.old_interface.IsRootEnabled() @decorators.WithTimeoutAndRetriesFromInstance() @@ -171,7 +182,7 @@ class DeviceUtils(object): self.old_interface.WaitForSdCardReady(timeout) if wifi: while not 'Wi-Fi is enabled' in ( - self.old_interface.RunShellCommand('dumpsys wifi')): + self._RunShellCommandImpl('dumpsys wifi')): time.sleep(0.1) @decorators.WithTimeoutAndRetriesDefaults( @@ -232,6 +243,61 @@ class DeviceUtils(object): raise device_errors.CommandFailedError( ['adb', 'install', apk_path], str(e)) + @decorators.WithTimeoutAndRetriesFromInstance() + def RunShellCommand(self, cmd, check_return=False, root=False, timeout=None, + retries=None): + """Run an ADB shell command. + + TODO(jbudorick) Switch the default value of check_return to True after + AndroidCommands is gone. + + Args: + cmd: A list containing the command to run on the device and any arguments. + check_return: A boolean indicating whether or not the return code should + be checked. + timeout: Same as for |IsOnline|. + retries: Same as for |IsOnline|. + Raises: + CommandFailedError if check_return is True and the return code is nozero. + Returns: + The output of the command. + """ + return self._RunShellCommandImpl(cmd, check_return=check_return, root=root, + timeout=timeout) + + def _RunShellCommandImpl(self, cmd, check_return=False, root=False, + timeout=None): + """Implementation of RunShellCommand. + + This is split from RunShellCommand to allow other DeviceUtils methods to + call RunShellCommand without spawning a new timeout thread. + + TODO(jbudorick) Remove the timeout parameter once this is no longer + implemented via AndroidCommands. + + Args: + cmd: Same as for |RunShellCommand|. + check_return: Same as for |RunShellCommand|. + timeout: Same as for |IsOnline|. + Raises: + Same as for |RunShellCommand|. + Returns: + Same as for |RunShellCommand|. + """ + if isinstance(cmd, list): + cmd = ' '.join(cmd) + if root and not self.HasRoot(): + cmd = 'su -c %s' % cmd + if check_return: + code, output = self.old_interface.GetShellCommandStatusAndOutput( + cmd, timeout_time=timeout) + if int(code) != 0: + raise device_errors.CommandFailedError( + cmd, 'Nonzero exit code (%d)' % code) + else: + output = self.old_interface.RunShellCommand(cmd, timeout_time=timeout) + return output + def __str__(self): """Returns the device serial.""" return self.old_interface.GetDevice() diff --git a/build/android/pylib/flag_changer.py b/build/android/pylib/flag_changer.py index c1e8cb8..9ccdc1e 100644 --- a/build/android/pylib/flag_changer.py +++ b/build/android/pylib/flag_changer.py @@ -114,11 +114,7 @@ class FlagChanger(object): assert len(file_contents) == 1 and file_contents[0] == cmd_line, ( 'Failed to set the command line file at %s' % self._cmdline_file) else: - if use_root: - self._device.old_interface.RunShellCommandWithSU( - 'rm ' + self._cmdline_file) - else: - self._device.old_interface.RunShellCommand('rm ' + self._cmdline_file) + self._device.RunShellCommand('rm ' + self._cmdline_file, root=use_root) assert ( not self._device.old_interface.FileExistsOnDevice( self._cmdline_file)), ( diff --git a/build/android/pylib/gtest/test_package_apk.py b/build/android/pylib/gtest/test_package_apk.py index 83b6b00..f431526 100644 --- a/build/android/pylib/gtest/test_package_apk.py +++ b/build/android/pylib/gtest/test_package_apk.py @@ -55,7 +55,7 @@ class TestPackageApk(TestPackage): return '/data/data/' + self._package_info.package + '/files/test.fifo' def _ClearFifo(self, device): - device.old_interface.RunShellCommand('rm -f ' + self._GetFifo()) + device.RunShellCommand('rm -f ' + self._GetFifo()) def _WatchFifo(self, device, timeout, logfile=None): for i in range(10): @@ -86,9 +86,9 @@ class TestPackageApk(TestPackage): # files over time. if self.suite_name == 'content_browsertests': try: - device.old_interface.RunShellCommand( + device.RunShellCommand( 'rm -r %s/content_shell' % device.GetExternalStoragePath(), - timeout_time=60 * 2) + timeout=60 * 2) except device_errors.CommandFailedError: # TODO(jbudorick) Handle this exception appropriately once the # conversions are done. diff --git a/build/android/pylib/gtest/test_package_exe.py b/build/android/pylib/gtest/test_package_exe.py index 18146ad..252c4a4 100644 --- a/build/android/pylib/gtest/test_package_exe.py +++ b/build/android/pylib/gtest/test_package_exe.py @@ -106,7 +106,7 @@ class TestPackageExecutable(TestPackage): #override def GetAllTests(self, device): - all_tests = device.old_interface.RunShellCommand( + all_tests = device.RunShellCommand( '%s %s/%s --gtest_list_tests' % (self.tool.GetTestWrapper(), constants.TEST_EXECUTABLE_DIR, diff --git a/build/android/pylib/instrumentation/test_runner.py b/build/android/pylib/instrumentation/test_runner.py index 12ae702..050985f 100644 --- a/build/android/pylib/instrumentation/test_runner.py +++ b/build/android/pylib/instrumentation/test_runner.py @@ -154,8 +154,8 @@ class TestRunner(base_test_runner.BaseTestRunner): if self.device.old_interface.SetJavaAssertsEnabled(True): # TODO(jbudorick) How to best do shell restart after the # android_commands refactor? - self.device.old_interface.RunShellCommand('stop') - self.device.old_interface.RunShellCommand('start') + self.device.RunShellCommand('stop') + self.device.RunShellCommand('start') # We give different default value to launch HTTP server based on shard index # because it may have race condition when multiple processes are trying to @@ -237,7 +237,7 @@ class TestRunner(base_test_runner.BaseTestRunner): if self.coverage_dir: self.device.old_interface.Adb().Pull( self.coverage_device_file, self.coverage_host_file) - self.device.old_interface.RunShellCommand( + self.device.RunShellCommand( 'rm -f %s' % self.coverage_device_file) def TearDownPerfMonitoring(self, test): diff --git a/build/android/pylib/linker/test_case.py b/build/android/pylib/linker/test_case.py index 0530f53..e8b2ffe 100644 --- a/build/android/pylib/linker/test_case.py +++ b/build/android/pylib/linker/test_case.py @@ -112,7 +112,7 @@ def _WriteCommandLineFile(device, command_line, command_line_file): """Create a command-line file on the device. This does not use FlagChanger because its implementation assumes the device has 'su', and thus does not work at all with production devices.""" - device.old_interface.RunShellCommand( + device.RunShellCommand( 'echo "%s" > %s' % (command_line, command_line_file)) diff --git a/build/android/pylib/monkey/test_runner.py b/build/android/pylib/monkey/test_runner.py index 31d8851..5f0cc5d 100644 --- a/build/android/pylib/monkey/test_runner.py +++ b/build/android/pylib/monkey/test_runner.py @@ -40,8 +40,7 @@ class TestRunner(base_test_runner.BaseTestRunner): '--kill-process-after-error', self._options.extra_args, '%d' % self._options.event_count] - return self.device.old_interface.RunShellCommand( - ' '.join(cmd), timeout_time=timeout_ms) + return self.device.RunShellCommand(' '.join(cmd), timeout=timeout_ms) def RunTest(self, test_name): """Run a Monkey test on the device. diff --git a/build/android/pylib/perf/cache_control.py b/build/android/pylib/perf/cache_control.py index adc3219..09107db 100644 --- a/build/android/pylib/perf/cache_control.py +++ b/build/android/pylib/perf/cache_control.py @@ -16,7 +16,7 @@ class CacheControl(object): def DropRamCaches(self): """Drops the filesystem ram caches for performance testing.""" - self._device.old_interface.RunShellCommandWithSU('sync') + self._device.RunShellCommand('sync', root=True) self._device.old_interface.SetProtectedFileContents( CacheControl._DROP_CACHES, '3') diff --git a/build/android/pylib/perf/perf_control.py b/build/android/pylib/perf/perf_control.py index cde12ec..1c88945 100644 --- a/build/android/pylib/perf/perf_control.py +++ b/build/android/pylib/perf/perf_control.py @@ -73,12 +73,11 @@ class PerfControl(object): """ def ForceCpuOnline(online_path): script = 'chmod 644 {0}; echo 1 > {0}; chmod 444 {0}'.format(online_path) - self._device.old_interface.RunShellCommandWithSU(script) + self._device.RunShellCommand(script, root=True) return self._device.old_interface.GetFileContents(online_path)[0] == '1' def ResetCpu(online_path): - self._device.old_interface.RunShellCommandWithSU( - 'chmod 644 %s' % online_path) + self._device.RunShellCommand('chmod 644 %s' % online_path, root=True) def WaitFor(condition): for _ in range(100): @@ -87,7 +86,7 @@ class PerfControl(object): time.sleep(0.1) raise RuntimeError('Timed out') - cpu_online_files = self._device.old_interface.RunShellCommand( + cpu_online_files = self._device.RunShellCommand( 'ls -d /sys/devices/system/cpu/cpu[0-9]*/online') for online_path in cpu_online_files: if force_online: diff --git a/build/android/pylib/perf/perf_control_unittest.py b/build/android/pylib/perf/perf_control_unittest.py index bd30a4e..a83b482 100644 --- a/build/android/pylib/perf/perf_control_unittest.py +++ b/build/android/pylib/perf/perf_control_unittest.py @@ -25,20 +25,20 @@ class TestPerfControl(unittest.TestCase): def testForceAllCpusOnline(self): perf = perf_control.PerfControl(self._device) - cpu_online_files = self._device.old_interface.RunShellCommand( + cpu_online_files = self._device.RunShellCommand( 'ls -d /sys/devices/system/cpu/cpu[0-9]*/online') try: perf.ForceAllCpusOnline(True) for path in cpu_online_files: self.assertEquals('1', self._device.old_interface.GetFileContents(path)[0]) - mode = self._device.old_interface.RunShellCommand('ls -l %s' % path)[0] + mode = self._device.RunShellCommand('ls -l %s' % path)[0] self.assertEquals('-r--r--r--', mode[:10]) finally: perf.ForceAllCpusOnline(False) for path in cpu_online_files: - mode = self._device.old_interface.RunShellCommand('ls -l %s' % path)[0] + mode = self._device.RunShellCommand('ls -l %s' % path)[0] self.assertEquals('-rw-r--r--', mode[:10]) diff --git a/build/android/pylib/perf/surface_stats_collector.py b/build/android/pylib/perf/surface_stats_collector.py index 223e18c..a34d87d1 100644 --- a/build/android/pylib/perf/surface_stats_collector.py +++ b/build/android/pylib/perf/surface_stats_collector.py @@ -215,7 +215,7 @@ class SurfaceStatsCollector(object): """ # The command returns nothing if it is supported, otherwise returns many # lines of result just like 'dumpsys SurfaceFlinger'. - results = self._device.old_interface.RunShellCommand( + results = self._device.RunShellCommand( 'dumpsys SurfaceFlinger --latency-clear SurfaceView') return not len(results) @@ -258,9 +258,8 @@ class SurfaceStatsCollector(object): # We use the special "SurfaceView" window name because the statistics for # the activity's main window are not updated when the main web content is # composited into a SurfaceView. - results = self._device.old_interface.RunShellCommand( - 'dumpsys SurfaceFlinger --latency SurfaceView', - log_result=logging.getLogger().isEnabledFor(logging.DEBUG)) + results = self._device.RunShellCommand( + 'dumpsys SurfaceFlinger --latency SurfaceView') if not len(results): return (None, None) @@ -296,8 +295,7 @@ class SurfaceStatsCollector(object): Returns: Dict of {page_flip_count (or 0 if there was an error), timestamp}. """ - results = self._device.old_interface.RunShellCommand( - 'service call SurfaceFlinger 1013') + results = self._device.RunShellCommand('service call SurfaceFlinger 1013') assert len(results) == 1 match = re.search('^Result: Parcel\((\w+)', results[0]) cur_surface = 0 diff --git a/build/android/pylib/perf/thermal_throttle.py b/build/android/pylib/perf/thermal_throttle.py index 60156de..87ae966 100644 --- a/build/android/pylib/perf/thermal_throttle.py +++ b/build/android/pylib/perf/thermal_throttle.py @@ -102,7 +102,7 @@ class ThermalThrottle(object): return False has_been_throttled = False serial_number = self._device.old_interface.GetDevice() - log = self._device.old_interface.RunShellCommand('dmesg -c') + log = self._device.RunShellCommand('dmesg -c') degree_symbol = unichr(0x00B0) for line in log: if self._detector.BecameThrottled(line): @@ -128,8 +128,7 @@ class ThermalThrottle(object): serial_number, temperature, degree_symbol) # Print temperature of battery, to give a system temperature - dumpsys_log = self._device.old_interface.RunShellCommand( - 'dumpsys battery') + dumpsys_log = self._device.RunShellCommand('dumpsys battery') for line in dumpsys_log: if 'temperature' in line: btemp = float([s for s in line.split() if s.isdigit()][0]) / 10.0 diff --git a/build/android/pylib/ports.py b/build/android/pylib/ports.py index 88b7cb2..34efb52 100644 --- a/build/android/pylib/ports.py +++ b/build/android/pylib/ports.py @@ -114,8 +114,7 @@ def IsDevicePortUsed(device, device_port, state=''): True if the port on device is already used, otherwise returns False. """ base_url = '127.0.0.1:%d' % device_port - netstat_results = device.old_interface.RunShellCommand( - 'netstat', log_result=False) + netstat_results = device.RunShellCommand('netstat') for single_connect in netstat_results: # Column 3 is the local address which we want to check with. connect_results = single_connect.split() diff --git a/build/android/pylib/screenshot.py b/build/android/pylib/screenshot.py index 5cf3c26..a09bc3d 100644 --- a/build/android/pylib/screenshot.py +++ b/build/android/pylib/screenshot.py @@ -76,7 +76,7 @@ class VideoRecorder(object): self._is_started = False if not self._recorder or not self._recorder_pids: return - self._device.old_interface.RunShellCommand( + self._device.RunShellCommand( 'kill -SIGINT ' + ' '.join(self._recorder_pids)) self._recorder.wait() @@ -88,5 +88,5 @@ class VideoRecorder(object): """ self._device.old_interface.PullFileFromDevice( self._device_file, self._host_file) - self._device.old_interface.RunShellCommand('rm -f "%s"' % self._device_file) + self._device.RunShellCommand('rm -f "%s"' % self._device_file) return self._host_file diff --git a/build/android/pylib/utils/emulator.py b/build/android/pylib/utils/emulator.py index 91aa23e..81b9c98 100644 --- a/build/android/pylib/utils/emulator.py +++ b/build/android/pylib/utils/emulator.py @@ -394,6 +394,7 @@ class Emulator(object): """ seconds_waited = 0 number_of_waits = 2 # Make sure we can wfd twice + # TODO(jbudorick) Un-handroll this in the implementation switch. adb_cmd = "adb -s %s %s" % (self.device_serial, 'wait-for-device') while seconds_waited < self._LAUNCH_TIMEOUT: try: diff --git a/build/android/pylib/valgrind_tools.py b/build/android/pylib/valgrind_tools.py index 0c94557..8f845fb 100644 --- a/build/android/pylib/valgrind_tools.py +++ b/build/android/pylib/valgrind_tools.py @@ -37,7 +37,7 @@ def SetChromeTimeoutScale(device, scale): path = '/data/local/tmp/chrome_timeout_scale' if not scale or scale == 1.0: # Delete if scale is None/0.0/1.0 since the default timeout scale is 1.0 - device.old_interface.RunShellCommand('rm %s' % path) + device.RunShellCommand('rm %s' % path) else: device.old_interface.SetProtectedFileContents(path, '%f' % scale) @@ -166,9 +166,9 @@ class ValgrindTool(BaseTool): def CopyFiles(self): """Copies Valgrind tools to the device.""" - self._device.old_interface.RunShellCommand( + self._device.RunShellCommand( 'rm -r %s; mkdir %s' % (ValgrindTool.VG_DIR, ValgrindTool.VG_DIR)) - self._device.old_interface.RunShellCommand( + self._device.RunShellCommand( 'rm -r %s; mkdir %s' % (ValgrindTool.VGLOGS_DIR, ValgrindTool.VGLOGS_DIR)) files = self.GetFilesForTool() @@ -179,17 +179,17 @@ class ValgrindTool(BaseTool): def SetupEnvironment(self): """Sets up device environment.""" - self._device.old_interface.RunShellCommand('chmod 777 /data/local/tmp') - self._device.old_interface.RunShellCommand('setenforce 0') + self._device.RunShellCommand('chmod 777 /data/local/tmp') + self._device.RunShellCommand('setenforce 0') for prop in self._wrap_properties: - self._device.old_interface.RunShellCommand( + self._device.RunShellCommand( 'setprop %s "logwrapper %s"' % (prop, self.GetTestWrapper())) SetChromeTimeoutScale(self._device, self.GetTimeoutScale()) def CleanUpEnvironment(self): """Cleans up device environment.""" for prop in self._wrap_properties: - self._device.old_interface.RunShellCommand('setprop %s ""' % (prop,)) + self._device.RunShellCommand('setprop %s ""' % (prop,)) SetChromeTimeoutScale(self._device, None) def GetFilesForTool(self): diff --git a/build/android/tombstones.py b/build/android/tombstones.py index cb1d700..76dab15 100755 --- a/build/android/tombstones.py +++ b/build/android/tombstones.py @@ -29,8 +29,7 @@ def _ListTombstones(device): Yields: Tuples of (tombstone filename, date time of file on device). """ - lines = device.old_interface.RunShellCommand( - 'TZ=UTC su -c ls -a -l /data/tombstones') + lines = device.RunShellCommand('TZ=UTC su -c ls -a -l /data/tombstones') for line in lines: if 'tombstone' in line and not 'No such file or directory' in line: details = line.split() @@ -48,7 +47,7 @@ def _GetDeviceDateTime(device): Returns: A datetime instance. """ - device_now_string = device.old_interface.RunShellCommand('TZ=UTC date') + device_now_string = device.RunShellCommand('TZ=UTC date') return datetime.datetime.strptime( device_now_string[0], '%a %b %d %H:%M:%S %Z %Y') @@ -74,8 +73,8 @@ def _EraseTombstone(device, tombstone_file): device: An instance of DeviceUtils. tombstone_file: the tombstone to delete. """ - return device.old_interface.RunShellCommandWithSU( - 'rm /data/tombstones/' + tombstone_file) + return device.RunShellCommand( + 'rm /data/tombstones/' + tombstone_file, root=True) def _ResolveSymbols(tombstone_data, include_stack): diff --git a/tools/android/adb_profile_chrome/perf_controller.py b/tools/android/adb_profile_chrome/perf_controller.py index 064300d..523fb85 100644 --- a/tools/android/adb_profile_chrome/perf_controller.py +++ b/tools/android/adb_profile_chrome/perf_controller.py @@ -65,8 +65,7 @@ class _PerfProfiler(object): def SignalAndWait(self): perf_pids = self._device.old_interface.ExtractPid('perf') - self._device.old_interface.RunShellCommand( - 'kill -SIGINT ' + ' '.join(perf_pids)) + self._device.RunShellCommand('kill -SIGINT ' + ' '.join(perf_pids)) self._perf_process.wait() self._perf_control.ForceAllCpusOnline(False) @@ -117,7 +116,7 @@ class PerfProfilerController(controllers.BaseController): @classmethod def GetCategories(cls, device): perf_binary = cls._PrepareDevice(device) - return device.old_interface.RunShellCommand('%s list' % perf_binary) + return device.RunShellCommand('%s list' % perf_binary) def StartTracing(self, _): self._perf_instance = _PerfProfiler(self._device, diff --git a/tools/android/adb_profile_chrome/systrace_controller.py b/tools/android/adb_profile_chrome/systrace_controller.py index 369bc88..3ec4cc7 100644 --- a/tools/android/adb_profile_chrome/systrace_controller.py +++ b/tools/android/adb_profile_chrome/systrace_controller.py @@ -37,7 +37,7 @@ class SystraceController(controllers.BaseController): @staticmethod def GetCategories(device): - return device.old_interface.RunShellCommand('atrace --list_categories') + return device.RunShellCommand('atrace --list_categories') def StartTracing(self, _): self._thread = threading.Thread(target=self._CollectData) diff --git a/tools/memory_inspector/memory_inspector/backends/android/android_backend.py b/tools/memory_inspector/memory_inspector/backends/android/android_backend.py index ef022155..2116bb6 100644 --- a/tools/memory_inspector/memory_inspector/backends/android/android_backend.py +++ b/tools/memory_inspector/memory_inspector/backends/android/android_backend.py @@ -260,8 +260,7 @@ class AndroidDevice(backends.Device): return self._sys_stats dump_out = '\n'.join( - self.underlying_device.old_interface.RunShellCommand( - _PSEXT_PATH_ON_DEVICE)) + self.underlying_device.RunShellCommand(_PSEXT_PATH_ON_DEVICE)) stats = json.loads(dump_out) assert(all([x in stats for x in ['cpu', 'processes', 'time', 'mem']])), ( 'ps_ext returned a malformed JSON dictionary.') @@ -288,13 +287,12 @@ class AndroidDevice(backends.Device): prebuilts_fetcher.GetIfChanged(local_path) with open(local_path, 'rb') as f: local_hash = hashlib.md5(f.read()).hexdigest() - device_md5_out = self.underlying_device.old_interface.RunShellCommand( + device_md5_out = self.underlying_device.RunShellCommand( 'md5 "%s"' % path_on_device) if local_hash in device_md5_out: return self.underlying_device.old_interface.Adb().Push(local_path, path_on_device) - self.underlying_device.old_interface.RunShellCommand( - 'chmod 755 "%s"' % path_on_device) + self.underlying_device.RunShellCommand('chmod 755 "%s"' % path_on_device) @property def name(self): @@ -317,7 +315,7 @@ class AndroidProcess(backends.Process): def DumpMemoryMaps(self): """Grabs and parses memory maps through memdump.""" cmd = '%s %d' % (_MEMDUMP_PATH_ON_DEVICE, self.pid) - dump_out = self.device.underlying_device.old_interface.RunShellCommand(cmd) + dump_out = self.device.underlying_device.RunShellCommand(cmd) return memdump_parser.Parse(dump_out) def DumpNativeHeap(self): @@ -325,14 +323,13 @@ class AndroidProcess(backends.Process): # TODO(primiano): grab also mmap bt (depends on pending framework change). dump_file_path = _DUMPHEAP_OUT_FILE_PATH % self.pid cmd = 'am dumpheap -n %d %s' % (self.pid, dump_file_path) - self.device.underlying_device.old_interface.RunShellCommand(cmd) + self.device.underlying_device.RunShellCommand(cmd) # TODO(primiano): Some pre-KK versions of Android might need a sleep here # as, IIRC, 'am dumpheap' did not wait for the dump to be completed before # returning. Double check this and either add a sleep or remove this TODO. dump_out = self.device.underlying_device.old_interface.GetFileContents( dump_file_path) - self.device.underlying_device.old_interface.RunShellCommand( - 'rm %s' % dump_file_path) + self.device.underlying_device.RunShellCommand('rm %s' % dump_file_path) return dumpheap_native_parser.Parse(dump_out) def GetStats(self): diff --git a/tools/telemetry/telemetry/core/backends/chrome/android_browser_backend.py b/tools/telemetry/telemetry/core/backends/chrome/android_browser_backend.py index 46fdd76..3ead0bf 100644 --- a/tools/telemetry/telemetry/core/backends/chrome/android_browser_backend.py +++ b/tools/telemetry/telemetry/core/backends/chrome/android_browser_backend.py @@ -33,10 +33,11 @@ class AndroidBrowserBackendSettings(object): raise NotImplementedError() def RemoveProfile(self): - files = self.adb.RunShellCommandWithSU('ls "%s"' % self.profile_dir) + files = self.adb.device().RunShellCommand( + 'ls "%s"' % self.profile_dir, root=True) # Don't delete lib, since it is created by the installer. paths = ['"%s/%s"' % (self.profile_dir, f) for f in files if f != 'lib'] - self.adb.RunShellCommandWithSU('rm -r %s' % ' '.join(paths)) + self.adb.device().RunShellCommand('rm -r %s' % ' '.join(paths), root=True) def PushProfile(self, _): logging.critical('Profiles cannot be overriden with current configuration') @@ -91,16 +92,18 @@ class ChromeBackendSettings(AndroidBrowserBackendSettings): self.adb.device().old_interface.EfficientDeviceDirectoryCopy( saved_profile_location, self.profile_dir) - dumpsys = self.adb.RunShellCommand('dumpsys package %s' % self.package) + dumpsys = self.adb.device().RunShellCommand( + 'dumpsys package %s' % self.package) id_line = next(line for line in dumpsys if 'userId=' in line) uid = re.search('\d+', id_line).group() - files = self.adb.RunShellCommandWithSU('ls "%s"' % self.profile_dir) + files = self.adb.device().RunShellCommand( + 'ls "%s"' % self.profile_dir, root=True) files.remove('lib') paths = ['%s/%s' % (self.profile_dir, f) for f in files] for path in paths: extended_path = '%s %s/* %s/*/* %s/*/*/*' % (path, path, path, path) - self.adb.RunShellCommand('chown %s.%s %s' % - (uid, uid, extended_path)) + self.adb.device().RunShellCommand( + 'chown %s.%s %s' % (uid, uid, extended_path)) class ContentShellBackendSettings(AndroidBrowserBackendSettings): def __init__(self, adb, package): @@ -215,8 +218,8 @@ class AndroidBrowserBackend(chrome_browser_backend.ChromeBrowserBackend): # Set the debug app if needed. if self._adb.IsUserBuild(): logging.debug('User build device, setting debug app') - self._adb.RunShellCommand('am set-debug-app --persistent %s' % - self._backend_settings.package) + self._adb.device().RunShellCommand( + 'am set-debug-app --persistent %s' % self._backend_settings.package) def _SetUpCommandLine(self): def QuoteIfNeeded(arg): @@ -272,7 +275,7 @@ class AndroidBrowserBackend(chrome_browser_backend.ChromeBrowserBackend): def Start(self): self._SetUpCommandLine() - self._adb.RunShellCommand('logcat -c') + self._adb.device().RunShellCommand('logcat -c') if self.browser_options.startup_url: url = self.browser_options.startup_url elif self.browser_options.profile_dir: @@ -378,7 +381,7 @@ class AndroidBrowserBackend(chrome_browser_backend.ChromeBrowserBackend): # pulled down is really needed e.g. .pak files. if not os.path.exists(self._output_profile_path): os.makedirs(self._output_profile_pathame) - files = self.adb.RunShellCommandWithSU( + files = self.adb.device().RunShellCommand( 'ls "%s"' % self._backend_settings.profile_dir) for f in files: # Don't pull lib, since it is created by the installer. @@ -400,7 +403,7 @@ class AndroidBrowserBackend(chrome_browser_backend.ChromeBrowserBackend): return local_port def GetStandardOutput(self): - return '\n'.join(self._adb.RunShellCommand('logcat -d -t 500')) + return '\n'.join(self._adb.device().RunShellCommand('logcat -d -t 500')) def GetStackTrace(self): def Decorate(title, content): diff --git a/tools/telemetry/telemetry/core/forwarders/android_forwarder.py b/tools/telemetry/telemetry/core/forwarders/android_forwarder.py index 60138e4..4c542f5 100644 --- a/tools/telemetry/telemetry/core/forwarders/android_forwarder.py +++ b/tools/telemetry/telemetry/core/forwarders/android_forwarder.py @@ -184,7 +184,7 @@ class AndroidRndisConfigurator(object): def _FindDeviceRndisInterface(self): """Returns the name of the RNDIS network interface if present.""" - config = self._device.old_interface.RunShellCommand('netcfg') + config = self._device.RunShellCommand('netcfg') interfaces = [line.split()[0] for line in config] candidates = [iface for iface in interfaces if re.match('rndis|usb', iface)] if candidates: @@ -257,8 +257,8 @@ doit & 'prefix': script_prefix } self._device.old_interface.SetFileContents('%s.sh' % script_prefix, script) # TODO(szym): run via su -c if necessary. - self._device.old_interface.RunShellCommand('rm %s.log' % script_prefix) - self._device.old_interface.RunShellCommand('. %s.sh' % script_prefix) + self._device.RunShellCommand('rm %s.log' % script_prefix) + self._device.RunShellCommand('. %s.sh' % script_prefix) self._WaitForDevice() result = self._device.old_interface.GetFileContents( '%s.log' % script_prefix) @@ -332,7 +332,7 @@ doit & else: excluded = 'no interfaces excluded on other devices' addresses += [line.split()[2] - for line in device.old_interface.RunShellCommand('netcfg') + for line in device.RunShellCommand('netcfg') if excluded not in line] return addresses @@ -421,7 +421,7 @@ doit & netmask = _Long2Ip(netmask) # TODO(szym) run via su -c if necessary. - self._device.old_interface.RunShellCommand( + self._device.RunShellCommand( 'ifconfig %s %s netmask %s up' % (device_iface, device_ip, netmask)) # Enabling the interface sometimes breaks adb. self._WaitForDevice() diff --git a/tools/telemetry/telemetry/core/platform/android_platform_backend.py b/tools/telemetry/telemetry/core/platform/android_platform_backend.py index 5115d59..5242cb4 100644 --- a/tools/telemetry/telemetry/core/platform/android_platform_backend.py +++ b/tools/telemetry/telemetry/core/platform/android_platform_backend.py @@ -184,8 +184,7 @@ class AndroidPlatformBackend( raise NotImplementedError() def FlushDnsCache(self): - self._device.old_interface.RunShellCommandWithSU( - 'ndc resolver flushdefaultif') + self._device.RunShellCommand('ndc resolver flushdefaultif', root=True) def LaunchApplication( self, application, parameters=None, elevate_privilege=False): @@ -197,8 +196,7 @@ class AndroidPlatformBackend( raise NotImplementedError("elevate_privilege isn't supported on android.") if not parameters: parameters = '' - self._device.old_interface.RunShellCommand( - 'am start ' + parameters + ' ' + application) + self._device.RunShellCommand('am start ' + parameters + ' ' + application) def IsApplicationRunning(self, application): if application in _HOST_APPLICATIONS: @@ -269,8 +267,7 @@ class AndroidPlatformBackend( command = 'ps' if pid: command += ' -p %d' % pid - ps = self._device.old_interface.RunShellCommand( - command, log_result=False)[1:] + ps = self._device.RunShellCommand(command)[1:] output = [] for line in ps: data = line.split() diff --git a/tools/telemetry/telemetry/core/platform/power_monitor/android_ds2784_power_monitor.py b/tools/telemetry/telemetry/core/platform/power_monitor/android_ds2784_power_monitor.py index 8b66e89..8d4ae26 100644 --- a/tools/telemetry/telemetry/core/platform/power_monitor/android_ds2784_power_monitor.py +++ b/tools/telemetry/telemetry/core/platform/power_monitor/android_ds2784_power_monitor.py @@ -45,7 +45,7 @@ class DS2784PowerMonitor(power_monitor.PowerMonitor): android_prebuilt_profiler_helper.InstallOnDevice( self._device, 'file_poller') self._powermonitor_process_port = int( - self._device.old_interface.RunShellCommand( + self._device.RunShellCommand( '%s %d %s %s %s' % (self._file_poller_binary, SAMPLE_RATE_HZ, CHARGE_COUNTER, CURRENT, VOLTAGE))[0]) @@ -53,7 +53,7 @@ class DS2784PowerMonitor(power_monitor.PowerMonitor): assert self._powermonitor_process_port, ( 'StartMonitoringPower() not called.') try: - result = '\n'.join(self._device.old_interface.RunShellCommand( + result = '\n'.join(self._device.RunShellCommand( '%s %d' % (self._file_poller_binary, self._powermonitor_process_port))) assert result, 'PowerMonitor produced no output' diff --git a/tools/telemetry/telemetry/core/platform/power_monitor/android_dumpsys_power_monitor.py b/tools/telemetry/telemetry/core/platform/power_monitor/android_dumpsys_power_monitor.py index 15e80f0..9432d70 100644 --- a/tools/telemetry/telemetry/core/platform/power_monitor/android_dumpsys_power_monitor.py +++ b/tools/telemetry/telemetry/core/platform/power_monitor/android_dumpsys_power_monitor.py @@ -46,7 +46,7 @@ class DumpsysPowerMonitor(power_monitor.PowerMonitor): package = self._browser._browser_backend.package # By default, 'dumpsys batterystats' measures power consumption during the # last unplugged period. - result = self._device.old_interface.RunShellCommand( + result = self._device.RunShellCommand( 'dumpsys batterystats -c %s' % package) assert result, 'Dumpsys produced no output' return DumpsysPowerMonitor.ParseSamplingOutput(package, result) diff --git a/tools/telemetry/telemetry/core/platform/profiler/android_prebuilt_profiler_helper.py b/tools/telemetry/telemetry/core/platform/profiler/android_prebuilt_profiler_helper.py index fa838ea..6d689d1 100644 --- a/tools/telemetry/telemetry/core/platform/profiler/android_prebuilt_profiler_helper.py +++ b/tools/telemetry/telemetry/core/platform/profiler/android_prebuilt_profiler_helper.py @@ -28,6 +28,6 @@ def InstallOnDevice(device, profiler_binary): device_binary_path = GetDevicePath(profiler_binary) device.old_interface.PushIfNeeded(host_path, device_binary_path) - device.old_interface.RunShellCommand('chmod 777 ' + device_binary_path) + device.RunShellCommand('chmod 777 ' + device_binary_path) return True diff --git a/tools/telemetry/telemetry/core/platform/profiler/android_profiling_helper.py b/tools/telemetry/telemetry/core/platform/profiler/android_profiling_helper.py index f2e2144..8b64093 100644 --- a/tools/telemetry/telemetry/core/platform/profiler/android_profiling_helper.py +++ b/tools/telemetry/telemetry/core/platform/profiler/android_profiling_helper.py @@ -36,7 +36,7 @@ def _ElfSectionMd5Sum(elf_file, section): def _FindMatchingUnstrippedLibraryOnHost(device, lib): lib_base = os.path.basename(lib) - device_md5 = device.old_interface.RunShellCommandWithSU('md5 "%s"' % lib)[0] + device_md5 = device.RunShellCommand('md5 "%s"' % lib, root=True)[0] device_md5 = device_md5.split(' ', 1)[0] def FindMatchingStrippedLibrary(out_path): diff --git a/tools/telemetry/telemetry/core/platform/profiler/netlog_profiler.py b/tools/telemetry/telemetry/core/platform/profiler/netlog_profiler.py index c3d8ef0..0e3115a 100644 --- a/tools/telemetry/telemetry/core/platform/profiler/netlog_profiler.py +++ b/tools/telemetry/telemetry/core/platform/profiler/netlog_profiler.py @@ -38,8 +38,7 @@ class NetLogProfiler(profiler.Profiler): self._browser_backend.adb.device().old_interface.Adb().Pull( output_file, host_output_file) # Clean the device - self._browser_backend.adb.device().old_interface.RunShellCommand( - 'rm %s' % output_file) + self._browser_backend.adb.device().RunShellCommand('rm %s' % output_file) output_file = host_output_file print 'Net-internals log saved as %s' % output_file print 'To view, open in chrome://net-internals' diff --git a/tools/telemetry/telemetry/core/platform/profiler/perf_profiler.py b/tools/telemetry/telemetry/core/platform/profiler/perf_profiler.py index f32eba3..6b460d9 100644 --- a/tools/telemetry/telemetry/core/platform/profiler/perf_profiler.py +++ b/tools/telemetry/telemetry/core/platform/profiler/perf_profiler.py @@ -101,8 +101,7 @@ class _SingleProcessPerfProfiler(object): if self._is_android: device = self._browser_backend.adb.device() perf_pids = device.old_interface.ExtractPid('perf') - device.old_interface.RunShellCommand( - 'kill -SIGINT ' + ' '.join(perf_pids)) + device.RunShellCommand('kill -SIGINT ' + ' '.join(perf_pids)) util.WaitFor(lambda: not device.old_interface.ExtractPid('perf'), timeout=2) self._proc.send_signal(signal.SIGINT) diff --git a/tools/telemetry/telemetry/core/platform/profiler/v8_profiler.py b/tools/telemetry/telemetry/core/platform/profiler/v8_profiler.py index a804cfe..e29bb07 100644 --- a/tools/telemetry/telemetry/core/platform/profiler/v8_profiler.py +++ b/tools/telemetry/telemetry/core/platform/profiler/v8_profiler.py @@ -40,8 +40,7 @@ class V8Profiler(profiler.Profiler): self._browser_backend.adb.device().old_interface.Adb().Pull( output_file, host_output_file) # Clean the device - self._browser_backend.adb.device().old_interface.RunShellCommand( - 'rm %s' % output_file) + self._browser_backend.adb.device().RunShellCommand('rm %s' % output_file) output_file = host_output_file print 'V8 profile saved as %s' % output_file print 'To view, open in ' \ |