catch security exception when reading file

This commit is contained in:
Daniel Gultsch 2021-03-24 10:47:50 +01:00
parent 9cc95d4cc2
commit 77f448692c
2 changed files with 9 additions and 6 deletions

View file

@ -29,6 +29,7 @@ import android.util.Log;
import android.util.LruCache;
import androidx.annotation.RequiresApi;
import androidx.annotation.StringRes;
import androidx.core.content.FileProvider;
import java.io.ByteArrayOutputStream;
@ -646,12 +647,13 @@ public class FileBackend {
} catch (IOException e) {
throw new FileWriterException();
}
} catch (FileNotFoundException e) {
} catch (final FileNotFoundException e) {
throw new FileCopyException(R.string.error_file_not_found);
} catch (FileWriterException e) {
} catch (final FileWriterException e) {
throw new FileCopyException(R.string.error_unable_to_create_temporary_file);
} catch (IOException e) {
e.printStackTrace();
} catch (final SecurityException e) {
throw new FileCopyException(R.string.error_security_exception);
} catch (final IOException e) {
throw new FileCopyException(R.string.error_io_exception);
} finally {
close(os);
@ -1462,11 +1464,11 @@ public class FileBackend {
public static class FileCopyException extends Exception {
private final int resId;
private FileCopyException(int resId) {
private FileCopyException(@StringRes int resId) {
this.resId = resId;
}
public int getResId() {
public @StringRes int getResId() {
return resId;
}
}

View file

@ -148,6 +148,7 @@
<string name="error_file_not_found">File not found</string>
<string name="error_io_exception">General I/O error. Maybe you ran out of storage space?</string>
<string name="error_security_exception_during_image_copy">The app you used to select this image did not provide enough permissions to read the file.\n\n<small>Use a different file manager to choose an image</small>.</string>
<string name="error_security_exception">The app you used to share this file did not provide enough permissions.</string>
<string name="account_status_unknown">Unknown</string>
<string name="account_status_disabled">Temporarily disabled</string>
<string name="account_status_online">Online</string>