{"id":1689,"date":"2016-11-28T10:35:15","date_gmt":"2016-11-28T09:35:15","guid":{"rendered":"http:\/\/www.daniel-ritter.de\/blog\/?p=1689"},"modified":"2024-05-13T01:09:49","modified_gmt":"2024-05-12T23:09:49","slug":"shell-commands-for-hardware-management-in-android-6-marshmallow-cyanogenmod-13","status":"publish","type":"post","link":"https:\/\/www.daniel-ritter.de\/blog\/shell-commands-for-hardware-management-in-android-6-marshmallow-cyanogenmod-13\/","title":{"rendered":"Shell commands for hardware management in Android 6 Marshmallow \/ Cyanogenmod 13"},"content":{"rendered":"<p><a href=\"https:\/\/www.daniel-ritter.de\/blog\/wp-content\/uploads\/2016\/11\/android-shell.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-1707\" src=\"https:\/\/www.daniel-ritter.de\/blog\/wp-content\/uploads\/2016\/11\/android-shell.jpg\" alt=\"android-shell\" width=\"865\" height=\"517\" srcset=\"https:\/\/www.daniel-ritter.de\/blog\/wp-content\/uploads\/2016\/11\/android-shell.jpg 865w, https:\/\/www.daniel-ritter.de\/blog\/wp-content\/uploads\/2016\/11\/android-shell-300x179.jpg 300w, https:\/\/www.daniel-ritter.de\/blog\/wp-content\/uploads\/2016\/11\/android-shell-768x459.jpg 768w\" sizes=\"auto, (max-width: 865px) 100vw, 865px\" \/><\/a>If 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.<\/p>\n<p>Run all shell commands as root.<\/p>\n<p><strong>WIFI<\/strong><\/p>\n<pre>svc wifi enable\r\nsvc wifi disable\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>DATA<\/p>\n<pre>svc data enable\r\nsvc data disable\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>GPS<\/p>\n<pre># turn GPS on\r\nsettings put secure location_providers_allowed +gps \r\n# turn GPS off\r\nsettings put secure location_providers_allowed -gps \r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Flightmode<\/p>\n<pre># Flightmode on\r\nsettings put global airplane_mode_on 1\r\nam broadcast -a android.intent.action.AIRPLANE_MODE\r\n\r\n# Flightmode off\r\nsettings put global airplane_mode_on 0\r\nam broadcast -a android.intent.action.AIRPLANE_MODE\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Turn off screen without locking device (emulate power button keypress)<\/p>\n<pre>input keyevent 26\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Toggle Network mode (2G\/3G\/4G)<br \/>\nI have been searching for a long time, but there seems to be no direct way to do this.<br \/>\nThe best solution I have found requires xposed framework and gravitybox installed.<\/p>\n<p>I found the available network types here:<br \/>\n<a href=\"http:\/\/android.stackexchange.com\/questions\/44347\/simple-way-to-toggle-between-2g-and-3g-connection\">http:\/\/android.stackexchange.com\/questions\/44347\/simple-way-to-toggle-between-2g-and-3g-connection<\/a><\/p>\n<p>Identify the right settings for your device:<\/p>\n<pre># Disable your automation app, set networking mode with the preferences in your devices GUI.\r\n# Then run\r\n\r\nsettings get global preferred_network_mode \r\n\r\n# The currently set network mode number will be shown in shell\r\n\r\n<\/pre>\n<p>Just send the following intent to toggle network mode:<\/p>\n<pre>Send Intent [\r\nAction: gravitybox.intent.action.CHANGE_NETWORK_TYPE\r\nCat: None\r\nMime Type:\r\nData:\r\nExtra: networkType:1\r\nExtra:\r\nPackage:\r\nClass:\r\nTarget: Broadcast Receiver]\r\n\r\nnetworkType enum values are: \r\n0: WCDMA Preferred \r\n1: GSM only &lt;-- This would be \"2G\" on GSM networks\r\n2: WCDMA only &lt;--WCDMA is \"3G\" on GSM networks. You may know it as HSPA\r\n3: GSM auto (PRL)\r\n4: CDMA auto (PRL)\r\n5: CDMA only &lt;-- This would be \"2G\" on CDMA networks\r\n6: EvDo only &lt;-- EvDo is \"3G\" on CDMA networks\r\n7: GSM\/CDMA auto (PRL)\r\n8: LTE\/CDMA auto (PRL)\r\n9: LTE\/GSM auto (PRL)\r\n10: LTE\/GSM\/CDMA auto (PRL)\r\n11: LTE only\r\n12: \"unknown\"\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Disable captive portal detection<br \/>\nThis needs to be set at boottime. It doesn&#8217;t survive a reboot.<\/p>\n<pre>settings put global captive_portal_detection_enabled 0\r\nsettings put global captive_portal_server 127.0.0.1\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Force a DNS of your choice<br \/>\nGoogle removed the option to change the DNS for mobile data. (ugly, ugly, ugly)<br \/>\nYou can force your device to use your fav DNS with iptables for mobile data:<\/p>\n<pre>\/system\/bin\/iptables -t nat -A OUTPUT ! -o wlan0 -p udp --dport 53 -j DNAT --to-destination 213.73.91.35:53\r\n<\/pre>\n<p>In case you have found a better way to switch network mode, I&#8217;d really appreciate your comment :)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1707,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[228],"tags":[208,218,219,217,215,216],"class_list":["post-1689","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android","tag-adb","tag-data","tag-flightmode","tag-gps","tag-shell","tag-wifi"],"_links":{"self":[{"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/posts\/1689","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/comments?post=1689"}],"version-history":[{"count":21,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/posts\/1689\/revisions"}],"predecessor-version":[{"id":1892,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/posts\/1689\/revisions\/1892"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/media\/1707"}],"wp:attachment":[{"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/media?parent=1689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/categories?post=1689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/tags?post=1689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}