Skip to content

Commit 230a709

Browse files
Jim MillerAndroid (Google) Code Review
authored andcommitted
Merge "Fix 5863053: Add method to lock screen immediately." into ics-mr1
2 parents db2e716 + 93c518e commit 230a709

File tree

6 files changed

+37
-0
lines changed

6 files changed

+37
-0
lines changed

core/java/android/view/IWindowManager.aidl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,9 @@ interface IWindowManager
229229
* Device has a software navigation bar (separate from the status bar).
230230
*/
231231
boolean hasNavigationBar();
232+
233+
/**
234+
* Lock the device immediately.
235+
*/
236+
void lockNow();
232237
}

core/java/android/view/WindowManagerPolicy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,11 @@ interface OnKeyguardExitResult {
10271027
*/
10281028
public boolean hasNavigationBar();
10291029

1030+
/**
1031+
* Lock the device now.
1032+
*/
1033+
public void lockNow();
1034+
10301035
/**
10311036
* Print the WindowManagerPolicy's state into the given stream.
10321037
*

policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,6 +3488,12 @@ public void run() {
34883488
}
34893489
};
34903490

3491+
public void lockNow() {
3492+
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
3493+
mHandler.removeCallbacks(mScreenLockTimeout);
3494+
mHandler.post(mScreenLockTimeout);
3495+
}
3496+
34913497
private void updateLockScreenTimeout() {
34923498
synchronized (mScreenLockTimeout) {
34933499
boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly && mKeyguardMediator.isSecure());

services/java/com/android/server/DevicePolicyManagerService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import android.util.Printer;
6161
import android.util.Slog;
6262
import android.util.Xml;
63+
import android.view.IWindowManager;
6364
import android.view.WindowManagerPolicy;
6465

6566
import java.io.File;
@@ -96,6 +97,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
9697
final PowerManager.WakeLock mWakeLock;
9798

9899
IPowerManager mIPowerManager;
100+
IWindowManager mIWindowManager;
99101

100102
int mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
101103
int mActivePasswordLength = 0;
@@ -506,6 +508,14 @@ private IPowerManager getIPowerManager() {
506508
return mIPowerManager;
507509
}
508510

511+
private IWindowManager getWindowManager() {
512+
if (mIWindowManager == null) {
513+
IBinder b = ServiceManager.getService(Context.WINDOW_SERVICE);
514+
mIWindowManager = IWindowManager.Stub.asInterface(b);
515+
}
516+
return mIWindowManager;
517+
}
518+
509519
ActiveAdmin getActiveAdminUncheckedLocked(ComponentName who) {
510520
ActiveAdmin admin = mAdminMap.get(who);
511521
if (admin != null
@@ -1649,8 +1659,11 @@ public void lockNow() {
16491659
DeviceAdminInfo.USES_POLICY_FORCE_LOCK);
16501660
long ident = Binder.clearCallingIdentity();
16511661
try {
1662+
// Power off the display
16521663
mIPowerManager.goToSleepWithReason(SystemClock.uptimeMillis(),
16531664
WindowManagerPolicy.OFF_BECAUSE_OF_ADMIN);
1665+
// Ensure the device is locked
1666+
getWindowManager().lockNow();
16541667
} catch (RemoteException e) {
16551668
} finally {
16561669
Binder.restoreCallingIdentity(ident);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9415,6 +9415,10 @@ public boolean hasNavigationBar() {
94159415
return mPolicy.hasNavigationBar();
94169416
}
94179417

9418+
public void lockNow() {
9419+
mPolicy.lockNow();
9420+
}
9421+
94189422
void dumpInput(FileDescriptor fd, PrintWriter pw, boolean dumpAll) {
94199423
pw.println("WINDOW MANAGER INPUT (dumpsys window input)");
94209424
mInputManager.dump(pw);

tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,4 +471,8 @@ public void dismissKeyguard() {
471471
public boolean hasNavigationBar() {
472472
return false; // should this return something else?
473473
}
474+
475+
public void lockNow() {
476+
// TODO Auto-generated method stub
477+
}
474478
}

0 commit comments

Comments
 (0)