From 0839b1eccc8e373e01d96cc97f079b1ce44b5d33 Mon Sep 17 00:00:00 2001 From: Sarmad Hashmi Date: Sat, 9 Apr 2016 22:18:12 -0700 Subject: Add after call notification code in InCallUI. +Add asynchronous call to update inCallHistory boolean variable which specifies whether the number is in the call history (has previously called before) +Add CallHistoryStatus enum and variable to Call object to determine if the number is present in the call history +Added SpamCallListListener object which listens for changes in the CallList +Update the CallHistoryStatus for the call whenever an incoming call comes in +Added 11 tests for new listener BUG=27323295 Change-Id: I242cd4a53b3aeca69fbce972221a2c941d9d37ce --- .../dialer/calllog/CallLogAsyncTaskUtil.java | 44 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'src/com') diff --git a/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java b/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java index 34b2f0ea9..b95d58e26 100644 --- a/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java +++ b/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java @@ -17,6 +17,7 @@ package com.android.dialer.calllog; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; import android.content.ContentResolver; import android.content.ContentValues; @@ -58,7 +59,8 @@ public class CallLogAsyncTaskUtil { MARK_VOICEMAIL_READ, MARK_CALL_READ, GET_CALL_DETAILS, - UPDATE_DURATION + UPDATE_DURATION, + GET_NUMBER_IN_CALL_HISTORY } private static final class CallDetailQuery { @@ -122,6 +124,10 @@ public class CallLogAsyncTaskUtil { void onGetCallDetails(PhoneCallDetails[] details); } + public interface OnGetNumberInCallHistoryListener { + void onComplete(boolean inCallHistory); + } + public interface OnCallLogQueryFinishedListener { void onQueryFinished(boolean hasEntry); } @@ -456,6 +462,42 @@ public class CallLogAsyncTaskUtil { }); } + /** + * Checks if the number is in the call history. + */ + public static void getNumberInCallHistory( + final Context context, + final String number, + final OnGetNumberInCallHistoryListener listener) { + Preconditions.checkNotNull(listener); + if (!PermissionsUtil.hasPhonePermissions(context)) { + return; + } + if (sAsyncTaskExecutor == null) { + initTaskExecutor(); + } + + sAsyncTaskExecutor.submit(Tasks.GET_NUMBER_IN_CALL_HISTORY, + new AsyncTask() { + @Override + public Boolean doInBackground(Void... params) { + try (Cursor cursor = context.getContentResolver().query( + TelecomUtil.getCallLogUri(context), + new String[] {CallLog.Calls._ID}, + CallLog.Calls.NUMBER + " = ?", + new String[] {number}, + null)) { + return cursor != null && cursor.getCount() > 0; + } + } + + @Override + public void onPostExecute(Boolean inCallHistory) { + listener.onComplete(inCallHistory); + } + }); + } + @VisibleForTesting public static void resetForTest() { sAsyncTaskExecutor = null; -- cgit v1.2.3