BrowserContract.java revision 4d67ac248fd64492c71327f829b54235f8a4320c
1/* 2 * Copyright (C) 2010 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.accounts.Account; 20import android.content.ContentProviderClient; 21import android.content.ContentProviderOperation; 22import android.content.ContentResolver; 23import android.content.ContentUris; 24import android.graphics.BitmapFactory; 25import android.net.Uri; 26import android.os.RemoteException; 27import android.provider.SyncStateContract; 28import android.util.Pair; 29 30/** 31 * @hide 32 */ 33public class BrowserContract { 34 /** The authority for the browser provider */ 35 public static final String AUTHORITY = "com.android.browser"; 36 37 /** A content:// style uri to the authority for the browser provider */ 38 public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY); 39 40 /** 41 * An optional insert, update or delete URI parameter that allows the caller 42 * to specify that it is a sync adapter. The default value is false. If true 43 * the dirty flag is not automatically set and the "syncToNetwork" parameter 44 * is set to false when calling 45 * {@link ContentResolver#notifyChange(android.net.Uri, android.database.ContentObserver, boolean)}. 46 */ 47 public static final String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter"; 48 49 /** 50 * A parameter for use when querying any table that allows specifying a limit on the number 51 * of rows returned. 52 */ 53 public static final String PARAM_LIMIT = "limit"; 54 55 /** 56 * Generic columns for use by sync adapters. The specific functions of 57 * these columns are private to the sync adapter. Other clients of the API 58 * should not attempt to either read or write these columns. 59 */ 60 interface BaseSyncColumns { 61 /** Generic column for use by sync adapters. */ 62 public static final String SYNC1 = "sync1"; 63 /** Generic column for use by sync adapters. */ 64 public static final String SYNC2 = "sync2"; 65 /** Generic column for use by sync adapters. */ 66 public static final String SYNC3 = "sync3"; 67 /** Generic column for use by sync adapters. */ 68 public static final String SYNC4 = "sync4"; 69 /** Generic column for use by sync adapters. */ 70 public static final String SYNC5 = "sync5"; 71 } 72 73 /** 74 * Convenience definitions for use in implementing chrome bookmarks sync in the Bookmarks table. 75 */ 76 public static final class ChromeSyncColumns { 77 private ChromeSyncColumns() {} 78 79 /** The server unique ID for an item */ 80 public static final String SERVER_UNIQUE = BaseSyncColumns.SYNC3; 81 82 public static final String FOLDER_NAME_ROOT = "google_chrome"; 83 public static final String FOLDER_NAME_BOOKMARKS = "google_chrome_bookmarks"; 84 public static final String FOLDER_NAME_BOOKMARKS_BAR = "bookmark_bar"; 85 public static final String FOLDER_NAME_OTHER_BOOKMARKS = "other_bookmarks"; 86 87 /** The client unique ID for an item */ 88 public static final String CLIENT_UNIQUE = BaseSyncColumns.SYNC4; 89 } 90 91 /** 92 * Columns that appear when each row of a table belongs to a specific 93 * account, including sync information that an account may need. 94 */ 95 interface SyncColumns extends BaseSyncColumns { 96 /** 97 * The name of the account instance to which this row belongs, which when paired with 98 * {@link #ACCOUNT_TYPE} identifies a specific account. 99 * <P>Type: TEXT</P> 100 */ 101 public static final String ACCOUNT_NAME = "account_name"; 102 103 /** 104 * The type of account to which this row belongs, which when paired with 105 * {@link #ACCOUNT_NAME} identifies a specific account. 106 * <P>Type: TEXT</P> 107 */ 108 public static final String ACCOUNT_TYPE = "account_type"; 109 110 /** 111 * String that uniquely identifies this row to its source account. 112 * <P>Type: TEXT</P> 113 */ 114 public static final String SOURCE_ID = "sourceid"; 115 116 /** 117 * Version number that is updated whenever this row or its related data 118 * changes. 119 * <P>Type: INTEGER</P> 120 */ 121 public static final String VERSION = "version"; 122 123 /** 124 * Flag indicating that {@link #VERSION} has changed, and this row needs 125 * to be synchronized by its owning account. 126 * <P>Type: INTEGER (boolean)</P> 127 */ 128 public static final String DIRTY = "dirty"; 129 130 /** 131 * The time that this row was last modified by a client (msecs since the epoch). 132 * <P>Type: INTEGER</P> 133 */ 134 public static final String DATE_MODIFIED = "modified"; 135 } 136 137 interface CommonColumns { 138 /** 139 * The unique ID for a row. 140 * <P>Type: INTEGER (long)</P> 141 */ 142 public static final String _ID = "_id"; 143 144 /** 145 * The URL of the bookmark. 146 * <P>Type: TEXT (URL)</P> 147 */ 148 public static final String URL = "url"; 149 150 /** 151 * The user visible title of the bookmark. 152 * <P>Type: TEXT</P> 153 */ 154 public static final String TITLE = "title"; 155 156 /** 157 * The time that this row was created on its originating client (msecs 158 * since the epoch). 159 * <P>Type: INTEGER</P> 160 */ 161 public static final String DATE_CREATED = "created"; 162 } 163 164 interface ImageColumns { 165 /** 166 * The favicon of the bookmark, may be NULL. 167 * Must decode via {@link BitmapFactory#decodeByteArray}. 168 * <p>Type: BLOB (image)</p> 169 */ 170 public static final String FAVICON = "favicon"; 171 172 /** 173 * A thumbnail of the page,may be NULL. 174 * Must decode via {@link BitmapFactory#decodeByteArray}. 175 * <p>Type: BLOB (image)</p> 176 */ 177 public static final String THUMBNAIL = "thumbnail"; 178 179 /** 180 * The touch icon for the web page, may be NULL. 181 * Must decode via {@link BitmapFactory#decodeByteArray}. 182 * <p>Type: BLOB (image)</p> 183 * @hide 184 */ 185 public static final String TOUCH_ICON = "touch_icon"; 186 } 187 188 interface HistoryColumns { 189 /** 190 * The date the item was last visited, in milliseconds since the epoch. 191 * <p>Type: INTEGER (date in milliseconds since January 1, 1970)</p> 192 */ 193 public static final String DATE_LAST_VISITED = "date"; 194 195 /** 196 * The number of times the item has been visited. 197 * <p>Type: INTEGER</p> 198 */ 199 public static final String VISITS = "visits"; 200 201 public static final String USER_ENTERED = "user_entered"; 202 } 203 204 /** 205 * The bookmarks table, which holds the user's browser bookmarks. 206 */ 207 public static final class Bookmarks implements CommonColumns, ImageColumns, SyncColumns { 208 /** 209 * This utility class cannot be instantiated. 210 */ 211 private Bookmarks() {} 212 213 /** 214 * The content:// style URI for this table 215 */ 216 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "bookmarks"); 217 218 /** 219 * The content:// style URI for the default folder 220 */ 221 public static final Uri CONTENT_URI_DEFAULT_FOLDER = 222 Uri.withAppendedPath(CONTENT_URI, "folder"); 223 224 /** 225 * Query parameter used to specify an account name 226 */ 227 public static final String PARAM_ACCOUNT_NAME = "acct_name"; 228 229 /** 230 * Query parameter used to specify an account type 231 */ 232 public static final String PARAM_ACCOUNT_TYPE = "acct_type"; 233 234 /** 235 * Builds a URI that points to a specific folder. 236 * @param folderId the ID of the folder to point to 237 */ 238 public static final Uri buildFolderUri(long folderId) { 239 return ContentUris.withAppendedId(CONTENT_URI_DEFAULT_FOLDER, folderId); 240 } 241 242 /** 243 * The MIME type of {@link #CONTENT_URI} providing a directory of bookmarks. 244 */ 245 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/bookmark"; 246 247 /** 248 * The MIME type of a {@link #CONTENT_URI} of a single bookmark. 249 */ 250 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/bookmark"; 251 252 /** 253 * Query parameter to use if you want to see deleted bookmarks that are still 254 * around on the device and haven't been synced yet. 255 * @see #IS_DELETED 256 */ 257 public static final String QUERY_PARAMETER_SHOW_DELETED = "show_deleted"; 258 259 /** 260 * Flag indicating if an item is a folder or bookmark. Non-zero values indicate 261 * a folder and zero indicates a bookmark. 262 * <P>Type: INTEGER (boolean)</P> 263 */ 264 public static final String IS_FOLDER = "folder"; 265 266 /** 267 * The ID of the parent folder. ID 0 is the root folder. 268 * <P>Type: INTEGER (reference to item in the same table)</P> 269 */ 270 public static final String PARENT = "parent"; 271 272 /** 273 * The source ID for an item's parent. Read-only. 274 * @see #PARENT 275 */ 276 public static final String PARENT_SOURCE_ID = "parent_source"; 277 278 /** 279 * The position of the bookmark in relation to it's siblings that share the same 280 * {@link #PARENT}. May be negative. 281 * <P>Type: INTEGER</P> 282 */ 283 public static final String POSITION = "position"; 284 285 /** 286 * The item that the bookmark should be inserted after. 287 * May be negative. 288 * <P>Type: INTEGER</P> 289 */ 290 public static final String INSERT_AFTER = "insert_after"; 291 292 /** 293 * The source ID for the item that the bookmark should be inserted after. Read-only. 294 * May be negative. 295 * <P>Type: INTEGER</P> 296 * @see #INSERT_AFTER 297 */ 298 public static final String INSERT_AFTER_SOURCE_ID = "insert_after_source"; 299 300 /** 301 * A flag to indicate if an item has been deleted. Queries will not return deleted 302 * entries unless you add the {@link #QUERY_PARAMETER_SHOW_DELETED} query paramter 303 * to the URI when performing your query. 304 * <p>Type: INTEGER (non-zero if the item has been deleted, zero if it hasn't) 305 * @see #QUERY_PARAMETER_SHOW_DELETED 306 */ 307 public static final String IS_DELETED = "deleted"; 308 } 309 310 /** 311 * Read-only table that lists all the accounts that are used to provide bookmarks. 312 */ 313 public static final class Accounts { 314 /** 315 * Directory under {@link Bookmarks#CONTENT_URI} 316 */ 317 public static final Uri CONTENT_URI = 318 AUTHORITY_URI.buildUpon().appendPath("accounts").build(); 319 320 /** 321 * The name of the account instance to which this row belongs, which when paired with 322 * {@link #ACCOUNT_TYPE} identifies a specific account. 323 * <P>Type: TEXT</P> 324 */ 325 public static final String ACCOUNT_NAME = "account_name"; 326 327 /** 328 * The type of account to which this row belongs, which when paired with 329 * {@link #ACCOUNT_NAME} identifies a specific account. 330 * <P>Type: TEXT</P> 331 */ 332 public static final String ACCOUNT_TYPE = "account_type"; 333 } 334 335 /** 336 * The history table, which holds the browsing history. 337 */ 338 public static final class History implements CommonColumns, HistoryColumns, ImageColumns { 339 /** 340 * This utility class cannot be instantiated. 341 */ 342 private History() {} 343 344 /** 345 * The content:// style URI for this table 346 */ 347 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "history"); 348 349 /** 350 * The MIME type of {@link #CONTENT_URI} providing a directory of browser history items. 351 */ 352 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/browser-history"; 353 354 /** 355 * The MIME type of a {@link #CONTENT_URI} of a single browser history item. 356 */ 357 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/browser-history"; 358 } 359 360 /** 361 * The search history table. 362 * @hide 363 */ 364 public static final class Searches { 365 private Searches() {} 366 367 /** 368 * The content:// style URI for this table 369 */ 370 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "searches"); 371 372 /** 373 * The MIME type of {@link #CONTENT_URI} providing a directory of browser search items. 374 */ 375 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/searches"; 376 377 /** 378 * The MIME type of a {@link #CONTENT_URI} of a single browser search item. 379 */ 380 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/searches"; 381 382 /** 383 * The unique ID for a row. 384 * <P>Type: INTEGER (long)</P> 385 */ 386 public static final String _ID = "_id"; 387 388 /** 389 * The user entered search term. 390 */ 391 public static final String SEARCH = "search"; 392 393 /** 394 * The date the search was performed, in milliseconds since the epoch. 395 * <p>Type: NUMBER (date in milliseconds since January 1, 1970)</p> 396 */ 397 public static final String DATE = "date"; 398 } 399 400 /** 401 * A table provided for sync adapters to use for storing private sync state data. 402 * 403 * @see SyncStateContract 404 */ 405 public static final class SyncState implements SyncStateContract.Columns { 406 /** 407 * This utility class cannot be instantiated 408 */ 409 private SyncState() {} 410 411 public static final String CONTENT_DIRECTORY = 412 SyncStateContract.Constants.CONTENT_DIRECTORY; 413 414 /** 415 * The content:// style URI for this table 416 */ 417 public static final Uri CONTENT_URI = 418 Uri.withAppendedPath(AUTHORITY_URI, CONTENT_DIRECTORY); 419 420 /** 421 * @see android.provider.SyncStateContract.Helpers#get 422 */ 423 public static byte[] get(ContentProviderClient provider, Account account) 424 throws RemoteException { 425 return SyncStateContract.Helpers.get(provider, CONTENT_URI, account); 426 } 427 428 /** 429 * @see android.provider.SyncStateContract.Helpers#get 430 */ 431 public static Pair<Uri, byte[]> getWithUri(ContentProviderClient provider, Account account) 432 throws RemoteException { 433 return SyncStateContract.Helpers.getWithUri(provider, CONTENT_URI, account); 434 } 435 436 /** 437 * @see android.provider.SyncStateContract.Helpers#set 438 */ 439 public static void set(ContentProviderClient provider, Account account, byte[] data) 440 throws RemoteException { 441 SyncStateContract.Helpers.set(provider, CONTENT_URI, account, data); 442 } 443 444 /** 445 * @see android.provider.SyncStateContract.Helpers#newSetOperation 446 */ 447 public static ContentProviderOperation newSetOperation(Account account, byte[] data) { 448 return SyncStateContract.Helpers.newSetOperation(CONTENT_URI, account, data); 449 } 450 } 451 452 /** 453 * Stores images for URLs. Only support query() and update(). 454 * @hide 455 */ 456 public static final class Images implements ImageColumns { 457 /** 458 * This utility class cannot be instantiated 459 */ 460 private Images() {} 461 462 /** 463 * The content:// style URI for this table 464 */ 465 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "images"); 466 467 /** 468 * The URL the images came from. 469 * <P>Type: TEXT (URL)</P> 470 */ 471 public static final String URL = "url_key"; 472 } 473 474 /** 475 * A combined view of bookmarks and history. All bookmarks in all folders are included and 476 * no folders are included. 477 */ 478 public static final class Combined implements CommonColumns, HistoryColumns, ImageColumns { 479 /** 480 * This utility class cannot be instantiated 481 */ 482 private Combined() {} 483 484 /** 485 * The content:// style URI for this table 486 */ 487 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "combined"); 488 489 /** 490 * Flag indicating that an item is a bookmark. A value of 1 indicates a bookmark, a value 491 * of 0 indicates a history item. 492 * <p>Type: INTEGER (boolean)</p> 493 */ 494 public static final String IS_BOOKMARK = "bookmark"; 495 } 496} 497