blob: ebaba0ab6d8a7324fe225bb03a56b88d2111a867 [file] [log] [blame]
csmartdaltond7a9db62016-09-22 05:10:02 -07001# Copyright 2016 Google Inc.
2#
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6from __future__ import print_function
7from _hardware import Hardware
8import sys
9import time
10
11class HardwareAndroid(Hardware):
12 def __init__(self, adb):
13 Hardware.__init__(self)
csmartdalton5772eaa2016-10-11 18:28:54 -070014 self.warmup_time = 5
csmartdaltond7a9db62016-09-22 05:10:02 -070015 self._adb = adb
csmartdaltone4fd0782016-11-09 08:41:23 -080016
17 if self._adb.root():
csmartdaltond7a9db62016-09-22 05:10:02 -070018 self._adb.remount()
csmartdaltond7a9db62016-09-22 05:10:02 -070019 self._initial_ASLR = \
20 self._adb.check('cat /proc/sys/kernel/randomize_va_space')
csmartdaltone4fd0782016-11-09 08:41:23 -080021
22 def __enter__(self):
23 self._adb.shell('\n'.join([
24 # turn on airplane mode.
25 '''
26 settings put global airplane_mode_on 1''',
27
28 # disable GPS.
29 '''
30 for MODE in gps wifi network; do
31 settings put secure location_providers_allowed -$MODE
32 done''']))
33
34 if self._adb.is_root():
35 self._adb.shell('\n'.join([
36 # disable bluetooth, wifi, and mobile data.
37 '''
38 service call bluetooth_manager 8
39 svc wifi disable
40 svc data disable''',
41
42 # kill the gui.
43 '''
44 setprop ctl.stop media
45 setprop ctl.stop zygote
46 setprop ctl.stop surfaceflinger
47 setprop ctl.stop drm''',
48
49 # disable ASLR
50 '''
51 echo 0 > /proc/sys/kernel/randomize_va_space''']))
csmartdaltond7a9db62016-09-22 05:10:02 -070052 else:
53 print("WARNING: no adb root access; results may be unreliable.",
54 file=sys.stderr)
55
56 return Hardware.__enter__(self)
57
58 def __exit__(self, exception_type, exception_value, traceback):
59 Hardware.__exit__(self, exception_type, exception_value, traceback)
60
csmartdaltone4fd0782016-11-09 08:41:23 -080061 if self._adb.is_root():
62 self._adb.shell('\n'.join([
63 # restore ASLR.
64 '''
65 echo %s > /proc/sys/kernel/randomize_va_space''' % self._initial_ASLR,
csmartdaltond7a9db62016-09-22 05:10:02 -070066
csmartdaltone4fd0782016-11-09 08:41:23 -080067 # revive the gui.
68 '''
69 setprop ctl.start drm
70 setprop ctl.start surfaceflinger
71 setprop ctl.start zygote
72 setprop ctl.start media''']))
csmartdaltond7a9db62016-09-22 05:10:02 -070073
74 def sanity_check(self):
75 Hardware.sanity_check(self)
76
csmartdalton2a961012016-10-11 12:15:13 -070077 def print_debug_diagnostics(self):
78 # search for and print thermal trip points that may have been exceeded.
79 self._adb.shell('''\
80 THERMALDIR=/sys/class/thermal
csmartdalton310d72c2016-10-18 09:19:50 -070081 if [ ! -d $THERMALDIR ]; then
82 exit
83 fi
84 for ZONE in $(cd $THERMALDIR; echo thermal_zone*); do
85 cd $THERMALDIR/$ZONE
86 if [ ! -e mode ] || grep -Fxqv enabled mode || [ ! -e trip_point_0_temp ]; then
87 continue
88 fi
89 TEMP=$(cat temp)
90 TRIPPOINT=trip_point_0_temp
91 if [ $TEMP -le $(cat $TRIPPOINT) ]; then
92 echo "$ZONE ($(cat type)): temp=$TEMP <= $TRIPPOINT=$(cat $TRIPPOINT)" 1>&2
93 else
94 let i=1
95 while [ -e trip_point_${i}_temp ] &&
96 [ $TEMP -gt $(cat trip_point_${i}_temp) ]; do
97 TRIPPOINT=trip_point_${i}_temp
98 let i=i+1
99 done
100 echo "$ZONE ($(cat type)): temp=$TEMP > $TRIPPOINT=$(cat $TRIPPOINT)" 1>&2
101 fi
102 done''')
csmartdalton2a961012016-10-11 12:15:13 -0700103
104 Hardware.print_debug_diagnostics(self)
105
csmartdaltond7a9db62016-09-22 05:10:02 -0700106 def sleep(self, sleeptime):
107 Hardware.sleep(self, sleeptime)