I'm trying to check if sim Pin is enabled or not.I'm aiming at 4.2 on wards. I have already tried this:
TelephonyManager manager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
int state = manager.getSimState();
Log.i(TAG,"SIM State is: "+String.valueOf(state));
if(state == TelephonyManager.SIM_STATE_PIN_REQUIRED ||state ==TelephonyManager.SIM_STATE_PUK_REQUIRED)
{
Log.i(TAG,"Pin required");
}`
but its always returns 5 (SIM_READY_STATE)
I have also tried using reflection
TelephonyManager tm = (TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
Class<?> clazz;
try {
clazz = Class.forName(tm.getClass().getName());
Method m;
m = clazz.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony it =(ITelephony) m.invoke(tm);
if(it.isSimPinEnabled())
Log.i(TAG,"Pin required");
}
but this also returns false.
Can someone suggest something here? Please note that mine is a system app.
Edit: If someone can tell me where is this toggle value stored, that will also do. I have seen this link Detect changes of "Lock SIM card" in Settings/Security/Set up SIM card lock but I can't find this particular setting in my settings.db