From eb2c458dc1b6d7e1c7a02cd858fc43cc53ef0413 Mon Sep 17 00:00:00 2001
From: Js0n <29531167+JasonKhew96@users.noreply.github.com>
Date: Sat, 11 Nov 2023 21:05:34 +0800
Subject: [PATCH] fix(manager): keep alive service crashing in A14 (#259)
---
manager/src/main/AndroidManifest.xml | 2 ++
.../org/lsposed/lspatch/manager/ModuleService.kt | 16 +++++++++++++++-
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/manager/src/main/AndroidManifest.xml b/manager/src/main/AndroidManifest.xml
index a95bf0b..0032835 100644
--- a/manager/src/main/AndroidManifest.xml
+++ b/manager/src/main/AndroidManifest.xml
@@ -7,6 +7,7 @@
tools:ignore="QueryAllPackagesPermission" />
+
diff --git a/manager/src/main/java/org/lsposed/lspatch/manager/ModuleService.kt b/manager/src/main/java/org/lsposed/lspatch/manager/ModuleService.kt
index c6ceae4..a695075 100644
--- a/manager/src/main/java/org/lsposed/lspatch/manager/ModuleService.kt
+++ b/manager/src/main/java/org/lsposed/lspatch/manager/ModuleService.kt
@@ -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)
}