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