Skip to content

Commit 67ae551

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Keep activities stopped while the lock screen is up."
2 parents cbba37c + ff5b158 commit 67ae551

File tree

4 files changed

+98
-13
lines changed

4 files changed

+98
-13
lines changed

core/java/android/app/ActivityManagerNative.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
10001000
}
10011001
return true;
10021002
}
1003-
1003+
10041004
case GOING_TO_SLEEP_TRANSACTION: {
10051005
data.enforceInterface(IActivityManager.descriptor);
10061006
goingToSleep();
@@ -1015,6 +1015,13 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
10151015
return true;
10161016
}
10171017

1018+
case SET_LOCK_SCREEN_SHOWN_TRANSACTION: {
1019+
data.enforceInterface(IActivityManager.descriptor);
1020+
setLockScreenShown(data.readInt() != 0);
1021+
reply.writeNoException();
1022+
return true;
1023+
}
1024+
10181025
case SET_DEBUG_APP_TRANSACTION: {
10191026
data.enforceInterface(IActivityManager.descriptor);
10201027
String pn = data.readString();
@@ -2912,6 +2919,17 @@ public void wakingUp() throws RemoteException
29122919
data.recycle();
29132920
reply.recycle();
29142921
}
2922+
public void setLockScreenShown(boolean shown) throws RemoteException
2923+
{
2924+
Parcel data = Parcel.obtain();
2925+
Parcel reply = Parcel.obtain();
2926+
data.writeInterfaceToken(IActivityManager.descriptor);
2927+
data.writeInt(shown ? 1 : 0);
2928+
mRemote.transact(SET_LOCK_SCREEN_SHOWN_TRANSACTION, data, reply, 0);
2929+
reply.readException();
2930+
data.recycle();
2931+
reply.recycle();
2932+
}
29152933
public void setDebugApp(
29162934
String packageName, boolean waitForDebugger, boolean persistent)
29172935
throws RemoteException

core/java/android/app/IActivityManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ public void showWaitingForDebugger(IApplicationThread who, boolean waiting)
205205
// Note: probably don't want to allow applications access to these.
206206
public void goingToSleep() throws RemoteException;
207207
public void wakingUp() throws RemoteException;
208-
208+
public void setLockScreenShown(boolean shown) throws RemoteException;
209+
209210
public void unhandledBack() throws RemoteException;
210211
public ParcelFileDescriptor openContentUri(Uri uri) throws RemoteException;
211212
public void setDebugApp(
@@ -588,4 +589,5 @@ private WaitResult(Parcel source) {
588589
int GET_CURRENT_USER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+144;
589590
int TARGET_TASK_AFFINITY_MATCHES_ACTIVITY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+145;
590591
int NAVIGATE_UP_TO_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+146;
592+
int SET_LOCK_SCREEN_SHOWN_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+147;
591593
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ private void handleSetHidden(boolean isHidden) {
567567
synchronized (KeyguardViewMediator.this) {
568568
if (mHidden != isHidden) {
569569
mHidden = isHidden;
570+
updateActivityLockScreenState();
570571
adjustUserActivityLocked();
571572
adjustStatusBarLocked();
572573
}
@@ -1162,6 +1163,14 @@ private void playSounds(boolean locked) {
11621163
}
11631164
}
11641165

1166+
private void updateActivityLockScreenState() {
1167+
try {
1168+
ActivityManagerNative.getDefault().setLockScreenShown(
1169+
mShowing && !mHidden);
1170+
} catch (RemoteException e) {
1171+
}
1172+
}
1173+
11651174
/**
11661175
* Handle message sent by {@link #showLocked}.
11671176
* @see #SHOW
@@ -1173,6 +1182,7 @@ private void handleShow() {
11731182

11741183
mKeyguardViewManager.show();
11751184
mShowing = true;
1185+
updateActivityLockScreenState();
11761186
adjustUserActivityLocked();
11771187
adjustStatusBarLocked();
11781188
try {
@@ -1207,6 +1217,7 @@ private void handleHide() {
12071217

12081218
mKeyguardViewManager.hide();
12091219
mShowing = false;
1220+
updateActivityLockScreenState();
12101221
adjustUserActivityLocked();
12111222
adjustStatusBarLocked();
12121223
}
@@ -1324,6 +1335,7 @@ private void handleVerifyUnlock() {
13241335
if (DEBUG) Log.d(TAG, "handleVerifyUnlock");
13251336
mKeyguardViewManager.verifyUnlock();
13261337
mShowing = true;
1338+
updateActivityLockScreenState();
13271339
}
13281340
}
13291341

services/java/com/android/server/am/ActivityManagerService.java

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,16 @@ private class Identity {
696696
*/
697697
boolean mSleeping = false;
698698

699+
/**
700+
* State of external calls telling us if the device is asleep.
701+
*/
702+
boolean mWentToSleep = false;
703+
704+
/**
705+
* State of external call telling us if the lock screen is shown.
706+
*/
707+
boolean mLockScreenShown = false;
708+
699709
/**
700710
* Set if we are shutting down the system, similar to sleeping.
701711
*/
@@ -6656,17 +6666,26 @@ public boolean isSleeping() {
66566666
}
66576667

66586668
public void goingToSleep() {
6669+
if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER)
6670+
!= PackageManager.PERMISSION_GRANTED) {
6671+
throw new SecurityException("Requires permission "
6672+
+ android.Manifest.permission.DEVICE_POWER);
6673+
}
6674+
66596675
synchronized(this) {
6660-
mSleeping = true;
6676+
mWentToSleep = true;
66616677
mWindowManager.setEventDispatching(false);
66626678

6663-
mMainStack.stopIfSleepingLocked();
6679+
if (!mSleeping) {
6680+
mSleeping = true;
6681+
mMainStack.stopIfSleepingLocked();
66646682

6665-
// Initialize the wake times of all processes.
6666-
checkExcessivePowerUsageLocked(false);
6667-
mHandler.removeMessages(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
6668-
Message nmsg = mHandler.obtainMessage(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
6669-
mHandler.sendMessageDelayed(nmsg, POWER_CHECK_DELAY);
6683+
// Initialize the wake times of all processes.
6684+
checkExcessivePowerUsageLocked(false);
6685+
mHandler.removeMessages(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
6686+
Message nmsg = mHandler.obtainMessage(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
6687+
mHandler.sendMessageDelayed(nmsg, POWER_CHECK_DELAY);
6688+
}
66706689
}
66716690
}
66726691

@@ -6726,12 +6745,40 @@ public final void activitySlept(IBinder token) {
67266745
Binder.restoreCallingIdentity(origId);
67276746
}
67286747

6748+
private void comeOutOfSleepIfNeededLocked() {
6749+
if (!mWentToSleep && !mLockScreenShown) {
6750+
if (mSleeping) {
6751+
mSleeping = false;
6752+
mMainStack.awakeFromSleepingLocked();
6753+
mMainStack.resumeTopActivityLocked(null);
6754+
}
6755+
}
6756+
}
6757+
67296758
public void wakingUp() {
6759+
if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER)
6760+
!= PackageManager.PERMISSION_GRANTED) {
6761+
throw new SecurityException("Requires permission "
6762+
+ android.Manifest.permission.DEVICE_POWER);
6763+
}
6764+
67306765
synchronized(this) {
6766+
mWentToSleep = false;
67316767
mWindowManager.setEventDispatching(true);
6732-
mSleeping = false;
6733-
mMainStack.awakeFromSleepingLocked();
6734-
mMainStack.resumeTopActivityLocked(null);
6768+
comeOutOfSleepIfNeededLocked();
6769+
}
6770+
}
6771+
6772+
public void setLockScreenShown(boolean shown) {
6773+
if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER)
6774+
!= PackageManager.PERMISSION_GRANTED) {
6775+
throw new SecurityException("Requires permission "
6776+
+ android.Manifest.permission.DEVICE_POWER);
6777+
}
6778+
6779+
synchronized(this) {
6780+
mLockScreenShown = shown;
6781+
comeOutOfSleepIfNeededLocked();
67356782
}
67366783
}
67376784

@@ -8815,7 +8862,13 @@ boolean dumpProcessesLocked(FileDescriptor fd, PrintWriter pw, String[] args,
88158862
}
88168863
}
88178864
}
8818-
pw.println(" mSleeping=" + mSleeping + " mShuttingDown=" + mShuttingDown);
8865+
if (mSleeping || mWentToSleep || mLockScreenShown) {
8866+
pw.println(" mSleeping=" + mSleeping + " mWentToSleep=" + mWentToSleep
8867+
+ " mLockScreenShown " + mLockScreenShown);
8868+
}
8869+
if (mShuttingDown) {
8870+
pw.println(" mShuttingDown=" + mShuttingDown);
8871+
}
88198872
if (mDebugApp != null || mOrigDebugApp != null || mDebugTransient
88208873
|| mOrigWaitForDebugger) {
88218874
pw.println(" mDebugApp=" + mDebugApp + "/orig=" + mOrigDebugApp

0 commit comments

Comments
 (0)