Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
fix(manager): keep alive service crashing in A14 (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonKhew96 authored Nov 11, 2023
1 parent 8b5d06f commit eb2c458
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions manager/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -27,6 +28,7 @@
</activity>

<service
android:foregroundServiceType="specialUse"
android:name=".manager.ModuleService"
android:exported="true" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit eb2c458

Please sign in to comment.