diff options
author | 2024-09-15 05:56:37 +0000 | |
---|---|---|
committer | 2024-09-18 22:35:00 +0000 | |
commit | 66112fa6c9d41d54c98cb61dc93fe20127e4c088 (patch) | |
tree | 6de781272dde72b23ed713351df9c5ddf51f7542 /tests/FlickerTests | |
parent | 6f62c8c15a197e84f855cfff7710879e048d29b1 (diff) |
Require hold-to-drag for App Handle drags
Adds a holding period functionality to DragDetector, which requires a
hold within the slop region to be maintained for X amount of ms before
ACTION_MOVEs outside the slop are allowed (reported to the event
handler). This functionality is enabled for the App Handle's drag
detector behind a flag, and disable for every other drag detector
(header, resize listener).
Also modifies e2e test to check the type of input before entering
desktop with drag, and simulates a hold-to-drag when the input is from a
touchscreen.
Flag: com.android.window.flags.enable_hold_to_drag_app_handle
Bug: 356409496
Test: atest WMShellUnitTests; atest PlatformScenarioTests
Change-Id: Ib57be0ce8b63aaa17ecc57b70d1629ab88c69787
Diffstat (limited to 'tests/FlickerTests')
2 files changed, 48 insertions, 17 deletions
diff --git a/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt b/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt index 3f6a0bf49eb4..c77413b6a55a 100644 --- a/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt +++ b/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt @@ -20,6 +20,7 @@ import android.content.Context import android.graphics.Insets import android.graphics.Rect import android.graphics.Region +import android.os.SystemClock import android.platform.uiautomator_helpers.DeviceHelpers import android.tools.device.apphelpers.IStandardAppHelper import android.tools.helpers.SYSTEMUI_PACKAGE @@ -27,11 +28,14 @@ import android.tools.traces.parsers.WindowManagerStateHelper import android.tools.traces.wm.WindowingMode import android.view.WindowInsets import android.view.WindowManager +import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation import androidx.test.uiautomator.By import androidx.test.uiautomator.BySelector import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.UiObject2 import androidx.test.uiautomator.Until +import com.android.server.wm.flicker.helpers.MotionEventHelper.InputMethod.TOUCH +import com.android.window.flags.Flags import java.time.Duration /** @@ -69,13 +73,22 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) : fun enterDesktopWithDrag( wmHelper: WindowManagerStateHelper, device: UiDevice, + motionEventHelper: MotionEventHelper = MotionEventHelper(getInstrumentation(), TOUCH) ) { innerHelper.launchViaIntent(wmHelper) - dragToDesktop(wmHelper, device) + dragToDesktop( + wmHelper = wmHelper, + device = device, + motionEventHelper = motionEventHelper + ) waitForAppToMoveToDesktop(wmHelper) } - private fun dragToDesktop(wmHelper: WindowManagerStateHelper, device: UiDevice) { + private fun dragToDesktop( + wmHelper: WindowManagerStateHelper, + device: UiDevice, + motionEventHelper: MotionEventHelper + ) { val windowRect = wmHelper.getWindowRegion(innerHelper).bounds val startX = windowRect.centerX() @@ -88,7 +101,17 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) : val endY = displayRect.centerY() / 2 // drag the window to move to desktop - device.drag(startX, startY, startX, endY, 100) + if (motionEventHelper.inputMethod == TOUCH + && Flags.enableHoldToDragAppHandle()) { + // Touch requires hold-to-drag. + val downTime = SystemClock.uptimeMillis() + motionEventHelper.actionDown(startX, startY, time = downTime) + SystemClock.sleep(100L) // hold for 100ns before starting the move. + motionEventHelper.actionMove(startX, startY, startX, endY, 100, downTime = downTime) + motionEventHelper.actionUp(startX, endY, downTime = downTime) + } else { + device.drag(startX, startY, startX, endY, 100) + } } private fun getMaximizeButtonForTheApp(caption: UiObject2?): UiObject2 { @@ -220,9 +243,10 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) : val endY = startY + verticalChange val endX = startX + horizontalChange - motionEvent.actionDown(startX, startY) - motionEvent.actionMove(startX, startY, endX, endY, /* steps= */100) - motionEvent.actionUp(endX, endY) + val downTime = SystemClock.uptimeMillis() + motionEvent.actionDown(startX, startY, time = downTime) + motionEvent.actionMove(startX, startY, endX, endY, /* steps= */100, downTime = downTime) + motionEvent.actionUp(endX, endY, downTime = downTime) wmHelper .StateSyncBuilder() .withAppTransitionIdle() diff --git a/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/MotionEventHelper.kt b/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/MotionEventHelper.kt index 083539890906..86a0b0f8c66e 100644 --- a/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/MotionEventHelper.kt +++ b/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/MotionEventHelper.kt @@ -21,6 +21,7 @@ import android.os.SystemClock import android.view.ContentInfo.Source import android.view.InputDevice.SOURCE_MOUSE import android.view.InputDevice.SOURCE_STYLUS +import android.view.InputDevice.SOURCE_TOUCHSCREEN import android.view.MotionEvent import android.view.MotionEvent.ACTION_DOWN import android.view.MotionEvent.ACTION_MOVE @@ -36,23 +37,24 @@ import android.view.MotionEvent.ToolType */ class MotionEventHelper( private val instr: Instrumentation, - private val inputMethod: InputMethod + val inputMethod: InputMethod ) { enum class InputMethod(@ToolType val toolType: Int, @Source val source: Int) { STYLUS(TOOL_TYPE_STYLUS, SOURCE_STYLUS), MOUSE(TOOL_TYPE_MOUSE, SOURCE_MOUSE), - TOUCHPAD(TOOL_TYPE_FINGER, SOURCE_MOUSE) + TOUCHPAD(TOOL_TYPE_FINGER, SOURCE_MOUSE), + TOUCH(TOOL_TYPE_FINGER, SOURCE_TOUCHSCREEN) } - fun actionDown(x: Int, y: Int) { - injectMotionEvent(ACTION_DOWN, x, y) + fun actionDown(x: Int, y: Int, time: Long = SystemClock.uptimeMillis()) { + injectMotionEvent(ACTION_DOWN, x, y, downTime = time, eventTime = time) } - fun actionUp(x: Int, y: Int) { - injectMotionEvent(ACTION_UP, x, y) + fun actionUp(x: Int, y: Int, downTime: Long) { + injectMotionEvent(ACTION_UP, x, y, downTime = downTime) } - fun actionMove(startX: Int, startY: Int, endX: Int, endY: Int, steps: Int) { + fun actionMove(startX: Int, startY: Int, endX: Int, endY: Int, steps: Int, downTime: Long) { val incrementX = (endX - startX).toFloat() / (steps - 1) val incrementY = (endY - startY).toFloat() / (steps - 1) @@ -61,14 +63,19 @@ class MotionEventHelper( val x = startX + incrementX * i val y = startY + incrementY * i - val moveEvent = getMotionEvent(time, time, ACTION_MOVE, x, y) + val moveEvent = getMotionEvent(downTime, time, ACTION_MOVE, x, y) injectMotionEvent(moveEvent) } } - private fun injectMotionEvent(action: Int, x: Int, y: Int): MotionEvent { - val eventTime = SystemClock.uptimeMillis() - val event = getMotionEvent(eventTime, eventTime, action, x.toFloat(), y.toFloat()) + private fun injectMotionEvent( + action: Int, + x: Int, + y: Int, + downTime: Long = SystemClock.uptimeMillis(), + eventTime: Long = SystemClock.uptimeMillis() + ): MotionEvent { + val event = getMotionEvent(downTime, eventTime, action, x.toFloat(), y.toFloat()) injectMotionEvent(event) return event } |