From 3691428a6884bbfbc300e7b2df5b4cb33918d6e1 Mon Sep 17 00:00:00 2001 From: tzugen Date: Sun, 17 Apr 2022 06:58:39 +0200 Subject: [PATCH] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 7a8f20ade7d2522c1281b63a31c3e9630df12553 Author: Holger Müller Date: Fri Apr 8 23:21:15 2022 +0200 make build working with target sdk 31 commit 5890c32b7eb91621ce628ac6d900cb00a1481d71 Author: Holger Müller Date: Fri Apr 8 22:57:23 2022 +0200 make build working with target sdk 31 commit 1c7c4839b3eed5eef8298c2ddce22812e14d6329 Merge: 48b0cdea 92ef78a3 Author: Holger Müller Date: Fri Apr 8 21:55:14 2022 +0200 Merge remote-tracking branch 'upstream/media3-flat' into media3-flat commit 48b0cdea83433cc29760972c522a497f812d6d30 Merge: 9101980c 3ca25ed1 Author: Holger Müller Date: Fri Apr 8 19:58:55 2022 +0200 Merge remote-tracking branch 'upstream/media3-flat' into media3-flat commit 9101980cb6d8972ee6e49b58737b36c4ac36e495 Merge: 515690ab 97798446 Author: Holger Müller Date: Fri Apr 8 17:07:54 2022 +0200 Merge remote-tracking branch 'upstream/media3-flat' into media3-flat commit 515690abaccd5405709b1fe877a9ef9c9bbf3e21 Author: Holger Müller Date: Thu Apr 7 08:55:42 2022 +0200 made button off mode better visible --- .../ultrasonic/playback/PlaybackService.kt | 9 +++++--- .../provider/UltrasonicAppWidgetProvider.kt | 21 +++++++++++++------ .../ultrasonic/service/DownloadService.kt | 8 ++++--- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/PlaybackService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/PlaybackService.kt index 1d446797..edd24315 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/PlaybackService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/PlaybackService.kt @@ -15,9 +15,9 @@ */ package org.moire.ultrasonic.playback -import android.annotation.SuppressLint import android.app.PendingIntent import android.content.Intent +import android.os.Build import androidx.media3.common.AudioAttributes import androidx.media3.common.C import androidx.media3.common.C.CONTENT_TYPE_MUSIC @@ -132,11 +132,14 @@ class PlaybackService : MediaLibraryService(), KoinComponent { .build() } - @SuppressLint("UnspecifiedImmutableFlag") private fun getPendingIntentForContent(): PendingIntent { val intent = Intent(this, NavigationActivity::class.java) .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) - val flags = PendingIntent.FLAG_UPDATE_CURRENT + var flags = PendingIntent.FLAG_UPDATE_CURRENT + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + // needed starting Android 12 (S = 31) + flags = flags or PendingIntent.FLAG_IMMUTABLE + } intent.putExtra(Constants.INTENT_SHOW_PLAYER, true) return PendingIntent.getActivity(this, 0, intent, flags) } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/provider/UltrasonicAppWidgetProvider.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/provider/UltrasonicAppWidgetProvider.kt index 7a12fdfe..ddc11e3f 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/provider/UltrasonicAppWidgetProvider.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/provider/UltrasonicAppWidgetProvider.kt @@ -7,13 +7,13 @@ package org.moire.ultrasonic.provider -import android.annotation.SuppressLint import android.app.PendingIntent import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetProvider import android.content.ComponentName import android.content.Context import android.content.Intent +import android.os.Build import android.os.Environment import android.view.KeyEvent import android.widget.RemoteViews @@ -164,7 +164,6 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() { /** * Link up various button actions using [PendingIntent]. */ - @SuppressLint("UnspecifiedImmutableFlag") private fun linkButtons(context: Context, views: RemoteViews, playerActive: Boolean) { var intent = Intent( context, @@ -173,8 +172,13 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() { if (playerActive) intent.putExtra(Constants.INTENT_SHOW_PLAYER, true) intent.action = "android.intent.action.MAIN" intent.addCategory("android.intent.category.LAUNCHER") + var flags = PendingIntent.FLAG_UPDATE_CURRENT + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + // needed starting Android 12 (S = 31) + flags = flags or PendingIntent.FLAG_IMMUTABLE + } var pendingIntent = - PendingIntent.getActivity(context, 10, intent, PendingIntent.FLAG_UPDATE_CURRENT) + PendingIntent.getActivity(context, 10, intent, flags) views.setOnClickPendingIntent(R.id.appwidget_coverart, pendingIntent) views.setOnClickPendingIntent(R.id.appwidget_top, pendingIntent) @@ -185,7 +189,12 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() { Intent.EXTRA_KEY_EVENT, KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) ) - pendingIntent = PendingIntent.getBroadcast(context, 11, intent, 0) + flags = 0 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + // needed starting Android 12 (S = 31) + flags = flags or PendingIntent.FLAG_IMMUTABLE + } + pendingIntent = PendingIntent.getBroadcast(context, 11, intent, flags) views.setOnClickPendingIntent(R.id.control_play, pendingIntent) intent = Intent(Constants.CMD_PROCESS_KEYCODE) intent.component = ComponentName(context, MediaButtonIntentReceiver::class.java) @@ -193,7 +202,7 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() { Intent.EXTRA_KEY_EVENT, KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT) ) - pendingIntent = PendingIntent.getBroadcast(context, 12, intent, 0) + pendingIntent = PendingIntent.getBroadcast(context, 12, intent, flags) views.setOnClickPendingIntent(R.id.control_next, pendingIntent) intent = Intent(Constants.CMD_PROCESS_KEYCODE) intent.component = ComponentName(context, MediaButtonIntentReceiver::class.java) @@ -201,7 +210,7 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() { Intent.EXTRA_KEY_EVENT, KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS) ) - pendingIntent = PendingIntent.getBroadcast(context, 13, intent, 0) + pendingIntent = PendingIntent.getBroadcast(context, 13, intent, flags) views.setOnClickPendingIntent(R.id.control_previous, pendingIntent) } } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadService.kt index e9cc351d..f6b2ed49 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadService.kt @@ -7,7 +7,6 @@ package org.moire.ultrasonic.service -import android.annotation.SuppressLint import android.app.Notification import android.app.NotificationChannel import android.app.NotificationManager @@ -154,11 +153,14 @@ class DownloadService : Service() { return notificationBuilder.build() } - @SuppressLint("UnspecifiedImmutableFlag") private fun getPendingIntentForContent(): PendingIntent { val intent = Intent(this, NavigationActivity::class.java) .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) - val flags = PendingIntent.FLAG_UPDATE_CURRENT + var flags = PendingIntent.FLAG_UPDATE_CURRENT + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + // needed starting Android 12 (S = 31) + flags = flags or PendingIntent.FLAG_IMMUTABLE + } intent.putExtra(Constants.INTENT_SHOW_PLAYER, true) return PendingIntent.getActivity(this, 0, intent, flags) }