androidbluetoothairplane-mode

Android: does flight mode turn off radio completely or just transmission portion?


I have an Android application that uses both ble and wifi. Periodically ble locks up and no longer detects devices. while fault-finding the lock up, I noticed that I can reestablish normal operation by switching flight/airplane mode on an off. BUT if I turn bluetooth on/off or wifi on/off, or both wifi and bluetooth on/off, I cannot replicate the results I get by turning flight mode on/off. This tells me that flight mode is doing something different. So:

what is the difference between flight mode and the separate functions for turning bluetooth and/or wifi on and off?


Solution

  • What we know

    Airplane mode disables all radios, cellular, bluetooth, GPS, NFC, wimax, and any other radios declared in Settings.Global.AIRPLANE_MODE_RADIOS you can check the list in your particular device by executing adb shell settings get global airplane_mode_radios.

    What we don't know

    As to why it's different from simply disabling a certain radios by itself, I also experienced something similar with WIFI not connecting anymore and working once again after ON/OFF of airplane mode.

    You can follow the source code of what APM does but in the end it broadcasts as user the intent Intent.ACTION_AIRPLANE_MODE_CHANGED and this intent is handled by all the broadcast receivers of the radios individually. How they handle this differently from a simple toggle of the radios in settings makes the difference between it coming back to life or not.

    Digging deeper

    For example, in the BluetoothManagerService, when we enable Airplane mode, we trigger status 2 for the radio, instead of 0 which would be disabled. So there clearly is a differentiation between disabled and airplane mode disabled, this is interesting.

    // Bluetooth persisted setting is off
    private static final int BLUETOOTH_OFF=0;
    // Bluetooth persisted setting is on
    // and Airplane mode won't affect Bluetooth state at start up
    private static final int BLUETOOTH_ON_BLUETOOTH=1;
    // Bluetooth persisted setting is on
    // but Airplane mode will affect Bluetooth state at start up
    // and Airplane mode will have higher priority.
    private static final int BLUETOOTH_ON_AIRPLANE=2;
    

    As you can see, in the very source code of the Manager, it's noted that the Airplane mode will affect the startup. So perhaps this is what you're after. When we enable the radio after airplane mode, this is the code that's run:

    sendEnableMsg(mQuietEnableExternal);
    

    However, simply enabling the radio runs this one: sendEnableMsg(false);

    Conclussion

    Maybe it has something to do with the quiet mode? It's rather fascinating, and I'm sorry I can't provide a better answer but hopefully it's a good starting point if you care to dig even deeper.