vendredi 30 décembre 2022

NoSuchMethodException is throwing when trying to access getActivePasswordQuality() method of LockPatternUtils class

I want to get access to com.android.internal.widget.LockPatternUtils class object using reflection and want to know the Lock method user has set in Android device.

I am using below code for that :

    private fun getAuthenticationMethodType() : Int {
    var lockType = 0
    try {
        val lockPatternUtilsClass = Class.forName("com.android.internal.widget.LockPatternUtils")
        val lockPatternUtils =
            lockPatternUtilsClass.getConstructor(Context::class.java).newInstance(this)


        val method: Method = lockPatternUtilsClass.getMethod("getActivePasswordQuality")
        // === The above Line throws an exception NoSuchMethodException === //

        val method2: Method = lockPatternUtilsClass.getDeclaredMethod("getActivePasswordQuality",
                            Class.forName("android.os.UserHandle"))
       // === Tried above line too, but this Line also throws an exception NoSuchMethodException === //

        val userHandleClass = Class.forName("android.os.UserHandle")
        val myUserIdMethod = userHandleClass.getMethod("myUserId")
        val userId = myUserIdMethod.invoke(userHandleClass)

        lockType = method.invoke(lockPatternUtils, userId) as Int
    } catch (e: java.lang.Exception) {
        e.printStackTrace()
        Log.d("TAG","exception : " + e.printStackTrace())
    }
     return lockType
}

I know the above code works fine until Android 6. I am trying on Android 12.

I checked on Android Documentation Non-SDK API lists and found that getActivePasswordQuality and getKeyguardStoredPasswordQuality methods are marked as greyList. As per documentation of greyList, it says :

Unsupported (greylist) : Non-SDK interfaces that are currently unrestricted and your app can use. Note however, that these interfaces are unsupported and subject to change without notice. Expect these interfaces to be conditionally blocked in future Android versions in a max-target-x list.

But, these both methods are not accessible. My understanding is that the methods marked with greyList can be accessible. Is it correct?

Is there any mistake in my code?

How to know lock password type that user has set like PIN/Password/Pattern/Biometric, just categorisation is needed





Aucun commentaire:

Enregistrer un commentaire