ExperimentalBandwidthMeter


@UnstableApi
class ExperimentalBandwidthMeter : BandwidthMeter, TransferListener


An experimental BandwidthMeter that estimates bandwidth by listening to data transfers.

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 Builder.

Summary

Nested types

Builder for a bandwidth meter.

Constants

const Long

Default initial bitrate estimate used when the device is offline or the network type cannot be determined, in bits per second.

const ImmutableList<Long!>!

Default initial 2G bitrate estimates in bits per second.

const ImmutableList<Long!>!

Default initial 3G bitrate estimates in bits per second.

const ImmutableList<Long!>!

Default initial 4G bitrate estimates in bits per second.

const ImmutableList<Long!>!

Default initial 5G-NSA bitrate estimates in bits per second.

const ImmutableList<Long!>!

Default initial 5G-SA bitrate estimates in bits per second.

const ImmutableList<Long!>!

Default initial Wifi bitrate estimate in bits per second.

const Float

Default percentile for estimating the time to first byte.

const Int

Default number of samples to keep in the sliding window for estimating the time to first byte.

Public functions

synchronized Unit
addEventListener(
    eventHandler: Handler!,
    eventListener: BandwidthMeter.EventListener!
)

Adds an EventListener.

synchronized Long

Returns the estimated bitrate.

synchronized Long

Returns the estimated time to first byte, in microseconds, or TIME_UNSET if no estimate is available.

TransferListener!

Returns the TransferListener that this instance uses to gather bandwidth information from data transfers.

synchronized Unit
onBytesTransferred(
    source: DataSource!,
    dataSpec: DataSpec!,
    isNetwork: Boolean,
    bytesTransferred: Int
)

Called incrementally during a transfer.

synchronized Unit
onTransferEnd(source: DataSource!, dataSpec: DataSpec!, isNetwork: Boolean)

Called when a transfer ends.

synchronized Unit
onTransferInitializing(
    source: DataSource!,
    dataSpec: DataSpec!,
    isNetwork: Boolean
)

Called when a transfer is being initialized.

synchronized Unit
onTransferStart(source: DataSource!, dataSpec: DataSpec!, isNetwork: Boolean)

Called when a transfer starts.

synchronized Unit

Removes an EventListener.

synchronized Unit

Overrides the network type.

Constants

DEFAULT_INITIAL_BITRATE_ESTIMATE

const val DEFAULT_INITIAL_BITRATE_ESTIMATE = 1000000: Long

Default initial bitrate estimate used when the device is offline or the network type cannot be determined, in bits per second.

DEFAULT_INITIAL_BITRATE_ESTIMATES_2G

const val DEFAULT_INITIAL_BITRATE_ESTIMATES_2GImmutableList<Long!>!

Default initial 2G bitrate estimates in bits per second.

DEFAULT_INITIAL_BITRATE_ESTIMATES_3G

const val DEFAULT_INITIAL_BITRATE_ESTIMATES_3GImmutableList<Long!>!

Default initial 3G bitrate estimates in bits per second.

DEFAULT_INITIAL_BITRATE_ESTIMATES_4G

const val DEFAULT_INITIAL_BITRATE_ESTIMATES_4GImmutableList<Long!>!

Default initial 4G bitrate estimates in bits per second.

DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSA

const val DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSAImmutableList<Long!>!

Default initial 5G-NSA bitrate estimates in bits per second.

DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SA

const val DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SAImmutableList<Long!>!

Default initial 5G-SA bitrate estimates in bits per second.

DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI

const val DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFIImmutableList<Long!>!

Default initial Wifi bitrate estimate in bits per second.

DEFAULT_TIME_TO_FIRST_BYTE_PERCENTILE

const val DEFAULT_TIME_TO_FIRST_BYTE_PERCENTILE = 0.5f: Float

Default percentile for estimating the time to first byte.

DEFAULT_TIME_TO_FIRST_BYTE_SAMPLES

const val DEFAULT_TIME_TO_FIRST_BYTE_SAMPLES = 20: Int

Default number of samples to keep in the sliding window for estimating the time to first byte.

Public functions

addEventListener

synchronized fun addEventListener(
    eventHandler: Handler!,
    eventListener: BandwidthMeter.EventListener!
): Unit

Adds an EventListener.

Parameters
eventHandler: Handler!

A handler for events.

eventListener: BandwidthMeter.EventListener!

A listener of events.

getBitrateEstimate

synchronized fun getBitrateEstimate(): Long

Returns the estimated bitrate.

getTimeToFirstByteEstimateUs

synchronized fun getTimeToFirstByteEstimateUs(): Long

Returns the estimated time to first byte, in microseconds, or TIME_UNSET if no estimate is available.

getTransferListener

fun getTransferListener(): TransferListener!

Returns the TransferListener that this instance uses to gather bandwidth information from data transfers. May be null if the implementation does not listen to data transfers.

onBytesTransferred

synchronized fun onBytesTransferred(
    source: DataSource!,
    dataSpec: DataSpec!,
    isNetwork: Boolean,
    bytesTransferred: Int
): Unit

Called incrementally during a transfer.

Parameters
source: DataSource!

The source performing the transfer.

dataSpec: DataSpec!

Describes the data being transferred.

isNetwork: Boolean

Whether the data is transferred through a network.

bytesTransferred: Int

The number of bytes transferred since the previous call to this method.

onTransferEnd

synchronized fun onTransferEnd(source: DataSource!, dataSpec: DataSpec!, isNetwork: Boolean): Unit

Called when a transfer ends.

Parameters
source: DataSource!

The source performing the transfer.

dataSpec: DataSpec!

Describes the data being transferred.

isNetwork: Boolean

Whether the data is transferred through a network.

onTransferInitializing

synchronized fun onTransferInitializing(
    source: DataSource!,
    dataSpec: DataSpec!,
    isNetwork: Boolean
): Unit

Called when a transfer is being initialized.

Parameters
source: DataSource!

The source performing the transfer.

dataSpec: DataSpec!

Describes the data for which the transfer is initialized.

isNetwork: Boolean

Whether the data is transferred through a network.

onTransferStart

synchronized fun onTransferStart(source: DataSource!, dataSpec: DataSpec!, isNetwork: Boolean): Unit

Called when a transfer starts.

Parameters
source: DataSource!

The source performing the transfer.

dataSpec: DataSpec!

Describes the data being transferred.

isNetwork: Boolean

Whether the data is transferred through a network.

removeEventListener

synchronized fun removeEventListener(eventListener: BandwidthMeter.EventListener!): Unit

Removes an EventListener.

Parameters
eventListener: BandwidthMeter.EventListener!

The listener to be removed.

setNetworkTypeOverride

synchronized fun setNetworkTypeOverride(@C.NetworkType networkType: Int): Unit

Overrides the network type. Handled in the same way as if the meter had detected a change from the current network type to the specified network type internally.

Applications should not normally call this method. It is intended for testing purposes.

Parameters
@C.NetworkType networkType: Int

The overriding network type.