delete pre lolipop weOwnFile()

This commit is contained in:
Daniel Gultsch 2022-02-23 12:16:49 +01:00
parent 48f8c1a6a0
commit 35c54f0ae9
2 changed files with 4 additions and 21 deletions

View file

@ -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())) { if (uri == null || !ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
return false; return false;
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return fileIsInFilesDir(context, uri);
} else { } else {
return weOwnFileLollipop(uri); return weOwnFileLollipop(uri);
} }
} }
/** private static boolean weOwnFileLollipop(final Uri 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) {
try { try {
File file = new File(uri.getPath()); File file = new File(uri.getPath());
FileDescriptor fd = FileDescriptor fd =

View file

@ -2255,10 +2255,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
private List<Uri> cleanUris(final List<Uri> uris) { private List<Uri> cleanUris(final List<Uri> uris) {
Iterator<Uri> iterator = uris.iterator(); final Iterator<Uri> iterator = uris.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
final Uri uri = iterator.next(); final Uri uri = iterator.next();
if (FileBackend.weOwnFile(getActivity(), uri)) { if (FileBackend.weOwnFile(uri)) {
iterator.remove(); iterator.remove();
Toast.makeText(getActivity(), R.string.security_violation_not_attaching_file, Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), R.string.security_violation_not_attaching_file, Toast.LENGTH_SHORT).show();
} }