From caf7c55069804dce58b4be8e9df5b8211ae5ac78 Mon Sep 17 00:00:00 2001 From: wb9688 Date: Fri, 15 May 2020 15:05:20 +0200 Subject: [PATCH] Log only in debug build --- .../newpipe/player/NotificationUtil.java | 16 +++++-- .../player/helper/MediaSessionManager.java | 48 ++++++++++--------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java b/app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java index 62f25810b..d88a26b2f 100644 --- a/app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java +++ b/app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java @@ -75,7 +75,9 @@ public final class NotificationUtil { if (areOldNotificationsEnabled) { notificationBuilder = createOldPopupPlayerNotification(context, playerImpl); } else if (notificationBuilder == null || recreate) { - Log.d(TAG, "N_ recreatePopupPlayerNotification(true)"); + if (DEBUG) { + Log.d(TAG, "N_ recreatePopupPlayerNotification(true)"); + } notificationBuilder = createPopupPlayerNotification(context, mediaSessionCompatToken, playerImpl, sharedPreferences); } @@ -91,7 +93,9 @@ public final class NotificationUtil { if (areOldNotificationsEnabled) { notificationBuilder = createOldPopupPlayerNotification(context, playerImpl); } else if (notificationBuilder == null) { - Log.d(TAG, "N_ recreatePopupPlayerNotification()"); + if (DEBUG) { + Log.d(TAG, "N_ recreatePopupPlayerNotification()"); + } notificationBuilder = createPopupPlayerNotification(context, mediaSessionCompatToken, playerImpl, sharedPreferences); } @@ -105,7 +109,9 @@ public final class NotificationUtil { final boolean areOldNotificationsEnabled = sharedPreferences .getBoolean(context.getString(R.string.enable_old_notifications_key), false); if (notificationBuilder == null || recreate || areOldNotificationsEnabled) { - Log.d(TAG, "N_ recreateBackgroundPlayerNotification(true)"); + if (DEBUG) { + Log.d(TAG, "N_ recreateBackgroundPlayerNotification(true)"); + } notificationBuilder = createBackgroundPlayerNotification(context, mediaSessionCompatToken, basePlayerImpl, sharedPreferences); } @@ -119,7 +125,9 @@ public final class NotificationUtil { final boolean areOldNotificationsEnabled = sharedPreferences .getBoolean(context.getString(R.string.enable_old_notifications_key), false); if (notificationBuilder == null || areOldNotificationsEnabled) { - Log.d(TAG, "N_ recreateBackgroundPlayerNotification()"); + if (DEBUG) { + Log.d(TAG, "N_ recreateBackgroundPlayerNotification()"); + } notificationBuilder = createBackgroundPlayerNotification(context, mediaSessionCompatToken, basePlayerImpl, sharedPreferences); } diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/MediaSessionManager.java b/app/src/main/java/org/schabi/newpipe/player/helper/MediaSessionManager.java index d0939a914..3bb2965a2 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/MediaSessionManager.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/MediaSessionManager.java @@ -16,12 +16,14 @@ import androidx.media.session.MediaButtonReceiver; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector; +import org.schabi.newpipe.BuildConfig; import org.schabi.newpipe.player.mediasession.MediaSessionCallback; import org.schabi.newpipe.player.mediasession.PlayQueueNavigator; import org.schabi.newpipe.player.mediasession.PlayQueuePlaybackController; public class MediaSessionManager { private static final String TAG = "MediaSessionManager"; + public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release"); @NonNull private final MediaSessionCompat mediaSession; @@ -72,33 +74,35 @@ public class MediaSessionManager { return; } - if (getMetadataAlbumArt() == null) { - Log.d(TAG, "N_getMetadataAlbumArt: thumb == null"); - } - if (getMetadataTitle() == null) { - Log.d(TAG, "N_getMetadataTitle: title == null"); - } - if (getMetadataArtist() == null) { - Log.d(TAG, "N_getMetadataArtist: artist == null"); - } - if (getMetadataDuration() <= 1) { - Log.d(TAG, "N_getMetadataDuration: duration <= 1; " + getMetadataDuration()); + if (DEBUG) { + if (getMetadataAlbumArt() == null) { + Log.d(TAG, "N_getMetadataAlbumArt: thumb == null"); + } + if (getMetadataTitle() == null) { + Log.d(TAG, "N_getMetadataTitle: title == null"); + } + if (getMetadataArtist() == null) { + Log.d(TAG, "N_getMetadataArtist: artist == null"); + } + if (getMetadataDuration() <= 1) { + Log.d(TAG, "N_getMetadataDuration: duration <= 1; " + getMetadataDuration()); + } } if (getMetadataAlbumArt() == null || getMetadataTitle() == null || getMetadataArtist() == null || getMetadataDuration() <= 1 || albumArt.hashCode() != tmpThumbHash) { - Log.d(TAG, "setMetadata: N_Metadata update: t: " + title + " a: " + artist - + " thumb: " + albumArt.hashCode() + " d: " + duration); - mediaSession.setMetadata( - new MediaMetadataCompat.Builder() - .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title) - .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist) - .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt) - .putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, albumArt) - .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration) - .build() - ); + if (DEBUG) { + Log.d(TAG, "setMetadata: N_Metadata update: t: " + title + " a: " + artist + + " thumb: " + albumArt.hashCode() + " d: " + duration); + } + + mediaSession.setMetadata(new MediaMetadataCompat.Builder() + .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title) + .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist) + .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt) + .putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, albumArt) + .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration).build()); tmpThumbHash = albumArt.hashCode(); } }