class IBinder

Defined at line 52 of file ../../third_party/android/platform/frameworks/native/libs/binder/include/binder/IBinder.h

Base class and low-level protocol for a remotable object.

You can derive from this class to create an object for which other

processes can hold references to it. Communication between processes

(method calls, property get and set) is down through a low-level

protocol implemented on top of the transact() API.

Public Methods

void IBinder ()
sp<IInterface> queryLocalInterface (const String16 & descriptor)

Check if this IBinder implements the interface named by

If it does, the base pointer to it is returned,

which you can safely static_cast

<

> to the concrete C++ interface.

const String16 & getInterfaceDescriptor ()

Return the canonical name of the interface provided by this IBinder

object.

bool isBinderAlive ()

Last known alive status, from last call. May be arbitrarily stale.

May be incorrect if a service returns an incorrect status code.

status_t pingBinder ()
status_t dump (int fd, const Vector<String16> & args)
status_t shellCommand (const sp<IBinder> & target, int in, int out, int err, Vector<String16> & args, const sp<IShellCallback> & callback, const sp<IResultReceiver> & resultReceiver)
status_t getExtension (sp<IBinder> * out)

This allows someone to add their own additions to an interface without

having to modify the original interface.

For instance, imagine if we have this interface:

interface IFoo { void doFoo(); }

If an unrelated owner (perhaps in a downstream codebase) wants to make a

change to the interface, they have two options:

A). Historical option that has proven to be BAD! Only the original

author of an interface should change an interface. If someone

downstream wants additional functionality, they should not ever

change the interface or use this method.

BAD TO DO: interface IFoo { BAD TO DO

BAD TO DO: void doFoo(); BAD TO DO

BAD TO DO: + void doBar(); // adding a method BAD TO DO

BAD TO DO: } BAD TO DO

B). Option that this method enables!

Leave the original interface unchanged (do not change IFoo!).

Instead, create a new interface in a downstream package:

package com.

<name

>; // new functionality in a new package

interface IBar { void doBar(); }

When registering the interface, add:

sp

<MyFoo

> foo = new MyFoo; // class in AOSP codebase

sp

<MyBar

> bar = new MyBar; // custom extension class

foo->setExtension(bar); // use method in BBinder

Then, clients of IFoo can get this extension:

sp

<IBinder

> binder = ...;

sp

<IFoo

> foo = interface_cast

<IFoo

>(binder); // handle if null

sp

<IBinder

> barBinder;

... handle error ... = binder->getExtension(

&barBinder

);

sp

<IBar

> bar = interface_cast

<IBar

>(barBinder);

// if bar is null, then there is no extension or a different

// type of extension

status_t getDebugPid (pid_t * outPid)

Dump PID for a binder, for debugging.

status_t setRpcClientDebug (binder::unique_fd socketFd, const sp<IBinder> & keepAliveBinder)

Set the RPC client fd to this binder service, for debugging. This is only available on

debuggable builds.

When this is called on a binder service, the service:

1. sets up RPC server

2. spawns 1 new thread that calls RpcServer::join()

- join() spawns some number of threads that accept() connections; see RpcServer

setRpcClientDebug() may be called multiple times. Each call will add a new RpcServer

and opens up a TCP port.

Note: A thread is spawned for each accept()'ed fd, which may call into functions of the

interface freely. See RpcServer::join(). To avoid such race conditions, implement the service

functions with multithreading support.

On death of

the RpcServer shuts down.

status_t transact (uint32_t code, const Parcel & data, Parcel * reply, uint32_t flags)

NOLINTNEXTLINE(google-default-arguments)

status_t linkToDeath (const sp<DeathRecipient> & recipient, void * cookie, uint32_t flags)

Register the

for a notification if this binder

goes away. If this binder object unexpectedly goes away

(typically because its hosting process has been killed),

then DeathRecipient::binderDied() will be called with a reference

to this.

The

is optional -- if non-NULL, it should be a

memory address that you own (that is, you know it is unique).

NOLINTNEXTLINE(google-default-arguments)

status_t unlinkToDeath (const wp<DeathRecipient> & recipient, void * cookie, uint32_t flags, wp<DeathRecipient> * outRecipient)

Remove a previously registered death notification.

The

will no longer be called if this object

dies. The

is optional. If non-NULL, you can

supply a NULL

and the recipient previously

added with that cookie will be unlinked.

If the binder is dead, this will return DEAD_OBJECT. Deleting

the object will also unlink all death recipients.

NOLINTNEXTLINE(google-default-arguments)

status_t addFrozenStateChangeCallback (const wp<FrozenStateChangeCallback> & callback)

addFrozenStateChangeCallback provides a callback mechanism to notify

about process frozen/unfrozen events. Upon registration and any

subsequent state changes, the callback is invoked with the latest process

frozen state.

If the listener process (the one using this API) is itself frozen, state

change events might be combined into a single one with the latest state.

(meaning 'frozen, unfrozen' might just be 'unfrozen'). This single event

would then be delivered when the listener process becomes unfrozen.

Similarly, if an event happens before the previous event is consumed,

they might be combined. This means the callback might not be called for

every single state change, so don't rely on this API to count how many

times the state has changed.

status_t removeFrozenStateChangeCallback (const wp<FrozenStateChangeCallback> & callback)

Remove a previously registered freeze callback.

The

will no longer be called if this object

changes its frozen state.

bool checkSubclass (const void * subclassID)
void * attachObject (const void * objectID, void * object, void * cleanupCookie, object_cleanup_func func)

This object is attached for the lifetime of this binder object. When

this binder object is destructed, the cleanup function of all attached

objects are invoked with their respective objectID, object, and

cleanupCookie. Access to these APIs can be made from multiple threads,

but calls from different threads are allowed to be interleaved.

This returns the object which is already attached. If this returns a

non-null value, it means that attachObject failed (a given objectID can

only be used once).

void * findObject (const void * objectID)

Returns object attached with attachObject.

void * detachObject (const void * objectID)

Returns object attached with attachObject, and detaches it. This does not

delete the object.

void withLock (const std::function<void ()> & doWithLock)

Use the lock that this binder contains internally. For instance, this can

be used to modify an attached object without needing to add an additional

lock (though, that attached object must be retrieved before calling this

method). Calling (most) IBinder methods inside this will deadlock.

BBinder * localBinder ()
BpBinder * remoteBinder ()
sp<IBinder> lookupOrCreateWeak (const void * objectID, object_make_func make, const void * makeArgs)

Protected Methods

void ~IBinder ()

Enumerations

enum 
Name Value
FIRST_CALL_TRANSACTION 0x00000001
LAST_CALL_TRANSACTION 0x00ffffff
PING_TRANSACTION B_PACK_CHARS('_', 'P', 'N', 'G')
START_RECORDING_TRANSACTION B_PACK_CHARS('_', 'S', 'R', 'D')
STOP_RECORDING_TRANSACTION B_PACK_CHARS('_', 'E', 'R', 'D')
DUMP_TRANSACTION B_PACK_CHARS('_', 'D', 'M', 'P')
SHELL_COMMAND_TRANSACTION B_PACK_CHARS('_', 'C', 'M', 'D')
INTERFACE_TRANSACTION B_PACK_CHARS('_', 'N', 'T', 'F')
SYSPROPS_TRANSACTION B_PACK_CHARS('_', 'S', 'P', 'R')
EXTENSION_TRANSACTION B_PACK_CHARS('_', 'E', 'X', 'T')
DEBUG_PID_TRANSACTION B_PACK_CHARS('_', 'P', 'I', 'D')
SET_RPC_CLIENT_TRANSACTION B_PACK_CHARS('_', 'R', 'P', 'C')
TWEET_TRANSACTION B_PACK_CHARS('_', 'T', 'W', 'T')
LIKE_TRANSACTION B_PACK_CHARS('_', 'L', 'I', 'K')
FLAG_ONEWAY 0x00000001
FLAG_CLEAR_BUF 0x00000020
FLAG_PRIVATE_VENDOR 0x10000000

Defined at line 54 of file ../../third_party/android/platform/frameworks/native/libs/binder/include/binder/IBinder.h

Records