Move Util.getCountryCode off main thread in DefaultBandwidthMeter

PiperOrigin-RevId: 721293354
This commit is contained in:
tonihei 2025-01-30 01:20:52 -08:00 committed by Copybara-Service
parent 6b31b4620c
commit 17100259cd
4 changed files with 228 additions and 72 deletions

View File

@ -15,12 +15,16 @@
*/ */
package androidx.media3.exoplayer.upstream; package androidx.media3.exoplayer.upstream;
import static com.google.common.base.Strings.nullToEmpty;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.os.Handler; import android.os.Handler;
import androidx.annotation.GuardedBy; import androidx.annotation.GuardedBy;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.media3.common.C; import androidx.media3.common.C;
import androidx.media3.common.util.Assertions; import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.BackgroundExecutor;
import androidx.media3.common.util.Clock; import androidx.media3.common.util.Clock;
import androidx.media3.common.util.NetworkTypeObserver; import androidx.media3.common.util.NetworkTypeObserver;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
@ -35,6 +39,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/** /**
* Estimates bandwidth by listening to data transfers. * Estimates bandwidth by listening to data transfers.
@ -116,14 +121,17 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
*/ */
private static final int COUNTRY_GROUP_INDEX_5G_SA = 5; private static final int COUNTRY_GROUP_INDEX_5G_SA = 5;
@Nullable private static DefaultBandwidthMeter singletonInstance; // Intentionally mutable static field and using application context to prevent leakage.
@SuppressLint({"NonFinalStaticField", "StaticFieldLeak"})
@Nullable
private static DefaultBandwidthMeter singletonInstance;
/** Builder for a bandwidth meter. */ /** Builder for a bandwidth meter. */
public static final class Builder { public static final class Builder {
@Nullable private final Context context; @Nullable private final Context context;
private final Map<Integer, Long> initialBitrateEstimates;
private Map<Integer, Long> initialBitrateEstimates;
private int slidingWindowMaxWeight; private int slidingWindowMaxWeight;
private Clock clock; private Clock clock;
private boolean resetOnNetworkTypeChange; private boolean resetOnNetworkTypeChange;
@ -136,10 +144,18 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
public Builder(Context context) { public Builder(Context context) {
// Handling of null is for backward compatibility only. // Handling of null is for backward compatibility only.
this.context = context == null ? null : context.getApplicationContext(); this.context = context == null ? null : context.getApplicationContext();
initialBitrateEstimates = getInitialBitrateEstimatesForCountry(Util.getCountryCode(context));
slidingWindowMaxWeight = DEFAULT_SLIDING_WINDOW_MAX_WEIGHT; slidingWindowMaxWeight = DEFAULT_SLIDING_WINDOW_MAX_WEIGHT;
clock = Clock.DEFAULT; clock = Clock.DEFAULT;
resetOnNetworkTypeChange = true; resetOnNetworkTypeChange = true;
initialBitrateEstimates = new HashMap<>(/* initialCapacity= */ 8);
initialBitrateEstimates.put(C.NETWORK_TYPE_UNKNOWN, DEFAULT_INITIAL_BITRATE_ESTIMATE);
initialBitrateEstimates.put(C.NETWORK_TYPE_WIFI, C.TIME_UNSET);
initialBitrateEstimates.put(C.NETWORK_TYPE_2G, C.TIME_UNSET);
initialBitrateEstimates.put(C.NETWORK_TYPE_3G, C.TIME_UNSET);
initialBitrateEstimates.put(C.NETWORK_TYPE_4G, C.TIME_UNSET);
initialBitrateEstimates.put(C.NETWORK_TYPE_5G_NSA, C.TIME_UNSET);
initialBitrateEstimates.put(C.NETWORK_TYPE_5G_SA, C.TIME_UNSET);
initialBitrateEstimates.put(C.NETWORK_TYPE_ETHERNET, C.TIME_UNSET);
} }
/** /**
@ -194,8 +210,11 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
*/ */
@CanIgnoreReturnValue @CanIgnoreReturnValue
public Builder setInitialBitrateEstimate(String countryCode) { public Builder setInitialBitrateEstimate(String countryCode) {
initialBitrateEstimates = countryCode = Ascii.toUpperCase(countryCode);
getInitialBitrateEstimatesForCountry(Ascii.toUpperCase(countryCode)); for (Integer networkType : initialBitrateEstimates.keySet()) {
setInitialBitrateEstimate(
networkType, getInitialBitrateEstimatesForCountry(countryCode, networkType));
}
return this; return this;
} }
@ -237,35 +256,6 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
clock, clock,
resetOnNetworkTypeChange); resetOnNetworkTypeChange);
} }
private static Map<Integer, Long> getInitialBitrateEstimatesForCountry(String countryCode) {
int[] groupIndices = getInitialBitrateCountryGroupAssignment(countryCode);
Map<Integer, Long> result = new HashMap<>(/* initialCapacity= */ 8);
result.put(C.NETWORK_TYPE_UNKNOWN, DEFAULT_INITIAL_BITRATE_ESTIMATE);
result.put(
C.NETWORK_TYPE_WIFI,
DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI.get(groupIndices[COUNTRY_GROUP_INDEX_WIFI]));
result.put(
C.NETWORK_TYPE_2G,
DEFAULT_INITIAL_BITRATE_ESTIMATES_2G.get(groupIndices[COUNTRY_GROUP_INDEX_2G]));
result.put(
C.NETWORK_TYPE_3G,
DEFAULT_INITIAL_BITRATE_ESTIMATES_3G.get(groupIndices[COUNTRY_GROUP_INDEX_3G]));
result.put(
C.NETWORK_TYPE_4G,
DEFAULT_INITIAL_BITRATE_ESTIMATES_4G.get(groupIndices[COUNTRY_GROUP_INDEX_4G]));
result.put(
C.NETWORK_TYPE_5G_NSA,
DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSA.get(groupIndices[COUNTRY_GROUP_INDEX_5G_NSA]));
result.put(
C.NETWORK_TYPE_5G_SA,
DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SA.get(groupIndices[COUNTRY_GROUP_INDEX_5G_SA]));
// Assume default Wifi speed for Ethernet to prevent using the slower fallback.
result.put(
C.NETWORK_TYPE_ETHERNET,
DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI.get(groupIndices[COUNTRY_GROUP_INDEX_WIFI]));
return result;
}
} }
/** /**
@ -284,6 +274,7 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
private static final int ELAPSED_MILLIS_FOR_ESTIMATE = 2000; private static final int ELAPSED_MILLIS_FOR_ESTIMATE = 2000;
private static final int BYTES_TRANSFERRED_FOR_ESTIMATE = 512 * 1024; private static final int BYTES_TRANSFERRED_FOR_ESTIMATE = 512 * 1024;
@Nullable private final Context context;
private final ImmutableMap<Integer, Long> initialBitrateEstimates; private final ImmutableMap<Integer, Long> initialBitrateEstimates;
private final EventDispatcher eventDispatcher; private final EventDispatcher eventDispatcher;
private final Clock clock; private final Clock clock;
@ -316,6 +307,7 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
private @C.NetworkType int networkType; private @C.NetworkType int networkType;
private boolean networkTypeOverrideSet; private boolean networkTypeOverrideSet;
private @C.NetworkType int networkTypeOverride; private @C.NetworkType int networkTypeOverride;
private @MonotonicNonNull String countryCode;
private DefaultBandwidthMeter( private DefaultBandwidthMeter(
@Nullable Context context, @Nullable Context context,
@ -323,6 +315,7 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
int maxWeight, int maxWeight,
Clock clock, Clock clock,
boolean resetOnNetworkTypeChange) { boolean resetOnNetworkTypeChange) {
this.context = context == null ? null : context.getApplicationContext();
this.initialBitrateEstimates = ImmutableMap.copyOf(initialBitrateEstimates); this.initialBitrateEstimates = ImmutableMap.copyOf(initialBitrateEstimates);
this.eventDispatcher = new EventDispatcher(); this.eventDispatcher = new EventDispatcher();
this.slidingPercentile = new SlidingPercentile(maxWeight); this.slidingPercentile = new SlidingPercentile(maxWeight);
@ -332,10 +325,11 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
NetworkTypeObserver networkTypeObserver = NetworkTypeObserver.getInstance(context); NetworkTypeObserver networkTypeObserver = NetworkTypeObserver.getInstance(context);
networkType = networkTypeObserver.getNetworkType(); networkType = networkTypeObserver.getNetworkType();
bitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType); bitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType);
networkTypeObserver.register(/* listener= */ this::onNetworkTypeChanged); networkTypeObserver.register(
/* listener= */ this::onNetworkTypeChanged, BackgroundExecutor.get());
} else { } else {
networkType = C.NETWORK_TYPE_UNKNOWN; networkType = C.NETWORK_TYPE_UNKNOWN;
bitrateEstimate = getInitialBitrateEstimateForNetworkType(C.NETWORK_TYPE_UNKNOWN); bitrateEstimate = DEFAULT_INITIAL_BITRATE_ESTIMATE;
} }
} }
@ -434,7 +428,7 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
if (networkTypeOverrideSet) { if (networkTypeOverrideSet) {
networkType = networkTypeOverride; networkType = networkTypeOverride;
} }
if (this.networkType == networkType) { if (this.networkType == networkType && countryCode != null) {
return; return;
} }
@ -446,6 +440,10 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
return; return;
} }
if (countryCode == null) {
countryCode = Util.getCountryCode(context);
}
// Reset the bitrate estimate and report it, along with any bytes transferred. // Reset the bitrate estimate and report it, along with any bytes transferred.
this.bitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType); this.bitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType);
long nowMs = clock.elapsedRealtime(); long nowMs = clock.elapsedRealtime();
@ -474,6 +472,8 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
Long initialBitrateEstimate = initialBitrateEstimates.get(networkType); Long initialBitrateEstimate = initialBitrateEstimates.get(networkType);
if (initialBitrateEstimate == null) { if (initialBitrateEstimate == null) {
initialBitrateEstimate = initialBitrateEstimates.get(C.NETWORK_TYPE_UNKNOWN); initialBitrateEstimate = initialBitrateEstimates.get(C.NETWORK_TYPE_UNKNOWN);
} else if (initialBitrateEstimate == C.TIME_UNSET) {
initialBitrateEstimate = getInitialBitrateEstimatesForCountry(countryCode, networkType);
} }
if (initialBitrateEstimate == null) { if (initialBitrateEstimate == null) {
initialBitrateEstimate = DEFAULT_INITIAL_BITRATE_ESTIMATE; initialBitrateEstimate = DEFAULT_INITIAL_BITRATE_ESTIMATE;
@ -485,6 +485,31 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
return isNetwork && !dataSpec.isFlagSet(DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED); return isNetwork && !dataSpec.isFlagSet(DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED);
} }
private static long getInitialBitrateEstimatesForCountry(
@Nullable String countryCode, @C.NetworkType int networkType) {
int[] groupIndices = getInitialBitrateCountryGroupAssignment(nullToEmpty(countryCode));
switch (networkType) {
case C.NETWORK_TYPE_WIFI:
case C.NETWORK_TYPE_ETHERNET:
// Assume default Wifi speed for Ethernet to prevent using the slower fallback.
return DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI.get(groupIndices[COUNTRY_GROUP_INDEX_WIFI]);
case C.NETWORK_TYPE_2G:
return DEFAULT_INITIAL_BITRATE_ESTIMATES_2G.get(groupIndices[COUNTRY_GROUP_INDEX_2G]);
case C.NETWORK_TYPE_3G:
return DEFAULT_INITIAL_BITRATE_ESTIMATES_3G.get(groupIndices[COUNTRY_GROUP_INDEX_3G]);
case C.NETWORK_TYPE_4G:
return DEFAULT_INITIAL_BITRATE_ESTIMATES_4G.get(groupIndices[COUNTRY_GROUP_INDEX_4G]);
case C.NETWORK_TYPE_5G_NSA:
return DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSA.get(
groupIndices[COUNTRY_GROUP_INDEX_5G_NSA]);
case C.NETWORK_TYPE_5G_SA:
return DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SA.get(groupIndices[COUNTRY_GROUP_INDEX_5G_SA]);
case C.NETWORK_TYPE_UNKNOWN:
default:
return DEFAULT_INITIAL_BITRATE_ESTIMATE;
}
}
/** /**
* Returns initial bitrate group assignments for a {@code country}. The initial bitrate is a list * Returns initial bitrate group assignments for a {@code country}. The initial bitrate is a list
* of indices for [Wifi, 2G, 3G, 4G, 5G_NSA, 5G_SA]. * of indices for [Wifi, 2G, 3G, 4G, 5G_NSA, 5G_SA].

View File

@ -16,12 +16,14 @@
package androidx.media3.exoplayer.upstream.experimental; package androidx.media3.exoplayer.upstream.experimental;
import static androidx.media3.common.util.Assertions.checkNotNull; import static androidx.media3.common.util.Assertions.checkNotNull;
import static com.google.common.base.Strings.nullToEmpty;
import android.content.Context; import android.content.Context;
import android.os.Handler; import android.os.Handler;
import androidx.annotation.GuardedBy; import androidx.annotation.GuardedBy;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.media3.common.C; import androidx.media3.common.C;
import androidx.media3.common.util.BackgroundExecutor;
import androidx.media3.common.util.NetworkTypeObserver; import androidx.media3.common.util.NetworkTypeObserver;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util; import androidx.media3.common.util.Util;
@ -36,6 +38,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/** /**
* An experimental {@link BandwidthMeter} that estimates bandwidth by listening to data transfers. * An experimental {@link BandwidthMeter} that estimates bandwidth by listening to data transfers.
@ -124,8 +127,8 @@ public final class ExperimentalBandwidthMeter implements BandwidthMeter, Transfe
public static final class Builder { public static final class Builder {
private final Context context; private final Context context;
private final Map<Integer, Long> initialBitrateEstimates;
private Map<Integer, Long> initialBitrateEstimates;
private TimeToFirstByteEstimator timeToFirstByteEstimator; private TimeToFirstByteEstimator timeToFirstByteEstimator;
private BandwidthEstimator bandwidthEstimator; private BandwidthEstimator bandwidthEstimator;
private boolean resetOnNetworkTypeChange; private boolean resetOnNetworkTypeChange;
@ -138,13 +141,21 @@ public final class ExperimentalBandwidthMeter implements BandwidthMeter, Transfe
public Builder(Context context) { public Builder(Context context) {
// Handling of null is for backward compatibility only. // Handling of null is for backward compatibility only.
this.context = context.getApplicationContext(); this.context = context.getApplicationContext();
initialBitrateEstimates = getInitialBitrateEstimatesForCountry(Util.getCountryCode(context));
timeToFirstByteEstimator = timeToFirstByteEstimator =
new PercentileTimeToFirstByteEstimator( new PercentileTimeToFirstByteEstimator(
/* numberOfSamples= */ DEFAULT_TIME_TO_FIRST_BYTE_SAMPLES, /* numberOfSamples= */ DEFAULT_TIME_TO_FIRST_BYTE_SAMPLES,
/* percentile= */ DEFAULT_TIME_TO_FIRST_BYTE_PERCENTILE); /* percentile= */ DEFAULT_TIME_TO_FIRST_BYTE_PERCENTILE);
bandwidthEstimator = new SplitParallelSampleBandwidthEstimator.Builder().build(); bandwidthEstimator = new SplitParallelSampleBandwidthEstimator.Builder().build();
resetOnNetworkTypeChange = true; resetOnNetworkTypeChange = true;
initialBitrateEstimates = new HashMap<>(/* initialCapacity= */ 8);
initialBitrateEstimates.put(C.NETWORK_TYPE_UNKNOWN, DEFAULT_INITIAL_BITRATE_ESTIMATE);
initialBitrateEstimates.put(C.NETWORK_TYPE_WIFI, C.TIME_UNSET);
initialBitrateEstimates.put(C.NETWORK_TYPE_2G, C.TIME_UNSET);
initialBitrateEstimates.put(C.NETWORK_TYPE_3G, C.TIME_UNSET);
initialBitrateEstimates.put(C.NETWORK_TYPE_4G, C.TIME_UNSET);
initialBitrateEstimates.put(C.NETWORK_TYPE_5G_NSA, C.TIME_UNSET);
initialBitrateEstimates.put(C.NETWORK_TYPE_5G_SA, C.TIME_UNSET);
initialBitrateEstimates.put(C.NETWORK_TYPE_ETHERNET, C.TIME_UNSET);
} }
/** /**
@ -187,8 +198,11 @@ public final class ExperimentalBandwidthMeter implements BandwidthMeter, Transfe
*/ */
@CanIgnoreReturnValue @CanIgnoreReturnValue
public Builder setInitialBitrateEstimate(String countryCode) { public Builder setInitialBitrateEstimate(String countryCode) {
initialBitrateEstimates = countryCode = Ascii.toUpperCase(countryCode);
getInitialBitrateEstimatesForCountry(Ascii.toUpperCase(countryCode)); for (Integer networkType : initialBitrateEstimates.keySet()) {
setInitialBitrateEstimate(
networkType, getInitialBitrateEstimatesForCountry(countryCode, networkType));
}
return this; return this;
} }
@ -244,37 +258,9 @@ public final class ExperimentalBandwidthMeter implements BandwidthMeter, Transfe
bandwidthEstimator, bandwidthEstimator,
resetOnNetworkTypeChange); resetOnNetworkTypeChange);
} }
private static Map<Integer, Long> getInitialBitrateEstimatesForCountry(String countryCode) {
int[] groupIndices = getInitialBitrateCountryGroupAssignment(countryCode);
Map<Integer, Long> result = new HashMap<>(/* initialCapacity= */ 8);
result.put(C.NETWORK_TYPE_UNKNOWN, DEFAULT_INITIAL_BITRATE_ESTIMATE);
result.put(
C.NETWORK_TYPE_WIFI,
DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI.get(groupIndices[COUNTRY_GROUP_INDEX_WIFI]));
result.put(
C.NETWORK_TYPE_2G,
DEFAULT_INITIAL_BITRATE_ESTIMATES_2G.get(groupIndices[COUNTRY_GROUP_INDEX_2G]));
result.put(
C.NETWORK_TYPE_3G,
DEFAULT_INITIAL_BITRATE_ESTIMATES_3G.get(groupIndices[COUNTRY_GROUP_INDEX_3G]));
result.put(
C.NETWORK_TYPE_4G,
DEFAULT_INITIAL_BITRATE_ESTIMATES_4G.get(groupIndices[COUNTRY_GROUP_INDEX_4G]));
result.put(
C.NETWORK_TYPE_5G_NSA,
DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSA.get(groupIndices[COUNTRY_GROUP_INDEX_5G_NSA]));
result.put(
C.NETWORK_TYPE_5G_SA,
DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SA.get(groupIndices[COUNTRY_GROUP_INDEX_5G_SA]));
// Assume default Wifi speed for Ethernet to prevent using the slower fallback.
result.put(
C.NETWORK_TYPE_ETHERNET,
DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI.get(groupIndices[COUNTRY_GROUP_INDEX_WIFI]));
return result;
}
} }
@Nullable private final Context context;
private final ImmutableMap<Integer, Long> initialBitrateEstimates; private final ImmutableMap<Integer, Long> initialBitrateEstimates;
private final boolean resetOnNetworkTypeChange; private final boolean resetOnNetworkTypeChange;
@ -288,6 +274,7 @@ public final class ExperimentalBandwidthMeter implements BandwidthMeter, Transfe
private long initialBitrateEstimate; private long initialBitrateEstimate;
private boolean networkTypeOverrideSet; private boolean networkTypeOverrideSet;
private @C.NetworkType int networkTypeOverride; private @C.NetworkType int networkTypeOverride;
private @MonotonicNonNull String countryCode;
private ExperimentalBandwidthMeter( private ExperimentalBandwidthMeter(
Context context, Context context,
@ -295,6 +282,7 @@ public final class ExperimentalBandwidthMeter implements BandwidthMeter, Transfe
TimeToFirstByteEstimator timeToFirstByteEstimator, TimeToFirstByteEstimator timeToFirstByteEstimator,
BandwidthEstimator bandwidthEstimator, BandwidthEstimator bandwidthEstimator,
boolean resetOnNetworkTypeChange) { boolean resetOnNetworkTypeChange) {
this.context = context == null ? null : context.getApplicationContext();
this.initialBitrateEstimates = ImmutableMap.copyOf(initialBitrateEstimates); this.initialBitrateEstimates = ImmutableMap.copyOf(initialBitrateEstimates);
this.timeToFirstByteEstimator = timeToFirstByteEstimator; this.timeToFirstByteEstimator = timeToFirstByteEstimator;
this.bandwidthEstimator = bandwidthEstimator; this.bandwidthEstimator = bandwidthEstimator;
@ -302,7 +290,8 @@ public final class ExperimentalBandwidthMeter implements BandwidthMeter, Transfe
NetworkTypeObserver networkTypeObserver = NetworkTypeObserver.getInstance(context); NetworkTypeObserver networkTypeObserver = NetworkTypeObserver.getInstance(context);
networkType = networkTypeObserver.getNetworkType(); networkType = networkTypeObserver.getNetworkType();
initialBitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType); initialBitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType);
networkTypeObserver.register(/* listener= */ this::onNetworkTypeChanged); networkTypeObserver.register(
/* listener= */ this::onNetworkTypeChanged, BackgroundExecutor.get());
} }
/** /**
@ -395,7 +384,7 @@ public final class ExperimentalBandwidthMeter implements BandwidthMeter, Transfe
if (networkTypeOverrideSet) { if (networkTypeOverrideSet) {
networkType = networkTypeOverride; networkType = networkTypeOverride;
} }
if (this.networkType == networkType) { if (this.networkType == networkType && countryCode != null) {
return; return;
} }
@ -407,6 +396,10 @@ public final class ExperimentalBandwidthMeter implements BandwidthMeter, Transfe
return; return;
} }
if (countryCode == null) {
countryCode = Util.getCountryCode(context);
}
// Reset the bitrate estimate and report it, along with any bytes transferred. // Reset the bitrate estimate and report it, along with any bytes transferred.
this.initialBitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType); this.initialBitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType);
bandwidthEstimator.onNetworkTypeChange(initialBitrateEstimate); bandwidthEstimator.onNetworkTypeChange(initialBitrateEstimate);
@ -417,6 +410,8 @@ public final class ExperimentalBandwidthMeter implements BandwidthMeter, Transfe
@Nullable Long initialBitrateEstimate = initialBitrateEstimates.get(networkType); @Nullable Long initialBitrateEstimate = initialBitrateEstimates.get(networkType);
if (initialBitrateEstimate == null) { if (initialBitrateEstimate == null) {
initialBitrateEstimate = initialBitrateEstimates.get(C.NETWORK_TYPE_UNKNOWN); initialBitrateEstimate = initialBitrateEstimates.get(C.NETWORK_TYPE_UNKNOWN);
} else if (initialBitrateEstimate == C.TIME_UNSET) {
initialBitrateEstimate = getInitialBitrateEstimatesForCountry(countryCode, networkType);
} }
if (initialBitrateEstimate == null) { if (initialBitrateEstimate == null) {
initialBitrateEstimate = DEFAULT_INITIAL_BITRATE_ESTIMATE; initialBitrateEstimate = DEFAULT_INITIAL_BITRATE_ESTIMATE;
@ -428,6 +423,31 @@ public final class ExperimentalBandwidthMeter implements BandwidthMeter, Transfe
return isNetwork && !dataSpec.isFlagSet(DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED); return isNetwork && !dataSpec.isFlagSet(DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED);
} }
private static long getInitialBitrateEstimatesForCountry(
@Nullable String countryCode, @C.NetworkType int networkType) {
int[] groupIndices = getInitialBitrateCountryGroupAssignment(nullToEmpty(countryCode));
switch (networkType) {
case C.NETWORK_TYPE_WIFI:
case C.NETWORK_TYPE_ETHERNET:
// Assume default Wifi speed for Ethernet to prevent using the slower fallback.
return DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI.get(groupIndices[COUNTRY_GROUP_INDEX_WIFI]);
case C.NETWORK_TYPE_2G:
return DEFAULT_INITIAL_BITRATE_ESTIMATES_2G.get(groupIndices[COUNTRY_GROUP_INDEX_2G]);
case C.NETWORK_TYPE_3G:
return DEFAULT_INITIAL_BITRATE_ESTIMATES_3G.get(groupIndices[COUNTRY_GROUP_INDEX_3G]);
case C.NETWORK_TYPE_4G:
return DEFAULT_INITIAL_BITRATE_ESTIMATES_4G.get(groupIndices[COUNTRY_GROUP_INDEX_4G]);
case C.NETWORK_TYPE_5G_NSA:
return DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSA.get(
groupIndices[COUNTRY_GROUP_INDEX_5G_NSA]);
case C.NETWORK_TYPE_5G_SA:
return DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SA.get(groupIndices[COUNTRY_GROUP_INDEX_5G_SA]);
case C.NETWORK_TYPE_UNKNOWN:
default:
return DEFAULT_INITIAL_BITRATE_ESTIMATE;
}
}
/** /**
* Returns initial bitrate group assignments for a {@code country}. The initial bitrate is a list * Returns initial bitrate group assignments for a {@code country}. The initial bitrate is a list
* of indices for [Wifi, 2G, 3G, 4G, 5G_NSA, 5G_SA]. * of indices for [Wifi, 2G, 3G, 4G, 5G_NSA, 5G_SA].

View File

@ -136,11 +136,13 @@ public final class DefaultBandwidthMeterTest {
setActiveNetworkInfo(networkInfoWifi); setActiveNetworkInfo(networkInfoWifi);
DefaultBandwidthMeter bandwidthMeterWifi = DefaultBandwidthMeter bandwidthMeterWifi =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateWifi = bandwidthMeterWifi.getBitrateEstimate(); long initialEstimateWifi = bandwidthMeterWifi.getBitrateEstimate();
setActiveNetworkInfo(networkInfo2g); setActiveNetworkInfo(networkInfo2g);
DefaultBandwidthMeter bandwidthMeter2g = DefaultBandwidthMeter bandwidthMeter2g =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate(); long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate();
assertThat(initialEstimateWifi).isGreaterThan(initialEstimate2g); assertThat(initialEstimateWifi).isGreaterThan(initialEstimate2g);
@ -151,11 +153,13 @@ public final class DefaultBandwidthMeterTest {
setActiveNetworkInfo(networkInfoWifi); setActiveNetworkInfo(networkInfoWifi);
DefaultBandwidthMeter bandwidthMeterWifi = DefaultBandwidthMeter bandwidthMeterWifi =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateWifi = bandwidthMeterWifi.getBitrateEstimate(); long initialEstimateWifi = bandwidthMeterWifi.getBitrateEstimate();
setActiveNetworkInfo(networkInfo3g); setActiveNetworkInfo(networkInfo3g);
DefaultBandwidthMeter bandwidthMeter3g = DefaultBandwidthMeter bandwidthMeter3g =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate();
assertThat(initialEstimateWifi).isGreaterThan(initialEstimate3g); assertThat(initialEstimateWifi).isGreaterThan(initialEstimate3g);
@ -166,11 +170,13 @@ public final class DefaultBandwidthMeterTest {
setActiveNetworkInfo(networkInfoEthernet); setActiveNetworkInfo(networkInfoEthernet);
DefaultBandwidthMeter bandwidthMeterEthernet = DefaultBandwidthMeter bandwidthMeterEthernet =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateEthernet = bandwidthMeterEthernet.getBitrateEstimate(); long initialEstimateEthernet = bandwidthMeterEthernet.getBitrateEstimate();
setActiveNetworkInfo(networkInfo2g); setActiveNetworkInfo(networkInfo2g);
DefaultBandwidthMeter bandwidthMeter2g = DefaultBandwidthMeter bandwidthMeter2g =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate(); long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate();
assertThat(initialEstimateEthernet).isGreaterThan(initialEstimate2g); assertThat(initialEstimateEthernet).isGreaterThan(initialEstimate2g);
@ -181,11 +187,13 @@ public final class DefaultBandwidthMeterTest {
setActiveNetworkInfo(networkInfoEthernet); setActiveNetworkInfo(networkInfoEthernet);
DefaultBandwidthMeter bandwidthMeterEthernet = DefaultBandwidthMeter bandwidthMeterEthernet =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateEthernet = bandwidthMeterEthernet.getBitrateEstimate(); long initialEstimateEthernet = bandwidthMeterEthernet.getBitrateEstimate();
setActiveNetworkInfo(networkInfo3g); setActiveNetworkInfo(networkInfo3g);
DefaultBandwidthMeter bandwidthMeter3g = DefaultBandwidthMeter bandwidthMeter3g =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate();
assertThat(initialEstimateEthernet).isGreaterThan(initialEstimate3g); assertThat(initialEstimateEthernet).isGreaterThan(initialEstimate3g);
@ -196,11 +204,13 @@ public final class DefaultBandwidthMeterTest {
setActiveNetworkInfo(networkInfo4g); setActiveNetworkInfo(networkInfo4g);
DefaultBandwidthMeter bandwidthMeter4g = DefaultBandwidthMeter bandwidthMeter4g =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate4g = bandwidthMeter4g.getBitrateEstimate(); long initialEstimate4g = bandwidthMeter4g.getBitrateEstimate();
setActiveNetworkInfo(networkInfo2g); setActiveNetworkInfo(networkInfo2g);
DefaultBandwidthMeter bandwidthMeter2g = DefaultBandwidthMeter bandwidthMeter2g =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate(); long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate();
assertThat(initialEstimate4g).isGreaterThan(initialEstimate2g); assertThat(initialEstimate4g).isGreaterThan(initialEstimate2g);
@ -211,11 +221,13 @@ public final class DefaultBandwidthMeterTest {
setActiveNetworkInfo(networkInfo4g); setActiveNetworkInfo(networkInfo4g);
DefaultBandwidthMeter bandwidthMeter4g = DefaultBandwidthMeter bandwidthMeter4g =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate4g = bandwidthMeter4g.getBitrateEstimate(); long initialEstimate4g = bandwidthMeter4g.getBitrateEstimate();
setActiveNetworkInfo(networkInfo3g); setActiveNetworkInfo(networkInfo3g);
DefaultBandwidthMeter bandwidthMeter3g = DefaultBandwidthMeter bandwidthMeter3g =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate();
assertThat(initialEstimate4g).isGreaterThan(initialEstimate3g); assertThat(initialEstimate4g).isGreaterThan(initialEstimate3g);
@ -226,11 +238,13 @@ public final class DefaultBandwidthMeterTest {
setActiveNetworkInfo(networkInfo3g); setActiveNetworkInfo(networkInfo3g);
DefaultBandwidthMeter bandwidthMeter3g = DefaultBandwidthMeter bandwidthMeter3g =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate();
setActiveNetworkInfo(networkInfo2g); setActiveNetworkInfo(networkInfo2g);
DefaultBandwidthMeter bandwidthMeter2g = DefaultBandwidthMeter bandwidthMeter2g =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate(); long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate();
assertThat(initialEstimate3g).isGreaterThan(initialEstimate2g); assertThat(initialEstimate3g).isGreaterThan(initialEstimate2g);
@ -242,11 +256,13 @@ public final class DefaultBandwidthMeterTest {
setActiveNetworkInfo(networkInfo4g); setActiveNetworkInfo(networkInfo4g);
DefaultBandwidthMeter bandwidthMeter4g = DefaultBandwidthMeter bandwidthMeter4g =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate4g = bandwidthMeter4g.getBitrateEstimate(); long initialEstimate4g = bandwidthMeter4g.getBitrateEstimate();
setActiveNetworkInfo(networkInfo4g, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA); setActiveNetworkInfo(networkInfo4g, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA);
DefaultBandwidthMeter bandwidthMeter5gNsa = DefaultBandwidthMeter bandwidthMeter5gNsa =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate5gNsa = bandwidthMeter5gNsa.getBitrateEstimate(); long initialEstimate5gNsa = bandwidthMeter5gNsa.getBitrateEstimate();
assertThat(initialEstimate5gNsa).isGreaterThan(initialEstimate4g); assertThat(initialEstimate5gNsa).isGreaterThan(initialEstimate4g);
@ -258,11 +274,13 @@ public final class DefaultBandwidthMeterTest {
setActiveNetworkInfo(networkInfo3g); setActiveNetworkInfo(networkInfo3g);
DefaultBandwidthMeter bandwidthMeter3g = DefaultBandwidthMeter bandwidthMeter3g =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate();
setActiveNetworkInfo(networkInfo5gSa); setActiveNetworkInfo(networkInfo5gSa);
DefaultBandwidthMeter bandwidthMeter5gSa = DefaultBandwidthMeter bandwidthMeter5gSa =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate5gSa = bandwidthMeter5gSa.getBitrateEstimate(); long initialEstimate5gSa = bandwidthMeter5gSa.getBitrateEstimate();
assertThat(initialEstimate5gSa).isGreaterThan(initialEstimate3g); assertThat(initialEstimate5gSa).isGreaterThan(initialEstimate3g);
@ -273,6 +291,7 @@ public final class DefaultBandwidthMeterTest {
setActiveNetworkInfo(networkInfoOffline); setActiveNetworkInfo(networkInfoOffline);
DefaultBandwidthMeter bandwidthMeter = DefaultBandwidthMeter bandwidthMeter =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isGreaterThan(100_000L); assertThat(initialEstimate).isGreaterThan(100_000L);
@ -286,11 +305,13 @@ public final class DefaultBandwidthMeterTest {
setNetworkCountryIso(FAST_COUNTRY_ISO); setNetworkCountryIso(FAST_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterFast = DefaultBandwidthMeter bandwidthMeterFast =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate();
setNetworkCountryIso(SLOW_COUNTRY_ISO); setNetworkCountryIso(SLOW_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterSlow = DefaultBandwidthMeter bandwidthMeterSlow =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate();
assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow);
@ -303,11 +324,13 @@ public final class DefaultBandwidthMeterTest {
setNetworkCountryIso(FAST_COUNTRY_ISO); setNetworkCountryIso(FAST_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterFast = DefaultBandwidthMeter bandwidthMeterFast =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate();
setNetworkCountryIso(SLOW_COUNTRY_ISO); setNetworkCountryIso(SLOW_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterSlow = DefaultBandwidthMeter bandwidthMeterSlow =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate();
assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow);
@ -320,11 +343,13 @@ public final class DefaultBandwidthMeterTest {
setNetworkCountryIso(FAST_COUNTRY_ISO); setNetworkCountryIso(FAST_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterFast = DefaultBandwidthMeter bandwidthMeterFast =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate();
setNetworkCountryIso(SLOW_COUNTRY_ISO); setNetworkCountryIso(SLOW_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterSlow = DefaultBandwidthMeter bandwidthMeterSlow =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate();
assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow);
@ -337,11 +362,13 @@ public final class DefaultBandwidthMeterTest {
setNetworkCountryIso(FAST_COUNTRY_ISO); setNetworkCountryIso(FAST_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterFast = DefaultBandwidthMeter bandwidthMeterFast =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate();
setNetworkCountryIso(SLOW_COUNTRY_ISO); setNetworkCountryIso(SLOW_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterSlow = DefaultBandwidthMeter bandwidthMeterSlow =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate();
assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow);
@ -354,11 +381,13 @@ public final class DefaultBandwidthMeterTest {
setNetworkCountryIso(FAST_COUNTRY_ISO); setNetworkCountryIso(FAST_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterFast = DefaultBandwidthMeter bandwidthMeterFast =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate();
setNetworkCountryIso(SLOW_COUNTRY_ISO); setNetworkCountryIso(SLOW_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterSlow = DefaultBandwidthMeter bandwidthMeterSlow =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate();
assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow);
@ -372,11 +401,13 @@ public final class DefaultBandwidthMeterTest {
setNetworkCountryIso(FAST_COUNTRY_ISO); setNetworkCountryIso(FAST_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterFast = DefaultBandwidthMeter bandwidthMeterFast =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate();
setNetworkCountryIso(SLOW_COUNTRY_ISO); setNetworkCountryIso(SLOW_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterSlow = DefaultBandwidthMeter bandwidthMeterSlow =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate();
assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow);
@ -391,11 +422,13 @@ public final class DefaultBandwidthMeterTest {
setNetworkCountryIso(FAST_COUNTRY_ISO); setNetworkCountryIso(FAST_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterFast = DefaultBandwidthMeter bandwidthMeterFast =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate();
setNetworkCountryIso(SLOW_COUNTRY_ISO); setNetworkCountryIso(SLOW_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterSlow = DefaultBandwidthMeter bandwidthMeterSlow =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate();
assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow);
@ -408,6 +441,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(123456789) .setInitialBitrateEstimate(123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -420,6 +454,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(123456789) .setInitialBitrateEstimate(123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -432,6 +467,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -445,6 +481,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isNotEqualTo(123456789); assertThat(initialEstimate).isNotEqualTo(123456789);
@ -458,6 +495,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_ETHERNET, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_ETHERNET, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -471,6 +509,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isNotEqualTo(123456789); assertThat(initialEstimate).isNotEqualTo(123456789);
@ -483,6 +522,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_2G, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_2G, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -496,6 +536,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_2G, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_2G, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isNotEqualTo(123456789); assertThat(initialEstimate).isNotEqualTo(123456789);
@ -508,6 +549,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_3G, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_3G, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -521,6 +563,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_3G, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_3G, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isNotEqualTo(123456789); assertThat(initialEstimate).isNotEqualTo(123456789);
@ -533,6 +576,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_4G, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_4G, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -546,6 +590,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_4G, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_4G, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isNotEqualTo(123456789); assertThat(initialEstimate).isNotEqualTo(123456789);
@ -559,6 +604,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_5G_NSA, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_5G_NSA, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -573,6 +619,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_5G_NSA, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_5G_NSA, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isNotEqualTo(123456789); assertThat(initialEstimate).isNotEqualTo(123456789);
@ -586,6 +633,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_5G_SA, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_5G_SA, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -600,6 +648,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_5G_SA, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_5G_SA, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isNotEqualTo(123456789); assertThat(initialEstimate).isNotEqualTo(123456789);
@ -612,6 +661,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_OFFLINE, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_OFFLINE, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -625,6 +675,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_OFFLINE, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_OFFLINE, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isNotEqualTo(123456789); assertThat(initialEstimate).isNotEqualTo(123456789);
@ -635,6 +686,7 @@ public final class DefaultBandwidthMeterTest {
setNetworkCountryIso(SLOW_COUNTRY_ISO); setNetworkCountryIso(SLOW_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterSlow = DefaultBandwidthMeter bandwidthMeterSlow =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate();
setNetworkCountryIso(FAST_COUNTRY_ISO); setNetworkCountryIso(FAST_COUNTRY_ISO);
@ -642,6 +694,7 @@ public final class DefaultBandwidthMeterTest {
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(SLOW_COUNTRY_ISO) .setInitialBitrateEstimate(SLOW_COUNTRY_ISO)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimateFastWithSlowOverwrite = long initialEstimateFastWithSlowOverwrite =
bandwidthMeterFastWithSlowOverwrite.getBitrateEstimate(); bandwidthMeterFastWithSlowOverwrite.getBitrateEstimate();
@ -653,9 +706,11 @@ public final class DefaultBandwidthMeterTest {
setActiveNetworkInfo(networkInfoEthernet); setActiveNetworkInfo(networkInfoEthernet);
DefaultBandwidthMeter bandwidthMeter = DefaultBandwidthMeter bandwidthMeter =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateEthernet = bandwidthMeter.getBitrateEstimate(); long initialEstimateEthernet = bandwidthMeter.getBitrateEstimate();
bandwidthMeter.setNetworkTypeOverride(C.NETWORK_TYPE_2G); bandwidthMeter.setNetworkTypeOverride(C.NETWORK_TYPE_2G);
ShadowLooper.idleMainLooper();
long initialEstimate2g = bandwidthMeter.getBitrateEstimate(); long initialEstimate2g = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimateEthernet).isGreaterThan(initialEstimate2g); assertThat(initialEstimateEthernet).isGreaterThan(initialEstimate2g);
@ -695,6 +750,7 @@ public final class DefaultBandwidthMeterTest {
public void defaultInitialBitrateEstimate_withoutContext_isReasonable() { public void defaultInitialBitrateEstimate_withoutContext_isReasonable() {
DefaultBandwidthMeter bandwidthMeter = DefaultBandwidthMeter bandwidthMeter =
new DefaultBandwidthMeter.Builder(/* context= */ null).build(); new DefaultBandwidthMeter.Builder(/* context= */ null).build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isGreaterThan(100_000L); assertThat(initialEstimate).isGreaterThan(100_000L);

View File

@ -137,11 +137,13 @@ public final class ExperimentalBandwidthMeterTest {
setActiveNetworkInfo(networkInfoWifi); setActiveNetworkInfo(networkInfoWifi);
ExperimentalBandwidthMeter bandwidthMeterWifi = ExperimentalBandwidthMeter bandwidthMeterWifi =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateWifi = bandwidthMeterWifi.getBitrateEstimate(); long initialEstimateWifi = bandwidthMeterWifi.getBitrateEstimate();
setActiveNetworkInfo(networkInfo2g); setActiveNetworkInfo(networkInfo2g);
ExperimentalBandwidthMeter bandwidthMeter2g = ExperimentalBandwidthMeter bandwidthMeter2g =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate(); long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate();
assertThat(initialEstimateWifi).isGreaterThan(initialEstimate2g); assertThat(initialEstimateWifi).isGreaterThan(initialEstimate2g);
@ -152,11 +154,13 @@ public final class ExperimentalBandwidthMeterTest {
setActiveNetworkInfo(networkInfoWifi); setActiveNetworkInfo(networkInfoWifi);
ExperimentalBandwidthMeter bandwidthMeterWifi = ExperimentalBandwidthMeter bandwidthMeterWifi =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateWifi = bandwidthMeterWifi.getBitrateEstimate(); long initialEstimateWifi = bandwidthMeterWifi.getBitrateEstimate();
setActiveNetworkInfo(networkInfo3g); setActiveNetworkInfo(networkInfo3g);
ExperimentalBandwidthMeter bandwidthMeter3g = ExperimentalBandwidthMeter bandwidthMeter3g =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate();
assertThat(initialEstimateWifi).isGreaterThan(initialEstimate3g); assertThat(initialEstimateWifi).isGreaterThan(initialEstimate3g);
@ -167,11 +171,13 @@ public final class ExperimentalBandwidthMeterTest {
setActiveNetworkInfo(networkInfoEthernet); setActiveNetworkInfo(networkInfoEthernet);
ExperimentalBandwidthMeter bandwidthMeterEthernet = ExperimentalBandwidthMeter bandwidthMeterEthernet =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateEthernet = bandwidthMeterEthernet.getBitrateEstimate(); long initialEstimateEthernet = bandwidthMeterEthernet.getBitrateEstimate();
setActiveNetworkInfo(networkInfo2g); setActiveNetworkInfo(networkInfo2g);
ExperimentalBandwidthMeter bandwidthMeter2g = ExperimentalBandwidthMeter bandwidthMeter2g =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate(); long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate();
assertThat(initialEstimateEthernet).isGreaterThan(initialEstimate2g); assertThat(initialEstimateEthernet).isGreaterThan(initialEstimate2g);
@ -182,11 +188,13 @@ public final class ExperimentalBandwidthMeterTest {
setActiveNetworkInfo(networkInfoEthernet); setActiveNetworkInfo(networkInfoEthernet);
ExperimentalBandwidthMeter bandwidthMeterEthernet = ExperimentalBandwidthMeter bandwidthMeterEthernet =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateEthernet = bandwidthMeterEthernet.getBitrateEstimate(); long initialEstimateEthernet = bandwidthMeterEthernet.getBitrateEstimate();
setActiveNetworkInfo(networkInfo3g); setActiveNetworkInfo(networkInfo3g);
ExperimentalBandwidthMeter bandwidthMeter3g = ExperimentalBandwidthMeter bandwidthMeter3g =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate();
assertThat(initialEstimateEthernet).isGreaterThan(initialEstimate3g); assertThat(initialEstimateEthernet).isGreaterThan(initialEstimate3g);
@ -197,11 +205,13 @@ public final class ExperimentalBandwidthMeterTest {
setActiveNetworkInfo(networkInfo4g); setActiveNetworkInfo(networkInfo4g);
ExperimentalBandwidthMeter bandwidthMeter4g = ExperimentalBandwidthMeter bandwidthMeter4g =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate4g = bandwidthMeter4g.getBitrateEstimate(); long initialEstimate4g = bandwidthMeter4g.getBitrateEstimate();
setActiveNetworkInfo(networkInfo2g); setActiveNetworkInfo(networkInfo2g);
ExperimentalBandwidthMeter bandwidthMeter2g = ExperimentalBandwidthMeter bandwidthMeter2g =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate(); long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate();
assertThat(initialEstimate4g).isGreaterThan(initialEstimate2g); assertThat(initialEstimate4g).isGreaterThan(initialEstimate2g);
@ -212,11 +222,13 @@ public final class ExperimentalBandwidthMeterTest {
setActiveNetworkInfo(networkInfo4g); setActiveNetworkInfo(networkInfo4g);
ExperimentalBandwidthMeter bandwidthMeter4g = ExperimentalBandwidthMeter bandwidthMeter4g =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate4g = bandwidthMeter4g.getBitrateEstimate(); long initialEstimate4g = bandwidthMeter4g.getBitrateEstimate();
setActiveNetworkInfo(networkInfo3g); setActiveNetworkInfo(networkInfo3g);
ExperimentalBandwidthMeter bandwidthMeter3g = ExperimentalBandwidthMeter bandwidthMeter3g =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate();
assertThat(initialEstimate4g).isGreaterThan(initialEstimate3g); assertThat(initialEstimate4g).isGreaterThan(initialEstimate3g);
@ -227,11 +239,13 @@ public final class ExperimentalBandwidthMeterTest {
setActiveNetworkInfo(networkInfo3g); setActiveNetworkInfo(networkInfo3g);
ExperimentalBandwidthMeter bandwidthMeter3g = ExperimentalBandwidthMeter bandwidthMeter3g =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate();
setActiveNetworkInfo(networkInfo2g); setActiveNetworkInfo(networkInfo2g);
ExperimentalBandwidthMeter bandwidthMeter2g = ExperimentalBandwidthMeter bandwidthMeter2g =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate(); long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate();
assertThat(initialEstimate3g).isGreaterThan(initialEstimate2g); assertThat(initialEstimate3g).isGreaterThan(initialEstimate2g);
@ -243,11 +257,13 @@ public final class ExperimentalBandwidthMeterTest {
setActiveNetworkInfo(networkInfo4g); setActiveNetworkInfo(networkInfo4g);
ExperimentalBandwidthMeter bandwidthMeter4g = ExperimentalBandwidthMeter bandwidthMeter4g =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate4g = bandwidthMeter4g.getBitrateEstimate(); long initialEstimate4g = bandwidthMeter4g.getBitrateEstimate();
setActiveNetworkInfo(networkInfo4g, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA); setActiveNetworkInfo(networkInfo4g, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA);
ExperimentalBandwidthMeter bandwidthMeter5gNsa = ExperimentalBandwidthMeter bandwidthMeter5gNsa =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate5gNsa = bandwidthMeter5gNsa.getBitrateEstimate(); long initialEstimate5gNsa = bandwidthMeter5gNsa.getBitrateEstimate();
assertThat(initialEstimate5gNsa).isGreaterThan(initialEstimate4g); assertThat(initialEstimate5gNsa).isGreaterThan(initialEstimate4g);
@ -259,11 +275,13 @@ public final class ExperimentalBandwidthMeterTest {
setActiveNetworkInfo(networkInfo3g); setActiveNetworkInfo(networkInfo3g);
ExperimentalBandwidthMeter bandwidthMeter3g = ExperimentalBandwidthMeter bandwidthMeter3g =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate();
setActiveNetworkInfo(networkInfo5gSa); setActiveNetworkInfo(networkInfo5gSa);
ExperimentalBandwidthMeter bandwidthMeter5gSa = ExperimentalBandwidthMeter bandwidthMeter5gSa =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate5gSa = bandwidthMeter5gSa.getBitrateEstimate(); long initialEstimate5gSa = bandwidthMeter5gSa.getBitrateEstimate();
assertThat(initialEstimate5gSa).isGreaterThan(initialEstimate3g); assertThat(initialEstimate5gSa).isGreaterThan(initialEstimate3g);
@ -274,6 +292,7 @@ public final class ExperimentalBandwidthMeterTest {
setActiveNetworkInfo(networkInfoOffline); setActiveNetworkInfo(networkInfoOffline);
ExperimentalBandwidthMeter bandwidthMeter = ExperimentalBandwidthMeter bandwidthMeter =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isGreaterThan(100_000L); assertThat(initialEstimate).isGreaterThan(100_000L);
@ -287,11 +306,13 @@ public final class ExperimentalBandwidthMeterTest {
setNetworkCountryIso(FAST_COUNTRY_ISO); setNetworkCountryIso(FAST_COUNTRY_ISO);
ExperimentalBandwidthMeter bandwidthMeterFast = ExperimentalBandwidthMeter bandwidthMeterFast =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate();
setNetworkCountryIso(SLOW_COUNTRY_ISO); setNetworkCountryIso(SLOW_COUNTRY_ISO);
ExperimentalBandwidthMeter bandwidthMeterSlow = ExperimentalBandwidthMeter bandwidthMeterSlow =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate();
assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow);
@ -304,11 +325,13 @@ public final class ExperimentalBandwidthMeterTest {
setNetworkCountryIso(FAST_COUNTRY_ISO); setNetworkCountryIso(FAST_COUNTRY_ISO);
ExperimentalBandwidthMeter bandwidthMeterFast = ExperimentalBandwidthMeter bandwidthMeterFast =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate();
setNetworkCountryIso(SLOW_COUNTRY_ISO); setNetworkCountryIso(SLOW_COUNTRY_ISO);
ExperimentalBandwidthMeter bandwidthMeterSlow = ExperimentalBandwidthMeter bandwidthMeterSlow =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate();
assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow);
@ -321,11 +344,13 @@ public final class ExperimentalBandwidthMeterTest {
setNetworkCountryIso(FAST_COUNTRY_ISO); setNetworkCountryIso(FAST_COUNTRY_ISO);
ExperimentalBandwidthMeter bandwidthMeterFast = ExperimentalBandwidthMeter bandwidthMeterFast =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate();
setNetworkCountryIso(SLOW_COUNTRY_ISO); setNetworkCountryIso(SLOW_COUNTRY_ISO);
ExperimentalBandwidthMeter bandwidthMeterSlow = ExperimentalBandwidthMeter bandwidthMeterSlow =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate();
assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow);
@ -338,11 +363,13 @@ public final class ExperimentalBandwidthMeterTest {
setNetworkCountryIso(FAST_COUNTRY_ISO); setNetworkCountryIso(FAST_COUNTRY_ISO);
ExperimentalBandwidthMeter bandwidthMeterFast = ExperimentalBandwidthMeter bandwidthMeterFast =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate();
setNetworkCountryIso(SLOW_COUNTRY_ISO); setNetworkCountryIso(SLOW_COUNTRY_ISO);
ExperimentalBandwidthMeter bandwidthMeterSlow = ExperimentalBandwidthMeter bandwidthMeterSlow =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate();
assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow);
@ -355,11 +382,13 @@ public final class ExperimentalBandwidthMeterTest {
setNetworkCountryIso(FAST_COUNTRY_ISO); setNetworkCountryIso(FAST_COUNTRY_ISO);
ExperimentalBandwidthMeter bandwidthMeterFast = ExperimentalBandwidthMeter bandwidthMeterFast =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate();
setNetworkCountryIso(SLOW_COUNTRY_ISO); setNetworkCountryIso(SLOW_COUNTRY_ISO);
ExperimentalBandwidthMeter bandwidthMeterSlow = ExperimentalBandwidthMeter bandwidthMeterSlow =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate();
assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow);
@ -373,11 +402,13 @@ public final class ExperimentalBandwidthMeterTest {
setNetworkCountryIso(FAST_COUNTRY_ISO); setNetworkCountryIso(FAST_COUNTRY_ISO);
ExperimentalBandwidthMeter bandwidthMeterFast = ExperimentalBandwidthMeter bandwidthMeterFast =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate();
setNetworkCountryIso(SLOW_COUNTRY_ISO); setNetworkCountryIso(SLOW_COUNTRY_ISO);
ExperimentalBandwidthMeter bandwidthMeterSlow = ExperimentalBandwidthMeter bandwidthMeterSlow =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate();
assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow);
@ -392,11 +423,13 @@ public final class ExperimentalBandwidthMeterTest {
setNetworkCountryIso(FAST_COUNTRY_ISO); setNetworkCountryIso(FAST_COUNTRY_ISO);
ExperimentalBandwidthMeter bandwidthMeterFast = ExperimentalBandwidthMeter bandwidthMeterFast =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate();
setNetworkCountryIso(SLOW_COUNTRY_ISO); setNetworkCountryIso(SLOW_COUNTRY_ISO);
ExperimentalBandwidthMeter bandwidthMeterSlow = ExperimentalBandwidthMeter bandwidthMeterSlow =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate();
assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow);
@ -409,6 +442,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(123456789) .setInitialBitrateEstimate(123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -421,6 +455,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(123456789) .setInitialBitrateEstimate(123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -433,6 +468,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -446,6 +482,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isNotEqualTo(123456789); assertThat(initialEstimate).isNotEqualTo(123456789);
@ -459,6 +496,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_ETHERNET, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_ETHERNET, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -472,6 +510,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isNotEqualTo(123456789); assertThat(initialEstimate).isNotEqualTo(123456789);
@ -484,6 +523,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_2G, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_2G, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -497,6 +537,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_2G, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_2G, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isNotEqualTo(123456789); assertThat(initialEstimate).isNotEqualTo(123456789);
@ -509,6 +550,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_3G, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_3G, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -522,6 +564,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_3G, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_3G, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isNotEqualTo(123456789); assertThat(initialEstimate).isNotEqualTo(123456789);
@ -534,6 +577,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_4G, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_4G, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -547,6 +591,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_4G, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_4G, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isNotEqualTo(123456789); assertThat(initialEstimate).isNotEqualTo(123456789);
@ -560,6 +605,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_5G_NSA, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_5G_NSA, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -574,6 +620,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_5G_NSA, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_5G_NSA, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isNotEqualTo(123456789); assertThat(initialEstimate).isNotEqualTo(123456789);
@ -587,6 +634,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_5G_SA, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_5G_SA, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -601,6 +649,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_5G_SA, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_5G_SA, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isNotEqualTo(123456789); assertThat(initialEstimate).isNotEqualTo(123456789);
@ -613,6 +662,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_OFFLINE, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_OFFLINE, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isEqualTo(123456789); assertThat(initialEstimate).isEqualTo(123456789);
@ -626,6 +676,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(C.NETWORK_TYPE_OFFLINE, 123456789) .setInitialBitrateEstimate(C.NETWORK_TYPE_OFFLINE, 123456789)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimate = bandwidthMeter.getBitrateEstimate(); long initialEstimate = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimate).isNotEqualTo(123456789); assertThat(initialEstimate).isNotEqualTo(123456789);
@ -636,6 +687,7 @@ public final class ExperimentalBandwidthMeterTest {
setNetworkCountryIso(SLOW_COUNTRY_ISO); setNetworkCountryIso(SLOW_COUNTRY_ISO);
ExperimentalBandwidthMeter bandwidthMeterSlow = ExperimentalBandwidthMeter bandwidthMeterSlow =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate();
setNetworkCountryIso(FAST_COUNTRY_ISO); setNetworkCountryIso(FAST_COUNTRY_ISO);
@ -643,6 +695,7 @@ public final class ExperimentalBandwidthMeterTest {
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
.setInitialBitrateEstimate(SLOW_COUNTRY_ISO) .setInitialBitrateEstimate(SLOW_COUNTRY_ISO)
.build(); .build();
ShadowLooper.idleMainLooper();
long initialEstimateFastWithSlowOverwrite = long initialEstimateFastWithSlowOverwrite =
bandwidthMeterFastWithSlowOverwrite.getBitrateEstimate(); bandwidthMeterFastWithSlowOverwrite.getBitrateEstimate();
@ -654,9 +707,11 @@ public final class ExperimentalBandwidthMeterTest {
setActiveNetworkInfo(networkInfoEthernet); setActiveNetworkInfo(networkInfoEthernet);
ExperimentalBandwidthMeter bandwidthMeter = ExperimentalBandwidthMeter bandwidthMeter =
new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); new ExperimentalBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
ShadowLooper.idleMainLooper();
long initialEstimateEthernet = bandwidthMeter.getBitrateEstimate(); long initialEstimateEthernet = bandwidthMeter.getBitrateEstimate();
bandwidthMeter.setNetworkTypeOverride(C.NETWORK_TYPE_2G); bandwidthMeter.setNetworkTypeOverride(C.NETWORK_TYPE_2G);
ShadowLooper.idleMainLooper();
long initialEstimate2g = bandwidthMeter.getBitrateEstimate(); long initialEstimate2g = bandwidthMeter.getBitrateEstimate();
assertThat(initialEstimateEthernet).isGreaterThan(initialEstimate2g); assertThat(initialEstimateEthernet).isGreaterThan(initialEstimate2g);