Example #1
0
  def __init__(self, device):
    assert device, (
        'AndroidPlatformBackend can only be initialized from remote device')
    super(AndroidPlatformBackend, self).__init__(device)
    self._device = device_utils.DeviceUtils(device.device_id)
    # Trying to root the device, if possible.
    if not self._device.HasRoot():
      try:
        self._device.EnableRoot()
      except device_errors.CommandFailedError:
        logging.warning('Unable to root %s', str(self._device))
    self._can_elevate_privilege = (
        self._device.HasRoot() or self._device.NeedsSU())
    assert self._can_elevate_privilege, (
        'Android device must have root access to run Telemetry')
    self._battery = battery_utils.BatteryUtils(self._device)
    self._enable_performance_mode = device.enable_performance_mode
    self._surface_stats_collector = None
    self._perf_tests_setup = perf_control.PerfControl(self._device)
    self._thermal_throttle = thermal_throttle.ThermalThrottle(self._device)
    self._raw_display_frame_rate_measurements = []
    self._device_copy_script = None
    self._power_monitor = (
        android_power_monitor_controller.AndroidPowerMonitorController([
            android_temperature_monitor.AndroidTemperatureMonitor(self._device),
            android_dumpsys_power_monitor.DumpsysPowerMonitor(
                self._battery, self),
            sysfs_power_monitor.SysfsPowerMonitor(self, standalone=True),
            android_fuelgauge_power_monitor.FuelGaugePowerMonitor(
                self._battery),
        ], self._battery))
    self._video_recorder = None
    self._system_ui = None

    _FixPossibleAdbInstability()
Example #2
0
    def __init__(self, device, finder_options):
        assert device, (
            'AndroidPlatformBackend can only be initialized from remote device'
        )
        super(AndroidPlatformBackend, self).__init__(device)
        self._device = device_utils.DeviceUtils(device.device_id)
        installed_prebuilt_tools = _SetupPrebuiltTools(self._device)
        if not installed_prebuilt_tools:
            logging.error(
                '%s detected, however prebuilt android tools could not '
                'be used. To run on Android you must build them first:\n'
                '  $ ninja -C out/Release android_tools' % device.name)
            raise exceptions.PlatformError()
        # Trying to root the device, if possible.
        if not self._device.HasRoot():
            try:
                self._device.EnableRoot()
            except device_errors.CommandFailedError:
                logging.warning('Unable to root %s', str(self._device))
        self._battery = battery_utils.BatteryUtils(self._device)
        self._enable_performance_mode = device.enable_performance_mode
        self._surface_stats_collector = None
        self._perf_tests_setup = perf_control.PerfControl(self._device)
        self._thermal_throttle = thermal_throttle.ThermalThrottle(self._device)
        self._raw_display_frame_rate_measurements = []
        try:
            self._can_access_protected_file_contents = (self._device.HasRoot()
                                                        or
                                                        self._device.NeedsSU())
        except Exception:
            logging.exception('New exception caused by DeviceUtils conversion')
            raise
        self._device_copy_script = None
        self._power_monitor = (
            android_power_monitor_controller.AndroidPowerMonitorController([
                android_temperature_monitor.AndroidTemperatureMonitor(
                    self._device),
                monsoon_power_monitor.MonsoonPowerMonitor(self._device, self),
                android_dumpsys_power_monitor.DumpsysPowerMonitor(
                    self._battery, self),
                sysfs_power_monitor.SysfsPowerMonitor(self, standalone=True),
                android_fuelgauge_power_monitor.FuelGaugePowerMonitor(
                    self._battery, self),
            ], self._battery))
        self._video_recorder = None
        self._installed_applications = None

        self._wpr_ca_cert_path = None
        self._device_cert_util = None
        self._is_test_ca_installed = False

        self._use_rndis_forwarder = (
            finder_options.android_rndis
            or finder_options.browser_options.netsim
            or platform.GetHostPlatform().GetOSName() != 'linux')

        _FixPossibleAdbInstability()
    def testComposition(self, _):
        class P1(power_monitor.PowerMonitor):
            def StartMonitoringPower(self, browser):
                raise NotImplementedError()

            def StopMonitoringPower(self):
                raise NotImplementedError()

        class P2(power_monitor.PowerMonitor):
            def __init__(self, value):
                super(P2, self).__init__()
                self._value = {'P2': value}

            def CanMonitorPower(self):
                return True

            def StartMonitoringPower(self, browser):
                pass

            def StopMonitoringPower(self):
                return self._value

        class P3(power_monitor.PowerMonitor):
            def __init__(self, value):
                super(P3, self).__init__()
                self._value = {'P3': value}

            def CanMonitorPower(self):
                return True

            def StartMonitoringPower(self, browser):
                pass

            def StopMonitoringPower(self):
                return self._value

        battery = battery_utils.BatteryUtils(None)
        controller = android_power_monitor_controller.AndroidPowerMonitorController(
            [P1(), P2(1), P3(2)], battery)
        self.assertEqual(controller.CanMonitorPower(), True)
        controller.StartMonitoringPower(None)
        controller_returns = controller.StopMonitoringPower()
        self.assertEqual(controller_returns['P2'], 1)
        self.assertEqual(controller_returns['P3'], 2)