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

Commit 1599b648 authored by Ming-Shin Lu's avatar Ming-Shin Lu Committed by Android (Google) Code Review
Browse files

Merge "Add Null check when excluding IME window surface for snapshot"

parents 30afb2d5 8260aebe
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -369,7 +369,8 @@ class TaskSnapshotController {
        SurfaceControl[] excludeLayers;
        final WindowState imeWindow = task.getDisplayContent().mInputMethodWindow;
        // Exclude IME window snapshot when IME isn't proper to attach to app.
        if (imeWindow != null && !task.getDisplayContent().isImeAttachedToApp()) {
        if (imeWindow != null && imeWindow.getSurfaceControl() != null
                && !task.getDisplayContent().isImeAttachedToApp()) {
            excludeLayers = new SurfaceControl[1];
            excludeLayers[0] = imeWindow.getSurfaceControl();
        } else {
+20 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;

import android.app.ActivityManager;
import android.app.WindowConfiguration;
@@ -183,6 +185,24 @@ public class TaskSnapshotControllerTest extends WindowTestsBase {
        }
    }

    @UseTestDisplay(addWindows = {W_ACTIVITY, W_INPUT_METHOD})
    @Test
    public void testCreateTaskSnapshotWithExcludingIme() {
        Task task = mAppWindow.mActivityRecord.getTask();
        spyOn(task);
        spyOn(mDisplayContent);
        when(task.getDisplayContent().isImeAttachedToApp()).thenReturn(false);
        // Intentionally set the SurfaceControl of input method window as null.
        mDisplayContent.mInputMethodWindow.setSurfaceControl(null);
        // Verify no NPE happens when calling createTaskSnapshot.
        try {
            mWm.mTaskSnapshotController.createTaskSnapshot(mAppWindow.mActivityRecord.getTask(),
                    1f /* scaleFraction */, PixelFormat.UNKNOWN, null /* outTaskSize */);
        } catch (NullPointerException e) {
            fail("There should be no exception when calling createTaskSnapshot");
        }
    }

    @UseTestDisplay(addWindows = W_ACTIVITY)
    @Test
    public void testPrepareTaskSnapshot() {