1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 10:10:46 +00:00

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.
This commit is contained in:
Marc Bonnici 2017-07-06 17:31:02 +01:00
parent ddd2e29b87
commit 3e751746d6

View File

@ -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')