From de6dc5414b89a33bbe7b639083ceb2aeae355e42 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 10 Apr 2025 11:58:49 +0530 Subject: [PATCH 1/2] Use native Bundle.toString() implementation --- .../main/java/org/schabi/newpipe/ktx/Bundle.kt | 13 ------------- .../org/schabi/newpipe/player/PlayerService.java | 16 ++++++++++------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/ktx/Bundle.kt b/app/src/main/java/org/schabi/newpipe/ktx/Bundle.kt index 1c73c5d7c25..c65b286cfa6 100644 --- a/app/src/main/java/org/schabi/newpipe/ktx/Bundle.kt +++ b/app/src/main/java/org/schabi/newpipe/ktx/Bundle.kt @@ -7,16 +7,3 @@ import java.io.Serializable inline fun Bundle.serializable(key: String?): T? { return BundleCompat.getSerializable(this, key, T::class.java) } - -fun Bundle?.toDebugString(): String { - if (this == null) { - return "null" - } - val string = StringBuilder("Bundle{") - for (key in this.keySet()) { - @Suppress("DEPRECATION") // we want this[key] to return items of any type - string.append(" ").append(key).append(" => ").append(this[key]).append(";") - } - string.append(" }") - return string.toString() -} diff --git a/app/src/main/java/org/schabi/newpipe/player/PlayerService.java b/app/src/main/java/org/schabi/newpipe/player/PlayerService.java index 1888bce019c..20740aacc8c 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PlayerService.java +++ b/app/src/main/java/org/schabi/newpipe/player/PlayerService.java @@ -37,7 +37,6 @@ import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector; -import org.schabi.newpipe.ktx.BundleKt; import org.schabi.newpipe.player.mediabrowser.MediaBrowserImpl; import org.schabi.newpipe.player.mediabrowser.MediaBrowserPlaybackPreparer; import org.schabi.newpipe.player.mediasession.MediaSessionPlayerUi; @@ -126,9 +125,11 @@ public void onCreate() { @Override public int onStartCommand(final Intent intent, final int flags, final int startId) { if (DEBUG) { - Log.d(TAG, "onStartCommand() called with: intent = [" + intent - + "], extras = [" + BundleKt.toDebugString(intent.getExtras()) - + "], flags = [" + flags + "], startId = [" + startId + "]"); + final var extras = intent.getExtras(); + // isEmpty unparcels the bundle + final var extrasString = extras != null && !extras.isEmpty() ? extras.toString() : ""; + Log.d(TAG, "onStartCommand() called with: intent = [" + intent + "], extras = [" + + extrasString + "], flags = [" + flags + "], startId = [" + startId + "]"); } // All internal NewPipe intents used to interact with the player, that are sent to the @@ -269,8 +270,11 @@ protected void attachBaseContext(final Context base) { @Override public IBinder onBind(final Intent intent) { if (DEBUG) { - Log.d(TAG, "onBind() called with: intent = [" + intent - + "], extras = [" + BundleKt.toDebugString(intent.getExtras()) + "]"); + final var extras = intent.getExtras(); + // isEmpty unparcels the bundle + final var extrasString = extras != null && !extras.isEmpty() ? extras.toString() : ""; + Log.d(TAG, "onBind() called with: intent = [" + intent + "], extras = [" + + extrasString + "]"); } if (BIND_PLAYER_HOLDER_ACTION.equals(intent.getAction())) { From 9c3fa3e08f7d595b1305d262c9f11f9adb53243a Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Tue, 15 Apr 2025 14:54:26 +0530 Subject: [PATCH 2/2] Add Intent extension --- .../main/java/org/schabi/newpipe/ktx/Intent.kt | 6 ++++++ .../org/schabi/newpipe/player/PlayerService.java | 16 ++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/ktx/Intent.kt diff --git a/app/src/main/java/org/schabi/newpipe/ktx/Intent.kt b/app/src/main/java/org/schabi/newpipe/ktx/Intent.kt new file mode 100644 index 00000000000..cdf475252a2 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/ktx/Intent.kt @@ -0,0 +1,6 @@ +package org.schabi.newpipe.ktx + +import android.content.Intent + +// isEmpty unparcels the extras +fun Intent.extrasString(): String = extras?.takeIf { !it.isEmpty }?.toString() ?: "" diff --git a/app/src/main/java/org/schabi/newpipe/player/PlayerService.java b/app/src/main/java/org/schabi/newpipe/player/PlayerService.java index 20740aacc8c..b273175ec02 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PlayerService.java +++ b/app/src/main/java/org/schabi/newpipe/player/PlayerService.java @@ -37,6 +37,7 @@ import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector; +import org.schabi.newpipe.ktx.IntentKt; import org.schabi.newpipe.player.mediabrowser.MediaBrowserImpl; import org.schabi.newpipe.player.mediabrowser.MediaBrowserPlaybackPreparer; import org.schabi.newpipe.player.mediasession.MediaSessionPlayerUi; @@ -125,11 +126,9 @@ public void onCreate() { @Override public int onStartCommand(final Intent intent, final int flags, final int startId) { if (DEBUG) { - final var extras = intent.getExtras(); - // isEmpty unparcels the bundle - final var extrasString = extras != null && !extras.isEmpty() ? extras.toString() : ""; - Log.d(TAG, "onStartCommand() called with: intent = [" + intent + "], extras = [" - + extrasString + "], flags = [" + flags + "], startId = [" + startId + "]"); + Log.d(TAG, "onStartCommand() called with: intent = [" + intent + "], " + + "extras = [" + IntentKt.extrasString(intent) + "], flags = [" + flags + "], " + + "startId = [" + startId + "]"); } // All internal NewPipe intents used to interact with the player, that are sent to the @@ -270,11 +269,8 @@ protected void attachBaseContext(final Context base) { @Override public IBinder onBind(final Intent intent) { if (DEBUG) { - final var extras = intent.getExtras(); - // isEmpty unparcels the bundle - final var extrasString = extras != null && !extras.isEmpty() ? extras.toString() : ""; - Log.d(TAG, "onBind() called with: intent = [" + intent + "], extras = [" - + extrasString + "]"); + Log.d(TAG, "onBind() called with: intent = [" + intent + "], " + + "extras = [" + IntentKt.extrasString(intent) + "]"); } if (BIND_PLAYER_HOLDER_ACTION.equals(intent.getAction())) {