Home | History | Annotate | Download | only in g3doc
      1 # 3rd party instructions for using Cloud EPG feature of Live Channels
      2 
      3 Partners can ask Live Channels to retrieve EPG data for their TV Input Service
      4 using live channels
      5 
      6 ## Prerequisites
      7 
      8 *   Updated agreement with Google
      9 *   Oreo or patched Nougat
     10 
     11 ## Nougat
     12 
     13 To use cloud epg with Nougat you will need the following changes.
     14 
     15 ### Patch TVProvider
     16 
     17 To run in Nougat you must cherry pick [change
     18 455319](https://android-review.googlesource.com/c/platform/packages/providers/TvProvider/+/455319)
     19 to TV Provider.
     20 
     21 ### Customisation
     22 
     23 Indicate TvProvider is patched by including the following in their TV
     24 customization resource
     25 
     26 ```
     27 <bool name="tvprovider_allows_system_inserts_to_program_table">true</bool>
     28 ```
     29 
     30 See https://source.android.com/devices/tv/customize-tv-app
     31 
     32 ## **Input Setup**
     33 
     34 During the input setup activity, the TIS will query the content provider for
     35 lineups in a given postal code. The TIS then inserts a row to the inputs table
     36 with input_id and lineup_id
     37 
     38 On completion of the activity the TIS sets the extra data in the result to
     39 
     40 *   `com.android.tv.extra.USE_CLOUD_EPG = true`
     41 *   `TvInputInfo.EXTRA_INPUT_ID` with their input_id
     42 
     43 This is used to tell Live Channels to immediately start the EPG fetch for that
     44 input.
     45 
     46 ### Sample Input Setup code.
     47 
     48 A complete sample is at
     49 ../third_party/samples/src/com/example/partnersupportsampletvinput
     50 
     51 #### query lineup
     52 
     53 ```java
     54  private AsyncTask<Void, Void, List<Lineup>> createFetchLineupsTask() {
     55         return new AsyncTask<Void, Void, List<Lineup>>() {
     56             @Override
     57             protected List<Lineup> doInBackground(Void... params) {
     58                 ContentResolver cr = getActivity().getContentResolver();
     59 
     60                 List<Lineup> results = new ArrayList<>();
     61                 Cursor cursor =
     62                         cr.query(
     63                                 Uri.parse(
     64                                         "content://com.android.tv.data.epg/lineups/postal_code/"
     65                                                 + ZIP),
     66                                 null,
     67                                 null,
     68                                 null,
     69                                 null);
     70 
     71                 while (cursor.moveToNext()) {
     72                     String id = cursor.getString(0);
     73                     String name = cursor.getString(1);
     74                     String channels = cursor.getString(2);
     75                     results.add(new Lineup(id, name, channels));
     76                 }
     77 
     78                 return results;
     79             }
     80 
     81             @Override
     82             protected void onPostExecute(List<Lineup> lineups) {
     83                 showLineups(lineups);
     84             }
     85         };
     86     }
     87 ```
     88 
     89 #### Insert cloud_epg_input
     90 
     91 ```java
     92 ContentValues values = new ContentValues();
     93 values.put(EpgContract.EpgInputs.COLUMN_INPUT_ID, SampleTvInputService.INPUT_ID);
     94 values.put(EpgContract.EpgInputs.COLUMN_LINEUP_ID, lineup.getId());
     95 ContentResolver contentResolver = getActivity().getContentResolver();
     96 EpgInput epgInput = EpgInputs.queryEpgInput(contentResolver, SampleTvInputService.INPUT_ID);
     97 if (epgInput == null) {
     98     contentResolver.insert(EpgContract.EpgInputs.CONTENT_URI, values);
     99 } else {
    100     values.put(EpgContract.EpgInputs.COLUMN_ID, epgInput.getId());
    101     EpgInputs.update(contentResolver, EpgInput.createEpgChannel(values));
    102 }
    103 ```
    104 
    105 #### Return use_cloud_epg
    106 
    107 ```java
    108 Intent data = new Intent();
    109 data.putExtra(TvInputInfo.EXTRA_INPUT_ID, inputId);
    110 data.putExtra(com.android.tv.extra.USE_CLOUD_EPG, true);
    111 setResult(Activity.RESULT_OK, data);
    112 ```
    113