【发布时间】:2016-10-18 02:37:57
【问题描述】:
是否可以向内容提供者添加过滤器以使其仅接受来自一组已知应用程序 ID 的请求? 例如,如果 com.domain1.app1 和 com.domain2.app2 是我信任的两个应用程序,我想让它们读取我的数据。任何其他应用程序都应保留在外面。 类似于意图过滤器,但与来自其他应用程序的传入请求相关。
我知道相同的签名密钥,但这不是我需要的。
【问题讨论】:
-
Android 中并没有为此添加任何内容。您可以从相关的
ContentProvider方法(例如query())中尝试Binder.getCallingUid(),看看它是否为您提供了调用者的UID。如果是这样,您可以将其与PackageManager一起使用来确定与该 UID 关联的应用程序 ID。但是,我忘记了Binder.getCallingUid()是否在ContentProvider中工作,这就是为什么我不确定这是否可行。 -
Android Content Providers - Is it possible to restrict the provider to a set of applications not written by me? 的可能重复项。无论如何,根据ContentProvider and getCallingUid() 使用
Binder.getCallingUid()应该可以工作。
标签: android android-contentprovider restrictions