MediaSession crashes with "packageName should be nonempty" when a media button event's sender package is empty

オープン
#3,563 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 4 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
android, java

調査の方向性

Start with MediaSessionCompat.MediaSessionImplApi28.getCurrentControllerInfo() and the RemoteUserInfo constructor mentioned in the stack trace, then inspect related tests for controller information and media button events. Reproduce the empty-package case on Android 11 or 12, or with the described API 37 binder call. Done means the event no longer crashes the app and the sender is treated as an unknown, untrusted controller.

索引モデルが issue の本文から書いたものです。

説明

bug needs triage
Version

Media3 1.11.1

More version details

Also present on main.
MediaSessionLegacyStub.onMediaButtonEvent builds a ControllerInfo from sessionCompat.getCurrentControllerInfo(). On API 28+ that is MediaSessionImplApi28.getCurrentControllerInfo(), which wraps the platform's MediaSession.getCurrentControllerInfo() in new RemoteUserInfo(info), and that constructor throws IllegalArgumentException when the package name is empty. The constructor's own comment says the platform does not guarantee a non-empty package, and the platform does deliver one: on Android 11 and 12 MediaShellCommand dispatches keys with PACKAGE_NAME = "" ("This doesn't belongs to any package"), and MediaSessionService passes the caller's package to the session without checking it (still true on main). The exception is thrown on the session's application looper before MediaSession.Callback.onMediaButtonEvent runs, so an app cannot catch it.

Devices that reproduce the issue
  • A JOYAR device on Android 11, in production (crash report below).
  • Android emulator, API 37 (sdk_gphone64_x86_64), sending the key with an empty package through ISessionManager.dispatchMediaKeyEvent (steps below).
Devices that do not reproduce the issue

The same emulator with the same call and package com.android.shell: the key is handled normally.

Reproducible in the demo app?

Not tested

Reproduction steps
  1. Play media in an app whose MediaSession is the media button session (adb shell dumpsys media_session shows it as the media button session).
  2. Android 11 or 12: adb shell cmd media_session dispatch play-pause.
    Android 13 and later fill in com.android.shell for the shell command, so call the binder method directly with an empty package (transaction 5 is dispatchMediaKeyEvent on that API 37 image; the arguments are a KeyEvent parcel, sent once with ACTION_DOWN and once with ACTION_UP):
    adb shell 'service call media_session 5 s16 "" i32 0 i32 1 i32 2 i32 4242 i32 -1 i32 257 i32 0 i32 -1 i32 0 i32 85 i32 0 i32 0 i32 0 i32 0 i64 0 i64 0 i32 -1 i32 0; service call media_session 5 s16 "" i32 0 i32 1 i32 2 i32 4243 i32 -1 i32 257 i32 0 i32 -1 i32 1 i32 85 i32 0 i32 0 i32 0 i32 0 i64 0 i64 0 i32 -1 i32 0'
    
Expected result

The key event is handled, or ignored, with the sender treated as an unknown, untrusted controller. MediaSessionImplBase already does this below API 24 by returning RemoteUserInfo.LEGACY_CONTROLLER.

Actual result

The app process dies:

FATAL EXCEPTION: ExoPlayerThread
java.lang.IllegalArgumentException: packageName should be nonempty
  at androidx.media3.session.legacy.MediaSessionManager$RemoteUserInfo.<init>(MediaSessionManager.java:159)
  at androidx.media3.session.legacy.MediaSessionCompat$MediaSessionImplApi28.getCurrentControllerInfo(MediaSessionCompat.java:2284)
  at androidx.media3.session.legacy.MediaSessionCompat.getCurrentControllerInfo(MediaSessionCompat.java:678)
  at androidx.media3.session.MediaSessionLegacyStub.onMediaButtonEvent(MediaSessionLegacyStub.java:537)
  at androidx.media3.session.legacy.MediaSessionCompat$Callback$MediaSessionCallback.onMediaButtonEvent(MediaSessionCompat.java:1142)
  at android.media.session.MediaSession$CallbackMessageHandler.handleMessage(MediaSession.java:1566)
  at android.os.Handler.dispatchMessage(Handler.java:106)
  at android.os.Looper.loop(Looper.java:223)
  at android.os.HandlerThread.run(HandlerThread.java:67)

A suggested fix, in MediaSessionCompat.MediaSessionImplApi28.getCurrentControllerInfo():

android.media.session.MediaSessionManager.RemoteUserInfo info =
    sessionFwk.getCurrentControllerInfo();
if (TextUtils.isEmpty(info.getPackageName())) {
  return new RemoteUserInfo(RemoteUserInfo.LEGACY_CONTROLLER, info.getPid(), info.getUid());
}
return new RemoteUserInfo(info);
Media

Not applicable: any playing item reproduces it.

Bug Report
  • You will email the zip file produced by adb bugreport to [email protected] after filing this issue.
主要言語
Java
スター
3.1k
フォーク
1k
平均マージ
6日 4時間
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

androidx/media のほかの issue

androidx/media の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。