summaryrefslogtreecommitdiff
path: root/tests/FlickerTests
diff options
context:
space:
mode:
author Jorge Gil <jorgegil@google.com> 2024-09-20 01:23:45 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-09-20 01:23:45 +0000
commit548994e13b8cc74ba40a0ae7396f0b88e3331336 (patch)
treeb5c8fa9ecd5aa2703105c043edafe1610cd9d179 /tests/FlickerTests
parent1d3f84d5485b6c26e829540416119bbcee3b69b8 (diff)
parent66112fa6c9d41d54c98cb61dc93fe20127e4c088 (diff)
Merge "Require hold-to-drag for App Handle drags" into main
Diffstat (limited to 'tests/FlickerTests')
-rw-r--r--tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt36
-rw-r--r--tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/MotionEventHelper.kt29
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
}