Getting rid of dataSync foreground service type for keeping app alive in background as it won't work more than 6h a day starting Android 15

This commit is contained in:
Sylvain Berfini 2024-05-31 14:32:35 +02:00
parent 84b39df26c
commit 8f4c5bdc61
3 changed files with 17 additions and 7 deletions

View file

@ -30,7 +30,12 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_PHONE_CALL" />
<!-- Required for foreground service started when a push is being received,
without it app won't be able to access network if data saver is ON (for example) -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<!-- Needed to keep a permanent foreground service and keep app alive to be able to receive
messages & calls for third party accounts for which push notifications aren't available -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<application
android:name=".LinphoneApplication"
@ -165,9 +170,13 @@
<service
android:name=".core.CoreKeepAliveThirdPartyAccountsService"
android:exported="false"
android:foregroundServiceType="dataSync"
android:foregroundServiceType="specialUse"
android:stopWithTask="false"
android:label="@string/app_name" />
android:label="@string/app_name">
<property
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="Needed to keep app alive to be able to receive messages and calls from third party SIP servers for which push notifications aren't available." />
</service>
<!-- Receivers -->

View file

@ -38,10 +38,11 @@ class Compatibility {
companion object {
private const val TAG = "[Compatibility]"
const val FOREGROUND_SERVICE_TYPE_DATA_SYNC = 1 // Matches ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
const val FOREGROUND_SERVICE_TYPE_PHONE_CALL = 4 // Matches ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL
const val FOREGROUND_SERVICE_TYPE_CAMERA = 64 // Matches ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA
const val FOREGROUND_SERVICE_TYPE_DATA_SYNC = 1 // ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
const val FOREGROUND_SERVICE_TYPE_PHONE_CALL = 4 // ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL
const val FOREGROUND_SERVICE_TYPE_CAMERA = 64 // ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA
const val FOREGROUND_SERVICE_TYPE_MICROPHONE = 128 // ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
const val FOREGROUND_SERVICE_TYPE_SPECIAL_USE = 1073741824 // ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
fun startServiceForeground(
service: Service,

View file

@ -1296,13 +1296,13 @@ class NotificationsManager @MainThread constructor(private val context: Context)
val notification = builder.build()
Log.i(
"$TAG Keep alive for third party accounts Service found, starting it as foreground using notification ID [$KEEP_ALIVE_FOR_THIRD_PARTY_ACCOUNTS_ID] with type DATA_SYNC"
"$TAG Keep alive for third party accounts Service found, starting it as foreground using notification ID [$KEEP_ALIVE_FOR_THIRD_PARTY_ACCOUNTS_ID] with type [SPECIAL_USE]"
)
Compatibility.startServiceForeground(
service,
KEEP_ALIVE_FOR_THIRD_PARTY_ACCOUNTS_ID,
notification,
Compatibility.FOREGROUND_SERVICE_TYPE_DATA_SYNC
Compatibility.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
)
currentKeepAliveThirdPartyAccountsForegroundServiceNotificationId = KEEP_ALIVE_FOR_THIRD_PARTY_ACCOUNTS_ID
} else {