summaryrefslogtreecommitdiff
path: root/src/com/android/dialer/calllog/CallLogQueryHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/dialer/calllog/CallLogQueryHandler.java')
-rw-r--r--src/com/android/dialer/calllog/CallLogQueryHandler.java121
1 files changed, 18 insertions, 103 deletions
diff --git a/src/com/android/dialer/calllog/CallLogQueryHandler.java b/src/com/android/dialer/calllog/CallLogQueryHandler.java
index 750b41697..fed381427 100644
--- a/src/com/android/dialer/calllog/CallLogQueryHandler.java
+++ b/src/com/android/dialer/calllog/CallLogQueryHandler.java
@@ -41,7 +41,6 @@ import com.google.common.collect.Lists;
import java.lang.ref.WeakReference;
import java.util.List;
-import java.util.concurrent.TimeUnit;
import javax.annotation.concurrent.GuardedBy;
@@ -52,10 +51,8 @@ import javax.annotation.concurrent.GuardedBy;
private static final String TAG = "CallLogQueryHandler";
private static final int NUM_LOGS_TO_DISPLAY = 1000;
- /** The token for the query to fetch the new entries from the call log. */
- private static final int QUERY_NEW_CALLS_TOKEN = 53;
/** The token for the query to fetch the old entries from the call log. */
- private static final int QUERY_OLD_CALLS_TOKEN = 54;
+ private static final int QUERY_CALLLOG_TOKEN = 54;
/** The token for the query to mark all missed calls as old after seeing the call log. */
private static final int UPDATE_MARK_AS_OLD_TOKEN = 55;
/** The token for the query to mark all new voicemails as old. */
@@ -71,24 +68,15 @@ import javax.annotation.concurrent.GuardedBy;
*/
public static final int CALL_TYPE_ALL = -1;
- /**
- * The time window from the current time within which an unread entry will be added to the new
- * section.
- */
- private static final long NEW_SECTION_TIME_WINDOW = TimeUnit.DAYS.toMillis(7);
-
private final WeakReference<Listener> mListener;
- /** The cursor containing the new calls, or null if they have not yet been fetched. */
- @GuardedBy("this") private Cursor mNewCallsCursor;
/** The cursor containing the old calls, or null if they have not yet been fetched. */
- @GuardedBy("this") private Cursor mOldCallsCursor;
+ @GuardedBy("this") private Cursor mCallLogCursor;
/**
* The identifier of the latest calls request.
* <p>
* A request for the list of calls requires two queries and hence the two cursor
- * {@link #mNewCallsCursor} and {@link #mOldCallsCursor} above, corresponding to
- * {@link #QUERY_NEW_CALLS_TOKEN} and {@link #QUERY_OLD_CALLS_TOKEN}.
+ * and {@link #mCallLogCursor} above, corresponding to {@link #QUERY_CALLLOG_TOKEN}.
* <p>
* When a new request is about to be started, existing cursors are closed. However, it is
* possible that one of the queries completes after the new request has started. This means that
@@ -137,29 +125,6 @@ import javax.annotation.concurrent.GuardedBy;
mListener = new WeakReference<Listener>(listener);
}
- /** Creates a cursor that contains a single row and maps the section to the given value. */
- private Cursor createHeaderCursorFor(int section) {
- MatrixCursor matrixCursor =
- new MatrixCursor(CallLogQuery.EXTENDED_PROJECTION);
- // The values in this row correspond to default values for _PROJECTION from CallLogQuery
- // plus the section value.
- matrixCursor.addRow(new Object[]{
- 0L, "", 0L, 0L, 0, "", "", "", null, 0, null, null, null, null, 0L, null, 0,
- Calls.PRESENTATION_ALLOWED, section
- });
- return matrixCursor;
- }
-
- /** Returns a cursor for the old calls header. */
- private Cursor createOldCallsHeaderCursor() {
- return createHeaderCursorFor(CallLogQuery.SECTION_OLD_HEADER);
- }
-
- /** Returns a cursor for the new calls header. */
- private Cursor createNewCallsHeaderCursor() {
- return createHeaderCursorFor(CallLogQuery.SECTION_NEW_HEADER);
- }
-
/**
* Fetches the list of calls from the call log for a given type.
* <p>
@@ -168,8 +133,7 @@ import javax.annotation.concurrent.GuardedBy;
public void fetchCalls(int callType) {
cancelFetch();
int requestId = newCallsRequest();
- fetchCalls(QUERY_NEW_CALLS_TOKEN, requestId, true /*isNew*/, callType);
- fetchCalls(QUERY_OLD_CALLS_TOKEN, requestId, false /*isNew*/, callType);
+ fetchCalls(QUERY_CALLLOG_TOKEN, requestId, callType);
}
public void fetchVoicemailStatus() {
@@ -178,21 +142,16 @@ import javax.annotation.concurrent.GuardedBy;
}
/** Fetches the list of calls in the call log, either the new one or the old ones. */
- private void fetchCalls(int token, int requestId, boolean isNew, int callType) {
+ private void fetchCalls(int token, int requestId, int callType) {
// We need to check for NULL explicitly otherwise entries with where READ is NULL
// may not match either the query or its negation.
// We consider the calls that are not yet consumed (i.e. IS_READ = 0) as "new".
- String selection = String.format("%s IS NOT NULL AND %s = 0 AND %s > ?",
- Calls.IS_READ, Calls.IS_READ, Calls.DATE);
- List<String> selectionArgs = Lists.newArrayList(
- Long.toString(System.currentTimeMillis() - NEW_SECTION_TIME_WINDOW));
- if (!isNew) {
- // Negate the query.
- selection = String.format("NOT (%s)", selection);
- }
+ String selection = null;
+ List<String> selectionArgs = Lists.newArrayList();
+
if (callType > CALL_TYPE_ALL) {
// Add a clause to fetch only items of type voicemail.
- selection = String.format("(%s) AND (%s = ?)", selection, Calls.TYPE);
+ selection = String.format("(%s = ?)", Calls.TYPE);
selectionArgs.add(Integer.toString(callType));
}
Uri uri = Calls.CONTENT_URI_WITH_VOICEMAIL.buildUpon()
@@ -205,8 +164,7 @@ import javax.annotation.concurrent.GuardedBy;
/** Cancel any pending fetch request. */
private void cancelFetch() {
- cancelOperation(QUERY_NEW_CALLS_TOKEN);
- cancelOperation(QUERY_OLD_CALLS_TOKEN);
+ cancelOperation(QUERY_CALLLOG_TOKEN);
}
/** Updates all new calls to mark them as old. */
@@ -261,16 +219,14 @@ import javax.annotation.concurrent.GuardedBy;
* Closes any open cursor that has not yet been sent to the requester.
*/
private synchronized int newCallsRequest() {
- MoreCloseables.closeQuietly(mNewCallsCursor);
- MoreCloseables.closeQuietly(mOldCallsCursor);
- mNewCallsCursor = null;
- mOldCallsCursor = null;
+ MoreCloseables.closeQuietly(mCallLogCursor);
+ mCallLogCursor = null;
return ++mCallsRequestId;
}
@Override
protected void onNotNullableQueryComplete(int token, Object cookie, Cursor cursor) {
- if (token == QUERY_NEW_CALLS_TOKEN) {
+ if (token == QUERY_CALLLOG_TOKEN) {
int requestId = ((Integer) cookie).intValue();
if (requestId != mCallsRequestId) {
// Ignore this query since it does not correspond to the latest request.
@@ -278,20 +234,8 @@ import javax.annotation.concurrent.GuardedBy;
}
// Store the returned cursor.
- MoreCloseables.closeQuietly(mNewCallsCursor);
- mNewCallsCursor = new ExtendedCursor(
- cursor, CallLogQuery.SECTION_NAME, CallLogQuery.SECTION_NEW_ITEM);
- } else if (token == QUERY_OLD_CALLS_TOKEN) {
- int requestId = ((Integer) cookie).intValue();
- if (requestId != mCallsRequestId) {
- // Ignore this query since it does not correspond to the latest request.
- return;
- }
-
- // Store the returned cursor.
- MoreCloseables.closeQuietly(mOldCallsCursor);
- mOldCallsCursor = new ExtendedCursor(
- cursor, CallLogQuery.SECTION_NAME, CallLogQuery.SECTION_OLD_ITEM);
+ MoreCloseables.closeQuietly(mCallLogCursor);
+ mCallLogCursor = cursor;
} else if (token == QUERY_VOICEMAIL_STATUS_TOKEN) {
updateVoicemailStatus(cursor);
return;
@@ -300,38 +244,9 @@ import javax.annotation.concurrent.GuardedBy;
return;
}
- if (mNewCallsCursor != null && mOldCallsCursor != null) {
- updateAdapterData(createMergedCursor());
- }
- }
-
- /** Creates the merged cursor representing the data to show in the call log. */
- @GuardedBy("this")
- private Cursor createMergedCursor() {
- try {
- final boolean hasNewCalls = mNewCallsCursor.getCount() != 0;
- final boolean hasOldCalls = mOldCallsCursor.getCount() != 0;
-
- if (!hasNewCalls) {
- // Return only the old calls, without the header.
- MoreCloseables.closeQuietly(mNewCallsCursor);
- return mOldCallsCursor;
- }
-
- if (!hasOldCalls) {
- // Return only the new calls.
- MoreCloseables.closeQuietly(mOldCallsCursor);
- return new MergeCursor(
- new Cursor[]{ createNewCallsHeaderCursor(), mNewCallsCursor });
- }
-
- return new MergeCursor(new Cursor[]{
- createNewCallsHeaderCursor(), mNewCallsCursor,
- createOldCallsHeaderCursor(), mOldCallsCursor});
- } finally {
- // Any cursor still open is now owned, directly or indirectly, by the caller.
- mNewCallsCursor = null;
- mOldCallsCursor = null;
+ if (mCallLogCursor != null) {
+ updateAdapterData(mCallLogCursor);
+ mCallLogCursor = null;
}
}