-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFakeCrashReportingSdk.kt
More file actions
61 lines (50 loc) · 2.49 KB
/
FakeCrashReportingSdk.kt
File metadata and controls
61 lines (50 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.aquib.androidperflab.sdk
import android.content.Context
import android.util.Log
import java.io.File
object FakeCrashReportingSdk {
// ── Fast path — called synchronously from CrashReportingInitializer ──────────
//
// Only registers the UncaughtExceptionHandler. Safe to call from any thread.
// Separated from uploadPendingReports() so the handler is installed before any
// other SDK work begins — matching the original "must be first" requirement —
// without blocking the main thread for the full 120 ms upload simulation.
fun registerHandler(context: Context) {
val previousHandler = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
Log.e("FakeCrashReportingSdk", "Uncaught exception on ${thread.name}", throwable)
previousHandler?.uncaughtException(thread, throwable)
}
Log.d("FakeCrashReportingSdk", "registerHandler complete")
}
// ── Slow path — called from Dispatchers.IO via CrashReportingInitializer ─────
//
// Simulates: scanning the cache directory for pending crash dumps, parsing them,
// writing a session sentinel, and uploading reports to the backend. All I/O and
// the blocking upload sleep are safe on a background thread.
fun uploadPendingReports(context: Context) {
val cacheDir = context.cacheDir
// Simulate: scanning cache dir for pending crash dump files
val crashDumps = cacheDir.listFiles { f -> f.name.startsWith("crash_") }
?.toList()
?: emptyList()
// Simulate: parsing each crash dump (string + I/O work per file)
val parsedReports = crashDumps.map { file ->
buildString {
append("report["); append(file.name); append("]: ")
append(file.length()); append(" bytes, modified=")
append(file.lastModified())
}
}
// Simulate: writing a session sentinel so the next launch can detect clean exits
val sentinel = File(cacheDir, "crash_sentinel_${System.currentTimeMillis()}.tmp")
sentinel.createNewFile()
// Simulate: blocking upload of pending reports to the backend
Thread.sleep(120L)
Log.d(
"FakeCrashReportingSdk",
"uploadPendingReports complete — found ${crashDumps.size} dumps, " +
"parsed ${parsedReports.size} reports",
)
}
}