Android M获取屏幕锁定的相关信息:“无”,“滑动”,“PIN码”,"图案","密码"

Posted 好久不见

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android M获取屏幕锁定的相关信息:“无”,“滑动”,“PIN码”,"图案","密码"相关的知识,希望对你有一定的参考价值。

ENV: android M 6.0.1

        import android.os.UserHandle;
        import com.android.internal.widget.LockPatternUtils;
        import android.app.admin.DevicePolicyManager;

        LockPatternUtils mLockPatternUtils = new LockPatternUtils(mContext);
        int userId = UserHandle.myUserId();
        boolean lockScreenDisabled = mLockPatternUtils.isLockScreenDisabled(userId);
        boolean security = mLockPatternUtils.isSecure(userId);
        boolean isLockPasswordEnabled = mLockPatternUtils.isLockPasswordEnabled(userId);
        boolean isLockPatternEnabled = mLockPatternUtils.isLockPatternEnabled(userId);

        final int quality = mLockPatternUtils.getKeyguardStoredPasswordQuality(userId);

        Log.d(TAG, "lockScreenDisabled = " + lockScreenDisabled);
        Log.d(TAG, "security = " + security);
        Log.d(TAG, "isLockPasswordEnabled = " + isLockPasswordEnabled);
        Log.d(TAG, "isLockPatternEnabled = " + isLockPatternEnabled);
        Log.d(TAG, "quality = " + quality);

        switch (quality) {
            case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
            case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
                if (mLockPatternUtils.isLockPasswordEnabled(userId)) {
                    Log.d(TAG, "PIN码 安全模式");
                }
                break;
            case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
            case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
            case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
                if (mLockPatternUtils.isLockPasswordEnabled(userId)) {
                    Log.d(TAG, "密码 安全模式");
                }
                break;

            case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
            case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED:
                if (mLockPatternUtils.isLockPatternEnabled(userId)) {
                    Log.d(TAG, "图案 安全模式");
                }
                break;
         }

打印Log
[email protected]:~$ adb logcat -s LockPatternUtilsHelp
--------- beginning of system
--------- beginning of main

//图案
11-02 14:36:22.721  4896  4896 D LockPatternUtilsHelp: lockScreenDisabled = false
11-02 14:36:22.721  4896  4896 D LockPatternUtilsHelp: security = true
11-02 14:36:22.721  4896  4896 D LockPatternUtilsHelp: isLockPasswordEnabled = false
11-02 14:36:22.721  4896  4896 D LockPatternUtilsHelp: isLockPatternEnabled = true
11-02 14:36:22.722  4896  4896 D LockPatternUtilsHelp: quality = 65536
11-02 14:36:22.722  4896  4896 D LockPatternUtilsHelp: 图案 安全模式

//PIN码
11-02 14:37:34.748  4896  4896 D LockPatternUtilsHelp: lockScreenDisabled = false
11-02 14:37:34.748  4896  4896 D LockPatternUtilsHelp: security = true
11-02 14:37:34.748  4896  4896 D LockPatternUtilsHelp: isLockPasswordEnabled = true
11-02 14:37:34.748  4896  4896 D LockPatternUtilsHelp: isLockPatternEnabled = false
11-02 14:37:34.748  4896  4896 D LockPatternUtilsHelp: quality = 131072
11-02 14:37:34.748  4896  4896 D LockPatternUtilsHelp: PIN码 安全模式

// 密码
11-02 14:38:10.930  4896  4896 D LockPatternUtilsHelp: lockScreenDisabled = false
11-02 14:38:10.930  4896  4896 D LockPatternUtilsHelp: security = true
11-02 14:38:10.930  4896  4896 D LockPatternUtilsHelp: isLockPasswordEnabled = true
11-02 14:38:10.930  4896  4896 D LockPatternUtilsHelp: isLockPatternEnabled = false
11-02 14:38:10.930  4896  4896 D LockPatternUtilsHelp: quality = 327680
11-02 14:38:10.931  4896  4896 D LockPatternUtilsHelp: 密码 安全模式

// 滑动
11-02 14:36:58.968  4896  4896 D LockPatternUtilsHelp: lockScreenDisabled = false
11-02 14:36:58.968  4896  4896 D LockPatternUtilsHelp: security = false
11-02 14:36:58.968  4896  4896 D LockPatternUtilsHelp: isLockPasswordEnabled = false
11-02 14:36:58.968  4896  4896 D LockPatternUtilsHelp: isLockPatternEnabled = false
11-02 14:36:58.968  4896  4896 D LockPatternUtilsHelp: quality = 0

// 无
11-02 14:36:58.968  4896  4896 D LockPatternUtilsHelp: lockScreenDisabled = true
11-02 14:36:58.968  4896  4896 D LockPatternUtilsHelp: security = false
11-02 14:36:58.968  4896  4896 D LockPatternUtilsHelp: isLockPasswordEnabled = false
11-02 14:36:58.968  4896  4896 D LockPatternUtilsHelp: isLockPatternEnabled = false
11-02 14:36:58.968  4896  4896 D LockPatternUtilsHelp: quality = 0

 

一 如何判断当前锁定方式是否为"无"?
通过LockPatternUtils类的isLockScreenDisabled判断

二 如何判断当前锁定方式是否为"滑动"?
通过LockPatternUtils类的! isSecure方法和! isLockScreenDisabled方法判断

三 如何判断当前锁定方式是否为"安全密码"锁屏?
通过LockPatternUtils类的isSecure方法和getKeyguardStoredPasswordQuality方法判断

PS:LockPatternUtils类为平台内部类,第三方应用层无法获取该类,可考虑通过反射调用亦可考虑其他方式判断































































































以上是关于Android M获取屏幕锁定的相关信息:“无”,“滑动”,“PIN码”,"图案","密码"的主要内容,如果未能解决你的问题,请参考以下文章

在Android中的锁定屏幕上显示自定义信息[重复]

如何在屏幕镜像期间锁定Android屏幕?

微信wx.getLocation方法,锁定android屏幕

如何在Android中锁定屏幕时长按电源按钮启用GPS?

使 iPad 屏幕关闭,但通过触摸唤醒(无锁定) - - iOS 6.0 / openFrameworks

android系统用户数据锁定怎么办?