more fixes

* use bold style in status (mission_item_linear.xml)
* fix download attemps not begin updated
* dont stop the queue if a download fails
* implement partial wake-lock & wifi-lock
* show notifications for failed downloads
* ¿proper bitmap dispose? (DownloadManagerService.java)
* improve buffer filling (CircularFile.java)
* [Mp4Dash] increment reserved space from 2MiB to 15MiB. This is expensive but useful for devices with low ram
* [WebM] use 2MiB of reserved space
* fix debug warning if one thread is used
* fix wrong download speed when the activity is suspended
* Fix "Queue" menu item that appears in post-processing errors
* fix mission length dont being updated (missing commit)
This commit is contained in:
kapodamy 2018-11-20 19:10:50 -03:00
parent fef9d541ed
commit d647555e3a
19 changed files with 400 additions and 150 deletions

View file

@ -116,7 +116,6 @@ public class DownloadManager {
return result;
}
@SuppressWarnings("ResultOfMethodCallIgnored")
private void loadPendingMissions() {
File[] subs = mPendingMissionsDir.listFiles();
@ -136,9 +135,11 @@ public class DownloadManager {
DownloadMission mis = Utility.readFromFile(sub);
if (mis == null) {
//noinspection ResultOfMethodCallIgnored
sub.delete();
} else {
if (mis.isFinished()) {
//noinspection ResultOfMethodCallIgnored
sub.delete();
continue;
}
@ -173,6 +174,7 @@ public class DownloadManager {
m.threadCount = mis.threadCount;
m.source = mis.source;
m.maxRetry = mis.maxRetry;
m.nearLength = mis.nearLength;
mis = m;
}
@ -204,7 +206,7 @@ public class DownloadManager {
* @param postProcessingArgs the arguments for the post-processing algorithm.
*/
void startMission(String[] urls, String location, String name, char kind, int threads, String source,
String postprocessingName, String[] postProcessingArgs) {
String postprocessingName, String[] postProcessingArgs, long nearLength) {
synchronized (this) {
// check for existing pending download
DownloadMission pendingMission = getPendingMission(location, name);
@ -229,6 +231,7 @@ public class DownloadManager {
mission.source = source;
mission.mHandler = mHandler;
mission.maxRetry = mPrefs.getInt(mPrefMaxRetry, 3);
mission.nearLength = nearLength;
while (true) {
mission.metadata = new File(mPendingMissionsDir, String.valueOf(mission.timestamp));
@ -406,26 +409,30 @@ public class DownloadManager {
* Set a pending download as finished
*
* @param mission the desired mission
* @return true if exits pending missions running, otherwise, false
*/
boolean setFinished(DownloadMission mission) {
void setFinished(DownloadMission mission) {
synchronized (this) {
int i = mMissionsPending.indexOf(mission);
mMissionsPending.remove(i);
mMissionsPending.remove(mission);
mMissionsFinished.add(0, new FinishedMission(mission));
mDownloadDataSource.addMission(mission);
}
}
/**
* runs another mission in queue if possible
* @return true if exits pending missions running or a mission was started, otherwise, false
*/
boolean runAnotherMission() {
synchronized (this) {
if (mMissionsPending.size() < 1) return false;
i = getRunningMissionsCount();
int i = getRunningMissionsCount();
if (i > 0) return true;
// before returning, check the queue
if (!canDownloadInCurrentNetwork()) return false;
for (DownloadMission mission1 : mMissionsPending) {
if (!mission1.running && mission.errCode != DownloadMission.ERROR_POSTPROCESSING_FAILED && mission1.enqueued) {
for (DownloadMission mission : mMissionsPending) {
if (!mission.running && mission.errCode != DownloadMission.ERROR_POSTPROCESSING_FAILED && mission.enqueued) {
resumeMission(mMissionsPending.get(i));
return true;
}
@ -481,6 +488,12 @@ public class DownloadManager {
if (flag) mHandler.sendEmptyMessage(DownloadManagerService.MESSAGE_PAUSED);
}
void updateMaximumAttempts(int maxRetry) {
synchronized (this) {
for (DownloadMission mission : mMissionsPending) mission.maxRetry = maxRetry;
}
}
/**
* Fast check for pending downloads. If exists, the user will be notified
* TODO: call this method in somewhere