diff options
9 files changed, 26 insertions, 81 deletions
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 860fe15f648a..2d93e237120d 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -659,7 +659,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A boolean mVoiceInteraction; - private int mPendingRelaunchCount; + int mPendingRelaunchCount; long mRelaunchStartTime; // True if we are current in the process of removing this app token from the display @@ -3988,7 +3988,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // If the display does not have running activity, the configuration may need to be // updated for restoring original orientation of the display. if (next == null) { - mRootWindowContainer.ensureVisibilityAndConfig(next, getDisplayId(), + mRootWindowContainer.ensureVisibilityAndConfig(null /* starting */, mDisplayContent, true /* deferResume */); } if (activityRemoved) { @@ -6465,12 +6465,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A * state to match that fact. */ void completeResumeLocked() { - final boolean wasVisible = mVisibleRequested; - setVisibility(true); - if (!wasVisible) { - // Visibility has changed, so take a note of it so we call the TaskStackChangedListener - mTaskSupervisor.mAppVisibilitiesChangedSinceLastPause = true; - } idle = false; results = null; if (newIntents != null && newIntents.size() > 0) { diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java index 6ad056f5a902..2c39c5875389 100644 --- a/services/core/java/com/android/server/wm/ActivityStarter.java +++ b/services/core/java/com/android/server/wm/ActivityStarter.java @@ -1625,7 +1625,7 @@ class ActivityStarter { final ActivityRecord currentTop = startedActivityRootTask.topRunningActivity(); if (currentTop != null && currentTop.shouldUpdateConfigForDisplayChanged()) { mRootWindowContainer.ensureVisibilityAndConfig( - currentTop, currentTop.getDisplayId(), false /* deferResume */); + currentTop, currentTop.mDisplayContent, false /* deferResume */); } if (!avoidMoveToFront() && mDoResume && mRootWindowContainer diff --git a/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java b/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java index 2cda1f55b038..826e332b5f3c 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java +++ b/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java @@ -842,7 +842,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks { // Deferring resume here because we're going to launch new activity shortly. // We don't want to perform a redundant launch of the same record while ensuring // configurations and trying to resume top activity of focused root task. - mRootWindowContainer.ensureVisibilityAndConfig(r, r.getDisplayId(), + mRootWindowContainer.ensureVisibilityAndConfig(r, r.mDisplayContent, true /* deferResume */); } @@ -1011,7 +1011,8 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks { if (andResume && readyToResume()) { // As part of the process of launching, ActivityThread also performs // a resume. - rootTask.minimalResumeActivityLocked(r); + r.setState(RESUMED, "realStartActivityLocked"); + r.completeResumeLocked(); } else { // This activity is not starting in the resumed state... which should look like we asked // it to pause+stop (but remain visible), and it has done so and reported back the diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java index 07a03ebcc9b2..a75d3b6ef16d 100644 --- a/services/core/java/com/android/server/wm/RootWindowContainer.java +++ b/services/core/java/com/android/server/wm/RootWindowContainer.java @@ -1742,30 +1742,21 @@ class RootWindowContainer extends WindowContainer<DisplayContent> * * @param starting The currently starting activity or {@code null} if there is * none. - * @param displayId The id of the display where operation is executed. + * @param displayContent The display where the operation is executed. * @param deferResume Whether to defer resume while updating config. - * @return 'true' if starting activity was kept or wasn't provided, 'false' if it was relaunched - * because of configuration update. */ - boolean ensureVisibilityAndConfig(ActivityRecord starting, int displayId, boolean deferResume) { + void ensureVisibilityAndConfig(@Nullable ActivityRecord starting, + @NonNull DisplayContent displayContent, boolean deferResume) { // First ensure visibility without updating the config just yet. We need this to know what // activities are affecting configuration now. // Passing null here for 'starting' param value, so that visibility of actual starting // activity will be properly updated. ensureActivitiesVisible(null /* starting */, false /* notifyClients */); - if (displayId == INVALID_DISPLAY) { - // The caller didn't provide a valid display id, skip updating config. - return true; - } - // Force-update the orientation from the WindowManager, since we need the true configuration // to send to the client now. - final DisplayContent displayContent = getDisplayContent(displayId); - Configuration config = null; - if (displayContent != null) { - config = displayContent.updateOrientation(starting, true /* forceUpdate */); - } + final Configuration config = + displayContent.updateOrientation(starting, true /* forceUpdate */); // Visibilities may change so let the starting activity have a chance to report. Can't do it // when visibility is changed in each AppWindowToken because it may trigger wrong // configuration push because the visibility of some activities may not be updated yet. @@ -1773,13 +1764,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent> starting.reportDescendantOrientationChangeIfNeeded(); } - if (displayContent != null) { - // Update the configuration of the activities on the display. - return displayContent.updateDisplayOverrideConfigurationLocked(config, starting, - deferResume); - } else { - return true; - } + // Update the configuration of the activities on the display. + displayContent.updateDisplayOverrideConfigurationLocked(config, starting, deferResume); } /** diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 1353ff09b292..8574c97bcf75 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -4946,13 +4946,6 @@ class Task extends TaskFragment { } } - void minimalResumeActivityLocked(ActivityRecord r) { - ProtoLog.v(WM_DEBUG_STATES, "Moving to RESUMED: %s (starting new instance) " - + "callers=%s", r, Debug.getCallers(5)); - r.setState(RESUMED, "minimalResumeActivityLocked"); - r.completeResumeLocked(); - } - void checkReadyForSleep() { if (shouldSleepActivities() && goToSleepIfPossible(false /* shuttingDown */)) { mTaskSupervisor.checkReadyForSleepLocked(true /* allowDelay */); @@ -5861,7 +5854,7 @@ class Task extends TaskFragment { } mRootWindowContainer.ensureVisibilityAndConfig(null /* starting */, - mDisplayContent.mDisplayId, false /* deferResume */); + mDisplayContent, false /* deferResume */); } finally { if (mTransitionController.isShellTransitionsEnabled()) { mAtmService.continueWindowLayout(); diff --git a/services/core/java/com/android/server/wm/TaskFragment.java b/services/core/java/com/android/server/wm/TaskFragment.java index 85d81c4db2ca..d3485698589f 100644 --- a/services/core/java/com/android/server/wm/TaskFragment.java +++ b/services/core/java/com/android/server/wm/TaskFragment.java @@ -1533,10 +1533,6 @@ class TaskFragment extends WindowContainer<WindowContainer> { next.setState(RESUMED, "resumeTopActivity"); - // Have the window manager re-evaluate the orientation of - // the screen based on the new activity order. - boolean notUpdated = true; - // Activity should also be visible if set mLaunchTaskBehind to true (see // ActivityRecord#shouldBeVisibleIgnoringKeyguard()). if (shouldBeVisible(next)) { @@ -1548,28 +1544,15 @@ class TaskFragment extends WindowContainer<WindowContainer> { // result of invisible window resize. // TODO: Remove this once visibilities are set correctly immediately when // starting an activity. - notUpdated = !mRootWindowContainer.ensureVisibilityAndConfig(next, getDisplayId(), + final int originalRelaunchingCount = next.mPendingRelaunchCount; + mRootWindowContainer.ensureVisibilityAndConfig(next, mDisplayContent, false /* deferResume */); - } - - if (notUpdated) { - // The configuration update wasn't able to keep the existing - // instance of the activity, and instead started a new one. - // We should be all done, but let's just make sure our activity - // is still at the top and schedule another run if something - // weird happened. - ActivityRecord nextNext = topRunningActivity(); - ProtoLog.i(WM_DEBUG_STATES, "Activity config changed during resume: " - + "%s, new next: %s", next, nextNext); - if (nextNext != next) { - // Do over! - mTaskSupervisor.scheduleResumeTopActivities(); - } - if (!next.isVisibleRequested() || next.mAppStopped) { - next.setVisibility(true); + if (next.mPendingRelaunchCount > originalRelaunchingCount) { + // The activity is scheduled to relaunch, then ResumeActivityItem will be also + // included (see ActivityRecord#relaunchActivityLocked) if it should resume. + next.completeResumeLocked(); + return true; } - next.completeResumeLocked(); - return true; } try { @@ -1652,17 +1635,7 @@ class TaskFragment extends WindowContainer<WindowContainer> { return true; } - // From this point on, if something goes wrong there is no way - // to recover the activity. - try { - next.completeResumeLocked(); - } catch (Exception e) { - // If any exception gets thrown, toss away this - // activity and try the next one. - Slog.w(TAG, "Exception thrown during resume of " + next, e); - next.finishIfPossible("resume-exception", true /* oomAdj */); - return true; - } + next.completeResumeLocked(); } else { // Whoops, need to restart this activity! if (!next.hasBeenLaunched) { diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java index 09e7b9141e04..45a2ba4bfcca 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java @@ -3147,12 +3147,12 @@ public class ActivityRecordTests extends WindowTestsBase { // By default, activity is visible. assertTrue(activity.isVisible()); assertTrue(activity.isVisibleRequested()); - assertTrue(activity.mDisplayContent.mOpeningApps.contains(activity)); assertFalse(activity.mDisplayContent.mClosingApps.contains(activity)); // Request the activity to be visible. Although the activity is already visible, app // transition animation should be applied on this activity. This might be unnecessary, but // until we verify no logic relies on this behavior, we'll keep this as is. + mDisplayContent.prepareAppTransition(0); activity.setVisibility(true); assertTrue(activity.isVisible()); assertTrue(activity.isVisibleRequested()); @@ -3167,11 +3167,11 @@ public class ActivityRecordTests extends WindowTestsBase { // By default, activity is visible. assertTrue(activity.isVisible()); assertTrue(activity.isVisibleRequested()); - assertTrue(activity.mDisplayContent.mOpeningApps.contains(activity)); assertFalse(activity.mDisplayContent.mClosingApps.contains(activity)); // Request the activity to be invisible. Since the visibility changes, app transition // animation should be applied on this activity. + mDisplayContent.prepareAppTransition(0); activity.setVisibility(false); assertTrue(activity.isVisible()); assertFalse(activity.isVisibleRequested()); @@ -3187,7 +3187,6 @@ public class ActivityRecordTests extends WindowTestsBase { // activity. assertFalse(activity.isVisible()); assertTrue(activity.isVisibleRequested()); - assertTrue(activity.mDisplayContent.mOpeningApps.contains(activity)); assertFalse(activity.mDisplayContent.mClosingApps.contains(activity)); // Request the activity to be visible. Since the visibility changes, app transition @@ -3389,6 +3388,7 @@ public class ActivityRecordTests extends WindowTestsBase { // frozen until the input started. mDisplayContent.setImeLayeringTarget(app1); mDisplayContent.updateImeInputAndControlTarget(app1); + mDisplayContent.computeImeTarget(true /* updateImeTarget */); performSurfacePlacementAndWaitForWindowAnimator(); assertEquals(app1, mDisplayContent.getImeInputTarget()); diff --git a/services/tests/wmtests/src/com/android/server/wm/RootTaskTests.java b/services/tests/wmtests/src/com/android/server/wm/RootTaskTests.java index 527ea0d35f02..ce9050456681 100644 --- a/services/tests/wmtests/src/com/android/server/wm/RootTaskTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/RootTaskTests.java @@ -1239,7 +1239,7 @@ public class RootTaskTests extends WindowTestsBase { final ActivityRecord activity1 = finishTopActivity(rootTask1); assertEquals(DESTROYING, activity1.getState()); verify(mRootWindowContainer).ensureVisibilityAndConfig(eq(null) /* starting */, - eq(display.mDisplayId), anyBoolean()); + eq(display), anyBoolean()); } private ActivityRecord finishTopActivity(Task task) { diff --git a/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java b/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java index 60130635108c..47140dbbee5b 100644 --- a/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java @@ -835,8 +835,6 @@ public class RootWindowContainerTests extends WindowTestsBase { new TestDisplayContent.Builder(mAtm, 1000, 1500) .setSystemDecorations(true).build(); - doReturn(true).when(mRootWindowContainer) - .ensureVisibilityAndConfig(any(), anyInt(), anyBoolean()); doReturn(true).when(mRootWindowContainer).canStartHomeOnDisplayArea(any(), any(), anyBoolean()); |