diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-04-13 11:14:36 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-04-13 11:14:36 +0200 |
commit | 594e65bb2b26d1c99b96c12558bf9d523e68269e (patch) | |
tree | 6ed10aa0316b675a340b9347079fd049b3b90183 /src/main/java/eu/siacs/conversations/persistance/FileBackend.java | |
parent | 4332b0df44bb6345b0fbb861d1bb8d24568ea847 (diff) |
hacky workaround to determine if uri points to private file on < lolipop
Diffstat (limited to 'src/main/java/eu/siacs/conversations/persistance/FileBackend.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/persistance/FileBackend.java | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 0d770fef6..306092141 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -693,13 +693,29 @@ public class FileBackend { } - public static boolean weOwnFile(Uri uri) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + public static boolean weOwnFile(Context context, Uri uri) { + if (uri == null || !ContentResolver.SCHEME_FILE.equals(uri.getScheme())) { return false; + } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + return fileIsInFilesDir(context, uri); } else { - return uri != null - && ContentResolver.SCHEME_FILE.equals(uri.getScheme()) - && weOwnFileLollipop(uri); + return weOwnFileLollipop(uri); + } + } + + + /** + * This is more than hacky but probably way better than doing nothing + * Further 'optimizations' might contain to get the parents of CacheDir and NoBackupDir + * and check against those as well + */ + private static boolean fileIsInFilesDir(Context context, Uri uri) { + try { + final String haystack = context.getFilesDir().getParentFile().getCanonicalPath(); + final String needle = new File(uri.getPath()).getCanonicalPath(); + return needle.startsWith(haystack); + } catch (IOException e) { + return false; } } |