From 5069efed6b85eea5cdccced366334e139b6b5360 Mon Sep 17 00:00:00 2001 From: Brandon Maxwell Date: Wed, 2 Dec 2015 17:06:19 -0800 Subject: Fixing where clause issue with call log query Change-Id: Ib4baa544925f8bcc6b8f4df8989927ebb3635ce3 --- .../dialer/calllog/CallLogQueryHandler.java | 31 +++++++--------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/com/android/dialer/calllog/CallLogQueryHandler.java b/src/com/android/dialer/calllog/CallLogQueryHandler.java index d99284698..559cf97b2 100644 --- a/src/com/android/dialer/calllog/CallLogQueryHandler.java +++ b/src/com/android/dialer/calllog/CallLogQueryHandler.java @@ -50,8 +50,6 @@ import java.util.List; /** Handles asynchronous queries to the call log. */ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { - private static final String[] EMPTY_STRING_ARRAY = new String[0]; - private static final String TAG = "CallLogQueryHandler"; private static final int NUM_LOGS_TO_DISPLAY = 1000; @@ -162,27 +160,25 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { /** Fetches the list of calls in the call log. */ private void fetchCalls(int token, int callType, boolean newOnly, long newerThan) { - // 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". StringBuilder where = new StringBuilder(); List selectionArgs = Lists.newArrayList(); + // Always hide blocked calls. + where.append("(").append(Calls.TYPE).append(" != ?)"); + selectionArgs.add(Integer.toString(AppCompatConstants.CALLS_BLOCKED_TYPE)); + // Ignore voicemails marked as deleted if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M) >= Build.VERSION_CODES.M) { - where.append(Voicemails.DELETED).append(" = 0"); + where.append(" AND (").append(Voicemails.DELETED).append(" = 0)"); } if (newOnly) { - where.append(" AND "); - where.append(Calls.NEW); - where.append(" = 1"); + where.append(" AND (").append(Calls.NEW).append(" = 1)"); } if (callType > CALL_TYPE_ALL) { - where.append(" AND "); - where.append("(" + Calls.TYPE + " = ?)"); + where.append(" AND (").append(Calls.TYPE).append(" = ?)"); selectionArgs.add(Integer.toString(callType)); } else { where.append(" AND NOT "); @@ -190,24 +186,17 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { } if (newerThan > 0) { - where.append(" AND "); - where.append("(" + Calls.DATE + " > ?)"); + where.append(" AND (").append(Calls.DATE).append(" > ?)"); selectionArgs.add(Long.toString(newerThan)); } - // Always hide blocked calls. - where.append(" AND "); - where.append("(" + Calls.TYPE + " != ?)"); - selectionArgs.add(Integer.toString(AppCompatConstants.CALLS_BLOCKED_TYPE)); - final int limit = (mLogLimit == -1) ? NUM_LOGS_TO_DISPLAY : mLogLimit; final String selection = where.length() > 0 ? where.toString() : null; Uri uri = TelecomUtil.getCallLogUri(mContext).buildUpon() .appendQueryParameter(Calls.LIMIT_PARAM_KEY, Integer.toString(limit)) .build(); - startQuery(token, null, uri, - CallLogQuery._PROJECTION, selection, selectionArgs.toArray(EMPTY_STRING_ARRAY), - Calls.DEFAULT_SORT_ORDER); + startQuery(token, null, uri, CallLogQuery._PROJECTION, selection, selectionArgs.toArray( + new String[selectionArgs.size()]), Calls.DEFAULT_SORT_ORDER); } /** Cancel any pending fetch request. */ -- cgit v1.2.3