android - 申请的进程中没有加入对应的组ID

标签 android linux android-permissions

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 没有改变。我认为它应该更新,所以我有什么错误吗?

最佳答案

总结

android.permission.WRITE_EXTERNAL_STORAGE 现在(> API 23)实现为 内置 android 权限,现在由运行时管理。早些时候(< API 23)权限是低级内核强制执行的权限组的一部分,实现为Linux Supplementary Group。 ,即在安装时将组分配给应用。

Marshmallow 之前的行为(< API 23)

在 Marshmallow 之前(特别是在引入 Runtime Permission 之前),android.permission.WRITE_EXTERNAL_STORAGE 是在内核级别 实现的。每当任何进程尝试访问外部存储时,调用都会通过内核(open() 系统调用),内核会在其中检查调用进程的权限(通常是 Linux 东西......)。对于极客来说,调用堆栈是这样的:

  1. 阅读File你使用 FileOutputStream 打开一个流到它.当我们构造一个 FileOutputStream , 这叫 IOBridge.open(String, int) . IOBridge是一个内部类,并将打开委托(delegate)给 native JNI 调用。

  2. IOBridge.open()里面调用,该方法委托(delegate)给 Libcore.os.open() .再次Libcore是一个内部类。

  3. Libcore.os.open()是一个本地方法,实现了here .和 here , 该方法调用 open()系统调用和内核启动!

开始 Marshmallow 的行为(>= API 23)

从 Marshmallow 开始(引入了 Runtime Permission ),开发人员需要向用户请求 android.permission.WRITE_EXTERNAL_STORAGE。这会更改将权限分配给应用程序的方式。 Android 仍会在安装 时分配正常 权限,但对于危险 应用,Android 要求该应用显示一个弹出窗口来请求权限。当用户授予权限时,PackageManager 将其记录下来并将其添加到应用程序的数据库记录中(在 /data/system/packages.xml 中)。如果权限是低级权限,即由内核使用实现,则PackageManager添加应用程序的用户ID也到相应的组。 早些时候,android.permission.WRITE_EXTERNAL_STORAGE 是作为低级权限实现的(因此由内核管理),但现在该应用程序是作为内置 权限由运行时管理。 调用堆栈现在看起来像:

  1. 阅读File你使用 FileOutputStream 打开一个流到它.当我们构造一个 FileOutputStream ,它调用私有(private) FileOutputStream.open() native 功能已实现 here .

  2. native FileOutputStream.open()调用助手 fileOpen()哪些代表调用JVM_Open()由运行时实现,因此运行时现在管理权限。

因为app没有加入组,所以在dumpsys中没有显示。

有关 Android 权限和安全性的更多详细信息,我建议您阅读 Android Security Internals by Nikolay Elenkov

关于android - 申请的进程中没有加入对应的组ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49166049/

相关文章:

android - 来自 texturepacker xml 的动画 Sprite

python - 读取文件,在 windows 或 linux 上的结果不同

c++ - 应用程序中两个不同版本的库

Android - WRITE_EXTERNAL_STORAGE 权限和写入应用程序日志

android - 应用程序不适用于 Google Play 上的 Nexus 7

android - ArrayList<Object> 使用 getSerialized 问题到第二个 Activity

android - 在 Android 中无需 ART/Dalvik 参与即可运行代码

android - startActivityForResult() 不适用于外部 Activity

Linux CLI - 光栅到矢量(追踪)

android - 执行需要粗略位置许可的网络扫描