Removed unneeded todo's, add docs.

This commit is contained in:
Peter Serwylo 2014-05-20 08:59:27 +09:30
parent 75586ec4e5
commit d9e5b07054
3 changed files with 20 additions and 12 deletions

View File

@ -31,6 +31,11 @@ import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.security.NoSuchAlgorithmException; 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 { public class ApkDownloader implements AsyncDownloadWrapper.Listener {
private static final String TAG = "org.fdroid.fdroid.net.ApkDownloader"; 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); 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() { public File localFile() {
return localFile; return localFile;
} }

View File

@ -8,6 +8,13 @@ import org.fdroid.fdroid.ProgressListener;
import java.io.IOException; 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 { public class AsyncDownloadWrapper extends Handler {
private static final String TAG = "org.fdroid.fdroid.net.AsyncDownloadWrapper"; private static final String TAG = "org.fdroid.fdroid.net.AsyncDownloadWrapper";
@ -71,6 +78,11 @@ public class AsyncDownloadWrapper extends Handler {
downloadThread.interrupt(); 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) { public void handleMessage(Message message) {
if (message.arg1 == MSG_PROGRESS) { if (message.arg1 == MSG_PROGRESS) {
Bundle data = message.getData(); Bundle data = message.getData();

View File

@ -47,15 +47,6 @@ public abstract class Downloader {
outputStream = new FileOutputStream(outputFile); 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) public Downloader(OutputStream output)
throws MalformedURLException { throws MalformedURLException {
outputStream = output; outputStream = output;
@ -158,8 +149,6 @@ public abstract class Downloader {
*/ */
private void throwExceptionIfInterrupted() throws InterruptedException { private void throwExceptionIfInterrupted() throws InterruptedException {
if (Thread.interrupted()) { 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"); Log.d(TAG, "Received interrupt, cancelling download");
throw new InterruptedException(); throw new InterruptedException();
} }