From d9e5b070541ae8963b259f3cbe4d51cc3e899b89 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Tue, 20 May 2014 08:59:27 +0930 Subject: [PATCH] Removed unneeded todo's, add docs. --- src/org/fdroid/fdroid/net/ApkDownloader.java | 9 ++++++++- src/org/fdroid/fdroid/net/AsyncDownloadWrapper.java | 12 ++++++++++++ src/org/fdroid/fdroid/net/Downloader.java | 11 ----------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/org/fdroid/fdroid/net/ApkDownloader.java b/src/org/fdroid/fdroid/net/ApkDownloader.java index c2f4aa475..27d052baf 100644 --- a/src/org/fdroid/fdroid/net/ApkDownloader.java +++ b/src/org/fdroid/fdroid/net/ApkDownloader.java @@ -31,6 +31,11 @@ import java.io.IOException; import java.net.MalformedURLException; import java.security.NoSuchAlgorithmException; +/** + * Downloads and verifies (against the Apk.hash) the apk file. + * If the file has previously been downloaded, it will make use of that + * instead, without going to the network to download a new one. + */ public class ApkDownloader implements AsyncDownloadWrapper.Listener { private static final String TAG = "org.fdroid.fdroid.net.ApkDownloader"; @@ -71,7 +76,9 @@ public class ApkDownloader implements AsyncDownloadWrapper.Listener { localFile = new File(destDir, curApk.apkName); } - // The downloaded APK. Valid only when getStatus() has returned STATUS.DONE. + /** + * The downloaded APK. Valid only when getStatus() has returned STATUS.DONE. + */ public File localFile() { return localFile; } diff --git a/src/org/fdroid/fdroid/net/AsyncDownloadWrapper.java b/src/org/fdroid/fdroid/net/AsyncDownloadWrapper.java index 01aba30cb..5e250aaa4 100644 --- a/src/org/fdroid/fdroid/net/AsyncDownloadWrapper.java +++ b/src/org/fdroid/fdroid/net/AsyncDownloadWrapper.java @@ -8,6 +8,13 @@ import org.fdroid.fdroid.ProgressListener; import java.io.IOException; +/** + * Given a {@link org.fdroid.fdroid.net.Downloader}, this wrapper will conduct the download operation on a + * separate thread. All progress/status/error/etc events will be forwarded from that thread to the thread + * that {@link AsyncDownloadWrapper#download()} was invoked on. If you want to respond with UI feedback + * to these events, it is important that you execute the download method of this class from the UI thread. + * That way, all forwarded events will be handled on that thread. + */ public class AsyncDownloadWrapper extends Handler { private static final String TAG = "org.fdroid.fdroid.net.AsyncDownloadWrapper"; @@ -71,6 +78,11 @@ public class AsyncDownloadWrapper extends Handler { downloadThread.interrupt(); } + /** + * Receives "messages" from the download thread, and passes them onto the + * relevant {@link org.fdroid.fdroid.net.AsyncDownloadWrapper.Listener} + * @param message + */ public void handleMessage(Message message) { if (message.arg1 == MSG_PROGRESS) { Bundle data = message.getData(); diff --git a/src/org/fdroid/fdroid/net/Downloader.java b/src/org/fdroid/fdroid/net/Downloader.java index 9be48bd20..8c9f7cf77 100644 --- a/src/org/fdroid/fdroid/net/Downloader.java +++ b/src/org/fdroid/fdroid/net/Downloader.java @@ -47,15 +47,6 @@ public abstract class Downloader { outputStream = new FileOutputStream(outputFile); } - /** - * Downloads to a temporary file, which *you must delete yourself when - * you are done*. - * @see org.fdroid.fdroid.net.Downloader#getFile() - */ - public Downloader(File destFile, Context ctx) throws IOException { - // TODO: Reimplement (is it still necessary? In what context was it being used before?) - } - public Downloader(OutputStream output) throws MalformedURLException { outputStream = output; @@ -158,8 +149,6 @@ public abstract class Downloader { */ private void throwExceptionIfInterrupted() throws InterruptedException { if (Thread.interrupted()) { - // TODO: Do we need to provide more information to whoever needs it, - // so they can, for example, remove any partially created files? Log.d(TAG, "Received interrupt, cancelling download"); throw new InterruptedException(); }