TvContract.java revision 3a0f19980dcc3b9deba60b9b4f6b96dd3639dd45
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.media.tv;
18
19import android.content.ComponentName;
20import android.content.ContentResolver;
21import android.content.ContentUris;
22import android.net.Uri;
23import android.provider.BaseColumns;
24
25import java.util.List;
26
27/**
28 * <p>
29 * The contract between the TV provider and applications. Contains definitions for the supported
30 * URIs and columns.
31 * </p>
32 * <h3>Overview</h3>
33 * <p>
34 * TvContract defines a basic database of TV content metadata such as channel and program
35 * information. The information is stored in {@link Channels} and {@link Programs} tables.
36 * </p>
37 * <ul>
38 *     <li>A row in the {@link Channels} table represents information about a TV channel. The data
39 *         format can vary greatly from standard to standard or according to service provider, thus
40 *         the columns here are mostly comprised of basic entities that are usually seen to users
41 *         regardless of standard such as channel number and name.</li>
42 *     <li>A row in the {@link Programs} table represents a set of data describing a TV program such
43 *         as program title and start time.</li>
44 * </ul>
45 */
46public final class TvContract {
47    /** The authority for the TV provider. */
48    public static final String AUTHORITY = "android.media.tv";
49
50    private static final String PATH_CHANNEL = "channel";
51    private static final String PATH_PROGRAM = "program";
52    private static final String PATH_INPUT = "input";
53
54    /**
55     * An optional query, update or delete URI parameter that allows the caller to specify start
56     * time (in milliseconds since the epoch) to filter programs.
57     *
58     * @hide
59     */
60    public static final String PARAM_START_TIME = "start_time";
61
62    /**
63     * An optional query, update or delete URI parameter that allows the caller to specify end time
64     * (in milliseconds since the epoch) to filter programs.
65     *
66     * @hide
67     */
68    public static final String PARAM_END_TIME = "end_time";
69
70    /**
71     * A query, update or delete URI parameter that allows the caller to operate on all or
72     * browsable-only channels. If set to "true", the rows that contain non-browsable channels are
73     * not affected.
74     *
75     * @hide
76     */
77    public static final String PARAM_BROWSABLE_ONLY = "browsable_only";
78
79    /**
80     * Builds a URI that points to a specific channel.
81     *
82     * @param channelId The ID of the channel to point to.
83     */
84    public static final Uri buildChannelUri(long channelId) {
85        return ContentUris.withAppendedId(Channels.CONTENT_URI, channelId);
86    }
87
88    /**
89     * Builds a URI that points to a channel logo. See {@link Channels.Logo}.
90     *
91     * @param channelId The ID of the channel whose logo is pointed to.
92     */
93    public static final Uri buildChannelLogoUri(long channelId) {
94        return buildChannelLogoUri(buildChannelUri(channelId));
95    }
96
97    /**
98     * Builds a URI that points to a channel logo. See {@link Channels.Logo}.
99     *
100     * @param channelUri The URI of the channel whose logo is pointed to.
101     */
102    public static final Uri buildChannelLogoUri(Uri channelUri) {
103        if (!PATH_CHANNEL.equals(channelUri.getPathSegments().get(0))) {
104            throw new IllegalArgumentException("Not a channel: " + channelUri);
105        }
106        return Uri.withAppendedPath(channelUri, Channels.Logo.CONTENT_DIRECTORY);
107    }
108
109    /**
110     * Builds a URI that points to all browsable channels from a given TV input.
111     *
112     * @param name {@link ComponentName} of the {@link android.media.tv.TvInputService} that
113     *            implements the given TV input.
114     */
115    public static final Uri buildChannelsUriForInput(ComponentName name) {
116        return buildChannelsUriForInput(name, true);
117    }
118
119    /**
120     * Builds a URI that points to all or browsable-only channels from a given TV input.
121     *
122     * @param name {@link ComponentName} of the {@link android.media.tv.TvInputService} that
123     *            implements the given TV input.
124     * @param browsableOnly If set to {@code true} the URI points to only browsable channels. If set
125     *            to {@code false} the URI points to all channels regardless of whether they are
126     *            browsable or not.
127     */
128    public static final Uri buildChannelsUriForInput(ComponentName name, boolean browsableOnly) {
129        return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(AUTHORITY)
130                .appendPath(PATH_INPUT).appendPath(name.getPackageName())
131                .appendPath(name.getClassName()).appendPath(PATH_CHANNEL)
132                .appendQueryParameter(PARAM_BROWSABLE_ONLY, String.valueOf(browsableOnly)).build();
133    }
134
135    /**
136     * Builds a URI that points to a specific program.
137     *
138     * @param programId The ID of the program to point to.
139     */
140    public static final Uri buildProgramUri(long programId) {
141        return ContentUris.withAppendedId(Programs.CONTENT_URI, programId);
142    }
143
144    /**
145     * Builds a URI that points to all programs on a given channel.
146     *
147     * @param channelUri The URI of the channel to return programs for.
148     */
149    public static final Uri buildProgramsUriForChannel(Uri channelUri) {
150        if (!PATH_CHANNEL.equals(channelUri.getPathSegments().get(0))) {
151            throw new IllegalArgumentException("Not a channel: " + channelUri);
152        }
153        String channelId = String.valueOf(ContentUris.parseId(channelUri));
154        return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(AUTHORITY)
155                .appendPath(PATH_CHANNEL).appendPath(channelId).appendPath(PATH_PROGRAM).build();
156    }
157
158    /**
159     * Builds a URI that points to programs on a specific channel whose schedules overlap with the
160     * given time frame.
161     *
162     * @param channelUri The URI of the channel to return programs for.
163     * @param startTime The start time used to filter programs. The returned programs should have
164     *            {@link Programs#COLUMN_END_TIME_UTC_MILLIS} that is greater than this time.
165     * @param endTime The end time used to filter programs. The returned programs should have
166     *            {@link Programs#COLUMN_START_TIME_UTC_MILLIS} that is less than this time.
167     */
168    public static final Uri buildProgramsUriForChannel(Uri channelUri, long startTime,
169            long endTime) {
170        Uri uri = buildProgramsUriForChannel(channelUri);
171        return uri.buildUpon().appendQueryParameter(PARAM_START_TIME, String.valueOf(startTime))
172                .appendQueryParameter(PARAM_END_TIME, String.valueOf(endTime)).build();
173    }
174
175    /**
176     * Builds a URI that points to a specific program the user watched.
177     *
178     * @param watchedProgramId The ID of the watched program to point to.
179     * @hide
180     */
181    public static final Uri buildWatchedProgramUri(long watchedProgramId) {
182        return ContentUris.withAppendedId(WatchedPrograms.CONTENT_URI, watchedProgramId);
183    }
184
185    /**
186     * Extracts the {@link Channels#COLUMN_PACKAGE_NAME} from a given URI.
187     *
188     * @param channelsUri A URI constructed by {@link #buildChannelsUriForInput(ComponentName)} or
189     *            {@link #buildChannelsUriForInput(ComponentName, boolean)}.
190     * @hide
191     */
192    public static final String getPackageName(Uri channelsUri) {
193        final List<String> paths = channelsUri.getPathSegments();
194        if (paths.size() < 4) {
195            throw new IllegalArgumentException("Not channels: " + channelsUri);
196        }
197        if (!PATH_INPUT.equals(paths.get(0)) || !PATH_CHANNEL.equals(paths.get(3))) {
198            throw new IllegalArgumentException("Not channels: " + channelsUri);
199        }
200        return paths.get(1);
201    }
202
203    /**
204     * Extracts the {@link Channels#COLUMN_SERVICE_NAME} from a given URI.
205     *
206     * @param channelsUri A URI constructed by {@link #buildChannelsUriForInput(ComponentName)} or
207     *            {@link #buildChannelsUriForInput(ComponentName, boolean)}.
208     * @hide
209     */
210    public static final String getServiceName(Uri channelsUri) {
211        final List<String> paths = channelsUri.getPathSegments();
212        if (paths.size() < 4) {
213            throw new IllegalArgumentException("Not channels: " + channelsUri);
214        }
215        if (!PATH_INPUT.equals(paths.get(0)) || !PATH_CHANNEL.equals(paths.get(3))) {
216            throw new IllegalArgumentException("Not channels: " + channelsUri);
217        }
218        return paths.get(2);
219    }
220
221    /**
222     * Extracts the {@link Channels#_ID} from a given URI.
223     *
224     * @param programsUri A URI constructed by {@link #buildProgramsUriForChannel(Uri)} or
225     *            {@link #buildProgramsUriForChannel(Uri, long, long)}.
226     * @hide
227     */
228    public static final String getChannelId(Uri programsUri) {
229        final List<String> paths = programsUri.getPathSegments();
230        if (paths.size() < 3) {
231            throw new IllegalArgumentException("Not programs: " + programsUri);
232        }
233        if (!PATH_CHANNEL.equals(paths.get(0)) || !PATH_PROGRAM.equals(paths.get(2))) {
234            throw new IllegalArgumentException("Not programs: " + programsUri);
235        }
236        return paths.get(1);
237    }
238
239
240    private TvContract() {}
241
242    /**
243     * Common base for the tables of TV channels/programs.
244     */
245    public interface BaseTvColumns extends BaseColumns {
246        /**
247         * The name of the package that owns a row in each table.
248         * <p>
249         * The TV provider fills it in with the name of the package that provides the initial data
250         * of that row. If the package is later uninstalled, the rows it owns are automatically
251         * removed from the tables.
252         * </p><p>
253         * Type: TEXT
254         * </p>
255         */
256        public static final String COLUMN_PACKAGE_NAME = "package_name";
257    }
258
259    /** Column definitions for the TV channels table. */
260    public static final class Channels implements BaseTvColumns {
261
262        /** The content:// style URI for this table. */
263        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/"
264                + PATH_CHANNEL);
265
266        /** The MIME type of a directory of TV channels. */
267        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/channel";
268
269        /** The MIME type of a single TV channel. */
270        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/channel";
271
272        /** A generic channel type. */
273        public static final int TYPE_OTHER = 0x0;
274
275        /** The channel type for NTSC. */
276        public static final int TYPE_NTSC = 0x1;
277
278        /** The channel type for PAL. */
279        public static final int TYPE_PAL = 0x2;
280
281        /** The channel type for SECAM. */
282        public static final int TYPE_SECAM = 0x3;
283
284        /** The special channel type used for pass-through inputs such as HDMI. */
285        public static final int TYPE_PASSTHROUGH = 0x00010000;
286
287        /** The channel type for DVB-T (terrestrial). */
288        public static final int TYPE_DVB_T = 0x00020000;
289
290        /** The channel type for DVB-T2 (terrestrial). */
291        public static final int TYPE_DVB_T2 = 0x00020001;
292
293        /** The channel type for DVB-S (satellite). */
294        public static final int TYPE_DVB_S = 0x00020100;
295
296        /** The channel type for DVB-S2 (satellite). */
297        public static final int TYPE_DVB_S2 = 0x00020101;
298
299        /** The channel type for DVB-C (cable). */
300        public static final int TYPE_DVB_C = 0x00020200;
301
302        /** The channel type for DVB-C2 (cable). */
303        public static final int TYPE_DVB_C2 = 0x00020201;
304
305        /** The channel type for DVB-H (handheld). */
306        public static final int TYPE_DVB_H = 0x00020300;
307
308        /** The channel type for DVB-SH (satellite). */
309        public static final int TYPE_DVB_SH = 0x00020400;
310
311        /** The channel type for ATSC (terrestrial). */
312        public static final int TYPE_ATSC_T = 0x00030000;
313
314        /** The channel type for ATSC (cable). */
315        public static final int TYPE_ATSC_C = 0x00030200;
316
317        /** The channel type for ATSC-M/H (mobile/handheld). */
318        public static final int TYPE_ATSC_M_H = 0x00030300;
319
320        /** The channel type for ISDB-T (terrestrial). */
321        public static final int TYPE_ISDB_T = 0x00040000;
322
323        /** The channel type for ISDB-Tb (Brazil). */
324        public static final int TYPE_ISDB_TB = 0x00040100;
325
326        /** The channel type for ISDB-S (satellite). */
327        public static final int TYPE_ISDB_S = 0x00040200;
328
329        /** The channel type for ISDB-C (cable). */
330        public static final int TYPE_ISDB_C = 0x00040300;
331
332        /** The channel type for 1seg (handheld). */
333        public static final int TYPE_1SEG = 0x00040400;
334
335        /** The channel type for DTMB (terrestrial). */
336        public static final int TYPE_DTMB = 0x00050000;
337
338        /** The channel type for CMMB (handheld). */
339        public static final int TYPE_CMMB = 0x00050100;
340
341        /** The channel type for T-DMB (terrestrial). */
342        public static final int TYPE_T_DMB = 0x00060000;
343
344        /** The channel type for S-DMB (satellite). */
345        public static final int TYPE_S_DMB = 0x00060100;
346
347        /** A generic service type. */
348        public static final int SERVICE_TYPE_OTHER = 0x0;
349
350        /** The service type for regular TV channels that have both audio and video. */
351        public static final int SERVICE_TYPE_AUDIO_VIDEO = 0x1;
352
353        /** The service type for radio channels that have audio only. */
354        public static final int SERVICE_TYPE_AUDIO = 0x2;
355
356        /**
357         * The name of the {@link TvInputService} subclass that provides this TV channel. This
358         * should be a fully qualified class name (such as, "com.example.project.TvInputService").
359         * <p>
360         * This is a required field.
361         * </p><p>
362         * Type: TEXT
363         * </p>
364         */
365        public static final String COLUMN_SERVICE_NAME = "service_name";
366
367        /**
368         * The predefined type of this TV channel.
369         * <p>
370         * This is primarily used to indicate which broadcast standard (e.g. ATSC, DVB or ISDB) the
371         * current channel conforms to, with an exception being {@link #TYPE_PASSTHROUGH}, which is
372         * a special channel type used only by pass-through inputs such as HDMI. The value should
373         * match to one of the followings: {@link #TYPE_OTHER}, {@link #TYPE_PASSTHROUGH},
374         * {@link #TYPE_DVB_T}, {@link #TYPE_DVB_T2}, {@link #TYPE_DVB_S}, {@link #TYPE_DVB_S2},
375         * {@link #TYPE_DVB_C}, {@link #TYPE_DVB_C2}, {@link #TYPE_DVB_H}, {@link #TYPE_DVB_SH},
376         * {@link #TYPE_ATSC_T}, {@link #TYPE_ATSC_C}, {@link #TYPE_ATSC_M_H}, {@link #TYPE_ISDB_T},
377         * {@link #TYPE_ISDB_TB}, {@link #TYPE_ISDB_S}, {@link #TYPE_ISDB_C} {@link #TYPE_1SEG},
378         * {@link #TYPE_DTMB}, {@link #TYPE_CMMB}, {@link #TYPE_T_DMB}, {@link #TYPE_S_DMB}
379         * </p><p>
380         * This is a required field.
381         * </p><p>
382         * Type: INTEGER
383         * </p>
384         */
385        public static final String COLUMN_TYPE = "type";
386
387        /**
388         * The predefined service type of this TV channel.
389         * <p>
390         * This is primarily used to indicate whether the current channel is a regular TV channel or
391         * a radio-like channel. Use the same coding for {@code service_type} in the underlying
392         * broadcast standard if it is defined there (e.g. ATSC A/53, ETSI EN 300 468 and ARIB
393         * STD-B10). Otherwise use one of the followings: {@link #SERVICE_TYPE_OTHER},
394         * {@link #SERVICE_TYPE_AUDIO_VIDEO}, {@link #SERVICE_TYPE_AUDIO}
395         * </p><p>
396         * This is a required field.
397         * </p><p>
398         * Type: INTEGER
399         * </p>
400         */
401        public static final String COLUMN_SERVICE_TYPE = "service_type";
402
403        /**
404         * The original network ID of this TV channel.
405         * <p>
406         * This is used to identify the originating delivery system, if applicable. Use the same
407         * coding for {@code original_network_id} in the underlying broadcast standard if it is
408         * defined there (e.g. ETSI EN 300 468/TR 101 211 and ARIB STD-B10). If channels cannot be
409         * globally identified by 2-tuple {{@link #COLUMN_TRANSPORT_STREAM_ID},
410         * {@link #COLUMN_SERVICE_ID}}, one must carefully assign a value to this field to form a
411         * unique 3-tuple identification {{@link #COLUMN_ORIGINAL_NETWORK_ID},
412         * {@link #COLUMN_TRANSPORT_STREAM_ID}, {@link #COLUMN_SERVICE_ID}} for its channels.
413         * </p><p>
414         * This is a required field if the channel cannot be uniquely identified by a 2-tuple
415         * {{@link #COLUMN_TRANSPORT_STREAM_ID}, {@link #COLUMN_SERVICE_ID}}.
416         * </p><p>
417         * Type: INTEGER
418         * </p>
419         */
420        public static final String COLUMN_ORIGINAL_NETWORK_ID = "original_network_id";
421
422        /**
423         * The transport stream ID of this channel.
424         * <p>
425         * This is used to identify the Transport Stream that contains the current channel from any
426         * other multiplex within a network, if applicable. Use the same coding for
427         * {@code transport_stream_id} defined in ISO/IEC 13818-1 if the channel is transmitted via
428         * the MPEG Transport Stream as is the case for many digital broadcast standards.
429         * </p><p>
430         * This is a required field if the current channel is transmitted via the MPEG Transport
431         * Stream.
432         * </p><p>
433         * Type: INTEGER
434         * </p>
435         */
436        public static final String COLUMN_TRANSPORT_STREAM_ID = "transport_stream_id";
437
438        /**
439         * The service ID of this channel.
440         * <p>
441         * This is used to identify the current service (roughly equivalent to channel) from any
442         * other service within the Transport Stream, if applicable. Use the same coding for
443         * {@code service_id} in the underlying broadcast standard if it is defined there (e.g. ETSI
444         * EN 300 468 and ARIB STD-B10) or {@code program_number} (which usually has the same value
445         * as {@code service_id}) in ISO/IEC 13818-1 if the channel is transmitted via the MPEG
446         * Transport Stream.
447         * </p><p>
448         * This is a required field if the current channel is transmitted via the MPEG Transport
449         * Stream.
450         * </p><p>
451         * Type: INTEGER
452         * </p>
453         */
454        public static final String COLUMN_SERVICE_ID = "service_id";
455
456        /**
457         * The channel number that is displayed to the user.
458         * <p>
459         * The format can vary depending on broadcast standard and product specification.
460         * </p><p>
461         * Type: TEXT
462         * </p>
463         */
464        public static final String COLUMN_DISPLAY_NUMBER = "display_number";
465
466        /**
467         * The channel name that is displayed to the user.
468         * <p>
469         * A call sign is a good candidate to use for this purpose but any name that helps the user
470         * recognize the current channel will be enough. Can also be empty depending on broadcast
471         * standard.
472         * </p><p>
473         * Type: TEXT
474         * </p>
475         */
476        public static final String COLUMN_DISPLAY_NAME = "display_name";
477
478        /**
479         * The description of this TV channel.
480         * <p>
481         * Can be empty initially.
482         * </p><p>
483         * Type: TEXT
484         * </p>
485         */
486        public static final String COLUMN_DESCRIPTION = "description";
487
488        /**
489         * The flag indicating whether this TV channel is browsable or not.
490         * <p>
491         * A value of 1 indicates the channel is included in the channel list that applications use
492         * to browse channels, a value of 0 indicates the channel is not included in the list. If
493         * not specified, this value is set to 1 (browsable) by default.
494         * </p><p>
495         * Type: INTEGER (boolean)
496         * </p>
497         */
498        public static final String COLUMN_BROWSABLE = "browsable";
499
500        /**
501         * The flag indicating whether this TV channel is searchable or not.
502         * <p>
503         * In some regions, it is not allowed to surface search results for a given channel without
504         * broadcaster's consent. This is used to impose such restriction. A value of 1 indicates
505         * the channel is searchable and can be included in search results, a value of 0 indicates
506         * the channel and its TV programs are hidden from search. If not specified, this value is
507         * set to 1 (searchable) by default.
508         * </p>
509         * <p>
510         * Type: INTEGER (boolean)
511         * </p>
512         */
513        public static final String COLUMN_SEARCHABLE = "searchable";
514
515        /**
516         * The flag indicating whether this TV channel is locked or not.
517         * <p>
518         * This is primarily used for alternative parental control to prevent unauthorized users
519         * from watching the current channel regardless of the content rating. A value of 1
520         * indicates the channel is locked and the user is required to enter passcode to unlock it
521         * in order to watch the current program from the channel, a value of 0 indicates the
522         * channel is not locked thus the user is not prompted to enter passcode If not specified,
523         * this value is set to 0 (not locked) by default.
524         * </p><p>
525         * Type: INTEGER (boolean)
526         * </p>
527         * @hide
528         */
529        public static final String COLUMN_LOCKED = "locked";
530
531        /**
532         * Internal data used by individual TV input services.
533         * <p>
534         * This is internal to the provider that inserted it, and should not be decoded by other
535         * apps.
536         * </p><p>
537         * Type: BLOB
538         * </p>
539         */
540        public static final String COLUMN_INTERNAL_PROVIDER_DATA = "internal_provider_data";
541
542        /**
543         * The version number of this row entry used by TV input services.
544         * <p>
545         * This is best used by sync adapters to identify the rows to update. The number can be
546         * defined by individual TV input services. One may assign the same value as
547         * {@code version_number} that appears in ETSI EN 300 468 or ATSC A/65, if the data are
548         * coming from a TV broadcast.
549         * </p><p>
550         * Type: INTEGER
551         * </p>
552         */
553        public static final String COLUMN_VERSION_NUMBER = "version_number";
554
555        private Channels() {}
556
557        /**
558         * A sub-directory of a single TV channel that represents its primary logo.
559         * <p>
560         * To access this directory, append {@link Channels.Logo#CONTENT_DIRECTORY} to the raw
561         * channel URI.  The resulting URI represents an image file, and should be interacted
562         * using ContentResolver.openAssetFileDescriptor.
563         * </p>
564         * <p>
565         * Note that this sub-directory also supports opening the logo as an asset file in write
566         * mode.  Callers can create or replace the primary logo associated with this channel by
567         * opening the asset file and writing the full-size photo contents into it.  When the file
568         * is closed, the image will be parsed, sized down if necessary, and stored.
569         * </p>
570         * <p>
571         * Usage example:
572         * <pre>
573         * public void writeChannelLogo(long channelId, byte[] logo) {
574         *     Uri channelLogoUri = TvContract.buildChannelLogoUri(channelId);
575         *     try {
576         *         AssetFileDescriptor fd =
577         *             getContentResolver().openAssetFileDescriptor(channelLogoUri, "rw");
578         *         OutputStream os = fd.createOutputStream();
579         *         os.write(logo);
580         *         os.close();
581         *         fd.close();
582         *     } catch (IOException e) {
583         *         // Handle error cases.
584         *     }
585         * }
586         * </pre>
587         * </p>
588         */
589        public static final class Logo {
590
591            /**
592             * The directory twig for this sub-table.
593             */
594            public static final String CONTENT_DIRECTORY = "logo";
595
596            private Logo() {}
597        }
598    }
599
600    /** Column definitions for the TV programs table. */
601    public static final class Programs implements BaseTvColumns {
602
603        /** The content:// style URI for this table. */
604        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/"
605                + PATH_PROGRAM);
606
607        /** The MIME type of a directory of TV programs. */
608        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/program";
609
610        /** The MIME type of a single TV program. */
611        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/program";
612
613        /**
614         * The ID of the TV channel that contains this TV program.
615         * <p>
616         * This is a part of the channel URI and matches to {@link BaseColumns#_ID}.
617         * </p><p>
618         * Type: INTEGER (long)
619         * </p>
620         */
621        public static final String COLUMN_CHANNEL_ID = "channel_id";
622
623        /**
624         * The title of this TV program.
625         * <p>
626         * Type: TEXT
627         * </p>
628         **/
629        public static final String COLUMN_TITLE = "title";
630
631        /**
632         * The start time of this TV program, in milliseconds since the epoch.
633         * <p>
634         * Type: INTEGER (long)
635         * </p>
636         */
637        public static final String COLUMN_START_TIME_UTC_MILLIS = "start_time_utc_millis";
638
639        /**
640         * The end time of this TV program, in milliseconds since the epoch.
641         * <p>
642         * Type: INTEGER (long)
643         * </p>
644         */
645        public static final String COLUMN_END_TIME_UTC_MILLIS = "end_time_utc_millis";
646
647        /**
648         * The comma-separated genre string of this TV program.
649         * <p>
650         * Use the same language appeared in the underlying broadcast standard, if applicable. (For
651         * example, one can refer to the genre strings used in Genre Descriptor of ATSC A/65 or
652         * Content Descriptor of ETSI EN 300 468, if appropriate.) Otherwise, leave empty.
653         * </p><p>
654         * Type: TEXT
655         * </p>
656         */
657        public static final String COLUMN_BROADCAST_GENRE = "broadcast_genre";
658
659        /**
660         * The comma-separated canonical genre string of this TV program.
661         * <p>
662         * Canonical genres are defined in {@link Genres}. Use {@link Genres#encode Genres.encode()}
663         * to create a text that can be stored in this column. Use {@link Genres#decode
664         * Genres.decode()} to get the canonical genre strings from the text stored in this column.
665         * </p><p>
666         * Type: TEXT
667         * </p>
668         * @see Genres
669         */
670        public static final String COLUMN_CANONICAL_GENRE = "canonical_genre";
671
672        /**
673         * The short description of this TV program that is displayed to the user by default.
674         * <p>
675         * It is recommended to limit the length of the descriptions to 256 characters.
676         * </p><p>
677         * Type: TEXT
678         * </p>
679         */
680        public static final String COLUMN_SHORT_DESCRIPTION = "short_description";
681
682        /**
683         * The detailed, lengthy description of this TV program that is displayed only when the user
684         * wants to see more information.
685         * <p>
686         * TV input services should leave this field empty if they have no additional details beyond
687         * {@link #COLUMN_SHORT_DESCRIPTION}.
688         * </p><p>
689         * Type: TEXT
690         * </p>
691         */
692        public static final String COLUMN_LONG_DESCRIPTION = "long_description";
693
694        /**
695         * The comma-separated audio languages of this TV program.
696         * <p>
697         * This is used to describe available audio languages included in the program. Use
698         * 3-character language code as specified by ISO 639-2.
699         * </p><p>
700         * Type: TEXT
701         * </p>
702         */
703        public static final String COLUMN_AUDIO_LANGUAGE = "audio_language";
704
705        /**
706         * The URI for the poster art of this TV program.
707         * <p>
708         * Can be empty.
709         * </p><p>
710         * Type: TEXT
711         * </p>
712         */
713        public static final String COLUMN_POSTER_ART_URI = "poster_art_uri";
714
715        /**
716         * The URI for the thumbnail of this TV program.
717         * <p>
718         * Can be empty.
719         * </p><p>
720         * Type: TEXT
721         * </p>
722         */
723        public static final String COLUMN_THUMBNAIL_URI = "thumbnail_uri";
724
725        /**
726         * Internal data used by individual TV input services.
727         * <p>
728         * This is internal to the provider that inserted it, and should not be decoded by other
729         * apps.
730         * </p><p>
731         * Type: BLOB
732         * </p>
733         */
734        public static final String COLUMN_INTERNAL_PROVIDER_DATA = "internal_provider_data";
735
736        /**
737         * The version number of this row entry used by TV input services.
738         * <p>
739         * This is best used by sync adapters to identify the rows to update. The number can be
740         * defined by individual TV input services. One may assign the same value as
741         * {@code version_number} in ETSI EN 300 468 or ATSC A/65, if the data are coming from a TV
742         * broadcast.
743         * </p><p>
744         * Type: INTEGER
745         * </p>
746         */
747        public static final String COLUMN_VERSION_NUMBER = "version_number";
748
749        private Programs() {}
750
751        /** Canonical genres for TV programs. */
752        public static final class Genres {
753            /** The genre for Family/Kids. */
754            public static final String FAMILY_KIDS = "Family/Kids";
755
756            /** The genre for Sports. */
757            public static final String SPORTS = "Sports";
758
759            /** The genre for Shopping. */
760            public static final String SHOPPING = "Shopping";
761
762            /** The genre for Movies. */
763            public static final String MOVIES = "Movies";
764
765            /** The genre for Comedy. */
766            public static final String COMEDY = "Comedy";
767
768            /** The genre for Travel. */
769            public static final String TRAVEL = "Travel";
770
771            /** The genre for Drama. */
772            public static final String DRAMA = "Drama";
773
774            /** The genre for Education. */
775            public static final String EDUCATION = "Education";
776
777            /** The genre for Animal/Wildlife. */
778            public static final String ANIMAL_WILDLIFE = "Animal/Wildlife";
779
780            /** The genre for News. */
781            public static final String NEWS = "News";
782
783            /** The genre for Gaming. */
784            public static final String GAMING = "Gaming";
785
786            private Genres() {}
787
788            /**
789             * Encodes canonical genre strings to a text that can be put into the database.
790             *
791             * @param genres Canonical genre strings. Use the strings defined in this class.
792             * @return an encoded genre string that can be inserted into the
793             *         {@link #COLUMN_CANONICAL_GENRE} column.
794             */
795            public static String encode(String... genres) {
796                StringBuilder sb = new StringBuilder();
797                String separator = "";
798                for (String genre : genres) {
799                    sb.append(separator).append(genre);
800                    separator = ",";
801                }
802                return sb.toString();
803            }
804
805            /**
806             * Decodes the canonical genre strings from the text stored in the database.
807             *
808             * @param genres The encoded genre string retrieved from the
809             *            {@link #COLUMN_CANONICAL_GENRE} column.
810             * @return canonical genre strings.
811             */
812            public static String[] decode(String genres) {
813                return genres.split("\\s*,\\s*");
814            }
815        }
816    }
817
818    /**
819     * Column definitions for the TV programs that the user watched. Applications do not have access
820     * to this table.
821     *
822     * @hide
823     */
824    public static final class WatchedPrograms implements BaseColumns {
825
826        /** The content:// style URI for this table. */
827        public static final Uri CONTENT_URI =
828                Uri.parse("content://" + AUTHORITY + "/watched_program");
829
830        /** The MIME type of a directory of watched programs. */
831        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/watched_program";
832
833        /** The MIME type of a single item in this table. */
834        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/watched_program";
835
836        /**
837         * The UTC time that the user started watching this TV program, in milliseconds since the
838         * epoch.
839         * <p>
840         * Type: INTEGER (long)
841         * </p>
842         */
843        public static final String COLUMN_WATCH_START_TIME_UTC_MILLIS =
844                "watch_start_time_utc_millis";
845
846        /**
847         * The UTC time that the user stopped watching this TV program, in milliseconds since the
848         * epoch.
849         * <p>
850         * Type: INTEGER (long)
851         * </p>
852         */
853        public static final String COLUMN_WATCH_END_TIME_UTC_MILLIS = "watch_end_time_utc_millis";
854
855        /**
856         * The channel ID that contains this TV program.
857         * <p>
858         * Type: INTEGER (long)
859         * </p>
860         */
861        public static final String COLUMN_CHANNEL_ID = "channel_id";
862
863        /**
864         * The title of this TV program.
865         * <p>
866         * Type: TEXT
867         * </p>
868         */
869        public static final String COLUMN_TITLE = "title";
870
871        /**
872         * The start time of this TV program, in milliseconds since the epoch.
873         * <p>
874         * Type: INTEGER (long)
875         * </p>
876         */
877        public static final String COLUMN_START_TIME_UTC_MILLIS = "start_time_utc_millis";
878
879        /**
880         * The end time of this TV program, in milliseconds since the epoch.
881         * <p>
882         * Type: INTEGER (long)
883         * </p>
884         */
885        public static final String COLUMN_END_TIME_UTC_MILLIS = "end_time_utc_millis";
886
887        /**
888         * The description of this TV program.
889         * <p>
890         * Type: TEXT
891         * </p>
892         */
893        public static final String COLUMN_DESCRIPTION = "description";
894
895        private WatchedPrograms() {}
896    }
897}
898