Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Inherited Constants](https://developer.android.com/reference/android/os/Binder#inhconstants) \| [Ctors](https://developer.android.com/reference/android/os/Binder#pubctors) \| [Methods](https://developer.android.com/reference/android/os/Binder#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/os/Binder#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/os/Binder#inhmethods)

# Binder

*** ** * ** ***

` public class Binder `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/android/os/IBinder `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.os.Binder |

<br />

*** ** * ** ***

Base class for a remotable object, the core part of a lightweight remote procedure call mechanism defined by `https://developer.android.com/reference/android/os/IBinder`. This class is an implementation of IBinder that provides standard local implementation of such an object.

Most developers will not implement this class directly, instead using the [aidl](https://developer.android.com/guide/components/aidl) tool to describe the desired interface, having it generate the appropriate Binder subclass. You can, however, derive directly from Binder to implement your own custom RPC protocol or simply instantiate a raw Binder object directly to use as a token that can be shared across processes.

This class is just a basic IPC primitive; it has no impact on an application's lifecycle, and is valid only as long as the process that created it continues to run. To use this correctly, you must be doing so within the context of a top-level application component (a `https://developer.android.com/reference/android/app/Service`, `https://developer.android.com/reference/android/app/Activity`, or `https://developer.android.com/reference/android/content/ContentProvider`) that lets the system know your process should remain running.

You must keep in mind the situations in which your process could go away, and thus require that you later re-create a new Binder and re-attach it when the process starts again. For example, if you are using this within an `https://developer.android.com/reference/android/app/Activity`, your activity's process may be killed any time the activity is not started; if the activity is later re-created you will need to create a new Binder and hand it back to the correct place again; you need to be aware that your process may be started for another reason (for example to receive a broadcast) that will not involve re-creating the activity and thus run its code to create a new Binder.
**See also:**

- `https://developer.android.com/reference/android/os/IBinder`

## Summary

### Inherited constants

From interface `https://developer.android.com/reference/android/os/IBinder` `int` `https://developer.android.com/reference/android/os/IBinder#DUMP_TRANSACTION`

IBinder protocol transaction code: dump internal state.
`int` `https://developer.android.com/reference/android/os/IBinder#FIRST_CALL_TRANSACTION`

The first transaction code available for user commands.
`int` `https://developer.android.com/reference/android/os/IBinder#FLAG_ONEWAY`

Flag to `https://developer.android.com/reference/android/os/IBinder#transact(int,%20android.os.Parcel,%20android.os.Parcel,%20int)`: this is a one-way call, meaning that the caller returns immediately, without waiting for a result from the callee.
`int` `https://developer.android.com/reference/android/os/IBinder#INTERFACE_TRANSACTION`

IBinder protocol transaction code: interrogate the recipient side of the transaction for its canonical interface descriptor.
`int` `https://developer.android.com/reference/android/os/IBinder#LAST_CALL_TRANSACTION`

The last transaction code available for user commands.
`int` `https://developer.android.com/reference/android/os/IBinder#LIKE_TRANSACTION`

IBinder protocol transaction code: tell an app asynchronously that the caller likes it.
`int` `https://developer.android.com/reference/android/os/IBinder#PING_TRANSACTION`

IBinder protocol transaction code: pingBinder().
`int` `https://developer.android.com/reference/android/os/IBinder#TWEET_TRANSACTION`

IBinder protocol transaction code: send a tweet to the target object.

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/os/Binder#Binder()() ` Default constructor just initializes the object. |
| ` https://developer.android.com/reference/android/os/Binder#Binder(java.lang.String)(https://developer.android.com/reference/java/lang/String descriptor) ` Constructor for creating a raw Binder object (token) along with a descriptor. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/os/Binder#attachInterface(android.os.IInterface,%20java.lang.String)(https://developer.android.com/reference/android/os/IInterface owner, https://developer.android.com/reference/java/lang/String descriptor) ` Convenience method for associating a specific interface with the Binder. |
| ` static final long` | ` https://developer.android.com/reference/android/os/Binder#clearCallingIdentity()() ` Reset the identity of the incoming IPC on the current thread. |
| ` static final long` | ` https://developer.android.com/reference/android/os/Binder#clearCallingWorkSource()() ` Clears the work source on this thread. |
| ` void` | ` https://developer.android.com/reference/android/os/Binder#dump(java.io.FileDescriptor,%20java.lang.String[])(https://developer.android.com/reference/java/io/FileDescriptor fd, https://developer.android.com/reference/java/lang/String args) ` Implemented to call the more convenient version `https://developer.android.com/reference/android/os/Binder#dump(java.io.FileDescriptor,%20java.io.PrintWriter,%20java.lang.String[])`. |
| ` void` | ` https://developer.android.com/reference/android/os/Binder#dumpAsync(java.io.FileDescriptor,%20java.lang.String[])(https://developer.android.com/reference/java/io/FileDescriptor fd, https://developer.android.com/reference/java/lang/String args) ` Like `https://developer.android.com/reference/android/os/Binder#dump(java.io.FileDescriptor,%20java.lang.String[])`, but ensures the target executes asynchronously. |
| ` static final void` | ` https://developer.android.com/reference/android/os/Binder#flushPendingCommands()() ` Flush any Binder commands pending in the current thread to the kernel driver. |
| ` static final int` | ` https://developer.android.com/reference/android/os/Binder#getCallingPid()() ` Return the ID of the process that sent you the current transaction that is being processed. |
| ` static final int` | ` https://developer.android.com/reference/android/os/Binder#getCallingUid()() ` Return the Linux UID assigned to the process that sent you the current transaction that is being processed. |
| ` static final int` | ` https://developer.android.com/reference/android/os/Binder#getCallingUidOrThrow()() ` Return the Linux UID assigned to the process that sent the transaction currently being processed. |
| ` static final https://developer.android.com/reference/android/os/UserHandle` | ` https://developer.android.com/reference/android/os/Binder#getCallingUserHandle()() ` Return the UserHandle assigned to the process that sent you the current transaction that is being processed. |
| ` static final int` | ` https://developer.android.com/reference/android/os/Binder#getCallingWorkSourceUid()() ` Returns the work source set by the caller. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/os/Binder#getInterfaceDescriptor()() ` Default implementation returns an empty interface name. |
| ` boolean` | ` https://developer.android.com/reference/android/os/Binder#isBinderAlive()() ` Check to see if the process that the binder is in is still alive. Note that if you're calling on a local binder, this always returns true because your process is alive if you're calling it. |
| ` static final void` | ` https://developer.android.com/reference/android/os/Binder#joinThreadPool()() ` Add the calling thread to the IPC thread pool. |
| ` void` | ` https://developer.android.com/reference/android/os/Binder#linkToDeath(android.os.IBinder.DeathRecipient,%20int)(https://developer.android.com/reference/android/os/IBinder.DeathRecipient recipient, int flags) ` Local implementation is a no-op. |
| ` boolean` | ` https://developer.android.com/reference/android/os/Binder#pingBinder()() ` Default implementation always returns true -- if you got here, the object is alive. |
| ` https://developer.android.com/reference/android/os/IInterface` | ` https://developer.android.com/reference/android/os/Binder#queryLocalInterface(java.lang.String)(https://developer.android.com/reference/java/lang/String descriptor) ` Use information supplied to `https://developer.android.com/reference/android/os/Binder#attachInterface(android.os.IInterface,%20java.lang.String)` to return the associated `https://developer.android.com/reference/android/os/IInterface` if it matches the requested descriptor. |
| ` static final void` | ` https://developer.android.com/reference/android/os/Binder#restoreCallingIdentity(long)(long token) ` Restore the identity of the incoming IPC on the current thread back to a previously identity that was returned by `https://developer.android.com/reference/android/os/Binder#clearCallingIdentity()`. |
| ` static final void` | ` https://developer.android.com/reference/android/os/Binder#restoreCallingWorkSource(long)(long token) ` Restores the work source on this thread using a token returned by `https://developer.android.com/reference/android/os/Binder#setCallingWorkSourceUid(int)` or `https://developer.android.com/reference/android/os/Binder#clearCallingWorkSource()`. |
| ` static final long` | ` https://developer.android.com/reference/android/os/Binder#setCallingWorkSourceUid(int)(int workSource) ` Sets the work source for this thread. |
| ` final boolean` | ` https://developer.android.com/reference/android/os/Binder#transact(int,%20android.os.Parcel,%20android.os.Parcel,%20int)(int code, https://developer.android.com/reference/android/os/Parcel data, https://developer.android.com/reference/android/os/Parcel reply, int flags) ` Default implementation rewinds the parcels and calls onTransact. |
| ` boolean` | ` https://developer.android.com/reference/android/os/Binder#unlinkToDeath(android.os.IBinder.DeathRecipient,%20int)(https://developer.android.com/reference/android/os/IBinder.DeathRecipient recipient, int flags) ` Local implementation is a no-op. |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/os/Binder#dump(java.io.FileDescriptor,%20java.io.PrintWriter,%20java.lang.String[])(https://developer.android.com/reference/java/io/FileDescriptor fd, https://developer.android.com/reference/java/io/PrintWriter fout, https://developer.android.com/reference/java/lang/String args) ` Print the object's state into the given stream. |
| ` boolean` | ` https://developer.android.com/reference/android/os/Binder#onTransact(int,%20android.os.Parcel,%20android.os.Parcel,%20int)(int code, https://developer.android.com/reference/android/os/Parcel data, https://developer.android.com/reference/android/os/Parcel reply, int flags) ` Default implementation is a stub that returns false. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.
From interface ` https://developer.android.com/reference/android/os/IBinder ` ` default void` ` https://developer.android.com/reference/android/os/IBinder#addFrozenStateChangeCallback(java.util.concurrent.Executor,%20android.os.IBinder.FrozenStateChangeCallback)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/IBinder.FrozenStateChangeCallback callback) `

This method provides a callback mechanism to notify about process frozen/unfrozen events.
` abstract void` ` https://developer.android.com/reference/android/os/IBinder#dump(java.io.FileDescriptor,%20java.lang.String[])(https://developer.android.com/reference/java/io/FileDescriptor fd, https://developer.android.com/reference/java/lang/String args) `

Print the object's state into the given stream.
` abstract void` ` https://developer.android.com/reference/android/os/IBinder#dumpAsync(java.io.FileDescriptor,%20java.lang.String[])(https://developer.android.com/reference/java/io/FileDescriptor fd, https://developer.android.com/reference/java/lang/String args) `

Like `https://developer.android.com/reference/android/os/IBinder#dump(java.io.FileDescriptor,%20java.lang.String[])` but always executes asynchronously.
` abstract https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/android/os/IBinder#getInterfaceDescriptor()() `

Get the canonical name of the interface supported by this binder.
` static int` ` https://developer.android.com/reference/android/os/IBinder#getSuggestedMaxIpcSizeBytes()() `

Limit that should be placed on IPC sizes, in bytes, to keep them safely under the transaction buffer limit.
` abstract boolean` ` https://developer.android.com/reference/android/os/IBinder#isBinderAlive()() `

Check to see if the process that the binder is in is still alive.
` abstract void` ` https://developer.android.com/reference/android/os/IBinder#linkToDeath(android.os.IBinder.DeathRecipient,%20int)(https://developer.android.com/reference/android/os/IBinder.DeathRecipient recipient, int flags) `

Register the recipient for a notification if this binder goes away.
` abstract boolean` ` https://developer.android.com/reference/android/os/IBinder#pingBinder()() `

Check to see if the object still exists.
` abstract https://developer.android.com/reference/android/os/IInterface` ` https://developer.android.com/reference/android/os/IBinder#queryLocalInterface(java.lang.String)(https://developer.android.com/reference/java/lang/String descriptor) `

Attempt to retrieve a local implementation of an interface for this Binder object.
` default boolean` ` https://developer.android.com/reference/android/os/IBinder#removeFrozenStateChangeCallback(android.os.IBinder.FrozenStateChangeCallback)(https://developer.android.com/reference/android/os/IBinder.FrozenStateChangeCallback callback) `

Unregister a `https://developer.android.com/reference/android/os/IBinder.FrozenStateChangeCallback`.
` abstract boolean` ` https://developer.android.com/reference/android/os/IBinder#transact(int,%20android.os.Parcel,%20android.os.Parcel,%20int)(int code, https://developer.android.com/reference/android/os/Parcel data, https://developer.android.com/reference/android/os/Parcel reply, int flags) `

Perform a generic operation with the object.
` abstract boolean` ` https://developer.android.com/reference/android/os/IBinder#unlinkToDeath(android.os.IBinder.DeathRecipient,%20int)(https://developer.android.com/reference/android/os/IBinder.DeathRecipient recipient, int flags) `

Remove a previously registered death notification.

## Public constructors

### Binder

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Binder ()
```

Default constructor just initializes the object.

If you're creating a Binder token (a Binder object without an attached interface), you should use `https://developer.android.com/reference/android/os/Binder#Binder(java.lang.String)` instead.

<br />

### Binder

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Binder (String descriptor)
```

Constructor for creating a raw Binder object (token) along with a descriptor.

The descriptor of binder objects usually specifies the interface they are implementing. In case of binder tokens, no interface is implemented, and the descriptor can be used as a sort of tag to help identify the binder token. This will help identify remote references to these objects more easily when debugging.

<br />

| Parameters ||
|---|---|
| `descriptor` | `String`: Used to identify the creator of this token, for example the class name. Instead of creating multiple tokens with the same descriptor, consider adding a suffix to help identify them. This value may be `null`. <br /> |

## Public methods

### attachInterface

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void attachInterface (IInterface owner, 
                String descriptor)
```

Convenience method for associating a specific interface with the Binder. After calling, `https://developer.android.com/reference/android/os/Binder#queryLocalInterface(java.lang.String)` will be implemented for you to return the given owner IInterface when the corresponding descriptor is requested.

<br />

| Parameters ||
|---|---|
| `owner` | `IInterface`: This value may be `null`. <br /> |
| `descriptor` | `String`: This value may be `null`. <br /> |

### clearCallingIdentity

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long clearCallingIdentity ()
```

Reset the identity of the incoming IPC on the current thread. This can be useful if, while handling an incoming call, you will be calling on interfaces of other objects that may be local to your process and need to do permission checks on the calls coming into them (so they will check the permission of your own local process, and not whatever process originally called you).

<br />

| Returns ||
|---|---|
| `long` | Returns an opaque token that can be used to restore the original calling identity by passing it to `https://developer.android.com/reference/android/os/Binder#restoreCallingIdentity(long)`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/os/Binder#getCallingPid()`
- `https://developer.android.com/reference/android/os/Binder#getCallingUid()`
- `https://developer.android.com/reference/android/os/Binder#restoreCallingIdentity(long)`

### clearCallingWorkSource

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long clearCallingWorkSource ()
```

Clears the work source on this thread.

The work source will be propagated for future outgoing binder transactions executed on this thread.

`https://developer.android.com/reference/android/os/Binder#restoreCallingWorkSource(long)` must always be called after clearing the worksource.

A typical use case would be

```
long token = Binder.clearCallingWorkSource();
try {
  // Call an API.
} finally {
  Binder.restoreCallingWorkSource(token);
}
```

<br />

<br />

| Returns ||
|---|---|
| `long` | token to restore original work source. <br /> |

### dump

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void dump (FileDescriptor fd, 
                String[] args)
```

Implemented to call the more convenient version `https://developer.android.com/reference/android/os/Binder#dump(java.io.FileDescriptor,%20java.io.PrintWriter,%20java.lang.String[])`.

<br />

| Parameters ||
|---|---|
| `fd` | `FileDescriptor`: This value cannot be `null`. <br /> |
| `args` | `String`: This value may be `null`. <br /> |

### dumpAsync

Added in [API level 13](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void dumpAsync (FileDescriptor fd, 
                String[] args)
```

Like `https://developer.android.com/reference/android/os/Binder#dump(java.io.FileDescriptor,%20java.lang.String[])`, but ensures the target executes asynchronously.

<br />

| Parameters ||
|---|---|
| `fd` | `FileDescriptor`: This value cannot be `null`. <br /> |
| `args` | `String`: This value may be `null`. <br /> |

### flushPendingCommands

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final void flushPendingCommands ()
```

Flush any Binder commands pending in the current thread to the kernel driver. This can be useful to call before performing an operation that may block for a long time, to ensure that any pending object references have been released in order to prevent the process from holding on to objects longer than it needs to.

<br />

### getCallingPid

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int getCallingPid ()
```

Return the ID of the process that sent you the current transaction that is being processed. This PID can be used with higher-level system services to determine its identity and check permissions. If the current thread is not currently executing an incoming transaction, then its own PID is returned. Warning do not use this as a security identifier! PID is unreliable as it may be re-used. This should mostly be used for debugging. oneway transactions do not receive PID. Even if you expect a transaction to be synchronous, a misbehaving client could send it as a asynchronous call and result in a 0 PID here. Additionally, if there is a race and the calling process dies, the PID may still be 0 for a synchronous call.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### getCallingUid

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int getCallingUid ()
```

Return the Linux UID assigned to the process that sent you the current transaction that is being processed. This UID can be used with higher-level system services to determine its identity and check permissions. If the current thread is not currently executing an incoming transaction, then its own UID is returned.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### getCallingUidOrThrow

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int getCallingUidOrThrow ()
```

Return the Linux UID assigned to the process that sent the transaction currently being processed.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the current thread is not currently executing an incoming transaction and the calling identity has not been explicitly set with `https://developer.android.com/reference/android/os/Binder#clearCallingIdentity()` |

### getCallingUserHandle

Added in [API level 17](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final UserHandle getCallingUserHandle ()
```

Return the UserHandle assigned to the process that sent you the current transaction that is being processed. This is the user of the caller. It is distinct from `https://developer.android.com/reference/android/os/Binder#getCallingUid()` in that a particular user will have multiple distinct apps running under it each with their own UID. If the current thread is not currently executing an incoming transaction, then its own UserHandle is returned.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/UserHandle` | This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/os/UserHandle`

### getCallingWorkSourceUid

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int getCallingWorkSourceUid ()
```

Returns the work source set by the caller.

Unlike `https://developer.android.com/reference/android/os/Binder#getCallingUid()`, this result of this method cannot be trusted. The caller can set the value to whatever they want. Only use this value if you trust the calling UID.

<br />

| Returns ||
|---|---|
| `int` | The original UID responsible for the binder transaction. <br /> |

### getInterfaceDescriptor

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getInterfaceDescriptor ()
```

Default implementation returns an empty interface name.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | This value may be `null`. <br /> |

### isBinderAlive

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isBinderAlive ()
```

Check to see if the process that the binder is in is still alive. Note that if you're calling on a local binder, this always returns true because your process is alive if you're calling it.

<br />

| Returns ||
|---|---|
| `boolean` | false if the process is not alive. Note that if it returns true, the process may have died while the call is returning. <br /> |

### joinThreadPool

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final void joinThreadPool ()
```

Add the calling thread to the IPC thread pool. This function does not return until the current process is exiting.

<br />

### linkToDeath

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void linkToDeath (IBinder.DeathRecipient recipient, 
                int flags)
```

Local implementation is a no-op.

<br />

| Parameters ||
|---|---|
| `recipient` | `IBinder.DeathRecipient`: This value cannot be `null`. <br /> |
| `flags` | `int` <br /> |

### pingBinder

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean pingBinder ()
```

Default implementation always returns true -- if you got here, the object is alive.

<br />

| Returns ||
|---|---|
| `boolean` | Returns false if the hosting process is gone, otherwise the result (always by default true) returned by the pingBinder() implementation on the other side. <br /> |

### queryLocalInterface

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public IInterface queryLocalInterface (String descriptor)
```

Use information supplied to `https://developer.android.com/reference/android/os/Binder#attachInterface(android.os.IInterface,%20java.lang.String)` to return the associated `https://developer.android.com/reference/android/os/IInterface` if it matches the requested descriptor.

<br />

| Parameters ||
|---|---|
| `descriptor` | `String`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/IInterface` | This value may be `null`. <br /> |

### restoreCallingIdentity

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final void restoreCallingIdentity (long token)
```

Restore the identity of the incoming IPC on the current thread back to a previously identity that was returned by `https://developer.android.com/reference/android/os/Binder#clearCallingIdentity()`.

<br />

| Parameters ||
|---|---|
| `token` | `long`: The opaque token that was previously returned by `https://developer.android.com/reference/android/os/Binder#clearCallingIdentity()`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/os/Binder#clearCallingIdentity()`

### restoreCallingWorkSource

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final void restoreCallingWorkSource (long token)
```

Restores the work source on this thread using a token returned by `https://developer.android.com/reference/android/os/Binder#setCallingWorkSourceUid(int)` or `https://developer.android.com/reference/android/os/Binder#clearCallingWorkSource()`.

A typical use case would be

```
long token = Binder.setCallingWorkSourceUid(uid);
try {
  // Call an API.
} finally {
  Binder.restoreCallingWorkSource(token);
}
```

<br />

<br />

| Parameters ||
|---|---|
| `token` | `long` <br /> |

### setCallingWorkSourceUid

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long setCallingWorkSourceUid (int workSource)
```

Sets the work source for this thread.

All the following binder calls on this thread will use the provided work source. If this is called during an on-going binder transaction, all the following binder calls will use the work source until the end of the transaction.

The concept of worksource is similar to `https://developer.android.com/reference/android/os/WorkSource`. However, for performance reasons, we only support one UID. This UID represents the original user responsible for the binder calls.

`https://developer.android.com/reference/android/os/Binder#restoreCallingWorkSource(long)` must always be called after setting the worksource.

A typical use case would be

```
long token = Binder.setCallingWorkSourceUid(uid);
try {
  // Call an API.
} finally {
  Binder.restoreCallingWorkSource(token);
}
```

The work source will be propagated for future outgoing binder transactions executed on this thread.

<br />

| Parameters ||
|---|---|
| `workSource` | `int`: The original UID responsible for the binder call. <br /> |

| Returns ||
|---|---|
| `long` | token to restore original work source. <br /> |

### transact

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final boolean transact (int code, 
                Parcel data, 
                Parcel reply, 
                int flags)
```

Default implementation rewinds the parcels and calls onTransact. On the remote side, transact calls into the binder to do the IPC.

<br />

| Parameters ||
|---|---|
| `code` | `int`: The action to perform. This should be a number between `https://developer.android.com/reference/android/os/IBinder#FIRST_CALL_TRANSACTION` and `https://developer.android.com/reference/android/os/IBinder#LAST_CALL_TRANSACTION`. <br /> |
| `data` | `Parcel`: This value cannot be `null`. <br /> |
| `reply` | `Parcel`: This value may be `null`. <br /> |
| `flags` | `int`: Additional operation flags. Either 0 for a normal RPC, or `https://developer.android.com/reference/android/os/IBinder#FLAG_ONEWAY` for a one-way RPC. <br /> |

| Returns ||
|---|---|
| `boolean` | Returns the result from `https://developer.android.com/reference/android/os/Binder#onTransact(int,%20android.os.Parcel,%20android.os.Parcel,%20int)`. A successful call generally returns true; false generally means the transaction code was not understood. For a oneway call to a different process false should never be returned. If a oneway call is made to code in the same process (usually to a C++ or Rust implementation), then there are no oneway semantics, and false can still be returned. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException` |   |

### unlinkToDeath

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean unlinkToDeath (IBinder.DeathRecipient recipient, 
                int flags)
```

Local implementation is a no-op.

<br />

| Parameters ||
|---|---|
| `recipient` | `IBinder.DeathRecipient`: This value cannot be `null`. <br /> |
| `flags` | `int` <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if the <var translate="no">recipient</var> is successfully unlinked, assuring you that its `https://developer.android.com/reference/android/os/IBinder.DeathRecipient#binderDied()` method will not be called; `false` if the target IBinder has already died, meaning the method has been (or soon will be) called. <br /> |

## Protected methods

### dump

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void dump (FileDescriptor fd, 
                PrintWriter fout, 
                String[] args)
```

Print the object's state into the given stream.

<br />

| Parameters ||
|---|---|
| `fd` | `FileDescriptor`: The raw file descriptor that the dump is being sent to. This value cannot be `null`. <br /> |
| `fout` | `PrintWriter`: The file to which you should dump your state. This will be closed for you after you return. This value cannot be `null`. <br /> |
| `args` | `String`: additional arguments to the dump request. This value may be `null`. <br /> |

### onTransact

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected boolean onTransact (int code, 
                Parcel data, 
                Parcel reply, 
                int flags)
```

Default implementation is a stub that returns false. You will want to override this to do the appropriate unmarshalling of transactions.

If you want to call this, call transact().

Implementations that are returning a result should generally use `https://developer.android.com/reference/android/os/Parcel#writeNoException()` and `https://developer.android.com/reference/android/os/Parcel#writeException(java.lang.Exception)` to propagate exceptions back to the caller.

<br />

| Parameters ||
|---|---|
| `code` | `int`: The action to perform. This should be a number between `https://developer.android.com/reference/android/os/IBinder#FIRST_CALL_TRANSACTION` and `https://developer.android.com/reference/android/os/IBinder#LAST_CALL_TRANSACTION`. <br /> |
| `data` | `Parcel`: Marshalled data being received from the caller. This value cannot be `null`. <br /> |
| `reply` | `Parcel`: If the caller is expecting a result back, it should be marshalled in to here. This value may be `null`. <br /> |
| `flags` | `int`: Additional operation flags. Either 0 for a normal RPC, or `https://developer.android.com/reference/android/os/IBinder#FLAG_ONEWAY` for a one-way RPC. <br /> |

| Returns ||
|---|---|
| `boolean` | Return true on a successful call; returning false is generally used to indicate that you did not understand the transaction code. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException` |   |