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

Commit bbc072be authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Correctly dispose of input channels." into main

parents 326973a1 c76ef2ce
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -23,12 +23,12 @@ import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERL
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;

import static com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.ResizeTrigger;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE;
import static com.android.wm.shell.windowdecor.DragPositioningCallback.CTRL_TYPE_BOTTOM;
import static com.android.wm.shell.windowdecor.DragPositioningCallback.CTRL_TYPE_LEFT;
import static com.android.wm.shell.windowdecor.DragPositioningCallback.CTRL_TYPE_RIGHT;
import static com.android.wm.shell.windowdecor.DragPositioningCallback.CTRL_TYPE_TOP;
import static com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.ResizeTrigger;
import static com.android.wm.shell.windowdecor.DragResizeWindowGeometry.isEdgeResizePermitted;
import static com.android.wm.shell.windowdecor.DragResizeWindowGeometry.isEventFromTouchscreen;

@@ -127,7 +127,9 @@ class DragResizeInputListener implements AutoCloseable {
            Supplier<SurfaceControl.Builder> surfaceControlBuilderSupplier,
            Supplier<SurfaceControl.Transaction> surfaceControlTransactionSupplier,
            DisplayController displayController,
            DesktopModeEventLogger desktopModeEventLogger) {
            DesktopModeEventLogger desktopModeEventLogger,
            InputChannel inputChannel,
            InputChannel sinkInputChannel) {
        mContext = context;
        mWindowSession = windowSession;
        mBgExecutor = bgExecutor;
@@ -154,9 +156,13 @@ class DragResizeInputListener implements AutoCloseable {
            final InputSetUpResult result = setUpInputChannels(mDisplayId, mWindowSession,
                    mDecorationSurface, mClientToken, mSinkClientToken,
                    mSurfaceControlBuilderSupplier,
                    mSurfaceControlTransactionSupplier);
                    mSurfaceControlTransactionSupplier, inputChannel, sinkInputChannel);
            mainExecutor.execute(() -> {
                if (mClosed) {
                    result.mInputChannel.dispose();
                    result.mSinkInputChannel.dispose();
                    mSurfaceControlTransactionSupplier.get().remove(
                            result.mInputSinkSurface).apply();
                    return;
                }
                mInputSinkSurface = result.mInputSinkSurface;
@@ -208,7 +214,7 @@ class DragResizeInputListener implements AutoCloseable {
                new DefaultTaskResizeInputEventReceiverFactory(), taskInfo,
                handler, choreographer, displayId, decorationSurface, callback,
                surfaceControlBuilderSupplier, surfaceControlTransactionSupplier,
                displayController, desktopModeEventLogger);
                displayController, desktopModeEventLogger, new InputChannel(), new InputChannel());
    }

    DragResizeInputListener(
@@ -251,11 +257,11 @@ class DragResizeInputListener implements AutoCloseable {
            @NonNull IBinder clientToken,
            @NonNull IBinder sinkClientToken,
            @NonNull Supplier<SurfaceControl.Builder> surfaceControlBuilderSupplier,
            @NonNull Supplier<SurfaceControl.Transaction> surfaceControlTransactionSupplier) {
            @NonNull Supplier<SurfaceControl.Transaction> surfaceControlTransactionSupplier,
            @NonNull InputChannel inputChannel,
            @NonNull InputChannel sinkInputChannel) {
        Trace.beginSection("DragResizeInputListener#setUpInputChannels");
        final InputTransferToken inputTransferToken = new InputTransferToken();
        final InputChannel inputChannel = new InputChannel();
        final InputChannel sinkInputChannel = new InputChannel();
        try {
            windowSession.grantInputChannel(
                    displayId,
+14 −0
Original line number Diff line number Diff line
@@ -63,6 +63,8 @@ class DragResizeInputListenerTest : ShellTestCase() {
    private val testBgExecutor = TestShellExecutor()
    private val mockWindowSession = mock<IWindowSession>()
    private val mockInputEventReceiver = mock<TaskResizeInputEventReceiver>()
    private val inputChannel = mock<InputChannel>()
    private val sinkInputChannel = mock<InputChannel>()

    @Test
    fun testGrantInputChannelOffMainThread() {
@@ -143,6 +145,16 @@ class DragResizeInputListenerTest : ShellTestCase() {
        verify(mockWindowSession).remove(inputListener.mSinkClientToken)
    }

    @Test
    fun testClose_afterBgSetup_disposesOfInputChannels() {
        val inputListener = create()
        testBgExecutor.flushAll()
        inputListener.close()
        testMainExecutor.flushAll()
        verify(inputChannel).dispose()
        verify(sinkInputChannel).dispose()
    }

    private fun verifyNoInputChannelGrantRequests() {
        verify(mockWindowSession, never())
            .grantInputChannel(
@@ -178,6 +190,8 @@ class DragResizeInputListenerTest : ShellTestCase() {
            { StubTransaction() },
            mock<DisplayController>(),
            mock<DesktopModeEventLogger>(),
            inputChannel,
            sinkInputChannel,
        )

    private class TestInitializationCallback : Runnable {