问题
I have a Xiaomi Mi6, which supports two SIMs. I need to figure out how I can switch the second SIM (SIM2) off outside business hours using Tasker.
I've got as far as figuring out how to open the settings page for SIM2 with Tasker:
Action: android.intent.action.MAIN
Cat: Launcher
Extra 1: subscription_id:1
Extra 2: slot_id:1
Package: com.android.phone
Class: com.android.phone.settings.MultiSimInfoEditorActivity
Target: Activity
which brings up the settings page for SIM2, like so. However, I can't figure out how to toggle the SIM on or off.
In hope of finding something useful I have decompiled com.android.phone (TeleService.apk) but as I don't know Java I haven't an idea where to go from here. I know there is a Java solution already on SO here but I have no idea if it works or how to adapt it to Tasker.
The decompiled MultiSimInfoEditorActivity can be found here. I have also taken a logcat of what occurs when the SIM is switched off and on again.
I greatly appreciate any help!
回答1:
I've solved the issue, although it may not work for all versions of Android. I've only tested it with my Mi6 running MIUI v9, Android build 8.0.0. It requires root.
After studying the SO solution linked above in my question I noticed that the code was retrieving the index number of a particular telephony function, which it would then use to run a command to switch off mobile data. Using this, I've found a way to actually switch the SIM off.
Googling produced this page from Haotian Deng that showed these indexes for the service call function were listed inside the ITelephony.aidl file. These are what were being fetched by the Java code . None of these worked for the Mi6, but linked to this page which explained the service call command:
# service
Usage: service [-h|-?]
service list
service check SERVICE
service call SERVICE CODE [i32 INT | s16 STR] ...
Options:
i32: Write the integer INT into the send parcel.
s16: Write the UTF-16 string STR into the send parcel.
Armed with this I found that the indexes were listed in com.android.internal.telephony.ITelephony in the devices' framework.jar.
So, to get the required index out of your device, you'll need to run the following commands from command prompt:
- Download jadx from here
- ADB pull the devices framework.jar (adb pull /system/framework/framework.jar)
- Open the .jar file with 7-Zip and extract the *.dex files.
- Open each .dex file with jadx-gui until you find the one with the following tree: com.android.internal.telephony.ITelephony
- Search for the item TRANSACTION_setSimPowerStateForSlot. Note the = x after it; this is the index number.
Now you have the index number you can test the following command in adb shell (or Tasker, with the "run shell" function). You will need to "su" in shell, or set Tasker to "Use Root".
service call phone x i32 y i32 z
Where:
x = index number you fetched previously,
y = your subscription ID (generally, SIM1 = 0, SIM2 = 1)
z = whether on (1) or off (0)
Of course, now that you can execute it in Tasker you can now switch either SIM off at specific times.
I've verified that it does indeed switch the SIM off (calls go straight to voicemail right after this command is executed) but I'm unsure of any further effects this switch has.
Enjoy!
来源:https://stackoverflow.com/questions/48696898/turning-off-second-sim-via-adb-shell-tasker-using-activities-intents