The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.provider; |
| 18 | |
| 19 | import android.content.ContentQueryMap; |
| 20 | import android.content.ContentResolver; |
| 21 | import android.content.ContentUris; |
| 22 | import android.content.ContentValues; |
| 23 | import android.database.Cursor; |
| 24 | import android.net.Uri; |
| 25 | import android.os.Handler; |
| 26 | |
| 27 | import java.util.HashMap; |
| 28 | |
| 29 | /** |
| 30 | * The IM provider stores all information about roster contacts, chat messages, presence, etc. |
| 31 | * |
| 32 | * @hide |
| 33 | */ |
| 34 | public class Im { |
| 35 | /** |
| 36 | * no public constructor since this is a utility class |
| 37 | */ |
| 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 Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 874 | * The common columns for messages table |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 875 | */ |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 876 | public interface MessageColumns { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 877 | /** |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 878 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 882 | */ |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 883 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | |
| 929 | /** |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 930 | * Is groupchat message or not |
| 931 | * <P>Type: INTEGER</P> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 932 | */ |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 933 | String IS_GROUP_CHAT = "is_muc"; |
Wei Huang | 1abf498 | 2009-08-21 07:56:36 -0700 | [diff] [blame^] | 934 | |
| 935 | /** |
| 936 | * A hint that the UI should show the sent time of this message |
| 937 | * <P>Type: INTEGER</P> |
| 938 | */ |
| 939 | String DISPLAY_SENT_TIME = "show_ts"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | /** |
| 943 | * This table contains messages. |
| 944 | */ |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 945 | public static final class Messages implements BaseColumns, MessageColumns { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 946 | /** |
| 947 | * no public constructor since this is a utility class |
| 948 | */ |
| 949 | private Messages() {} |
| 950 | |
| 951 | /** |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 952 | * Gets the Uri to query messages by thread id. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | * |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 954 | * @param threadId the thread id of the message. |
| 955 | * @return the Uri |
| 956 | */ |
| 957 | public static final Uri getContentUriByThreadId(long threadId) { |
| 958 | Uri.Builder builder = CONTENT_URI_MESSAGES_BY_THREAD_ID.buildUpon(); |
| 959 | ContentUris.appendId(builder, threadId); |
| 960 | return builder.build(); |
| 961 | } |
| 962 | |
| 963 | /** |
| 964 | * @deprecated |
| 965 | * |
| 966 | * Gets the Uri to query messages by account and contact. |
| 967 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 968 | * @param accountId the account id of the contact. |
| 969 | * @param username the user name of the contact. |
| 970 | * @return the Uri |
| 971 | */ |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 972 | public static final Uri getContentUriByContact(long accountId, String username) { |
| 973 | Uri.Builder builder = CONTENT_URI_MESSAGES_BY_ACCOUNT_AND_CONTACT.buildUpon(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 974 | ContentUris.appendId(builder, accountId); |
| 975 | builder.appendPath(username); |
| 976 | return builder.build(); |
| 977 | } |
| 978 | |
| 979 | /** |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 980 | * Gets the Uri to query messages by provider. |
| 981 | * |
Wei Huang | 0ba58de | 2009-05-18 19:04:17 -0700 | [diff] [blame] | 982 | * @param providerId the service provider id. |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 983 | * @return the Uri |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 984 | */ |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 985 | public static final Uri getContentUriByProvider(long providerId) { |
| 986 | Uri.Builder builder = CONTENT_URI_MESSAGES_BY_PROVIDER.buildUpon(); |
| 987 | ContentUris.appendId(builder, providerId); |
| 988 | return builder.build(); |
| 989 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 990 | |
| 991 | /** |
Wei Huang | 0ba58de | 2009-05-18 19:04:17 -0700 | [diff] [blame] | 992 | * Gets the Uri to query off the record messages by account. |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 993 | * |
Wei Huang | 0ba58de | 2009-05-18 19:04:17 -0700 | [diff] [blame] | 994 | * @param accountId the account id. |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 995 | * @return the Uri |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | */ |
Wei Huang | 0ba58de | 2009-05-18 19:04:17 -0700 | [diff] [blame] | 997 | public static final Uri getContentUriByAccount(long accountId) { |
| 998 | Uri.Builder builder = CONTENT_URI_BY_ACCOUNT.buildUpon(); |
| 999 | ContentUris.appendId(builder, accountId); |
| 1000 | return builder.build(); |
| 1001 | } |
| 1002 | |
| 1003 | /** |
| 1004 | * Gets the Uri to query off the record messages by thread id. |
| 1005 | * |
| 1006 | * @param threadId the thread id of the message. |
| 1007 | * @return the Uri |
| 1008 | */ |
| 1009 | public static final Uri getOtrMessagesContentUriByThreadId(long threadId) { |
| 1010 | Uri.Builder builder = OTR_MESSAGES_CONTENT_URI_BY_THREAD_ID.buildUpon(); |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 1011 | ContentUris.appendId(builder, threadId); |
| 1012 | return builder.build(); |
| 1013 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1014 | |
| 1015 | /** |
Wei Huang | 0ba58de | 2009-05-18 19:04:17 -0700 | [diff] [blame] | 1016 | * @deprecated |
| 1017 | * |
| 1018 | * Gets the Uri to query off the record messages by account and contact. |
| 1019 | * |
| 1020 | * @param accountId the account id of the contact. |
| 1021 | * @param username the user name of the contact. |
| 1022 | * @return the Uri |
| 1023 | */ |
| 1024 | public static final Uri getOtrMessagesContentUriByContact(long accountId, String username) { |
| 1025 | Uri.Builder builder = OTR_MESSAGES_CONTENT_URI_BY_ACCOUNT_AND_CONTACT.buildUpon(); |
| 1026 | ContentUris.appendId(builder, accountId); |
| 1027 | builder.appendPath(username); |
| 1028 | return builder.build(); |
| 1029 | } |
| 1030 | |
| 1031 | /** |
| 1032 | * Gets the Uri to query off the record messages by provider. |
| 1033 | * |
| 1034 | * @param providerId the service provider id. |
| 1035 | * @return the Uri |
| 1036 | */ |
| 1037 | public static final Uri getOtrMessagesContentUriByProvider(long providerId) { |
| 1038 | Uri.Builder builder = OTR_MESSAGES_CONTENT_URI_BY_PROVIDER.buildUpon(); |
| 1039 | ContentUris.appendId(builder, providerId); |
| 1040 | return builder.build(); |
| 1041 | } |
| 1042 | |
| 1043 | /** |
| 1044 | * Gets the Uri to query off the record messages by account. |
| 1045 | * |
| 1046 | * @param accountId the account id. |
| 1047 | * @return the Uri |
| 1048 | */ |
| 1049 | public static final Uri getOtrMessagesContentUriByAccount(long accountId) { |
| 1050 | Uri.Builder builder = OTR_MESSAGES_CONTENT_URI_BY_ACCOUNT.buildUpon(); |
| 1051 | ContentUris.appendId(builder, accountId); |
| 1052 | return builder.build(); |
| 1053 | } |
| 1054 | |
| 1055 | /** |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 1056 | * The content:// style URL for this table |
| 1057 | */ |
Wei Huang | 0ba58de | 2009-05-18 19:04:17 -0700 | [diff] [blame] | 1058 | public static final Uri CONTENT_URI = |
| 1059 | Uri.parse("content://im/messages"); |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 1060 | |
| 1061 | /** |
| 1062 | * The content:// style URL for messages by thread id |
| 1063 | */ |
| 1064 | public static final Uri CONTENT_URI_MESSAGES_BY_THREAD_ID = |
| 1065 | Uri.parse("content://im/messagesByThreadId"); |
| 1066 | |
| 1067 | /** |
| 1068 | * The content:// style URL for messages by account and contact |
| 1069 | */ |
| 1070 | public static final Uri CONTENT_URI_MESSAGES_BY_ACCOUNT_AND_CONTACT = |
| 1071 | Uri.parse("content://im/messagesByAcctAndContact"); |
| 1072 | |
| 1073 | /** |
| 1074 | * The content:// style URL for messages by provider |
| 1075 | */ |
| 1076 | public static final Uri CONTENT_URI_MESSAGES_BY_PROVIDER = |
| 1077 | Uri.parse("content://im/messagesByProvider"); |
| 1078 | |
| 1079 | /** |
Wei Huang | 0ba58de | 2009-05-18 19:04:17 -0700 | [diff] [blame] | 1080 | * The content:// style URL for messages by account |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 1081 | */ |
Wei Huang | 0ba58de | 2009-05-18 19:04:17 -0700 | [diff] [blame] | 1082 | public static final Uri CONTENT_URI_BY_ACCOUNT = |
| 1083 | Uri.parse("content://im/messagesByAccount"); |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 1084 | |
| 1085 | /** |
Wei Huang | 0ba58de | 2009-05-18 19:04:17 -0700 | [diff] [blame] | 1086 | * The content:// style url for off the record messages |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 1087 | */ |
Wei Huang | 0ba58de | 2009-05-18 19:04:17 -0700 | [diff] [blame] | 1088 | public static final Uri OTR_MESSAGES_CONTENT_URI = |
| 1089 | Uri.parse("content://im/otrMessages"); |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 1090 | |
| 1091 | /** |
Wei Huang | 0ba58de | 2009-05-18 19:04:17 -0700 | [diff] [blame] | 1092 | * The content:// style url for off the record messages by thread id |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 1093 | */ |
Wei Huang | 0ba58de | 2009-05-18 19:04:17 -0700 | [diff] [blame] | 1094 | public static final Uri OTR_MESSAGES_CONTENT_URI_BY_THREAD_ID = |
| 1095 | Uri.parse("content://im/otrMessagesByThreadId"); |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 1096 | |
| 1097 | /** |
Wei Huang | 0ba58de | 2009-05-18 19:04:17 -0700 | [diff] [blame] | 1098 | * The content:// style url for off the record messages by account and contact |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 1099 | */ |
Wei Huang | 0ba58de | 2009-05-18 19:04:17 -0700 | [diff] [blame] | 1100 | public static final Uri OTR_MESSAGES_CONTENT_URI_BY_ACCOUNT_AND_CONTACT = |
| 1101 | Uri.parse("content://im/otrMessagesByAcctAndContact"); |
| 1102 | |
| 1103 | /** |
| 1104 | * The content:// style URL for off the record messages by provider |
| 1105 | */ |
| 1106 | public static final Uri OTR_MESSAGES_CONTENT_URI_BY_PROVIDER = |
| 1107 | Uri.parse("content://im/otrMessagesByProvider"); |
| 1108 | |
| 1109 | /** |
| 1110 | * The content:// style URL for off the record messages by account |
| 1111 | */ |
| 1112 | public static final Uri OTR_MESSAGES_CONTENT_URI_BY_ACCOUNT = |
| 1113 | Uri.parse("content://im/otrMessagesByAccount"); |
| 1114 | |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 1115 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | * The MIME type of {@link #CONTENT_URI} providing a directory of |
| 1117 | * people. |
| 1118 | */ |
Wei Huang | 0ba58de | 2009-05-18 19:04:17 -0700 | [diff] [blame] | 1119 | public static final String CONTENT_TYPE = |
| 1120 | "vnd.android.cursor.dir/im-messages"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | |
| 1122 | /** |
| 1123 | * The MIME type of a {@link #CONTENT_URI} subdirectory of a single |
| 1124 | * person. |
| 1125 | */ |
| 1126 | public static final String CONTENT_ITEM_TYPE = |
| 1127 | "vnd.android.cursor.item/im-messages"; |
| 1128 | |
| 1129 | /** |
| 1130 | * The default sort order for this table |
| 1131 | */ |
| 1132 | public static final String DEFAULT_SORT_ORDER = "date ASC"; |
| 1133 | |
Wei Huang | b3624b9 | 2009-04-27 17:09:32 -0700 | [diff] [blame] | 1134 | /** |
| 1135 | * The "contact" column. This is not a real column in the messages table, but a |
| 1136 | * temoprary column created when querying for messages (joined with the contacts table) |
| 1137 | */ |
| 1138 | public static final String CONTACT = "contact"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | /** |
| 1142 | * Columns for the GroupMember table. |
| 1143 | */ |
| 1144 | public interface GroupMemberColumns { |
| 1145 | /** |
| 1146 | * The id of the group this member belongs to. |
| 1147 | * <p>Type: INTEGER</p> |
| 1148 | */ |
| 1149 | String GROUP = "groupId"; |
| 1150 | |
| 1151 | /** |
| 1152 | * The full name of this member. |
| 1153 | * <p>Type: TEXT</p> |
| 1154 | */ |
| 1155 | String USERNAME = "username"; |
| 1156 | |
| 1157 | /** |
| 1158 | * The nick name of this member. |
| 1159 | * <p>Type: TEXT</p> |
| 1160 | */ |
| 1161 | String NICKNAME = "nickname"; |
| 1162 | } |
| 1163 | |
| 1164 | public final static class GroupMembers implements GroupMemberColumns { |
| 1165 | private GroupMembers(){} |
| 1166 | |
| 1167 | public static final Uri CONTENT_URI = |
| 1168 | Uri.parse("content://im/groupMembers"); |
| 1169 | |
| 1170 | /** |
| 1171 | * The MIME type of {@link #CONTENT_URI} providing a directory of |
| 1172 | * group members. |
| 1173 | */ |
| 1174 | public static final String CONTENT_TYPE = |
| 1175 | "vnd.android.cursor.dir/im-groupMembers"; |
| 1176 | |
| 1177 | /** |
| 1178 | * The MIME type of a {@link #CONTENT_URI} subdirectory of a single |
| 1179 | * group member. |
| 1180 | */ |
| 1181 | public static final String CONTENT_ITEM_TYPE = |
| 1182 | "vnd.android.cursor.item/im-groupMembers"; |
| 1183 | } |
| 1184 | |
| 1185 | /** |
| 1186 | * Columns from the Invitation table. |
| 1187 | */ |
| 1188 | public interface InvitationColumns { |
| 1189 | /** |
| 1190 | * The provider id. |
| 1191 | * <p>Type: INTEGER</p> |
| 1192 | */ |
| 1193 | String PROVIDER = "providerId"; |
| 1194 | |
| 1195 | /** |
| 1196 | * The account id. |
| 1197 | * <p>Type: INTEGER</p> |
| 1198 | */ |
| 1199 | String ACCOUNT = "accountId"; |
| 1200 | |
| 1201 | /** |
| 1202 | * The invitation id. |
| 1203 | * <p>Type: TEXT</p> |
| 1204 | */ |
| 1205 | String INVITE_ID = "inviteId"; |
| 1206 | |
| 1207 | /** |
| 1208 | * The name of the sender of the invitation. |
| 1209 | * <p>Type: TEXT</p> |
| 1210 | */ |
| 1211 | String SENDER = "sender"; |
| 1212 | |
| 1213 | /** |
| 1214 | * The name of the group which the sender invite you to join. |
| 1215 | * <p>Type: TEXT</p> |
| 1216 | */ |
| 1217 | String GROUP_NAME = "groupName"; |
| 1218 | |
| 1219 | /** |
| 1220 | * A note |
| 1221 | * <p>Type: TEXT</p> |
| 1222 | */ |
| 1223 | String NOTE = "note"; |
| 1224 | |
| 1225 | /** |
| 1226 | * The current status of the invitation. |
| 1227 | * <p>Type: TEXT</p> |
| 1228 | */ |
| 1229 | String STATUS = "status"; |
| 1230 | |
| 1231 | int STATUS_PENDING = 0; |
| 1232 | int STATUS_ACCEPTED = 1; |
| 1233 | int STATUS_REJECTED = 2; |
| 1234 | } |
| 1235 | |
| 1236 | /** |
| 1237 | * This table contains the invitations received from others. |
| 1238 | */ |
| 1239 | public final static class Invitation implements InvitationColumns, |
| 1240 | BaseColumns { |
| 1241 | private Invitation() { |
| 1242 | } |
| 1243 | |
| 1244 | /** |
| 1245 | * The content:// style URL for this table |
| 1246 | */ |
| 1247 | public static final Uri CONTENT_URI = |
| 1248 | Uri.parse("content://im/invitations"); |
| 1249 | |
| 1250 | /** |
| 1251 | * The MIME type of {@link #CONTENT_URI} providing a directory of |
| 1252 | * invitations. |
| 1253 | */ |
| 1254 | public static final String CONTENT_TYPE = |
| 1255 | "vnd.android.cursor.dir/im-invitations"; |
| 1256 | |
| 1257 | /** |
| 1258 | * The MIME type of a {@link #CONTENT_URI} subdirectory of a single |
| 1259 | * invitation. |
| 1260 | */ |
| 1261 | public static final String CONTENT_ITEM_TYPE = |
| 1262 | "vnd.android.cursor.item/im-invitations"; |
| 1263 | } |
| 1264 | |
| 1265 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | * Columns from the Avatars table |
| 1267 | */ |
| 1268 | public interface AvatarsColumns { |
| 1269 | /** |
| 1270 | * The contact this avatar belongs to |
| 1271 | * <P>Type: TEXT</P> |
| 1272 | */ |
| 1273 | String CONTACT = "contact"; |
| 1274 | |
| 1275 | String PROVIDER = "provider_id"; |
| 1276 | |
| 1277 | String ACCOUNT = "account_id"; |
| 1278 | |
| 1279 | /** |
| 1280 | * The hash of the image data |
| 1281 | * <P>Type: TEXT</P> |
| 1282 | */ |
| 1283 | String HASH = "hash"; |
| 1284 | |
| 1285 | /** |
| 1286 | * raw image data |
| 1287 | * <P>Type: BLOB</P> |
| 1288 | */ |
| 1289 | String DATA = "data"; |
| 1290 | } |
| 1291 | |
| 1292 | /** |
| 1293 | * This table contains avatars. |
| 1294 | */ |
| 1295 | public static final class Avatars implements BaseColumns, AvatarsColumns { |
| 1296 | /** |
| 1297 | * no public constructor since this is a utility class |
| 1298 | */ |
| 1299 | private Avatars() {} |
| 1300 | |
| 1301 | /** |
| 1302 | * The content:// style URL for this table |
| 1303 | */ |
| 1304 | public static final Uri CONTENT_URI = Uri.parse("content://im/avatars"); |
| 1305 | |
| 1306 | /** |
| 1307 | * The content:// style URL for avatars by provider, account and contact |
| 1308 | */ |
| 1309 | public static final Uri CONTENT_URI_AVATARS_BY = |
| 1310 | Uri.parse("content://im/avatarsBy"); |
| 1311 | |
| 1312 | /** |
| 1313 | * The MIME type of {@link #CONTENT_URI} providing the avatars |
| 1314 | */ |
| 1315 | public static final String CONTENT_TYPE = "vnd.android.cursor.dir/im-avatars"; |
| 1316 | |
| 1317 | /** |
| 1318 | * The MIME type of a {@link #CONTENT_URI} |
| 1319 | */ |
| 1320 | public static final String CONTENT_ITEM_TYPE = |
| 1321 | "vnd.android.cursor.item/im-avatars"; |
| 1322 | |
| 1323 | /** |
| 1324 | * The default sort order for this table |
| 1325 | */ |
| 1326 | public static final String DEFAULT_SORT_ORDER = "contact ASC"; |
| 1327 | |
| 1328 | } |
| 1329 | |
| 1330 | /** |
| 1331 | * Common presence columns shared between the IM and contacts presence tables |
| 1332 | */ |
| 1333 | public interface CommonPresenceColumns { |
| 1334 | /** |
| 1335 | * The priority, an integer, used by XMPP presence |
| 1336 | * <P>Type: INTEGER</P> |
| 1337 | */ |
| 1338 | String PRIORITY = "priority"; |
| 1339 | |
| 1340 | /** |
| 1341 | * The server defined status. |
| 1342 | * <P>Type: INTEGER (one of the values below)</P> |
| 1343 | */ |
| 1344 | String PRESENCE_STATUS = "mode"; |
| 1345 | |
| 1346 | /** |
| 1347 | * Presence Status definition |
| 1348 | */ |
| 1349 | int OFFLINE = 0; |
| 1350 | int INVISIBLE = 1; |
| 1351 | int AWAY = 2; |
| 1352 | int IDLE = 3; |
| 1353 | int DO_NOT_DISTURB = 4; |
| 1354 | int AVAILABLE = 5; |
| 1355 | |
| 1356 | /** |
| 1357 | * The user defined status line. |
| 1358 | * <P>Type: TEXT</P> |
| 1359 | */ |
| 1360 | String PRESENCE_CUSTOM_STATUS = "status"; |
| 1361 | } |
| 1362 | |
| 1363 | /** |
| 1364 | * Columns from the Presence table. |
| 1365 | */ |
| 1366 | public interface PresenceColumns extends CommonPresenceColumns { |
| 1367 | /** |
| 1368 | * The contact id |
| 1369 | * <P>Type: INTEGER</P> |
| 1370 | */ |
| 1371 | String CONTACT_ID = "contact_id"; |
| 1372 | |
| 1373 | /** |
| 1374 | * The contact's JID resource, only relevant for XMPP contact |
| 1375 | * <P>Type: TEXT</P> |
| 1376 | */ |
| 1377 | String JID_RESOURCE = "jid_resource"; |
| 1378 | |
| 1379 | /** |
| 1380 | * The contact's client type |
| 1381 | */ |
| 1382 | String CLIENT_TYPE = "client_type"; |
| 1383 | |
| 1384 | /** |
| 1385 | * client type definitions |
| 1386 | */ |
| 1387 | int CLIENT_TYPE_DEFAULT = 0; |
| 1388 | int CLIENT_TYPE_MOBILE = 1; |
| 1389 | int CLIENT_TYPE_ANDROID = 2; |
| 1390 | } |
| 1391 | |
| 1392 | /** |
| 1393 | * Contains presence infomation for contacts. |
| 1394 | */ |
| 1395 | public static final class Presence implements BaseColumns, PresenceColumns { |
| 1396 | /** |
| 1397 | * The content:// style URL for this table |
| 1398 | */ |
| 1399 | public static final Uri CONTENT_URI = Uri.parse("content://im/presence"); |
| 1400 | |
| 1401 | /** |
| 1402 | * The content URL for IM presences for an account |
| 1403 | */ |
| 1404 | public static final Uri CONTENT_URI_BY_ACCOUNT = Uri.parse("content://im/presence/account"); |
| 1405 | |
| 1406 | /** |
| 1407 | * The content:// style URL for operations on bulk contacts |
| 1408 | */ |
| 1409 | public static final Uri BULK_CONTENT_URI = Uri.parse("content://im/bulk_presence"); |
| 1410 | |
| 1411 | /** |
| 1412 | * The content:// style URL for seeding presences for a given account id. |
| 1413 | */ |
| 1414 | public static final Uri SEED_PRESENCE_BY_ACCOUNT_CONTENT_URI = |
| 1415 | Uri.parse("content://im/seed_presence/account"); |
| 1416 | |
| 1417 | /** |
| 1418 | * The MIME type of a {@link #CONTENT_URI} providing a directory of presence |
| 1419 | */ |
| 1420 | public static final String CONTENT_TYPE = "vnd.android.cursor.dir/im-presence"; |
| 1421 | |
| 1422 | /** |
| 1423 | * The default sort order for this table |
| 1424 | */ |
| 1425 | public static final String DEFAULT_SORT_ORDER = "mode DESC"; |
| 1426 | } |
| 1427 | |
| 1428 | /** |
| 1429 | * Columns from the Chats table. |
| 1430 | */ |
| 1431 | public interface ChatsColumns { |
| 1432 | /** |
| 1433 | * The contact ID this chat belongs to. The value is a long. |
| 1434 | * <P>Type: INT</P> |
| 1435 | */ |
| 1436 | String CONTACT_ID = "contact_id"; |
| 1437 | |
| 1438 | /** |
| 1439 | * The GTalk JID resource. The value is a string. |
| 1440 | * <P>Type: TEXT</P> |
| 1441 | */ |
| 1442 | String JID_RESOURCE = "jid_resource"; |
| 1443 | |
| 1444 | /** |
| 1445 | * Whether this is a groupchat or not. |
| 1446 | * <P>Type: INT</P> |
| 1447 | */ |
| 1448 | String GROUP_CHAT = "groupchat"; |
| 1449 | |
| 1450 | /** |
| 1451 | * The last unread message. This both indicates that there is an |
| 1452 | * unread message, and what the message is. |
| 1453 | * <P>Type: TEXT</P> |
| 1454 | */ |
| 1455 | String LAST_UNREAD_MESSAGE = "last_unread_message"; |
| 1456 | |
| 1457 | /** |
| 1458 | * The last message timestamp |
| 1459 | * <P>Type: INT</P> |
| 1460 | */ |
| 1461 | String LAST_MESSAGE_DATE = "last_message_date"; |
| 1462 | |
| 1463 | /** |
| 1464 | * A message that is being composed. This indicates that there was a |
| 1465 | * message being composed when the chat screen was shutdown, and what the |
| 1466 | * message is. |
| 1467 | * <P>Type: TEXT</P> |
| 1468 | */ |
| 1469 | String UNSENT_COMPOSED_MESSAGE = "unsent_composed_message"; |
| 1470 | |
| 1471 | /** |
| 1472 | * A value from 0-9 indicating which quick-switch chat screen slot this |
| 1473 | * chat is occupying. If none (for instance, this is the 12th active chat) |
| 1474 | * then the value is -1. |
| 1475 | * <P>Type: INT</P> |
| 1476 | */ |
| 1477 | String SHORTCUT = "shortcut"; |
| 1478 | } |
| 1479 | |
| 1480 | /** |
| 1481 | * Contains ongoing chat sessions. |
| 1482 | */ |
| 1483 | public static final class Chats implements BaseColumns, ChatsColumns { |
| 1484 | /** |
| 1485 | * no public constructor since this is a utility class |
| 1486 | */ |
| 1487 | private Chats() {} |
| 1488 | |
| 1489 | /** |
| 1490 | * The content:// style URL for this table |
| 1491 | */ |
| 1492 | public static final Uri CONTENT_URI = |
| 1493 | Uri.parse("content://im/chats"); |
| 1494 | |
| 1495 | /** |
| 1496 | * The content URL for all chats that belong to the account |
| 1497 | */ |
| 1498 | public static final Uri CONTENT_URI_BY_ACCOUNT = Uri.parse("content://im/chats/account"); |
| 1499 | |
| 1500 | /** |
| 1501 | * The MIME type of {@link #CONTENT_URI} providing a directory of chats. |
| 1502 | */ |
| 1503 | public static final String CONTENT_TYPE = "vnd.android.cursor.dir/im-chats"; |
| 1504 | |
| 1505 | /** |
| 1506 | * The MIME type of a {@link #CONTENT_URI} subdirectory of a single chat. |
| 1507 | */ |
| 1508 | public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im-chats"; |
| 1509 | |
| 1510 | /** |
| 1511 | * The default sort order for this table |
| 1512 | */ |
| 1513 | public static final String DEFAULT_SORT_ORDER = "last_message_date ASC"; |
| 1514 | } |
| 1515 | |
| 1516 | /** |
| 1517 | * Columns from session cookies table. Used for IMPS. |
| 1518 | */ |
| 1519 | public static interface SessionCookiesColumns { |
| 1520 | String NAME = "name"; |
| 1521 | String VALUE = "value"; |
| 1522 | String PROVIDER = "provider"; |
| 1523 | String ACCOUNT = "account"; |
| 1524 | } |
| 1525 | |
| 1526 | /** |
| 1527 | * Contains IMPS session cookies. |
| 1528 | */ |
| 1529 | public static class SessionCookies implements SessionCookiesColumns, BaseColumns { |
| 1530 | private SessionCookies() { |
| 1531 | } |
| 1532 | |
| 1533 | /** |
| 1534 | * The content:// style URI for this table |
| 1535 | */ |
| 1536 | public static final Uri CONTENT_URI = Uri.parse("content://im/sessionCookies"); |
| 1537 | |
| 1538 | /** |
| 1539 | * The content:// style URL for session cookies by provider and account |
| 1540 | */ |
| 1541 | public static final Uri CONTENT_URI_SESSION_COOKIES_BY = |
| 1542 | Uri.parse("content://im/sessionCookiesBy"); |
| 1543 | |
| 1544 | /** |
| 1545 | * The MIME type of {@link #CONTENT_URI} providing a directory of |
| 1546 | * people. |
| 1547 | */ |
| 1548 | public static final String CONTENT_TYPE = "vnd.android-dir/im-sessionCookies"; |
| 1549 | } |
| 1550 | |
| 1551 | /** |
| 1552 | * Columns from ProviderSettings table |
| 1553 | */ |
| 1554 | public static interface ProviderSettingsColumns { |
| 1555 | /** |
| 1556 | * The id in database of the related provider |
| 1557 | * |
| 1558 | * <P>Type: INT</P> |
| 1559 | */ |
| 1560 | String PROVIDER = "provider"; |
| 1561 | |
| 1562 | /** |
| 1563 | * The name of the setting |
| 1564 | * <P>Type: TEXT</P> |
| 1565 | */ |
| 1566 | String NAME = "name"; |
| 1567 | |
| 1568 | /** |
| 1569 | * The value of the setting |
| 1570 | * <P>Type: TEXT</P> |
| 1571 | */ |
| 1572 | String VALUE = "value"; |
| 1573 | } |
| 1574 | |
| 1575 | public static class ProviderSettings implements ProviderSettingsColumns { |
| 1576 | private ProviderSettings() { |
| 1577 | } |
| 1578 | |
| 1579 | /** |
| 1580 | * The content:// style URI for this table |
| 1581 | */ |
| 1582 | public static final Uri CONTENT_URI = |
| 1583 | Uri.parse("content://im/providerSettings"); |
| 1584 | |
| 1585 | /** |
| 1586 | * The MIME type of {@link #CONTENT_URI} providing provider settings |
| 1587 | */ |
| 1588 | public static final String CONTENT_TYPE = "vnd.android-dir/im-providerSettings"; |
| 1589 | |
| 1590 | /** |
| 1591 | * A boolean value to indicate whether this provider should show the offline contacts |
| 1592 | */ |
| 1593 | public static final String SHOW_OFFLINE_CONTACTS = "show_offline_contacts"; |
| 1594 | |
| 1595 | /** controls whether or not the GTalk service automatically connect to server. */ |
| 1596 | public static final String SETTING_AUTOMATICALLY_CONNECT_GTALK = "gtalk_auto_connect"; |
| 1597 | |
| 1598 | /** controls whether or not the IM service will be automatically started after boot */ |
| 1599 | public static final String SETTING_AUTOMATICALLY_START_SERVICE = "auto_start_service"; |
| 1600 | |
| 1601 | /** controls whether or not the offline contacts will be hided */ |
| 1602 | public static final String SETTING_HIDE_OFFLINE_CONTACTS = "hide_offline_contacts"; |
| 1603 | |
| 1604 | /** controls whether or not enable the IM notification */ |
| 1605 | public static final String SETTING_ENABLE_NOTIFICATION = "enable_notification"; |
| 1606 | |
| 1607 | /** specifies whether or not to vibrate */ |
| 1608 | public static final String SETTING_VIBRATE = "vibrate"; |
| 1609 | |
| 1610 | /** specifies the Uri string of the ringtone */ |
| 1611 | public static final String SETTING_RINGTONE = "ringtone"; |
| 1612 | |
| 1613 | /** specifies the Uri of the default ringtone */ |
| 1614 | public static final String SETTING_RINGTONE_DEFAULT = |
| 1615 | "content://settings/system/notification_sound"; |
| 1616 | |
| 1617 | /** specifies whether or not to show mobile indicator to friends */ |
| 1618 | public static final String SETTING_SHOW_MOBILE_INDICATOR = "mobile_indicator"; |
| 1619 | |
Ye Wen | 8c737f7 | 2009-06-09 13:08:03 -0700 | [diff] [blame] | 1620 | /** specifies whether or not to show as away when device is idle */ |
| 1621 | public static final String SETTING_SHOW_AWAY_ON_IDLE = "show_away_on_idle"; |
| 1622 | |
Ye Wen | 47b4a55 | 2009-08-04 09:31:56 -0700 | [diff] [blame] | 1623 | /** specifies whether or not to upload heartbeat stat upon login */ |
| 1624 | public static final String SETTING_UPLOAD_HEARTBEAT_STAT = "upload_heartbeat_stat"; |
| 1625 | |
| 1626 | /** specifies the last heartbeat interval received from the server */ |
| 1627 | public static final String SETTING_HEARTBEAT_INTERVAL = "heartbeat_interval"; |
| 1628 | |
Wei Huang | c650bf5 | 2009-08-14 09:49:01 -0700 | [diff] [blame] | 1629 | /** specifiy the JID resource used for Google Talk connection */ |
| 1630 | public static final String SETTING_JID_RESOURCE = "jid_resource"; |
| 1631 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1632 | /** |
| 1633 | * Used for reliable message queue (RMQ). This is for storing the last rmq id received |
| 1634 | * from the GTalk server |
| 1635 | */ |
| 1636 | public static final String LAST_RMQ_RECEIVED = "last_rmq_rec"; |
| 1637 | |
| 1638 | /** |
| 1639 | * Query the settings of the provider specified by id |
| 1640 | * |
| 1641 | * @param cr |
| 1642 | * the relative content resolver |
| 1643 | * @param providerId |
| 1644 | * the specified id of provider |
| 1645 | * @return a HashMap which contains all the settings for the specified |
| 1646 | * provider |
| 1647 | */ |
| 1648 | public static HashMap<String, String> queryProviderSettings(ContentResolver cr, |
| 1649 | long providerId) { |
| 1650 | HashMap<String, String> settings = new HashMap<String, String>(); |
| 1651 | |
| 1652 | String[] projection = { NAME, VALUE }; |
| 1653 | Cursor c = cr.query(ContentUris.withAppendedId(CONTENT_URI, providerId), projection, null, null, null); |
| 1654 | if (c == null) { |
| 1655 | return null; |
| 1656 | } |
| 1657 | |
| 1658 | while(c.moveToNext()) { |
| 1659 | settings.put(c.getString(0), c.getString(1)); |
| 1660 | } |
| 1661 | |
| 1662 | c.close(); |
| 1663 | |
| 1664 | return settings; |
| 1665 | } |
| 1666 | |
| 1667 | /** |
| 1668 | * Get the string value of setting which is specified by provider id and the setting name. |
| 1669 | * |
| 1670 | * @param cr The ContentResolver to use to access the settings table. |
| 1671 | * @param providerId The id of the provider. |
| 1672 | * @param settingName The name of the setting. |
| 1673 | * @return The value of the setting if the setting exist, otherwise return null. |
| 1674 | */ |
| 1675 | public static String getStringValue(ContentResolver cr, long providerId, String settingName) { |
| 1676 | String ret = null; |
| 1677 | Cursor c = getSettingValue(cr, providerId, settingName); |
| 1678 | if (c != null) { |
| 1679 | ret = c.getString(0); |
| 1680 | c.close(); |
| 1681 | } |
| 1682 | |
| 1683 | return ret; |
| 1684 | } |
| 1685 | |
| 1686 | /** |
| 1687 | * Get the boolean value of setting which is specified by provider id and the setting name. |
| 1688 | * |
| 1689 | * @param cr The ContentResolver to use to access the settings table. |
| 1690 | * @param providerId The id of the provider. |
| 1691 | * @param settingName The name of the setting. |
| 1692 | * @return The value of the setting if the setting exist, otherwise return false. |
| 1693 | */ |
| 1694 | public static boolean getBooleanValue(ContentResolver cr, long providerId, String settingName) { |
| 1695 | boolean ret = false; |
| 1696 | Cursor c = getSettingValue(cr, providerId, settingName); |
| 1697 | if (c != null) { |
| 1698 | ret = c.getInt(0) != 0; |
| 1699 | c.close(); |
| 1700 | } |
| 1701 | return ret; |
| 1702 | } |
| 1703 | |
| 1704 | private static Cursor getSettingValue(ContentResolver cr, long providerId, String settingName) { |
| 1705 | Cursor c = cr.query(ContentUris.withAppendedId(CONTENT_URI, providerId), new String[]{VALUE}, NAME + "=?", |
| 1706 | new String[]{settingName}, null); |
| 1707 | if (c != null) { |
| 1708 | if (!c.moveToFirst()) { |
| 1709 | c.close(); |
| 1710 | return null; |
| 1711 | } |
| 1712 | } |
| 1713 | return c; |
| 1714 | } |
| 1715 | |
| 1716 | /** |
| 1717 | * Save a long value of setting in the table providerSetting. |
| 1718 | * |
| 1719 | * @param cr The ContentProvider used to access the providerSetting table. |
| 1720 | * @param providerId The id of the provider. |
| 1721 | * @param name The name of the setting. |
| 1722 | * @param value The value of the setting. |
| 1723 | */ |
| 1724 | public static void putLongValue(ContentResolver cr, long providerId, String name, |
| 1725 | long value) { |
| 1726 | ContentValues v = new ContentValues(3); |
| 1727 | v.put(PROVIDER, providerId); |
| 1728 | v.put(NAME, name); |
| 1729 | v.put(VALUE, value); |
| 1730 | |
| 1731 | cr.insert(CONTENT_URI, v); |
| 1732 | } |
| 1733 | |
| 1734 | /** |
| 1735 | * Save a boolean value of setting in the table providerSetting. |
| 1736 | * |
| 1737 | * @param cr The ContentProvider used to access the providerSetting table. |
| 1738 | * @param providerId The id of the provider. |
| 1739 | * @param name The name of the setting. |
| 1740 | * @param value The value of the setting. |
| 1741 | */ |
| 1742 | public static void putBooleanValue(ContentResolver cr, long providerId, String name, |
| 1743 | boolean value) { |
| 1744 | ContentValues v = new ContentValues(3); |
| 1745 | v.put(PROVIDER, providerId); |
| 1746 | v.put(NAME, name); |
| 1747 | v.put(VALUE, Boolean.toString(value)); |
| 1748 | |
| 1749 | cr.insert(CONTENT_URI, v); |
| 1750 | } |
| 1751 | |
| 1752 | /** |
| 1753 | * Save a string value of setting in the table providerSetting. |
| 1754 | * |
| 1755 | * @param cr The ContentProvider used to access the providerSetting table. |
| 1756 | * @param providerId The id of the provider. |
| 1757 | * @param name The name of the setting. |
| 1758 | * @param value The value of the setting. |
| 1759 | */ |
| 1760 | public static void putStringValue(ContentResolver cr, long providerId, String name, |
| 1761 | String value) { |
| 1762 | ContentValues v = new ContentValues(3); |
| 1763 | v.put(PROVIDER, providerId); |
| 1764 | v.put(NAME, name); |
| 1765 | v.put(VALUE, value); |
| 1766 | |
| 1767 | cr.insert(CONTENT_URI, v); |
| 1768 | } |
| 1769 | |
| 1770 | /** |
| 1771 | * A convenience method to set whether or not the GTalk service should be started |
| 1772 | * automatically. |
| 1773 | * |
| 1774 | * @param contentResolver The ContentResolver to use to access the settings table |
| 1775 | * @param autoConnect Whether the GTalk service should be started automatically. |
| 1776 | */ |
| 1777 | public static void setAutomaticallyConnectGTalk(ContentResolver contentResolver, |
| 1778 | long providerId, boolean autoConnect) { |
| 1779 | putBooleanValue(contentResolver, providerId, SETTING_AUTOMATICALLY_CONNECT_GTALK, |
| 1780 | autoConnect); |
| 1781 | } |
| 1782 | |
| 1783 | /** |
| 1784 | * A convenience method to set whether or not the offline contacts should be hided |
| 1785 | * |
| 1786 | * @param contentResolver The ContentResolver to use to access the setting table |
| 1787 | * @param hideOfflineContacts Whether the offline contacts should be hided |
| 1788 | */ |
| 1789 | public static void setHideOfflineContacts(ContentResolver contentResolver, |
| 1790 | long providerId, boolean hideOfflineContacts) { |
| 1791 | putBooleanValue(contentResolver, providerId, SETTING_HIDE_OFFLINE_CONTACTS, |
| 1792 | hideOfflineContacts); |
| 1793 | } |
| 1794 | |
| 1795 | /** |
| 1796 | * A convenience method to set whether or not enable the IM notification. |
| 1797 | * |
| 1798 | * @param contentResolver The ContentResolver to use to access the setting table. |
| 1799 | * @param enable Whether enable the IM notification |
| 1800 | */ |
| 1801 | public static void setEnableNotification(ContentResolver contentResolver, long providerId, |
| 1802 | boolean enable) { |
| 1803 | putBooleanValue(contentResolver, providerId, SETTING_ENABLE_NOTIFICATION, enable); |
| 1804 | } |
| 1805 | |
| 1806 | /** |
| 1807 | * A convenience method to set whether or not to vibrate. |
| 1808 | * |
| 1809 | * @param contentResolver The ContentResolver to use to access the setting table. |
| 1810 | * @param vibrate Whether or not to vibrate |
| 1811 | */ |
| 1812 | public static void setVibrate(ContentResolver contentResolver, long providerId, |
| 1813 | boolean vibrate) { |
| 1814 | putBooleanValue(contentResolver, providerId, SETTING_VIBRATE, vibrate); |
| 1815 | } |
| 1816 | |
| 1817 | /** |
| 1818 | * A convenience method to set the Uri String of the ringtone. |
| 1819 | * |
| 1820 | * @param contentResolver The ContentResolver to use to access the setting table. |
| 1821 | * @param ringtoneUri The Uri String of the ringtone to be set. |
| 1822 | */ |
| 1823 | public static void setRingtoneURI(ContentResolver contentResolver, long providerId, |
| 1824 | String ringtoneUri) { |
| 1825 | putStringValue(contentResolver, providerId, SETTING_RINGTONE, ringtoneUri); |
| 1826 | } |
| 1827 | |
| 1828 | /** |
| 1829 | * A convenience method to set whether or not to show mobile indicator. |
| 1830 | * |
| 1831 | * @param contentResolver The ContentResolver to use to access the setting table. |
| 1832 | * @param showMobileIndicator Whether or not to show mobile indicator. |
| 1833 | */ |
| 1834 | public static void setShowMobileIndicator(ContentResolver contentResolver, long providerId, |
| 1835 | boolean showMobileIndicator) { |
| 1836 | putBooleanValue(contentResolver, providerId, SETTING_SHOW_MOBILE_INDICATOR, |
| 1837 | showMobileIndicator); |
| 1838 | } |
| 1839 | |
Ye Wen | 8c737f7 | 2009-06-09 13:08:03 -0700 | [diff] [blame] | 1840 | /** |
| 1841 | * A convenience method to set whether or not to show as away when device is idle. |
| 1842 | * |
| 1843 | * @param contentResolver The ContentResolver to use to access the setting table. |
| 1844 | * @param showAway Whether or not to show as away when device is idle. |
| 1845 | */ |
| 1846 | public static void setShowAwayOnIdle(ContentResolver contentResolver, |
| 1847 | long providerId, boolean showAway) { |
| 1848 | putBooleanValue(contentResolver, providerId, SETTING_SHOW_AWAY_ON_IDLE, showAway); |
| 1849 | } |
| 1850 | |
Ye Wen | 47b4a55 | 2009-08-04 09:31:56 -0700 | [diff] [blame] | 1851 | /** |
| 1852 | * A convenience method to set whether or not to upload heartbeat stat. |
| 1853 | * |
| 1854 | * @param contentResolver The ContentResolver to use to access the setting table. |
| 1855 | * @param uploadStat Whether or not to upload heartbeat stat. |
| 1856 | */ |
| 1857 | public static void setUploadHeartbeatStat(ContentResolver contentResolver, |
| 1858 | long providerId, boolean uploadStat) { |
| 1859 | putBooleanValue(contentResolver, providerId, SETTING_UPLOAD_HEARTBEAT_STAT, uploadStat); |
| 1860 | } |
| 1861 | |
| 1862 | /** |
| 1863 | * A convenience method to set the heartbeat interval last received from the server. |
| 1864 | * |
| 1865 | * @param contentResolver The ContentResolver to use to access the setting table. |
| 1866 | * @param interval The heartbeat interval last received from the server. |
| 1867 | */ |
| 1868 | public static void setHeartbeatInterval(ContentResolver contentResolver, |
| 1869 | long providerId, long interval) { |
| 1870 | putLongValue(contentResolver, providerId, SETTING_HEARTBEAT_INTERVAL, interval); |
| 1871 | } |
| 1872 | |
Wei Huang | c650bf5 | 2009-08-14 09:49:01 -0700 | [diff] [blame] | 1873 | /** |
| 1874 | * A convenience method to set the jid resource. |
| 1875 | */ |
| 1876 | public static void setJidResource(ContentResolver contentResolver, |
| 1877 | long providerId, String jidResource) { |
| 1878 | putStringValue(contentResolver, providerId, SETTING_JID_RESOURCE, jidResource); |
| 1879 | } |
| 1880 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1881 | public static class QueryMap extends ContentQueryMap { |
| 1882 | private ContentResolver mContentResolver; |
| 1883 | private long mProviderId; |
| 1884 | |
| 1885 | public QueryMap(ContentResolver contentResolver, long providerId, boolean keepUpdated, |
| 1886 | Handler handlerForUpdateNotifications) { |
| 1887 | super(contentResolver.query(CONTENT_URI, |
| 1888 | new String[] {NAME,VALUE}, |
| 1889 | PROVIDER + "=" + providerId, |
| 1890 | null, // no selection args |
| 1891 | null), // no sort order |
| 1892 | NAME, keepUpdated, handlerForUpdateNotifications); |
| 1893 | mContentResolver = contentResolver; |
| 1894 | mProviderId = providerId; |
| 1895 | } |
| 1896 | |
| 1897 | /** |
| 1898 | * Set if the GTalk service should automatically connect to server. |
| 1899 | * |
| 1900 | * @param autoConnect if the GTalk service should auto connect to server. |
| 1901 | */ |
| 1902 | public void setAutomaticallyConnectToGTalkServer(boolean autoConnect) { |
| 1903 | ProviderSettings.setAutomaticallyConnectGTalk(mContentResolver, mProviderId, |
| 1904 | autoConnect); |
| 1905 | } |
| 1906 | |
| 1907 | /** |
| 1908 | * Check if the GTalk service should automatically connect to server. |
| 1909 | * @return if the GTalk service should automatically connect to server. |
| 1910 | */ |
| 1911 | public boolean getAutomaticallyConnectToGTalkServer() { |
| 1912 | return getBoolean(SETTING_AUTOMATICALLY_CONNECT_GTALK, |
| 1913 | true /* default to automatically sign in */); |
| 1914 | } |
| 1915 | |
| 1916 | /** |
| 1917 | * Set whether or not the offline contacts should be hided. |
| 1918 | * |
| 1919 | * @param hideOfflineContacts Whether or not the offline contacts should be hided. |
| 1920 | */ |
| 1921 | public void setHideOfflineContacts(boolean hideOfflineContacts) { |
| 1922 | ProviderSettings.setHideOfflineContacts(mContentResolver, mProviderId, |
| 1923 | hideOfflineContacts); |
| 1924 | } |
| 1925 | |
| 1926 | /** |
| 1927 | * Check if the offline contacts should be hided. |
| 1928 | * |
| 1929 | * @return Whether or not the offline contacts should be hided. |
| 1930 | */ |
| 1931 | public boolean getHideOfflineContacts() { |
| 1932 | return getBoolean(SETTING_HIDE_OFFLINE_CONTACTS, |
| 1933 | false/* by default not hide the offline contacts*/); |
| 1934 | } |
| 1935 | |
| 1936 | /** |
| 1937 | * Set whether or not enable the IM notification. |
| 1938 | * |
| 1939 | * @param enable Whether or not enable the IM notification. |
| 1940 | */ |
| 1941 | public void setEnableNotification(boolean enable) { |
| 1942 | ProviderSettings.setEnableNotification(mContentResolver, mProviderId, enable); |
| 1943 | } |
| 1944 | |
| 1945 | /** |
| 1946 | * Check if the IM notification is enabled. |
| 1947 | * |
| 1948 | * @return Whether or not enable the IM notification. |
| 1949 | */ |
| 1950 | public boolean getEnableNotification() { |
| 1951 | return getBoolean(SETTING_ENABLE_NOTIFICATION, |
| 1952 | true/* by default enable the notification */); |
| 1953 | } |
| 1954 | |
| 1955 | /** |
| 1956 | * Set whether or not to vibrate on IM notification. |
| 1957 | * |
| 1958 | * @param vibrate Whether or not to vibrate. |
| 1959 | */ |
| 1960 | public void setVibrate(boolean vibrate) { |
| 1961 | ProviderSettings.setVibrate(mContentResolver, mProviderId, vibrate); |
| 1962 | } |
| 1963 | |
| 1964 | /** |
| 1965 | * Gets whether or not to vibrate on IM notification. |
| 1966 | * |
| 1967 | * @return Whether or not to vibrate. |
| 1968 | */ |
| 1969 | public boolean getVibrate() { |
| 1970 | return getBoolean(SETTING_VIBRATE, false /* by default disable vibrate */); |
| 1971 | } |
| 1972 | |
| 1973 | /** |
| 1974 | * Set the Uri for the ringtone. |
| 1975 | * |
| 1976 | * @param ringtoneUri The Uri of the ringtone to be set. |
| 1977 | */ |
| 1978 | public void setRingtoneURI(String ringtoneUri) { |
| 1979 | ProviderSettings.setRingtoneURI(mContentResolver, mProviderId, ringtoneUri); |
| 1980 | } |
| 1981 | |
| 1982 | /** |
| 1983 | * Get the Uri String of the current ringtone. |
| 1984 | * |
| 1985 | * @return The Uri String of the current ringtone. |
| 1986 | */ |
| 1987 | public String getRingtoneURI() { |
| 1988 | return getString(SETTING_RINGTONE, SETTING_RINGTONE_DEFAULT); |
| 1989 | } |
| 1990 | |
| 1991 | /** |
| 1992 | * Set whether or not to show mobile indicator to friends. |
| 1993 | * |
| 1994 | * @param showMobile whether or not to show mobile indicator. |
| 1995 | */ |
| 1996 | public void setShowMobileIndicator(boolean showMobile) { |
| 1997 | ProviderSettings.setShowMobileIndicator(mContentResolver, mProviderId, showMobile); |
| 1998 | } |
| 1999 | |
| 2000 | /** |
| 2001 | * Gets whether or not to show mobile indicator. |
| 2002 | * |
| 2003 | * @return Whether or not to show mobile indicator. |
| 2004 | */ |
| 2005 | public boolean getShowMobileIndicator() { |
| 2006 | return getBoolean(SETTING_SHOW_MOBILE_INDICATOR, |
| 2007 | true /* by default show mobile indicator */); |
| 2008 | } |
| 2009 | |
| 2010 | /** |
Ye Wen | 8c737f7 | 2009-06-09 13:08:03 -0700 | [diff] [blame] | 2011 | * Set whether or not to show as away when device is idle. |
| 2012 | * |
| 2013 | * @param showAway whether or not to show as away when device is idle. |
| 2014 | */ |
| 2015 | public void setShowAwayOnIdle(boolean showAway) { |
| 2016 | ProviderSettings.setShowAwayOnIdle(mContentResolver, mProviderId, showAway); |
| 2017 | } |
| 2018 | |
| 2019 | /** |
| 2020 | * Get whether or not to show as away when device is idle. |
| 2021 | * |
| 2022 | * @return Whether or not to show as away when device is idle. |
| 2023 | */ |
| 2024 | public boolean getShowAwayOnIdle() { |
| 2025 | return getBoolean(SETTING_SHOW_AWAY_ON_IDLE, |
| 2026 | true /* by default show as away on idle*/); |
| 2027 | } |
| 2028 | |
| 2029 | /** |
Ye Wen | 47b4a55 | 2009-08-04 09:31:56 -0700 | [diff] [blame] | 2030 | * Set whether or not to upload heartbeat stat. |
| 2031 | * |
| 2032 | * @param uploadStat whether or not to upload heartbeat stat. |
| 2033 | */ |
| 2034 | public void setUploadHeartbeatStat(boolean uploadStat) { |
| 2035 | ProviderSettings.setUploadHeartbeatStat(mContentResolver, mProviderId, uploadStat); |
| 2036 | } |
| 2037 | |
| 2038 | /** |
| 2039 | * Get whether or not to upload heartbeat stat. |
| 2040 | * |
| 2041 | * @return Whether or not to upload heartbeat stat. |
| 2042 | */ |
| 2043 | public boolean getUploadHeartbeatStat() { |
| 2044 | return getBoolean(SETTING_UPLOAD_HEARTBEAT_STAT, |
| 2045 | false /* by default do not upload */); |
| 2046 | } |
| 2047 | |
| 2048 | /** |
| 2049 | * Set the last received heartbeat interval from the server. |
| 2050 | * |
| 2051 | * @param interval the last received heartbeat interval from the server. |
| 2052 | */ |
| 2053 | public void setHeartbeatInterval(long interval) { |
| 2054 | ProviderSettings.setHeartbeatInterval(mContentResolver, mProviderId, interval); |
| 2055 | } |
| 2056 | |
| 2057 | /** |
| 2058 | * Get the last received heartbeat interval from the server. |
| 2059 | * |
| 2060 | * @return the last received heartbeat interval from the server. |
| 2061 | */ |
| 2062 | public long getHeartbeatInterval() { |
| 2063 | return getLong(SETTING_HEARTBEAT_INTERVAL, 0L /* an invalid default interval */); |
| 2064 | } |
| 2065 | |
| 2066 | /** |
Wei Huang | c650bf5 | 2009-08-14 09:49:01 -0700 | [diff] [blame] | 2067 | * Set the JID resource. |
| 2068 | * |
| 2069 | * @param jidResource the jid resource to be stored. |
| 2070 | */ |
| 2071 | public void setJidResource(String jidResource) { |
| 2072 | ProviderSettings.setJidResource(mContentResolver, mProviderId, jidResource); |
| 2073 | } |
| 2074 | /** |
| 2075 | * Get the JID resource used for the Google Talk connection |
| 2076 | * |
| 2077 | * @return the JID resource stored. |
| 2078 | */ |
| 2079 | public String getJidResource() { |
| 2080 | return getString(SETTING_JID_RESOURCE, null); |
| 2081 | } |
| 2082 | |
| 2083 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2084 | * Convenience function for retrieving a single settings value |
| 2085 | * as a boolean. |
| 2086 | * |
| 2087 | * @param name The name of the setting to retrieve. |
| 2088 | * @param def Value to return if the setting is not defined. |
| 2089 | * @return The setting's current value, or 'def' if it is not defined. |
| 2090 | */ |
| 2091 | private boolean getBoolean(String name, boolean def) { |
| 2092 | ContentValues values = getValues(name); |
| 2093 | return values != null ? values.getAsBoolean(VALUE) : def; |
| 2094 | } |
| 2095 | |
| 2096 | /** |
| 2097 | * Convenience function for retrieving a single settings value |
| 2098 | * as a String. |
| 2099 | * |
| 2100 | * @param name The name of the setting to retrieve. |
| 2101 | * @param def The value to return if the setting is not defined. |
| 2102 | * @return The setting's current value or 'def' if it is not defined. |
| 2103 | */ |
| 2104 | private String getString(String name, String def) { |
| 2105 | ContentValues values = getValues(name); |
| 2106 | return values != null ? values.getAsString(VALUE) : def; |
| 2107 | } |
| 2108 | |
| 2109 | /** |
| 2110 | * Convenience function for retrieving a single settings value |
| 2111 | * as an Integer. |
| 2112 | * |
| 2113 | * @param name The name of the setting to retrieve. |
| 2114 | * @param def The value to return if the setting is not defined. |
| 2115 | * @return The setting's current value or 'def' if it is not defined. |
| 2116 | */ |
| 2117 | private int getInteger(String name, int def) { |
| 2118 | ContentValues values = getValues(name); |
| 2119 | return values != null ? values.getAsInteger(VALUE) : def; |
| 2120 | } |
Ye Wen | 47b4a55 | 2009-08-04 09:31:56 -0700 | [diff] [blame] | 2121 | |
| 2122 | /** |
| 2123 | * Convenience function for retrieving a single settings value |
| 2124 | * as a Long. |
| 2125 | * |
| 2126 | * @param name The name of the setting to retrieve. |
| 2127 | * @param def The value to return if the setting is not defined. |
| 2128 | * @return The setting's current value or 'def' if it is not defined. |
| 2129 | */ |
| 2130 | private long getLong(String name, long def) { |
| 2131 | ContentValues values = getValues(name); |
| 2132 | return values != null ? values.getAsLong(VALUE) : def; |
| 2133 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | } |
| 2137 | |
Wei Huang | 1e4807a | 2009-07-29 18:50:00 -0700 | [diff] [blame] | 2138 | |
| 2139 | /** |
| 2140 | * Columns for IM branding resource map cache table. This table caches the result of |
| 2141 | * loading the branding resources to speed up IM landing page start. |
| 2142 | */ |
| 2143 | public interface BrandingResourceMapCacheColumns { |
| 2144 | /** |
| 2145 | * The provider ID |
| 2146 | * <P>Type: INTEGER</P> |
| 2147 | */ |
| 2148 | String PROVIDER_ID = "provider_id"; |
| 2149 | /** |
| 2150 | * The application resource ID |
| 2151 | * <P>Type: INTEGER</P> |
| 2152 | */ |
| 2153 | String APP_RES_ID = "app_res_id"; |
| 2154 | /** |
| 2155 | * The plugin resource ID |
| 2156 | * <P>Type: INTEGER</P> |
| 2157 | */ |
| 2158 | String PLUGIN_RES_ID = "plugin_res_id"; |
| 2159 | } |
| 2160 | |
| 2161 | /** |
| 2162 | * The table for caching the result of loading IM branding resources. |
| 2163 | */ |
| 2164 | public static final class BrandingResourceMapCache |
| 2165 | implements BaseColumns, BrandingResourceMapCacheColumns { |
| 2166 | /** |
| 2167 | * The content:// style URL for this table. |
| 2168 | */ |
| 2169 | public static final Uri CONTENT_URI = Uri.parse("content://im/brandingResMapCache"); |
| 2170 | } |
| 2171 | |
| 2172 | |
| 2173 | |
| 2174 | /** |
| 2175 | * //TODO: move these to MCS specific provider. |
| 2176 | * The following are MCS stuff, and should really live in a separate provider specific to |
| 2177 | * MCS code. |
| 2178 | */ |
| 2179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2180 | /** |
| 2181 | * Columns from OutgoingRmq table |
| 2182 | */ |
| 2183 | public interface OutgoingRmqColumns { |
| 2184 | String RMQ_ID = "rmq_id"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2185 | String TIMESTAMP = "ts"; |
| 2186 | String DATA = "data"; |
Wei Huang | 1e4807a | 2009-07-29 18:50:00 -0700 | [diff] [blame] | 2187 | String PROTOBUF_TAG = "type"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | /** |
Wei Huang | 1e4807a | 2009-07-29 18:50:00 -0700 | [diff] [blame] | 2191 | * //TODO: we should really move these to their own provider and database. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2192 | * The table for storing outgoing rmq packets. |
| 2193 | */ |
| 2194 | public static final class OutgoingRmq implements BaseColumns, OutgoingRmqColumns { |
| 2195 | private static String[] RMQ_ID_PROJECTION = new String[] { |
| 2196 | RMQ_ID, |
| 2197 | }; |
| 2198 | |
| 2199 | /** |
| 2200 | * queryHighestRmqId |
| 2201 | * |
| 2202 | * @param resolver the content resolver |
| 2203 | * @return the highest rmq id assigned to the rmq packet, or 0 if there are no rmq packets |
| 2204 | * in the OutgoingRmq table. |
| 2205 | */ |
| 2206 | public static final long queryHighestRmqId(ContentResolver resolver) { |
| 2207 | Cursor cursor = resolver.query(Im.OutgoingRmq.CONTENT_URI_FOR_HIGHEST_RMQ_ID, |
| 2208 | RMQ_ID_PROJECTION, |
| 2209 | null, // selection |
| 2210 | null, // selection args |
| 2211 | null // sort |
| 2212 | ); |
| 2213 | |
| 2214 | long retVal = 0; |
| 2215 | try { |
| 2216 | //if (DBG) log("initializeRmqid: cursor.count= " + cursor.count()); |
| 2217 | |
| 2218 | if (cursor.moveToFirst()) { |
| 2219 | retVal = cursor.getLong(cursor.getColumnIndexOrThrow(RMQ_ID)); |
| 2220 | } |
| 2221 | } finally { |
| 2222 | cursor.close(); |
| 2223 | } |
| 2224 | |
| 2225 | return retVal; |
| 2226 | } |
| 2227 | |
| 2228 | /** |
| 2229 | * The content:// style URL for this table. |
| 2230 | */ |
| 2231 | public static final Uri CONTENT_URI = Uri.parse("content://im/outgoingRmqMessages"); |
| 2232 | |
| 2233 | /** |
| 2234 | * The content:// style URL for the highest rmq id for the outgoing rmq messages |
| 2235 | */ |
| 2236 | public static final Uri CONTENT_URI_FOR_HIGHEST_RMQ_ID = |
| 2237 | Uri.parse("content://im/outgoingHighestRmqId"); |
| 2238 | |
| 2239 | /** |
| 2240 | * The default sort order for this table. |
| 2241 | */ |
| 2242 | public static final String DEFAULT_SORT_ORDER = "rmq_id ASC"; |
| 2243 | } |
| 2244 | |
| 2245 | /** |
| 2246 | * Columns for the LastRmqId table, which stores a single row for the last client rmq id |
| 2247 | * sent to the server. |
| 2248 | */ |
| 2249 | public interface LastRmqIdColumns { |
| 2250 | String RMQ_ID = "rmq_id"; |
| 2251 | } |
| 2252 | |
| 2253 | /** |
Wei Huang | 1e4807a | 2009-07-29 18:50:00 -0700 | [diff] [blame] | 2254 | * //TODO: move these out into their own provider and database |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2255 | * The table for storing the last client rmq id sent to the server. |
| 2256 | */ |
| 2257 | public static final class LastRmqId implements BaseColumns, LastRmqIdColumns { |
| 2258 | private static String[] PROJECTION = new String[] { |
| 2259 | RMQ_ID, |
| 2260 | }; |
| 2261 | |
| 2262 | /** |
| 2263 | * queryLastRmqId |
| 2264 | * |
| 2265 | * queries the last rmq id saved in the LastRmqId table. |
| 2266 | * |
| 2267 | * @param resolver the content resolver. |
| 2268 | * @return the last rmq id stored in the LastRmqId table, or 0 if not found. |
| 2269 | */ |
| 2270 | public static final long queryLastRmqId(ContentResolver resolver) { |
| 2271 | Cursor cursor = resolver.query(Im.LastRmqId.CONTENT_URI, |
| 2272 | PROJECTION, |
| 2273 | null, // selection |
| 2274 | null, // selection args |
| 2275 | null // sort |
| 2276 | ); |
| 2277 | |
| 2278 | long retVal = 0; |
| 2279 | try { |
| 2280 | if (cursor.moveToFirst()) { |
| 2281 | retVal = cursor.getLong(cursor.getColumnIndexOrThrow(RMQ_ID)); |
| 2282 | } |
| 2283 | } finally { |
| 2284 | cursor.close(); |
| 2285 | } |
| 2286 | |
| 2287 | return retVal; |
| 2288 | } |
| 2289 | |
| 2290 | /** |
| 2291 | * saveLastRmqId |
| 2292 | * |
| 2293 | * saves the rmqId to the lastRmqId table. This will override the existing row if any, |
| 2294 | * as we only keep one row of data in this table. |
| 2295 | * |
| 2296 | * @param resolver the content resolver. |
| 2297 | * @param rmqId the rmq id to be saved. |
| 2298 | */ |
| 2299 | public static final void saveLastRmqId(ContentResolver resolver, long rmqId) { |
| 2300 | ContentValues values = new ContentValues(); |
| 2301 | |
| 2302 | // always replace the first row. |
| 2303 | values.put(_ID, 1); |
| 2304 | values.put(RMQ_ID, rmqId); |
| 2305 | resolver.insert(CONTENT_URI, values); |
| 2306 | } |
| 2307 | |
| 2308 | /** |
| 2309 | * The content:// style URL for this table. |
| 2310 | */ |
| 2311 | public static final Uri CONTENT_URI = Uri.parse("content://im/lastRmqId"); |
| 2312 | } |
| 2313 | |
| 2314 | /** |
Wei Huang | 1e4807a | 2009-07-29 18:50:00 -0700 | [diff] [blame] | 2315 | * Columns for the s2dRmqIds table, which stores the server-to-device message |
| 2316 | * persistent ids. These are used in the RMQ2 protocol, where in the login request, the |
| 2317 | * client selective acks these s2d ids to the server. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2318 | */ |
Wei Huang | 1e4807a | 2009-07-29 18:50:00 -0700 | [diff] [blame] | 2319 | public interface ServerToDeviceRmqIdsColumn { |
| 2320 | String RMQ_ID = "rmq_id"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2321 | } |
| 2322 | |
Wei Huang | 1e4807a | 2009-07-29 18:50:00 -0700 | [diff] [blame] | 2323 | public static final class ServerToDeviceRmqIds implements BaseColumns, |
| 2324 | ServerToDeviceRmqIdsColumn { |
| 2325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2326 | /** |
| 2327 | * The content:// style URL for this table. |
| 2328 | */ |
Wei Huang | 1e4807a | 2009-07-29 18:50:00 -0700 | [diff] [blame] | 2329 | public static final Uri CONTENT_URI = Uri.parse("content://im/s2dids"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2330 | } |
Wei Huang | 1e4807a | 2009-07-29 18:50:00 -0700 | [diff] [blame] | 2331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2332 | } |