commons-app / apps-android-commons

The Wikimedia Commons Android app allows users to upload pictures from their Android phone/tablet to Wikimedia Commons
https://commons-app.github.io/
Apache License 2.0
990 stars 1.18k forks source link

SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.MediaContentProvider that is not exported from uid 10063 #173

Closed misaochan closed 6 years ago

misaochan commented 8 years ago

Posted by Tommy Gildseth on 12 Jul:

USER_COMMENT=Clicked the back button from a failed upload
ANDROID_VERSION=6.0.1
APP_VERSION_NAME=1.17
BRAND=google
PHONE_MODEL=Nexus 5X
CUSTOM_DATA=
STACK_TRACE=java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.MediaContentProvider from ProcessRecord{50fff77 18404:fr.free.nrw.commons/u0a118} (pid=18404, uid=10118) that is not exported from uid 10063
at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3550)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:4783)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2018)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1468)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1088)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:942)
at android.content.ContentResolver.openInputStream(ContentResolver.java:662)
at fr.free.nrw.commons.upload.UploadService.uploadContribution(UploadService.java:176)
at fr.free.nrw.commons.upload.UploadService.handle(UploadService.java:114)
at fr.free.nrw.commons.upload.UploadService.handle(UploadService.java:27)
at fr.free.nrw.commons.HandlerService$ServiceHandler.handleMessage(HandlerService.java:19)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
misaochan commented 8 years ago

Wow, there are an awful lot of bugs involving Google Photos, and my StackOverflow thread isn't yielding any answers. :(

nicolas-raoul commented 8 years ago

Linking it here for the sake of findability: http://stackoverflow.com/q/38301605

misaochan commented 8 years ago

Oof, another Google Photos crash just showed up. :/ I've been reading up as much as I can on it, and the only solution I can find seems to require a major overhaul of how the image data is passed around.

Apparently it is due to a permissions change by the google photos provider:

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.

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

For the time being, should we tell people that our app has issues integrating with Google Photos?

misaochan commented 8 years ago

Similar crashes:

By Franc Furt, 18 Jul:

USER_COMMENT=
ANDROID_VERSION=6.0.1
APP_VERSION_NAME=1.18
BRAND=motorola
PHONE_MODEL=Moto G (4)
CUSTOM_DATA=
STACK_TRACE=java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.MediaContentProvider from ProcessRecord{a1da333 7235:fr.free.nrw.commons/u0a121} (pid=7235, uid=10121) that is not exported from uid 10106

at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3605)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:4799)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2018)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1466)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1087)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:942)
at android.content.ContentResolver.openInputStream(ContentResolver.java:662)
at fr.free.nrw.commons.upload.UploadService.uploadContribution(UploadService.java:176)
at fr.free.nrw.commons.upload.UploadService.handle(UploadService.java:114)
at fr.free.nrw.commons.upload.UploadService.handle(UploadService.java:27)
at fr.free.nrw.commons.HandlerService$ServiceHandler.handleMessage(HandlerService.java:19)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61) 

By Wikipedia Valencia, 18 Jul:

USER_COMMENT=
ANDROID_VERSION=6.0.1
APP_VERSION_NAME=1.18
BRAND=motorola
PHONE_MODEL=Moto G (4)
CUSTOM_DATA=
STACK_TRACE=java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.MediaContentProvider from ProcessRecord{8ef5fdb 14995:fr.free.nrw.commons/u0a121} (pid=14995, uid=10121) that is not exported from uid 10106

at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3605)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:4799)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2018)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1466)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1087)

at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:942)
at android.content.ContentResolver.openInputStream(ContentResolver.java:662)
at fr.free.nrw.commons.upload.UploadService.uploadContribution(UploadService.java:176)
at fr.free.nrw.commons.upload.UploadService.handle(UploadService.java:114)
at fr.free.nrw.commons.upload.UploadService.handle(UploadService.java:27)
at fr.free.nrw.commons.HandlerService$ServiceHandler.handleMessage(HandlerService.java:19)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
misaochan commented 8 years ago

How odd. I finally have access to an Android 6 phone... but I can't replicate the Google Photos crash. Yet so many people are having it. :/

I'll submit a PR for what I think MIGHT solve the bug I guess, and we'll see if people still get the crash.

nicolas-raoul commented 8 years ago

I also can't reproduce with Android 6.0.1 and Google Photos 1.23.1.126715090 I open Photos, select a picture, press Share, choose Commons, it is loaded and upload works.

misaochan commented 8 years ago

Yeah, ditto. :/ I'll try to ask them for more details I guess...

misaochan commented 8 years ago

By Wikipedia Valencia on 20 Jul:

USER_COMMENT= New version. Selected several files in Google photos and clicked on "share".
ANDROID_VERSION=6.0.1
APP_VERSION_NAME=1.20
BRAND=motorola
PHONE_MODEL=Moto G (4)
CUSTOM_DATA=
STACK_TRACE=java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.MediaContentProvider from ProcessRecord{89dd118 8999:fr.free.nrw.commons/u0a125} (pid=8999, uid=10125) that is not exported from uid 10106

at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3605)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:4799)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2018)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1466)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1087)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:942)
at android.content.ContentResolver.openInputStream(ContentResolver.java:662)
at fr.free.nrw.commons.upload.UploadService.uploadContribution(UploadService.java:178)
at fr.free.nrw.commons.upload.UploadService.handle(UploadService.java:115)
at fr.free.nrw.commons.upload.UploadService.handle(UploadService.java:27)
at fr.free.nrw.commons.HandlerService$ServiceHandler.handleMessage(HandlerService.java:20)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
misaochan commented 8 years ago

Did the exact same thing (selected several files instead of just one) and still no crash on my device... :(

nicolas-raoul commented 8 years ago

Do you think that trying to implement http://stackoverflow.com/a/30567302/226958 would be worth a try? Or is it a different problem?

misaochan commented 8 years ago

Oh, I think I might have succeeded in reproducing the crash after manually revoking permissions and repeating what Wikipedia Valencia did. I think the issue is with MultipleShareActivity.java, which is the activity launched by the <action android:name="android.intent.action.SEND_MULTIPLE" /> intent filter. We have been focusing on ShareActivity.java for runtime permissions because that is the one called by the app code. Will try to add those to MultipleShareActivity and see how it goes.

If it still doesn't work then I might try what the SO thread you linked says.

USER_COMMENT=Testing multiple upload with revoked permissions
ANDROID_VERSION=6.0.1
APP_VERSION_NAME=1.20
BRAND=samsung
PHONE_MODEL=SM-G930F
CUSTOM_DATA=
STACK_TRACE=java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.MediaContentProvider from ProcessRecord{35f5876 16385:fr.free.nrw.commons/u0a215} (pid=16385, uid=10215) that is not exported from uid 10128

at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:4240)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:6392)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2321)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1521)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1139)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:991)
at android.content.ContentResolver.openInputStream(ContentResolver.java:711)

at fr.free.nrw.commons.upload.UploadService.uploadContribution(UploadService.java:178)
at fr.free.nrw.commons.upload.UploadService.handle(UploadService.java:115)
at fr.free.nrw.commons.upload.UploadService.handle(UploadService.java:27)
at fr.free.nrw.commons.HandlerService$ServiceHandler.handleMessage(HandlerService.java:20)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.os.HandlerThread.run(HandlerThread.java:61)
misaochan commented 8 years ago

Gosh. Now it works for API 23 but not for those below... -_- The difference is that API 21 actually tries to upload first though. The progress bar goes all the way to 100% before it crashes.

Also... the first image uploaded via MultipleShareActivity in API 21 succeeds. It's only the 2nd image onwards that fails.(whereas in API 23 all images fail). Single images uploaded via ShareActivity do not cause a crash.

USER_COMMENT=testing multiple share from Google photos on api21. crashes after category selection etc while photo is uploading
ANDROID_VERSION=5.0.1
APP_VERSION_NAME=1.21
BRAND=samsung
PHONE_MODEL=GT-I9505
CUSTOM_DATA=
STACK_TRACE=java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.MediaContentProvider from ProcessRecord{11b87a1f 18901:fr.free.nrw.commons/u0a300} (pid=18901, uid=10300) that is not exported from uid 10005
at android.os.Parcel.readException(Parcel.java:1540)
at android.os.Parcel.readException(Parcel.java:1493)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3639)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:5193)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2938)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1452)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1072)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:927)
at android.content.ContentResolver.openInputStream(ContentResolver.java:652)

at fr.free.nrw.commons.upload.UploadService.uploadContribution(UploadService.java:178)
at fr.free.nrw.commons.upload.UploadService.handle(UploadService.java:115)
at fr.free.nrw.commons.upload.UploadService.handle(UploadService.java:27)
at fr.free.nrw.commons.HandlerService$ServiceHandler.handleMessage(HandlerService.java:20)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.os.HandlerThread.run(HandlerThread.java:61)
misaochan commented 8 years ago

Well, even after reverting to old APK, API 21 still crashes, so that means the issue has always been there and wasn't caused by my change. So I'll push the fix through anyway to hopefully solve the issue for the API 23 folks first, while looking into API 21.

misaochan commented 8 years ago

From La Represa:

Selected several files from G. photos. I was able to upload 2 in a row. With 11 it crashes

misaochan commented 7 years ago

Some people are still having issues. New response about this:

Usually crash only if i don't wait every single upload and there are some photos awaiting "in coda"

neslihanturan commented 6 years ago

I guess this is no longer a problem.

lionuncle commented 3 years ago

java.lang.SecurityException: Permission Denial: opening provider

Can somebody provide solution?

nicolas-raoul commented 3 years ago

@lionuncle Is it happening in the Wikimedia Commons app?

Talloju commented 2 years ago

I am getting "java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.impl.MediaContentProvider from ProcessRecord{114f054 4881:jp.trilltrill.trill.dev/u0a468} (pid=4881, uid=10468) that is not exported from UID 10116" in aversion devices till Android 12. Can someone help.

nicolas-raoul commented 2 years ago

@Talloju: It happens while you are testing the app you are developing, right? Here is the GitHub of the Wikimedia Commons app. Unless you are working on the Wikimedia Commons app, please post to https://stackoverflow.com. Thank you!

SweetD3v commented 2 years ago

Try this..It worked for me! Giving permission to all available packages.

Intent intent = new Intent(Intent.ACTION_VIEW, mediaUri);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        for (ResolveInfo resolveInfo : resInfoList) {
            String packageName = resolveInfo.activityInfo.packageName;
            grantUriPermission(packageName, mediaUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
        startActivity(intent);
nicolas-raoul commented 2 years ago

Anyone experiencing this issue on our latest Commons app, please open a new issue, thank you! :-)