Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#pubctors) \| [Methods](https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#inhmethods)

# TvAdService.Session

*** ** * ** ***


`
public
static

abstract
class
TvAdService.Session
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


implements

https://developer.android.com/reference/android/view/KeyEvent.Callback


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.media.tv.ad.TvAdService.Session |

<br />

*** ** * ** ***

Base class for derived classes to implement to provide a TV AD session.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#Session(android.content.Context)(https://developer.android.com/reference/android/content/Context context) ` Creates a new Session. |

| ### Public methods ||
|---|---|
| ` boolean` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#isMediaViewEnabled()() ` Returns `true` if media view is enabled, `false` otherwise. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#layoutSurface(int,%20int,%20int,%20int)(int left, int top, int right, int bottom) ` Assigns a size and position to the surface passed in `https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onSetSurface(android.view.Surface)`. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#notifySessionStateChanged(int,%20int)(int state, int err) ` Notifies when the session state is changed. |
| ` https://developer.android.com/reference/android/view/View` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onCreateMediaView()() ` Called when the application requests to create a media view. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onCurrentChannelUri(android.net.Uri)(https://developer.android.com/reference/android/net/Uri channelUri) ` Receives current channel URI. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onCurrentTvInputId(java.lang.String)(https://developer.android.com/reference/java/lang/String inputId) ` Receives current TV input ID. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onCurrentVideoBounds(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect bounds) ` Receives current video bounds. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onError(java.lang.String,%20android.os.Bundle)(https://developer.android.com/reference/java/lang/String errMsg, https://developer.android.com/reference/android/os/Bundle params) ` Called when the application sends information of an error. |
| ` boolean` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onGenericMotionEvent(android.view.MotionEvent)(https://developer.android.com/reference/android/view/MotionEvent event) ` Implement this method to handle generic motion events on the current session. |
| ` boolean` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onKeyDown(int,%20android.view.KeyEvent)(int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) ` Called when a key down event has occurred. |
| ` boolean` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onKeyLongPress(int,%20android.view.KeyEvent)(int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) ` Called when a long press has occurred. |
| ` boolean` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onKeyMultiple(int,%20int,%20android.view.KeyEvent)(int keyCode, int count, https://developer.android.com/reference/android/view/KeyEvent event) ` Called when a user's interaction with an analog control, such as flinging a trackball, generates simulated down/up events for the same key multiple times in quick succession. |
| ` boolean` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onKeyUp(int,%20android.view.KeyEvent)(int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) ` Called when a key up event has occurred. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onMediaViewSizeChanged(int,%20int)(int width, int height) ` Called when the size of the media view is changed by the application. |
| ` abstract void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onRelease()() ` Releases TvAdService session. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onResetAdService()() ` Resets TvAdService session. |
| ` abstract boolean` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onSetSurface(android.view.Surface)(https://developer.android.com/reference/android/view/Surface surface) ` Called when the application sets the surface. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onSigningResult(java.lang.String,%20byte[])(https://developer.android.com/reference/java/lang/String signingId, byte[] result) ` Receives signing result. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onStartAdService()() ` Starts TvAdService session. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onStopAdService()() ` Stops TvAdService session. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onSurfaceChanged(int,%20int,%20int)(int format, int width, int height) ` Called after any structural changes (format or size) have been made to the surface passed in `https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onSetSurface(android.view.Surface)`. |
| ` boolean` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onTouchEvent(android.view.MotionEvent)(https://developer.android.com/reference/android/view/MotionEvent event) ` Implement this method to handle touch screen motion events on the current session. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onTrackInfoList(java.util.List<android.media.tv.TvTrackInfo>)(https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/media/tv/TvTrackInfo> tracks) ` Receives track list. |
| ` boolean` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onTrackballEvent(android.view.MotionEvent)(https://developer.android.com/reference/android/view/MotionEvent event) ` Implement this method to handle trackball events on the current session. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onTvInputSessionData(java.lang.String,%20android.os.Bundle)(https://developer.android.com/reference/java/lang/String type, https://developer.android.com/reference/android/os/Bundle data) ` Called when data from the linked `https://developer.android.com/reference/android/media/tv/TvInputService` is received. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onTvMessage(int,%20android.os.Bundle)(int type, https://developer.android.com/reference/android/os/Bundle data) ` Called when a TV message is received |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#requestCurrentChannelUri()() ` Requests the URI of the current channel. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#requestCurrentTvInputId()() ` Requests current TV input ID. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#requestCurrentVideoBounds()() ` Requests the bounds of the current video. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#requestSigning(java.lang.String,%20java.lang.String,%20java.lang.String,%20byte[])(https://developer.android.com/reference/java/lang/String signingId, https://developer.android.com/reference/java/lang/String algorithm, https://developer.android.com/reference/java/lang/String alias, byte[] data) ` Requests signing of the given data. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#requestTrackInfoList()() ` Requests the list of `https://developer.android.com/reference/android/media/tv/TvTrackInfo`. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#sendTvAdSessionData(java.lang.String,%20android.os.Bundle)(https://developer.android.com/reference/java/lang/String type, https://developer.android.com/reference/android/os/Bundle data) ` Sends data related to this session to corresponding linked `https://developer.android.com/reference/android/media/tv/TvInputService` object via TvView. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#setMediaViewEnabled(boolean)(boolean enable) ` Enables or disables the media view. |

| ### 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/view/KeyEvent.Callback ` |---|---| | ` abstract boolean` | ` https://developer.android.com/reference/android/view/KeyEvent.Callback#onKeyDown(int,%20android.view.KeyEvent)(int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) ` Called when a key down event has occurred. | | ` abstract boolean` | ` https://developer.android.com/reference/android/view/KeyEvent.Callback#onKeyLongPress(int,%20android.view.KeyEvent)(int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) ` Called when a long press has occurred. | | ` abstract boolean` | ` https://developer.android.com/reference/android/view/KeyEvent.Callback#onKeyMultiple(int,%20int,%20android.view.KeyEvent)(int keyCode, int count, https://developer.android.com/reference/android/view/KeyEvent event) ` Called when a user's interaction with an analog control, such as flinging a trackball, generates simulated down/up events for the same key multiple times in quick succession. | | ` abstract boolean` | ` https://developer.android.com/reference/android/view/KeyEvent.Callback#onKeyUp(int,%20android.view.KeyEvent)(int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) ` Called when a key up event has occurred. | ||

## Public constructors

### Session

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

```
public Session (Context context)
```

Creates a new Session.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: The context of the application. This value cannot be `null`. <br /> |

## Public methods

### isMediaViewEnabled

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

```
public boolean isMediaViewEnabled ()
```

Returns `true` if media view is enabled, `false` otherwise.

<br />

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

**See also:**

- `https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#setMediaViewEnabled(boolean)`

### layoutSurface

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

```
public void layoutSurface (int left, 
                int top, 
                int right, 
                int bottom)
```

Assigns a size and position to the surface passed in `https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onSetSurface(android.view.Surface)`. The position
is relative to the overlay view that sits on top of this surface.


If you override this method you *must* call through to the
superclass implementation.

<br />

| Parameters ||
|---|---|
| `left` | `int`: Left position in pixels, relative to the overlay view. <br /> |
| `top` | `int`: Top position in pixels, relative to the overlay view. <br /> |
| `right` | `int`: Right position in pixels, relative to the overlay view. <br /> |
| `bottom` | `int`: Bottom position in pixels, relative to the overlay view. <br /> |

### notifySessionStateChanged

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

```
public void notifySessionStateChanged (int state, 
                int err)
```

Notifies when the session state is changed.


If you override this method you *must* call through to the
superclass implementation.

<br />

| Parameters ||
|---|---|
| `state` | `int`: the current session state. Value is one of the following: - `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#SESSION_STATE_STOPPED` - `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#SESSION_STATE_RUNNING` - `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#SESSION_STATE_ERROR` |
| `err` | `int`: the error code for error state. `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#ERROR_NONE` is used when the state is not `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#SESSION_STATE_ERROR`. Value is one of the following: - `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#ERROR_NONE` - `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#ERROR_UNKNOWN` - `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#ERROR_NOT_SUPPORTED` - `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#ERROR_WEAK_SIGNAL` - `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#ERROR_RESOURCE_UNAVAILABLE` - `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#ERROR_BLOCKED` - `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#ERROR_ENCRYPTED` - `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#ERROR_UNKNOWN_CHANNEL` |

### onCreateMediaView

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

```
public View onCreateMediaView ()
```

Called when the application requests to create a media view. Each session
implementation can override this method and return its own view.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/view/View` | a view attached to the media window. `null` if no media view is created. <br /> |

### onCurrentChannelUri

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

```
public void onCurrentChannelUri (Uri channelUri)
```

Receives current channel URI.

<br />

| Parameters ||
|---|---|
| `channelUri` | `Uri`: This value may be `null`. <br /> |

### onCurrentTvInputId

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

```
public void onCurrentTvInputId (String inputId)
```

Receives current TV input ID.

<br />

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

### onCurrentVideoBounds

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

```
public void onCurrentVideoBounds (Rect bounds)
```

Receives current video bounds.

<br />

| Parameters ||
|---|---|
| `bounds` | `Rect`: the rectangle area for rendering the current video. This value cannot be `null`. <br /> |

### onError

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

```
public void onError (String errMsg, 
                Bundle params)
```

Called when the application sends information of an error.

<br />

| Parameters ||
|---|---|
| `errMsg` | `String`: the message of the error. This value cannot be `null`. <br /> |
| `params` | `Bundle`: additional parameters of the error. For example, the signingId of `https://developer.android.com/reference/android/media/tv/ad/TvAdView.TvAdCallback#onRequestSigning(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20byte[])` can be included to identify the related signing request, and the method name "onRequestSigning" can also be added to the params. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/tv/ad/TvAdView#ERROR_KEY_METHOD_NAME`

### onGenericMotionEvent

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

```
public boolean onGenericMotionEvent (MotionEvent event)
```

Implement this method to handle generic motion events on the current session.

<br />

| Parameters ||
|---|---|
| `event` | `MotionEvent`: The motion event being received. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | If you handled the event, return `true`. If you want to allow the event to be handled by the next receiver, return `false`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/View#onGenericMotionEvent(android.view.MotionEvent)`

### onKeyDown

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

```
public boolean onKeyDown (int keyCode, 
                KeyEvent event)
```

Called when a key down event has occurred. If you return true,
you can first call `https://developer.android.com/reference/android/view/KeyEvent#startTracking()` to have the framework track the event
through its `https://developer.android.com/reference/android/view/KeyEvent.Callback#onKeyUp(int,%20android.view.KeyEvent)` and also call your
`https://developer.android.com/reference/android/view/KeyEvent.Callback#onKeyLongPress(int,%20android.view.KeyEvent)` if it occurs.

<br />

| Parameters ||
|---|---|
| `keyCode` | `int`: The value in event.getKeyCode(). <br /> |
| `event` | `KeyEvent`: This value may be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. <br /> |

### onKeyLongPress

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

```
public boolean onKeyLongPress (int keyCode, 
                KeyEvent event)
```

Called when a long press has occurred. If you return true,
the final key up will have `https://developer.android.com/reference/android/view/KeyEvent#FLAG_CANCELED` and
`https://developer.android.com/reference/android/view/KeyEvent#FLAG_CANCELED_LONG_PRESS` set. Note that in
order to receive this callback, someone in the event change
*must* return true from `https://developer.android.com/reference/android/view/KeyEvent.Callback#onKeyDown(int,%20android.view.KeyEvent)` *and*
call `https://developer.android.com/reference/android/view/KeyEvent#startTracking()` on the event.

<br />

| Parameters ||
|---|---|
| `keyCode` | `int`: The value in event.getKeyCode(). <br /> |
| `event` | `KeyEvent`: This value may be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. <br /> |

### onKeyMultiple

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

```
public boolean onKeyMultiple (int keyCode, 
                int count, 
                KeyEvent event)
```

Called when a user's interaction with an analog control, such as
flinging a trackball, generates simulated down/up events for the same
key multiple times in quick succession.

<br />

| Parameters ||
|---|---|
| `keyCode` | `int`: The value in event.getKeyCode(). <br /> |
| `count` | `int`: Number of pairs as returned by event.getRepeatCount(). <br /> |
| `event` | `KeyEvent`: This value may be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. <br /> |

### onKeyUp

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

```
public boolean onKeyUp (int keyCode, 
                KeyEvent event)
```

Called when a key up event has occurred.

<br />

| Parameters ||
|---|---|
| `keyCode` | `int`: The value in event.getKeyCode(). <br /> |
| `event` | `KeyEvent`: This value may be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. <br /> |

### onMediaViewSizeChanged

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

```
public void onMediaViewSizeChanged (int width, 
                int height)
```

Called when the size of the media view is changed by the application.

This is always called at least once when the session is created regardless of whether
the media view is enabled or not. The media view container size is the same as the
containing `https://developer.android.com/reference/android/media/tv/ad/TvAdView`. Note that the size of the underlying surface can
be different if the surface was changed by calling `https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#layoutSurface(int,%20int,%20int,%20int)`.

<br />

| Parameters ||
|---|---|
| `width` | `int`: The width of the media view, in pixels. The units of this value are pixels. <br /> |
| `height` | `int`: The height of the media view, in pixels. The units of this value are pixels. <br /> |

### onRelease

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

```
public abstract void onRelease ()
```

Releases TvAdService session.

<br />

### onResetAdService

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

```
public void onResetAdService ()
```

Resets TvAdService session.

<br />

### onSetSurface

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

```
public abstract boolean onSetSurface (Surface surface)
```

Called when the application sets the surface.

The TV AD service should render AD UI onto the given surface. When called with
`null`, the AD service should immediately free any references to the currently set
surface and stop using it.

<br />

| Parameters ||
|---|---|
| `surface` | `Surface`: The surface to be used for AD UI rendering. Can be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if the surface was set successfully, `false` otherwise. <br /> |

### onSigningResult

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

```
public void onSigningResult (String signingId, 
                byte[] result)
```

Receives signing result.

<br />

| Parameters ||
|---|---|
| `signingId` | `String`: the ID to identify the request. It's the same as the corresponding ID in `https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#requestSigning(java.lang.String,%20java.lang.String,%20java.lang.String,%20byte[])` This value cannot be `null`. <br /> |
| `result` | `byte`: the signed result. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#requestSigning(java.lang.String,%20java.lang.String,%20java.lang.String,%20byte[])`

### onStartAdService

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

```
public void onStartAdService ()
```

Starts TvAdService session.

<br />

### onStopAdService

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

```
public void onStopAdService ()
```

Stops TvAdService session.

<br />

### onSurfaceChanged

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

```
public void onSurfaceChanged (int format, 
                int width, 
                int height)
```

Called after any structural changes (format or size) have been made to the surface passed
in `https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onSetSurface(android.view.Surface)`. This method is always called at least once, after
`https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onSetSurface(android.view.Surface)` is called with non-null surface.

<br />

| Parameters ||
|---|---|
| `format` | `int`: The new `https://developer.android.com/reference/android/graphics/PixelFormat` of the surface. Value is one of the following: - `https://developer.android.com/reference/android/graphics/PixelFormat#RGBA_8888` - `https://developer.android.com/reference/android/graphics/PixelFormat#RGBX_8888` - `https://developer.android.com/reference/android/graphics/PixelFormat#RGBA_F16` - `https://developer.android.com/reference/android/graphics/PixelFormat#RGBA_1010102` - `https://developer.android.com/reference/android/graphics/PixelFormat#RGB_888` - `https://developer.android.com/reference/android/graphics/PixelFormat#RGB_565` |
| `width` | `int`: The new width of the surface. <br /> |
| `height` | `int`: The new height of the surface. <br /> |

### onTouchEvent

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

```
public boolean onTouchEvent (MotionEvent event)
```

Implement this method to handle touch screen motion events on the current session.

<br />

| Parameters ||
|---|---|
| `event` | `MotionEvent`: The motion event being received. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | If you handled the event, return `true`. If you want to allow the event to be handled by the next receiver, return `false`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/View#onTouchEvent(android.view.MotionEvent)`

### onTrackInfoList

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

```
public void onTrackInfoList (List<TvTrackInfo> tracks)
```

Receives track list.

<br />

| Parameters ||
|---|---|
| `tracks` | `List`: This value cannot be `null`. <br /> |

### onTrackballEvent

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

```
public boolean onTrackballEvent (MotionEvent event)
```

Implement this method to handle trackball events on the current session.

<br />

| Parameters ||
|---|---|
| `event` | `MotionEvent`: The motion event being received. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | If you handled the event, return `true`. If you want to allow the event to be handled by the next receiver, return `false`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/View#onTrackballEvent(android.view.MotionEvent)`

### onTvInputSessionData

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

```
public void onTvInputSessionData (String type, 
                Bundle data)
```

Called when data from the linked `https://developer.android.com/reference/android/media/tv/TvInputService` is received.

<br />

| Parameters ||
|---|---|
| `type` | `String`: the type of the data. This value cannot be `null`. Value is one of the following: - `https://developer.android.com/reference/android/media/tv/TvInputManager#SESSION_DATA_TYPE_TUNED` - `https://developer.android.com/reference/android/media/tv/TvInputManager#SESSION_DATA_TYPE_TRACK_SELECTED` - `https://developer.android.com/reference/android/media/tv/TvInputManager#SESSION_DATA_TYPE_TRACKS_CHANGED` - `https://developer.android.com/reference/android/media/tv/TvInputManager#SESSION_DATA_TYPE_VIDEO_AVAILABLE` - `https://developer.android.com/reference/android/media/tv/TvInputManager#SESSION_DATA_TYPE_VIDEO_UNAVAILABLE` - `https://developer.android.com/reference/android/media/tv/TvInputManager#SESSION_DATA_TYPE_BROADCAST_INFO_RESPONSE` - `https://developer.android.com/reference/android/media/tv/TvInputManager#SESSION_DATA_TYPE_AD_RESPONSE` - `https://developer.android.com/reference/android/media/tv/TvInputManager#SESSION_DATA_TYPE_AD_BUFFER_CONSUMED` - `https://developer.android.com/reference/android/media/tv/TvInputManager#SESSION_DATA_TYPE_TV_MESSAGE` |
| `data` | `Bundle`: a bundle contains the data received. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/tv/TvInputService.Session#sendTvInputSessionData(java.lang.String,%20android.os.Bundle)`
- `https://developer.android.com/reference/android/media/tv/ad/TvAdView#setTvView(android.media.tv.TvView)`

### onTvMessage

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

```
public void onTvMessage (int type, 
                Bundle data)
```

Called when a TV message is received

<br />

| Parameters ||
|---|---|
| `type` | `int`: The type of message received, such as `https://developer.android.com/reference/android/media/tv/TvInputManager#TV_MESSAGE_TYPE_WATERMARK` Value is one of the following: - `https://developer.android.com/reference/android/media/tv/TvInputManager#TV_MESSAGE_TYPE_WATERMARK` - `https://developer.android.com/reference/android/media/tv/TvInputManager#TV_MESSAGE_TYPE_CLOSED_CAPTION` - `https://developer.android.com/reference/android/media/tv/TvInputManager#TV_MESSAGE_TYPE_OTHER` |
| `data` | `Bundle`: The raw data of the message. The bundle keys are: `https://developer.android.com/reference/android/media/tv/TvInputManager#TV_MESSAGE_KEY_STREAM_ID`, `https://developer.android.com/reference/android/media/tv/TvInputManager#TV_MESSAGE_KEY_GROUP_ID`, `https://developer.android.com/reference/android/media/tv/TvInputManager#TV_MESSAGE_KEY_SUBTYPE`, `https://developer.android.com/reference/android/media/tv/TvInputManager#TV_MESSAGE_KEY_RAW_DATA`. See `https://developer.android.com/reference/android/media/tv/TvInputManager#TV_MESSAGE_KEY_SUBTYPE` for more information on how to parse this data. This value cannot be `null`. <br /> |

### requestCurrentChannelUri

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

```
public void requestCurrentChannelUri ()
```

Requests the URI of the current channel.


If you override this method you *must* call through to the
superclass implementation.

<br />

### requestCurrentTvInputId

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

```
public void requestCurrentTvInputId ()
```

Requests current TV input ID.


If you override this method you *must* call through to the
superclass implementation.

<br />

**See also:**

- `https://developer.android.com/reference/android/media/tv/TvInputInfo`

### requestCurrentVideoBounds

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

```
public void requestCurrentVideoBounds ()
```

Requests the bounds of the current video.


If you override this method you *must* call through to the
superclass implementation.

<br />

### requestSigning

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

```
public void requestSigning (String signingId, 
                String algorithm, 
                String alias, 
                byte[] data)
```

Requests signing of the given data.

This is used when the corresponding server of the AD service app requires signing
during handshaking, and the service doesn't have the built-in private key. The private
key is provided by the content providers and pre-built in the related app, such as TV
app.


If you override this method you *must* call through to the
superclass implementation.

<br />

| Parameters ||
|---|---|
| `signingId` | `String`: the ID to identify the request. When a result is received, this ID can be used to correlate the result with the request. This value cannot be `null`. <br /> |
| `algorithm` | `String`: the standard name of the signature algorithm requested, such as MD5withRSA, SHA256withDSA, etc. The name is from standards like FIPS PUB 186-4 and PKCS #1. This value cannot be `null`. <br /> |
| `alias` | `String`: the alias of the corresponding `https://developer.android.com/reference/java/security/KeyStore`. This value cannot be `null`. <br /> |
| `data` | `byte`: the original bytes to be signed. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session#onSigningResult(java.lang.String,%20byte[])`

### requestTrackInfoList

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

```
public void requestTrackInfoList ()
```

Requests the list of `https://developer.android.com/reference/android/media/tv/TvTrackInfo`.


If you override this method you *must* call through to the
superclass implementation.

<br />

### sendTvAdSessionData

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

```
public void sendTvAdSessionData (String type, 
                Bundle data)
```

Sends data related to this session to corresponding linked
`https://developer.android.com/reference/android/media/tv/TvInputService` object via TvView.

<br />

| Parameters ||
|---|---|
| `type` | `String`: data type. This value cannot be `null`. Value is one of the following: - `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#SESSION_DATA_TYPE_AD_REQUEST` - `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#SESSION_DATA_TYPE_AD_BUFFER_READY` - `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#SESSION_DATA_TYPE_BROADCAST_INFO_REQUEST` - `https://developer.android.com/reference/android/media/tv/ad/TvAdManager#SESSION_DATA_TYPE_REMOVE_BROADCAST_INFO_REQUEST` |
| `data` | `Bundle`: the related data values. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/tv/ad/TvAdView#setTvView(android.media.tv.TvView)`

### setMediaViewEnabled

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

```
public void setMediaViewEnabled (boolean enable)
```

Enables or disables the media view.

By default, the media view is disabled. Must be called explicitly after the
session is created to enable the media view.

The TV AD service can disable its media view when needed.


If you override this method you *must* call through to the
superclass implementation.

<br />

| Parameters ||
|---|---|
| `enable` | `boolean`: `true` if you want to enable the media view. `false` otherwise. <br /> |