OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 import logging | 5 import logging |
6 import os | 6 import os |
7 import posixpath | 7 import posixpath |
8 import re | 8 import re |
9 import subprocess | 9 import subprocess |
10 import tempfile | 10 import tempfile |
(...skipping 10 matching lines...) Expand all Loading... |
21 from telemetry.internal.platform import linux_based_platform_backend | 21 from telemetry.internal.platform import linux_based_platform_backend |
22 from telemetry.internal.platform.power_monitor import android_dumpsys_power_moni
tor | 22 from telemetry.internal.platform.power_monitor import android_dumpsys_power_moni
tor |
23 from telemetry.internal.platform.power_monitor import android_fuelgauge_power_mo
nitor | 23 from telemetry.internal.platform.power_monitor import android_fuelgauge_power_mo
nitor |
24 from telemetry.internal.platform.power_monitor import android_temperature_monito
r | 24 from telemetry.internal.platform.power_monitor import android_temperature_monito
r |
25 from telemetry.internal.platform.power_monitor import ( | 25 from telemetry.internal.platform.power_monitor import ( |
26 android_power_monitor_controller) | 26 android_power_monitor_controller) |
27 from telemetry.internal.platform.power_monitor import sysfs_power_monitor | 27 from telemetry.internal.platform.power_monitor import sysfs_power_monitor |
28 from telemetry.internal.platform.profiler import android_prebuilt_profiler_helpe
r | 28 from telemetry.internal.platform.profiler import android_prebuilt_profiler_helpe
r |
29 from telemetry.internal.util import binary_manager | 29 from telemetry.internal.util import binary_manager |
30 from telemetry.internal.util import external_modules | 30 from telemetry.internal.util import external_modules |
31 from telemetry.internal.util import webpagereplay_go_server | |
32 | 31 |
33 psutil = external_modules.ImportOptionalModule('psutil') | 32 psutil = external_modules.ImportOptionalModule('psutil') |
34 | 33 |
35 from devil.android import app_ui | 34 from devil.android import app_ui |
36 from devil.android import battery_utils | 35 from devil.android import battery_utils |
37 from devil.android import device_errors | 36 from devil.android import device_errors |
38 from devil.android import device_utils | 37 from devil.android import device_utils |
39 from devil.android.perf import cache_control | 38 from devil.android.perf import cache_control |
40 from devil.android.perf import perf_control | 39 from devil.android.perf import perf_control |
41 from devil.android.perf import thermal_throttle | 40 from devil.android.perf import thermal_throttle |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 android_temperature_monitor.AndroidTemperatureMonitor(self._device), | 93 android_temperature_monitor.AndroidTemperatureMonitor(self._device), |
95 android_dumpsys_power_monitor.DumpsysPowerMonitor( | 94 android_dumpsys_power_monitor.DumpsysPowerMonitor( |
96 self._battery, self), | 95 self._battery, self), |
97 sysfs_power_monitor.SysfsPowerMonitor(self, standalone=True), | 96 sysfs_power_monitor.SysfsPowerMonitor(self, standalone=True), |
98 android_fuelgauge_power_monitor.FuelGaugePowerMonitor( | 97 android_fuelgauge_power_monitor.FuelGaugePowerMonitor( |
99 self._battery), | 98 self._battery), |
100 ], self._battery)) | 99 ], self._battery)) |
101 self._video_recorder = None | 100 self._video_recorder = None |
102 self._installed_applications = None | 101 self._installed_applications = None |
103 | 102 |
104 self._test_ca_installed = None | |
105 self._system_ui = None | 103 self._system_ui = None |
106 | 104 |
107 _FixPossibleAdbInstability() | 105 _FixPossibleAdbInstability() |
108 | 106 |
109 @property | 107 @property |
110 def log_file_path(self): | 108 def log_file_path(self): |
111 return None | 109 return None |
112 | 110 |
113 @classmethod | 111 @classmethod |
114 def SupportsDevice(cls, device): | 112 def SupportsDevice(cls, device): |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 break | 550 break |
553 | 551 |
554 def IsAppRunning(self, process_name): | 552 def IsAppRunning(self, process_name): |
555 """Determine if the given process is running. | 553 """Determine if the given process is running. |
556 | 554 |
557 Args: | 555 Args: |
558 process_name: The full package name string of the process. | 556 process_name: The full package name string of the process. |
559 """ | 557 """ |
560 return bool(self._device.GetPids(process_name)) | 558 return bool(self._device.GetPids(process_name)) |
561 | 559 |
562 @property | |
563 def supports_test_ca(self): | |
564 # TODO(nednguyen): figure out how to install certificate on Android M | |
565 # crbug.com/593152 | |
566 # TODO(crbug.com/716084): enable support for test CA | |
567 # return self._device.build_version_sdk <= version_codes.LOLLIPOP_MR1 | |
568 return False | |
569 | |
570 def InstallTestCa(self): | |
571 """Install a randomly generated root CA on the android device. | |
572 | |
573 This allows transparent HTTPS testing with WPR server without need | |
574 to tweak application network stack. | |
575 | |
576 Note: If this method fails with any exception, then RemoveTestCa will be | |
577 automatically called by the network_controller_backend. | |
578 """ | |
579 if self._test_ca_installed is not None: | |
580 logging.warning('Test certificate authority is already installed.') | |
581 return | |
582 webpagereplay_go_server.ReplayServer.InstallRootCertificate( | |
583 android_device_id=self._device.adb.GetDeviceSerial(), | |
584 adb_path=self._device.adb.GetAdbPath()) | |
585 | |
586 def RemoveTestCa(self): | |
587 """Remove root CA from device installed by InstallTestCa. | |
588 | |
589 Note: Any exceptions raised by this method will be logged but dismissed by | |
590 the network_controller_backend. | |
591 """ | |
592 if self._test_ca_installed is not None: | |
593 try: | |
594 webpagereplay_go_server.ReplayServer.RemoveRootCertificate( | |
595 android_device_id=self._device.adb.GetDeviceSerial(), | |
596 adb_path=self._device.adb.GetAdbPath()) | |
597 finally: | |
598 self._test_ca_installed = None | |
599 | |
600 def PushProfile(self, package, new_profile_dir): | 560 def PushProfile(self, package, new_profile_dir): |
601 """Replace application profile with files found on host machine. | 561 """Replace application profile with files found on host machine. |
602 | 562 |
603 Pushing the profile is slow, so we don't want to do it every time. | 563 Pushing the profile is slow, so we don't want to do it every time. |
604 Avoid this by pushing to a safe location using PushChangedFiles, and | 564 Avoid this by pushing to a safe location using PushChangedFiles, and |
605 then copying into the correct location on each test run. | 565 then copying into the correct location on each test run. |
606 | 566 |
607 Args: | 567 Args: |
608 package: The full package name string of the application for which the | 568 package: The full package name string of the application for which the |
609 profile is to be updated. | 569 profile is to be updated. |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 for process in psutil.process_iter(): | 817 for process in psutil.process_iter(): |
858 try: | 818 try: |
859 if psutil.version_info >= (2, 0): | 819 if psutil.version_info >= (2, 0): |
860 if 'adb' in process.name(): | 820 if 'adb' in process.name(): |
861 process.cpu_affinity([0]) | 821 process.cpu_affinity([0]) |
862 else: | 822 else: |
863 if 'adb' in process.name: | 823 if 'adb' in process.name: |
864 process.set_cpu_affinity([0]) | 824 process.set_cpu_affinity([0]) |
865 except (psutil.NoSuchProcess, psutil.AccessDenied): | 825 except (psutil.NoSuchProcess, psutil.AccessDenied): |
866 logging.warn('Failed to set adb process CPU affinity') | 826 logging.warn('Failed to set adb process CPU affinity') |
OLD | NEW |