From 7bd99637c17fc5bee4a1cd5a0c292164e96e4da8 Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Thu, 14 Dec 2017 17:25:48 +0000 Subject: [PATCH] Target/AndroidAssistant: Try to disable selinux If the target is rooted, attempt to disable selinux as this can cause issues during runtime. --- wa/framework/target/assistant.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/wa/framework/target/assistant.py b/wa/framework/target/assistant.py index 6d472fd1..f23a08b7 100644 --- a/wa/framework/target/assistant.py +++ b/wa/framework/target/assistant.py @@ -49,6 +49,8 @@ class AndroidAssistant(object): def __init__(self, target, logcat_poll_period=None): self.target = target + if self.target.is_rooted: + self.disable_selinux() if logcat_poll_period: self.logcat_poller = LogcatPoller(target, logcat_poll_period) else: @@ -78,6 +80,14 @@ class AndroidAssistant(object): if self.logcat_poller: self.logcat_poller.clear_buffer() + def disable_selinux(self): + # SELinux was added in Android 4.3 (API level 18). Trying to + # 'getenforce' in earlier versions will produce an error. + if self.target.get_sdk_version() >= 18: + se_status = self.target.execute('getenforce', as_root=True).strip() + if se_status == 'Enforcing': + self.target.execute('setenforce 0', as_root=True, check_exit_code=False) + class LogcatPoller(threading.Thread):