Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
* Change the default value for
`MediaLibrarySession.Builder.setLibraryErrorReplicationMode` to non
fatal.
* Add a `Context` parameter to
`MediaButtonReceiver.onForegroundServiceStartNotAllowedException`
([#2625](https://github.com/androidx/media/pull/2625)).
* UI:
* Add `ProgressStateWithTickInterval` class and the corresponding
`rememberProgressStateWithTickInterval` Composable to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ protected final void handleIntentAndMaybeStartTheService(
} catch (/* ForegroundServiceStartNotAllowedException */ IllegalStateException e) {
if (SDK_INT >= 31 && Api31.instanceOfForegroundServiceStartNotAllowedException(e)) {
onForegroundServiceStartNotAllowedException(
serviceIntent, Api31.castToForegroundServiceStartNotAllowedException(e));
context, serviceIntent, Api31.castToForegroundServiceStartNotAllowedException(e));
} else {
throw e;
}
Expand Down Expand Up @@ -226,6 +226,21 @@ protected boolean shouldStartForegroundService(Context context, Intent intent) {
return true;
}

/**
* @deprecated Use {@link #onForegroundServiceStartNotAllowedException(Context, Intent,
* ForegroundServiceStartNotAllowedException)} instead.
*/
@Deprecated
@RequiresApi(31)
protected void onForegroundServiceStartNotAllowedException(
Intent intent, ForegroundServiceStartNotAllowedException e) {
Log.e(
TAG,
"caught exception when trying to start a foreground service from the "
+ "background: "
+ e.getMessage());
}

/**
* This method is called when an exception is thrown when calling {@link
* Context#startForegroundService(Intent)} as a result of receiving a media button event.
Expand All @@ -249,18 +264,16 @@ protected boolean shouldStartForegroundService(Context context, Intent intent) {
* apps must use a {@link MediaBrowser} or {@link MediaController} to bind to the service instead
* of broadcasting an intent.
*
* @param context The broadcast receiver's {@linkplain Context}
* @param intent The intent that was used {@linkplain Context#startForegroundService(Intent) for
* starting the foreground service}.
* @param e The exception thrown by the system and caught by this broadcast receiver.
*/
@SuppressWarnings("deprecation")
@RequiresApi(31)
protected void onForegroundServiceStartNotAllowedException(
Intent intent, ForegroundServiceStartNotAllowedException e) {
Log.e(
TAG,
"caught exception when trying to start a foreground service from the "
+ "background: "
+ e.getMessage());
Context context, Intent intent, ForegroundServiceStartNotAllowedException e) {
onForegroundServiceStartNotAllowedException(intent, e);
}

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