diff --git a/core/proto/android/server/windowmanagerservice.proto b/core/proto/android/server/windowmanagerservice.proto index 653d381e2960d..3db24778a2c9a 100644 --- a/core/proto/android/server/windowmanagerservice.proto +++ b/core/proto/android/server/windowmanagerservice.proto @@ -235,7 +235,7 @@ message AppWindowTokenProto { optional WindowContainerThumbnailProto thumbnail = 6; optional bool fills_parent = 7; optional bool app_stopped = 8; - optional bool hidden_requested = 9; + optional bool visible_requested = 9; optional bool client_hidden = 10; optional bool defer_hiding_client = 11; optional bool reported_drawn = 12; diff --git a/data/etc/services.core.protolog.json b/data/etc/services.core.protolog.json index 753f8a05cbe3b..9b3198073e610 100644 --- a/data/etc/services.core.protolog.json +++ b/data/etc/services.core.protolog.json @@ -73,6 +73,12 @@ "group": "WM_ERROR", "at": "com\/android\/server\/wm\/WindowManagerService.java" }, + "-1972506791": { + "message": "Set freezing of %s: hidden=%b freezing=%b visibleRequested=%b. %s", + "level": "INFO", + "group": "WM_DEBUG_ORIENTATION", + "at": "com\/android\/server\/wm\/ActivityRecord.java" + }, "-1963461591": { "message": "Removing %s from %s", "level": "VERBOSE", @@ -883,6 +889,12 @@ "group": "WM_DEBUG_ORIENTATION", "at": "com\/android\/server\/wm\/ActivityRecord.java" }, + "-229838822": { + "message": "setAppVisibility(%s, visible=%b): %s hidden=%b mVisibleRequested=%b Callers=%s", + "level": "VERBOSE", + "group": "WM_DEBUG_APP_TRANSITIONS", + "at": "com\/android\/server\/wm\/ActivityRecord.java" + }, "-198463978": { "message": "updateRotationUnchecked: alwaysSendConfiguration=%b forceRelayout=%b", "level": "VERBOSE", @@ -1207,12 +1219,6 @@ "group": "WM_DEBUG_ORIENTATION", "at": "com\/android\/server\/wm\/WindowManagerService.java" }, - "358613119": { - "message": "setAppVisibility(%s, visible=%b): %s hidden=%b hiddenRequested=%b Callers=%s", - "level": "VERBOSE", - "group": "WM_DEBUG_APP_TRANSITIONS", - "at": "com\/android\/server\/wm\/ActivityRecord.java" - }, "371641947": { "message": "Window Manager Crash %s", "level": "WTF", @@ -1501,12 +1507,6 @@ "group": "WM_DEBUG_RECENTS_ANIMATIONS", "at": "com\/android\/server\/wm\/RecentsAnimation.java" }, - "857751535": { - "message": "commitVisibility: %s: hidden=%b hiddenRequested=%b", - "level": "VERBOSE", - "group": "WM_DEBUG_APP_TRANSITIONS", - "at": "com\/android\/server\/wm\/ActivityRecord.java" - }, "873914452": { "message": "goodToGo()", "level": "DEBUG", @@ -1993,10 +1993,10 @@ "group": "WM_DEBUG_REMOTE_ANIMATIONS", "at": "com\/android\/server\/wm\/RemoteAnimationController.java" }, - "1966564525": { - "message": "Set freezing of %s: hidden=%b freezing=%b hiddenRequested=%b. %s", - "level": "INFO", - "group": "WM_DEBUG_ORIENTATION", + "1965198071": { + "message": "commitVisibility: %s: hidden=%b visibleRequested=%b", + "level": "VERBOSE", + "group": "WM_DEBUG_APP_TRANSITIONS", "at": "com\/android\/server\/wm\/ActivityRecord.java" }, "1984470582": { diff --git a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java index 73034b020a76d..0a861ade29006 100644 --- a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java +++ b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java @@ -548,7 +548,7 @@ class ActivityMetricsLogger { private static boolean hasActivityToBeDrawn(Task t) { for (int i = t.getChildCount() - 1; i >= 0; --i) { final ActivityRecord r = t.getChildAt(i); - if (r.visible && !r.mDrawn && !r.finishing) { + if (r.mVisibleRequested && !r.mDrawn && !r.finishing) { return true; } } diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 8039724edf642..ce1941457fe99 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -176,7 +176,6 @@ import static com.android.server.wm.AppWindowTokenProto.CLIENT_HIDDEN; import static com.android.server.wm.AppWindowTokenProto.DEFER_HIDING_CLIENT; import static com.android.server.wm.AppWindowTokenProto.FILLS_PARENT; import static com.android.server.wm.AppWindowTokenProto.FROZEN_BOUNDS; -import static com.android.server.wm.AppWindowTokenProto.HIDDEN_REQUESTED; import static com.android.server.wm.AppWindowTokenProto.HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW; import static com.android.server.wm.AppWindowTokenProto.IS_ANIMATING; import static com.android.server.wm.AppWindowTokenProto.IS_WAITING_FOR_TRANSITION_START; @@ -192,6 +191,7 @@ import static com.android.server.wm.AppWindowTokenProto.STARTING_DISPLAYED; import static com.android.server.wm.AppWindowTokenProto.STARTING_MOVED; import static com.android.server.wm.AppWindowTokenProto.STARTING_WINDOW; import static com.android.server.wm.AppWindowTokenProto.THUMBNAIL; +import static com.android.server.wm.AppWindowTokenProto.VISIBLE_REQUESTED; import static com.android.server.wm.AppWindowTokenProto.WINDOW_TOKEN; import static com.android.server.wm.IdentifierProto.HASH_CODE; import static com.android.server.wm.IdentifierProto.TITLE; @@ -462,7 +462,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A private boolean keysPaused; // has key dispatching been paused for it? int launchMode; // the launch mode activity attribute. int lockTaskLaunchMode; // the lockTaskMode manifest attribute, subject to override - boolean visible; // does this activity's window need to be shown? boolean visibleIgnoringKeyguard; // is this activity visible, ignoring the fact that Keyguard // might hide this activity? // True if the hidden state of this token was forced to false due to a transferred starting @@ -622,11 +621,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // case do not clear allDrawn until the animation completes. boolean deferClearAllDrawn; - // Is this window's surface needed? This is almost like hidden, except - // it will sometimes be true a little earlier: when the token has + // Is this window's surface needed? This is almost like visible, except + // it will sometimes be true a little earlier: when the activity record has // been shown, but is still waiting for its app transition to execute // before making its windows shown. - boolean hiddenRequested; + boolean mVisibleRequested; // Last visibility state we reported to the app token. boolean reportedVisible; @@ -836,7 +835,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(" visible="); pw.print(visible); pw.print(" sleeping="); pw.print(sleeping); pw.print(" idle="); pw.print(idle); pw.print(" mStartingWindowState="); @@ -860,7 +858,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } pw.print(prefix); pw.print(" mOccludesParent="); pw.print(mOccludesParent); pw.print(" mOrientation="); pw.println(mOrientation); - pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden + pw.println(prefix + "mVisibleRequested=" + mVisibleRequested + + " mClientHidden=" + mClientHidden + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "") + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible); if (paused) { @@ -1488,7 +1487,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // Application tokens start out hidden. setHidden(true); - hiddenRequested = true; + mVisibleRequested = false; ColorDisplayService.ColorDisplayServiceInternal cds = LocalServices.getService( ColorDisplayService.ColorDisplayServiceInternal.class); @@ -1517,7 +1516,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A deferRelaunchUntilPaused = false; keysPaused = false; inHistory = false; - visible = false; nowVisible = false; mDrawn = false; idle = false; @@ -2200,7 +2198,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A * 2. App is delayed closing since it might enter PIP. */ boolean isClosingOrEnteringPip() { - return (isAnimating(TRANSITION | PARENTS) && hiddenRequested) || mWillCloseOrEnterPip; + return (isAnimating(TRANSITION | PARENTS) && !mVisibleRequested) || mWillCloseOrEnterPip; } /** * @return Whether AppOps allows this package to enter picture-in-picture. @@ -2459,7 +2457,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A mAtmService.getLockTaskController().clearLockedTask(task); } } else if (!isState(PAUSING)) { - if (visible) { + if (mVisibleRequested) { // Prepare and execute close transition. prepareActivityHideTransitionAnimation(transit); } @@ -2538,12 +2536,13 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // TODO(b/137329632): find the next activity directly underneath this one, not just anywhere final ActivityRecord next = getDisplay().topRunningActivity( true /* considerKeyguardState */); - final boolean isVisible = visible || nowVisible; + final boolean isVisible = mVisibleRequested || nowVisible; // isNextNotYetVisible is to check if the next activity is invisible, or it has been // requested to be invisible but its windows haven't reported as invisible. If so, it // implied that the current finishing activity should be added into stopping list rather // than destroy immediately. - final boolean isNextNotYetVisible = next != null && (!next.nowVisible || !next.visible); + final boolean isNextNotYetVisible = next != null + && (!next.nowVisible || !next.mVisibleRequested); if (isVisible && isNextNotYetVisible) { // Add this activity to the list of stopping activities. It will be processed and // destroyed when the next activity reports idle. @@ -3226,7 +3225,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } if (!fromActivity.isHidden()) { setHidden(false); - hiddenRequested = false; + mVisibleRequested = true; mHiddenSetFromTransferredStartingWindow = true; } setClientHidden(fromActivity.mClientHidden); @@ -3275,7 +3274,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A if (fromActivity == this) { return; } - if (fromActivity.hiddenRequested && transferStartingWindow(fromActivity.token)) { + if (!fromActivity.mVisibleRequested && transferStartingWindow(fromActivity.token)) { return; } } @@ -3790,6 +3789,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A return opts; } + boolean allowMoveToFront() { + return pendingOptions == null || !pendingOptions.getAvoidMoveToFront(); + } + void removeUriPermissionsLocked() { if (uriPermissions != null) { uriPermissions.removeUriPermissions(); @@ -3826,7 +3829,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A return; } mDeferHidingClient = deferHidingClient; - if (!mDeferHidingClient && !visible) { + if (!mDeferHidingClient && !mVisibleRequested) { // Hiding the client is no longer deferred and the app isn't visible still, go ahead and // update the visibility. setVisibility(false); @@ -3846,20 +3849,17 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A + appToken); return; } + if (visible) { + mDeferHidingClient = false; + } setVisibility(visible, mDeferHidingClient); mAtmService.addWindowLayoutReasons( ActivityTaskManagerService.LAYOUT_REASON_VISIBILITY_CHANGED); mStackSupervisor.getActivityMetricsLogger().notifyVisibilityChanged(this); - } - - // TODO: Look into merging with #commitVisibility() - void setVisible(boolean newVisible) { - visible = newVisible; - mDeferHidingClient = !visible && mDeferHidingClient; - setVisibility(visible); mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; } + @VisibleForTesting void setVisibility(boolean visible, boolean deferHidingClient) { final AppTransition appTransition = getDisplayContent().mAppTransition; @@ -3870,7 +3870,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // transition can be selected. // TODO: Probably a good idea to separate the concept of opening/closing apps from the // concept of setting visibility... - if (!visible && hiddenRequested) { + if (!visible && !mVisibleRequested) { if (!deferHidingClient && mLastDeferHidingClient) { // We previously deferred telling the client to hide itself when visibility was @@ -3882,8 +3882,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, - "setAppVisibility(%s, visible=%b): %s hidden=%b hiddenRequested=%b Callers=%s", - appToken, visible, appTransition, isHidden(), hiddenRequested, + "setAppVisibility(%s, visible=%b): %s hidden=%b mVisibleRequested=%b Callers=%s", + appToken, visible, appTransition, isHidden(), mVisibleRequested, Debug.getCallers(6)); final DisplayContent displayContent = getDisplayContent(); @@ -3894,7 +3894,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } displayContent.mChangingApps.remove(this); waitingToShow = false; - hiddenRequested = !visible; + mVisibleRequested = visible; mLastDeferHidingClient = deferHidingClient; if (!visible) { @@ -4033,7 +4033,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } setHidden(!visible); - hiddenRequested = !visible; + mVisibleRequested = visible; visibilityChanged = true; if (!visible) { stopFreezingScreen(true, true); @@ -4051,8 +4051,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, - "commitVisibility: %s: hidden=%b hiddenRequested=%b", this, - isHidden(), hiddenRequested); + "commitVisibility: %s: hidden=%b visibleRequested=%b", this, + isHidden(), mVisibleRequested); if (changed) { displayContent.getInputMonitor().setUpdateInputWindowsNeededLw(); @@ -4397,7 +4397,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A updateOptionsLocked(returningOptions); stack.mUndrawnActivitiesBelowTopTranslucent.add(this); } - setVisible(true); + setVisibility(true); sleeping = false; app.postPendingUiCleanMsg(true); if (reportToClient) { @@ -4433,7 +4433,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } void makeInvisible() { - if (!visible) { + if (!mVisibleRequested) { if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Already invisible: " + this); return; } @@ -4455,7 +4455,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A final boolean deferHidingClient = canEnterPictureInPicture && !isState(STOPPING, STOPPED, PAUSED); setDeferHidingClient(deferHidingClient); - setVisible(false); + setVisibility(false); switch (getState()) { case STOPPING: @@ -4642,8 +4642,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A * state to match that fact. */ void completeResumeLocked() { - final boolean wasVisible = visible; - setVisible(true); + final boolean wasVisible = mVisibleRequested; + setVisibility(true); if (!wasVisible) { // Visibility has changed, so take a note of it so we call the TaskStackChangedListener mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; @@ -4727,15 +4727,16 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } setState(STOPPING, "stopIfPossible"); if (DEBUG_VISIBILITY) { - Slog.v(TAG_VISIBILITY, "Stopping visible=" + visible + " for " + this); + Slog.v(TAG_VISIBILITY, "Stopping visibleRequested=" + + mVisibleRequested + " for " + this); } - if (!visible) { - setVisible(false); + if (!mVisibleRequested) { + setVisibility(false); } EventLogTags.writeAmStopActivity( mUserId, System.identityHashCode(this), shortComponentName); mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, - StopActivityItem.obtain(visible, configChangeFlags)); + StopActivityItem.obtain(mVisibleRequested, configChangeFlags)); if (stack.shouldSleepOrShutDownActivities()) { setSleeping(true); } @@ -4898,10 +4899,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A void startFreezingScreen() { ProtoLog.i(WM_DEBUG_ORIENTATION, - "Set freezing of %s: hidden=%b freezing=%b hiddenRequested=%b. %s", - appToken, isHidden(), mFreezingScreen, hiddenRequested, + "Set freezing of %s: hidden=%b freezing=%b visibleRequested=%b. %s", + appToken, isHidden(), mFreezingScreen, mVisibleRequested, new RuntimeException().fillInStackTrace()); - if (!hiddenRequested) { + if (mVisibleRequested) { if (!mFreezingScreen) { mFreezingScreen = true; mWmService.registerAppFreezeListener(this); @@ -5180,7 +5181,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController + " pv=" + w.isVisibleByPolicy() + " mDrawState=" + winAnimator.drawStateToString() - + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested + + " ph=" + w.isParentWindowHidden() + " th=" + mVisibleRequested + " a=" + isAnimating(TRANSITION)); } } @@ -5288,7 +5289,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A * currently pausing, or is resumed. */ public boolean isInterestingToUserLocked() { - return visible || nowVisible || mState == PAUSING || mState == RESUMED; + return mVisibleRequested || nowVisible || mState == PAUSING || mState == RESUMED; } void setSleeping(boolean _sleeping) { @@ -5362,7 +5363,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // We're not ready for this kind of thing. return false; } - if (visible) { + if (mVisibleRequested) { // The user would notice this! return false; } @@ -5920,7 +5921,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A "AppWindowToken"); clearThumbnail(); - setClientHidden(isHidden() && hiddenRequested); + setClientHidden(isHidden() && !mVisibleRequested); getDisplayContent().computeImeTargetIfNeeded(this); @@ -6516,7 +6517,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A if (display == null) { return; } - if (visible) { + if (mVisibleRequested) { // It may toggle the UI for user to restart the size compatibility mode activity. display.handleActivitySizeCompatModeIfNeeded(this); } else if (mCompatDisplayInsets != null) { @@ -6813,7 +6814,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } else { if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Config is relaunching " + this); - if (DEBUG_STATES && !visible) { + if (DEBUG_STATES && !mVisibleRequested) { Slog.v(TAG_STATES, "Config is relaunching invisible activity " + this + " called by " + Debug.getCallers(4)); } @@ -6999,7 +7000,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // Reset the existing override configuration so it can be updated according to the latest // configuration. clearSizeCompatMode(); - if (visible) { + if (mVisibleRequested) { // Configuration will be ensured when becoming visible, so if it is already visible, // then the manual update is needed. updateSizeCompatMode(); @@ -7012,7 +7013,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // The restarting state avoids removing this record when process is died. setState(RESTARTING_PROCESS, "restartActivityProcess"); - if (!visible || mHaveState) { + if (!mVisibleRequested || mHaveState) { // Kill its process immediately because the activity should be in background. // The activity state will be update to {@link #DESTROYED} in // {@link ActivityStack#cleanUp} when handling process died. @@ -7303,7 +7304,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A writeToProto(proto, APP_WINDOW_TOKEN, WindowTraceLogLevel.ALL); writeIdentifierToProto(proto, IDENTIFIER); proto.write(STATE, mState.toString()); - proto.write(VISIBLE, visible); + proto.write(VISIBLE, mVisibleRequested); proto.write(FRONT_OF_TASK, isRootOfTask()); if (hasProcess()) { proto.write(PROC_ID, app.getPid()); @@ -7339,7 +7340,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } proto.write(FILLS_PARENT, mOccludesParent); proto.write(APP_STOPPED, mAppStopped); - proto.write(HIDDEN_REQUESTED, hiddenRequested); + proto.write(VISIBLE_REQUESTED, mVisibleRequested); proto.write(CLIENT_HIDDEN, mClientHidden); proto.write(DEFER_HIDING_CLIENT, mDeferHidingClient); proto.write(REPORTED_DRAWN, reportedDrawn); diff --git a/services/core/java/com/android/server/wm/ActivityServiceConnectionsHolder.java b/services/core/java/com/android/server/wm/ActivityServiceConnectionsHolder.java index c56a9e2ac5600..6e75f9c9167f5 100644 --- a/services/core/java/com/android/server/wm/ActivityServiceConnectionsHolder.java +++ b/services/core/java/com/android/server/wm/ActivityServiceConnectionsHolder.java @@ -73,7 +73,7 @@ public class ActivityServiceConnectionsHolder { public boolean isActivityVisible() { synchronized (mService.mGlobalLock) { - return mActivity.visible || mActivity.isState(RESUMED, PAUSING); + return mActivity.mVisibleRequested || mActivity.isState(RESUMED, PAUSING); } } diff --git a/services/core/java/com/android/server/wm/ActivityStack.java b/services/core/java/com/android/server/wm/ActivityStack.java index 8385232b72d8f..d51c72bd11ead 100644 --- a/services/core/java/com/android/server/wm/ActivityStack.java +++ b/services/core/java/com/android/server/wm/ActivityStack.java @@ -1693,7 +1693,8 @@ class ActivityStack extends WindowContainer implements BoundsAnimationTarg prev = prev.completeFinishing("completePausedLocked"); } else if (prev.hasProcess()) { if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueue pending stop if needed: " + prev - + " wasStopping=" + wasStopping + " visible=" + prev.visible); + + " wasStopping=" + wasStopping + + " visibleRequested=" + prev.mVisibleRequested); if (prev.deferRelaunchUntilPaused) { // Complete the deferred relaunch that was waiting for pause to complete. if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Re-launching after pause: " + prev); @@ -1703,7 +1704,7 @@ class ActivityStack extends WindowContainer implements BoundsAnimationTarg // We can't clobber it, because the stop confirmation will not be handled. // We don't need to schedule another stop, we only need to let it happen. prev.setState(STOPPING, "completePausedLocked"); - } else if (!prev.visible || shouldSleepOrShutDownActivities()) { + } else if (!prev.mVisibleRequested || shouldSleepOrShutDownActivities()) { // Clear out any deferred client hide we might currently have. prev.setDeferHidingClient(false); // If we were visible then resumeTopActivities will release resources before @@ -1824,7 +1825,7 @@ class ActivityStack extends WindowContainer implements BoundsAnimationTarg boolean isTopActivityVisible() { final ActivityRecord topActivity = getTopNonFinishingActivity(); - return topActivity != null && topActivity.visible; + return topActivity != null && topActivity.mVisibleRequested; } /** @@ -1965,7 +1966,7 @@ class ActivityStack extends WindowContainer implements BoundsAnimationTarg for (int taskNdx = getChildCount() - 1; taskNdx >= 0; --taskNdx) { final Task task = getChildAt(taskNdx); ActivityRecord r = task.topRunningActivityLocked(); - if (r == null || r.finishing || !r.visible) { + if (r == null || r.finishing || !r.mVisibleRequested) { task.mLayerRank = -1; } else { task.mLayerRank = baseLayer + layer++; @@ -2054,7 +2055,7 @@ class ActivityStack extends WindowContainer implements BoundsAnimationTarg if (!r.attachedToProcess()) { makeVisibleAndRestartIfNeeded(starting, configChanges, isTop, resumeTopActivity && isTop, r); - } else if (r.visible) { + } else if (r.mVisibleRequested) { // If this activity is already visible, then there is nothing to do here. if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Skipping: already visible at " + r); @@ -2231,16 +2232,16 @@ class ActivityStack extends WindowContainer implements BoundsAnimationTarg // invisible. If the app is already visible, it must have died while it was visible. In this // case, we'll show the dead window but will not restart the app. Otherwise we could end up // thrashing. - if (isTop || !r.visible) { + if (isTop || !r.mVisibleRequested) { // This activity needs to be visible, but isn't even running... // get it started and resume if no other stack in this stack is resumed. if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Start and freeze screen for " + r); if (r != starting) { r.startFreezingScreenLocked(configChanges); } - if (!r.visible || r.mLaunchTaskBehind) { + if (!r.mVisibleRequested || r.mLaunchTaskBehind) { if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Starting and making visible: " + r); - r.setVisible(true); + r.setVisibility(true); } if (r != starting) { mStackSupervisor.startSpecificActivityLocked(r, andResume, true /* checkConfig */); @@ -2683,7 +2684,8 @@ class ActivityStack extends WindowContainer implements BoundsAnimationTarg if (next.attachedToProcess()) { if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next - + " stopped=" + next.stopped + " visible=" + next.visible); + + " stopped=" + next.stopped + + " visibleRequested=" + next.mVisibleRequested); // If the previous activity is translucent, force a visibility update of // the next activity, so that it's added to WM's opening app list, and @@ -2698,7 +2700,7 @@ class ActivityStack extends WindowContainer implements BoundsAnimationTarg && !lastFocusedStack.mLastPausedActivity.occludesParent())); // This activity is now becoming visible. - if (!next.visible || next.stopped || lastActivityTranslucent) { + if (!next.mVisibleRequested || next.stopped || lastActivityTranslucent) { next.setVisibility(true); } @@ -2753,7 +2755,7 @@ class ActivityStack extends WindowContainer implements BoundsAnimationTarg // Do over! mStackSupervisor.scheduleResumeTopActivities(); } - if (!next.visible || next.stopped) { + if (!next.mVisibleRequested || next.stopped) { next.setVisibility(true); } next.completeResumeLocked(); @@ -3422,7 +3424,7 @@ class ActivityStack extends WindowContainer implements BoundsAnimationTarg final ActivityRecord top = stack.topRunningActivityLocked(); - if (stack.isActivityTypeHome() && (top == null || !top.visible)) { + if (stack.isActivityTypeHome() && (top == null || !top.mVisibleRequested)) { // If we will be focusing on the home stack next and its current top activity isn't // visible, then use the move the home stack task to top to make the activity visible. stack.getDisplay().moveHomeActivityToTop(reason); @@ -3919,7 +3921,10 @@ class ActivityStack extends WindowContainer implements BoundsAnimationTarg "Record #" + targetIndex + " " + r + ": app=" + r.app); if (r.app == app) { - if (r.visible) { + if (r.isVisible() || r.mVisibleRequested) { + // While an activity launches a new activity, it's possible that the old + // activity is already requested to be hidden (mVisibleRequested=false), but + // this visibility is not yet committed, so isVisible()=true. hasVisibleActivities = true; } final boolean remove; @@ -3935,8 +3940,8 @@ class ActivityStack extends WindowContainer implements BoundsAnimationTarg // Don't currently have state for the activity, or // it is finishing -- always remove it. remove = true; - } else if (!r.visible && r.launchCount > 2 && - r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) { + } else if (!r.mVisibleRequested && r.launchCount > 2 + && r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) { // We have launched this activity too many times since it was // able to run, so give up and remove it. // (Note if the activity is visible, we don't remove the record. @@ -3972,7 +3977,7 @@ class ActivityStack extends WindowContainer implements BoundsAnimationTarg // it died, we leave the dead window on screen so it's basically visible. // This is needed when user later tap on the dead window, we need to stop // other apps when user transfers focus to the restarted activity. - r.nowVisible = r.visible; + r.nowVisible = r.mVisibleRequested; } r.cleanUp(true /* cleanServices */, true /* setState */); if (remove) { @@ -4155,7 +4160,7 @@ class ActivityStack extends WindowContainer implements BoundsAnimationTarg * Ensures all visible activities at or below the input activity have the right configuration. */ void ensureVisibleActivitiesConfigurationLocked(ActivityRecord start, boolean preserveWindow) { - if (start == null || !start.visible) { + if (start == null || !start.mVisibleRequested) { return; } @@ -4550,7 +4555,7 @@ class ActivityStack extends WindowContainer implements BoundsAnimationTarg final ActivityRecord a = task.getChildAt(activityNdx); if (a.info.packageName.equals(packageName)) { a.forceNewConfig = true; - if (starting != null && a == starting && a.visible) { + if (starting != null && a == starting && a.mVisibleRequested) { a.startFreezingScreenLocked(CONFIG_SCREEN_LAYOUT); } } diff --git a/services/core/java/com/android/server/wm/ActivityStackSupervisor.java b/services/core/java/com/android/server/wm/ActivityStackSupervisor.java index 530fdcf066a9d..6ea80d259a4dc 100644 --- a/services/core/java/com/android/server/wm/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/wm/ActivityStackSupervisor.java @@ -773,12 +773,11 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { } if (r.getActivityStack().checkKeyguardVisibility(r, true /* shouldBeVisible */, - true /* isTop */)) { - // We only set the visibility to true if the activity is allowed to be visible - // based on - // keyguard state. This avoids setting this into motion in window manager that is - // later cancelled due to later calls to ensure visible activities that set - // visibility back to false. + true /* isTop */) && r.allowMoveToFront()) { + // We only set the visibility to true if the activity is not being launched in + // background, and is allowed to be visible based on keyguard state. This avoids + // setting this into motion in window manager that is later cancelled due to later + // calls to ensure visible activities that set visibility back to false. r.setVisibility(true); } diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index b4dd55de2dbaa..a7fd1a4fd78d8 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -653,11 +653,11 @@ class DisplayContent extends WindowContainer