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

Commit bf827793 authored by Robert Gross's avatar Robert Gross
Browse files

Fix incorrect handling of undefined call-screening service

If registration of call-screening service fails (by default it is not
available), the disconnection of said service is still attempted
throwing an error due to an attempt to unregister a receiver that
doesn't exist.

Test: manual testing and unit test
Bug: 189464381
Change-Id: Ic96dfd09e03f3d1b9da8730273e868699b1a9b39
Merged-In: Ib25cb5b0324e95b9cda3e09bf428e11e2b79601e
parent 1a384081
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -313,11 +313,15 @@ public class CallScreeningServiceFilter extends CallFilter {

    private void bindCallScreeningService(
            CompletableFuture<CallFilteringResult> resultFuture) {
        mConnection = new CallScreeningServiceConnection(resultFuture);
        CallScreeningServiceConnection connection = new CallScreeningServiceConnection(
                resultFuture);
        if (!CallScreeningServiceHelper.bindCallScreeningService(mContext,
                mCallsManager.getCurrentUserHandle(), mPackageName, mConnection)) {
                mCallsManager.getCurrentUserHandle(), mPackageName, connection)) {
            Log.i(this, "Call screening service binding failed.");
            resultFuture.complete(mPriorStageResult);
            mConnection = null;
        } else {
            mConnection = connection;
        }
    }

+20 −1
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock;

import java.util.Collections;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit;

@@ -229,10 +230,28 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {
        CallScreeningServiceFilter filter = new CallScreeningServiceFilter(mCall, PKG_NAME,
                CallScreeningServiceFilter.PACKAGE_TYPE_CARRIER, mContext, mCallsManager,
                mAppLabelProxy, mParcelableCallUtilsConverter);
        filter.startFilterLookup(inputResult);
        CompletableFuture<CallFilteringResult> result = filter.startFilterLookup(inputResult)
                .toCompletableFuture();

        assertEquals(result.isDone(), false);

        filter.unbindCallScreeningService();
    }

    @SmallTest
    @Test
    public void testBindingFailed() {
        // Use an empty package name here, which fails in the bindCallScreeningService.
        CallScreeningServiceFilter filter = new CallScreeningServiceFilter(mCall, "",
                CallScreeningServiceFilter.PACKAGE_TYPE_CARRIER, mContext, mCallsManager,
                mAppLabelProxy, mParcelableCallUtilsConverter);

        CompletableFuture<CallFilteringResult> result = filter.startFilterLookup(inputResult)
                .toCompletableFuture();

        assertEquals(result.isDone(), true);
    }

    @SmallTest
    @Test
    public void testAllowCall() throws Exception {