Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5cdbeb1a authored by wilsonshih's avatar wilsonshih
Browse files

Ensure no starting window leak in WMShell before adding.

Before adding the snapshot start window, remove any existing window
at the same task if any. Also make sure if starting window was create
failed, the window should be remove after it been added.

Bug: 185318171
Test: manual test without ag/14308714
Change-Id: I5de7d54907bc0318c6d979c44ca8e64a5fcea062
parent 87a5a818
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -347,8 +347,13 @@ public class StartingSurfaceDrawer {
    void makeTaskSnapshotWindow(StartingWindowInfo startingWindowInfo, IBinder appToken,
            TaskSnapshot snapshot) {
        final int taskId = startingWindowInfo.taskInfo.taskId;
        // Remove any existing starting window for this task before adding.
        removeWindowNoAnimate(taskId);
        final TaskSnapshotWindow surface = TaskSnapshotWindow.create(startingWindowInfo, appToken,
                snapshot, mSplashScreenExecutor, () -> removeWindowNoAnimate(taskId));
        if (surface == null) {
            return;
        }
        final StartingWindowRecord tView = new StartingWindowRecord(appToken,
                null/* decorView */, surface);
        mStartingWindowRecords.put(taskId, tView);
+30 −31
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import static com.android.internal.policy.DecorView.STATUS_BAR_COLOR_VIEW_ATTRIB
import static com.android.internal.policy.DecorView.getNavigationBarRect;

import android.annotation.BinderThread;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityManager.TaskDescription;
@@ -141,7 +142,8 @@ public class TaskSnapshotWindow {
    private final float[] mTmpFloat9 = new float[9];

    static TaskSnapshotWindow create(StartingWindowInfo info, IBinder appToken,
            TaskSnapshot snapshot, ShellExecutor mainExecutor, Runnable clearWindowHandler) {
            TaskSnapshot snapshot, ShellExecutor splashScreenExecutor,
            @NonNull Runnable clearWindowHandler) {
        final ActivityManager.RunningTaskInfo runningTaskInfo = info.taskInfo;
        final int taskId = runningTaskInfo.taskId;
        if (DEBUG) {
@@ -208,12 +210,12 @@ public class TaskSnapshotWindow {
        final TaskSnapshotWindow snapshotSurface = new TaskSnapshotWindow(
                surfaceControl, snapshot, layoutParams.getTitle(), taskDescription, appearance,
                windowFlags, windowPrivateFlags, taskBounds, orientation,
                topWindowInsetsState, clearWindowHandler, mainExecutor);
                topWindowInsetsState, clearWindowHandler, splashScreenExecutor);
        final Window window = snapshotSurface.mWindow;

        final InsetsState mTmpInsetsState = new InsetsState();
        final InputChannel tmpInputChannel = new InputChannel();
        mainExecutor.execute(() -> {

        try {
            Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "TaskSnapshot#addToDisplay");
            final int res = session.addToDisplay(window, layoutParams, View.GONE, displayId,
@@ -221,7 +223,7 @@ public class TaskSnapshotWindow {
            Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
            if (res < 0) {
                Slog.w(TAG, "Failed to add snapshot starting window res=" + res);
                    return;
                return null;
            }
        } catch (RemoteException e) {
            snapshotSurface.clearWindowSynced();
@@ -240,7 +242,6 @@ public class TaskSnapshotWindow {
        final Rect systemBarInsets = getSystemBarInsets(tmpFrames.frame, topWindowInsetsState);
        snapshotSurface.setFrames(tmpFrames.frame, systemBarInsets);
        snapshotSurface.drawSnapshot();
        });
        return snapshotSurface;
    }

@@ -469,9 +470,7 @@ public class TaskSnapshotWindow {
     * Clear window from drawer, must be post on main executor.
     */
    private void clearWindowSynced() {
        if (mClearWindowHandler != null) {
            mClearWindowHandler.run();
        }
        mSplashScreenExecutor.executeDelayed(mClearWindowHandler, 0);
    }

    private void reportDrawn() {