Skip to content
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

Merged
merged 10 commits into from
Feb 12, 2024

Conversation

geriux
Copy link
Contributor

@geriux geriux commented Feb 7, 2024

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 original uri to the media type validation functions.

It also includes a change in WordPress Utils where it adds the heic and heif 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

  • Open an image editing app like Lightroom
  • Edit an image and share it to the Jetpack app
  • Tap on Add to new post
  • Expect the editor to be opened and the image to be loaded

Share an image from a browser

  • Open a web browser
  • Go to any website and long-press on an image
  • Share the image to the Jetpack app
  • Tap on Add to new post
  • Expect the editor to be opened and the image to be loaded

Share an image from the Photos app

  • Open the Photos app
  • Select an image or images
  • Share the image(s) to the Jetpack app
  • Tap on Add to new post
  • Expect the editor to be opened and the image(s) to be loaded

Share an image from a Files Explorer app

  • Open the Files Explorer app
  • Select an image or images
  • Share the image(s) to the Jetpack app
  • Tap on Add to new post
  • Expect the editor to be opened and the image(s) to be loaded

Share a HEIC image

  • Open the Gallery/Files app
  • Select a heic image
  • Share the image to the Jetpack app
  • Tap on Add to new post
  • Expect the editor to be opened and the image to be loaded

Regression Notes

  1. Potential unintended areas of impact

    • N/A, it should only affect sharing media through intents.
  2. What I did to test those areas of impact (or what existing automated tests I relied on)

    • Manual testing
  3. What automated tests I added (or what prevented me from doing so)

    • N/A, relied on manual testing.

PR Submission Checklist:

  • I have completed the Regression Notes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Testing Checklist:

  • WordPress.com sites and self-hosted Jetpack sites.
  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • Talkback.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • Large and small screen sizes. (Tablet and smaller phones)
  • Multi-tasking: Split screen and Pop-up view. (Android 10 or higher)

@geriux geriux added this to the 24.2 ❄️ milestone Feb 7, 2024
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Feb 7, 2024

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr20138-6c13ba8
Commit6c13ba8
Direct Downloadwordpress-prototype-build-pr20138-6c13ba8.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Feb 7, 2024

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr20138-6c13ba8
Commit6c13ba8
Direct Downloadjetpack-prototype-build-pr20138-6c13ba8.apk
Note: Google Login is not supported on these builds.

@geriux geriux marked this pull request as ready for review February 7, 2024 14:27
@peril-wordpress-mobile
Copy link

Warnings
⚠️ This PR is assigned to a milestone which is closing in less than 4 days Please, make sure to get it merged by then or assign it to a later expiring milestone

Generated by 🚫 dangerJS

@dangermattic
Copy link
Collaborator

dangermattic commented Feb 7, 2024

1 Warning
⚠️ This PR is assigned to the milestone 24.2 ❄️. The due date for this milestone has already passed.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.

Generated by 🚫 Danger

@fluiddot fluiddot self-requested a review February 7, 2024 16:23
Comment on lines +121 to +124
// For cases when getRealPathFromURI returns an empty string
if (TextUtils.isEmpty(filePath)) {
filePath = String.valueOf(uri);
}
Copy link
Contributor

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 🙇 !

Copy link
Contributor

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.

Copy link
Contributor

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:

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.

Copy link
Contributor Author

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

Copy link
Contributor

@fluiddot fluiddot left a 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.

Copy link
Contributor

@fluiddot fluiddot left a 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);
Copy link
Contributor

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.

Copy link
Contributor Author

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!

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

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 😅

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@antonis antonis left a 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

@wpmobilebot
Copy link
Contributor

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

@geriux geriux merged commit 9972cb5 into release/24.2 Feb 12, 2024
20 checks passed
@geriux geriux deleted the fix/sharing-image-regression branch February 12, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants