Reputation: 35
I want to Enable and Disable Airplane Mode on my device which is not rooted.
To enable the Airplane mode i use the following commands:
adb shell settings put global airplane_mode_on 1 adb shell am broadcast -a android.intent.action.AIRPLANE_MODE
To disable the Airplane mode i use the following command:
adb shell settings put global airplane_mode_on 0 adb shell am broadcast -a android.intent.action.AIRPLANE_MODE
This commands work well for android <7.0 but for android version >=7.0 i get the following error:
ZX1G523ZW6 : Enabling airplane mode...
Broadcasting: Intent { act=android.intent.action.AIRPLANE_MODE (has extras) }
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.AIRPLANE_MODE from pid=8824, uid=2000
at android.os.Parcel.readException(Parcel.java:1684)
at android.os.Parcel.readException(Parcel.java:1637)
at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:3537)
at com.android.commands.am.Am.sendBroadcast(Am.java:772)
at com.android.commands.am.Am.onRun(Am.java:404)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:51)
at com.android.commands.am.Am.main(Am.java:121)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:262)
Is there a solution to this for Android version >=7.0 without a rooted device? Thank you in advance.
Upvotes: 1
Views: 3949
Reputation: 44861
As you can see here,
android.intent.action.AIRPLANE_MODE
is a protected broadcast.
Before Android 7.0 there was a security problem regarding the protected broadcasts which enabled normal users to call those inside application code or using adb interface.
Starting with Android 7.0 this security flaws have been fixed and now if you want to continue with the same behaviour you need a rooted device or a device with Android < 7.0.
Upvotes: 0