DevicePolicyManager.resetPasswordWithToken throws NPE

Viewed 383

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?

1 Answers

Probaby internal implementation sets the token to null if the user is not admin on the device. Check what isResetPasswordTokenActive() returns.

Related