2

I want to use an android internal class, com.android.internal.widget.LockPatternUtils .

I searched for examples and I got this:

LockPatternUtils lpu = new LockPatternUtils(this.getContentResolver());

However, i cant import, autimport does not appear and manually doing

import com.android.internal.widget.LockPatternUtils 

doesnt work.

How is this handled? I think there was something about creating an interface but not sure about it

EDIT: I got this:

  boolean patternLocked = android.provider.Settings.System.getInt(
     getContentResolver(),Settings.System.LOCK_PATTERN_ENABLED, 0)==1;

That works for the pattern lock, but i cant know about the pin or password lock

JesusS
  • 1,645
  • 1
  • 18
  • 31

3 Answers3

6

Use reflection to access the internal Android method getActivePasswordQuality (line 350 of LockPatternUtils.java) and compare the int it returns to the int for any of the DevicePolicyManager Constants:

protected boolean isSecure() {

    String LOCK_PATTERN_UTILS = "com.android.internal.widget.LockPatternUtils";

    try {
        Class<?> lockPatternUtilsClass = Class.forName(LOCK_PATTERN_UTILS);
        Object lockPatternUtils = lockPatternUtilsClass.getConstructor(Context.class).newInstance(this);
        Method method = lockPatternUtilsClass.getMethod("getActivePasswordQuality");
        int lockProtectionLevel = Integer.valueOf(String.valueOf(method.invoke(lockPatternUtils)));

        // Then check if lockProtectionLevel == DevicePolicyManager.TheConstantForWhicheverLevelOfProtectionYouWantToEnforce, and return true if the check passes, false if it fails
    }
    catch (Exception ex) {
        ex.printStackTrace();
    }

    return false;
}
esme_louise
  • 540
  • 2
  • 9
  • 28
  • `getActivePasswordQuality` was changed in API `23` and now requires an int argument (the user id). Is there a way to determine the user id of the current user without `MANAGE_USERS` permission? – friederbluemle Oct 12 '15 at 15:44
2

How is this handled?

Those classes are only available as part of full firmware builds, not from Android SDK apps.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • The Telephony class is internal too but it is possible to be accessed in 3rd party app. Doesnt this have a solution like that? – JesusS Jul 05 '13 at 11:34
  • @JesusS: "The Telephony class is internal too but it is possible to be accessed in 3rd party app" -- not reliably. Anything that is internal can and will be modified (or even removed) by device manufacturers and ROM modders. – CommonsWare Jul 05 '13 at 11:37
2

You can not use Android internal classes, they do not come with the public SDK.

You can build your own SDK exposing them more or less as they do here How do I build the Android SDK with hidden and internal APIs available?

This is not recommended because you will have no guarantees.

Community
  • 1
  • 1
Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158