How to disable airplane mode switch when phone is locked When I display the quick settings panel, there are shortcuts to enable some functions (wifi, data connection ...)

When my phone is locked (pin code), the location switch disappears, (for security reasons AFAIK).

But the airplane mode switch is ever displayed, so a thiefer could easily enable it, and disable location by the same.

Is there a way to disable the airplane mode switch when my phone is locked ?

Locked : 



Unlocked :
Note: 


The following solution is tested on COS12 (Android 5.0.2) and Carbon ROM (Android 5.1.1).
For this answer, you would need ADB setup in your machine, USB debugging enabled in the device and connected to PC.  Alternatively, for rooted devices,  terminal app like  Terminal Emulator for Android can be used.
Root access is required (see exception at the bottom).




The tiles that you can toggle in the Quick Settings are assigned particular names and are stored as a value for the key sysui_qs_tiles under the table secure (both key and the table may differ for your ROM) of settings.db (Settings Storage app).

Note:


When using a terminal emulator app, enter su and then follow the commands without the prefix adb shell.
For each stage, two commands are mentioned. Both are alternatives to each other here. 
For the usage of settings and content, enter adb shell settings and adb shell content respectively 


To find out the value stored in the key sysui_qs_tiles, enter the command

adb shell settings get secure sysui_qs_tiles
adb shell content --query content://settings/secure --where "name='systeui_qs_tiles'"


The output would be like:

wifi,bt,cell,rotation,flashlight,hotspot,location,airplane


airplane is for Airplane mode. If you remove it from the value, the quick tile would instantaneously vanish. 

Example,

adb shell settings put secure sysui_qs_tiles "wifi,bt,cell,rotation,flashlight,hotspot,location"
adb shell content update --url content://settings/secure value:s:"wifi,bt,cell,rotation,flashlight,hotspot,location" --where "name='sysui_qs_tiles'"


It must be noted that you should not use the aforesaid value but only the one which you got from your query. 

As for hiding/removing the Airplane mode on the lock-screen and adding it back when the screen is unlocked you can use an automation tool, such as Tasker or MacroDroid.

Instructions for Tasker


Create a task named "Screen unlocked".
Add an action as Code &rarr; Run Shell, and add these details:


Command: 

settings put secure sysui_qs_tiles "wifi,bt,cell,rotation,flashlight,hotspot,location,airplane"

Use the key-value relevant for your device. Also, as an alternative, you can use the content command, if you would like to. This info remains valid for further instructions as well.
Check Use Root 

Create an another task named "Screen locked".
Note: If you configured lock-screen settings so that the screen doesn't lock right after the device gets to sleep, but after XY seconds (such as, 30 seconds), then create an action as Task &rarr; Wait and set those XY Seconds. Alternatively, sleep XY command can also be used.
Add an action as Code &rarr; Run Shell, and add these details:


Command: 

settings put secure sysui_qs_tiles "wifi,bt,cell,rotation,flashlight,hotspot,location"
Check Use Root 

Create a profile named "S-unlocked" under Event &rarr; Display &rarr; Display Unlocked, choose Highest Priority, and link the task "Screen unlocked". 
Create an another profile named "S-locked" under Event &rarr; Display &rarr; Display Off, choose Highest Priority, and link the task "Screen locked".
Have the Tasker enabled and behold the desired action by locking/unlocking the screen. 




Should you decide to use MacroDroid, install Secure Settings too because it is needed to run commands in MacroDroid's actions.

Relevant triggers in MacroDroid:


Screen On/Off &rarr; Screen Off
Screen Unlocked


Relevant actions in MacroDroid:


Secure Settings &rarr; Actions &rarr; Run Command


Use the commands learned in this solution. Follow instructions for Tasker for any guidance

Wait Before Next Action




Screenshots

Order of images as "All tiles available when screen is unlocked" &rarr;  "No Airplane tile when screen is locked"

(Click image to enlarge)






It is possible to use this solution without root access. You would need ADB running in wireless and loopback mode for that. It is not very convenient, however, it does work. For any guidance, see my answer for Lollipop hide quick settings on Lock screen.