Fix Android 14+ FGS type crash

This commit is contained in:
Aleksandras Kostarevas 2024-01-17 15:08:07 +02:00
parent 965b17d912
commit ec6969b5c2
2 changed files with 19 additions and 2 deletions

View File

@ -15,7 +15,8 @@
--> -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.futo.inputmethod.latin"> xmlns:tools="http://schemas.android.com/tools"
package="org.futo.inputmethod.latin">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION"/> <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION"/>
@ -35,6 +36,7 @@
<uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/> <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"/>
<!-- A signature-protected permission to ask AOSP Keyboard to close the software keyboard. <!-- A signature-protected permission to ask AOSP Keyboard to close the software keyboard.
To use this, add the following line into calling application's AndroidManifest.xml To use this, add the following line into calling application's AndroidManifest.xml
@ -200,5 +202,15 @@
android:multiprocess="false" android:multiprocess="false"
android:label="@string/dictionary_provider_name"> android:label="@string/dictionary_provider_name">
</provider> </provider>
<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="specialUse"
tools:node="merge">
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="Neural network model training"/>
</service>
</application> </application>
</manifest> </manifest>

View File

@ -3,6 +3,7 @@ package org.futo.inputmethod.latin.xlm
import android.app.NotificationChannel import android.app.NotificationChannel
import android.app.NotificationManager import android.app.NotificationManager
import android.content.Context import android.content.Context
import android.content.pm.ServiceInfo
import android.os.Build import android.os.Build
import android.os.PowerManager import android.os.PowerManager
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
@ -204,7 +205,11 @@ class TrainingWorker(context: Context, parameters: WorkerParameters) : Coroutine
.addAction(android.R.drawable.ic_delete, cancel, intent) .addAction(android.R.drawable.ic_delete, cancel, intent)
.build() .build()
return ForegroundInfo(NOTIFICATION_ID, notification) return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
ForegroundInfo(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
} else {
ForegroundInfo(NOTIFICATION_ID, notification)
}
} }
@RequiresApi(Build.VERSION_CODES.O) @RequiresApi(Build.VERSION_CODES.O)