-->

Is it possible to unlock the sim and let the softw

2020-06-30 04:03发布

问题:

I´m going to give away phones (Android) to clients (mostly kids) and want to create a ´lock´-app. I don´t want the clients to bother with the pincode for the phone, but when you turn on the device, the ´lock´-app should just start. I then overwrite the buttons and they shouldn´t be able to make phonecalls.

Only thing is, in case of removal of the sim, or in case of theft, I want a pincode on the simcard. So is it possible that my ´lock´-app unlocks the sim by putting in the pin by code?

How can I do that?

回答1:

That is possible. I do it in this code:

    try {
        @SuppressWarnings("rawtypes")
        Class clazz = Class.forName(telephonyManager.getClass().getName());
        Method m = clazz.getDeclaredMethod("getITelephony");
        m.setAccessible(true);
        ITelephony it = (ITelephony) m.invoke(telephonyManager);
        if (it.supplyPin("1234")) {
            // SIM unlocked
        } else {
            // not unlocked
        }

    } catch (Exception e) {
        // 
    }

In order to do that, you need the ITelephony interface. You can find its source here. Make com.android.internal.telephony package in your src folder and put iTelephony.java there. This approach uses *android.permission.MODIFY_PHONE_STATE* permission, which is only available up to Android 2.2. Since version 2.3 this permission is limited to system apps. If you want to use that code in latest version, you have to move your application apk file from /data/app to /system/app folder.