mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Bugfix/security exception (#3627)
* Fixes #3626 * Check is file is actually created before writing to file, file picker android * Handle Security exception
This commit is contained in:
parent
c961099013
commit
05a9aa8575
2 changed files with 8 additions and 5 deletions
|
|
@ -166,7 +166,7 @@ public class FilePicker implements Constants {
|
|||
public static List<UploadableFile> handleExternalImagesPicked(Intent data, Activity activity) {
|
||||
try {
|
||||
return getFilesFromGalleryPictures(data, activity);
|
||||
} catch (IOException e) {
|
||||
} catch (IOException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new ArrayList<>();
|
||||
|
|
@ -207,7 +207,7 @@ public class FilePicker implements Constants {
|
|||
}
|
||||
}
|
||||
|
||||
private static List<UploadableFile> getFilesFromGalleryPictures(Intent data, Activity activity) throws IOException {
|
||||
private static List<UploadableFile> getFilesFromGalleryPictures(Intent data, Activity activity) throws IOException, SecurityException {
|
||||
List<UploadableFile> files = new ArrayList<>();
|
||||
ClipData clipData = data.getClipData();
|
||||
if (clipData == null) {
|
||||
|
|
|
|||
|
|
@ -104,12 +104,15 @@ class PickedFiles implements Constants {
|
|||
});
|
||||
}
|
||||
|
||||
static UploadableFile pickedExistingPicture(@NonNull Context context, Uri photoUri) throws IOException {
|
||||
static UploadableFile pickedExistingPicture(@NonNull Context context, Uri photoUri) throws IOException, SecurityException {// SecurityException for those file providers who share URI but forget to grant necessary permissions
|
||||
InputStream pictureInputStream = context.getContentResolver().openInputStream(photoUri);
|
||||
File directory = tempImageDirectory(context);
|
||||
File photoFile = new File(directory, UUID.randomUUID().toString() + "." + getMimeType(context, photoUri));
|
||||
photoFile.createNewFile();
|
||||
writeToFile(pictureInputStream, photoFile);
|
||||
if (photoFile.createNewFile()) {
|
||||
writeToFile(pictureInputStream, photoFile);
|
||||
} else {
|
||||
throw new IOException("could not create photoFile to write upon");
|
||||
}
|
||||
return new UploadableFile(photoUri, photoFile);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue