2016-09-22 12:10:02 +00:00
|
|
|
# Copyright 2016 Google Inc.
|
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
from _hardware import Hardware
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
class HardwareAndroid(Hardware):
|
|
|
|
def __init__(self, adb):
|
|
|
|
Hardware.__init__(self)
|
2016-10-12 01:28:54 +00:00
|
|
|
self.warmup_time = 5
|
2016-09-22 12:10:02 +00:00
|
|
|
self._adb = adb
|
2016-11-09 16:41:23 +00:00
|
|
|
|
|
|
|
if self._adb.root():
|
2016-09-22 12:10:02 +00:00
|
|
|
self._adb.remount()
|
|
|
|
|
|
|
|
def __enter__(self):
|
2017-10-20 15:58:32 +00:00
|
|
|
Hardware.__enter__(self)
|
|
|
|
if not self._adb.is_root() and self._adb.root():
|
|
|
|
self._adb.remount()
|
|
|
|
|
2016-11-09 16:41:23 +00:00
|
|
|
self._adb.shell('\n'.join([
|
|
|
|
# turn on airplane mode.
|
|
|
|
'''
|
|
|
|
settings put global airplane_mode_on 1''',
|
2016-09-22 12:10:02 +00:00
|
|
|
|
2016-11-09 16:41:23 +00:00
|
|
|
# disable GPS.
|
|
|
|
'''
|
|
|
|
for MODE in gps wifi network; do
|
|
|
|
settings put secure location_providers_allowed -$MODE
|
|
|
|
done''']))
|
2016-09-22 12:10:02 +00:00
|
|
|
|
2016-11-09 16:41:23 +00:00
|
|
|
if self._adb.is_root():
|
|
|
|
self._adb.shell('\n'.join([
|
|
|
|
# disable bluetooth, wifi, and mobile data.
|
|
|
|
'''
|
|
|
|
service call bluetooth_manager 8
|
|
|
|
svc wifi disable
|
|
|
|
svc data disable''',
|
2016-09-22 12:10:02 +00:00
|
|
|
|
2016-11-09 16:41:23 +00:00
|
|
|
# kill the gui.
|
|
|
|
'''
|
|
|
|
setprop ctl.stop media
|
|
|
|
setprop ctl.stop zygote
|
|
|
|
setprop ctl.stop surfaceflinger
|
|
|
|
setprop ctl.stop drm''',
|
2016-09-22 12:10:02 +00:00
|
|
|
|
2016-11-09 16:41:23 +00:00
|
|
|
# disable ASLR
|
|
|
|
'''
|
|
|
|
echo 0 > /proc/sys/kernel/randomize_va_space''']))
|
2016-09-22 12:10:02 +00:00
|
|
|
else:
|
|
|
|
print("WARNING: no adb root access; results may be unreliable.",
|
|
|
|
file=sys.stderr)
|
|
|
|
|
2017-10-20 15:58:32 +00:00
|
|
|
return self
|
2016-09-22 12:10:02 +00:00
|
|
|
|
|
|
|
def __exit__(self, exception_type, exception_value, traceback):
|
|
|
|
Hardware.__exit__(self, exception_type, exception_value, traceback)
|
2017-10-23 23:19:37 +00:00
|
|
|
self._adb.reboot() # some devices struggle waking up; just hard reboot.
|
2016-09-22 12:10:02 +00:00
|
|
|
|
|
|
|
def sanity_check(self):
|
|
|
|
Hardware.sanity_check(self)
|
|
|
|
|
2016-10-11 19:15:13 +00:00
|
|
|
def print_debug_diagnostics(self):
|
|
|
|
# search for and print thermal trip points that may have been exceeded.
|
|
|
|
self._adb.shell('''\
|
|
|
|
THERMALDIR=/sys/class/thermal
|
2016-10-18 16:19:50 +00:00
|
|
|
if [ ! -d $THERMALDIR ]; then
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
for ZONE in $(cd $THERMALDIR; echo thermal_zone*); do
|
|
|
|
cd $THERMALDIR/$ZONE
|
|
|
|
if [ ! -e mode ] || grep -Fxqv enabled mode || [ ! -e trip_point_0_temp ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
TEMP=$(cat temp)
|
|
|
|
TRIPPOINT=trip_point_0_temp
|
|
|
|
if [ $TEMP -le $(cat $TRIPPOINT) ]; then
|
|
|
|
echo "$ZONE ($(cat type)): temp=$TEMP <= $TRIPPOINT=$(cat $TRIPPOINT)" 1>&2
|
|
|
|
else
|
|
|
|
let i=1
|
|
|
|
while [ -e trip_point_${i}_temp ] &&
|
|
|
|
[ $TEMP -gt $(cat trip_point_${i}_temp) ]; do
|
|
|
|
TRIPPOINT=trip_point_${i}_temp
|
|
|
|
let i=i+1
|
|
|
|
done
|
|
|
|
echo "$ZONE ($(cat type)): temp=$TEMP > $TRIPPOINT=$(cat $TRIPPOINT)" 1>&2
|
|
|
|
fi
|
|
|
|
done''')
|
2016-10-11 19:15:13 +00:00
|
|
|
|
|
|
|
Hardware.print_debug_diagnostics(self)
|