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

# IkeSessionCallback

*** ** * ** ***

` public interface IkeSessionCallback `   
` `

|---|
| android.net.ipsec.ike.IkeSessionCallback |

<br />

*** ** * ** ***

Callback interface for receiving state changes of an `https://developer.android.com/reference/android/net/ipsec/ike/IkeSession`.

`https://developer.android.com/reference/android/net/ipsec/ike/IkeSessionCallback` MUST be unique to each `https://developer.android.com/reference/android/net/ipsec/ike/IkeSession`. It is registered when callers are requesting a new `https://developer.android.com/reference/android/net/ipsec/ike/IkeSession`. It is automatically unregistered when an `https://developer.android.com/reference/android/net/ipsec/ike/IkeSession` is closed.
**See also:**

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

## Summary

| ### Public methods ||
|---|---|
| ` abstract void` | ` https://developer.android.com/reference/android/net/ipsec/ike/IkeSessionCallback#onClosed()() ` Called when the `https://developer.android.com/reference/android/net/ipsec/ike/IkeSession` is closed. |
| ` default void` | ` https://developer.android.com/reference/android/net/ipsec/ike/IkeSessionCallback#onClosedWithException(android.net.ipsec.ike.exceptions.IkeException)(https://developer.android.com/reference/android/net/ipsec/ike/exceptions/IkeException exception) ` Called if `https://developer.android.com/reference/android/net/ipsec/ike/IkeSession` setup failed or `https://developer.android.com/reference/android/net/ipsec/ike/IkeSession` is closed because of a fatal error. |
| ` default void` | ` https://developer.android.com/reference/android/net/ipsec/ike/IkeSessionCallback#onError(android.net.ipsec.ike.exceptions.IkeException)(https://developer.android.com/reference/android/net/ipsec/ike/exceptions/IkeException exception) ` Called if a recoverable error is encountered in an established `https://developer.android.com/reference/android/net/ipsec/ike/IkeSession`. |
| ` abstract void` | ` https://developer.android.com/reference/android/net/ipsec/ike/IkeSessionCallback#onOpened(android.net.ipsec.ike.IkeSessionConfiguration)(https://developer.android.com/reference/android/net/ipsec/ike/IkeSessionConfiguration sessionConfiguration) ` Called when the `https://developer.android.com/reference/android/net/ipsec/ike/IkeSession` 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 `https://developer.android.com/reference/android/net/ipsec/ike/IkeSession` is closed.

When the closure is caused by a local, fatal error, `https://developer.android.com/reference/android/net/ipsec/ike/IkeSessionCallback#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 `https://developer.android.com/reference/android/net/ipsec/ike/IkeSession` setup failed or `https://developer.android.com/reference/android/net/ipsec/ike/IkeSession` is closed because of a fatal error.

<br />

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

### onError

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

```
public void onError (IkeException exception)
```

Called if a recoverable error is encountered in an established `https://developer.android.com/reference/android/net/ipsec/ike/IkeSession`.

This method may be triggered by protocol errors such as an INVALID_IKE_SPI, or by non-protocol errors such as the underlying `https://developer.android.com/reference/android/net/Network` dying.

<br />

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

### onOpened

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

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

Called when the `https://developer.android.com/reference/android/net/ipsec/ike/IkeSession` setup succeeds.

This method does not indicate the first Child Session has been setup. Caller MUST refer to the corresponding `https://developer.android.com/reference/android/net/ipsec/ike/ChildSessionCallback` for the Child Session setup result.

<br />

| Parameters ||
|---|---|
| `sessionConfiguration` | `IkeSessionConfiguration`: the configuration information of `https://developer.android.com/reference/android/net/ipsec/ike/IkeSession` negotiated during IKE setup. This value cannot be `null`. <br /> |