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

Commit 70142302 authored by mpodolian's avatar mpodolian
Browse files

Made launcher show secondary drop target for shell drag.

Required update to the shell process to fix issue b/422752999

Test: DropTargetManagerTest
Fixes: 422752999
Flag: com.android.wm.shell.enable_create_any_bubble
Change-Id: If2d9139afad7ff0d04c001fc46554a5eff587731
parent 463796b7
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ class DropTargetManager(
    private fun setupDropTarget(view: View?) {
        if (view == null) return
        if (view.parent != null) container.removeView(view)
        view.tag = getDropViewTag()
        container.addView(view, 0)
        view.alpha = 0f

@@ -206,7 +207,10 @@ class DropTargetManager(

    private fun onDropTargetRemoved() {
        val action = onDropTargetsRemovedAction ?: return
        if ((0 until container.childCount).any { container.getChildAt(it) is DropTargetView }) {
        if ((0 until container.childCount).any {
                val childView = container.getChildAt(it)
                childView is DropTargetView && childView.tag == getDropViewTag()
            }) {
            return
        }
        onDropTargetsRemovedAction = null
@@ -233,6 +237,8 @@ class DropTargetManager(
        }
    }

    private fun getDropViewTag(): Int = this.hashCode()

    private val DraggedObject.initialLocation: BubbleBarLocation?
        get() =
            when (this) {
+65 −0
Original line number Diff line number Diff line
@@ -590,6 +590,71 @@ class DropTargetManagerTest {
        )
    }

    @Test
    fun onDropTargetsRemoved_multipleManagers_actionExecutedOnlyWhenItsViewsAreRemoved() {
        var firstRunnableExecuted = false
        val firstAction = Runnable { firstRunnableExecuted = true }

        var secondRunnableExecuted = false
        val secondAction = Runnable { secondRunnableExecuted = true }

        // Create a second DropTargetManager sharing the same container
        val secondDropTargetManager =
            DropTargetManager(context, container, FakeDragZoneChangedListener())

        val randomViewsCount = 10

        // Add some random views to the shared container
        repeat(randomViewsCount) {
            container.addView(View(context))
        }

        // First manager starts a drag, adds its views
        dropTargetManager.onDragStarted(
            DraggedObject.LauncherIcon(bubbleBarHasBubbles = false) {},
            listOf(bubbleLeftDragZoneWithSecondDropTarget)
        )
        assertThat(container.childCount)
            .isEqualTo(randomViewsCount + DROP_VIEWS_COUNT_FOR_TWO_DROP_TARGETS)
        dropTargetManager.onDropTargetRemoved(firstAction)
        assertThat(firstRunnableExecuted).isFalse() // Manager 1 views are still there

        // Second manager starts a drag, adds its views
        secondDropTargetManager.onDragStarted(
            DraggedObject.LauncherIcon(bubbleBarHasBubbles = false) {},
            listOf(bubbleRightDragZoneWithSecondDropTarget)
        )
        // Now container has views from both managers
        assertThat(container.childCount)
            .isEqualTo(randomViewsCount + DROP_VIEWS_COUNT_FOR_TWO_DROP_TARGETS * 2)
        secondDropTargetManager.onDropTargetRemoved(secondAction)
        assertThat(secondRunnableExecuted).isFalse() // Second manager views are still there

        // First manager ends its drag
        InstrumentationRegistry.getInstrumentation().runOnMainSync {
            dropTargetManager.onDragEnded()
            animatorTestRule.advanceTimeBy(250) // Ensure fade out completes
        }

        // First manager's views should be removed, its runnable executed.
        // Second manager's views are still present.
        assertThat(firstRunnableExecuted).isTrue()
        assertThat(secondRunnableExecuted).isFalse()
        // Count should be only manager 2's views
        assertThat(container.childCount)
            .isEqualTo(randomViewsCount + DROP_VIEWS_COUNT_FOR_TWO_DROP_TARGETS)

        // Second manager ends its drag
        InstrumentationRegistry.getInstrumentation().runOnMainSync {
            secondDropTargetManager.onDragEnded()
            animatorTestRule.advanceTimeBy(250) // Ensure fade out completes
        }

        // Second manager's views should be removed, its runnable executed.
        assertThat(secondRunnableExecuted).isTrue()
        assertThat(container.childCount).isEqualTo(randomViewsCount) // All managers views removed
    }

    private fun verifyDropTargetPosition(rect: Rect) {
        verifyDropTargetPosition(dropTargetView, rect)
    }