-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Refactor Image Loading: Use Internal Storage with Content URI for Enhanced Security and Compatibility #17846
Conversation
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.
Seems like it should work, and this will be a nice improvement, thank you
Left a style note about shifting to a quick-return vs deep if/else nesting
Left a note that's a must-change (but an easy one) about log levels
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Outdated
Show resolved
Hide resolved
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.
This works for me - it.exists()
may not be strictly necessary but a little extra checking can't hurt here
Timber.w now - thank you, early returns so nesting is avoided but error conditions are cleanly dealt with one by one in an obvious way - thank you
Good call-out from David to indicate to the user something went wrong, that's a good addition
This will be a nice fix for the share case, and now in combination with the crop fix where png/webp go through, we should have a "really, it works!" feature for sharing images to ankidroid from the context menu.
That add image via share feature broke when we started using the WebView in order to add sharing an SVG as a feature - which is a lesson in unintended consequences! But now all working I think, jpg, svg, png, webp
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Show resolved
Hide resolved
Marked for high priority review so we can get this in (hopefully) QA ✅ - I have pulled the PR locally and confirm that images shared (from, for instance, android files app or gallery) are now correctly displayed in the previewer when you use "AnkiDroid - Add Image" system share target, so this passes testing Still doesn't preserve transparency on crop but that's separate of course - I'm surprised that #17840 isn't in yet! - will push on that one |
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 then
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, thanks!
Please squash the two commits.
…ent uri to pre-view the image.
Thanks! |
Purpose / Description
Fixes
Fixes #17776
Superseeds and closes #17778
Approach
Internalizing Shared Images:
The shared image is first internalized, ensuring it’s stored temporarily within AnkiDroid's private storage, making it accessible only to the app. This resolves any issues related to image accessibility or permission errors.
Using content:// URIs:
By utilizing Android's FileProvider to generate content:// URIs, the PR avoids direct file path access, which may fail on newer Android versions (Android 10 and above). The content:// URI provides a safe, standardized way to share and access files between apps, complying with Android’s modern file access restrictions.
WebView Compatibility:
The PR fixes the issue where images weren't displaying by using the content:// URI format in WebView. This ensures proper loading of images in the app without needing risky settings, which could expose sensitive data or create security vulnerabilities.
How Has This Been Tested?
Manual Testing on Samsung F23 5G
test_loadimage.mp4
Checklist
Please, go through these checks before submitting the PR.