Skip to content

Instantly share code, notes, and snippets.

View LethalMaus's full-sized avatar

James Cullimore LethalMaus

View GitHub Profile
@LethalMaus
LethalMaus / dejavu-cleaner-fix-runtime.kt
Created May 7, 2026 19:50
Dejavu cleaner runtime fix for article
package dejavu.internal
import android.app.Activity
import android.app.Application
import android.os.Bundle
import androidx.compose.runtime.tooling.CompositionData
import java.lang.ref.WeakReference
import java.lang.reflect.Field
import java.util.Collections
import java.util.IdentityHashMap
@LethalMaus
LethalMaus / dejavu-minimal-fix-rule.kt
Created May 7, 2026 19:50
Dejavu minimal rule fix for article
package dejavu
import androidx.activity.ComponentActivity
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.ext.junit.rules.ActivityScenarioRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
@LethalMaus
LethalMaus / dejavu-mapping-repro-test.kt
Created May 7, 2026 19:50
Dejavu mapping repro test for article
package dev.repro.dejavu
import androidx.activity.ComponentActivity
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.test.ext.junit.runners.AndroidJUnit4
import dejavu.assertRecompositions
@LethalMaus
LethalMaus / dejavu-mapping-repro-screen.kt
Created May 7, 2026 19:50
Dejavu mapping repro screen for article
package dev.repro.dejavu
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Card
@LethalMaus
LethalMaus / deferred-runtime-startup-code.kt
Last active April 9, 2026 19:31
Deferred runtime startup code
onStartupRouteReady {
postToNextUiTurn {
waitBrieflyForFirstFrameToSettle()
trace("DeferredRuntimeStartup") {
startBackgroundService()
requestMissingStorageAccessIfNeeded()
initializeFileWatcher()
connectRuntimeClient()
}
@LethalMaus
LethalMaus / post-draw-startup-deferral-pseudocode.kt
Created April 9, 2026 19:15
Post-draw startup deferral pseudocode for article
var postDrawWorkEnabled by remember { mutableStateOf(false) }
onFirstFrameRendered {
markStartupComplete()
postDrawWorkEnabled = true
}
onScreenVisible(postDrawWorkEnabled) {
updateConnectivityFlags()
if (postDrawWorkEnabled) {
@LethalMaus
LethalMaus / perfetto-trace-slices-pseudocode.kt
Last active April 9, 2026 19:31
Perfetto trace slice naming code
trace("AppStartup") {
registerEarlyListeners()
resolveInitialState()
renderRootUi()
}
trace("RuntimeConnect") {
startLocalWatchers()
createRuntimeClient()
openRuntimeConnection()
@LethalMaus
LethalMaus / host_test_script_inspect.sh
Created April 1, 2026 20:55
TrustKeyService: adb host inspect script snippet
adb shell am broadcast \
-n "$RECEIVER" \
-a "$PACKAGE.action.EXECUTE_COMMAND" \
--es request_id "$request_id" \
--es operation inspect \
--es alias "$alias" >/dev/null
adb logcat -d -s "$TAG:I"
@LethalMaus
LethalMaus / keystore_security_verdict.kt
Created April 1, 2026 20:55
TrustKeyService: Android Keystore security verdict helper
@Suppress("DEPRECATION")
private fun KeyInfo.toSecurityVerdict(): String {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
return if (isInsideSecureHardware) "HARDWARE_BACKED" else "SOFTWARE_BACKED"
}
return when (securityLevel) {
KeyProperties.SECURITY_LEVEL_SOFTWARE -> "SOFTWARE_BACKED"
KeyProperties.SECURITY_LEVEL_TRUSTED_ENVIRONMENT -> "HARDWARE_BACKED_TEE"
KeyProperties.SECURITY_LEVEL_STRONGBOX -> "HARDWARE_BACKED_STRONGBOX"
@LethalMaus
LethalMaus / keystore_key_generation.kt
Created April 1, 2026 20:55
TrustKeyService: Android Keystore AES key generation snippet
val builder = KeyGenParameterSpec.Builder(
alias,
KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT,
).setBlockModes(KeyProperties.BLOCK_MODE_GCM)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
.setRandomizedEncryptionRequired(true)
.setKeySize(256)
if (requestStrongBox && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
builder.setIsStrongBoxBacked(true)