Start all visible running activities when attaching app
This fixes an issue where a translucent activity was on top of a
normal activity in the same process. Now, when reopening the
translucent activity after the process has been killed we only
used to start the very top activity, leaving the normal activity
in destroyed state. However, we make the activity visible already
so in window manager we are waiting for it but a window is never
added to it.
This fixes the issue by starting all activities that are visible
and running once the app is attached.
Test: go/wm-smoke
Test: Have app with translucent activity on top of normal
activity, kill app via shell, navigate back to app via recents.
Observe no excessive delay.
Change-Id: I444b7064b8e2e878fac5fa9ac8b36e0e2fe248bc
Fixes: 33269100
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
index 51e0e3b..d75e6a9 100644
--- a/services/core/java/com/android/server/am/ActivityStack.java
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -659,6 +659,13 @@
return topRunningActivityLocked(false /* focusableOnly */);
}
+ void getAllRunningVisibleActivitiesLocked(ArrayList<ActivityRecord> outActivities) {
+ outActivities.clear();
+ for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+ mTaskHistory.get(taskNdx).getAllRunningVisibleActivitiesLocked(outActivities);
+ }
+ }
+
private ActivityRecord topRunningActivityLocked(boolean focusableOnly) {
for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked();
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index f3963ed..ce86624 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -457,6 +457,8 @@
final ActivityMetricsLogger mActivityMetricsLogger;
+ private final ArrayList<ActivityRecord> mTmpActivityList = new ArrayList<>();
+
@Override
protected int getChildCount() {
return mActivityDisplays.size();
@@ -964,17 +966,21 @@
if (!isFocusedStack(stack)) {
continue;
}
- ActivityRecord hr = stack.topRunningActivityLocked();
- if (hr != null) {
- if (hr.app == null && app.uid == hr.info.applicationInfo.uid
- && processName.equals(hr.processName)) {
+ stack.getAllRunningVisibleActivitiesLocked(mTmpActivityList);
+ final ActivityRecord top = stack.topRunningActivityLocked();
+ final int size = mTmpActivityList.size();
+ for (int i = 0; i < size; i++) {
+ final ActivityRecord activity = mTmpActivityList.get(i);
+ if (activity.app == null && app.uid == activity.info.applicationInfo.uid
+ && processName.equals(activity.processName)) {
try {
- if (realStartActivityLocked(hr, app, true, true)) {
+ if (realStartActivityLocked(activity, app,
+ top == activity /* andResume */, true /* checkConfig */)) {
didSomething = true;
}
} catch (RemoteException e) {
Slog.w(TAG, "Exception in new application when starting activity "
- + hr.intent.getComponent().flattenToShortString(), e);
+ + top.intent.getComponent().flattenToShortString(), e);
throw e;
}
}
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
index 96d8573..24e0692 100644
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -1160,6 +1160,17 @@
return null;
}
+ void getAllRunningVisibleActivitiesLocked(ArrayList<ActivityRecord> outActivities) {
+ if (mStack != null) {
+ for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
+ ActivityRecord r = mActivities.get(activityNdx);
+ if (!r.finishing && r.okToShowLocked() && r.visible) {
+ outActivities.add(r);
+ }
+ }
+ }
+ }
+
ActivityRecord topRunningActivityWithStartingWindowLocked() {
if (mStack != null) {
for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {