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

Commit 766f2629 authored by Chris Li's avatar Chris Li
Browse files

Catch RejectedExecutionException for DisplayChanged from WM

Fix: 339385595
Test: atest FrameworksCoreTests:ClientTransactionListenerControllerTest
Change-Id: I5620ed93c1395a7c39654ec254c11e31081d10a7
parent d885398d
Loading
Loading
Loading
Loading
+20 −6
Original line number Diff line number Diff line
@@ -33,11 +33,13 @@ import android.hardware.display.DisplayManagerGlobal;
import android.os.IBinder;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
import android.window.ActivityWindowInfo;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;

import java.util.concurrent.RejectedExecutionException;
import java.util.function.BiConsumer;

/**
@@ -47,6 +49,8 @@ import java.util.function.BiConsumer;
 */
public class ClientTransactionListenerController {

    private static final String TAG = "ClientTransactionListenerController";

    private static ClientTransactionListenerController sController;

    private final Object mLock = new Object();
@@ -179,11 +183,15 @@ public class ClientTransactionListenerController {
        }

        // Dispatch the display changed callbacks.
        try {
            final int displayCount = configUpdatedDisplayIds.size();
            for (int i = 0; i < displayCount; i++) {
                final int displayId = configUpdatedDisplayIds.valueAt(i);
                onDisplayChanged(displayId);
            }
        } catch (RejectedExecutionException e) {
            Log.w(TAG, "Failed to notify DisplayListener because the Handler is shutting down");
        }
    }

    /** Called before updating the Configuration of the given {@code context}. */
@@ -222,7 +230,11 @@ public class ClientTransactionListenerController {
        }

        if (changedDisplayId != INVALID_DISPLAY) {
            try {
                onDisplayChanged(changedDisplayId);
            } catch (RejectedExecutionException e) {
                Log.w(TAG, "Failed to notify DisplayListener because the Handler is shutting down");
            }
        }
    }

@@ -235,9 +247,11 @@ public class ClientTransactionListenerController {
    /**
     * Called when receives a {@link Configuration} changed event that is updating display-related
     * window configuration.
     *
     * @throws RejectedExecutionException if the display listener handler is closing.
     */
    @VisibleForTesting
    public void onDisplayChanged(int displayId) {
    public void onDisplayChanged(int displayId) throws RejectedExecutionException {
        mDisplayManager.handleDisplayChangeFromWindowManager(displayId);
    }
}
+15 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -65,6 +66,7 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.concurrent.RejectedExecutionException;
import java.util.function.BiConsumer;

/**
@@ -221,4 +223,17 @@ public class ClientTransactionListenerControllerTest {
                123 /* newDisplayId */, true /* shouldReportConfigChange*/);
        inOrder.verify(mController).onContextConfigurationPostChanged(context);
    }

    @Test
    public void testDisplayListenerHandlerClosed() {
        doReturn(123).when(mActivity).getDisplayId();
        doThrow(new RejectedExecutionException()).when(mController).onDisplayChanged(123);

        mController.onContextConfigurationPreChanged(mActivity);
        mConfiguration.windowConfiguration.setMaxBounds(new Rect(0, 0, 100, 200));
        mController.onContextConfigurationPostChanged(mActivity);

        // No crash
        verify(mController).onDisplayChanged(123);
    }
}