Session
abstract class Session : KeyEvent.Callback
kotlin.Any | |
↳ | android.media.tv.ad.TvAdService.Session |
Base class for derived classes to implement to provide a TV AD session.
Summary
Public constructors | |
---|---|
Creates a new Session. |
Public methods | |
---|---|
open Boolean |
Returns |
open Unit |
layoutSurface(left: Int, top: Int, right: Int, bottom: Int) Assigns a size and position to the surface passed in |
open Unit |
notifySessionStateChanged(state: Int, err: Int) Notifies when the session state is changed. |
open View? |
Called when the application requests to create a media view. |
open Unit |
onCurrentChannelUri(channelUri: Uri?) Receives current channel URI. |
open Unit |
onCurrentTvInputId(inputId: String?) Receives current TV input ID. |
open Unit |
onCurrentVideoBounds(bounds: Rect) Receives current video bounds. |
open Unit |
Called when the application sends information of an error. |
open Boolean |
onGenericMotionEvent(event: MotionEvent) Implement this method to handle generic motion events on the current session. |
open Boolean |
Called when a key down event has occurred. |
open Boolean |
onKeyLongPress(keyCode: Int, event: KeyEvent?) Called when a long press has occurred. |
open Boolean |
onKeyMultiple(keyCode: Int, count: Int, event: KeyEvent?) 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. |
open Boolean |
Called when a key up event has occurred. |
open Unit |
onMediaViewSizeChanged(width: Int, height: Int) Called when the size of the media view is changed by the application. |
abstract Unit |
Releases TvAdService session. |
open Unit |
Resets TvAdService session. |
abstract Boolean |
onSetSurface(surface: Surface?) Called when the application sets the surface. |
open Unit |
onSigningResult(signingId: String, result: ByteArray) Receives signing result. |
open Unit |
Starts TvAdService session. |
open Unit |
Stops TvAdService session. |
open Unit |
onSurfaceChanged(format: Int, width: Int, height: Int) Called after any structural changes (format or size) have been made to the surface passed in |
open Boolean |
onTouchEvent(event: MotionEvent) Implement this method to handle touch screen motion events on the current session. |
open Unit |
onTrackInfoList(tracks: MutableList<TvTrackInfo!>) Receives track list. |
open Boolean |
onTrackballEvent(event: MotionEvent) Implement this method to handle trackball events on the current session. |
open Unit |
onTvInputSessionData(type: String, data: Bundle) Called when data from the linked |
open Unit |
onTvMessage(type: Int, data: Bundle) Called when a TV message is received |
open Unit |
Requests the URI of the current channel. |
open Unit |
Requests current TV input ID. |
open Unit |
Requests the bounds of the current video. |
open Unit |
requestSigning(signingId: String, algorithm: String, alias: String, data: ByteArray) Requests signing of the given data. |
open Unit |
Requests the list of |
open Unit |
sendTvAdSessionData(type: String, data: Bundle) Sends data related to this session to corresponding linked |
open Unit |
setMediaViewEnabled(enable: Boolean) Enables or disables the media view. |
Public constructors
Session
Session(context: Context)
Creates a new Session.
Parameters | |
---|---|
context |
Context: The context of the application This value cannot be null . |
Public methods
isMediaViewEnabled
open fun isMediaViewEnabled(): Boolean
Returns true
if media view is enabled, false
otherwise.
See Also
layoutSurface
open fun layoutSurface(
left: Int,
top: Int,
right: Int,
bottom: Int
): Unit
Assigns a size and position to the surface passed in onSetSurface
. 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.
Parameters | |
---|---|
left |
Int: Left position in pixels, relative to the overlay view. |
top |
Int: Top position in pixels, relative to the overlay view. |
right |
Int: Right position in pixels, relative to the overlay view. |
bottom |
Int: Bottom position in pixels, relative to the overlay view. |
notifySessionStateChanged
open fun notifySessionStateChanged(
state: Int,
err: Int
): Unit
Notifies when the session state is changed.
If you override this method you must call through to the superclass implementation.
Parameters | |
---|---|
state |
Int: the current session state. Value is android.media.tv.ad.TvAdManager#SESSION_STATE_STOPPED , android.media.tv.ad.TvAdManager#SESSION_STATE_RUNNING , or android.media.tv.ad.TvAdManager#SESSION_STATE_ERROR |
err |
Int: the error code for error state. TvAdManager.ERROR_NONE is used when the state is not TvAdManager.SESSION_STATE_ERROR . Value is android.media.tv.ad.TvAdManager#ERROR_NONE , android.media.tv.ad.TvAdManager#ERROR_UNKNOWN , android.media.tv.ad.TvAdManager#ERROR_NOT_SUPPORTED , android.media.tv.ad.TvAdManager#ERROR_WEAK_SIGNAL , android.media.tv.ad.TvAdManager#ERROR_RESOURCE_UNAVAILABLE , android.media.tv.ad.TvAdManager#ERROR_BLOCKED , android.media.tv.ad.TvAdManager#ERROR_ENCRYPTED , or android.media.tv.ad.TvAdManager#ERROR_UNKNOWN_CHANNEL |
onCreateMediaView
open fun onCreateMediaView(): View?
Called when the application requests to create a media view. Each session implementation can override this method and return its own view.
Return | |
---|---|
View? |
a view attached to the media window. null if no media view is created. |
onCurrentChannelUri
open fun onCurrentChannelUri(channelUri: Uri?): Unit
Receives current channel URI.
Parameters | |
---|---|
channelUri |
Uri?: This value may be null . |
onCurrentTvInputId
open fun onCurrentTvInputId(inputId: String?): Unit
Receives current TV input ID.
Parameters | |
---|---|
inputId |
String?: This value may be null . |
onCurrentVideoBounds
open fun onCurrentVideoBounds(bounds: Rect): Unit
Receives current video bounds.
Parameters | |
---|---|
bounds |
Rect: the rectangle area for rendering the current video. This value cannot be null . |
onError
open fun onError(
errMsg: String,
params: Bundle
): Unit
Called when the application sends information of an error.
Parameters | |
---|---|
errMsg |
String: the message of the error. This value cannot be null . |
params |
Bundle: additional parameters of the error. For example, the signingId of android.media.tv.ad.TvAdView.TvAdCallback#onRequestSigning(java.lang.String,java.lang.String,java.lang.String,java.lang.String,byte[]) 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 . |
onGenericMotionEvent
open fun onGenericMotionEvent(event: MotionEvent): Boolean
Implement this method to handle generic motion events on the current session.
Parameters | |
---|---|
event |
MotionEvent: The motion event being received. This value cannot be null . |
Return | |
---|---|
Boolean |
If you handled the event, return true . If you want to allow the event to be handled by the next receiver, return false . |
onKeyDown
open fun onKeyDown(
keyCode: Int,
event: KeyEvent?
): Boolean
Called when a key down event has occurred. If you return true, you can first call KeyEvent.startTracking()
to have the framework track the event through its onKeyUp(int,android.view.KeyEvent)
and also call your onKeyLongPress(int,android.view.KeyEvent)
if it occurs.
Parameters | |
---|---|
keyCode |
Int: The value in event.getKeyCode(). |
event |
KeyEvent?: This value may be null . |
Return | |
---|---|
Boolean |
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |
onKeyLongPress
open fun onKeyLongPress(
keyCode: Int,
event: KeyEvent?
): Boolean
Called when a long press has occurred. If you return true, the final key up will have KeyEvent.FLAG_CANCELED
and KeyEvent.FLAG_CANCELED_LONG_PRESS
set. Note that in order to receive this callback, someone in the event change must return true from onKeyDown
and call KeyEvent.startTracking()
on the event.
Parameters | |
---|---|
keyCode |
Int: The value in event.getKeyCode(). |
event |
KeyEvent?: This value may be null . |
Return | |
---|---|
Boolean |
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |
onKeyMultiple
open fun onKeyMultiple(
keyCode: Int,
count: Int,
event: KeyEvent?
): Boolean
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.
Parameters | |
---|---|
keyCode |
Int: The value in event.getKeyCode(). |
count |
Int: Number of pairs as returned by event.getRepeatCount(). |
event |
KeyEvent?: This value may be null . |
Return | |
---|---|
Boolean |
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |
onKeyUp
open fun onKeyUp(
keyCode: Int,
event: KeyEvent?
): Boolean
Called when a key up event has occurred.
Parameters | |
---|---|
keyCode |
Int: The value in event.getKeyCode(). |
event |
KeyEvent?: This value may be null . |
Return | |
---|---|
Boolean |
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |
onMediaViewSizeChanged
open fun onMediaViewSizeChanged(
width: Int,
height: Int
): Unit
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 TvAdView
. Note that the size of the underlying surface can be different if the surface was changed by calling layoutSurface
.
Parameters | |
---|---|
width |
Int: The width of the media view, in pixels. The units of this value are pixels. |
height |
Int: The height of the media view, in pixels. The units of this value are pixels. |
onResetAdService
open fun onResetAdService(): Unit
Resets TvAdService session.
onSetSurface
abstract fun onSetSurface(surface: Surface?): Boolean
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.
Parameters | |
---|---|
surface |
Surface?: The surface to be used for AD UI rendering. Can be null . |
Return | |
---|---|
Boolean |
true if the surface was set successfully, false otherwise. |
onSigningResult
open fun onSigningResult(
signingId: String,
result: ByteArray
): Unit
Receives signing result.
Parameters | |
---|---|
signingId |
String: the ID to identify the request. It's the same as the corresponding ID in Session.requestSigning(String, String, String, byte[]) This value cannot be null . |
result |
ByteArray: the signed result. This value cannot be null . |
onStartAdService
open fun onStartAdService(): Unit
Starts TvAdService session.
onStopAdService
open fun onStopAdService(): Unit
Stops TvAdService session.
onSurfaceChanged
open fun onSurfaceChanged(
format: Int,
width: Int,
height: Int
): Unit
Called after any structural changes (format or size) have been made to the surface passed in onSetSurface
. This method is always called at least once, after onSetSurface
is called with non-null surface.
Parameters | |
---|---|
format |
Int: The new PixelFormat of the surface. Value is android.graphics.PixelFormat#RGBA_8888 , android.graphics.PixelFormat#RGBX_8888 , android.graphics.PixelFormat#RGBA_F16 , android.graphics.PixelFormat#RGBA_1010102 , android.graphics.PixelFormat#RGB_888 , android.graphics.PixelFormat#RGB_565 , or android.graphics.PixelFormat.R_8 |
width |
Int: The new width of the surface. |
height |
Int: The new height of the surface. |
onTouchEvent
open fun onTouchEvent(event: MotionEvent): Boolean
Implement this method to handle touch screen motion events on the current session.
Parameters | |
---|---|
event |
MotionEvent: The motion event being received. This value cannot be null . |
Return | |
---|---|
Boolean |
If you handled the event, return true . If you want to allow the event to be handled by the next receiver, return false . |
See Also
onTrackInfoList
open fun onTrackInfoList(tracks: MutableList<TvTrackInfo!>): Unit
Receives track list.
Parameters | |
---|---|
tracks |
MutableList<TvTrackInfo!>: This value cannot be null . |
onTrackballEvent
open fun onTrackballEvent(event: MotionEvent): Boolean
Implement this method to handle trackball events on the current session.
Parameters | |
---|---|
event |
MotionEvent: The motion event being received. This value cannot be null . |
Return | |
---|---|
Boolean |
If you handled the event, return true . If you want to allow the event to be handled by the next receiver, return false . |
See Also
onTvInputSessionData
open fun onTvInputSessionData(
type: String,
data: Bundle
): Unit
Called when data from the linked android.media.tv.TvInputService
is received.
Parameters | |
---|---|
type |
String: the type of the data This value cannot be null . Value is android.media.tv.TvInputManager#SESSION_DATA_TYPE_TUNED , android.media.tv.TvInputManager#SESSION_DATA_TYPE_TRACK_SELECTED , android.media.tv.TvInputManager#SESSION_DATA_TYPE_TRACKS_CHANGED , android.media.tv.TvInputManager#SESSION_DATA_TYPE_VIDEO_AVAILABLE , android.media.tv.TvInputManager#SESSION_DATA_TYPE_VIDEO_UNAVAILABLE , android.media.tv.TvInputManager#SESSION_DATA_TYPE_BROADCAST_INFO_RESPONSE , android.media.tv.TvInputManager#SESSION_DATA_TYPE_AD_RESPONSE , android.media.tv.TvInputManager#SESSION_DATA_TYPE_AD_BUFFER_CONSUMED , or android.media.tv.TvInputManager#SESSION_DATA_TYPE_TV_MESSAGE |
data |
Bundle: a bundle contains the data received This value cannot be null . |
onTvMessage
open fun onTvMessage(
type: Int,
data: Bundle
): Unit
Called when a TV message is received
Parameters | |
---|---|
type |
Int: The type of message received, such as TvInputManager.TV_MESSAGE_TYPE_WATERMARK Value is android.media.tv.TvInputManager#TV_MESSAGE_TYPE_WATERMARK , android.media.tv.TvInputManager#TV_MESSAGE_TYPE_CLOSED_CAPTION , or android.media.tv.TvInputManager#TV_MESSAGE_TYPE_OTHER |
data |
Bundle: The raw data of the message. The bundle keys are: TvInputManager.TV_MESSAGE_KEY_STREAM_ID , TvInputManager.TV_MESSAGE_KEY_GROUP_ID , TvInputManager.TV_MESSAGE_KEY_SUBTYPE , TvInputManager.TV_MESSAGE_KEY_RAW_DATA . See TvInputManager.TV_MESSAGE_KEY_SUBTYPE for more information on how to parse this data. This value cannot be null . |
requestCurrentChannelUri
open fun requestCurrentChannelUri(): Unit
Requests the URI of the current channel.
If you override this method you must call through to the superclass implementation.
requestCurrentTvInputId
open fun requestCurrentTvInputId(): Unit
Requests current TV input ID.
If you override this method you must call through to the superclass implementation.
See Also
requestCurrentVideoBounds
open fun requestCurrentVideoBounds(): Unit
Requests the bounds of the current video.
If you override this method you must call through to the superclass implementation.
requestSigning
open fun requestSigning(
signingId: String,
algorithm: String,
alias: String,
data: ByteArray
): Unit
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.
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 . |
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 . |
alias |
String: the alias of the corresponding java.security.KeyStore . This value cannot be null . |
data |
ByteArray: the original bytes to be signed. This value cannot be null . |
See Also
requestTrackInfoList
open fun requestTrackInfoList(): Unit
Requests the list of TvTrackInfo
.
If you override this method you must call through to the superclass implementation.
sendTvAdSessionData
open fun sendTvAdSessionData(
type: String,
data: Bundle
): Unit
Sends data related to this session to corresponding linked android.media.tv.TvInputService
object via TvView.
Parameters | |
---|---|
type |
String: data type This value cannot be null . Value is android.media.tv.ad.TvAdManager#SESSION_DATA_TYPE_AD_REQUEST , android.media.tv.ad.TvAdManager#SESSION_DATA_TYPE_AD_BUFFER_READY , android.media.tv.ad.TvAdManager#SESSION_DATA_TYPE_BROADCAST_INFO_REQUEST , or android.media.tv.ad.TvAdManager#SESSION_DATA_TYPE_REMOVE_BROADCAST_INFO_REQUEST |
data |
Bundle: the related data values This value cannot be null . |
setMediaViewEnabled
open fun setMediaViewEnabled(enable: Boolean): Unit
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.
Parameters | |
---|---|
enable |
Boolean: true if you want to enable the media view. false otherwise. |