1 <html devsite> 2 <head> 3 <title>TV Input Framework</title> 4 <meta name="project_path" value="/_project.yaml" /> 5 <meta name="book_path" value="/_book.yaml" /> 6 </head> 7 <body> 8 <!-- 9 Copyright 2017 The Android Open Source Project 10 11 Licensed under the Apache License, Version 2.0 (the "License"); 12 you may not use this file except in compliance with the License. 13 You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 --> 23 24 25 26 <img style="float: right; margin: 0px 15px 15px 15px;" src="images/ape_fwk_hal_tv.png" alt="Android TV HAL icon"/> 27 28 <p>The Android TV Input Framework (TIF) simplifies delivery of live content to Android TV. The Android TIF provides a standard API for manufacturers to create input modules for controlling Android TV, and enables live TV search and recommendations via metadata published by the TV Input.</p> 29 <p>The framework does not seek to implement TV standards or regional requirements, but does make it easier for device manufacturers to meet regional digital TV broadcast standards without re-implementation. Documentation in this section might also be useful to third-party app developers who want to create custom TV Inputs.</p> 30 31 <h2 id="components">Components</h2> 32 33 <p>The Android TV Input Framework implementation includes a TV Input Manager. 34 The TIF works with the TV App, a system app that cant be replaced by a 35 third-party app, to access built-in and IP tuner channels. The TV App 36 communicates with TV Input modules supplied by the device manufacturer or other 37 parties through the TV Input Manager.</p> 38 39 <p>The TV Input Framework consists of:</p> 40 41 <ul> 42 <li>TV Provider (<code>com.android.providers.tv.TvProvider</code>): a database of channels, programs, and associated permissions 43 <li>TV App (<code>com.android.tv.TvActivity</code>): the app that handles user interaction 44 <li>TV Input Manager (<code>android.media.tv.TvInputManager</code>): allows the TV Inputs to communicate with the TV App 45 <li>TV Input: an app representing physical or virtual tuners and input ports 46 <li>TV Input HAL (<code>tv_input</code> module): a hardware definition that allows system TV Inputs to access 47 TV-specific hardware when implemented 48 <li>Parental Control: the technology to allow blocking of channels and programs 49 <li>HDMI-CEC: the technology to allow remote control of various devices over HDMI 50 </ul> 51 52 <p>These components are covered in detail below. See the following diagram for a 53 detailed view of the Android TV Input Framework architecture.</p> 54 55 <img src="images/TIF_Overview.png" alt="Overview of the Android TIF architecture"> 56 <p class="img-caption"><strong>Figure 1.</strong> Android TV Input Framework (TIF) architecture</p> 57 58 <h2 id="flow">Flow</h2> 59 60 <p>Here is how the architecture is exercised:</p> 61 62 <ol> 63 <li>The user sees and interacts with the TV App, a system app that cant be 64 replaced by a third-party app. 65 <li>The TV App displays the AV content from the TV Input. 66 <li>The TV App cannot talk directly with the TV Inputs. The TV Input Manager 67 identifies the state of TV Inputs for the TV App. See <em>TV Input Manager</em> below for more details about these limitations. 68 </ol> 69 70 <h2 id="permissions">Permissions</h2> 71 72 <ul> 73 <li>Only <code><a 74 href="http://developer.android.com/guide/topics/manifest/permission-element.html#plevel">signatureOrSystem</a></code> 75 TV Inputs and TV App have full access to the TV Provider database and are able 76 to receive KeyEvents. 77 <li>Only system TV Inputs can access the TV Input HAL through the TV Input Manager 78 service. TV Inputs are accessed one-to-one via TV Input Manager sessions. 79 <li>Third-party TV Inputs have package-locked access to the TV Provider database 80 and can READ/WRITE only to matching package rows. 81 <li>Third-party TV inputs can either display their own content or content from a 82 device manufacturers passthrough TV inputs, like HDMI1. They cant display 83 content from non-passthrough TV inputs, like a built-in or IPTV tuner. 84 <li><code>TV_INPUT_HARDWARE</code> permission for a hardware TV Input app, signals the TV Input Manager Service 85 to notify the TV Input service on boot to call the TV Input Manager Service and 86 add its TV Inputs. This permission allows a hardware TV Input app to support 87 multiple TV Inputs per TV Input service, as well as being able to dynamically 88 add and remove its supported TV Inputs. 89 </ul> 90 91 <h2 id="tv_provider">TV Provider</h2> 92 93 <p>The TV Provider database stores the channels and programs from TV Inputs. The 94 TV Provider also publishes and manages the associated permissions so that TV 95 Inputs can see only their own records. For instance, a specific TV Input can 96 see only the channels and programs it has supplied and is prohibited from 97 accessing any other TV Inputs channels and programs. </p> 98 99 <p>The TV Provider maps "broadcast genre" to "canonical genre" internally. TV 100 Inputs are responsible for populating "broadcast genre" with the value in the 101 underlying broadcast standard, and the "canonical genre" field will 102 automatically 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 103 (meaning Sports), the TV Input will populate the broadcast genre with the 104 String Sports and TV Provider will populate the canonical genre field with 105 the mapped value <code>android.provider.TvContract.Genres.SPORTS</code>.</p> 106 107 <p>See the diagram below for a detailed view of the TV Provider. </p> 108 109 <img src="images/TIF_TV_Provider.png" alt="Android TV Provider"> 110 <p class="img-caption"><strong>Figure 2.</strong> Android TV Provider</p> 111 112 <p><em>Only apps in the privileged system partition can read the entire TV Provider 113 database. </em></p> 114 115 <p>Passthrough TV inputs do not store channels and programs. </p> 116 117 <p>In addition to the standard fields for channels and programs, the TV Provider 118 database 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 119 can include custom information, such as frequency of the associated tuner, and 120 may be provided in a protocol buffer or another form. A Searchable field is 121 available to make certain channels unavailable in search (such as to meet 122 country-specific requirements for content protection).</p> 123 124 <h3 id="tv_provider_database_field_examples">Database field examples</h3> 125 126 <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 127 like the TV App. These tables have four types of fields:</p> 128 129 <ul> 130 <li><strong>Display: </strong>Display fields contain information that apps may want to make visible to the 131 user, like a channels name (<code>COLUMN_DISPLAY_NAME</code>) or number (<code>COLUMN_DISPLAY_NUMBER</code>), or the title of the program being viewed. 132 <li><strong>Metadata:</strong> There are three fields for identifying content, according to relevant 133 standards, like a channels 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>). 134 <li><strong>Internal data</strong>: Fields that are for the custom use of TV Inputs.<br> 135 Some fields, like <code>COLUMN_INTERNAL_PROVIDER_DATA</code>, are customizable BLOB fields where a TV Input can store arbitrary metadata 136 about their channel or program. 137 <li><strong>Flag: </strong>Flag fields represent whether a channel should be restricted from search, 138 browse, or viewing. This can be set only at the channel level. All programs 139 defer to the setting on the channel. 140 <ul> 141 <li><code>COLUMN_SEARCHABLE</code>: Restricting search from some channels may be a requirement in certain 142 regions. <code>COLUMN_SEARCHABLE = 0</code> means the channel should not be exposed in search results. 143 <li><code>COLUMN_BROWSABLE</code>: Visible to system applications only. Restricting channel from being browsed 144 by applications. <code>COLUMN_BROWSABLE = 0</code> means the channel should not be included in the channel list. 145 <li><code>COLUMN_LOCKED</code>: Visible to system applications only. Restricting channel from being viewed by 146 invalid accounts without entering PIN code. <code>COLUMN_LOCKED = 1</code> means the channel should be protected by parental control. 147 </ul> 148 </ul> 149 150 <p>For a more exhaustive list of the fields, see <code>android/frameworks/base/media/java/android/media/tv/TvContract.java</code></p> 151 152 <h3 id="permissions_and_access_control">Permissions and access control</h3> 153 154 <p>All fields are visible to anyone with access to the corresponding row. No 155 fields are directly accessible to users; they see only what the TV App, System 156 apps, or TV Inputs surface.</p> 157 158 <ul> 159 <li>Each row has <code>PACKAGE_NAME</code>, the package (app) that owns that row, checked on Query, Insert, Update via 160 TvProvider.java. 161 A TV Input may access only the information it wrote and is 162 cordoned off from the information provided by other TV Inputs. 163 <li>READ, WRITE permissions via AndroidManifest.xml (requires user consent) to 164 determine available channels. 165 <li>Only <code>signatureOrSystem</code> apps can acquire <code>ACCESS_ALL_EPG_DATA</code> permission to access the entire database. 166 </ul> 167 168 <h2 id="tv_input_manager">TV Input Manager</h2> 169 170 <p>The TV Input Manager provides a central system API to the overall Android TV 171 Input Framework. It arbitrates interaction between apps and TV Inputs and 172 provides parental control functionality. TV Input Manager sessions must be 173 created one-to-one with TV Inputs. The TV Input Manager allows access to 174 installed TV Inputs so apps may:</p> 175 176 <ul> 177 <li>List TV inputs and check their status 178 <li>Create sessions and manage listeners 179 </ul> 180 181 <p>For sessions, a TV Input may be tuned by the TV App only to URIs it has added 182 to the TV Provider database, except for passthrough TV Inputs which can be 183 tuned to using <code>TvContract.buildChannelUriForPassthroughInput()</code>. A TV Input may also have its volume set. TV Inputs provided and signed by the 184 device manufacturer (signature apps) or other apps installed in the system 185 partition will have access to the entire TV Provider database. This access can 186 be used to construct apps to browse and search across all available TV channels 187 and programs.</p> 188 189 <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 Inputs state change or on the addition or removal 190 of a TV Input. For example, a TV App can react when a TV Input is disconnected 191 by displaying it as disconnected and preventing its selection.</p> 192 193 <p>The TV Input Manager abstracts communication between the TV App and TV Inputs. 194 The standard interface of TV Input Manager and TV Input allows multiple 195 device manufacturers to create their own TV Apps while helping all third-party TV Inputs 196 work on all TV Apps.</p> 197 198 <h2 id="tv_inputs">TV Inputs</h2> 199 200 <p>TV Inputs are Android apps in the sense they have an AndroidManifest.xml and 201 are installed (via Play, pre-installed, or sideloaded). Android TV supports 202 pre-installed system apps, apps signed by the device manufacturer and 203 third-party TV Inputs. </p> 204 205 <p>Some inputs, like the HDMI input or built-in tuner input, can be provided only 206 by the manufacturer as they speak directly with the underlying hardware. 207 Others, such as IPTV, place-shifting, and external STB, can be supplied by 208 third parties as APKs on Google Play Store. Once downloaded and installed, the 209 new input can be selected within the TV App.</p> 210 211 <h3 id=passthrough_input_example>Passthrough input example</h3> 212 213 <img src="images/TIF_HDMI_TV_Input.png" alt="Android TV System Input"> 214 <p class="img-caption"><strong>Figure 3.</strong> Android TV System Input</p> 215 216 <p>In this example, the TV Input provided by the device manufacturer is trusted 217 and has full access to the TV Provider. As a passthrough TV Input, it does not 218 register any channels or programs with the TV Provider. To obtain the URI used 219 to 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 220 Input. </p> 221 222 <h3 id=built-in_tuner_example>Built-in tuner example</h3> 223 224 <img src="images/Built-in_Tuner_TV_Input.png" alt="Android TV Built-in Tuner Input"> 225 <p class="img-caption"><strong>Figure 4.</strong> Android TV Built-in Tuner Input</p> 226 227 <p>In this example, the Built-in Tuner TV Input provided by the device 228 manufacturer is trusted and has full access to the TV Provider. </p> 229 230 <h3 id=third-party_input_example>Third-party input example</h3> 231 232 <img src="images/Third-party_Input_HDMI.png" alt="Android TV third-party input"> 233 <p class="img-caption"><strong>Figure 5.</strong> Android TV third-party input</p> 234 235 <p>In this example, the external STB TV Input is provided by a third party. Since 236 that TV Input cant directly access the HDMI video feed coming in, it must go 237 through the TV Input Manager and use the HDMI TV Input provided by the device 238 manufacture.</p> 239 240 <p>Through the TV Input Manager, the external STB TV Input can speak with the HDMI 241 TV Input and ask it to show the video on HDMI1. So the STB TV Input can control 242 the TV while the manufacturer-provided HDMI TV Input renders the video.</p> 243 244 <h3 id=picture_in_picture_pip_example>Picture in picture (PIP) example </h3> 245 246 <img src="images/TIF_PIP-PAP.png" alt="Android TV KeyEvents"> 247 <p class="img-caption"><strong>Figure 6.</strong> Android TV KeyEvents</p> 248 249 <p>The diagram above shows how buttons on a remote control are passed to a 250 specific TV Input for picture in picture (PIP) display. Those button presses 251 are interpreted by the hardware driver supplied by the device manufacturer, 252 converting hardware scancodes to Android keycodes and passing them to the 253 standard Android <a href="/devices/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> 254 255 <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 256 to consume and should allow the TV App to handle the keys it does not need to 257 consume.</p> 258 259 <p>The TV App is responsible for knowing which system TV Input is active, meaning 260 selected 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> 261 262 <h3 id="mheg-5_input_example">MHEG-5 input example</h3> 263 264 <p>The following diagram shows a more detailed view of how <code>KeyEvents</code> are routed through the Android TIF.</p> 265 266 <img src="images/TIF_MHEG5_app.png" alt="Android TV Red button example"> 267 <p class="img-caption"><strong>Figure 7.</strong> Android TV Red button example</p> 268 269 <p>It depicts the flow of a Red button app, common in Europe for letting users 270 access interactive apps on their televisions. An app can be delivered over this 271 transport stream. When the button is clicked, it lets users interact with these 272 broadcast apps. For example, you might use these broadcast apps to access 273 related web pages or sports scores.</p> 274 275 <p>See the <em>Broadcast app</em> section to learn how broadcast apps interact with the TV App.</p> 276 277 <p>In this example:</p> 278 279 <ol> 280 <li>The TV App is in focus and receives all keys. 281 <li><code>KeyEvents</code> (e.g. the Red button) is passed to the active TV Input as <code>InputEvents.</code> 282 <li>The system TV Input integrates with MHEG-5 stack and has the <code>RECEIVE_INPUT_EVENT</code> system permission. 283 <li>On receiving activation keycode (e.g. Red button), the TV Input activates 284 broadcast app. 285 <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. 286 </ol> 287 288 <p class="note"><strong>Note</strong>: Third-party TV inputs never receive keys. </p> 289 290 <h2 id="tv_input_hal">TV Input HAL</h2> 291 292 <p>The TV Input HAL aids development of TV Inputs to access TV-specific hardware. 293 As with other Android HALs, the TV Input HAL (<code>tv_input</code>) is 294 available in the AOSP source tree and the vendor develops its implementation.</p> 295 296 <h2 id="tv_app">TV App</h2> 297 298 299 <p>The system TV App presents live TV content to the user. A reference TV 300 App (Live TV) is provided alongside the Android platform, which 301 can be used as-is, customized, extended, or replaced by device manufacturers. 302 The <a href="https://android.googlesource.com/platform/packages/apps/TV/">source code</a> 303 is available in the Android Open Source Project, and you can get started with 304 it in the <a href="/devices/tv/reference-tv-app.html">Reference TV app</a> article.</p> 305 306 <p>Device manufacturers may extend their TV Apps to implement device 307 manufacturer or country-specific features, however this is not in the scope of 308 TIF or the reference TV App.</p> 309 310 <p>At a minimum, the system TV App needs to handle the following tasks:</p> 311 312 <h3 id="setup_and_configuration">Setup and configuration</h3> 313 314 315 <ul> 316 <li> Auto-detect TV Inputs 317 <li> Let TV Inputs initiate channel setup 318 <li> Control parental settings 319 <li> Edit channels 320 </ul> 321 322 <h3 id="viewing">Viewing</h3> 323 324 325 <ul> 326 <li> Access and navigate all TV channels 327 <li> Access TV program information bar 328 <li> Display Electronic Programming Guide (EPG) data 329 <li> Support multiple audio and subtitle tracks 330 <li> Supply parental control PIN challenge 331 <li> Allow TV Input UI overlay for: 332 <ul> 333 <li> TV standard (HbbTV, etc.) 334 </ul> 335 <li> Populate search results for TV channels and programs 336 <li> Display app linking cards 337 <li> Support timeshifting APIs 338 <li> Handle DVR functionality and support TV recording APIs 339 </ul> 340 341 <p>This feature set will increase in line with new Android versions 342 where the platform TIF APIs are extended. CTS Verifier provides the 343 compatibility test coverage. </p> 344 345 <h3 id=support_for_third-party_tv_inputs>Support for third-party TV Inputs</h3> 346 347 348 <p>Android TV provides developer APIs for third-party TV inputs, enabling 349 installed apps to deliver software channels into the live TV experience. To 350 ensure a compatible Android device implementation, the system TV App has some 351 responsibilities regarding surfacing third-party TV inputs and channels to the 352 user. The reference Live TV app provides a compatible implementation; if 353 replacing the system TV App, device manufacturers must ensure their own apps 354 provide similar compatibility, to meet developer expectations across all 355 Android TV devices.</p> 356 357 <p>The system TV App must surface third-party inputs alongside the device's 358 default live TV service. 359 The promise of the developer APIs is that users will be able to find channels 360 (once installed) within their standard TV experience.</p> 361 362 <p>Visual differentiation between built-in channels and third-party channels is 363 allowed, as defined in the TV App section of the Android CDD.</p> 364 365 <p>The following sections show how the Live TV application fulfills the CDD 366 requirements.</p> 367 368 <h4 id=new_channel_setup>New channel setup</h4> 369 370 371 <p>The addition of new third-party inputs/channels begins with the user finding 372 and installing a TV Input from an 373 application store, such as Google Play.</p> 374 375 <p>Some third-party TV inputs automatically add channels to the TvProvider 376 database. However most will provide a Setup activity to enable the user to set 377 up their channels, provide login details, and other actions. The system TV App 378 needs to ensure the user can activate this Setup activity, which is why the CDD 379 requires third-party inputs be minimal navigation actions away from the main TV 380 App.</p> 381 382 <p>The reference Live TV app provides the Channel Sources menu for accessing 383 inputs.</p> 384 385 <img src="images/LiveChannels_settings.png" alt="Go to Settings"> 386 <p class="img-caption"><strong>Figure 8.</strong> Go to <strong>Settings</strong>.</p> 387 388 <img src="images/LiveChannels_channel_sources.png" alt="Go to Channel source in Settings"> 389 <p class="img-caption"><strong>Figure 9.</strong> Go to <strong>Channel sources</strong> in Settings.</p> 390 391 <img src="images/LiveChannels_sources.png" alt="Select your source from the list."> 392 <p class="img-caption"><strong>Figure 10.</strong> Select your source from the list.</p> 393 394 <img src="images/LiveChannels_Add_channel.png" alt="Add channels from your source"> 395 <p class="img-caption"><strong>Figure 11.</strong> Add channels from your source</p> 396 397 <p>In addition a notification card is shown at the top of the TV App menu after a new TvInput is installed, to take the user directly to the Setup:</p> 398 399 <img src="images/LiveChannels_set_up_sources.png" alt="Notification that shows new channel sources are available."> 400 <p class="img-caption"><strong>Figure 12.</strong> Notification that shows new channel sources are available.</p> 401 402 <p>If the user takes action through the notification, they can select to set up their sources as seen in Figure 10.</p> 403 <p>See <a href="http://developer.android.com/training/tv/tif/tvinput.html#setup">Define Your TV Input Service</a> 404 for developer expectations in this area.</p> 405 406 <h4 id=customize_the_channel_list>Customize the channel list</h4> 407 408 409 <p>Device manufacturers may provide a UI to hide certain channels and 410 enable users to manage their own EPGs. Live TV includes this facility.</p> 411 412 <img src="images/LiveChannels_channel_list.png" alt="Open the channel list in Settings."> 413 <p class="img-caption"><strong>Figure 13.</strong> Open the channel list in <strong>Settings</strong>.</p> 414 415 <img src="images/LiveChannels_customize_channel-list.png" alt="Customize your channel list."> 416 <p class="img-caption"><strong>Figure 14.</strong> Customize your channel list.</p> 417 418 <h4 id=epg>EPG</h4> 419 420 421 <p>Third-party input developers need to have confidence that users can easily 422 navigate to their channels during general usage, across all compatible Android 423 TV devices.</p> 424 425 <p>Channels from third-party inputs must be presented as part of the device's 426 standard live TV experience EPG. Visual separation or separate categories for 427 third-party channels can be used (see the TV App section of the Android CDD)what's key 428 is that users are able to find the channels they have installed. </p> 429 430 <h4 id=search>Search</h4> 431 432 433 <p>Manufacturers must implement the TV App to include search results for global 434 search requests in order to ensure the best user experience. Live TV provides an 435 implementation (see <a href="https://android.googlesource.com/platform/packages/apps/TV/+/android-live-tv/src/com/android/tv/search/TvProviderSearch.java">com.android.tv.search.TvProviderSearch</a>) which provides results from third-party inputs (required for platform 436 compatibility) as well as built-in inputs.</p> 437 438 <h4 id="time-shifting">Time shifting</h4> 439 <p> 440 For devices on Android 6.0 and above, the TV App must support the Android 441 framework <a 442 href="https://developer.android.com/reference/android/media/tv/TvView.html">time 443 shifting APIs</a>. Additionally, manufacturers must implement playback controls 444 in the TV App, which allow users to pause, resume, rewind, and fast forward the 445 playback. 446 </p> 447 <p> 448 For TV Inputs that support time shifting, the TV App needs to display playback 449 controls. 450 </p> 451 452 <p> 453 <img src="images/TIF_timeshift.png" alt="Playback controls"> 454 </p> 455 <p class="img-caption"><strong>Figure 15.</strong> Playback controls</p> 456 457 <h4 id="dvr">DVR</h4> 458 <p> 459 For devices on Android 7.0 and above, the TV App must support the Android 460 framework <a 461 href="https://developer.android.com/reference/android/media/tv/TvRecordingClient.html">TV 462 recording APIs</a>, to support, list, and play recorded programs. 463 </p> 464 <p> 465 This allows device manufacturers to plug their DVR subsystems into TIF and 466 dramatically reduce the integration effort it takes to enable or integrate DVR 467 functionality on a TV device. It also enables third parties to provide 468 aftermarket DVR systems that can be plugged into an Android TV device. 469 </p> 470 <p> 471 In addition to recording live content, the TV App also handles resource 472 conflict. For example, if the device has two tuners, it can record two programs at 473 the same time. If the user asks to record three, the TV App must handle the 474 conflict and should either surface a notification or request that the user 475 schedules a priority for these requests. 476 </p> 477 <p> 478 TV Apps can also implement more sophisticated logic like asking a user if theyd 479 like to record all future episodes in a series when they request to record one 480 episode. 481 </p> 482 <p> 483 See the following diagram for a view into a possible DVR implementation in 484 Android TV. 485 </p> 486 <p> 487 <img src="images/TV_Input_DVR.png" alt="Digital video recording in Android TV"> 488 </p> 489 <p class="img-caption"><strong>Figure 16.</strong> Digital video recording in Android TV</p> 490 491 <ol> 492 <li>The TV Input Service tells the TV App how many tuners are available so that 493 the TV App can handle possible resource conflict. 494 <li>The TV App receives a user-initiated request to record a TV program. 495 <li>The TV App stores the recording schedule in its internal database. 496 <li>When its time to record, the TV App passes a request to tune to the channel 497 associated with the recording. 498 <li>The TV Input Service receives this request, responds with whether or not 499 there are appropriate resources, and tunes to the channel. 500 <li>Then the TV App passes a request to start recording to 501 the TV Input Manger. 502 <li>The TV Input Service receives this request and starts recording. 503 <li>The TV Input Service stores the actual video data in its storage, which can 504 be external storage or cloud storage. 505 <li>When it's time to finish the recording, the TV App passes the stop recording 506 request to the TV Input Manager. 507 <li>Once the TV Input Service receives the request, it stops the recording and 508 adds its associated metadata to the TV Provider so that the TV App can show the 509 recording to users when requested.</li> 510 </ol> 511 512 <p> 513 For more information about implementing Recording features in your TV Input 514 service, see this <a 515 href="https://developer.android.com/preview/features/tv-recording-api.html">TV 516 Recording</a> article. 517 </p> 518 519 <h3 id=useful_resources>Useful resources</h3> 520 521 522 <ul> 523 <li> The <a href="/compatibility/android-cdd.pdf">Android CDD</a> 524 and documented developer APIs are the definitive references. 525 <li> CTS Verifier exercises the APIs as part of the compatibility testing program. 526 Running this against Live TV may be a useful way to see the EPG, 527 Search, Parental Control, and other requirements in the context of third-party 528 inputs. 529 <li> See <a href="http://developer.android.com/training/tv/tif/tvinput.html#setup">Define Your TV Input Service</a> 530 for developer expectations in this area. 531 </ul> 532 533 <h2 id="parental_control">Parental Control</h2> 534 535 <p>Parental control lets a user block undesired channels and programs, but bypass 536 the block by entering a PIN code.</p> 537 538 <p>Responsibility for parental control functionality is shared amongst the TV App, 539 TV Input Manager service, TV Provider, and TV Input.</p> 540 541 <p>Parental control is mandatory, and is covered by CTS Verifier.</p> 542 543 <p>A number of countries have defined rating systems that TV Inputs can use via 544 the <a href="https://developer.android.com/reference/android/media/tv/TvContentRating.html"> 545 TVContentRating API</a>. Additionally, TV Inputs can register their own custom 546 rating systems as demonstrated by the CTS Verifier test, which introduces a 547 'fake' rating. For countries where a standard rating system exists, device 548 manufacturers are encouraged to combine the TV Input Framework Parental Control 549 with any other mechanisms they may include.</p> 550 551 <h3 id="tv_provider">TV Provider</h3> 552 553 <p>Each channel row has a <code>COLUMN_LOCKED</code> field that is used to lock 554 specific channels from viewing without entering a PIN code. The program field 555 <code>COLUMN_CONTENT_RATING</code> is intended for display and is not used to 556 enforce parental control.</p> 557 558 <h3 id="tv_input_manager">TV Input Manager</h3> 559 560 <p>The TV Input Manager stores every blocked <code>TvContentRating</code> and 561 responds to <code>isRatingBlocked()</code> to advise if content with the given 562 rating should be blocked.</p> 563 564 <h3 id="tv_input">TV Input</h3> 565 566 <p>The TV Input checks if the current content should be blocked by calling 567 <code>isRatingBlocked()</code> on the TV Input Manager when the rating of the 568 displayed content has changed 569 (on program or channel change), or parental control settings have changed (on 570 <code>ACTION_BLOCKED_RATINGS_CHANGED</code> and 571 <code>ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED</code>). If the content should 572 be blocked, the TV Input disables the audio and video 573 and notifies the TV app that the current content is blocked by calling 574 <code>notifyContentBlocked(TvContentRating)</code>. If the content should not 575 be blocked, the TV Input enables audio and video and notifies the TV App 576 the current content is allowed by calling <code>notifyContentAllowed()</code>.</p> 577 578 <h3 id="tv_app">TV App</h3> 579 580 <p>To honor the parental control APIs, and therefore create a compatible 581 platform, the system TV App needs to provide a way for users to manage 582 parental control, including for any custom ratings registered by specific apps.</p> 583 584 <p>The TV App shows a PIN code UI when it 585 is notified by a TV Input that the current content is blocked or when the user 586 attempts to view a blocked channel.</p> 587 588 <p>The TV App does not directly store the parental control settings. When the user 589 changes the parental control settings, every blocked 590 <code>TvContentRating</code> is stored by the TV Input Manager, and blocked 591 channels are stored by the TV Provider.</p> 592 593 <p>The TV App needs to declare the permission 594 <code>android.permission.MODIFY_PARENTAL_CONTROLS</code> in order to change 595 the parental control settings.</p> 596 597 <p>Device manufacturers are encouraged to:</p> 598 <ul> 599 <li>Exercise the CTS Verifier parental controls test against the reference 600 Live TV application for a demonstration of the compatibility requirements.</li> 601 <li>Use the Live TV app as reference for their own TV App: in particular see 602 the <a href="https://android.googlesource.com/platform/packages/apps/TV/+/android-live-tv/src/com/android/tv/parental/ContentRatingsManager.java"> 603 ContentRatingsManager</a> and 604 <a href="https://android.googlesource.com/platform/packages/apps/TV/+/android-live-tv-l-mr1/src/com/android/tv/ui/sidepanel/parentalcontrols/RatingSystemsFragment.java"> 605 RatingSystemsFragment</a> source, and how they handle custom ratings.</li> 606 </ul> 607 608 609 <h2 id="hdmi-cec">HDMI-CEC</h2> 610 611 <p>HDMI-CEC allows one device to control another, thereby enabling a single remote 612 to control multiple appliances in a home theater. It is used by Android TV to 613 speed setup and allow distant control over various TV Inputs via the central TV 614 App. For instance, it may switch inputs, power up or down devices, and more.</p> 615 616 <p>The Android TIF implements HDMI-CEC as the HDMI Control Service so that 617 device manufacturers merely need to develop low-level drivers that interact with the 618 lightweight Android TV HAL, skipping more complex business logic. In providing 619 a standard implementation, Android seeks to mitigate compatibility issues by 620 reducing fragmented implementations and selective feature support. The HDMI 621 Control Service uses the existing Android services, including input and power.</p> 622 623 <p>This means existing HDMI-CEC implementations will need to be redesigned to 624 interoperate with the Android TIF. We recommend the hardware platform contain a 625 microprocessor to receive CEC power on and other commands.</p> 626 627 <img src="images/TV_App_CEC_integration.png" alt="CEC integration on Android TV"> 628 <p class="img-caption"><strong>Figure 17.</strong> CEC integration on Android TV</p> 629 630 <ol> 631 <li> The CEC bus receives a command from the currently active source to switch to a 632 different source. 633 <li> The driver passes the command to the HDMI-CEC HAL. 634 <li> The HAL notifies all <code>ActiveSourceChangeListeners</code>. 635 <li> THe HDMI Control Service is notified of source change via <code>ActiveSourceChangeListener</code>. 636 <li> The TV Input Manager service generates an intent for the TV App to switch the 637 source. 638 <li> The TV App then creates a TV Input Manager Session for the TV Input being 639 switched to and calls <code>setMain</code> on that session. 640 <li> The TV Input Manager Session passes this information on to the HDMI TV Input. 641 <li> The HDMI TV input requests to set sideband surface. 642 <li> The TV Input Manager Service generates a corresponding routing control command 643 back to HDMI Control Service when the surface is set. 644 </ol> 645 646 <h2 id="tv_integration_guidelines">TV integration guidelines</h2> 647 648 <h3 id="broadcast_app">Broadcast app</h3> 649 650 <p>Because each country has broadcast-specific requirements (MHEG, Teletext, 651 HbbTV, and more), manufacturers are expected to supply their own solutions for 652 the broadcast app, for example:</p> 653 654 <ul> 655 <li> MHEG: native stack 656 <li> Teletext: native stack 657 <li> HbbTV: webkit modification by Opera browser 658 </ul> 659 660 <p>In the Android L release, Android TV expects device manufacturers to use systems 661 integrators or the Android solutions for regional TV stacks, pass the surface 662 to TV software stacks, or pass the necessary key code to interact with legacy 663 stacks.</p> 664 665 <p>Heres how the broadcast app and TV App interact:</p> 666 667 <ol> 668 <li>The TV App is in focus, receiving all keys. 669 <li>The TV App passes keys (e.g. Red button) to the TV Input device. 670 <li>The TV Input device internally integrates with legacy TV stack. 671 <li>On receiving an activation keycode (e.g. Red button), the TV Input device 672 activates broadcast apps. 673 <li>A broadcast app takes focus in the TV App and handles user actions. 674 </ol> 675 676 <p>For voice search/recommendation, the broadcast app may support In-app search 677 for voice search.</p> 678 679 680 </body> 681 </html> 682