Android Keyguard Lock
Asked Answered
P

2

5

I am working on an application that will replace the default lock screen (swipe to unlock) for android devices. I have successfully done this by disabling the keyguard manager and showing my activity using the broadcast receiver for screen OFF and screen ON intent. Now, the problem is when I set the default screen lock again for any reason then my application would not disable the keyguard unless I force close it and launch it again.

      km = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
      if( km.inKeyguardRestrictedInputMode()) {
       //it is locked
          km = (KeyguardManager) getApplicationContext().getSystemService(KEYGUARD_SERVICE);
      kl=km.newKeyguardLock("com.example.helloworld.MainActivity");
      kl.disableKeyguard();
      } else {
          Intent i = getIntent();
          i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          getApplicationContext().startActivity(i);
      }
Portmanteau answered 17/10, 2012 at 20:28 Comment(2)
If you receive the broadcast for screen off, can't you check with isKeyGuardLocked() if it is locked, and then immediately disable it again?Resort
I am already doing it, but it do not disabling it again for unknown reasons. Once I force close the application and launch it again then everything runs fine.Portmanteau
T
4

You cannot replace the lock screen with a user application. Anything you do is a hack and may or may not work on some device, and will likely break with new releases. You can create something that looks like a screen lock, but it won't work like one. Additionally, in recent versions of Android (post-ICS), unlocking the screen does extra things like unlocking the credential storage, which your app cannot possibly do (since it doesn't have system permissions).

If you really want to replace the screen lock, you need to build your own Android ROM, modifying/replacing the stock one.

Torquemada answered 18/10, 2012 at 2:39 Comment(2)
I got it. I have tested GO launcher and it has the same problem that my app is facing. Thanks for the answer :)Portmanteau
@Nikolay Very well said.Dabber
K
4

The accepted answer may be out of date.

As a result, it's theoretically possible to secure the actual lock screen using an app-generated password (providing real security), float a custom lock screen above the android lock screen, and -- when a proper password is provided -- unlock and dismiss the real lock screen. Finally, you would use a receiver to restore or clear the password on relevant events like SCREEN_OFF or SCREEN_ON -- the latter could automatically clear the password if a timeout was not yet reached.

FWIW, I don't recommend this approach since a crash or uninstall would leave a user with a device locked by a password they do not know.

Kaiulani answered 8/6, 2015 at 15:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.