From ac8d80a044dce4d5897730433b8f6417b0209b7a Mon Sep 17 00:00:00 2001 From: olly Date: Tue, 26 Jul 2022 12:49:34 +0000 Subject: [PATCH] DownloadService: Attempt to clarify the static map PiperOrigin-RevId: 463315188 --- .../media3/exoplayer/offline/DownloadService.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/offline/DownloadService.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/offline/DownloadService.java index e17fa4a6fc..e7fdf2dd46 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/offline/DownloadService.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/offline/DownloadService.java @@ -171,9 +171,11 @@ public abstract class DownloadService extends Service { private static final String TAG = "DownloadService"; - // Keep a DownloadManagerHelper for each DownloadService as long as the process is running. The - // helper is needed to restart the DownloadService when there's no scheduler. Even when there is a - // scheduler, the DownloadManagerHelper is typically able to restart the DownloadService faster. + // Maps each concrete DownloadService subclass to a single DownloadManagerHelper instance. This + // ensures getDownloadManager is only called once per subclass, even if a new instance of the + // service is created. The DownloadManagerHelper wrapper also takes care of restarting the service + // when there's no scheduler, and is often able to restart the service faster than the scheduler + // even when there is one. private static final HashMap, DownloadManagerHelper> downloadManagerHelpers = new HashMap<>(); @@ -711,8 +713,11 @@ public abstract class DownloadService extends Service { } /** - * Returns a {@link DownloadManager} to be used to downloaded content. Called only once in the - * life cycle of the process. + * Returns a {@link DownloadManager} to be used to downloaded content. For each concrete download + * service subclass, this is called once in the lifecycle of the process when {@link #onCreate} is + * called on the first instance of the service. If the service is destroyed and a new instance is + * created later, the new instance will use the previously returned {@link DownloadManager} + * without this method being called again. */ protected abstract DownloadManager getDownloadManager();