Android obtains SIM card related information of dual-card mobile phone through reflection and AIDL, and registers monitoring

Before Android 5.0, although some mobile phones were dual-SIM phones, the dual-SIM solutions were made by ODM manufacturers themselves, or completed with source code provided by chip manufacturers. Therefore, if you want to obtain dual-SIM information on mobile phones before 4.4 or even earlier, it is basically not a huge project. Although I have tried to use the reflection method to get the "com.mediatek.common.telephony.ITelephonyEx.aidl" class of Qualcomm's "android.telephony.MSimTelephonyManager" class MTK, print out the method and parameters of the function and class attributes, and then guess , but because the source code cannot be directly read, and the ODM manufacturer will also modify the corresponding code to achieve other users' itching functions (main card 3/4G network, secondary card traffic) and so on. So before Lollipop, the dual SIM problem was temporarily abandoned. But there are still ways to call other functions. For example, create the following folder under your own project

Put ITelephony.aidl in, then obtain the ITelephony instance by reflecting the getITelephony() method of TelephonyManager, and then call methods such as endCall() to achieve blacklist interception of incoming calls, etc. eg:

After Android 5.0, Google's official API began to support multiple SIM cards, which is a good thing for developers and means that applications can implement more and more functions. On Lollipop, Google has added a new Isub.aidl file. From the naming, it can be seen that this is a process service, so when using it, like ITelephony.adil, create a corresponding adil folder in your own project, put Just pull in ISub.aidl. When used, it is called as follows:

For example, suppose that the current dual-SIM dual-standby mobile phone system is Lollipop, and we want to know which card is currently used as the traffic card, so we must know the default traffic subId. The specific method is to call getDefaultDataSubId() of ISub.aidl.

After the corresponding traffic card subId, you need to call the getSubscriberid(long subId) method under TelephonyManager, but this method is a bit pitted, that is, in 5.0, the parameter book was of long type, but in 5.1, it was changed to int type , so you must pay attention to the specific use when using

By introducing the AIDL of the system, other methods can also be called to display more functions. In 6.0, Google has further opened up SIM card related APIs. We can use the SubscriptionManager API. This management class is simpler to use, similar to TelephonyManager. Get instance: Get default data card information:

Get the number of activated SIM cards:

, Since the SIM card information can be obtained, there is another important thing to obtain, that is, how to monitor the signal field strength information of the two SIM cards and the corresponding base station neighbor cell information. Before 5.0, this could not be done, because before 5.0, the PhoneStateListener method had only a constructor without parameters, so it was impossible to register listeners, but after 5.0, there was

But a big @hide isolates you from the possibility of listening. Moreover, @hide is added to the parameter protected, which is obviously not open to ordinary developers.

However, we all know that reflection can get the parameters of the class, and of course you can set the parameter value. The specific setting method, implement the constructor when inheriting PhoneStateListener

And set the listener in the constructor.

Also, there is a good article: http://blog.csdn.net/firedancer0089/article/details/60121128

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325137384&siteId=291194637