• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 
17 package com.android.tv.util;
18 
19 import android.content.UriMatcher;
20 import android.media.tv.TvContract;
21 import android.net.Uri;
22 import android.support.annotation.IntDef;
23 
24 import java.lang.annotation.Retention;
25 import java.lang.annotation.RetentionPolicy;
26 
27 /**
28  * Utility class to aid in matching URIs in TvProvider.
29  */
30 public class TvProviderUriMatcher {
31     private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
32 
33     @Retention(RetentionPolicy.SOURCE)
34     @IntDef({MATCH_CHANNEL, MATCH_CHANNEL_ID, MATCH_PROGRAM, MATCH_PROGRAM_ID,
35             MATCH_RECORDED_PROGRAM, MATCH_RECORDED_PROGRAM_ID, MATCH_WATCHED_PROGRAM_ID})
36     private @interface TvProviderUriMatchCode {}
37     /** The code for the channels URI. */
38     public static final int MATCH_CHANNEL = 1;
39     /** The code for the channel URI. */
40     public static final int MATCH_CHANNEL_ID = 2;
41     /** The code for the programs URI. */
42     public static final int MATCH_PROGRAM = 3;
43     /** The code for the program URI. */
44     public static final int MATCH_PROGRAM_ID = 4;
45     /** The code for the recorded programs URI. */
46     public static final int MATCH_RECORDED_PROGRAM = 5;
47     /** The code for the recorded program URI. */
48     public static final int MATCH_RECORDED_PROGRAM_ID = 6;
49     /** The code for the watched program URI. */
50     public static final int MATCH_WATCHED_PROGRAM_ID = 7;
51     static {
URI_MATCHER.addURI(TvContract.AUTHORITY, "channel", MATCH_CHANNEL)52         URI_MATCHER.addURI(TvContract.AUTHORITY, "channel", MATCH_CHANNEL);
URI_MATCHER.addURI(TvContract.AUTHORITY, "channel/#", MATCH_CHANNEL_ID)53         URI_MATCHER.addURI(TvContract.AUTHORITY, "channel/#", MATCH_CHANNEL_ID);
URI_MATCHER.addURI(TvContract.AUTHORITY, "program", MATCH_PROGRAM)54         URI_MATCHER.addURI(TvContract.AUTHORITY, "program", MATCH_PROGRAM);
URI_MATCHER.addURI(TvContract.AUTHORITY, "program/#", MATCH_PROGRAM_ID)55         URI_MATCHER.addURI(TvContract.AUTHORITY, "program/#", MATCH_PROGRAM_ID);
URI_MATCHER.addURI(TvContract.AUTHORITY, "recorded_program", MATCH_RECORDED_PROGRAM)56         URI_MATCHER.addURI(TvContract.AUTHORITY, "recorded_program", MATCH_RECORDED_PROGRAM);
URI_MATCHER.addURI(TvContract.AUTHORITY, "recorded_program/#", MATCH_RECORDED_PROGRAM_ID)57         URI_MATCHER.addURI(TvContract.AUTHORITY, "recorded_program/#", MATCH_RECORDED_PROGRAM_ID);
URI_MATCHER.addURI(TvContract.AUTHORITY, "watched_program/#", MATCH_WATCHED_PROGRAM_ID)58         URI_MATCHER.addURI(TvContract.AUTHORITY, "watched_program/#", MATCH_WATCHED_PROGRAM_ID);
59     }
60 
TvProviderUriMatcher()61     private TvProviderUriMatcher() { }
62 
63     /**
64      * Try to match against the path in a url.
65      *
66      * @see UriMatcher#match
67      */
68     @SuppressWarnings("WrongConstant")
match(Uri uri)69     @TvProviderUriMatchCode public static int match(Uri uri) {
70         return URI_MATCHER.match(uri);
71     }
72 }
73