OSDN Git Service

Make sure to report wait result when clean up activities
authorLouis Chang <louischang@google.com>
Wed, 20 Mar 2019 09:17:22 +0000 (17:17 +0800)
committerLouis Chang <louischang@google.com>
Mon, 25 Mar 2019 01:59:22 +0000 (09:59 +0800)
Starting activity with ‘-W’ option from shell waited forever
because activity was brought to top, but being removed from
waiting visible activities (due to process was gone) without
reporting the wait result.

Also correcting the component to avoid waiting for a top
finishing activity.

Bug: 117579987
Test: atest ActivityManagerAmStartOptionsTests

Change-Id: I7c1e6781544f0d794225a13fdf417475ff0598a3

services/core/java/com/android/server/wm/ActivityRecord.java
services/core/java/com/android/server/wm/ActivityStackSupervisor.java
services/core/java/com/android/server/wm/ActivityStarter.java

index 4706930..a519938 100644 (file)
@@ -2159,8 +2159,7 @@ final class ActivityRecord extends ConfigurationContainer {
         }
 
         if (nowVisible) {
-            // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now.
-            mStackSupervisor.reportActivityVisibleLocked(this);
+            mStackSupervisor.stopWaitingForActivityVisible(this);
         }
 
         // Schedule an idle timeout in case the app doesn't do it for us.
@@ -2349,7 +2348,7 @@ final class ActivityRecord extends ConfigurationContainer {
             final @LaunchState int launchState = info != null ? info.getLaunchState() : -1;
             mStackSupervisor.reportActivityLaunchedLocked(false /* timeout */, this,
                     windowsDrawnDelayMs, launchState);
-            mStackSupervisor.sendWaitingVisibleReportLocked(this);
+            mStackSupervisor.stopWaitingForActivityVisible(this);
             finishLaunchTickingLocked();
             if (task != null) {
                 task.hasBeenVisible = true;
@@ -2360,7 +2359,7 @@ final class ActivityRecord extends ConfigurationContainer {
     /** Called when the windows associated app window container are visible. */
     public void onWindowsVisible() {
         synchronized (mAtmService.mGlobalLock) {
-            mStackSupervisor.reportActivityVisibleLocked(this);
+            mStackSupervisor.stopWaitingForActivityVisible(this);
             if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this);
             if (!nowVisible) {
                 nowVisible = true;
index d7c9bc7..53dc1df 100644 (file)
@@ -553,18 +553,10 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
         // down to the max limit while they are still waiting to finish.
         mFinishingActivities.remove(r);
 
-        for (int i = mWaitingForActivityVisible.size() - 1; i >= 0; --i) {
-            if (mWaitingForActivityVisible.get(i).matches(r.mActivityComponent)) {
-                mWaitingForActivityVisible.remove(i);
-            }
-        }
-    }
-
-    void reportActivityVisibleLocked(ActivityRecord r) {
-        sendWaitingVisibleReportLocked(r);
+        stopWaitingForActivityVisible(r);
     }
 
-    void sendWaitingVisibleReportLocked(ActivityRecord r) {
+    void stopWaitingForActivityVisible(ActivityRecord r) {
         boolean changed = false;
         for (int i = mWaitingForActivityVisible.size() - 1; i >= 0; --i) {
             final WaitInfo w = mWaitingForActivityVisible.get(i);
index 2b23ff0..3acd4e7 100644 (file)
@@ -1538,10 +1538,13 @@ class ActivityStarter {
                 if (!mAddingToTask && mReuseTask == null) {
                     // We didn't do anything...  but it was needed (a.k.a., client don't use that
                     // intent!)  And for paranoia, make sure we have correctly resumed the top activity.
-
                     resumeTargetStackIfNeeded();
                     if (outActivity != null && outActivity.length > 0) {
-                        outActivity[0] = reusedActivity;
+                        // The reusedActivity could be finishing, for example of starting an
+                        // activity with FLAG_ACTIVITY_CLEAR_TOP flag. In that case, return the
+                        // top running activity in the task instead.
+                        outActivity[0] = reusedActivity.finishing
+                                ? reusedActivity.getTaskRecord().getTopActivity() : reusedActivity;
                     }
 
                     return mMovedToFront ? START_TASK_TO_FRONT : START_DELIVERED_TO_TOP;