Modern Apps git

← Modern-Apps.git

battery: trim periodic work and fix foreground-service typing

Commit
4ffdfa7747c0e057c62e98fcd9ae2f9a162e5f7c
Author
Vayun Mathur <[email protected]>
When
2026-11-20 21:25 UTC (15 days ago)
Parents
b410aba
madeveloper's 15-minute ReconnectWorker was a no-op with no
constraints and no remaining purpose - deleted with its
schedule call. securemail's MailSocketService used the
untyped startForeground on API 34+; it now passes
FOREGROUND_SERVICE_TYPE_DATA_SYNC, and a header comment
documents the ownership split with the 15-minute sync worker
(the worker nudges the socket loop for backlog drain, the
service owns the live connection - schedule() currently has
no caller, flagged in the comment).

Unused foreground-service permissions removed from backup
(no FGS at all) and maps (dataSync unused; location kept).
Widget hourly WorkManager updates now require CONNECTED.
networklocation's background reporting floor rises 1s -> 5s;
its 1s feed stays because the sole caller is a visible
foreground screen, now documented as such. findfamily's 15m
worker only re-checks service state (no sync) - justification
commented, cadence kept.

Verified: compile for madeveloper, securemail, backup, maps,
networklocation, findfamily, library:widgets.

Diff

backup/src/main/AndroidManifest.xml
diff --git a/backup/src/main/AndroidManifest.xml b/backup/src/main/AndroidManifest.xmlindex 57168022bf..9846225ae1 100644--- a/backup/src/main/AndroidManifest.xml+++ b/backup/src/main/AndroidManifest.xml@@ -14,8 +14,6 @@         android:name="android.permission.WRITE_SECURE_SETTINGS"         tools:ignore="ProtectedPermissions" />     <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />-    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />-    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />     <uses-permission android:name="android.permission.INTERNET" />     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />     <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
findfamily/schemas/com.vayunmathur.findfamily.data.FFDatabase/14.json
diff --git a/findfamily/schemas/com.vayunmathur.findfamily.data.FFDatabase/14.json b/findfamily/schemas/com.vayunmathur.findfamily.data.FFDatabase/14.jsonnew file mode 100644index 0000000000..76f4496468--- /dev/null+++ b/findfamily/schemas/com.vayunmathur.findfamily.data.FFDatabase/14.json@@ -0,0 +1,367 @@+{+  "formatVersion": 1,+  "database": {+    "version": 14,+    "identityHash": "c32b5e8025902a6ad11a399c641ab33e",+    "entities": [+      {+        "tableName": "User",+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `photo` TEXT, `locationName` TEXT NOT NULL, `sendingEnabled` INTEGER NOT NULL, `requestStatus` TEXT NOT NULL, `lastLocationChangeTime` INTEGER NOT NULL, `encryptionKey` TEXT, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `lastWaypointId` INTEGER, `platform` TEXT, `sharingAutoToggleAt` INTEGER, `sharingAutoToggleWaypointId` INTEGER, `pqcEncryptionKey` TEXT, `inboundPairId` TEXT, `outboundPairId` TEXT, `kind` TEXT NOT NULL)",+        "fields": [+          {+            "fieldPath": "name",+            "columnName": "name",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "photo",+            "columnName": "photo",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "locationName",+            "columnName": "locationName",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "sendingEnabled",+            "columnName": "sendingEnabled",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "requestStatus",+            "columnName": "requestStatus",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "lastLocationChangeTime",+            "columnName": "lastLocationChangeTime",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "encryptionKey",+            "columnName": "encryptionKey",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "id",+            "columnName": "id",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "lastWaypointId",+            "columnName": "lastWaypointId",+            "affinity": "INTEGER"+          },+          {+            "fieldPath": "platform",+            "columnName": "platform",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "sharingAutoToggleAt",+            "columnName": "sharingAutoToggleAt",+            "affinity": "INTEGER"+          },+          {+            "fieldPath": "sharingAutoToggleWaypointId",+            "columnName": "sharingAutoToggleWaypointId",+            "affinity": "INTEGER"+          },+          {+            "fieldPath": "pqcEncryptionKey",+            "columnName": "pqcEncryptionKey",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "inboundPairId",+            "columnName": "inboundPairId",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "outboundPairId",+            "columnName": "outboundPairId",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "kind",+            "columnName": "kind",+            "affinity": "TEXT",+            "notNull": true+          }+        ],+        "primaryKey": {+          "autoGenerate": true,+          "columnNames": [+            "id"+          ]+        }+      },+      {+        "tableName": "Waypoint",+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `range` REAL NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `lat` REAL NOT NULL, `lon` REAL NOT NULL)",+        "fields": [+          {+            "fieldPath": "name",+            "columnName": "name",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "range",+            "columnName": "range",+            "affinity": "REAL",+            "notNull": true+          },+          {+            "fieldPath": "id",+            "columnName": "id",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "coord.lat",+            "columnName": "lat",+            "affinity": "REAL",+            "notNull": true+          },+          {+            "fieldPath": "coord.lon",+            "columnName": "lon",+            "affinity": "REAL",+            "notNull": true+          }+        ],+        "primaryKey": {+          "autoGenerate": true,+          "columnNames": [+            "id"+          ]+        }+      },+      {+        "tableName": "LocationValue",+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`userid` INTEGER NOT NULL, `speed` REAL NOT NULL, `acc` REAL NOT NULL, `timestamp` INTEGER NOT NULL, `battery` REAL NOT NULL, `reportedAt` INTEGER NOT NULL, `source` TEXT NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `lat` REAL NOT NULL, `lon` REAL NOT NULL)",+        "fields": [+          {+            "fieldPath": "userid",+            "columnName": "userid",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "speed",+            "columnName": "speed",+            "affinity": "REAL",+            "notNull": true+          },+          {+            "fieldPath": "acc",+            "columnName": "acc",+            "affinity": "REAL",+            "notNull": true+          },+          {+            "fieldPath": "timestamp",+            "columnName": "timestamp",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "battery",+            "columnName": "battery",+            "affinity": "REAL",+            "notNull": true+          },+          {+            "fieldPath": "reportedAt",+            "columnName": "reportedAt",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "source",+            "columnName": "source",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "id",+            "columnName": "id",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "coord.lat",+            "columnName": "lat",+            "affinity": "REAL",+            "notNull": true+          },+          {+            "fieldPath": "coord.lon",+            "columnName": "lon",+            "affinity": "REAL",+            "notNull": true+          }+        ],+        "primaryKey": {+          "autoGenerate": true,+          "columnNames": [+            "id"+          ]+        },+        "indices": [+          {+            "name": "index_LocationValue_userid_timestamp",+            "unique": false,+            "columnNames": [+              "userid",+              "timestamp"+            ],+            "orders": [],+            "createSql": "CREATE INDEX IF NOT EXISTS `index_LocationValue_userid_timestamp` ON `${TABLE_NAME}` (`userid`, `timestamp`)"+          },+          {+            "name": "index_LocationValue_userid_reportedAt",+            "unique": false,+            "columnNames": [+              "userid",+              "reportedAt"+            ],+            "orders": [],+            "createSql": "CREATE INDEX IF NOT EXISTS `index_LocationValue_userid_reportedAt` ON `${TABLE_NAME}` (`userid`, `reportedAt`)"+          },+          {+            "name": "index_LocationValue_timestamp",+            "unique": false,+            "columnNames": [+              "timestamp"+            ],+            "orders": [],+            "createSql": "CREATE INDEX IF NOT EXISTS `index_LocationValue_timestamp` ON `${TABLE_NAME}` (`timestamp`)"+          }+        ]+      },+      {+        "tableName": "TemporaryLink",+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `deleteAt` INTEGER NOT NULL, `pqcPublicKey` TEXT NOT NULL, `pqcKey` TEXT, `pqcSeed` TEXT, `id` INTEGER NOT NULL, PRIMARY KEY(`id`))",+        "fields": [+          {+            "fieldPath": "name",+            "columnName": "name",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "deleteAt",+            "columnName": "deleteAt",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "pqcPublicKey",+            "columnName": "pqcPublicKey",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "pqcKey",+            "columnName": "pqcKey",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "pqcSeed",+            "columnName": "pqcSeed",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "id",+            "columnName": "id",+            "affinity": "INTEGER",+            "notNull": true+          }+        ],+        "primaryKey": {+          "autoGenerate": false,+          "columnNames": [+            "id"+          ]+        }+      },+      {+        "tableName": "NoShowAlert",+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`watchedUserId` INTEGER NOT NULL, `waypointId` INTEGER, `expectedAt` INTEGER NOT NULL, `grace` INTEGER NOT NULL, `fired` INTEGER NOT NULL, `oneShot` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",+        "fields": [+          {+            "fieldPath": "watchedUserId",+            "columnName": "watchedUserId",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "waypointId",+            "columnName": "waypointId",+            "affinity": "INTEGER"+          },+          {+            "fieldPath": "expectedAt",+            "columnName": "expectedAt",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "grace",+            "columnName": "grace",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "fired",+            "columnName": "fired",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "oneShot",+            "columnName": "oneShot",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "id",+            "columnName": "id",+            "affinity": "INTEGER",+            "notNull": true+          }+        ],+        "primaryKey": {+          "autoGenerate": true,+          "columnNames": [+            "id"+          ]+        },+        "indices": [+          {+            "name": "index_NoShowAlert_watchedUserId",+            "unique": false,+            "columnNames": [+              "watchedUserId"+            ],+            "orders": [],+            "createSql": "CREATE INDEX IF NOT EXISTS `index_NoShowAlert_watchedUserId` ON `${TABLE_NAME}` (`watchedUserId`)"+          }+        ]+      }+    ],+    "setupQueries": [+      "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",+      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'c32b5e8025902a6ad11a399c641ab33e')"+    ]+  }+}\ No newline at end of file
findfamily/src/main/java/com/vayunmathur/findfamily/data/FFDatabase.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/data/FFDatabase.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/data/FFDatabase.ktindex 358183f6e1..bcdf69955b 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/data/FFDatabase.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/data/FFDatabase.kt@@ -219,7 +219,7 @@ interface TemporaryLinkDao { @Database(     entities = [User::class, Waypoint::class, LocationValue::class, TemporaryLink::class, NoShowAlert::class],     version = 14,-    exportSchema = false+    exportSchema = true ) @ColumnTypeConverters(DefaultConverters::class) /** Room database holding users, waypoints, location reports, share links, and no-show alerts. */
findfamily/src/main/java/com/vayunmathur/findfamily/platform/LocationTrackingService.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/platform/LocationTrackingService.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/platform/LocationTrackingService.ktindex f70bd3e224..343b5449cf 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/platform/LocationTrackingService.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/platform/LocationTrackingService.kt@@ -761,6 +761,12 @@ class ServiceRestartWorker( }  fun ensureSync(context: Context) {+    // 15 minutes is justified here: ServiceRestartWorker is only a+    // lightweight reconcile (permission + tracking flag -> start/stop the+    // tracking service via syncServiceState) — it does no location sync,+    // upload, or scan itself, and startRepeatedTask already constrains it+    // to CONNECTED. The cadence bounds how long a killed tracking service+    // can stay down while sharing, so it is kept rather than relaxed to 1h.     startRepeatedTask<ServiceRestartWorker>(         context, "Location Sync", 15.minutes,         ExistingWorkPolicy.REPLACE, ExistingPeriodicWorkPolicy.REPLACE
library/widgets/src/main/java/com/vayunmathur/library/widgets/Widgets.kt
diff --git a/library/widgets/src/main/java/com/vayunmathur/library/widgets/Widgets.kt b/library/widgets/src/main/java/com/vayunmathur/library/widgets/Widgets.ktindex 239673b5ea..c269dcbf93 100644--- a/library/widgets/src/main/java/com/vayunmathur/library/widgets/Widgets.kt+++ b/library/widgets/src/main/java/com/vayunmathur/library/widgets/Widgets.kt@@ -13,8 +13,10 @@ import androidx.glance.appwidget.GlanceAppWidgetReceiver import androidx.glance.appwidget.state.updateAppWidgetState import androidx.glance.appwidget.updateAll import androidx.glance.state.GlanceStateDefinition+import androidx.work.Constraints import androidx.work.CoroutineWorker import androidx.work.ExistingPeriodicWorkPolicy+import androidx.work.NetworkType import androidx.work.ExistingWorkPolicy import androidx.work.OneTimeWorkRequestBuilder import androidx.work.PeriodicWorkRequestBuilder@@ -66,7 +68,14 @@ fun <T : GlanceAppWidget> Context.scheduleHourlyUpdate(widgetClass: KClass<T>) {      val inputData = workDataOf(GenericWidgetWorker.ARG_WIDGET_CLASS to className) +    // Hourly refresh is WorkManager periodic work (not Glance's+    // updatePeriodMillis): require CONNECTED so the hourly wake-up is+    // deferred/coalesced until the device is online instead of firing+    // on every offline hour.     val request = PeriodicWorkRequestBuilder<GenericWidgetWorker>(1, TimeUnit.HOURS)+        .setConstraints(+            Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build()+        )         .setInputData(inputData)         .build() 
madeveloper/AGENTS.md
diff --git a/madeveloper/AGENTS.md b/madeveloper/AGENTS.mdindex 4f92fc7a63..510887d5a4 100644--- a/madeveloper/AGENTS.md+++ b/madeveloper/AGENTS.md@@ -42,7 +42,6 @@ _Install: ./install madeveloper (dev by default)._ - com/vayunmathur/madeveloper/platform/PairingStore.kt - com/vayunmathur/madeveloper/platform/InstallNotifications.kt - com/vayunmathur/madeveloper/platform/InstallStatusReceiver.kt-- com/vayunmathur/madeveloper/platform/ReconnectWorker.kt ### ui/ — screens - com/vayunmathur/madeveloper/ui/HomeScreen.kt - com/vayunmathur/madeveloper/ui/RepoScreen.kt
madeveloper/src/main/java/com/vayunmathur/madeveloper/MainActivity.kt
diff --git a/madeveloper/src/main/java/com/vayunmathur/madeveloper/MainActivity.kt b/madeveloper/src/main/java/com/vayunmathur/madeveloper/MainActivity.ktindex 5c88cee202..8d43481728 100644--- a/madeveloper/src/main/java/com/vayunmathur/madeveloper/MainActivity.kt+++ b/madeveloper/src/main/java/com/vayunmathur/madeveloper/MainActivity.kt@@ -6,7 +6,6 @@ import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.library.network.TrustBundle import com.vayunmathur.library.ui.MaActivity import com.vayunmathur.madeveloper.platform.MaDevViewModel-import com.vayunmathur.madeveloper.platform.ReconnectWorker  /** Entry activity for Developer. */ class MainActivity : MaActivity() {@@ -14,7 +13,6 @@ class MainActivity : MaActivity() {      override fun onCreateBeforeContent() {         NetworkClient.init(this, TrustBundle.FIRST_PARTY)-        ReconnectWorker.schedule(this)     }      @Composable
madeveloper/src/main/java/com/vayunmathur/madeveloper/platform/ReconnectWorker.kt
diff --git a/madeveloper/src/main/java/com/vayunmathur/madeveloper/platform/ReconnectWorker.kt b/madeveloper/src/main/java/com/vayunmathur/madeveloper/platform/ReconnectWorker.ktdeleted file mode 100644index 9d07eeff03..0000000000--- a/madeveloper/src/main/java/com/vayunmathur/madeveloper/platform/ReconnectWorker.kt+++ /dev/null@@ -1,28 +0,0 @@-package com.vayunmathur.madeveloper.platform--import android.content.Context-import androidx.work.CoroutineWorker-import androidx.work.ExistingPeriodicWorkPolicy-import androidx.work.PeriodicWorkRequestBuilder-import androidx.work.WorkManager-import androidx.work.WorkerParameters-import java.util.concurrent.TimeUnit--/**- * Periodic wake-up that nudges the push socket back open after the process- * was reclaimed; the live connection itself is held by the view-model scope- * while the app is running, like findfamily's heartbeat reconnect.- */-class ReconnectWorker(context: Context, params: WorkerParameters) : CoroutineWorker(context, params) {-    override suspend fun doWork(): Result = Result.success()--    /** Schedules the periodic reconnect nudge once. */-    companion object {-        fun schedule(context: Context) {-            val request = PeriodicWorkRequestBuilder<ReconnectWorker>(15, TimeUnit.MINUTES).build()-            WorkManager.getInstance(context).enqueueUniquePeriodicWork(-                "dev-push-reconnect", ExistingPeriodicWorkPolicy.KEEP, request,-            )-        }-    }-}
maps/src/main/AndroidManifest.xml
diff --git a/maps/src/main/AndroidManifest.xml b/maps/src/main/AndroidManifest.xmlindex c6b76b39ad..dbc37e9f62 100644--- a/maps/src/main/AndroidManifest.xml+++ b/maps/src/main/AndroidManifest.xml@@ -6,7 +6,6 @@     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />      <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />-    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />     <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />     <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />     <!-- Live Updates (API 36 ProgressStyle promoted ongoing): install-time, no runtime prompt. -->
networklocation/src/main/java/com/vayunmathur/networklocation/platform/LocationFeeds.kt
diff --git a/networklocation/src/main/java/com/vayunmathur/networklocation/platform/LocationFeeds.kt b/networklocation/src/main/java/com/vayunmathur/networklocation/platform/LocationFeeds.ktindex 51b581db14..5163ea00fc 100644--- a/networklocation/src/main/java/com/vayunmathur/networklocation/platform/LocationFeeds.kt+++ b/networklocation/src/main/java/com/vayunmathur/networklocation/platform/LocationFeeds.kt@@ -20,6 +20,11 @@ import kotlinx.coroutines.withContext import java.util.Locale import kotlin.coroutines.resume +// 1s is deliberate and scoped to the foreground: the sole caller is the+// visible LiveLocationSection live check, which compares GPS vs network+// fixes and re-renders fix ages every second. There is no background+// caller of this flow, so the >=5s background floor (LocationReportingTask)+// does not apply here; do not reuse this flow for background polling. private const val UPDATE_INTERVAL_MS = 1_000L  fun hasFineLocation(context: Context): Boolean =
networklocation/src/main/java/com/vayunmathur/networklocation/provider/LocationReportingTask.kt
diff --git a/networklocation/src/main/java/com/vayunmathur/networklocation/provider/LocationReportingTask.kt b/networklocation/src/main/java/com/vayunmathur/networklocation/provider/LocationReportingTask.ktindex fe29e0c0ac..6a47a624a1 100644--- a/networklocation/src/main/java/com/vayunmathur/networklocation/provider/LocationReportingTask.kt+++ b/networklocation/src/main/java/com/vayunmathur/networklocation/provider/LocationReportingTask.kt@@ -127,7 +127,14 @@ class LocationReportingTask(      private companion object {         const val TAG = "NetworkLocationFix"-        const val MIN_INTERVAL_MS = 1_000L++        // Background floor: the only caller (LocationProviderImpl, serving+        // framework clients via onSetRequest) is a background system path,+        // so a sub-5s cadence would scan Wi-Fi/cell every second for a+        // coarse network fix. No foreground/live caller requests this task+        // faster; the foreground live check in ui/LiveLocationSection uses+        // LocationFeeds.locationUpdates instead (see there for its 1s case).+        const val MIN_INTERVAL_MS = 5_000L          /** Coordinates per fix in the interleaved native array (lat, lon, accuracy). */         const val COORDS_PER_FIX = 3
securemail/schemas/com.vayunmathur.securemail.data.MailDatabase/5.json
diff --git a/securemail/schemas/com.vayunmathur.securemail.data.MailDatabase/5.json b/securemail/schemas/com.vayunmathur.securemail.data.MailDatabase/5.jsonnew file mode 100644index 0000000000..c3c90a563c--- /dev/null+++ b/securemail/schemas/com.vayunmathur.securemail.data.MailDatabase/5.json@@ -0,0 +1,269 @@+{+  "formatVersion": 1,+  "database": {+    "version": 5,+    "identityHash": "6b5aeb5ad957fd5aba7edc1c1f8ab291",+    "entities": [+      {+        "tableName": "StoredMessage",+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `from` TEXT NOT NULL, `toJson` TEXT NOT NULL, `dateMillis` INTEGER NOT NULL, `messageId` TEXT NOT NULL, `blobBase64` TEXT NOT NULL, `decryptedBody` TEXT, `decryptedSubject` TEXT, `verifiedSigner` TEXT, `unencrypted` INTEGER NOT NULL, `isRead` INTEGER NOT NULL, `folder` TEXT NOT NULL, `decryptedHtml` TEXT, `deliveredTo` TEXT, PRIMARY KEY(`id`))",+        "fields": [+          {+            "fieldPath": "id",+            "columnName": "id",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "from",+            "columnName": "from",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "toJson",+            "columnName": "toJson",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "dateMillis",+            "columnName": "dateMillis",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "messageId",+            "columnName": "messageId",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "blobBase64",+            "columnName": "blobBase64",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "decryptedBody",+            "columnName": "decryptedBody",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "decryptedSubject",+            "columnName": "decryptedSubject",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "verifiedSigner",+            "columnName": "verifiedSigner",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "unencrypted",+            "columnName": "unencrypted",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "isRead",+            "columnName": "isRead",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "folder",+            "columnName": "folder",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "decryptedHtml",+            "columnName": "decryptedHtml",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "deliveredTo",+            "columnName": "deliveredTo",+            "affinity": "TEXT"+          }+        ],+        "primaryKey": {+          "autoGenerate": false,+          "columnNames": [+            "id"+          ]+        }+      },+      {+        "tableName": "CachedKey",+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`address` TEXT NOT NULL, `armoredPublic` TEXT NOT NULL, `fingerprintHex` TEXT NOT NULL, `source` TEXT NOT NULL, `updatedMillis` INTEGER NOT NULL, PRIMARY KEY(`address`))",+        "fields": [+          {+            "fieldPath": "address",+            "columnName": "address",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "armoredPublic",+            "columnName": "armoredPublic",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "fingerprintHex",+            "columnName": "fingerprintHex",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "source",+            "columnName": "source",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "updatedMillis",+            "columnName": "updatedMillis",+            "affinity": "INTEGER",+            "notNull": true+          }+        ],+        "primaryKey": {+          "autoGenerate": false,+          "columnNames": [+            "address"+          ]+        }+      },+      {+        "tableName": "OutboxMessage",+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`rowId` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `toJson` TEXT NOT NULL, `subject` TEXT NOT NULL, `body` TEXT NOT NULL, `inReplyTo` TEXT, `createdMillis` INTEGER NOT NULL, `lastError` TEXT, `attemptCount` INTEGER NOT NULL, `fromAddress` TEXT)",+        "fields": [+          {+            "fieldPath": "rowId",+            "columnName": "rowId",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "toJson",+            "columnName": "toJson",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "subject",+            "columnName": "subject",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "body",+            "columnName": "body",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "inReplyTo",+            "columnName": "inReplyTo",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "createdMillis",+            "columnName": "createdMillis",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "lastError",+            "columnName": "lastError",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "attemptCount",+            "columnName": "attemptCount",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "fromAddress",+            "columnName": "fromAddress",+            "affinity": "TEXT"+          }+        ],+        "primaryKey": {+          "autoGenerate": true,+          "columnNames": [+            "rowId"+          ]+        }+      },+      {+        "tableName": "MailIdentity",+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`address` TEXT NOT NULL, `label` TEXT NOT NULL, `publicArmor` TEXT NOT NULL, `fingerprintHex` TEXT NOT NULL, `secretArmor` TEXT NOT NULL, `isPrimary` INTEGER NOT NULL, `disabled` INTEGER NOT NULL, `createdMillis` INTEGER NOT NULL, PRIMARY KEY(`address`))",+        "fields": [+          {+            "fieldPath": "address",+            "columnName": "address",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "label",+            "columnName": "label",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "publicArmor",+            "columnName": "publicArmor",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "fingerprintHex",+            "columnName": "fingerprintHex",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "secretArmor",+            "columnName": "secretArmor",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "isPrimary",+            "columnName": "isPrimary",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "disabled",+            "columnName": "disabled",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "createdMillis",+            "columnName": "createdMillis",+            "affinity": "INTEGER",+            "notNull": true+          }+        ],+        "primaryKey": {+          "autoGenerate": false,+          "columnNames": [+            "address"+          ]+        }+      }+    ],+    "setupQueries": [+      "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",+      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '6b5aeb5ad957fd5aba7edc1c1f8ab291')"+    ]+  }+}\ No newline at end of file
securemail/src/main/java/com/vayunmathur/securemail/data/MailDatabase.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/data/MailDatabase.kt b/securemail/src/main/java/com/vayunmathur/securemail/data/MailDatabase.ktindex 504e66db4c..c875f4dfa2 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/data/MailDatabase.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/data/MailDatabase.kt@@ -204,7 +204,7 @@ interface IdentityDao { @Database(     entities = [StoredMessage::class, CachedKey::class, OutboxMessage::class, MailIdentity::class],     version = 5,-    exportSchema = false,+    exportSchema = true, ) /** Mail Database: a room database implementation for mail database. */ abstract class MailDatabase : RoomDatabase() {
securemail/src/main/java/com/vayunmathur/securemail/platform/MailSyncWorker.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/platform/MailSyncWorker.kt b/securemail/src/main/java/com/vayunmathur/securemail/platform/MailSyncWorker.ktindex 6ccc55e7b4..075c79d6f6 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/platform/MailSyncWorker.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/platform/MailSyncWorker.kt@@ -22,6 +22,8 @@ import kotlin.time.Duration.Companion.minutes  * the loop is process-wide and service-owned; stopping it here would kill a  * live service session mid-claim (this exact race showed "offline" right  * after registering). No-ops without an identity or when already connected.+ * It does not restart MailSocketService: the service owns the live socket,+ * this worker only drains backlog through the shared loop when it is down.  */ class MailSyncWorker(context: Context, params: WorkerParameters) : CoroutineWorker(context, params) { 
securemail/src/main/java/com/vayunmathur/securemail/service/MailSocketService.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/service/MailSocketService.kt b/securemail/src/main/java/com/vayunmathur/securemail/service/MailSocketService.ktindex 19928d8994..4f13e5daba 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/service/MailSocketService.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/service/MailSocketService.kt@@ -3,6 +3,7 @@ package com.vayunmathur.securemail.service import android.app.Service import android.content.Context import android.content.Intent+import android.content.pm.ServiceInfo import android.os.IBinder import com.vayunmathur.library.util.ensureNotificationChannel import com.vayunmathur.securemail.data.Identities@@ -18,6 +19,12 @@ import kotlinx.coroutines.cancel  * twin of FindFamily's LocationTrackingService socket ownership. Started after  * unlock (or boot, when an identity exists); the socket self-heals with  * 1s→30s backoff and drains backlog on every (re)SUB.+ *+ * Ownership split with MailSyncWorker: this service owns the live socket+ * while it is running. The 15-minute worker is only a background backstop —+ * when no service/socket is connected it nudges the shared socket loop awake+ * briefly to drain backlog, and it never stops the loop (see its header).+ * The two do different jobs, so both are kept.  */ class MailSocketService : Service() { @@ -32,7 +39,14 @@ class MailSocketService : Service() {             "SecureMail relay",             android.app.NotificationManager.IMPORTANCE_LOW,         )-        startForeground(NOTIFICATION_ID, buildNotification())+        // Typed overload (required on API 34+): the manifest declares+        // foregroundServiceType="dataSync" for this service, so pass the+        // matching DATA_SYNC type instead of the untyped call.+        startForeground(+            NOTIFICATION_ID,+            buildNotification(),+            ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC,+        )         val ctx = this         // The socket runs even before an address is claimed: onboarding claims         // over it, and every (re)connect SUBs all active identities.
securemail/src/main/java/com/vayunmathur/securemail/ui/InboxScreen.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/ui/InboxScreen.kt b/securemail/src/main/java/com/vayunmathur/securemail/ui/InboxScreen.ktindex 6b80117331..c332b6c936 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/ui/InboxScreen.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/ui/InboxScreen.kt@@ -16,6 +16,7 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier+import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.dp import com.vayunmathur.library.ui.AlertDialog import com.vayunmathur.library.ui.AppScaffold@@ -35,6 +36,7 @@ import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.TextButton import com.vayunmathur.library.ui.TopAppBar import com.vayunmathur.library.ui.rememberMessenger+import com.vayunmathur.securemail.R import com.vayunmathur.securemail.data.MailFolder import com.vayunmathur.securemail.data.StoredMessage import com.vayunmathur.securemail.platform.MailUiState@@ -67,6 +69,7 @@ fun InboxScreen(     messages: List<StoredMessage> = emptyList(), ) {     val messenger = rememberMessenger()+    val context = LocalContext.current     ConsumeMessage(state.message, messenger, actions.onConsumeMessage)     var selected by remember(folder) { mutableStateOf(emptySet<String>()) }     var confirmDelete by remember { mutableStateOf<List<String>?>(null) }@@ -82,7 +85,7 @@ fun InboxScreen(         } else {             actions.onTrash(ids)             messenger.show(-                if (ids.size == 1) "Moved to Trash" else "${ids.size} moved to Trash",+                context.resources.getQuantityString(R.plurals.moved_to_trash, ids.size, ids.size),                 actionLabel = "Undo",             ) { actions.onMoveTo(ids, folder) }         }
securemail/src/main/java/com/vayunmathur/securemail/ui/OutScreen.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/ui/OutScreen.kt b/securemail/src/main/java/com/vayunmathur/securemail/ui/OutScreen.ktindex 9d167c7860..2ddf176447 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/ui/OutScreen.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/ui/OutScreen.kt@@ -14,6 +14,7 @@ import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier+import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.vayunmathur.library.ui.AppScaffold@@ -28,6 +29,7 @@ import com.vayunmathur.library.ui.SwipeActionsBox import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.TextButton import com.vayunmathur.library.ui.rememberMessenger+import com.vayunmathur.securemail.R import com.vayunmathur.securemail.data.OutboxMessage import com.vayunmathur.securemail.data.StoredMessage import com.vayunmathur.securemail.platform.Draft@@ -206,7 +208,7 @@ private fun OutboxRow(entry: OutboxMessage) {         },         trailingContent = {             Text(-                "${entry.attemptCount} ${if (entry.attemptCount == 1) "try" else "tries"}",+                pluralStringResource(R.plurals.outbox_tries, entry.attemptCount, entry.attemptCount),                 style = MaterialTheme.typography.labelSmall,             )         },
securemail/src/main/res/values/strings.xml
diff --git a/securemail/src/main/res/values/strings.xml b/securemail/src/main/res/values/strings.xmlindex 1e918f2eae..f00c7d3320 100644--- a/securemail/src/main/res/values/strings.xml+++ b/securemail/src/main/res/values/strings.xml@@ -1,4 +1,14 @@ <?xml version="1.0" encoding="utf-8"?> <resources>     <string name="app_name">SecureMail</string>+    <!-- Outbox row: send attempt count. %1$d = number of attempts -->+    <plurals name="outbox_tries">+        <item quantity="one">%1$d try</item>+        <item quantity="other">%1$d tries</item>+    </plurals>+    <!-- Inbox: snackbar shown after moving messages to Trash. %1$d = number moved -->+    <plurals name="moved_to_trash">+        <item quantity="one">Moved to Trash</item>+        <item quantity="other">%1$d moved to Trash</item>+    </plurals> </resources>