The underlying interface of a remote object is a core part of a lightweight remote invocation mechanism designed to perform high performance in both process and inter-process calls. This interface describes the abstract protocol that interacts with remote objects. Do not implement this interface directly, but by inheriting binder.
The key API for IBinder is the Transact () that matches binder.ontransact (). This method allows you to make a request to the IBinder object and receive a request to enter a Binder object. This transaction API is synchronous so that a call to Transact () will return after the target returns from Binder.ontransact (), which is the expected behavior in invoking a local process object. and the potential IPC (interprocess communication mechanism) also ensures that these same semantics are applied when switching between processes.
The data sent through Transact () is a Parcel, a usual data buffer, and contains some metadata about his content. These metadata are used to manage references to IBinder objects during the buffer period, so that those references can be included when the buffer crosses the process. This mechanism ensures that when a ibinder is written to a parcel to be transmitted to other processes, the original process receives the same IBinder object if the other process returns the same IBinder reference as the original process. These semantics allow the Ibinder/binder object to be used as the only identity that is managed when switching between processes (serving as a flag or other purpose).
The system maintains a pool of transaction threads in the process in which each transaction thread runs. These threads are used to distribute all IPCS from other processes. For example, when an IPC is established from a process to a B process, the calling thread in a is issuing a transaction to process B with Transact (). In B, the next valid thread pool receives incoming transactions, calls Binder.ontransact () on the target object, and replies with the result parcel. When the result is received, the thread in process a returns to allow the process to continue execution. On the effect, other processes appear to be used as additional threads that you do not create in your own process.
The binder system also supports recursive calls between processes. For example, if process a executes a transaction to process B, and Process B calls transact () on a ibinder implemented in a in a while processing this transaction, then a thread in a that is waiting for the previous transaction to end, will be concerned about calling Binder.ontransact () to the object being called by B. This ensures that the recursive semantics when invoking remote binder objects are the same as when invoking local objects.
When dealing with remote objects, you often want to find out when they are no longer valid. Here are three ways to be sure:
- A RemoteException exception is thrown when you try to call the Transact () method on a ibinder that the owning process already does not exist.
- Pingbinder () can be called and will return FALSE if the remote process no longer exists.
- The Linktodeath () method can be used to register a ibinder.deathrecipient with this ibinder, which is called when the containing process disappears.
Ibinder.deathrecipient |
The interface that receives a callback after the service of a ibinder process disappears. |
Binder, ipackageinstallobserver.stub, Sensormanager see
Summary constants
|
|
| Value
|
|
Int |
Dump_transaction |
IBinder Transaction Protocol code: Clear Internal state |
1598311760 |
0x5f444d50 |
Int |
First_call_transaction |
The first transaction code for a user instruction is available. |
1 |
0x00000001 |
Int |
Flag_oneway |
Transact (Int,parcel, Parcel, int) marker: This is a one-way call, which means that the caller returns immediately without waiting for the result from the callee. |
1 |
0x00000001 |
Int |
Interface_transaction |
IBinder Transaction Protocol code: Ask the transaction receiver for his canonical interface descriptor. |
1598968902 |
0x5f4e5446 |
Int |
Last_call_transaction |
The last transaction code for the user instruction is available. |
16777215 |
0x00ffffff |
Int |
Ping_transaction |
IBinder Transaction Protocol Code: Pingbinder (). |
1599098439 |
0x5f504e47 |
Public methods
|
|
|
|
|
String |
Getinterfacedescriptor () |
|
Gets the canonical name of the interface supported by this binder. |
|
|
|
|
|
Boolean |
Isbinderalive () |
|
Check that the process where the binder resides is still present. |
|
|
|
|
|
void |
Linktodeath (ibinder.deathrecipientrecipient, int flags) |
|
If this binder disappears, register a receiver for the flag information. |
|
|
|
|
|
Boolean |
Pingbinder () |
|
Check to see if this object still exists. |
|
|
|
|
|
IInterface |
Querylocalinterface (Stringdescriptor) |
|
An attempt was made to obtain a local implementation of an interface to this binder object. |
|
|
|
|
|
Boolean |
Transact (Intcode,parceldata, parcelreply, int flags) |
|
Perform a generic operation with the object. |
|
|
|
|
|
Boolean |
Unlinktodeath (ibinder.deathrecipientrecipient, int flags) |
|
Clears a previously registered death identification information. |
Content constant public static final Intdump_transactionibinder Transaction protocol code: Clear internal state constant value: 1598311760 (0X5F444D50) public static final Intfirst _call_transaction the first transaction code of the user instruction available constant value: 1 (0x00000001) public static final Intflag_onewaytransact (Int,parcel, Parcel, int) Marker: This is a one-way call, which means that the caller returns immediately without waiting for the result from the callee. Constant value: 1 (0x00000001) public static final Intinterface_transactionibinder Transaction protocol code: Ask the transaction receiver for his canonical interface descriptor. Constant value: 1598968902 (0x5f4e5446) public static final Intlast_call_transaction the last transaction code of the user instruction is available. Constant value: 16777215 (0X00FFFFFF) public static final Intping_transactionibinder Transaction protocol code: Pingbinder (). Constant value: 1599098439 (0x5f504e47) Public method Common Stringgetinterfacedescriptor () obtains the canonical name of the interface supported by this binder. Abnormal
Public booleanisbinderalive () checks if the process in which the binder resides is still present. return value
- False values are returned if the process cannot be on. NoteIf a true value is returned, the process may have died when the call returned.
public void Linktodeath (ibinder.deathrecipientrecipient, int flags) If this binder disappears, register a sink for the flag information. If this binder object disappears (typically because his service process has been terminated) then the Deathrecipient.binderdied () method of this given ibinder.deathrecipient will be called.
You will only receive a death identification message from the remote binders, as the local binders in the definition will not die before the call to death.
Abnormal
|
RemoteException if the target IBinder process is dead. |
RemoteException |
|
Please see
- Unlinktodeath (Ibinder.deathrecipient,int)
public boolean Pingbinder () checks whether this object still exists. return value
- Returns a false value if the service process has disappeared, otherwise the result is returned by Pingbinder () on the other side (usually the default is true).
Public Iinterfacequerylocalinterface (Stringdescriptor) attempts to obtain a local implementation of an interface to this binder object. If NULL is returned, you will need to instantiate a proxy class to call the group through the Transact () method. The public boolean transact (Intcode, Parceldata, parcelreply, int flags) performs a generic operation with the object. Parameters
Code |
The behavior performed. This will be a number between first_call_transaction and last_call_transaction. |
Data |
The grouped data sent to the target, usually not null. If you do not transmit any data, you have to create an empty parcel to put here. |
Reply |
The grouped data from the target being received. If you are not interested in the return value, you may return null. |
Flags |
Additional operators. 0 is the usual meaning of RPC, or Flag_oneway represents a one-way RPC. |
Abnormal
public boolean Unlinktodeath (ibinder.deathrecipientrecipient, int flags)
Clears a previously registered death identification information. If this object is dead, the receiver will no longer be called.
return value
- If the receiver is successfully disconnected then return true, you must ensure that his deathrecipient.binderdied () method is not called. If the target ibinder is dead, then a false value is returned, meaning that the method has been (or will) been called.
Abnormal
|
Nosuchelementexception if the given receiver has not yet registered with IBinder, and the IBinder is alive. Note that if the receiver has never been registered, but IBinder is dead, the exception will not be thrown and you will receive a false value as the return value. |
Chinese translation of IBinder class