fix(manager): keep alive service crashing in A14 (#259)

This commit is contained in:
Js0n 2023-11-11 21:05:34 +08:00 committed by GitHub
parent 8b5d06f073
commit eb2c458dc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -7,6 +7,7 @@
tools:ignore="QueryAllPackagesPermission" />
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<application
android:name=".LSPApplication"
@ -27,6 +28,7 @@
</activity>
<service
android:foregroundServiceType="specialUse"
android:name=".manager.ModuleService"
android:exported="true" />

View File

@ -4,6 +4,8 @@ import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.Service
import android.content.Intent
import android.content.pm.ServiceInfo
import android.os.Build
import android.os.IBinder
import android.util.Log
import androidx.core.app.NotificationCompat
@ -23,7 +25,19 @@ class ModuleService : Service() {
val channel = NotificationChannel(Constants.MANAGER_PACKAGE_NAME, TAG, NotificationManager.IMPORTANCE_DEFAULT)
val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
manager.createNotificationChannel(channel)
startForeground(1, NotificationCompat.Builder(this, Constants.MANAGER_PACKAGE_NAME).build())
// TODO: https://developer.android.com/guide/components/bound-services
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startForeground(
1,
NotificationCompat.Builder(this, Constants.MANAGER_PACKAGE_NAME).build(),
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
)
} else {
startForeground(
1,
NotificationCompat.Builder(this, Constants.MANAGER_PACKAGE_NAME).build()
)
}
} else {
stopForeground(STOP_FOREGROUND_REMOVE)
}