Android 系统应用的运行时权限
Android runtime permission for system apps
关于 Android 运行时权限的问题。 AFAIK,android 在运行时授予危险权限。我重置了我的 phone,然后 adb pull /data/system/users/0/runtime-permissions.xml,我发现 android.ui.system 已经授予了很多危险的权限。谁能告诉我它是怎么做到的?
通过用户确认对话框将 dangerous runtime permissions 插入 /data/system/users/0/runtime-permissions.xml
文件的机制仅适用于第三方应用程序,与内置应用程序无关。
For built-in/system applications and framework components, all
permissions are granted by default when a new user is created or
when the device boots and a systemReady
event is fired.
可以看到AOSP中的AndroidManifest.xml,里面写的都是系统组件需要的各种权限。
对于第三方应用程序,当用户授予任何运行时权限时,它会被添加到文件中 /data/system/users/0/runtime-permissions.xml
。当用户从任何第三方应用程序撤销权限时,权限将从文件中删除。在完全恢复出厂设置的情况下,所有第三方应用程序的运行时权限都将被删除,因为 /data/system/users/0/runtime-permissions.xml
被删除(数据分区擦除)。
但即使在恢复出厂设置后,/data/system/users/0/runtime-permissions.xml
仍包含系统应用程序的运行时权限(甚至是危险的权限),请参阅默认权限:runtime-permissions.xml。
这是因为:
All the default permissions are granted from
PackageManagerService
, via these two methods:
newUserCreated() //this get called when new user is created
systemReady() //this get called when device is booted
and the above methods internally invoke:
DefaultPermissionPolicy.grantDefaultPermissions();
Have a look at How DefaultPermissionPolicy triggers
And if you see DefaultPermissionPolicy's implementation, it
contains all the relevant method to load all type of permissions for
System components.
Specifically DefaultPermissionPolicy.grantDefaultPermissions()
internally calls
grantPermissionsToSysComponentsAndPrivApps(userId);
grantDefaultSystemHandlerPermissions(userId);
and it internally invokes grantRuntimePermissionsLPw()
, which
performs all the remaining work.
关于 Android 运行时权限的问题。 AFAIK,android 在运行时授予危险权限。我重置了我的 phone,然后 adb pull /data/system/users/0/runtime-permissions.xml,我发现 android.ui.system 已经授予了很多危险的权限。谁能告诉我它是怎么做到的?
通过用户确认对话框将 dangerous runtime permissions 插入 /data/system/users/0/runtime-permissions.xml
文件的机制仅适用于第三方应用程序,与内置应用程序无关。
For built-in/system applications and framework components, all permissions are granted by default when a new user is created or when the device boots and a
systemReady
event is fired.
可以看到AOSP中的AndroidManifest.xml,里面写的都是系统组件需要的各种权限。
对于第三方应用程序,当用户授予任何运行时权限时,它会被添加到文件中 /data/system/users/0/runtime-permissions.xml
。当用户从任何第三方应用程序撤销权限时,权限将从文件中删除。在完全恢复出厂设置的情况下,所有第三方应用程序的运行时权限都将被删除,因为 /data/system/users/0/runtime-permissions.xml
被删除(数据分区擦除)。
但即使在恢复出厂设置后,/data/system/users/0/runtime-permissions.xml
仍包含系统应用程序的运行时权限(甚至是危险的权限),请参阅默认权限:runtime-permissions.xml。
这是因为:
All the default permissions are granted from
PackageManagerService
, via these two methods:newUserCreated() //this get called when new user is created systemReady() //this get called when device is booted
and the above methods internally invoke:
DefaultPermissionPolicy.grantDefaultPermissions();
Have a look at How DefaultPermissionPolicy triggers
And if you see DefaultPermissionPolicy's implementation, it contains all the relevant method to load all type of permissions for System components.
Specifically
DefaultPermissionPolicy.grantDefaultPermissions()
internally callsgrantPermissionsToSysComponentsAndPrivApps(userId); grantDefaultSystemHandlerPermissions(userId);
and it internally invokes
grantRuntimePermissionsLPw()
, which performs all the remaining work.