google / modernstorage

ModernStorage is a group of libraries that provide an abstraction layer over storage on Android to simplify its interactions
https://google.github.io/modernstorage/
Apache License 2.0
1.24k stars 54 forks source link

Treat last_modified and mime_type columns from DocumentProvider as nullable #100

Open saket opened 1 year ago

saket commented 1 year ago

OpenableColumns makes it clear that a DocumentProvider is only required to implement two columns: OpenableColumns.DISPLAY_NAME and OpenableColumns.SIZE. All other columns are optional and can cause modernstorage to crash because it expects last_modified and mime_type to be always present.

Example 1: Files by Google

FATAL EXCEPTION: main
    Process: me.saket.teleport.debug, PID: 9944
    java.lang.IllegalArgumentException: Invalid column last_modified
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:172)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
        at android.content.ContentProviderProxy.query(ContentProviderNative.java:481)
        at android.content.ContentResolver.query(ContentResolver.java:1219)
        at android.content.ContentResolver.query(ContentResolver.java:1151)
        at android.content.ContentResolver.query(ContentResolver.java:1107)
        at com.google.modernstorage.storage.AndroidFileSystem.fetchMetadataFromDocumentProvider(AndroidFileSystem.kt:302)
        at com.google.modernstorage.storage.AndroidFileSystem.metadataOrNull(AndroidFileSystem.kt:185)

Example 2: Cx file explorer

FATAL EXCEPTION: main
    Process: me.saket.teleport.debug, PID: 9439
    java.lang.IllegalStateException: Couldn't read row 0, col 3 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
        at android.database.CursorWindow.nativeGetLong(Native Method)
        at android.database.CursorWindow.getLong(CursorWindow.java:539)
        at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:78)
        at android.database.CursorWrapper.getLong(CursorWrapper.java:131)
        at com.google.modernstorage.storage.AndroidFileSystem.fetchMetadataFromDocumentProvider(AndroidFileSystem.kt:327)
        at com.google.modernstorage.storage.AndroidFileSystem.metadataOrNull(AndroidFileSystem.kt:185)

This PR treats those two columns as nullable. Thoughts?