summaryrefslogtreecommitdiffstats
path: root/core/java/android/provider/SubscribedFeeds.java
blob: f94b4427bd283e05346106d6b1d334b9f33c13d8 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
 * Copyright (C) 2006 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 android.provider;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.accounts.Account;

/**
 * The SubscribedFeeds provider stores all information about subscribed feeds.
 * 
 * @hide
 */
public class SubscribedFeeds {
    private SubscribedFeeds() {}
    
    /**
     * Columns from the Feed table that other tables join into themselves.
     */
    public interface FeedColumns {
        /**
         * The feed url.
         * <P>Type: TEXT</P>
         */
        public static final String FEED = "feed";

        /**
         * The authority that cares about the feed.
         * <P>Type: TEXT</P>
         */
        public static final String AUTHORITY = "authority";

        /**
         * The gaia service this feed is for (used for authentication).
         * <P>Type: TEXT</P>
         */
        public static final String SERVICE = "service";
    }

    /**
     * Provides constants to access the Feeds table and some utility methods
     * to ease using the Feeds content provider.
     */
    public static final class Feeds implements BaseColumns, SyncConstValue,
            FeedColumns {
        private Feeds() {}
        
        public static Cursor query(ContentResolver cr, String[] projection) {
            return cr.query(CONTENT_URI, projection, null, null, DEFAULT_SORT_ORDER);
        }

        public static Cursor query(ContentResolver cr, String[] projection,
                String where, String[] whereArgs, String orderBy) {
            return cr.query(CONTENT_URI, projection, where,
                    whereArgs, (orderBy == null) ? DEFAULT_SORT_ORDER : orderBy);
        }

        /**
         * The content:// style URL for this table
         */
        public static final Uri CONTENT_URI =
            Uri.parse("content://subscribedfeeds/feeds");

        /**
         * The content:// style URL for this table
         */
        public static final Uri DELETED_CONTENT_URI =
            Uri.parse("content://subscribedfeeds/deleted_feeds");

        /**
         * The MIME type of {@link #CONTENT_URI} providing a directory of
         * subscribed feeds.
         */
        public static final String CONTENT_TYPE =
                "vnd.android.cursor.dir/subscribedfeeds";

        /**
         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
         * subscribed feed.
         */
        public static final String CONTENT_ITEM_TYPE =
                "vnd.android.cursor.item/subscribedfeed";

        /**
         * The default sort order for this table
         */
        public static final String DEFAULT_SORT_ORDER = "_SYNC_ACCOUNT_TYPE, _SYNC_ACCOUNT ASC";
    }

    /**
     * A convenience method to add a feed to the SubscribedFeeds
     * content provider. The user specifies the values of the FEED,
     * _SYNC_ACCOUNT, AUTHORITY. SERVICE, and ROUTING_INFO.
     * @param resolver          used to access the underlying content provider
     * @param feed              corresponds to the FEED column
     * @param account           corresponds to the _SYNC_ACCOUNT column
     * @param authority         corresponds to the AUTHORITY column
     * @param service           corresponds to the SERVICE column
     * @return  the Uri of the feed that was added
     */
    public static Uri addFeed(ContentResolver resolver,
            String feed, Account account,
            String authority, String service) {
        ContentValues values = new ContentValues();
        values.put(SubscribedFeeds.Feeds.FEED, feed);
        values.put(SubscribedFeeds.Feeds._SYNC_ACCOUNT, account.mName);
        values.put(SubscribedFeeds.Feeds._SYNC_ACCOUNT_TYPE, account.mType);
        values.put(SubscribedFeeds.Feeds.AUTHORITY, authority);
        values.put(SubscribedFeeds.Feeds.SERVICE, service);
        return resolver.insert(SubscribedFeeds.Feeds.CONTENT_URI, values);
    }

    public static int deleteFeed(ContentResolver resolver,
            String feed, Account account, String authority) {
        StringBuilder where = new StringBuilder();
        where.append(SubscribedFeeds.Feeds._SYNC_ACCOUNT + "=?");
        where.append(" AND " + SubscribedFeeds.Feeds._SYNC_ACCOUNT_TYPE + "=?");
        where.append(" AND " + SubscribedFeeds.Feeds.FEED + "=?");
        where.append(" AND " + SubscribedFeeds.Feeds.AUTHORITY + "=?");
        return resolver.delete(SubscribedFeeds.Feeds.CONTENT_URI,
                where.toString(), new String[] {account.mName, account.mType, feed, authority});
    }

    public static int deleteFeeds(ContentResolver resolver,
            Account account, String authority) {
        StringBuilder where = new StringBuilder();
        where.append(SubscribedFeeds.Feeds._SYNC_ACCOUNT + "=?");
        where.append(" AND " + SubscribedFeeds.Feeds._SYNC_ACCOUNT_TYPE + "=?");
        where.append(" AND " + SubscribedFeeds.Feeds.AUTHORITY + "=?");
        return resolver.delete(SubscribedFeeds.Feeds.CONTENT_URI,
                where.toString(), new String[] {account.mName, account.mType, authority});
    }

    /**
     * Columns from the Accounts table.
     */
    public interface AccountColumns {
        /**
         * The account.
         * <P>Type: TEXT</P>
         */
        public static final String _SYNC_ACCOUNT = SyncConstValue._SYNC_ACCOUNT;

        /**
         * The account type.
         * <P>Type: TEXT</P>
         */
        public static final String _SYNC_ACCOUNT_TYPE = SyncConstValue._SYNC_ACCOUNT_TYPE;
    }

    /**
     * Provides constants to access the Accounts table and some utility methods
     * to ease using it.
     */
    public static final class Accounts implements BaseColumns, AccountColumns {
        private Accounts() {}

        public static Cursor query(ContentResolver cr, String[] projection) {
            return cr.query(CONTENT_URI, projection, null, null, DEFAULT_SORT_ORDER);
        }

        public static Cursor query(ContentResolver cr, String[] projection,
                String where, String orderBy) {
            return cr.query(CONTENT_URI, projection, where,
                    null, (orderBy == null) ? DEFAULT_SORT_ORDER : orderBy);
        }

        /**
         * The content:// style URL for this table
         */
        public static final Uri CONTENT_URI =
            Uri.parse("content://subscribedfeeds/accounts");

        /**
         * The MIME type of {@link #CONTENT_URI} providing a directory of
         * accounts that have subscribed feeds.
         */
        public static final String CONTENT_TYPE =
                "vnd.android.cursor.dir/subscribedfeedaccounts";

        /**
         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
         * account in the subscribed feeds.
         */
        public static final String CONTENT_ITEM_TYPE =
                "vnd.android.cursor.item/subscribedfeedaccount";

        /**
         * The default sort order for this table
         */
        public static final String DEFAULT_SORT_ORDER = "_SYNC_ACCOUNT_TYPE, _SYNC_ACCOUNT ASC";
    }
}