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

Commit 3e2094cd authored by Tyler Gunn's avatar Tyler Gunn Committed by Hall Liu
Browse files

Ensure we only bind to CallScreeningService once.

Where the default dialer also fills the caller ID and spam role, ensure
that we only bind to the underlying CallScreeningService once.

Bug: 140950071
Test: Manual test by setting default dialer as the caller id and spam
role filler; verify we only bind once in Telecom logs.
Test: Added new unit test to ensure Callscreeningservicecontroller only
binds a single time.

Change-Id: Ib8c46b409ab69f43e04ba882c97545d7028ff764
parent 739118f6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -137,6 +137,7 @@ public class LogUtils {
        public static final String BIND_SCREENING = "BIND_SCREENING";
        public static final String SCREENING_BOUND = "SCREENING_BOUND";
        public static final String SCREENING_SENT = "SCREENING_SENT";
        public static final String SCREENING_SKIPPED = "SCREENING_SKIPPED";
        public static final String CONTROLLER_SCREENING_COMPLETED =
                "CONTROLLER_SCREENING_COMPLETED";
        public static final String SCREENING_COMPLETED = "SCREENING_COMPLETED";
+12 −4
Original line number Diff line number Diff line
@@ -194,12 +194,20 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi
            String userChosenPackageName = getUserChosenPackageName();
            if (TextUtils.isEmpty(userChosenPackageName)) {
                mIsUserChosenFinished = true;
            } else {
                // If the user chosen call screening service is the same as the default dialer, then
                // we have already bound to it above and don't need to do so again here.
                if (userChosenPackageName.equals(dialerPackageName)) {
                    Log.addEvent(mCall, LogUtils.Events.SCREENING_SKIPPED,
                            "user pkg same as dialer: " + userChosenPackageName);
                    mIsUserChosenFinished = true;
                } else {
                    createCallScreeningServiceFilter().startCallScreeningFilter(mCall,
                            CallScreeningServiceController.this, userChosenPackageName,
                            mAppLabelProxy.getAppLabel(userChosenPackageName),
                            CallScreeningServiceFilter.CALL_SCREENING_FILTER_TYPE_USER_SELECTED);
                }
            }

            if (mIsDefaultDialerFinished && mIsUserChosenFinished) {
                finishCallScreening();
+63 −0
Original line number Diff line number Diff line
@@ -356,6 +356,69 @@ public class CallScreeningServiceControllerTest extends TelecomTestCase {
        )));
    }

    /**
     * This test verifies that where the default dialer role is filled by the same app as the caller
     * id and spam role, we will only bind to that call screening service once.
     */
    @SmallTest
    @Test
    public void testOnlyBindOnce() {
        // Assume the user chose the default dialer to also fill the caller id and spam role.
        when(mRoleManagerAdapter.getDefaultCallScreeningApp()).thenReturn(
                DEFAULT_DIALER_CALL_SCREENING.getPackageName());
        CallScreeningServiceController controller = new CallScreeningServiceController(mContext,
                mCallsManager,
                mPhoneAccountRegistrar, mParcelableCallUtilsConverter, mLock,
                mSettingsSecureAdapter, mCallerInfoLookupHelper, mAppLabelProxy);

        controller.startFilterLookup(mCall, mCallback);

        controller.onCallScreeningFilterComplete(mCall, PASS_RESULT,
                CARRIER_DEFINED_CALL_SCREENING.getPackageName());

        CallerInfoLookupHelper.OnQueryCompleteListener queryListener = verifyLookupStart();
        CallerInfo callerInfo = new CallerInfo();
        callerInfo.contactExists = false;
        queryListener.onCallerInfoQueryComplete(TEST_HANDLE, callerInfo);

        controller.onCallScreeningFilterComplete(mCall, new CallFilteringResult(
                        false, // shouldAllowCall
                        true, // shouldReject
                        false, // shouldAddToCallLog
                        true, // shouldShowNotification
                        CallLog.Calls.BLOCK_REASON_CALL_SCREENING_SERVICE,
                        APP_NAME,
                        DEFAULT_DIALER_CALL_SCREENING.flattenToString()
                ),
                DEFAULT_DIALER_CALL_SCREENING.getPackageName());
        controller.onCallScreeningFilterComplete(mCall, new CallFilteringResult(
                false, // shouldAllowCall
                true, // shouldReject
                false, // shouldAddToCallLog
                true, // shouldShowNotification
                CallLog.Calls.BLOCK_REASON_CALL_SCREENING_SERVICE,
                APP_NAME,
                DEFAULT_DIALER_CALL_SCREENING.flattenToString()
        ), USER_CHOSEN_CALL_SCREENING.getPackageName());

        // Expect to bind twice; once to the carrier defined service, and then again to the default
        // dialer.
        verify(mContext, times(2)).bindServiceAsUser(any(Intent.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE),
                eq(UserHandle.CURRENT));

        // Expect filtering to complete only a single time from the default dialer service.
        verify(mCallback, times(1)).onCallFilteringComplete(eq(mCall), eq(new CallFilteringResult(
                false, // shouldAllowCall
                true, // shouldReject
                true, // shouldAddToCallLog
                true, // shouldShowNotification
                CallLog.Calls.BLOCK_REASON_CALL_SCREENING_SERVICE,
                APP_NAME,
                DEFAULT_DIALER_CALL_SCREENING.flattenToString()
        )));    }

    private CallerInfoLookupHelper.OnQueryCompleteListener verifyLookupStart() {
        return verifyLookupStart(TEST_HANDLE);
    }