am 733fdf34: Disable keyguard while docked when the lock screen is insecure.

Merge commit '733fdf34b6a8a8e3983ff7663828a928d3c19944' into eclair-plus-aosp

* commit '733fdf34b6a8a8e3983ff7663828a928d3c19944':
  Disable keyguard while docked when the lock screen is insecure.
This commit is contained in:
Mike Lockwood
2009-09-28 16:28:36 -07:00
committed by Android Git Automerger
2 changed files with 31 additions and 4 deletions

View File

@@ -17,6 +17,7 @@
package com.android.server; package com.android.server;
import android.app.Activity; import android.app.Activity;
import android.app.KeyguardManager;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
@@ -27,6 +28,8 @@ import android.os.SystemClock;
import android.os.UEventObserver; import android.os.UEventObserver;
import android.util.Log; import android.util.Log;
import com.android.internal.widget.LockPatternUtils;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@@ -46,7 +49,11 @@ class DockObserver extends UEventObserver {
private final Context mContext; private final Context mContext;
private PowerManagerService mPowerManager; private PowerManagerService mPowerManager;
private KeyguardManager.KeyguardLock mKeyguardLock;
private boolean mKeyguardDisabled;
private LockPatternUtils mLockPatternUtils;
// The broadcast receiver which receives the result of the ordered broadcast sent when // The broadcast receiver which receives the result of the ordered broadcast sent when
// the dock state changes. The original ordered broadcast is sent with an initial result // the dock state changes. The original ordered broadcast is sent with an initial result
// code of RESULT_OK. If any of the registered broadcast receivers changes this value, e.g., // code of RESULT_OK. If any of the registered broadcast receivers changes this value, e.g.,
@@ -88,6 +95,7 @@ class DockObserver extends UEventObserver {
public DockObserver(Context context, PowerManagerService pm) { public DockObserver(Context context, PowerManagerService pm) {
mContext = context; mContext = context;
mPowerManager = pm; mPowerManager = pm;
mLockPatternUtils = new LockPatternUtils(context.getContentResolver());
init(); // set initial status init(); // set initial status
startObserving(DOCK_UEVENT_MATCH); startObserving(DOCK_UEVENT_MATCH);
} }
@@ -130,6 +138,10 @@ class DockObserver extends UEventObserver {
void systemReady() { void systemReady() {
synchronized (this) { synchronized (this) {
KeyguardManager keyguardManager =
(KeyguardManager)mContext.getSystemService(Context.KEYGUARD_SERVICE);
mKeyguardLock = keyguardManager.newKeyguardLock(TAG);
// don't bother broadcasting undocked here // don't bother broadcasting undocked here
if (mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) { if (mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
update(); update();
@@ -142,10 +154,25 @@ class DockObserver extends UEventObserver {
mHandler.sendEmptyMessage(0); mHandler.sendEmptyMessage(0);
} }
private final void updateKeyguardLocked() {
if (!mLockPatternUtils.isLockPatternEnabled()) {
if (!mKeyguardDisabled && mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
Log.d(TAG, "calling mKeyguardLock.disableKeyguard");
mKeyguardLock.disableKeyguard();
mKeyguardDisabled = true;
} else if (mKeyguardDisabled && mDockState == Intent.EXTRA_DOCK_STATE_UNDOCKED) {
Log.d(TAG, "calling mKeyguardLock.reenableKeyguard");
mKeyguardLock.reenableKeyguard();
mKeyguardDisabled = false;
}
}
}
private final Handler mHandler = new Handler() { private final Handler mHandler = new Handler() {
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
synchronized (this) { synchronized (this) {
updateKeyguardLocked();
Log.d(TAG, "Broadcasting dock state " + mDockState); Log.d(TAG, "Broadcasting dock state " + mDockState);
// Pack up the values and broadcast them to everyone // Pack up the values and broadcast them to everyone
mPowerManager.userActivityWithForce(SystemClock.uptimeMillis(), false, true); mPowerManager.userActivityWithForce(SystemClock.uptimeMillis(), false, true);

View File

@@ -3965,7 +3965,7 @@ public class WindowManagerService extends IWindowManager.Stub
// ------------------------------------------------------------- // -------------------------------------------------------------
public void disableKeyguard(IBinder token, String tag) { public void disableKeyguard(IBinder token, String tag) {
if (mContext.checkCallingPermission(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");
} }
@@ -3973,7 +3973,7 @@ public class WindowManagerService extends IWindowManager.Stub
} }
public void reenableKeyguard(IBinder token) { public void reenableKeyguard(IBinder token) {
if (mContext.checkCallingPermission(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");
} }
@@ -3999,7 +3999,7 @@ public class WindowManagerService extends IWindowManager.Stub
* @see android.app.KeyguardManager#exitKeyguardSecurely * @see android.app.KeyguardManager#exitKeyguardSecurely
*/ */
public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
if (mContext.checkCallingPermission(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");
} }