Chromium Code Reviews| Index: appengine/swarming/swarming_bot/api/platforms/android.py |
| diff --git a/appengine/swarming/swarming_bot/api/platforms/android.py b/appengine/swarming/swarming_bot/api/platforms/android.py |
| index b95434c4b2cb5eeba4a87a022f52a85e2c50c066..570d23126c091efa43c4d6c94a4817ad36310f97 100644 |
| --- a/appengine/swarming/swarming_bot/api/platforms/android.py |
| +++ b/appengine/swarming/swarming_bot/api/platforms/android.py |
| @@ -15,8 +15,8 @@ import subprocess |
| import sys |
| import time |
| -# This file must be imported from swarming_bot.zip (or with '..' in sys.path). |
| -# libusb1 must have been put in the path already. |
| +# This file must be imported from swarming_bot.zip (or with '../..' in |
| +# sys.path). libusb1 must have been put in the path already. |
| import adb |
| import adb.adb_commands |
| @@ -456,6 +456,7 @@ def get_build_prop(device): |
| def get_temp(device): |
| """Returns the device's 2 temperatures if available.""" |
| + assert isinstance(device, Device), device |
| # Not all devices export this file. On other devices, the only real way to |
| # read it is via Java |
| # developer.android.com/guide/topics/sensors/sensors_environment.html |
| @@ -463,12 +464,16 @@ def get_temp(device): |
| for i in xrange(2): |
| out, _ = device.shell('cat /sys/class/thermal/thermal_zone%d/temp' % i) |
| if out: |
| - temps.append(int(out)) |
| + try: |
| + temps.append(int(out)) |
| + except ValueError: |
| + pass |
|
ghost stip (do not use)
2015/10/13 21:03:40
should we append a NaN instead? otherwise people w
M-A Ruel
2015/10/13 21:08:57
I prefer to not add invalid values; in this case t
ghost stip (do not use)
2015/10/13 21:21:08
you're doing for i in xrange(2):
so if the first
M-A Ruel
2015/10/13 21:22:52
It is ok; the first sensor is on the CPU, the seco
|
| return temps |
| def get_battery(device): |
| """Returns details about the battery's state.""" |
| + assert isinstance(device, Device), device |
| props = {} |
| out = _dumpsys(device, 'battery') |
| if not out: |
| @@ -477,12 +482,14 @@ def get_battery(device): |
| if line.endswith(u':'): |
| continue |
| # On Android 4.1.2, it uses "voltage:123" instead of "voltage: 123". |
| - key, value = line.split(u':', 2) |
| - props[key.lstrip()] = value.strip() |
| + parts = line.split(u':', 2) |
| + if len(parts) == 2: |
| + key, value = parts |
| + props[key.lstrip()] = value.strip() |
| out = {u'power': []} |
| - if props[u'AC powered'] == u'true': |
| + if props.get(u'AC powered') == u'true': |
| out[u'power'].append(u'AC') |
| - if props[u'USB powered'] == u'true': |
| + if props.get(u'USB powered') == u'true': |
| out[u'power'].append(u'USB') |
| if props.get(u'Wireless powered') == u'true': |
| out[u'power'].append(u'Wireless') |
| @@ -493,6 +500,7 @@ def get_battery(device): |
| def get_cpu_scale(device): |
| """Returns the CPU scaling factor.""" |
| + assert isinstance(device, Device), device |
| mapping = { |
| 'cpuinfo_max_freq': u'max', |
| 'cpuinfo_min_freq': u'min', |
| @@ -507,6 +515,7 @@ def get_cpu_scale(device): |
| def get_uptime(device): |
| """Returns the device's uptime in second.""" |
| + assert isinstance(device, Device), device |
| out, _ = device.shell('cat /proc/uptime') |
| if out: |
| return float(out.split()[1]) |
| @@ -515,6 +524,7 @@ def get_uptime(device): |
| def get_disk(device): |
| """Returns details about the battery's state.""" |
| + assert isinstance(device, Device), device |
| props = {} |
| out = _dumpsys(device, 'diskstats') |
| if not out: |
| @@ -522,13 +532,15 @@ def get_disk(device): |
| for line in out.splitlines(): |
| if line.endswith(u':'): |
| continue |
| - key, value = line.split(u': ', 2) |
| - match = re.match(u'^(\d+)K / (\d+)K.*', value) |
| - if match: |
| - props[key.lstrip()] = { |
| - 'free_mb': round(float(match.group(1)) / 1024., 1), |
| - 'size_mb': round(float(match.group(2)) / 1024., 1), |
| - } |
| + parts = line.split(u': ', 2) |
| + if len(parts) == 2: |
| + key, value = parts |
| + match = re.match(u'^(\d+)K / (\d+)K.*', value) |
| + if match: |
| + props[key.lstrip()] = { |
| + 'free_mb': round(float(match.group(1)) / 1024., 1), |
| + 'size_mb': round(float(match.group(2)) / 1024., 1), |
| + } |
| return { |
| u'cache': props[u'Cache-Free'], |
| u'data': props[u'Data-Free'], |
| @@ -538,6 +550,7 @@ def get_disk(device): |
| def get_imei(device): |
| """Returns the phone's IMEI.""" |
| + assert isinstance(device, Device), device |
| # Android <5.0. |
| out = _dumpsys(device, 'iphonesubinfo') |
| if out: |
| @@ -558,6 +571,7 @@ def get_imei(device): |
| def get_ip(device): |
| """Returns the IP address.""" |
| + assert isinstance(device, Device), device |
| # If ever needed, read wifi.interface from /system/build.prop if a device |
| # doesn't use wlan0. |
| ip, _ = device.shell('getprop dhcp.wlan0.ipaddress') |