Skip to content

Commit

Permalink
Upgrade to Android 14, Sdk Version 34 (#986)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
SyncedSynapse authored Nov 16, 2023
1 parent b77fc22 commit c312847
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<!--
Added notification permission so that code in MediaSessionService doesn't show errors.
This is not really necessary, given that notifications are sent via MediaService, and those
Expand All @@ -31,8 +32,7 @@
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"
android:networkSecurityConfig="@xml/network_security_config"
tools:targetApi="n">
android:networkSecurityConfig="@xml/network_security_config">

<!-- Activities -->
<activity
Expand Down Expand Up @@ -195,6 +195,7 @@
android:exported="false" />
<service
android:name=".service.MediaSessionService"
android:foregroundServiceType="mediaPlayback"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/org/xbmc/kore/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c312847

Please sign in to comment.