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
diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl
index c475f6b..51d7caa 100644
--- a/core/java/android/view/IWindowManager.aidl
+++ b/core/java/android/view/IWindowManager.aidl
@@ -69,11 +69,11 @@
 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 @@
     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);
diff --git a/core/java/android/window/IUnhandledDragListener.aidl b/core/java/android/window/IGlobalDragListener.aidl
similarity index 89%
rename from core/java/android/window/IUnhandledDragListener.aidl
rename to core/java/android/window/IGlobalDragListener.aidl
index 52e9895..8138855 100644
--- a/core/java/android/window/IUnhandledDragListener.aidl
+++ b/core/java/android/window/IGlobalDragListener.aidl
@@ -20,10 +20,10 @@
 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
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
index 4fe79c1..34359a5 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
@@ -65,7 +65,7 @@
 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 @@
 
     @WMSingleton
     @Provides
-    static UnhandledDragController provideUnhandledDragController(
+    static GlobalDragListener provideGlobalDragListener(
             IWindowManager wmService,
             @ShellMainThread ShellExecutor mainExecutor) {
-        return new UnhandledDragController(wmService, mainExecutor);
+        return new GlobalDragListener(wmService, mainExecutor);
     }
 
     @WMSingleton
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/UnhandledDragController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/GlobalDragListener.kt
similarity index 81%
rename from libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/UnhandledDragController.kt
rename to libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/GlobalDragListener.kt
index ccf48d0..eb352fc 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/UnhandledDragController.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/GlobalDragListener.kt
@@ -19,8 +19,8 @@
 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 @@
 /**
  * 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 @@
     /**
      * 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 @@
                 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 @@
     }
 
     companion object {
-        private val TAG = UnhandledDragController::class.java.simpleName
+        private val TAG = GlobalDragListener::class.java.simpleName
     }
 }
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/UnhandledDragControllerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/GlobalDragListenerTest.kt
similarity index 84%
rename from libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/UnhandledDragControllerTest.kt
rename to libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/GlobalDragListenerTest.kt
index 522f052..4c02598 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/UnhandledDragControllerTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/GlobalDragListenerTest.kt
@@ -25,7 +25,7 @@
 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 @@
     @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 @@
         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
diff --git a/services/core/java/com/android/server/wm/DragDropController.java b/services/core/java/com/android/server/wm/DragDropController.java
index a3e2869..a83c25f 100644
--- a/services/core/java/com/android/server/wm/DragDropController.java
+++ b/services/core/java/com/android/server/wm/DragDropController.java
@@ -43,8 +43,8 @@
 import android.view.SurfaceControl;
 import android.view.View;
 import android.view.accessibility.AccessibilityManager;
+import android.window.IGlobalDragListener;
 import android.window.IUnhandledDragCallback;
-import android.window.IUnhandledDragListener;
 
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.server.wm.WindowManagerInternal.IDragDropCallback;
@@ -81,9 +81,9 @@
     private WindowManagerService mService;
     private final Handler mHandler;
 
-    // The unhandled drag listener for handling cross-window drags that end with no target window
-    private IUnhandledDragListener mUnhandledDragListener;
-    private final IBinder.DeathRecipient mUnhandledDragListenerDeathRecipient =
+    // The global drag listener for handling cross-window drags
+    private IGlobalDragListener mGlobalDragListener;
+    private final IBinder.DeathRecipient mGlobalDragListenerDeathRecipient =
             new IBinder.DeathRecipient() {
         @Override
         public void binderDied() {
@@ -91,7 +91,7 @@
                 if (hasPendingUnhandledDropCallback()) {
                     onUnhandledDropCallback(false /* consumedByListeners */);
                 }
-                setUnhandledDragListener(null);
+                setGlobalDragListener(null);
             }
         }
     };
@@ -129,29 +129,22 @@
     /**
      * Sets the listener for unhandled cross-window drags.
      */
-    public void setUnhandledDragListener(IUnhandledDragListener listener) {
-        if (mUnhandledDragListener != null && mUnhandledDragListener.asBinder() != null) {
-            mUnhandledDragListener.asBinder().unlinkToDeath(
-                    mUnhandledDragListenerDeathRecipient, 0);
+    public void setGlobalDragListener(IGlobalDragListener listener) {
+        if (mGlobalDragListener != null && mGlobalDragListener.asBinder() != null) {
+            mGlobalDragListener.asBinder().unlinkToDeath(
+                    mGlobalDragListenerDeathRecipient, 0);
         }
-        mUnhandledDragListener = listener;
+        mGlobalDragListener = listener;
         if (listener != null && listener.asBinder() != null) {
             try {
-                mUnhandledDragListener.asBinder().linkToDeath(
-                        mUnhandledDragListenerDeathRecipient, 0);
+                mGlobalDragListener.asBinder().linkToDeath(
+                        mGlobalDragListenerDeathRecipient, 0);
             } catch (RemoteException e) {
-                mUnhandledDragListener = null;
+                mGlobalDragListener = null;
             }
         }
     }
 
-    /**
-     * Returns whether there is an unhandled drag listener set.
-     */
-    boolean hasUnhandledDragListener() {
-        return mUnhandledDragListener != null;
-    }
-
     void sendDragStartedIfNeededLocked(WindowState window) {
         mDragState.sendDragStartedIfNeededLocked(window);
     }
@@ -367,19 +360,19 @@
         final boolean isLocalDrag =
                 (mDragState.mFlags & (DRAG_FLAG_GLOBAL_SAME_APPLICATION | DRAG_FLAG_GLOBAL)) == 0;
         if (!com.android.window.flags.Flags.delegateUnhandledDrags()
-                || mUnhandledDragListener == null
+                || mGlobalDragListener == null
                 || isLocalDrag) {
             // Skip if the flag is disabled, there is no unhandled-drag listener, or if this is a
             // purely local drag
             if (DEBUG_DRAG) Slog.d(TAG_WM, "Skipping unhandled listener "
-                    + "(listener=" + mUnhandledDragListener + ", flags=" + mDragState.mFlags + ")");
+                    + "(listener=" + mGlobalDragListener + ", flags=" + mDragState.mFlags + ")");
             return false;
         }
         if (DEBUG_DRAG) Slog.d(TAG_WM, "Sending DROP to unhandled listener (" + reason + ")");
         try {
             // Schedule timeout for the unhandled drag listener to call back
             sendTimeoutMessage(MSG_UNHANDLED_DROP_LISTENER_TIMEOUT, null, DRAG_TIMEOUT_MS);
-            mUnhandledDragListener.onUnhandledDrop(dropEvent, new IUnhandledDragCallback.Stub() {
+            mGlobalDragListener.onUnhandledDrop(dropEvent, new IUnhandledDragCallback.Stub() {
                 @Override
                 public void notifyUnhandledDropComplete(boolean consumedByListener) {
                     if (DEBUG_DRAG) Slog.d(TAG_WM, "Unhandled listener finished handling DROP");
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 61480d2..f33fab2 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -306,11 +306,11 @@
 import android.view.inputmethod.ImeTracker;
 import android.window.AddToSurfaceSyncGroupResult;
 import android.window.ClientWindowFrames;
+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.SystemPerformanceHinter;
@@ -10019,14 +10019,13 @@
     }
 
     /**
-     * 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.
      */
     @Override
-    public void setUnhandledDragListener(IUnhandledDragListener listener) throws RemoteException {
+    public void setGlobalDragListener(IGlobalDragListener listener) throws RemoteException {
         mAtmService.enforceTaskPermission("setUnhandledDragListener");
         synchronized (mGlobalLock) {
-            mDragDropController.setUnhandledDragListener(listener);
+            mDragDropController.setGlobalDragListener(listener);
         }
     }
 }
diff --git a/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java
index 9e2b1ec..ad40885 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java
@@ -67,7 +67,7 @@
 import android.view.View;
 import android.view.WindowManager;
 import android.view.accessibility.AccessibilityManager;
-import android.window.IUnhandledDragListener;
+import android.window.IGlobalDragListener;
 
 import androidx.test.filters.SmallTest;
 
@@ -544,9 +544,9 @@
     public void testUnhandledDragListenerNotCalledForNormalDrags() throws RemoteException {
         assumeTrue(com.android.window.flags.Flags.delegateUnhandledDrags());
 
-        final IUnhandledDragListener listener = mock(IUnhandledDragListener.class);
+        final IGlobalDragListener listener = mock(IGlobalDragListener.class);
         doReturn(mock(Binder.class)).when(listener).asBinder();
-        mTarget.setUnhandledDragListener(listener);
+        mTarget.setGlobalDragListener(listener);
         doDragAndDrop(0, ClipData.newPlainText("label", "Test"), 0, 0);
         verify(listener, times(0)).onUnhandledDrop(any(), any());
     }
@@ -555,9 +555,9 @@
     public void testUnhandledDragListenerReceivesUnhandledDropOverWindow() {
         assumeTrue(com.android.window.flags.Flags.delegateUnhandledDrags());
 
-        final IUnhandledDragListener listener = mock(IUnhandledDragListener.class);
+        final IGlobalDragListener listener = mock(IGlobalDragListener.class);
         doReturn(mock(Binder.class)).when(listener).asBinder();
-        mTarget.setUnhandledDragListener(listener);
+        mTarget.setGlobalDragListener(listener);
         final int invalidXY = 100_000;
         startDrag(View.DRAG_FLAG_GLOBAL, ClipData.newPlainText("label", "Test"), () -> {
             // Notify the unhandled drag listener
@@ -578,9 +578,9 @@
     public void testUnhandledDragListenerReceivesUnhandledDropOverNoValidWindow() {
         assumeTrue(com.android.window.flags.Flags.delegateUnhandledDrags());
 
-        final IUnhandledDragListener listener = mock(IUnhandledDragListener.class);
+        final IGlobalDragListener listener = mock(IGlobalDragListener.class);
         doReturn(mock(Binder.class)).when(listener).asBinder();
-        mTarget.setUnhandledDragListener(listener);
+        mTarget.setGlobalDragListener(listener);
         final int invalidXY = 100_000;
         startDrag(View.DRAG_FLAG_GLOBAL, ClipData.newPlainText("label", "Test"), () -> {
             // Notify the unhandled drag listener
@@ -600,9 +600,9 @@
     public void testUnhandledDragListenerCallbackTimeout() {
         assumeTrue(com.android.window.flags.Flags.delegateUnhandledDrags());
 
-        final IUnhandledDragListener listener = mock(IUnhandledDragListener.class);
+        final IGlobalDragListener listener = mock(IGlobalDragListener.class);
         doReturn(mock(Binder.class)).when(listener).asBinder();
-        mTarget.setUnhandledDragListener(listener);
+        mTarget.setGlobalDragListener(listener);
         final int invalidXY = 100_000;
         startDrag(View.DRAG_FLAG_GLOBAL, ClipData.newPlainText("label", "Test"), () -> {
             // Notify the unhandled drag listener