Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / platform / android_platform_backend.py
index 64c8f64..a1d4623 100644 (file)
@@ -6,11 +6,15 @@ import logging
 import subprocess
 import tempfile
 
+from telemetry import decorators
 from telemetry.core import bitmap
 from telemetry.core import exceptions
 from telemetry.core import platform
 from telemetry.core import util
 from telemetry.core.platform import proc_supporting_platform_backend
+from telemetry.core.platform.power_monitor import android_ds2784_power_monitor
+from telemetry.core.platform.power_monitor import monsoon_power_monitor
+from telemetry.core.platform.power_monitor import power_monitor_controller
 from telemetry.core.platform.profiler import android_prebuilt_profiler_helper
 
 # Get build/android scripts into our path.
@@ -45,6 +49,10 @@ class AndroidPlatformBackend(
     self._host_platform_backend = platform.CreatePlatformBackendForCurrentOS()
     self._can_access_protected_file_contents = \
         self._adb.CanAccessProtectedFileContents()
+    self._powermonitor = power_monitor_controller.PowerMonitorController([
+        monsoon_power_monitor.MonsoonPowerMonitor(),
+        android_ds2784_power_monitor.DS2784PowerMonitor(adb)
+    ])
     self._video_recorder = None
     self._video_output = None
     if self._no_performance_mode:
@@ -98,6 +106,13 @@ class AndroidPlatformBackend(
         return int(line.split()[2]) * 1024
     return 0
 
+  @decorators.Cache
+  def GetSystemTotalPhysicalMemory(self):
+    for line in self._adb.RunShellCommand('dumpsys meminfo', log_result=False):
+      if line.startswith('Total RAM: '):
+        return int(line.split()[2]) * 1024
+    return 0
+
   def GetCpuStats(self, pid):
     if not self._can_access_protected_file_contents:
       logging.warning('CPU stats cannot be retrieved on non-rooted device.')
@@ -154,6 +169,7 @@ class AndroidPlatformBackend(
   def GetOSName(self):
     return 'android'
 
+  @decorators.Cache
   def GetOSVersionName(self):
     return self._adb.GetBuildId()[0]
 
@@ -167,10 +183,14 @@ class AndroidPlatformBackend(
   def FlushSystemCacheForDirectory(self, directory, ignoring=None):
     raise NotImplementedError()
 
-  def LaunchApplication(self, application, parameters=None):
+  def LaunchApplication(
+      self, application, parameters=None, elevate_privilege=False):
     if application in _HOST_APPLICATIONS:
-      self._host_platform_backend.LaunchApplication(application, parameters)
+      self._host_platform_backend.LaunchApplication(
+          application, parameters, elevate_privilege=elevate_privilege)
       return
+    if elevate_privilege:
+      raise NotImplementedError("elevate_privilege isn't supported on android.")
     if not parameters:
       parameters = ''
     self._adb.RunShellCommand('am start ' + parameters + ' ' + application)
@@ -192,6 +212,7 @@ class AndroidPlatformBackend(
     raise NotImplementedError(
         'Please teach Telemetry how to install ' + application)
 
+  @decorators.Cache
   def CanCaptureVideo(self):
     return self.GetOSVersionName() >= 'K'
 
@@ -216,6 +237,15 @@ class AndroidPlatformBackend(
     for frame in self._FramesFromMp4(self._video_output):
       yield frame
 
+  def CanMonitorPowerAsync(self):
+    return self._powermonitor.CanMonitorPowerAsync()
+
+  def StartMonitoringPowerAsync(self):
+    self._powermonitor.StartMonitoringPowerAsync()
+
+  def StopMonitoringPowerAsync(self):
+    return self._powermonitor.StopMonitoringPowerAsync()
+
   def _FramesFromMp4(self, mp4_file):
     if not self.CanLaunchApplication('avconv'):
       self.InstallApplication('avconv')