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:
Ashish Kumar 2020-04-17 12:29:30 +05:30 committed by GitHub
parent c961099013
commit 05a9aa8575
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View file

@ -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) {

View file

@ -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);
}