Fix ANR while installing extensions (#1652)

Update foreground service type for ExtensionInstallService to dataSync
This commit is contained in:
Cuong-Tran 2026-05-19 15:58:12 +07:00 committed by GitHub
parent 94eac94ce7
commit 9a7d1b6143
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 2 deletions

View file

@ -241,7 +241,7 @@
<service
android:name=".extension.util.ExtensionInstallService"
android:exported="false"
android:foregroundServiceType="shortService" />
android:foregroundServiceType="dataSync" />
<service
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"

View file

@ -3,8 +3,10 @@ package eu.kanade.tachiyomi.extension.util
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.ServiceInfo
import android.graphics.BitmapFactory
import android.net.Uri
import android.os.Build
import android.os.IBinder
import androidx.core.content.ContextCompat
import eu.kanade.domain.base.BasePreferences
@ -20,6 +22,11 @@ import exh.log.xLogE
import tachiyomi.core.common.i18n.stringResource
import tachiyomi.i18n.MR
/**
* Foreground service that stages and installs extension APKs via [PackageInstallerInstaller] or
* [ShizukuInstaller]. Uses [ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC] because installs can
* wait on multiple system confirmation dialogs; `shortService` times out after ~3 minutes.
*/
class ExtensionInstallService : Service() {
private var installer: Installer? = null
@ -35,7 +42,17 @@ class ExtensionInstallService : Service() {
setContentTitle(stringResource(MR.strings.ext_install_service_notif))
setProgress(100, 100, true)
}.build()
startForeground(Notifications.ID_EXTENSION_INSTALLER, notification)
// KMK -->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(
Notifications.ID_EXTENSION_INSTALLER,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC,
)
} else {
// KMK <--
startForeground(Notifications.ID_EXTENSION_INSTALLER, notification)
}
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {