Custom chooser activity: SecurityException UID n does not have permission to content:// uri

拥有回忆 提交于 2019-12-04 11:07:04

Is this a Chrome bug? An Android bug? Or am I doing something wrong?

My guess is that it is a client-side bug, coming from people creating ACTION_CHOOSER Intent objects directly rather than through Intent.createChooser(). Intent.createChooser() looks like it is taking the flags from what you called mPayloadIntent and adds them to mIntent.

You should be able to test this yourself. Create a scrap app that creates an ACTION_SEND Intent with EXTRA_STREAM pointing to some piece of content (e.g., served by FileProvider). Then, try invoking your chooser three ways:

  1. Wrap the Intent via Intent.createChooser()

  2. Wrap the Intent via an ACTION_CHOOSER Intent, where you follow what the docs say and put the flags on both Intent objects

  3. Wrap the Intent via an ACTION_CHOOSER Intent, where you skip the flags on the ACTION_CHOOSER Intent

If I am correct, #1 and #2 will work, and #3 will fail with the same basic failure mode that you're seeing.

If my theory holds up so far, try running the three apps again, but this time use the system chooser. My guess is that the system chooser does get some special benefits from being part of the core OS and all three will work. Otherwise, the developers of Chrome and WhatsApp would have run into this problem in their testing and would have fixed it.

And, if all of this theory holds up... you're somewhat screwed. I would assume that more people use Intent.createChooser() than use ACTION_CHOOSER directly, as Intent.createChooser() is simpler. And, some subset of the people who use ACTION_CHOOSER might actually follow the documentation...

hahahahahahahahaha... gasp ...hahahahahahahahahaha!

...and for those, you're OK. And, some people using ACTION_CHOOSER might have a Uri in EXTRA_STREAM that is world-readable (which isn't a good idea, but it works in your favor here). It will only be for buggy clients that create ACTION_CHOOSER manually, fail to set the Intent flags properly, but do secure their content properly, that you won't be able to correctly process the Intent.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!