/** * Start a delete of the conversation with the specified thread ID. * * @param handler An AsyncQueryHandler that will receive onDeleteComplete * upon completion of the conversation being deleted * @param token The token that will be passed to onDeleteComplete * @param deleteAll Delete the whole thread including locked messages * @param threadIds Collection of thread IDs of the conversations to be deleted */ public static void startDelete(ConversationQueryHandler handler, int token, boolean deleteAll, Collection<Long> threadIds) { synchronized (sDeletingThreadsLock) { if (DELETEDEBUG) { Log.v(TAG, "Conversation startDelete sDeletingThreads: " + sDeletingThreads); } if (sDeletingThreads) { Log.e(TAG, "startDeleteAll already in the middle of a delete", new Exception()); } //MmsApp.getApplication().getPduLoaderManager().clear(); sDeletingThreads = true; for (long threadId : threadIds) { Uri uri = ContentUris.withAppendedId(Threads.CONTENT_URI, threadId); String selection = deleteAll ? null : "locked=0"; handler.setDeleteToken(token); handler.startDelete(token, new Long(threadId), uri, selection, null); DraftCache.getInstance().setDraftState(threadId, false); } } }
/** * Start deleting all conversations in the database. * * @param handler An AsyncQueryHandler that will receive onDeleteComplete * upon completion of all conversations being deleted * @param token The token that will be passed to onDeleteComplete * @param deleteAll Delete the whole thread including locked messages */ public static void startDeleteAll(ConversationQueryHandler handler, int token, boolean deleteAll) { synchronized (sDeletingThreadsLock) { if (DELETEDEBUG) { Log.v(TAG, "Conversation startDeleteAll sDeletingThreads: " + sDeletingThreads); } if (sDeletingThreads) { Log.e(TAG, "startDeleteAll already in the middle of a delete", new Exception()); } sDeletingThreads = true; String selection = deleteAll ? null : "locked=0"; QKSMSAppBase app = QKSMSApp.getApplication(); //app.getPduLoaderManager().clear(); //app.getThumbnailManager().clear(); handler.setDeleteToken(token); handler.startDelete(token, new Long(-1), Threads.CONTENT_URI, selection, null); } }
private int queryUnreadCount() { Cursor cursor = null; int unreadCount = 0; try { cursor = mContext.getContentResolver().query(Conversation.sAllThreadsUri, Conversation.ALL_THREADS_PROJECTION, Threads.READ + "=0", null, null); if (cursor != null) { unreadCount = cursor.getCount(); } } finally { if (cursor != null) { cursor.close(); } } return unreadCount; }
private int queryUnreadCount() { Cursor cursor = null; int unreadCount = 0; try { cursor = mContext.getContentResolver().query( Conversation.sAllThreadsUri, Conversation.ALL_THREADS_PROJECTION, Threads.READ + "=0", null, null); if (cursor != null) { unreadCount = cursor.getCount(); } } finally { if (cursor != null) { cursor.close(); } } return unreadCount; }
public static List<Conversation> getSMSThreadIds(Context context) { List<Conversation> list = new ArrayList<Conversation>(); final String[] allThreadProjections = { Threads._ID, Threads.MESSAGE_COUNT, Threads.RECIPIENT_IDS, Threads.SNIPPET }; Cursor cursor = context.getContentResolver().query(Uri.parse(URI_CONVERSATIONS), allThreadProjections, null, null, null); while (cursor.moveToNext()) { long threadId = cursor.getLong(cursor.getColumnIndex(Threads._ID)); long msgCount = cursor.getLong(cursor.getColumnIndex(Threads.MESSAGE_COUNT)); long rec = cursor.getLong(cursor.getColumnIndex(Threads.RECIPIENT_IDS)); String snippet = cursor.getString(cursor.getColumnIndex(Threads.SNIPPET)); String phoneNumber = getNumberForId(rec, context); Contact contact = ContactUtils.getContactFromPhoneNumber(phoneNumber, context); list.add(new Conversation(threadId, msgCount, contact, snippet)); Log.d(TAG, "Found " + threadId + " " + msgCount + " " + rec); } cursor.close(); return list; }
/** * Start a delete of the conversation with the specified thread ID. * * @param handler An AsyncQueryHandler that will receive onDeleteComplete * upon completion of the conversation being deleted * @param token The token that will be passed to onDeleteComplete * @param deleteAll Delete the whole thread including locked messages * @param threadIds Collection of thread IDs of the conversations to be deleted */ public static void startDelete(ConversationQueryHandler handler, int token, boolean deleteAll, Collection<Long> threadIds) { synchronized(sDeletingThreadsLock) { if (DELETEDEBUG) { Log.v(TAG, "Conversation startDelete sDeletingThreads: " + sDeletingThreads); } if (sDeletingThreads) { Log.e(TAG, "startDeleteAll already in the middle of a delete", new Exception()); } MmsApp.getApplication().getPduLoaderManager().clear(); sDeletingThreads = true; for (long threadId : threadIds) { Uri uri = ContentUris.withAppendedId(Threads.CONTENT_URI, threadId); String selection = deleteAll ? null : "locked=0"; handler.setDeleteToken(token); handler.startDelete(token, new Long(threadId), uri, selection, null); DraftCache.getInstance().setDraftState(threadId, false); } } }
/** * Start deleting all conversations in the database. * @param handler An AsyncQueryHandler that will receive onDeleteComplete * upon completion of all conversations being deleted * @param token The token that will be passed to onDeleteComplete * @param deleteAll Delete the whole thread including locked messages */ public static void startDeleteAll(ConversationQueryHandler handler, int token, boolean deleteAll) { synchronized(sDeletingThreadsLock) { if (DELETEDEBUG) { Log.v(TAG, "Conversation startDeleteAll sDeletingThreads: " + sDeletingThreads); } if (sDeletingThreads) { Log.e(TAG, "startDeleteAll already in the middle of a delete", new Exception()); } sDeletingThreads = true; String selection = deleteAll ? null : "locked=0"; MmsApp app = MmsApp.getApplication(); app.getPduLoaderManager().clear(); app.getThumbnailManager().clear(); handler.setDeleteToken(token); handler.startDelete(token, new Long(-1), Threads.CONTENT_URI, selection, null); } }
/** * Returns a content:// URI referring to this conversation, * or null if it does not exist on disk yet. */ public synchronized Uri getUri() { if (mThreadId <= 0) return null; return ContentUris.withAppendedId(Threads.CONTENT_URI, mThreadId); }
/** * Returns a content:// URI referring to this conversation, or null if it * does not exist on disk yet. */ public synchronized Uri getUri() { if (mThreadId <= 0) return null; return ContentUris.withAppendedId(Threads.CONTENT_URI, mThreadId); }
private static long getOrCreateThreadId(Context context, ContactList list) { HashSet<String> recipients = new HashSet<String>(); Contact cacheContact = null; for (Contact c : list) { cacheContact = Contact.get(c.getNumber(), false); if (cacheContact != null) { recipients.add(cacheContact.getNumber()); } else { recipients.add(c.getNumber()); } } synchronized (sDeletingThreadsLock) { long now = System.currentTimeMillis(); while (sDeletingThreads) { try { sDeletingThreadsLock.wait(30000); } catch (InterruptedException e) { } if (System.currentTimeMillis() - now > 29000) { // The deleting thread task is stuck or onDeleteComplete // wasn't called. // Unjam ourselves. Log.e(TAG, "getOrCreateThreadId timed out waiting for delete to complete", new Exception()); sDeletingThreads = false; break; } } long retVal = Threads.getOrCreateThreadId(context, recipients);//出错 if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { LogTag.debug( "[Conversation] getOrCreateThreadId for (%s) returned %d", recipients, retVal); } return retVal; } }
/** * Start a delete of the conversation with the specified thread ID. * * @param handler * An AsyncQueryHandler that will receive onDeleteComplete upon * completion of the conversation being deleted * @param token * The token that will be passed to onDeleteComplete * @param deleteAll * Delete the whole thread including locked messages * @param threadId * Thread ID of the conversation to be deleted */ public static void startDelete(ConversationQueryHandler handler, int token, boolean deleteAll, long threadId) { synchronized (sDeletingThreadsLock) { if (sDeletingThreads) { Log.e(TAG, "startDeleteAll already in the middle of a delete", new Exception()); } sDeletingThreads = true; Uri uri = ContentUris.withAppendedId(Threads.CONTENT_URI, threadId); String selection = deleteAll ? null : "locked=0"; MmsApp.getApplication().getPduLoaderManager().clear(); // HACK: the keys to the thumbnail cache are the part uris, such as // mms/part/3 // Because the part table doesn't have auto-increment ids, the part // ids are reused // when a message or thread is deleted. For now, we're clearing the // whole thumbnail // cache so we don't retrieve stale images when part ids are reused. // This will be // fixed in the next release in the mms provider. MmsApp.getApplication().getThumbnailManager().clear(); handler.setDeleteToken(token); handler.startDelete(token, new Long(threadId), uri, selection, null); } }
/** * Start deleting all conversations in the database. * * @param handler * An AsyncQueryHandler that will receive onDeleteComplete upon * completion of all conversations being deleted * @param token * The token that will be passed to onDeleteComplete * @param deleteAll * Delete the whole thread including locked messages */ public static void startDeleteAll(ConversationQueryHandler handler, int token, boolean deleteAll) { synchronized (sDeletingThreadsLock) { if (sDeletingThreads) { Log.e(TAG, "startDeleteAll already in the middle of a delete", new Exception()); } sDeletingThreads = true; String selection = deleteAll ? null : "locked=0"; MmsApp.getApplication().getPduLoaderManager().clear(); // HACK: the keys to the thumbnail cache are the part uris, such as // mms/part/3 // Because the part table doesn't have auto-increment ids, the part // ids are reused // when a message or thread is deleted. For now, we're clearing the // whole thumbnail // cache so we don't retrieve stale images when part ids are reused. // This will be // fixed in the next release in the mms provider. MmsApp.getApplication().getThumbnailManager().clear(); handler.setDeleteToken(token); handler.startDelete(token, new Long(-1), Threads.CONTENT_URI, selection, null); } }
private void startAsyncQuery() { try { ((TextView) (getListView().getEmptyView())) .setText(R.string.loading_conversations); Conversation.startQueryForAll(mQueryHandler, THREAD_LIST_QUERY_TOKEN); Conversation.startQuery(mQueryHandler, UNREAD_THREADS_QUERY_TOKEN, Threads.READ + "=0"); } catch (SQLiteException e) { SqliteWrapper.checkSQLiteException(this, e); } }
private void startAsyncQuery() { try { ((TextView)(getListView().getEmptyView())).setText(R.string.loading_conversations); Conversation.startQueryForAll(mQueryHandler, THREAD_LIST_QUERY_TOKEN); Conversation.startQuery(mQueryHandler, UNREAD_THREADS_QUERY_TOKEN, Threads.READ + "=0"); } catch (SQLiteException e) { SqliteWrapper.checkSQLiteException(this, e); } }
private static long getOrCreateThreadId(Context context, ContactList list) { HashSet<String> recipients = new HashSet<String>(); Contact cacheContact = null; for (Contact c : list) { cacheContact = Contact.get(c.getNumber(), false); if (cacheContact != null) { recipients.add(cacheContact.getNumber()); } else { recipients.add(c.getNumber()); } } synchronized(sDeletingThreadsLock) { if (DELETEDEBUG) { ComposeMessageActivity.log("Conversation getOrCreateThreadId for: " + list.formatNamesAndNumbers(",") + " sDeletingThreads: " + sDeletingThreads); } long now = System.currentTimeMillis(); while (sDeletingThreads) { try { sDeletingThreadsLock.wait(30000); } catch (InterruptedException e) { } if (System.currentTimeMillis() - now > 29000) { // The deleting thread task is stuck or onDeleteComplete wasn't called. // Unjam ourselves. Log.e(TAG, "getOrCreateThreadId timed out waiting for delete to complete", new Exception()); sDeletingThreads = false; break; } } long retVal = Threads.getOrCreateThreadId(context, recipients); if (DELETEDEBUG || Log.isLoggable(LogTag.APP, Log.VERBOSE)) { LogTag.debug("[Conversation] getOrCreateThreadId for (%s) returned %d", recipients, retVal); } return retVal; } }
public static long getOrCreateThreadId(Context context, String address) { synchronized(sDeletingThreadsLock) { if (DELETEDEBUG) { ComposeMessageActivity.log("Conversation getOrCreateThreadId for: " + address + " sDeletingThreads: " + sDeletingThreads); } long now = System.currentTimeMillis(); while (sDeletingThreads) { try { sDeletingThreadsLock.wait(30000); } catch (InterruptedException e) { } if (System.currentTimeMillis() - now > 29000) { // The deleting thread task is stuck or onDeleteComplete wasn't called. // Unjam ourselves. Log.e(TAG, "getOrCreateThreadId timed out waiting for delete to complete", new Exception()); sDeletingThreads = false; break; } } long retVal = Threads.getOrCreateThreadId(context, address); if (DELETEDEBUG || Log.isLoggable(LogTag.APP, Log.VERBOSE)) { LogTag.debug("[Conversation] getOrCreateThreadId for (%s) returned %d", address, retVal); } return retVal; } }
/** * Return the Uri for all messages in the given thread ID. * * @deprecated */ public static Uri getUri(long threadId) { // TODO: Callers using this should really just have a Conversation // and call getUri() on it, but this guarantees no blocking. return ContentUris.withAppendedId(Threads.CONTENT_URI, threadId); }
/** * Remove any obsolete conversations sitting around on disk. Obsolete * threads are threads that aren't referenced by any message in the pdu or * sms tables. */ public static void asyncDeleteObsoleteThreads(AsyncQueryHandler handler, int token) { handler.startDelete(token, null, Threads.OBSOLETE_THREADS_URI, null, null); }
private Uri storeMessage(Context context, String address, String message) { // Store the message in the content provider. ContentValues values = new ContentValues(); // values.put(Sms.ERROR_CODE, 0); values.put(Inbox.ADDRESS, address); // Use now for the timestamp to avoid confusion with clock // drift between the handset and the SMSC. values.put(Inbox.DATE, new Long(System.currentTimeMillis())); values.put(Inbox.PROTOCOL, 0); values.put(Inbox.READ, Integer.valueOf(0)); // if (sms.getPseudoSubject().length() > 0) { // values.put(Inbox.SUBJECT, sms.getPseudoSubject()); // } values.put(Inbox.REPLY_PATH_PRESENT, 0); values.put(Inbox.SERVICE_CENTER, 0); values.put(Inbox.BODY, message); // Make sure we've got a thread id so after the insert we'll be able to delete // excess messages. Long threadId = 0L; Contact cacheContact = Contact.get(address,true); if (cacheContact != null) { address = cacheContact.getNumber(); } if (((threadId == null) || (threadId == 0)) && (address != null)) { values.put(Sms.THREAD_ID, Threads.getOrCreateThreadId( context, address)); } ContentResolver resolver = context.getContentResolver(); Uri insertedUri = SqliteWrapper.insert(context, resolver, Inbox.CONTENT_URI, values); // Now make sure we're not over the limit in stored messages threadId = values.getAsLong(Sms.THREAD_ID); Recycler.getSmsRecycler().deleteOldMessagesByThreadId(context, threadId); return insertedUri; }
/** * Return the Uri for all messages in the given thread ID. * @deprecated */ public static Uri getUri(long threadId) { // TODO: Callers using this should really just have a Conversation // and call getUri() on it, but this guarantees no blocking. return ContentUris.withAppendedId(Threads.CONTENT_URI, threadId); }
/** * Remove any obsolete conversations sitting around on disk. Obsolete threads are threads * that aren't referenced by any message in the pdu or sms tables. */ public static void asyncDeleteObsoleteThreads(AsyncQueryHandler handler, int token) { handler.startDelete(token, null, Threads.OBSOLETE_THREADS_URI, null, null); }
public static ArrayList<Map<String, Object>> getRecipientsIds( Context context, long threadId) { ArrayList<Long> recipients_ids = new ArrayList<Long>(); Cursor c = context.getContentResolver().query(sAllThreadsUri, ALL_THREADS_PROJECTION, Threads._ID + " = " + threadId, null, null); if(c==null||c.getCount()==0) return null; c.moveToPosition(-1); c.moveToNext(); String spaceSepIds = c.getString(RECIPIENT_IDS); // zaizhe ɾ��ݸ������ϵ���Ҳ����ݸ��recipient����IDs String[] ids = spaceSepIds.split(" "); for (String id : ids) { long longId; try { longId = Long.parseLong(id); recipients_ids.add(longId); } catch (NumberFormatException ex) { // skip this id continue; } } ContactList recipients = ContactList.getByIds( c.getString(RECIPIENT_IDS), false); String[] numbers = recipients.getNumbers(); ArrayList<Map<String, Object>> recipient_all = new ArrayList<Map<String, Object>>(); for (int i = 0; i < recipients_ids.size(); i++) { Map<String, Object> map = new HashMap<String, Object>(); map.put("thread_id", recipients_ids.get(i)); map.put("number", numbers[i]); recipient_all.add(map); } // Log.v("ConversationUtils", // "number: "+recipients.toString()+" exact number: "+numbers[1]); c.close(); return recipient_all; }