[Android] Implement all the new Android 34 restrictions
Nicolas Pomepuy
git at videolan.org
Thu Oct 3 07:36:48 UTC 2024
vlc-android | branch: 3.5.x | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Aug 28 13:56:51 2023 +0200| [a7e0820e93191e1b4bebd36267d83100fd661efc] | committer: Nicolas Pomepuy
Implement all the new Android 34 restrictions
(cherry picked from commit 7f74e9a5d5a31c9bc0c3ceb08607613dfed15333)
> https://code.videolan.org/videolan/vlc-android/commit/a7e0820e93191e1b4bebd36267d83100fd661efc
---
.../vlc-android/src/org/videolan/vlc/DebugLogService.kt | 5 ++++-
.../vlc-android/src/org/videolan/vlc/MediaParsingService.kt | 10 +++++++---
.../vlc-android/src/org/videolan/vlc/PlaybackService.kt | 12 +++++++++---
.../src/org/videolan/vlc/gui/video/PopupManager.kt | 6 +++++-
4 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/DebugLogService.kt b/application/vlc-android/src/org/videolan/vlc/DebugLogService.kt
index 3eb13a5938..1576eceb85 100644
--- a/application/vlc-android/src/org/videolan/vlc/DebugLogService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/DebugLogService.kt
@@ -138,7 +138,10 @@ class DebugLogService : Service(), Logcat.Callback, Runnable {
builder.setSmallIcon(R.drawable.ic_stat_vlc)
builder.setContentIntent(pi)
val notification = builder.build()
- startForegroundCompat(3, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
+ startForeground(3, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
+ else
+ startForeground(3, notification)
}
@Synchronized
diff --git a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 5729ed160e..c358a6309f 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -134,7 +134,7 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb {
val filter = IntentFilter()
filter.addAction(ACTION_PAUSE_SCAN)
filter.addAction(ACTION_RESUME_SCAN)
- registerReceiverCompat(receiver, filter, false)
+ registerReceiver(receiver, filter, RECEIVER_NOT_EXPORTED)
val pm = applicationContext.getSystemService<PowerManager>()!!
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VLC:MediaParsingService")
@@ -206,7 +206,9 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb {
private fun forceForeground() {
val notification = NotificationHelper.createScanNotification(applicationContext, getString(R.string.loading_medialibrary), scanPaused, -1, -1)
try {
- startForegroundCompat(43, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
+ startForeground(43, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
+ else startForeground(43, notification)
} catch (e: Exception) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && e is ForegroundServiceStartNotAllowedException) {
Log.w("MediaParsingService", "ForegroundServiceStartNotAllowedException caught!")
@@ -388,7 +390,9 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb {
try {
val notification = NotificationHelper.createScanNotification(applicationContext, progressText, scanPaused, scheduled, done)
try {
- startForegroundCompat(43, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
+ startForeground(43, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
+ else startForeground(43, notification)
} catch (e: Exception) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && e is ForegroundServiceStartNotAllowedException) {
Log.w("MediaParsingService", "ForegroundServiceStartNotAllowedException caught!")
diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index b70b6249ef..e692e1c25f 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -643,7 +643,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner, CoroutineSc
addAction(ACTION_CAR_MODE_EXIT)
addAction(CUSTOM_ACTION)
}
- registerReceiverCompat(receiver, filter, false)
+ registerReceiver(receiver, filter, RECEIVER_NOT_EXPORTED)
if (CarConnectionHandler.preferCarConnectionHandler()) {
carConnectionHandler = CarConnectionHandler(contentResolver)
carConnectionHandler.connectionType.observeForever {
@@ -770,7 +770,10 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner, CoroutineSc
ctx.resources.getString(R.string.loading), "", "", null, false, true,
true, speed, isPodcastMode, false, enabledActions, null, pi)
}
- startForegroundCompat(3, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
+ startForeground(3, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK)
+ else
+ startForeground(3, notification)
isForeground = true
if (stopped) lifecycleScope.launch { hideNotification(true) }
}
@@ -912,7 +915,10 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner, CoroutineSc
if (!AndroidUtil.isLolliPopOrLater || playing || audioFocusHelper.lossTransient) {
if (!isForeground) {
ctx.launchForeground(Intent(ctx, PlaybackService::class.java)) {
- startForegroundCompat(3, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
+ startForeground(3, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK)
+ else
+ startForeground(3, notification)
isForeground = true
}
} else
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.kt
index 6c3a995bc9..a7b5f61615 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.kt
@@ -26,6 +26,7 @@ package org.videolan.vlc.gui.video
import android.content.Intent
import android.content.pm.ServiceInfo
+import android.os.Build
import android.os.Handler
import android.os.Looper
import android.os.Message
@@ -271,7 +272,10 @@ class PopupManager constructor(private val service: PlaybackService) : PlaybackS
else
builder.addAction(R.drawable.ic_popup_play, service.getString(R.string.play), piPlay)
builder.addAction(R.drawable.ic_popup_fullscreen, service.getString(R.string.popup_expand), piExpand)
- service.startForegroundCompat(42, builder.build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
+ service.startForeground(42, builder.build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK)
+ else
+ service.startForeground(42, builder.build())
}
private fun hideNotification() {
More information about the Android
mailing list