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.