6

How do I unlock phone screen when some event happens?I tried the following code but it does not unlock the screeen . By unlock I mean bypass PIN or pattern

Am using following code and its get triggered when a sms is received.

private void unlockScreen(Context context){
        Log.d("dialog", "unlocking screen now");
        PowerManager powermanager = ((PowerManager)context.getSystemService(Context.POWER_SERVICE));
        WakeLock wakeLock = powermanager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag");
        wakeLock.acquire();
        Window wind = DialogActivity.this.getWindow();
        wind.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
        wind.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        wind.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);


    }

Screen is powered on but the user has to enter PIN/pattern.How do I get over it?

TN888
  • 7,659
  • 9
  • 48
  • 84
user93796
  • 18,749
  • 31
  • 94
  • 150
  • You don't! Write a custom ROM. What would be the point of a lock pattern or PIN if the OS allowed 3rd party apps to bypass it? – Simon Jul 25 '13 at 18:05
  • I think that this would be a huge security problem. I would probably place money on you can't do this. I only say this because someone could build a stealth app to unlock the screen when an in coming command came in or something. – ObieMD5 Jul 25 '13 at 18:05
  • The short: You can't get over it. It would raise a huge security issue otherwise if an app could be able to bypass the unlock screen. – ConcurrentHashMap Jul 25 '13 at 18:05
  • Does this help http://stackoverflow.com/questions/8073631/android-wake-unlock-phone – sevensevens Jul 25 '13 at 18:06
  • if we cant then how does our phone gets automaticaly unlocked when there is a incoming call? – user93796 Jul 25 '13 at 18:38
  • because the service montioring for a call is probaly running as root also that has access to device management. – ObieMD5 Jul 25 '13 at 18:41
  • I dont want to permanently bypass keyguard, just for that moment .For example when a alarm is raised (eg wake up alarm) i can dismiss /snooze it whithot unlocking screen .How??I want to achive the same behaviour.I want start a dialog which should be on top on locked screen. I can click button on dialog without unlocking .Is this possible? – user93796 Jul 25 '13 at 18:42
  • @ObieMD5 can u plz reply to my previous comment? – user93796 Jul 25 '13 at 18:43
  • What comment? you asked about incoming calls. I answered it with the one below that. – ObieMD5 Jul 25 '13 at 18:50
  • @ObieMD5 asked a sperate question for this :http://stackoverflow.com/questions/17866419/how-to-start-a-dialog-like-alarm-dimiss-snooze-that-can-be-clicked-without-un – user93796 Jul 25 '13 at 18:53

1 Answers1

4

Straight from the android API Site for disableKeyguard():

Disable the keyguard from showing. If the keyguard is currently showing, hide it. The keyguard will be prevented from showing again until reenableKeyguard() is called. A good place to call this is from onResume() Note: This call has no effect while any DevicePolicyManager is enabled that requires a password.

Based off that bolded statement I would probably say that you cannot do that without a password. The only way passed that is if you had yourself(app) added to the phone as a device admin, then you could control that from your device admin application of removing the password, wiping it etc.

Source : KeyguardManager.KeyguardLock & DevicePolicyManager

EDIT

I found the source code of the LockPatternUtils (I know it is from older version, but I doubt it has changed much) that is in part pattern locks and it has DevicePolicyManager all over it. I believe it has an internal service running as root in the system that does all the work. So without being a device admin, you do not even have authority to unlock the phone when it has a security setting for it.

ObieMD5
  • 2,684
  • 1
  • 16
  • 26
  • I dont want to permanently bypass keyguard, just for that moment .For example when a alarm is raised (eg wake up alarm) i can dismiss /snooze it whithot unlocking screen .How??I want to achive the same behaviour.I start a dialog which should be on top on locked screen.Is this possible? – user93796 Jul 25 '13 at 18:41
  • Ask another question on SO with the question that states "How do add an event to the lockscreen such as an alarm with the ability to dismiss/snooze without unlocking the screen. My thoughts on it is you have to create a widget that can be displayed on the lockscreen but I cannot answer that question. Best bet is to ask that question in a new question. – ObieMD5 Jul 25 '13 at 18:47
  • http://stackoverflow.com/questions/17866419/how-to-start-a-dialog-like-alarm-dimiss-snooze-that-can-be-clicked-without-un – user93796 Jul 25 '13 at 18:52
  • @user93796 please mark the question as answered so others will see this as the correct answer. Thank you and good luck on your other quesiton. – ObieMD5 Jul 25 '13 at 20:08