-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFakeCrashReportingSdk.kt
More file actions
45 lines (37 loc) · 1.88 KB
/
Copy pathFakeCrashReportingSdk.kt
File metadata and controls
45 lines (37 loc) · 1.88 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
package com.aquib.androidperflab.sdk
import android.content.Context
import android.util.Log
import java.io.File
object FakeCrashReportingSdk {
// Simulates: scanning the cache directory for pending crash dumps left by a previous
// session, installing an UncaughtExceptionHandler, and uploading any found dumps
// synchronously before the app is considered "ready".
fun init(context: Context) {
// Simulate: scanning cache dir for pending crash dump files
val cacheDir = context.cacheDir
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 file so the next launch can detect
// whether this session ended cleanly
val sentinel = File(cacheDir, "crash_sentinel_${System.currentTimeMillis()}.tmp")
sentinel.createNewFile()
// Simulate: registering the uncaught exception handler (involves thread locking)
val previousHandler = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
Log.e("FakeCrashReportingSdk", "Uncaught exception on ${thread.name}", throwable)
previousHandler?.uncaughtException(thread, throwable)
}
// Simulate: blocking upload of any pending crash reports to the backend
Thread.sleep(120L)
Log.d("FakeCrashReportingSdk", "init complete — found ${crashDumps.size} pending dumps, parsed ${parsedReports.size} reports")
}
}