@replayd/capacitor-android 0.1.11 → 0.1.13

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.
@@ -13,7 +13,9 @@ import com.getcapacitor.PluginMethod
13
13
  import com.getcapacitor.annotation.CapacitorPlugin
14
14
  import org.json.JSONArray
15
15
  import org.json.JSONObject
16
+ import java.io.ByteArrayOutputStream
16
17
  import java.io.File
18
+ import java.io.InputStream
17
19
 
18
20
  /**
19
21
  * T-154: native crashes and ANRs for replayd. An uncaught Java/Kotlin exception is written to app storage by a handler
@@ -63,8 +65,9 @@ class ReplaydNativePlugin : Plugin() {
63
65
  return list.map { info ->
64
66
  val sid = CrashStore.sidAt(timeline, info.timestamp)
65
67
  val anr = info.reason == ApplicationExitInfo.REASON_ANR
66
- val trace = try {
67
- info.traceInputStream?.use { s -> String(s.readBytes().take(CrashStore.MAX_BYTES).toByteArray()) }
68
+ // only an ANR's stack is reported, so native crashes never open their (possibly huge) trace stream
69
+ val trace = if (!anr) null else try {
70
+ info.traceInputStream?.use { s -> CrashStore.readCapped(s, CrashStore.MAX_BYTES) }
68
71
  } catch (_: Throwable) {
69
72
  null
70
73
  }
@@ -135,6 +138,20 @@ internal object CrashStore {
135
138
  e.apply()
136
139
  }
137
140
 
141
+ /** At most [max] bytes of [s] as text, read in small chunks: an oversized stream is never held in memory. */
142
+ fun readCapped(s: InputStream, max: Int): String {
143
+ val out = ByteArrayOutputStream(minOf(max, 8192))
144
+ val buf = ByteArray(8192)
145
+ var left = max
146
+ while (left > 0) {
147
+ val n = s.read(buf, 0, minOf(buf.size, left))
148
+ if (n < 0) break
149
+ out.write(buf, 0, n)
150
+ left -= n
151
+ }
152
+ return String(out.toByteArray(), Charsets.UTF_8)
153
+ }
154
+
138
155
  private fun dir(ctx: Context) = File(ctx.filesDir, "replayd-crashes").apply { mkdirs() }
139
156
 
140
157
  fun install(ctx: Context) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replayd/capacitor-android",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Capacitor Android plugin for replayd: native (Java/Kotlin) crashes and ANRs, reported on the next launch",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -25,12 +25,12 @@
25
25
  }
26
26
  },
27
27
  "peerDependencies": {
28
- "@replayd/core": "^0.1.11"
28
+ "@replayd/core": "^0.1.13"
29
29
  },
30
30
  "devDependencies": {
31
- "@replayd/core": "0.1.11"
31
+ "@replayd/core": "0.1.13"
32
32
  },
33
- "gitHead": "3d25e9b1b327f080b8b47af7edb36056c0613ad8",
33
+ "gitHead": "fd431a5d7805356f4043393e1a2fe292dce2ee3e",
34
34
  "scripts": {
35
35
  "build": "node ../../scripts/build.mjs build.json && tsc -p tsconfig.build.json"
36
36
  }