diff options
author | jbudorick <jbudorick@chromium.org> | 2015-05-14 15:52:11 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-14 22:52:42 +0000 |
commit | ac496302b1d0ada0bbe8ef7beecfdff67d480c6b (patch) | |
tree | 586e2e0673fdad932fea7bf83feacff0c969e816 | |
parent | 76f8ac50bafd70b41324350c3252fb7b0e3c40d6 (diff) | |
download | chromium_src-ac496302b1d0ada0bbe8ef7beecfdff67d480c6b.zip chromium_src-ac496302b1d0ada0bbe8ef7beecfdff67d480c6b.tar.gz chromium_src-ac496302b1d0ada0bbe8ef7beecfdff67d480c6b.tar.bz2 |
[Android] Remove more references to and uses of AndroidCommands.
This includes removing most direct references and uses from telemetry.
BUG=267773,476709
Review URL: https://codereview.chromium.org/1132993004
Cr-Commit-Position: refs/heads/master@{#329963}
28 files changed, 123 insertions, 118 deletions
diff --git a/build/android/adb_install_apk.py b/build/android/adb_install_apk.py index 7bc634c..00bd38e 100755 --- a/build/android/adb_install_apk.py +++ b/build/android/adb_install_apk.py @@ -11,6 +11,7 @@ import os import sys from pylib import constants +from pylib.device import device_errors from pylib.device import device_utils @@ -73,14 +74,11 @@ def main(argv): devices = device_utils.DeviceUtils.HealthyDevices() if options.device: - device_serials = [d.adb.GetDeviceSerial() for d in devices] - if options.device not in device_serials: - raise Exception('Error: %s not in attached devices %s' % (options.device, - ','.join(device_serials))) - devices = [options.device] - - if not devices: - raise Exception('Error: no connected devices') + devices = [d for d in devices if d == options.device] + if not devices: + raise device_errors.DeviceUnreachableError(options.device) + elif not devices: + raise device_errors.NoDevicesError() device_utils.DeviceUtils.parallel(devices).Install( options.apk, reinstall=options.keep_data) diff --git a/build/android/adb_reverse_forwarder.py b/build/android/adb_reverse_forwarder.py index 6cae0cf..3ce5359 100755 --- a/build/android/adb_reverse_forwarder.py +++ b/build/android/adb_reverse_forwarder.py @@ -19,6 +19,7 @@ import time from pylib import constants from pylib import forwarder from pylib.device import adb_wrapper +from pylib.device import device_errors from pylib.device import device_utils from pylib.utils import run_tests_helper @@ -56,16 +57,15 @@ def main(argv): devices = device_utils.DeviceUtils.HealthyDevices() if options.device: - if options.device not in [str(d) for d in devices]: - raise Exception('Error: %s not in attached devices %s' % (options.device, - ','.join(devices))) - devices = [options.device] - else: - if not devices: - raise Exception('Error: no connected devices') + device = next((d for d in devices if d == options.device), None) + if not device: + raise device_errors.DeviceUnreachableError(options.device) + elif devices: + device = devices[0] logging.info('No device specified. Defaulting to %s', devices[0]) + else: + raise device_errors.NoDevicesError() - device = devices[0] constants.SetBuildType(options.build_type) try: forwarder.Forwarder.Map(port_pairs, device) diff --git a/build/android/buildbot/bb_device_steps.py b/build/android/buildbot/bb_device_steps.py index b9a9937..665c736 100755 --- a/build/android/buildbot/bb_device_steps.py +++ b/build/android/buildbot/bb_device_steps.py @@ -18,7 +18,6 @@ import bb_annotations sys.path.append(os.path.join(os.path.dirname(__file__), '..')) import provision_devices -from pylib import android_commands from pylib import constants from pylib.device import device_utils from pylib.gtest import gtest_config @@ -215,9 +214,9 @@ def RunChromeProxyTests(options): """ InstallApk(options, INSTRUMENTATION_TESTS['ChromeShell'], False) args = ['--browser', 'android-chrome-shell'] - devices = android_commands.GetAttachedDevices() + devices = device_utils.DeviceUtils.HealthyDevices() if devices: - args = args + ['--device', devices[0]] + args = args + ['--device', devices[0].adb.GetDeviceSerial()] bb_annotations.PrintNamedStep('chrome_proxy') RunCmd(['tools/chrome_proxy/run_tests'] + args) @@ -234,7 +233,7 @@ def RunTelemetryTests(options, step_name, run_tests_path): """ InstallApk(options, INSTRUMENTATION_TESTS['ChromeShell'], False) args = ['--browser', 'android-chrome-shell'] - devices = android_commands.GetAttachedDevices() + devices = device_utils.DeviceUtils.HealthyDevices() if devices: args = args + ['--device', 'android'] bb_annotations.PrintNamedStep(step_name) diff --git a/build/android/provision_devices.py b/build/android/provision_devices.py index b366f0c..259bd55 100755 --- a/build/android/provision_devices.py +++ b/build/android/provision_devices.py @@ -50,10 +50,11 @@ class _PHASES(object): def ProvisionDevices(options): - if options.device is not None: - devices = [options.device] - else: - devices = device_utils.DeviceUtils.HealthyDevices() + devices = device_utils.DeviceUtils.HealthyDevices() + if options.device: + devices = [d for d in devices if d == options.device] + if not devices: + raise device_errors.DeviceUnreachableError(options.device) parallel_devices = device_utils.DeviceUtils.parallel(devices) parallel_devices.pMap(ProvisionDevice, options) diff --git a/build/android/pylib/android_commands.py b/build/android/pylib/android_commands.py index 1ed1877..f7191f79 100644 --- a/build/android/pylib/android_commands.py +++ b/build/android/pylib/android_commands.py @@ -5,7 +5,11 @@ """Provides an interface to communicate with the device via the adb command. Assumes adb binary is currently on system path. + +Note that this module is deprecated. """ +# TODO(jbudorick): Delete this file once no clients use it. + # pylint: skip-file import collections diff --git a/build/android/screenshot.py b/build/android/screenshot.py index c48a255..097739f 100755 --- a/build/android/screenshot.py +++ b/build/android/screenshot.py @@ -74,8 +74,11 @@ def main(): logging.getLogger().setLevel(logging.DEBUG) devices = device_utils.DeviceUtils.HealthyDevices() - - if not options.device: + if options.device: + device = next((d for d in devices if d == options.device), None) + if not device: + raise device_errors.DeviceUnreachableError(options.device) + else: if len(devices) > 1: parser.error('Multiple devices are attached. ' 'Please specify device serial number with --device.') @@ -83,8 +86,6 @@ def main(): device = devices[0] else: raise device_errors.NoDevicesError() - else: - device = device_utils.DeviceUtils(options.device) if options.video: _CaptureVideo(device, host_file, options) diff --git a/chrome/test/chromedriver/test/run_py_tests.py b/chrome/test/chromedriver/test/run_py_tests.py index 3b2b6c5..1dc119b 100755 --- a/chrome/test/chromedriver/test/run_py_tests.py +++ b/chrome/test/chromedriver/test/run_py_tests.py @@ -37,7 +37,6 @@ _TEST_DATA_DIR = os.path.join(chrome_paths.GetTestData(), 'chromedriver') if util.IsLinux(): sys.path.insert(0, os.path.join(chrome_paths.GetSrc(), 'build', 'android')) - from pylib import android_commands from pylib import constants from pylib import forwarder from pylib import valgrind_tools @@ -236,8 +235,7 @@ class ChromeDriverTest(ChromeDriverBaseTest): chrome_paths.GetTestData()) ChromeDriverTest._sync_server = webserver.SyncWebServer() if _ANDROID_PACKAGE_KEY: - ChromeDriverTest._device = device_utils.DeviceUtils( - android_commands.GetAttachedDevices()[0]) + ChromeDriverTest._device = device_utils.DeviceUtils.HealthyDevices()[0] http_host_port = ChromeDriverTest._http_server._server.server_port sync_host_port = ChromeDriverTest._sync_server._server.server_port forwarder.Forwarder.Map( @@ -1069,8 +1067,8 @@ class ChromeDriverAndroidTest(ChromeDriverBaseTest): print 'Unable to fetch current version info from omahaproxy (%s)' % e def testDeviceManagement(self): - self._drivers = [self.CreateDriver() for x in - android_commands.GetAttachedDevices()] + self._drivers = [self.CreateDriver() + for _ in device_utils.DeviceUtils.HealthyDevices()] self.assertRaises(chromedriver.UnknownError, self.CreateDriver) self._drivers[0].Quit() self._drivers[0] = self.CreateDriver() diff --git a/chrome/test/chromedriver/test/test_environment.py b/chrome/test/chromedriver/test/test_environment.py index 190721a..f90c12e 100644 --- a/chrome/test/chromedriver/test/test_environment.py +++ b/chrome/test/chromedriver/test/test_environment.py @@ -18,7 +18,6 @@ _THIS_DIR = os.path.abspath(os.path.dirname(__file__)) if util.IsLinux(): sys.path.insert(0, os.path.join(chrome_paths.GetSrc(), 'build', 'android')) - from pylib import android_commands from pylib import forwarder from pylib import valgrind_tools from pylib.device import device_errors @@ -96,12 +95,12 @@ class AndroidTestEnvironment(DesktopTestEnvironment): def GlobalSetUp(self): os.putenv('TEST_HTTP_PORT', str(ANDROID_TEST_HTTP_PORT)) os.putenv('TEST_HTTPS_PORT', str(ANDROID_TEST_HTTPS_PORT)) - devices = android_commands.GetAttachedDevices() + devices = device_utils.DeviceUtils.HealthyDevices() if not devices: raise device_errors.NoDevicesError() elif len(devices) > 1: logging.warning('Multiple devices attached. Using %s.' % devices[0]) - self._device = device_utils.DeviceUtils(devices[0]) + self._device = devices[0] forwarder.Forwarder.Map( [(ANDROID_TEST_HTTP_PORT, ANDROID_TEST_HTTP_PORT), (ANDROID_TEST_HTTPS_PORT, ANDROID_TEST_HTTPS_PORT)], diff --git a/tools/android/mempressure.py b/tools/android/mempressure.py index 5c81f3e..c763038 100755 --- a/tools/android/mempressure.py +++ b/tools/android/mempressure.py @@ -15,7 +15,6 @@ BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), 'build', 'android') sys.path.append(BUILD_ANDROID_DIR) -from pylib import android_commands from pylib import constants from pylib import flag_changer from pylib.device import device_errors @@ -88,12 +87,12 @@ def main(argv): package = package_info.package activity = package_info.activity - devices = android_commands.GetAttachedDevices() + devices = device_utils.DeviceUtils.HealthyDevices() if not devices: raise device_errors.NoDevicesError() elif len(devices) > 1: - logging.warning('Multiple devices attached. Using %s.' % devices[0]) - device = device_utils.DeviceUtils(devices[0]) + logging.warning('Multiple devices attached. Using %s.', str(devices[0])) + device = devices[0] try: device.EnableRoot() diff --git a/tools/cygprofile/profile_android_startup.py b/tools/cygprofile/profile_android_startup.py index 9287cea..79f5461 100644 --- a/tools/cygprofile/profile_android_startup.py +++ b/tools/cygprofile/profile_android_startup.py @@ -18,7 +18,6 @@ import tempfile import time sys.path.append(os.path.join(sys.path[0], '..', '..', 'build', 'android')) -from pylib import android_commands from pylib import constants from pylib import flag_changer from pylib import forwarder @@ -201,8 +200,8 @@ class AndroidProfileTool(object): def __init__(self, output_directory): - devices = android_commands.GetAttachedDevices() - self._device = device_utils.DeviceUtils(devices[0]) + devices = device_utils.DeviceUtils.HealthyDevices() + self._device = devices[0] self._cygprofile_tests = os.path.join( output_directory, 'cygprofile_unittests') self._host_cyglog_dir = os.path.join( diff --git a/tools/profile_chrome/controllers_unittest.py b/tools/profile_chrome/controllers_unittest.py index 1d9a10c..94f3685 100644 --- a/tools/profile_chrome/controllers_unittest.py +++ b/tools/profile_chrome/controllers_unittest.py @@ -6,19 +6,18 @@ import unittest from profile_chrome import profiler -from pylib import android_commands from pylib.device import device_utils from pylib.device import intent class BaseControllerTest(unittest.TestCase): def setUp(self): - devices = android_commands.GetAttachedDevices() + devices = device_utils.DeviceUtils.HealthyDevices() self.browser = 'stable' self.package_info = profiler.GetSupportedBrowsers()[self.browser] - self.device = device_utils.DeviceUtils(devices[0]) + self.device = devices[0] - self.device.old_interface.CloseApplication(self.package_info.package) + self.device.ForceStop(self.package_info.package) self.device.StartActivity( intent.Intent(activity=self.package_info.activity, package=self.package_info.package), diff --git a/tools/profile_chrome/main.py b/tools/profile_chrome/main.py index 25adbfb..7db45fb 100755 --- a/tools/profile_chrome/main.py +++ b/tools/profile_chrome/main.py @@ -18,7 +18,6 @@ from profile_chrome import profiler from profile_chrome import systrace_controller from profile_chrome import ui -from pylib import android_commands from pylib.device import device_utils @@ -170,15 +169,15 @@ When in doubt, just try out --trace-frame-viewer. if options.verbose: logging.getLogger().setLevel(logging.DEBUG) - devices = android_commands.GetAttachedDevices() + devices = device_utils.DeviceUtils.HealthyDevices() device = None - if options.device in devices: - device = options.device - elif not options.device and len(devices) == 1: + if options.device: + device = next((d for d in devices if d == options.device), None) + elif len(devices) == 1: device = devices[0] + if not device: parser.error('Use -d/--device to select a device:\n' + '\n'.join(devices)) - device = device_utils.DeviceUtils(device) package_info = profiler.GetSupportedBrowsers()[options.browser] if options.chrome_categories in ['list', 'help']: diff --git a/tools/profile_chrome/perf_controller.py b/tools/profile_chrome/perf_controller.py index 06992cf..bd979d5 100644 --- a/tools/profile_chrome/perf_controller.py +++ b/tools/profile_chrome/perf_controller.py @@ -15,6 +15,7 @@ from profile_chrome import ui from pylib import android_commands from pylib import constants from pylib.perf import perf_control +from pylib.utils import device_temp_file sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 'tools', @@ -47,8 +48,8 @@ _PERF_OPTIONS = [ class _PerfProfiler(object): def __init__(self, device, perf_binary, categories): self._device = device - self._output_file = android_commands.DeviceTempFile( - self._device.old_interface, prefix='perf_output') + self._output_file = device_temp_file.DeviceTempFile( + self._device.adb, prefix='perf_output') self._log_file = tempfile.TemporaryFile() # TODO(jbudorick) Look at providing a way to unhandroll this once the diff --git a/tools/profile_chrome_startup.py b/tools/profile_chrome_startup.py index 5620907..632e363 100755 --- a/tools/profile_chrome_startup.py +++ b/tools/profile_chrome_startup.py @@ -19,7 +19,6 @@ from profile_chrome import flags from profile_chrome import profiler from profile_chrome import systrace_controller from profile_chrome import ui -from pylib import android_commands from pylib.device import device_utils @@ -58,11 +57,11 @@ def main(): if options.verbose: logging.getLogger().setLevel(logging.DEBUG) - devices = android_commands.GetAttachedDevices() + devices = device_utils.DeviceUtils.HealthyDevices() if len(devices) != 1: logging.error('Exactly 1 device must be attached.') return 1 - device = device_utils.DeviceUtils(devices[0]) + device = devices[0] package_info = profiler.GetSupportedBrowsers()[options.browser] if options.systrace_categories in ['list', 'help']: diff --git a/tools/telemetry/telemetry/core/forwarders/android_forwarder.py b/tools/telemetry/telemetry/core/forwarders/android_forwarder.py index b2f58e0..ed8ed7b 100644 --- a/tools/telemetry/telemetry/core/forwarders/android_forwarder.py +++ b/tools/telemetry/telemetry/core/forwarders/android_forwarder.py @@ -185,8 +185,11 @@ class AndroidRndisConfigurator(object): def __init__(self, adb): self._device = adb.device() - is_root_enabled = self._device.old_interface.EnableAdbRoot() - assert is_root_enabled, 'RNDIS forwarding requires a rooted device.' + try: + self._device.EnableRoot() + except device_errors.CommandFailedError: + logging.error('RNDIS forwarding requires a rooted device.') + raise self._device_ip = None self._host_iface = None @@ -207,9 +210,6 @@ class AndroidRndisConfigurator(object): """Checks that the device has RNDIS support in the kernel.""" return self._device.FileExists('%s/f_rndis/device' % self._RNDIS_DEVICE) - def _WaitForDevice(self): - self._device.old_interface.Adb().SendCommand('wait-for-device') - def _FindDeviceRndisInterface(self): """Returns the name of the RNDIS network interface if present.""" config = self._device.RunShellCommand('netcfg') @@ -279,7 +279,7 @@ class AndroidRndisConfigurator(object): except device_errors.AdbCommandFailedError: # Ignore exception due to USB connection being reset. pass - self._WaitForDevice() + self._device.adb.WaitForDevice() def _EnableRndis(self): """Enables the RNDIS network interface.""" @@ -321,7 +321,7 @@ doit & # TODO(szym): run via su -c if necessary. self._device.RunShellCommand('rm %s.log' % script_prefix) self._device.RunShellCommand('. %s.sh' % script_prefix) - self._WaitForDevice() + self._device.adb.WaitForDevice() result = self._device.ReadFile('%s.log' % script_prefix).splitlines() assert any('DONE' in line for line in result), 'RNDIS script did not run!' @@ -489,7 +489,7 @@ doit & self._device.RunShellCommand( 'ifconfig %s %s netmask %s up' % (device_iface, device_ip, netmask)) # Enabling the interface sometimes breaks adb. - self._WaitForDevice() + self._device.adb.WaitForDevice() self._host_iface = host_iface self._host_ip = host_ip self.device_iface = device_iface diff --git a/tools/telemetry/telemetry/core/platform/android_platform_backend.py b/tools/telemetry/telemetry/core/platform/android_platform_backend.py index 0fcd4c6..bc23118 100644 --- a/tools/telemetry/telemetry/core/platform/android_platform_backend.py +++ b/tools/telemetry/telemetry/core/platform/android_platform_backend.py @@ -37,13 +37,13 @@ import platformsettings # pylint: disable=import-error # Get build/android scripts into our path. util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android') +from pylib import constants # pylint: disable=F0401 +from pylib import screenshot # pylint: disable=F0401 from pylib.device import battery_utils # pylint: disable=F0401 from pylib.perf import cache_control # pylint: disable=F0401 from pylib.perf import perf_control # pylint: disable=F0401 from pylib.perf import thermal_throttle # pylint: disable=F0401 from pylib.utils import device_temp_file # pylint: disable=F0401 -from pylib import constants # pylint: disable=F0401 -from pylib import screenshot # pylint: disable=F0401 try: from pylib.perf import surface_stats_collector # pylint: disable=import-error @@ -51,6 +51,13 @@ except Exception: surface_stats_collector = None +_DEVICE_COPY_SCRIPT_FILE = os.path.join( + constants.DIR_SOURCE_ROOT, 'build', 'android', 'pylib', + 'efficient_android_directory_copy.sh') +_DEVICE_COPY_SCRIPT_LOCATION = ( + '/data/local/tmp/efficient_android_directory_copy.sh') + + class AndroidPlatformBackend( linux_based_platform_backend.LinuxBasedPlatformBackend): def __init__(self, device, finder_options): @@ -76,8 +83,9 @@ class AndroidPlatformBackend( self._perf_tests_setup = perf_control.PerfControl(self._device) self._thermal_throttle = thermal_throttle.ThermalThrottle(self._device) self._raw_display_frame_rate_measurements = [] - self._can_access_protected_file_contents = \ - self._device.old_interface.CanAccessProtectedFileContents() + self._can_access_protected_file_contents = ( + self._device.HasRoot() or self._device.NeedsSU()) + self._device_copy_script = None power_controller = power_monitor_controller.PowerMonitorController([ monsoon_power_monitor.MonsoonPowerMonitor(self._device, self), android_ds2784_power_monitor.DS2784PowerMonitor(self._device, self), @@ -201,11 +209,11 @@ class AndroidPlatformBackend( if not android_prebuilt_profiler_helper.InstallOnDevice( self._device, 'purge_ashmem'): raise Exception('Error installing purge_ashmem.') - (status, output) = self._device.old_interface.GetAndroidToolStatusAndOutput( + output = self._device.RunShellCommand( android_prebuilt_profiler_helper.GetDevicePath('purge_ashmem'), - log_result=True) - if status != 0: - raise Exception('Error while purging ashmem: ' + '\n'.join(output)) + check_return=True) + for l in output: + logging.info(l) def GetMemoryStats(self, pid): memory_usage = self._device.GetMemoryUsageForPid(pid) @@ -530,7 +538,7 @@ class AndroidPlatformBackend( self._device.PushChangedFiles([(new_profile_dir, saved_profile_location)]) profile_dir = self._GetProfileDir(package) - self._device.old_interface.EfficientDeviceDirectoryCopy( + self._EfficientDeviceDirectoryCopy( saved_profile_location, profile_dir) dumpsys = self._device.RunShellCommand('dumpsys package %s' % package) id_line = next(line for line in dumpsys if 'userId=' in line) @@ -544,6 +552,16 @@ class AndroidPlatformBackend( self._device.RunShellCommand( 'chown %s.%s %s' % (uid, uid, extended_path)) + def _EfficientDeviceDirectoryCopy(self, source, dest): + if not self._device_copy_script: + self._device.adb.Push( + _DEVICE_COPY_SCRIPT_FILE, + _DEVICE_COPY_SCRIPT_LOCATION) + self._device_copy_script = _DEVICE_COPY_SCRIPT_FILE + self._device.RunShellCommand( + ['sh', self._device_copy_script, source, dest], + check_return=True) + def RemoveProfile(self, package, ignore_list): """Delete application profile on device. @@ -574,17 +592,14 @@ class AndroidPlatformBackend( # pulled down is really needed e.g. .pak files. if not os.path.exists(output_profile_path): os.makedirs(output_profile_path) - files = self._device.RunShellCommand('ls "%s"' % profile_dir) + files = self._device.RunShellCommand( + ['ls', profile_dir], check_return=True) for f in files: # Don't pull lib, since it is created by the installer. if f != 'lib': source = '%s%s' % (profile_dir, f) dest = os.path.join(output_profile_path, f) - # self._adb.Pull(source, dest) doesn't work because its timeout - # is fixed in android's adb_interface at 60 seconds, which may - # be too short to pull the cache. - cmd = 'pull %s %s' % (source, dest) - self._device.old_interface.Adb().SendCommand(cmd, timeout_time=240) + self._device.PullFile(source, dest, timeout=240) def _GetProfileDir(self, package): """Returns the on-device location where the application profile is stored diff --git a/tools/telemetry/telemetry/core/platform/android_platform_backend_unittest.py b/tools/telemetry/telemetry/core/platform/android_platform_backend_unittest.py index 6bd8edeb7..1db861b 100644 --- a/tools/telemetry/telemetry/core/platform/android_platform_backend_unittest.py +++ b/tools/telemetry/telemetry/core/platform/android_platform_backend_unittest.py @@ -44,8 +44,7 @@ class AndroidPlatformBackendTest(unittest.TestCase): '1074767676 0 4612 0 38136 4294967295 0 0 17 0 0 0 0 0 0 ' '1074470376 1074470912 1102155776\n') self._stubs.adb_commands.adb_device.mock_content = proc_stat_content - old_interface = self._stubs.adb_commands.adb_device.old_interface - old_interface.can_access_protected_file_contents = True + self._stubs.adb_commands.adb_device.has_root = True backend = android_platform_backend.AndroidPlatformBackend( android_device.AndroidDevice('12345'), self._options) cpu_stats = backend.GetCpuStats('7702') 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 25c375b..92abae1 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 @@ -5,10 +5,14 @@ import logging import os +from telemetry.core import util from telemetry.core.platform.power_monitor import sysfs_power_monitor from telemetry.core.platform.profiler import android_prebuilt_profiler_helper from telemetry import decorators +util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android') +from pylib.device import battery_utils # pylint: disable=F0401 + SAMPLE_RATE_HZ = 2 # The data is collected from the ds2784 fuel gauge chip # that only updates its data every 3.5s. @@ -27,6 +31,7 @@ class DS2784PowerMonitor(sysfs_power_monitor.SysfsPowerMonitor): def __init__(self, device, platform_backend): super(DS2784PowerMonitor, self).__init__(platform_backend) self._device = device + self._device_battery = battery_utils.BatteryUtils(self._device) self._powermonitor_process_port = None self._file_poller_binary = android_prebuilt_profiler_helper.GetDevicePath( 'file_poller') @@ -38,8 +43,8 @@ class DS2784PowerMonitor(sysfs_power_monitor.SysfsPowerMonitor): def CanMonitorPower(self): if not self._HasFuelGauge(): return False - if self._device.old_interface.IsDeviceCharging(): - logging.warning('Can\'t monitor power usage since device is charging.') + if self._device_battery.GetCharging(): + logging.warning("Can't monitor power usage since device is charging.") return False return True diff --git a/tools/telemetry/telemetry/core/platform/power_monitor/android_temperature_monitor_unittest.py b/tools/telemetry/telemetry/core/platform/power_monitor/android_temperature_monitor_unittest.py index ea283ac..0ca4d05 100644 --- a/tools/telemetry/telemetry/core/platform/power_monitor/android_temperature_monitor_unittest.py +++ b/tools/telemetry/telemetry/core/platform/power_monitor/android_temperature_monitor_unittest.py @@ -59,10 +59,8 @@ class AndroidTemperatureMonitorTest(unittest.TestCase): def testSysfsReadFailed(self): mock_power_monitor = simple_mock.MockObject() mock_power_monitor.ExpectCall('CanMonitorPower').WillReturn(False) - mock_adb = simple_mock.MockObject() mock_device_utils = simple_mock.MockObject() mock_device_utils.ExpectCall('ReadFile', _).WillReturn('') - setattr(mock_device_utils, 'old_interface', mock_adb) monitor = android_temperature_monitor.AndroidTemperatureMonitor( mock_power_monitor, mock_device_utils) 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 f38664b..bbdd9f5 100644 --- a/tools/telemetry/telemetry/core/platform/profiler/android_profiling_helper.py +++ b/tools/telemetry/telemetry/core/platform/profiler/android_profiling_helper.py @@ -17,6 +17,10 @@ from telemetry.core import util from telemetry import decorators from telemetry.util import support_binaries +util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android') +from pylib.utils import md5sum # pylint: disable=F0401 + + try: import sqlite3 except ImportError: @@ -166,7 +170,6 @@ def CreateSymFs(device, symfs_dir, libraries, use_symlinks=True): """ logging.info('Building symfs into %s.' % symfs_dir) - mismatching_files = {} for lib in libraries: device_dir = os.path.dirname(lib) output_dir = os.path.join(symfs_dir, device_dir[1:]) @@ -201,14 +204,9 @@ def CreateSymFs(device, symfs_dir, libraries, use_symlinks=True): # the profiler can at least use the public symbols of that library. To # speed things up, only pull files that don't match copies we already # have in the symfs. - if not device_dir in mismatching_files: - changed_files = device.old_interface.GetFilesChanged(output_dir, - device_dir) - mismatching_files[device_dir] = [ - device_path for _, device_path in changed_files] - - if not os.path.exists(output_lib) or lib in mismatching_files[device_dir]: - logging.info('Pulling %s to %s' % (lib, output_lib)) + if (md5sum.CalculateHostMd5Sums([output_lib])[0] != + md5sum.CalculateDeviceMd5Sums([lib])[0]): + logging.info('Pulling %s to %s', lib, output_lib) device.PullFile(lib, output_lib) # Also pull a copy of the kernel symbols. diff --git a/tools/telemetry/telemetry/core/platform/profiler/android_traceview_profiler.py b/tools/telemetry/telemetry/core/platform/profiler/android_traceview_profiler.py index 5e24526..3f7a080 100644 --- a/tools/telemetry/telemetry/core/platform/profiler/android_traceview_profiler.py +++ b/tools/telemetry/telemetry/core/platform/profiler/android_traceview_profiler.py @@ -58,7 +58,7 @@ class AndroidTraceviewProfiler(profiler.Profiler): # pylint: disable=cell-var-from-loop util.WaitFor(lambda: self._FileSize(trace_file) > 0, timeout=10) output_files.append(trace_file) - self._browser_backend.adb.device().old_interface.Adb().Pull( + self._browser_backend.adb.device().PullFile( self._DEFAULT_DEVICE_DIR, self._output_path) self._browser_backend.adb.RunShellCommand( 'rm ' + os.path.join(self._DEFAULT_DEVICE_DIR, '*')) diff --git a/tools/telemetry/telemetry/core/platform/profiler/java_heap_profiler.py b/tools/telemetry/telemetry/core/platform/profiler/java_heap_profiler.py index b6693bb..8719406 100644 --- a/tools/telemetry/telemetry/core/platform/profiler/java_heap_profiler.py +++ b/tools/telemetry/telemetry/core/platform/profiler/java_heap_profiler.py @@ -48,7 +48,7 @@ class JavaHeapProfiler(profiler.Profiler): def CollectProfile(self): self._timer.cancel() self._DumpJavaHeap(True) - self._browser_backend.adb.device().old_interface.Adb().Pull( + self._browser_backend.adb.device().PullFile( self._DEFAULT_DEVICE_DIR, self._output_path) self._browser_backend.adb.RunShellCommand( 'rm ' + os.path.join(self._DEFAULT_DEVICE_DIR, '*')) diff --git a/tools/telemetry/telemetry/core/platform/profiler/netlog_profiler.py b/tools/telemetry/telemetry/core/platform/profiler/netlog_profiler.py index 0c2e604..aa0070a 100644 --- a/tools/telemetry/telemetry/core/platform/profiler/netlog_profiler.py +++ b/tools/telemetry/telemetry/core/platform/profiler/netlog_profiler.py @@ -36,8 +36,7 @@ class NetLogProfiler(profiler.Profiler): # On Android pull the output file to the host. if self._platform_backend.GetOSName() == 'android': host_output_file = '%s.json' % self._output_path - self._browser_backend.adb.device().old_interface.Adb().Pull( - output_file, host_output_file) + self._browser_backend.adb.device().PullFile(output_file, host_output_file) # Clean the device self._browser_backend.adb.device().RunShellCommand('rm %s' % output_file) output_file = host_output_file diff --git a/tools/telemetry/telemetry/core/platform/profiler/perf_profiler.py b/tools/telemetry/telemetry/core/platform/profiler/perf_profiler.py index 5065ad6..f0982e6 100644 --- a/tools/telemetry/telemetry/core/platform/profiler/perf_profiler.py +++ b/tools/telemetry/telemetry/core/platform/profiler/perf_profiler.py @@ -128,8 +128,7 @@ Try rerunning this script under sudo or setting self._output_file) if self._is_android: device = self._browser_backend.adb.device() - device.old_interface.Adb().Pull(self._device_output_file, - self._output_file) + device.PullFile(self._device_output_file, self._output_file) required_libs = \ android_profiling_helper.GetRequiredLibrariesForPerfProfile( self._output_file) diff --git a/tools/telemetry/telemetry/core/platform/profiler/tcmalloc_heap_profiler.py b/tools/telemetry/telemetry/core/platform/profiler/tcmalloc_heap_profiler.py index 14cf6f7..4fc3982 100644 --- a/tools/telemetry/telemetry/core/platform/profiler/tcmalloc_heap_profiler.py +++ b/tools/telemetry/telemetry/core/platform/profiler/tcmalloc_heap_profiler.py @@ -34,7 +34,7 @@ class _TCMallocHeapProfilerAndroid(object): def _SetDeviceProperties(self, properties): device_configured = False # This profiler requires adb root to set properties. - self._browser_backend.adb.device().old_interface.EnableAdbRoot() + self._browser_backend.adb.device().EnableRoot() for values in properties.itervalues(): device_property = self._browser_backend.adb.device().GetProp(values[0]) if not device_property or not device_property.strip(): @@ -51,7 +51,7 @@ class _TCMallocHeapProfilerAndroid(object): raise Exception('Device required special config, run again.') def CollectProfile(self): - self._browser_backend.adb.device().old_interface.Adb().Pull( + self._browser_backend.adb.device().PullFile( self._DEFAULT_DEVICE_DIR, self._output_path) self._browser_backend.adb.RunShellCommand( 'rm ' + os.path.join(self._DEFAULT_DEVICE_DIR, '*')) diff --git a/tools/telemetry/telemetry/core/platform/profiler/tcpdump_profiler.py b/tools/telemetry/telemetry/core/platform/profiler/tcpdump_profiler.py index cd168d0..6ad22c4 100644 --- a/tools/telemetry/telemetry/core/platform/profiler/tcpdump_profiler.py +++ b/tools/telemetry/telemetry/core/platform/profiler/tcpdump_profiler.py @@ -44,8 +44,7 @@ class _TCPDumpProfilerAndroid(object): self._proc.terminate() host_dump = os.path.join(self._output_path, os.path.basename(self._DEVICE_DUMP_FILE)) - self._adb.device().old_interface.Adb().Pull(self._DEVICE_DUMP_FILE, - host_dump) + self._adb.device().PullFile(self._DEVICE_DUMP_FILE, host_dump) print 'TCP dump available at: %s ' % host_dump print 'Use Wireshark to open it.' return host_dump diff --git a/tools/telemetry/telemetry/core/platform/profiler/v8_profiler.py b/tools/telemetry/telemetry/core/platform/profiler/v8_profiler.py index a35b73192..73e126e 100644 --- a/tools/telemetry/telemetry/core/platform/profiler/v8_profiler.py +++ b/tools/telemetry/telemetry/core/platform/profiler/v8_profiler.py @@ -38,8 +38,7 @@ class V8Profiler(profiler.Profiler): # On Android pull the output file to the host. if self._platform_backend.GetOSName() == 'android': host_output_file = '%s.log' % self._output_path - self._browser_backend.adb.device().old_interface.Adb().Pull( - output_file, host_output_file) + self._browser_backend.adb.device().PullFile(output_file, host_output_file) # Clean the device self._browser_backend.adb.device().RunShellCommand('rm %s' % output_file) output_file = host_output_file diff --git a/tools/telemetry/telemetry/unittest_util/system_stub.py b/tools/telemetry/telemetry/unittest_util/system_stub.py index 72fca71..cb7c20d 100644 --- a/tools/telemetry/telemetry/unittest_util/system_stub.py +++ b/tools/telemetry/telemetry/unittest_util/system_stub.py @@ -60,24 +60,22 @@ class Override(object): self._overrides = {} -class AndroidCommands(object): - - def __init__(self): - self.can_access_protected_file_contents = False - - def CanAccessProtectedFileContents(self): - return self.can_access_protected_file_contents - - class AdbDevice(object): def __init__(self): + self.has_root = False + self.needs_su = False self.shell_command_handlers = {} self.mock_content = [] self.system_properties = {} if self.system_properties.get('ro.product.cpu.abi') == None: self.system_properties['ro.product.cpu.abi'] = 'armeabi-v7a' - self.old_interface = AndroidCommands() + + def HasRoot(self): + return self.has_root + + def NeedsSU(self): + return self.needs_su def RunShellCommand(self, args, **_kwargs): if isinstance(args, basestring): |