Modern Apps git

← Modern-Apps.git

downloadservice: declare the dataSync foreground-service type once

Commit
1bc8f3bfa216509b49f4fd9f1eb77d79660079b2
Author
Vayun Mathur <[email protected]>
When
2026-11-21 22:20 UTC (14 days ago)
Parents
195a680
Every consumer's lint failed SpecifyForegroundServiceType:
WorkManager's SystemForegroundService ships without a type,
and no manifest overrode it. The worker already promoted with
an untyped ForegroundInfo on one branch - now always typed
FOREGROUND_SERVICE_TYPE_DATA_SYNC (securemail's pattern), the
library manifest declares the merged service override +
FOREGROUND_SERVICE_DATA_SYNC so all consumers inherit it, and
the four consumers (translate, maps, networklocation,
openassistant) declare the permissions their merged manifests
were missing.

Verified: downloadservice, translate, networklocation and
openassistant lint pass; maps' merged manifest is correct
(its 2 remaining lint errors are pre-existing in untouched
files - a DeparturesSheet FileLength and a CommentedOutCode,
triaged next).

Diff

library/downloadservice/src/main/AndroidManifest.xml
diff --git a/library/downloadservice/src/main/AndroidManifest.xml b/library/downloadservice/src/main/AndroidManifest.xmlindex d1438ca9ae..66156cecb6 100644--- a/library/downloadservice/src/main/AndroidManifest.xml+++ b/library/downloadservice/src/main/AndroidManifest.xml@@ -1,7 +1,27 @@ <?xml version="1.0" encoding="utf-8"?>-<manifest xmlns:android="http://schemas.android.com/apk/res/android">+<manifest xmlns:android="http://schemas.android.com/apk/res/android"+    xmlns:tools="http://schemas.android.com/tools">      <uses-permission android:name="android.permission.INTERNET" />     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />+    <!-- ModelDownloadWorker promotes itself via setForeground(ForegroundInfo)+         with FOREGROUND_SERVICE_TYPE_DATA_SYNC (API 34+ requires both the+         typed promotion and these declarations). Like INTERNET above, this+         library declares them itself so every consumer inherits them through+         manifest merger; consumers also declare them explicitly. -->+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />++    <application>+        <!-- WorkManager's own manifest declares SystemForegroundService+             without a foregroundServiceType; override it (merge) with the+             dataSync type that ModelDownloadWorker passes to ForegroundInfo.+             Without this, lint SpecifyForegroundServiceType fails in every+             consumer (and the platform may reject the promotion). -->+        <service+            android:name="androidx.work.impl.foreground.SystemForegroundService"+            android:foregroundServiceType="dataSync"+            tools:node="merge" />+    </application>  </manifest>
library/downloadservice/src/main/java/com/vayunmathur/library/downloadservice/ModelDownloadWorker.kt
diff --git a/library/downloadservice/src/main/java/com/vayunmathur/library/downloadservice/ModelDownloadWorker.kt b/library/downloadservice/src/main/java/com/vayunmathur/library/downloadservice/ModelDownloadWorker.ktindex 88c0ae86b3..027c660e8d 100644--- a/library/downloadservice/src/main/java/com/vayunmathur/library/downloadservice/ModelDownloadWorker.kt+++ b/library/downloadservice/src/main/java/com/vayunmathur/library/downloadservice/ModelDownloadWorker.kt@@ -5,7 +5,6 @@ import android.app.PendingIntent import android.content.Context import android.content.Intent import android.content.pm.ServiceInfo-import android.os.Build import androidx.core.app.NotificationCompat import androidx.work.BackoffPolicy import androidx.work.Constraints@@ -125,16 +124,19 @@ class ModelDownloadWorker(context: Context, params: WorkerParameters) :                 )             )         }-        val foregroundInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {-            ForegroundInfo(-                NOTIFICATION_ID,-                builder.build(),-                ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC,-            )-        } else {-            ForegroundInfo(NOTIFICATION_ID, builder.build())-        }-        return foregroundInfo+        // Typed promotion, unconditional (minSdk 31 > API 29 where the typed+        // ForegroundInfo constructor exists): on API 34+ the platform and+        // WorkManager lint require the type here to match the manifest —+        // this library's manifest declares SystemForegroundService with+        // foregroundServiceType="dataSync" and consumers declare+        // FOREGROUND_SERVICE_DATA_SYNC, exactly as securemail's+        // MailSocketService pairs its typed startForeground with+        // foregroundServiceType="dataSync".+        return ForegroundInfo(+            NOTIFICATION_ID,+            builder.build(),+            ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC,+        )     }      /** WorkManager input keys, enqueue entry points and spec decoding for [ModelDownloadWorker]. */
maps/src/main/AndroidManifest.xml
diff --git a/maps/src/main/AndroidManifest.xml b/maps/src/main/AndroidManifest.xmlindex ab72128b74..65852429e1 100644--- a/maps/src/main/AndroidManifest.xml+++ b/maps/src/main/AndroidManifest.xml@@ -7,6 +7,8 @@      <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />     <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />+    <!-- ModelDownloadWorker (downloadservice) foreground dataSync promotion. -->+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />     <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />     <!-- Live Updates (API 36 ProgressStyle promoted ongoing): install-time, no runtime prompt. -->     <uses-permission android:name="android.permission.POST_PROMOTED_NOTIFICATIONS" />
networklocation/src/main/AndroidManifest.xml
diff --git a/networklocation/src/main/AndroidManifest.xml b/networklocation/src/main/AndroidManifest.xmlindex 259c82f746..de7d3ea30e 100644--- a/networklocation/src/main/AndroidManifest.xml+++ b/networklocation/src/main/AndroidManifest.xml@@ -16,6 +16,9 @@     <uses-permission android:name="android.permission.INTERNET" />     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />     <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />+    <!-- ModelDownloadWorker (downloadservice) foreground dataSync promotion. -->+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />     <!-- ProtectedPermissions: this app ships preinstalled in /system/priv-app as the          platform network-location provider, so the signature|privileged permission is          granted at install; lint cannot see the system-image grant. -->
openassistant/src/main/AndroidManifest.xml
diff --git a/openassistant/src/main/AndroidManifest.xml b/openassistant/src/main/AndroidManifest.xmlindex b8de7d2b76..e37f7ad93f 100644--- a/openassistant/src/main/AndroidManifest.xml+++ b/openassistant/src/main/AndroidManifest.xml@@ -29,6 +29,8 @@     <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />     <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />     <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />+    <!-- ModelDownloadWorker (downloadservice) foreground dataSync promotion. -->+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />      <uses-permission android:name="android.permission.RECORD_AUDIO" /> 
translate/src/main/AndroidManifest.xml
diff --git a/translate/src/main/AndroidManifest.xml b/translate/src/main/AndroidManifest.xmlindex f6ebf061d6..0402251c3b 100644--- a/translate/src/main/AndroidManifest.xml+++ b/translate/src/main/AndroidManifest.xml@@ -13,6 +13,9 @@     <uses-permission android:name="android.permission.CAMERA" />     <uses-permission android:name="android.permission.RECORD_AUDIO" />     <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />+    <!-- ModelDownloadWorker (downloadservice) foreground dataSync promotion. -->+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />      <uses-feature android:name="android.hardware.camera.any" android:required="false" />