Index: tools/skpbench/_hardware_android.py |
diff --git a/tools/skpbench/_hardware_android.py b/tools/skpbench/_hardware_android.py |
index 68c8522e3e9e2e005f767c0961d09ff1f6a3ce14..ebaba0ab6d8a7324fe225bb03a56b88d2111a867 100644 |
--- a/tools/skpbench/_hardware_android.py |
+++ b/tools/skpbench/_hardware_android.py |
@@ -13,48 +13,42 @@ class HardwareAndroid(Hardware): |
Hardware.__init__(self) |
self.warmup_time = 5 |
self._adb = adb |
- self._is_root = self._adb.attempt_root() |
- if self._is_root: |
- self._adb.remount() |
- self._initial_airplane_mode = None |
- self._initial_location_providers = None |
- self._initial_ASLR = None |
- def __enter__(self): |
- # turn on airplane mode. |
- self._initial_airplane_mode = \ |
- self._adb.check('settings get global airplane_mode_on') |
- self._adb.shell('settings put global airplane_mode_on 1') |
- |
- # disable GPS. |
- self._initial_location_providers = \ |
- self._adb.check('settings get secure location_providers_allowed') |
- self._initial_location_providers = \ |
- self._initial_location_providers.replace(',', ' ') |
- self._adb.shell('''\ |
- for PROVIDER in %s; do |
- settings put secure location_providers_allowed -$PROVIDER |
- done''' % self._initial_location_providers) |
- |
- if self._is_root: |
- # disable bluetooth, wifi, and mobile data. |
- # TODO: can we query these initial values? |
- self._adb.shell('''\ |
- service call bluetooth_manager 8 && |
- svc wifi disable && |
- svc data disable''') |
- |
- # kill the gui. |
- self._adb.shell('''\ |
- setprop ctl.stop media && |
- setprop ctl.stop zygote && |
- setprop ctl.stop surfaceflinger && |
- setprop ctl.stop drm''') |
- |
- # disable ASLR. |
+ if self._adb.root(): |
+ self._adb.remount() |
self._initial_ASLR = \ |
self._adb.check('cat /proc/sys/kernel/randomize_va_space') |
- self._adb.shell('echo 0 > /proc/sys/kernel/randomize_va_space') |
+ |
+ def __enter__(self): |
+ self._adb.shell('\n'.join([ |
+ # turn on airplane mode. |
+ ''' |
+ settings put global airplane_mode_on 1''', |
+ |
+ # disable GPS. |
+ ''' |
+ for MODE in gps wifi network; do |
+ settings put secure location_providers_allowed -$MODE |
+ done'''])) |
+ |
+ 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''', |
+ |
+ # kill the gui. |
+ ''' |
+ setprop ctl.stop media |
+ setprop ctl.stop zygote |
+ setprop ctl.stop surfaceflinger |
+ setprop ctl.stop drm''', |
+ |
+ # disable ASLR |
+ ''' |
+ echo 0 > /proc/sys/kernel/randomize_va_space'''])) |
else: |
print("WARNING: no adb root access; results may be unreliable.", |
file=sys.stderr) |
@@ -64,27 +58,18 @@ class HardwareAndroid(Hardware): |
def __exit__(self, exception_type, exception_value, traceback): |
Hardware.__exit__(self, exception_type, exception_value, traceback) |
- if self._is_root: |
- # restore ASLR. |
- self._adb.shell('echo %s > /proc/sys/kernel/randomize_va_space' % |
- self._initial_ASLR) |
- |
- # revive the gui. |
- self._adb.shell('''\ |
- setprop ctl.start drm && |
- setprop ctl.start surfaceflinger && |
- setprop ctl.start zygote && |
- setprop ctl.start media''') |
- else: |
- # restore GPS (doesn't seem to work if we killed the gui). |
- self._adb.shell('''\ |
- for PROVIDER in %s; do |
- settings put secure location_providers_allowed +$PROVIDER |
- done''' % self._initial_location_providers) |
- |
- # restore airplane mode (doesn't seem to work if we killed the gui). |
- self._adb.shell('settings put global airplane_mode_on %s' % |
- self._initial_airplane_mode) |
+ if self._adb.is_root(): |
+ self._adb.shell('\n'.join([ |
+ # restore ASLR. |
+ ''' |
+ echo %s > /proc/sys/kernel/randomize_va_space''' % self._initial_ASLR, |
+ |
+ # revive the gui. |
+ ''' |
+ setprop ctl.start drm |
+ setprop ctl.start surfaceflinger |
+ setprop ctl.start zygote |
+ setprop ctl.start media'''])) |
def sanity_check(self): |
Hardware.sanity_check(self) |