DefaultBandwidthMeter implements BandwidthMeter, TransferListener { @Override public synchronized long getBitrateEstimate() { return bitrateEstimate; } @Deprecated  DefaultBandwidthMeter(); private  DefaultBandwidthMeter(
      @Nullable Context context,
      SparseArray<Long> initialBitrateEstimates,
      int maxWeight,
      Clock clock,
      boolean resetOnNetworkTypeChange); static synchronized DefaultBandwidthMeter getSingletonInstance(Context context); synchronized void setNetworkTypeOverride(@C.NetworkType int networkType); @Override synchronized long getBitrateEstimate(); @Override @Nullable TransferListener getTransferListener(); @Override void addEventListener(Handler eventHandler, EventListener eventListener); @Override void removeEventListener(EventListener eventListener); @Override void onTransferInitializing(DataSource source, DataSpec dataSpec, boolean isNetwork); @Override synchronized void onTransferStart(
      DataSource source, DataSpec dataSpec, boolean isNetwork); @Override synchronized void onBytesTransferred(
      DataSource source, DataSpec dataSpec, boolean isNetwork, int bytes); @Override synchronized void onTransferEnd(DataSource source, DataSpec dataSpec, boolean isNetwork); static final Map<String, int[]> DEFAULT_INITIAL_BITRATE_COUNTRY_GROUPS; static final long[] DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI; static final long[] DEFAULT_INITIAL_BITRATE_ESTIMATES_2G; static final long[] DEFAULT_INITIAL_BITRATE_ESTIMATES_3G; static final long[] DEFAULT_INITIAL_BITRATE_ESTIMATES_4G; static final long DEFAULT_INITIAL_BITRATE_ESTIMATE; static final int DEFAULT_SLIDING_WINDOW_MAX_WEIGHT; }
@Test public void defaultInitialBitrateEstimate_forWifi_isGreaterThanEstimateFor2G() { setActiveNetworkInfo(networkInfoWifi); DefaultBandwidthMeter bandwidthMeterWifi = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimateWifi = bandwidthMeterWifi.getBitrateEstimate(); setActiveNetworkInfo(networkInfo2g); DefaultBandwidthMeter bandwidthMeter2g = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate(); assertThat(initialEstimateWifi).isGreaterThan(initialEstimate2g); }
@Test public void defaultInitialBitrateEstimate_forWifi_isGreaterThanEstimateFor3G() { setActiveNetworkInfo(networkInfoWifi); DefaultBandwidthMeter bandwidthMeterWifi = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimateWifi = bandwidthMeterWifi.getBitrateEstimate(); setActiveNetworkInfo(networkInfo3g); DefaultBandwidthMeter bandwidthMeter3g = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); assertThat(initialEstimateWifi).isGreaterThan(initialEstimate3g); }
@Test public void defaultInitialBitrateEstimate_forEthernet_isGreaterThanEstimateFor2G() { setActiveNetworkInfo(networkInfoEthernet); DefaultBandwidthMeter bandwidthMeterEthernet = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimateEthernet = bandwidthMeterEthernet.getBitrateEstimate(); setActiveNetworkInfo(networkInfo2g); DefaultBandwidthMeter bandwidthMeter2g = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate(); assertThat(initialEstimateEthernet).isGreaterThan(initialEstimate2g); }
@Test public void defaultInitialBitrateEstimate_forEthernet_isGreaterThanEstimateFor3G() { setActiveNetworkInfo(networkInfoEthernet); DefaultBandwidthMeter bandwidthMeterEthernet = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimateEthernet = bandwidthMeterEthernet.getBitrateEstimate(); setActiveNetworkInfo(networkInfo3g); DefaultBandwidthMeter bandwidthMeter3g = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); assertThat(initialEstimateEthernet).isGreaterThan(initialEstimate3g); }
@Test public void defaultInitialBitrateEstimate_for4G_isGreaterThanEstimateFor2G() { setActiveNetworkInfo(networkInfo4g); DefaultBandwidthMeter bandwidthMeter4g = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimate4g = bandwidthMeter4g.getBitrateEstimate(); setActiveNetworkInfo(networkInfo2g); DefaultBandwidthMeter bandwidthMeter2g = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate(); assertThat(initialEstimate4g).isGreaterThan(initialEstimate2g); }
@Test public void defaultInitialBitrateEstimate_for4G_isGreaterThanEstimateFor3G() { setActiveNetworkInfo(networkInfo4g); DefaultBandwidthMeter bandwidthMeter4g = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimate4g = bandwidthMeter4g.getBitrateEstimate(); setActiveNetworkInfo(networkInfo3g); DefaultBandwidthMeter bandwidthMeter3g = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); assertThat(initialEstimate4g).isGreaterThan(initialEstimate3g); }
@Test public void defaultInitialBitrateEstimate_for3G_isGreaterThanEstimateFor2G() { setActiveNetworkInfo(networkInfo3g); DefaultBandwidthMeter bandwidthMeter3g = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); setActiveNetworkInfo(networkInfo2g); DefaultBandwidthMeter bandwidthMeter2g = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate(); assertThat(initialEstimate3g).isGreaterThan(initialEstimate2g); }
@Test public void defaultInitialBitrateEstimate_forOffline_isReasonable() { setActiveNetworkInfo(networkInfoOffline); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isGreaterThan(100_000L); assertThat(initialEstimate).isLessThan(50_000_000L); }
@Test public void defaultInitialBitrateEstimate_forWifi_forFastCountry_isGreaterThanEstimateForSlowCountry() { setActiveNetworkInfo(networkInfoWifi); setNetworkCountryIso(FAST_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterFast = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); setNetworkCountryIso(SLOW_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterSlow = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); }
@Test public void defaultInitialBitrateEstimate_forEthernet_forFastCountry_isGreaterThanEstimateForSlowCountry() { setActiveNetworkInfo(networkInfoEthernet); setNetworkCountryIso(FAST_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterFast = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); setNetworkCountryIso(SLOW_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterSlow = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); }
@Test public void defaultInitialBitrateEstimate_for2G_forFastCountry_isGreaterThanEstimateForSlowCountry() { setActiveNetworkInfo(networkInfo2g); setNetworkCountryIso(FAST_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterFast = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); setNetworkCountryIso(SLOW_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterSlow = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); }
@Test public void defaultInitialBitrateEstimate_for3G_forFastCountry_isGreaterThanEstimateForSlowCountry() { setActiveNetworkInfo(networkInfo3g); setNetworkCountryIso(FAST_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterFast = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); setNetworkCountryIso(SLOW_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterSlow = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); }
@Test public void defaultInitialBitrateEstimate_for4g_forFastCountry_isGreaterThanEstimateForSlowCountry() { setActiveNetworkInfo(networkInfo4g); setNetworkCountryIso(FAST_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterFast = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); setNetworkCountryIso(SLOW_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterSlow = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); }
@Test public void initialBitrateEstimateOverwrite_whileConnectedToNetwork_setsInitialEstimate() { setActiveNetworkInfo(networkInfoWifi); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) .setInitialBitrateEstimate(123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_whileOffline_setsInitialEstimate() { setActiveNetworkInfo(networkInfoOffline); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) .setInitialBitrateEstimate(123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_forWifi_whileConnectedToWifi_setsInitialEstimate() { setActiveNetworkInfo(networkInfoWifi); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) .setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_forWifi_whileConnectedToOtherNetwork_doesNotSetInitialEstimate() { setActiveNetworkInfo(networkInfo2g); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) .setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isNotEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_forEthernet_whileConnectedToEthernet_setsInitialEstimate() { setActiveNetworkInfo(networkInfoEthernet); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) .setInitialBitrateEstimate(C.NETWORK_TYPE_ETHERNET, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_forEthernet_whileConnectedToOtherNetwork_doesNotSetInitialEstimate() { setActiveNetworkInfo(networkInfo2g); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) .setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isNotEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_for2G_whileConnectedTo2G_setsInitialEstimate() { setActiveNetworkInfo(networkInfo2g); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) .setInitialBitrateEstimate(C.NETWORK_TYPE_2G, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_for2G_whileConnectedToOtherNetwork_doesNotSetInitialEstimate() { setActiveNetworkInfo(networkInfoWifi); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) .setInitialBitrateEstimate(C.NETWORK_TYPE_2G, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isNotEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_for3G_whileConnectedTo3G_setsInitialEstimate() { setActiveNetworkInfo(networkInfo3g); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) .setInitialBitrateEstimate(C.NETWORK_TYPE_3G, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_for3G_whileConnectedToOtherNetwork_doesNotSetInitialEstimate() { setActiveNetworkInfo(networkInfoWifi); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) .setInitialBitrateEstimate(C.NETWORK_TYPE_3G, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isNotEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_for4G_whileConnectedTo4G_setsInitialEstimate() { setActiveNetworkInfo(networkInfo4g); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) .setInitialBitrateEstimate(C.NETWORK_TYPE_4G, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_for4G_whileConnectedToOtherNetwork_doesNotSetInitialEstimate() { setActiveNetworkInfo(networkInfoWifi); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) .setInitialBitrateEstimate(C.NETWORK_TYPE_4G, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isNotEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_forOffline_whileOffline_setsInitialEstimate() { setActiveNetworkInfo(networkInfoOffline); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) .setInitialBitrateEstimate(C.NETWORK_TYPE_OFFLINE, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_forOffline_whileConnectedToNetwork_doesNotSetInitialEstimate() { setActiveNetworkInfo(networkInfoWifi); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) .setInitialBitrateEstimate(C.NETWORK_TYPE_OFFLINE, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isNotEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_forCountry_usesDefaultValuesForCountry() { setNetworkCountryIso(SLOW_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterSlow = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); setNetworkCountryIso(FAST_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterFastWithSlowOverwrite = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()) .setInitialBitrateEstimate(SLOW_COUNTRY_ISO) .build(); long initialEstimateFastWithSlowOverwrite = bandwidthMeterFastWithSlowOverwrite.getBitrateEstimate(); assertThat(initialEstimateFastWithSlowOverwrite).isEqualTo(initialEstimateSlow); }
@Test @SuppressWarnings("deprecation") public void defaultInitialBitrateEstimate_withoutContext_isReasonable() { DefaultBandwidthMeter bandwidthMeterWithBuilder = new DefaultBandwidthMeter.Builder( null).build(); long initialEstimateWithBuilder = bandwidthMeterWithBuilder.getBitrateEstimate(); DefaultBandwidthMeter bandwidthMeterWithoutBuilder = new DefaultBandwidthMeter(); long initialEstimateWithoutBuilder = bandwidthMeterWithoutBuilder.getBitrateEstimate(); assertThat(initialEstimateWithBuilder).isGreaterThan(100_000L); assertThat(initialEstimateWithBuilder).isLessThan(50_000_000L); assertThat(initialEstimateWithoutBuilder).isGreaterThan(100_000L); assertThat(initialEstimateWithoutBuilder).isLessThan(50_000_000L); }