android 5 (lollipop) fixup

this commit attempts to fix the pickAvailableTemporalDir() method in ROMS that not are CTS compliant.
This commit is contained in:
kapodamy 2020-01-08 14:36:31 -03:00
parent 9f47a274a8
commit 00eddcb237
2 changed files with 24 additions and 9 deletions

View File

@ -80,7 +80,7 @@ public abstract class Postprocessing implements Serializable {
private transient DownloadMission mission; private transient DownloadMission mission;
private File tempFile; private transient File tempFile;
Postprocessing(boolean reserveSpace, boolean worksOnSameFile, String algorithmName) { Postprocessing(boolean reserveSpace, boolean worksOnSameFile, String algorithmName) {
this.reserveSpace = reserveSpace; this.reserveSpace = reserveSpace;
@ -95,8 +95,12 @@ public abstract class Postprocessing implements Serializable {
public void cleanupTemporalDir() { public void cleanupTemporalDir() {
if (tempFile != null && tempFile.exists()) { if (tempFile != null && tempFile.exists()) {
//noinspection ResultOfMethodCallIgnored try {
tempFile.delete(); //noinspection ResultOfMethodCallIgnored
tempFile.delete();
} catch (Exception e) {
// nothing to do
}
} }
} }

View File

@ -139,6 +139,9 @@ public class DownloadManager {
Log.d(TAG, "Loading pending downloads from directory: " + mPendingMissionsDir.getAbsolutePath()); Log.d(TAG, "Loading pending downloads from directory: " + mPendingMissionsDir.getAbsolutePath());
} }
File tempDir = pickAvailableTemporalDir(ctx);
Log.i(TAG, "using '" + tempDir + "' as temporal directory");
for (File sub : subs) { for (File sub : subs) {
if (!sub.isFile()) continue; if (!sub.isFile()) continue;
if (sub.getName().equals(".tmp")) continue; if (sub.getName().equals(".tmp")) continue;
@ -184,7 +187,7 @@ public class DownloadManager {
if (mis.psAlgorithm != null) { if (mis.psAlgorithm != null) {
mis.psAlgorithm.cleanupTemporalDir(); mis.psAlgorithm.cleanupTemporalDir();
mis.psAlgorithm.setTemporalDir(pickAvailableTemporalDir(ctx)); mis.psAlgorithm.setTemporalDir(tempDir);
} }
mis.metadata = sub; mis.metadata = sub;
@ -513,13 +516,21 @@ public class DownloadManager {
} }
static File pickAvailableTemporalDir(@NonNull Context ctx) { static File pickAvailableTemporalDir(@NonNull Context ctx) {
if (isDirectoryAvailable(ctx.getExternalFilesDir(null))) File dir = ctx.getExternalFilesDir(null);
return ctx.getExternalFilesDir(null); if (isDirectoryAvailable(dir)) return dir;
else if (isDirectoryAvailable(ctx.getFilesDir()))
return ctx.getFilesDir(); dir = ctx.getFilesDir();
if (isDirectoryAvailable(dir)) return dir;
// this never should happen // this never should happen
return ctx.getDir("tmp", Context.MODE_PRIVATE); dir = ctx.getDir("muxing_tmp", Context.MODE_PRIVATE);
if (isDirectoryAvailable(dir)) return dir;
// fallback to cache dir
dir = ctx.getCacheDir();
if (isDirectoryAvailable(dir)) return dir;
throw new RuntimeException("Not temporal directories are available");
} }
@Nullable @Nullable