# ChildSessionCallback

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

# ChildSessionCallback

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/net/ipsec/ike/ChildSessionCallback "View this page in Kotlin") \|Java


`
public


interface
ChildSessionCallback
`


`


`

|--------------------------------------------|
| android.net.ipsec.ike.ChildSessionCallback |

<br />

*** ** * ** ***

Callback interface for receiving state changes of a Child Session.

[ChildSessionCallback](https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionCallback) MUST be unique to each Child Session. It is registered when
callers are requesting a new Child Session. It is automatically unregistered when a Child Session
or the parent IKE Session is closed.

[ChildSessionCallback](https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionCallback)s are also used for identifying Child Sessions. It is required
when a caller wants to delete a specific Child Session.  
**See also:**

- [RFC 7296, Internet Key Exchange Protocol
  Version 2 (IKEv2)](https://tools.ietf.org/html/rfc7296)
- [RFC 4301, Security Architecture for the
  Internet Protocol (IKEv2)](https://tools.ietf.org/html/rfc4301)

## Summary

|                                                                                                                                                                                                                      ### Public methods                                                                                                                                                                                                                      ||
|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract void` | ` `[onClosed](https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionCallback#onClosed())`() ` Called when the Child Session is closed.                                                                                                                                                                                                                                                                                 |
| ` default void`  | ` `[onClosedWithException](https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionCallback#onClosedWithException(android.net.ipsec.ike.exceptions.IkeException))`(`[IkeException](https://developer.android.com/reference/android/net/ipsec/ike/exceptions/IkeException)` exception) ` Called if the Child Session setup failed or Child Session is closed because of a fatal error.                                    |
| ` abstract void` | ` `[onIpSecTransformCreated](https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionCallback#onIpSecTransformCreated(android.net.IpSecTransform,%20int))`(`[IpSecTransform](https://developer.android.com/reference/android/net/IpSecTransform)` ipSecTransform, int direction) ` Called when an [IpSecTransform](https://developer.android.com/reference/android/net/IpSecTransform) is created by this Child Session. |
| ` abstract void` | ` `[onIpSecTransformDeleted](https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionCallback#onIpSecTransformDeleted(android.net.IpSecTransform,%20int))`(`[IpSecTransform](https://developer.android.com/reference/android/net/IpSecTransform)` ipSecTransform, int direction) ` Called when an [IpSecTransform](https://developer.android.com/reference/android/net/IpSecTransform) is deleted by this Child Session. |
| ` abstract void` | ` `[onOpened](https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionCallback#onOpened(android.net.ipsec.ike.ChildSessionConfiguration))`(`[ChildSessionConfiguration](https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionConfiguration)` sessionConfiguration) ` Called when the Child Session setup succeeds.                                                                                  |

## Public methods

### onClosed

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

```
public abstract void onClosed ()
```

Called when the Child Session is closed.

This method will be called immediately after [onIpSecTransformDeleted(android.net.IpSecTransform, int)](https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionCallback#onIpSecTransformDeleted(android.net.IpSecTransform,%20int)) for the deleted IPsec SA pair is fired.

When the closure is caused by a local, fatal error, [onClosedWithException(android.net.ipsec.ike.exceptions.IkeException)](https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionCallback#onClosedWithException(android.net.ipsec.ike.exceptions.IkeException)) will be fired instead of this method.

<br />

### onClosedWithException

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

```
public void onClosedWithException (IkeException exception)
```

Called if the Child Session setup failed or Child Session is closed because of a fatal error.

This method will be called immediately after [onIpSecTransformDeleted(android.net.IpSecTransform, int)](https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionCallback#onIpSecTransformDeleted(android.net.IpSecTransform,%20int)) for the deleted IPsec SA pair is fired.

<br />

|                                            Parameters                                            ||
|-------------|-------------------------------------------------------------------------------------|
| `exception` | `IkeException`: the detailed error information. This value cannot be `null`. <br /> |

### onIpSecTransformCreated

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

```
public abstract void onIpSecTransformCreated (IpSecTransform ipSecTransform, 
                int direction)
```

Called when an [IpSecTransform](https://developer.android.com/reference/android/net/IpSecTransform) is created by this Child Session.

This method is fired when a Child Session is created or rekeyed.

The [IpSecTransform](https://developer.android.com/reference/android/net/IpSecTransform) must be applied to relevant sockets or interfaces when this
method is called; traffic may otherwise flow over the socket or interface unprotected.

As this method is fired on an executor, there is an inherent race condition during rekeys
where traffic may be routed through the old transforms while the remote has switched to using
the new set of transforms.

To avoid the initial startup race condition where the transforms have not yet been
applied, the [onOpened(android.net.ipsec.ike.ChildSessionConfiguration)](https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionCallback#onOpened(android.net.ipsec.ike.ChildSessionConfiguration)) callback should be used as the
authoritative signal that the socket or tunnel is ready, as it is fired after both transforms
have had a chance to be applied.

<br />

|                                                                                                                                                                                    Parameters                                                                                                                                                                                    ||
|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `ipSecTransform` | `IpSecTransform`: the created [IpSecTransform](https://developer.android.com/reference/android/net/IpSecTransform). This value cannot be `null`. <br />                                                                                                                                                                                                        |
| `direction`      | `int`: the direction of this [IpSecTransform](https://developer.android.com/reference/android/net/IpSecTransform). Value is [IpSecManager.DIRECTION_IN](https://developer.android.com/reference/android/net/IpSecManager#DIRECTION_IN), or [IpSecManager.DIRECTION_OUT](https://developer.android.com/reference/android/net/IpSecManager#DIRECTION_OUT) <br /> |

### onIpSecTransformDeleted

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

```
public abstract void onIpSecTransformDeleted (IpSecTransform ipSecTransform, 
                int direction)
```

Called when an [IpSecTransform](https://developer.android.com/reference/android/net/IpSecTransform) is deleted by this Child Session.

This method is fired when a Child Session is closed or a Child Session has deleted old
IPsec SA during rekey. When this method is fired due to Child Session closure, it will be
followed by [onClosed()](https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionCallback#onClosed()) or [onClosedWithException(android.net.ipsec.ike.exceptions.IkeException)](https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionCallback#onClosedWithException(android.net.ipsec.ike.exceptions.IkeException)).

Users SHOULD remove the [IpSecTransform](https://developer.android.com/reference/android/net/IpSecTransform) from the socket or interface when this
method is called. Otherwise the IPsec traffic protected by this [IpSecTransform](https://developer.android.com/reference/android/net/IpSecTransform) will
be discarded.

<br />

|                                                                                                                                                                                    Parameters                                                                                                                                                                                    ||
|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `ipSecTransform` | `IpSecTransform`: the deleted [IpSecTransform](https://developer.android.com/reference/android/net/IpSecTransform). This value cannot be `null`. <br />                                                                                                                                                                                                        |
| `direction`      | `int`: the direction of this [IpSecTransform](https://developer.android.com/reference/android/net/IpSecTransform). Value is [IpSecManager.DIRECTION_IN](https://developer.android.com/reference/android/net/IpSecManager#DIRECTION_IN), or [IpSecManager.DIRECTION_OUT](https://developer.android.com/reference/android/net/IpSecManager#DIRECTION_OUT) <br /> |

### onOpened

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

```
public abstract void onOpened (ChildSessionConfiguration sessionConfiguration)
```

Called when the Child Session setup succeeds.

This method will be called immediately after [onIpSecTransformCreated(android.net.IpSecTransform, int)](https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionCallback#onIpSecTransformCreated(android.net.IpSecTransform,%20int)) for the created IPsec SA pair is fired.

<br />

|                                                                                                                              Parameters                                                                                                                              ||
|------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `sessionConfiguration` | `ChildSessionConfiguration`: the [ChildSessionConfiguration](https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionConfiguration) of Child Session negotiated during Child creation. This value cannot be `null`. <br /> |