Shell commands for hardware management in Android 6 Marshmallow / Cyanogenmod 13


android-shellIf you are using an automation app like Tasker, Llama or Automate, you can toggle / turn on / turn off WIFI, Data, GPS etc. with shell commands. I collected these little sniplets for my own setup. They work on my device (Nexus 5x with Cyanogenmod 13). They should work on other Android 6 devices as well.

Run all shell commands as root.


svc wifi enable
svc wifi disable



svc data enable
svc data disable



# turn GPS on
settings put secure location_providers_allowed +gps 
# turn GPS off
settings put secure location_providers_allowed -gps 



# Flightmode on
settings put global airplane_mode_on 1
am broadcast -a android.intent.action.AIRPLANE_MODE

# Flightmode off
settings put global airplane_mode_on 0
am broadcast -a android.intent.action.AIRPLANE_MODE


Turn off screen without locking device (emulate power button keypress)

input keyevent 26


Toggle Network mode (2G/3G/4G)
I have been searching for a long time, but there seems to be no direct way to do this.
The best solution I have found requires xposed framework and gravitybox installed.

I found the available network types here:

Identify the right settings for your device:

# Disable your automation app, set networking mode with the preferences in your devices GUI.
# Then run

settings get global preferred_network_mode 

# The currently set network mode number will be shown in shell

Just send the following intent to toggle network mode:

Send Intent [
Action: gravitybox.intent.action.CHANGE_NETWORK_TYPE
Cat: None
Mime Type:
Extra: networkType:1
Target: Broadcast Receiver]

networkType enum values are: 
0: WCDMA Preferred 
1: GSM only <-- This would be "2G" on GSM networks
2: WCDMA only <--WCDMA is "3G" on GSM networks. You may know it as HSPA
3: GSM auto (PRL)
4: CDMA auto (PRL)
5: CDMA only <-- This would be "2G" on CDMA networks
6: EvDo only <-- EvDo is "3G" on CDMA networks
7: GSM/CDMA auto (PRL)
8: LTE/CDMA auto (PRL)
9: LTE/GSM auto (PRL)
10: LTE/GSM/CDMA auto (PRL)
11: LTE only
12: "unknown"


Disable captive portal detection
This needs to be set at boottime. It doesn’t survive a reboot.

settings put global captive_portal_detection_enabled 0
settings put global captive_portal_server


Force a DNS of your choice
Google removed the option to change the DNS for mobile data. (ugly, ugly, ugly)
You can force your device to use your fav DNS with iptables for mobile data:

/system/bin/iptables -t nat -A OUTPUT ! -o wlan0 -p udp --dport 53 -j DNAT --to-destination

In case you have found a better way to switch network mode, I’d really appreciate your comment :)

2 Kommentare zu “Shell commands for hardware management in Android 6 Marshmallow / Cyanogenmod 13

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Nach oben