Skip to content

Commit 8de7ca3

Browse files
Merge pull request #2625 from nift4:mbrcontext
PiperOrigin-RevId: 786218618
2 parents ec6ac47 + 5bb86b9 commit 8de7ca3

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

RELEASENOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
* Fix a bug that causes a player's first playback error to be incorrectly
8888
treated as a persistent custom exception. This prevents the application
8989
from recovering.
90+
* Add a `Context` parameter to
91+
`MediaButtonReceiver.onForegroundServiceStartNotAllowedException`
92+
([#2625](https://github.com/androidx/media/pull/2625)).
9093
* UI:
9194
* Add `ProgressStateWithTickInterval` class and the corresponding
9295
`rememberProgressStateWithTickInterval` Composable to

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ protected final void handleIntentAndMaybeStartTheService(
190190
} catch (/* ForegroundServiceStartNotAllowedException */ IllegalStateException e) {
191191
if (SDK_INT >= 31 && Api31.instanceOfForegroundServiceStartNotAllowedException(e)) {
192192
onForegroundServiceStartNotAllowedException(
193-
serviceIntent, Api31.castToForegroundServiceStartNotAllowedException(e));
193+
context, serviceIntent, Api31.castToForegroundServiceStartNotAllowedException(e));
194194
} else {
195195
throw e;
196196
}
@@ -226,6 +226,21 @@ protected boolean shouldStartForegroundService(Context context, Intent intent) {
226226
return true;
227227
}
228228

229+
/**
230+
* @deprecated Use {@link #onForegroundServiceStartNotAllowedException(Context, Intent,
231+
* ForegroundServiceStartNotAllowedException)} instead.
232+
*/
233+
@Deprecated
234+
@RequiresApi(31)
235+
protected void onForegroundServiceStartNotAllowedException(
236+
Intent intent, ForegroundServiceStartNotAllowedException e) {
237+
Log.e(
238+
TAG,
239+
"caught exception when trying to start a foreground service from the "
240+
+ "background: "
241+
+ e.getMessage());
242+
}
243+
229244
/**
230245
* This method is called when an exception is thrown when calling {@link
231246
* Context#startForegroundService(Intent)} as a result of receiving a media button event.
@@ -249,18 +264,16 @@ protected boolean shouldStartForegroundService(Context context, Intent intent) {
249264
* apps must use a {@link MediaBrowser} or {@link MediaController} to bind to the service instead
250265
* of broadcasting an intent.
251266
*
267+
* @param context The broadcast receiver's {@linkplain Context}
252268
* @param intent The intent that was used {@linkplain Context#startForegroundService(Intent) for
253269
* starting the foreground service}.
254270
* @param e The exception thrown by the system and caught by this broadcast receiver.
255271
*/
272+
@SuppressWarnings("deprecation")
256273
@RequiresApi(31)
257274
protected void onForegroundServiceStartNotAllowedException(
258-
Intent intent, ForegroundServiceStartNotAllowedException e) {
259-
Log.e(
260-
TAG,
261-
"caught exception when trying to start a foreground service from the "
262-
+ "background: "
263-
+ e.getMessage());
275+
Context context, Intent intent, ForegroundServiceStartNotAllowedException e) {
276+
onForegroundServiceStartNotAllowedException(intent, e);
264277
}
265278

266279
@SuppressWarnings("QueryPermissionsNeeded") // Needs to be provided in the app manifest.

0 commit comments

Comments
 (0)