From c312847fec240720420f0cfda6561274ab8f56a7 Mon Sep 17 00:00:00 2001 From: Synced Synapse Date: Thu, 16 Nov 2023 19:32:42 +0000 Subject: [PATCH] Upgrade to Android 14, Sdk Version 34 (#986) - Specify foreground service type, namely on the MediaSessionService - Regarding changes to granting partial access to photos and videos, nothing was changed, so it relies on compatibility mode. [More here](https://developer.android.com/about/versions/14/changes/partial-photo-video-access) The default compatibility mode works more or less ok, and adding specific logic to handle partial access wouldn't help much and would confuse the code. --- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 5 +++-- .../java/org/xbmc/kore/service/MediaSessionService.java | 7 ++++++- app/src/main/java/org/xbmc/kore/utils/Utils.java | 4 ++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 902c87291..bc1fe2278 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,7 +15,7 @@ android { defaultConfig { applicationId "org.xbmc.kore" minSdkVersion 24 - targetSdkVersion 33 + targetSdkVersion 34 versionCode 31 versionName = getVersionName() testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0e73631ea..3eaaefdbb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,6 +9,7 @@ + diff --git a/app/src/main/java/org/xbmc/kore/service/MediaSessionService.java b/app/src/main/java/org/xbmc/kore/service/MediaSessionService.java index 0d24746cf..4474da276 100644 --- a/app/src/main/java/org/xbmc/kore/service/MediaSessionService.java +++ b/app/src/main/java/org/xbmc/kore/service/MediaSessionService.java @@ -10,6 +10,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.content.pm.ServiceInfo; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; @@ -200,7 +201,11 @@ public int onStartCommand(Intent intent, int flags, int startId) { } // Request foreground and show default notification, will update later - startForeground(NOTIFICATION_ID, nothingPlayingNotification); + if (Utils.isUpsideDownCakeOrLater()) { + startForeground(NOTIFICATION_ID, nothingPlayingNotification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK); + } else { + startForeground(NOTIFICATION_ID, nothingPlayingNotification); + } HostConnectionObserver connectionObserver = HostManager.getInstance(this).getHostConnectionObserver(); if (hostConnectionObserver == null || hostConnectionObserver != connectionObserver) { diff --git a/app/src/main/java/org/xbmc/kore/utils/Utils.java b/app/src/main/java/org/xbmc/kore/utils/Utils.java index b4719c2b4..cbee0f6eb 100644 --- a/app/src/main/java/org/xbmc/kore/utils/Utils.java +++ b/app/src/main/java/org/xbmc/kore/utils/Utils.java @@ -52,6 +52,10 @@ public static boolean isTiramisuOrLater() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU; } + public static boolean isUpsideDownCakeOrLater() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE; + } + /** * Concats a list of strings * @param list List to concatenate