From c8c0164964da2c8aaa7614565f2a1ffefd9537b7 Mon Sep 17 00:00:00 2001 From: zarzet Date: Sat, 10 Jan 2026 04:51:15 +0700 Subject: [PATCH] chore: update targetSdk to 36 (Android 16) with timeout handler --- android/app/build.gradle.kts | 2 +- .../kotlin/com/zarz/spotiflac/DownloadService.kt | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index d04ce68..aa313d3 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -46,7 +46,7 @@ android { defaultConfig { applicationId = "com.zarz.spotiflac" minSdk = flutter.minSdkVersion - targetSdk = 34 + targetSdk = 36 versionCode = flutter.versionCode versionName = flutter.versionName multiDexEnabled = true diff --git a/android/app/src/main/kotlin/com/zarz/spotiflac/DownloadService.kt b/android/app/src/main/kotlin/com/zarz/spotiflac/DownloadService.kt index 2cc7f0d..c3fd7b4 100644 --- a/android/app/src/main/kotlin/com/zarz/spotiflac/DownloadService.kt +++ b/android/app/src/main/kotlin/com/zarz/spotiflac/DownloadService.kt @@ -15,6 +15,9 @@ import androidx.core.app.NotificationCompat /** * Foreground service to keep downloads running when app is in background. * This prevents Android from killing the download process or throttling network. + * + * Note: Android 15+ (API 35+) has a 6-hour timeout for dataSync foreground services. + * The service will be stopped automatically after 6 hours of cumulative runtime in 24 hours. */ class DownloadService : Service() { @@ -106,6 +109,19 @@ class DownloadService : Service() { override fun onBind(intent: Intent?): IBinder? = null + /** + * Called when the foreground service timeout is reached (Android 15+, API 35+). + * dataSync services have a 6-hour limit in a 24-hour period. + * We must call stopSelf() within a few seconds to avoid a crash. + */ + override fun onTimeout(startId: Int, fgsType: Int) { + // Log the timeout for debugging + android.util.Log.w("DownloadService", "Foreground service timeout reached (6 hours limit). Stopping service.") + + // Gracefully stop the service + stopForegroundService() + } + private fun createNotificationChannel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val channel = NotificationChannel(