Skip to content

Commit 156aeec

Browse files
author
Ji-Hwan Lee
committed
TIF: Make TvContract URI consistent
- input/*/channel -> channel?input=* - channel/#/program -> program?channel=# Bug: 16806157, Bug: 16804331 Change-Id: Idbded032da166e789148c4b8e38ea521468fd9fa
1 parent dd06d04 commit 156aeec

1 file changed

Lines changed: 56 additions & 54 deletions

File tree

media/java/android/media/tv/TvContract.java

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,32 @@ public final class TvContract {
5353

5454
private static final String PATH_CHANNEL = "channel";
5555
private static final String PATH_PROGRAM = "program";
56-
private static final String PATH_INPUT = "input";
5756
private static final String PATH_PASSTHROUGH = "passthrough";
5857

58+
/**
59+
* An optional query, update or delete URI parameter that allows the caller to specify TV input
60+
* ID to filter channels.
61+
* @hide
62+
*/
63+
public static final String PARAM_INPUT = "input";
64+
65+
/**
66+
* An optional query, update or delete URI parameter that allows the caller to specify channel
67+
* ID to filter programs.
68+
* @hide
69+
*/
70+
public static final String PARAM_CHANNEL = "channel";
71+
5972
/**
6073
* An optional query, update or delete URI parameter that allows the caller to specify start
6174
* time (in milliseconds since the epoch) to filter programs.
62-
*
6375
* @hide
6476
*/
6577
public static final String PARAM_START_TIME = "start_time";
6678

6779
/**
6880
* An optional query, update or delete URI parameter that allows the caller to specify end time
6981
* (in milliseconds since the epoch) to filter programs.
70-
*
7182
* @hide
7283
*/
7384
public static final String PARAM_END_TIME = "end_time";
@@ -76,15 +87,13 @@ public final class TvContract {
7687
* A query, update or delete URI parameter that allows the caller to operate on all or
7788
* browsable-only channels. If set to "true", the rows that contain non-browsable channels are
7889
* not affected.
79-
*
8090
* @hide
8191
*/
8292
public static final String PARAM_BROWSABLE_ONLY = "browsable_only";
8393

8494
/**
8595
* A optional query, update or delete URI parameter that allows the caller to specify canonical
8696
* genre to filter programs.
87-
*
8897
* @hide
8998
*/
9099
public static final String PARAM_CANONICAL_GENRE = "canonical_genre";
@@ -116,17 +125,7 @@ public static final Uri buildChannelUri(long channelId) {
116125
*/
117126
public static final Uri buildChannelUriForPassthroughTvInput(String inputId) {
118127
return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(AUTHORITY)
119-
.appendPath(PATH_INPUT).appendPath(inputId).appendPath(PATH_CHANNEL)
120-
.appendPath(PATH_PASSTHROUGH).build();
121-
}
122-
123-
/**
124-
* Returns true, if {@code channelUri} is a channel URI for a passthrough TV input.
125-
* @hide
126-
*/
127-
@SystemApi
128-
public static final boolean isChannelUriForPassthroughTvInput(Uri channelUri) {
129-
return channelUri.toString().endsWith(PATH_PASSTHROUGH);
128+
.appendPath(PATH_PASSTHROUGH).appendPath(inputId).build();
130129
}
131130

132131
/**
@@ -144,7 +143,7 @@ public static final Uri buildChannelLogoUri(long channelId) {
144143
* @param channelUri The URI of the channel whose logo is pointed to.
145144
*/
146145
public static final Uri buildChannelLogoUri(Uri channelUri) {
147-
if (!PATH_CHANNEL.equals(channelUri.getPathSegments().get(0))) {
146+
if (!isChannelUriForTunerTvInput(channelUri)) {
148147
throw new IllegalArgumentException("Not a channel: " + channelUri);
149148
}
150149
return Uri.withAppendedPath(channelUri, Channels.Logo.CONTENT_DIRECTORY);
@@ -169,8 +168,8 @@ public static final Uri buildChannelsUriForInput(String inputId) {
169168
* @hide
170169
*/
171170
public static final Uri buildChannelsUriForInput(String inputId, boolean browsableOnly) {
172-
return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(AUTHORITY)
173-
.appendPath(PATH_INPUT).appendPath(inputId).appendPath(PATH_CHANNEL)
171+
return Channels.CONTENT_URI.buildUpon()
172+
.appendQueryParameter(PARAM_INPUT, inputId)
174173
.appendQueryParameter(PARAM_BROWSABLE_ONLY, String.valueOf(browsableOnly)).build();
175174
}
176175

@@ -194,8 +193,7 @@ public static final Uri buildChannelsUriForCanonicalGenre(String inputId, String
194193

195194
Uri uri;
196195
if (inputId == null) {
197-
uri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(AUTHORITY)
198-
.appendPath(PATH_CHANNEL).build();
196+
uri = Channels.CONTENT_URI;
199197
} else {
200198
uri = buildChannelsUriForInput(inputId, browsableOnly);
201199
}
@@ -217,9 +215,8 @@ public static final Uri buildProgramUri(long programId) {
217215
* @param channelId The ID of the channel to return programs for.
218216
*/
219217
public static final Uri buildProgramsUriForChannel(long channelId) {
220-
return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(AUTHORITY)
221-
.appendPath(PATH_CHANNEL).appendPath(String.valueOf(channelId))
222-
.appendPath(PATH_PROGRAM).build();
218+
return Programs.CONTENT_URI.buildUpon()
219+
.appendQueryParameter(PARAM_CHANNEL, String.valueOf(channelId)).build();
223220
}
224221

225222
/**
@@ -228,7 +225,7 @@ public static final Uri buildProgramsUriForChannel(long channelId) {
228225
* @param channelUri The URI of the channel to return programs for.
229226
*/
230227
public static final Uri buildProgramsUriForChannel(Uri channelUri) {
231-
if (!PATH_CHANNEL.equals(channelUri.getPathSegments().get(0))) {
228+
if (!isChannelUriForTunerTvInput(channelUri)) {
232229
throw new IllegalArgumentException("Not a channel: " + channelUri);
233230
}
234231
return buildProgramsUriForChannel(ContentUris.parseId(channelUri));
@@ -263,7 +260,7 @@ public static final Uri buildProgramsUriForChannel(long channelId, long startTim
263260
*/
264261
public static final Uri buildProgramsUriForChannel(Uri channelUri, long startTime,
265262
long endTime) {
266-
if (!PATH_CHANNEL.equals(channelUri.getPathSegments().get(0))) {
263+
if (!isChannelUriForTunerTvInput(channelUri)) {
267264
throw new IllegalArgumentException("Not a channel: " + channelUri);
268265
}
269266
return buildProgramsUriForChannel(ContentUris.parseId(channelUri), startTime, endTime);
@@ -279,41 +276,47 @@ public static final Uri buildWatchedProgramUri(long watchedProgramId) {
279276
return ContentUris.withAppendedId(WatchedPrograms.CONTENT_URI, watchedProgramId);
280277
}
281278

279+
private static final boolean isTvUri(Uri uri) {
280+
return uri != null && ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())
281+
&& AUTHORITY.equals(uri.getAuthority());
282+
}
283+
284+
private static final boolean isTwoSegmentUriStartingWith(Uri uri, String pathSegment) {
285+
List<String> pathSegments = uri.getPathSegments();
286+
return pathSegments.size() == 2 && pathSegment.equals(pathSegments.get(0));
287+
}
288+
282289
/**
283-
* Extracts the {@link Channels#COLUMN_INPUT_ID} from a given URI.
284-
*
285-
* @param channelsUri A URI constructed by {@link #buildChannelsUriForInput(String)},
286-
* {@link #buildChannelsUriForInput(String, boolean)}, or
287-
* {@link #buildChannelsUriForCanonicalGenre(String, String, boolean)}.
290+
* Returns true, if {@code uri} is a channel URI.
288291
* @hide
289292
*/
290-
public static final String getInputId(Uri channelsUri) {
291-
final List<String> paths = channelsUri.getPathSegments();
292-
if (paths.size() < 3) {
293-
throw new IllegalArgumentException("Not channels: " + channelsUri);
294-
}
295-
if (!PATH_INPUT.equals(paths.get(0)) || !PATH_CHANNEL.equals(paths.get(2))) {
296-
throw new IllegalArgumentException("Not channels: " + channelsUri);
297-
}
298-
return paths.get(1);
293+
public static final boolean isChannelUri(Uri uri) {
294+
return isChannelUriForTunerTvInput(uri) || isChannelUriForPassthroughTvInput(uri);
299295
}
300296

301297
/**
302-
* Extracts the {@link Channels#_ID} from a given URI.
303-
*
304-
* @param programsUri A URI constructed by {@link #buildProgramsUriForChannel(Uri)} or
305-
* {@link #buildProgramsUriForChannel(Uri, long, long)}.
298+
* Returns true, if {@code uri} is a channel URI for a tuner TV input.
306299
* @hide
307300
*/
308-
public static final String getChannelId(Uri programsUri) {
309-
final List<String> paths = programsUri.getPathSegments();
310-
if (paths.size() < 3) {
311-
throw new IllegalArgumentException("Not programs: " + programsUri);
312-
}
313-
if (!PATH_CHANNEL.equals(paths.get(0)) || !PATH_PROGRAM.equals(paths.get(2))) {
314-
throw new IllegalArgumentException("Not programs: " + programsUri);
315-
}
316-
return paths.get(1);
301+
public static final boolean isChannelUriForTunerTvInput(Uri uri) {
302+
return isTvUri(uri) && isTwoSegmentUriStartingWith(uri, PATH_CHANNEL);
303+
}
304+
305+
/**
306+
* Returns true, if {@code uri} is a channel URI for a passthrough TV input.
307+
* @hide
308+
*/
309+
@SystemApi
310+
public static final boolean isChannelUriForPassthroughTvInput(Uri uri) {
311+
return isTvUri(uri) && isTwoSegmentUriStartingWith(uri, PATH_PASSTHROUGH);
312+
}
313+
314+
/**
315+
* Returns true, if {@code uri} is a program URI.
316+
* @hide
317+
*/
318+
public static final boolean isProgramUri(Uri uri) {
319+
return isTvUri(uri) && isTwoSegmentUriStartingWith(uri, PATH_PROGRAM);
317320
}
318321

319322

@@ -1104,7 +1107,6 @@ public static boolean isCanonical(String genre) {
11041107
/**
11051108
* Column definitions for the TV programs that the user watched. Applications do not have access
11061109
* to this table.
1107-
*
11081110
* @hide
11091111
*/
11101112
public static final class WatchedPrograms implements BaseTvColumns {

0 commit comments

Comments
 (0)