Adb命令adb shell dumpsys package com.hackerli.girl
可以帮助我获取应用信息。
在我申请android.permission.WRITE_EXTERNAL_STORAGE
权限之前,我的应用有一个gids=[3003]
。
requested permissions:
android.permission.INTERNET
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.READ_EXTERNAL_STORAGE
android.permission.ACCESS_NETWORK_STATE
install permissions:
android.permission.INTERNET: granted=true
android.permission.ACCESS_NETWORK_STATE: granted=true
User 0: ceDataInode=1531967 installed=true hidden=false suspended=false stopped=true notLaunched=false enabled=0
gids=[3003]
runtime permissions:
User 999: ceDataInode=0 installed=false hidden=false suspended=false stopped=true notLaunched=true enabled=0
gids=[3003]
runtime permissions:
在授予运行时权限android.permission.WRITE_EXTERNAL_STORAGE
后,我会收到以下信息。
requested permissions:
android.permission.INTERNET
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.READ_EXTERNAL_STORAGE
android.permission.ACCESS_NETWORK_STATE
install permissions:
android.permission.INTERNET: granted=true
android.permission.ACCESS_NETWORK_STATE: granted=true
User 0: ceDataInode=1531967 installed=true hidden=false suspended=false stopped=false notLaunched=false enabled=0
gids=[3003]
runtime permissions:
android.permission.READ_EXTERNAL_STORAGE: granted=true
android.permission.WRITE_EXTERNAL_STORAGE: granted=true
User 999: ceDataInode=0 installed=false hidden=false suspended=false stopped=true notLaunched=true enabled=0
gids=[3003]
runtime permissions:
如您所见,READ_EXTERNAL_STORAGE
权限也被授予,因为它与WRITE_EXTERNAL_STORAGE
属于同一个群组。 但gids
未更改。我认为它应该更新,所以我有什么错误吗?
答案 0 :(得分:1)
android.permission.WRITE_EXTERNAL_STORAGE
现在(> API 23)实现为内置 android权限,现在由运行时管理。早期(< API 23),权限是低级内核强制执行的Linux Supplementary Group权限组的一部分,即通过在安装时将组分配给应用程序。
在Marshmallow之前(特别是在引入Runtime Permission之前),android.permission.WRITE_EXTERNAL_STORAGE
是在内核级别实现的。每当任何进程尝试访问外部存储时,调用都会通过内核(open()
系统调用),内核检查调用进程的权限(通常的Linux内容......)。对于 geeks ,这就是调用堆栈的样子:
要阅读File
,请使用FileOutputStream
打开一个流。当我们构建FileOutputStream
时,会调用IOBridge.open(String, int)
。 IOBridge
是一个内部类,并将开头委托给 native JNI-call。
在IOBridge.open()
调用中,该方法委托给Libcore.os.open()
。同样Libcore
是一个内部类。
Libcore.os.open()
是一种原生方法,已实施here。 here,该方法调用open()
系统调用和内核启动!
从Marshmallow开始(引入Runtime Permission)开发人员需要向用户请求android.permission.WRITE_EXTERNAL_STORAGE
。这会更改为应用分配权限的方式。 Android仍会在安装时分配普通权限,但对于危险应用,Android需要该应用显示一个要求获得权限的弹出窗口。当用户授予权限时,PackageManager
会将其记录下来并将其添加到应用程序的数据库记录中(/data/system/packages.xml
中)。如果权限是低级权限,即由内核使用组实现,则PackageManager
会添加应用程序&#39 ; s用户ID也是相应的组。
早期android.permission.WRITE_EXTERNAL_STORAGE
是作为低级权限实现的(因此由内核管理)但现在应用程序实现为运行时管理的内置权限。
调用堆栈现在看起来像:
要阅读File
,请使用FileOutputStream
打开一个流。当我们构建FileOutputStream
时,会调用私有的FileOutputStream.open()
本机函数here。
本机FileOutputStream.open()
调用帮助程序fileOpen()
,该程序委托调用运行时实现的JVM_Open()
,因此运行时现在可以管理权限。
由于该应用未添加到群组中,因此不会显示在dumpsys
。
有关Android上权限和安全性的详细信息,建议您阅读Android Security Internals by Nikolay Elenkov