@tduncan / Cortana / commits / 908cbba

fix: migrate foreground service type from dataSync to specialUse for persistent model inference

abdulmominsakib committed May 23, 2026 at 21:30 UTC 908cbba5cbe8744bddad2f893901b2fcbcf73432
2 files changed +12 -3
android/app/src/main/AndroidManifest.xml
+6 -2
@@ -2,7 +2,7 @@
2 xmlns:tools="http://schemas.android.com/tools">
3 <uses-permission android:name="android.permission.INTERNET" />
4 <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
5 - <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
5 + <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
6 <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
7 <uses-permission android:name="android.permission.WAKE_LOCK" />
8
@@ -43,7 +43,11 @@
43 android:name=".ChatForegroundService"
44 android:enabled="true"
45 android:exported="false"
46 - android:foregroundServiceType="dataSync" />
46 + android:foregroundServiceType="specialUse">
47 + <property
48 + android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
49 + android:value="Used to keep the local AI model inference process alive when the user switches apps, preventing the OS from terminating the heavy background computation." />
50 + </service>
51 </application>
52 <!-- Required to query activities that can process text, see:
53 https://developer.android.com/training/package-visibility and
android/app/src/main/kotlin/pro/momin/localmind/ChatForegroundService.kt
+6 -1
@@ -3,6 +3,7 @@ package pro.momin.localmind
3 import android.app.*
4 import android.content.Context
5 import android.content.Intent
6 +import android.content.pm.ServiceInfo
7 import android.os.Build
8 import android.os.IBinder
9 import androidx.core.app.NotificationCompat
@@ -45,7 +46,11 @@ class ChatForegroundService : Service() {
46 .setPriority(NotificationCompat.PRIORITY_LOW)
47 .build()
48
48 - startForeground(NOTIFICATION_ID, notification)
49 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
50 + startForeground(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
51 + } else {
52 + startForeground(NOTIFICATION_ID, notification)
53 + }
54
55 return START_STICKY
56 }