class RpcSession

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

This represents a session (group of connections) between a client

and a server. Multiple connections are needed for multiple parallel "binder"

calls which may also have nested calls.

Once a binder exists in the session, if all references to all binders are dropped,

the session shuts down.

Public Methods

sp<RpcSession> make ()

Create an RpcSession with default configuration (raw sockets).

sp<RpcSession> make (std::unique_ptr<RpcTransportCtxFactory> rpcTransportCtxFactory)

Create an RpcSession with the given configuration. |serverRpcCertificateFormat| and

|serverCertificate| must have values or be nullopt simultaneously. If they have values, set

server certificate.

void setMaxIncomingThreads (size_t threads)

Set the maximum number of incoming threads allowed to be made (for things like callbacks).

By default, this is 0. This must be called before setting up this connection as a client.

Server sessions will inherits this value from RpcServer. Each thread will serve a

connection to the remote RpcSession.

If this is called, 'shutdown' on this session must also be called.

Otherwise, a threadpool will leak.

TODO(b/189955605): start these lazily - currently all are started

size_t getMaxIncomingThreads ()
void setMaxOutgoingConnections (size_t connections)

Set the maximum number of outgoing connections allowed to be made.

By default, this is |kDefaultMaxOutgoingConnections|. This must be called before setting up

this connection as a client.

For an RpcSession client, if you are connecting to a server which starts N threads,

then this must be set to >= N. If you set the maximum number of outgoing connections

to 1, but the server requests 10, then it would be considered an error. If you set a

maximum number of connections to 10, and the server requests 1, then only 1 will be

created. This API is used to limit the amount of resources a server can request you

create.

size_t getMaxOutgoingThreads ()
bool setProtocolVersion (uint32_t version)

By default, the minimum of the supported versions of the client and the

server will be used. Usually, this API should only be used for debugging.

std::optional<uint32_t> getProtocolVersion ()
void setFileDescriptorTransportMode (FileDescriptorTransportMode mode)

Set the transport for sending and receiving file descriptors.

FileDescriptorTransportMode getFileDescriptorTransportMode ()
status_t setupUnixDomainClient (const char * path)

This should be called once per thread, matching 'join' in the remote

process.

status_t setupUnixDomainSocketBootstrapClient (binder::unique_fd bootstrap)

Connects to an RPC server over a nameless Unix domain socket pair.

status_t setupVsockClient (unsigned int cid, unsigned int port)

Connects to an RPC server at the CID

&

port.

status_t setupInetClient (const char * addr, unsigned int port)

Connects to an RPC server at the given address and port.

status_t setupPreconnectedClient (binder::unique_fd fd, std::function<binder::unique_fd ()> && request)

Starts talking to an RPC server which has already been connected to. This

is expected to be used when another process has permission to connect to

a binder RPC service, but this process only has permission to talk to

that service.

For convenience, if 'fd' is -1, 'request' will be called.

For future compatibility, 'request' should not reference any stack data.

status_t addNullDebuggingClient ()

For debugging!

Sets up an empty connection. All queries to this connection which require a

response will never be satisfied. All data sent here will be

unceremoniously cast down the bottomless pit, /dev/null.

sp<IBinder> getRootObject ()

Query the other side of the session for the root object hosted by that

process's RpcServer (if one exists)

status_t getRemoteMaxThreads (size_t * maxThreads)

Query the other side of the session for the maximum number of threads

it supports (maximum number of concurrent non-nested synchronous transactions)

std::vector<uint8_t> getCertificate (RpcCertificateFormat )

See RpcTransportCtx::getCertificate

bool shutdownAndWait (bool wait)

Shuts down the service.

For client sessions, wait can be true or false. For server sessions,

waiting is not currently supported (will abort).

Warning: this is currently not active/nice (the server isn't told we're

shutting down). Being nicer to the server could potentially make it

reclaim resources faster.

If this is called w/ 'wait' true, then this will wait for shutdown to

complete before returning. This will hang if it is called from the

session threadpool (when processing received calls).

status_t transact (const sp<IBinder> & binder, uint32_t code, const Parcel & data, Parcel * reply, uint32_t flags)
status_t sendDecStrong (const BpBinder * binder)

Generally, you should not call this, unless you are testing error

conditions, as this is called automatically by BpBinders when they are

deleted (this is also why a raw pointer is used here)

bool hasActiveRequests ()

Whether any requests are currently being processed.

void ~RpcSession ()
sp<RpcServer> server ()

Server if this session is created as part of a server (symmetrical to

client servers). Otherwise, nullptr.

void setSessionSpecificRoot (const sp<IBinder> & sessionSpecificRoot)

Sets the session-specific root object. This is the object that will be used to attach

the IAccessor binder to the RpcSession when a binder is set up via accessor.

const std::unique_ptr<RpcState> & state ()

internal only

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

Enumerations

enum FileDescriptorTransportMode
Name Value
NONE 0
UNIX 1
TRUSTY 2

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

Friends

class WaitForShutdownListener
class RpcState
class RpcServerTrusty
class RpcServer
class sp