Network type cleanup
1. Remove option to pass null context to Util.getNetworkType. IMO it's clearer for the caller to just not call the method in this case. 2. Stop using deprecated DefaultBandwidthMeter.Builder constructor in all but one place. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=217147091
This commit is contained in:
parent
6e7b41512f
commit
dbf5b073a6
@ -18,6 +18,8 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.google.android.exoplayer2.core.test">
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
|
||||
<application android:debuggable="true"
|
||||
android:allowBackup="false"
|
||||
tools:ignore="MissingApplicationIcon,HardcodedDebugMode">
|
||||
|
@ -187,7 +187,9 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
|
||||
* @return A bandwidth meter with the configured properties.
|
||||
*/
|
||||
public DefaultBandwidthMeter build() {
|
||||
Long initialBitrateEstimate = initialBitrateEstimates.get(Util.getNetworkType(context));
|
||||
Long initialBitrateEstimate =
|
||||
initialBitrateEstimates.get(
|
||||
context == null ? C.NETWORK_TYPE_UNKNOWN : Util.getNetworkType(context));
|
||||
if (initialBitrateEstimate == null) {
|
||||
initialBitrateEstimate = initialBitrateEstimates.get(C.NETWORK_TYPE_UNKNOWN);
|
||||
}
|
||||
|
@ -1620,31 +1620,24 @@ public final class Util {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link C.NetworkType} of the current network connection. {@link
|
||||
* C#NETWORK_TYPE_UNKNOWN} will be returned if the {@code ACCESS_NETWORK_STATE} permission is not
|
||||
* granted or the network connection type couldn't be determined.
|
||||
* Returns the {@link C.NetworkType} of the current network connection.
|
||||
*
|
||||
* @param context A context to access the connectivity manager.
|
||||
* @return The {@link C.NetworkType} of the current network connection, or {@link
|
||||
* C#NETWORK_TYPE_UNKNOWN} if the {@code ACCESS_NETWORK_STATE} permission is not granted or
|
||||
* {@code context} is null.
|
||||
* @return The {@link C.NetworkType} of the current network connection.
|
||||
*/
|
||||
public static @C.NetworkType int getNetworkType(@Nullable Context context) {
|
||||
@C.NetworkType
|
||||
public static int getNetworkType(Context context) {
|
||||
if (context == null) {
|
||||
// Note: This is for backward compatibility only (context used to be @Nullable).
|
||||
return C.NETWORK_TYPE_UNKNOWN;
|
||||
}
|
||||
NetworkInfo networkInfo;
|
||||
try {
|
||||
ConnectivityManager connectivityManager =
|
||||
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
if (connectivityManager == null) {
|
||||
return C.NETWORK_TYPE_UNKNOWN;
|
||||
}
|
||||
networkInfo = connectivityManager.getActiveNetworkInfo();
|
||||
} catch (SecurityException e) {
|
||||
// Permission ACCESS_NETWORK_STATE not granted.
|
||||
return C.NETWORK_TYPE_UNKNOWN;
|
||||
}
|
||||
if (networkInfo == null || !networkInfo.isConnected()) {
|
||||
return C.NETWORK_TYPE_OFFLINE;
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ public final class ExoPlayerTestRunner implements Player.EventListener, ActionSc
|
||||
trackSelector = new DefaultTrackSelector();
|
||||
}
|
||||
if (bandwidthMeter == null) {
|
||||
bandwidthMeter = new DefaultBandwidthMeter.Builder().build();
|
||||
bandwidthMeter = new DefaultBandwidthMeter.Builder(context).build();
|
||||
}
|
||||
if (renderersFactory == null) {
|
||||
if (renderers == null) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user