mirror of
https://github.com/androidx/media.git
synced 2025-05-18 04:59:54 +08:00
Rename DownloadManager.DownloadListener -> DownloadManager.Listener
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=195362765
This commit is contained in:
parent
c13722992f
commit
08e56394c5
@ -51,7 +51,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
public final class DownloadManager {
|
||||
|
||||
/** Listener for {@link DownloadManager} events. */
|
||||
public interface DownloadListener {
|
||||
public interface Listener {
|
||||
/**
|
||||
* Called when the state of a task changes.
|
||||
*
|
||||
@ -86,7 +86,7 @@ public final class DownloadManager {
|
||||
private final Handler handler;
|
||||
private final HandlerThread fileIOThread;
|
||||
private final Handler fileIOHandler;
|
||||
private final CopyOnWriteArraySet<DownloadListener> listeners;
|
||||
private final CopyOnWriteArraySet<Listener> listeners;
|
||||
|
||||
private int nextTaskId;
|
||||
private boolean actionFileLoadCompleted;
|
||||
@ -219,20 +219,20 @@ public final class DownloadManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a {@link DownloadListener}.
|
||||
* Adds a {@link Listener}.
|
||||
*
|
||||
* @param listener The listener to be added.
|
||||
*/
|
||||
public void addListener(DownloadListener listener) {
|
||||
public void addListener(Listener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a {@link DownloadListener}.
|
||||
* Removes a {@link Listener}.
|
||||
*
|
||||
* @param listener The listener to be removed.
|
||||
*/
|
||||
public void removeListener(DownloadListener listener) {
|
||||
public void removeListener(Listener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
@ -377,7 +377,7 @@ public final class DownloadManager {
|
||||
return;
|
||||
}
|
||||
logd("Notify idle state");
|
||||
for (DownloadListener listener : listeners) {
|
||||
for (Listener listener : listeners) {
|
||||
listener.onIdle(this);
|
||||
}
|
||||
}
|
||||
@ -404,7 +404,7 @@ public final class DownloadManager {
|
||||
|
||||
private void notifyListenersTaskStateChange(Task task) {
|
||||
TaskState taskState = task.getDownloadState();
|
||||
for (DownloadListener listener : listeners) {
|
||||
for (Listener listener : listeners) {
|
||||
listener.onTaskStateChanged(this, taskState);
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public abstract class DownloadService extends Service {
|
||||
private final @StringRes int channelName;
|
||||
|
||||
private DownloadManager downloadManager;
|
||||
private DownloadListener downloadListener;
|
||||
private DownloadManagerListener downloadManagerListener;
|
||||
private int lastStartId;
|
||||
|
||||
/**
|
||||
@ -171,8 +171,8 @@ public abstract class DownloadService extends Service {
|
||||
this, channelId, channelName, NotificationUtil.IMPORTANCE_LOW);
|
||||
}
|
||||
downloadManager = getDownloadManager();
|
||||
downloadListener = new DownloadListener();
|
||||
downloadManager.addListener(downloadListener);
|
||||
downloadManagerListener = new DownloadManagerListener();
|
||||
downloadManager.addListener(downloadManagerListener);
|
||||
|
||||
RequirementsHelper requirementsHelper;
|
||||
synchronized (requirementsHelpers) {
|
||||
@ -190,7 +190,7 @@ public abstract class DownloadService extends Service {
|
||||
public void onDestroy() {
|
||||
logd("onDestroy");
|
||||
foregroundNotificationUpdater.stopPeriodicUpdates();
|
||||
downloadManager.removeListener(downloadListener);
|
||||
downloadManager.removeListener(downloadManagerListener);
|
||||
if (downloadManager.getTaskCount() == 0) {
|
||||
synchronized (requirementsHelpers) {
|
||||
RequirementsHelper requirementsHelper = requirementsHelpers.remove(getClass());
|
||||
@ -312,7 +312,7 @@ public abstract class DownloadService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private final class DownloadListener implements DownloadManager.DownloadListener {
|
||||
private final class DownloadManagerListener implements DownloadManager.Listener {
|
||||
@Override
|
||||
public void onTaskStateChanged(DownloadManager downloadManager, TaskState taskState) {
|
||||
DownloadService.this.onTaskStateChanged(taskState);
|
||||
|
@ -21,7 +21,6 @@ import static org.junit.Assert.fail;
|
||||
import android.net.Uri;
|
||||
import android.os.ConditionVariable;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.offline.DownloadManager.DownloadListener;
|
||||
import com.google.android.exoplayer2.offline.DownloadManager.TaskState;
|
||||
import com.google.android.exoplayer2.offline.DownloadManager.TaskState.State;
|
||||
import com.google.android.exoplayer2.testutil.DummyMainThread;
|
||||
@ -67,7 +66,7 @@ public class DownloadManagerTest {
|
||||
private Uri uri3;
|
||||
private DummyMainThread dummyMainThread;
|
||||
private File actionFile;
|
||||
private TestDownloadListener testDownloadListener;
|
||||
private TestDownloadManagerListener downloadManagerListener;
|
||||
private DownloadManager downloadManager;
|
||||
|
||||
@Before
|
||||
@ -78,7 +77,7 @@ public class DownloadManagerTest {
|
||||
uri3 = Uri.parse("http://abc.com/media3");
|
||||
dummyMainThread = new DummyMainThread();
|
||||
actionFile = Util.createTempFile(RuntimeEnvironment.application, "ExoPlayerTest");
|
||||
testDownloadListener = new TestDownloadListener();
|
||||
downloadManagerListener = new TestDownloadManagerListener();
|
||||
setUpDownloadManager(100);
|
||||
}
|
||||
|
||||
@ -109,9 +108,9 @@ public class DownloadManagerTest {
|
||||
fakeDownloader.assertStarted(MAX_RETRY_DELAY).unblock();
|
||||
}
|
||||
downloadAction.assertFailed();
|
||||
testDownloadListener.clearDownloadError();
|
||||
downloadManagerListener.clearDownloadError();
|
||||
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -125,7 +124,7 @@ public class DownloadManagerTest {
|
||||
downloadAction.unblock().assertCanceled();
|
||||
removeAction.unblock();
|
||||
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -143,7 +142,7 @@ public class DownloadManagerTest {
|
||||
}
|
||||
downloadAction.assertCompleted();
|
||||
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -164,7 +163,7 @@ public class DownloadManagerTest {
|
||||
}
|
||||
downloadAction.assertCompleted();
|
||||
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -230,7 +229,7 @@ public class DownloadManagerTest {
|
||||
removeAction1.assertCanceled();
|
||||
downloadAction3.assertCanceled();
|
||||
removeAction2.assertStarted().unblock().assertCompleted();
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -248,7 +247,7 @@ public class DownloadManagerTest {
|
||||
removeAction1.unblock().assertCanceled();
|
||||
removeAction3.assertStarted().unblock().assertCompleted();
|
||||
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -284,7 +283,7 @@ public class DownloadManagerTest {
|
||||
downloadAction1.unblock().assertCompleted();
|
||||
downloadAction2.unblock().assertCompleted();
|
||||
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -303,7 +302,7 @@ public class DownloadManagerTest {
|
||||
downloadAction1.unblock().assertCompleted();
|
||||
downloadAction2.unblock().assertCompleted();
|
||||
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -322,7 +321,7 @@ public class DownloadManagerTest {
|
||||
removeAction1.assertStarted();
|
||||
removeAction1.unblock().assertCompleted();
|
||||
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -371,7 +370,7 @@ public class DownloadManagerTest {
|
||||
download2Action.assertStarted().unblock().assertCompleted();
|
||||
download3Action.assertStarted().unblock().assertCompleted();
|
||||
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -418,7 +417,7 @@ public class DownloadManagerTest {
|
||||
download2Action.unblock();
|
||||
download3Action.unblock();
|
||||
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
}
|
||||
|
||||
private void setUpDownloadManager(final int maxActiveDownloadTasks) throws Exception {
|
||||
@ -438,7 +437,7 @@ public class DownloadManagerTest {
|
||||
MIN_RETRY_COUNT,
|
||||
actionFile,
|
||||
ProgressiveDownloadAction.DESERIALIZER);
|
||||
downloadManager.addListener(testDownloadListener);
|
||||
downloadManager.addListener(downloadManagerListener);
|
||||
downloadManager.startDownloads();
|
||||
}
|
||||
});
|
||||
@ -463,7 +462,7 @@ public class DownloadManagerTest {
|
||||
|
||||
private void doTestActionRuns(FakeDownloadAction action) throws Throwable {
|
||||
action.post().assertStarted().unblock().assertCompleted();
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
}
|
||||
|
||||
private void doTestActionsRunSequentially(FakeDownloadAction action1, FakeDownloadAction action2)
|
||||
@ -475,7 +474,7 @@ public class DownloadManagerTest {
|
||||
action2.assertStarted();
|
||||
|
||||
action2.unblock().assertCompleted();
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
}
|
||||
|
||||
private void doTestActionsRunInParallel(FakeDownloadAction action1, FakeDownloadAction action2)
|
||||
@ -484,7 +483,7 @@ public class DownloadManagerTest {
|
||||
action2.post().assertStarted();
|
||||
action1.unblock().assertCompleted();
|
||||
action2.unblock().assertCompleted();
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
}
|
||||
|
||||
private FakeDownloadAction createDownloadAction(Uri uri) {
|
||||
@ -495,16 +494,16 @@ public class DownloadManagerTest {
|
||||
return new FakeDownloadAction(uri, /* isRemoveAction= */ true);
|
||||
}
|
||||
|
||||
private void runOnMainThread(final Runnable r) throws Throwable {
|
||||
private void runOnMainThread(final Runnable r) {
|
||||
dummyMainThread.runOnMainThread(r);
|
||||
}
|
||||
|
||||
private static final class TestDownloadListener implements DownloadListener {
|
||||
private static final class TestDownloadManagerListener implements DownloadManager.Listener {
|
||||
|
||||
private ConditionVariable downloadFinishedCondition;
|
||||
private Throwable downloadError;
|
||||
|
||||
private TestDownloadListener() {
|
||||
private TestDownloadManagerListener() {
|
||||
downloadFinishedCondition = new ConditionVariable();
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class DownloadManagerDashTest {
|
||||
private DownloadManager downloadManager;
|
||||
private RepresentationKey fakeRepresentationKey1;
|
||||
private RepresentationKey fakeRepresentationKey2;
|
||||
private TestDownloadListener downloadListener;
|
||||
private TestDownloadManagerListener downloadManagerListener;
|
||||
private File actionFile;
|
||||
private DummyMainThread dummyMainThread;
|
||||
|
||||
@ -243,7 +243,7 @@ public class DownloadManagerDashTest {
|
||||
}
|
||||
|
||||
private void blockUntilTasksCompleteAndThrowAnyDownloadError() throws Throwable {
|
||||
downloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
}
|
||||
|
||||
private void handleDownloadAction(RepresentationKey... keys) {
|
||||
@ -269,8 +269,9 @@ public class DownloadManagerDashTest {
|
||||
actionFile,
|
||||
DashDownloadAction.DESERIALIZER);
|
||||
|
||||
downloadListener = new TestDownloadListener(downloadManager, dummyMainThread);
|
||||
downloadManager.addListener(downloadListener);
|
||||
downloadManagerListener =
|
||||
new TestDownloadManagerListener(downloadManager, dummyMainThread);
|
||||
downloadManager.addListener(downloadManagerListener);
|
||||
downloadManager.startDownloads();
|
||||
}
|
||||
});
|
||||
|
@ -69,7 +69,7 @@ public class DownloadServiceDashTest {
|
||||
private Context context;
|
||||
private DownloadService dashDownloadService;
|
||||
private ConditionVariable pauseDownloadCondition;
|
||||
private TestDownloadListener testDownloadListener;
|
||||
private TestDownloadManagerListener downloadManagerListener;
|
||||
private DummyMainThread dummyMainThread;
|
||||
|
||||
@Before
|
||||
@ -129,8 +129,9 @@ public class DownloadServiceDashTest {
|
||||
3,
|
||||
actionFile,
|
||||
DashDownloadAction.DESERIALIZER);
|
||||
testDownloadListener = new TestDownloadListener(dashDownloadManager, dummyMainThread);
|
||||
dashDownloadManager.addListener(testDownloadListener);
|
||||
downloadManagerListener =
|
||||
new TestDownloadManagerListener(dashDownloadManager, dummyMainThread);
|
||||
dashDownloadManager.addListener(downloadManagerListener);
|
||||
dashDownloadManager.startDownloads();
|
||||
|
||||
dashDownloadService =
|
||||
@ -189,7 +190,7 @@ public class DownloadServiceDashTest {
|
||||
downloadKeys(fakeRepresentationKey1);
|
||||
downloadKeys(fakeRepresentationKey2);
|
||||
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
|
||||
assertCachedData(cache, fakeDataSet);
|
||||
}
|
||||
@ -199,11 +200,11 @@ public class DownloadServiceDashTest {
|
||||
public void testRemoveAction() throws Throwable {
|
||||
downloadKeys(fakeRepresentationKey1, fakeRepresentationKey2);
|
||||
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
|
||||
removeAll();
|
||||
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
|
||||
assertCacheEmpty(cache);
|
||||
}
|
||||
@ -216,7 +217,7 @@ public class DownloadServiceDashTest {
|
||||
|
||||
removeAll();
|
||||
|
||||
testDownloadListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
|
||||
assertCacheEmpty(cache);
|
||||
}
|
||||
|
@ -18,13 +18,12 @@ package com.google.android.exoplayer2.source.dash.offline;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.android.exoplayer2.offline.DownloadManager;
|
||||
import com.google.android.exoplayer2.offline.DownloadManager.DownloadListener;
|
||||
import com.google.android.exoplayer2.testutil.DummyMainThread;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/** A {@link DownloadListener} for testing. */
|
||||
/*package*/ final class TestDownloadListener implements DownloadListener {
|
||||
/** A {@link DownloadManager.Listener} for testing. */
|
||||
/* package */ final class TestDownloadManagerListener implements DownloadManager.Listener {
|
||||
|
||||
private static final int TIMEOUT = 1000;
|
||||
|
||||
@ -33,7 +32,8 @@ import java.util.concurrent.TimeUnit;
|
||||
private CountDownLatch downloadFinishedCondition;
|
||||
private Throwable downloadError;
|
||||
|
||||
public TestDownloadListener(DownloadManager downloadManager, DummyMainThread dummyMainThread) {
|
||||
public TestDownloadManagerListener(
|
||||
DownloadManager downloadManager, DummyMainThread dummyMainThread) {
|
||||
this.downloadManager = downloadManager;
|
||||
this.dummyMainThread = dummyMainThread;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user