blob: 025d5c266783b82740016b7bbeac217672c542b0 [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/**
Ye Wen9a0bf142009-09-11 11:48:19 -070030 * The GTalk provider stores all information about roster contacts, chat messages, presence, etc.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031 *
32 * @hide
33 */
34public class Im {
35 /**
36 * no public constructor since this is a utility class
37 */
38 private Im() {}
39
40 /**
Ye Wen9a0bf142009-09-11 11:48:19 -070041 * The Columns for IM providers
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042 */
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";
Scott Su527f0152009-08-20 22:34:55 +0800141 public static final String ACTIVE_ACCOUNT_KEEP_SIGNED_IN = "account_keepSignedIn";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 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 =
Ye Wen9a0bf142009-09-11 11:48:19 -0700149 Uri.parse("content://com.google.android.providers.talk/providers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150
151 public static final Uri CONTENT_URI_WITH_ACCOUNT =
Ye Wen9a0bf142009-09-11 11:48:19 -0700152 Uri.parse("content://com.google.android.providers.talk/providers/account");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153
154 /**
155 * The MIME type of {@link #CONTENT_URI} providing a directory of
156 * people.
157 */
158 public static final String CONTENT_TYPE =
Ye Wen9a0bf142009-09-11 11:48:19 -0700159 "vnd.android.cursor.dir/gtalk-providers";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160
161 public static final String CONTENT_ITEM_TYPE =
Ye Wen9a0bf142009-09-11 11:48:19 -0700162 "vnd.android.cursor.item/gtalk-providers";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163
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 {
227 private Account() {}
228
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -0700256 Uri.parse("content://com.google.android.providers.talk/accounts");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257
258 /**
259 * The MIME type of {@link #CONTENT_URI} providing a directory of
260 * account.
261 */
262 public static final String CONTENT_TYPE =
Ye Wen9a0bf142009-09-11 11:48:19 -0700263 "vnd.android.cursor.dir/gtalk-accounts";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -0700270 "vnd.android.cursor.item/gtalk-accounts";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -0700329 Uri.parse("content://com.google.android.providers.talk/accountStatus");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330
331 /**
332 * The MIME type of {@link #CONTENT_URI} providing a directory of account status.
333 */
334 public static final String CONTENT_TYPE =
Ye Wen9a0bf142009-09-11 11:48:19 -0700335 "vnd.android.cursor.dir/gtalk-account-status";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -0700341 "vnd.android.cursor.item/gtalk-account-status";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342
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 */
519 private Contacts() {}
520
521 /**
522 * The content:// style URL for this table
523 */
524 public static final Uri CONTENT_URI =
Ye Wen9a0bf142009-09-11 11:48:19 -0700525 Uri.parse("content://com.google.android.providers.talk/contacts");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526
527 /**
528 * The content:// style URL for contacts joined with presence
529 */
530 public static final Uri CONTENT_URI_WITH_PRESENCE =
Ye Wen9a0bf142009-09-11 11:48:19 -0700531 Uri.parse("content://com.google.android.providers.talk/contactsWithPresence");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -0700537 Uri.parse("content://com.google.android.providers.talk/contactsBarebone");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538
539 /**
540 * The content:// style URL for contacts who have an open chat session
541 */
542 public static final Uri CONTENT_URI_CHAT_CONTACTS =
Mark Wagnere7d26692009-09-28 15:10:28 -0700543 Uri.parse("content://com.google.android.providers.talk/contacts_chatting");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544
545 /**
546 * The content:// style URL for contacts who have been blocked
547 */
548 public static final Uri CONTENT_URI_BLOCKED_CONTACTS =
Ye Wen9a0bf142009-09-11 11:48:19 -0700549 Uri.parse("content://com.google.android.providers.talk/contacts/blocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550
551 /**
552 * The content:// style URL for contacts by provider and account
553 */
554 public static final Uri CONTENT_URI_CONTACTS_BY =
Ye Wen9a0bf142009-09-11 11:48:19 -0700555 Uri.parse("content://com.google.android.providers.talk/contacts");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -0700562 Uri.parse("content://com.google.android.providers.talk/contacts/chatting");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -0700569 Uri.parse("content://com.google.android.providers.talk/contacts/online");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -0700576 Uri.parse("content://com.google.android.providers.talk/contacts/offline");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577
578 /**
579 * The content:// style URL for operations on bulk contacts
580 */
581 public static final Uri BULK_CONTENT_URI =
Ye Wen9a0bf142009-09-11 11:48:19 -0700582 Uri.parse("content://com.google.android.providers.talk/bulk_contacts");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -0700589 Uri.parse("content://com.google.android.providers.talk/contacts/onlineCount");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590
591 /**
592 * The MIME type of {@link #CONTENT_URI} providing a directory of
593 * people.
594 */
Ye Wen9a0bf142009-09-11 11:48:19 -0700595 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/gtalk-contacts";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596
597 /**
598 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
599 * person.
600 */
Ye Wen9a0bf142009-09-11 11:48:19 -0700601 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/gtalk-contacts";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602
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 {
631 private ContactList() {}
632
633 /**
634 * The content:// style URL for this table
635 */
636 public static final Uri CONTENT_URI =
Ye Wen9a0bf142009-09-11 11:48:19 -0700637 Uri.parse("content://com.google.android.providers.talk/contactLists");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638
639 /**
640 * The MIME type of {@link #CONTENT_URI} providing a directory of
641 * people.
642 */
643 public static final String CONTENT_TYPE =
Ye Wen9a0bf142009-09-11 11:48:19 -0700644 "vnd.android.cursor.dir/gtalk-contactLists";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -0700651 "vnd.android.cursor.item/gtalk-contactLists";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652
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 {
696 private BlockedList() {}
697
698 /**
699 * The content:// style URL for this table
700 */
701 public static final Uri CONTENT_URI =
Ye Wen9a0bf142009-09-11 11:48:19 -0700702 Uri.parse("content://com.google.android.providers.talk/blockedList");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703
704 /**
705 * The MIME type of {@link #CONTENT_URI} providing a directory of
706 * people.
707 */
708 public static final String CONTENT_TYPE =
Ye Wen9a0bf142009-09-11 11:48:19 -0700709 "vnd.android.cursor.dir/gtalk-blockedList";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -0700716 "vnd.android.cursor.item/gtalk-blockedList";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717
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 {
756 private ContactsEtag() {}
757
758 public static final Cursor query(ContentResolver cr,
759 String[] projection) {
760 return cr.query(CONTENT_URI, projection, null, null, null);
761 }
762
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
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
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -0700825 Uri.parse("content://com.google.android.providers.talk/contactsEtag");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826
827 /**
828 * The MIME type of {@link #CONTENT_URI} providing a directory of
829 * people.
830 */
831 public static final String CONTENT_TYPE =
Ye Wen9a0bf142009-09-11 11:48:19 -0700832 "vnd.android.cursor.dir/gtalk-contactsEtag";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -0700839 "vnd.android.cursor.item/gtalk-contactsEtag";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 }
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 /**
Wei Huangb3624b92009-04-27 17:09:32 -0700875 * The common columns for messages table
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800876 */
Wei Huangb3624b92009-04-27 17:09:32 -0700877 public interface MessageColumns {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800878 /**
Wei Huangb3624b92009-04-27 17:09:32 -0700879 * 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.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 */
Wei Huangb3624b92009-04-27 17:09:32 -0700884 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";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891
892 /**
893 * The body
894 * <P>Type: TEXT</P>
895 */
896 String BODY = "body";
897
898 /**
Wei Huangfbb72632009-09-27 10:18:31 -0700899 * The date this message is sent or received. This represents the display date for
900 * the message.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 * <P>Type: INTEGER</P>
902 */
903 String DATE = "date";
904
905 /**
Wei Huangfbb72632009-09-27 10:18:31 -0700906 * 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 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 * 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";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938
939 /**
Wei Huangb3624b92009-04-27 17:09:32 -0700940 * Is groupchat message or not
941 * <P>Type: INTEGER</P>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 */
Wei Huangb3624b92009-04-27 17:09:32 -0700943 String IS_GROUP_CHAT = "is_muc";
Wei Huang1abf4982009-08-21 07:56:36 -0700944
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";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 }
951
952 /**
953 * This table contains messages.
954 */
Wei Huangb3624b92009-04-27 17:09:32 -0700955 public static final class Messages implements BaseColumns, MessageColumns {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 /**
957 * no public constructor since this is a utility class
958 */
959 private Messages() {}
960
961 /**
Wei Huangb3624b92009-04-27 17:09:32 -0700962 * Gets the Uri to query messages by thread id.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 *
Wei Huangb3624b92009-04-27 17:09:32 -0700964 * @param threadId the thread id of the message.
965 * @return the Uri
966 */
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 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 * @param accountId the account id of the contact.
979 * @param username the user name of the contact.
980 * @return the Uri
981 */
Wei Huangb3624b92009-04-27 17:09:32 -0700982 public static final Uri getContentUriByContact(long accountId, String username) {
983 Uri.Builder builder = CONTENT_URI_MESSAGES_BY_ACCOUNT_AND_CONTACT.buildUpon();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 ContentUris.appendId(builder, accountId);
985 builder.appendPath(username);
986 return builder.build();
987 }
988
989 /**
Wei Huangb3624b92009-04-27 17:09:32 -0700990 * Gets the Uri to query messages by provider.
991 *
Wei Huang0ba58de2009-05-18 19:04:17 -0700992 * @param providerId the service provider id.
Wei Huangb3624b92009-04-27 17:09:32 -0700993 * @return the Uri
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 */
Wei Huangb3624b92009-04-27 17:09:32 -0700995 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 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000
1001 /**
Wei Huang0ba58de2009-05-18 19:04:17 -07001002 * Gets the Uri to query off the record messages by account.
Wei Huangb3624b92009-04-27 17:09:32 -07001003 *
Wei Huang0ba58de2009-05-18 19:04:17 -07001004 * @param accountId the account id.
Wei Huangb3624b92009-04-27 17:09:32 -07001005 * @return the Uri
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 */
Wei Huang0ba58de2009-05-18 19:04:17 -07001007 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 */
1019 public static final Uri getOtrMessagesContentUriByThreadId(long threadId) {
1020 Uri.Builder builder = OTR_MESSAGES_CONTENT_URI_BY_THREAD_ID.buildUpon();
Wei Huangb3624b92009-04-27 17:09:32 -07001021 ContentUris.appendId(builder, threadId);
1022 return builder.build();
1023 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001024
1025 /**
Wei Huang0ba58de2009-05-18 19:04:17 -07001026 * @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 */
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 */
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 */
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 /**
Wei Huangb3624b92009-04-27 17:09:32 -07001066 * The content:// style URL for this table
1067 */
Wei Huang0ba58de2009-05-18 19:04:17 -07001068 public static final Uri CONTENT_URI =
Ye Wen9a0bf142009-09-11 11:48:19 -07001069 Uri.parse("content://com.google.android.providers.talk/messages");
Wei Huangb3624b92009-04-27 17:09:32 -07001070
1071 /**
1072 * The content:// style URL for messages by thread id
1073 */
1074 public static final Uri CONTENT_URI_MESSAGES_BY_THREAD_ID =
Ye Wen9a0bf142009-09-11 11:48:19 -07001075 Uri.parse("content://com.google.android.providers.talk/messagesByThreadId");
Wei Huangb3624b92009-04-27 17:09:32 -07001076
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -07001081 Uri.parse("content://com.google.android.providers.talk/messagesByAcctAndContact");
Wei Huangb3624b92009-04-27 17:09:32 -07001082
1083 /**
1084 * The content:// style URL for messages by provider
1085 */
1086 public static final Uri CONTENT_URI_MESSAGES_BY_PROVIDER =
Ye Wen9a0bf142009-09-11 11:48:19 -07001087 Uri.parse("content://com.google.android.providers.talk/messagesByProvider");
Wei Huangb3624b92009-04-27 17:09:32 -07001088
1089 /**
Wei Huang0ba58de2009-05-18 19:04:17 -07001090 * The content:// style URL for messages by account
Wei Huangb3624b92009-04-27 17:09:32 -07001091 */
Wei Huang0ba58de2009-05-18 19:04:17 -07001092 public static final Uri CONTENT_URI_BY_ACCOUNT =
Ye Wen9a0bf142009-09-11 11:48:19 -07001093 Uri.parse("content://com.google.android.providers.talk/messagesByAccount");
Wei Huangb3624b92009-04-27 17:09:32 -07001094
1095 /**
Wei Huang0ba58de2009-05-18 19:04:17 -07001096 * The content:// style url for off the record messages
Wei Huangb3624b92009-04-27 17:09:32 -07001097 */
Wei Huang0ba58de2009-05-18 19:04:17 -07001098 public static final Uri OTR_MESSAGES_CONTENT_URI =
Ye Wen9a0bf142009-09-11 11:48:19 -07001099 Uri.parse("content://com.google.android.providers.talk/otrMessages");
Wei Huangb3624b92009-04-27 17:09:32 -07001100
1101 /**
Wei Huang0ba58de2009-05-18 19:04:17 -07001102 * The content:// style url for off the record messages by thread id
Wei Huangb3624b92009-04-27 17:09:32 -07001103 */
Wei Huang0ba58de2009-05-18 19:04:17 -07001104 public static final Uri OTR_MESSAGES_CONTENT_URI_BY_THREAD_ID =
Ye Wen9a0bf142009-09-11 11:48:19 -07001105 Uri.parse("content://com.google.android.providers.talk/otrMessagesByThreadId");
Wei Huangb3624b92009-04-27 17:09:32 -07001106
1107 /**
Wei Huang0ba58de2009-05-18 19:04:17 -07001108 * The content:// style url for off the record messages by account and contact
Wei Huangb3624b92009-04-27 17:09:32 -07001109 */
Wei Huang0ba58de2009-05-18 19:04:17 -07001110 public static final Uri OTR_MESSAGES_CONTENT_URI_BY_ACCOUNT_AND_CONTACT =
Ye Wen9a0bf142009-09-11 11:48:19 -07001111 Uri.parse("content://com.google.android.providers.talk/otrMessagesByAcctAndContact");
Wei Huang0ba58de2009-05-18 19:04:17 -07001112
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -07001117 Uri.parse("content://com.google.android.providers.talk/otrMessagesByProvider");
Wei Huang0ba58de2009-05-18 19:04:17 -07001118
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -07001123 Uri.parse("content://com.google.android.providers.talk/otrMessagesByAccount");
Wei Huang0ba58de2009-05-18 19:04:17 -07001124
Wei Huangb3624b92009-04-27 17:09:32 -07001125 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 * The MIME type of {@link #CONTENT_URI} providing a directory of
1127 * people.
1128 */
Wei Huang0ba58de2009-05-18 19:04:17 -07001129 public static final String CONTENT_TYPE =
Ye Wen9a0bf142009-09-11 11:48:19 -07001130 "vnd.android.cursor.dir/gtalk-messages";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -07001137 "vnd.android.cursor.item/gtalk-messages";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138
1139 /**
1140 * The default sort order for this table
1141 */
1142 public static final String DEFAULT_SORT_ORDER = "date ASC";
1143
Wei Huangb3624b92009-04-27 17:09:32 -07001144 /**
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";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 }
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 {
1175 private GroupMembers(){}
1176
1177 public static final Uri CONTENT_URI =
Ye Wen9a0bf142009-09-11 11:48:19 -07001178 Uri.parse("content://com.google.android.providers.talk/groupMembers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179
1180 /**
1181 * The MIME type of {@link #CONTENT_URI} providing a directory of
1182 * group members.
1183 */
1184 public static final String CONTENT_TYPE =
Ye Wen9a0bf142009-09-11 11:48:19 -07001185 "vnd.android.cursor.dir/gtalk-groupMembers";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -07001192 "vnd.android.cursor.item/gtalk-groupMembers";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 }
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 {
1251 private Invitation() {
1252 }
1253
1254 /**
1255 * The content:// style URL for this table
1256 */
1257 public static final Uri CONTENT_URI =
Ye Wen9a0bf142009-09-11 11:48:19 -07001258 Uri.parse("content://com.google.android.providers.talk/invitations");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259
1260 /**
1261 * The MIME type of {@link #CONTENT_URI} providing a directory of
1262 * invitations.
1263 */
1264 public static final String CONTENT_TYPE =
Ye Wen9a0bf142009-09-11 11:48:19 -07001265 "vnd.android.cursor.dir/gtalk-invitations";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001266
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -07001272 "vnd.android.cursor.item/gtalk-invitations";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001273 }
1274
1275 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 * 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 */
1309 private Avatars() {}
1310
1311 /**
1312 * The content:// style URL for this table
1313 */
Ye Wen9a0bf142009-09-11 11:48:19 -07001314 public static final Uri CONTENT_URI =
1315 Uri.parse("content://com.google.android.providers.talk/avatars");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316
1317 /**
1318 * The content:// style URL for avatars by provider, account and contact
1319 */
1320 public static final Uri CONTENT_URI_AVATARS_BY =
Ye Wen9a0bf142009-09-11 11:48:19 -07001321 Uri.parse("content://com.google.android.providers.talk/avatarsBy");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001322
1323 /**
1324 * The MIME type of {@link #CONTENT_URI} providing the avatars
1325 */
Ye Wen9a0bf142009-09-11 11:48:19 -07001326 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/gtalk-avatars";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001327
1328 /**
1329 * The MIME type of a {@link #CONTENT_URI}
1330 */
1331 public static final String CONTENT_ITEM_TYPE =
Ye Wen9a0bf142009-09-11 11:48:19 -07001332 "vnd.android.cursor.item/gtalk-avatars";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333
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 */
Ye Wen9a0bf142009-09-11 11:48:19 -07001410 public static final Uri CONTENT_URI =
1411 Uri.parse("content://com.google.android.providers.talk/presence");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001412
1413 /**
Ye Wen9a0bf142009-09-11 11:48:19 -07001414 * The content URL for Talk presences for an account
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001415 */
Ye Wen9a0bf142009-09-11 11:48:19 -07001416 public static final Uri CONTENT_URI_BY_ACCOUNT =
1417 Uri.parse("content://com.google.android.providers.talk/presence/account");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001418
1419 /**
1420 * The content:// style URL for operations on bulk contacts
1421 */
Ye Wen9a0bf142009-09-11 11:48:19 -07001422 public static final Uri BULK_CONTENT_URI =
1423 Uri.parse("content://com.google.android.providers.talk/bulk_presence");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001424
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -07001429 Uri.parse("content://com.google.android.providers.talk/seed_presence/account");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001430
1431 /**
1432 * The MIME type of a {@link #CONTENT_URI} providing a directory of presence
1433 */
Ye Wen9a0bf142009-09-11 11:48:19 -07001434 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/gtalk-presence";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435
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";
Scott Su527f0152009-08-20 22:34:55 +08001484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001485 /**
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 */
1501 private Chats() {}
1502
1503 /**
1504 * The content:// style URL for this table
1505 */
1506 public static final Uri CONTENT_URI =
Ye Wen9a0bf142009-09-11 11:48:19 -07001507 Uri.parse("content://com.google.android.providers.talk/chats");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001508
1509 /**
1510 * The content URL for all chats that belong to the account
1511 */
Ye Wen9a0bf142009-09-11 11:48:19 -07001512 public static final Uri CONTENT_URI_BY_ACCOUNT =
1513 Uri.parse("content://com.google.android.providers.talk/chats/account");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514
1515 /**
1516 * The MIME type of {@link #CONTENT_URI} providing a directory of chats.
1517 */
Ye Wen9a0bf142009-09-11 11:48:19 -07001518 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/gtalk-chats";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519
1520 /**
1521 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single chat.
1522 */
Ye Wen9a0bf142009-09-11 11:48:19 -07001523 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/gtalk-chats";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001524
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 {
1545 private SessionCookies() {
1546 }
1547
1548 /**
1549 * The content:// style URI for this table
1550 */
Ye Wen9a0bf142009-09-11 11:48:19 -07001551 public static final Uri CONTENT_URI =
1552 Uri.parse("content://com.google.android.providers.talk/sessionCookies");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001553
1554 /**
1555 * The content:// style URL for session cookies by provider and account
1556 */
1557 public static final Uri CONTENT_URI_SESSION_COOKIES_BY =
Ye Wen9a0bf142009-09-11 11:48:19 -07001558 Uri.parse("content://com.google.android.providers.talk/sessionCookiesBy");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001559
1560 /**
1561 * The MIME type of {@link #CONTENT_URI} providing a directory of
1562 * people.
1563 */
Ye Wen9a0bf142009-09-11 11:48:19 -07001564 public static final String CONTENT_TYPE = "vnd.android-dir/gtalk-sessionCookies";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001565 }
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 {
1592 private ProviderSettings() {
1593 }
1594
1595 /**
1596 * The content:// style URI for this table
1597 */
1598 public static final Uri CONTENT_URI =
Ye Wen9a0bf142009-09-11 11:48:19 -07001599 Uri.parse("content://com.google.android.providers.talk/providerSettings");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600
1601 /**
1602 * The MIME type of {@link #CONTENT_URI} providing provider settings
1603 */
Ye Wen9a0bf142009-09-11 11:48:19 -07001604 public static final String CONTENT_TYPE = "vnd.android-dir/gtalk-providerSettings";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001605
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
Ye Wen9a0bf142009-09-11 11:48:19 -07001614 /** controls whether or not the GTalk service will be automatically started after boot */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001615 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
Ye Wen9a0bf142009-09-11 11:48:19 -07001620 /** controls whether or not enable the GTalk notification */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 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
Ye Wen8c737f72009-06-09 13:08:03 -07001636 /** 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
Ye Wen47b4a552009-08-04 09:31:56 -07001639 /** 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
Wei Huangc650bf52009-08-14 09:49:01 -07001645 /** specifiy the JID resource used for Google Talk connection */
1646 public static final String SETTING_JID_RESOURCE = "jid_resource";
1647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001648 /**
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 */
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 */
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 */
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
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 */
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 */
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 */
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 */
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 */
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 /**
Ye Wen9a0bf142009-09-11 11:48:19 -07001812 * A convenience method to set whether or not enable the GTalk notification.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001813 *
1814 * @param contentResolver The ContentResolver to use to access the setting table.
Ye Wen9a0bf142009-09-11 11:48:19 -07001815 * @param enable Whether enable the GTalk notification
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001816 */
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 */
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 */
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 */
1850 public static void setShowMobileIndicator(ContentResolver contentResolver, long providerId,
1851 boolean showMobileIndicator) {
1852 putBooleanValue(contentResolver, providerId, SETTING_SHOW_MOBILE_INDICATOR,
1853 showMobileIndicator);
1854 }
1855
Ye Wen8c737f72009-06-09 13:08:03 -07001856 /**
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 */
1862 public static void setShowAwayOnIdle(ContentResolver contentResolver,
1863 long providerId, boolean showAway) {
1864 putBooleanValue(contentResolver, providerId, SETTING_SHOW_AWAY_ON_IDLE, showAway);
1865 }
1866
Ye Wen47b4a552009-08-04 09:31:56 -07001867 /**
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 */
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 */
1884 public static void setHeartbeatInterval(ContentResolver contentResolver,
1885 long providerId, long interval) {
1886 putLongValue(contentResolver, providerId, SETTING_HEARTBEAT_INTERVAL, interval);
1887 }
1888
Wei Huangc650bf52009-08-14 09:49:01 -07001889 /**
1890 * A convenience method to set the jid resource.
1891 */
1892 public static void setJidResource(ContentResolver contentResolver,
1893 long providerId, String jidResource) {
1894 putStringValue(contentResolver, providerId, SETTING_JID_RESOURCE, jidResource);
1895 }
1896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001897 public static class QueryMap extends ContentQueryMap {
1898 private ContentResolver mContentResolver;
1899 private long mProviderId;
1900
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 */
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 */
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 */
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 */
1947 public boolean getHideOfflineContacts() {
1948 return getBoolean(SETTING_HIDE_OFFLINE_CONTACTS,
1949 false/* by default not hide the offline contacts*/);
1950 }
1951
1952 /**
Ye Wen9a0bf142009-09-11 11:48:19 -07001953 * Set whether or not enable the GTalk notification.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001954 *
Ye Wen9a0bf142009-09-11 11:48:19 -07001955 * @param enable Whether or not enable the GTalk notification.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001956 */
1957 public void setEnableNotification(boolean enable) {
1958 ProviderSettings.setEnableNotification(mContentResolver, mProviderId, enable);
1959 }
1960
1961 /**
Ye Wen9a0bf142009-09-11 11:48:19 -07001962 * Check if the GTalk notification is enabled.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001963 *
Ye Wen9a0bf142009-09-11 11:48:19 -07001964 * @return Whether or not enable the GTalk notification.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 */
1966 public boolean getEnableNotification() {
1967 return getBoolean(SETTING_ENABLE_NOTIFICATION,
1968 true/* by default enable the notification */);
1969 }
1970
1971 /**
Ye Wen9a0bf142009-09-11 11:48:19 -07001972 * Set whether or not to vibrate on GTalk notification.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001973 *
1974 * @param vibrate Whether or not to vibrate.
1975 */
1976 public void setVibrate(boolean vibrate) {
1977 ProviderSettings.setVibrate(mContentResolver, mProviderId, vibrate);
1978 }
1979
1980 /**
Ye Wen9a0bf142009-09-11 11:48:19 -07001981 * Gets whether or not to vibrate on GTalk notification.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001982 *
1983 * @return Whether or not to vibrate.
1984 */
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 */
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 */
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 */
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 */
2021 public boolean getShowMobileIndicator() {
2022 return getBoolean(SETTING_SHOW_MOBILE_INDICATOR,
2023 true /* by default show mobile indicator */);
2024 }
2025
2026 /**
Ye Wen8c737f72009-06-09 13:08:03 -07002027 * 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 */
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 */
2040 public boolean getShowAwayOnIdle() {
2041 return getBoolean(SETTING_SHOW_AWAY_ON_IDLE,
2042 true /* by default show as away on idle*/);
2043 }
2044
2045 /**
Ye Wen47b4a552009-08-04 09:31:56 -07002046 * Set whether or not to upload heartbeat stat.
2047 *
2048 * @param uploadStat whether or not to upload heartbeat stat.
2049 */
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 */
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 */
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 */
2078 public long getHeartbeatInterval() {
2079 return getLong(SETTING_HEARTBEAT_INTERVAL, 0L /* an invalid default interval */);
2080 }
2081
2082 /**
Wei Huangc650bf52009-08-14 09:49:01 -07002083 * Set the JID resource.
2084 *
2085 * @param jidResource the jid resource to be stored.
2086 */
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 */
2095 public String getJidResource() {
2096 return getString(SETTING_JID_RESOURCE, null);
2097 }
2098
2099 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002100 * 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 */
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 */
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 */
2133 private int getInteger(String name, int def) {
2134 ContentValues values = getValues(name);
2135 return values != null ? values.getAsInteger(VALUE) : def;
2136 }
Ye Wen47b4a552009-08-04 09:31:56 -07002137
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 */
2146 private long getLong(String name, long def) {
2147 ContentValues values = getValues(name);
2148 return values != null ? values.getAsLong(VALUE) : def;
2149 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002150 }
2151
2152 }
2153
Wei Huang1e4807a2009-07-29 18:50:00 -07002154
2155 /**
Ye Wen9a0bf142009-09-11 11:48:19 -07002156 * 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.
Wei Huang1e4807a2009-07-29 18:50:00 -07002158 */
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 /**
Ye Wen9a0bf142009-09-11 11:48:19 -07002178 * The table for caching the result of loading GTalk branding resources.
Wei Huang1e4807a2009-07-29 18:50:00 -07002179 */
2180 public static final class BrandingResourceMapCache
2181 implements BaseColumns, BrandingResourceMapCacheColumns {
2182 /**
2183 * The content:// style URL for this table.
2184 */
Ye Wen9a0bf142009-09-11 11:48:19 -07002185 public static final Uri CONTENT_URI =
2186 Uri.parse("content://com.google.android.providers.talk/brandingResMapCache");
Wei Huang1e4807a2009-07-29 18:50:00 -07002187 }
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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 /**
2198 * Columns from OutgoingRmq table
2199 */
2200 public interface OutgoingRmqColumns {
2201 String RMQ_ID = "rmq_id";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002202 String TIMESTAMP = "ts";
2203 String DATA = "data";
Wei Huang1e4807a2009-07-29 18:50:00 -07002204 String PROTOBUF_TAG = "type";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002205 }
2206
2207 /**
Wei Huang1e4807a2009-07-29 18:50:00 -07002208 * //TODO: we should really move these to their own provider and database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002209 * 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 */
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 */
Ye Wen9a0bf142009-09-11 11:48:19 -07002248 public static final Uri CONTENT_URI =
2249 Uri.parse("content://com.google.android.providers.talk/outgoingRmqMessages");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250
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 =
Ye Wen9a0bf142009-09-11 11:48:19 -07002255 Uri.parse("content://com.google.android.providers.talk/outgoingHighestRmqId");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002256
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 /**
Wei Huang1e4807a2009-07-29 18:50:00 -07002272 * //TODO: move these out into their own provider and database
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 * 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 */
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 */
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 */
Ye Wen9a0bf142009-09-11 11:48:19 -07002329 public static final Uri CONTENT_URI =
2330 Uri.parse("content://com.google.android.providers.talk/lastRmqId");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002331 }
2332
2333 /**
Wei Huang1e4807a2009-07-29 18:50:00 -07002334 * 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.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002337 */
Wei Huang1e4807a2009-07-29 18:50:00 -07002338 public interface ServerToDeviceRmqIdsColumn {
2339 String RMQ_ID = "rmq_id";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002340 }
2341
Wei Huang1e4807a2009-07-29 18:50:00 -07002342 public static final class ServerToDeviceRmqIds implements BaseColumns,
2343 ServerToDeviceRmqIdsColumn {
2344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002345 /**
2346 * The content:// style URL for this table.
2347 */
Ye Wen9a0bf142009-09-11 11:48:19 -07002348 public static final Uri CONTENT_URI =
2349 Uri.parse("content://com.google.android.providers.talk/s2dids");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002350 }
Wei Huang1e4807a2009-07-29 18:50:00 -07002351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002352}