@quiesco/native 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Quiesco contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,18 @@
1
- # Temporary Holding Version
1
+ # @quiesco/native
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Expo module for Quiesco: real touches and text input on iOS and Android. Linked only into e2e builds
4
+ (`EXPO_PUBLIC_QUIESCO=1` at `expo prebuild`) by [`@quiesco/expo-plugin`](https://github.com/h2nology/quiesco/tree/main/packages/expo-plugin);
5
+ production builds do not contain it.
6
+
7
+ ```sh
8
+ npm i @quiesco/agent @quiesco/native
9
+ ```
10
+
11
+ You do not call it yourself: `@quiesco/agent` uses it when it is present and falls back to JS
12
+ callbacks (`js` input mode) when it is not.
13
+
14
+ Part of [Quiesco](https://github.com/h2nology/quiesco): gray-box end-to-end testing for Expo apps on iOS, Android and the web. Setup: `npx quiesco init` ([quick start](https://github.com/h2nology/quiesco#quick-start-web-about-10-minutes)).
15
+
16
+ ## License
17
+
18
+ MIT
@@ -0,0 +1,25 @@
1
+ plugins {
2
+ id 'com.android.library'
3
+ id 'expo-module-gradle-plugin'
4
+ }
5
+
6
+ group = 'dev.quiesco.nativemodule'
7
+ version = '0.0.0'
8
+
9
+ android {
10
+ namespace "dev.quiesco.nativemodule"
11
+ defaultConfig {
12
+ versionCode 1
13
+ versionName "0.0.0"
14
+ }
15
+ lintOptions {
16
+ abortOnError false
17
+ }
18
+ }
19
+
20
+ dependencies {
21
+ // UIManagerHelper / ReactContext: resolve React view tags to Android views.
22
+ implementation 'com.facebook.react:react-android'
23
+ // WebView (Phase 6.8): document-start scripts; the same library react-native-webview uses.
24
+ implementation 'androidx.webkit:webkit:1.14.0'
25
+ }
@@ -0,0 +1,498 @@
1
+ package dev.quiesco.nativemodule
2
+
3
+ import android.app.Notification
4
+ import android.app.NotificationChannel
5
+ import android.app.NotificationManager
6
+ import android.app.PendingIntent
7
+ import android.content.ClipData
8
+ import android.content.Intent
9
+ import android.content.ClipboardManager
10
+ import android.content.Context
11
+ import android.os.Build
12
+ import android.os.Handler
13
+ import android.os.Looper
14
+ import android.os.SystemClock
15
+ import android.view.InputDevice
16
+ import android.view.KeyEvent
17
+ import android.view.MotionEvent
18
+ import android.view.View
19
+ import android.view.ViewGroup
20
+ import android.view.accessibility.AccessibilityNodeInfo
21
+ import android.view.inputmethod.EditorInfo
22
+ import android.webkit.WebView
23
+ import android.widget.AbsSeekBar
24
+ import android.widget.EditText
25
+ import androidx.webkit.WebViewCompat
26
+ import androidx.webkit.WebViewFeature
27
+ import com.facebook.react.uimanager.UIManagerHelper
28
+ import expo.modules.kotlin.Promise
29
+ import expo.modules.kotlin.functions.Queues
30
+ import expo.modules.kotlin.modules.Module
31
+ import expo.modules.kotlin.modules.ModuleDefinition
32
+
33
+ /**
34
+ * Real touch / text input inside the app process (requirements.md §6.3, docs/spikes/03-android-touch.md).
35
+ * Public Android APIs only. Targets are addressed by React view tag: the View's real on-screen position
36
+ * is read here (so native-driver animations are taken into account) and events are dispatched to the
37
+ * root view of the window the View lives in (so RN `Modal` dialogs work).
38
+ * Coordinates exchanged with JS are dp in that window's coordinate space.
39
+ */
40
+ class QuiescoNativeModule : Module() {
41
+ private val main = Handler(Looper.getMainLooper())
42
+
43
+ override fun definition() = ModuleDefinition {
44
+ Name("QuiescoNative")
45
+
46
+ // docs/spikes/05: `am start ... --es quiescoPort <p> --es quiescoSession <id>`. The current intent may
47
+ // have lost the extras (dev client relaunch), so fall back to what QuiescoNativePackage captured.
48
+ Function("getLaunchParams") {
49
+ LaunchParamsStore.capture(appContext.currentActivity?.intent)
50
+ mapOf("port" to LaunchParamsStore.port, "session" to LaunchParamsStore.session, "args" to LaunchParamsStore.args)
51
+ }
52
+
53
+ /**
54
+ * `app.device.clipboard` (Phase 6.6): adb has no clipboard command, so the app's process reads and
55
+ * writes it (Android 10+ lets only the focused app read it: the app under test is in front).
56
+ */
57
+ AsyncFunction("getClipboard") {
58
+ val cm = clipboard() ?: return@AsyncFunction ""
59
+ val clip = cm.primaryClip
60
+ if (clip == null || clip.itemCount == 0) "" else clip.getItemAt(0).coerceToText(appContext.reactContext).toString()
61
+ }.runOnQueue(Queues.MAIN)
62
+
63
+ AsyncFunction("setClipboard") { text: String ->
64
+ clipboard()?.setPrimaryClip(ClipData.newPlainText("quiesco", text))
65
+ Unit
66
+ }.runOnQueue(Queues.MAIN)
67
+
68
+ /**
69
+ * `app.device.sendNotification()` on Android (Phase 6.7): an emulator has no push service to deliver
70
+ * through, so the notification is posted as the app itself (HU 2026-11-09). Tapping it opens the app
71
+ * with `data` as intent extras; it does not go through the app's push library (no "received" /
72
+ * "response" callbacks of expo-notifications). Resolves with whether the app may show notifications.
73
+ */
74
+ AsyncFunction("postNotification") { title: String, body: String, data: Map<String, String> ->
75
+ val ctx = appContext.reactContext ?: throw IllegalStateException("the app has no context yet")
76
+ val nm = ctx.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
77
+ if (Build.VERSION.SDK_INT >= 26) {
78
+ nm.createNotificationChannel(NotificationChannel(NOTIFICATION_CHANNEL, "Quiesco e2e", NotificationManager.IMPORTANCE_HIGH))
79
+ }
80
+ val launch = ctx.packageManager.getLaunchIntentForPackage(ctx.packageName)
81
+ ?: throw IllegalStateException("the app has no launcher activity")
82
+ launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
83
+ for ((k, v) in data) launch.putExtra(k, v)
84
+ val id = (SystemClock.elapsedRealtime() % Int.MAX_VALUE).toInt()
85
+ val tap = PendingIntent.getActivity(ctx, id, launch, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
86
+ val builder = if (Build.VERSION.SDK_INT >= 26) Notification.Builder(ctx, NOTIFICATION_CHANNEL) else Notification.Builder(ctx)
87
+ nm.notify(id, builder.setSmallIcon(ctx.applicationInfo.icon).setContentTitle(title).setContentText(body).setContentIntent(tap).setAutoCancel(true).build())
88
+ mapOf("enabled" to nm.areNotificationsEnabled())
89
+ }
90
+
91
+ /** Where a view really is, and whether its window is the one receiving input. */
92
+ /**
93
+ * Show / hide the scrollbars of the view of `tag` (Phase 6.9 full-page screenshots: they stay drawn for
94
+ * a while after each scroll). Returns what they were: 1 shown, 0 hidden, -1 no view.
95
+ */
96
+ AsyncFunction("setScrollIndicators") { tag: Int, visible: Boolean ->
97
+ val view = findView(tag) ?: return@AsyncFunction -1
98
+ val was = if (view.isVerticalScrollBarEnabled) 1 else 0
99
+ view.isVerticalScrollBarEnabled = visible
100
+ view.isHorizontalScrollBarEnabled = visible
101
+ view.invalidate()
102
+ was
103
+ }.runOnQueue(Queues.MAIN)
104
+
105
+ // ---- Phase 6.8 WebView (spike) ----
106
+
107
+ /** The android.webkit.WebView inside the React view `tag` (react-native-webview): rect in dp and load state. */
108
+ AsyncFunction("webviewInfo") { tag: Int ->
109
+ val web = findView(tag)?.let { findWebView(it) } ?: return@AsyncFunction mapOf("found" to false)
110
+ val d = density()
111
+ val loc = IntArray(2)
112
+ web.getLocationInWindow(loc)
113
+ mapOf(
114
+ "found" to true,
115
+ "x" to loc[0] / d, "y" to loc[1] / d, "width" to web.width / d, "height" to web.height / d,
116
+ "loading" to (web.progress < 100), "progress" to web.progress / 100.0,
117
+ "url" to (web.url ?: ""), "title" to (web.title ?: ""),
118
+ "density" to d,
119
+ "documentStartScript" to WebViewFeature.isFeatureSupported(WebViewFeature.DOCUMENT_START_SCRIPT),
120
+ )
121
+ }.runOnQueue(Queues.MAIN)
122
+
123
+ /** Evaluate `script` in the page's main frame; resolves with its value (a string expression's string). */
124
+ AsyncFunction("webviewEval") { tag: Int, script: String, promise: Promise ->
125
+ val web = findView(tag)?.let { findWebView(it) } ?: return@AsyncFunction promise.reject("E_NO_VIEW", "no WebView in view $tag", null)
126
+ web.evaluateJavascript(script) { raw ->
127
+ // The callback gets the value as JSON: a string comes quoted.
128
+ val value = try {
129
+ when (val v = org.json.JSONTokener(raw ?: "null").nextValue()) {
130
+ null, org.json.JSONObject.NULL -> ""
131
+ else -> v.toString()
132
+ }
133
+ } catch (e: Exception) {
134
+ raw ?: ""
135
+ }
136
+ promise.resolve(value)
137
+ }
138
+ }.runOnQueue(Queues.MAIN)
139
+
140
+ /** Run `source` at document start of every later page load (androidx.webkit, where the WebView supports it). */
141
+ AsyncFunction("webviewAddStartScript") { tag: Int, source: String ->
142
+ val web = findView(tag)?.let { findWebView(it) } ?: return@AsyncFunction false
143
+ if (!WebViewFeature.isFeatureSupported(WebViewFeature.DOCUMENT_START_SCRIPT)) return@AsyncFunction false
144
+ WebViewCompat.addDocumentStartJavaScript(web, source, setOf("*"))
145
+ true
146
+ }.runOnQueue(Queues.MAIN)
147
+
148
+ AsyncFunction("locate") { tag: Int ->
149
+ val view = findView(tag) ?: return@AsyncFunction mapOf("found" to false)
150
+ describe(view)
151
+ }.runOnQueue(Queues.MAIN)
152
+
153
+ /** Tap the center of `tag` (or the point `x`,`y` in dp of the activity window when tag < 0). */
154
+ AsyncFunction("tap") { tag: Int, xDp: Double, yDp: Double, holdMs: Int, count: Int, promise: Promise ->
155
+ val target = resolveTarget(tag, xDp, yDp) ?: return@AsyncFunction promise.reject("E_NO_VIEW", "view $tag not found", null)
156
+ val (root, x, y) = target
157
+ var handled = true
158
+ fun one(i: Int) {
159
+ val down = SystemClock.uptimeMillis()
160
+ handled = dispatch(root, down, down, MotionEvent.ACTION_DOWN, x, y) && handled
161
+ main.postDelayed({
162
+ handled = dispatch(root, down, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, x, y) && handled
163
+ if (i + 1 < count) main.postDelayed({ one(i + 1) }, DOUBLE_TAP_GAP_MS) else promise.resolve(result(root, x, y, handled))
164
+ }, holdMs.toLong())
165
+ }
166
+ one(0)
167
+ }.runOnQueue(Queues.MAIN)
168
+
169
+ /** Drag from (fromX, fromY) to (toX, toY) in dp of the window of `tag` over `durationMs`. */
170
+ AsyncFunction("swipe") { tag: Int, fromX: Double, fromY: Double, toX: Double, toY: Double, durationMs: Int, promise: Promise ->
171
+ val root = (if (tag >= 0) findView(tag)?.rootView else null) ?: appContext.currentActivity?.window?.decorView
172
+ ?: return@AsyncFunction promise.reject("E_NO_VIEW", "no window for view $tag", null)
173
+ val d = density()
174
+ val steps = maxOf(4, durationMs / STEP_MS)
175
+ val down = SystemClock.uptimeMillis()
176
+ val x0 = (fromX * d).toFloat(); val y0 = (fromY * d).toFloat()
177
+ val x1 = (toX * d).toFloat(); val y1 = (toY * d).toFloat()
178
+ var handled = dispatch(root, down, down, MotionEvent.ACTION_DOWN, x0, y0)
179
+ fun step(i: Int) {
180
+ val t = i.toFloat() / steps
181
+ val x = x0 + (x1 - x0) * t; val y = y0 + (y1 - y0) * t
182
+ if (i < steps) {
183
+ handled = dispatch(root, down, SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE, x, y) && handled
184
+ main.postDelayed({ step(i + 1) }, (durationMs / steps).toLong())
185
+ } else {
186
+ handled = dispatch(root, down, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, x1, y1) && handled
187
+ promise.resolve(mapOf("handled" to handled))
188
+ }
189
+ }
190
+ main.postDelayed({ step(1) }, (durationMs / steps).toLong())
191
+ }.runOnQueue(Queues.MAIN)
192
+
193
+ /**
194
+ * One finger along a timed path in dp of the window of `tag` (activity window when tag < 0): `path`
195
+ * is flat [x, y, tMs, ...] with t from 0, increasing. Down at the first point, up at the last; moves
196
+ * are interpolated every STEP_MS between points that differ, none while the finger rests (a hold).
197
+ */
198
+ AsyncFunction("gesture") { tag: Int, path: List<Double>, promise: Promise ->
199
+ if (path.size < 6 || path.size % 3 != 0) return@AsyncFunction promise.reject("E_BAD_ARGS", "path needs at least two [x, y, tMs] points", null)
200
+ val root = (if (tag >= 0) findView(tag)?.rootView else null) ?: appContext.currentActivity?.window?.decorView
201
+ ?: return@AsyncFunction promise.reject("E_NO_VIEW", "no window for view $tag", null)
202
+ val d = density()
203
+ val pts = (path.indices step 3).map { Triple((path[it] * d).toFloat(), (path[it + 1] * d).toFloat(), path[it + 2]) }
204
+ val events = ArrayList<Triple<Float, Float, Double>>()
205
+ for (i in 1 until pts.size) {
206
+ val (ax, ay, ta) = pts[i - 1]
207
+ val (bx, by, tb) = pts[i]
208
+ val steps = if (ax == bx && ay == by) 1 else maxOf(1, ((tb - ta) / STEP_MS).toInt())
209
+ for (k in 1..steps) {
210
+ val t = k.toFloat() / steps
211
+ events.add(Triple(ax + (bx - ax) * t, ay + (by - ay) * t, ta + (tb - ta) * t))
212
+ }
213
+ }
214
+ val down = SystemClock.uptimeMillis()
215
+ var handled = dispatch(root, down, down, MotionEvent.ACTION_DOWN, pts[0].first, pts[0].second)
216
+ fun fire(i: Int) {
217
+ val (x, y, _) = events[i]
218
+ val last = i == events.size - 1
219
+ handled = dispatch(root, down, SystemClock.uptimeMillis(), if (last) MotionEvent.ACTION_UP else MotionEvent.ACTION_MOVE, x, y) && handled
220
+ if (last) promise.resolve(mapOf("handled" to handled))
221
+ else main.postAtTime({ fire(i + 1) }, down + events[i + 1].third.toLong())
222
+ }
223
+ main.postAtTime({ fire(0) }, down + events[0].third.toLong())
224
+ }.runOnQueue(Queues.MAIN)
225
+
226
+ /**
227
+ * Several fingers along timed paths in dp of the window of `tag` (activity window when tag < 0).
228
+ * `frames` is flat: per frame [tMs, down0, x0, y0, down1, x1, y1, ...] for `fingerCount` fingers
229
+ * (down = 1 while the finger touches), t from 0 and increasing. Per frame, as a touchscreen reports
230
+ * it: new fingers go down (ACTION_DOWN, then ACTION_POINTER_DOWN), moved fingers move (one
231
+ * ACTION_MOVE with every pointer), lifted fingers go up (ACTION_POINTER_UP, the last ACTION_UP).
232
+ * Every finger is lifted after the last frame.
233
+ */
234
+ AsyncFunction("multiGesture") { tag: Int, fingerCount: Int, frames: List<Double>, promise: Promise ->
235
+ val stride = 1 + 3 * fingerCount
236
+ if (fingerCount < 1 || frames.size < stride || frames.size % stride != 0) {
237
+ return@AsyncFunction promise.reject("E_BAD_ARGS", "frames must be [t, down, x, y, ...] for $fingerCount fingers", null)
238
+ }
239
+ val root = (if (tag >= 0) findView(tag)?.rootView else null) ?: appContext.currentActivity?.window?.decorView
240
+ ?: return@AsyncFunction promise.reject("E_NO_VIEW", "no window for view $tag", null)
241
+ val d = density()
242
+ val count = frames.size / stride
243
+ val down = SystemClock.uptimeMillis()
244
+ val touch = MultiTouch(root, down)
245
+ fun fire(f: Int) {
246
+ val base = f * stride
247
+ val points = (0 until fingerCount).map { i ->
248
+ val o = base + 1 + 3 * i
249
+ if (frames[o] > 0.5) Pair((frames[o + 1] * d).toFloat(), (frames[o + 2] * d).toFloat()) else null
250
+ }
251
+ touch.frame(points)
252
+ if (f + 1 < count) {
253
+ main.postAtTime({ fire(f + 1) }, down + frames[(f + 1) * stride].toLong())
254
+ } else {
255
+ touch.frame(points.map { null })
256
+ promise.resolve(mapOf("handled" to touch.handled))
257
+ }
258
+ }
259
+ main.postAtTime({ fire(0) }, down + frames[0].toLong())
260
+ }.runOnQueue(Queues.MAIN)
261
+
262
+ /**
263
+ * A key of the soft keyboard on the text field `tag`, through its InputConnection: `enter` performs
264
+ * the field's IME action (where React Native submits), or commits a newline when the field asks for
265
+ * no enter action (multi-line); `backspace` sends KEYCODE_DEL (RN reports it to onKeyPress).
266
+ */
267
+ AsyncFunction("pressKey") { tag: Int, key: String, promise: Promise ->
268
+ val view = findView(tag) ?: return@AsyncFunction promise.reject("E_NO_VIEW", "view $tag not found", null)
269
+ val edit = findEditText(view) ?: return@AsyncFunction promise.reject("E_NOT_TEXT_INPUT", "view $tag is not a text field", null)
270
+ edit.requestFocus()
271
+ val info = EditorInfo()
272
+ val ic = edit.onCreateInputConnection(info) ?: return@AsyncFunction promise.reject("E_NOT_TEXT_INPUT", "view $tag has no input connection", null)
273
+ when (key) {
274
+ "enter" -> {
275
+ val action = info.imeOptions and EditorInfo.IME_MASK_ACTION
276
+ if ((info.imeOptions and EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0 || action == EditorInfo.IME_ACTION_NONE) ic.commitText("\n", 1)
277
+ else ic.performEditorAction(if (action == EditorInfo.IME_ACTION_UNSPECIFIED) EditorInfo.IME_ACTION_DONE else action)
278
+ }
279
+ "backspace" -> {
280
+ ic.sendKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL))
281
+ ic.sendKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL))
282
+ }
283
+ else -> return@AsyncFunction promise.reject("E_BAD_ARGS", "unknown key $key", null)
284
+ }
285
+ promise.resolve(mapOf("text" to (edit.text?.toString() ?: ""), "focused" to edit.isFocused))
286
+ }.runOnQueue(Queues.MAIN)
287
+
288
+ /**
289
+ * Type into the text field `tag` (or the EditText inside it) through its InputConnection, the path a
290
+ * soft keyboard uses, so TextWatchers / onChangeText fire. `replace` clears the field first.
291
+ */
292
+ AsyncFunction("typeText") { tag: Int, text: String, replace: Boolean, promise: Promise ->
293
+ val view = findView(tag) ?: return@AsyncFunction promise.reject("E_NO_VIEW", "view $tag not found", null)
294
+ val edit = findEditText(view) ?: return@AsyncFunction promise.reject("E_NOT_TEXT_INPUT", "view $tag is not a text field", null)
295
+ edit.requestFocus()
296
+ val ic = edit.onCreateInputConnection(EditorInfo())
297
+ if (ic != null) {
298
+ ic.beginBatchEdit()
299
+ if (replace) {
300
+ ic.setSelection(0, edit.text?.length ?: 0)
301
+ ic.commitText("", 1)
302
+ }
303
+ ic.commitText(text, 1)
304
+ ic.endBatchEdit()
305
+ } else {
306
+ if (replace) edit.setText(text) else edit.text?.append(text)
307
+ }
308
+ promise.resolve(mapOf("text" to (edit.text?.toString() ?: ""), "inputConnection" to (ic != null), "focused" to edit.isFocused))
309
+ }.runOnQueue(Queues.MAIN)
310
+
311
+ /**
312
+ * Geometry of the SeekBar in `tag`'s view, in dp of its window: x of the thumb center at the minimum
313
+ * and at the maximum (the track spans the view minus its horizontal padding), the current thumb x and y.
314
+ */
315
+ AsyncFunction("sliderInfo") { tag: Int ->
316
+ val view = findView(tag) ?: return@AsyncFunction mapOf("found" to false)
317
+ val bar = findSeekBar(view) ?: return@AsyncFunction mapOf("found" to false)
318
+ val d = density()
319
+ val loc = IntArray(2)
320
+ bar.getLocationInWindow(loc)
321
+ val lo = loc[0] + bar.paddingLeft
322
+ val hi = loc[0] + bar.width - bar.paddingRight
323
+ val min = if (Build.VERSION.SDK_INT >= 26) bar.min else 0
324
+ val ratio = if (bar.max > min) (bar.progress - min).toFloat() / (bar.max - min) else 0f
325
+ mapOf(
326
+ "found" to true, "minX" to lo / d, "maxX" to hi / d, "y" to (loc[1] + bar.height / 2f) / d,
327
+ "thumbX" to (lo + (hi - lo) * ratio) / d, "value" to bar.progress, "minimum" to min, "maximum" to bar.max,
328
+ )
329
+ }.runOnQueue(Queues.MAIN)
330
+
331
+ /**
332
+ * Perform the accessibility action `name` on `tag`'s view the way TalkBack does
333
+ * (View.performAccessibilityAction). React Native's ReactAccessibilityDelegate maps the standard
334
+ * names to framework actions and gives every other declared action a generated id (from 0x3f000000)
335
+ * in declaration order: `customIndex` is the action's index among those.
336
+ */
337
+ AsyncFunction("accessibilityAction") { tag: Int, name: String, _label: String, _index: Int, customIndex: Int, promise: Promise ->
338
+ val view = findView(tag) ?: return@AsyncFunction promise.reject("E_NO_VIEW", "view $tag not found", null)
339
+ // Like TalkBack, read the node info first: ReactAccessibilityDelegate fills its id → name map there,
340
+ // and only performs actions it has listed.
341
+ val info = view.createAccessibilityNodeInfo()
342
+ val id = STANDARD_ACTIONS[name] ?: info.actionList.filter { it.id >= CUSTOM_ACTION_BASE }.getOrNull(customIndex)?.id
343
+ ?: return@AsyncFunction promise.reject("E_NO_ACTION", "view $tag has no accessibility action \"$name\"", null)
344
+ if (info.actionList.none { it.id == id }) {
345
+ return@AsyncFunction promise.reject("E_NO_ACTION", "view $tag does not offer the accessibility action \"$name\" (offers ${info.actionList.map { it.id }})", null)
346
+ }
347
+ val performed = view.performAccessibilityAction(id, null)
348
+ promise.resolve(mapOf("performed" to performed, "via" to "performAccessibilityAction", "actionId" to id))
349
+ }.runOnQueue(Queues.MAIN)
350
+ }
351
+
352
+ /** Multi-pointer MotionEvents for one gesture, in px of `root`'s window. Pointer id = finger index. */
353
+ private class MultiTouch(private val root: View, private val downTime: Long) {
354
+ /** Fingers currently down, in pointer-index order (ascending id), with their positions. */
355
+ private val active = sortedMapOf<Int, Pair<Float, Float>>()
356
+ var handled = true
357
+
358
+ fun frame(points: List<Pair<Float, Float>?>) {
359
+ // 1. New fingers go down, each with the others at their previous positions.
360
+ for ((i, p) in points.withIndex()) {
361
+ if (p == null || active.containsKey(i)) continue
362
+ active[i] = p
363
+ val index = active.keys.indexOf(i)
364
+ val action = if (active.size == 1) MotionEvent.ACTION_DOWN else MotionEvent.ACTION_POINTER_DOWN or (index shl MotionEvent.ACTION_POINTER_INDEX_SHIFT)
365
+ send(action)
366
+ }
367
+ // 2. Fingers that stay down and moved: one move with every pointer.
368
+ var moved = false
369
+ for ((i, p) in points.withIndex()) {
370
+ val cur = active[i] ?: continue
371
+ if (p != null && p != cur) {
372
+ active[i] = p
373
+ moved = true
374
+ }
375
+ }
376
+ if (moved) send(MotionEvent.ACTION_MOVE)
377
+ // 3. Lifted fingers go up; the last one ends the gesture.
378
+ for ((i, p) in points.withIndex()) {
379
+ if (p != null || !active.containsKey(i)) continue
380
+ val index = active.keys.indexOf(i)
381
+ val action = if (active.size == 1) MotionEvent.ACTION_UP else MotionEvent.ACTION_POINTER_UP or (index shl MotionEvent.ACTION_POINTER_INDEX_SHIFT)
382
+ send(action)
383
+ active.remove(i)
384
+ }
385
+ }
386
+
387
+ private fun send(action: Int) {
388
+ val ids = active.keys.toList()
389
+ val props = Array(ids.size) { k -> MotionEvent.PointerProperties().apply { id = ids[k]; toolType = MotionEvent.TOOL_TYPE_FINGER } }
390
+ val coords = Array(ids.size) { k ->
391
+ val (x, y) = active.getValue(ids[k])
392
+ MotionEvent.PointerCoords().apply { this.x = x; this.y = y; pressure = 1f; size = 1f }
393
+ }
394
+ val ev = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), action, ids.size, props, coords, 0, 0, 1f, 1f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0)
395
+ try {
396
+ handled = root.dispatchTouchEvent(ev) && handled
397
+ } finally {
398
+ ev.recycle()
399
+ }
400
+ }
401
+ }
402
+
403
+ private fun findSeekBar(view: View): AbsSeekBar? {
404
+ if (view is AbsSeekBar) return view
405
+ if (view is ViewGroup) for (i in 0 until view.childCount) findSeekBar(view.getChildAt(i))?.let { return it }
406
+ return null
407
+ }
408
+
409
+ private fun clipboard(): ClipboardManager? =
410
+ appContext.reactContext?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
411
+
412
+ private fun density(): Float = appContext.reactContext?.resources?.displayMetrics?.density ?: 1f
413
+
414
+ private fun findView(tag: Int): View? {
415
+ val ctx = appContext.reactContext ?: return null
416
+ return try {
417
+ UIManagerHelper.getUIManagerForReactTag(ctx as com.facebook.react.bridge.ReactContext, tag)?.resolveView(tag)
418
+ } catch (e: Exception) {
419
+ null
420
+ }
421
+ }
422
+
423
+ private fun findWebView(view: View): WebView? {
424
+ if (view is WebView) return view
425
+ if (view is ViewGroup) for (i in 0 until view.childCount) findWebView(view.getChildAt(i))?.let { return it }
426
+ return null
427
+ }
428
+
429
+ private fun findEditText(view: View): EditText? {
430
+ if (view is EditText) return view
431
+ if (view is ViewGroup) for (i in 0 until view.childCount) findEditText(view.getChildAt(i))?.let { return it }
432
+ return null
433
+ }
434
+
435
+ /** Root view of the window and the target point in that window's px coordinates. */
436
+ private fun resolveTarget(tag: Int, xDp: Double, yDp: Double): Triple<View, Float, Float>? {
437
+ if (tag < 0) {
438
+ val root = appContext.currentActivity?.window?.decorView ?: return null
439
+ val d = density()
440
+ return Triple(root, (xDp * d).toFloat(), (yDp * d).toFloat())
441
+ }
442
+ val view = findView(tag) ?: return null
443
+ val loc = IntArray(2)
444
+ view.getLocationInWindow(loc)
445
+ return Triple(view.rootView, loc[0] + view.width / 2f, loc[1] + view.height / 2f)
446
+ }
447
+
448
+ private fun describe(view: View): Map<String, Any?> {
449
+ val d = density()
450
+ val loc = IntArray(2)
451
+ view.getLocationInWindow(loc)
452
+ val root = view.rootView
453
+ val windows = if (Build.VERSION.SDK_INT >= 29) android.view.inspector.WindowInspector.getGlobalWindowViews() else emptyList()
454
+ val visibleWindows = windows.filter { it.isAttachedToWindow && it.visibility == View.VISIBLE }
455
+ return mapOf(
456
+ "found" to true,
457
+ "x" to loc[0] / d, "y" to loc[1] / d, "width" to view.width / d, "height" to view.height / d,
458
+ "shown" to view.isShown,
459
+ "windowHasFocus" to root.hasWindowFocus(),
460
+ "windowIndex" to visibleWindows.indexOf(root),
461
+ "windowCount" to visibleWindows.size,
462
+ "windowClass" to root.javaClass.simpleName,
463
+ )
464
+ }
465
+
466
+ private fun result(root: View, x: Float, y: Float, handled: Boolean): Map<String, Any?> {
467
+ val d = density()
468
+ return mapOf("x" to x / d, "y" to y / d, "handled" to handled, "windowHasFocus" to root.hasWindowFocus())
469
+ }
470
+
471
+ private fun dispatch(root: View, downTime: Long, eventTime: Long, action: Int, x: Float, y: Float): Boolean {
472
+ val props = arrayOf(MotionEvent.PointerProperties().apply { id = 0; toolType = MotionEvent.TOOL_TYPE_FINGER })
473
+ val coords = arrayOf(MotionEvent.PointerCoords().apply { this.x = x; this.y = y; pressure = 1f; size = 1f })
474
+ val ev = MotionEvent.obtain(downTime, eventTime, action, 1, props, coords, 0, 0, 1f, 1f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0)
475
+ try {
476
+ return root.dispatchTouchEvent(ev)
477
+ } finally {
478
+ ev.recycle()
479
+ }
480
+ }
481
+
482
+ companion object {
483
+ /** ReactAccessibilityDelegate: standard action names → framework action ids. */
484
+ val STANDARD_ACTIONS = mapOf(
485
+ "activate" to AccessibilityNodeInfo.ACTION_CLICK,
486
+ "longpress" to AccessibilityNodeInfo.ACTION_LONG_CLICK,
487
+ "increment" to AccessibilityNodeInfo.ACTION_SCROLL_FORWARD,
488
+ "decrement" to AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD,
489
+ "expand" to AccessibilityNodeInfo.ACTION_EXPAND,
490
+ "collapse" to AccessibilityNodeInfo.ACTION_COLLAPSE,
491
+ )
492
+ const val CUSTOM_ACTION_BASE = 0x3f000000
493
+ const val DOUBLE_TAP_GAP_MS = 80L
494
+ const val STEP_MS = 16
495
+ }
496
+ }
497
+
498
+ private const val NOTIFICATION_CHANNEL = "quiesco-e2e"
@@ -0,0 +1,46 @@
1
+ package dev.quiesco.nativemodule
2
+
3
+ import android.app.Activity
4
+ import android.content.Context
5
+ import android.content.Intent
6
+ import android.os.Bundle
7
+ import expo.modules.core.interfaces.Package
8
+ import expo.modules.core.interfaces.ReactActivityLifecycleListener
9
+
10
+ /**
11
+ * Keeps the connection parameters (`--es quiescoPort` / `--es quiescoSession`) for the life of the
12
+ * process. An Expo dev client that has run before relaunches its activity with CLEAR_TASK and an
13
+ * intent of its own, so by the time JS asks, `currentActivity.intent` no longer carries our extras;
14
+ * the agent would then fall back to the build-time port (7357) — wrong for parallel worker N > 0.
15
+ */
16
+ object LaunchParamsStore {
17
+ @Volatile var port: String? = null
18
+ private set
19
+ @Volatile var session: String? = null
20
+ private set
21
+ /** Base64 of the test's launch arguments as JSON (`--es quiescoArgs`, Phase 6.5). */
22
+ @Volatile var args: String? = null
23
+ private set
24
+
25
+ /** Remember the parameters of `intent` when it has them (a newer launch replaces older ones). */
26
+ fun capture(intent: Intent?) {
27
+ val p = intent?.getStringExtra("quiescoPort") ?: return
28
+ port = p
29
+ session = intent.getStringExtra("quiescoSession")
30
+ args = intent.getStringExtra("quiescoArgs")
31
+ }
32
+ }
33
+
34
+ class QuiescoNativePackage : Package {
35
+ override fun createReactActivityLifecycleListeners(activityContext: Context?): List<ReactActivityLifecycleListener> =
36
+ listOf(object : ReactActivityLifecycleListener {
37
+ override fun onCreate(activity: Activity?, savedInstanceState: Bundle?) {
38
+ LaunchParamsStore.capture(activity?.intent)
39
+ }
40
+
41
+ override fun onNewIntent(intent: Intent?): Boolean {
42
+ LaunchParamsStore.capture(intent)
43
+ return false // observe only; other listeners still handle the intent
44
+ }
45
+ })
46
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "platforms": ["apple", "android"],
3
+ "apple": {
4
+ "modules": ["QuiescoNativeModule"]
5
+ },
6
+ "android": {
7
+ "modules": ["dev.quiesco.nativemodule.QuiescoNativeModule"]
8
+ }
9
+ }
@@ -0,0 +1,43 @@
1
+ #import <UIKit/UIKit.h>
2
+
3
+ NS_ASSUME_NONNULL_BEGIN
4
+
5
+ /**
6
+ * Synthesized UITouch / UIEvent injection inside the app process (docs/spikes/04-ios-touch.md).
7
+ * Uses private UIKit / IOKit API: e2e builds only. All methods must be called on the main thread.
8
+ * Points are in the coordinate space of `window`.
9
+ */
10
+ @interface QSTouchInjector : NSObject
11
+
12
+ /** nil when every private selector this class relies on is available, else the first missing one. */
13
+ + (nullable NSString *)missingPrivateAPI;
14
+
15
+ /** Foreground key window of the active scene. */
16
+ + (nullable UIWindow *)keyWindow;
17
+
18
+ /** All visible windows of the foreground scenes, front-most last. */
19
+ + (NSArray<UIWindow *> *)windows;
20
+
21
+ /** The mounted React component view with this tag (Fabric sets `UIView.tag` to the React tag). */
22
+ + (nullable UIView *)viewWithReactTag:(NSInteger)tag;
23
+
24
+ /** Begin a touch. Returns the hit-tested view, or nil when there is no window. */
25
+ + (nullable UIView *)touchDownAt:(CGPoint)point inWindow:(UIWindow *)window tapCount:(NSUInteger)tapCount;
26
+ /** Move the current touch. */
27
+ + (BOOL)touchMoveTo:(CGPoint)point;
28
+ /** End the current touch. */
29
+ + (BOOL)touchUp;
30
+
31
+ /**
32
+ * Several fingers at once. `points[i]` is an NSValue (CGPoint in `window`) while finger i touches, or
33
+ * NSNull while it does not; a finger that appears goes down, one that disappears lifts, one that moves
34
+ * moves (the others are stationary). One UIEvent carries every touching finger. Returns NO when
35
+ * nothing was sent (no change).
36
+ */
37
+ + (BOOL)sendFingers:(NSArray *)points inWindow:(UIWindow *)window;
38
+ /** Lift every finger still down (end of a multi-finger gesture). */
39
+ + (void)liftAllFingers;
40
+
41
+ @end
42
+
43
+ NS_ASSUME_NONNULL_END