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
Add tests to show document media provider crashes #2531
base: master
Are you sure you want to change the base?
Conversation
Generated by 🚫 Danger |
I was wrong here. The code I linked was for 8 years old commit. I looked at the latest code for MediaDocumentProvider and it indeed has a check for |
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.
Addtionally, the crash happens when users are installing the offline ccz but rather than providing a path to valid ccz file, they're selecting any random path.
So perhaps we should first check the file extension before doing any processing maybe?
yeah if that's possible it would be great.
Though we should not merge this test without the fix as it's an anti-pattern in the code to have tests for failing behaviours. It formalizes an expectation that we are supposed to crash in such a case which is not true.
Agreed, I was looking into https://android.googlesource.com/platform/packages/providers/MediaProvider/+/refs/heads/master/src/com/android/providers/media/MediaDocumentsProvider.java#423 to figure out how to get the path from a DocumentsProvider but haven't been successful so far. So I'm thinking about this approach:
2nd point is why I'm still searching on possible ways to get file path from the documents provider uri. |
One other thought, if it's a |
already tried that, it returns the uri itself |
I see, I think returning URI is a valid response from here if we can't find a better solution to it. We do seem to handle for URI later in the code path. |
@damagatchi retest this please |
Can one of the admins verify this patch? |
Summary
Adds a test to confirm this crash: https://console.firebase.google.com/u/0/project/commcare-a57e4/crashlytics/app/android:org.commcare.dalvik/issues/5ce2e2aaf8b88c2963706428?time=last-thirty-days&versions=2.52.1%20(464182)&sessionEventKey=6133BA63028B00010FB080C17D73CF8E_1582592414843474720
I initially wanted to add it as a unit test, but I couldn't get it work with the content resolver queries.
Details about the crash:
ACTION_GET_CONTENT
has an option for documents provider just like it has options for image, audio or video providers. When you select a pdf document from a document provider, it gives a uri like this:content://com.android.providers.media.documents/document/document:59845
.https://github.com/dimagi/commcare-android/blob/master/app/src/org/commcare/utils/UriToFilePath.java#L64-L83 Our code here correctly identifies it as a media provider uri, and then it checks the type. In our case the type is
document
, but the checks only exists for image, audio and video types.So the call to
getDataColumn
happens with a nullcontentUri
and it fails.The only thing that I'm concerned here is that https://android.googlesource.com/platform/packages/providers/MediaProvider/+/5d36def/src/com/android/providers/media/MediaDocumentsProvider.java#123 the official
MediaDocumentProvider
class also only checks the types to be one of image, audio or video. So I'm not sure if this should be handled here or not.Addtionally, the crash happens when users are installing the offline
ccz
but rather than providing a path to valid ccz file, they're selecting any random path.So perhaps we should first check the file extension before doing any processing maybe?
But also, we should be able to support getting paths for document file types using
UriToFilePath
.This is just a test PR. Will create a follow up PR for the fix.
Feature Flag
Product Description
Safety Assurance
Automated test coverage
Safety story