Loading src/com/android/server/telecom/Call.java +4 −1 Original line number Diff line number Diff line Loading @@ -1831,7 +1831,10 @@ public class Call implements CreateConnectionResponse { */ private void setCallerInfo(Uri handle, CallerInfo callerInfo) { Trace.beginSection("setCallerInfo"); Preconditions.checkNotNull(callerInfo); if (callerInfo == null) { Log.i(this, "CallerInfo lookup returned null, skipping update"); return; } if (!handle.equals(mHandle)) { Log.i(this, "setCallerInfo received stale caller info for an old handle. Ignoring."); Loading src/com/android/server/telecom/CallerInfoLookupHelper.java +5 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.telecom; import android.annotation.Nullable; import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; Loading @@ -41,7 +42,7 @@ public class CallerInfoLookupHelper { * @param info * @return true if the value should be cached, false otherwise. */ void onCallerInfoQueryComplete(Uri handle, CallerInfo info); void onCallerInfoQueryComplete(Uri handle, @Nullable CallerInfo info); void onContactPhotoQueryComplete(Uri handle, CallerInfo info); } Loading @@ -54,6 +55,7 @@ public class CallerInfoLookupHelper { listeners = new LinkedList<>(); } } private final Map<Uri, CallerInfoQueryInfo> mQueryEntries = new HashMap<>(); private final CallerInfoAsyncQueryFactory mCallerInfoAsyncQueryFactory; Loading @@ -74,11 +76,13 @@ public class CallerInfoLookupHelper { public void startLookup(final Uri handle, OnQueryCompleteListener listener) { if (handle == null) { listener.onCallerInfoQueryComplete(handle, null); return; } final String number = handle.getSchemeSpecificPart(); if (TextUtils.isEmpty(number)) { listener.onCallerInfoQueryComplete(handle, null); return; } Loading src/com/android/server/telecom/callfiltering/DirectToVoicemailCallFilter.java +5 −2 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ import com.android.server.telecom.Call; import com.android.server.telecom.CallerInfoLookupHelper; import com.android.server.telecom.Log; import java.util.Objects; public class DirectToVoicemailCallFilter implements IncomingCallFilter.CallFilter { private final CallerInfoLookupHelper mCallerInfoLookupHelper; Loading @@ -34,13 +36,14 @@ public class DirectToVoicemailCallFilter implements IncomingCallFilter.CallFilte public void startFilterLookup(final Call call, CallFilterResultCallback callback) { Log.event(call, Log.Events.DIRECT_TO_VM_INITIATED); final Uri callHandle = call.getHandle(); mCallerInfoLookupHelper.startLookup(callHandle, new CallerInfoLookupHelper.OnQueryCompleteListener() { @Override public void onCallerInfoQueryComplete(Uri handle, CallerInfo info) { CallFilteringResult result; if (callHandle.equals(handle)) { if (info.shouldSendToVoicemail) { if (Objects.equals(callHandle, handle)) { if (info != null && info.shouldSendToVoicemail) { result = new CallFilteringResult( false, // shouldAllowCall true, // shouldReject Loading tests/src/com/android/server/telecom/tests/CallerInfoLookupHelperTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.test.suitebuilder.annotation.SmallTest; import com.android.internal.telephony.CallerInfo; import com.android.internal.telephony.CallerInfoAsyncQuery; Loading @@ -43,6 +44,7 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.isNull; import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; Loading Loading @@ -93,6 +95,16 @@ public class CallerInfoLookupHelperTest extends TelecomTestCase { } } @SmallTest public void testLookupWithEmptyHandle() { CallerInfoLookupHelper.OnQueryCompleteListener listener = mock( CallerInfoLookupHelper.OnQueryCompleteListener.class); mCallerInfoLookupHelper.startLookup(Uri.EMPTY, listener); verify(listener).onCallerInfoQueryComplete(eq(Uri.EMPTY), isNull(CallerInfo.class)); verifyProperCleanup(); } public void testSimpleLookup() { CallerInfoLookupHelper.OnQueryCompleteListener listener = mock( CallerInfoLookupHelper.OnQueryCompleteListener.class); Loading tests/src/com/android/server/telecom/tests/DirectToVoicemailCallFilterTest.java +20 −2 Original line number Diff line number Diff line Loading @@ -42,7 +42,6 @@ public class DirectToVoicemailCallFilterTest extends TelecomTestCase { public void setUp() throws Exception { super.setUp(); when(mCall.getHandle()).thenReturn(TEST_HANDLE); } @SmallTest Loading Loading @@ -79,13 +78,32 @@ public class DirectToVoicemailCallFilterTest extends TelecomTestCase { )); } @SmallTest public void testNullResponseFromLookupHelper() { CallerInfoLookupHelper.OnQueryCompleteListener queryListener = verifyLookupStart(null); queryListener.onCallerInfoQueryComplete(null, null); verify(mCallback).onCallFilteringComplete(mCall, new CallFilteringResult( true, // shouldAllowCall false, // shouldReject true, // shouldAddToCallLog true // shouldShowNotification )); } private CallerInfoLookupHelper.OnQueryCompleteListener verifyLookupStart() { return verifyLookupStart(TEST_HANDLE); } private CallerInfoLookupHelper.OnQueryCompleteListener verifyLookupStart(Uri handle) { when(mCall.getHandle()).thenReturn(handle); DirectToVoicemailCallFilter filter = new DirectToVoicemailCallFilter(mCallerInfoLookupHelper); filter.startFilterLookup(mCall, mCallback); ArgumentCaptor<CallerInfoLookupHelper.OnQueryCompleteListener> captor = ArgumentCaptor.forClass(CallerInfoLookupHelper.OnQueryCompleteListener.class); verify(mCallerInfoLookupHelper).startLookup(eq(TEST_HANDLE), captor.capture()); verify(mCallerInfoLookupHelper).startLookup(eq(handle), captor.capture()); return captor.getValue(); } } Loading
src/com/android/server/telecom/Call.java +4 −1 Original line number Diff line number Diff line Loading @@ -1831,7 +1831,10 @@ public class Call implements CreateConnectionResponse { */ private void setCallerInfo(Uri handle, CallerInfo callerInfo) { Trace.beginSection("setCallerInfo"); Preconditions.checkNotNull(callerInfo); if (callerInfo == null) { Log.i(this, "CallerInfo lookup returned null, skipping update"); return; } if (!handle.equals(mHandle)) { Log.i(this, "setCallerInfo received stale caller info for an old handle. Ignoring."); Loading
src/com/android/server/telecom/CallerInfoLookupHelper.java +5 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.telecom; import android.annotation.Nullable; import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; Loading @@ -41,7 +42,7 @@ public class CallerInfoLookupHelper { * @param info * @return true if the value should be cached, false otherwise. */ void onCallerInfoQueryComplete(Uri handle, CallerInfo info); void onCallerInfoQueryComplete(Uri handle, @Nullable CallerInfo info); void onContactPhotoQueryComplete(Uri handle, CallerInfo info); } Loading @@ -54,6 +55,7 @@ public class CallerInfoLookupHelper { listeners = new LinkedList<>(); } } private final Map<Uri, CallerInfoQueryInfo> mQueryEntries = new HashMap<>(); private final CallerInfoAsyncQueryFactory mCallerInfoAsyncQueryFactory; Loading @@ -74,11 +76,13 @@ public class CallerInfoLookupHelper { public void startLookup(final Uri handle, OnQueryCompleteListener listener) { if (handle == null) { listener.onCallerInfoQueryComplete(handle, null); return; } final String number = handle.getSchemeSpecificPart(); if (TextUtils.isEmpty(number)) { listener.onCallerInfoQueryComplete(handle, null); return; } Loading
src/com/android/server/telecom/callfiltering/DirectToVoicemailCallFilter.java +5 −2 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ import com.android.server.telecom.Call; import com.android.server.telecom.CallerInfoLookupHelper; import com.android.server.telecom.Log; import java.util.Objects; public class DirectToVoicemailCallFilter implements IncomingCallFilter.CallFilter { private final CallerInfoLookupHelper mCallerInfoLookupHelper; Loading @@ -34,13 +36,14 @@ public class DirectToVoicemailCallFilter implements IncomingCallFilter.CallFilte public void startFilterLookup(final Call call, CallFilterResultCallback callback) { Log.event(call, Log.Events.DIRECT_TO_VM_INITIATED); final Uri callHandle = call.getHandle(); mCallerInfoLookupHelper.startLookup(callHandle, new CallerInfoLookupHelper.OnQueryCompleteListener() { @Override public void onCallerInfoQueryComplete(Uri handle, CallerInfo info) { CallFilteringResult result; if (callHandle.equals(handle)) { if (info.shouldSendToVoicemail) { if (Objects.equals(callHandle, handle)) { if (info != null && info.shouldSendToVoicemail) { result = new CallFilteringResult( false, // shouldAllowCall true, // shouldReject Loading
tests/src/com/android/server/telecom/tests/CallerInfoLookupHelperTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.test.suitebuilder.annotation.SmallTest; import com.android.internal.telephony.CallerInfo; import com.android.internal.telephony.CallerInfoAsyncQuery; Loading @@ -43,6 +44,7 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.isNull; import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; Loading Loading @@ -93,6 +95,16 @@ public class CallerInfoLookupHelperTest extends TelecomTestCase { } } @SmallTest public void testLookupWithEmptyHandle() { CallerInfoLookupHelper.OnQueryCompleteListener listener = mock( CallerInfoLookupHelper.OnQueryCompleteListener.class); mCallerInfoLookupHelper.startLookup(Uri.EMPTY, listener); verify(listener).onCallerInfoQueryComplete(eq(Uri.EMPTY), isNull(CallerInfo.class)); verifyProperCleanup(); } public void testSimpleLookup() { CallerInfoLookupHelper.OnQueryCompleteListener listener = mock( CallerInfoLookupHelper.OnQueryCompleteListener.class); Loading
tests/src/com/android/server/telecom/tests/DirectToVoicemailCallFilterTest.java +20 −2 Original line number Diff line number Diff line Loading @@ -42,7 +42,6 @@ public class DirectToVoicemailCallFilterTest extends TelecomTestCase { public void setUp() throws Exception { super.setUp(); when(mCall.getHandle()).thenReturn(TEST_HANDLE); } @SmallTest Loading Loading @@ -79,13 +78,32 @@ public class DirectToVoicemailCallFilterTest extends TelecomTestCase { )); } @SmallTest public void testNullResponseFromLookupHelper() { CallerInfoLookupHelper.OnQueryCompleteListener queryListener = verifyLookupStart(null); queryListener.onCallerInfoQueryComplete(null, null); verify(mCallback).onCallFilteringComplete(mCall, new CallFilteringResult( true, // shouldAllowCall false, // shouldReject true, // shouldAddToCallLog true // shouldShowNotification )); } private CallerInfoLookupHelper.OnQueryCompleteListener verifyLookupStart() { return verifyLookupStart(TEST_HANDLE); } private CallerInfoLookupHelper.OnQueryCompleteListener verifyLookupStart(Uri handle) { when(mCall.getHandle()).thenReturn(handle); DirectToVoicemailCallFilter filter = new DirectToVoicemailCallFilter(mCallerInfoLookupHelper); filter.startFilterLookup(mCall, mCallback); ArgumentCaptor<CallerInfoLookupHelper.OnQueryCompleteListener> captor = ArgumentCaptor.forClass(CallerInfoLookupHelper.OnQueryCompleteListener.class); verify(mCallerInfoLookupHelper).startLookup(eq(TEST_HANDLE), captor.capture()); verify(mCallerInfoLookupHelper).startLookup(eq(handle), captor.capture()); return captor.getValue(); } }