Keyguard Learning -- lockpatternkeyguardview

Source: Internet
Author: User

1. Lock Screen mode

There are two lock modes:

 /**     * Either a lock screen (an informational keyguard screen), or an unlock     * screen (a means for unlocking the device) is shown at any given time.     */    enum Mode {        LockScreen,        UnlockScreen    }

Lockscreen is the default unlock method, which is generally called the "unlock" interface; unlockscreen is generally called the "unlock" interface.
They are in a parallel relationship, that is, they will determine the case after entering the unlock, and then enter, and unlockscreen is not the final case, it is subdivided into the following situations:

 /**     * The different types screens available for {@link Mode#UnlockScreen}.     * @see com.android.internal.policy.impl.LockPatternKeyguardView#getUnlockMode()     */    enum UnlockMode {        /**         * Unlock by drawing a pattern.         */        Pattern,        /**         * Unlock by entering a sim pin.         */        SimPin,        /**         * Unlock by entering a sim2 pin.         */        Sim2Pin,                /**         * Unlock by entering an account's login and password.         */        Account,        /**         * Unlock by entering a password or PIN         */        Password,        /**         * Unknown (uninitialized) value         */        Unknown    }

There are a total of five unlockscreen methods, which are simple and do not need to be explained.

2. getinitialmode Method

This method is used to obtain the initial lock mode. The returned result is either lockscreen or unlockscreen in mode. For the unlockscreen mode, no specific method is provided: pin, password, or pattern. This will be judged in another method.

private Mode getInitialMode() {    if (stuckOnLockScreenBecauseSimMissing()) {        return Mode.LockScreen;    } else {        if (!isSecure() || mShowLockBeforeUnlock) {            return Mode.LockScreen;        } else {            return Mode.UnlockScreen;        }    }}

When the SIM card does not exist, the user does not select a safe method (Insecure means that the current screen lock method is sliding to unlock, rather than pin, password, pattern, etc ), if you need to display lockscreen before unlockscreen is displayed, lockscreen is returned; otherwise, unlockscreen is returned.

3. getunlockmode Method

This method can obtain which unlock mode should be under unlockscreen. It returns one of the five unlockmodes.

Note that the unlock method has a priority. The source code is as follows:

private UnlockMode getUnlockMode() {    final IccCard.State simState = mUpdateMonitor.getSimState(Phone.GEMINI_SIM_1);    final IccCard.State sim2State = mUpdateMonitor.getSimState(Phone.GEMINI_SIM_2);    UnlockMode currentMode = UnlockMode.Unknown;    if (simState == IccCard.State.PIN_REQUIRED         && !mUpdateMonitor.getPINDismissFlag(Phone.GEMINI_SIM_1, true)        || (simState == IccCard.State.PUK_REQUIRED         && !mUpdateMonitor.getPINDismissFlag(Phone.GEMINI_SIM_1, false))){        currentMode = UnlockMode.SimPin;    }  else if (sim2State == IccCard.State.PIN_REQUIRED         && !mUpdateMonitor.getPINDismissFlag(Phone.GEMINI_SIM_2, true)        || (sim2State == IccCard.State.PUK_REQUIRED         && !mUpdateMonitor.getPINDismissFlag(Phone.GEMINI_SIM_2, false))){        currentMode = UnlockMode.Sim2Pin;    } else {        final int mode = mLockPatternUtils.getKeyguardStoredPasswordQuality();        switch (mode) {            case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:            case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:            case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:            case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:                currentMode = UnlockMode.Password;                break;            case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:            case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED:                // "forgot pattern" button is only available in the pattern mode...                if (mForgotPattern || mLockPatternUtils.isPermanentlyLocked()) {                    currentMode = UnlockMode.Account;                } else {                    currentMode = UnlockMode.Pattern;                }                break;            default:               throw new IllegalStateException("Unknown unlock mode:" + mode);        }    }    return currentMode;}

The default value is unlockmode. Unknown.
The highest priority is unlockmode. simpin, then unlockmode. sim2pin, and several other

Private Final keyguardupdatemonitor mupdatemonitor;
The keyguardupdatemonitor can monitor the status of the current mobile phone and provide getsimstate, which can return the status of the current SIM card. The SIM card has multiple statuses, which are defined in icccard. java.

public enum State {    UNKNOWN,    ABSENT,    PIN_REQUIRED,    PUK_REQUIRED,    NETWORK_LOCKED,    READY,    NOT_READY,    PERM_DISABLED;}

Here we will only discuss the pin_required and puk_required statuses.

Inal int mode = mlockpatternutils. getkeyguardstoredpasswordquality ();
In other cases, there should be a location to record these modes, but I did not find them. I guess they are in the database.

Iv. updatescreen Method

Private void updatescreen (mode, Boolean force) {mmode = mode;/*** two-step verification is required to call the recreatelockscreen method, this method is not called when any step fails. ** Step 1: The current unlock mode is lockscreen, or you need to show lock before unlock. This step passes ** Step 2: when other methods call updatescreen, use force to specify the force call, or the lockscreen is still empty and has not been created, this step passes * // re-create the lock screen if necessary if (mode = mode. lockscreen | mshowlockbeforeunlock) {If (Force | mlockscreen = NULL) {recreatelockscree N () ;}// re-create the unlock screen if necessary. this is primarily required to properly handle // SIM state changes. this typically happens when this method is called by reset () if (mode = mode. unlockscreen) {final unlockmode = getunlockmode (); If (Force | munlockscreen = NULL | unlockmode! = Munlockscreenmode) {Boolean restartfacelock = stopfacelockifrunning (); recreateunlockscreen (unlockmode); If (restartfacelock) activatefacelockifable ();}} /*** mlockscreen and munlockscreen respectively represent lockscreen and unlockscreen ** gonescreen and visiblescreen respectively represent the disappears and visible. You should choose one of them and only one is visible at the same time, and the other is the disappearing * // visiblescreen shold never be null final view gonescreen = (mode = mode. lockscreen )? Munlockscreen: mlockscreen; final view visiblescreen = (mode = mode. lockscreen )? Mlockscreen: munlockscreen; // do this before changing visibility so focus isn' t requested before the input // flag is set mwindowcontroller. setneedsinput (keyguardscreen) visiblescreen ). needsinput (); If (mscreenon) {If (gonescreen! = NULL & gonescreen. getvisibility () = view. Visible) {(keyguardscreen) gonescreen). onpause () ;}if (visiblescreen. getvisibility ()! = View. Visible) {(keyguardscreen) visiblescreen). onresume () ;}} if (gonescreen! = NULL) {gonescreen. setvisibility (view. Gone);} visiblescreen. setvisibility (view. Visible); requestlayout ();}

V. recreatelockscreen Method

Private void recreatelockscreen () {/*** if mlockscreen already exists, then it is in the state of force create mlockscreen ** call onpause and cleanup methods respectively, and then removeview, then create a new one, set the visibility, and add it to viewgroup. ** the recreateunlockscreen method is similar to this method */If (mlockscreen! = NULL) {(keyguardscreen) mlockscreen ). onpause (); (keyguardscreen) mlockscreen ). cleanup (); removeview (mlockscreen);} mlockscreen = createlockscreen (); mlockscreen. setvisibility (view. invisible); addview (mlockscreen );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.