remove EVENT_DATA_ERROR_TYPE for DownloaderService reorg

As part of the process of moving the APK downloading to an
IntentService, I'm removing and incrementally reorganizing the
existing events so that the code continues to be functional as it is
reorganized.  We might want to include more detail in a download error
to expose to the user, but I think instead what will be more fruitful
is to hide details on errors where there is nothing the user can do
except retry.  Then if there are errors where the user can do
something about it, then F-Droid should instead offer them the option
of doing that, and not just show an error message and walk away.
This commit is contained in:
Hans-Christoph Steiner 2016-03-29 15:39:18 +02:00
parent d38058497e
commit 91edad0c31
3 changed files with 5 additions and 25 deletions

View File

@ -985,14 +985,8 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
boolean finished = false; boolean finished = false;
switch (event.type) { switch (event.type) {
case ApkDownloader.EVENT_ERROR: case ApkDownloader.EVENT_ERROR:
final int res;
if (event.getData().getInt(ApkDownloader.EVENT_DATA_ERROR_TYPE) == ApkDownloader.ERROR_HASH_MISMATCH) {
res = R.string.corrupt_download;
} else {
res = R.string.details_notinstalled;
}
// this must be on the main UI thread // this must be on the main UI thread
Toast.makeText(this, res, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.details_notinstalled, Toast.LENGTH_LONG).show();
cleanUpFinishedDownload(); cleanUpFinishedDownload();
finished = true; finished = true;
break; break;

View File

@ -29,10 +29,6 @@ public interface ProgressListener {
this(type, NO_VALUE, NO_VALUE, null); this(type, NO_VALUE, NO_VALUE, null);
} }
public Event(String type, Bundle data) {
this(type, NO_VALUE, NO_VALUE, data);
}
public Event(String type, int progress, int total, Bundle data) { public Event(String type, int progress, int total, Bundle data) {
this.type = type; this.type = type;
this.progress = progress; this.progress = progress;

View File

@ -27,10 +27,12 @@ import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import org.fdroid.fdroid.Hasher; import org.fdroid.fdroid.Hasher;
import org.fdroid.fdroid.Preferences; import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.ProgressListener; import org.fdroid.fdroid.ProgressListener;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.Utils; import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.compat.FileCompat; import org.fdroid.fdroid.compat.FileCompat;
import org.fdroid.fdroid.data.Apk; import org.fdroid.fdroid.data.Apk;
@ -56,16 +58,9 @@ public class ApkDownloader implements AsyncDownloader.Listener {
public static final String ACTION_STATUS = "apkDownloadStatus"; public static final String ACTION_STATUS = "apkDownloadStatus";
public static final int ERROR_HASH_MISMATCH = 101;
private static final String EVENT_SOURCE_ID = "sourceId"; private static final String EVENT_SOURCE_ID = "sourceId";
private static long downloadIdCounter; private static long downloadIdCounter;
/**
* Used as a key to pass data through with an error event, explaining the type of event.
*/
public static final String EVENT_DATA_ERROR_TYPE = "apkDownloadErrorType";
@NonNull private final App app; @NonNull private final App app;
@NonNull private final Apk curApk; @NonNull private final Apk curApk;
@NonNull private final Context context; @NonNull private final Context context;
@ -208,12 +203,6 @@ public class ApkDownloader implements AsyncDownloader.Listener {
sendProgressEvent(new ProgressListener.Event(type)); sendProgressEvent(new ProgressListener.Event(type));
} }
private void sendError(int errorType) {
Bundle data = new Bundle(1);
data.putInt(EVENT_DATA_ERROR_TYPE, errorType);
sendProgressEvent(new Event(EVENT_ERROR, data));
}
// TODO: Completely remove progress listener, only use broadcasts... // TODO: Completely remove progress listener, only use broadcasts...
private void sendProgressEvent(Event event) { private void sendProgressEvent(Event event) {
@ -246,7 +235,8 @@ public class ApkDownloader implements AsyncDownloader.Listener {
public void onDownloadComplete() { public void onDownloadComplete() {
if (!verifyOrDelete(localFile)) { if (!verifyOrDelete(localFile)) {
sendError(ERROR_HASH_MISMATCH); sendProgressEvent(new Event(EVENT_ERROR));
Toast.makeText(context, R.string.corrupt_download, Toast.LENGTH_LONG).show();
return; return;
} }