aboutsummaryrefslogtreecommitdiff
path: root/partner_support/src/com/google/android/tv/partner/support/EpgContract.java
blob: 1f47b15bdbb8aeff0c394d775d07a4390b72c295 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.google.android.tv.partner.support;

import android.content.ContentUris;
import android.net.Uri;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * The contract between the EPG provider and applications. Contains definitions for the supported
 * URIs and columns.
 *
 * <h3>Overview</h3>
 *
 * <p>
 *
 * <p>EpgContract defines a basic database of EPG data for third party inputs. The information is
 * stored in {@link Lineups} and {@link EpgInputs} tables.
 *
 * <p>
 *
 * <ul>
 *   <li>A row in the {@link Lineups} table represents information TV Lineups for postal codes.
 *   <li>A row in the {@link EpgInputs} table represents partner or 3rd party inputs with the lineup
 *       that input uses.
 * </ul>
 */
public final class EpgContract {

    /** The authority for the EPG provider. */
    public static final String AUTHORITY = "com.google.android.tv.data.epg";

    /** The delimiter between channel numbers. */
    public static final String CHANNEL_NUMBER_DELIMITER = ", ";

    /**
     * A constant of the key for intent to indicate whether cloud EPG is used.
     *
     * <p>Value type: Boolean
     */
    public static final String EXTRA_USE_CLOUD_EPG = "com.google.android.tv.extra.USE_CLOUD_EPG";

    /**
     * Returns the list of channels as a CSV string.
     *
     * <p>Any commas in the original channels are converted to periods.
     */
    public static String toChannelString(List<String> channels) {
        // TODO use a StringJoiner if we set the min SDK to N
        StringBuilder result = new StringBuilder();
        for (String channel : channels) {
            channel = channel.replace(",", ".");
            if (result.length() > 0) {
                result.append(CHANNEL_NUMBER_DELIMITER);
            }
            result.append(channel);
        }
        return result.toString();
    }

    /** Returns a list of channels. */
    public static List<String> toChannelList(String channelString) {
        return channelString == null
                ? Collections.EMPTY_LIST
                : Arrays.asList(channelString.split(CHANNEL_NUMBER_DELIMITER));
    }

    /** Column definitions for the EPG lineups table. */
    public static final class Lineups {

        /** Base content:// style URI for all lines in a postal code. */
        private static final Uri LINEUPS_IN_POSTAL_CODE_URI =
                Uri.parse("content://" + AUTHORITY + "/lineups/postal_code");

        /** The MIME type of a directory of TV channels. */
        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/lineup";

        /** The MIME type of a single TV channel. */
        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/lineup";

        /** The content:// style URI all lineups in a postal code. */
        public static Uri uriForPostalCode(String postalCode) {
            return LINEUPS_IN_POSTAL_CODE_URI.buildUpon().appendPath(postalCode).build();
        }

        /**
         * The line up id.
         *
         * <p>This is a opaque string that should not be parsed.
         *
         * <p>Type: TEXT
         */
        public static final String COLUMN_ID = "_ID";

        /**
         * The line up name that is displayed to the user.
         *
         * <p>Type: TEXT
         */
        public static final String COLUMN_NAME = "NAME";

        /**
         * The channel numbers that are supported by this lineup that is displayed to the user.
         *
         * <p>Comma separated value of channel numbers
         *
         * <p>Type: TEXT
         */
        public static final String COLUMN_CHANNELS = "CHANNELS";

        /**
         * The line up type.
         *
         * <p>Type: TEXT
         */
        public static final String COLUMN_TYPE = "TYPE";

        private Lineups() {}
    }

    /** Column definitions for the EPG inputs table. */
    public static final class EpgInputs {

        /** The content:// style URI for this table. */
        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/epg_input");

        /** The MIME type of a directory of TV channels. */
        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/epg_input";

        /** The MIME type of a single TV channel. */
        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/epg_input";

        /**
         * Builds a URI that points to a specific input.
         *
         * @param rowId The ID of the input to point to.
         */
        public static final Uri buildUri(long rowId) {
            return ContentUris.withAppendedId(CONTENT_URI, rowId);
        }

        /**
         * The unique ID for a row.
         *
         * <p>Type: INTEGER (long)
         */
        public static final String COLUMN_ID = "_ID";

        /**
         * The name of the package that owns the current row.
         *
         * <p>The EPG provider fills in this column with the name of the package that provides the
         * initial data of the row. If the package is later uninstalled, the rows it owns are
         * automatically removed from the tables.
         *
         * <p>Type: TEXT
         */
        public static final String COLUMN_PACKAGE_NAME = "PACKAGE_NAME";

        /**
         * The ID of the TV input service that provides this TV channel.
         *
         * <p>Use {@link android.media.tv.TvContract#buildInputId} to build the ID.
         *
         * <p>This is a required field.
         *
         * <p>Type: TEXT
         */
        public static final String COLUMN_INPUT_ID = "INPUT_ID";
        /**
         * The line up id.
         *
         * <p>This is a opaque string that should not be parsed.
         *
         * <p>This is a required field.
         *
         * <p>Type: TEXT
         */
        public static final String COLUMN_LINEUP_ID = "LINEUP_ID";

        private EpgInputs() {}
    }

    private EpgContract() {}
}