Java 类android.provider.Telephony.Sms.Conversations 实例源码

项目:qksms    文件:Conversation.java   
/**
 * Check for locked messages in all threads or a specified thread.
 *
 * @param handler   An AsyncQueryHandler that will receive onQueryComplete
 *                  upon completion of looking for locked messages
 * @param threadIds A list of threads to search. null means all threads
 * @param token     The token that will be passed to onQueryComplete
 */
public static void startQueryHaveLockedMessages(AsyncQueryHandler handler,
                                                Collection<Long> threadIds,
                                                int token) {
    handler.cancelOperation(token);
    Uri uri = MmsSms.CONTENT_LOCKED_URI;

    String selection = null;
    if (threadIds != null) {
        StringBuilder buf = new StringBuilder();
        int i = 0;

        for (long threadId : threadIds) {
            if (i++ > 0) {
                buf.append(" OR ");
            }
            // We have to build the selection arg into the selection because deep down in
            // provider, the function buildUnionSubQuery takes selectionArgs, but ignores it.
            buf.append(Mms.THREAD_ID).append("=").append(Long.toString(threadId));
        }
        selection = buf.toString();
    }
    handler.startQuery(token, threadIds, uri,
            ALL_THREADS_PROJECTION, selection, null, Conversations.DEFAULT_SORT_ORDER);
}
项目:android-aosp-mms    文件:Conversation.java   
/**
 * Check for locked messages in all threads or a specified thread.
 * @param handler An AsyncQueryHandler that will receive onQueryComplete
 *                upon completion of looking for locked messages
 * @param threadIds   A list of threads to search. null means all threads
 * @param token   The token that will be passed to onQueryComplete
 */
public static void startQueryHaveLockedMessages(AsyncQueryHandler handler,
        Collection<Long> threadIds,
        int token) {
    handler.cancelOperation(token);
    Uri uri = MmsSms.CONTENT_LOCKED_URI;

    String selection = null;
    if (threadIds != null) {
        StringBuilder buf = new StringBuilder();
        int i = 0;

        for (long threadId : threadIds) {
            if (i++ > 0) {
                buf.append(" OR ");
            }
            // We have to build the selection arg into the selection because deep down in
            // provider, the function buildUnionSubQuery takes selectionArgs, but ignores it.
            buf.append(Mms.THREAD_ID).append("=").append(Long.toString(threadId));
        }
        selection = buf.toString();
    }
    handler.startQuery(token, threadIds, uri,
            ALL_THREADS_PROJECTION, selection, null, Conversations.DEFAULT_SORT_ORDER);
}
项目:qksms    文件:Conversation.java   
/**
 * Start a query for in the database on the specified AsyncQueryHandler with the specified
 * "where" clause.
 *
 * @param handler   An AsyncQueryHandler that will receive onQueryComplete
 *                  upon completion of the query
 * @param token     The token that will be passed to onQueryComplete
 * @param selection A where clause (can be null) to select particular conv items.
 */
public static void startQuery(AsyncQueryHandler handler, int token, String selection) {
    handler.cancelOperation(token);

    // This query looks like this in the log:
    // I/Database(  147): elapsedTime4Sql|/data/data/com.android.providers.telephony/databases/
    // mmssms.db|2.253 ms|SELECT _id, date, message_count, recipient_ids, snippet, snippet_cs,
    // read, error, has_attachment FROM threads ORDER BY  date DESC

    handler.startQuery(token, null, sAllThreadsUri,
            ALL_THREADS_PROJECTION, selection, null, Conversations.DEFAULT_SORT_ORDER);
}
项目:qksms    文件:Recycler.java   
protected Cursor getAllThreads(Context context) {
    ContentResolver resolver = context.getContentResolver();
    Cursor cursor = SqliteWrapper.query(context, resolver,
            Conversations.CONTENT_URI,
            ALL_SMS_THREADS_PROJECTION, null, null, Conversations.DEFAULT_SORT_ORDER);

    return cursor;
}
项目:qksms    文件:Recycler.java   
@Override
protected boolean anyThreadOverLimit(Context context) {
    Cursor cursor = getAllThreads(context);
    if (cursor == null) {
        return false;
    }
    int limit = getMessageLimit(context);
    try {
        while (cursor.moveToNext()) {
            long threadId = getThreadId(cursor);
            ContentResolver resolver = context.getContentResolver();
            Cursor msgs = SqliteWrapper.query(context, resolver,
                    ContentUris.withAppendedId(Conversations.CONTENT_URI, threadId),
                    SMS_MESSAGE_PROJECTION,
                    "locked=0",
                    null, "date DESC");     // get in newest to oldest order
            if (msgs == null) {
                return false;
            }
            try {
                if (msgs.getCount() >= limit) {
                    return true;
                }
            } finally {
                msgs.close();
            }
        }
    } finally {
        cursor.close();
    }
    return false;
}
项目:qksms    文件:Recycler.java   
protected Cursor getAllThreads(Context context) {
    ContentResolver resolver = context.getContentResolver();
    Cursor cursor = SqliteWrapper.query(context, resolver,
            Uri.withAppendedPath(Mms.CONTENT_URI, "threads"),
            ALL_MMS_THREADS_PROJECTION, null, null, Conversations.DEFAULT_SORT_ORDER);

    return cursor;
}
项目:sms_DualCard    文件:Conversation.java   
/**
 * Start a query for in the database on the specified AsyncQueryHandler with
 * the specified "where" clause.
 * 
 * @param handler
 *            An AsyncQueryHandler that will receive onQueryComplete upon
 *            completion of the query
 * @param token
 *            The token that will be passed to onQueryComplete
 * @param selection
 *            A where clause (can be null) to select particular conv items.
 */
public static void startQuery(AsyncQueryHandler handler, int token,
        String selection) {
    handler.cancelOperation(token);

    // This query looks like this in the log:
    // I/Database( 147):
    // elapsedTime4Sql|/data/data/com.android.providers.telephony/databases/
    // mmssms.db|2.253 ms|SELECT _id, date, message_count, recipient_ids,
    // snippet, snippet_cs,
    // read, error, has_attachment FROM threads ORDER BY date DESC

    handler.startQuery(token, null, sAllThreadsUri, ALL_THREADS_PROJECTION,
            selection, null, Conversations.DEFAULT_SORT_ORDER);
}
项目:sms_DualCard    文件:Conversation.java   
/**
 * Check for locked messages in all threads or a specified thread.
 * 
 * @param handler
 *            An AsyncQueryHandler that will receive onQueryComplete upon
 *            completion of looking for locked messages
 * @param threadIds
 *            A list of threads to search. null means all threads
 * @param token
 *            The token that will be passed to onQueryComplete
 */
public static void startQueryHaveLockedMessages(AsyncQueryHandler handler,
        Collection<Long> threadIds, int token) {
    handler.cancelOperation(token);
    Uri uri = MmsSms.CONTENT_LOCKED_URI;

    String selection = null;
    if (threadIds != null) {
        StringBuilder buf = new StringBuilder();
        int i = 0;

        for (long threadId : threadIds) {
            if (i++ > 0) {
                buf.append(" OR ");
            }
            // We have to build the selection arg into the selection because
            // deep down in
            // provider, the function buildUnionSubQuery takes
            // selectionArgs, but ignores it.
            buf.append(Mms.THREAD_ID).append("=")
                    .append(Long.toString(threadId));
        }
        selection = buf.toString();
    }
    handler.startQuery(token, threadIds, uri, ALL_THREADS_PROJECTION,
            selection, null, Conversations.DEFAULT_SORT_ORDER);
}
项目:sms_DualCard    文件:Recycler.java   
protected Cursor getAllThreads(Context context) {
    ContentResolver resolver = context.getContentResolver();
    Cursor cursor = SqliteWrapper.query(context, resolver,
            Telephony.Sms.Conversations.CONTENT_URI,
            ALL_SMS_THREADS_PROJECTION, null, null, Conversations.DEFAULT_SORT_ORDER);

    return cursor;
}
项目:sms_DualCard    文件:Recycler.java   
@Override
protected boolean anyThreadOverLimit(Context context) {
    Cursor cursor = getAllThreads(context);
    if (cursor == null) {
        return false;
    }
    int limit = getMessageLimit(context);
    try {
        while (cursor.moveToNext()) {
            long threadId = getThreadId(cursor);
            ContentResolver resolver = context.getContentResolver();
            Cursor msgs = SqliteWrapper.query(context, resolver,
                    ContentUris.withAppendedId(Sms.Conversations.CONTENT_URI, threadId),
                    SMS_MESSAGE_PROJECTION,
                    "locked=0",
                    null, "date DESC");     // get in newest to oldest order
            if (msgs == null) {
                return false;
            }
            try {
                if (msgs.getCount() >= limit) {
                    return true;
                }
            } finally {
                msgs.close();
            }
        }
    } finally {
        cursor.close();
    }
    return false;
}
项目:sms_DualCard    文件:Recycler.java   
protected Cursor getAllThreads(Context context) {
    ContentResolver resolver = context.getContentResolver();
    Cursor cursor = SqliteWrapper.query(context, resolver,
            Uri.withAppendedPath(Telephony.Mms.CONTENT_URI, "threads"),
            ALL_MMS_THREADS_PROJECTION, null, null, Conversations.DEFAULT_SORT_ORDER);

    return cursor;
}
项目:sms_DualCard    文件:RecyclerTest.java   
public void run() {
    final int MAXSEND = Integer.MAX_VALUE;

    for (int i = 0; i < MAXSEND; i++) {
        // Put a random message to one of the random recipients in the SMS db.
        Uri uri = storeMessage(getContext(),
                mRecipients.get(mRandom.nextInt(mRecipientCnt)),
                generateMessage());
        Log.v(TAG, "Generating msg uri: " + uri);
        if (i > 100) {
            // Wait until we've sent a bunch of messages to guarantee we've got
            // some threads built up. Then check to make sure all the threads are there
            // on each message. All these queries will provide additional stress on the
            // sms db.
            Cursor cursor = null;
            try {
                cursor = SqliteWrapper.query(getContext(),
                        getContext().getContentResolver(), sAllThreadsUri,
                        ALL_THREADS_PROJECTION, null, null,
                        Conversations.DEFAULT_SORT_ORDER);
                assertNotNull("Cursor from thread query is null!", cursor);
                int cnt = cursor.getCount();
                assertTrue("The threads appeared to have been wiped out",
                    cursor.getCount() >= mRecipientCnt);
            } catch (SQLiteException e) {
                Log.v(TAG, "query for threads failed with exception: " + e);
                fail("query for threads failed with exception: " + e);
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
        }
    }
}
项目:android-aosp-mms    文件:Conversation.java   
/**
 * Start a query for in the database on the specified AsyncQueryHandler with the specified
 * "where" clause.
 *
 * @param handler An AsyncQueryHandler that will receive onQueryComplete
 *                upon completion of the query
 * @param token   The token that will be passed to onQueryComplete
 * @param selection   A where clause (can be null) to select particular conv items.
 */
public static void startQuery(AsyncQueryHandler handler, int token, String selection) {
    handler.cancelOperation(token);

    // This query looks like this in the log:
    // I/Database(  147): elapsedTime4Sql|/data/data/com.android.providers.telephony/databases/
    // mmssms.db|2.253 ms|SELECT _id, date, message_count, recipient_ids, snippet, snippet_cs,
    // read, error, has_attachment FROM threads ORDER BY  date DESC

    handler.startQuery(token, null, sAllThreadsUri,
            ALL_THREADS_PROJECTION, selection, null, Conversations.DEFAULT_SORT_ORDER);
}
项目:android-aosp-mms    文件:Recycler.java   
protected Cursor getAllThreads(Context context) {
    ContentResolver resolver = context.getContentResolver();
    Cursor cursor = SqliteWrapper.query(context, resolver,
            Telephony.Sms.Conversations.CONTENT_URI,
            ALL_SMS_THREADS_PROJECTION, null, null, Conversations.DEFAULT_SORT_ORDER);

    return cursor;
}
项目:android-aosp-mms    文件:Recycler.java   
@Override
protected boolean anyThreadOverLimit(Context context) {
    Cursor cursor = getAllThreads(context);
    if (cursor == null) {
        return false;
    }
    int limit = getMessageLimit(context);
    try {
        while (cursor.moveToNext()) {
            long threadId = getThreadId(cursor);
            ContentResolver resolver = context.getContentResolver();
            Cursor msgs = SqliteWrapper.query(context, resolver,
                    ContentUris.withAppendedId(Sms.Conversations.CONTENT_URI, threadId),
                    SMS_MESSAGE_PROJECTION,
                    "locked=0",
                    null, "date DESC");     // get in newest to oldest order
            if (msgs == null) {
                return false;
            }
            try {
                if (msgs.getCount() >= limit) {
                    return true;
                }
            } finally {
                msgs.close();
            }
        }
    } finally {
        cursor.close();
    }
    return false;
}
项目:android-aosp-mms    文件:Recycler.java   
protected Cursor getAllThreads(Context context) {
    ContentResolver resolver = context.getContentResolver();
    Cursor cursor = SqliteWrapper.query(context, resolver,
            Uri.withAppendedPath(Telephony.Mms.CONTENT_URI, "threads"),
            ALL_MMS_THREADS_PROJECTION, null, null, Conversations.DEFAULT_SORT_ORDER);

    return cursor;
}
项目:android-aosp-mms    文件:RecyclerTest.java   
public void run() {
    final int MAXSEND = Integer.MAX_VALUE;

    for (int i = 0; i < MAXSEND; i++) {
        // Put a random message to one of the random recipients in the SMS db.
        Uri uri = storeMessage(getContext(),
                mRecipients.get(mRandom.nextInt(mRecipientCnt)),
                generateMessage());
        Log.v(TAG, "Generating msg uri: " + uri);
        if (i > 100) {
            // Wait until we've sent a bunch of messages to guarantee we've got
            // some threads built up. Then check to make sure all the threads are there
            // on each message. All these queries will provide additional stress on the
            // sms db.
            Cursor cursor = null;
            try {
                cursor = SqliteWrapper.query(getContext(),
                        getContext().getContentResolver(), sAllThreadsUri,
                        ALL_THREADS_PROJECTION, null, null,
                        Conversations.DEFAULT_SORT_ORDER);
                assertNotNull("Cursor from thread query is null!", cursor);
                int cnt = cursor.getCount();
                assertTrue("The threads appeared to have been wiped out",
                    cursor.getCount() >= mRecipientCnt);
            } catch (SQLiteException e) {
                Log.v(TAG, "query for threads failed with exception: " + e);
                fail("query for threads failed with exception: " + e);
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
        }
    }
}
项目:qksms    文件:Recycler.java   
protected void deleteMessagesForThread(Context context, long threadId, int keep) {
    if (LOCAL_DEBUG) {
        Log.v(TAG, "SMS: deleteMessagesForThread");
    }
    ContentResolver resolver = context.getContentResolver();
    Cursor cursor = null;
    try {
        cursor = SqliteWrapper.query(context, resolver,
                ContentUris.withAppendedId(Conversations.CONTENT_URI, threadId),
                SMS_MESSAGE_PROJECTION,
                "locked=0",
                null, "date DESC");     // get in newest to oldest order
        if (cursor == null) {
            Log.e(TAG, "SMS: deleteMessagesForThread got back null cursor");
            return;
        }
        int count = cursor.getCount();
        int numberToDelete = count - keep;
        if (LOCAL_DEBUG) {
            Log.v(TAG, "SMS: deleteMessagesForThread keep: " + keep +
                    " count: " + count +
                    " numberToDelete: " + numberToDelete);
        }
        if (numberToDelete <= 0) {
            return;
        }
       // Move to the keep limit and then delete everything older than that one.
        cursor.move(keep);
        long latestDate = cursor.getLong(COLUMN_SMS_DATE);

        long cntDeleted = SqliteWrapper.delete(context, resolver,
                ContentUris.withAppendedId(Conversations.CONTENT_URI, threadId),
                "locked=0 AND date<" + latestDate,
                null);
        if (LOCAL_DEBUG) {
            Log.v(TAG, "SMS: deleteMessagesForThread cntDeleted: " + cntDeleted);
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
项目:sms_DualCard    文件:Recycler.java   
protected void deleteMessagesForThread(Context context, long threadId, int keep) {
    if (LOCAL_DEBUG) {
        Log.v(TAG, "SMS: deleteMessagesForThread");
    }
    ContentResolver resolver = context.getContentResolver();
    Cursor cursor = null;
    try {
        cursor = SqliteWrapper.query(context, resolver,
                ContentUris.withAppendedId(Sms.Conversations.CONTENT_URI, threadId),
                SMS_MESSAGE_PROJECTION,
                "locked=0",
                null, "date DESC");     // get in newest to oldest order
        if (cursor == null) {
            Log.e(TAG, "SMS: deleteMessagesForThread got back null cursor");
            return;
        }
        int count = cursor.getCount();
        int numberToDelete = count - keep;
        if (LOCAL_DEBUG) {
            Log.v(TAG, "SMS: deleteMessagesForThread keep: " + keep +
                    " count: " + count +
                    " numberToDelete: " + numberToDelete);
        }
        if (numberToDelete <= 0) {
            return;
        }
       // Move to the keep limit and then delete everything older than that one.
        cursor.move(keep);
        long latestDate = cursor.getLong(COLUMN_SMS_DATE);

        long cntDeleted = SqliteWrapper.delete(context, resolver,
                ContentUris.withAppendedId(Sms.Conversations.CONTENT_URI, threadId),
                "locked=0 AND date<" + latestDate,
                null);
        if (LOCAL_DEBUG) {
            Log.v(TAG, "SMS: deleteMessagesForThread cntDeleted: " + cntDeleted);
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
项目:android-aosp-mms    文件:Recycler.java   
protected void deleteMessagesForThread(Context context, long threadId, int keep) {
    if (LOCAL_DEBUG) {
        Log.v(TAG, "SMS: deleteMessagesForThread");
    }
    ContentResolver resolver = context.getContentResolver();
    Cursor cursor = null;
    try {
        cursor = SqliteWrapper.query(context, resolver,
                ContentUris.withAppendedId(Sms.Conversations.CONTENT_URI, threadId),
                SMS_MESSAGE_PROJECTION,
                "locked=0",
                null, "date DESC");     // get in newest to oldest order
        if (cursor == null) {
            Log.e(TAG, "SMS: deleteMessagesForThread got back null cursor");
            return;
        }
        int count = cursor.getCount();
        int numberToDelete = count - keep;
        if (LOCAL_DEBUG) {
            Log.v(TAG, "SMS: deleteMessagesForThread keep: " + keep +
                    " count: " + count +
                    " numberToDelete: " + numberToDelete);
        }
        if (numberToDelete <= 0) {
            return;
        }
       // Move to the keep limit and then delete everything older than that one.
        cursor.move(keep);
        long latestDate = cursor.getLong(COLUMN_SMS_DATE);

        long cntDeleted = SqliteWrapper.delete(context, resolver,
                ContentUris.withAppendedId(Sms.Conversations.CONTENT_URI, threadId),
                "locked=0 AND date<" + latestDate,
                null);
        if (LOCAL_DEBUG) {
            Log.v(TAG, "SMS: deleteMessagesForThread cntDeleted: " + cntDeleted);
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
项目:sms_DualCard    文件:TraditionalActivity.java   
public ContentValues getMmsValues(long id) {

        Cursor c = getContentResolver().query(ALL_MMS_INBOX, null, "_id=" + id,
                null, null);

        c.moveToFirst();
        long threadId = c.getLong(c.getColumnIndex(Conversations.THREAD_ID));

        String subject = c.getString(c.getColumnIndex(Mms.SUBJECT));

        int subjectCharSet = c.getInt(c.getColumnIndex(Mms.SUBJECT_CHARSET));

        long date = c.getLong(c.getColumnIndex(Mms.DATE));
        long dateSent = c.getLong(c.getColumnIndex(Mms.DATE_SENT));
        int read = c.getInt(c.getColumnIndex(Mms.READ));

        int mType = c.getInt(c.getColumnIndex(Mms.MESSAGE_TYPE));
        int mBox = c.getInt(c.getColumnIndex(Mms.MESSAGE_BOX));

        int dReport = c.getInt(c.getColumnIndex(Mms.DELIVERY_REPORT));

        int readReport = c.getInt(c.getColumnIndex(Mms.READ_REPORT));

        int mLocked = c.getInt(c.getColumnIndex(Mms.LOCKED));

        int st = c.getInt(c.getColumnIndex(Mms.STATUS));

        c.close();

        ContentValues values = new ContentValues();

        values.put("msg_id", id);

        values.put(Conversations.THREAD_ID, threadId);

        values.put(Mms.SUBJECT, subject);

        values.put(Mms.SUBJECT_CHARSET, subjectCharSet);

        values.put(Mms.DATE, date);

        values.put(Mms.DATE_SENT, dateSent);

        values.put(Mms.READ, read);

        values.put(Mms.MESSAGE_TYPE, mType);
        values.put(Mms.MESSAGE_BOX, mBox);
        values.put(Mms.DELIVERY_REPORT, dReport);
        values.put(Mms.READ_REPORT, readReport);
        values.put(Mms.LOCKED, mLocked);
        values.put(Mms.STATUS, st);

        return values;

    }