5196: Fix location stripped from EXIF metadata (#5227)

* MainActivity: add ACCESS_MEDIA_LOCATION permission check to retain location info in EXIF metadata

* remove redundant permission check and optimise imports

* FilePicker: switch to ACTION_OPEN_DOCUMENT intent for opening image files

* add a comment explaining the change

* implement GET_CONTENT photo picker toggle switch

* add location loss warning pop up

* SettingsFragment: modify the comment about GET_CONTENT takeover for more clarity
This commit is contained in:
Ritika Pahwa 2023-06-15 06:35:55 +05:30 committed by GitHub
parent 4d71c305f2
commit 9a0f35c681
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 97 additions and 20 deletions

View file

@ -46,10 +46,11 @@ public class FilePicker implements Constants {
return uri;
}
private static Intent createGalleryIntent(@NonNull Context context, int type) {
private static Intent createGalleryIntent(@NonNull Context context, int type,
boolean isGetContentPickerPreferred) {
// storing picked image type to shared preferences
storeType(context, type);
return plainGalleryPickerIntent()
return plainGalleryPickerIntent(isGetContentPickerPreferred)
.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, configuration(context).allowsMultiplePickingInGallery());
}
@ -105,8 +106,8 @@ public class FilePicker implements Constants {
*
* @param type Custom type of your choice, which will be returned with the images
*/
public static void openGallery(Activity activity, int type) {
Intent intent = createGalleryIntent(activity, type);
public static void openGallery(Activity activity, int type, boolean isGetContentPickerPreferred) {
Intent intent = createGalleryIntent(activity, type, isGetContentPickerPreferred);
activity.startActivityForResult(intent, RequestCodes.PICK_PICTURE_FROM_GALLERY);
}
@ -200,8 +201,40 @@ public class FilePicker implements Constants {
return data == null || (data.getData() == null && data.getClipData() == null);
}
private static Intent plainGalleryPickerIntent() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
private static Intent plainGalleryPickerIntent(boolean isGetContentPickerPreferred) {
/**
* Asking for ACCESS_MEDIA_LOCATION at runtime solved the location-loss issue
* in the custom selector in Contributions fragment.
* Detailed discussion: https://github.com/commons-app/apps-android-commons/issues/5015
*
* This permission check, however, was insufficient to fix location-loss in
* the regular selector in Contributions fragment and Nearby fragment,
* especially on some devices running Android 13 that use the new Photo Picker by default.
*
* New Photo Picker: https://developer.android.com/training/data-storage/shared/photopicker
*
* The new Photo Picker introduced by Android redacts location tags from EXIF metadata.
* Reported on the Google Issue Tracker: https://issuetracker.google.com/issues/243294058
* Status: Won't fix (Intended behaviour)
*
* Switched intent from ACTION_GET_CONTENT to ACTION_OPEN_DOCUMENT
* (based on user's preference) as:
*
* ACTION_GET_CONTENT opens the 'best application' for choosing that kind of data
* The best application is the new Photo Picker that redacts the location tags
*
* ACTION_OPEN_DOCUMENT, however, displays the various DocumentsProvider instances
* installed on the device, letting the user interactively navigate through them.
*
* So, this allows us to use the traditional file picker that does not redact location tags from EXIF.
*
*/
Intent intent;
if (isGetContentPickerPreferred) {
intent = new Intent(Intent.ACTION_GET_CONTENT);
} else {
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
}
intent.setType("image/*");
return intent;
}