TvAdService.Session
public
static
abstract
class
TvAdService.Session
extends Object
implements
KeyEvent.Callback
java.lang.Object | |
↳ | android.media.tv.ad.TvAdService.Session |
Base class for derived classes to implement to provide a TV AD session.
Summary
Public constructors | |
---|---|
Session(Context context)
Creates a new Session. |
Public methods | |
---|---|
boolean
|
isMediaViewEnabled()
Returns |
void
|
layoutSurface(int left, int top, int right, int bottom)
Assigns a size and position to the surface passed in |
void
|
notifySessionStateChanged(int state, int err)
Notifies when the session state is changed. |
View
|
onCreateMediaView()
Called when the application requests to create a media view. |
void
|
onCurrentChannelUri(Uri channelUri)
Receives current channel URI. |
void
|
onCurrentTvInputId(String inputId)
Receives current TV input ID. |
void
|
onCurrentVideoBounds(Rect bounds)
Receives current video bounds. |
void
|
onError(String errMsg, Bundle params)
Called when the application sends information of an error. |
boolean
|
onGenericMotionEvent(MotionEvent event)
Implement this method to handle generic motion events on the current session. |
boolean
|
onKeyDown(int keyCode, KeyEvent event)
Called when a key down event has occurred. |
boolean
|
onKeyLongPress(int keyCode, KeyEvent event)
Called when a long press has occurred. |
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. |
boolean
|
onKeyUp(int keyCode, KeyEvent event)
Called when a key up event has occurred. |
void
|
onMediaViewSizeChanged(int width, int height)
Called when the size of the media view is changed by the application. |
abstract
void
|
onRelease()
Releases TvAdService session. |
void
|
onResetAdService()
Resets TvAdService session. |
abstract
boolean
|
onSetSurface(Surface surface)
Called when the application sets the surface. |
void
|
onSigningResult(String signingId, byte[] result)
Receives signing result. |
void
|
onStartAdService()
Starts TvAdService session. |
void
|
onStopAdService()
Stops TvAdService session. |
void
|
onSurfaceChanged(int format, int width, int height)
Called after any structural changes (format or size) have been made to the surface passed
in |
boolean
|
onTouchEvent(MotionEvent event)
Implement this method to handle touch screen motion events on the current session. |
void
|
onTrackInfoList(List<TvTrackInfo> tracks)
Receives track list. |
boolean
|
onTrackballEvent(MotionEvent event)
Implement this method to handle trackball events on the current session. |
void
|
onTvInputSessionData(String type, Bundle data)
Called when data from the linked |
void
|
onTvMessage(int type, Bundle data)
Called when a TV message is received |
void
|
requestCurrentChannelUri()
Requests the URI of the current channel. |
void
|
requestCurrentTvInputId()
Requests current TV input ID. |
void
|
requestCurrentVideoBounds()
Requests the bounds of the current video. |
void
|
requestSigning(String signingId, String algorithm, String alias, byte[] data)
Requests signing of the given data. |
void
|
requestTrackInfoList()
Requests the list of |
void
|
sendTvAdSessionData(String type, Bundle data)
Sends data related to this session to corresponding linked
|
void
|
setMediaViewEnabled(boolean enable)
Enables or disables the media view. |
Inherited methods | |
---|---|
Public constructors
Session
public Session (Context context)
Creates a new Session.
Parameters | |
---|---|
context |
Context : The context of the application
This value cannot be null . |
Public methods
isMediaViewEnabled
public boolean isMediaViewEnabled ()
Returns true
if media view is enabled, false
otherwise.
Returns | |
---|---|
boolean |
See also:
layoutSurface
public void layoutSurface (int left, int top, int right, int bottom)
Assigns a size and position to the surface passed in onSetSurface(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.
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
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.
Parameters | |
---|---|
state |
int : the current session state.
Value is TvAdManager.SESSION_STATE_STOPPED , TvAdManager.SESSION_STATE_RUNNING , or 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 TvAdManager.ERROR_NONE , TvAdManager.ERROR_UNKNOWN , TvAdManager.ERROR_NOT_SUPPORTED , TvAdManager.ERROR_WEAK_SIGNAL , TvAdManager.ERROR_RESOURCE_UNAVAILABLE , TvAdManager.ERROR_BLOCKED , TvAdManager.ERROR_ENCRYPTED , or TvAdManager.ERROR_UNKNOWN_CHANNEL |
onCreateMediaView
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.
Returns | |
---|---|
View |
a view attached to the media window. null if no media view is created. |
onCurrentChannelUri
public void onCurrentChannelUri (Uri channelUri)
Receives current channel URI.
Parameters | |
---|---|
channelUri |
Uri : This value may be null . |
onCurrentTvInputId
public void onCurrentTvInputId (String inputId)
Receives current TV input ID.
Parameters | |
---|---|
inputId |
String : This value may be null . |
onCurrentVideoBounds
public void onCurrentVideoBounds (Rect bounds)
Receives current video bounds.
Parameters | |
---|---|
bounds |
Rect : the rectangle area for rendering the current video.
This value cannot be null . |
onError
public void onError (String errMsg, Bundle params)
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 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 . |
See also:
onGenericMotionEvent
public boolean onGenericMotionEvent (MotionEvent event)
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 . |
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 . |
See also:
onKeyDown
public boolean onKeyDown (int keyCode, KeyEvent event)
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 . |
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. |
onKeyLongPress
public boolean onKeyLongPress (int keyCode, KeyEvent event)
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(int, KeyEvent)
and
call KeyEvent.startTracking()
on the event.
Parameters | |
---|---|
keyCode |
int : The value in event.getKeyCode(). |
event |
KeyEvent : This value may be null . |
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. |
onKeyMultiple
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.
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 . |
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. |
onKeyUp
public boolean onKeyUp (int keyCode, KeyEvent event)
Called when a key up event has occurred.
Parameters | |
---|---|
keyCode |
int : The value in event.getKeyCode(). |
event |
KeyEvent : This value may be null . |
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. |
onMediaViewSizeChanged
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 TvAdView
. Note that the size of the underlying surface can
be different if the surface was changed by calling layoutSurface(int, int, int, int)
.
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
public void onResetAdService ()
Resets TvAdService session.
onSetSurface
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.
Parameters | |
---|---|
surface |
Surface : The surface to be used for AD UI rendering. Can be null . |
Returns | |
---|---|
boolean |
true if the surface was set successfully, false otherwise. |
onSigningResult
public void onSigningResult (String signingId, byte[] result)
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 |
byte : the signed result.
This value cannot be null . |
onStartAdService
public void onStartAdService ()
Starts TvAdService session.
onSurfaceChanged
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 onSetSurface(Surface)
. This method is always called at least once, after
onSetSurface(Surface)
is called with non-null surface.
Parameters | |
---|---|
format |
int : The new PixelFormat of the surface.
Value is PixelFormat.RGBA_8888 , PixelFormat.RGBX_8888 , PixelFormat.RGBA_F16 , PixelFormat.RGBA_1010102 , PixelFormat.RGB_888 , 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
public boolean onTouchEvent (MotionEvent event)
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 . |
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 . |
See also:
onTrackInfoList
public void onTrackInfoList (List<TvTrackInfo> tracks)
Receives track list.
Parameters | |
---|---|
tracks |
List : This value cannot be null . |
onTrackballEvent
public boolean onTrackballEvent (MotionEvent event)
Implement this method to handle trackball events on the current session.
Parameters | |
---|---|
event |
MotionEvent : The motion event being received.
This value cannot be null . |
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 . |
See also:
onTvInputSessionData
public void onTvInputSessionData (String type, Bundle data)
Called when data from the linked TvInputService
is received.
Parameters | |
---|---|
type |
String : the type of the data
This value cannot be null .
Value is TvInputManager.SESSION_DATA_TYPE_TUNED , TvInputManager.SESSION_DATA_TYPE_TRACK_SELECTED , TvInputManager.SESSION_DATA_TYPE_TRACKS_CHANGED , TvInputManager.SESSION_DATA_TYPE_VIDEO_AVAILABLE , TvInputManager.SESSION_DATA_TYPE_VIDEO_UNAVAILABLE , TvInputManager.SESSION_DATA_TYPE_BROADCAST_INFO_RESPONSE , TvInputManager.SESSION_DATA_TYPE_AD_RESPONSE , TvInputManager.SESSION_DATA_TYPE_AD_BUFFER_CONSUMED , or TvInputManager.SESSION_DATA_TYPE_TV_MESSAGE |
data |
Bundle : a bundle contains the data received
This value cannot be null . |
onTvMessage
public void onTvMessage (int type, Bundle data)
Called when a TV message is received
Parameters | |
---|---|
type |
int : The type of message received, such as
TvInputManager.TV_MESSAGE_TYPE_WATERMARK
Value is TvInputManager.TV_MESSAGE_TYPE_WATERMARK , TvInputManager.TV_MESSAGE_TYPE_CLOSED_CAPTION , or 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
public void requestCurrentChannelUri ()
Requests the URI of the current channel.
If you override this method you must call through to the
superclass implementation.
requestCurrentTvInputId
public void requestCurrentTvInputId ()
Requests current TV input ID.
If you override this method you must call through to the
superclass implementation.
See also:
requestCurrentVideoBounds
public void requestCurrentVideoBounds ()
Requests the bounds of the current video.
If you override this method you must call through to the
superclass implementation.
requestSigning
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.
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 KeyStore .
This value cannot be null . |
data |
byte : the original bytes to be signed.
This value cannot be null . |
See also:
requestTrackInfoList
public void requestTrackInfoList ()
Requests the list of TvTrackInfo
.
If you override this method you must call through to the
superclass implementation.
sendTvAdSessionData
public void sendTvAdSessionData (String type, Bundle data)
Sends data related to this session to corresponding linked
TvInputService
object via TvView.
Parameters | |
---|---|
type |
String : data type
This value cannot be null .
Value is TvAdManager.SESSION_DATA_TYPE_AD_REQUEST , TvAdManager.SESSION_DATA_TYPE_AD_BUFFER_READY , TvAdManager.SESSION_DATA_TYPE_BROADCAST_INFO_REQUEST , or TvAdManager.SESSION_DATA_TYPE_REMOVE_BROADCAST_INFO_REQUEST |
data |
Bundle : the related data values
This value cannot be null . |
See also:
setMediaViewEnabled
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.
Parameters | |
---|---|
enable |
boolean : true if you want to enable the media view. false
otherwise. |