Move NetworkTypeObserver 5G-NSA config to separate Config class
PiperOrigin-RevId: 386970718
This commit is contained in:
parent
9e615ce5f3
commit
f53f44c9c3
@ -58,9 +58,26 @@ public final class NetworkTypeObserver {
|
||||
void onNetworkTypeChanged(@C.NetworkType int networkType);
|
||||
}
|
||||
|
||||
@Nullable private static NetworkTypeObserver staticInstance;
|
||||
/*
|
||||
* Static configuration that may need to be set at app startup time is located in a separate
|
||||
* static Config class. This allows apps to set their desired config without incurring unnecessary
|
||||
* class loading costs during startup.
|
||||
*/
|
||||
/** Configuration for {@link NetworkTypeObserver}. */
|
||||
public static final class Config {
|
||||
|
||||
private static volatile boolean disable5GNsaDisambiguation;
|
||||
|
||||
/** Disables logic to disambiguate 5G-NSA networks from 4G networks. */
|
||||
public static void disable5GNsaDisambiguation() {
|
||||
disable5GNsaDisambiguation = true;
|
||||
}
|
||||
|
||||
private Config() {}
|
||||
}
|
||||
|
||||
@Nullable private static NetworkTypeObserver staticInstance;
|
||||
|
||||
private final Handler mainHandler;
|
||||
// This class needs to hold weak references as it doesn't require listeners to unregister.
|
||||
private final CopyOnWriteArrayList<WeakReference<Listener>> listeners;
|
||||
@ -70,11 +87,6 @@ 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.
|
||||
*
|
||||
@ -223,7 +235,9 @@ public final class NetworkTypeObserver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@C.NetworkType int networkType = getNetworkTypeFromConnectivityManager(context);
|
||||
if (Util.SDK_INT >= 29 && !disable5GNsaDisambiguation && networkType == C.NETWORK_TYPE_4G) {
|
||||
if (Util.SDK_INT >= 29
|
||||
&& !Config.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
|
||||
|
Loading…
x
Reference in New Issue
Block a user