summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author wilsonshih <wilsonshih@google.com> 2020-10-15 11:41:00 +0800
committer wilsonshih <wilsonshih@google.com> 2020-10-27 10:26:54 +0800
commit9979a51ed01f1012f50e4f9a4e09809307f8f295 (patch)
tree9581f6716b671c792921f5892d28feda733d5554
parent9a095a4e40f4dac1e324fe31b91d65b1095ab05f (diff)
Replace ActivityRecord#mSetToSleep by canTurnScreenOn
The member ActivityRecord#mSetToSleep can be replaced by checking canTurnScreenOn & mCurrentLaunchCanTurnScreenOn. Before Task#goToSleep been called, the display will be set to sleeping in RootWindowContainer#applySleepTokens, so when checking ActivityRecord#shouldBeVisibleUnchecked while display is sleeping, we only need to perform an additional check whether this activity can turn screen on. This is because there are only two ways to apply sleep token, which are keyguard and screen state, and we have checked the keyguard visibility through KeyguardController#checkKeyguardVisibility. Test: atest ActivityVisibilityTests KeyguardTests KeyguardLockedTests KeyguardTransitionTests Test: atest ActivityRecordTests Bug: 163993448 Change-Id: I64cf04e3037ab9ca7afec9d1c8bf65d202a02e36
-rw-r--r--services/core/java/com/android/server/wm/ActivityRecord.java25
-rw-r--r--services/core/java/com/android/server/wm/ActivityStackSupervisor.java1
-rw-r--r--services/core/java/com/android/server/wm/ActivityStarter.java4
-rw-r--r--services/core/java/com/android/server/wm/RootWindowContainer.java4
-rw-r--r--services/core/java/com/android/server/wm/Task.java22
5 files changed, 16 insertions, 40 deletions
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index 13e23f766668..d01bc815c28d 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -499,7 +499,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
// process that it is hidden.
private boolean mLastDeferHidingClient; // If true we will defer setting mClientVisible to false
// and reporting to the client that it is hidden.
- private boolean mSetToSleep; // have we told the activity to sleep?
boolean nowVisible; // is this activity's window visible?
boolean mClientVisibilityDeferred;// was the visibility change message to client deferred?
boolean idle; // has the activity gone idle?
@@ -906,7 +905,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
pw.print(" finishing="); pw.println(finishing);
pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
pw.print(" inHistory="); pw.print(inHistory);
- pw.print(" setToSleep="); pw.print(mSetToSleep);
pw.print(" idle="); pw.print(idle);
pw.print(" mStartingWindowState=");
pw.println(startingWindowStateToString(mStartingWindowState));
@@ -4675,14 +4673,13 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
return false;
}
- // Check if the activity is on a sleeping display
- // TODO b/163993448 mSetToSleep is required when restarting an existing activity, try to
- // remove it if possible.
- if (mSetToSleep && mDisplayContent.isSleeping()) {
- return false;
+ // Check if the activity is on a sleeping display, canTurnScreenOn will also check
+ // keyguard visibility
+ if (mDisplayContent.isSleeping()) {
+ return canTurnScreenOn();
+ } else {
+ return mStackSupervisor.getKeyguardController().checkKeyguardVisibility(this);
}
-
- return mStackSupervisor.getKeyguardController().checkKeyguardVisibility(this);
}
void updateVisibilityIgnoringKeyguard(boolean behindFullscreenActivity) {
@@ -4719,7 +4716,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
stack.mUndrawnActivitiesBelowTopTranslucent.add(this);
}
setVisibility(true);
- mSetToSleep = false;
app.postPendingUiCleanMsg(true);
if (reportToClient) {
mClientVisibilityDeferred = false;
@@ -5118,9 +5114,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken,
StopActivityItem.obtain(configChangeFlags));
- if (stack.shouldSleepOrShutDownActivities()) {
- setSleeping(true);
- }
mAtmService.mH.postDelayed(mStopTimeoutRunnable, STOP_TIMEOUT);
} catch (Exception e) {
// Maybe just ignore exceptions here... if the process has crashed, our death
@@ -5711,10 +5704,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
return mVisibleRequested || nowVisible || mState == PAUSING || mState == RESUMED;
}
- void setSleeping(boolean sleeping) {
- mSetToSleep = sleeping;
- }
-
static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
final ActivityRecord r = ActivityRecord.forTokenLocked(token);
if (r == null || r.getParent() == null) {
@@ -7561,7 +7550,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
return false;
}
final Task stack = getRootTask();
- return stack != null
+ return mCurrentLaunchCanTurnScreenOn && stack != null
&& mStackSupervisor.getKeyguardController().checkKeyguardVisibility(this);
}
diff --git a/services/core/java/com/android/server/wm/ActivityStackSupervisor.java b/services/core/java/com/android/server/wm/ActivityStackSupervisor.java
index a8079cfa1c85..a068d2b7c823 100644
--- a/services/core/java/com/android/server/wm/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/wm/ActivityStackSupervisor.java
@@ -820,7 +820,6 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
}
mService.getPackageManagerInternalLocked().notifyPackageUse(
r.intent.getComponent().getPackageName(), NOTIFY_PACKAGE_USE_ACTIVITY);
- r.setSleeping(false);
r.forceNewConfig = false;
mService.getAppWarningsLocked().onStartActivity(r);
r.compat = mService.compatibilityInfoForPackageLocked(r.info.applicationInfo);
diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java
index c8a8f81ebca1..910a1a2c69b2 100644
--- a/services/core/java/com/android/server/wm/ActivityStarter.java
+++ b/services/core/java/com/android/server/wm/ActivityStarter.java
@@ -2546,6 +2546,10 @@ class ActivityStarter {
private void resumeTargetStackIfNeeded() {
if (mDoResume) {
+ final ActivityRecord next = mTargetStack.topRunningActivity(true /* focusableOnly */);
+ if (next != null) {
+ next.setCurrentLaunchCanTurnScreenOn(true);
+ }
mRootWindowContainer.resumeFocusedStacksTopActivities(mTargetStack, null, mOptions);
} else {
ActivityOptions.abort(mOptions);
diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java
index c1e518b8b82c..04b303053d8f 100644
--- a/services/core/java/com/android/server/wm/RootWindowContainer.java
+++ b/services/core/java/com/android/server/wm/RootWindowContainer.java
@@ -55,6 +55,7 @@ import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_L
import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME;
import static com.android.server.wm.ActivityStackSupervisor.ON_TOP;
+import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS;
import static com.android.server.wm.ActivityStackSupervisor.dumpHistoryList;
import static com.android.server.wm.ActivityStackSupervisor.printThisActivity;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RECENTS;
@@ -2779,7 +2780,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
if (allowDelay) {
result &= stack.goToSleepIfPossible(shuttingDown);
} else {
- stack.goToSleep();
+ stack.ensureActivitiesVisible(null /* starting */, 0 /* configChanges */,
+ !PRESERVE_WINDOWS);
}
}
return result;
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 557c92e9704e..132029f36096 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -5342,8 +5342,6 @@ class Task extends WindowContainer<WindowContainer> {
}
void awakeFromSleepingLocked() {
- // Ensure activities are no longer sleeping.
- forAllActivities((Consumer<ActivityRecord>) (r) -> r.setSleeping(false));
if (mPausingActivity != null) {
Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause");
mPausingActivity.activityPaused(true);
@@ -5397,27 +5395,13 @@ class Task extends WindowContainer<WindowContainer> {
}
if (shouldSleep) {
- goToSleep();
+ ensureActivitiesVisible(null /* starting */, 0 /* configChanges */,
+ !PRESERVE_WINDOWS);
}
return shouldSleep;
}
- void goToSleep() {
- // Make sure all visible activities are now sleeping. This will update the activity's
- // visibility and onStop() will be called.
- forAllActivities((r) -> {
- if (r.isState(STARTED, RESUMED, PAUSING, PAUSED, STOPPING, STOPPED)) {
- r.setSleeping(true);
- }
- });
-
- // Ensure visibility after updating sleep states without updating configuration,
- // as activities are about to be sent to sleep.
- ensureActivitiesVisible(null /* starting */, 0 /* configChanges */,
- !PRESERVE_WINDOWS);
- }
-
private boolean containsActivityFromStack(List<ActivityRecord> rs) {
for (ActivityRecord r : rs) {
if (r.getRootTask() == this) {
@@ -5948,7 +5932,6 @@ class Task extends WindowContainer<WindowContainer> {
// The activity may be waiting for stop, but that is no longer
// appropriate for it.
mStackSupervisor.mStoppingActivities.remove(next);
- next.setSleeping(false);
if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next);
@@ -6221,7 +6204,6 @@ class Task extends WindowContainer<WindowContainer> {
EventLogTags.writeWmResumeActivity(next.mUserId, System.identityHashCode(next),
next.getTask().mTaskId, next.shortComponentName);
- next.setSleeping(false);
mAtmService.getAppWarningsLocked().onResumeActivity(next);
next.app.setPendingUiCleanAndForceProcessStateUpTo(mAtmService.mTopProcessState);
next.clearOptionsLocked();