From 2b582b540aaa0ba5981ca5922e8a6e64fd76ce89 Mon Sep 17 00:00:00 2001 From: ibaker Date: Mon, 26 Apr 2021 09:42:08 +0100 Subject: [PATCH] Add thread names to the 'player accessed on wrong thread' message This will help app developers identify which thread is being used and which is expected. PiperOrigin-RevId: 370409697 --- .../android/exoplayer2/SimpleExoPlayer.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java index b6e5d9140e..bed3526dd8 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java @@ -588,9 +588,6 @@ public class SimpleExoPlayer extends BasePlayer } private static final String TAG = "SimpleExoPlayer"; - private static final String WRONG_THREAD_ERROR_MESSAGE = - "Player is accessed on the wrong thread. See " - + "https://exoplayer.dev/issues/player-accessed-on-wrong-thread"; protected final Renderer[] renderers; @@ -2014,13 +2011,18 @@ public class SimpleExoPlayer extends BasePlayer // the app thread until the constructor finished executing. constructorFinished.blockUninterruptible(); if (Looper.myLooper() != getApplicationLooper()) { + String message = + Util.formatInvariant( + "Player is accessed on the wrong thread.\n" + + "Current thread: '%s'\n" + + "Expected thread: '%s'\n" + + "See https://exoplayer.dev/issues/player-accessed-on-wrong-thread", + Looper.myLooper().getThread().getName(), + getApplicationLooper().getThread().getName()); if (throwsWhenUsingWrongThread) { - throw new IllegalStateException(WRONG_THREAD_ERROR_MESSAGE); + throw new IllegalStateException(message); } - Log.w( - TAG, - WRONG_THREAD_ERROR_MESSAGE, - hasNotifiedFullWrongThreadWarning ? null : new IllegalStateException()); + Log.w(TAG, message, hasNotifiedFullWrongThreadWarning ? null : new IllegalStateException()); hasNotifiedFullWrongThreadWarning = true; } }