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

Commit aeca005a authored by wilsonshih's avatar wilsonshih Committed by Wei Sheng Shih
Browse files

Validate the surface of snapshot window before draw.

Core will not create surface for the snapshot window if the window was
removed just during launch app sequence, and there won't return any
error message for this case. Validate the out surface before draw to
preventing for crash.

Flag: EXEMPT bugfix
Bug: 351721867
Test: atest StartingSurfaceDrawerTests
Change-Id: I1b7926299b710cf2e965a61c75a362dbd19701f1
parent 611e4316
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -146,6 +146,11 @@ public class TaskSnapshotWindow {
            Slog.w(TAG, "Failed to relayout snapshot starting window");
            return null;
        }
        if (!surfaceControl.isValid()) {
            snapshotSurface.clearWindowSynced();
            Slog.w(TAG, "Unable to draw snapshot, no valid surface");
            return null;
        }

        SnapshotDrawerUtils.drawSnapshotOnSurface(info, layoutParams, surfaceControl, snapshot,
                info.taskBounds, topWindowInsetsState, true /* releaseAfterDraw */);
+5 −15
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import static com.android.wm.shell.startingsurface.SplashscreenContentDrawer.MIN
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.times;
@@ -56,12 +55,11 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.UserHandle;
import android.testing.TestableContext;
import android.view.IWindowSession;
import android.view.InsetsState;
import android.view.Surface;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import android.view.WindowMetrics;
import android.window.SnapshotDrawerUtils;
import android.window.StartingWindowInfo;
import android.window.StartingWindowRemovalInfo;
import android.window.TaskSnapshot;
@@ -220,18 +218,10 @@ public class StartingSurfaceDrawerTests extends ShellTestCase {
                createWindowInfo(taskId, android.R.style.Theme, mBinder);
        TaskSnapshot snapshot = createTaskSnapshot(100, 100, new Point(100, 100),
                new Rect(0, 0, 0, 50), true /* hasImeSurface */);
        final IWindowSession session = WindowManagerGlobal.getWindowSession();
        spyOn(session);
        doReturn(WindowManagerGlobal.ADD_OKAY).when(session).addToDisplay(
                any() /* window */, any() /* attrs */,
                anyInt() /* viewVisibility */, anyInt() /* displayId */,
                anyInt() /* requestedVisibleTypes */, any() /* outInputChannel */,
                any() /* outInsetsState */, any() /* outActiveControls */,
                any() /* outAttachedFrame */, any() /* outSizeCompatScale */);
        TaskSnapshotWindow mockSnapshotWindow = TaskSnapshotWindow.create(windowInfo,
                mBinder,
                snapshot, mTestExecutor, () -> {
                });
        final TaskSnapshotWindow mockSnapshotWindow = new TaskSnapshotWindow(
                snapshot, SnapshotDrawerUtils.getOrCreateTaskDescription(windowInfo.taskInfo),
                snapshot.getOrientation(),
                () -> {}, mTestExecutor);
        spyOn(mockSnapshotWindow);
        try (AutoCloseable mockTaskSnapshotSession = new AutoCloseable() {
            MockitoSession mockSession = mockitoSession()