1page.title=TV Input Framework 2@jd:body 3 4<!-- 5 Copyright 2014 The Android Open Source Project 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18--> 19<div id="qv-wrapper"> 20 <div id="qv"> 21 <h2>In this document</h2> 22 <ol id="auto-toc"> 23 </ol> 24 </div> 25</div> 26 27<h2 id=introduction>Introduction</h2> 28 29<p>The Android TV Input Framework (TIF) simplifies the delivery of live content to 30Android TV. The Android TIF provides a standard API for manufacturers to use to 31create input modules for controlling Android TV. It also enables live TV search 32and recommendations via metadata published by the TV Input. The framework does 33not seek to implement TV standards or regional requirements.</p> 34 35<p>The Android TIF makes it easier for device manufacturers to meet regional digital TV 36broadcast standards without re-implementation. This document may also inform 37third-party app developers who would like to create custom TV Inputs.</p> 38 39<h2 id=components>Components</h2> 40 41<p>The Android TV Input Framework implementation includes a TV Input Manager. 42The TIF works with the TV App, a system app that can’t be replaced by a 43third-party app, to access built-in and IP tuner channels. The TV App 44communicates with TV Input modules supplied by the device manufacturer or other 45parties through the TV Input Manager.</p> 46 47<p>The TV Input Framework consists of:</p> 48 49<ul> 50 <li>TV Provider (<code>com.android.providers.tv.TvProvider</code>): a database of channels, programs, and associated permissions 51 <li>TV App (<code>com.android.tv.TvActivity</code>): the app that handles user interaction 52 <li>TV Input Manager (<code>android.media.tv.TvInputManager</code>): allows the TV Inputs to communicate with the TV App 53 <li>TV Input: an app representing physical or virtual tuners and input ports 54 <li>TV Input HAL (<code>tv_input</code> module): a hardware definition that allows system TV Inputs to access 55TV-specific hardware when implemented 56 <li>Parental Control: the technology to allow blocking of channels and programs 57 <li>HDMI-CEC: the technology to allow remote control of various devices over HDMI 58</ul> 59 60<p>These components are covered in detail below. See the following diagram for a 61detailed view of the Android TV Input Framework architecture.</p> 62 63<img src="images/TIF_Overview.png" alt="Overview of the Android TIF architecture"> 64<p class="img-caption"><strong>Figure 1.</strong> Android TV Input Framework (TIF) architecture</p> 65 66<h2 id=flow>Flow</h2> 67 68<p>Here is how the architecture is exercised:</p> 69 70<ol> 71 <li>The user sees and interacts with the TV App, a system app that can’t be 72replaced by a third-party app. 73 <li>The TV App displays the AV content from the TV Input. 74 <li>The TV App cannot talk directly with the TV Inputs. The TV Input Manager 75identifies the state of TV Inputs for the TV App. See <em>TV Input Manager</em> below for more details about these limitations. 76</ol> 77 78<h2 id=permissions>Permissions</h2> 79 80<ul> 81 <li>Only <code><a 82href="http://developer.android.com/guide/topics/manifest/permission-element.html#plevel">signatureOrSystem</a></code> 83TV Inputs and TV App have full access to the TV Provider database and are able 84to receive KeyEvents. 85 <li>Only system TV Inputs can access the TV Input HAL through the TV Input Manager 86service. TV Inputs are accessed one-to-one via TV Input Manager sessions. 87 <li>Third-party TV Inputs have package-locked access to the TV Provider database 88and can READ/WRITE only to matching package rows. 89 <li>Third-party TV inputs can either display their own content or content from a 90device manufacturer’s passthrough TV inputs, like HDMI1. They can’t display 91content from non-passthrough TV inputs, like a built-in or IPTV tuner. 92 <li><code>TV_INPUT_HARDWARE</code> permission for a hardware TV Input app, signals the TV Input Manager Service 93to notify the TV Input service on boot to call the TV Input Manager Service and 94add its TV Inputs. This permission allows a hardware TV Input app to support 95multiple TV Inputs per TV Input service, as well as being able to dynamically 96add and remove its supported TV Inputs. 97</ul> 98 99<h2 id=tv_provider>TV Provider</h2> 100 101<p>The TV Provider database stores the channels and programs from TV Inputs. The 102TV Provider also publishes and manages the associated permissions so that TV 103Inputs can see only their own records. For instance, a specific TV Input can 104see only the channels and programs it has supplied and is prohibited from 105accessing any other TV Inputs’ channels and programs. </p> 106 107<p>The TV Provider maps "broadcast genre" to "canonical genre" internally. TV 108Inputs are responsible for populating "broadcast genre" with the value in the 109underlying broadcast standard, and the "canonical genre" field will 110automatically be populated with the correct associated genre from <code>android.provider.TvContract.Genres</code>. For example, with broadcast standard ATSC A/65 and program with genre 0x25 111(meaning “Sports”), the TV Input will populate the “broadcast genre” with the 112String “Sports” and TV Provider will populate the “canonical genre” field with 113the mapped value <code>android.provider.TvContract.Genres.SPORTS</code>.</p> 114 115<p>See the diagram below for a detailed view of the TV Provider. </p> 116 117<img src="images/TIF_TV_Provider.png" alt="Android TV Provider"> 118<p class="img-caption"><strong>Figure 2.</strong> Android TV Provider</p> 119 120<p><em>Only apps in the privileged system partition can read the entire TV Provider 121database. </em></p> 122 123<p>Passthrough TV inputs do not store channels and programs. </p> 124 125<p>In addition to the standard fields for channels and programs, the TV Provider 126database also offers a BLOB type field, <code>COLUMN_INTERNAL_PROVIDER_DATA</code>, in each table that TV Inputs may use to store arbitrary data. That BLOB data 127can include custom information, such as frequency of the associated tuner, and 128may be provided in a protocol buffer or another form. A Searchable field is 129available to make certain channels unavailable in search (such as to meet 130country-specific requirements for content protection).</p> 131 132<h3 id=tv_provider_database_field_examples>Database field examples</h3> 133 134<p>The TV Provider supports structured data in channel (<code>android.provider.TvContract.Channels</code>) and program (<code>android.provider.TvContract.Programs</code>) tables. These tables are populated and accessed by TV Inputs and system apps 135like the TV App. These tables have four types of fields:</p> 136 137<ul> 138 <li><strong>Display: </strong>Display fields contain information that apps may want to make visible to the 139user, like a channel’s name (<code>COLUMN_DISPLAY_NAME</code>) or number (<code>COLUMN_DISPLAY_NUMBER</code>), or the title of the program being viewed. 140 <li><strong>Metadata:</strong> There are three fields for identifying content, according to relevant 141standards, like a channel’s transport stream ID (<code>COLUMN_TRANSPORT_STREAM_ID</code>), original network ID (<code>COLUMN_ORIGINAL_NETWORK_ID</code>) and service id (<code>COLUMN_SERVICE_ID</code>). 142 <li><strong>Internal data</strong>: Fields that are for the custom use of TV Inputs.<br> 143 Some fields, like <code>COLUMN_INTERNAL_PROVIDER_DATA</code>, are customizable BLOB fields where a TV Input can store arbitrary metadata 144about their channel or program. 145 <li><strong>Flag: </strong>Flag fields represent whether a channel should be restricted from search, 146browse, or viewing. This can be set only at the channel level. All programs 147defer to the setting on the channel. 148 <ul> 149 <li><code>COLUMN_SEARCHABLE</code>: Restricting search from some channels may be a requirement in certain 150regions. <code>COLUMN_SEARCHABLE = 0</code> means the channel should not be exposed in search results. 151 <li><code>COLUMN_BROWSABLE</code>: Visible to system applications only. Restricting channel from being browsed 152by applications. <code>COLUMN_BROWSABLE = 0</code> means the channel should not be included in the channel list. 153 <li><code>COLUMN_LOCKED</code>: Visible to system applications only. Restricting channel from being viewed by 154invalid accounts without entering PIN code. <code>COLUMN_LOCKED = 1</code> means the channel should be protected by parental control. 155 </ul> 156</ul> 157 158<p>For a more exhaustive list of the fields, see <code>android/frameworks/base/media/java/android/media/tv/TvContract.java</code></p> 159 160<h3 id=permissions_and_access_control>Permissions and access control</h3> 161 162<p>All fields are visible to anyone with access to the corresponding row. No 163fields are directly accessible to users; they see only what the TV App, System 164apps, or TV Inputs surface.</p> 165 166<ul> 167 <li>Each row has <code>PACKAGE_NAME</code>, the package (app) that owns that row, checked on Query, Insert, Update via 168TvProvider.java. 169A TV Input may access only the information it wrote and is 170cordoned off from the information provided by other TV Inputs. 171 <li>READ, WRITE permissions via AndroidManifest.xml (requires user consent) to 172determine available channels. 173 <li>Only <code>signatureOrSystem</code> apps can acquire <code>ACCESS_ALL_EPG_DATA</code> permission to access the entire database. 174</ul> 175 176<h2 id=tv_input_manager>TV Input Manager</h2> 177 178<p>The TV Input Manager provides a central system API to the overall Android TV 179Input Framework. It arbitrates interaction between apps and TV Inputs and 180provides parental control functionality. TV Input Manager sessions must be 181created one-to-one with TV Inputs. The TV Input Manager allows access to 182installed TV Inputs so apps may:</p> 183 184<ul> 185 <li>List TV inputs and check their status 186 <li>Create sessions and manage listeners 187</ul> 188 189<p>For sessions, a TV Input may be tuned by the TV App only to URIs it has added 190to the TV Provider database, except for passthrough TV Inputs which can be 191tuned to using <code>TvContract.buildChannelUriForPassthroughInput()</code>. A TV Input may also have its volume set. TV Inputs provided and signed by the 192device manufacturer (signature apps) or other apps installed in the system 193partition will have access to the entire TV Provider database. This access can 194be used to construct apps to browse and search across all available TV channels 195and programs.</p> 196 197<p>An app may create and register a <code>TvInputCallback</code> with the <code>android.media.tv.TvInputManager</code> to be called back on a TV Input’s state change or on the addition or removal 198of a TV Input. For example, a TV App can react when a TV Input is disconnected 199by displaying it as disconnected and preventing its selection.</p> 200 201<p>The TV Input Manager abstracts communication between the TV App and TV Inputs. 202The standard interface of TV Input Manager and TV Input allows multiple 203device manufacturers to create their own TV Apps while helping all third-party TV Inputs 204work on all TV Apps.</p> 205 206<h2 id=tv_inputs>TV Inputs</h2> 207 208<p>TV Inputs are Android apps in the sense they have an AndroidManifest.xml and 209are installed (via Play, pre-installed, or sideloaded). Android TV supports 210pre-installed system apps, apps signed by the device manufacturer and 211third-party TV Inputs. </p> 212 213<p>Some inputs, like the HDMI input or built-in tuner input, can be provided only 214by the manufacturer as they speak directly with the underlying hardware. 215Others, such as IPTV, place-shifting, and external STB, can be supplied by 216third parties as APKs on Google Play Store. Once downloaded and installed, the 217new input can be selected within the TV App.</p> 218 219<h3 id=passthrough_input_example>Passthrough input example</h3> 220 221<img src="images/TIF_HDMI_TV_Input.png" alt="Android TV System Input"> 222<p class="img-caption"><strong>Figure 3.</strong> Android TV System Input</p> 223 224<p>In this example, the TV Input provided by the device manufacturer is trusted 225and has full access to the TV Provider. As a passthrough TV Input, it does not 226register any channels or programs with the TV Provider. To obtain the URI used 227to reference the passthrough input, use the <code>android.media.tv.TvContract</code> utility method <code>buildChannelUriForPassthroughInput(String inputId)</code>. The TV App communicates with the TV Input Manager to reach the HDMI TV 228Input. </p> 229 230<h3 id=built-in_tuner_example>Built-in tuner example</h3> 231 232<img src="images/Built-in_Tuner_TV_Input.png" alt="Android TV Built-in Tuner Input"> 233<p class="img-caption"><strong>Figure 4.</strong> Android TV Built-in Tuner Input</p> 234 235<p>In this example, the Built-in Tuner TV Input provided by the device 236manufacturer is trusted and has full access to the TV Provider. </p> 237 238<h3 id=third-party_input_example>Third-party input example</h3> 239 240<img src="images/Third-party_Input_HDMI.png" alt="Android TV third-party input"> 241<p class="img-caption"><strong>Figure 5.</strong> Android TV third-party input</p> 242 243<p>In this example, the external STB TV Input is provided by a third party. Since 244that TV Input can’t directly access the HDMI video feed coming in, it must go 245through the TV Input Manager and use the HDMI TV Input provided by the device 246manufacture.</p> 247 248<p>Through the TV Input Manager, the external STB TV Input can speak with the HDMI 249TV Input and ask it to show the video on HDMI1. So the STB TV Input can control 250the TV while the manufacturer-provided HDMI TV Input renders the video.</p> 251 252<h3 id=picture_in_picture_pip_example>Picture in picture (PIP) example </h3> 253 254<img src="images/TIF_PIP-PAP.png" alt="Android TV KeyEvents"> 255<p class="img-caption"><strong>Figure 6.</strong> Android TV KeyEvents</p> 256 257<p>The diagram above shows how buttons on a remote control are passed to a 258specific TV Input for picture in picture (PIP) display. Those button presses 259are interpreted by the hardware driver supplied by the device manufacturer, 260converting hardware scancodes to Android keycodes and passing them to the 261standard Android <a href="http://source.android.com/devices/tech/input/overview.html">input pipeline</a> <code>InputReader</code> and <code>InputDispatcher</code> functions as <a href="http://developer.android.com/reference/android/view/KeyEvent.html">KeyEvents</a>. These in turn trigger events on the TV App if it is in focus. </p> 262 263<p>Only system TV Inputs are eligible to receive <code>InputEvents</code>, and only if they have the <code>RECEIVE_INPUT_EVENT</code> system permission. The TV Input is responsible to determine which InputEvents 264to consume and should allow the TV App to handle the keys it does not need to 265consume.</p> 266 267<p>The TV App is responsible for knowing which system TV Input is active, meaning 268selected by the user, and to disambiguate incoming <code>KeyEvents</code> and route them to the correct TV Input Manager session, calling <code>dispatchInputEvent()</code> to pass on the event to the associated TV Input. </p> 269 270<h3 id=mheg-5_input_example>MHEG-5 input example</h3> 271 272<p>The following diagram shows a more detailed view of how <code>KeyEvents</code> are routed through the Android TIF.</p> 273 274<img src="images/TIF_MHEG5_app.png" alt="Android TV Red button example"> 275<p class="img-caption"><strong>Figure 7.</strong> Android TV Red button example</p> 276 277<p>It depicts the flow of a Red button app, common in Europe for letting users 278access interactive apps on their televisions. An app can be delivered over this 279transport stream. When the button is clicked, it lets users interact with these 280broadcast apps. For example, you might use these broadcast apps to access 281related web pages or sports scores.</p> 282 283<p>See the <em>Broadcast app</em> section to learn how broadcast apps interact with the TV App.</p> 284 285<p>In this example:</p> 286 287<ol> 288 <li>The TV App is in focus and receives all keys. 289 <li><code>KeyEvents</code> (e.g. the Red button) is passed to the active TV Input as <code>InputEvents.</code> 290 <li>The system TV Input integrates with MHEG-5 stack and has the <code>RECEIVE_INPUT_EVENT</code> system permission. 291 <li>On receiving activation keycode (e.g. Red button), the TV Input activates 292broadcast app. 293 <li>TV input consumes <code>KeyEvents</code> as <code>InputEvents</code> and the broadcast app is the focus and handles <code>InputEvents</code> until dismissed. 294</ol> 295 296<p class="note"><strong>Note</strong>: Third-party TV inputs never receive keys. </p> 297 298<h2 id=tv_input_hal>TV Input HAL</h2> 299 300<p>The TV Input HAL aids development of TV Inputs to access TV-specific hardware. 301As with other Android HALs, the TV Input HAL (<code>tv_input</code>) is 302available in the AOSP source tree and the vendor develops its implementation.</p> 303 304<h2 id=tv_app>TV App</h2> 305 306<p>The TV App provides channel and program search results (via 307<code>com.android.tv.search.TvProviderSearch</code>) and passes keys, tune, and 308volume calls to TV Inputs through the TV Input 309Manager. Manufacturers must implement the TV App to ensure search functions 310work for their users. Otherwise, users will struggle to navigate the resulting 311Android TV. Third-party developers cannot develop TV Apps as the APIs require 312system or signature permission.</p> 313 314<p>As with the TIF in general, the TV App does not seek to implement device 315manufacturer or country-specific features. Instead, it handles these tasks by 316default:</p> 317 318<h3 id=setup_and_configuration>Setup and configuration</h3> 319 320<ul> 321 <li>Auto-detect TV Inputs 322 <li>Let TV Inputs initiate channel setup 323 <li>Control parental settings 324 <li>Alter TV settings 325 <ul> 326 <li>Edit channel 327 </ul> 328</ul> 329 330<h3 id=viewing>Viewing</h3> 331<ul> 332 <li>Access and navigate all TV channels 333 <li>Access TV program information bar 334 <li>Multiple audio and subtitle track support 335 <li>Parental control PIN challenge 336 <li>Allow TV Input UI overlay for: 337 <ul> 338 <li>TV standard (HbbTV, etc.) 339 </ul> 340</ul> 341 342<h2 id=parental_control>Parental Control</h2> 343 344<p>Parental control lets a user block undesired channels and programs, but bypass 345the block by entering a PIN code.</p> 346 347<p>Responsibility for parental control functionality is shared amongst the TV App, 348TV Input Manager service, TV Provider, and TV Input. </p> 349 350<h3 id=tv_provider>TV Provider</h3> 351 352<p>Each channel row has a <code>COLUMN_LOCKED</code> field that is used to lock 353specific channels from viewing without entering a PIN code. The program field 354<code>COLUMN_CONTENT_RATING</code> is intended for display and is not used to 355enforce parental control.</p> 356 357<h3 id=tv_input_manager>TV Input Manager</h3> 358 359<p>The TV Input Manager stores every blocked <code>TvContentRating</code> and 360responds to <code>isRatingBlocked()</code> to advise if content with the given 361rating should be blocked.</p> 362 363<h3 id=tv_input>TV Input</h3> 364 365<p>The TV Input checks if the current content should be blocked by calling 366<code>isRatingBlocked()</code> on the TV Input Manager when the rating of the 367displayed content has changed 368(on program or channel change), or parental control settings have changed (on 369<code>ACTION_BLOCKED_RATINGS_CHANGED</code> and 370<code>ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED</code>). If the content should 371be blocked, the TV Input disables the audio and video 372and notifies the TV app that the current content is blocked by calling 373<code>notifyContentBlocked(TvContentRating)</code>. If the content should not 374be blocked, the TV Input enables audio and video and notifies the TV App 375the current content is allowed by calling <code>notifyContentAllowed()</code>.</p> 376 377<h3 id=tv_app>TV App</h3> 378 379<p>The TV App shows parental control settings to users and a PIN code UI when it 380is notified by a TV Input that the current content is blocked or when the user 381attempts to view a blocked channel.</p> 382 383<p>The TV App does not directly store the parental control settings. When the user 384changes the parental control settings, every blocked 385<code>TvContentRating</code> is stored by the TV Input Manager, and blocked 386channels are stored by the TV Provider.</p> 387 388<h2 id=hdmi-cec>HDMI-CEC</h2> 389 390<p>HDMI-CEC allows one device to control another, thereby enabling a single remote 391to control multiple appliances in a home theater. It is used by Android TV to 392speed setup and allow distant control over various TV Inputs via the central TV 393App. For instance, it may switch inputs, power up or down devices, and more.</p> 394 395<p>The Android TIF implements HDMI-CEC as the HDMI Control Service so that 396device manufacturers merely need to develop low-level drivers that interact with the 397lightweight Android TV HAL, skipping more complex business logic. In providing 398a standard implementation, Android seeks to mitigate compatibility issues by 399reducing fragmented implementations and selective feature support. The HDMI 400Control Service uses the existing Android services, including input and power.</p> 401 402<p>This means existing HDMI-CEC implementations will need to be redesigned to 403interoperate with the Android TIF. We recommend the hardware platform contain a 404microprocessor to receive CEC power on and other commands.</p> 405 406<img src="images/TV_App_CEC_integration.png" alt="CEC integration on Android TV"> 407<p class="img-caption"><strong>Figure 8.</strong> CEC integration on Android TV</p> 408 409<ol> 410 <li> The CEC bus receives a command from the currently active source to switch to a 411different source. 412 <li> The driver passes the command to the HDMI-CEC HAL. 413 <li> The HAL notifies all <code>ActiveSourceChangeListeners</code>. 414 <li> THe HDMI Control Service is notified of source change via <code>ActiveSourceChangeListener</code>. 415 <li> The TV Input Manager service generates an intent for the TV App to switch the 416source. 417 <li> The TV App then creates a TV Input Manager Session for the TV Input being 418switched to and calls <code>setMain</code> on that session. 419 <li> The TV Input Manager Session passes this information on to the HDMI TV Input. 420 <li> The HDMI TV input requests to set sideband surface. 421 <li> The TV Input Manager Service generates a corresponding routing control command 422back to HDMI Control Service when the surface is set. 423</ol> 424 425<h2 id=tv_integration_guidelines>TV integration guidelines</h2> 426 427<h3 id=broadcast_app>Broadcast app</h3> 428 429<p>Because each country has broadcast-specific requirements (MHEG, Teletext, 430HbbTV, and more), manufacturers are expected to supply their own solutions for 431the broadcast app, for example:</p> 432 433<ul> 434 <li> MHEG: native stack 435 <li> Teletext: native stack 436 <li> HbbTV: webkit modification by Opera browser 437</ul> 438 439<p>In the Android L release, Android TV expects device manufacturers to use systems 440integrators or the Android solutions for regional TV stacks, pass the surface 441to TV software stacks, or pass the necessary key code to interact with legacy 442stacks.</p> 443 444<p>Here’s how the broadcast app and TV App interact:</p> 445 446<ol> 447 <li>The TV App is in focus, receiving all keys. 448 <li>The TV App passes keys (e.g. Red button) to the TV Input device. 449 <li>The TV Input device internally integrates with legacy TV stack. 450 <li>On receiving an activation keycode (e.g. Red button), the TV Input device 451activates broadcast apps. 452 <li>A broadcast app takes focus in the TV App and handles user actions. 453</ol> 454 455<p>For voice search/recommendation, the broadcast app may support In-app search 456for voice search.</p> 457 458<h3 id=dvr>DVR</h3> 459 460<p>Android TV supports digital video recording (DVR) with device manufacturer development. The 461DVR function works like so:</p> 462 463<ol> 464 <li> DVR recording function / Live Buffer can be implemented by any TV Input. 465 <li> TV App passes on key inputs to TV Input (including recording/pause/fast 466forward/ rewind keys). 467 <li> When playing the recorded content, the TV Input handles it with trick play 468overlay. 469 <li> DVR app enables users to browse and manage recorded program. 470</ol> 471 472<p>For voice search/recommendation:</p> 473 474<ul> 475 <li>DVR app supports In-app search for Voice search. 476 <li>DVR app can propose recommendation using notifications. 477</ul> 478 479<p>See the following diagram for a view into a possible DVR implementation in 480Android TV.</p> 481 482<img src="images/TV_Input_DVR.png" alt="Digital video recording in Android TV"> 483<p class="img-caption"><strong>Figure 9.</strong> Digital video recording in Android TV</p> 484