From 3e751746d6c07a1643cdfb7f383dbc4a17765d88 Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Thu, 6 Jul 2017 17:31:02 +0100 Subject: [PATCH] AndroidTarget: Adds methods to get/set airplane mode In order to change the state of airplane mode, the setting needs to be configured before broadcasting an intent to update the system. As of Android N, root is required to send the broadcast, therefore this method will raise an error if the requirements are not satisfied. --- devlib/target.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/devlib/target.py b/devlib/target.py index af49989..925f770 100644 --- a/devlib/target.py +++ b/devlib/target.py @@ -1206,6 +1206,18 @@ class AndroidTarget(Target): cmd = 'settings get system screen_brightness' return integer(self.execute(cmd).strip()) + def get_airplane_mode(self): + cmd = 'settings get global airplane_mode_on' + return boolean(self.execute(cmd).strip()) + + def set_airplane_mode(self, mode): + root_required = self.get_sdk_version() > 23 + if root_required and not self.is_rooted: + raise TargetError('Root is required to toggle airplane mode on Android 7+') + cmd = 'settings put global airplane_mode_on {}' + self.execute(cmd.format(int(boolean(mode)))) + self.execute('am broadcast -a android.intent.action.AIRPLANE_MODE', as_root=root_required) + def homescreen(self): self.execute('am start -a android.intent.action.MAIN -c android.intent.category.HOME')