Skip to content

Commit e807fe5

Browse files
Merge pull request #2330 from nift4:mbrstrict
PiperOrigin-RevId: 777492666
2 parents 6c5c5f2 + 802eec6 commit e807fe5

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

RELEASENOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ This release includes the following changes since the
159159
position artefacts in the Android Auto UI (and other controllers using
160160
this information from the platform media session)
161161
([#1758](https://github.com/androidx/media/issues/1758)).
162+
* Fix StrictMode unsafe launch violation warning
163+
([#2330](https://github.com/androidx/media/pull/2330)).
162164
* Cronet extension:
163165
* Add automatic cookie handling
164166
([#5975](https://github.com/google/ExoPlayer/issues/5975)).

libraries/session/src/main/java/androidx/media3/session/MediaButtonReceiver.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,10 @@ protected final void handleIntentAndMaybeStartTheService(
174174
for (String action : ACTIONS) {
175175
ComponentName mediaButtonServiceComponentName = getServiceComponentByAction(context, action);
176176
if (mediaButtonServiceComponentName != null) {
177-
intent.setComponent(mediaButtonServiceComponentName);
178-
if (!shouldStartForegroundService(context, intent)) {
177+
Intent serviceIntent = new Intent();
178+
serviceIntent.setComponent(mediaButtonServiceComponentName);
179+
serviceIntent.fillIn(intent, 0);
180+
if (!shouldStartForegroundService(context, serviceIntent)) {
179181
Log.i(
180182
TAG,
181183
"onReceive(Intent) does not start the media button event target service into the"
@@ -184,11 +186,11 @@ protected final void handleIntentAndMaybeStartTheService(
184186
return;
185187
}
186188
try {
187-
ContextCompat.startForegroundService(context, intent);
189+
ContextCompat.startForegroundService(context, serviceIntent);
188190
} catch (/* ForegroundServiceStartNotAllowedException */ IllegalStateException e) {
189191
if (SDK_INT >= 31 && Api31.instanceOfForegroundServiceStartNotAllowedException(e)) {
190192
onForegroundServiceStartNotAllowedException(
191-
intent, Api31.castToForegroundServiceStartNotAllowedException(e));
193+
serviceIntent, Api31.castToForegroundServiceStartNotAllowedException(e));
192194
} else {
193195
throw e;
194196
}
@@ -214,8 +216,8 @@ protected final void handleIntentAndMaybeStartTheService(
214216
*
215217
* @param context The {@link Context} that {@linkplain #onReceive(Context, Intent) was received by
216218
* the media button event receiver}.
217-
* @param intent The intent that {@linkplain #onReceive(Context, Intent) was received by the media
218-
* button event receiver}.
219+
* @param intent The intent that will be used by {@linkplain
220+
* Context#startForegroundService(Intent) for starting the foreground service}.
219221
* @return true if the service should be {@linkplain ContextCompat#startForegroundService(Context,
220222
* Intent) started as a foreground service}. If false is returned the service is not started
221223
* and the receiver call is a no-op.

0 commit comments

Comments
 (0)