androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.67k stars 397 forks source link

RemoteServiceException "Bad notification" when device language is set to chinese #1160

Open chop-suey opened 7 months ago

chop-suey commented 7 months ago

Version

Media3 main branch

More version details

1.2.1

Devices that reproduce the issue

Huawei Mate 40 Pro running Android 12

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

I do not have the affected device available

Expected result

The media plays successfully without crashing the app

Actual result

When playing media using a service that extends MediaSessionService the app crashes. This sounds similar to #903 but we do not use setWhen nor setShowWhen.

Stacktrace:

android.app.RemoteServiceException: Bad notification(tag=null, id=xxx) posted from package xx.xxx.xx, crashing app(uid=xxxxx, pid=xxxxx): long overflow
    at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2580)
    at android.app.ActivityThread.access$4000(ActivityThread.java:311)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2990)
    at android.os.Handler.dispatchMessage(Handler.java:117)
    at android.os.Looper.loopOnce(Looper.java:205)
    at android.os.Looper.loop(Looper.java:293)
    at android.app.ActivityThread.loopProcess(ActivityThread.java:9934)
    at android.app.ActivityThread.main(ActivityThread.java:9923)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:586)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1240)

Media

Do not have specific media at hand, but doubt that it is related to the actual media it probably has the following specs, though:

Format: AAC LC Codec ID: mp4a-40-2 Bit rate: 32.0 kb/s Channels: 1 channel Sampling rate: 44.1 kHz

Bug Report

tianyif commented 7 months ago

Hi @chop-suey,

Thanks for reporting! Could you please provide us the steps to reproduce on the demo app?

chop-suey commented 7 months ago

Hi @tianyif Thanks for getting back. Unfortunetaly i cannot reproduce this issue, since it only happens on some devices i do not have at hand. What i forgot to mention, but might be quite important: It only happens when the device language is set to chinese.

There seems to be a problem when the notification for the foreground service is shown in that language. #903 implicates there might be some problem with the duration of the media. But i am not quite sure if that correlates to a language dependent problem.

What we do:

icbaker commented 7 months ago

In case it helps debug further, that exception seems to originate here in the framework: https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/services/core/java/com/android/server/notification/NotificationManagerService.java;l=1396;drc=c11765ac782525cb803ac13886bd61dcdf71e33b

And the message "long overflow" probably comes from an invocation of one of the Math.xxxExact methods: https://cs.android.com/android/platform/superproject/main/+/main:libcore/ojluni/src/main/java/java/lang/Math.java

Unfortunately we're obviously missing the stack trace to indicate where the ArithmeticException is being thrown from.

I wonder if we need to look at the other place we call setWhen?

https://github.com/androidx/media/blob/d13a0f4ec62ca092b79746a5725b62a3244cc5b4/libraries/ui/src/main/java/androidx/media3/ui/PlayerNotificationManager.java#L1309

It doesn't look obviously problematic though...

Aside: I'm not sure how this code interacts with live playback, when getContentPosition returns a negative value (https://developer.android.com/media/media3/exoplayer/live-streaming). I think that results in a 'future' timestamp on the notification, which looks like it's permitted: https://developer.android.com/reference/android/app/Notification#when