diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 94cc81bb495..07504c609df 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -159,6 +159,8 @@ This release includes the following changes since the position artefacts in the Android Auto UI (and other controllers using this information from the platform media session) ([#1758](https://github.com/androidx/media/issues/1758)). + * Fix StrictMode unsafe launch violation warning + ([#2330](https://github.com/androidx/media/pull/2330)). * Cronet extension: * Add automatic cookie handling ([#5975](https://github.com/google/ExoPlayer/issues/5975)). diff --git a/libraries/session/src/main/java/androidx/media3/session/MediaButtonReceiver.java b/libraries/session/src/main/java/androidx/media3/session/MediaButtonReceiver.java index 766a6f326aa..a98309b78c8 100644 --- a/libraries/session/src/main/java/androidx/media3/session/MediaButtonReceiver.java +++ b/libraries/session/src/main/java/androidx/media3/session/MediaButtonReceiver.java @@ -174,8 +174,10 @@ protected final void handleIntentAndMaybeStartTheService( for (String action : ACTIONS) { ComponentName mediaButtonServiceComponentName = getServiceComponentByAction(context, action); if (mediaButtonServiceComponentName != null) { - intent.setComponent(mediaButtonServiceComponentName); - if (!shouldStartForegroundService(context, intent)) { + Intent serviceIntent = new Intent(); + serviceIntent.setComponent(mediaButtonServiceComponentName); + serviceIntent.fillIn(intent, 0); + if (!shouldStartForegroundService(context, serviceIntent)) { Log.i( TAG, "onReceive(Intent) does not start the media button event target service into the" @@ -184,11 +186,11 @@ protected final void handleIntentAndMaybeStartTheService( return; } try { - ContextCompat.startForegroundService(context, intent); + ContextCompat.startForegroundService(context, serviceIntent); } catch (/* ForegroundServiceStartNotAllowedException */ IllegalStateException e) { if (SDK_INT >= 31 && Api31.instanceOfForegroundServiceStartNotAllowedException(e)) { onForegroundServiceStartNotAllowedException( - intent, Api31.castToForegroundServiceStartNotAllowedException(e)); + serviceIntent, Api31.castToForegroundServiceStartNotAllowedException(e)); } else { throw e; } @@ -214,8 +216,8 @@ protected final void handleIntentAndMaybeStartTheService( * * @param context The {@link Context} that {@linkplain #onReceive(Context, Intent) was received by * the media button event receiver}. - * @param intent The intent that {@linkplain #onReceive(Context, Intent) was received by the media - * button event receiver}. + * @param intent The intent that will be used by {@linkplain + * Context#startForegroundService(Intent) for starting the foreground service}. * @return true if the service should be {@linkplain ContextCompat#startForegroundService(Context, * Intent) started as a foreground service}. If false is returned the service is not started * and the receiver call is a no-op.