I use it like this:
devicePolicyManager
.resetPasswordWithToken(
componentName,
nonNullOrEmptyPassword,
nonNullOrEmptyByteArray,
0
)
And it throws NPE:
java.lang.NullPointerException: Attempt to get length of null array
at android.os.Parcel.createException(Parcel.java:2094)
at android.os.Parcel.readException(Parcel.java:2056)
at android.os.Parcel.readException(Parcel.java:2004)
at android.app.admin.IDevicePolicyManager$Stub$Proxy.resetPasswordWithToken(IDevicePolicyManager.java:15625)
at android.app.admin.DevicePolicyManager.resetPasswordWithToken(DevicePolicyManager.java:3959)
Android 10, Samsung A51, app is a device owner. What's wrong?
I tested this and i think this happens in case, when you call resetPasswordWithToken()
right after setResetPasswordToken()
when password already has been set by user. I suppose on some devices it's "okay" behavior, for example i used to reproduce it on Huawei 10 and mentioned above case occurs the same issue, but on Realme 11 everything is okay, setResetPasswordToken()
just returns false and that's it.
Case again:
setResetPasswordToken()
resetPasswordWithToken()
resetPasswordWithToken()
throws that error or returns falseSolution:
I noticed that error only in one case i explained above.
This happens because of device peculiarity.
You can wrap that resetPasswordWithToken()
method into try{}catch{}
and just return false when error on some devices occure.
And finally to reset password user need to confirm his password by blocking the screen to user enters his password again by waiting for user to block screen by yourself, via lockNow()
or just when user's screen screen timeout will be expired. After this isResetPasswordTokenActive()
is going to be true and you can reset user's password via resetPasswordWithToken()
.
Case to reset password:
Case again:
setResetPasswordToken()
lockNow()
or just by waiting)resetPasswordWithToken()
resetPasswordWithToken()
should be successfully changed