I'm working on a service to auto PIN/PUK when starting device. Service is launched at Boot time. I'm using ITelephony with reflexive methods. My phone is lollipop 5.1.1, it's a rooted nexus 5. My manifest has Android Studio says "Permission is only granted to system apps"
I'm using this code snippet :
TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
int state = tm.getSimState();
if(state == TelephonyManager.SIM_STATE_PIN_REQUIRED || state == TelephonyManager.SIM_STATE_PUK_REQUIRED)
{
Log.d(TAG,"PIN PUK STATE = " + state );
if (state == TelephonyManager.SIM_STATE_PIN_REQUIRED ){
try {
message += ", PIN Code required" ;
Class clazz = Class.forName(tm.getClass().getName());
if (clazz != null) {
Method m = clazz.getDeclaredMethod("getITelephony");
m.setAccessible(true);
Object iTelephony = m.invoke(tm);
Class params[] = new Class[1];
params[0] = String.class;
Method m2 = iTelephony.getClass().getDeclaredMethod("supplyPin", params);
m2.setAccessible(true);
Object i = m2.invoke(iTelephony, "1111");
Log.d(TAG, m2.toString() + " *** " + i.toString());
}
}catch (Exception e) {
Log.d(TAG,"Impossible to unlock " + e.toString());
e.printStackTrace();
}
}
And I get this log :
07-20 10:31:33.109 1267-1267/eu.cabrera.pinunlocker W/System.err﹕ Caused by: java.lang.SecurityException: Neither user 10032 nor current process has android.permission.MODIFY_PHONE_STATE.
07-20 10:31:33.112 1267-1267/eu.cabrera.pinunlocker W/System.err﹕ at android.os.Parcel.readException(Parcel.java:1546)
07-20 10:31:33.112 1267-1267/eu.cabrera.pinunlocker W/System.err﹕ at android.os.Parcel.readException(Parcel.java:1499)
07-20 10:31:33.112 1267-1267/eu.cabrera.pinunlocker W/System.err﹕ at com.android.internal.telephony.ITelephony$Stub$Proxy.supplyPin(ITelephony.java:1540)
I've tested with a regular app and now with a system app, same problem.
Am I doing something bad? Is my app really system? I have copied eu.cabrera.pinunlocker.apk to /system/app
What do I need to grant my app the android.permission.MODIFY_PHONE_STATE?
Thanks for your help. Antoine
Did you try to put your app to /system/priv-app? Becouse if you need to grant system permission /system/priv-app is the correct location for your app. Only apks in /system/priv-app can use "system"-level permissions