Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/media/MediaCas#nestedclasses) \| [Constants](https://developer.android.com/reference/android/media/MediaCas#constants) \| [Ctors](https://developer.android.com/reference/android/media/MediaCas#pubctors) \| [Methods](https://developer.android.com/reference/android/media/MediaCas#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/media/MediaCas#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/media/MediaCas#inhmethods)

# MediaCas

*** ** * ** ***

` public final class MediaCas `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/java/lang/AutoCloseable `

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

<br />

*** ** * ** ***

MediaCas can be used to obtain keys for descrambling protected media streams, in conjunction with `https://developer.android.com/reference/android/media/MediaDescrambler`. The MediaCas APIs are designed to support conditional access such as those in the ISO/IEC13818-1. The CA system is identified by a 16-bit integer CA_system_id. The scrambling algorithms are usually proprietary and implemented by vendor-specific CA plugins installed on the device.

The app is responsible for constructing a MediaCas object for the CA system it intends to use. The app can query if a certain CA system is supported using static method `https://developer.android.com/reference/android/media/MediaCas#isSystemIdSupported(int)`. It can also obtain the entire list of supported CA systems using static method `https://developer.android.com/reference/android/media/MediaCas#enumeratePlugins()`.

Once the MediaCas object is constructed, the app should properly provision it by using method `https://developer.android.com/reference/android/media/MediaCas#provision(java.lang.String)` and/or `https://developer.android.com/reference/android/media/MediaCas#processEmm(byte[])`. The EMMs (Entitlement management messages) can be distributed out-of-band, or in-band with the stream.

To descramble elementary streams, the app first calls `https://developer.android.com/reference/android/media/MediaCas#openSession()` to generate a `https://developer.android.com/reference/android/media/MediaCas.Session` object that will uniquely identify a session. A session provides a context for subsequent key updates and descrambling activities. The ECMs (Entitlement control messages) are sent to the session via method `https://developer.android.com/reference/android/media/MediaCas.Session#processEcm(byte[])`.

The app next constructs a MediaDescrambler object, and initializes it with the session using `https://developer.android.com/reference/android/media/MediaDescrambler#setMediaCasSession(android.media.MediaCas.Session)`. This ties the descrambler to the session, and the descrambler can then be used to descramble content secured with the session's key, either during extraction, or during decoding with `https://developer.android.com/reference/android/media/MediaCodec`.

If the app handles sample extraction using its own extractor, it can use MediaDescrambler to descramble samples into clear buffers (if the session's license doesn't require secure decoders), or descramble a small amount of data to retrieve information necessary for the downstream pipeline to process the sample (if the session's license requires secure decoders).

If the session requires a secure decoder, a MediaDescrambler needs to be provided to MediaCodec to descramble samples queued by `https://developer.android.com/reference/android/media/MediaCodec#queueSecureInputBuffer(int,%20int,%20android.media.MediaCodec.CryptoInfo,%20long,%20int)` into protected buffers. The app should use `https://developer.android.com/reference/android/media/MediaCodec#configure(android.media.MediaFormat,%20android.view.Surface,%20int,%20android.media.MediaDescrambler)` instead of the normal `https://developer.android.com/reference/android/media/MediaCodec#configure(android.media.MediaFormat,%20android.view.Surface,%20android.media.MediaCrypto,%20int)` method to configure MediaCodec.

<br />

### Using Android's MediaExtractor

If the app uses `https://developer.android.com/reference/android/media/MediaExtractor`, it can delegate the CAS session management to MediaExtractor by calling `https://developer.android.com/reference/android/media/MediaExtractor#setMediaCas(android.media.MediaCas)`. MediaExtractor will take over and call `https://developer.android.com/reference/android/media/MediaCas#openSession()`, `https://developer.android.com/reference/android/media/MediaCas#processEmm(byte[])` and/or `https://developer.android.com/reference/android/media/MediaCas.Session#processEcm(byte[])`, etc.. if necessary.

When using `https://developer.android.com/reference/android/media/MediaExtractor`, the app would still need a MediaDescrambler to use with `https://developer.android.com/reference/android/media/MediaCodec` if the licensing requires a secure decoder. The session associated with the descrambler of a track can be retrieved by calling `https://developer.android.com/reference/android/media/MediaExtractor#getCasInfo(int)`, and used to initialize a MediaDescrambler object for MediaCodec.

<br />

### Listeners

The app may register a listener to receive events from the CA system using method `https://developer.android.com/reference/android/media/MediaCas#setEventListener(android.media.MediaCas.EventListener,%20android.os.Handler)`. The exact format of the event is scheme-specific and is not specified by this API.

## Summary

| ### Nested classes ||
|---|---|
| ` interface` | `https://developer.android.com/reference/android/media/MediaCas.EventListener` An interface registered by the caller to `https://developer.android.com/reference/android/media/MediaCas#setEventListener(android.media.MediaCas.EventListener,%20android.os.Handler)` to receives scheme-specific notifications from a MediaCas instance. |
| ` class` | `https://developer.android.com/reference/android/media/MediaCas.PluginDescriptor` Describe a CAS plugin with its CA_system_ID and string name. |
| ` class` | `https://developer.android.com/reference/android/media/MediaCas.Session` Class for an open session with the CA system. |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/media/MediaCas#PLUGIN_STATUS_PHYSICAL_MODULE_CHANGED` The event to indicate that the status of CAS system is changed by the removal or insertion of physical CAS modules. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#PLUGIN_STATUS_SESSION_NUMBER_CHANGED` The event to indicate that the number of CAS system's session is changed. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_AES128` Advanced Encryption System (AES) 128-bit Encryption mode. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_AES_CBC` Advanced Encryption System (AES) Cipher Block Chaining (CBC) mode. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_AES_ECB` Advanced Encryption System (AES) Electronic Code Book (ECB) mode. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_AES_SCTE52` Advanced Encryption System (AES) Society of Cable Telecommunications Engineers (SCTE) 52 mode. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_DVB_CISSA_V1` DVB Common IPTV Software-oriented Scrambling Algorithm (CISSA) Version 1. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_DVB_CSA1` DVB (Digital Video Broadcasting) Common Scrambling Algorithm (CSA) 1. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_DVB_CSA2` DVB CSA 2. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_DVB_CSA3_ENHANCE` DVB CSA 3 in fully enhanced mode. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_DVB_CSA3_MINIMAL` DVB CSA 3 in minimally enhanced mode. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_DVB_CSA3_STANDARD` DVB CSA 3 in standard mode. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_DVB_IDSA` ATIS-0800006 IIF Default Scrambling Algorithm (IDSA). |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_MULTI2` A symmetric key algorithm. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_RESERVED` DVB (Digital Video Broadcasting) reserved mode. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_TDES_ECB` Triple Data Encryption Algorithm (TDES) Electronic Code Book (ECB) mode. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_TDES_SCTE52` Triple Data Encryption Algorithm (TDES) Society of Cable Telecommunications Engineers (SCTE) 52 mode. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SESSION_USAGE_LIVE` Cas session is used to descramble live streams. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SESSION_USAGE_PLAYBACK` Cas session is used to descramble recoreded streams. |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SESSION_USAGE_RECORD` Cas session is used to descramble live streams and encrypt local recorded content |
| `int` | `https://developer.android.com/reference/android/media/MediaCas#SESSION_USAGE_TIMESHIFT` Cas session is used to descramble live streams , encrypt local recorded content and playback local encrypted content. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/media/MediaCas#MediaCas(android.content.Context,%20int,%20java.lang.String,%20int)(https://developer.android.com/reference/android/content/Context context, int casSystemId, https://developer.android.com/reference/java/lang/String tvInputServiceSessionId, int priorityHint) ` Instantiate a CA system of the specified system id. |
| ` https://developer.android.com/reference/android/media/MediaCas#MediaCas(android.content.Context,%20int,%20java.lang.String,%20int,%20android.os.Handler,%20android.media.MediaCas.EventListener)(https://developer.android.com/reference/android/content/Context context, int casSystemId, https://developer.android.com/reference/java/lang/String tvInputServiceSessionId, int priorityHint, https://developer.android.com/reference/android/os/Handler handler, https://developer.android.com/reference/android/media/MediaCas.EventListener listener) ` Instantiate a CA system of the specified system id with EvenListener. |
| ` https://developer.android.com/reference/android/media/MediaCas#MediaCas(int)(int casSystemId) ` Instantiate a CA system of the specified system id. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/media/MediaCas#close()() ` Closes this resource, relinquishing any underlying resources. |
| ` static https://developer.android.com/reference/android/media/MediaCas.PluginDescriptor` | ` https://developer.android.com/reference/android/media/MediaCas#enumeratePlugins()() ` List all available CA plugins on the device. |
| ` static boolean` | ` https://developer.android.com/reference/android/media/MediaCas#isSystemIdSupported(int)(int CA_system_id) ` Query if a certain CA system is supported on this device. |
| ` https://developer.android.com/reference/android/media/MediaCas.Session` | ` https://developer.android.com/reference/android/media/MediaCas#openSession(int,%20int)(int sessionUsage, int scramblingMode) ` Open a session with usage and scrambling information, so that descrambler can be configured to descramble one or more streams scrambled by the conditional access system. |
| ` https://developer.android.com/reference/android/media/MediaCas.Session` | ` https://developer.android.com/reference/android/media/MediaCas#openSession()() ` Open a session to descramble one or more streams scrambled by the conditional access system. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaCas#processEmm(byte[])(byte[] data) ` Send a received EMM packet to the CA system. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaCas#processEmm(byte[],%20int,%20int)(byte[] data, int offset, int length) ` Send a received EMM packet to the CA system. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaCas#provision(java.lang.String)(https://developer.android.com/reference/java/lang/String provisionString) ` Initiate a provisioning operation for a CA system. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaCas#refreshEntitlements(int,%20byte[])(int refreshType, byte[] refreshData) ` Notify the CA system to refresh entitlement keys. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaCas#sendEvent(int,%20int,%20byte[])(int event, int arg, byte[] data) ` Send an event to a CA system. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaCas#setEventListener(android.media.MediaCas.EventListener,%20android.os.Handler)(https://developer.android.com/reference/android/media/MediaCas.EventListener listener, https://developer.android.com/reference/android/os/Handler handler) ` Set an event listener to receive notifications from the MediaCas instance. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaCas#setPrivateData(byte[])(byte[] data) ` Send the private data for the CA system. |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/media/MediaCas#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |

### 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/java/lang/AutoCloseable ` ` abstract void` ` https://developer.android.com/reference/java/lang/AutoCloseable#close()() `

Closes this resource, relinquishing any underlying resources.

## Constants

### PLUGIN_STATUS_PHYSICAL_MODULE_CHANGED

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

```
public static final int PLUGIN_STATUS_PHYSICAL_MODULE_CHANGED
```

The event to indicate that the status of CAS system is changed by the removal or insertion of physical CAS modules.

<br />

Constant Value: 0 (0x00000000)

### PLUGIN_STATUS_SESSION_NUMBER_CHANGED

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

```
public static final int PLUGIN_STATUS_SESSION_NUMBER_CHANGED
```

The event to indicate that the number of CAS system's session is changed.

<br />

Constant Value: 1 (0x00000001)

### SCRAMBLING_MODE_AES128

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

```
public static final int SCRAMBLING_MODE_AES128
```

Advanced Encryption System (AES) 128-bit Encryption mode.

<br />

Constant Value: 9 (0x00000009)

### SCRAMBLING_MODE_AES_CBC

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

```
public static final int SCRAMBLING_MODE_AES_CBC
```

Advanced Encryption System (AES) Cipher Block Chaining (CBC) mode.

<br />

Constant Value: 14 (0x0000000e)

### SCRAMBLING_MODE_AES_ECB

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

```
public static final int SCRAMBLING_MODE_AES_ECB
```

Advanced Encryption System (AES) Electronic Code Book (ECB) mode.

<br />

Constant Value: 10 (0x0000000a)

### SCRAMBLING_MODE_AES_SCTE52

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

```
public static final int SCRAMBLING_MODE_AES_SCTE52
```

Advanced Encryption System (AES) Society of Cable Telecommunications Engineers (SCTE) 52 mode.

<br />

Constant Value: 11 (0x0000000b)

### SCRAMBLING_MODE_DVB_CISSA_V1

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

```
public static final int SCRAMBLING_MODE_DVB_CISSA_V1
```

DVB Common IPTV Software-oriented Scrambling Algorithm (CISSA) Version 1.

<br />

Constant Value: 6 (0x00000006)

### SCRAMBLING_MODE_DVB_CSA1

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

```
public static final int SCRAMBLING_MODE_DVB_CSA1
```

DVB (Digital Video Broadcasting) Common Scrambling Algorithm (CSA) 1.

<br />

Constant Value: 1 (0x00000001)

### SCRAMBLING_MODE_DVB_CSA2

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

```
public static final int SCRAMBLING_MODE_DVB_CSA2
```

DVB CSA 2.

<br />

Constant Value: 2 (0x00000002)

### SCRAMBLING_MODE_DVB_CSA3_ENHANCE

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

```
public static final int SCRAMBLING_MODE_DVB_CSA3_ENHANCE
```

DVB CSA 3 in fully enhanced mode.

<br />

Constant Value: 5 (0x00000005)

### SCRAMBLING_MODE_DVB_CSA3_MINIMAL

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

```
public static final int SCRAMBLING_MODE_DVB_CSA3_MINIMAL
```

DVB CSA 3 in minimally enhanced mode.

<br />

Constant Value: 4 (0x00000004)

### SCRAMBLING_MODE_DVB_CSA3_STANDARD

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

```
public static final int SCRAMBLING_MODE_DVB_CSA3_STANDARD
```

DVB CSA 3 in standard mode.

<br />

Constant Value: 3 (0x00000003)

### SCRAMBLING_MODE_DVB_IDSA

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

```
public static final int SCRAMBLING_MODE_DVB_IDSA
```

ATIS-0800006 IIF Default Scrambling Algorithm (IDSA).

<br />

Constant Value: 7 (0x00000007)

### SCRAMBLING_MODE_MULTI2

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

```
public static final int SCRAMBLING_MODE_MULTI2
```

A symmetric key algorithm.

<br />

Constant Value: 8 (0x00000008)

### SCRAMBLING_MODE_RESERVED

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

```
public static final int SCRAMBLING_MODE_RESERVED
```

DVB (Digital Video Broadcasting) reserved mode.

<br />

Constant Value: 0 (0x00000000)

### SCRAMBLING_MODE_TDES_ECB

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

```
public static final int SCRAMBLING_MODE_TDES_ECB
```

Triple Data Encryption Algorithm (TDES) Electronic Code Book (ECB) mode.

<br />

Constant Value: 12 (0x0000000c)

### SCRAMBLING_MODE_TDES_SCTE52

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

```
public static final int SCRAMBLING_MODE_TDES_SCTE52
```

Triple Data Encryption Algorithm (TDES) Society of Cable Telecommunications Engineers (SCTE) 52 mode.

<br />

Constant Value: 13 (0x0000000d)

### SESSION_USAGE_LIVE

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

```
public static final int SESSION_USAGE_LIVE
```

Cas session is used to descramble live streams.

<br />

Constant Value: 0 (0x00000000)

### SESSION_USAGE_PLAYBACK

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

```
public static final int SESSION_USAGE_PLAYBACK
```

Cas session is used to descramble recoreded streams.

<br />

Constant Value: 1 (0x00000001)

### SESSION_USAGE_RECORD

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

```
public static final int SESSION_USAGE_RECORD
```

Cas session is used to descramble live streams and encrypt local recorded content

<br />

Constant Value: 2 (0x00000002)

### SESSION_USAGE_TIMESHIFT

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

```
public static final int SESSION_USAGE_TIMESHIFT
```

Cas session is used to descramble live streams , encrypt local recorded content and playback local encrypted content.

<br />

Constant Value: 3 (0x00000003)

## Public constructors

### MediaCas

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

```
public MediaCas (Context context, 
                int casSystemId, 
                String tvInputServiceSessionId, 
                int priorityHint)
```

Instantiate a CA system of the specified system id.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: the context of the caller. This value cannot be `null`. <br /> |
| `casSystemId` | `int`: The system id of the CA system. <br /> |
| `tvInputServiceSessionId` | `String`: The Id of the session opened in TV Input Service (TIS) `https://developer.android.com/reference/android/media/tv/TvInputService#onCreateSession(java.lang.String,%20java.lang.String)` This value may be `null`. <br /> |
| `priorityHint` | `int`: priority hint from the use case type for new created CAS system. Value is one of the following: - `https://developer.android.com/reference/android/media/tv/TvInputService#PRIORITY_HINT_USE_CASE_TYPE_BACKGROUND` - `https://developer.android.com/reference/android/media/tv/TvInputService#PRIORITY_HINT_USE_CASE_TYPE_SCAN` - `https://developer.android.com/reference/android/media/tv/TvInputService#PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK` - `https://developer.android.com/reference/android/media/tv/TvInputService#PRIORITY_HINT_USE_CASE_TYPE_LIVE` - `https://developer.android.com/reference/android/media/tv/TvInputService#PRIORITY_HINT_USE_CASE_TYPE_RECORD` |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/media/MediaCasException.UnsupportedCasException` | if the device does not support the specified CA system. |

### MediaCas

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

```
public MediaCas (Context context, 
                int casSystemId, 
                String tvInputServiceSessionId, 
                int priorityHint, 
                Handler handler, 
                MediaCas.EventListener listener)
```

Instantiate a CA system of the specified system id with EvenListener.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: the context of the caller. This value cannot be `null`. <br /> |
| `casSystemId` | `int`: The system id of the CA system. <br /> |
| `tvInputServiceSessionId` | `String`: The Id of the session opened in TV Input Service (TIS) `https://developer.android.com/reference/android/media/tv/TvInputService#onCreateSession(java.lang.String,%20java.lang.String)` This value may be `null`. <br /> |
| `priorityHint` | `int`: priority hint from the use case type for new created CAS system. Value is one of the following: - `https://developer.android.com/reference/android/media/tv/TvInputService#PRIORITY_HINT_USE_CASE_TYPE_BACKGROUND` - `https://developer.android.com/reference/android/media/tv/TvInputService#PRIORITY_HINT_USE_CASE_TYPE_SCAN` - `https://developer.android.com/reference/android/media/tv/TvInputService#PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK` - `https://developer.android.com/reference/android/media/tv/TvInputService#PRIORITY_HINT_USE_CASE_TYPE_LIVE` - `https://developer.android.com/reference/android/media/tv/TvInputService#PRIORITY_HINT_USE_CASE_TYPE_RECORD` |
| `handler` | `Handler`: the handler whose looper the event listener will be called on. If handler is null, we'll try to use current thread's looper, or the main looper. If neither are available, an internal thread will be created instead. <br /> |
| `listener` | `MediaCas.EventListener`: the event listener to be set. This value may be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/media/MediaCasException.UnsupportedCasException` | if the device does not support the specified CA system. |

### MediaCas

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

```
public MediaCas (int casSystemId)
```

Instantiate a CA system of the specified system id.

<br />

| Parameters ||
|---|---|
| `casSystemId` | `int`: The system id of the CA system. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/media/MediaCasException.UnsupportedCasException` | if the device does not support the specified CA system. |

## Public methods

### close

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

```
public void close ()
```

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the `try`-with-resources statement.

<br />

### enumeratePlugins

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

```
public static PluginDescriptor[] enumeratePlugins ()
```

List all available CA plugins on the device.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/media/MediaCas.PluginDescriptor` | an array of descriptors for the available CA plugins. <br /> |

### isSystemIdSupported

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

```
public static boolean isSystemIdSupported (int CA_system_id)
```

Query if a certain CA system is supported on this device.

<br />

| Parameters ||
|---|---|
| `CA_system_id` | `int`: the id of the CA system. <br /> |

| Returns ||
|---|---|
| `boolean` | Whether the specified CA system is supported on this device. <br /> |

### openSession

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

```
public MediaCas.Session openSession (int sessionUsage, 
                int scramblingMode)
```

Open a session with usage and scrambling information, so that descrambler can be configured to descramble one or more streams scrambled by the conditional access system.

Tuner resource manager (TRM) uses the client priority value to decide whether it is able to get cas session resource if cas session resources is limited. If the client can't get the resource, this call returns `https://developer.android.com/reference/android/media/MediaCasException.InsufficientResourceException`.

<br />

| Parameters ||
|---|---|
| `sessionUsage` | `int`: used for the created session. Value is one of the following: - `https://developer.android.com/reference/android/media/MediaCas#SESSION_USAGE_LIVE` - `https://developer.android.com/reference/android/media/MediaCas#SESSION_USAGE_PLAYBACK` - `https://developer.android.com/reference/android/media/MediaCas#SESSION_USAGE_RECORD` - `https://developer.android.com/reference/android/media/MediaCas#SESSION_USAGE_TIMESHIFT` |
| `scramblingMode` | `int`: used for the created session. Value is one of the following: - `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_RESERVED` - `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_DVB_CSA1` - `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_DVB_CSA2` - `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_DVB_CSA3_STANDARD` - `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_DVB_CSA3_MINIMAL` - `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_DVB_CSA3_ENHANCE` - `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_DVB_CISSA_V1` - `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_DVB_IDSA` - `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_MULTI2` - `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_AES128` - `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_AES_CBC` - `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_AES_ECB` - `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_AES_SCTE52` - `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_TDES_ECB` - `https://developer.android.com/reference/android/media/MediaCas#SCRAMBLING_MODE_TDES_SCTE52` |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/media/MediaCas.Session` | session the newly opened session. This value may be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/media/MediaCasException` | for CAS-specific errors. |
| `https://developer.android.com/reference/android/media/MediaCasStateException` | for CAS-specific state exceptions. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the MediaCas instance is not valid. |

### openSession

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

```
public MediaCas.Session openSession ()
```

Open a session to descramble one or more streams scrambled by the conditional access system.

Tuner resource manager (TRM) uses the client priority value to decide whether it is able to get cas session resource if cas session resources is limited. If the client can't get the resource, this call returns `https://developer.android.com/reference/android/media/MediaCasException.InsufficientResourceException`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/media/MediaCas.Session` | session the newly opened session. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/media/MediaCasException` | for CAS-specific errors. |
| `https://developer.android.com/reference/android/media/MediaCasStateException` | for CAS-specific state exceptions. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the MediaCas instance is not valid. |

### processEmm

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

```
public void processEmm (byte[] data)
```

Send a received EMM packet to the CA system. This is similar to `https://developer.android.com/reference/android/media/MediaCas#processEmm(byte[],%20int,%20int)` except that the entire byte array is sent.

<br />

| Parameters ||
|---|---|
| `data` | `byte`: byte array of the EMM data. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/media/MediaCasException` | for CAS-specific errors. |
| `https://developer.android.com/reference/android/media/MediaCasStateException` | for CAS-specific state exceptions. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the MediaCas instance is not valid. |

### processEmm

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

```
public void processEmm (byte[] data, 
                int offset, 
                int length)
```

Send a received EMM packet to the CA system.

<br />

| Parameters ||
|---|---|
| `data` | `byte`: byte array of the EMM data. This value cannot be `null`. <br /> |
| `offset` | `int`: position within data where the EMM data begins. <br /> |
| `length` | `int`: length of the data (starting from offset). <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/media/MediaCasException` | for CAS-specific errors. |
| `https://developer.android.com/reference/android/media/MediaCasStateException` | for CAS-specific state exceptions. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the MediaCas instance is not valid. |

### provision

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

```
public void provision (String provisionString)
```

Initiate a provisioning operation for a CA system.

<br />

| Parameters ||
|---|---|
| `provisionString` | `String`: string containing information needed for the provisioning operation, the format of which is scheme and implementation specific. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/media/MediaCasException` | for CAS-specific errors. |
| `https://developer.android.com/reference/android/media/MediaCasStateException` | for CAS-specific state exceptions. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the MediaCas instance is not valid. |

### refreshEntitlements

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

```
public void refreshEntitlements (int refreshType, 
                byte[] refreshData)
```

Notify the CA system to refresh entitlement keys.

<br />

| Parameters ||
|---|---|
| `refreshType` | `int`: the type of the refreshment. <br /> |
| `refreshData` | `byte`: private data associated with the refreshment. This value may be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/media/MediaCasException` | for CAS-specific errors. |
| `https://developer.android.com/reference/android/media/MediaCasStateException` | for CAS-specific state exceptions. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the MediaCas instance is not valid. |

### sendEvent

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

```
public void sendEvent (int event, 
                int arg, 
                byte[] data)
```

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

<br />

| Parameters ||
|---|---|
| `event` | `int`: an integer denoting a scheme-specific event to be sent. <br /> |
| `arg` | `int`: a scheme-specific integer argument for the event. <br /> |
| `data` | `byte`: a byte array containing scheme-specific data for the event. This value may be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/media/MediaCasException` | for CAS-specific errors. |
| `https://developer.android.com/reference/android/media/MediaCasStateException` | for CAS-specific state exceptions. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the MediaCas instance is not valid. |

### setEventListener

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

```
public void setEventListener (MediaCas.EventListener listener, 
                Handler handler)
```

Set an event listener to receive notifications from the MediaCas instance.

<br />

| Parameters ||
|---|---|
| `listener` | `MediaCas.EventListener`: the event listener to be set. This value may be `null`. <br /> |
| `handler` | `Handler`: the handler whose looper the event listener will be called on. If handler is null, we'll try to use current thread's looper, or the main looper. If neither are available, an internal thread will be created instead. <br /> |

### setPrivateData

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

```
public void setPrivateData (byte[] data)
```

Send the private data for the CA system.

<br />

| Parameters ||
|---|---|
| `data` | `byte`: byte array of the private data. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/media/MediaCasException` | for CAS-specific errors. |
| `https://developer.android.com/reference/android/media/MediaCasStateException` | for CAS-specific state exceptions. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the MediaCas instance is not valid. |

## Protected methods

### finalize

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

```
protected void finalize ()
```

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the `finalize` method to dispose of system resources or to perform other cleanup.

The general contract of `finalize` is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The `finalize` method may take any action, including making this object available again to other threads; the usual purpose of `finalize`, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The `finalize` method of class `Object` performs no special action; it simply returns normally. Subclasses of `Object` may override this definition.

The Java programming language does not guarantee which thread will invoke the `finalize` method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the `finalize` method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The `finalize` method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the `finalize` method causes the finalization of this object to be halted, but is otherwise ignored.

<br />