From 8290449fed9ae1017b24b15831890fe98ebf15cb Mon Sep 17 00:00:00 2001 From: TobiGr Date: Fri, 26 May 2023 14:47:03 +0200 Subject: [PATCH] Disable media tunneling if the device is known for not supporting it Revert removing the Utils related to media tunneling. --- .../newpipe/settings/NewPipeSettings.java | 18 +++++++++++ .../newpipe/settings/SettingMigrations.java | 14 +++++++- .../org/schabi/newpipe/util/DeviceUtils.java | 32 +++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/NewPipeSettings.java b/app/src/main/java/org/schabi/newpipe/settings/NewPipeSettings.java index 16df646f981..9e246574ef0 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/NewPipeSettings.java +++ b/app/src/main/java/org/schabi/newpipe/settings/NewPipeSettings.java @@ -76,6 +76,10 @@ public static void initSettings(final Context context) { saveDefaultVideoDownloadDirectory(context); saveDefaultAudioDownloadDirectory(context); + + if (isFirstRun) { // NOSONAR: isFirstRun is never null + setMediaTunneling(context); + } } static void saveDefaultVideoDownloadDirectory(final Context context) { @@ -152,4 +156,18 @@ public static boolean showRemoteSearchSuggestions(final Context context, return showSearchSuggestions(context, sharedPreferences, R.string.show_remote_search_suggestions_key); } + + /** + * Check if device does not support media tunneling + * and disable that exoplayer feature if necessary. + * @see DeviceUtils#shouldSupportMediaTunneling() + * @param context + */ + public static void setMediaTunneling(@NonNull final Context context) { + if (!DeviceUtils.shouldSupportMediaTunneling()) { + PreferenceManager.getDefaultSharedPreferences(context).edit() + .putBoolean(context.getString(R.string.disable_media_tunneling_key), true) + .apply(); + } + } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java b/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java index bf691dc2850..8b8dddbade2 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java @@ -128,6 +128,17 @@ protected void migrate(@NonNull final Context context) { } }; + private static final Migration MIGRATION_5_6 = new Migration(5, 6) { + @Override + protected void migrate(@NonNull final Context context) { + // PR #8875 added a new settings page for exoplayer introducing a specific setting + // to disable media tunneling. However, media tunneling should be disabled by default + // for some devices, because they are known for not supporting media tunneling + // which can result in a black screen while playing videos. + NewPipeSettings.setMediaTunneling(context); + } + }; + /** * List of all implemented migrations. *

@@ -140,12 +151,13 @@ protected void migrate(@NonNull final Context context) { MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5, + MIGRATION_5_6, }; /** * Version number for preferences. Must be incremented every time a migration is necessary. */ - private static final int VERSION = 5; + private static final int VERSION = 6; public static void initMigrations(@NonNull final Context context, final boolean isFirstRun) { diff --git a/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java b/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java index f656c61446a..b0e6026ec8f 100644 --- a/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java +++ b/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java @@ -36,6 +36,22 @@ public final class DeviceUtils { private static Boolean isTV = null; private static Boolean isFireTV = null; + /* + * Devices that do not support media tunneling + */ + // Formuler Z8 Pro, Z8, CC, Z Alpha, Z+ Neo + private static final boolean HI3798MV200 = Build.VERSION.SDK_INT == 24 + && Build.DEVICE.equals("Hi3798MV200"); + // Zephir TS43UHD-2 + private static final boolean CVT_MT5886_EU_1G = Build.VERSION.SDK_INT == 24 + && Build.DEVICE.equals("cvt_mt5886_eu_1g"); + // Hilife TV + private static final boolean REALTEKATV = Build.VERSION.SDK_INT == 25 + && Build.DEVICE.equals("RealtekATV"); + // Philips QM16XE + private static final boolean QM16XE_U = Build.VERSION.SDK_INT == 23 + && Build.DEVICE.equals("QM16XE_U"); + private DeviceUtils() { } @@ -224,4 +240,20 @@ public static int getWindowHeight(@NonNull final WindowManager windowManager) { return point.y; } } + + /** + * Some devices have broken tunneled video playback but claim to support it. + * See https://github.com/TeamNewPipe/NewPipe/issues/5911 + * @Note Add a new {@link org.schabi.newpipe.settings.SettingMigrations.Migration} which calls + * {@link org.schabi.newpipe.settings.NewPipeSettings#setMediaTunneling(Context)} + * when adding a new device to the method + * @return {@code false} if affected device; {@code true} otherwise + */ + public static boolean shouldSupportMediaTunneling() { + // Maintainers note: add a new SettingsMigration which calls + return !HI3798MV200 + && !CVT_MT5886_EU_1G + && !REALTEKATV + && !QM16XE_U; + } }