# MediaCas.Session

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

# Session

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/media/MediaCas.Session "View this page in Java")  

```
class Session : AutoCloseable
```

|---|------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                   ||
| ↳ | [android.media.MediaCas.Session](https://developer.android.com/reference/kotlin/android/media/MediaCas.Session#) |

Class for an open session with the CA system.

## Summary

|                                                                                                                                                                                                                                                                                              Public methods                                                                                                                                                                                                                                                                                              ||
|-----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)            | [close](https://developer.android.com/reference/kotlin/android/media/MediaCas.Session#close())`()` Close the session.                                                                                                                                                                                                                                                                                                                                                                                           |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)      | [equals](https://developer.android.com/reference/kotlin/android/media/MediaCas.Session#equals(kotlin.Any))`(`other:` `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)?`)` Query if an object equal current Session object.                                                                                                                                                                                                                                                           |
| [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html) | [getSessionId](https://developer.android.com/reference/kotlin/android/media/MediaCas.Session#getSessionId())`()` Get Session Id.                                                                                                                                                                                                                                                                                                                                                                                |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)            | [processEcm](https://developer.android.com/reference/kotlin/android/media/MediaCas.Session#processEcm(kotlin.ByteArray))`(`data:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)`)` Send a received ECM packet to the specified session of the CA system.                                                                                                                                                                                                             |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)            | [processEcm](https://developer.android.com/reference/kotlin/android/media/MediaCas.Session#processEcm(kotlin.ByteArray,%20kotlin.Int,%20kotlin.Int))`(`data:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)`, `offset:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `length:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Send a received ECM packet to the specified session of the CA system. |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)            | [sendSessionEvent](https://developer.android.com/reference/kotlin/android/media/MediaCas.Session#sendSessionEvent(kotlin.Int,%20kotlin.Int,%20kotlin.ByteArray))`(`event:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `arg:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `data:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)?`)` Send a session event to a CA system.                         |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)            | [setPrivateData](https://developer.android.com/reference/kotlin/android/media/MediaCas.Session#setPrivateData(kotlin.ByteArray))`(`data:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)`)` Set the private data for a session.                                                                                                                                                                                                                                       |

## Public methods

### close

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

```
fun close(): Unit
```

Close the session.

|                                   Exceptions                                   ||
|----------------------------------------|----------------------------------------|
| `java.lang.Exception`                  | if this resource cannot be closed      |
| `java.lang.IllegalStateException`      | if the MediaCas instance is not valid. |
| `android.media.MediaCasStateException` | for CAS-specific state exceptions.     |

### equals

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

```
fun equals(other: Any?): Boolean
```

Query if an object equal current Session object.

|                       Parameters                       ||
|-------|-------------------------------------------------|
| `obj` | an object to compare to current Session object. |

|                                                                 Return                                                                 ||
|------------------------------------------------------------------------------------|----------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | Whether input object equal current Session object. |

### getSessionId

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

```
fun getSessionId(): ByteArray
```

Get Session Id.

|                                                                     Return                                                                      ||
|-----------------------------------------------------------------------------------------|--------------------------------------------------------|
| [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html) | session Id of the session. This value cannot be`null`. |

|                                Exceptions                                 ||
|-----------------------------------|----------------------------------------|
| `java.lang.IllegalStateException` | if the MediaCas instance is not valid. |

### processEcm

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

```
fun processEcm(data: ByteArray): Unit
```

Send a received ECM packet to the specified session of the CA system. This is similar to[Session.processEcm(byte[], int, int)](https://developer.android.com/reference/kotlin/android/media/MediaCas.Session#processEcm(kotlin.ByteArray,%20kotlin.Int,%20kotlin.Int))except that the entire byte array is sent.

|                                                                       Parameters                                                                        ||
|--------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| `data` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html):byte array of the ECM data. This value cannot be`null`. |

|                                   Exceptions                                   ||
|----------------------------------------|----------------------------------------|
| `java.lang.IllegalStateException`      | if the MediaCas instance is not valid. |
| `android.media.MediaCasException`      | for CAS-specific errors.               |
| `android.media.MediaCasStateException` | for CAS-specific state exceptions.     |

### processEcm

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

```
fun processEcm(
    data: ByteArray, 
    offset: Int, 
    length: Int
): Unit
```

Send a received ECM packet to the specified session of the CA system.

|                                                                        Parameters                                                                         ||
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| `data`   | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html):byte array of the ECM data. This value cannot be`null`. |
| `offset` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):position within data where the ECM data begins.                      |
| `length` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):length of the data (starting from offset).                           |

|                                   Exceptions                                   ||
|----------------------------------------|----------------------------------------|
| `java.lang.IllegalStateException`      | if the MediaCas instance is not valid. |
| `android.media.MediaCasException`      | for CAS-specific errors.               |
| `android.media.MediaCasStateException` | for CAS-specific state exceptions.     |

### sendSessionEvent

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

```
fun sendSessionEvent(
    event: Int, 
    arg: Int, 
    data: ByteArray?
): Unit
```

Send a session event to a CA system. The format of the event is scheme-specific and is opaque to the framework.

|                                                                                       Parameters                                                                                       ||
|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `event` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):an integer denoting a scheme-specific event to be sent.                                            |
| `arg`   | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):a scheme-specific integer argument for the event.                                                  |
| `data`  | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)?:a byte array containing scheme-specific data for the event. This value may be`null`. |

|                                   Exceptions                                   ||
|----------------------------------------|----------------------------------------|
| `java.lang.IllegalStateException`      | if the MediaCas instance is not valid. |
| `android.media.MediaCasException`      | for CAS-specific errors.               |
| `android.media.MediaCasStateException` | for CAS-specific state exceptions.     |

### setPrivateData

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

```
fun setPrivateData(data: ByteArray): Unit
```

Set the private data for a session.

|                                                                         Parameters                                                                          ||
|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
| `data` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html):byte array of the private data. This value cannot be`null`. |

|                                   Exceptions                                   ||
|----------------------------------------|----------------------------------------|
| `java.lang.IllegalStateException`      | if the MediaCas instance is not valid. |
| `android.media.MediaCasException`      | for CAS-specific errors.               |
| `android.media.MediaCasStateException` | for CAS-specific state exceptions.     |