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

Commit d11c1826 authored by Maryam Dehaini's avatar Maryam Dehaini
Browse files

Fix NPE in DesktopModeWindowDecor#setAnimatingTaskResizeOrReposition

setAnimatingTaskResizeOrReposition currently check if the viewHolder is
an instance of an AppHandleViewHolder, and, if so, returns. However,
this does not account in cases where the view holder is null (i.e. if
the app crashes before setAnimatingTaskResizeOrReposition is called).

Bug: 406515706
Test: drag to desktop
Flag: EXEMPT bugfix
Change-Id: Ibce8eba0eb8c45ee9d87c91a062c6a305cee7f78
parent f4740b36
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1871,7 +1871,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
    }

    void setAnimatingTaskResizeOrReposition(boolean animatingTaskResizeOrReposition) {
        if (mRelayoutParams.mLayoutResId == R.layout.desktop_mode_app_handle) return;
        if (!isAppHeader(mWindowDecorViewHolder)) return;
        final boolean inFullImmersive =
                mDesktopUserRepositories.getProfile(mTaskInfo.userId)
                        .isTaskInFullImmersiveState(mTaskInfo.taskId);
+18 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import static com.google.common.truth.Truth.assertThat;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;

import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.argThat;
@@ -1705,6 +1706,23 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
        verifyHandleMenuCreated(TEST_URI3);
    }

    @Test
    public void setAnimatingTaskResizeOrReposition_returnsWhenViewHolderIsNull() {
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final DesktopModeWindowDecoration decor =
                spy(createWindowDecoration(taskInfo, true /* relayout */));

        // Close the decor to close the view holder and set it to null
        decor.close();

        // Verify returns when view holder is null
        try {
            decor.setAnimatingTaskResizeOrReposition(true /* animatingTaskResizeOrReposition */);
        } catch (NullPointerException e) {
            fail("Attempted to access view holder after window decor is closed");
        }
    }


    private void verifyHandleMenuCreated(@Nullable Uri uri) {
        verify(mMockHandleMenuFactory).create(any(), any(), any(), any(), any(), anyInt(),