|
|
@@ -150,7 +150,9 @@ public class DownloadService extends Service {
|
|
|
case "apk":
|
|
|
default:
|
|
|
DownLoadInfo downloadInfo = downloadUtil.setDownloadTaskTotal(task.getUrl(), totalLength);
|
|
|
- EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_START).setData(downloadInfo));
|
|
|
+ if (downloadInfo != null) {
|
|
|
+ EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_START).setData(downloadInfo));
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -170,7 +172,9 @@ public class DownloadService extends Service {
|
|
|
case "apk":
|
|
|
default:
|
|
|
DownLoadInfo downloadInfo = downloadUtil.setDownloadTaskPercent(currentOffset, taskSpeed.averageSpeed(), task.getId(), task.getUrl());
|
|
|
- EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_RUNNING).setData(downloadInfo));
|
|
|
+ if (downloadInfo != null) {
|
|
|
+ EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_RUNNING).setData(downloadInfo));
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -197,8 +201,10 @@ public class DownloadService extends Service {
|
|
|
case COMPLETED://下载完成
|
|
|
if (task.getFile() != null) {
|
|
|
downLoadInfo = downloadUtil.setDownloadTaskFinish(task.getUrl(), task.getFile().getAbsolutePath());
|
|
|
+ if (downLoadInfo != null) {
|
|
|
+ EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_COMPLETE).setData(downLoadInfo));
|
|
|
+ }
|
|
|
ApkUtils.installApk(getApplicationContext(), task.getFile().getAbsolutePath());
|
|
|
- EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_COMPLETE).setData(downLoadInfo));
|
|
|
}
|
|
|
break;
|
|
|
case PRE_ALLOCATE_FAILED://预先分配失败
|
|
|
@@ -209,11 +215,13 @@ public class DownloadService extends Service {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
downLoadInfo = downloadUtil.getDownloadTaskByUrl(task.getUrl());
|
|
|
- downLoadInfo.setMStatus(DownloadUtil.STATUS_FAIL);
|
|
|
- if (realCause != null)
|
|
|
- downLoadInfo.setRealCauseMsg(realCause.getMessage());
|
|
|
- DDProviderHelper.getInstance().updateDownload(downLoadInfo);
|
|
|
- EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_FAIL).setData(downLoadInfo));
|
|
|
+ if (downLoadInfo != null) {
|
|
|
+ downLoadInfo.setMStatus(DownloadUtil.STATUS_FAIL);
|
|
|
+ if (realCause != null)
|
|
|
+ downLoadInfo.setRealCauseMsg(realCause.getMessage());
|
|
|
+ DDProviderHelper.getInstance().updateDownload(downLoadInfo);
|
|
|
+ EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_FAIL).setData(downLoadInfo));
|
|
|
+ }
|
|
|
break;
|
|
|
case FILE_BUSY:
|
|
|
case ERROR://下载错误
|
|
|
@@ -236,12 +244,16 @@ public class DownloadService extends Service {
|
|
|
} else {
|
|
|
if (downLoadInfo != null) {
|
|
|
EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_FAIL).setData(downLoadInfo));
|
|
|
+ } else {
|
|
|
+ EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_FAIL));
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
case CANCELED://取消下载
|
|
|
downLoadInfo = downloadUtil.setDownloadTaskStatus(task.getUrl(), DownloadUtil.STATUS_PAUSE);
|
|
|
- EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_STOP).setData(downLoadInfo));
|
|
|
+ if (downLoadInfo != null) {
|
|
|
+ EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_STOP).setData(downLoadInfo));
|
|
|
+ }
|
|
|
break;
|
|
|
case SAME_TASK_BUSY:
|
|
|
break;
|