aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tv/util/TvUriMatcher.java
blob: 9e74117e606c9a0cf05270b495cf04450e1754aa (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
/*
 * Copyright (C) 2016 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.android.tv.util;

import android.app.SearchManager;
import android.content.UriMatcher;
import android.media.tv.TvContract;
import android.net.Uri;
import android.support.annotation.IntDef;
import com.android.tv.search.LocalSearchProvider;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/** Utility class to aid in matching URIs in TvProvider. */
public class TvUriMatcher {
    private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
        MATCH_CHANNEL,
        MATCH_CHANNEL_ID,
        MATCH_PROGRAM,
        MATCH_PROGRAM_ID,
        MATCH_RECORDED_PROGRAM,
        MATCH_RECORDED_PROGRAM_ID,
        MATCH_WATCHED_PROGRAM_ID,
        MATCH_ON_DEVICE_SEARCH
    })
    private @interface TvProviderUriMatchCode {}
    /** The code for the channels URI. */
    public static final int MATCH_CHANNEL = 1;
    /** The code for the channel URI. */
    public static final int MATCH_CHANNEL_ID = 2;
    /** The code for the programs URI. */
    public static final int MATCH_PROGRAM = 3;
    /** The code for the program URI. */
    public static final int MATCH_PROGRAM_ID = 4;
    /** The code for the recorded programs URI. */
    public static final int MATCH_RECORDED_PROGRAM = 5;
    /** The code for the recorded program URI. */
    public static final int MATCH_RECORDED_PROGRAM_ID = 6;
    /** The code for the watched program URI. */
    public static final int MATCH_WATCHED_PROGRAM_ID = 7;
    /** The code for the on-device search URI. */
    public static final int MATCH_ON_DEVICE_SEARCH = 8;

    static {
        URI_MATCHER.addURI(TvContract.AUTHORITY, "channel", MATCH_CHANNEL);
        URI_MATCHER.addURI(TvContract.AUTHORITY, "channel/#", MATCH_CHANNEL_ID);
        URI_MATCHER.addURI(TvContract.AUTHORITY, "program", MATCH_PROGRAM);
        URI_MATCHER.addURI(TvContract.AUTHORITY, "program/#", MATCH_PROGRAM_ID);
        URI_MATCHER.addURI(TvContract.AUTHORITY, "recorded_program", MATCH_RECORDED_PROGRAM);
        URI_MATCHER.addURI(TvContract.AUTHORITY, "recorded_program/#", MATCH_RECORDED_PROGRAM_ID);
        URI_MATCHER.addURI(TvContract.AUTHORITY, "watched_program/#", MATCH_WATCHED_PROGRAM_ID);
        URI_MATCHER.addURI(
                LocalSearchProvider.AUTHORITY,
                SearchManager.SUGGEST_URI_PATH_QUERY + "/*",
                MATCH_ON_DEVICE_SEARCH);
    }

    private TvUriMatcher() {}

    /**
     * Try to match against the path in a url.
     *
     * @see UriMatcher#match
     */
    @SuppressWarnings("WrongConstant")
    @TvProviderUriMatchCode
    public static int match(Uri uri) {
        return URI_MATCHER.match(uri);
    }
}