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

Commit 9f970266 authored by Chris Li's avatar Chris Li
Browse files

Fix crashed reportSystemGestureExclusionChanged

As an IPC call, there is a small chance that the window is removed
before this method is called. Similar to setOnBackInvokedCallback(), log
instead of exception

Fix: 288913430
Test: atest WmTests:WindowManagerServiceTests
Change-Id: I914ae438f1468f6b49d3948baac5fb45df48f3f8
parent ac6b6e99
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -4648,7 +4648,14 @@ public class WindowManagerService extends IWindowManager.Stub
    void reportSystemGestureExclusionChanged(Session session, IWindow window,
            List<Rect> exclusionRects) {
        synchronized (mGlobalLock) {
            final WindowState win = windowForClientLocked(session, window, true);
            final WindowState win = windowForClientLocked(session, window,
                    false /* throwOnError */);
            if (win == null) {
                Slog.i(TAG_WM,
                        "reportSystemGestureExclusionChanged(): No window state for package:"
                                + session.mPackageName);
                return;
            }
            if (win.setSystemGestureExclusion(exclusionRects)) {
                win.getDisplayContent().updateSystemGestureExclusion();
            }
@@ -4658,7 +4665,14 @@ public class WindowManagerService extends IWindowManager.Stub
    void reportKeepClearAreasChanged(Session session, IWindow window,
            List<Rect> restricted, List<Rect> unrestricted) {
        synchronized (mGlobalLock) {
            final WindowState win = windowForClientLocked(session, window, true);
            final WindowState win = windowForClientLocked(session, window,
                    false /* throwOnError */);
            if (win == null) {
                Slog.i(TAG_WM,
                        "reportKeepClearAreasChanged(): No window state for package:"
                                + session.mPackageName);
                return;
            }
            if (win.setKeepClearAreas(restricted, unrestricted)) {
                win.getDisplayContent().updateKeepClearAreas();
            }
+24 −0
Original line number Diff line number Diff line
@@ -107,6 +107,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;

import java.util.ArrayList;

/**
 * Build/Install/Run:
 * atest WmTests:WindowManagerServiceTests
@@ -975,6 +977,28 @@ public class WindowManagerServiceTests extends WindowTestsBase {
        verify(window, times(2)).requestAppKeyboardShortcuts(receiver, 0);
    }

    @Test
    public void testReportSystemGestureExclusionChanged_invalidWindow() {
        final Session session = mock(Session.class);
        final IWindow window = mock(IWindow.class);
        final IBinder binder = mock(IBinder.class);
        doReturn(binder).when(window).asBinder();

        // No exception even if the window doesn't exist
        mWm.reportSystemGestureExclusionChanged(session, window, new ArrayList<>());
    }

    @Test
    public void testReportKeepClearAreasChanged_invalidWindow() {
        final Session session = mock(Session.class);
        final IWindow window = mock(IWindow.class);
        final IBinder binder = mock(IBinder.class);
        doReturn(binder).when(window).asBinder();

        // No exception even if the window doesn't exist
        mWm.reportKeepClearAreasChanged(session, window, new ArrayList<>(), new ArrayList<>());
    }

    class TestResultReceiver implements IResultReceiver {
        public android.os.Bundle resultData;
        private final IBinder mBinder = mock(IBinder.class);