package link.roadio.riff import android.app.Application import android.content.Context import android.os.SystemClock import android.util.Log import java.io.PrintWriter import java.util.concurrent.ConcurrentHashMap /** Monotonic process-entry evidence; no configuration, selected-root or media access. */ class RiffApplication : Application() { override fun attachBaseContext(base: Context) { super.attachBaseContext(base) StartupTrace.begin(Application.getProcessName()) } } internal object StartupTrace { private var entry = 0L private val milestones = ConcurrentHashMap() fun begin(process: String) { entry = SystemClock.elapsedRealtime() Log.i("RiffStartup", "application_entry uptime_ms=$entry process=$process") } fun mark( event: String, details: String = "", ) { val now = SystemClock.elapsedRealtime() if (milestones.putIfAbsent(event, now) != null) return Log.i("RiffStartup", "$event elapsed_ms=${now - entry} uptime_ms=$now $details") } /** Service dumps retain evidence when vendor logging evicts early process milestones. */ fun dump(writer: PrintWriter) { writer.println("RiffStartup: application_entry uptime_ms=$entry") milestones.toSortedMap().forEach { (event, now) -> writer.println("RiffStartup: $event elapsed_ms=${now - entry} uptime_ms=$now") } } }