android / storage-samples

Multiple samples showing the best practices in storage APIs on Android.
Apache License 2.0
1.54k stars 579 forks source link

Is it normal for functions to be called multiple times in StorageProvider? #54

Open jacopotediosi opened 4 years ago

jacopotediosi commented 4 years ago

I am studying Documents Providers and I have found something that I cannot understand, which also happens with the "StorageProvider" example of this repository.

It appears that all functions are called more than once when I open SAF.

I report the logcat:

When I first open SAF:

2020-05-27 19:57:45.888 20322-20362/com.example.android.storageprovider V/MyCloudProvider: queryDocument
2020-05-27 19:57:45.971 20322-20362/com.example.android.storageprovider V/MyCloudProvider: queryChildDocuments, parentDocumentId: root: sortOrder: _display_name ASC
2020-05-27 19:57:45.990 20322-20362/com.example.android.storageprovider V/MyCloudProvider: queryChildDocuments, parentDocumentId: root: sortOrder: _display_name ASC
2020-05-27 19:57:46.036 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocumentThumbnail
2020-05-27 19:57:46.078 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocumentThumbnail
2020-05-27 19:57:46.093 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocumentThumbnail
2020-05-27 19:57:46.109 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocumentThumbnail

When I open a file (eg a photo with Google Foto):

2020-05-27 19:58:01.127 20322-20341/com.example.android.storageprovider V/MyCloudProvider: queryDocument
2020-05-27 19:58:01.273 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
2020-05-27 19:58:01.306 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
2020-05-27 19:58:01.344 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
2020-05-27 19:58:01.345 20322-20341/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
2020-05-27 19:58:01.381 20322-20341/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
2020-05-27 19:58:01.775 20322-20341/com.example.android.storageprovider V/MyCloudProvider: queryDocument
2020-05-27 19:58:01.810 20322-20341/com.example.android.storageprovider V/MyCloudProvider: queryDocument
2020-05-27 19:58:01.843 20322-20341/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
2020-05-27 19:58:01.849 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
2020-05-27 19:58:01.854 20322-20341/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
2020-05-27 19:58:01.868 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r

Is it normal for queryDocument() and openDocument () to be called so many times? That way, if my document provider were to download a file over the network, wouldn't it be downloaded multiple times?

lukeisontheroad commented 4 years ago

@jacopotediosi we do see the same issue on an Android 8.1 device. Were you able to fix this?

jacopotediosi commented 4 years ago

@lukeisontheroad Unfortunately no. The documentation is very weak on this point.

cketti commented 4 years ago

I think these are absolutely cases that you need to be able to handle. Even if the SAF screen is changed to only query your providers once, there's nothing preventing apps from querying your provider multiple times.