How do we retain the seamless fingerprint unlocking effect after using DevicePolicyManager to perform lockNow() in Android 6.0?
Assuming on devices with fingerprint scanner and the app calling lockNow() has "USES_POLICY_FORCE_LOCK" and had been granted Device Administrator status.
This is the documentation for the lockNow() function:
public void lockNow ()
Make the device lock immediately, as if the lock screen timeout has expired at the point of this call.
The calling device admin must have requested USES_POLICY_FORCE_LOCK to be able to call this method; if it has not, a security exception will be thrown.
Gaining Device Administrator status and performing lock just fine. For sake of reference, see this SO question for the approach I used.
The problem is after the phone locks, the fingerprint scanner no longer smoothly unlocks the phone. Instead, the fingerprint scanner prompts me to input the fallback PIN code. Is there something new I have to do in Android 6.0 in order to retain the fingerprint unlocking effect after performing a lockNow() call?
I have looked at all the DevicePolicyManager flags (in the documentation) and it seems to be offering disabling of things rather than enabling of things.
Thanks!
Looks like Google has marked it Working as Intended without any proper explanation.
https://code.google.com/p/android/issues/detail?id=79735#c110
and also here
https://code.google.com/p/android/issues/detail?id=191955#c23
So we currently we have no way of locking the screen programmatically while keeping smart lock working. They also say that "developers are using it incorrectly". Not sure if they are joking or serious.
EDIT : some unsatisfactory explanation here https://code.google.com/p/android/issues/detail?id=79735#c115
As mentioned in this link: https://code.google.com/p/android/issues/detail?id=79735, this seems to be a problem with smart lock, and not just the google imprint (fingerprint scanner).
If you can rely on root privileges you can probably use: PowerManager.goToSleep(0);
Without root privileges it looks like there is no better solution as of today.
version: android 4.4.2
I use keyguardLock.disableKeyguard() unlock the screen, then use keyguardManager.inKeyguardRestrictedInputMode() print screen lock state, it always return true,but the powerManager.isScreenOn() return true,and i can use my phone normally.
ps: I do lock and unlock in a android service.
Is there any thing wrong when use disableKeyguard()?
The keyguardLock is deprecated starting from API 13. Please use the FLAG_DISMISS_KEYGUARD and/or FLAG_SHOW_WHEN_LOCKED. See here
I have written an application that locks android phone remotely. That is when a special code is sent from server then application locks the phone based on the special code. This is the code I am using.
if (!mDPM.isAdminActive(mDeviceAdminSample)) {
// try to become active – must happen here in this activity, to get result
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,mDeviceAdminSample);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,"Admin is added to do security operation.");
startActivityForResult(intent, 0);
} else {
// Already is a device administrator, can do security operations now.
mDPM.lockNow();
}
The above code is working and it's locking the phone.
I am able to unlock the phone by entering password from soft keypad. Is there any way to unlock it through code?
My question is how to unlock the phone through code.(This unlocking should be done remotely in the manner I explained for locking)
I believe you cannot override the built-in screen-lock unless you make your own device like Samsung and HTC do. However, by having your customers use your own screen-lock-like app you probably can achieve what you are trying to do.
I do not think your remote unlock goal is achievable.
The way Android is set up, is that many apps may have Device Administrator privilege, and any Device Administrator can issue a lock command, but the unlock has to come from the user.
I can suggest one thing you to simplify this: Your app could try to remove the key lock password, and then the user can use the device without a code simply by sliding a finger on the screen.
Now there is a snag in what I suggested, if your app is not the only device administrator. In that case, some other administrator app could set a minimum password length (or some other password restriction) which would prevent your app from clearing the screen lock password.
If your goal is to help a user that forgot his/her screen lock password, then your server could invent a new password, inform the user what the new password is, and also send the new password to your app and your app could apply the password. The user can then unlock the phone. Do not worry, it is not as complicated as it sounds.
Sorry to write that - There is no way to unlock phone from code. If you find any way to do that - no warranty to work. So there is no way to remote unlock, writing custom lock screens, etc.
You need to use mDPM.resetPassword("", 0)
http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html#resetPassword(java.lang.String, int)
When set password string as "", current password is replaced with empty values & screen lock disappears.
try this
KeyguardManager manager = (KeyguardManager)context.getSystemService(KEYGUARD_SERVICE);
kl = manager.newKeyguardLock("my-remote-app");
kl.disableKeyguard();
//for reenabling keyguard on exit (if you need)
onDestroy() {
kl.reenableKeyguard();
}
this works <=ICS.
This is a deprecated api, they suggested you to use the flags from WindowManager for similar effect. Although I failed to generate the similar effect using the WindowManger.
Hope this helps,
Please note that I'm not an Android developer, but:
If you look at this, it looks like you can ask the WindowManager to dismiss the key guard if you have the right permission, even if you're in "secure lock" mode.
As per my knowledge, we cant unlock password protected phone programatically.
One solution would be to write a "custom lockscreen".
Sure, it's not the easiest way, but it would work as you can do everything you want with your own lockscreen.
If you are considering that solution, feel free to contact me, I'll give you some useful links.
Cheers!
I'm trying to lock/unlock the screen using Keyguard and everything works as expected when using the KeyguardManager.KeyguardLock disableKeyguard() and reenableKeyguard() functions.
I've tried it with "regular" slider lock, pattern, PIN and password lock and
they are all disabled and enabled when the appropriate functions are called.
The only thing that worries me is that the documentation of these functions has the following statement:
This call has no effect while any DevicePolicyManager is enabled that requires a password
I'm not sure I understand exactly in which cases this might not work and wouldn't like to find out after I release my application...
I tried reading a bit more on DevicePolicyManager but couldn't find any way to find out if there is an active DevicePolicyManager that will prevent the enable/disable screen lock functions to work.
Can you please describe a scenario that this will not work, and how I can identify these cases ?
The most common form of this "in the wild" is the user having a corporate Exchange device admin that requires they have a password. I believe the DeviceAdmin in the APIDemos is sufficient to test against this.
I'd like to keep the screen on whenever one of my Activities are running and the phone is plugged in to a power source. I know that Wakelocks are tricky, so I'm looking for an example or some documentation on how to accomplish this specific goal.
Don't use wake locks for this -- just set and clear the window flag WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON based on whether the device is currently plugged in. You can set the flag with Activity.getWindow().addFlags().
So the code would be
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
A WakeLockisn't that tricky, just make sure to check that it isn't already held when you call acquire() and make sure it is held when you call release(). You also want to make sure you have the android.permission.WAKE_LOCK permission defined in your manifest file.
If you only want to acquire the WakeLock when the phone is plugged in, you can register a BroadcastReceiver that watches for the android.intent.action.ACTION_POWER_CONNECTED and android.intent.action.ACTION_POWER_DISCONNECTED intents. I haven't used these myself, so there may be some application permission you need to get before these intents will actually work.