public final class DefaultBandwidthMeter extends java.lang.Object implements BandwidthMeter, TransferListener
The bandwidth estimate is calculated using a SlidingPercentile and is updated each
time a transfer ends. The initial estimate is based on the current operator's network country
code or the locale of the user, as well as the network connection type. This can be configured in
the DefaultBandwidthMeter.Builder.
| Modifier and Type | Class and Description |
|---|---|
static class |
DefaultBandwidthMeter.Builder
Builder for a bandwidth meter.
|
BandwidthMeter.EventListener| Modifier and Type | Field and Description |
|---|---|
static java.util.Map<java.lang.String,int[]> |
DEFAULT_INITIAL_BITRATE_COUNTRY_GROUPS
Country groups used to determine the default initial bitrate estimate.
|
static long |
DEFAULT_INITIAL_BITRATE_ESTIMATE
Default initial bitrate estimate used when the device is offline or the network type cannot be
determined, in bits per second.
|
static long[] |
DEFAULT_INITIAL_BITRATE_ESTIMATES_2G
Default initial 2G bitrate estimates in bits per second.
|
static long[] |
DEFAULT_INITIAL_BITRATE_ESTIMATES_3G
Default initial 3G bitrate estimates in bits per second.
|
static long[] |
DEFAULT_INITIAL_BITRATE_ESTIMATES_4G
Default initial 4G bitrate estimates in bits per second.
|
static long[] |
DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI
Default initial Wifi bitrate estimate in bits per second.
|
static int |
DEFAULT_SLIDING_WINDOW_MAX_WEIGHT
Default maximum weight for the sliding window.
|
| Constructor and Description |
|---|
DefaultBandwidthMeter()
Creates a bandwidth meter with default parameters.
|
DefaultBandwidthMeter(android.os.Handler eventHandler,
BandwidthMeter.EventListener eventListener)
Deprecated.
Use
DefaultBandwidthMeter.Builder instead. |
DefaultBandwidthMeter(android.os.Handler eventHandler,
BandwidthMeter.EventListener eventListener,
int maxWeight)
Deprecated.
Use
DefaultBandwidthMeter.Builder instead. |
| Modifier and Type | Method and Description |
|---|---|
void |
addEventListener(android.os.Handler eventHandler,
BandwidthMeter.EventListener eventListener)
Adds an
BandwidthMeter.EventListener to be informed of bandwidth samples. |
long |
getBitrateEstimate()
Returns the estimated bandwidth in bits/sec.
|
TransferListener |
getTransferListener()
Returns the
TransferListener that this instance uses to gather bandwidth information
from data transfers. |
void |
onBytesTransferred(DataSource source,
DataSpec dataSpec,
boolean isNetwork,
int bytes)
Called incrementally during a transfer.
|
void |
onTransferEnd(DataSource source,
DataSpec dataSpec,
boolean isNetwork)
Called when a transfer ends.
|
void |
onTransferInitializing(DataSource source,
DataSpec dataSpec,
boolean isNetwork)
Called when a transfer is being initialized.
|
void |
onTransferStart(DataSource source,
DataSpec dataSpec,
boolean isNetwork)
Called when a transfer starts.
|
void |
removeEventListener(BandwidthMeter.EventListener eventListener)
Removes an
BandwidthMeter.EventListener. |
public static final java.util.Map<java.lang.String,int[]> DEFAULT_INITIAL_BITRATE_COUNTRY_GROUPS
public static final long[] DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI
public static final long[] DEFAULT_INITIAL_BITRATE_ESTIMATES_2G
public static final long[] DEFAULT_INITIAL_BITRATE_ESTIMATES_3G
public static final long[] DEFAULT_INITIAL_BITRATE_ESTIMATES_4G
public static final long DEFAULT_INITIAL_BITRATE_ESTIMATE
public static final int DEFAULT_SLIDING_WINDOW_MAX_WEIGHT
public DefaultBandwidthMeter()
@Deprecated
public DefaultBandwidthMeter(android.os.Handler eventHandler,
BandwidthMeter.EventListener eventListener)
DefaultBandwidthMeter.Builder instead.@Deprecated
public DefaultBandwidthMeter(android.os.Handler eventHandler,
BandwidthMeter.EventListener eventListener,
int maxWeight)
DefaultBandwidthMeter.Builder instead.public long getBitrateEstimate()
BandwidthMetergetBitrateEstimate in interface BandwidthMeter@Nullable public TransferListener getTransferListener()
BandwidthMeterTransferListener that this instance uses to gather bandwidth information
from data transfers. May be null, if no transfer listener is used.getTransferListener in interface BandwidthMeterpublic void addEventListener(android.os.Handler eventHandler,
BandwidthMeter.EventListener eventListener)
BandwidthMeterBandwidthMeter.EventListener to be informed of bandwidth samples.addEventListener in interface BandwidthMetereventHandler - A handler for events.eventListener - A listener of events.public void removeEventListener(BandwidthMeter.EventListener eventListener)
BandwidthMeterBandwidthMeter.EventListener.removeEventListener in interface BandwidthMetereventListener - The listener to be removed.public void onTransferInitializing(DataSource source, DataSpec dataSpec, boolean isNetwork)
TransferListeneronTransferInitializing in interface TransferListenersource - The source performing the transfer.dataSpec - Describes the data for which the transfer is initialized.isNetwork - Whether the data is transferred through a network.public void onTransferStart(DataSource source, DataSpec dataSpec, boolean isNetwork)
TransferListeneronTransferStart in interface TransferListenersource - The source performing the transfer.dataSpec - Describes the data being transferred.isNetwork - Whether the data is transferred through a network.public void onBytesTransferred(DataSource source, DataSpec dataSpec, boolean isNetwork, int bytes)
TransferListeneronBytesTransferred in interface TransferListenersource - The source performing the transfer.dataSpec - Describes the data being transferred.isNetwork - Whether the data is transferred through a network.bytes - The number of bytes transferred since the previous call to this methodpublic void onTransferEnd(DataSource source, DataSpec dataSpec, boolean isNetwork)
TransferListeneronTransferEnd in interface TransferListenersource - The source performing the transfer.dataSpec - Describes the data being transferred.isNetwork - Whether the data is transferred through a network.