From 3670541465ceb96fc918cd7741c02b95ccd907e1 Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 14 Jul 2021 00:25:24 +0100 Subject: [PATCH] Add option to disable 5G-NSA disambiguation PiperOrigin-RevId: 384575860 --- .../android/exoplayer2/util/NetworkTypeObserver.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/util/NetworkTypeObserver.java b/library/core/src/main/java/com/google/android/exoplayer2/util/NetworkTypeObserver.java index fb43396156..488c7947cc 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/util/NetworkTypeObserver.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/util/NetworkTypeObserver.java @@ -59,6 +59,7 @@ public final class NetworkTypeObserver { } @Nullable private static NetworkTypeObserver staticInstance; + private static volatile boolean disable5GNsaDisambiguation; private final Handler mainHandler; // This class needs to hold weak references as it doesn't require listeners to unregister. @@ -69,6 +70,11 @@ public final class NetworkTypeObserver { @C.NetworkType private int networkType; + /** Disables logic to disambiguate 5G-NSA networks from 4G networks. */ + public static void disable5GNsaDisambiguation() { + disable5GNsaDisambiguation = true; + } + /** * Returns a network type observer instance. * @@ -217,7 +223,7 @@ public final class NetworkTypeObserver { @Override public void onReceive(Context context, Intent intent) { @C.NetworkType int networkType = getNetworkTypeFromConnectivityManager(context); - if (networkType == C.NETWORK_TYPE_4G && Util.SDK_INT >= 29) { + if (Util.SDK_INT >= 29 && !disable5GNsaDisambiguation && networkType == C.NETWORK_TYPE_4G) { // Delay update of the network type to check whether this is actually 5G-NSA. try { // We can't access TelephonyManager getters like getServiceState() directly as they