@oodle-ai/mobile-sdk-reactnative 0.0.0-stage → 0.1.0
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 +201 -0
- package/OodleMobileSdkReactNative.podspec +24 -0
- package/README.md +191 -2
- package/android/build.gradle +55 -0
- package/android/proguard-rules.pro +5 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/ai/oodle/rum/Connectivity.kt +19 -0
- package/android/src/main/java/ai/oodle/rum/CrashReporter.kt +88 -0
- package/android/src/main/java/ai/oodle/rum/DeviceInfo.kt +50 -0
- package/android/src/main/java/ai/oodle/rum/ExitReasons.kt +104 -0
- package/android/src/main/java/ai/oodle/rum/NativeEvents.kt +24 -0
- package/android/src/main/java/ai/oodle/rum/OodleRumModule.kt +96 -0
- package/android/src/main/java/ai/oodle/rum/OodleRumPackage.kt +26 -0
- package/android/src/main/java/ai/oodle/rum/Storage.kt +84 -0
- package/android/src/main/java/ai/oodle/rum/Vitals.kt +188 -0
- package/android/src/main/java/ai/oodle/rum/Watchdog.kt +81 -0
- package/android/src/main/java/ai/oodle/rum/WireframeCapture.kt +398 -0
- package/bin/oodle-rum-upload.mjs +104 -0
- package/ios/OodleCrashReporter.h +16 -0
- package/ios/OodleCrashReporter.m +202 -0
- package/ios/OodleRum.h +18 -0
- package/ios/OodleRum.mm +129 -0
- package/ios/OodleRumImpl.swift +450 -0
- package/ios/WireframeWalker.swift +279 -0
- package/lib/core/clock.d.ts +19 -0
- package/lib/core/clock.js +47 -0
- package/lib/core/clock.js.map +1 -0
- package/lib/core/config.d.ts +142 -0
- package/lib/core/config.js +178 -0
- package/lib/core/config.js.map +1 -0
- package/lib/core/consent.d.ts +5 -0
- package/lib/core/consent.js +33 -0
- package/lib/core/consent.js.map +1 -0
- package/lib/core/context.d.ts +36 -0
- package/lib/core/context.js +172 -0
- package/lib/core/context.js.map +1 -0
- package/lib/core/flags.d.ts +3 -0
- package/lib/core/flags.js +20 -0
- package/lib/core/flags.js.map +1 -0
- package/lib/core/ids.d.ts +7 -0
- package/lib/core/ids.js +40 -0
- package/lib/core/ids.js.map +1 -0
- package/lib/core/internal.d.ts +6 -0
- package/lib/core/internal.js +10 -0
- package/lib/core/internal.js.map +1 -0
- package/lib/core/logger.d.ts +8 -0
- package/lib/core/logger.js +38 -0
- package/lib/core/logger.js.map +1 -0
- package/lib/core/native.d.ts +71 -0
- package/lib/core/native.js +156 -0
- package/lib/core/native.js.map +1 -0
- package/lib/core/rate-limiter.d.ts +7 -0
- package/lib/core/rate-limiter.js +31 -0
- package/lib/core/rate-limiter.js.map +1 -0
- package/lib/core/session.d.ts +51 -0
- package/lib/core/session.js +196 -0
- package/lib/core/session.js.map +1 -0
- package/lib/core/size.d.ts +15 -0
- package/lib/core/size.js +68 -0
- package/lib/core/size.js.map +1 -0
- package/lib/core/tags.d.ts +10 -0
- package/lib/core/tags.js +33 -0
- package/lib/core/tags.js.map +1 -0
- package/lib/core/telemetry.d.ts +6 -0
- package/lib/core/telemetry.js +37 -0
- package/lib/core/telemetry.js.map +1 -0
- package/lib/core/tracing.d.ts +9 -0
- package/lib/core/tracing.js +57 -0
- package/lib/core/tracing.js.map +1 -0
- package/lib/core/transport.d.ts +76 -0
- package/lib/core/transport.js +560 -0
- package/lib/core/transport.js.map +1 -0
- package/lib/core/user.d.ts +12 -0
- package/lib/core/user.js +41 -0
- package/lib/core/user.js.map +1 -0
- package/lib/events/actions.d.ts +13 -0
- package/lib/events/actions.js +147 -0
- package/lib/events/actions.js.map +1 -0
- package/lib/events/emit.d.ts +21 -0
- package/lib/events/emit.js +144 -0
- package/lib/events/emit.js.map +1 -0
- package/lib/events/errors.d.ts +19 -0
- package/lib/events/errors.js +257 -0
- package/lib/events/errors.js.map +1 -0
- package/lib/events/lifecycle.d.ts +7 -0
- package/lib/events/lifecycle.js +101 -0
- package/lib/events/lifecycle.js.map +1 -0
- package/lib/events/longtasks.d.ts +2 -0
- package/lib/events/longtasks.js +42 -0
- package/lib/events/longtasks.js.map +1 -0
- package/lib/events/resources.d.ts +15 -0
- package/lib/events/resources.js +156 -0
- package/lib/events/resources.js.map +1 -0
- package/lib/events/tap-target.d.ts +42 -0
- package/lib/events/tap-target.js +191 -0
- package/lib/events/tap-target.js.map +1 -0
- package/lib/events/view-state.d.ts +13 -0
- package/lib/events/view-state.js +25 -0
- package/lib/events/view-state.js.map +1 -0
- package/lib/events/views.d.ts +21 -0
- package/lib/events/views.js +347 -0
- package/lib/events/views.js.map +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +24 -0
- package/lib/index.js.map +1 -0
- package/lib/navigation/react-navigation.d.ts +33 -0
- package/lib/navigation/react-navigation.js +61 -0
- package/lib/navigation/react-navigation.js.map +1 -0
- package/lib/react/OodlePrivacy.d.ts +15 -0
- package/lib/react/OodlePrivacy.js +13 -0
- package/lib/react/OodlePrivacy.js.map +1 -0
- package/lib/react/OodleProvider.d.ts +18 -0
- package/lib/react/OodleProvider.js +72 -0
- package/lib/react/OodleProvider.js.map +1 -0
- package/lib/replay/recorder.d.ts +22 -0
- package/lib/replay/recorder.js +317 -0
- package/lib/replay/recorder.js.map +1 -0
- package/lib/replay/rrweb.d.ts +105 -0
- package/lib/replay/rrweb.js +335 -0
- package/lib/replay/rrweb.js.map +1 -0
- package/lib/rum.d.ts +52 -0
- package/lib/rum.js +281 -0
- package/lib/rum.js.map +1 -0
- package/lib/specs/NativeOodleRum.d.ts +43 -0
- package/lib/specs/NativeOodleRum.js +5 -0
- package/lib/specs/NativeOodleRum.js.map +1 -0
- package/lib/version.d.ts +1 -0
- package/lib/version.js +6 -0
- package/lib/version.js.map +1 -0
- package/package.json +91 -4
- package/react-native.config.js +10 -0
- package/src/core/clock.ts +43 -0
- package/src/core/config.ts +344 -0
- package/src/core/consent.ts +32 -0
- package/src/core/context.ts +189 -0
- package/src/core/flags.ts +15 -0
- package/src/core/ids.ts +35 -0
- package/src/core/internal.ts +6 -0
- package/src/core/logger.ts +37 -0
- package/src/core/native.ts +201 -0
- package/src/core/rate-limiter.ts +34 -0
- package/src/core/session.ts +209 -0
- package/src/core/size.ts +79 -0
- package/src/core/tags.ts +30 -0
- package/src/core/telemetry.ts +35 -0
- package/src/core/tracing.ts +60 -0
- package/src/core/transport.ts +590 -0
- package/src/core/user.ts +45 -0
- package/src/events/actions.ts +157 -0
- package/src/events/emit.ts +131 -0
- package/src/events/errors.ts +283 -0
- package/src/events/lifecycle.ts +102 -0
- package/src/events/longtasks.ts +40 -0
- package/src/events/resources.ts +167 -0
- package/src/events/tap-target.ts +210 -0
- package/src/events/view-state.ts +30 -0
- package/src/events/views.ts +356 -0
- package/src/index.ts +34 -0
- package/src/navigation/react-navigation.ts +72 -0
- package/src/react/OodlePrivacy.tsx +25 -0
- package/src/react/OodleProvider.tsx +88 -0
- package/src/replay/recorder.ts +310 -0
- package/src/replay/rrweb.ts +460 -0
- package/src/rum.ts +295 -0
- package/src/specs/NativeOodleRum.ts +51 -0
- package/src/version.ts +2 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
package ai.oodle.rum
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.graphics.Color
|
|
5
|
+
import android.graphics.RectF
|
|
6
|
+
import android.graphics.drawable.ColorDrawable
|
|
7
|
+
import android.graphics.drawable.GradientDrawable
|
|
8
|
+
import android.os.Build
|
|
9
|
+
import android.os.SystemClock
|
|
10
|
+
import android.text.InputType
|
|
11
|
+
import android.text.method.PasswordTransformationMethod
|
|
12
|
+
import android.view.Gravity
|
|
13
|
+
import android.view.SurfaceView
|
|
14
|
+
import android.view.TextureView
|
|
15
|
+
import android.view.View
|
|
16
|
+
import android.view.ViewGroup
|
|
17
|
+
import android.view.ViewTreeObserver
|
|
18
|
+
import android.webkit.WebView
|
|
19
|
+
import android.widget.CompoundButton
|
|
20
|
+
import android.widget.EditText
|
|
21
|
+
import android.widget.HorizontalScrollView
|
|
22
|
+
import android.widget.ImageView
|
|
23
|
+
import android.widget.ScrollView
|
|
24
|
+
import android.widget.TextView
|
|
25
|
+
import com.facebook.react.uimanager.BackgroundStyleApplicator
|
|
26
|
+
import com.facebook.react.uimanager.style.BorderRadiusProp
|
|
27
|
+
import com.facebook.react.uimanager.style.LogicalEdge
|
|
28
|
+
import org.json.JSONArray
|
|
29
|
+
import org.json.JSONObject
|
|
30
|
+
import java.util.WeakHashMap
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Walks the visible view tree and describes each view that draws
|
|
34
|
+
* something as a wireframe: a box with a position, colors, and text.
|
|
35
|
+
* The JS side turns wireframes into replay events and applies privacy
|
|
36
|
+
* masking. Must run on the main thread.
|
|
37
|
+
*/
|
|
38
|
+
object WireframeCapture {
|
|
39
|
+
private const val PRIVACY_PREFIX = "oodle-privacy-"
|
|
40
|
+
/** Walks longer than this stop early, to keep frames from dropping. */
|
|
41
|
+
private const val TIME_BUDGET_MS = 40L
|
|
42
|
+
private const val UNCHANGED = "{\"unchanged\":true}"
|
|
43
|
+
|
|
44
|
+
private class Walk(
|
|
45
|
+
val density: Float,
|
|
46
|
+
val baseX: Int,
|
|
47
|
+
val baseY: Int,
|
|
48
|
+
val maxNodes: Int,
|
|
49
|
+
val deadline: Long,
|
|
50
|
+
) {
|
|
51
|
+
val nodes = JSONArray()
|
|
52
|
+
var truncated = false
|
|
53
|
+
val loc = IntArray(2)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Draw passes of the tracked windows. When no window drew since the last
|
|
58
|
+
* walk, the screen is the same, so the walk and the transfer to JS are
|
|
59
|
+
* skipped. This keeps an idle screen from costing main thread time.
|
|
60
|
+
*/
|
|
61
|
+
private var drawTick = 0L
|
|
62
|
+
private val tracked = WeakHashMap<View, ViewTreeObserver.OnDrawListener>()
|
|
63
|
+
private var lastSignature: String? = null
|
|
64
|
+
|
|
65
|
+
private fun track(roots: List<View>) {
|
|
66
|
+
for (root in roots) {
|
|
67
|
+
if (tracked.containsKey(root)) continue
|
|
68
|
+
val listener = ViewTreeObserver.OnDrawListener { drawTick++ }
|
|
69
|
+
try {
|
|
70
|
+
root.viewTreeObserver.addOnDrawListener(listener)
|
|
71
|
+
tracked[root] = listener
|
|
72
|
+
} catch (_: Throwable) {
|
|
73
|
+
// A dead observer: the root is walked every time.
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
fun capture(activity: Activity?, options: JSONObject): String {
|
|
79
|
+
val roots = rootViews(activity)
|
|
80
|
+
val base = activity?.window?.decorView ?: roots.firstOrNull()
|
|
81
|
+
val out = JSONObject()
|
|
82
|
+
if (base == null || base.width == 0) {
|
|
83
|
+
lastSignature = null
|
|
84
|
+
out.put("width", 0).put("height", 0).put("nodes", JSONArray())
|
|
85
|
+
return out.toString()
|
|
86
|
+
}
|
|
87
|
+
track(roots)
|
|
88
|
+
val signature =
|
|
89
|
+
roots.joinToString(",") { System.identityHashCode(it).toString() } +
|
|
90
|
+
"|${base.width}x${base.height}|$drawTick"
|
|
91
|
+
if (options.optBoolean("skipUnchanged", false) && signature == lastSignature) {
|
|
92
|
+
return UNCHANGED
|
|
93
|
+
}
|
|
94
|
+
lastSignature = signature
|
|
95
|
+
val density = base.resources.displayMetrics.density
|
|
96
|
+
val baseLoc = IntArray(2)
|
|
97
|
+
base.getLocationOnScreen(baseLoc)
|
|
98
|
+
val walk =
|
|
99
|
+
Walk(
|
|
100
|
+
density,
|
|
101
|
+
baseLoc[0],
|
|
102
|
+
baseLoc[1],
|
|
103
|
+
options.optInt("maxNodes", 2000),
|
|
104
|
+
SystemClock.uptimeMillis() + TIME_BUDGET_MS,
|
|
105
|
+
)
|
|
106
|
+
val screen = RectF(0f, 0f, base.width.toFloat(), base.height.toFloat())
|
|
107
|
+
for (root in roots) walk(root, walk, screen, 1f, null)
|
|
108
|
+
out.put("width", round(base.width / density))
|
|
109
|
+
out.put("height", round(base.height / density))
|
|
110
|
+
out.put("nodes", walk.nodes)
|
|
111
|
+
if (walk.truncated) out.put("truncated", true)
|
|
112
|
+
return out.toString()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The activity window plus any dialog windows (React Native's Modal is a
|
|
117
|
+
* dialog), in the order they were added, which is back to front.
|
|
118
|
+
*/
|
|
119
|
+
@Suppress("UNCHECKED_CAST")
|
|
120
|
+
private fun rootViews(activity: Activity?): List<View> {
|
|
121
|
+
val decor = activity?.window?.decorView
|
|
122
|
+
try {
|
|
123
|
+
val wmg = Class.forName("android.view.WindowManagerGlobal")
|
|
124
|
+
val instance = wmg.getMethod("getInstance").invoke(null)
|
|
125
|
+
val field = wmg.getDeclaredField("mViews").apply { isAccessible = true }
|
|
126
|
+
val views = ArrayList(field.get(instance) as List<View>)
|
|
127
|
+
val visible = views.filter { it.isAttachedToWindow && it.windowVisibility == View.VISIBLE && it.width > 0 }
|
|
128
|
+
if (visible.isNotEmpty() && (decor == null || visible.contains(decor))) return visible
|
|
129
|
+
} catch (_: Throwable) {
|
|
130
|
+
// Hidden API not reachable: record the activity window only.
|
|
131
|
+
}
|
|
132
|
+
return listOfNotNull(decor)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private fun walk(view: View, w: Walk, clip: RectF, parentAlpha: Float, privacy: String?) {
|
|
136
|
+
if (w.nodes.length() >= w.maxNodes || SystemClock.uptimeMillis() > w.deadline) {
|
|
137
|
+
w.truncated = true
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
if (view.visibility != View.VISIBLE || view.width == 0 || view.height == 0) return
|
|
141
|
+
val alpha = parentAlpha * view.alpha
|
|
142
|
+
if (alpha <= 0.01f) return
|
|
143
|
+
view.getLocationOnScreen(w.loc)
|
|
144
|
+
val x = (w.loc[0] - w.baseX).toFloat()
|
|
145
|
+
val y = (w.loc[1] - w.baseY).toFloat()
|
|
146
|
+
val rect = RectF(x, y, x + view.width * view.scaleX, y + view.height * view.scaleY)
|
|
147
|
+
val visible = RectF(rect)
|
|
148
|
+
if (!visible.intersect(clip)) return
|
|
149
|
+
|
|
150
|
+
var pv = privacy
|
|
151
|
+
val nativeId = nativeId(view)
|
|
152
|
+
if (nativeId != null && nativeId.startsWith(PRIVACY_PREFIX)) {
|
|
153
|
+
when (nativeId.substring(PRIVACY_PREFIX.length)) {
|
|
154
|
+
"hidden" -> {
|
|
155
|
+
w.nodes.put(box(view, "h", rect, visible, w, alpha))
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
"mask" -> pv = "mask"
|
|
159
|
+
"allow" -> pv = "allow"
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
describe(view, rect, visible, w, alpha, pv)?.let { w.nodes.put(it) }
|
|
164
|
+
|
|
165
|
+
if (view is ViewGroup && !isLeaf(view)) {
|
|
166
|
+
val childClip = if (clipsChildren(view)) visible else clip
|
|
167
|
+
for (i in 0 until view.childCount) {
|
|
168
|
+
walk(view.getChildAt(i), w, childClip, alpha, pv)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private fun isLeaf(view: ViewGroup): Boolean = view is WebView
|
|
174
|
+
|
|
175
|
+
private fun nativeId(view: View): String? =
|
|
176
|
+
try {
|
|
177
|
+
view.getTag(com.facebook.react.R.id.view_tag_native_id) as? String
|
|
178
|
+
} catch (_: Throwable) {
|
|
179
|
+
null
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private fun clipsChildren(view: ViewGroup): Boolean {
|
|
183
|
+
if (view is ScrollView || view is HorizontalScrollView) return true
|
|
184
|
+
if (view.javaClass.name.contains("ScrollView")) return true
|
|
185
|
+
if (view.clipChildren) return true
|
|
186
|
+
// React Native views keep clipChildren off and clip for overflow: hidden.
|
|
187
|
+
return try {
|
|
188
|
+
val overflow = view.javaClass.getMethod("getOverflow").invoke(view)
|
|
189
|
+
overflow != null && overflow.toString().lowercase().let { it.contains("hidden") || it.contains("scroll") }
|
|
190
|
+
} catch (_: Throwable) {
|
|
191
|
+
false
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private fun describe(view: View, rect: RectF, visible: RectF, w: Walk, alpha: Float, pv: String?): JSONObject? {
|
|
196
|
+
val bg = backgroundColor(view)
|
|
197
|
+
val borderWidth = borderWidth(view)
|
|
198
|
+
return when {
|
|
199
|
+
view is EditText -> {
|
|
200
|
+
val n = box(view, "in", rect, visible, w, alpha)
|
|
201
|
+
styleBox(n, view, bg, borderWidth, w)
|
|
202
|
+
n.put("tx", view.text?.toString() ?: "")
|
|
203
|
+
view.hint?.toString()?.takeIf { it.isNotEmpty() }?.let { n.put("ph", it) }
|
|
204
|
+
textStyle(n, view, w)
|
|
205
|
+
if (isSensitive(view)) n.put("sen", true)
|
|
206
|
+
pv?.let { n.put("pv", it) }
|
|
207
|
+
n
|
|
208
|
+
}
|
|
209
|
+
view is CompoundButton && isSwitch(view) -> {
|
|
210
|
+
val n = box(view, "sw", rect, visible, w, alpha)
|
|
211
|
+
n.put("on", view.isChecked)
|
|
212
|
+
n
|
|
213
|
+
}
|
|
214
|
+
view is TextView -> {
|
|
215
|
+
val text = view.text?.toString() ?: ""
|
|
216
|
+
if (isIconGlyph(text)) {
|
|
217
|
+
return box(view, "i", rect, visible, w, alpha)
|
|
218
|
+
}
|
|
219
|
+
if (text.isBlank() && !hasPaint(bg, borderWidth)) return null
|
|
220
|
+
val n = box(view, if (text.isBlank()) "s" else "t", rect, visible, w, alpha)
|
|
221
|
+
styleBox(n, view, bg, borderWidth, w)
|
|
222
|
+
if (text.isNotBlank()) {
|
|
223
|
+
n.put("tx", text)
|
|
224
|
+
textStyle(n, view, w)
|
|
225
|
+
pv?.let { n.put("pv", it) }
|
|
226
|
+
}
|
|
227
|
+
n
|
|
228
|
+
}
|
|
229
|
+
view.javaClass.simpleName == "PreparedLayoutTextView" -> preparedLayoutText(view, rect, visible, w, alpha, pv, bg, borderWidth)
|
|
230
|
+
view is ImageView -> box(view, "i", rect, visible, w, alpha).also { styleBox(it, view, null, 0f, w) }
|
|
231
|
+
view is WebView -> box(view, "wv", rect, visible, w, alpha)
|
|
232
|
+
view is SurfaceView || view is TextureView -> box(view, "p", rect, visible, w, alpha)
|
|
233
|
+
hasPaint(bg, borderWidth) -> box(view, "s", rect, visible, w, alpha).also { styleBox(it, view, bg, borderWidth, w) }
|
|
234
|
+
else -> null
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private fun isSwitch(view: CompoundButton): Boolean = view.javaClass.name.contains("Switch", ignoreCase = true)
|
|
239
|
+
|
|
240
|
+
private fun hasPaint(bg: Int?, borderWidth: Float): Boolean = (bg != null && Color.alpha(bg) > 0) || borderWidth > 0f
|
|
241
|
+
|
|
242
|
+
/** Icon fonts draw glyphs from the Unicode private use area; text would show boxes. */
|
|
243
|
+
private fun isIconGlyph(text: String): Boolean {
|
|
244
|
+
if (text.isEmpty() || text.length > 4) return false
|
|
245
|
+
return text.all { it.code in 0xE000..0xF8FF || Character.isSurrogate(it) }
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
private fun box(view: View, kind: String, rect: RectF, visible: RectF, w: Walk, alpha: Float): JSONObject {
|
|
249
|
+
val d = w.density
|
|
250
|
+
val n = JSONObject()
|
|
251
|
+
n.put("id", System.identityHashCode(view))
|
|
252
|
+
n.put("k", kind)
|
|
253
|
+
n.put("x", round(rect.left / d))
|
|
254
|
+
n.put("y", round(rect.top / d))
|
|
255
|
+
n.put("w", round(rect.width() / d))
|
|
256
|
+
n.put("h", round(rect.height() / d))
|
|
257
|
+
if (alpha < 0.99f) n.put("o", round(alpha))
|
|
258
|
+
if (visible != rect) {
|
|
259
|
+
val insets = JSONArray()
|
|
260
|
+
insets.put(round((visible.top - rect.top) / d))
|
|
261
|
+
insets.put(round((rect.right - visible.right) / d))
|
|
262
|
+
insets.put(round((rect.bottom - visible.bottom) / d))
|
|
263
|
+
insets.put(round((visible.left - rect.left) / d))
|
|
264
|
+
n.put("c", insets)
|
|
265
|
+
}
|
|
266
|
+
return n
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
private fun styleBox(n: JSONObject, view: View, bg: Int?, borderWidth: Float, w: Walk) {
|
|
270
|
+
if (bg != null && Color.alpha(bg) > 0) n.put("bg", css(bg))
|
|
271
|
+
if (borderWidth > 0f) {
|
|
272
|
+
n.put("bw", round(borderWidth))
|
|
273
|
+
borderColor(view)?.let { n.put("bc", css(it)) }
|
|
274
|
+
}
|
|
275
|
+
val r = radius(view, n.optDouble("w", 0.0).toFloat(), w)
|
|
276
|
+
if (r > 0f) n.put("r", round(r))
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
private fun textStyle(n: JSONObject, view: TextView, w: Walk) {
|
|
280
|
+
n.put("tc", css(view.currentTextColor))
|
|
281
|
+
n.put("fs", round(view.textSize / w.density))
|
|
282
|
+
val tf = view.typeface
|
|
283
|
+
val weight = when {
|
|
284
|
+
tf == null -> 400
|
|
285
|
+
Build.VERSION.SDK_INT >= 28 -> tf.weight
|
|
286
|
+
tf.isBold -> 700
|
|
287
|
+
else -> 400
|
|
288
|
+
}
|
|
289
|
+
if (weight != 400) n.put("fw", weight)
|
|
290
|
+
when (view.gravity and Gravity.HORIZONTAL_GRAVITY_MASK) {
|
|
291
|
+
Gravity.CENTER_HORIZONTAL -> n.put("ta", "center")
|
|
292
|
+
Gravity.RIGHT, Gravity.END -> n.put("ta", "right")
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** React Native's newer text view keeps its text in a prepared Layout. */
|
|
297
|
+
private fun preparedLayoutText(
|
|
298
|
+
view: View,
|
|
299
|
+
rect: RectF,
|
|
300
|
+
visible: RectF,
|
|
301
|
+
w: Walk,
|
|
302
|
+
alpha: Float,
|
|
303
|
+
pv: String?,
|
|
304
|
+
bg: Int?,
|
|
305
|
+
borderWidth: Float,
|
|
306
|
+
): JSONObject? =
|
|
307
|
+
try {
|
|
308
|
+
val getter = view.javaClass.methods.first { it.name.startsWith("getPreparedLayout") && it.parameterCount == 0 }
|
|
309
|
+
val prepared = getter.invoke(view) ?: return null
|
|
310
|
+
val layout = prepared.javaClass.getMethod("getLayout").invoke(prepared) as android.text.Layout
|
|
311
|
+
val text = layout.text?.toString() ?: ""
|
|
312
|
+
val n = box(view, if (text.isBlank()) "s" else "t", rect, visible, w, alpha)
|
|
313
|
+
styleBox(n, view, bg, borderWidth, w)
|
|
314
|
+
if (text.isNotBlank()) {
|
|
315
|
+
n.put("tx", text)
|
|
316
|
+
n.put("tc", css(layout.paint.color))
|
|
317
|
+
n.put("fs", round(layout.paint.textSize / w.density))
|
|
318
|
+
when (layout.alignment) {
|
|
319
|
+
android.text.Layout.Alignment.ALIGN_CENTER -> n.put("ta", "center")
|
|
320
|
+
android.text.Layout.Alignment.ALIGN_OPPOSITE -> n.put("ta", "right")
|
|
321
|
+
else -> {}
|
|
322
|
+
}
|
|
323
|
+
pv?.let { n.put("pv", it) }
|
|
324
|
+
}
|
|
325
|
+
n
|
|
326
|
+
} catch (_: Throwable) {
|
|
327
|
+
if (hasPaint(bg, borderWidth)) box(view, "s", rect, visible, w, alpha) else null
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
private fun isSensitive(view: EditText): Boolean {
|
|
331
|
+
if (view.transformationMethod is PasswordTransformationMethod) return true
|
|
332
|
+
val type = view.inputType
|
|
333
|
+
val cls = type and InputType.TYPE_MASK_CLASS
|
|
334
|
+
val variation = type and InputType.TYPE_MASK_VARIATION
|
|
335
|
+
return when (cls) {
|
|
336
|
+
InputType.TYPE_CLASS_TEXT ->
|
|
337
|
+
variation == InputType.TYPE_TEXT_VARIATION_PASSWORD ||
|
|
338
|
+
variation == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD ||
|
|
339
|
+
variation == InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD ||
|
|
340
|
+
variation == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS ||
|
|
341
|
+
variation == InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS ||
|
|
342
|
+
variation == InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS
|
|
343
|
+
InputType.TYPE_CLASS_NUMBER -> variation == InputType.TYPE_NUMBER_VARIATION_PASSWORD
|
|
344
|
+
InputType.TYPE_CLASS_PHONE -> true
|
|
345
|
+
else -> false
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
private fun backgroundColor(view: View): Int? {
|
|
350
|
+
try {
|
|
351
|
+
BackgroundStyleApplicator.getBackgroundColor(view)?.let { return it }
|
|
352
|
+
} catch (_: Throwable) {
|
|
353
|
+
}
|
|
354
|
+
return when (val bg = view.background) {
|
|
355
|
+
is ColorDrawable -> bg.color
|
|
356
|
+
is GradientDrawable -> bg.color?.defaultColor
|
|
357
|
+
else -> null
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
private fun borderWidth(view: View): Float =
|
|
362
|
+
try {
|
|
363
|
+
BackgroundStyleApplicator.getBorderWidth(view, LogicalEdge.ALL)
|
|
364
|
+
?: BackgroundStyleApplicator.getBorderWidth(view, LogicalEdge.TOP)
|
|
365
|
+
?: 0f
|
|
366
|
+
} catch (_: Throwable) {
|
|
367
|
+
0f
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
private fun borderColor(view: View): Int? =
|
|
371
|
+
try {
|
|
372
|
+
BackgroundStyleApplicator.getBorderColor(view, LogicalEdge.ALL)
|
|
373
|
+
?: BackgroundStyleApplicator.getBorderColor(view, LogicalEdge.TOP)
|
|
374
|
+
} catch (_: Throwable) {
|
|
375
|
+
null
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
private fun radius(view: View, widthDp: Float, w: Walk): Float {
|
|
379
|
+
try {
|
|
380
|
+
val r =
|
|
381
|
+
BackgroundStyleApplicator.getBorderRadius(view, BorderRadiusProp.BORDER_RADIUS)
|
|
382
|
+
?: BackgroundStyleApplicator.getBorderRadius(view, BorderRadiusProp.BORDER_TOP_LEFT_RADIUS)
|
|
383
|
+
if (r != null) return r.resolve(widthDp)
|
|
384
|
+
} catch (_: Throwable) {
|
|
385
|
+
}
|
|
386
|
+
val bg = view.background
|
|
387
|
+
if (bg is GradientDrawable && Build.VERSION.SDK_INT >= 24) {
|
|
388
|
+
return bg.cornerRadius / w.density
|
|
389
|
+
}
|
|
390
|
+
return 0f
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** ARGB int to CSS #rrggbbaa. */
|
|
394
|
+
private fun css(color: Int): String =
|
|
395
|
+
String.format("#%02x%02x%02x%02x", Color.red(color), Color.green(color), Color.blue(color), Color.alpha(color))
|
|
396
|
+
|
|
397
|
+
private fun round(v: Float): Double = Math.round(v * 10.0) / 10.0
|
|
398
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Uploads the files Oodle needs to turn release stack traces back into
|
|
3
|
+
// source locations: the JS source map of the Hermes bundle, and the R8
|
|
4
|
+
// mapping of the Android build. Run it after each release build, with the
|
|
5
|
+
// same service, version and build that the app sends.
|
|
6
|
+
import { readFile } from 'node:fs/promises';
|
|
7
|
+
import { basename } from 'node:path';
|
|
8
|
+
import { parseArgs } from 'node:util';
|
|
9
|
+
|
|
10
|
+
const USAGE = `Usage:
|
|
11
|
+
oodle-rum-upload --service <name> --version <version> [--build <build>]
|
|
12
|
+
(--sourcemap <file.map> --bundle <bundle name> | --r8-mapping <mapping.txt>)
|
|
13
|
+
|
|
14
|
+
Connection (flags or environment variables):
|
|
15
|
+
--api-url OODLE_API_URL Oodle API URL, for example https://<instance>.api.oodle.ai
|
|
16
|
+
--instance OODLE_INSTANCE Oodle instance ID
|
|
17
|
+
--api-key OODLE_API_KEY API key that can write RUM settings (not the RUM ingest key)
|
|
18
|
+
|
|
19
|
+
Bundle names: index.android.bundle (Android), main.jsbundle (iOS).`;
|
|
20
|
+
|
|
21
|
+
function fail(message) {
|
|
22
|
+
console.error(`oodle-rum-upload: ${message}\n\n${USAGE}`);
|
|
23
|
+
process.exit(2);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let args;
|
|
27
|
+
try {
|
|
28
|
+
({ values: args } = parseArgs({
|
|
29
|
+
options: {
|
|
30
|
+
'api-url': { type: 'string' },
|
|
31
|
+
instance: { type: 'string' },
|
|
32
|
+
'api-key': { type: 'string' },
|
|
33
|
+
service: { type: 'string' },
|
|
34
|
+
version: { type: 'string' },
|
|
35
|
+
build: { type: 'string' },
|
|
36
|
+
sourcemap: { type: 'string' },
|
|
37
|
+
bundle: { type: 'string' },
|
|
38
|
+
'r8-mapping': { type: 'string' },
|
|
39
|
+
help: { type: 'boolean', short: 'h' },
|
|
40
|
+
},
|
|
41
|
+
}));
|
|
42
|
+
} catch (e) {
|
|
43
|
+
fail(e.message);
|
|
44
|
+
}
|
|
45
|
+
if (args.help) {
|
|
46
|
+
console.log(USAGE);
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const apiUrl = (args['api-url'] ?? process.env.OODLE_API_URL ?? '').replace(/\/+$/, '');
|
|
51
|
+
const instance = args.instance ?? process.env.OODLE_INSTANCE ?? '';
|
|
52
|
+
const apiKey = args['api-key'] ?? process.env.OODLE_API_KEY ?? '';
|
|
53
|
+
if (!apiUrl || !instance || !apiKey) fail('--api-url, --instance and --api-key are required');
|
|
54
|
+
if (!args.service || !args.version) fail('--service and --version are required');
|
|
55
|
+
if (!args.sourcemap === !args['r8-mapping']) fail('give either --sourcemap or --r8-mapping');
|
|
56
|
+
|
|
57
|
+
async function upload({ kind, fileName, minifiedUrl, data }) {
|
|
58
|
+
const form = new FormData();
|
|
59
|
+
form.set('service', args.service);
|
|
60
|
+
form.set('version', args.version);
|
|
61
|
+
if (args.build) form.set('build', args.build);
|
|
62
|
+
form.set('kind', kind);
|
|
63
|
+
form.set('minified_url', minifiedUrl);
|
|
64
|
+
form.set('file', new Blob([data]), fileName);
|
|
65
|
+
const url = `${apiUrl}/v1/api/instance/${encodeURIComponent(instance)}/rum/source-maps`;
|
|
66
|
+
const res = await fetch(url, {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
headers: { 'X-API-KEY': apiKey, 'X-OODLE-INSTANCE': instance },
|
|
69
|
+
body: form,
|
|
70
|
+
});
|
|
71
|
+
const text = await res.text();
|
|
72
|
+
if (!res.ok) {
|
|
73
|
+
console.error(`oodle-rum-upload: HTTP ${res.status}: ${text.slice(0, 500)}`);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
console.log(`Uploaded ${fileName} (${kind}) for ${args.service} ${args.version}${args.build ? ` build ${args.build}` : ''}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (args.sourcemap) {
|
|
80
|
+
if (!args.bundle) fail('--bundle is required with --sourcemap');
|
|
81
|
+
let map;
|
|
82
|
+
try {
|
|
83
|
+
map = JSON.parse(await readFile(args.sourcemap, 'utf8'));
|
|
84
|
+
} catch (e) {
|
|
85
|
+
fail(`cannot read the source map: ${e.message}`);
|
|
86
|
+
}
|
|
87
|
+
if (map.version !== 3 || typeof map.mappings !== 'string') fail('the file is not a version 3 source map');
|
|
88
|
+
// Stack frames name the bundle file, so the map must name it too.
|
|
89
|
+
map.file = args.bundle;
|
|
90
|
+
await upload({
|
|
91
|
+
kind: 'sourcemap',
|
|
92
|
+
fileName: `${basename(args.bundle)}.map`,
|
|
93
|
+
minifiedUrl: args.bundle,
|
|
94
|
+
data: JSON.stringify(map),
|
|
95
|
+
});
|
|
96
|
+
} else {
|
|
97
|
+
let data;
|
|
98
|
+
try {
|
|
99
|
+
data = await readFile(args['r8-mapping']);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
fail(`cannot read the mapping file: ${e.message}`);
|
|
102
|
+
}
|
|
103
|
+
await upload({ kind: 'r8-mapping', fileName: 'mapping.txt', minifiedUrl: 'mapping.txt', data });
|
|
104
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
+
|
|
5
|
+
/// Writes an uncaught exception or a fatal signal to disk before the
|
|
6
|
+
/// process ends. The JS side sends it on the next start.
|
|
7
|
+
@interface OodleCrashReporter : NSObject
|
|
8
|
+
|
|
9
|
+
+ (BOOL)installWithDirectory:(NSString *)directory;
|
|
10
|
+
|
|
11
|
+
/// The crash that ended the previous run, as JSON, or nil. Deletes it.
|
|
12
|
+
+ (nullable NSString *)consumeWithDirectory:(NSString *)directory;
|
|
13
|
+
|
|
14
|
+
@end
|
|
15
|
+
|
|
16
|
+
NS_ASSUME_NONNULL_END
|