Implement Storage Access Framework

* re-work finished mission database
* re-work DownloadMission and bump it Serializable version
* keep the classic Java IO API
* SAF Tree API support on Android Lollipop or higher
* add wrapper for SAF stream opening
* implement Closeable in SharpStream to replace the dispose() method

* do required changes for this API:
** remove any file creation logic from DownloadInitializer
** make PostProcessing Serializable and reduce the number of iterations
** update all strings.xml files
** storage helpers: StoredDirectoryHelper & StoredFileHelper
** best effort to handle any kind of SAF errors/exceptions
This commit is contained in:
kapodamy 2019-04-05 14:45:39 -03:00
parent 9e34fee58c
commit f6b32823ba
62 changed files with 2439 additions and 1180 deletions

View file

@ -12,11 +12,11 @@ import android.support.v4.content.ContextCompat;
import android.widget.Toast;
import org.schabi.newpipe.R;
import org.schabi.newpipe.streams.io.SharpStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
@ -25,7 +25,8 @@ import java.io.Serializable;
import java.net.HttpURLConnection;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Locale;
import us.shandian.giga.io.StoredFileHelper;
public class Utility {
@ -206,7 +207,7 @@ public class Utility {
Toast.makeText(context, R.string.msg_copied, Toast.LENGTH_SHORT).show();
}
public static String checksum(String path, String algorithm) {
public static String checksum(StoredFileHelper source, String algorithm) {
MessageDigest md;
try {
@ -215,11 +216,11 @@ public class Utility {
throw new RuntimeException(e);
}
FileInputStream i;
SharpStream i;
try {
i = new FileInputStream(path);
} catch (FileNotFoundException e) {
i = source.getStream();
} catch (Exception e) {
throw new RuntimeException(e);
}
@ -247,15 +248,15 @@ public class Utility {
}
@SuppressWarnings("ResultOfMethodCallIgnored")
public static boolean mkdir(File path, boolean allDirs) {
if (path.exists()) return true;
public static boolean mkdir(File p, boolean allDirs) {
if (p.exists()) return true;
if (allDirs)
path.mkdirs();
p.mkdirs();
else
path.mkdir();
p.mkdir();
return path.exists();
return p.exists();
}
public static long getContentLength(HttpURLConnection connection) {