/**
   * Set outgoing group chat message or file to delivered
   *
   * @param chatId Group chat ID
   * @param contact The contact ID for which the entry is to be updated
   * @param msgId Message ID
   * @param timestampDelivered Time for delivery
   */
  public boolean setGroupChatDeliveryInfoDelivered(
      String chatId, ContactId contact, String msgId, long timestampDelivered) {
    GroupDeliveryInfo.Status status = GroupDeliveryInfo.Status.DELIVERED;
    GroupDeliveryInfo.ReasonCode reason = GroupDeliveryInfo.ReasonCode.UNSPECIFIED;

    ContentValues values = new ContentValues();
    values.put(GroupDeliveryInfoData.KEY_STATUS, status.toInt());
    values.put(GroupDeliveryInfoData.KEY_TIMESTAMP_DELIVERED, timestampDelivered);
    values.put(GroupDeliveryInfoData.KEY_REASON_CODE, reason.toInt());
    String[] selectionArgs = new String[] {msgId, contact.toString()};

    if (mLocalContentResolver.update(
            GroupDeliveryInfoData.CONTENT_URI,
            values,
            SELECTION_DELIVERY_INFO_BY_MSG_ID_AND_CONTACT_EXCLUDE_DISPLAYED,
            selectionArgs)
        > 0) {
      /* A matching GDI row was found and updated. */
      return true;
    }

    Cursor cursor = null;
    try {
      Uri contentUri = GroupDeliveryInfoData.CONTENT_URI;
      cursor =
          mLocalContentResolver.query(
              contentUri,
              PROJECTION_MESSAGE_ID,
              SELECTION_DELIVERY_INFO_BY_MSG_ID_AND_CONTACT,
              selectionArgs,
              null);
      CursorUtil.assertCursorIsNotNull(cursor, contentUri);
      if (cursor.getCount() < 1) {
        /*
         * No entry updated means that there was no matching row. Adding row and setting
         * displayed timestamp to 0.
         */
        addGroupChatDeliveryInfoEntry(
            chatId, contact, msgId, status, reason, timestampDelivered, 0);
        return true;
      }
      /*
       * A matching row was found but since it was not already updated above we can assume it
       * shouldn't be updated.
       */
      return false;
    } finally {
      CursorUtil.close(cursor);
    }
  }
  @Override
  public boolean isDisplayedByAllRecipients(String msgId) {
    Cursor cursor = null;
    try {
      Uri contentUri = Uri.withAppendedPath(GroupDeliveryInfoData.CONTENT_URI, msgId);
      cursor =
          mLocalContentResolver.query(
              contentUri, null, SELECTION_DELIVERY_INFO_NOT_DISPLAYED, null, null);
      CursorUtil.assertCursorIsNotNull(cursor, contentUri);
      return !cursor.moveToFirst();

    } finally {
      CursorUtil.close(cursor);
    }
  }
  @Override
  public boolean isDeliveredToAllRecipients(String msgId) {
    Cursor cursor = null;
    try {
      cursor =
          mLocalContentResolver.query(
              Uri.withAppendedPath(GroupDeliveryInfoData.CONTENT_URI, msgId),
              null,
              SELECTION_CONTACTS_NOT_RECEIVED_MESSAGE,
              null,
              null);
      CursorUtil.assertCursorIsNotNull(cursor, GroupDeliveryInfoData.CONTENT_URI);
      return !cursor.moveToFirst();

    } finally {
      CursorUtil.close(cursor);
    }
  }
示例#4
0
  /** Start address book monitoring */
  public void start() {
    if (sLogger.isActivated()) {
      sLogger.info("Start address book monitoring");
    }
    /* Instantiate background executor */
    mCleanupExecutor = Executors.newSingleThreadExecutor();

    if (!mObserverIsRegistered) {
      /* Instantiate content observer */
      mContactsContractObserver = new ContactsContractObserver(new Handler());

      mContactsContractCursor = mContentResolver.query(Phone.CONTENT_URI, null, null, null, null);
      CursorUtil.assertCursorIsNotNull(mContactsContractCursor, Phone.CONTENT_URI);

      mContactsContractCursor.registerContentObserver(mContactsContractObserver);
      mObserverIsRegistered = true;
    }
  }