wordpress-mobile / WordPress-Android

WordPress for Android
http://android.wordpress.org
GNU General Public License v2.0
2.98k stars 1.33k forks source link

Crash report 7.2.1: SecurityException: Permission Denial: com.google.android.apps.photos.contentprovider.MediaContentProvider #5818

Closed mzorz closed 7 years ago

mzorz commented 7 years ago

http://crashes.to/s/b4e0c187f19

Fatal Exception: java.lang.RuntimeException: An error occured while executing doInBackground()
       at android.os.AsyncTask$3.done(AsyncTask.java:300)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)
Caused by java.lang.SecurityException: Permission Denial: reading com.google.android.apps.photos.contentprovider.MediaContentProvider uri content://com.google.android.apps.photos.contentprovider/0/1/mediakey%3A%2Flocal%253A7c1d3c4c-bfed-445c-a330-05ccafc1ca8f/ORIGINAL/NONE/1120761078 from pid=18359, uid=10262 requires the provider be exported, or grantUriPermission()
       at android.os.Parcel.readException(Parcel.java:1547)
       at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
       at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:148)
       at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:689)
       at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1080)
       at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:921)
       at android.content.ContentResolver.openInputStream(ContentResolver.java:646)
       at com.yalantis.ucrop.task.BitmapLoadTask.copyFile(BitmapLoadTask.java:198)
       at com.yalantis.ucrop.task.BitmapLoadTask.processInputUri(BitmapLoadTask.java:176)
       at com.yalantis.ucrop.task.BitmapLoadTask.doInBackground(BitmapLoadTask.java:90)
       at com.yalantis.ucrop.task.BitmapLoadTask.doInBackground(BitmapLoadTask.java:41)
       at android.os.AsyncTask$2.call(AsyncTask.java:288)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)
daniloercoli commented 7 years ago

Related/Duplicate of https://github.com/wordpress-mobile/WordPress-Android/issues/5672 ?

daniloercoli commented 7 years ago

It seems that we can't download an external file by using AsyncTask. For security reasons, the permissions are temporary, so once the client app's task stack is finished, the file is no longer accessible. You must get the file data when you receive the intent answer, in the onActivityResult method. Store a copy of the file data, because the file won't be available anymore when onActivityResult returns.

See Access the Requested File section here https://developer.android.com/training/secure-file-sharing/request-file.html#OpenFile

Also http://stackoverflow.com/questions/30572261/using-data-from-context-providers-or-requesting-google-photos-read-permission

mzorz commented 7 years ago

Closing via #5827

maxme commented 7 years ago

This is still happening in 7.4

Fatal Exception: java.lang.RuntimeException: An error occured while executing doInBackground()
       at android.os.AsyncTask$3.done(AsyncTask.java:304)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)
Caused by java.lang.SecurityException: Permission Denial: reading com.android.externalstorage.ExternalStorageProvider uri content://com.android.externalstorage.documents/document/3238-3038%3APictures%2FInstagram%2FIMG_20170526_090612_561.jpg from pid=13149, uid=10228 requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()
       at android.os.Parcel.readException(Parcel.java:1553)
       at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
       at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:148)
       at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:691)
       at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1085)
       at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:925)
       at android.content.ContentResolver.openInputStream(ContentResolver.java:650)
       at com.yalantis.ucrop.task.BitmapLoadTask.copyFile(BitmapLoadTask.java:198)
       at com.yalantis.ucrop.task.BitmapLoadTask.processInputUri(BitmapLoadTask.java:176)
       at com.yalantis.ucrop.task.BitmapLoadTask.doInBackground(BitmapLoadTask.java:90)
       at com.yalantis.ucrop.task.BitmapLoadTask.doInBackground(BitmapLoadTask.java:41)
       at android.os.AsyncTask$2.call(AsyncTask.java:292)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)
daniloercoli commented 7 years ago

Fixed for the Me fragment in #5963.