package com.peachpasswords.ui.components import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.ui.platform.LocalContext import androidx.fragment.app.FragmentActivity import com.peachpasswords.BuildConfig /** * Acquires a reference-counted secure-window lease while this composable is in * the composition — blocking screenshots, screen recording, and the recents * thumbnail of screens that display secrets (MN-3: recovery words, export blob, * codex generation). Mirrors the inline effect EntryDetailScreen / NotesModeScreen * already use. The lease is safe when secret composables are nested. * * Skipped only when BuildConfig.DEBUG is true AND [QaFlags.disableSecureCaptureForQa] * was explicitly opted into (see that file) — automated visual QA needs to capture * these screens too. Always enforced in release builds regardless of the flag. */ @Composable fun SecureFlagEffect() { val context = LocalContext.current DisposableEffect(Unit) { if (BuildConfig.DEBUG && QaFlags.disableSecureCaptureForQa) { return@DisposableEffect onDispose { } } val window = (context as? FragmentActivity)?.window // MainActivity installs a permanent release owner before Compose starts; // on debug builds this is a reference-counted lease. In either case a // child effect can never clear a sibling's or the activity's protection. window?.let(SecureWindowPolicy::acquire) onDispose { window?.let(SecureWindowPolicy::release) } } }