Android runtime permission for system apps

你离开我真会死。 提交于 2019-11-29 00:03:35
shridutt kothari

The mechanism to insert Runtime permission into the /data/system/users/0/runtime-permissions.xml file by user confirmation dialog for Dangerous permission level, is for third party applications, and This is not relevant for built-in applications.

For built-in/system applications and framework components, all permissions are granted by default when a new user is created or device boots and systemReady event is fired.

You can see the AndroidManifest.xml from AOSP, where all types of required permissions are written for system components.

For third party apps, when User grants any runtime permission, it gets added into the file /data/system/users/0/runtime-permissions.xml, and gets removed when you revoke permission of any third party app, whereas after full factory reset, runtime permission of all the third party apps is removed, as /data/system/users/0/runtime-permissions.xml gets deleted (data partition wipe).

But even after factory reset, /data/system/users/0/runtime-permissions.xml contains runtime permissions(Even dangerous level) for system apps, see the default permissions: runtime-permissions.xml.

And it happens because:

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 above methods internally invokes:

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 they gives calls to grantRuntimePermissionsLPw() method, which performs all the remaining work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!