DevicePolicyManger (). GetCurrentFailedPasswordAttempts application crash

It looks like some DeviceAdmin features were corrupted in Lollipop, at least on my Nexus 5.

This works great on KitKat, JellyBean and Ice Cream Sandwich.

@Override public void onPasswordFailed(Context context, Intent intent) { DevicePolicyManager policyManager = (DevicePolicyManager)context.getSystemService(Context.DEVICE_POLICY_SERVICE); if(policyManager != null){ int attempts = policyManager.getCurrentFailedPasswordAttempts(); Log.v("TAG", "Attempts = " + attempts); } } 

But on my Nexus 5 with Android 5.0 Lollipop, the following error occurs:

 11-24 16:11:50.117 27053-27053/com.example.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.myapp, PID: 27053 java.lang.RuntimeException: Unable to start receiver com.example.myapp.receivers.AdminReceiver: java.lang.NullPointerException: Attempt to read from field 'int android.content.pm.UserInfo.id' on a null object reference at android.app.ActivityThread.handleReceiver(ActivityThread.java:2586) at android.app.ActivityThread.access$1700(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) Caused by: java.lang.NullPointerException: Attempt to read from field 'int android.content.pm.UserInfo.id' on a null object reference at android.os.Parcel.readException(Parcel.java:1546) at android.os.Parcel.readException(Parcel.java:1493) at android.app.admin.IDevicePolicyManager$Stub$Proxy.getCurrentFailedPasswordAttempts(IDevicePolicyManager.java:2476) at android.app.admin.DevicePolicyManager.getCurrentFailedPasswordAttempts(DevicePolicyManager.java:1261) at com.example.myapp.receivers.AdminReceiver.onPasswordFailed(AdminReceiver.java:48) at android.app.admin.DeviceAdminReceiver.onReceive(DeviceAdminReceiver.java:417) at android.app.ActivityThread.handleReceiver(ActivityThread.java:2579)            at android.app.ActivityThread.access$1700(ActivityThread.java:144)            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)            at android.os.Handler.dispatchMessage(Handler.java:102)            at android.os.Looper.loop(Looper.java:135)            at android.app.ActivityThread.main(ActivityThread.java:5221)            at java.lang.reflect.Method.invoke(Native Method)            at java.lang.reflect.Method.invoke(Method.java:372)            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 

Reported as a problem in L-preview as well .

My question is, what causes this?

+5
source share
1 answer

I have the same error, and I realized that it may not work for versions version 5.0 and higher. So what I did, I check the number of failed attempts programmatically. As if someone wants to unlock the template or display it if it doesn’t do the right thing, then the receiver will catch and call the passwordFailed () method. So I created a SharedPreference object, and I save the number of passwordFailed () methods. Based on this, I get the number of invalid patterns. I think this is right or wrong, I don’t know.

0
source

Source: https://habr.com/ru/post/1207603/


All Articles