{"id":2034,"date":"2024-11-03T03:26:21","date_gmt":"2024-11-03T02:26:21","guid":{"rendered":"https:\/\/www.daniel-ritter.de\/blog\/?p=2034"},"modified":"2024-11-04T19:56:03","modified_gmt":"2024-11-04T18:56:03","slug":"change-preferred-network-mode-on-android-15-2g-3g-lte-4g-5g-with-shell-command","status":"publish","type":"post","link":"https:\/\/www.daniel-ritter.de\/blog\/change-preferred-network-mode-on-android-15-2g-3g-lte-4g-5g-with-shell-command\/","title":{"rendered":"Change Preferred Network Type Mode on Android 15 \/ 2G \/ 3G \/ LTE \/ 4G \/ 5G with shell command"},"content":{"rendered":"<p>Changing the preferred network mode in Android has always been a hassle. The backend to the function changed many times over the years and has become more and more complicated.<\/p>\n<p>Right now there seems to be no universal way to change the settings in an automated way without using the GUI. Every phone model \/ ROM \/ provider combination results in different code numbers to access Androids interface to control the baseband modem.<\/p>\n<p>But if you are up for the challenge, here is the way how to do it for your device.<\/p>\n<p>You need to find these values:<br \/>\n&#8211; Numeric Code to write to your phones modem device<br \/>\n&#8211; Numeric Code to read from your phones modem device<br \/>\n&#8211; Numeric Codes for every preferred network setting you want to use (2G,3G,4G, etc.)<\/p>\n<p>OK, lets go!<\/p>\n<p><strong>Download firmware.jar from your phone: <\/strong><\/p>\n<pre>\r\nadb pull \/system\/framework\/framework.jar\r\n<\/pre>\n<p><strong><br \/>\nUnpack firmware.jar:<\/strong><\/p>\n<pre>\r\nunzip .\/firmware.jar\r\n<\/pre>\n<p><strong>Search files in firmware.jar for the needed service code to write to the modem interface on your phone:<\/strong><\/p>\n<pre>\r\n> grep -r \"TRANSACTION_setAllowedNetworkTypesForReason\" .\r\n\r\n.\/f\/sources\/com\/android\/internal\/telephony\/ITelephony.java:        static final int TRANSACTION_setAllowedNetworkTypesForReason = <strong>108<\/strong>;\r\n<\/pre>\n<p>Code was found in &#8222;ITelephony.java&#8220; on my device (Pixel 6a). Code is <strong>108<\/strong><\/p>\n<p><strong>Search files in firmware.jar for the needed service code to read from the modem interface on your phone:<\/strong><\/p>\n<pre>\r\n> grep -r \"TRANSACTION_getAllowedNetworkTypesForReason\" .\r\n.\/f\/sources\/com\/android\/internal\/telephony\/ITelephony.java:        static final int TRANSACTION_getAllowedNetworkTypesForReason = <strong>107<\/strong>;\r\n<\/pre>\n<p>Code was found in &#8222;ITelephony.java&#8220; on my device (Pixel 6a). Code is <strong>107<\/strong><\/p>\n<p>Now we have the needed codes to read from (<strong>107<\/strong>) and write to (<strong>108<\/strong>) the modem interface.<\/p>\n<p>Next thing to do is go through all the available settings in the GUI.<br \/>\nI will set my phone to 2G only for this example. (Settings -> Network -> Simcard -> Cogwheel -> Preferred Network mode). You have to repeat this step for all the other settings too (3G,4G, etc.)<\/p>\n<p><strong>After setting the network mode to 2G read it&#8217;s code from Android:<\/strong><\/p>\n<pre>\r\nadb shell\r\n#Code <strong>107<\/strong> has been identified in the last step. It can be different on your device\r\nservice call phone <strong>107<\/strong>                                                                                                          \r\nResult: Parcel( 00000000 <strong>00008003<\/strong> 00000000  '............')\r\n<\/pre>\n<p>Now we got a Hex value for the phones 2G-setting (<strong>00008003<\/strong>)<\/p>\n<p>We need to convert that to decimal, because the interface command expects that as input.<br \/>\nYou can use this website for easy conversion: <a href=\"https:\/\/www.rapidtables.com\/convert\/number\/hex-to-decimal.html\">https:\/\/www.rapidtables.com\/convert\/number\/hex-to-decimal.html<\/a><\/p>\n<p>(HEX) <strong>00008003<\/strong> converts to (DEC) <strong>32771<\/strong><\/p>\n<p>Cool. We now have everything we need.<br \/>\nLast thing to do is to try it out.<\/p>\n<p>Open up the settings GUI to see if it works. The prefered network entry in the GUI should change instantly to 2G after using the following command.<\/p>\n<p><strong>Use the code for writing you identified above (108 in my case) and the code for 2G from the last step (32771 in my case):<\/strong><\/p>\n<pre>\r\nadb shell\r\nservice call phone <strong>108<\/strong> i32 0 i32 0 i64 \"<strong>32771<\/strong>\"                                                                                            \r\nResult: Parcel( 00000000 00000001   '........')\r\n<\/pre>\n<p>Yay! That worked. Nice. The device switched to 2G mode.<\/p>\n<p>Repeat this for all the network type settings your device offers to get the other HEX-codes. Convert them to DEC and use them.<\/p>\n<p>Use the commands to switch network modes on the fly with automation apps like Tasker or Macrodroid.<\/p>\n<p>Thank you to Dev777 who brought me onto the right track in this forum thread:<br \/>\n<a href=\"https:\/\/www.macrodroidforum.com\/index.php?threads\/change-preferred-network-mode.2130\/\">https:\/\/www.macrodroidforum.com\/index.php?threads\/change-preferred-network-mode.2130\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This blog post explains how to change the preferred network mode on Android 15 with shell commands. 2G 3G 4G LTE 5G.<\/p>\n","protected":false},"author":1,"featured_media":1897,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[228],"tags":[],"class_list":["post-2034","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android"],"_links":{"self":[{"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/posts\/2034","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=2034"}],"version-history":[{"count":27,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/posts\/2034\/revisions"}],"predecessor-version":[{"id":2062,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/posts\/2034\/revisions\/2062"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/media\/1897"}],"wp:attachment":[{"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/media?parent=2034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/categories?post=2034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/tags?post=2034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}