Merge "Fix 2737842: disable keyguard API when device policy is enabled." into froyo
This commit is contained in:
@@ -53,6 +53,9 @@ public class KeyguardManager {
|
|||||||
*
|
*
|
||||||
* A good place to call this is from {@link android.app.Activity#onResume()}
|
* A good place to call this is from {@link android.app.Activity#onResume()}
|
||||||
*
|
*
|
||||||
|
* Note: This call has no effect while any {@link DevicePolicyManager} is enabled
|
||||||
|
* that requires a password.
|
||||||
|
*
|
||||||
* @see #reenableKeyguard()
|
* @see #reenableKeyguard()
|
||||||
*/
|
*/
|
||||||
public void disableKeyguard() {
|
public void disableKeyguard() {
|
||||||
@@ -68,6 +71,9 @@ public class KeyguardManager {
|
|||||||
*
|
*
|
||||||
* A good place to call this is from {@link android.app.Activity#onPause()}
|
* A good place to call this is from {@link android.app.Activity#onPause()}
|
||||||
*
|
*
|
||||||
|
* Note: This call has no effect while any {@link DevicePolicyManager} is enabled
|
||||||
|
* that requires a password.
|
||||||
|
*
|
||||||
* @see #disableKeyguard()
|
* @see #disableKeyguard()
|
||||||
*/
|
*/
|
||||||
public void reenableKeyguard() {
|
public void reenableKeyguard() {
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ import com.android.server.am.BatteryStatsService;
|
|||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.ActivityManagerNative;
|
import android.app.ActivityManagerNative;
|
||||||
import android.app.IActivityManager;
|
import android.app.IActivityManager;
|
||||||
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@@ -86,6 +87,7 @@ import android.os.TokenWatcher;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.EventLog;
|
import android.util.EventLog;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
import android.util.SparseIntArray;
|
import android.util.SparseIntArray;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
@@ -4171,13 +4173,31 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
// Misc IWindowSession methods
|
// Misc IWindowSession methods
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
|
|
||||||
|
private boolean allowDisableKeyguard()
|
||||||
|
{
|
||||||
|
// We fail safe if this gets called before the service has started.
|
||||||
|
boolean allow = false;
|
||||||
|
DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
|
||||||
|
Context.DEVICE_POLICY_SERVICE);
|
||||||
|
if (dpm != null) {
|
||||||
|
allow = dpm.getPasswordQuality(null)
|
||||||
|
== DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
|
||||||
|
}
|
||||||
|
return allow;
|
||||||
|
}
|
||||||
|
|
||||||
public void disableKeyguard(IBinder token, String tag) {
|
public void disableKeyguard(IBinder token, String tag) {
|
||||||
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
|
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
|
||||||
!= PackageManager.PERMISSION_GRANTED) {
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
throw new SecurityException("Requires DISABLE_KEYGUARD permission");
|
throw new SecurityException("Requires DISABLE_KEYGUARD permission");
|
||||||
}
|
}
|
||||||
synchronized (mKeyguardTokenWatcher) {
|
|
||||||
mKeyguardTokenWatcher.acquire(token, tag);
|
if (allowDisableKeyguard()) {
|
||||||
|
synchronized (mKeyguardTokenWatcher) {
|
||||||
|
mKeyguardTokenWatcher.acquire(token, tag);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, tag + ": disableKeyguard() ignored while DevicePolicyAmin is enabled.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4186,25 +4206,30 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
!= PackageManager.PERMISSION_GRANTED) {
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
throw new SecurityException("Requires DISABLE_KEYGUARD permission");
|
throw new SecurityException("Requires DISABLE_KEYGUARD permission");
|
||||||
}
|
}
|
||||||
synchronized (mKeyguardTokenWatcher) {
|
|
||||||
mKeyguardTokenWatcher.release(token);
|
|
||||||
|
|
||||||
if (!mKeyguardTokenWatcher.isAcquired()) {
|
if (allowDisableKeyguard()) {
|
||||||
// If we are the last one to reenable the keyguard wait until
|
synchronized (mKeyguardTokenWatcher) {
|
||||||
// we have actaully finished reenabling until returning.
|
mKeyguardTokenWatcher.release(token);
|
||||||
// It is possible that reenableKeyguard() can be called before
|
|
||||||
// the previous disableKeyguard() is handled, in which case
|
if (!mKeyguardTokenWatcher.isAcquired()) {
|
||||||
// neither mKeyguardTokenWatcher.acquired() or released() would
|
// If we are the last one to reenable the keyguard wait until
|
||||||
// be called. In that case mKeyguardDisabled will be false here
|
// we have actaully finished reenabling until returning.
|
||||||
// and we have nothing to wait for.
|
// It is possible that reenableKeyguard() can be called before
|
||||||
while (mKeyguardDisabled) {
|
// the previous disableKeyguard() is handled, in which case
|
||||||
try {
|
// neither mKeyguardTokenWatcher.acquired() or released() would
|
||||||
mKeyguardTokenWatcher.wait();
|
// be called. In that case mKeyguardDisabled will be false here
|
||||||
} catch (InterruptedException e) {
|
// and we have nothing to wait for.
|
||||||
Thread.currentThread().interrupt();
|
while (mKeyguardDisabled) {
|
||||||
|
try {
|
||||||
|
mKeyguardTokenWatcher.wait();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "reenableKeyguard() ignored while DevicePolicyAmin is enabled.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user