Skip to content

Commit d6b5705

Browse files
author
Jim Miller
committed
Fix 2737842: disable keyguard API when device policy is enabled.
This fix disables KeyguardManager's enable/disable API when any device policy admin requests a policy that enforces a password. Change-Id: Idb1da16b14ed8963142f7b1f62d2b060d84ffa65
1 parent df2e2ef commit d6b5705

File tree

2 files changed

+50
-19
lines changed

2 files changed

+50
-19
lines changed

core/java/android/app/KeyguardManager.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public class KeyguardLock {
5353
*
5454
* A good place to call this is from {@link android.app.Activity#onResume()}
5555
*
56+
* Note: This call has no effect while any {@link DevicePolicyManager} is enabled
57+
* that requires a password.
58+
*
5659
* @see #reenableKeyguard()
5760
*/
5861
public void disableKeyguard() {
@@ -66,7 +69,10 @@ public void disableKeyguard() {
6669
* Reenable the keyguard. The keyguard will reappear if the previous
6770
* call to {@link #disableKeyguard()} caused it it to be hidden.
6871
*
69-
* A good place to call this is from {@link android.app.Activity#onPause()}
72+
* A good place to call this is from {@link android.app.Activity#onPause()}
73+
*
74+
* Note: This call has no effect while any {@link DevicePolicyManager} is enabled
75+
* that requires a password.
7076
*
7177
* @see #disableKeyguard()
7278
*/

services/java/com/android/server/WindowManagerService.java

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import android.Manifest;
5555
import android.app.ActivityManagerNative;
5656
import android.app.IActivityManager;
57+
import android.app.admin.DevicePolicyManager;
5758
import android.content.Context;
5859
import android.content.pm.ActivityInfo;
5960
import android.content.pm.PackageManager;
@@ -86,6 +87,7 @@
8687
import android.provider.Settings;
8788
import android.util.DisplayMetrics;
8889
import android.util.EventLog;
90+
import android.util.Log;
8991
import android.util.Slog;
9092
import android.util.SparseIntArray;
9193
import android.view.Display;
@@ -4171,13 +4173,31 @@ public void moveAppTokensToBottom(List<IBinder> tokens) {
41714173
// Misc IWindowSession methods
41724174
// -------------------------------------------------------------
41734175

4176+
private boolean allowDisableKeyguard()
4177+
{
4178+
// We fail safe if this gets called before the service has started.
4179+
boolean allow = false;
4180+
DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4181+
Context.DEVICE_POLICY_SERVICE);
4182+
if (dpm != null) {
4183+
allow = dpm.getPasswordQuality(null)
4184+
== DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
4185+
}
4186+
return allow;
4187+
}
4188+
41744189
public void disableKeyguard(IBinder token, String tag) {
41754190
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
41764191
!= PackageManager.PERMISSION_GRANTED) {
41774192
throw new SecurityException("Requires DISABLE_KEYGUARD permission");
41784193
}
4179-
synchronized (mKeyguardTokenWatcher) {
4180-
mKeyguardTokenWatcher.acquire(token, tag);
4194+
4195+
if (allowDisableKeyguard()) {
4196+
synchronized (mKeyguardTokenWatcher) {
4197+
mKeyguardTokenWatcher.acquire(token, tag);
4198+
}
4199+
} else {
4200+
Log.w(TAG, tag + ": disableKeyguard() ignored while DevicePolicyAmin is enabled.");
41814201
}
41824202
}
41834203

@@ -4186,25 +4206,30 @@ public void reenableKeyguard(IBinder token) {
41864206
!= PackageManager.PERMISSION_GRANTED) {
41874207
throw new SecurityException("Requires DISABLE_KEYGUARD permission");
41884208
}
4189-
synchronized (mKeyguardTokenWatcher) {
4190-
mKeyguardTokenWatcher.release(token);
4191-
4192-
if (!mKeyguardTokenWatcher.isAcquired()) {
4193-
// If we are the last one to reenable the keyguard wait until
4194-
// we have actaully finished reenabling until returning.
4195-
// It is possible that reenableKeyguard() can be called before
4196-
// the previous disableKeyguard() is handled, in which case
4197-
// neither mKeyguardTokenWatcher.acquired() or released() would
4198-
// be called. In that case mKeyguardDisabled will be false here
4199-
// and we have nothing to wait for.
4200-
while (mKeyguardDisabled) {
4201-
try {
4202-
mKeyguardTokenWatcher.wait();
4203-
} catch (InterruptedException e) {
4204-
Thread.currentThread().interrupt();
4209+
4210+
if (allowDisableKeyguard()) {
4211+
synchronized (mKeyguardTokenWatcher) {
4212+
mKeyguardTokenWatcher.release(token);
4213+
4214+
if (!mKeyguardTokenWatcher.isAcquired()) {
4215+
// If we are the last one to reenable the keyguard wait until
4216+
// we have actaully finished reenabling until returning.
4217+
// It is possible that reenableKeyguard() can be called before
4218+
// the previous disableKeyguard() is handled, in which case
4219+
// neither mKeyguardTokenWatcher.acquired() or released() would
4220+
// be called. In that case mKeyguardDisabled will be false here
4221+
// and we have nothing to wait for.
4222+
while (mKeyguardDisabled) {
4223+
try {
4224+
mKeyguardTokenWatcher.wait();
4225+
} catch (InterruptedException e) {
4226+
Thread.currentThread().interrupt();
4227+
}
42054228
}
42064229
}
42074230
}
4231+
} else {
4232+
Log.w(TAG, "reenableKeyguard() ignored while DevicePolicyAmin is enabled.");
42084233
}
42094234
}
42104235

0 commit comments

Comments
 (0)