TestDownloadManagerListener


@UnstableApi
public final class TestDownloadManagerListener implements DownloadManager.Listener


Allows tests to block for, and assert properties of, calls from a DownloadManager to its DownloadManager.Listener.

Summary

Public constructors

Public methods

void

Asserts that the specified download is removed.

void
assertState(String id, @Download.State int state)

Asserts that the specified download transitions to the specified state.

void

Blocks until the manager is idle.

void

Blocks until the manager is idle and throws if any of the downloads failed.

void

Blocks until the manager is initialized.

void
onDownloadChanged(
    DownloadManager downloadManager,
    Download download,
    @Nullable Exception finalException
)

Called when the state of a download changes.

void
onDownloadRemoved(DownloadManager downloadManager, Download download)

Called when a download is removed.

void
onIdle(DownloadManager downloadManager)

Called when there is no active download left.

void
onInitialized(DownloadManager downloadManager)

Called when all downloads have been restored.

Inherited methods

From androidx.media3.exoplayer.offline.DownloadManager.Listener
void
onDownloadsPausedChanged(
    DownloadManager downloadManager,
    boolean downloadsPaused
)

Called when downloads are (paused or resumed.

void
onRequirementsStateChanged(
    DownloadManager downloadManager,
    Requirements requirements,
    @Requirements.RequirementFlags int notMetRequirements
)

Called when the download requirements state changed.

void
onWaitingForRequirementsChanged(
    DownloadManager downloadManager,
    boolean waitingForRequirements
)

Called when there is a change in whether this manager has one or more downloads that are not progressing for the sole reason that the Requirements are not met.

Public constructors

TestDownloadManagerListener

public TestDownloadManagerListener(DownloadManager downloadManager)

Public methods

assertRemoved

public void assertRemoved(String id)

Asserts that the specified download is removed.

assertState

public void assertState(String id, @Download.State int state)

Asserts that the specified download transitions to the specified state.

blockUntilIdle

public void blockUntilIdle()

Blocks until the manager is idle.

blockUntilIdleAndThrowAnyFailure

public void blockUntilIdleAndThrowAnyFailure()

Blocks until the manager is idle and throws if any of the downloads failed.

blockUntilInitialized

public void blockUntilInitialized()

Blocks until the manager is initialized.

onDownloadChanged

public void onDownloadChanged(
    DownloadManager downloadManager,
    Download download,
    @Nullable Exception finalException
)

Called when the state of a download changes.

Parameters
DownloadManager downloadManager

The reporting instance.

Download download

The state of the download.

@Nullable Exception finalException

If the download is transitioning to STATE_FAILED, this is the final exception that resulted in the failure.

onDownloadRemoved

public void onDownloadRemoved(DownloadManager downloadManager, Download download)

Called when a download is removed.

Parameters
DownloadManager downloadManager

The reporting instance.

Download download

The last state of the download before it was removed.

onIdle

public void onIdle(DownloadManager downloadManager)

Called when there is no active download left.

Parameters
DownloadManager downloadManager

The reporting instance.

onInitialized

public void onInitialized(DownloadManager downloadManager)

Called when all downloads have been restored.

Parameters
DownloadManager downloadManager

The reporting instance.