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