Refactor FilePicker.java
intent result handling
#5851
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #5850
What changes did you make and why?
Removed
CAPTURE_VIDEO
request code and it's checks, while from what I can understand we do not handle video mime type. Though if I missed something and I'm wrong please let me know, happy to make changes.Removed Video's picker test cases.
Only Gallery picker's callback was handling changes for both Document picker and Gallery picker. So, passed appropriate flag to make sure respective callbacks get invoked
EDIT:
isPhoto(data) method checks if the returned data is null or not. Now, it for
Document
andGallery
picker results we rely on returned results so we are making sure it's not null. But, later after all the specific checks we had the above code.To understand the problem, let's say we got the result of
Document
picker which also checks for!isPhoto()
to make sure result is not null. But let's say it is then the above mentioned check would invoke the callback for handling camera result but didn't we returned the result for document picker (however very unlikely to get null from document picker we either get cancelled or result ok, which we already take care of before making these checks).My understanding is this the check was added under the assumption that we store the image in the persistent storage when using camera's result. So it just made simple check if the result is null then it must be camera's result otherwise document's result. But from above we understand that it would wrong to use camera's image (will return the last stored image which is wrong) when user has chosen Document/Gallery one (less likely but still we shouldn't have this check)
Tests performed (required)
Ran test for
FilePicker.java
file.manually tested. below is this demo.
Screencast.from.2024-10-15.02-07-13.webm
Tested {build variant, e.g. ProdDebug} on {name of device or emulator} with API level {API level}.
Build variant: betaDebug
API level: 34 (Emulator) & 34 Oneplus 9RT 5G