Merge "Fix 5863053: Add method to lock screen immediately." into ics-mr1

This commit is contained in:
Jim Miller
2012-01-18 16:44:52 -08:00
committed by Android (Google) Code Review
6 changed files with 37 additions and 0 deletions

View File

@ -229,4 +229,9 @@ interface IWindowManager
* Device has a software navigation bar (separate from the status bar). * Device has a software navigation bar (separate from the status bar).
*/ */
boolean hasNavigationBar(); boolean hasNavigationBar();
/**
* Lock the device immediately.
*/
void lockNow();
} }

View File

@ -1027,6 +1027,11 @@ public interface WindowManagerPolicy {
*/ */
public boolean hasNavigationBar(); public boolean hasNavigationBar();
/**
* Lock the device now.
*/
public void lockNow();
/** /**
* Print the WindowManagerPolicy's state into the given stream. * Print the WindowManagerPolicy's state into the given stream.
* *

View File

@ -3488,6 +3488,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
} }
}; };
public void lockNow() {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
mHandler.removeCallbacks(mScreenLockTimeout);
mHandler.post(mScreenLockTimeout);
}
private void updateLockScreenTimeout() { private void updateLockScreenTimeout() {
synchronized (mScreenLockTimeout) { synchronized (mScreenLockTimeout) {
boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly && mKeyguardMediator.isSecure()); boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly && mKeyguardMediator.isSecure());

View File

@ -60,6 +60,7 @@ import android.util.PrintWriterPrinter;
import android.util.Printer; import android.util.Printer;
import android.util.Slog; import android.util.Slog;
import android.util.Xml; import android.util.Xml;
import android.view.IWindowManager;
import android.view.WindowManagerPolicy; import android.view.WindowManagerPolicy;
import java.io.File; import java.io.File;
@ -96,6 +97,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
final PowerManager.WakeLock mWakeLock; final PowerManager.WakeLock mWakeLock;
IPowerManager mIPowerManager; IPowerManager mIPowerManager;
IWindowManager mIWindowManager;
int mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; int mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
int mActivePasswordLength = 0; int mActivePasswordLength = 0;
@ -506,6 +508,14 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
return mIPowerManager; return mIPowerManager;
} }
private IWindowManager getWindowManager() {
if (mIWindowManager == null) {
IBinder b = ServiceManager.getService(Context.WINDOW_SERVICE);
mIWindowManager = IWindowManager.Stub.asInterface(b);
}
return mIWindowManager;
}
ActiveAdmin getActiveAdminUncheckedLocked(ComponentName who) { ActiveAdmin getActiveAdminUncheckedLocked(ComponentName who) {
ActiveAdmin admin = mAdminMap.get(who); ActiveAdmin admin = mAdminMap.get(who);
if (admin != null if (admin != null
@ -1649,8 +1659,11 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
DeviceAdminInfo.USES_POLICY_FORCE_LOCK); DeviceAdminInfo.USES_POLICY_FORCE_LOCK);
long ident = Binder.clearCallingIdentity(); long ident = Binder.clearCallingIdentity();
try { try {
// Power off the display
mIPowerManager.goToSleepWithReason(SystemClock.uptimeMillis(), mIPowerManager.goToSleepWithReason(SystemClock.uptimeMillis(),
WindowManagerPolicy.OFF_BECAUSE_OF_ADMIN); WindowManagerPolicy.OFF_BECAUSE_OF_ADMIN);
// Ensure the device is locked
getWindowManager().lockNow();
} catch (RemoteException e) { } catch (RemoteException e) {
} finally { } finally {
Binder.restoreCallingIdentity(ident); Binder.restoreCallingIdentity(ident);

View File

@ -9415,6 +9415,10 @@ public class WindowManagerService extends IWindowManager.Stub
return mPolicy.hasNavigationBar(); return mPolicy.hasNavigationBar();
} }
public void lockNow() {
mPolicy.lockNow();
}
void dumpInput(FileDescriptor fd, PrintWriter pw, boolean dumpAll) { void dumpInput(FileDescriptor fd, PrintWriter pw, boolean dumpAll) {
pw.println("WINDOW MANAGER INPUT (dumpsys window input)"); pw.println("WINDOW MANAGER INPUT (dumpsys window input)");
mInputManager.dump(pw); mInputManager.dump(pw);

View File

@ -471,4 +471,8 @@ public class BridgeWindowManager implements IWindowManager {
public boolean hasNavigationBar() { public boolean hasNavigationBar() {
return false; // should this return something else? return false; // should this return something else?
} }
public void lockNow() {
// TODO Auto-generated method stub
}
} }