Lock screen without disabling fingerprint
Asked Answered
O

4

10

I have the following problem. I'm trying to make an app that locks the screen. The method via DevicePolicyManager works very well. So far so good. But when I lock my phone with DPM the fingerprint unlocking method is disabling and I have to enter my pattern (or PIN or whatever I set) to unlock the phone. If I lock it the normal way (ie with power button) the fingerprint unlocking works.

So my question is How to lock the screen programmatically and be able to unlock it afterwards via fingerprint?

PS: I have an galaxy s5 mini with marshmallow lineage os

Outside answered 19/3, 2017 at 12:2 Comment(0)
V
5

That is the normal flow. It takes the device to restarted state where the device will ask for a pattern or password. Google have not provided any api for this. You can check any app in PlayStore which has locking feature will behave like this.

Edited: For the below queries you have asked response is shared here

  1. How can a user lock his phone without using the power button (through an app for example) and still be able to unlock it using fingerprint?

    There's intentionally no API for apps to call to lock the device.

  2. Is there a security reason/concern around this?

    Yes, there's a DOS (denial of service) concern if we allow apps to lock the device. Either intentional or accidental (app bug).

Found it here[https://code.google.com/p/android/issues/detail?id=79735#c115]

I think you need to search for how to lock with app shortcut and not with power button. Atleast I could help to this level.

Viceregent answered 19/3, 2017 at 14:50 Comment(9)
Thanks for your answer but I have to disagree. For example the app "greenify" let the user create a shortcut which locks the screen but doesn't put it to restarted stateOutside
Just now tried it. It seems they take device to sleep mode and not to lock state. You need to lock the device right?Viceregent
Sleep mode is OK too because my device locks immediately after screen turning off (but keeps fingerprint working). How do I put the device in sleep mode?Outside
This could help link but greenify don't lock the screen immediately. I get a text message saying "Turning off the screen" in bottom left.Viceregent
With your link you mean the part with keyguard? It doesn't put the device in sleep mode...Outside
As for greenify, it has to close the chosen apps first before it goes in sleep mode but somehow it does go into sleep mode, do you know how?Outside
I found a way, maybe it's interesting for you to know.. Of the device is rooted (like mine) one can start a shell stream and send "input keyevent 26" which kinda presses the power buttonOutside
@Outside shell method is bit slow.. i can feel the delay even with "sendevent"Theatrician
Yes, there's a DOS (denial of service) concern if we allow apps to lock the device. This argument does not make any sense taking into account there already is a way to lock device now. All that people want is to have a softer version of it.Playreader
T
5

Notice how the apex launcher or nova launcher got it way around. screen lock through apex launcher or nova launcher doesn't disable fingerprint scanner!

What it actually does is that it sets the screen to complete black i.e. soft lock (which gives user a false impression of screen off) and then after 5-10 seconds the display actually goes off due to time-out.

other app which implemented the same functionality OFF+ (Screen Off / Fingerprint unlock support).(I guess it modifys "lock screen timeout"


If the phone is rooted then a shell command can be executed to simulate the power key su input keyevent 26 but there might be a fraction of delay.


well, if some root user is looking, there's also a xposed module which solves this issue FingerprintEnabler

Theatrician answered 9/10, 2017 at 16:9 Comment(0)
V
3

I would like to add some points to the JerryGoyal's excellent answer.


Below is the screenshot from Microsoft Launcher which shows the two ways to lock the screen. It clearly states that the method via Device Policy Manager will not work with fingerprint.

A work around is done by showing a black screen until the screen times out.

In the next screen it asks for permission to Modify system settings to alter the screen timeout period.

Microsoft Launcher

Vulpecula answered 11/6, 2018 at 11:35 Comment(0)
P
1

From https://issuetracker.google.com/issues/37010802#comment148 (posted Aug 9, 2018 08:26AM):

Android 9 finally added a solution for this (or a workaround, it depends on how you look at it). A new AccessibilityService global action was added for locking the device [1], [2]. Nova Launcher already has a screen lock method using this service action in the latest beta, and it allows for locking the device and keeping fingerprint unlock and SmartLock working.

What sucks, though, is that users of your app have to enable the accessibility service for your app. And having any accessibility service enabled breaks Snackbar animation [3] (it no longer slides on the screen, it just appears there without any animation).

[1] https://developer.android.com/about/versions/pie/android-9.0#a11y-convenience-actions

[2] https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#GLOBAL_ACTION_LOCK_SCREEN

[3] https://issuetracker.google.com/issues/37092972

Playreader answered 15/11, 2020 at 16:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.