-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix sharing image regression and add support for heic and heif files #20138
Conversation
📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
|
Generated by 🚫 dangerJS |
// For cases when getRealPathFromURI returns an empty string | ||
if (TextUtils.isEmpty(filePath)) { | ||
filePath = String.valueOf(uri); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why the URI is not properly parsed. I debugged the code and found that it's caused by this line returning false
. My presumption is that for URIs like the following it should work:
content://media/external/images/media/1000000246
(media file from Gallery app)content://com.adobe.lrmobile.provider/myimages/20231013_1723402258340274679050296%20(17).jpg
(media file from Adobe Lightroom app)
Might be related to the Android version, although I haven't found any references in the documentation.
This code was introduced in 2017, so it might be a long shot, but I wonder @daniloercoli as author, if you could provide any info about this logic. Thanks for the help 🙇 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might not be critical, but the fact that we extract the path from the URI makes me hesitant about whether we can simply convert it to string
. Not sure if this might introduce undesired side-effects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize that the function isAllowedMediaType
was introduced recently in #19754:
WordPress-Android/WordPress/src/main/java/org/wordpress/android/ui/ShareIntentReceiverActivity.java
Lines 119 to 126 in 0c98841
private boolean isAllowedMediaType(@NonNull Uri uri) { | |
String filePath = MediaUtils.getRealPathFromURI(this, uri); | |
// For cases when getRealPathFromURI returns an empty string | |
if (TextUtils.isEmpty(filePath)) { | |
filePath = String.valueOf(uri); | |
} | |
return MediaUtils.isValidImage(filePath) || MediaUtils.isVideo(filePath); | |
} |
This reduces my concern about providing a fallback in case the URI can't be processed, as mentioned in #20138 (comment). Hence, I think we can proceed with this approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think the whole code that handles this should be revisited with the app permissions logic as well, which is something that was changed recently. The sharing media behavior is also different between OS versions and apps, so definitely worth looking into it to fix issues like this one #20140
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@geriux I tested the different test cases and confirmed it fixes the issue and works as expected. From my side, these changes look good. However, I'd like to defer my approval to @wordpress-mobile/android-developers, especially due to the concerns raised in https://github.com/wordpress-mobile/WordPress-Android/pull/20138/files#r1481890026.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎊 !
As shared in #20138 (comment), I'm now more confident about this solution.
mLocalMediaUris.add(MediaUtils.downloadExternalMedia(this, externalUri)); | ||
} | ||
} catch (Exception e) { | ||
AppLog.e(T.MEDIA, "ShareIntentReceiver failed to download media ", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to communicate the error to the user here (e.g. with ToastUtils.showToast
)
Note that I wasn't able to reach this Exception
flow in my tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! I'll add it, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a reference, this is how it will look like:
LoadMediaMessage.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the error message could mention the sharing action, Unable to load media
might be a bit cryptic to users. What about something like Unable to share media due to an error when loading, please try sharing other media files.
. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it but since this is to be included in the beta, I'm not sure how we usually handle new strings. Do you know if we are still in time to get it translated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user encounters the permissions issue, any file will give an error by the way 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it but since this is to be included in the beta, I'm not sure how we usually handle new strings. Do you know if we are still in time to get it translated?
Ah, good point. I saw that the PR #20156 recently updated the translations, so maybe we are still on time. cc @spencertransier
If the user encounters the permissions issue, any file will give an error by the way 😅
True. I presume we'd need to check the error type to provide the correct details in the error message. In that case, we could either expand the message to include potential permissions issues or make it more generic:
- Option 1:
Unable to share media.
- Option 2:
Unable to share media due to an error when loading.
- Option 3:
Unable to share media due to an error when loading, please try sharing other media files or check app permissions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Option 3:
Unable to share media due to an error when loading, please try sharing other media files or check app permissions.
If we choose a new resource option 3 sounds better to me since it provides some guidance to the user. I'm not sure if the please try sharing other media files
is helpful though if the user tries sharing with the same method/app. Wdyt of:
Unable to load the media for sharing. Please check the app's permissions or use the app's media library.
?
If we go with a long text we should also pass the ToastUtils.Duration.LONG
parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you both for the suggestions! 🙇♂️ I have updated in 42ad16f Once CI checks pass I'll merge this PR and ask for the translations process internally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your work on this @geriux 🙇
I was able to reproduce the image loading failure with Adobe Lightroom on a Pixel 5 (Android 14) and confirmed that the introduced fix works.
The code changes also look consistent 🎉
I left a minor non blocking suggestion with https://github.com/wordpress-mobile/WordPress-Android/pull/20138/files#r1482753237
Found 1 violations: The PR caused the following dependency changes:-\--- org.wordpress:utils:{strictly 3.12.0} -> 3.12.0
+\--- org.wordpress:utils:{strictly 3.13.0} -> 3.13.0
Please review and act accordingly
|
Related PRs:
Fixes an issue where some shared images into the app aren't being loaded in a post/media library correctly.
To address this problem, it adds a fallback when
getRealPathFromURI
returns an empty string, where it will return the originaluri
to the media type validation functions.It also includes a change in WordPress Utils where it adds the
heic
andheif
formats.I've also created this #20140 where it captures an issue where in some cases it's not possible to share an image to the app due to permissions denial. To prevent a crash, a try/catch has been added until that issue is solved.
To Test:
Share an image from an image editing app
Add to new post
Share an image from a browser
Add to new post
Share an image from the Photos app
Add to new post
Share an image from a Files Explorer app
Add to new post
Share a HEIC image
heic
imageAdd to new post
Regression Notes
Potential unintended areas of impact
What I did to test those areas of impact (or what existing automated tests I relied on)
What automated tests I added (or what prevented me from doing so)
PR Submission Checklist:
RELEASE-NOTES.txt
if necessary.Testing Checklist: