blob: f94b4427bd283e05346106d6b1d334b9f33c13d8 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 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
17package android.provider;
18
19import android.content.ContentResolver;
20import android.content.ContentValues;
21import android.database.Cursor;
22import android.net.Uri;
Fred Quintanad9d2f112009-04-23 13:36:27 -070023import android.accounts.Account;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
25/**
26 * The SubscribedFeeds provider stores all information about subscribed feeds.
27 *
28 * @hide
29 */
30public class SubscribedFeeds {
31 private SubscribedFeeds() {}
32
33 /**
34 * Columns from the Feed table that other tables join into themselves.
35 */
36 public interface FeedColumns {
37 /**
38 * The feed url.
39 * <P>Type: TEXT</P>
40 */
41 public static final String FEED = "feed";
42
43 /**
44 * The authority that cares about the feed.
45 * <P>Type: TEXT</P>
46 */
47 public static final String AUTHORITY = "authority";
48
49 /**
50 * The gaia service this feed is for (used for authentication).
51 * <P>Type: TEXT</P>
52 */
53 public static final String SERVICE = "service";
54 }
55
56 /**
57 * Provides constants to access the Feeds table and some utility methods
58 * to ease using the Feeds content provider.
59 */
60 public static final class Feeds implements BaseColumns, SyncConstValue,
61 FeedColumns {
62 private Feeds() {}
63
64 public static Cursor query(ContentResolver cr, String[] projection) {
65 return cr.query(CONTENT_URI, projection, null, null, DEFAULT_SORT_ORDER);
66 }
67
68 public static Cursor query(ContentResolver cr, String[] projection,
69 String where, String[] whereArgs, String orderBy) {
70 return cr.query(CONTENT_URI, projection, where,
71 whereArgs, (orderBy == null) ? DEFAULT_SORT_ORDER : orderBy);
72 }
73
74 /**
75 * The content:// style URL for this table
76 */
77 public static final Uri CONTENT_URI =
78 Uri.parse("content://subscribedfeeds/feeds");
79
80 /**
81 * The content:// style URL for this table
82 */
83 public static final Uri DELETED_CONTENT_URI =
84 Uri.parse("content://subscribedfeeds/deleted_feeds");
85
86 /**
87 * The MIME type of {@link #CONTENT_URI} providing a directory of
88 * subscribed feeds.
89 */
90 public static final String CONTENT_TYPE =
91 "vnd.android.cursor.dir/subscribedfeeds";
92
93 /**
94 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
95 * subscribed feed.
96 */
97 public static final String CONTENT_ITEM_TYPE =
98 "vnd.android.cursor.item/subscribedfeed";
99
100 /**
101 * The default sort order for this table
102 */
Fred Quintanad9d2f112009-04-23 13:36:27 -0700103 public static final String DEFAULT_SORT_ORDER = "_SYNC_ACCOUNT_TYPE, _SYNC_ACCOUNT ASC";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 }
105
106 /**
107 * A convenience method to add a feed to the SubscribedFeeds
108 * content provider. The user specifies the values of the FEED,
109 * _SYNC_ACCOUNT, AUTHORITY. SERVICE, and ROUTING_INFO.
110 * @param resolver used to access the underlying content provider
111 * @param feed corresponds to the FEED column
112 * @param account corresponds to the _SYNC_ACCOUNT column
113 * @param authority corresponds to the AUTHORITY column
114 * @param service corresponds to the SERVICE column
115 * @return the Uri of the feed that was added
116 */
117 public static Uri addFeed(ContentResolver resolver,
Fred Quintanad9d2f112009-04-23 13:36:27 -0700118 String feed, Account account,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 String authority, String service) {
120 ContentValues values = new ContentValues();
121 values.put(SubscribedFeeds.Feeds.FEED, feed);
Fred Quintanad9d2f112009-04-23 13:36:27 -0700122 values.put(SubscribedFeeds.Feeds._SYNC_ACCOUNT, account.mName);
123 values.put(SubscribedFeeds.Feeds._SYNC_ACCOUNT_TYPE, account.mType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 values.put(SubscribedFeeds.Feeds.AUTHORITY, authority);
125 values.put(SubscribedFeeds.Feeds.SERVICE, service);
126 return resolver.insert(SubscribedFeeds.Feeds.CONTENT_URI, values);
127 }
128
129 public static int deleteFeed(ContentResolver resolver,
Fred Quintanad9d2f112009-04-23 13:36:27 -0700130 String feed, Account account, String authority) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 StringBuilder where = new StringBuilder();
132 where.append(SubscribedFeeds.Feeds._SYNC_ACCOUNT + "=?");
Fred Quintanad9d2f112009-04-23 13:36:27 -0700133 where.append(" AND " + SubscribedFeeds.Feeds._SYNC_ACCOUNT_TYPE + "=?");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 where.append(" AND " + SubscribedFeeds.Feeds.FEED + "=?");
135 where.append(" AND " + SubscribedFeeds.Feeds.AUTHORITY + "=?");
136 return resolver.delete(SubscribedFeeds.Feeds.CONTENT_URI,
Fred Quintanad9d2f112009-04-23 13:36:27 -0700137 where.toString(), new String[] {account.mName, account.mType, feed, authority});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 }
139
140 public static int deleteFeeds(ContentResolver resolver,
Fred Quintanad9d2f112009-04-23 13:36:27 -0700141 Account account, String authority) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 StringBuilder where = new StringBuilder();
143 where.append(SubscribedFeeds.Feeds._SYNC_ACCOUNT + "=?");
Fred Quintanad9d2f112009-04-23 13:36:27 -0700144 where.append(" AND " + SubscribedFeeds.Feeds._SYNC_ACCOUNT_TYPE + "=?");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 where.append(" AND " + SubscribedFeeds.Feeds.AUTHORITY + "=?");
146 return resolver.delete(SubscribedFeeds.Feeds.CONTENT_URI,
Fred Quintanad9d2f112009-04-23 13:36:27 -0700147 where.toString(), new String[] {account.mName, account.mType, authority});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 }
149
150 /**
151 * Columns from the Accounts table.
152 */
153 public interface AccountColumns {
154 /**
155 * The account.
156 * <P>Type: TEXT</P>
157 */
158 public static final String _SYNC_ACCOUNT = SyncConstValue._SYNC_ACCOUNT;
Fred Quintanad9d2f112009-04-23 13:36:27 -0700159
160 /**
161 * The account type.
162 * <P>Type: TEXT</P>
163 */
164 public static final String _SYNC_ACCOUNT_TYPE = SyncConstValue._SYNC_ACCOUNT_TYPE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 }
166
167 /**
168 * Provides constants to access the Accounts table and some utility methods
169 * to ease using it.
170 */
171 public static final class Accounts implements BaseColumns, AccountColumns {
172 private Accounts() {}
173
174 public static Cursor query(ContentResolver cr, String[] projection) {
175 return cr.query(CONTENT_URI, projection, null, null, DEFAULT_SORT_ORDER);
176 }
177
178 public static Cursor query(ContentResolver cr, String[] projection,
179 String where, String orderBy) {
180 return cr.query(CONTENT_URI, projection, where,
181 null, (orderBy == null) ? DEFAULT_SORT_ORDER : orderBy);
182 }
183
184 /**
185 * The content:// style URL for this table
186 */
187 public static final Uri CONTENT_URI =
188 Uri.parse("content://subscribedfeeds/accounts");
189
190 /**
191 * The MIME type of {@link #CONTENT_URI} providing a directory of
192 * accounts that have subscribed feeds.
193 */
194 public static final String CONTENT_TYPE =
195 "vnd.android.cursor.dir/subscribedfeedaccounts";
196
197 /**
198 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
199 * account in the subscribed feeds.
200 */
201 public static final String CONTENT_ITEM_TYPE =
202 "vnd.android.cursor.item/subscribedfeedaccount";
203
204 /**
205 * The default sort order for this table
206 */
Fred Quintanad9d2f112009-04-23 13:36:27 -0700207 public static final String DEFAULT_SORT_ORDER = "_SYNC_ACCOUNT_TYPE, _SYNC_ACCOUNT ASC";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 }
209}