From cf9bec5bb6abfe134332d5004c1fee90901da62c Mon Sep 17 00:00:00 2001 From: Jae Seo Date: Fri, 13 Jun 2014 11:09:09 -0700 Subject: [PATCH] TvContract: Enable building programs URI also with channel ID Bug: 15446137 Change-Id: I322c1b90c272e553b028af1f9011feecde124915 --- api/current.txt | 2 ++ media/java/android/media/tv/TvContract.java | 39 +++++++++++++++++---- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/api/current.txt b/api/current.txt index 2f813aca82866..c74c6c5372d21 100644 --- a/api/current.txt +++ b/api/current.txt @@ -15791,7 +15791,9 @@ package android.media.tv { method public static final android.net.Uri buildChannelsUriForInput(android.content.ComponentName); method public static final android.net.Uri buildChannelsUriForInput(android.content.ComponentName, boolean); method public static final android.net.Uri buildProgramUri(long); + method public static final android.net.Uri buildProgramsUriForChannel(long); method public static final android.net.Uri buildProgramsUriForChannel(android.net.Uri); + method public static final android.net.Uri buildProgramsUriForChannel(long, long, long); method public static final android.net.Uri buildProgramsUriForChannel(android.net.Uri, long, long); field public static final java.lang.String AUTHORITY = "android.media.tv"; } diff --git a/media/java/android/media/tv/TvContract.java b/media/java/android/media/tv/TvContract.java index 7ff2c2ea80604..3f0405d78a9e3 100644 --- a/media/java/android/media/tv/TvContract.java +++ b/media/java/android/media/tv/TvContract.java @@ -141,6 +141,17 @@ public final class TvContract { return ContentUris.withAppendedId(Programs.CONTENT_URI, programId); } + /** + * Builds a URI that points to all programs on a given channel. + * + * @param channelId The ID of the channel to return programs for. + */ + public static final Uri buildProgramsUriForChannel(long channelId) { + return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(AUTHORITY) + .appendPath(PATH_CHANNEL).appendPath(String.valueOf(channelId)) + .appendPath(PATH_PROGRAM).build(); + } + /** * Builds a URI that points to all programs on a given channel. * @@ -150,9 +161,24 @@ public final class TvContract { if (!PATH_CHANNEL.equals(channelUri.getPathSegments().get(0))) { throw new IllegalArgumentException("Not a channel: " + channelUri); } - String channelId = String.valueOf(ContentUris.parseId(channelUri)); - return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(AUTHORITY) - .appendPath(PATH_CHANNEL).appendPath(channelId).appendPath(PATH_PROGRAM).build(); + return buildProgramsUriForChannel(ContentUris.parseId(channelUri)); + } + + /** + * Builds a URI that points to programs on a specific channel whose schedules overlap with the + * given time frame. + * + * @param channelId The ID of the channel to return programs for. + * @param startTime The start time used to filter programs. The returned programs should have + * {@link Programs#COLUMN_END_TIME_UTC_MILLIS} that is greater than this time. + * @param endTime The end time used to filter programs. The returned programs should have + * {@link Programs#COLUMN_START_TIME_UTC_MILLIS} that is less than this time. + */ + public static final Uri buildProgramsUriForChannel(long channelId, long startTime, + long endTime) { + Uri uri = buildProgramsUriForChannel(channelId); + return uri.buildUpon().appendQueryParameter(PARAM_START_TIME, String.valueOf(startTime)) + .appendQueryParameter(PARAM_END_TIME, String.valueOf(endTime)).build(); } /** @@ -167,9 +193,10 @@ public final class TvContract { */ public static final Uri buildProgramsUriForChannel(Uri channelUri, long startTime, long endTime) { - Uri uri = buildProgramsUriForChannel(channelUri); - return uri.buildUpon().appendQueryParameter(PARAM_START_TIME, String.valueOf(startTime)) - .appendQueryParameter(PARAM_END_TIME, String.valueOf(endTime)).build(); + if (!PATH_CHANNEL.equals(channelUri.getPathSegments().get(0))) { + throw new IllegalArgumentException("Not a channel: " + channelUri); + } + return buildProgramsUriForChannel(ContentUris.parseId(channelUri), startTime, endTime); } /**