Android Binder clearing caller identity

不问归期 提交于 2019-12-04 07:48:05

I don't think I can answer better than the description in the official APIs: http://developer.android.com/reference/android/os/Binder.html

public static final long clearCallingIdentity ()

Reset the identity of the incoming IPC on the current thread. This can be useful if, while handling an incoming call, you will be calling on interfaces of other objects that may be local to your process and need to do permission checks on the calls coming into them (so they will check the permission of your own local process, and not whatever process originally called you).

Although the question is old, it's worth putting more details in addition to the official method description.


Apart from (or along with) IPC the key role of the Binder framework in Android is security.

Each Binder transaction runs under the identity (PID and UID) of the calling process (caller) so that the called process (callee) could inspect the calling process' permissions and decide whether the requested method can be executed.

If such a transaction needs to be (temporary) running under the callee's identity, the caller's one can be cleared and later restored with the calls to Binder.clearCallingIdentity() and Binder.restoreCallingIdentity(long) respectively. Between the calls the callee's permissions will be checked.

As an example consider the system services (AOSP location: /frameworks/base/services/java/com/android/server). Running in the system_server process, UID=1000, the services can temporarily clear the caller's identity in order to pass the permission checks.

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