From my understanding (which may be wrong, since I have not worked much with IPC):
Given that your code is executed from another application (for example, your library was not compiled into the application, but is accessible to a third party using Binder or something like that), you can use checkCallingPermission to check if the third-party application has this permission , and checkCallingOrSelfPermission includes permissions from the application into which your library was compiled.
You need to handle the caller’s permissions separately, since you can also allow other applications to leak when checking your own permissions. From safety tips :
Do not skip protected data. This happens when your application provides IPC data, which is available only because it has specific permissions, but does not require the permission of any clients on its IPC interface.
[...]
If you provide an interface that requires access control, use checkCallingPermission() to check if the caller has permission. This is especially important before accessing the service on behalf of the caller, as the identity of your application is transferred to other interfaces.
The package manager method that you describe only checks the permissions of the application into which your library was compiled.
So, if your code is not executing from another process, you probably don't need to care about this difference. Also, use the package manager method or clear the calling identification file if you are interested in whether you can complete the task; additionally check the caller’s permissions if you want to check whether the calling process can complete the task.
source share