Translated by Android. OS. ibinder (to be continued)

Source: Internet
Author: User

Structure
Inheritance relationship
Public interface ibinder

Android. OS. ibinder

Subclass and indirect subclass
Indirect subclass

Binder
As a base class of remote objects, ibinder defines the core part of a lightweight Remote Process calling mechanism.

 

Class Overview
Base interface for a remotable object, the core part of a lightweight Remote Procedure Call mechanic designed for high performance when Discovery Ming in-process and cross-process CILS. this interface describes the abstract protocol for interacting with a remotable object. do not implement this interface directly, instead extend from binder.
The basic interface of a remote object is the core part of a lightweight Remote Call mechanism designed for high performance when calling within or between processes. This interface describes the abstraction protocol for interaction with remote objects. This interface is not directly implemented, but is derived from the binder class.
The key ibinder API is transact () matched by binder. ontransact (). these methods allow you to send a call to an ibinder object and receive a call coming in to a binder object, respectively. this transaction API is synchronous, such that a call to transact () does not return until the target has returned from binder. ontransact (); this is the expected behavior when calling an object that exists in the local process, and the underlying inter-process communication (IPC) machism ensures that these same semantics apply when going processing SS processes.
An important API of ibinder is transact (), which is similar to binder. ontransact. These two methods allow you to send one call to the ibinder object in sequence and receive one call to the binder object. This transaction API is synchronized until the target is in the binder. ontransact () is returned, and the called transact () is returned. It is foreseeable to call the action of an existing object in a local process and based on inter-process communication (IPC) the underlying mechanism ensures the same across processes.
The data sent through transact () is a parcel, a Generic Buffer of data that also maintains some meta-data about its contents. the meta data is used to manage ibinder object references in the buffer, so that those references can be maintained as the buffer moves into SS processes. this mechanism ensures that when an ibinder is written into a parcel and sent to another process, if that other process sends a reference to that same ibinder back to the original process, then the original process will receive the same ibinder object back. these semantics allow ibinder/binder objects to be used as a unique identity (to serve as a token or for other purposes) that can be managed into SS processes.
The data sent through transact () Is parcel, a common buffer with metadata describing its content. Metadata is often used to manage the ibinder object references in the buffer, so that those references can be passed to another process by the buffer. This mechanism ensures that ibinder is written to parcel and can be sent to another process. If another process sends the reference of the same ibinder back to the original process, then the original process will receive the same ibinder object. This mechanism enables the ibinder/binder object to be managed across processes as a unique identifier (as a sign or for other purposes.
The system maintains a pool of transaction threads in each process that it runs in. these threads are used to dispatch all IPCS coming in from other processes. for example, when an IPC is made from process a to process B, the calling thread in a blocks in transact () as it sends the transaction to process B. the next available pool thread in B has es the incoming transaction, callbinder. ontransact () on the target object, and replies with the result parcel. upon processing its result, the thread in process a returns to allow its execution to continue. in effect, other processes appear to use as additional threads that you did not create executing in your own process.
The system retains the Transaction Thread Pool in which each process runs. These threads are often used to dispatch IPCS that process all other processes (inter-process calls ). For example, when an IPC is used to send data from process a to process B, the thread that process a sends and calls is blocked in transact () because it sends a transaction to process B. Next, the valid pool thread of process B receives the incoming transaction, calls the binder. ontransact () of the target object, and replies with the result parcel. As soon as the thread of process a receives the result, it returns to make it continue to run. In fact, another process seems to be an additional thread of the current process, but it is not created and executed in your process.
The binder system also supports recursion extends SS processes. for example if process a performs a transaction to process B, and process B while handling that transaction calltransact () on an ibinder that is implemented in, then the thread in a that is currently waiting for the original transaction to finish will take care of calling binder. ontransact () on the object being called by B. this ensures that the recursion semantics when calling remote binder object are the same as when calling local objects.
The binder system also supports cross-process recursive calls. For example, if process a (by executing its own ibinder transaction () assigns a transaction to process B, and process B is in (its binder. in ontransaction (), when a transaction is processed, it is used to send a call to process a. The thread in process a will also use binder while waiting for the previous transaction to complete. ontransact () responds to B's call. This ensures that the recursive rules for calling remote binder objects are consistent with those for calling local objects.
When working with remote objects, you often want to find out when they are no longer valid. There are three ways this can be determined:
• The transact () method will throw a RemoteException exception if you try to call it on an ibinder whose process no longer exists.
• The pingbinder () method 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 the ibinder, which will be called when its containing process goes away.
When operating on remote objects, you often want to check whether they are valid. Three methods are available:
When you attempt to call ibinder using the transact () function, if the process in which it is located does not exist, a RemoteException will be thrown.
When the pingbinder () function is called, if the remote process does not exist, false is returned.
The linktodeath () function can be used as the ibinder. deathrecipient for registering ibinder. It can be called when a process containing this ibinder exits.

Reference
Binder

Overview

Internal class
Interfaceibinder. deathrecipient
Interface for processing ing a callback when the process hosting an ibinder has gone away.
Interface used to receive callback when a process with ibinder exits

Constant
Intdump_transaction
Ibinder protocol transaction code: Dump internal state.
Ibinder protocol Execution Code: the internal status code of the spam.
Intfirst_call_transaction
The first transaction code available for user commands.
The first valid Execution Code of the USER command.
Intflag_oneway
Flag to transact (INT, parcel, parcel, INT): this is a one-way call, meaning that the caller returns immediately, without waiting for a result from the callee.
The identifier of the transact (INT, parcel, parcel, INT) method: this is a one-way call, meaning that the caller will return immediately without waiting for the result of the caller.
Intinterface_transaction
Ibinder protocol transaction code: interrogate the recipient side of the transaction for its canonical interface descriptor.
Ibinder protocol Execution Code: it is used to query the standard interface descriptor of the invocation receiver.
Intlast_call_transaction
The last transaction code available for user commands.
The last valid Execution Code of the USER command.
Intlike_transaction
Ibinder protocol transaction code: tell an app asynchronously that the caller likes it.
Ibinder protocol Execution Code: asynchronously notifies the application caller of its liking.
Intping_transaction
Ibinder protocol transaction code: pingbinder ().
Ibinder protocol Execution Code: pingbinder ()
Inttweet_transaction
Ibinder protocol transaction code: Send a tweet to the target object.
Ibinder protocol Execution Code: Send tweet to the target object

Common Methods
Abstract void dump (filedescriptor FD, string [] ARGs)
Print the object's state into the given stream.
Print the object status to the given stream.
Abstract void dumpasync (filedescriptor FD, string [] ARGs)
Like dump (filedescriptor, string []) but always executes asynchronously.
Similar to dump (filedescriptor, string []), but it is always executed asynchronously.

Abstract string
Getinterfacedescriptor ()
Get the canonical name of the interface supported by this binder.
Obtain the name of the API Specification supported by the binder.
Abstract Boolean isbinderalive ()
Check to see if the process that the binder is in is still alive.
Check whether the binder is active in the process
Abstract void linktodeath (ibinder. deathrecipient recipient, int flags)
Register the recipient for a notification if this binder goes away.
If the binder exits, It is registered to the notification recipient.
Abstract Boolean pingbinder ()
Check to see if the object still exists.
Check whether the Object exits.
Abstract iinterface
Querylocalinterface (string descriptor)
Attempt to retrieve a local implementation of an interface for this binder object.
Attempts to implement the binder object Retrieval Interface locally.
Abstract Boolean transact (INT code, parcel data, parcel reply, int flags)
Perform a generic operation with the object.
Execute common operations on objects.
Abstract Boolean unlinktodeath (ibinder. deathrecipient recipient, int flags)
Remove a previusly registered death notification.
Remove the previously registered death notification.

Constant
Public static final int dump_transaction
Since: API Level 1
Ibinder protocol transaction code: Dump internal state.
Ibinder protocol Execution Code: the internal status code of the spam.
Constant Value: 1598311760 (0x5f444d50)
Public static final int first_call_transaction
Since: API Level 1
The first transaction code available for user commands.
The first valid Execution Code of the USER command.
Constant Value: 1 (0x00000001)
Public static final int flag_oneway
Since: API Level 1
Flag to transact (INT, parcel, parcel, INT): this is a one-way call, meaning that the caller returns immediately, without waiting for a result from the callee. applies only if the caller and callee are in different processes.
The identifier of the transact (INT, parcel, parcel, INT) method: this is a one-way call, meaning that the caller will return immediately without waiting for the result of the caller. Only applicable to the process where the caller and the called are different.
Constant Value: 1 (0x00000001)
Public static final int interface_transaction
Since: API Level 1
Ibinder protocol transaction code: interrogate the recipient side of the transaction for its canonical interface descriptor.
Ibinder protocol Execution Code: it is used to query the standard interface descriptor of the invocation receiver.

Constant Value: 1598968902 (0x5f4e5446)
Public static final int last_call_transaction
Since: API Level 1
The last transaction code available for user commands.
The last valid Execution Code of the USER command.
Constant Value: 16777215 (0x00ffffff)
Public static final int like_transaction
Since: API level 15
Ibinder protocol transaction code: tell an app asynchronously that the caller likes it. the app is responsible for incrementing and maintaining its own like counter, and may display this value to the user to indicate the quality of the app. this is an optional command that applications do not need to handle, so the default implementation is to do nothing.
There is no response returned and nothing about the system will be functionally affected by it, but it will improve the app's self-esteem.
Ibinder protocol Execution Code: asynchronously notifies the application caller of its liking. An application accumulates and maintains itself like a counter, and displays the value indicating the application quality to the user. This is an optional command and does not need to be processed by the application. Therefore, no processing is performed by default.
Constant Value: 1598835019 (0x5f4c494b)
Public static final int ping_transaction
Since: API Level 1
Ibinder protocol transaction code: pingbinder ().
Ibinder protocol Execution Code: pingbinder ().
Constant Value: 1599098439 (0x5f504e47)
Public static final int tweet_transaction
Since: API Level 13
Ibinder protocol transaction code: Send a tweet to the target object. the data in the parcel is intended to be delivered to a shared messaging service associated with the object; it can be anything, as long as it is not more than 130 UTF-8 characters to conservatively fit within common messaging services. as part of honeycomb_mr2, all binder objects are expected to support this protocol for fully integrated tweeting guest ss the platform. to support older code, the default implementation logs the tweet to the main log as a simple emulation of broadcasting it publicly over the Internet.
Also, upon completing the dispatch, the object must make a cup of tea, return it to the caller, and exclaim "Jolly Good message old boy! ".

Ibinder protocol Execution Code: Send tweet to the target object. The packaged data is sent to the shared message service associated with the object; it can be anything as long as it has less than 130 UTF-8 bytes that are carefully stored in the common message service. As part of honeycomb_mr2, it is expected that all binder objects will support the fully integrated tweet Protocol across platforms. To support the old code, the default implementation record the tweet message to the master log as a simple simulation for broadcasting on the Internet.
In addition, after the scheduling is completed, the object should have a cup of tea, return it to the caller, and loudly announce: "Great information, old boy !".

Constant Value: 1599362900 (0x5f545754)

Common Methods
Public abstract void dump (filedescriptor FD, string [] ARGs)
Since: API level 3
Print the object's state into the given stream.
Prints the object status to the specified stream.
Parameters
Fdthe raw file descriptor that the dump is being sent.
The original file descriptor that the dump is sent.
Argsadditional arguments to the dump request.
Additional Parameters of the dump request.

Throw an exception
RemoteException

Public abstract void dumpasync (filedescriptor FD, string [] ARGs)
Since: API Level 13
Like dump (filedescriptor, string []) but always executes asynchronously. if the object is local, a new thread is created to perform the dump.
Similar to dump (filedescriptor, string []), but it is always executed asynchronously. If the object is local, a new thread is created to run dump.
Parameters
Fdthe raw file descriptor that the dump is being sent.
The original file descriptor that the dump is sent.
Argsadditional arguments to the dump request.
Additional Parameters of the dump request.
Throw an exception
RemoteException

Public abstract string getinterfacedescriptor ()
Since: API Level 1
Get the canonical name of the interface supported by this binder.
Obtain the name of the API Specification supported by the binder.
Throw an exception
RemoteException

Public Abstract Boolean isbinderalive ()
Since: API Level 1
Check to see if the process that the binder is in is still alive.
Check whether the binder of the process is active.
Return
• False if the process is not alive. Note that if it returns true, the process may have died while the call is returning.
• If the process is inactive, false is returned. Note that if true is returned, the process may die when the call is returning.
Public abstract void linktodeath (ibinder. deathrecipient recipient, int flags)
Since: API Level 1
Register the recipient for a notification if this binder goes away. if this binder object unexpectedly goes away (typically because its hosting process has been killed), then the given ibinder. deathrecipient's deathrecipient. binderdied () method will be called.
If the binder exits, It is registered to the notification recipient. If the binder object unexpectedly exits (typically because its host process is killed), The deathrecipient. binderdied () method of the given ibinder. deathrecipient will be called.
You will only receive death configurations for remote binders, as local binders by definition can't die without you dying as well.
You will only receive notifications about the death of remote binders. Similarly, according to the definition, ibinder does not have local binders and cannot die.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.