~singpolyma/cheogram-android

35c54f0ae968ba76b78fed6c7081d52d2404c9ef — Daniel Gultsch 2 years ago 48f8c1a
delete pre lolipop weOwnFile()
M src/main/java/eu/siacs/conversations/persistance/FileBackend.java => src/main/java/eu/siacs/conversations/persistance/FileBackend.java +2 -19
@@ 354,32 354,15 @@ public class FileBackend {
        }
    }

    public static boolean weOwnFile(Context context, Uri uri) {
    public static boolean weOwnFile(final 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 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;
        }
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private static boolean weOwnFileLollipop(Uri uri) {
    private static boolean weOwnFileLollipop(final Uri uri) {
        try {
            File file = new File(uri.getPath());
            FileDescriptor fd =

M src/main/java/eu/siacs/conversations/ui/ConversationFragment.java => src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +2 -2
@@ 2255,10 2255,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
    }

    private List<Uri> cleanUris(final List<Uri> uris) {
        Iterator<Uri> iterator = uris.iterator();
        final Iterator<Uri> iterator = uris.iterator();
        while (iterator.hasNext()) {
            final Uri uri = iterator.next();
            if (FileBackend.weOwnFile(getActivity(), uri)) {
            if (FileBackend.weOwnFile(uri)) {
                iterator.remove();
                Toast.makeText(getActivity(), R.string.security_violation_not_attaching_file, Toast.LENGTH_SHORT).show();
            }