Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the behavior of Android's airplane mode so that it will not turn off the cellular radio?

I have been trying to create a simple application that will let the user customize the behavior of airplane mode in Android. The motivation for this is from a relative who has a Samsung Fascinate, and during calls he will accidentally turn on airplane mode. This happens when he holds the phone, accidentally holds down the side power/lock button, which opens a dialog with a menu for “Silent Mode”, “Airplane Mode”, and “Power Off”. He accidentally triggers airplane mode by a touch of the phone to his cheek. This drops the call and is an annoyance to him.

Ultimately, I would like to create an app that prevents the cellular radio from being turned off while the user is in the middle of a call. But, for a first iteration I thought it made sense to let the user manually choose which radios would not get turned off by airplane mode.

I am not looking to modify the Android source code or do something that would require rooting. I am looking for a solution within the standard framework

My first attempt to solve this was to create an application that would modify System.AIRPLANE_MODE_RADIOS like so:

System.putString(getApplication().getContentResolver(), System.AIRPLANE_MODE_RADIOS, "");

According to the API docs, this constant is "A comma separated list of radios that need to be disabled when airplane mode is on". It seems that airplane mode does not actually use this constant, and it continues to work as normal after the change is made.

My next attempt was to create a BroadCastReceiver, receive the AIRPLANE_MODE action, and send out an Intent to reverse it:

Intent am = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", 0);
context.sendBroadcast(am);

This does turn off airplane mode after it has been activated. However, if the user was in the middle of a call, it will still be dropped (which makes sense). So, this is not quite the solution to my problem.

Does anyone know how to prevent airplane mode from disabling the cellular radio?

like image 605
Eric Levine Avatar asked Feb 26 '23 17:02

Eric Levine


2 Answers

As far as i know you wont be able to do this since the option itself(airplane mode) would be of no use if 3rd party applications are able to access towers with airplane mode enabled on the device.

like image 76
DeRagan Avatar answered Apr 07 '23 18:04

DeRagan


The source of PhoneApp.java

https://android.googlesource.com/platform/packages/apps/Phone/+/gingerbread-release/src/com/android/phone/PhoneApp.java

Makes it clear why this will not work.

In contrast to the wifi and bluetooth implementations which register a receiver for Intent.ACTION_AIRPLANE_MODE_CHANGED only when on the list of airplane mode radios, PhoneApp does it all the time:

IntentFilter intentFilter =
new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);

And then unconditionally acts on it:

if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
    boolean enabled = System.getInt(getContentResolver(),
            System.AIRPLANE_MODE_ON, 0) == 0;
    phone.setRadioPower(enabled);
}

Given the purpose of airplane mode, I'm sure this is an intentional feature and not a bug.

like image 42
Chris Stratton Avatar answered Apr 07 '23 17:04

Chris Stratton