struct AIBinder

Represents a local or remote object which can be used for IPC or which can itself be sent.

This object has a refcount associated with it and will be deleted when its refcount reaches zero.

How methods interactive with this refcount is described below. When using this API, it is

intended for a client of a service to hold a strong reference to that service. This also means

that user data typically should hold a strong reference to a local AIBinder object. A remote

AIBinder object automatically holds a strong reference to the AIBinder object in the server's

process. A typically memory layout looks like this:

Key:

---> Ownership/a strong reference

...> A weak reference

(process boundary)

|

MyInterface ---> AIBinder_Weak | ProxyForMyInterface

^ . | |

| . | |

| v | v

UserData

<

--- AIBinder

<

-|- AIBinder

|

In this way, you'll notice that a proxy for the interface holds a strong reference to the

implementation and that in the server process, the AIBinder object which was sent can be resent

so that the same AIBinder object always represents the same object. This allows, for instance, an

implementation (usually a callback) to transfer all ownership to a remote process and

automatically be deleted when the remote process is done with it or dies. Other memory models are

possible, but this is the standard one.

If the process containing an AIBinder dies, it is possible to be holding a strong reference to

an object which does not exist. In this case, transactions to this binder will return

STATUS_DEAD_OBJECT. See also AIBinder_linkToDeath, AIBinder_unlinkToDeath, and AIBinder_isAlive.

Once an AIBinder is created, anywhere it is passed (remotely or locally), there is a 1-1

correspondence between the address of an AIBinder and the object it represents. This means that

when two AIBinder pointers point to the same address, they represent the same object (whether

that object is local or remote). This correspondance can be broken accidentally if AIBinder_new

is erronesouly called to create the same object multiple times.