communicate: reload threads on resume after SMS grant (#735)
- Commit
498508376e0f0e4273f39a7e95fcbc8f040bcfd9- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-13 20:22 UTC (1 month ago)
- Parents
2692f91
Diff
communicate/src/main/java/com/vayunmathur/communicate/ui/MessagesScreen.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/ui/MessagesScreen.kt b/communicate/src/main/java/com/vayunmathur/communicate/ui/MessagesScreen.ktindex 3a695d676d..3a7576c102 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/ui/MessagesScreen.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/ui/MessagesScreen.kt@@ -7,7 +7,9 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.produceState import androidx.compose.runtime.remember@@ -52,6 +54,11 @@ fun MessagesScreen(onOpenThread: (SmsThread) -> Unit, onOpenAccounts: () -> Unit val lineChoices = rememberLineChoices() val scope = rememberCoroutineScope() var showPicker by remember { mutableStateOf(false) }+ // #735: PermissionGate reads checkSelfPermission during composition with no+ // resume trigger, so granting SMS from Settings never recomposes the gate+ // (stuck on empty state until restart). resumeRevision forces the gate to+ // re-check + reloads threads. Scoped to this screen only.+ val resumeRevision = rememberResumeRevision() if (showPicker) { NewMessagePicker(@@ -233,8 +240,11 @@ fun MessagesScreen(onOpenThread: (SmsThread) -> Unit, onOpenAccounts: () -> Unit // Foreground polling: Google Voice has no cheap realtime channel wired up yet, // so while this screen is shown we re-fetch the merged inbox on an interval. // (The Punctual/WebChannel realtime upgrade is noted as future work.)- var tick by androidx.compose.runtime.remember { androidx.compose.runtime.mutableIntStateOf(0) }- androidx.compose.runtime.LaunchedEffect(roleRevision, permissionRevision) {+ // resumeRevision (bumped on activity resume above) is also a reload key:+ // granting SMS from Settings returns via resume with no permission-callback+ // re-fire, so without this the gate keeps its stale denial until restart.+ var tick by remember { mutableIntStateOf(0) }+ LaunchedEffect(roleRevision, permissionRevision, resumeRevision) { while (true) { kotlinx.coroutines.delay(15_000) tick++@@ -244,7 +254,13 @@ fun MessagesScreen(onOpenThread: (SmsThread) -> Unit, onOpenAccounts: () -> Unit initialValue = null, roleRevision, permissionRevision,+ resumeRevision, tick) {+ // No value=null reset: keep the previous list visible while the+ // resume-triggered reload runs in the background (avoids a+ // loading flash on every return from a thread). The+ // denied->granted transition still shows LoadingState first+ // because this content is newly composed (initialValue=null). value = withContext(Dispatchers.IO) { CommunicateRepository.loadSmsThreadsMerged(context) } }
communicate/src/main/java/com/vayunmathur/communicate/ui/ResumeRevision.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/ui/ResumeRevision.kt b/communicate/src/main/java/com/vayunmathur/communicate/ui/ResumeRevision.ktnew file mode 100644index 0000000000..031233722d--- /dev/null+++ b/communicate/src/main/java/com/vayunmathur/communicate/ui/ResumeRevision.kt@@ -0,0 +1,52 @@+package com.vayunmathur.communicate.ui++import android.app.Activity+import android.app.Application+import android.os.Bundle+import androidx.compose.runtime.Composable+import androidx.compose.runtime.DisposableEffect+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableIntStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.platform.LocalContext++/**+ * Epoch bumped on activity resume (after a pause) so permission gates re-check+ * grants made outside the app — e.g. SMS granted from Settings, whose result+ * no permission launcher ever reports (#735). Read at the call site's scope so+ * the bump recomposes the gates even when the gated content isn't composed.+ * Scoped to the calling screen — no shared permissions-architecture change.+ */+@Composable+fun rememberResumeRevision(): Int {+ val context = LocalContext.current+ var resumeRevision by remember { mutableIntStateOf(0) }+ DisposableEffect(context) {+ val app = context.applicationContext as? Application+ if (app == null) {+ onDispose {}+ } else {+ val callbacks = object : Application.ActivityLifecycleCallbacks {+ // Only resumes after a pause can reflect an out-of-app grant;+ // this also skips the initial onResume so callers don't load+ // twice at startup.+ var seenPause = false+ override fun onActivityResumed(activity: Activity) {+ if (seenPause) resumeRevision+++ }+ override fun onActivityPaused(activity: Activity) {+ seenPause = true+ }+ override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) = Unit+ override fun onActivityStarted(activity: Activity) = Unit+ override fun onActivityStopped(activity: Activity) = Unit+ override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) = Unit+ override fun onActivityDestroyed(activity: Activity) = Unit+ }+ app.registerActivityLifecycleCallbacks(callbacks)+ onDispose { app.unregisterActivityLifecycleCallbacks(callbacks) }+ }+ }+ return resumeRevision+}