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 benull. | 
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 isTvAdManager.SESSION_STATE_STOPPED,TvAdManager.SESSION_STATE_RUNNING, orTvAdManager.SESSION_STATE_ERROR | 
| err | int: the error code for error state.TvAdManager.ERROR_NONEis
            used when the state is notTvAdManager.SESSION_STATE_ERROR.
 Value isTvAdManager.ERROR_NONE,TvAdManager.ERROR_UNKNOWN,TvAdManager.ERROR_NOT_SUPPORTED,TvAdManager.ERROR_WEAK_SIGNAL,TvAdManager.ERROR_RESOURCE_UNAVAILABLE,TvAdManager.ERROR_BLOCKED,TvAdManager.ERROR_ENCRYPTED, orTvAdManager.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. nullif no media view is created. | 
onCurrentChannelUri
public void onCurrentChannelUri (Uri channelUri)
Receives current channel URI.
| Parameters | |
|---|---|
| channelUri | Uri: This value may benull. | 
onCurrentTvInputId
public void onCurrentTvInputId (String inputId)
Receives current TV input ID.
| Parameters | |
|---|---|
| inputId | String: This value may benull. | 
onCurrentVideoBounds
public void onCurrentVideoBounds (Rect bounds)
Receives current video bounds.
| Parameters | |
|---|---|
| bounds | Rect: the rectangle area for rendering the current video.
 This value cannot benull. | 
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 benull. | 
| params | Bundle: additional parameters of the error. For example, the signingId ofTvAdView.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 benull. | 
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 benull. | 
| Returns | |
|---|---|
| boolean | If you handled the event, return true. If you want to allow the event to
         be handled by the next receiver, returnfalse. | 
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 benull. | 
| 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 benull. | 
| 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 benull. | 
| 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 benull. | 
| 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. | 
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 benull. | 
| Returns | |
|---|---|
| boolean | trueif the surface was set successfully,falseotherwise. | 
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 inSession.requestSigning(String, String, String, byte[])This value cannot benull. | 
| result | byte: the signed result.
 This value cannot benull. | 
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 newPixelFormatof the surface.
 Value isPixelFormat.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 benull. | 
| Returns | |
|---|---|
| boolean | If you handled the event, return true. If you want to allow the event to
         be handled by the next receiver, returnfalse. | 
See also:
onTrackInfoList
public void onTrackInfoList (List<TvTrackInfo> tracks)
Receives track list.
| Parameters | |
|---|---|
| tracks | List: This value cannot benull. | 
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 benull. | 
| Returns | |
|---|---|
| boolean | If you handled the event, return true. If you want to allow the event to
         be handled by the next receiver, returnfalse. | 
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 benull.
 Value isTvInputManager.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, orTvInputManager.SESSION_DATA_TYPE_TV_MESSAGE | 
| data | Bundle: a bundle contains the data received
 This value cannot benull. | 
onTvMessage
public void onTvMessage (int type, 
                Bundle data)Called when a TV message is received
| Parameters | |
|---|---|
| type | int: The type of message received, such asTvInputManager.TV_MESSAGE_TYPE_WATERMARKValue isTvInputManager.TV_MESSAGE_TYPE_WATERMARK,TvInputManager.TV_MESSAGE_TYPE_CLOSED_CAPTION, orTvInputManager.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.
             SeeTvInputManager.TV_MESSAGE_KEY_SUBTYPEfor more information on
             how to parse this data.
 This value cannot benull. | 
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 benull. | 
| 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 benull. | 
| alias | String: the alias of the correspondingKeyStore.
 This value cannot benull. | 
| data | byte: the original bytes to be signed.
 This value cannot benull. | 
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 benull.
 Value isTvAdManager.SESSION_DATA_TYPE_AD_REQUEST,TvAdManager.SESSION_DATA_TYPE_AD_BUFFER_READY,TvAdManager.SESSION_DATA_TYPE_BROADCAST_INFO_REQUEST, orTvAdManager.SESSION_DATA_TYPE_REMOVE_BROADCAST_INFO_REQUEST | 
| data | Bundle: the related data values
 This value cannot benull. | 
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:trueif you want to enable the media view.falseotherwise. | 
