SoFunction
Updated on 2025-03-09

Android development method to eliminate screen locks

This article describes the method of Android development to eliminate screen locks. Share it for your reference, as follows:

Realize the screen without lock---->A state where the screen is not locked after turning on the power supply or after the lock screen time is exceeded or the power button is pressed.

After querying a lot of information and analyzing the code, we can find that the most important screen function isframework/base/policy/src/com/android/internal/policy/impl/middle.

There is a handleshow method inside:

There is a handlehide method for real lock screen implementation, and the handleshow method for real hidden lock screen implementation:

private void handleShow() {
  synchronized () {
    if (DEBUG) (TAG, "handleShow");
    if (!mSystemReady) return;
    playSounds(true);
    (); // Display the corresponding window of the lock screen interface    mShowing = true;       // Lock screen status, the lock screen is displayed    adjustUserActivityLocked();  // Uncontrolled user activity    adjustStatusBarLocked();   //Cancel the control of the status bar    try {
      ().closeSystemDialogs("lock");
    } catch (RemoteException e) {
    }
    ();
  }
}

As long as we comment out the above commented statement, the execution will be empty, and then the real lock screen implementation will be cancelled

Similarly, the handlehide method only needs to be commented

();
mShowing = false;
adjustUserActivityLocked();
AdjustStatusBarLocked()

You can cancel the real hidden lock screen implementation.

However, after doing the above, there is still a bug (problem), that is, after waking up the screen, the screen will turn from bright to dark within the specified time. We also need to make the following modifications: When pressing the POWER key, the bug of the screen changing from bright to dark is relieved.

existhandleWakeWhenReady(int keyCode)Comment out the method

pokeWakelock(); //When pressing the POWER key, the bug that the screen changes from light to dark

Then you can achieve the effect.

Another last method isThere is a variable inmExternallyEnabled, as long as it is initially changed to false, the interface needs to be displayed (doKeyguard()) will not continue to move forward, and the effect can be achieved.

For more information about Android related content, please check out the topic of this site:Android development introduction and advanced tutorial》、《Android debugging skills and solutions to common problems》、《Summary of the usage of basic Android components》、《Android View View Tips Summary》、《Android layout layout tips summary"and"Android control usage summary

I hope this article will be helpful to everyone's Android programming design.