Change preferred network mode

GiladB

Member
I've seen a few macros like this that might save battery when 4G is not needed.
Whenever I manually change it inside of the settings it reflects on the value that Macrodroid sees, but not the other way around.
Macrodroid can change the value but it doesn't affect the actual setting.
Anybody tried experimenting with this? Thanks.
Screenshot_20220326-225923_MacroDroid.jpg
 

King_DonMike

New member
Changing the preferred network type is unfortunately a lot more complicated than simply changing the value of a variable and AFAIK impossible to automate without root. I know of two methods that work.

First and most reliable method is through GravityBox, which requires Magisk and LSPosed to be installed. There's a setting in GravityBox that toggles the preferred network type when mobile data are on or off; it can be found in Phone > Smart radio. You can also send an intent with the target being "Broadcast", the action "gravitybox.intent.action.CHANGE_NETWORK_TYPE", extra field "networkType" and the value the number corresponding to your preferred network type.

Here's the full list:

0 = GSM/WCDMA preferred
1 = GSM only
2 = WCDMA only
3 = GSM/WCDMA auto (PRL)
4 = CDMA/EvDo auto (PRL)
5 = CDMA only
6 = EvDo only
7 = CDMA/EvDo/GSM/WCDMA (PRL)
8 = CDMA + LTE/EvDo (PRL)
9 = GSM/WCDMA/LTE (PRL)
10 = LTE/CDMA/EvDo/GSM/WCDMA (PRL)
11 = LTE only
12 = LTE/WCDMA
13 = TDSCDMA only
14 = TDSCDMA/WCDMA
15 = LTE/TDSCDMA
16 = TDSCDMA/GSM
17 = LTE/TDSCDMA/GSM
18 = TDSCDMA/GSM/WCDMA
19 = LTE/TDSCDMA/WCDMA
20 = LTE/TDSCDMA/GSM/WCDMA
21 = TDSCDMA/CDMA/EvDo/GSM/WCDMA
22 = LTE/TDSCDMA/CDMA/EvDo/GSM/WCDMA
23 = NR only
24 = NR/LTE
25 = NR/LTE/CDMA/EvDo
26 = NR/LTE/GSM/WCDMA
27 = NR/LTE/CDMA/EvDo/GSM/WCDMA
28 = NR/LTE/WCDMA
29 = NR/LTE/TDSCDMA
30 = NR/LTE/TDSCDMA/GSM
31 = NR/LTE/TDSCDMA/WCDMA
32 = NR/LTE/TDSCDMA/GSM/WCDMA
33 = NR/LTE/TDSCDMA/CDMA/EvDo/GSM/WCDMA
34 = Unknown

The other is by running a shell script that "calls" a service from your phone app, asking it to change the preferred network type. This is not universal, however, as in it doesn't work on every device and on every ROM without modification. It works using the "service call phone 100 i32 9 i32 9" command, where the number 100 is the ID of that service and 9 the number corresponding to your preferred network type.

Hope this was helpful, let me know if you need more assistance with this.
 

GiladB

Member
I
Changing the preferred network type is unfortunately a lot more complicated than simply changing the value of a variable and AFAIK impossible to automate without root. I know of two methods that work.

First and most reliable method is through GravityBox, which requires Magisk and LSPosed to be installed. There's a setting in GravityBox that toggles the preferred network type when mobile data are on or off; it can be found in Phone > Smart radio. You can also send an intent with the target being "Broadcast", the action "gravitybox.intent.action.CHANGE_NETWORK_TYPE", extra field "networkType" and the value the number corresponding to your preferred network type.

Here's the full list:

0 = GSM/WCDMA preferred
1 = GSM only
2 = WCDMA only
3 = GSM/WCDMA auto (PRL)
4 = CDMA/EvDo auto (PRL)
5 = CDMA only
6 = EvDo only
7 = CDMA/EvDo/GSM/WCDMA (PRL)
8 = CDMA + LTE/EvDo (PRL)
9 = GSM/WCDMA/LTE (PRL)
10 = LTE/CDMA/EvDo/GSM/WCDMA (PRL)
11 = LTE only
12 = LTE/WCDMA
13 = TDSCDMA only
14 = TDSCDMA/WCDMA
15 = LTE/TDSCDMA
16 = TDSCDMA/GSM
17 = LTE/TDSCDMA/GSM
18 = TDSCDMA/GSM/WCDMA
19 = LTE/TDSCDMA/WCDMA
20 = LTE/TDSCDMA/GSM/WCDMA
21 = TDSCDMA/CDMA/EvDo/GSM/WCDMA
22 = LTE/TDSCDMA/CDMA/EvDo/GSM/WCDMA
23 = NR only
24 = NR/LTE
25 = NR/LTE/CDMA/EvDo
26 = NR/LTE/GSM/WCDMA
27 = NR/LTE/CDMA/EvDo/GSM/WCDMA
28 = NR/LTE/WCDMA
29 = NR/LTE/TDSCDMA
30 = NR/LTE/TDSCDMA/GSM
31 = NR/LTE/TDSCDMA/WCDMA
32 = NR/LTE/TDSCDMA/GSM/WCDMA
33 = NR/LTE/TDSCDMA/CDMA/EvDo/GSM/WCDMA
34 = Unknown

The other is by running a shell script that "calls" a service from your phone app, asking it to change the preferred network type. This is not universal, however, as in it doesn't work on every device and on every ROM without modification. It works using the "service call phone 100 i32 9 i32 9" command, where the number 100 is the ID of that service and 9 the number corresponding to your preferred network type.

Hope this was helpful, let me know if you need more assistance with this.
Thanks for the details.
I can't nor am willing to root my device.
Is the shell script supposed to work without root?
I know of a few apps on the play store that can change the preferred network type without root, and was wondering whether it could be possible to use them with Macrodroid triggers.

I figured Bixby Routines can switch the network mode. It would make sense for Macrodroid to be able to do so as well, wouldn't it?

I found a tutorial on doing that with Tasker without root, so considering how Macrodroid and Tasker are similar, it would make sense for Macrodroid not to lose functionality compared to Tasker.

I also found this thread on the forum that might bring something up: https://www.macrodroidforum.com/index.php?threads/samsung-network-mode-switching.1889/
 

Attachments

  • Screenshot_20220327-122734_Bixby Routines.jpg
    Screenshot_20220327-122734_Bixby Routines.jpg
    203.7 KB · Views: 25
Last edited:

Snurre

Well-known member
I

Thanks for the details.
I can't nor am willing to root my device.
Is the shell script supposed to work without root?
I know of a few apps on the play store that can change the preferred network type without root, and was wondering whether it could be possible to use them with Macrodroid triggers.

I figured Bixby Routines can switch the network mode. It would make sense for Macrodroid to be able to do so as well, wouldn't it?

I found a tutorial on doing that with Tasker without root, so considering how Macrodroid and Tasker are similar, it would make sense for Macrodroid not to lose functionality compared to Tasker.

I also found this thread on the forum that might bring something up: https://www.macrodroidforum.com/index.php?threads/samsung-network-mode-switching.1889/
I've been struggling with this issue for a while and it's not that easy

I managed to make a macro that toggles 5g on/off (also works for 4g), but not directly

It's possible with "Send intent" that opens Network Settings and use an UI action to click on the appropriate option

It's not the optimal solution, but it works
 

GiladB

Member
I've been struggling with this issue for a while and it's not that easy

I managed to make a macro that toggles 5g on/off (also works for 4g), but not directly

It's possible with "Send intent" that opens Network Settings and use an UI action to click on the appropriate option

It's not the optimal solution, but it works
Would that work with the screen turned off?
If Tasker or a random app can do it, why wouldn't Macrodroid be able to as well?
 

MacroDroidDev

Administrator
Staff member
I'm a bit out of date on this issue, but often the question is can Tasker or a random app does this reliably on all devices across all OS versions?

I don't know the answer and don't expect you to either, but the point is just because something works on one device it can often fail on many others. I will need to spend some time to look into this and test more to understand if it's something that can be added or not.
 

Snurre

Well-known member
I'm a bit out of date on this issue, but often the question is can Tasker or a random app does this reliably on all devices across all OS versions?

I don't know the answer and don't expect you to either, but the point is just because something works on one device it can often fail on many others. I will need to spend some time to look into this and test more to understand if it's something that can be added or not.
Tasker can't, the only thing I found is Bixby
 

Dimlos

Well-known member
Perhaps the adb command can change the preferred network mode.
I was able to get the current value, but have not tried because an easy change could make the phone unusable.

The command to change the setting is settings put global preferred_network_mode xx.
With ADB Shell [Tasker Plugin], no root is needed.
 

Attachments

  • get preferred network mode.jpg
    get preferred network mode.jpg
    254.7 KB · Views: 34

Snurre

Well-known member
Perhaps the adb command can change the preferred network mode.
I was able to get the current value, but have not tried because an easy change could make the phone unusable.

The command to change the setting is settings put global preferred_network_mode xx.
With ADB Shell [Tasker Plugin], no root is needed.
The same settings can be done by MD in system settings

There are more to it than that, more settings to change

I don't know if it's device dependent but these are Galaxy with Android 12

These are for 5g
preferred_network_mode=26,9
preferred_network_mode-1=9
preferred_network_mode1=26

And these for 4g
preferred_network_mode=9,9
preferred_network_mode-1=9
preferred_network_mode1=9

I've tried to change, but don't work, there must be other things that depends on it
 

Endercraft

Moderator (& bug finder :D)
I found an app tht can do without root


And if possible can the macrodroid admin create discord server for easier communication.
The current server doesn't really have an admin but it's good enough.

 

Dev777

Active member
After changing the settings you have to call it for it to switch.

Eg adb shell service call phone 247 i32 11 i32 1 changes to 4G

All this is highly phone specific, you have to decompile framework-res.jar and the values are stored there. Like 247 calls for Preferred Network type. 11 stands for 4G etc.
Will post a guide soon when I get time
 

Dev777

Active member
This is what I did. Works with Xiaomi MIUI14 and Oxygen OS 11. No root needed
1. Extract firmware.jar from your phone. Use adb pull /system/framework/framework.jar
2. Download jadx from here https://github.com/skylot/jadx/releases/tag/v1.4.7 and open the firmware.jar with it
3. Now the hardest part. Search for the call number.
It varies with every manufacturer. You have to search for it.
In MIUI it is stored in android.app.wearsettings.WearSettingsEnums.
Search for CELLULAR_SIM_STATUS_NETWORK_TYPE and remember the number shown next to it or note it down somewhere.

In Oxygen Os 11 or probably other AOSPs it is stored in com.android.internal.telephony.ITelephony. Search for TRANSACTION_setPreferredNetworkType. Remember or note down the number.
I don't know about other brands. Maybe with trial and error this list can be expanded.
4. Catch the setting change when you change network type. It's change in preferred_network_mode in global settings. You can catch that using this macro. https://www.macrodroidlink.com/macrostore?id=18375
Or else if you know what needs to be changed you don't need to use the macro.
5. Change the global settings as per your need using adb shell or Macrodroid settings change
6. Now the other tricky part. To call the setting change you need ADB WiFi on.

adb shell service call phone "number you saved without quotes" i32 "network type code without quotes"
if it's a dual sim you include sim 2 next to first sim.

Eg
adb shell service call phone 247 i32 6
(This changes to EVDO if phone only allows one sim network change)

adb shell service call phone 247 i32 6 i32 6
(This changes to EVDO in SIM 1 and SIM 2 if phone allows both SIM 1 and SIM 2)


The call has to match the setting change otherwise it will not work.

This is a list of network type codes to use in the command :


I'll be free to help when I can

0 = GSM/WCDMA preferred
1 = GSM only
2 = WCDMA only
3 = GSM/WCDMA auto (PRL)
4 = CDMA/EvDo auto (PRL)
5 = CDMA only
6 = EvDo only
7 = CDMA/EvDo/GSM/WCDMA (PRL)
8 = CDMA + LTE/EvDo (PRL)
9 = GSM/WCDMA/LTE (PRL)
10 = LTE/CDMA/EvDo/GSM/WCDMA (PRL)
11 = LTE only
12 = LTE/WCDMA
13 = TDSCDMA only
14 = TDSCDMA/WCDMA
15 = LTE/TDSCDMA
16 = TDSCDMA/GSM
17 = LTE/TDSCDMA/GSM
18 = TDSCDMA/GSM/WCDMA
19 = LTE/TDSCDMA/WCDMA
20 = LTE/TDSCDMA/GSM/WCDMA
21 = TDSCDMA/CDMA/EvDo/GSM/WCDMA
22 = LTE/TDSCDMA/CDMA/EvDo/GSM/WCDMA
23 = NR only
24 = NR/LTE
25 = NR/LTE/CDMA/EvDo
26 = NR/LTE/GSM/WCDMA
27 = NR/LTE/CDMA/EvDo/GSM/WCDMA
28 = NR/LTE/WCDMA
29 = NR/LTE/TDSCDMA
30 = NR/LTE/TDSCDMA/GSM
31 = NR/LTE/TDSCDMA/WCDMA
32 = NR/LTE/TDSCDMA/GSM/WCDMA
33 = NR/LTE/TDSCDMA/CDMA/EvDo/GSM/WCDMA
34 = Unknown
 
Last edited:

thinker010

New member
I want this to work on samsung completely macrodroid(without abd and I don't have root).
I also found by sending an intent
Package as com.android.phone
Class as com.android.phone.settings.RadioInfo

The menu opens for changing network type.
Like this with intent can we just send value directly tht changes the mode without using ui(Idk how intents work) like sending data 23 for NR or 24 NR/LTE
 

Attachments

  • Screenshot_20231107_180822_Phone services.jpg
    Screenshot_20231107_180822_Phone services.jpg
    351.1 KB · Views: 10

Endercraft

Moderator (& bug finder :D)
I want this to work on samsung completely macrodroid(without abd and I don't have root).
I also found by sending an intent
Package as com.android.phone
Class as com.android.phone.settings.RadioInfo

The menu opens for changing network type.
Like this with intent can we just send value directly tht changes the mode without using ui(Idk how intents work) like sending data 23 for NR or 24 NR/LTE
There are some things you just can't do without adb/root or UI Interaction.
 
Top