| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.provider; |
| 18 |
|
| 19 |
import android.accounts.Account; |
| 20 |
import android.compat.annotation.UnsupportedAppUsage; |
| 21 |
import android.content.ContentProviderClient; |
| 22 |
import android.content.ContentProviderOperation; |
| 23 |
import android.content.ContentResolver; |
| 24 |
import android.content.ContentUris; |
| 25 |
import android.content.ContentValues; |
| 26 |
import android.content.Context; |
| 27 |
import android.database.Cursor; |
| 28 |
import android.graphics.BitmapFactory; |
| 29 |
import android.net.Uri; |
| 30 |
import android.os.Build; |
| 31 |
import android.os.RemoteException; |
| 32 |
import android.util.Pair; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public class BrowserContract { |
| 47 |
|
| 48 |
public static final String AUTHORITY = "com.android.browser"; |
| 49 |
|
| 50 |
|
| 51 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 52 |
public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY); |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public static final String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter"; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public static final String PARAM_LIMIT = "limit"; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
interface BaseSyncColumns { |
| 79 |
|
| 80 |
public static final String SYNC1 = "sync1"; |
| 81 |
|
| 82 |
public static final String SYNC2 = "sync2"; |
| 83 |
|
| 84 |
public static final String SYNC3 = "sync3"; |
| 85 |
|
| 86 |
public static final String SYNC4 = "sync4"; |
| 87 |
|
| 88 |
public static final String SYNC5 = "sync5"; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public static final class ChromeSyncColumns { |
| 96 |
private ChromeSyncColumns() {} |
| 97 |
|
| 98 |
|
| 99 |
public static final String SERVER_UNIQUE = BaseSyncColumns.SYNC3; |
| 100 |
|
| 101 |
public static final String FOLDER_NAME_ROOT = "google_chrome"; |
| 102 |
public static final String FOLDER_NAME_BOOKMARKS = "google_chrome_bookmarks"; |
| 103 |
public static final String FOLDER_NAME_BOOKMARKS_BAR = "bookmark_bar"; |
| 104 |
public static final String FOLDER_NAME_OTHER_BOOKMARKS = "other_bookmarks"; |
| 105 |
|
| 106 |
|
| 107 |
public static final String CLIENT_UNIQUE = BaseSyncColumns.SYNC4; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
interface SyncColumns extends BaseSyncColumns { |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
public static final String ACCOUNT_NAME = "account_name"; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
public static final String ACCOUNT_TYPE = "account_type"; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
public static final String SOURCE_ID = "sourceid"; |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
public static final String VERSION = "version"; |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
public static final String DIRTY = "dirty"; |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
public static final String DATE_MODIFIED = "modified"; |
| 155 |
} |
| 156 |
|
| 157 |
interface CommonColumns { |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
public static final String _ID = "_id"; |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
public static final String URL = "url"; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
public static final String TITLE = "title"; |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
public static final String DATE_CREATED = "created"; |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
interface ImageColumns { |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
public static final String FAVICON = "favicon"; |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
public static final String THUMBNAIL = "thumbnail"; |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
public static final String TOUCH_ICON = "touch_icon"; |
| 210 |
} |
| 211 |
|
| 212 |
interface HistoryColumns { |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
public static final String DATE_LAST_VISITED = "date"; |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
public static final String VISITS = "visits"; |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
public static final String USER_ENTERED = "user_entered"; |
| 229 |
} |
| 230 |
|
| 231 |
interface ImageMappingColumns { |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
public static final String IMAGE_ID = "image_id"; |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
public static final String URL = "url"; |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
public static final class Bookmarks implements CommonColumns, ImageColumns, SyncColumns { |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
private Bookmarks() {} |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
@UnsupportedAppUsage |
| 258 |
public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "bookmarks"); |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
public static final int BOOKMARK_TYPE_BOOKMARK = 1; |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
public static final int BOOKMARK_TYPE_FOLDER = 2; |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
public static final int BOOKMARK_TYPE_BOOKMARK_BAR_FOLDER = 3; |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
public static final int BOOKMARK_TYPE_OTHER_FOLDER = 4; |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
public static final int BOOKMARK_TYPE_MOBILE_FOLDER = 5; |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
public static final String TYPE = "type"; |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 308 |
public static final Uri CONTENT_URI_DEFAULT_FOLDER = |
| 309 |
Uri.withAppendedPath(CONTENT_URI, "folder"); |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
public static final String PARAM_ACCOUNT_NAME = "acct_name"; |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
public static final String PARAM_ACCOUNT_TYPE = "acct_type"; |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 329 |
public static final Uri buildFolderUri(long folderId) { |
| 330 |
return ContentUris.withAppendedId(CONTENT_URI_DEFAULT_FOLDER, folderId); |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/bookmark"; |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/bookmark"; |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
public static final String QUERY_PARAMETER_SHOW_DELETED = "show_deleted"; |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
public static final String IS_FOLDER = "folder"; |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
public static final String PARENT = "parent"; |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
public static final String PARENT_SOURCE_ID = "parent_source"; |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
public static final String POSITION = "position"; |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
public static final String INSERT_AFTER = "insert_after"; |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
public static final String INSERT_AFTER_SOURCE_ID = "insert_after_source"; |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
public static final String IS_DELETED = "deleted"; |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
public static final class Accounts { |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 417 |
public static final Uri CONTENT_URI = |
| 418 |
AUTHORITY_URI.buildUpon().appendPath("accounts").build(); |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
public static final String ACCOUNT_NAME = "account_name"; |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
public static final String ACCOUNT_TYPE = "account_type"; |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
public static final String ROOT_ID = "root_id"; |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
public static final class History implements CommonColumns, HistoryColumns, ImageColumns { |
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
private History() {} |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 455 |
public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "history"); |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/browser-history"; |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/browser-history"; |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
public static final class Searches { |
| 473 |
private Searches() {} |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "searches"); |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/searches"; |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/searches"; |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
public static final String _ID = "_id"; |
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
public static final String SEARCH = "search"; |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
public static final String DATE = "date"; |
| 506 |
} |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
public static final class SyncState implements SyncStateContract.Columns { |
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
private SyncState() {} |
| 519 |
|
| 520 |
public static final String CONTENT_DIRECTORY = |
| 521 |
SyncStateContract.Constants.CONTENT_DIRECTORY; |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
public static final Uri CONTENT_URI = |
| 527 |
Uri.withAppendedPath(AUTHORITY_URI, CONTENT_DIRECTORY); |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
public static byte[] get(ContentProviderClient provider, Account account) |
| 533 |
throws RemoteException { |
| 534 |
return SyncStateContract.Helpers.get(provider, CONTENT_URI, account); |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
public static Pair<Uri, byte[]> getWithUri(ContentProviderClient provider, Account account) |
| 541 |
throws RemoteException { |
| 542 |
return SyncStateContract.Helpers.getWithUri(provider, CONTENT_URI, account); |
| 543 |
} |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
public static void set(ContentProviderClient provider, Account account, byte[] data) |
| 549 |
throws RemoteException { |
| 550 |
SyncStateContract.Helpers.set(provider, CONTENT_URI, account, data); |
| 551 |
} |
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
public static ContentProviderOperation newSetOperation(Account account, byte[] data) { |
| 557 |
return SyncStateContract.Helpers.newSetOperation(CONTENT_URI, account, data); |
| 558 |
} |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
public static final class Images implements ImageColumns { |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
private Images() {} |
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 585 |
public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "images"); |
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/images"; |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/images"; |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
public static final int IMAGE_TYPE_FAVICON = 1; |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
public static final int IMAGE_TYPE_PRECOMPOSED_TOUCH_ICON = 2; |
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
public static final int IMAGE_TYPE_TOUCH_ICON = 4; |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
public static final String TYPE = "type"; |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
public static final String DATA = "data"; |
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
public static final String URL = "url_key"; |
| 638 |
} |
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
public static final class ImageMappings implements ImageMappingColumns { |
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
private ImageMappings() {} |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "image_mappings"); |
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/image_mappings"; |
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/image_mappings"; |
| 669 |
} |
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
public static final class Combined implements CommonColumns, HistoryColumns, ImageColumns { |
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
private Combined() {} |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 686 |
public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "combined"); |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
public static final String IS_BOOKMARK = "bookmark"; |
| 694 |
} |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
public static final class Settings { |
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
private Settings() {} |
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "settings"); |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
public static final String KEY = "key"; |
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
public static final String VALUE = "value"; |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
public static final String KEY_SYNC_ENABLED = "sync_enabled"; |
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
static public boolean isSyncEnabled(Context context) { |
| 730 |
Cursor cursor = null; |
| 731 |
try { |
| 732 |
cursor = context.getContentResolver().query(CONTENT_URI, new String[] { VALUE }, |
| 733 |
KEY + "=?", new String[] { KEY_SYNC_ENABLED }, null); |
| 734 |
if (cursor == null || !cursor.moveToFirst()) { |
| 735 |
return false; |
| 736 |
} |
| 737 |
return cursor.getInt(0) != 0; |
| 738 |
} finally { |
| 739 |
if (cursor != null) cursor.close(); |
| 740 |
} |
| 741 |
} |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
static public void setSyncEnabled(Context context, boolean enabled) { |
| 747 |
ContentValues values = new ContentValues(); |
| 748 |
values.put(KEY, KEY_SYNC_ENABLED); |
| 749 |
values.put(VALUE, enabled ? 1 : 0); |
| 750 |
context.getContentResolver().insert(CONTENT_URI, values); |
| 751 |
} |
| 752 |
} |
| 753 |
} |