Modern Apps git

← Modern-Apps.git

security: stop cloud backup shipping decrypted vaults

Commit
b59838155add9342dba6d887328f2bf0a81c4587
Author
Vayun Mathur <[email protected]>
When
2026-11-20 20:44 UTC (15 days ago)
Parents
35cd999
Critical census finding: eight apps declared a legacy
backupAgent that exported their SQLCipher databases DECRYPTED
(Key '') through Android cloud backup - passwords' entire
vault, findfamily's E2EE/PQC private keys (against its own
deny-all rules), photos' hidden secure folder, openassistant
conversation history, and the games hub behavioural profile the
rules explicitly exclude. Each app's audited
data_extraction_rules.xml was bypassed by the agent path.

The backupAgent attribute and agent classes are removed for
passwords, notes, photos, findfamily, todo, flashcards,
openassistant and games/hub, so the extraction rules now govern
both cloud and device-transfer channels (encrypted-file copies
where the rules allow them). User-triggered local backups
(KDBX sync, in-app backup buttons, manual FamilyBackup export)
are untouched.

Tests that asserted the old agents now assert the new contract
(no backupAgent in the manifest, extraction rules govern) or
the surviving in-app backup inputs: 2,888 tests across the
eight modules pass. Merged manifests verified: no backupAgent,
allowBackup with dataExtractionRules intact.

Diff

findfamily/src/main/AndroidManifest.xml
diff --git a/findfamily/src/main/AndroidManifest.xml b/findfamily/src/main/AndroidManifest.xmlindex 7eaaf15112..fa644a4266 100644--- a/findfamily/src/main/AndroidManifest.xml+++ b/findfamily/src/main/AndroidManifest.xml@@ -58,7 +58,6 @@      <application         android:allowBackup="true"-        android:backupAgent=".platform.AppBackupAgent"         android:dataExtractionRules="@xml/data_extraction_rules"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"
findfamily/src/main/java/com/vayunmathur/findfamily/domain/FamilyBackup.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/domain/FamilyBackup.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/domain/FamilyBackup.ktindex 3772eccb37..0ded9aa60c 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/domain/FamilyBackup.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/domain/FamilyBackup.kt@@ -11,12 +11,13 @@ package com.vayunmathur.findfamily.domain  * app version restore with the current code, because the reader derives the  * same names from [dbName]/[datastoreName].  *- * The manual backup covers the same payload as the OS-triggered one- * ([com.vayunmathur.findfamily.platform.AppBackupAgent]): the encrypted Room- * database plus the default DataStore, which holds the stable device identity- * and the E2EE key material. Pre-removal manual backups contained only the- * database entry; such legacy files still restore — the missing DataStore- * entry is simply skipped by the reader.+ * The manual backup covers the encrypted Room database plus the default+ * DataStore, which holds the stable device identity and the E2EE key material.+ * It is a user-triggered export to a user-chosen file only: OS backup no longer+ * carries this payload (no backupAgent is declared, and data_extraction_rules+ * deny cloud backup; D2D carries the database file alone, without the keys).+ * Pre-removal manual backups contained only the database entry; such legacy+ * files still restore — the missing DataStore entry is simply skipped by the reader.  */ object FamilyBackup {     /** Room database name, shared with [com.vayunmathur.findfamily.data.FindFamilyRepository]. */
findfamily/src/main/java/com/vayunmathur/findfamily/platform/AppBackupAgent.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/platform/AppBackupAgent.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/platform/AppBackupAgent.ktdeleted file mode 100644index 6cdc2f10e7..0000000000--- a/findfamily/src/main/java/com/vayunmathur/findfamily/platform/AppBackupAgent.kt+++ /dev/null@@ -1,25 +0,0 @@-package com.vayunmathur.findfamily.platform--import com.vayunmathur.library.room.SqlCipherDbCodec-import com.vayunmathur.library.util.BaseBackupAgent-import com.vayunmathur.library.util.DatabaseHelper-import java.io.File--/** Android backup agent covering the SQLCipher database passphrase and identity DataStore. */-class AppBackupAgent : BaseBackupAgent() {-    override val dbCodec = SqlCipherDbCodec--    override val dbConfigs: List<Pair<String, String>>-        get() {-            val pass = DatabaseHelper(this).getPassphrase()-            return listOf("passwords-db" to pass)-        }--    // Back up the app's DataStore (userid + e2ee keypair live here) so a new-    // device restore keeps a stable identity instead of regenerating one.-    override val datastoreNames: List<String>-        get() = listOf("datastore_default")--    override val extraFiles: List<File>-        get() = emptyList()-}
findfamily/src/test/java/com/vayunmathur/findfamily/service/TilesBootAndChannelsTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/service/TilesBootAndChannelsTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/service/TilesBootAndChannelsTest.ktindex 8ed0ec2df8..28c4c952ec 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/service/TilesBootAndChannelsTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/service/TilesBootAndChannelsTest.kt@@ -7,7 +7,6 @@ import android.content.Intent import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import com.vayunmathur.findfamily.notifications.FindFamilyNotificationChannels-import com.vayunmathur.findfamily.platform.AppBackupAgent import com.vayunmathur.findfamily.platform.BootReceiver import com.vayunmathur.findfamily.platform.LocationServiceController import com.vayunmathur.library.util.DataStoreUtils@@ -26,8 +25,8 @@ import kotlin.test.assertNotNull import kotlin.test.assertTrue  /**- * Quick Settings tiles, boot receiver, notification channels and the backup agent- * in the sandbox: tile clicks flip the persisted switches, the boot receiver+ * Quick Settings tiles, boot receiver, notification channels and the no-agent+ * backup contract in the sandbox: tile clicks flip the persisted switches, the boot receiver  * ignores unrelated broadcasts and unpermitted boots, and channels are created  * per person with the documented ids.  */@@ -140,15 +139,12 @@ class TilesBootAndChannelsTest {         )     } -    @Test fun backupAgentDeclaresDbAndDatastore() {-        com.vayunmathur.findfamily.platform.FakeAndroidKeyStore.install()-        // Production stores the SQLCipher passphrase at first database setup;-        // the backup agent only ever reads it back.-        com.vayunmathur.library.util.DatabaseHelper(ctx).storePassphrase("backup-test-pass")-        val agent = Robolectric.buildBackupAgent(AppBackupAgent::class.java).create().get()-        assertEquals(listOf("datastore_default"), agent.datastoreNames)-        assertTrue(agent.extraFiles.isEmpty())-        assertEquals(listOf("passwords-db" to "backup-test-pass"), agent.dbConfigs)+    @Test fun manifestHasNoBackupAgentAndExtractionRulesGovern() {+        // The legacy backup agent was removed (it bypassed the deny-all cloud+        // rules); data_extraction_rules.xml now governs both channels.+        val info = app.packageManager.getApplicationInfo(app.packageName, 0)+        assertEquals(null, info.backupAgentName)+        assertTrue(app.resources.getIdentifier("data_extraction_rules", "xml", app.packageName) != 0)         assertNotNull(DataStoreUtils.getInstance(ctx))     } }
flashcards/src/main/AndroidManifest.xml
diff --git a/flashcards/src/main/AndroidManifest.xml b/flashcards/src/main/AndroidManifest.xmlindex 21ba7f790b..93cce1a381 100644--- a/flashcards/src/main/AndroidManifest.xml+++ b/flashcards/src/main/AndroidManifest.xml@@ -14,7 +14,6 @@      <application         android:allowBackup="true"-        android:backupAgent=".platform.AppBackupAgent"         android:dataExtractionRules="@xml/data_extraction_rules"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"
flashcards/src/main/java/com/vayunmathur/flashcards/data/FlashcardsDatabase.kt
diff --git a/flashcards/src/main/java/com/vayunmathur/flashcards/data/FlashcardsDatabase.kt b/flashcards/src/main/java/com/vayunmathur/flashcards/data/FlashcardsDatabase.ktindex 72f96bacce..c713aee167 100644--- a/flashcards/src/main/java/com/vayunmathur/flashcards/data/FlashcardsDatabase.kt+++ b/flashcards/src/main/java/com/vayunmathur/flashcards/data/FlashcardsDatabase.kt@@ -16,7 +16,7 @@ import kotlinx.coroutines.flow.Flow  const val DB_NAME = "flashcards-db" -/** Backup config shared by [AppBackupAgent] and the in-app backup buttons. */+/** Backup config for the in-app backup buttons. */ fun flashcardsDbConfigs(context: Context): List<Pair<String, String>> =     listOf(DB_NAME to DatabaseHelper(context).getPassphrase()) 
flashcards/src/main/java/com/vayunmathur/flashcards/platform/AppBackupAgent.kt
diff --git a/flashcards/src/main/java/com/vayunmathur/flashcards/platform/AppBackupAgent.kt b/flashcards/src/main/java/com/vayunmathur/flashcards/platform/AppBackupAgent.ktdeleted file mode 100644index 2da35a7b11..0000000000--- a/flashcards/src/main/java/com/vayunmathur/flashcards/platform/AppBackupAgent.kt+++ /dev/null@@ -1,22 +0,0 @@-package com.vayunmathur.flashcards.platform--import com.vayunmathur.library.room.SqlCipherDbCodec-import com.vayunmathur.library.util.BaseBackupAgent-import com.vayunmathur.flashcards.data.flashcardsDbConfigs-import java.io.File--/** Backup agent that backs up the encrypted flashcards database and its DataStore settings. */-class AppBackupAgent : BaseBackupAgent() {-    override val dbCodec = SqlCipherDbCodec--    override val dbConfigs: List<Pair<String, String>>-        get() = flashcardsDbConfigs(this)--    // The shared DataStoreUtils file, holding app settings. res/xml/data_extraction_rules.xml-    // already lists it; the agent has to repeat it because it, not the XML, drives cloud backup.-    override val datastoreNames: List<String>-        get() = listOf("datastore_default")--    override val extraFiles: List<File>-        get() = emptyList()-}
flashcards/src/test/java/com/vayunmathur/flashcards/util/FlashcardsMiscTest.kt
diff --git a/flashcards/src/test/java/com/vayunmathur/flashcards/util/FlashcardsMiscTest.kt b/flashcards/src/test/java/com/vayunmathur/flashcards/util/FlashcardsMiscTest.ktindex deea374d9b..a234479ba8 100644--- a/flashcards/src/test/java/com/vayunmathur/flashcards/util/FlashcardsMiscTest.kt+++ b/flashcards/src/test/java/com/vayunmathur/flashcards/util/FlashcardsMiscTest.kt@@ -1,5 +1,4 @@ package com.vayunmathur.flashcards.util-import com.vayunmathur.flashcards.platform.AppBackupAgent import com.vayunmathur.flashcards.platform.MediaStore import com.vayunmathur.flashcards.platform.ReviewReminder import com.vayunmathur.flashcards.platform.ReviewReminderWorker@@ -63,11 +62,12 @@ class FlashcardsMiscTest {     }      @Test-    fun backupAgentConfig() {-        val agent = AppBackupAgent()-        assertEquals(listOf("datastore_default"), agent.datastoreNames)-        assertTrue(agent.extraFiles.isEmpty())-        assertEquals(com.vayunmathur.library.room.SqlCipherDbCodec, agent.dbCodec)+    fun manifestHasNoBackupAgentAndExtractionRulesGovern() {+        // The legacy backup agent was removed; data_extraction_rules.xml now+        // governs both cloud backup and device transfer.+        val info = ctx.packageManager.getApplicationInfo(ctx.packageName, 0)+        assertEquals(null, info.backupAgentName)+        assertTrue(ctx.resources.getIdentifier("data_extraction_rules", "xml", ctx.packageName) != 0)     }      @Test
games/hub/src/main/AndroidManifest.xml
diff --git a/games/hub/src/main/AndroidManifest.xml b/games/hub/src/main/AndroidManifest.xmlindex 6415415a9a..5865ae028d 100644--- a/games/hub/src/main/AndroidManifest.xml+++ b/games/hub/src/main/AndroidManifest.xml@@ -48,7 +48,6 @@      <application         android:allowBackup="true"-        android:backupAgent=".util.AppBackupAgent"         android:dataExtractionRules="@xml/data_extraction_rules"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"
games/hub/src/main/java/com/vayunmathur/games/hub/network/PlayOnTvSession.kt
diff --git a/games/hub/src/main/java/com/vayunmathur/games/hub/network/PlayOnTvSession.kt b/games/hub/src/main/java/com/vayunmathur/games/hub/network/PlayOnTvSession.ktindex 86cfe27a80..bb95e80f86 100644--- a/games/hub/src/main/java/com/vayunmathur/games/hub/network/PlayOnTvSession.kt+++ b/games/hub/src/main/java/com/vayunmathur/games/hub/network/PlayOnTvSession.kt@@ -46,8 +46,7 @@ private val Context.controllerStore by preferencesDataStore(name = "hub_controll  * duration alongside.  *  * Secrets follow the same rule as the kart TV host: the per-TV device keys live in their own- * `hub_controller` DataStore file, NOT in the shared `datastore_default` that [com.vayunmathur.games.hub.util.AppBackupAgent]- * ships to cloud. A restored backup must not silently inherit this phone's pairings.+ * `hub_controller` DataStore file, NOT in the shared `datastore_default`. A restored backup must not silently inherit this phone's pairings.  * Sealing to the TV's bundle is plain `Pqc.encryptTo` (the cast `SecretSealing` shape, without  * depending on `:cast:protocol`); the phone holds no long-term PQC identity of its own — the  * session secret is fresh per connection and the device key is the only thing persisted.
games/hub/src/main/java/com/vayunmathur/games/hub/util/AppBackupAgent.kt
diff --git a/games/hub/src/main/java/com/vayunmathur/games/hub/util/AppBackupAgent.kt b/games/hub/src/main/java/com/vayunmathur/games/hub/util/AppBackupAgent.ktdeleted file mode 100644index 178997963d..0000000000--- a/games/hub/src/main/java/com/vayunmathur/games/hub/util/AppBackupAgent.kt+++ /dev/null@@ -1,28 +0,0 @@-package com.vayunmathur.games.hub.util--import com.vayunmathur.games.hub.data.DB_NAME-import com.vayunmathur.library.room.SqlCipherDbCodec-import com.vayunmathur.library.util.BaseBackupAgent-import com.vayunmathur.library.util.DatabaseHelper-import java.io.File--/** App Backup Agent: a base backup agent implementation for app backup agent. */-class AppBackupAgent : BaseBackupAgent() {-    override val dbCodec = SqlCipherDbCodec--    override val dbConfigs: List<Pair<String, String>>-        get() {-            return try {-                val pass = DatabaseHelper(this).getPassphrase()-                listOf(DB_NAME to pass)-            } catch (_: Exception) {-                emptyList()-            }-        }--    override val datastoreNames: List<String>-        get() = listOf("datastore_default")--    override val extraFiles: List<File>-        get() = emptyList()-}
games/hub/src/main/res/xml/data_extraction_rules.xml
diff --git a/games/hub/src/main/res/xml/data_extraction_rules.xml b/games/hub/src/main/res/xml/data_extraction_rules.xmlindex 5706e46c01..ca686b24eb 100644--- a/games/hub/src/main/res/xml/data_extraction_rules.xml+++ b/games/hub/src/main/res/xml/data_extraction_rules.xml@@ -27,27 +27,15 @@   of the passphrase, which is undecryptable off-device and is regenerated on   first launch anyway. -  SCOPE — READ BEFORE RELYING ON THE <cloud-backup> SECTION BELOW.-  hub declares android:backupAgent=".util.AppBackupAgent" and does NOT set-  android:fullBackupOnly, so Android uses key/value backup for this app and the-  <cloud-backup> section here is NOT consulted. What actually leaves the device-  for cloud is whatever AppBackupAgent lists: dbConfigs (games-hub-db, exported-  by SqlCipherDbCodec) and datastoreNames (datastore_default). The rules below-  govern <device-transfer>, and they are the correct control if the backupAgent-  is ever removed.--  Privacy note, corrected: hub's DB is a cross-app behavioural profile (what the-  user plays and for how long, across eight apps). An earlier version of this-  comment claimed the exclusion below keeps that profile off Google's servers.-  That is WRONG. Because this app is key/value, the agent ships games-hub-db to-  cloud regardless of this file — and SqlCipherDbCodec.exportDatabase()-  sqlcipher_export()s it to PLAINTEXT inside the backup payload first. If that-  profile should not leave the device, the fix is to drop DB_NAME from-  AppBackupAgent.dbConfigs, not to edit this XML.+  These rules govern both cloud backup and device transfer. The legacy+  android:backupAgent was removed: it shipped games-hub-db — a cross-app+  behavioural profile (what the user plays and for how long, across eight apps) —+  to cloud as PLAINTEXT via SqlCipherDbCodec.exportDatabase() (sqlcipher_export+  with KEY ''), regardless of the exclusions below. With no agent declared, the+  hub DB stays off both channels, as excluded below. --> <data-extraction-rules>-    <!-- Not consulted while android:backupAgent is declared; see SCOPE above.-         Kept correct so behaviour is right if the agent is ever removed. -->+    <!-- Effective for cloud backup now that no backupAgent is declared. -->     <cloud-backup>         <include domain="root" path="." />         <include domain="file" path="." />
notes/src/main/AndroidManifest.xml
diff --git a/notes/src/main/AndroidManifest.xml b/notes/src/main/AndroidManifest.xmlindex 86e10cd797..c74ece569c 100644--- a/notes/src/main/AndroidManifest.xml+++ b/notes/src/main/AndroidManifest.xml@@ -27,7 +27,6 @@      <application         android:allowBackup="true"-        android:backupAgent=".platform.AppBackupAgent"         android:dataExtractionRules="@xml/data_extraction_rules"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"
notes/src/main/java/com/vayunmathur/notes/data/NoteDatabase.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/data/NoteDatabase.kt b/notes/src/main/java/com/vayunmathur/notes/data/NoteDatabase.ktindex 57df2c622f..cc68ca37d3 100644--- a/notes/src/main/java/com/vayunmathur/notes/data/NoteDatabase.kt+++ b/notes/src/main/java/com/vayunmathur/notes/data/NoteDatabase.kt@@ -16,7 +16,7 @@ import kotlinx.coroutines.flow.Flow  const val DB_NAME = "notes-db" -/** Backup config shared by [AppBackupAgent] and the in-app backup buttons. */+/** Backup config for the in-app backup buttons. */ fun noteDbConfigs(context: Context): List<Pair<String, String>> =     listOf(DB_NAME to DatabaseHelper(context).getPassphrase()) 
notes/src/main/java/com/vayunmathur/notes/platform/AppBackupAgent.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/platform/AppBackupAgent.kt b/notes/src/main/java/com/vayunmathur/notes/platform/AppBackupAgent.ktdeleted file mode 100644index a69cbfe924..0000000000--- a/notes/src/main/java/com/vayunmathur/notes/platform/AppBackupAgent.kt+++ /dev/null@@ -1,17 +0,0 @@-package com.vayunmathur.notes.platform--import com.vayunmathur.library.room.SqlCipherDbCodec-import com.vayunmathur.library.util.BaseBackupAgent-import com.vayunmathur.notes.data.noteDbConfigs-import java.io.File--/** Backup agent covering the notes database and note images. */-class AppBackupAgent : BaseBackupAgent() {-    override val dbCodec = SqlCipherDbCodec--    override val dbConfigs: List<Pair<String, String>>-        get() = noteDbConfigs(this)--    override val extraFiles: List<File>-        get() = NoteImageStore.backupFiles(this)-}
notes/src/test/java/com/vayunmathur/notes/IntentsAndRouteTest.kt
diff --git a/notes/src/test/java/com/vayunmathur/notes/IntentsAndRouteTest.kt b/notes/src/test/java/com/vayunmathur/notes/IntentsAndRouteTest.ktindex c0f37f8dfc..f10f62536c 100644--- a/notes/src/test/java/com/vayunmathur/notes/IntentsAndRouteTest.kt+++ b/notes/src/test/java/com/vayunmathur/notes/IntentsAndRouteTest.kt@@ -97,23 +97,17 @@ class IntentsAndRouteTest {         assertNotNull(Route.InkEditor.serializer())     } -    @Test fun backupAgentProperties() {-        val agent = com.vayunmathur.notes.platform.AppBackupAgent()-        assertNotNull(agent.dbCodec)-        // The agent getters use the agent itself as the Context, and an-        // unattached agent has no base context, so exercise the delegates-        // directly with the app context: the note_images dir must travel-        // with the database backup, or a restore renders embedded images-        // blank.+    @Test fun inAppBackupInputsCoverDbAndImages() {+        // Cloud/device backup is governed by data_extraction_rules.xml (no+        // backupAgent). These delegates now feed only the user-triggered+        // in-app backup buttons: the note_images dir must travel with the+        // database backup, or a restore renders embedded images blank.         assertEquals(             listOf(java.io.File(context.filesDir, "note_images").absolutePath),             com.vayunmathur.notes.platform.NoteImageStore.backupFiles(context).map { it.absolutePath },         )         FakeAndroidKeyStore.install()         runCatching { com.vayunmathur.library.util.DatabaseHelper(context).storePassphrase("test-passphrase") }-        // AppBackupAgent.dbConfigs delegates to noteDbConfigs with the agent as-        // context; an unattached agent has no base context, so exercise the-        // delegate directly with the app context.         val configs = com.vayunmathur.notes.data.noteDbConfigs(context)         assertEquals(1, configs.size)         assertEquals(com.vayunmathur.notes.data.DB_NAME, configs.single().first)
notes/src/test/java/com/vayunmathur/notes/MainActivityTest.kt
diff --git a/notes/src/test/java/com/vayunmathur/notes/MainActivityTest.kt b/notes/src/test/java/com/vayunmathur/notes/MainActivityTest.ktindex d0b4341956..c8fa64450b 100644--- a/notes/src/test/java/com/vayunmathur/notes/MainActivityTest.kt+++ b/notes/src/test/java/com/vayunmathur/notes/MainActivityTest.kt@@ -39,15 +39,12 @@ class MainActivityTest {         controller.pause().stop().destroy()     } -    @Test fun manifestBackupAgentClassExists() {+    @Test fun manifestHasNoBackupAgentAndExtractionRulesGovern() {+        // The legacy backup agent was removed; data_extraction_rules.xml now+        // governs both cloud backup and device transfer.         val info = app.packageManager.getApplicationInfo(app.packageName, 0)-        val agentName = info.backupAgentName-        assertEquals("com.vayunmathur.notes.platform.AppBackupAgent", agentName)-        // The named class must actually load, or Android backup silently never runs.-        assertEquals(-            com.vayunmathur.notes.platform.AppBackupAgent::class.java,-            Class.forName(agentName),-        )+        assertEquals(null, info.backupAgentName)+        assertTrue(app.resources.getIdentifier("data_extraction_rules", "xml", app.packageName) != 0)     }      @Test fun onNewIntentWithDataUriDoesNotCrash() {
notes/src/test/java/com/vayunmathur/notes/platform/NotesShareCoverageTest.kt
diff --git a/notes/src/test/java/com/vayunmathur/notes/platform/NotesShareCoverageTest.kt b/notes/src/test/java/com/vayunmathur/notes/platform/NotesShareCoverageTest.ktindex 531fa4d93b..1764abfc1b 100644--- a/notes/src/test/java/com/vayunmathur/notes/platform/NotesShareCoverageTest.kt+++ b/notes/src/test/java/com/vayunmathur/notes/platform/NotesShareCoverageTest.kt@@ -101,19 +101,16 @@ class NotesShareCoverageTest {         assertEquals("\n", exportNoteMarkdown(app, Note(title = "Empty", content = "")))     } -    @Test fun backupAgentExposesDbConfigsAndImageFiles() {-        val agent = AppBackupAgent()-        // BackupAgent.attachBaseContext is hidden; Robolectric allows the-        // reflective attach so the agent getters can run as Android runs them.-        val attach = android.content.ContextWrapper::class.java-            .getDeclaredMethod("attachBaseContext", android.content.Context::class.java)-            .apply { isAccessible = true }-        attach.invoke(agent, app)-        assertEquals(com.vayunmathur.notes.data.DB_NAME, agent.dbConfigs.single().first)-        assertTrue(agent.dbConfigs.single().second.isNotEmpty())+    @Test fun inAppBackupInputsCoverDbAndImageFiles() {+        // No backupAgent any more (extraction rules govern cloud/device+        // backup); noteDbConfigs + NoteImageStore.backupFiles are the inputs+        // to the user-triggered in-app backup buttons.+        val configs = com.vayunmathur.notes.data.noteDbConfigs(app)+        assertEquals(com.vayunmathur.notes.data.DB_NAME, configs.single().first)+        assertTrue(configs.single().second.isNotEmpty())         assertEquals(             listOf(java.io.File(app.filesDir, "note_images").absolutePath),-            agent.extraFiles.map { it.absolutePath },+            NoteImageStore.backupFiles(app).map { it.absolutePath },         )     } 
openassistant/src/main/AndroidManifest.xml
diff --git a/openassistant/src/main/AndroidManifest.xml b/openassistant/src/main/AndroidManifest.xmlindex 9a96cd0837..b8de7d2b76 100644--- a/openassistant/src/main/AndroidManifest.xml+++ b/openassistant/src/main/AndroidManifest.xml@@ -60,7 +60,6 @@      <application         android:allowBackup="true"-        android:backupAgent=".platform.AppBackupAgent"         android:dataExtractionRules="@xml/data_extraction_rules"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"
openassistant/src/main/java/com/vayunmathur/openassistant/platform/AppBackupAgent.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AppBackupAgent.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AppBackupAgent.ktdeleted file mode 100644index 3e25cc2c18..0000000000--- a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AppBackupAgent.kt+++ /dev/null@@ -1,20 +0,0 @@-package com.vayunmathur.openassistant.platform--import com.vayunmathur.library.room.SqlCipherDbCodec-import com.vayunmathur.library.util.BaseBackupAgent-import com.vayunmathur.library.util.DatabaseHelper-import java.io.File--/** App Backup Agent: a base backup agent implementation for app backup agent. */-class AppBackupAgent : BaseBackupAgent() {-    override val dbCodec = SqlCipherDbCodec--    override val dbConfigs: List<Pair<String, String>>-        get() = runCatching {-            val helper = DatabaseHelper(this)-            if (helper.isKeyGenerated()) listOf("passwords-db" to helper.getPassphrase())-            else emptyList()-        }.getOrDefault(emptyList())--    override val extraFiles: List<File> get() = emptyList()-}
openassistant/src/main/res/xml/data_extraction_rules.xml
diff --git a/openassistant/src/main/res/xml/data_extraction_rules.xml b/openassistant/src/main/res/xml/data_extraction_rules.xmlindex 873559d053..13906e26ab 100644--- a/openassistant/src/main/res/xml/data_extraction_rules.xml+++ b/openassistant/src/main/res/xml/data_extraction_rules.xml@@ -17,16 +17,12 @@      No API keys or remote credentials were found - inference runs on-device - so the only      secret-grade material is the keystore passphrase. -     SCOPE: openassistant declares android:backupAgent=".util.AppBackupAgent" and does NOT set-     android:fullBackupOnly, so cloud backup runs through the agent and the <cloud-backup>-     section below is NOT consulted. What actually reaches the cloud is the agent's-     dbConfigs = ["passwords-db"], i.e. the conversation history, exported decrypted by-     SqlCipherDbCodec. That is deliberate: losing a new phone's whole assistant history is-     worse than the exposure, and the history is the only thing here that is not-     regenerable. The <cloud-backup> denials below are kept as the policy that applies if-     the agent is ever removed and Auto Backup takes over: the models are gigabytes and-     re-downloadable, and the download markers are meaningless without them.-     <device-transfer> IS governed here and carries the history and nothing else. -->+     These rules now govern cloud backup too: the legacy android:backupAgent was removed.+     It exported the conversation history DECRYPTED via SqlCipherDbCodec, bypassing the+     <cloud-backup> denials below. (Its "passwords-db" name was the shared RoomRepository+     default file name, not a distinct passwords database.) Cloud stays deny-all: the+     models are gigabytes and re-downloadable, and the download markers are meaningless+     without them. <device-transfer> carries the history and nothing else. --> <data-extraction-rules>     <cloud-backup>         <exclude domain="root" path="." />
openassistant/src/test/java/com/vayunmathur/openassistant/util/CopyUriAndRouteTest.kt
diff --git a/openassistant/src/test/java/com/vayunmathur/openassistant/util/CopyUriAndRouteTest.kt b/openassistant/src/test/java/com/vayunmathur/openassistant/util/CopyUriAndRouteTest.ktindex e3cccc0377..67da5020d7 100644--- a/openassistant/src/test/java/com/vayunmathur/openassistant/util/CopyUriAndRouteTest.kt+++ b/openassistant/src/test/java/com/vayunmathur/openassistant/util/CopyUriAndRouteTest.kt@@ -2,18 +2,15 @@ package com.vayunmathur.openassistant.util  import android.net.Uri import androidx.test.core.app.ApplicationProvider-import com.vayunmathur.library.room.SqlCipherDbCodec import com.vayunmathur.openassistant.Route-import com.vayunmathur.openassistant.platform.FakeAndroidKeyStore import java.io.File import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNull import kotlin.test.assertTrue import com.vayunmathur.openassistant.platform.copyUriToFile-import com.vayunmathur.openassistant.platform.AppBackupAgent -/** copyUriToFile against the Robolectric content resolver, routes, backup agent config. */+/** copyUriToFile against the Robolectric content resolver, routes, backup contract. */ @org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class) class CopyUriAndRouteTest { @@ -48,12 +45,12 @@ class CopyUriAndRouteTest {         assertTrue(Route.ConversationPage(1L) != Route.ConversationPage(2L))     } -    @Test fun backupAgentConfigWithoutKey() {-        FakeAndroidKeyStore.install()-        val agent = AppBackupAgent()-        assertEquals(SqlCipherDbCodec, agent.dbCodec)-        assertEquals(emptyList(), agent.extraFiles)-        // No passphrase key has been generated in this environment.-        assertEquals(emptyList(), agent.dbConfigs)+    @Test fun manifestHasNoBackupAgentAndExtractionRulesGovern() {+        // The legacy backup agent was removed (it exported conversation history+        // decrypted, bypassing the deny-all cloud rules); data_extraction_+        // rules.xml now governs both cloud backup and device transfer.+        val info = ctx.packageManager.getApplicationInfo(ctx.packageName, 0)+        assertEquals(null, info.backupAgentName)+        assertTrue(ctx.resources.getIdentifier("data_extraction_rules", "xml", ctx.packageName) != 0)     } }
passwords/src/main/AndroidManifest.xml
diff --git a/passwords/src/main/AndroidManifest.xml b/passwords/src/main/AndroidManifest.xmlindex b76608008f..b7a3bfe799 100644--- a/passwords/src/main/AndroidManifest.xml+++ b/passwords/src/main/AndroidManifest.xml@@ -27,7 +27,6 @@      <application         android:allowBackup="true"-        android:backupAgent=".platform.AppBackupAgent"         android:dataExtractionRules="@xml/data_extraction_rules"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"
passwords/src/main/java/com/vayunmathur/passwords/platform/AppBackupAgent.kt
diff --git a/passwords/src/main/java/com/vayunmathur/passwords/platform/AppBackupAgent.kt b/passwords/src/main/java/com/vayunmathur/passwords/platform/AppBackupAgent.ktdeleted file mode 100644index 88c646e161..0000000000--- a/passwords/src/main/java/com/vayunmathur/passwords/platform/AppBackupAgent.kt+++ /dev/null@@ -1,20 +0,0 @@-package com.vayunmathur.passwords.platform--import com.vayunmathur.library.room.SqlCipherDbCodec-import com.vayunmathur.library.util.BaseBackupAgent-import com.vayunmathur.library.util.DatabaseHelper-import java.io.File--/** App Backup Agent: a base backup agent implementation for app backup agent. */-class AppBackupAgent : BaseBackupAgent() {-    override val dbCodec = SqlCipherDbCodec--    override val dbConfigs: List<Pair<String, String>>-        get() {-            val pass = DatabaseHelper(this).getPassphrase()-            return listOf("passwords-db" to pass)-        }--    override val extraFiles: List<File>-        get() = emptyList()-}
passwords/src/main/java/com/vayunmathur/passwords/sync/KdbxSyncEngine.kt
diff --git a/passwords/src/main/java/com/vayunmathur/passwords/sync/KdbxSyncEngine.kt b/passwords/src/main/java/com/vayunmathur/passwords/sync/KdbxSyncEngine.ktindex 17220e83ad..12db377b38 100644--- a/passwords/src/main/java/com/vayunmathur/passwords/sync/KdbxSyncEngine.kt+++ b/passwords/src/main/java/com/vayunmathur/passwords/sync/KdbxSyncEngine.kt@@ -730,7 +730,7 @@ suspend fun runKdbxSync(context: Context, db: PasswordDatabase): KdbxSyncResult         KdbxSyncEngine(db, NativeKdbxCodec).sync(             document = SafKdbxDocument(context, uri.toUri()),             vaultPassword = passwordHelper.getPassphrase(),-            onBackup = { previous -> File(context.filesDir, BACKUP_FILE_NAME).writeBytes(previous) },+            onBackup = { previous -> writeBytesAtomically(File(context.filesDir, BACKUP_FILE_NAME), previous) },         )     } @@ -774,7 +774,7 @@ suspend fun runKdbxSync(context: Context, repository: PasswordRepository): KdbxS         KdbxSyncEngine(repository, NativeKdbxCodec).sync(             document = SafKdbxDocument(context, uri.toUri()),             vaultPassword = passwordHelper.getPassphrase(),-            onBackup = { previous -> File(context.filesDir, BACKUP_FILE_NAME).writeBytes(previous) },+            onBackup = { previous -> writeBytesAtomically(File(context.filesDir, BACKUP_FILE_NAME), previous) },         )     } @@ -794,3 +794,25 @@ suspend fun runKdbxSync(context: Context, repository: PasswordRepository): KdbxS }  private const val BACKUP_FILE_NAME = "kdbx-sync-backup.kdbx"++/**+ * Write [bytes] to [target] via tmp file + rename, so a crash mid-backup never leaves a+ * torn KDBX backup in place of the last good one. Same shape as `AndroidFileBlobStore.put`+ * (library/everysync-core): temp in the same directory, rename, delete+rename fallback+ * where rename cannot replace, temp always cleaned up. (No `FileFiles.writeBytes` exists+ * in library/ — verified, it does not do this.)+ */+private fun writeBytesAtomically(target: File, bytes: ByteArray) {+    val dir = target.parentFile+    if (dir != null) dir.mkdirs()+    val tmp = File.createTempFile("kdbx-backup-", ".tmp", dir)+    try {+        tmp.writeBytes(bytes)+        if (!tmp.renameTo(target)) {+            target.delete()+            tmp.renameTo(target)+        }+    } finally {+        if (tmp.exists()) tmp.delete()+    }+}
passwords/src/main/res/xml/data_extraction_rules.xml
diff --git a/passwords/src/main/res/xml/data_extraction_rules.xml b/passwords/src/main/res/xml/data_extraction_rules.xmlindex fe8051f53e..30e11c6b69 100644--- a/passwords/src/main/res/xml/data_extraction_rules.xml+++ b/passwords/src/main/res/xml/data_extraction_rules.xml@@ -1,20 +1,11 @@ <?xml version="1.0" encoding="utf-8"?> <!---  SCOPE LIMIT — READ BEFORE TRUSTING THE <cloud-backup> SECTION BELOW.-  This app declares android:backupAgent=".util.AppBackupAgent" and does not set-  android:fullBackupOnly="true". AppBackupAgent extends BaseBackupAgent, which overrides-  onBackup()/onRestore() (library/src/main/java/com/vayunmathur/library/util/BackupAgent.kt:21,48),-  so cloud backup for this app runs through the KEY/VALUE transport and the <cloud-backup>-  section here is NOT consulted. What actually leaves the device is whatever the agent puts-  in its stream: today that is dbConfigs = listOf("passwords-db" to passphrase), which-  BackupHelper exports DECRYPTED via SqlCipherDbCodec. That is a plaintext vault going to-  Google, and no XML in this file can stop it. Fixing it requires a code change to the-  agent, or android:fullBackupOnly="true" to route cloud through these rules instead.--  The <device-transfer> section below IS effective: BaseBackupAgent does not override-  onFullBackup(), so the default BackupAgent.onFullBackup() runs for D2D and honours these-  rules. The <cloud-backup> section is kept deliberately, as correct-by-default policy for-  the day the agent is removed or fullBackupOnly is set.+  These rules govern both cloud backup and device transfer. This app declares no+  android:backupAgent (the legacy key/value agent was removed): it exported the vault+  DECRYPTED via SqlCipherDbCodec (sqlcipher_export with KEY ''), shipping a plaintext+  vault to Google and bypassing this file entirely. With no agent declared, Auto+  Backup and D2D both honour the sections below. The app's own KDBX sync and its+  in-app BackupButtons flow are separate user-triggered paths and are unaffected.    Deny-all. Overrides the permissive include-everything default in the shared :library module. 
passwords/src/test/java/com/vayunmathur/passwords/platform/ServicesExtraTest.kt
diff --git a/passwords/src/test/java/com/vayunmathur/passwords/platform/ServicesExtraTest.kt b/passwords/src/test/java/com/vayunmathur/passwords/platform/ServicesExtraTest.ktindex 8f128e26ce..f574279e93 100644--- a/passwords/src/test/java/com/vayunmathur/passwords/platform/ServicesExtraTest.kt+++ b/passwords/src/test/java/com/vayunmathur/passwords/platform/ServicesExtraTest.kt@@ -129,18 +129,15 @@ class ServicesExtraTest {         assertEquals("X-caBLE-Routing-ID", CableTunnel.ROUTING_ID_HEADER)     } -    // ---- AppBackupAgent ------    @Test fun backupAgentConfig() {-        // dbConfigs decrypts the stored vault passphrase; without one it is-        // expected to fail, so store one first like an unlocked vault would.-        DatabaseHelper(app).storePassphrase("backup-pw")-        val agent = Robolectric.buildBackupAgent(-            com.vayunmathur.passwords.platform.AppBackupAgent::class.java,-        ).create().get()-        assertEquals(listOf("passwords-db" to "backup-pw"), agent.dbConfigs)-        assertTrue(agent.extraFiles.isEmpty())-        assertNotNull(agent.dbCodec)+    // ---- Backup contract (no legacy agent) ----++    @Test fun manifestHasNoBackupAgentAndExtractionRulesGovern() {+        // The legacy backup agent was removed: it exported the vault decrypted,+        // bypassing data_extraction_rules.xml. Cloud/device backup is now+        // governed solely by those (deny-all) extraction rules.+        val info = app.packageManager.getApplicationInfo(app.packageName, 0)+        assertEquals(null, info.backupAgentName)+        assertTrue(app.resources.getIdentifier("data_extraction_rules", "xml", app.packageName) != 0)     }      @Test fun credentialServiceCreateCustomCredentialReturnsEmptyResponse() {
photos/src/main/AndroidManifest.xml
diff --git a/photos/src/main/AndroidManifest.xml b/photos/src/main/AndroidManifest.xmlindex 1f85ac91fa..5ddef92810 100644--- a/photos/src/main/AndroidManifest.xml+++ b/photos/src/main/AndroidManifest.xml@@ -30,7 +30,6 @@     <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />     <application         android:allowBackup="true"-        android:backupAgent=".platform.AppBackupAgent"         android:dataExtractionRules="@xml/data_extraction_rules"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"
photos/src/main/java/com/vayunmathur/photos/platform/AppBackupAgent.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/platform/AppBackupAgent.kt b/photos/src/main/java/com/vayunmathur/photos/platform/AppBackupAgent.ktdeleted file mode 100644index 5c837a9ee5..0000000000--- a/photos/src/main/java/com/vayunmathur/photos/platform/AppBackupAgent.kt+++ /dev/null@@ -1,26 +0,0 @@-package com.vayunmathur.photos.platform--import com.vayunmathur.library.room.SqlCipherDbCodec-import com.vayunmathur.library.util.BaseBackupAgent-import com.vayunmathur.library.util.DatabaseHelper-import java.io.File--/** App Backup Agent: a base backup agent implementation for app backup agent. */-class AppBackupAgent : BaseBackupAgent() {-    override val dbCodec = SqlCipherDbCodec--    override val dbConfigs: List<Pair<String, String>>-        get() {-            val pass = DatabaseHelper(this).getPassphrase()-            return listOf("vault-db" to pass)-        }--    // The shared DataStoreUtils file, holding the grid column count and model-version markers.-    // res/xml/data_extraction_rules.xml already lists it; the agent has to repeat it because it,-    // not the XML, drives cloud backup.-    override val datastoreNames: List<String>-        get() = listOf("datastore_default")--    override val extraFiles: List<File>-        get() = listOf(File(filesDir, "secure_vault"))-}
photos/src/main/java/com/vayunmathur/photos/platform/SyncWorker.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/platform/SyncWorker.kt b/photos/src/main/java/com/vayunmathur/photos/platform/SyncWorker.ktindex 34a84e5f8b..72011f46d6 100644--- a/photos/src/main/java/com/vayunmathur/photos/platform/SyncWorker.kt+++ b/photos/src/main/java/com/vayunmathur/photos/platform/SyncWorker.kt@@ -290,9 +290,6 @@ private const val MILLIS_PER_SECOND = 1000L /** SQLite bind-variable ceiling; deletions and favourite writes are chunked under it. */ private const val DELETE_ID_CHUNK_SIZE = 900 -/** OCR preview length in the worker log line. */-private const val OCR_LOG_PREVIEW_CHARS = 50- private fun isPhotoChanged(     existing: Photo?,     date: Long,@@ -650,7 +647,7 @@ suspend fun runOCR(scanRepository: PhotoScanRepository, context: Context) = coro                 boxes = result?.takeIf { it.boxes.isNotEmpty() }?.toJson(),             )             if (pendingResults.size >= INDEX_FLUSH_EVERY) flush()-            Log.status("OCRWorker", "OCR for ${photo.id}: ${text?.take(OCR_LOG_PREVIEW_CHARS)?.replace("\n", " ")}")+            Log.status("OCRWorker", "OCR for ${photo.id}: ${if (text.isNullOrEmpty()) "no text" else "text found"}")              // Short pause between images keeps sustained CPU/battery use low.             delay(OCR_INTER_ITEM_DELAY_MS)
todo/src/main/AndroidManifest.xml
diff --git a/todo/src/main/AndroidManifest.xml b/todo/src/main/AndroidManifest.xmlindex e12c398852..25f7d1dc28 100644--- a/todo/src/main/AndroidManifest.xml+++ b/todo/src/main/AndroidManifest.xml@@ -45,7 +45,6 @@     <application         android:name=".TodoApplication"         android:allowBackup="true"-        android:backupAgent=".platform.AppBackupAgent"         android:dataExtractionRules="@xml/data_extraction_rules"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"
todo/src/main/java/com/vayunmathur/todo/platform/AppBackupAgent.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/platform/AppBackupAgent.kt b/todo/src/main/java/com/vayunmathur/todo/platform/AppBackupAgent.ktdeleted file mode 100644index 4329d76370..0000000000--- a/todo/src/main/java/com/vayunmathur/todo/platform/AppBackupAgent.kt+++ /dev/null@@ -1,17 +0,0 @@-package com.vayunmathur.todo.platform--import com.vayunmathur.library.room.SqlCipherDbCodec-import com.vayunmathur.library.util.BaseBackupAgent-import com.vayunmathur.todo.data.todoDbConfigs-import java.io.File--/** Android backup agent that backs up the encrypted todo database with the shared database configs. */-class AppBackupAgent : BaseBackupAgent() {-    override val dbCodec = SqlCipherDbCodec--    override val dbConfigs: List<Pair<String, String>>-        get() = todoDbConfigs(this)--    override val extraFiles: List<File>-        get() = emptyList()-}