简体   繁体   中英

Unlock the lock screen

I am writing an application to manage or customize the unlock screen of the android devices. It works in the following steps:

  1. The user locks the screen using the power button.
  2. User attempts to unlock the screen, thus pressing the power button again
  3. My activity pops up -- The screen is still locked
  4. The user answers a question and if the answer is correct the screen unlocks

I have created an activity for the third step and added the following code to its onCreate method:

Window window = getWindow();

window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE);

This works properly and exactly as I had hoped. My problem is with the fourth step. I have searched and found a number of solutions, but none of them are doing it for me.

How to lock/unlock phone programmatically -- This is just a way to show an activity on top of the lock screen. It does not unlock it.

Android screen lock/ unlock programatically -- This solution is not only deprecated but it's also really unreliable. It does not unlock the screen, but creates another lock and unlocks that. So using this you can access the applications but it's impossible to access the sensitive settings. (Try it!)

I tried registering my application as a device administrator. That didn't help me as well. I can change the setting but I cannot unlock the screen.

mehrdadjg

I looked Android Api Source Code(level 23) I don't know how to use KeyguardService's methods with device administrator or root permissions but Android use this service(com.android.systemui.keyguard.KeyguardService.java). Android bind this service(IPC with aidl file) and use it.

The other side...

Keyguard controller class, its name is KeyguardViewMediator. Under "com.android.systemui.keyguard" package. ( Maybe review this lines 1157, 1433)

I don't know how to make unlock action, but Android use this class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM