The article is mainly recording the following skills
–>Android TIF code Structure and flow
–>How to use TIF in Tv App
References:
http://blog.csdn.net/wangmxe/article/details/50528682
http://blog.csdn.net/zhudaozhuan/article/details/50849542
1: TIF architecture
1.1: TIF OverView
The Android TV Input Framework (TIF) simplifies the delivery of content to Android TV. The TIF provides a standard API for manufacturers to use in constructing input modules for controlling
Android TV.
The Android TV Input Framework includes a TV Input Manager and an example TV App that works with a special remote control to access builtin and IP tuner channels.
In all, the TV Input Framework consists of:
● TV Provider (com.android.providers.tv.TvProvider) a database of channels, programs and associated permissions
● TV Input Manager (android.media.tv.TvInputManager) brokers
communication between the TV Inputs and TV App
● TV Input an application provided by the OEM, Google or third parties to route content
● TV App (com.android.tv.TvActivity) the application provided by the OEM or Google for user interaction
● HDMICEC the technology to allow remote control of various devices over HDMI
1.2: TIF Directory Structure
1.3: TIF Main Class
- TvView: Displays TV contents. The TvView class provides a high level interface for applications to show TV programs from various TV sources that implement {@link TvInputService}
–>TvInputCallback: Callback used to receive various status updates on the {@link TvView} - TvInputManager: Central system API to the overall TV input framework (TIF) architecture, which arbitrates interaction between applications and the selected TV inputs.
–>SessionCallback: Interface used to receive the created session,
–>TvInputCallback: Callback used to monitor status of the TV input
–>Session: The Session provides the per-session functionality of TV inputs - TvInputManagerService: This class provides a system service that manages television inputs.
- TvInputService: all of the input device must inherit the class.The TvInputService class represents a TV input or source such as HDMI or built-in tuner which provides pass-through video or broadcast TV programs.
1.4: TIS init flow
2: how to use TIF
2.1: create session
{
mTvInputManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE);
if (mTvInputManager != null) {
observerCallback = new ObserverSessionCallback();
List inputlist = mTvInputManager.getTvInputList();
if (inputlist != null) {
for (int i = 0; i < inputlist.size(); i++) {
TvInputInfo tinfo = (TvInputInfo) inputlist.get(i);
if ((tinfo.getType() == TvInputInfo.TYPE_TUNER) &&
(tinfo.getComponent().getPackageName().equals(ITVSessionContext.TUNERSERVICE_PKG_ID))) {
tunerServiceId = tinfo.getId();
Log.d(tag, "TunerService ID = " + tunerServiceId);
break;
}
}
}
if (mTvInputManager.getInputState(tunerServiceId) == TvInputManager.INPUT_STATE_CONNECTED) {
Log.d(tag, "creating the session,waiting for call back");
mTvInputManager.createSession(tunerServiceId, observerCallback, mSessionHandler);
} else {
Log.d(tag, "input tuner not added yet,waiting for call back");
}
} else {
Log.d(tag, "Could not get system service TV_INPUT_SERVICE!!");
}
}
2.2: inherit SessionCallback
public class ObserverSessionCallback extends SessionCallback {
Session mySession = null;
public void onSessionCreated(Session session) {
Log.d(tag, "onSessionCreated ");
if (session != null) {
Log.d(tag, "Session creation successful");
mySession = session;
String action = ITVSessionContext.APP_PRIVATE_COMMAND_SESSION_TYPE;
Bundle bundle = new Bundle();
bundle.putString(ITVSessionContext.KEY_SESSION_TYPE, ITVSessionContext.SESSION_TYPE_MAIN_OBSERVER);
mySession.sendAppPrivateCommand(action, bundle);
} else {
Log.d(tag, "Session creation failed");
}
}
public void onSessionReleased(Session session) {
Log.d(tag, "onSessionReleased called");
mySession = null;
mObserverSessionContext = null;
}
public void onChannelRetuned(Session session, Uri channelUri) {
}
public void onVideoUnavailable(Session session, int reason) {
}
public void onSessionEvent(Session session, String eventType, Bundle eventArgs) {
Log.i(tag, "onSessionEvent " + this);
if (eventType.equals(ITVSessionContext.EVENT_SESSION_CONTEXT_CREATED)) {
IBinder binder = eventArgs.getBinder(ITVSessionContext.SESSION_CONTEXT);
mObserverSessionContext = ITVSessionContext.instance.asInterface(binder);
ObserverSessionContextCallbacks mainSessionContextCallbacks = new ObserverSessionContextCallbacks();
mObserverSessionContext.registerSessionContextCallbacks(mainSessionContextCallbacks);
}
}
}
commit id: 98c0c6e7d5ffcefd0e939f6a5f2b40e30ee69cb2