Java 类android.provider.Telephony.Mms.Inbox 实例源码

项目:NoticeDog    文件:MmsMonitor.java   
@TargetApi(19)
void onConversationDatabaseChanged() {
    Cursor cursor = this.context.getContentResolver().query(Inbox.CONTENT_URI, null, null, null, MMS_SORT_ORDER);
    long messageId = -1;
    if (cursor.moveToFirst()) {
        messageId = cursor.getLong(cursor.getColumnIndex("_id"));
    }
    cursor.close();
    if (messageId != -1 && messageId > this.lastMessageId) {
        Log.d(TAG, "Adding messageId = " + messageId + " to the pending list");
        long pendingId = messageId;
        if (!this.pendingMessages.contains(Long.valueOf(pendingId))) {
            addPendingMessage(pendingId);
        }
    }
    this.lastMessageId = messageId;
    flushPendingMessages();
}
项目:sms_DualCard    文件:NotificationTransaction.java   
/**
 * This constructor is only used for test purposes.
 */
public NotificationTransaction(
        Context context, int serviceId,
        TransactionSettings connectionSettings, NotificationInd ind) {
    super(context, serviceId, connectionSettings);

    try {
        mUri = PduPersister.getPduPersister(context).persist(
                    ind, Inbox.CONTENT_URI);
    } catch (MmsException e) {
        Log.e(TAG, "Failed to save NotificationInd in constructor.", e);
        throw new IllegalArgumentException();
    }

    mNotificationInd = ind;
    mId = new String(ind.getTransactionId());
}
项目:android-aosp-mms    文件:NotificationTransaction.java   
/**
 * This constructor is only used for test purposes.
 */
public NotificationTransaction(
        Context context, int serviceId,
        TransactionSettings connectionSettings, NotificationInd ind) {
    super(context, serviceId, connectionSettings);

    try {
        // Save the pdu. If we can start downloading the real pdu immediately, don't allow
        // persist() to create a thread for the notificationInd because it causes UI jank.
        mUri = PduPersister.getPduPersister(context).persist(
                    ind, Inbox.CONTENT_URI, !allowAutoDownload(),
                    MessagingPreferenceActivity.getIsGroupMmsEnabled(context), null);
    } catch (MmsException e) {
        Log.e(TAG, "Failed to save NotificationInd in constructor.", e);
        throw new IllegalArgumentException();
    }

    mNotificationInd = ind;
    mId = new String(mNotificationInd.getContentLocation());
}
项目:NoticeDog    文件:MmsMonitor.java   
@TargetApi(19)
void loadLastMessageId() {
    Cursor cursor = this.context.getContentResolver().query(Inbox.CONTENT_URI, null, null, null, MMS_SORT_ORDER);
    if (cursor.moveToFirst()) {
        this.lastMessageId = cursor.getLong(cursor.getColumnIndex("_id"));
    }
    cursor.close();
}
项目:sms_DualCard    文件:RetrieveTransaction.java   
public void run() {
    try {
        // Change the downloading state of the M-Notification.ind.
        DownloadManager.getInstance().markState(
                mUri, DownloadManager.STATE_DOWNLOADING);

        // Send GET request to MMSC and retrieve the response data.
        byte[] resp = getPdu(mContentLocation);

        // Parse M-Retrieve.conf
        RetrieveConf retrieveConf = (RetrieveConf) new PduParser(resp).parse();
        if (null == retrieveConf) {
            throw new MmsException("Invalid M-Retrieve.conf PDU.");
        }

        Uri msgUri = null;
        if (isDuplicateMessage(mContext, retrieveConf)) {
            // Mark this transaction as failed to prevent duplicate
            // notification to user.
            mTransactionState.setState(TransactionState.FAILED);
            mTransactionState.setContentUri(mUri);
        } else {
            // Store M-Retrieve.conf into Inbox
            PduPersister persister = PduPersister.getPduPersister(mContext);
            msgUri = persister.persist(retrieveConf, Inbox.CONTENT_URI);

            // Use local time instead of PDU time
            ContentValues values = new ContentValues(1);
            values.put(Mms.DATE, System.currentTimeMillis() / 1000L);
            SqliteWrapper.update(mContext, mContext.getContentResolver(),
                    msgUri, values, null, null);

            // The M-Retrieve.conf has been successfully downloaded.
            mTransactionState.setState(TransactionState.SUCCESS);
            mTransactionState.setContentUri(msgUri);
            // Remember the location the message was downloaded from.
            // Since it's not critical, it won't fail the transaction.
            // Copy over the locked flag from the M-Notification.ind in case
            // the user locked the message before activating the download.
            updateContentLocation(mContext, msgUri, mContentLocation, mLocked);
        }

        // Delete the corresponding M-Notification.ind.
        SqliteWrapper.delete(mContext, mContext.getContentResolver(),
                             mUri, null, null);

        if (msgUri != null) {
            // Have to delete messages over limit *after* the delete above. Otherwise,
            // it would be counted as part of the total.
            Recycler.getMmsRecycler().deleteOldMessagesInSameThreadAsMessage(mContext, msgUri);
            MmsWidgetProvider.notifyDatasetChanged(mContext);
        }

        // Send ACK to the Proxy-Relay to indicate we have fetched the
        // MM successfully.
        // Don't mark the transaction as failed if we failed to send it.
        sendAcknowledgeInd(retrieveConf);
    } catch (Throwable t) {
        Log.e(TAG, Log.getStackTraceString(t));
    } finally {
        if (mTransactionState.getState() != TransactionState.SUCCESS) {
            mTransactionState.setState(TransactionState.FAILED);
            mTransactionState.setContentUri(mUri);
            Log.e(TAG, "Retrieval failed.");
        }
        notifyObservers();
    }
}
项目:android-aosp-mms    文件:RetrieveTransaction.java   
public void run() {
    try {
        // Change the downloading state of the M-Notification.ind.
        DownloadManager.getInstance().markState(
                mUri, DownloadManager.STATE_DOWNLOADING);

        // Send GET request to MMSC and retrieve the response data.
        byte[] resp = getPdu(mContentLocation);

        // Parse M-Retrieve.conf
        RetrieveConf retrieveConf = (RetrieveConf) new PduParser(resp).parse();
        if (null == retrieveConf) {
            throw new MmsException("Invalid M-Retrieve.conf PDU.");
        }

        Uri msgUri = null;
        if (isDuplicateMessage(mContext, retrieveConf)) {
            // Mark this transaction as failed to prevent duplicate
            // notification to user.
            mTransactionState.setState(TransactionState.FAILED);
            mTransactionState.setContentUri(mUri);
        } else {
            // Store M-Retrieve.conf into Inbox
            PduPersister persister = PduPersister.getPduPersister(mContext);
            msgUri = persister.persist(retrieveConf, Inbox.CONTENT_URI, true,
                    MessagingPreferenceActivity.getIsGroupMmsEnabled(mContext), null);

            // Use local time instead of PDU time
            ContentValues values = new ContentValues(1);
            values.put(Mms.DATE, System.currentTimeMillis() / 1000L);
            SqliteWrapper.update(mContext, mContext.getContentResolver(),
                    msgUri, values, null, null);

            // The M-Retrieve.conf has been successfully downloaded.
            mTransactionState.setState(TransactionState.SUCCESS);
            mTransactionState.setContentUri(msgUri);
            // Remember the location the message was downloaded from.
            // Since it's not critical, it won't fail the transaction.
            // Copy over the locked flag from the M-Notification.ind in case
            // the user locked the message before activating the download.
            updateContentLocation(mContext, msgUri, mContentLocation, mLocked);
        }

        // Delete the corresponding M-Notification.ind.
        SqliteWrapper.delete(mContext, mContext.getContentResolver(),
                             mUri, null, null);

        if (msgUri != null) {
            // Have to delete messages over limit *after* the delete above. Otherwise,
            // it would be counted as part of the total.
            Recycler.getMmsRecycler().deleteOldMessagesInSameThreadAsMessage(mContext, msgUri);
            MmsWidgetProvider.notifyDatasetChanged(mContext);
        }

        // Send ACK to the Proxy-Relay to indicate we have fetched the
        // MM successfully.
        // Don't mark the transaction as failed if we failed to send it.
        sendAcknowledgeInd(retrieveConf);
    } catch (Throwable t) {
        Log.e(TAG, Log.getStackTraceString(t));
    } finally {
        if (mTransactionState.getState() != TransactionState.SUCCESS) {
            mTransactionState.setState(TransactionState.FAILED);
            mTransactionState.setContentUri(mUri);
            Log.e(TAG, "Retrieval failed.");
        }
        notifyObservers();
    }
}