1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
7 from telemetry
.internal
.platform
import power_monitor
10 from devil
.android
import device_errors
# pylint: disable=import-error
15 _TEMPERATURE_FILE
= '/sys/class/thermal/thermal_zone0/temp'
18 class AndroidTemperatureMonitor(power_monitor
.PowerMonitor
):
20 Returns temperature results in power monitor dictionary format.
22 def __init__(self
, device
):
23 super(AndroidTemperatureMonitor
, self
).__init
__()
26 def CanMonitorPower(self
):
27 return self
._GetBoardTemperatureCelsius
() is not None
29 def StartMonitoringPower(self
, browser
):
30 # don't call _CheckStart() because this is temperature, not power
31 # therefore, StartMonitoringPower and StopMonitoringPower
32 # do not need to be paired
35 def StopMonitoringPower(self
):
36 avg_temp
= self
._GetBoardTemperatureCelsius
()
38 return {'identifier': 'android_temperature_monitor'}
40 return {'identifier': 'android_temperature_monitor',
41 'platform_info': {'average_temperature_c': avg_temp
}}
43 def _GetBoardTemperatureCelsius(self
):
45 contents
= self
._device
.ReadFile(_TEMPERATURE_FILE
)
46 return float(contents
) if contents
else None
48 logging
.warning('String returned from device.ReadFile(_TEMPERATURE_FILE) '
51 except device_errors
.CommandFailedError
: