Merge "Prevent IndexOOB when handling app crash"

This commit is contained in:
Louis Chang
2022-06-08 14:30:29 +00:00
committed by Android (Google) Code Review
4 changed files with 17 additions and 31 deletions

View File

@@ -6474,9 +6474,9 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
}
@Override
public void onHandleAppCrash(WindowProcessController wpc) {
public void onHandleAppCrash(@NonNull WindowProcessController wpc) {
synchronized (mGlobalLock) {
mRootWindowContainer.handleAppCrash(wpc);
wpc.handleAppCrash();
}
}

View File

@@ -32,8 +32,6 @@ import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE;
import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
import static android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_FLAG_APP_CRASHED;
import static android.view.WindowManager.TRANSIT_NONE;
import static android.view.WindowManager.TRANSIT_PIP;
import static android.view.WindowManager.TRANSIT_TO_BACK;
@@ -2723,23 +2721,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
return result[0];
}
void handleAppCrash(WindowProcessController app) {
final PooledConsumer c = PooledLambda.obtainConsumer(
RootWindowContainer::handleAppCrash, PooledLambda.__(ActivityRecord.class), app);
forAllActivities(c);
c.recycle();
}
private static void handleAppCrash(ActivityRecord r, WindowProcessController app) {
if (r.app != app) return;
Slog.w(TAG, " Force finishing activity "
+ r.intent.getComponent().flattenToShortString());
r.detachFromProcess();
r.mDisplayContent.requestTransitionAndLegacyPrepare(TRANSIT_CLOSE,
TRANSIT_FLAG_APP_CRASHED);
r.destroyIfPossible("handleAppCrashed");
}
ActivityRecord findActivity(Intent intent, ActivityInfo info, boolean compareIntentFilters) {
ComponentName cls = intent.getComponent();
if (info.targetActivity != null) {

View File

@@ -1509,16 +1509,7 @@ class Task extends TaskFragment {
!REMOVE_FROM_RECENTS, reason);
}
} else if (!mReuseTask && shouldRemoveSelfOnLastChildRemoval()) {
// Remove entire task if it doesn't have any activity left and it isn't marked for reuse
// or created by task organizer.
if (!isRootTask()) {
final WindowContainer<?> parent = getParent();
if (parent != null) {
parent.asTaskFragment().removeChild(this);
}
}
EventLogTags.writeWmTaskRemoved(mTaskId,
"removeChild:" + reason + " last r=" + r + " in t=" + this);
reason += ", last child = " + r + " in " + this;
removeIfPossible(reason);
}
}

View File

@@ -22,6 +22,8 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.content.res.Configuration.ASSETS_SEQ_UNDEFINED;
import static android.os.Build.VERSION_CODES.Q;
import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_FLAG_APP_CRASHED;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_CONFIGURATION;
import static com.android.internal.util.Preconditions.checkArgument;
@@ -353,6 +355,18 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
mCrashing = crashing;
}
void handleAppCrash() {
for (int i = mActivities.size() - 1; i >= 0; --i) {
final ActivityRecord r = mActivities.get(i);
Slog.w(TAG, " Force finishing activity "
+ r.mActivityComponent.flattenToShortString());
r.detachFromProcess();
r.mDisplayContent.requestTransitionAndLegacyPrepare(TRANSIT_CLOSE,
TRANSIT_FLAG_APP_CRASHED);
r.destroyIfPossible("handleAppCrashed");
}
}
boolean isCrashing() {
return mCrashing;
}