• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!
  • Fill out your device list and let everyone know which phones you have!    Edit Your Device Inventory

[GUIDE] Automatic dual sim switching on latest official OTA

Search This thread

projection

Senior Member
Nov 8, 2008
445
229
TL;DR:
You need root.
Shell command with root privileges to toggle sim programatically:
Code:
service call phone 162 i32 x i32 y
Where x is 0 for SIM1 and 1 for SIM2, and y is 0 to disable and 1 to enable.
For example:
Code:
service call phone 162 i32 1 i32 0
will disable SIM2 and
Code:
service call phone 162 i32 1 i32 1
will enable it.

Longer version, and how to find the magic "162" number:
You need:
1. vdexExtractor
2. jadx

Step by step:
1. Pull /system/framework/arm64/boot-framework.vdex
2. extract it with vdexExtractor, you should get some dex classfiles.
3. Open them with jadx and find the one that contains com.android.internal.telephony.ITelephony
4. Navigate to the class with jadx and locate the value of TRANSACTION_setSimPowerStateForSlot, this is your magic number.

After you have the command you can use for example Tasker to enable and disable the SIM card.
The only downside of using this method is that major Android version bumps will most likely break this, as the numbers vary from android build to android build.
 
Last edited:

kylemd

Senior Member
Aug 13, 2015
191
63
Sydney
Spent a few hours trying to figure this out for Oreo only to find your post about 5s before I found the solution myself! Many thanks. I've linked your post here to go with my N-only guide.
 
  • Like
Reactions: suvamroy

Vledderos

Senior Member
Feb 5, 2009
57
4
I tried this op OP6T but it doesn't seem to work. Can someone confirm? Maybe the 'magicnumber' differs.
I pulled the vdex file, but I don't know how to extract it with that command line tool vdexExtractor. Can someone help me with this? Here's the file
 

Vledderos

Senior Member
Feb 5, 2009
57
4
Jun 23, 2015
13
0
help

TL;DR:
You need root.
Shell command with root privileges to toggle sim programatically:
Code:
service call phone 162 i32 x i32 y
Where x is 0 for SIM1 and 1 for SIM2, and y is 0 to disable and 1 to enable.
For example:
Code:
service call phone 162 i32 1 i32 0
will disable SIM2 and
Code:
service call phone 162 i32 1 i32 1
will enable it.

Longer version, and how to find the magic "162" number:
You need:
1. vdexExtractor
2. jadx

Step by step:
1. Pull /system/framework/arm64/boot-framework.vdex
2. extract it with vdexExtractor, you should get some dex classfiles.
3. Open them with jadx and find the one that contains com.android.internal.telephony.ITelephony
4. Navigate to the class with jadx and locate the value of TRANSACTION_setSimPowerStateForSlot, this is your magic number.

After you have the command you can use for example Tasker to enable and disable the SIM card.
The only downside of using this method is that major Android version bumps will most likely break this, as the numbers vary from android build to android build.

what if i cant find TRANSACTION_setSimPowerStateForSlot even in nougat?
 
for what reason someone need to do such thing?

My reason is that I only want to be reached on my work number during work hours. So in my case I disable sim2 at 1600 when I go home from work, and then I enable it right before I start working again.
The apps available for this don't work on my phone (opo5) so this was the only way I could find.
 

alessandro_xda

Senior Member
Feb 8, 2007
443
85
Bologna
TL;DR:
You need root.
Shell command with root privileges to toggle sim programatically:
Code:
service call phone 162 i32 x i32 y
Where x is 0 for SIM1 and 1 for SIM2, and y is 0 to disable and 1 to enable.
For example:
Code:
service call phone 162 i32 1 i32 0
will disable SIM2 and
Code:
service call phone 162 i32 1 i32 1
will enable it.

Longer version, and how to find the magic "162" number:
You need:
1. vdexExtractor
2. jadx

Step by step:
1. Pull /system/framework/arm64/boot-framework.vdex
2. extract it with vdexExtractor, you should get some dex classfiles.
3. Open them with jadx and find the one that contains com.android.internal.telephony.ITelephony
4. Navigate to the class with jadx and locate the value of TRANSACTION_setSimPowerStateForSlot, this is your magic number.

After you have the command you can use for example Tasker to enable and disable the SIM card.
The only downside of using this method is that major Android version bumps will most likely break this, as the numbers vary from android build to android build.

i've succesfully extracted boot-framework.vdex and obtained 3 new files:
boot-framework_classes.cdex
boot-framework_classes2.cdex
boot-framework_classes3.cdex

but using jadx i don't get any result... just an empty window

btw: i'm on op5t running pie
 

BigBrosMo

Senior Member
Jul 10, 2012
307
96
TL;DR:
You need root.
Shell command with root privileges to toggle sim programatically:

Where x is 0 for SIM1 and 1 for SIM2, and y is 0 to disable and 1 to enable.
For example:

will disable SIM2 and


i've succesfully extracted boot-framework.vdex and obtained 3 new files:
boot-framework_classes.cdex
boot-framework_classes2.cdex
boot-framework_classes3.cdex

but using jadx i don't get any result... just an empty window

btw: i'm on op5t running pie
Any luck with this? I am on pie op5t also and want to be able to switch on and off
 

dragone17

Member
Sep 5, 2011
6
0
Italy
I had success. Oneplus 5 with Pie
I discovered that with Pie it is necessary another step between 2 and 3, because the step 2 now gives .cdex files (compact dex) instead of the .dex files, and jadx (at least the versions I tried) can read only .dex files.

In the github page of vdexExtractor I found a section about the vdexExtractor#compact-dex-converter, that is necessary to convert .cdex to .dex.
I used the Linux x86-64 - Statically compiled binaries, the shared libraries version didn't work on my Virtual Machine with linux Mint (I have only windows 10 on my pc)

Using that converter I obtained the .dex files that jadx can read and follow step 3 and 4 of the guide.

I hope to be of some help
 

BigBrosMo

Senior Member
Jul 10, 2012
307
96
I had success. Oneplus 5 with Pie
...
In the github page of vdexExtractor I found a section about the vdexExtractor#compact-dex-converter, that is necessary to convert .cdex to .dex.
I used the Linux x86-64 - Statically compiled binaries, the shared libraries version didn't work on my Virtual Machine with linux Mint (I have only windows 10 on my pc)

That's great! I am on an island right now in Thailand and with only a win7 machine. I would live to get this working as I don't want both Sims on all the time to conserve battery, and would like to automatically check my home SIM once and awhile in the background. While I am quite comp savvy I dont have the time/bandwidth to compile a Linux distro or virtual machine just to run this converter... Or... Do I even need to? What's the quickest and dirtiest method for me to find my "magic number"?

And is that number unique to the install or my IMEI? Like if I reinstall/upgrade the os do I need to redo the process or would it remain the same?
 
Last edited:

dragone17

Member
Sep 5, 2011
6
0
Italy
I'm sorry but I don't know if you can run vdexExtractor on windows. If it is possible, I couldn't find how. But jadx have a version with gui compiled to run on windows.
I suppose that the "magic number" depends on the os version, and maybe the phone model.
It didn't change for me on the various minor upgrades on oreo (5.1.5, 5.1.6, 5.1.7), and now it didn't change on the minor pie upgrades (9.0.2, 9.0.3).
Not sure if the number is the same on the various oneplus devices.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 5
    TL;DR:
    You need root.
    Shell command with root privileges to toggle sim programatically:
    Code:
    service call phone 162 i32 x i32 y
    Where x is 0 for SIM1 and 1 for SIM2, and y is 0 to disable and 1 to enable.
    For example:
    Code:
    service call phone 162 i32 1 i32 0
    will disable SIM2 and
    Code:
    service call phone 162 i32 1 i32 1
    will enable it.

    Longer version, and how to find the magic "162" number:
    You need:
    1. vdexExtractor
    2. jadx

    Step by step:
    1. Pull /system/framework/arm64/boot-framework.vdex
    2. extract it with vdexExtractor, you should get some dex classfiles.
    3. Open them with jadx and find the one that contains com.android.internal.telephony.ITelephony
    4. Navigate to the class with jadx and locate the value of TRANSACTION_setSimPowerStateForSlot, this is your magic number.

    After you have the command you can use for example Tasker to enable and disable the SIM card.
    The only downside of using this method is that major Android version bumps will most likely break this, as the numbers vary from android build to android build.
    4
    Hi , got commands to disable sim card on OP6 10.3.1 release - may work on other releases

    service call extphone 4 i32 1 (disable sim2)
    service call extphone 3 i32 1 (enable sim2)
    service call extphone 4 i32 0 (disable sim1)
    service call extphone 3 i32 0 (enable sim1)
    2
    Hi , got commands to disable sim card on OP6 10.3.1 release - may work on other releases

    service call extphone 4 i32 1 (disable sim2)
    service call extphone 3 i32 1 (enable sim2)
    service call extphone 4 i32 0 (disable sim1)
    service call extphone 3 i32 0 (enable sim1)
    Thanks it also work on my 5T openbeta 33

    Sent from my ONEPLUS A5010 using Tapatalk
    2
    for what reason someone need to do such thing?

    My reason is that I only want to be reached on my work number during work hours. So in my case I disable sim2 at 1600 when I go home from work, and then I enable it right before I start working again.
    The apps available for this don't work on my phone (opo5) so this was the only way I could find.
    2
    Took forever, but finally got it working. All via Windows. I have a OnePlus 5T and my number was also 176. OS vers 9.0.9
    -Used latest vdexExtractor.exe from https://github.com/fOmey/vdexExtractor/tree/master/bin
    -Then referenced kevinminions9 post from https://github.com/anestisb/vdexExtractor/issues/23 to download the android version of the converter tool, and then followed the directions to push the converter and pull the dex files back to my laptop
    -Couldn't get Jadx working for some reason, so used "Bytecode-Viewer" to find the magic number using the path mentioned in the OP