1 /* 2 * Copyright (C) 2007 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 17 package android.provider; 18 19 import android.content.ContentQueryMap; 20 import android.content.ContentResolver; 21 import android.content.ContentUris; 22 import android.content.ContentValues; 23 import android.database.Cursor; 24 import android.net.Uri; 25 import android.os.Handler; 26 27 import java.util.HashMap; 28 29 /** 30 * The GTalk provider stores all information about roster contacts, chat messages, presence, etc. 31 * 32 * @hide 33 */ 34 public class Im { 35 /** 36 * no public constructor since this is a utility class 37 */ Im()38 private Im() {} 39 40 /** 41 * The Columns for IM providers 42 */ 43 public interface ProviderColumns { 44 /** 45 * The name of the IM provider 46 * <P>Type: TEXT</P> 47 */ 48 String NAME = "name"; 49 50 /** 51 * The full name of the provider 52 * <P>Type: TEXT</P> 53 */ 54 String FULLNAME = "fullname"; 55 56 /** 57 * The category for the provider, used to form intent. 58 * <P>Type: TEXT</P> 59 */ 60 String CATEGORY = "category"; 61 62 /** 63 * The url users should visit to create a new account for this provider 64 * <P>Type: TEXT</P> 65 */ 66 String SIGNUP_URL = "signup_url"; 67 } 68 69 /** 70 * Known names corresponding to the {@link ProviderColumns#NAME} column 71 */ 72 public interface ProviderNames { 73 // 74 //NOTE: update Contacts.java with new providers when they're added. 75 // 76 String YAHOO = "Yahoo"; 77 String GTALK = "GTalk"; 78 String MSN = "MSN"; 79 String ICQ = "ICQ"; 80 String AIM = "AIM"; 81 String XMPP = "XMPP"; 82 String JABBER = "JABBER"; 83 String SKYPE = "SKYPE"; 84 String QQ = "QQ"; 85 } 86 87 /** 88 * This table contains the IM providers 89 */ 90 public static final class Provider implements BaseColumns, ProviderColumns { Provider()91 private Provider() {} 92 getProviderIdForName(ContentResolver cr, String providerName)93 public static final long getProviderIdForName(ContentResolver cr, String providerName) { 94 String[] selectionArgs = new String[1]; 95 selectionArgs[0] = providerName; 96 97 Cursor cursor = cr.query(CONTENT_URI, 98 PROVIDER_PROJECTION, 99 NAME+"=?", 100 selectionArgs, null); 101 102 long retVal = 0; 103 try { 104 if (cursor.moveToFirst()) { 105 retVal = cursor.getLong(cursor.getColumnIndexOrThrow(_ID)); 106 } 107 } finally { 108 cursor.close(); 109 } 110 111 return retVal; 112 } 113 getProviderNameForId(ContentResolver cr, long providerId)114 public static final String getProviderNameForId(ContentResolver cr, long providerId) { 115 Cursor cursor = cr.query(CONTENT_URI, 116 PROVIDER_PROJECTION, 117 _ID + "=" + providerId, 118 null, null); 119 120 String retVal = null; 121 try { 122 if (cursor.moveToFirst()) { 123 retVal = cursor.getString(cursor.getColumnIndexOrThrow(NAME)); 124 } 125 } finally { 126 cursor.close(); 127 } 128 129 return retVal; 130 } 131 132 private static final String[] PROVIDER_PROJECTION = new String[] { 133 _ID, 134 NAME 135 }; 136 137 public static final String ACTIVE_ACCOUNT_ID = "account_id"; 138 public static final String ACTIVE_ACCOUNT_USERNAME = "account_username"; 139 public static final String ACTIVE_ACCOUNT_PW = "account_pw"; 140 public static final String ACTIVE_ACCOUNT_LOCKED = "account_locked"; 141 public static final String ACTIVE_ACCOUNT_KEEP_SIGNED_IN = "account_keepSignedIn"; 142 public static final String ACCOUNT_PRESENCE_STATUS = "account_presenceStatus"; 143 public static final String ACCOUNT_CONNECTION_STATUS = "account_connStatus"; 144 145 /** 146 * The content:// style URL for this table 147 */ 148 public static final Uri CONTENT_URI = 149 Uri.parse("content://com.google.android.providers.talk/providers"); 150 151 public static final Uri CONTENT_URI_WITH_ACCOUNT = 152 Uri.parse("content://com.google.android.providers.talk/providers/account"); 153 154 /** 155 * The MIME type of {@link #CONTENT_URI} providing a directory of 156 * people. 157 */ 158 public static final String CONTENT_TYPE = 159 "vnd.android.cursor.dir/gtalk-providers"; 160 161 public static final String CONTENT_ITEM_TYPE = 162 "vnd.android.cursor.item/gtalk-providers"; 163 164 /** 165 * The default sort order for this table 166 */ 167 public static final String DEFAULT_SORT_ORDER = "name ASC"; 168 } 169 170 /** 171 * The columns for IM accounts. There can be more than one account for each IM provider. 172 */ 173 public interface AccountColumns { 174 /** 175 * The name of the account 176 * <P>Type: TEXT</P> 177 */ 178 String NAME = "name"; 179 180 /** 181 * The IM provider for this account 182 * <P>Type: INTEGER</P> 183 */ 184 String PROVIDER = "provider"; 185 186 /** 187 * The username for this account 188 * <P>Type: TEXT</P> 189 */ 190 String USERNAME = "username"; 191 192 /** 193 * The password for this account 194 * <P>Type: TEXT</P> 195 */ 196 String PASSWORD = "pw"; 197 198 /** 199 * A boolean value indicates if the account is active. 200 * <P>Type: INTEGER</P> 201 */ 202 String ACTIVE = "active"; 203 204 /** 205 * A boolean value indicates if the account is locked (not editable) 206 * <P>Type: INTEGER</P> 207 */ 208 String LOCKED = "locked"; 209 210 /** 211 * A boolean value to indicate whether this account is kept signed in. 212 * <P>Type: INTEGER</P> 213 */ 214 String KEEP_SIGNED_IN = "keep_signed_in"; 215 216 /** 217 * A boolean value indiciating the last login state for this account 218 * <P>Type: INTEGER</P> 219 */ 220 String LAST_LOGIN_STATE = "last_login_state"; 221 } 222 223 /** 224 * This table contains the IM accounts. 225 */ 226 public static final class Account implements BaseColumns, AccountColumns { Account()227 private Account() {} 228 getProviderIdForAccount(ContentResolver cr, long accountId)229 public static final long getProviderIdForAccount(ContentResolver cr, long accountId) { 230 Cursor cursor = cr.query(CONTENT_URI, 231 PROVIDER_PROJECTION, 232 _ID + "=" + accountId, 233 null /* selection args */, 234 null /* sort order */); 235 236 long providerId = 0; 237 238 try { 239 if (cursor.moveToFirst()) { 240 providerId = cursor.getLong(PROVIDER_COLUMN); 241 } 242 } finally { 243 cursor.close(); 244 } 245 246 return providerId; 247 } 248 249 private static final String[] PROVIDER_PROJECTION = new String[] { PROVIDER }; 250 private static final int PROVIDER_COLUMN = 0; 251 252 /** 253 * The content:// style URL for this table 254 */ 255 public static final Uri CONTENT_URI = 256 Uri.parse("content://com.google.android.providers.talk/accounts"); 257 258 /** 259 * The MIME type of {@link #CONTENT_URI} providing a directory of 260 * account. 261 */ 262 public static final String CONTENT_TYPE = 263 "vnd.android.cursor.dir/gtalk-accounts"; 264 265 /** 266 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single 267 * account. 268 */ 269 public static final String CONTENT_ITEM_TYPE = 270 "vnd.android.cursor.item/gtalk-accounts"; 271 272 /** 273 * The default sort order for this table 274 */ 275 public static final String DEFAULT_SORT_ORDER = "name ASC"; 276 277 } 278 279 /** 280 * Connection status 281 */ 282 public interface ConnectionStatus { 283 /** 284 * The connection is offline, not logged in. 285 */ 286 int OFFLINE = 0; 287 288 /** 289 * The connection is attempting to connect. 290 */ 291 int CONNECTING = 1; 292 293 /** 294 * The connection is suspended due to network not available. 295 */ 296 int SUSPENDED = 2; 297 298 /** 299 * The connection is logged in and online. 300 */ 301 int ONLINE = 3; 302 } 303 304 public interface AccountStatusColumns { 305 /** 306 * account id 307 * <P>Type: INTEGER</P> 308 */ 309 String ACCOUNT = "account"; 310 311 /** 312 * User's presence status, see definitions in {#link CommonPresenceColumn} 313 * <P>Type: INTEGER</P> 314 */ 315 String PRESENCE_STATUS = "presenceStatus"; 316 317 /** 318 * The connection status of this account, see {#link ConnectionStatus} 319 * <P>Type: INTEGER</P> 320 */ 321 String CONNECTION_STATUS = "connStatus"; 322 } 323 324 public static final class AccountStatus implements BaseColumns, AccountStatusColumns { 325 /** 326 * The content:// style URL for this table 327 */ 328 public static final Uri CONTENT_URI = 329 Uri.parse("content://com.google.android.providers.talk/accountStatus"); 330 331 /** 332 * The MIME type of {@link #CONTENT_URI} providing a directory of account status. 333 */ 334 public static final String CONTENT_TYPE = 335 "vnd.android.cursor.dir/gtalk-account-status"; 336 337 /** 338 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single account status. 339 */ 340 public static final String CONTENT_ITEM_TYPE = 341 "vnd.android.cursor.item/gtalk-account-status"; 342 343 /** 344 * The default sort order for this table 345 */ 346 public static final String DEFAULT_SORT_ORDER = "name ASC"; 347 } 348 349 /** 350 * Columns from the Contacts table. 351 */ 352 public interface ContactsColumns { 353 /** 354 * The username 355 * <P>Type: TEXT</P> 356 */ 357 String USERNAME = "username"; 358 359 /** 360 * The nickname or display name 361 * <P>Type: TEXT</P> 362 */ 363 String NICKNAME = "nickname"; 364 365 /** 366 * The IM provider for this contact 367 * <P>Type: INTEGER</P> 368 */ 369 String PROVIDER = "provider"; 370 371 /** 372 * The account (within a IM provider) for this contact 373 * <P>Type: INTEGER</P> 374 */ 375 String ACCOUNT = "account"; 376 377 /** 378 * The contactList this contact belongs to 379 * <P>Type: INTEGER</P> 380 */ 381 String CONTACTLIST = "contactList"; 382 383 /** 384 * Contact type 385 * <P>Type: INTEGER</P> 386 */ 387 String TYPE = "type"; 388 389 /** 390 * normal IM contact 391 */ 392 int TYPE_NORMAL = 0; 393 /** 394 * temporary contact, someone not in the list of contacts that we 395 * subscribe presence for. Usually created because of the user is 396 * having a chat session with this contact. 397 */ 398 int TYPE_TEMPORARY = 1; 399 /** 400 * temporary contact created for group chat. 401 */ 402 int TYPE_GROUP = 2; 403 /** 404 * blocked contact. 405 */ 406 int TYPE_BLOCKED = 3; 407 /** 408 * the contact is hidden. The client should always display this contact to the user. 409 */ 410 int TYPE_HIDDEN = 4; 411 /** 412 * the contact is pinned. The client should always display this contact to the user. 413 */ 414 int TYPE_PINNED = 5; 415 416 /** 417 * Contact subscription status 418 * <P>Type: INTEGER</P> 419 */ 420 String SUBSCRIPTION_STATUS = "subscriptionStatus"; 421 422 /** 423 * no pending subscription 424 */ 425 int SUBSCRIPTION_STATUS_NONE = 0; 426 /** 427 * requested to subscribe 428 */ 429 int SUBSCRIPTION_STATUS_SUBSCRIBE_PENDING = 1; 430 /** 431 * requested to unsubscribe 432 */ 433 int SUBSCRIPTION_STATUS_UNSUBSCRIBE_PENDING = 2; 434 435 /** 436 * Contact subscription type 437 * <P>Type: INTEGER </P> 438 */ 439 String SUBSCRIPTION_TYPE = "subscriptionType"; 440 441 /** 442 * The user and contact have no interest in each other's presence. 443 */ 444 int SUBSCRIPTION_TYPE_NONE = 0; 445 /** 446 * The user wishes to stop receiving presence updates from the contact. 447 */ 448 int SUBSCRIPTION_TYPE_REMOVE = 1; 449 /** 450 * The user is interested in receiving presence updates from the contact. 451 */ 452 int SUBSCRIPTION_TYPE_TO = 2; 453 /** 454 * The contact is interested in receiving presence updates from the user. 455 */ 456 int SUBSCRIPTION_TYPE_FROM = 3; 457 /** 458 * The user and contact have a mutual interest in each other's presence. 459 */ 460 int SUBSCRIPTION_TYPE_BOTH = 4; 461 /** 462 * This is a special type reserved for pending subscription requests 463 */ 464 int SUBSCRIPTION_TYPE_INVITATIONS = 5; 465 466 /** 467 * Quick Contact: derived from Google Contact Extension's "message_count" attribute. 468 * <P>Type: INTEGER</P> 469 */ 470 String QUICK_CONTACT = "qc"; 471 472 /** 473 * Google Contact Extension attribute 474 * 475 * Rejected: a boolean value indicating whether a subscription request from 476 * this client was ever rejected by the user. "true" indicates that it has. 477 * This is provided so that a client can block repeated subscription requests. 478 * <P>Type: INTEGER</P> 479 */ 480 String REJECTED = "rejected"; 481 482 /** 483 * Off The Record status: 0 for disabled, 1 for enabled 484 * <P>Type: INTEGER </P> 485 */ 486 String OTR = "otr"; 487 } 488 489 /** 490 * This defines the different type of values of {@link ContactsColumns#OTR} 491 */ 492 public interface OffTheRecordType { 493 /* 494 * Off the record not turned on 495 */ 496 int DISABLED = 0; 497 /** 498 * Off the record turned on, but we don't know who turned it on 499 */ 500 int ENABLED = 1; 501 /** 502 * Off the record turned on by the user 503 */ 504 int ENABLED_BY_USER = 2; 505 /** 506 * Off the record turned on by the buddy 507 */ 508 int ENABLED_BY_BUDDY = 3; 509 }; 510 511 /** 512 * This table contains contacts. 513 */ 514 public static final class Contacts implements BaseColumns, 515 ContactsColumns, PresenceColumns, ChatsColumns { 516 /** 517 * no public constructor since this is a utility class 518 */ Contacts()519 private Contacts() {} 520 521 /** 522 * The content:// style URL for this table 523 */ 524 public static final Uri CONTENT_URI = 525 Uri.parse("content://com.google.android.providers.talk/contacts"); 526 527 /** 528 * The content:// style URL for contacts joined with presence 529 */ 530 public static final Uri CONTENT_URI_WITH_PRESENCE = 531 Uri.parse("content://com.google.android.providers.talk/contactsWithPresence"); 532 533 /** 534 * The content:// style URL for barebone contacts, not joined with any other table 535 */ 536 public static final Uri CONTENT_URI_CONTACTS_BAREBONE = 537 Uri.parse("content://com.google.android.providers.talk/contactsBarebone"); 538 539 /** 540 * The content:// style URL for contacts who have an open chat session 541 */ 542 public static final Uri CONTENT_URI_CHAT_CONTACTS = 543 Uri.parse("content://com.google.android.providers.talk/contacts_chatting"); 544 545 /** 546 * The content:// style URL for contacts who have been blocked 547 */ 548 public static final Uri CONTENT_URI_BLOCKED_CONTACTS = 549 Uri.parse("content://com.google.android.providers.talk/contacts/blocked"); 550 551 /** 552 * The content:// style URL for contacts by provider and account 553 */ 554 public static final Uri CONTENT_URI_CONTACTS_BY = 555 Uri.parse("content://com.google.android.providers.talk/contacts"); 556 557 /** 558 * The content:// style URL for contacts by provider and account, 559 * and who have an open chat session 560 */ 561 public static final Uri CONTENT_URI_CHAT_CONTACTS_BY = 562 Uri.parse("content://com.google.android.providers.talk/contacts/chatting"); 563 564 /** 565 * The content:// style URL for contacts by provider and account, 566 * and who are online 567 */ 568 public static final Uri CONTENT_URI_ONLINE_CONTACTS_BY = 569 Uri.parse("content://com.google.android.providers.talk/contacts/online"); 570 571 /** 572 * The content:// style URL for contacts by provider and account, 573 * and who are offline 574 */ 575 public static final Uri CONTENT_URI_OFFLINE_CONTACTS_BY = 576 Uri.parse("content://com.google.android.providers.talk/contacts/offline"); 577 578 /** 579 * The content:// style URL for operations on bulk contacts 580 */ 581 public static final Uri BULK_CONTENT_URI = 582 Uri.parse("content://com.google.android.providers.talk/bulk_contacts"); 583 584 /** 585 * The content:// style URL for the count of online contacts in each 586 * contact list by provider and account. 587 */ 588 public static final Uri CONTENT_URI_ONLINE_COUNT = 589 Uri.parse("content://com.google.android.providers.talk/contacts/onlineCount"); 590 591 /** 592 * The MIME type of {@link #CONTENT_URI} providing a directory of 593 * people. 594 */ 595 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/gtalk-contacts"; 596 597 /** 598 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single 599 * person. 600 */ 601 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/gtalk-contacts"; 602 603 /** 604 * The default sort order for this table 605 */ 606 public static final String DEFAULT_SORT_ORDER = 607 "subscriptionType DESC, last_message_date DESC," + 608 " mode DESC, nickname COLLATE UNICODE ASC"; 609 610 public static final String CHATS_CONTACT = "chats_contact"; 611 612 public static final String AVATAR_HASH = "avatars_hash"; 613 614 public static final String AVATAR_DATA = "avatars_data"; 615 } 616 617 /** 618 * Columns from the ContactList table. 619 */ 620 public interface ContactListColumns { 621 String NAME = "name"; 622 String PROVIDER = "provider"; 623 String ACCOUNT = "account"; 624 } 625 626 /** 627 * This table contains the contact lists. 628 */ 629 public static final class ContactList implements BaseColumns, 630 ContactListColumns { ContactList()631 private ContactList() {} 632 633 /** 634 * The content:// style URL for this table 635 */ 636 public static final Uri CONTENT_URI = 637 Uri.parse("content://com.google.android.providers.talk/contactLists"); 638 639 /** 640 * The MIME type of {@link #CONTENT_URI} providing a directory of 641 * people. 642 */ 643 public static final String CONTENT_TYPE = 644 "vnd.android.cursor.dir/gtalk-contactLists"; 645 646 /** 647 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single 648 * person. 649 */ 650 public static final String CONTENT_ITEM_TYPE = 651 "vnd.android.cursor.item/gtalk-contactLists"; 652 653 /** 654 * The default sort order for this table 655 */ 656 public static final String DEFAULT_SORT_ORDER = "name COLLATE UNICODE ASC"; 657 658 public static final String PROVIDER_NAME = "provider_name"; 659 660 public static final String ACCOUNT_NAME = "account_name"; 661 } 662 663 /** 664 * Columns from the BlockedList table. 665 */ 666 public interface BlockedListColumns { 667 /** 668 * The username of the blocked contact. 669 * <P>Type: TEXT</P> 670 */ 671 String USERNAME = "username"; 672 673 /** 674 * The nickname of the blocked contact. 675 * <P>Type: TEXT</P> 676 */ 677 String NICKNAME = "nickname"; 678 679 /** 680 * The provider id of the blocked contact. 681 * <P>Type: INT</P> 682 */ 683 String PROVIDER = "provider"; 684 685 /** 686 * The account id of the blocked contact. 687 * <P>Type: INT</P> 688 */ 689 String ACCOUNT = "account"; 690 } 691 692 /** 693 * This table contains blocked lists 694 */ 695 public static final class BlockedList implements BaseColumns, BlockedListColumns { BlockedList()696 private BlockedList() {} 697 698 /** 699 * The content:// style URL for this table 700 */ 701 public static final Uri CONTENT_URI = 702 Uri.parse("content://com.google.android.providers.talk/blockedList"); 703 704 /** 705 * The MIME type of {@link #CONTENT_URI} providing a directory of 706 * people. 707 */ 708 public static final String CONTENT_TYPE = 709 "vnd.android.cursor.dir/gtalk-blockedList"; 710 711 /** 712 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single 713 * person. 714 */ 715 public static final String CONTENT_ITEM_TYPE = 716 "vnd.android.cursor.item/gtalk-blockedList"; 717 718 /** 719 * The default sort order for this table 720 */ 721 public static final String DEFAULT_SORT_ORDER = "nickname ASC"; 722 723 public static final String PROVIDER_NAME = "provider_name"; 724 725 public static final String ACCOUNT_NAME = "account_name"; 726 727 public static final String AVATAR_DATA = "avatars_data"; 728 } 729 730 /** 731 * Columns from the contactsEtag table 732 */ 733 public interface ContactsEtagColumns { 734 /** 735 * The roster etag, computed by the server, stored on the client. There is one etag 736 * per account roster. 737 * <P>Type: TEXT</P> 738 */ 739 String ETAG = "etag"; 740 741 /** 742 * The OTR etag, computed by the server, stored on the client. There is one OTR etag 743 * per account roster. 744 * <P>Type: TEXT</P> 745 */ 746 String OTR_ETAG = "otr_etag"; 747 748 /** 749 * The account id for the etag. 750 * <P> Type: INTEGER </P> 751 */ 752 String ACCOUNT = "account"; 753 } 754 755 public static final class ContactsEtag implements BaseColumns, ContactsEtagColumns { ContactsEtag()756 private ContactsEtag() {} 757 query(ContentResolver cr, String[] projection)758 public static final Cursor query(ContentResolver cr, 759 String[] projection) { 760 return cr.query(CONTENT_URI, projection, null, null, null); 761 } 762 query(ContentResolver cr, String[] projection, String where, String orderBy)763 public static final Cursor query(ContentResolver cr, 764 String[] projection, String where, String orderBy) { 765 return cr.query(CONTENT_URI, projection, where, 766 null, orderBy == null ? null : orderBy); 767 } 768 getRosterEtag(ContentResolver resolver, long accountId)769 public static final String getRosterEtag(ContentResolver resolver, long accountId) { 770 String retVal = null; 771 772 Cursor c = resolver.query(CONTENT_URI, 773 CONTACT_ETAG_PROJECTION, 774 ACCOUNT + "=" + accountId, 775 null /* selection args */, 776 null /* sort order */); 777 778 try { 779 if (c.moveToFirst()) { 780 retVal = c.getString(COLUMN_ETAG); 781 } 782 } finally { 783 c.close(); 784 } 785 786 return retVal; 787 } 788 getOtrEtag(ContentResolver resolver, long accountId)789 public static final String getOtrEtag(ContentResolver resolver, long accountId) { 790 String retVal = null; 791 792 Cursor c = resolver.query(CONTENT_URI, 793 CONTACT_OTR_ETAG_PROJECTION, 794 ACCOUNT + "=" + accountId, 795 null /* selection args */, 796 null /* sort order */); 797 798 try { 799 if (c.moveToFirst()) { 800 retVal = c.getString(COLUMN_OTR_ETAG); 801 } 802 } finally { 803 c.close(); 804 } 805 806 return retVal; 807 } 808 809 private static final String[] CONTACT_ETAG_PROJECTION = new String[] { 810 Im.ContactsEtag.ETAG // 0 811 }; 812 813 private static int COLUMN_ETAG = 0; 814 815 private static final String[] CONTACT_OTR_ETAG_PROJECTION = new String[] { 816 Im.ContactsEtag.OTR_ETAG // 0 817 }; 818 819 private static int COLUMN_OTR_ETAG = 0; 820 821 /** 822 * The content:// style URL for this table 823 */ 824 public static final Uri CONTENT_URI = 825 Uri.parse("content://com.google.android.providers.talk/contactsEtag"); 826 827 /** 828 * The MIME type of {@link #CONTENT_URI} providing a directory of 829 * people. 830 */ 831 public static final String CONTENT_TYPE = 832 "vnd.android.cursor.dir/gtalk-contactsEtag"; 833 834 /** 835 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single 836 * person. 837 */ 838 public static final String CONTENT_ITEM_TYPE = 839 "vnd.android.cursor.item/gtalk-contactsEtag"; 840 } 841 842 /** 843 * Message type definition 844 */ 845 public interface MessageType { 846 /* sent message */ 847 int OUTGOING = 0; 848 /* received message */ 849 int INCOMING = 1; 850 /* presence became available */ 851 int PRESENCE_AVAILABLE = 2; 852 /* presence became away */ 853 int PRESENCE_AWAY = 3; 854 /* presence became DND (busy) */ 855 int PRESENCE_DND = 4; 856 /* presence became unavailable */ 857 int PRESENCE_UNAVAILABLE = 5; 858 /* the message is converted to a group chat */ 859 int CONVERT_TO_GROUPCHAT = 6; 860 /* generic status */ 861 int STATUS = 7; 862 /* the message cannot be sent now, but will be sent later */ 863 int POSTPONED = 8; 864 /* off The Record status is turned off */ 865 int OTR_IS_TURNED_OFF = 9; 866 /* off the record status is turned on */ 867 int OTR_IS_TURNED_ON = 10; 868 /* off the record status turned on by user */ 869 int OTR_TURNED_ON_BY_USER = 11; 870 /* off the record status turned on by buddy */ 871 int OTR_TURNED_ON_BY_BUDDY = 12; 872 } 873 874 /** 875 * The common columns for messages table 876 */ 877 public interface MessageColumns { 878 /** 879 * The thread_id column stores the contact id of the contact the message belongs to. 880 * For groupchat messages, the thread_id stores the group id, which is the contact id 881 * of the temporary group contact created for the groupchat. So there should be no 882 * collision between groupchat message thread id and regular message thread id. 883 */ 884 String THREAD_ID = "thread_id"; 885 886 /** 887 * The nickname. This is used for groupchat messages to indicate the participant's 888 * nickname. For non groupchat messages, this field should be left empty. 889 */ 890 String NICKNAME = "nickname"; 891 892 /** 893 * The body 894 * <P>Type: TEXT</P> 895 */ 896 String BODY = "body"; 897 898 /** 899 * The date this message is sent or received. This represents the display date for 900 * the message. 901 * <P>Type: INTEGER</P> 902 */ 903 String DATE = "date"; 904 905 /** 906 * The real date for this message. While 'date' can be modified by the client 907 * to account for server time skew, the real_date is the original timestamp set 908 * by the server for incoming messages. 909 * <P>Type: INTEGER</P> 910 */ 911 String REAL_DATE = "real_date"; 912 913 /** 914 * Message Type, see {@link MessageType} 915 * <P>Type: INTEGER</P> 916 */ 917 String TYPE = "type"; 918 919 /** 920 * Error Code: 0 means no error. 921 * <P>Type: INTEGER </P> 922 */ 923 String ERROR_CODE = "err_code"; 924 925 /** 926 * Error Message 927 * <P>Type: TEXT</P> 928 */ 929 String ERROR_MESSAGE = "err_msg"; 930 931 /** 932 * Packet ID, auto assigned by the GTalkService for outgoing messages or the 933 * GTalk server for incoming messages. The packet id field is optional for messages, 934 * so it could be null. 935 * <P>Type: STRING</P> 936 */ 937 String PACKET_ID = "packet_id"; 938 939 /** 940 * Is groupchat message or not 941 * <P>Type: INTEGER</P> 942 */ 943 String IS_GROUP_CHAT = "is_muc"; 944 945 /** 946 * A hint that the UI should show the sent time of this message 947 * <P>Type: INTEGER</P> 948 */ 949 String DISPLAY_SENT_TIME = "show_ts"; 950 } 951 952 /** 953 * This table contains messages. 954 */ 955 public static final class Messages implements BaseColumns, MessageColumns { 956 /** 957 * no public constructor since this is a utility class 958 */ Messages()959 private Messages() {} 960 961 /** 962 * Gets the Uri to query messages by thread id. 963 * 964 * @param threadId the thread id of the message. 965 * @return the Uri 966 */ getContentUriByThreadId(long threadId)967 public static final Uri getContentUriByThreadId(long threadId) { 968 Uri.Builder builder = CONTENT_URI_MESSAGES_BY_THREAD_ID.buildUpon(); 969 ContentUris.appendId(builder, threadId); 970 return builder.build(); 971 } 972 973 /** 974 * @deprecated 975 * 976 * Gets the Uri to query messages by account and contact. 977 * 978 * @param accountId the account id of the contact. 979 * @param username the user name of the contact. 980 * @return the Uri 981 */ getContentUriByContact(long accountId, String username)982 public static final Uri getContentUriByContact(long accountId, String username) { 983 Uri.Builder builder = CONTENT_URI_MESSAGES_BY_ACCOUNT_AND_CONTACT.buildUpon(); 984 ContentUris.appendId(builder, accountId); 985 builder.appendPath(username); 986 return builder.build(); 987 } 988 989 /** 990 * Gets the Uri to query messages by provider. 991 * 992 * @param providerId the service provider id. 993 * @return the Uri 994 */ getContentUriByProvider(long providerId)995 public static final Uri getContentUriByProvider(long providerId) { 996 Uri.Builder builder = CONTENT_URI_MESSAGES_BY_PROVIDER.buildUpon(); 997 ContentUris.appendId(builder, providerId); 998 return builder.build(); 999 } 1000 1001 /** 1002 * Gets the Uri to query off the record messages by account. 1003 * 1004 * @param accountId the account id. 1005 * @return the Uri 1006 */ getContentUriByAccount(long accountId)1007 public static final Uri getContentUriByAccount(long accountId) { 1008 Uri.Builder builder = CONTENT_URI_BY_ACCOUNT.buildUpon(); 1009 ContentUris.appendId(builder, accountId); 1010 return builder.build(); 1011 } 1012 1013 /** 1014 * Gets the Uri to query off the record messages by thread id. 1015 * 1016 * @param threadId the thread id of the message. 1017 * @return the Uri 1018 */ getOtrMessagesContentUriByThreadId(long threadId)1019 public static final Uri getOtrMessagesContentUriByThreadId(long threadId) { 1020 Uri.Builder builder = OTR_MESSAGES_CONTENT_URI_BY_THREAD_ID.buildUpon(); 1021 ContentUris.appendId(builder, threadId); 1022 return builder.build(); 1023 } 1024 1025 /** 1026 * @deprecated 1027 * 1028 * Gets the Uri to query off the record messages by account and contact. 1029 * 1030 * @param accountId the account id of the contact. 1031 * @param username the user name of the contact. 1032 * @return the Uri 1033 */ getOtrMessagesContentUriByContact(long accountId, String username)1034 public static final Uri getOtrMessagesContentUriByContact(long accountId, String username) { 1035 Uri.Builder builder = OTR_MESSAGES_CONTENT_URI_BY_ACCOUNT_AND_CONTACT.buildUpon(); 1036 ContentUris.appendId(builder, accountId); 1037 builder.appendPath(username); 1038 return builder.build(); 1039 } 1040 1041 /** 1042 * Gets the Uri to query off the record messages by provider. 1043 * 1044 * @param providerId the service provider id. 1045 * @return the Uri 1046 */ getOtrMessagesContentUriByProvider(long providerId)1047 public static final Uri getOtrMessagesContentUriByProvider(long providerId) { 1048 Uri.Builder builder = OTR_MESSAGES_CONTENT_URI_BY_PROVIDER.buildUpon(); 1049 ContentUris.appendId(builder, providerId); 1050 return builder.build(); 1051 } 1052 1053 /** 1054 * Gets the Uri to query off the record messages by account. 1055 * 1056 * @param accountId the account id. 1057 * @return the Uri 1058 */ getOtrMessagesContentUriByAccount(long accountId)1059 public static final Uri getOtrMessagesContentUriByAccount(long accountId) { 1060 Uri.Builder builder = OTR_MESSAGES_CONTENT_URI_BY_ACCOUNT.buildUpon(); 1061 ContentUris.appendId(builder, accountId); 1062 return builder.build(); 1063 } 1064 1065 /** 1066 * The content:// style URL for this table 1067 */ 1068 public static final Uri CONTENT_URI = 1069 Uri.parse("content://com.google.android.providers.talk/messages"); 1070 1071 /** 1072 * The content:// style URL for messages by thread id 1073 */ 1074 public static final Uri CONTENT_URI_MESSAGES_BY_THREAD_ID = 1075 Uri.parse("content://com.google.android.providers.talk/messagesByThreadId"); 1076 1077 /** 1078 * The content:// style URL for messages by account and contact 1079 */ 1080 public static final Uri CONTENT_URI_MESSAGES_BY_ACCOUNT_AND_CONTACT = 1081 Uri.parse("content://com.google.android.providers.talk/messagesByAcctAndContact"); 1082 1083 /** 1084 * The content:// style URL for messages by provider 1085 */ 1086 public static final Uri CONTENT_URI_MESSAGES_BY_PROVIDER = 1087 Uri.parse("content://com.google.android.providers.talk/messagesByProvider"); 1088 1089 /** 1090 * The content:// style URL for messages by account 1091 */ 1092 public static final Uri CONTENT_URI_BY_ACCOUNT = 1093 Uri.parse("content://com.google.android.providers.talk/messagesByAccount"); 1094 1095 /** 1096 * The content:// style url for off the record messages 1097 */ 1098 public static final Uri OTR_MESSAGES_CONTENT_URI = 1099 Uri.parse("content://com.google.android.providers.talk/otrMessages"); 1100 1101 /** 1102 * The content:// style url for off the record messages by thread id 1103 */ 1104 public static final Uri OTR_MESSAGES_CONTENT_URI_BY_THREAD_ID = 1105 Uri.parse("content://com.google.android.providers.talk/otrMessagesByThreadId"); 1106 1107 /** 1108 * The content:// style url for off the record messages by account and contact 1109 */ 1110 public static final Uri OTR_MESSAGES_CONTENT_URI_BY_ACCOUNT_AND_CONTACT = 1111 Uri.parse("content://com.google.android.providers.talk/otrMessagesByAcctAndContact"); 1112 1113 /** 1114 * The content:// style URL for off the record messages by provider 1115 */ 1116 public static final Uri OTR_MESSAGES_CONTENT_URI_BY_PROVIDER = 1117 Uri.parse("content://com.google.android.providers.talk/otrMessagesByProvider"); 1118 1119 /** 1120 * The content:// style URL for off the record messages by account 1121 */ 1122 public static final Uri OTR_MESSAGES_CONTENT_URI_BY_ACCOUNT = 1123 Uri.parse("content://com.google.android.providers.talk/otrMessagesByAccount"); 1124 1125 /** 1126 * The MIME type of {@link #CONTENT_URI} providing a directory of 1127 * people. 1128 */ 1129 public static final String CONTENT_TYPE = 1130 "vnd.android.cursor.dir/gtalk-messages"; 1131 1132 /** 1133 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single 1134 * person. 1135 */ 1136 public static final String CONTENT_ITEM_TYPE = 1137 "vnd.android.cursor.item/gtalk-messages"; 1138 1139 /** 1140 * The default sort order for this table 1141 */ 1142 public static final String DEFAULT_SORT_ORDER = "date ASC"; 1143 1144 /** 1145 * The "contact" column. This is not a real column in the messages table, but a 1146 * temoprary column created when querying for messages (joined with the contacts table) 1147 */ 1148 public static final String CONTACT = "contact"; 1149 } 1150 1151 /** 1152 * Columns for the GroupMember table. 1153 */ 1154 public interface GroupMemberColumns { 1155 /** 1156 * The id of the group this member belongs to. 1157 * <p>Type: INTEGER</p> 1158 */ 1159 String GROUP = "groupId"; 1160 1161 /** 1162 * The full name of this member. 1163 * <p>Type: TEXT</p> 1164 */ 1165 String USERNAME = "username"; 1166 1167 /** 1168 * The nick name of this member. 1169 * <p>Type: TEXT</p> 1170 */ 1171 String NICKNAME = "nickname"; 1172 } 1173 1174 public final static class GroupMembers implements GroupMemberColumns { GroupMembers()1175 private GroupMembers(){} 1176 1177 public static final Uri CONTENT_URI = 1178 Uri.parse("content://com.google.android.providers.talk/groupMembers"); 1179 1180 /** 1181 * The MIME type of {@link #CONTENT_URI} providing a directory of 1182 * group members. 1183 */ 1184 public static final String CONTENT_TYPE = 1185 "vnd.android.cursor.dir/gtalk-groupMembers"; 1186 1187 /** 1188 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single 1189 * group member. 1190 */ 1191 public static final String CONTENT_ITEM_TYPE = 1192 "vnd.android.cursor.item/gtalk-groupMembers"; 1193 } 1194 1195 /** 1196 * Columns from the Invitation table. 1197 */ 1198 public interface InvitationColumns { 1199 /** 1200 * The provider id. 1201 * <p>Type: INTEGER</p> 1202 */ 1203 String PROVIDER = "providerId"; 1204 1205 /** 1206 * The account id. 1207 * <p>Type: INTEGER</p> 1208 */ 1209 String ACCOUNT = "accountId"; 1210 1211 /** 1212 * The invitation id. 1213 * <p>Type: TEXT</p> 1214 */ 1215 String INVITE_ID = "inviteId"; 1216 1217 /** 1218 * The name of the sender of the invitation. 1219 * <p>Type: TEXT</p> 1220 */ 1221 String SENDER = "sender"; 1222 1223 /** 1224 * The name of the group which the sender invite you to join. 1225 * <p>Type: TEXT</p> 1226 */ 1227 String GROUP_NAME = "groupName"; 1228 1229 /** 1230 * A note 1231 * <p>Type: TEXT</p> 1232 */ 1233 String NOTE = "note"; 1234 1235 /** 1236 * The current status of the invitation. 1237 * <p>Type: TEXT</p> 1238 */ 1239 String STATUS = "status"; 1240 1241 int STATUS_PENDING = 0; 1242 int STATUS_ACCEPTED = 1; 1243 int STATUS_REJECTED = 2; 1244 } 1245 1246 /** 1247 * This table contains the invitations received from others. 1248 */ 1249 public final static class Invitation implements InvitationColumns, 1250 BaseColumns { Invitation()1251 private Invitation() { 1252 } 1253 1254 /** 1255 * The content:// style URL for this table 1256 */ 1257 public static final Uri CONTENT_URI = 1258 Uri.parse("content://com.google.android.providers.talk/invitations"); 1259 1260 /** 1261 * The MIME type of {@link #CONTENT_URI} providing a directory of 1262 * invitations. 1263 */ 1264 public static final String CONTENT_TYPE = 1265 "vnd.android.cursor.dir/gtalk-invitations"; 1266 1267 /** 1268 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single 1269 * invitation. 1270 */ 1271 public static final String CONTENT_ITEM_TYPE = 1272 "vnd.android.cursor.item/gtalk-invitations"; 1273 } 1274 1275 /** 1276 * Columns from the Avatars table 1277 */ 1278 public interface AvatarsColumns { 1279 /** 1280 * The contact this avatar belongs to 1281 * <P>Type: TEXT</P> 1282 */ 1283 String CONTACT = "contact"; 1284 1285 String PROVIDER = "provider_id"; 1286 1287 String ACCOUNT = "account_id"; 1288 1289 /** 1290 * The hash of the image data 1291 * <P>Type: TEXT</P> 1292 */ 1293 String HASH = "hash"; 1294 1295 /** 1296 * raw image data 1297 * <P>Type: BLOB</P> 1298 */ 1299 String DATA = "data"; 1300 } 1301 1302 /** 1303 * This table contains avatars. 1304 */ 1305 public static final class Avatars implements BaseColumns, AvatarsColumns { 1306 /** 1307 * no public constructor since this is a utility class 1308 */ Avatars()1309 private Avatars() {} 1310 1311 /** 1312 * The content:// style URL for this table 1313 */ 1314 public static final Uri CONTENT_URI = 1315 Uri.parse("content://com.google.android.providers.talk/avatars"); 1316 1317 /** 1318 * The content:// style URL for avatars by provider, account and contact 1319 */ 1320 public static final Uri CONTENT_URI_AVATARS_BY = 1321 Uri.parse("content://com.google.android.providers.talk/avatarsBy"); 1322 1323 /** 1324 * The MIME type of {@link #CONTENT_URI} providing the avatars 1325 */ 1326 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/gtalk-avatars"; 1327 1328 /** 1329 * The MIME type of a {@link #CONTENT_URI} 1330 */ 1331 public static final String CONTENT_ITEM_TYPE = 1332 "vnd.android.cursor.item/gtalk-avatars"; 1333 1334 /** 1335 * The default sort order for this table 1336 */ 1337 public static final String DEFAULT_SORT_ORDER = "contact ASC"; 1338 1339 } 1340 1341 /** 1342 * Common presence columns shared between the IM and contacts presence tables 1343 */ 1344 public interface CommonPresenceColumns { 1345 /** 1346 * The priority, an integer, used by XMPP presence 1347 * <P>Type: INTEGER</P> 1348 */ 1349 String PRIORITY = "priority"; 1350 1351 /** 1352 * The server defined status. 1353 * <P>Type: INTEGER (one of the values below)</P> 1354 */ 1355 String PRESENCE_STATUS = "mode"; 1356 1357 /** 1358 * Presence Status definition 1359 */ 1360 int OFFLINE = 0; 1361 int INVISIBLE = 1; 1362 int AWAY = 2; 1363 int IDLE = 3; 1364 int DO_NOT_DISTURB = 4; 1365 int AVAILABLE = 5; 1366 1367 /** 1368 * The user defined status line. 1369 * <P>Type: TEXT</P> 1370 */ 1371 String PRESENCE_CUSTOM_STATUS = "status"; 1372 } 1373 1374 /** 1375 * Columns from the Presence table. 1376 */ 1377 public interface PresenceColumns extends CommonPresenceColumns { 1378 /** 1379 * The contact id 1380 * <P>Type: INTEGER</P> 1381 */ 1382 String CONTACT_ID = "contact_id"; 1383 1384 /** 1385 * The contact's JID resource, only relevant for XMPP contact 1386 * <P>Type: TEXT</P> 1387 */ 1388 String JID_RESOURCE = "jid_resource"; 1389 1390 /** 1391 * The contact's client type 1392 */ 1393 String CLIENT_TYPE = "client_type"; 1394 1395 /** 1396 * client type definitions 1397 */ 1398 int CLIENT_TYPE_DEFAULT = 0; 1399 int CLIENT_TYPE_MOBILE = 1; 1400 int CLIENT_TYPE_ANDROID = 2; 1401 } 1402 1403 /** 1404 * Contains presence infomation for contacts. 1405 */ 1406 public static final class Presence implements BaseColumns, PresenceColumns { 1407 /** 1408 * The content:// style URL for this table 1409 */ 1410 public static final Uri CONTENT_URI = 1411 Uri.parse("content://com.google.android.providers.talk/presence"); 1412 1413 /** 1414 * The content URL for Talk presences for an account 1415 */ 1416 public static final Uri CONTENT_URI_BY_ACCOUNT = 1417 Uri.parse("content://com.google.android.providers.talk/presence/account"); 1418 1419 /** 1420 * The content:// style URL for operations on bulk contacts 1421 */ 1422 public static final Uri BULK_CONTENT_URI = 1423 Uri.parse("content://com.google.android.providers.talk/bulk_presence"); 1424 1425 /** 1426 * The content:// style URL for seeding presences for a given account id. 1427 */ 1428 public static final Uri SEED_PRESENCE_BY_ACCOUNT_CONTENT_URI = 1429 Uri.parse("content://com.google.android.providers.talk/seed_presence/account"); 1430 1431 /** 1432 * The MIME type of a {@link #CONTENT_URI} providing a directory of presence 1433 */ 1434 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/gtalk-presence"; 1435 1436 /** 1437 * The default sort order for this table 1438 */ 1439 public static final String DEFAULT_SORT_ORDER = "mode DESC"; 1440 } 1441 1442 /** 1443 * Columns from the Chats table. 1444 */ 1445 public interface ChatsColumns { 1446 /** 1447 * The contact ID this chat belongs to. The value is a long. 1448 * <P>Type: INT</P> 1449 */ 1450 String CONTACT_ID = "contact_id"; 1451 1452 /** 1453 * The GTalk JID resource. The value is a string. 1454 * <P>Type: TEXT</P> 1455 */ 1456 String JID_RESOURCE = "jid_resource"; 1457 1458 /** 1459 * Whether this is a groupchat or not. 1460 * <P>Type: INT</P> 1461 */ 1462 String GROUP_CHAT = "groupchat"; 1463 1464 /** 1465 * The last unread message. This both indicates that there is an 1466 * unread message, and what the message is. 1467 * <P>Type: TEXT</P> 1468 */ 1469 String LAST_UNREAD_MESSAGE = "last_unread_message"; 1470 1471 /** 1472 * The last message timestamp 1473 * <P>Type: INT</P> 1474 */ 1475 String LAST_MESSAGE_DATE = "last_message_date"; 1476 1477 /** 1478 * A message that is being composed. This indicates that there was a 1479 * message being composed when the chat screen was shutdown, and what the 1480 * message is. 1481 * <P>Type: TEXT</P> 1482 */ 1483 String UNSENT_COMPOSED_MESSAGE = "unsent_composed_message"; 1484 1485 /** 1486 * A value from 0-9 indicating which quick-switch chat screen slot this 1487 * chat is occupying. If none (for instance, this is the 12th active chat) 1488 * then the value is -1. 1489 * <P>Type: INT</P> 1490 */ 1491 String SHORTCUT = "shortcut"; 1492 } 1493 1494 /** 1495 * Contains ongoing chat sessions. 1496 */ 1497 public static final class Chats implements BaseColumns, ChatsColumns { 1498 /** 1499 * no public constructor since this is a utility class 1500 */ Chats()1501 private Chats() {} 1502 1503 /** 1504 * The content:// style URL for this table 1505 */ 1506 public static final Uri CONTENT_URI = 1507 Uri.parse("content://com.google.android.providers.talk/chats"); 1508 1509 /** 1510 * The content URL for all chats that belong to the account 1511 */ 1512 public static final Uri CONTENT_URI_BY_ACCOUNT = 1513 Uri.parse("content://com.google.android.providers.talk/chats/account"); 1514 1515 /** 1516 * The MIME type of {@link #CONTENT_URI} providing a directory of chats. 1517 */ 1518 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/gtalk-chats"; 1519 1520 /** 1521 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single chat. 1522 */ 1523 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/gtalk-chats"; 1524 1525 /** 1526 * The default sort order for this table 1527 */ 1528 public static final String DEFAULT_SORT_ORDER = "last_message_date ASC"; 1529 } 1530 1531 /** 1532 * Columns from session cookies table. Used for IMPS. 1533 */ 1534 public static interface SessionCookiesColumns { 1535 String NAME = "name"; 1536 String VALUE = "value"; 1537 String PROVIDER = "provider"; 1538 String ACCOUNT = "account"; 1539 } 1540 1541 /** 1542 * Contains IMPS session cookies. 1543 */ 1544 public static class SessionCookies implements SessionCookiesColumns, BaseColumns { SessionCookies()1545 private SessionCookies() { 1546 } 1547 1548 /** 1549 * The content:// style URI for this table 1550 */ 1551 public static final Uri CONTENT_URI = 1552 Uri.parse("content://com.google.android.providers.talk/sessionCookies"); 1553 1554 /** 1555 * The content:// style URL for session cookies by provider and account 1556 */ 1557 public static final Uri CONTENT_URI_SESSION_COOKIES_BY = 1558 Uri.parse("content://com.google.android.providers.talk/sessionCookiesBy"); 1559 1560 /** 1561 * The MIME type of {@link #CONTENT_URI} providing a directory of 1562 * people. 1563 */ 1564 public static final String CONTENT_TYPE = "vnd.android-dir/gtalk-sessionCookies"; 1565 } 1566 1567 /** 1568 * Columns from ProviderSettings table 1569 */ 1570 public static interface ProviderSettingsColumns { 1571 /** 1572 * The id in database of the related provider 1573 * 1574 * <P>Type: INT</P> 1575 */ 1576 String PROVIDER = "provider"; 1577 1578 /** 1579 * The name of the setting 1580 * <P>Type: TEXT</P> 1581 */ 1582 String NAME = "name"; 1583 1584 /** 1585 * The value of the setting 1586 * <P>Type: TEXT</P> 1587 */ 1588 String VALUE = "value"; 1589 } 1590 1591 public static class ProviderSettings implements ProviderSettingsColumns { ProviderSettings()1592 private ProviderSettings() { 1593 } 1594 1595 /** 1596 * The content:// style URI for this table 1597 */ 1598 public static final Uri CONTENT_URI = 1599 Uri.parse("content://com.google.android.providers.talk/providerSettings"); 1600 1601 /** 1602 * The MIME type of {@link #CONTENT_URI} providing provider settings 1603 */ 1604 public static final String CONTENT_TYPE = "vnd.android-dir/gtalk-providerSettings"; 1605 1606 /** 1607 * A boolean value to indicate whether this provider should show the offline contacts 1608 */ 1609 public static final String SHOW_OFFLINE_CONTACTS = "show_offline_contacts"; 1610 1611 /** controls whether or not the GTalk service automatically connect to server. */ 1612 public static final String SETTING_AUTOMATICALLY_CONNECT_GTALK = "gtalk_auto_connect"; 1613 1614 /** controls whether or not the GTalk service will be automatically started after boot */ 1615 public static final String SETTING_AUTOMATICALLY_START_SERVICE = "auto_start_service"; 1616 1617 /** controls whether or not the offline contacts will be hided */ 1618 public static final String SETTING_HIDE_OFFLINE_CONTACTS = "hide_offline_contacts"; 1619 1620 /** controls whether or not enable the GTalk notification */ 1621 public static final String SETTING_ENABLE_NOTIFICATION = "enable_notification"; 1622 1623 /** specifies whether or not to vibrate */ 1624 public static final String SETTING_VIBRATE = "vibrate"; 1625 1626 /** specifies the Uri string of the ringtone */ 1627 public static final String SETTING_RINGTONE = "ringtone"; 1628 1629 /** specifies the Uri of the default ringtone */ 1630 public static final String SETTING_RINGTONE_DEFAULT = 1631 "content://settings/system/notification_sound"; 1632 1633 /** specifies whether or not to show mobile indicator to friends */ 1634 public static final String SETTING_SHOW_MOBILE_INDICATOR = "mobile_indicator"; 1635 1636 /** specifies whether or not to show as away when device is idle */ 1637 public static final String SETTING_SHOW_AWAY_ON_IDLE = "show_away_on_idle"; 1638 1639 /** specifies whether or not to upload heartbeat stat upon login */ 1640 public static final String SETTING_UPLOAD_HEARTBEAT_STAT = "upload_heartbeat_stat"; 1641 1642 /** specifies the last heartbeat interval received from the server */ 1643 public static final String SETTING_HEARTBEAT_INTERVAL = "heartbeat_interval"; 1644 1645 /** specifiy the JID resource used for Google Talk connection */ 1646 public static final String SETTING_JID_RESOURCE = "jid_resource"; 1647 1648 /** 1649 * Used for reliable message queue (RMQ). This is for storing the last rmq id received 1650 * from the GTalk server 1651 */ 1652 public static final String LAST_RMQ_RECEIVED = "last_rmq_rec"; 1653 1654 /** 1655 * Query the settings of the provider specified by id 1656 * 1657 * @param cr 1658 * the relative content resolver 1659 * @param providerId 1660 * the specified id of provider 1661 * @return a HashMap which contains all the settings for the specified 1662 * provider 1663 */ queryProviderSettings(ContentResolver cr, long providerId)1664 public static HashMap<String, String> queryProviderSettings(ContentResolver cr, 1665 long providerId) { 1666 HashMap<String, String> settings = new HashMap<String, String>(); 1667 1668 String[] projection = { NAME, VALUE }; 1669 Cursor c = cr.query(ContentUris.withAppendedId(CONTENT_URI, providerId), projection, null, null, null); 1670 if (c == null) { 1671 return null; 1672 } 1673 1674 while(c.moveToNext()) { 1675 settings.put(c.getString(0), c.getString(1)); 1676 } 1677 1678 c.close(); 1679 1680 return settings; 1681 } 1682 1683 /** 1684 * Get the string value of setting which is specified by provider id and the setting name. 1685 * 1686 * @param cr The ContentResolver to use to access the settings table. 1687 * @param providerId The id of the provider. 1688 * @param settingName The name of the setting. 1689 * @return The value of the setting if the setting exist, otherwise return null. 1690 */ getStringValue(ContentResolver cr, long providerId, String settingName)1691 public static String getStringValue(ContentResolver cr, long providerId, String settingName) { 1692 String ret = null; 1693 Cursor c = getSettingValue(cr, providerId, settingName); 1694 if (c != null) { 1695 ret = c.getString(0); 1696 c.close(); 1697 } 1698 1699 return ret; 1700 } 1701 1702 /** 1703 * Get the boolean value of setting which is specified by provider id and the setting name. 1704 * 1705 * @param cr The ContentResolver to use to access the settings table. 1706 * @param providerId The id of the provider. 1707 * @param settingName The name of the setting. 1708 * @return The value of the setting if the setting exist, otherwise return false. 1709 */ getBooleanValue(ContentResolver cr, long providerId, String settingName)1710 public static boolean getBooleanValue(ContentResolver cr, long providerId, String settingName) { 1711 boolean ret = false; 1712 Cursor c = getSettingValue(cr, providerId, settingName); 1713 if (c != null) { 1714 ret = c.getInt(0) != 0; 1715 c.close(); 1716 } 1717 return ret; 1718 } 1719 getSettingValue(ContentResolver cr, long providerId, String settingName)1720 private static Cursor getSettingValue(ContentResolver cr, long providerId, String settingName) { 1721 Cursor c = cr.query(ContentUris.withAppendedId(CONTENT_URI, providerId), new String[]{VALUE}, NAME + "=?", 1722 new String[]{settingName}, null); 1723 if (c != null) { 1724 if (!c.moveToFirst()) { 1725 c.close(); 1726 return null; 1727 } 1728 } 1729 return c; 1730 } 1731 1732 /** 1733 * Save a long value of setting in the table providerSetting. 1734 * 1735 * @param cr The ContentProvider used to access the providerSetting table. 1736 * @param providerId The id of the provider. 1737 * @param name The name of the setting. 1738 * @param value The value of the setting. 1739 */ putLongValue(ContentResolver cr, long providerId, String name, long value)1740 public static void putLongValue(ContentResolver cr, long providerId, String name, 1741 long value) { 1742 ContentValues v = new ContentValues(3); 1743 v.put(PROVIDER, providerId); 1744 v.put(NAME, name); 1745 v.put(VALUE, value); 1746 1747 cr.insert(CONTENT_URI, v); 1748 } 1749 1750 /** 1751 * Save a boolean value of setting in the table providerSetting. 1752 * 1753 * @param cr The ContentProvider used to access the providerSetting table. 1754 * @param providerId The id of the provider. 1755 * @param name The name of the setting. 1756 * @param value The value of the setting. 1757 */ putBooleanValue(ContentResolver cr, long providerId, String name, boolean value)1758 public static void putBooleanValue(ContentResolver cr, long providerId, String name, 1759 boolean value) { 1760 ContentValues v = new ContentValues(3); 1761 v.put(PROVIDER, providerId); 1762 v.put(NAME, name); 1763 v.put(VALUE, Boolean.toString(value)); 1764 1765 cr.insert(CONTENT_URI, v); 1766 } 1767 1768 /** 1769 * Save a string value of setting in the table providerSetting. 1770 * 1771 * @param cr The ContentProvider used to access the providerSetting table. 1772 * @param providerId The id of the provider. 1773 * @param name The name of the setting. 1774 * @param value The value of the setting. 1775 */ putStringValue(ContentResolver cr, long providerId, String name, String value)1776 public static void putStringValue(ContentResolver cr, long providerId, String name, 1777 String value) { 1778 ContentValues v = new ContentValues(3); 1779 v.put(PROVIDER, providerId); 1780 v.put(NAME, name); 1781 v.put(VALUE, value); 1782 1783 cr.insert(CONTENT_URI, v); 1784 } 1785 1786 /** 1787 * A convenience method to set whether or not the GTalk service should be started 1788 * automatically. 1789 * 1790 * @param contentResolver The ContentResolver to use to access the settings table 1791 * @param autoConnect Whether the GTalk service should be started automatically. 1792 */ setAutomaticallyConnectGTalk(ContentResolver contentResolver, long providerId, boolean autoConnect)1793 public static void setAutomaticallyConnectGTalk(ContentResolver contentResolver, 1794 long providerId, boolean autoConnect) { 1795 putBooleanValue(contentResolver, providerId, SETTING_AUTOMATICALLY_CONNECT_GTALK, 1796 autoConnect); 1797 } 1798 1799 /** 1800 * A convenience method to set whether or not the offline contacts should be hided 1801 * 1802 * @param contentResolver The ContentResolver to use to access the setting table 1803 * @param hideOfflineContacts Whether the offline contacts should be hided 1804 */ setHideOfflineContacts(ContentResolver contentResolver, long providerId, boolean hideOfflineContacts)1805 public static void setHideOfflineContacts(ContentResolver contentResolver, 1806 long providerId, boolean hideOfflineContacts) { 1807 putBooleanValue(contentResolver, providerId, SETTING_HIDE_OFFLINE_CONTACTS, 1808 hideOfflineContacts); 1809 } 1810 1811 /** 1812 * A convenience method to set whether or not enable the GTalk notification. 1813 * 1814 * @param contentResolver The ContentResolver to use to access the setting table. 1815 * @param enable Whether enable the GTalk notification 1816 */ setEnableNotification(ContentResolver contentResolver, long providerId, boolean enable)1817 public static void setEnableNotification(ContentResolver contentResolver, long providerId, 1818 boolean enable) { 1819 putBooleanValue(contentResolver, providerId, SETTING_ENABLE_NOTIFICATION, enable); 1820 } 1821 1822 /** 1823 * A convenience method to set whether or not to vibrate. 1824 * 1825 * @param contentResolver The ContentResolver to use to access the setting table. 1826 * @param vibrate Whether or not to vibrate 1827 */ setVibrate(ContentResolver contentResolver, long providerId, boolean vibrate)1828 public static void setVibrate(ContentResolver contentResolver, long providerId, 1829 boolean vibrate) { 1830 putBooleanValue(contentResolver, providerId, SETTING_VIBRATE, vibrate); 1831 } 1832 1833 /** 1834 * A convenience method to set the Uri String of the ringtone. 1835 * 1836 * @param contentResolver The ContentResolver to use to access the setting table. 1837 * @param ringtoneUri The Uri String of the ringtone to be set. 1838 */ setRingtoneURI(ContentResolver contentResolver, long providerId, String ringtoneUri)1839 public static void setRingtoneURI(ContentResolver contentResolver, long providerId, 1840 String ringtoneUri) { 1841 putStringValue(contentResolver, providerId, SETTING_RINGTONE, ringtoneUri); 1842 } 1843 1844 /** 1845 * A convenience method to set whether or not to show mobile indicator. 1846 * 1847 * @param contentResolver The ContentResolver to use to access the setting table. 1848 * @param showMobileIndicator Whether or not to show mobile indicator. 1849 */ setShowMobileIndicator(ContentResolver contentResolver, long providerId, boolean showMobileIndicator)1850 public static void setShowMobileIndicator(ContentResolver contentResolver, long providerId, 1851 boolean showMobileIndicator) { 1852 putBooleanValue(contentResolver, providerId, SETTING_SHOW_MOBILE_INDICATOR, 1853 showMobileIndicator); 1854 } 1855 1856 /** 1857 * A convenience method to set whether or not to show as away when device is idle. 1858 * 1859 * @param contentResolver The ContentResolver to use to access the setting table. 1860 * @param showAway Whether or not to show as away when device is idle. 1861 */ setShowAwayOnIdle(ContentResolver contentResolver, long providerId, boolean showAway)1862 public static void setShowAwayOnIdle(ContentResolver contentResolver, 1863 long providerId, boolean showAway) { 1864 putBooleanValue(contentResolver, providerId, SETTING_SHOW_AWAY_ON_IDLE, showAway); 1865 } 1866 1867 /** 1868 * A convenience method to set whether or not to upload heartbeat stat. 1869 * 1870 * @param contentResolver The ContentResolver to use to access the setting table. 1871 * @param uploadStat Whether or not to upload heartbeat stat. 1872 */ setUploadHeartbeatStat(ContentResolver contentResolver, long providerId, boolean uploadStat)1873 public static void setUploadHeartbeatStat(ContentResolver contentResolver, 1874 long providerId, boolean uploadStat) { 1875 putBooleanValue(contentResolver, providerId, SETTING_UPLOAD_HEARTBEAT_STAT, uploadStat); 1876 } 1877 1878 /** 1879 * A convenience method to set the heartbeat interval last received from the server. 1880 * 1881 * @param contentResolver The ContentResolver to use to access the setting table. 1882 * @param interval The heartbeat interval last received from the server. 1883 */ setHeartbeatInterval(ContentResolver contentResolver, long providerId, long interval)1884 public static void setHeartbeatInterval(ContentResolver contentResolver, 1885 long providerId, long interval) { 1886 putLongValue(contentResolver, providerId, SETTING_HEARTBEAT_INTERVAL, interval); 1887 } 1888 1889 /** 1890 * A convenience method to set the jid resource. 1891 */ setJidResource(ContentResolver contentResolver, long providerId, String jidResource)1892 public static void setJidResource(ContentResolver contentResolver, 1893 long providerId, String jidResource) { 1894 putStringValue(contentResolver, providerId, SETTING_JID_RESOURCE, jidResource); 1895 } 1896 1897 public static class QueryMap extends ContentQueryMap { 1898 private ContentResolver mContentResolver; 1899 private long mProviderId; 1900 QueryMap(ContentResolver contentResolver, long providerId, boolean keepUpdated, Handler handlerForUpdateNotifications)1901 public QueryMap(ContentResolver contentResolver, long providerId, boolean keepUpdated, 1902 Handler handlerForUpdateNotifications) { 1903 super(contentResolver.query(CONTENT_URI, 1904 new String[] {NAME,VALUE}, 1905 PROVIDER + "=" + providerId, 1906 null, // no selection args 1907 null), // no sort order 1908 NAME, keepUpdated, handlerForUpdateNotifications); 1909 mContentResolver = contentResolver; 1910 mProviderId = providerId; 1911 } 1912 1913 /** 1914 * Set if the GTalk service should automatically connect to server. 1915 * 1916 * @param autoConnect if the GTalk service should auto connect to server. 1917 */ setAutomaticallyConnectToGTalkServer(boolean autoConnect)1918 public void setAutomaticallyConnectToGTalkServer(boolean autoConnect) { 1919 ProviderSettings.setAutomaticallyConnectGTalk(mContentResolver, mProviderId, 1920 autoConnect); 1921 } 1922 1923 /** 1924 * Check if the GTalk service should automatically connect to server. 1925 * @return if the GTalk service should automatically connect to server. 1926 */ getAutomaticallyConnectToGTalkServer()1927 public boolean getAutomaticallyConnectToGTalkServer() { 1928 return getBoolean(SETTING_AUTOMATICALLY_CONNECT_GTALK, 1929 true /* default to automatically sign in */); 1930 } 1931 1932 /** 1933 * Set whether or not the offline contacts should be hided. 1934 * 1935 * @param hideOfflineContacts Whether or not the offline contacts should be hided. 1936 */ setHideOfflineContacts(boolean hideOfflineContacts)1937 public void setHideOfflineContacts(boolean hideOfflineContacts) { 1938 ProviderSettings.setHideOfflineContacts(mContentResolver, mProviderId, 1939 hideOfflineContacts); 1940 } 1941 1942 /** 1943 * Check if the offline contacts should be hided. 1944 * 1945 * @return Whether or not the offline contacts should be hided. 1946 */ getHideOfflineContacts()1947 public boolean getHideOfflineContacts() { 1948 return getBoolean(SETTING_HIDE_OFFLINE_CONTACTS, 1949 false/* by default not hide the offline contacts*/); 1950 } 1951 1952 /** 1953 * Set whether or not enable the GTalk notification. 1954 * 1955 * @param enable Whether or not enable the GTalk notification. 1956 */ setEnableNotification(boolean enable)1957 public void setEnableNotification(boolean enable) { 1958 ProviderSettings.setEnableNotification(mContentResolver, mProviderId, enable); 1959 } 1960 1961 /** 1962 * Check if the GTalk notification is enabled. 1963 * 1964 * @return Whether or not enable the GTalk notification. 1965 */ getEnableNotification()1966 public boolean getEnableNotification() { 1967 return getBoolean(SETTING_ENABLE_NOTIFICATION, 1968 true/* by default enable the notification */); 1969 } 1970 1971 /** 1972 * Set whether or not to vibrate on GTalk notification. 1973 * 1974 * @param vibrate Whether or not to vibrate. 1975 */ setVibrate(boolean vibrate)1976 public void setVibrate(boolean vibrate) { 1977 ProviderSettings.setVibrate(mContentResolver, mProviderId, vibrate); 1978 } 1979 1980 /** 1981 * Gets whether or not to vibrate on GTalk notification. 1982 * 1983 * @return Whether or not to vibrate. 1984 */ getVibrate()1985 public boolean getVibrate() { 1986 return getBoolean(SETTING_VIBRATE, false /* by default disable vibrate */); 1987 } 1988 1989 /** 1990 * Set the Uri for the ringtone. 1991 * 1992 * @param ringtoneUri The Uri of the ringtone to be set. 1993 */ setRingtoneURI(String ringtoneUri)1994 public void setRingtoneURI(String ringtoneUri) { 1995 ProviderSettings.setRingtoneURI(mContentResolver, mProviderId, ringtoneUri); 1996 } 1997 1998 /** 1999 * Get the Uri String of the current ringtone. 2000 * 2001 * @return The Uri String of the current ringtone. 2002 */ getRingtoneURI()2003 public String getRingtoneURI() { 2004 return getString(SETTING_RINGTONE, SETTING_RINGTONE_DEFAULT); 2005 } 2006 2007 /** 2008 * Set whether or not to show mobile indicator to friends. 2009 * 2010 * @param showMobile whether or not to show mobile indicator. 2011 */ setShowMobileIndicator(boolean showMobile)2012 public void setShowMobileIndicator(boolean showMobile) { 2013 ProviderSettings.setShowMobileIndicator(mContentResolver, mProviderId, showMobile); 2014 } 2015 2016 /** 2017 * Gets whether or not to show mobile indicator. 2018 * 2019 * @return Whether or not to show mobile indicator. 2020 */ getShowMobileIndicator()2021 public boolean getShowMobileIndicator() { 2022 return getBoolean(SETTING_SHOW_MOBILE_INDICATOR, 2023 true /* by default show mobile indicator */); 2024 } 2025 2026 /** 2027 * Set whether or not to show as away when device is idle. 2028 * 2029 * @param showAway whether or not to show as away when device is idle. 2030 */ setShowAwayOnIdle(boolean showAway)2031 public void setShowAwayOnIdle(boolean showAway) { 2032 ProviderSettings.setShowAwayOnIdle(mContentResolver, mProviderId, showAway); 2033 } 2034 2035 /** 2036 * Get whether or not to show as away when device is idle. 2037 * 2038 * @return Whether or not to show as away when device is idle. 2039 */ getShowAwayOnIdle()2040 public boolean getShowAwayOnIdle() { 2041 return getBoolean(SETTING_SHOW_AWAY_ON_IDLE, 2042 true /* by default show as away on idle*/); 2043 } 2044 2045 /** 2046 * Set whether or not to upload heartbeat stat. 2047 * 2048 * @param uploadStat whether or not to upload heartbeat stat. 2049 */ setUploadHeartbeatStat(boolean uploadStat)2050 public void setUploadHeartbeatStat(boolean uploadStat) { 2051 ProviderSettings.setUploadHeartbeatStat(mContentResolver, mProviderId, uploadStat); 2052 } 2053 2054 /** 2055 * Get whether or not to upload heartbeat stat. 2056 * 2057 * @return Whether or not to upload heartbeat stat. 2058 */ getUploadHeartbeatStat()2059 public boolean getUploadHeartbeatStat() { 2060 return getBoolean(SETTING_UPLOAD_HEARTBEAT_STAT, 2061 false /* by default do not upload */); 2062 } 2063 2064 /** 2065 * Set the last received heartbeat interval from the server. 2066 * 2067 * @param interval the last received heartbeat interval from the server. 2068 */ setHeartbeatInterval(long interval)2069 public void setHeartbeatInterval(long interval) { 2070 ProviderSettings.setHeartbeatInterval(mContentResolver, mProviderId, interval); 2071 } 2072 2073 /** 2074 * Get the last received heartbeat interval from the server. 2075 * 2076 * @return the last received heartbeat interval from the server. 2077 */ getHeartbeatInterval()2078 public long getHeartbeatInterval() { 2079 return getLong(SETTING_HEARTBEAT_INTERVAL, 0L /* an invalid default interval */); 2080 } 2081 2082 /** 2083 * Set the JID resource. 2084 * 2085 * @param jidResource the jid resource to be stored. 2086 */ setJidResource(String jidResource)2087 public void setJidResource(String jidResource) { 2088 ProviderSettings.setJidResource(mContentResolver, mProviderId, jidResource); 2089 } 2090 /** 2091 * Get the JID resource used for the Google Talk connection 2092 * 2093 * @return the JID resource stored. 2094 */ getJidResource()2095 public String getJidResource() { 2096 return getString(SETTING_JID_RESOURCE, null); 2097 } 2098 2099 /** 2100 * Convenience function for retrieving a single settings value 2101 * as a boolean. 2102 * 2103 * @param name The name of the setting to retrieve. 2104 * @param def Value to return if the setting is not defined. 2105 * @return The setting's current value, or 'def' if it is not defined. 2106 */ getBoolean(String name, boolean def)2107 private boolean getBoolean(String name, boolean def) { 2108 ContentValues values = getValues(name); 2109 return values != null ? values.getAsBoolean(VALUE) : def; 2110 } 2111 2112 /** 2113 * Convenience function for retrieving a single settings value 2114 * as a String. 2115 * 2116 * @param name The name of the setting to retrieve. 2117 * @param def The value to return if the setting is not defined. 2118 * @return The setting's current value or 'def' if it is not defined. 2119 */ getString(String name, String def)2120 private String getString(String name, String def) { 2121 ContentValues values = getValues(name); 2122 return values != null ? values.getAsString(VALUE) : def; 2123 } 2124 2125 /** 2126 * Convenience function for retrieving a single settings value 2127 * as an Integer. 2128 * 2129 * @param name The name of the setting to retrieve. 2130 * @param def The value to return if the setting is not defined. 2131 * @return The setting's current value or 'def' if it is not defined. 2132 */ getInteger(String name, int def)2133 private int getInteger(String name, int def) { 2134 ContentValues values = getValues(name); 2135 return values != null ? values.getAsInteger(VALUE) : def; 2136 } 2137 2138 /** 2139 * Convenience function for retrieving a single settings value 2140 * as a Long. 2141 * 2142 * @param name The name of the setting to retrieve. 2143 * @param def The value to return if the setting is not defined. 2144 * @return The setting's current value or 'def' if it is not defined. 2145 */ getLong(String name, long def)2146 private long getLong(String name, long def) { 2147 ContentValues values = getValues(name); 2148 return values != null ? values.getAsLong(VALUE) : def; 2149 } 2150 } 2151 2152 } 2153 2154 2155 /** 2156 * Columns for GTalk branding resource map cache table. This table caches the result of 2157 * loading the branding resources to speed up GTalk landing page start. 2158 */ 2159 public interface BrandingResourceMapCacheColumns { 2160 /** 2161 * The provider ID 2162 * <P>Type: INTEGER</P> 2163 */ 2164 String PROVIDER_ID = "provider_id"; 2165 /** 2166 * The application resource ID 2167 * <P>Type: INTEGER</P> 2168 */ 2169 String APP_RES_ID = "app_res_id"; 2170 /** 2171 * The plugin resource ID 2172 * <P>Type: INTEGER</P> 2173 */ 2174 String PLUGIN_RES_ID = "plugin_res_id"; 2175 } 2176 2177 /** 2178 * The table for caching the result of loading GTalk branding resources. 2179 */ 2180 public static final class BrandingResourceMapCache 2181 implements BaseColumns, BrandingResourceMapCacheColumns { 2182 /** 2183 * The content:// style URL for this table. 2184 */ 2185 public static final Uri CONTENT_URI = 2186 Uri.parse("content://com.google.android.providers.talk/brandingResMapCache"); 2187 } 2188 2189 2190 2191 /** 2192 * //TODO: move these to MCS specific provider. 2193 * The following are MCS stuff, and should really live in a separate provider specific to 2194 * MCS code. 2195 */ 2196 2197 /** 2198 * Columns from OutgoingRmq table 2199 */ 2200 public interface OutgoingRmqColumns { 2201 String RMQ_ID = "rmq_id"; 2202 String TIMESTAMP = "ts"; 2203 String DATA = "data"; 2204 String PROTOBUF_TAG = "type"; 2205 } 2206 2207 /** 2208 * //TODO: we should really move these to their own provider and database. 2209 * The table for storing outgoing rmq packets. 2210 */ 2211 public static final class OutgoingRmq implements BaseColumns, OutgoingRmqColumns { 2212 private static String[] RMQ_ID_PROJECTION = new String[] { 2213 RMQ_ID, 2214 }; 2215 2216 /** 2217 * queryHighestRmqId 2218 * 2219 * @param resolver the content resolver 2220 * @return the highest rmq id assigned to the rmq packet, or 0 if there are no rmq packets 2221 * in the OutgoingRmq table. 2222 */ queryHighestRmqId(ContentResolver resolver)2223 public static final long queryHighestRmqId(ContentResolver resolver) { 2224 Cursor cursor = resolver.query(Im.OutgoingRmq.CONTENT_URI_FOR_HIGHEST_RMQ_ID, 2225 RMQ_ID_PROJECTION, 2226 null, // selection 2227 null, // selection args 2228 null // sort 2229 ); 2230 2231 long retVal = 0; 2232 try { 2233 //if (DBG) log("initializeRmqid: cursor.count= " + cursor.count()); 2234 2235 if (cursor.moveToFirst()) { 2236 retVal = cursor.getLong(cursor.getColumnIndexOrThrow(RMQ_ID)); 2237 } 2238 } finally { 2239 cursor.close(); 2240 } 2241 2242 return retVal; 2243 } 2244 2245 /** 2246 * The content:// style URL for this table. 2247 */ 2248 public static final Uri CONTENT_URI = 2249 Uri.parse("content://com.google.android.providers.talk/outgoingRmqMessages"); 2250 2251 /** 2252 * The content:// style URL for the highest rmq id for the outgoing rmq messages 2253 */ 2254 public static final Uri CONTENT_URI_FOR_HIGHEST_RMQ_ID = 2255 Uri.parse("content://com.google.android.providers.talk/outgoingHighestRmqId"); 2256 2257 /** 2258 * The default sort order for this table. 2259 */ 2260 public static final String DEFAULT_SORT_ORDER = "rmq_id ASC"; 2261 } 2262 2263 /** 2264 * Columns for the LastRmqId table, which stores a single row for the last client rmq id 2265 * sent to the server. 2266 */ 2267 public interface LastRmqIdColumns { 2268 String RMQ_ID = "rmq_id"; 2269 } 2270 2271 /** 2272 * //TODO: move these out into their own provider and database 2273 * The table for storing the last client rmq id sent to the server. 2274 */ 2275 public static final class LastRmqId implements BaseColumns, LastRmqIdColumns { 2276 private static String[] PROJECTION = new String[] { 2277 RMQ_ID, 2278 }; 2279 2280 /** 2281 * queryLastRmqId 2282 * 2283 * queries the last rmq id saved in the LastRmqId table. 2284 * 2285 * @param resolver the content resolver. 2286 * @return the last rmq id stored in the LastRmqId table, or 0 if not found. 2287 */ queryLastRmqId(ContentResolver resolver)2288 public static final long queryLastRmqId(ContentResolver resolver) { 2289 Cursor cursor = resolver.query(Im.LastRmqId.CONTENT_URI, 2290 PROJECTION, 2291 null, // selection 2292 null, // selection args 2293 null // sort 2294 ); 2295 2296 long retVal = 0; 2297 try { 2298 if (cursor.moveToFirst()) { 2299 retVal = cursor.getLong(cursor.getColumnIndexOrThrow(RMQ_ID)); 2300 } 2301 } finally { 2302 cursor.close(); 2303 } 2304 2305 return retVal; 2306 } 2307 2308 /** 2309 * saveLastRmqId 2310 * 2311 * saves the rmqId to the lastRmqId table. This will override the existing row if any, 2312 * as we only keep one row of data in this table. 2313 * 2314 * @param resolver the content resolver. 2315 * @param rmqId the rmq id to be saved. 2316 */ saveLastRmqId(ContentResolver resolver, long rmqId)2317 public static final void saveLastRmqId(ContentResolver resolver, long rmqId) { 2318 ContentValues values = new ContentValues(); 2319 2320 // always replace the first row. 2321 values.put(_ID, 1); 2322 values.put(RMQ_ID, rmqId); 2323 resolver.insert(CONTENT_URI, values); 2324 } 2325 2326 /** 2327 * The content:// style URL for this table. 2328 */ 2329 public static final Uri CONTENT_URI = 2330 Uri.parse("content://com.google.android.providers.talk/lastRmqId"); 2331 } 2332 2333 /** 2334 * Columns for the s2dRmqIds table, which stores the server-to-device message 2335 * persistent ids. These are used in the RMQ2 protocol, where in the login request, the 2336 * client selective acks these s2d ids to the server. 2337 */ 2338 public interface ServerToDeviceRmqIdsColumn { 2339 String RMQ_ID = "rmq_id"; 2340 } 2341 2342 public static final class ServerToDeviceRmqIds implements BaseColumns, 2343 ServerToDeviceRmqIdsColumn { 2344 2345 /** 2346 * The content:// style URL for this table. 2347 */ 2348 public static final Uri CONTENT_URI = 2349 Uri.parse("content://com.google.android.providers.talk/s2dids"); 2350 } 2351 2352 } 2353