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

Commit b4d9b79e authored by Winson Chung's avatar Winson Chung
Browse files

Generalize the unhandled drag listener for other global drag callbacks

- Basically rename unhandled drag listener -> global drag listener

Bug: 320797628
Test: atest DragDropTests DragDropControllerTests CrossAppDragAndDropTests
Test: atest WMShellUnitTests
Change-Id: I96d7f7223852af358d45edbe7b0db135944af2b1
parent 1a191c20
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -69,11 +69,11 @@ import android.view.SurfaceControl;
import android.view.displayhash.DisplayHash;
import android.view.displayhash.VerifiedDisplayHash;
import android.window.AddToSurfaceSyncGroupResult;
import android.window.IGlobalDragListener;
import android.window.IScreenRecordingCallback;
import android.window.ISurfaceSyncGroupCompletedListener;
import android.window.ITaskFpsCallback;
import android.window.ITrustedPresentationListener;
import android.window.IUnhandledDragListener;
import android.window.InputTransferToken;
import android.window.ScreenCapture;
import android.window.TrustedPresentationThresholds;
@@ -1094,10 +1094,9 @@ interface IWindowManager
    void unregisterScreenRecordingCallback(IScreenRecordingCallback callback);

    /**
     * Sets the listener to be called back when a cross-window drag and drop operation is unhandled
     * (ie. not handled by any window which can handle the drag).
     * Sets the listener to be called back when a cross-window drag and drop operation happens.
     */
    void setUnhandledDragListener(IUnhandledDragListener listener);
    void setGlobalDragListener(IGlobalDragListener listener);

    boolean transferTouchGesture(in InputTransferToken transferFromToken,
            in InputTransferToken transferToToken);
+2 −2
Original line number Diff line number Diff line
@@ -20,10 +20,10 @@ import android.view.DragEvent;
import android.window.IUnhandledDragCallback;

/**
 * An interface to a handler for global drags that are not consumed (ie. not handled by any window).
 * An interface to a handler for global drags.
 * {@hide}
 */
oneway interface IUnhandledDragListener {
oneway interface IGlobalDragListener {
    /**
     * Called when the user finishes the drag gesture but no windows have reported handling the
     * drop.  The DragEvent is populated with the drag surface for the listener to animate.  The
+3 −3
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ import com.android.wm.shell.desktopmode.EnterDesktopTaskTransitionHandler;
import com.android.wm.shell.desktopmode.ExitDesktopTaskTransitionHandler;
import com.android.wm.shell.desktopmode.ToggleResizeDesktopTaskTransitionHandler;
import com.android.wm.shell.draganddrop.DragAndDropController;
import com.android.wm.shell.draganddrop.UnhandledDragController;
import com.android.wm.shell.draganddrop.GlobalDragListener;
import com.android.wm.shell.freeform.FreeformComponents;
import com.android.wm.shell.freeform.FreeformTaskListener;
import com.android.wm.shell.freeform.FreeformTaskTransitionHandler;
@@ -562,10 +562,10 @@ public abstract class WMShellModule {

    @WMSingleton
    @Provides
    static UnhandledDragController provideUnhandledDragController(
    static GlobalDragListener provideGlobalDragListener(
            IWindowManager wmService,
            @ShellMainThread ShellExecutor mainExecutor) {
        return new UnhandledDragController(wmService, mainExecutor);
        return new GlobalDragListener(wmService, mainExecutor);
    }

    @WMSingleton
+12 −12
Original line number Diff line number Diff line
@@ -19,8 +19,8 @@ import android.os.RemoteException
import android.util.Log
import android.view.DragEvent
import android.view.IWindowManager
import android.window.IGlobalDragListener
import android.window.IUnhandledDragCallback
import android.window.IUnhandledDragListener
import androidx.annotation.VisibleForTesting
import com.android.internal.protolog.common.ProtoLog
import com.android.wm.shell.common.ShellExecutor
@@ -30,25 +30,25 @@ import java.util.function.Consumer
/**
 * Manages the listener and callbacks for unhandled global drags.
 */
class UnhandledDragController(
class GlobalDragListener(
    val wmService: IWindowManager,
    mainExecutor: ShellExecutor
) {
    private var callback: UnhandledDragAndDropCallback? = null
    private var callback: GlobalDragListenerCallback? = null

    private val unhandledDragListener: IUnhandledDragListener =
        object : IUnhandledDragListener.Stub() {
    private val globalDragListener: IGlobalDragListener =
        object : IGlobalDragListener.Stub() {
            override fun onUnhandledDrop(event: DragEvent, callback: IUnhandledDragCallback) {
                mainExecutor.execute() {
                    this@UnhandledDragController.onUnhandledDrop(event, callback)
                    this@GlobalDragListener.onUnhandledDrop(event, callback)
                }
            }
        }

    /**
     * Listener called when an unhandled drag is started.
     * Callbacks for global drag events.
     */
    interface UnhandledDragAndDropCallback {
    interface GlobalDragListenerCallback {
        /**
         * Called when a global drag is unhandled (ie. dropped outside of all visible windows, or
         * dropped on a window that does not want to handle it).
@@ -62,7 +62,7 @@ class UnhandledDragController(
    /**
     * Sets a listener for callbacks when an unhandled drag happens.
     */
    fun setListener(listener: UnhandledDragAndDropCallback?) {
    fun setListener(listener: GlobalDragListenerCallback?) {
        val updateWm = (callback == null && listener != null)
                || (callback != null && listener == null)
        callback = listener
@@ -71,8 +71,8 @@ class UnhandledDragController(
                ProtoLog.v(ShellProtoLogGroup.WM_SHELL_DRAG_AND_DROP,
                    "%s unhandled drag listener",
                    if (callback != null) "Registering" else "Unregistering")
                wmService.setUnhandledDragListener(
                    if (callback != null) unhandledDragListener else null)
                wmService.setGlobalDragListener(
                    if (callback != null) globalDragListener else null)
            } catch (e: RemoteException) {
                Log.e(TAG, "Failed to set unhandled drag listener")
            }
@@ -95,6 +95,6 @@ class UnhandledDragController(
    }

    companion object {
        private val TAG = UnhandledDragController::class.java.simpleName
        private val TAG = GlobalDragListener::class.java.simpleName
    }
}
+9 −9
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.draganddrop.UnhandledDragController.UnhandledDragAndDropCallback
import com.android.wm.shell.draganddrop.GlobalDragListener.GlobalDragListenerCallback
import java.util.function.Consumer
import junit.framework.Assert.assertEquals
import org.junit.Before
@@ -51,29 +51,29 @@ class UnhandledDragControllerTest : ShellTestCase() {
    @Mock
    private lateinit var mMainExecutor: ShellExecutor

    private lateinit var mController: UnhandledDragController
    private lateinit var mController: GlobalDragListener

    @Before
    @Throws(RemoteException::class)
    fun setUp() {
        MockitoAnnotations.initMocks(this)
        mController = UnhandledDragController(mIWindowManager, mMainExecutor)
        mController = GlobalDragListener(mIWindowManager, mMainExecutor)
    }

    @Test
    fun setListener_registersUnregistersWithWM() {
        mController.setListener(object : UnhandledDragAndDropCallback {})
        mController.setListener(object : UnhandledDragAndDropCallback {})
        mController.setListener(object : UnhandledDragAndDropCallback {})
        mController.setListener(object : GlobalDragListenerCallback {})
        mController.setListener(object : GlobalDragListenerCallback {})
        mController.setListener(object : GlobalDragListenerCallback {})
        verify(mIWindowManager, Mockito.times(1))
                .setUnhandledDragListener(ArgumentMatchers.any())
                .setGlobalDragListener(ArgumentMatchers.any())

        reset(mIWindowManager)
        mController.setListener(null)
        mController.setListener(null)
        mController.setListener(null)
        verify(mIWindowManager, Mockito.times(1))
                .setUnhandledDragListener(ArgumentMatchers.isNull())
                .setGlobalDragListener(ArgumentMatchers.isNull())
    }

    @Test
@@ -92,7 +92,7 @@ class UnhandledDragControllerTest : ShellTestCase() {
        val lastDragEvent = arrayOfNulls<DragEvent>(1)

        // Set a listener to listen for unhandled drops
        mController.setListener(object : UnhandledDragAndDropCallback {
        mController.setListener(object : GlobalDragListenerCallback {
            override fun onUnhandledDrop(dragEvent: DragEvent,
                onFinishedCallback: Consumer<Boolean>) {
                lastDragEvent[0] = dragEvent
Loading