Android Content Providers - Is it possible to restrict the provider to a set of applications not written by me?

帅比萌擦擦* 提交于 2019-12-06 04:29:55

I do not know precisely but I think that you can use Binder.getCallingUid() function in your ContentProvider. Using this method you can check the Uids of the calling applications and restrict the usage of your CP basing on application UID.

Update: During the installation Android OS assigns UID to the installing application. So UIDs can be different on different devices. But the package name of the application is the same across all devices. But if I know which package can read your data I can simply spoof it.

One solution off the top of my head might be to wrap your content provider in a Service. This way queries come through as intents or through a binder. You can restrict the intents by checking the package name, which I think is harder fake if the app came through the app market.

I think you're asking the impossible though. Any attempt at this kind of security can be circumvented on rooted phones.

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