Handle IllegalArgumentException when setting broadcast receiver
Some devices seem to throw an `IllegalArgumentException` when attempting to set a valid media button broadcast receiver for playback resumption. This change handles this exception as a no-op to avoid crashing the app. As a result, playback resumption with media keys isn't going to work on these devices. This change needs to be reverted once the root cause on these devices has been fixed (see internal bug ref in source). Issue: androidx/media#1730 PiperOrigin-RevId: 677904243
This commit is contained in:
parent
869a91bba8
commit
b884d7ee9b
@ -79,6 +79,9 @@
|
||||
legacy service. This prevented the `MediaBrowser` to receive the actual
|
||||
return value sent back by the legacy service
|
||||
([#1474](https://github.com/androidx/media/issues/1474)).
|
||||
* Handle `IllegalArgumentException` thrown by devices of certain
|
||||
manufacturers when setting the broadcast receiver for media button
|
||||
intents ([#1730](https://github.com/androidx/media/issues/1730)).
|
||||
* UI:
|
||||
* Make the stretched/cropped video in
|
||||
`PlayerView`-in-Compose-`AndroidView` workaround opt-in, due to issues
|
||||
|
@ -50,6 +50,7 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@ -1483,8 +1484,22 @@ import org.checkerframework.checker.initialization.qual.Initialized;
|
||||
private static final class Api31 {
|
||||
public static void setMediaButtonBroadcastReceiver(
|
||||
MediaSessionCompat mediaSessionCompat, ComponentName broadcastReceiver) {
|
||||
((android.media.session.MediaSession) checkNotNull(mediaSessionCompat.getMediaSession()))
|
||||
.setMediaButtonBroadcastReceiver(broadcastReceiver);
|
||||
try {
|
||||
((android.media.session.MediaSession) checkNotNull(mediaSessionCompat.getMediaSession()))
|
||||
.setMediaButtonBroadcastReceiver(broadcastReceiver);
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (Build.MANUFACTURER.equals("motorola")) {
|
||||
// Internal bug ref: b/367415658
|
||||
Log.e(
|
||||
TAG,
|
||||
"caught IllegalArgumentException on a motorola device when attempting to set the"
|
||||
+ " media button broadcast receiver. See"
|
||||
+ " https://github.com/androidx/media/issues/1730 for details.",
|
||||
e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user