Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7bece85a authored by Hall Liu's avatar Hall Liu Committed by Android (Google) Code Review
Browse files

Merge "Fixed an issue in VoicemailCallFilter process timeouts." into nyc-mr1-dev

parents 00667fc0 f2373e17
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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.");
+5 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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);
    }

@@ -54,6 +55,7 @@ public class CallerInfoLookupHelper {
            listeners = new LinkedList<>();
        }
    }

    private final Map<Uri, CallerInfoQueryInfo> mQueryEntries = new HashMap<>();

    private final CallerInfoAsyncQueryFactory mCallerInfoAsyncQueryFactory;
@@ -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;
        }

+5 −2
Original line number Diff line number Diff line
@@ -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;

@@ -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
+12 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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);
+20 −2
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ public class DirectToVoicemailCallFilterTest extends TelecomTestCase {

    public void setUp() throws Exception {
        super.setUp();
        when(mCall.getHandle()).thenReturn(TEST_HANDLE);
    }

    @SmallTest
@@ -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();
    }
}