Skip to content

Commit d6a1170

Browse files
committed
Replace settings migration with automatic check for device blacklist version
1 parent 40d102f commit d6a1170

6 files changed

Lines changed: 85 additions & 45 deletions

File tree

app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,10 @@ private void cleanImport(@NonNull final Context context,
267267
// R.string.disabled_media_tunneling_automatically_key == 0:
268268
// automatic value overridden by user in settings
269269
// R.string.disabled_media_tunneling_automatically_key == -1: not set
270-
final boolean wasMediaTunnelingEnabledAutomatically =
270+
final boolean wasMediaTunnelingDisabledAutomatically =
271271
prefs.getInt(automaticTunnelingKey, -1) == 1
272272
&& prefs.getBoolean(tunnelingKey, false);
273-
if (wasMediaTunnelingEnabledAutomatically) {
273+
if (wasMediaTunnelingDisabledAutomatically) {
274274
prefs.edit()
275275
.putInt(automaticTunnelingKey, -1)
276276
.putBoolean(tunnelingKey, false)

app/src/main/java/org/schabi/newpipe/settings/ExoPlayerSettingsFragment.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ public void onCreatePreferences(@Nullable final Bundle savedInstanceState,
1717
@Nullable final String rootKey) {
1818
addPreferencesFromResourceRegistry();
1919

20-
final String disableMediaTunnelingAutomaticallyKey =
20+
final String disabledMediaTunnelingAutomaticallyKey =
2121
getString(R.string.disabled_media_tunneling_automatically_key);
2222
final SwitchPreferenceCompat disableMediaTunnelingPref =
2323
(SwitchPreferenceCompat) requirePreference(R.string.disable_media_tunneling_key);
2424
final SharedPreferences prefs = PreferenceManager
2525
.getDefaultSharedPreferences(requireContext());
26-
final boolean mediaTunnelingAutomaticallyEnabled =
27-
prefs.getInt(disableMediaTunnelingAutomaticallyKey, -1) == 1;
26+
final boolean mediaTunnelingAutomaticallyDisabled =
27+
prefs.getInt(disabledMediaTunnelingAutomaticallyKey, -1) == 1;
2828
final String summaryText = getString(R.string.disable_media_tunneling_summary);
29-
disableMediaTunnelingPref.setSummary(mediaTunnelingAutomaticallyEnabled
30-
? summaryText + getString(R.string.disable_media_tunneling_automatic_info)
29+
disableMediaTunnelingPref.setSummary(mediaTunnelingAutomaticallyDisabled
30+
? summaryText + " " + getString(R.string.disable_media_tunneling_automatic_info)
3131
: summaryText);
3232

3333
disableMediaTunnelingPref.setOnPreferenceChangeListener((Preference p, Object enabled) -> {
3434
if (Boolean.FALSE.equals(enabled)) {
3535
PreferenceManager.getDefaultSharedPreferences(requireContext())
3636
.edit()
37-
.putInt(disableMediaTunnelingAutomaticallyKey, 0)
37+
.putInt(disabledMediaTunnelingAutomaticallyKey, 0)
3838
.apply();
3939
// the info text might have been shown before
4040
p.setSummary(R.string.disable_media_tunneling_summary);

app/src/main/java/org/schabi/newpipe/settings/NewPipeSettings.java

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.schabi.newpipe.settings;
22

3+
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
4+
35
import android.content.Context;
46
import android.content.SharedPreferences;
57
import android.os.Build;
@@ -15,8 +17,6 @@
1517
import java.io.File;
1618
import java.util.Set;
1719

18-
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
19-
2020
/*
2121
* Created by k3b on 07.01.2016.
2222
*
@@ -61,7 +61,7 @@ public static void initSettings(final Context context) {
6161
}
6262

6363
// first run migrations, then setDefaultValues, since the latter requires the correct types
64-
SettingMigrations.initMigrations(context, isFirstRun);
64+
SettingMigrations.runMigrationsIfNeeded(context, isFirstRun);
6565

6666
// readAgain is true so that if new settings are added their default value is set
6767
PreferenceManager.setDefaultValues(context, R.xml.main_settings, true);
@@ -77,9 +77,7 @@ public static void initSettings(final Context context) {
7777
saveDefaultVideoDownloadDirectory(context);
7878
saveDefaultAudioDownloadDirectory(context);
7979

80-
if (isFirstRun) { // NOSONAR: isFirstRun is never null
81-
setMediaTunneling(context);
82-
}
80+
disableMediaTunnelingIfNecessary(context, isFirstRun);
8381
}
8482

8583
static void saveDefaultVideoDownloadDirectory(final Context context) {
@@ -157,19 +155,48 @@ public static boolean showRemoteSearchSuggestions(final Context context,
157155
R.string.show_remote_search_suggestions_key);
158156
}
159157

158+
private static void disableMediaTunnelingIfNecessary(@NonNull final Context context,
159+
final boolean isFirstRun) {
160+
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
161+
final String disabledTunnelingKey = context.getString(R.string.disable_media_tunneling_key);
162+
final String disabledTunnelingAutomaticallyKey =
163+
context.getString(R.string.disabled_media_tunneling_automatically_key);
164+
final String blacklistVersionKey =
165+
context.getString(R.string.media_tunneling_device_blacklist_version);
166+
167+
final int lastMediaTunnelingUpdate = prefs.getInt(blacklistVersionKey, 0);
168+
final boolean wasDeviceBlacklistUpdated =
169+
DeviceUtils.MEDIA_TUNNELING_DEVICE_BLACKLIST_VERSION != lastMediaTunnelingUpdate;
170+
final boolean wasMediaTunnelingEnabledByUser =
171+
prefs.getInt(disabledTunnelingAutomaticallyKey, -1) == 0
172+
&& !prefs.getBoolean(disabledTunnelingKey, false);
173+
174+
if (Boolean.TRUE.equals(isFirstRun)
175+
|| (wasDeviceBlacklistUpdated && !wasMediaTunnelingEnabledByUser)) {
176+
setMediaTunneling(context);
177+
}
178+
}
179+
160180
/**
161181
* Check if device does not support media tunneling
162182
* and disable that exoplayer feature if necessary.
163183
* @see DeviceUtils#shouldSupportMediaTunneling()
164184
* @param context
165185
*/
166186
public static void setMediaTunneling(@NonNull final Context context) {
187+
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
167188
if (!DeviceUtils.shouldSupportMediaTunneling()) {
168-
PreferenceManager.getDefaultSharedPreferences(context).edit()
189+
prefs.edit()
169190
.putBoolean(context.getString(R.string.disable_media_tunneling_key), true)
170191
.putInt(context.getString(
171192
R.string.disabled_media_tunneling_automatically_key), 1)
193+
.putInt(context.getString(R.string.media_tunneling_device_blacklist_version),
194+
DeviceUtils.MEDIA_TUNNELING_DEVICE_BLACKLIST_VERSION)
172195
.apply();
196+
} else {
197+
prefs.edit()
198+
.putInt(context.getString(R.string.media_tunneling_device_blacklist_version),
199+
DeviceUtils.MEDIA_TUNNELING_DEVICE_BLACKLIST_VERSION).apply();
173200
}
174201
}
175202
}

app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,6 @@ protected void migrate(@NonNull final Context context) {
128128
}
129129
};
130130

131-
private static final Migration MIGRATION_5_6 = new Migration(5, 6) {
132-
@Override
133-
protected void migrate(@NonNull final Context context) {
134-
// PR #8875 added a new settings page for exoplayer introducing a specific setting
135-
// to disable media tunneling. However, media tunneling should be disabled by default
136-
// for some devices, because they are known for not supporting media tunneling
137-
// which can result in a black screen while playing videos.
138-
NewPipeSettings.setMediaTunneling(context);
139-
}
140-
};
141-
142131
/**
143132
* List of all implemented migrations.
144133
* <p>
@@ -151,16 +140,16 @@ protected void migrate(@NonNull final Context context) {
151140
MIGRATION_2_3,
152141
MIGRATION_3_4,
153142
MIGRATION_4_5,
154-
MIGRATION_5_6,
155143
};
156144

157145
/**
158146
* Version number for preferences. Must be incremented every time a migration is necessary.
159147
*/
160-
private static final int VERSION = 6;
148+
private static final int VERSION = 5;
161149

162150

163-
public static void initMigrations(@NonNull final Context context, final boolean isFirstRun) {
151+
public static void runMigrationsIfNeeded(@NonNull final Context context,
152+
final boolean isFirstRun) {
164153
// setup migrations and check if there is something to do
165154
sp = PreferenceManager.getDefaultSharedPreferences(context);
166155
final String lastPrefVersionKey = context.getString(R.string.last_used_preferences_version);

app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,32 @@ public final class DeviceUtils {
3636
private static Boolean isTV = null;
3737
private static Boolean isFireTV = null;
3838

39+
/**
40+
* <p>The app version code that corresponds to the last update
41+
* of the media tunneling device blacklist.</p>
42+
* <p>The value of this variable needs to be updated everytime a new device that does not
43+
* support media tunneling to match the <strong>upcoming</strong> version code.</p>
44+
* @see #shouldSupportMediaTunneling()
45+
*/
46+
public static final int MEDIA_TUNNELING_DEVICE_BLACKLIST_VERSION = 994;
3947

40-
// region: devices not supporting media tunneling
48+
// region: devices not supporting media tunneling / media tunneling blacklist
4149
/**
42-
* Formuler Z8 Pro, Z8, CC, Z Alpha, Z+ Neo.
50+
* <p>Formuler Z8 Pro, Z8, CC, Z Alpha, Z+ Neo.</p>
51+
* <p>Blacklist reason: black screen</p>
52+
* <p>Board: HiSilicon Hi3798MV200</p>
4353
*/
4454
private static final boolean HI3798MV200 = Build.VERSION.SDK_INT == 24
4555
&& Build.DEVICE.equals("Hi3798MV200");
4656
/**
47-
* Zephir TS43UHD-2.
57+
* <p>Zephir TS43UHD-2.</p>
58+
* <p>Blacklist reason: black screen</p>
4859
*/
4960
private static final boolean CVT_MT5886_EU_1G = Build.VERSION.SDK_INT == 24
5061
&& Build.DEVICE.equals("cvt_mt5886_eu_1g");
5162
/**
5263
* Hilife TV.
64+
* <p>Blacklist reason: black screen</p>
5365
*/
5466
private static final boolean REALTEKATV = Build.VERSION.SDK_INT == 25
5567
&& Build.DEVICE.equals("RealtekATV");
@@ -60,19 +72,23 @@ public final class DeviceUtils {
6072
private static final boolean PH7M_EU_5596 = Build.VERSION.SDK_INT >= 26
6173
&& Build.DEVICE.equals("PH7M_EU_5596");
6274
/**
63-
* Philips QM16XE.
75+
* <p>Philips QM16XE.</p>
76+
* <p>Blacklist reason: black screen</p>
6477
*/
6578
private static final boolean QM16XE_U = Build.VERSION.SDK_INT == 23
6679
&& Build.DEVICE.equals("QM16XE_U");
6780
/**
6881
* <p>Sony Bravia VH1.</p>
69-
* Processor: MT5895
82+
* <p>Processor: MT5895</p>
83+
* <p>Blacklist reason: fullscreen crash / stuttering</p>
7084
*/
7185
private static final boolean BRAVIA_VH1 = Build.VERSION.SDK_INT == 29
7286
&& Build.DEVICE.equals("BRAVIA_VH1");
7387
/**
7488
* <p>Sony Bravia VH2.</p>
75-
* This includes model A90J.
89+
* <p>Blacklist reason: fullscreen crash; this includes model A90J as reported in
90+
* <a href="https://github.com/TeamNewPipe/NewPipe/issues/9023#issuecomment-1387106242">
91+
* #9023</a></p>
7692
*/
7793
private static final boolean BRAVIA_VH2 = Build.VERSION.SDK_INT == 29
7894
&& Build.DEVICE.equals("BRAVIA_VH2");
@@ -85,18 +101,22 @@ public final class DeviceUtils {
85101
private static final boolean BRAVIA_ATV2 = Build.DEVICE.equals("BRAVIA_ATV2");
86102
/**
87103
* <p>Sony Bravia Android TV platform 3 4K.</p>
88-
* Uses ARM MT5891 and a {@link #BRAVIA_ATV2} motherboard.
104+
* <p>Uses ARM MT5891 and a {@link #BRAVIA_ATV2} motherboard.</p>
105+
*
89106
* @see <a href="https://browser.geekbench.com/v4/cpu/9101105">
90107
* https://browser.geekbench.com/v4/cpu/9101105</a>
91108
*/
92109
private static final boolean BRAVIA_ATV3_4K = Build.DEVICE.equals("BRAVIA_ATV3_4K");
93110
/**
94-
* Panasonic 4KTV-JUP.
111+
* <p>Panasonic 4KTV-JUP.</p>
112+
* <p>Blacklist reason: fullscreen crash</p>
95113
*/
96114
private static final boolean TX_50JXW834 = Build.DEVICE.equals("TX_50JXW834");
97115
/**
98116
* <p>Bouygtel4K / Bouygues Telecom Bbox 4K.</p>
99-
* Reported at https://github.com/TeamNewPipe/NewPipe/pull/10122#issuecomment-1638475769
117+
* <p>Blacklist reason: black screen; reported at
118+
* <a href="https://github.com/TeamNewPipe/NewPipe/pull/10122#issuecomment-1638475769">
119+
* #10122</a></p>
100120
*/
101121
private static final boolean HMB9213NW = Build.DEVICE.equals("HMB9213NW");
102122
// endregion
@@ -292,24 +312,27 @@ public static int getWindowHeight(@NonNull final WindowManager windowManager) {
292312

293313
/**
294314
* <p>Some devices have broken tunneled video playback but claim to support it.</p>
295-
* See https://github.com/TeamNewPipe/NewPipe/issues/5911
296-
* @Note Add a new {@link org.schabi.newpipe.settings.SettingMigrations.Migration} which calls
297-
* {@link org.schabi.newpipe.settings.NewPipeSettings#setMediaTunneling(Context)}
315+
* <p>This can cause a black video player surface while attempting to play a video or
316+
* crashes while entering or exiting the full screen player.
317+
* The issue effects Android TVs most commonly.
318+
* See <a href="https://github.com/TeamNewPipe/NewPipe/issues/5911">#5911</a> and
319+
* <a href="https://github.com/TeamNewPipe/NewPipe/issues/9023">#9023</a> for more info.</p>
320+
* @Note Update {@link #MEDIA_TUNNELING_DEVICE_BLACKLIST_VERSION}
298321
* when adding a new device to the method.
299322
* @return {@code false} if affected device; {@code true} otherwise
300323
*/
301324
public static boolean shouldSupportMediaTunneling() {
302-
// Maintainers note: add a new SettingsMigration which calls
325+
// Maintainers note: update MEDIA_TUNNELING_DEVICES_UPDATE_APP_VERSION_CODE
303326
return !HI3798MV200
304327
&& !CVT_MT5886_EU_1G
305328
&& !REALTEKATV
306329
&& !QM16XE_U
307330
&& !BRAVIA_VH1
308331
&& !BRAVIA_VH2
309-
&& !BRAVIA_ATV2 // crash caused by exiting full screen
310-
&& !BRAVIA_ATV3_4K // crash caused by exiting full screen
332+
&& !BRAVIA_ATV2
333+
&& !BRAVIA_ATV3_4K
311334
&& !PH7M_EU_5596
312335
&& !TX_50JXW834
313-
&& !HMB9213NW; // crash caused by exiting full screen
336+
&& !HMB9213NW;
314337
}
315338
}

app/src/main/res/values/settings_keys.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,7 @@
13831383
<string name="exoplayer_settings_key">exoplayer_settings_key</string>
13841384
<string name="disable_media_tunneling_key">disable_media_tunneling_key</string>
13851385
<string name="disabled_media_tunneling_automatically_key">disabled_media_tunneling_automatically_key</string>
1386+
<string name="media_tunneling_device_blacklist_version">media_tunneling_device_blacklist_version</string>
13861387
<string name="use_exoplayer_decoder_fallback_key">use_exoplayer_decoder_fallback_key</string>
13871388
<string name="always_use_exoplayer_set_output_surface_workaround_key">always_use_exoplayer_set_output_surface_workaround_key</string>
13881389
</resources>

0 commit comments

Comments
 (0)