Java.lang.SecurityException: neither user 10032 nor the current process has android.permission.MODIFY_PHONE_STATE
I start the automatic PIN / PUK service when the device starts. The service starts at boot time. I am using ITelephony with reflective methods. My phone is lollipop 5.1.1, this is root 5. My Android Studio manifest says "Permission is granted to system apps only"
I am using this piece of code:
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 tested with a regular app and now with a system app, same problem.
Am I doing something bad? Is my application really a system? I copied eu.cabrera.pinunlocker.apk to/system/app
What do I need to give my app android.permission.MODIFY_PHONE_STATE?
Thank you for your help. Antoine
Have you tried putting your app in / system / priv -app? If you need to grant system permissions / system / private app this is the right place for your app. Only apks in / system / priv -app can use "system" -level permissions