Skip to content

Commit 93c518e

Browse files
author
Jim Miller
committed
Fix 5863053: Add method to lock screen immediately.
This fixes a bug where the device fails to lock when DevicePolicyManagerService requests the device to be locked and the screen was off because the user hit the power button. The change allows DPMS to directly invoke screen lock, bypasssing the screen state. Change-Id: Iecdda6fc61e9c519119de495be23c69c3b983921
1 parent ff321d4 commit 93c518e

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
@@ -1022,6 +1022,11 @@ interface OnKeyguardExitResult {
10221022
*/
10231023
public boolean hasNavigationBar();
10241024

1025+
/**
1026+
* Lock the device now.
1027+
*/
1028+
public void lockNow();
1029+
10251030
/**
10261031
* Print the WindowManagerPolicy's state into the given stream.
10271032
*

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
@@ -9411,6 +9411,10 @@ public boolean hasNavigationBar() {
94119411
return mPolicy.hasNavigationBar();
94129412
}
94139413

9414+
public void lockNow() {
9415+
mPolicy.lockNow();
9416+
}
9417+
94149418
void dumpInput(FileDescriptor fd, PrintWriter pw, boolean dumpAll) {
94159419
pw.println("WINDOW MANAGER INPUT (dumpsys window input)");
94169420
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)