aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java47
1 files changed, 4 insertions, 43 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java
index 236913be7..c4d84a2d4 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java
@@ -273,56 +273,17 @@ public class FileHelper {
}
/**
- * Tests whether a file is readable by others
- */
- @TargetApi(VERSION_CODES.LOLLIPOP)
- public static boolean S_IROTH(int mode) {
- return (mode & S_IROTH) == S_IROTH;
- }
-
- /**
* A replacement for ContentResolver.openInputStream() that does not allow the usage of
* "file" Uris that point to private files owned by the application only.
*
- * This is not allowed:
- * am start -a android.intent.action.SEND -t text/plain -n
- * "org.sufficientlysecure.keychain.debug/org.sufficientlysecure.keychain.ui.EncryptFilesActivity" --eu
- * android.intent.extra.STREAM
- * file:///data/data/org.sufficientlysecure.keychain.debug/databases/openkeychain.db
- *
- * @throws FileNotFoundException
+ * @see FileHelperLollipop
*/
- @TargetApi(VERSION_CODES.LOLLIPOP)
public static InputStream openInputStreamSafe(ContentResolver resolver, Uri uri)
- throws FileNotFoundException {
+ throws FileNotFoundException {
// Not supported on Android < 5
- if (Build.VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) {
- return resolver.openInputStream(uri);
- }
-
- String scheme = uri.getScheme();
- if (ContentResolver.SCHEME_FILE.equals(scheme)) {
- ParcelFileDescriptor pfd = ParcelFileDescriptor.open(
- new File(uri.getPath()), ParcelFileDescriptor.parseMode("r"));
-
- try {
- final StructStat st = Os.fstat(pfd.getFileDescriptor());
- if (!S_IROTH(st.st_mode)) {
- Log.e(Constants.TAG, "File is not readable by others, aborting!");
- throw new FileNotFoundException("Unable to create stream");
- }
- } catch (ErrnoException e) {
- Log.e(Constants.TAG, "fstat() failed: " + e);
- throw new FileNotFoundException("fstat() failed");
- }
-
- AssetFileDescriptor fd = new AssetFileDescriptor(pfd, 0, -1);
- try {
- return fd.createInputStream();
- } catch (IOException e) {
- throw new FileNotFoundException("Unable to create stream");
- }
+ if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
+ return FileHelperLollipop.openInputStreamSafe(resolver, uri);
} else {
return resolver.openInputStream(uri);
}