PackageManager 和 AndroidManifest.xml 报告不同的使用权限

发布于 2024-12-18 14:20:57 字数 1169 浏览 1 评论 0原文

一直在做一些 Android 权限研究,并遇到了一个应用程序 - 根据 AndroidManifest.xml 文件 - 仅将 WRITE_EXTERNAL_STORAGE 声明为权限。 Android Market 也只报告了这一点。使用 aapt 工具转储使用权限,它也只报告一个权限。

但是,在 Android 设备(或模拟器)上运行的代码中,执行以下操作:

PackageManager pm = getPackageManager();
List<PackageInfo> pkgList = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS | PackageManager.GET_SIGNATURES);

...

PackageInfo p = pkgList.get(i);  // where i is the index of the apk in question
String[] perms = p.requestedPermissions;

我获得此 APK 的 2 个权限,READ_PHONE_STATE 和清单中的一个权限,WRITE_EXTERNAL_STORAGE。查看“管理应用程序”屏幕并选择详细信息也会显示额外的 READ_PHONE_STATE 权限。

是否存在权限可以“隐含”的情况(在代码中,通过 功能使用等)在 Android 清单中不需要?或者换句话说,为什么 aapt 返回一组权限,而 getPackageManager().getPackageInfo() API 返回一组不同的权限?

编辑:

使用“更好”术语搜索发现了我正在寻找的答案: Android权限:电话通话:读取手机状态和身份

总之,使用早期版本的SDK编译的APK确实免费继承了一些权限...

Been doing some Android permission research and ran across an application that - according to the AndroidManifest.xml file - only declares WRITE_EXTERNAL_STORAGE as a permission. The Android Market only reports this as well. Using the aapt tool to dump the uses-permission it also only reports the one permission.

However, in code running on the Android device (or emulator), doing the following:

PackageManager pm = getPackageManager();
List<PackageInfo> pkgList = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS | PackageManager.GET_SIGNATURES);

...

PackageInfo p = pkgList.get(i);  // where i is the index of the apk in question
String[] perms = p.requestedPermissions;

I get 2 permissions for this APK, READ_PHONE_STATE and the one in the manifest, WRITE_EXTERNAL_STORAGE. Looking at the "Manage Apps" screen and selecting details for this also shows the additional READ_PHONE_STATE permission.

Are there cases where permissions can be/are 'implied' (in code, by feature use, etc) that would not be required in the Android Manifest? Or put another way, why does aapt return one set of permissions and the getPackageManager().getPackageInfo() API return a different set?

EDIT:

Searching with "more better" terms discovered the answer I was looking for: Android permissions: Phone Calls: read phone state and identity

In short, APKs compiled with earlier version of the SDK did inherit some permissions for free...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软糯酥胸 2024-12-25 14:20:57

据我所知,权限必须始终在清单中明确设置。

如果应用程序需要访问受权限保护的功能,则必须使用清单中的元素声明它需要该权限。然后,当应用程序安装在设备上时,安装程​​序通过检查签署应用程序证书的机构并在某些情况下询问用户来确定是否授予所请求的权限。如果授予权限,应用程序就可以使用受保护的功能。如果没有,它访问这些功能的尝试将会失败,并且不会向用户发出任何通知。

来源

我认为您所看到的差异是由于权限的 protectionLevel 属性。任何设置为“正常”的权限都不需要用户确定,因此它们只会显示在“详细信息”部分中。

As far as I know permissions must always be explicitly set in the manifest.

If an application needs access to a feature protected by a permission, it must declare that it requires that permission with a element in the manifest. Then, when the application is installed on the device, the installer determines whether or not to grant the requested permission by checking the authorities that signed the application's certificates and, in some cases, asking the user. If the permission is granted, the application is able to use the protected features. If not, its attempts to access those features will simply fail without any notification to the user.

source

The difference you are seeing I believe is due to the protectionLevel attribute on permissions. Any permissions that are set to "normal" are not required to be OK'd by the user so they just show up in the Details section.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文