public final class TvInputManager extends Object
Context.getSystemService(Context.TV_INPUT_SERVICE)
.
There are three primary parties involved in the TV input framework (TIF) architecture:
TvInputService
represents an input source
of TV, which can be a pass-through input such as HDMI, or a tuner input which provides broadcast
TV programs. The system binds to the TV input per application’s request.
on implementing TV inputs.
TvView
or
TvRecordingClient
for further interaction such as watching and recording broadcast TV
programs.
Modifier and Type | Class and Description |
---|---|
static class |
TvInputManager.Hardware
The Hardware provides the per-hardware functionality of TV hardware.
|
static class |
TvInputManager.HardwareCallback
Interface used to receive events from Hardware objects.
|
static interface |
TvInputManager.InputState |
static interface |
TvInputManager.RecordingError |
static class |
TvInputManager.Session
The Session provides the per-session functionality of TV inputs.
|
static class |
TvInputManager.SessionCallback
Interface used to receive the created session.
|
static interface |
TvInputManager.TimeShiftStatus |
static class |
TvInputManager.TvInputCallback
Callback used to monitor status of the TV inputs.
|
static interface |
TvInputManager.VideoUnavailableReason |
Constructor and Description |
---|
TvInputManager(ITvInputManager service,
int userId) |
Modifier and Type | Method and Description |
---|---|
TvInputManager.Hardware |
acquireTvInputHardware(int deviceId,
TvInputInfo info,
TvInputManager.HardwareCallback callback)
Acquires
TvInputManager.Hardware object for the given device ID. |
TvInputManager.Hardware |
acquireTvInputHardware(int deviceId,
TvInputManager.HardwareCallback callback,
TvInputInfo info)
Acquires
TvInputManager.Hardware object for the given device ID. |
void |
addBlockedRating(TvContentRating rating)
Adds a user blocked content rating.
|
boolean |
captureFrame(String inputId,
Surface surface,
TvStreamConfig config)
Take a snapshot of the given TV input into the provided Surface.
|
void |
createRecordingSession(String inputId,
TvInputManager.SessionCallback callback,
Handler handler)
Creates a recording
TvInputManager.Session for a given TV input. |
void |
createSession(String inputId,
TvInputManager.SessionCallback callback,
Handler handler)
Creates a
TvInputManager.Session for a given TV input. |
List<TvStreamConfig> |
getAvailableTvStreamConfigList(String inputId)
Returns the TvStreamConfig list of the given TV input.
|
List<TvContentRating> |
getBlockedRatings()
Returns the list of blocked content ratings.
|
List<DvbDeviceInfo> |
getDvbDeviceList()
Returns the list of currently available DVB devices on the system.
|
List<TvInputHardwareInfo> |
getHardwareList()
Returns a list of TvInputHardwareInfo objects representing available hardware.
|
int |
getInputState(String inputId)
Returns the state of a given TV input.
|
List<TvContentRatingSystemInfo> |
getTvContentRatingSystemList()
Returns the list of all TV content rating systems defined.
|
TvInputInfo |
getTvInputInfo(String inputId)
Returns the
TvInputInfo for a given TV input. |
List<TvInputInfo> |
getTvInputList()
Returns the complete list of TV inputs on the system.
|
boolean |
isParentalControlsEnabled()
Returns the user's parental controls enabled state.
|
boolean |
isRatingBlocked(TvContentRating rating)
Checks whether a given TV content rating is blocked by the user.
|
boolean |
isSingleSessionActive()
Returns true if there is only a single TV input session.
|
ParcelFileDescriptor |
openDvbDevice(DvbDeviceInfo info,
int device)
Returns a
ParcelFileDescriptor of a specified DVB device for a given
DvbDeviceInfo |
void |
registerCallback(TvInputManager.TvInputCallback callback,
Handler handler)
Registers a
TvInputManager.TvInputCallback . |
void |
releaseTvInputHardware(int deviceId,
TvInputManager.Hardware hardware)
Releases previously acquired hardware object.
|
void |
removeBlockedRating(TvContentRating rating)
Removes a user blocked content rating.
|
void |
setParentalControlsEnabled(boolean enabled)
Sets the user's parental controls enabled state.
|
void |
unregisterCallback(TvInputManager.TvInputCallback callback)
Unregisters the existing
TvInputManager.TvInputCallback . |
void |
updateTvInputInfo(TvInputInfo inputInfo)
Updates the
TvInputInfo for an existing TV input. |
public static final int DVB_DEVICE_DEMUX
public static final int DVB_DEVICE_DVR
public static final int DVB_DEVICE_FRONTEND
public static final int VIDEO_UNAVAILABLE_REASON_UNKNOWN
TvInputService.Session.notifyVideoUnavailable(int)
and
TvView.TvInputCallback.onVideoUnavailable(String, int)
: Video is unavailable due to
an unspecified error.public static final int VIDEO_UNAVAILABLE_REASON_TUNING
TvInputService.Session.notifyVideoUnavailable(int)
and
TvView.TvInputCallback.onVideoUnavailable(String, int)
: Video is unavailable because
the corresponding TV input is in the middle of tuning to a new channel.public static final int VIDEO_UNAVAILABLE_REASON_WEAK_SIGNAL
TvInputService.Session.notifyVideoUnavailable(int)
and
TvView.TvInputCallback.onVideoUnavailable(String, int)
: Video is unavailable due to
weak TV signal.public static final int VIDEO_UNAVAILABLE_REASON_BUFFERING
TvInputService.Session.notifyVideoUnavailable(int)
and
TvView.TvInputCallback.onVideoUnavailable(String, int)
: Video is unavailable because
the corresponding TV input has stopped playback temporarily to buffer more data.public static final int VIDEO_UNAVAILABLE_REASON_AUDIO_ONLY
TvInputService.Session.notifyVideoUnavailable(int)
and
TvView.TvInputCallback.onVideoUnavailable(String, int)
: Video is unavailable because
the current TV program is audio-only.public static final int TIME_SHIFT_STATUS_UNKNOWN
TvInputService.Session.notifyTimeShiftStatusChanged(int)
and
TvView.TvInputCallback.onTimeShiftStatusChanged(String, int)
: Unknown status. Also
the status prior to calling notifyTimeShiftStatusChanged
.public static final int TIME_SHIFT_STATUS_UNSUPPORTED
TvInputService.Session.notifyTimeShiftStatusChanged(int)
and
TvView.TvInputCallback.onTimeShiftStatusChanged(String, int)
: The current TV input
does not support time shifting.public static final int TIME_SHIFT_STATUS_UNAVAILABLE
TvInputService.Session.notifyTimeShiftStatusChanged(int)
and
TvView.TvInputCallback.onTimeShiftStatusChanged(String, int)
: Time shifting is
currently unavailable but might work again later.public static final int TIME_SHIFT_STATUS_AVAILABLE
TvInputService.Session.notifyTimeShiftStatusChanged(int)
and
TvView.TvInputCallback.onTimeShiftStatusChanged(String, int)
: Time shifting is
currently available. In this status, the application assumes it can pause/resume playback,
seek to a specified time position and set playback rate and audio mode.public static final long TIME_SHIFT_INVALID_TIME
TvInputService.Session.onTimeShiftGetCurrentPosition()
and
TvInputService.Session.onTimeShiftGetStartPosition()
when time shifting has not
yet started.public static final int RECORDING_ERROR_UNKNOWN
TvInputService.RecordingSession.notifyError(int)
and
TvRecordingClient.RecordingCallback.onError(int)
: The requested operation cannot be
completed due to a problem that does not fit under any other error codes, or the error code
for the problem is defined on the higher version than application's
android:targetSdkVersion
.public static final int RECORDING_ERROR_INSUFFICIENT_SPACE
TvInputService.RecordingSession.notifyError(int)
and
TvRecordingClient.RecordingCallback.onError(int)
: Recording cannot proceed due to
insufficient storage space.public static final int RECORDING_ERROR_RESOURCE_BUSY
TvInputService.RecordingSession.notifyError(int)
and
TvRecordingClient.RecordingCallback.onError(int)
: Recording cannot proceed because
a required recording resource was not able to be allocated.public static final int INPUT_STATE_CONNECTED
getInputState(String)
and
TvInputManager.TvInputCallback.onInputStateChanged(String, int)
: The input source is connected.
This state indicates that a source device is connected to the input port and is in the normal operation mode. It is mostly relevant to hardware inputs such as HDMI input. This is the default state for any hardware inputs where their states are unknown. Non-hardware inputs are considered connected all the time.
public static final int INPUT_STATE_CONNECTED_STANDBY
getInputState(String)
and
TvInputManager.TvInputCallback.onInputStateChanged(String, int)
: The input source is connected but
in standby mode.
This state indicates that a source device is connected to the input port but is in standby mode. It is mostly relevant to hardware inputs such as HDMI input.
public static final int INPUT_STATE_DISCONNECTED
getInputState(String)
and
TvInputManager.TvInputCallback.onInputStateChanged(String, int)
: The input source is disconnected.
This state indicates that a source device is disconnected from the input port. It is mostly relevant to hardware inputs such as HDMI input.
public static final String ACTION_BLOCKED_RATINGS_CHANGED
isRatingBlocked(android.media.tv.TvContentRating)
.public static final String ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED
isParentalControlsEnabled()
.public static final String ACTION_QUERY_CONTENT_RATING_SYSTEMS
The TV input manager service locates available content rating systems by querying broadcast receivers that are registered for this action. An application can offer additional content rating systems to the user by declaring a suitable broadcast receiver in its manifest.
Here is an example broadcast receiver declaration that an application might include in its AndroidManifest.xml to advertise custom content rating systems. The meta-data specifies a resource that contains a description of each content rating system that is provided by the application.
<receiver android:name=".TvInputReceiver"> <intent-filter> <action android:name= "android.media.tv.action.QUERY_CONTENT_RATING_SYSTEMS" /> </intent-filter> <meta-data android:name="android.media.tv.metadata.CONTENT_RATING_SYSTEMS" android:resource="@xml/tv_content_rating_systems" /> </receiver>
In the above example, the @xml/tv_content_rating_systems
resource refers to an
XML resource whose root element is <rating-system-definitions>
that
contains zero or more <rating-system-definition>
elements. Each
<rating-system-definition>
element specifies the ratings, sub-ratings and rating
orders of a particular content rating system.
TvContentRating
,
Constant Field Valuespublic static final String META_DATA_CONTENT_RATING_SYSTEMS
ACTION_QUERY_CONTENT_RATING_SYSTEMS
.
Specifies the resource ID of an XML resource that describes the content rating systems that are provided by the application.
public static final String ACTION_SETUP_INPUTS
TvInputInfo.TYPE_TUNER
. When invoked, the system will display an appropriate UI for
the user to initiate the individual setup flow provided by
android.R.attr#setupActivity
of each TV input service.public List<TvInputInfo> getTvInputList()
TvInputInfo
for each TV input that describes its meta information.public TvInputInfo getTvInputInfo(String inputId)
TvInputInfo
for a given TV input.inputId
- The ID of the TV input.TvInputInfo
for a given TV input. null
if not found.public void updateTvInputInfo(TvInputInfo inputInfo)
TvInputInfo
for an existing TV input. A TV input service
implementation may call this method to pass the application and system an up-to-date
TvInputInfo
object that describes itself.
The system automatically creates a TvInputInfo
object for each TV input,
based on the information collected from the AndroidManifest.xml
, thus it is not
necessary to call this method unless such information has changed dynamically.
Use TvInputInfo.Builder
to build a new TvInputInfo
object.
Attempting to change information about a TV input that the calling package does not own does nothing.
inputInfo
- The TvInputInfo
object that contains new information.IllegalArgumentException
- if the argument is null
.TvInputManager.TvInputCallback.onTvInputInfoUpdated(TvInputInfo)
public int getInputState(String inputId)
The state is one of the following:
inputId
- The ID of the TV input.IllegalArgumentException
- if the argument is null
.public void registerCallback(TvInputManager.TvInputCallback callback, Handler handler)
TvInputManager.TvInputCallback
.callback
- A callback used to monitor status of the TV inputs.handler
- A Handler
that the status change will be delivered to.public void unregisterCallback(TvInputManager.TvInputCallback callback)
TvInputManager.TvInputCallback
.callback
- The existing callback to remove.public boolean isParentalControlsEnabled()
true
if the user enabled the parental controls, false
otherwise.public void setParentalControlsEnabled(boolean enabled)
enabled
- The user's parental controls enabled state. true
if the user enabled
the parental controls, false
otherwise.isParentalControlsEnabled()
public boolean isRatingBlocked(TvContentRating rating)
rating
- The TV content rating to check. Can be TvContentRating.UNRATED
.true
if the given TV content rating is blocked, false
otherwise.public List<TvContentRating> getBlockedRatings()
public void addBlockedRating(TvContentRating rating)
rating
- The content rating to block.isRatingBlocked(android.media.tv.TvContentRating)
,
removeBlockedRating(android.media.tv.TvContentRating)
public void removeBlockedRating(TvContentRating rating)
rating
- The content rating to unblock.isRatingBlocked(android.media.tv.TvContentRating)
,
addBlockedRating(android.media.tv.TvContentRating)
public List<TvContentRatingSystemInfo> getTvContentRatingSystemList()
public void createSession(String inputId, TvInputManager.SessionCallback callback, Handler handler)
TvInputManager.Session
for a given TV input.
The number of sessions that can be created at the same time is limited by the capability of the given TV input.
inputId
- The ID of the TV input.callback
- A callback used to receive the created session.handler
- A Handler
that the session creation will be delivered to.public void createRecordingSession(String inputId, TvInputManager.SessionCallback callback, Handler handler)
TvInputManager.Session
for a given TV input.
The number of sessions that can be created at the same time is limited by the capability of the given TV input.
inputId
- The ID of the TV input.callback
- A callback used to receive the created session.handler
- A Handler
that the session creation will be delivered to.public List<TvStreamConfig> getAvailableTvStreamConfigList(String inputId)
TvInputManager.Hardware
object from acquireTvInputHardware(int, android.media.tv.TvInputManager.HardwareCallback, android.media.tv.TvInputInfo)
, you should get the list of available streams
from TvInputManager.HardwareCallback.onStreamConfigChanged(android.media.tv.TvStreamConfig[])
method, not from
here. This method is designed to be used with captureFrame(java.lang.String, android.view.Surface, android.media.tv.TvStreamConfig)
in
capture scenarios specifically and not suitable for any other use.inputId
- The ID of the TV input.TvStreamConfig
which is available for capturing
of the given TV input.public boolean captureFrame(String inputId, Surface surface, TvStreamConfig config)
inputId
- The ID of the TV input.surface
- the Surface
to which the snapshot is captured.config
- the TvStreamConfig
which is used for capturing.Surface
is ready to be captured.public boolean isSingleSessionActive()
public List<TvInputHardwareInfo> getHardwareList()
public TvInputManager.Hardware acquireTvInputHardware(int deviceId, TvInputManager.HardwareCallback callback, TvInputInfo info)
TvInputManager.Hardware
object for the given device ID.
A subsequent call to this method on the same deviceId
will release the currently
acquired Hardware.
deviceId
- The device ID to acquire Hardware for.callback
- A callback to receive updates on Hardware.info
- The TV input which will use the acquired Hardware.null
otherwise.public TvInputManager.Hardware acquireTvInputHardware(int deviceId, TvInputInfo info, TvInputManager.HardwareCallback callback)
TvInputManager.Hardware
object for the given device ID.
A subsequent call to this method on the same deviceId
will release the currently
acquired Hardware.
deviceId
- The device ID to acquire Hardware for.callback
- A callback to receive updates on Hardware.info
- The TV input which will use the acquired Hardware.null
otherwise.public void releaseTvInputHardware(int deviceId, TvInputManager.Hardware hardware)
deviceId
- The device ID this Hardware was acquired forhardware
- Hardware to release.public List<DvbDeviceInfo> getDvbDeviceList()
DvbDeviceInfo
objects representing available DVB devices.public ParcelFileDescriptor openDvbDevice(DvbDeviceInfo info, int device)
ParcelFileDescriptor
of a specified DVB device for a given
DvbDeviceInfo
info
- A DvbDeviceInfo
to open a DVB device.device
- A DVB device. The DVB device can be DVB_DEVICE_DEMUX
,
DVB_DEVICE_DVR
or DVB_DEVICE_FRONTEND
.ParcelFileDescriptor
of a specified DVB device for a given
DvbDeviceInfo
, or null
if the given DvbDeviceInfo
was invalid
or the specified DVB device was busy with a previous request.