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

Commit c76ef2ce authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Correctly dispose of input channels.

Previously, DragResizeInputListener did not dispose of input channels
when they were registered on a background thread and then
DragResizeInputListener was closed before the channels were populated on
the main thread. This change adds the necessary cleanup.

Flag: com.android.window.flags.enable_drag_resize_set_up_in_bg_thread
Bug: 401999837
Test: DragResizeInputListenerTest
Change-Id: I0c6f1e5e9de5df9ea5918fb9926e70e444842f77
parent 12bd0c83
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 {