I have an android phone on which I want to programatically toggle airplane mode.
I've been unable to root this device, which has prevented any apps I'm running from having permission to edit these settings, so am using adb to open the settings menu and toggle the switch there.
Executing the following adb shell commands will work in some cases:
//Get airplane mode settings menu
adb -s ${device} shell am start -a android.settings.AIRPLANE_MODE_SETTINGS
//Hit enter (as many times as required)
adb -s ${device} shell input keyevent KEYCODE_ENTER
//Check the state of airplane mode to determine when successful
adb -s ${device} shell settings get global airplane_mode_on
However, this only work if the menu containing the airplane mode switch is the first menu option listed on the settings page, since "android.settings.AIRPLANE_MODE_SETTINGS" will only navigate to the menu where the setting is found. It will not perform any focussing on the setting itself, so the following command to hit enter will press the wrong setting.
If using this approach, is there a way to identify/focus only the airplane toggle switch, or otherwise check which menu item is in focus so the items can be iterated until the correct one is found?
Additionally, it would be great if there was a way to execute these adb commands without requiring the phone to be plugged into a PC - i.e. can the adb client be run on the phone itself (and then trick itself into thinking it is a connected device).
And finally - the end goal here is simply to toggle airplane mode programatically on demand (ultimately the request will be triggered by a node.js process running in termux app). If there is a better way to achieve this without using adb that doesn't require root permissions, this would also work.
You can try to execute those new commands (without requiring root permissions):
If you want to enable the airplane mode:
adb shell cmd connectivity airplane-mode enable
If you want to disable the airplane mode:
adb shell cmd connectivity airplane-mode disable
If you want to know if the airplane mode is enabled or disabled:
adb shell cmd connectivity airplane-mode