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

Commit eee4a828 authored by Hall Liu's avatar Hall Liu
Browse files

Refactor CallFilteringResult to use a builder

In preparation for adding yet another field to CallFilteringResult, make
it use a builder pattern so we don't end up with a longer chain of
constructors.

Bug: 140317205
Test: unit
Change-Id: I60816545c28ec84f24a499067662ac32cd00d3e9
parent 3e2094cd
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ import com.android.server.telecom.callfiltering.AsyncBlockCheckFilter;
import com.android.server.telecom.callfiltering.BlockCheckerAdapter;
import com.android.server.telecom.callfiltering.CallFilterResultCallback;
import com.android.server.telecom.callfiltering.CallFilteringResult;
import com.android.server.telecom.callfiltering.CallFilteringResult.Builder;
import com.android.server.telecom.callfiltering.CallScreeningServiceController;
import com.android.server.telecom.callfiltering.DirectToVoicemailCallFilter;
import com.android.server.telecom.callfiltering.IncomingCallFilter;
@@ -609,7 +610,12 @@ public class CallsManager extends Call.ListenerBase
                    incomingCall.hasProperty(Connection.PROPERTY_EMERGENCY_CALLBACK_MODE),
                    incomingCall.isSelfManaged(),
                    extras.getBoolean(PhoneAccount.EXTRA_SKIP_CALL_FILTERING));
            onCallFilteringComplete(incomingCall, new CallFilteringResult(true, false, true, true));
            onCallFilteringComplete(incomingCall, new Builder()
                    .setShouldAllowCall(true)
                    .setShouldReject(false)
                    .setShouldAddToCallLog(true)
                    .setShouldShowNotification(true)
                    .build());
            incomingCall.setIsUsingCallFiltering(false);
            return;
        }
+16 −15
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.internal.telephony.CallerInfo;
import com.android.server.telecom.Call;
import com.android.server.telecom.CallerInfoLookupHelper;
import com.android.server.telecom.LogUtils;
import com.android.server.telecom.callfiltering.CallFilteringResult.Builder;
import com.android.server.telecom.settings.BlockedNumbersUtil;

/**
@@ -121,15 +122,15 @@ public class AsyncBlockCheckFilter extends AsyncTask<String, Void, Boolean>
        try {
            CallFilteringResult result;
            if (isBlocked) {
                result = new CallFilteringResult(
                        false, // shouldAllowCall
                        true, //shouldReject
                        true, //shouldAddToCallLog
                        false, // shouldShowNotification
                        convertBlockStatusToReason(), //callBlockReason
                        null, //callScreeningAppName
                        null //callScreeningComponentName
                );
                result = new Builder()
                        .setShouldAllowCall(false)
                        .setShouldReject(true)
                        .setShouldAddToCallLog(true)
                        .setShouldShowNotification(false)
                        .setCallBlockReason(convertBlockStatusToReason())
                        .setCallScreeningAppName(null)
                        .setCallScreeningComponentName(null)
                        .build();
                if (mCallBlockListener != null) {
                    String number = mIncomingCall.getHandle() == null ? null
                            : mIncomingCall.getHandle().getSchemeSpecificPart();
@@ -137,12 +138,12 @@ public class AsyncBlockCheckFilter extends AsyncTask<String, Void, Boolean>
                            mIncomingCall.getInitiatingUser());
                }
            } else {
                result = new CallFilteringResult(
                        true, // shouldAllowCall
                        false, // shouldReject
                        true, // shouldAddToCallLog
                        true // shouldShowNotification
                );
                result = new Builder()
                        .setShouldAllowCall(true)
                        .setShouldReject(false)
                        .setShouldAddToCallLog(true)
                        .setShouldShowNotification(true)
                        .build();
            }
            Log.addEvent(mIncomingCall, LogUtils.Events.BLOCK_CHECK_FINISHED,
                    BlockedNumberContract.SystemContract.blockStatusToString(mBlockStatus) + " "
+78 −50
Original line number Diff line number Diff line
@@ -21,47 +21,73 @@ import android.provider.CallLog.Calls;
import android.text.TextUtils;

public class CallFilteringResult {
    public boolean shouldAllowCall;
    public boolean shouldReject;
    public boolean shouldSilence;
    public boolean shouldAddToCallLog;
    public boolean shouldShowNotification;
    public int mCallBlockReason = CallLog.Calls.BLOCK_REASON_NOT_BLOCKED;
    public CharSequence mCallScreeningAppName = null;
    public String mCallScreeningComponentName = null;
    public static class Builder {
        private boolean mShouldAllowCall;
        private boolean mShouldReject;
        private boolean mShouldAddToCallLog;
        private boolean mShouldShowNotification;
        private boolean mShouldSilence = false;
        private int mCallBlockReason = Calls.BLOCK_REASON_NOT_BLOCKED;
        private CharSequence mCallScreeningAppName = null;
        private String mCallScreeningComponentName = null;

        public Builder setShouldAllowCall(boolean shouldAllowCall) {
            mShouldAllowCall = shouldAllowCall;
            return this;
        }

    public CallFilteringResult(boolean shouldAllowCall, boolean shouldReject, boolean
            shouldAddToCallLog, boolean shouldShowNotification) {
        this.shouldAllowCall = shouldAllowCall;
        this.shouldReject = shouldReject;
        this.shouldSilence = false;
        this.shouldAddToCallLog = shouldAddToCallLog;
        this.shouldShowNotification = shouldShowNotification;
        public Builder setShouldReject(boolean shouldReject) {
            mShouldReject = shouldReject;
            return this;
        }

    public CallFilteringResult(boolean shouldAllowCall, boolean shouldReject, boolean
            shouldAddToCallLog, boolean shouldShowNotification, int callBlockReason,
            CharSequence callScreeningAppName, String callScreeningComponentName) {
        this.shouldAllowCall = shouldAllowCall;
        this.shouldReject = shouldReject;
        this.shouldSilence = false;
        this.shouldAddToCallLog = shouldAddToCallLog;
        this.shouldShowNotification = shouldShowNotification;
        this.mCallBlockReason = callBlockReason;
        this.mCallScreeningAppName = callScreeningAppName;
        this.mCallScreeningComponentName = callScreeningComponentName;
        public Builder setShouldAddToCallLog(boolean shouldAddToCallLog) {
            mShouldAddToCallLog = shouldAddToCallLog;
            return this;
        }

    public CallFilteringResult(boolean shouldAllowCall, boolean shouldReject, boolean
            shouldSilence, boolean shouldAddToCallLog, boolean shouldShowNotification) {
        this.shouldAllowCall = shouldAllowCall;
        this.shouldReject = shouldReject;
        this.shouldSilence = shouldSilence;
        this.shouldAddToCallLog = shouldAddToCallLog;
        this.shouldShowNotification = shouldShowNotification;
        public Builder setShouldShowNotification(boolean shouldShowNotification) {
            mShouldShowNotification = shouldShowNotification;
            return this;
        }

        public Builder setShouldSilence(boolean shouldSilence) {
            mShouldSilence = shouldSilence;
            return this;
        }

        public Builder setCallBlockReason(int callBlockReason) {
            mCallBlockReason = callBlockReason;
            return this;
        }

        public Builder setCallScreeningAppName(CharSequence callScreeningAppName) {
            mCallScreeningAppName = callScreeningAppName;
            return this;
        }

        public Builder setCallScreeningComponentName(String callScreeningComponentName) {
            mCallScreeningComponentName = callScreeningComponentName;
            return this;
        }

        public CallFilteringResult build() {
            return new CallFilteringResult(mShouldAllowCall, mShouldReject, mShouldSilence,
                    mShouldAddToCallLog, mShouldShowNotification, mCallBlockReason,
                    mCallScreeningAppName, mCallScreeningComponentName);
        }
    }

    public CallFilteringResult(boolean shouldAllowCall, boolean shouldReject, boolean
    public boolean shouldAllowCall;
    public boolean shouldReject;
    public boolean shouldSilence;
    public boolean shouldAddToCallLog;
    public boolean shouldShowNotification;
    public int mCallBlockReason;
    public CharSequence mCallScreeningAppName;
    public String mCallScreeningComponentName;

    private CallFilteringResult(boolean shouldAllowCall, boolean shouldReject, boolean
            shouldSilence, boolean shouldAddToCallLog, boolean shouldShowNotification, int
            callBlockReason, CharSequence callScreeningAppName, String callScreeningComponentName) {
        this.shouldAllowCall = shouldAllowCall;
@@ -109,12 +135,13 @@ public class CallFilteringResult {
                other.mCallScreeningAppName, other.mCallScreeningComponentName);
        }

        return new CallFilteringResult(
            shouldAllowCall && other.shouldAllowCall,
            shouldReject || other.shouldReject,
            shouldSilence || other.shouldSilence,
            shouldAddToCallLog && other.shouldAddToCallLog,
            shouldShowNotification && other.shouldShowNotification);
        return new Builder()
                .setShouldAllowCall(shouldAllowCall && other.shouldAllowCall)
                .setShouldReject(shouldReject || other.shouldReject)
                .setShouldSilence(shouldSilence || other.shouldSilence)
                .setShouldAddToCallLog(shouldAddToCallLog && other.shouldAddToCallLog)
                .setShouldShowNotification(shouldShowNotification && other.shouldShowNotification)
                .build();
    }

    private boolean isBlockedByProvider(int blockReason) {
@@ -131,15 +158,16 @@ public class CallFilteringResult {

    private CallFilteringResult getCombinedCallFilteringResult(CallFilteringResult other,
        int callBlockReason, CharSequence callScreeningAppName, String callScreeningComponentName) {
        return new CallFilteringResult(
            shouldAllowCall && other.shouldAllowCall,
            shouldReject || other.shouldReject,
            shouldSilence|| other.shouldSilence,
            shouldAddToCallLog && other.shouldAddToCallLog,
            shouldShowNotification && other.shouldShowNotification,
            callBlockReason,
            callScreeningAppName,
            callScreeningComponentName);
        return new Builder()
                .setShouldAllowCall(shouldAllowCall && other.shouldAllowCall)
                .setShouldReject(shouldReject || other.shouldReject)
                .setShouldSilence(shouldSilence || other.shouldSilence)
                .setShouldAddToCallLog(shouldAddToCallLog && other.shouldAddToCallLog)
                .setShouldShowNotification(shouldShowNotification && other.shouldShowNotification)
                .setCallBlockReason(callBlockReason)
                .setCallScreeningAppName(callScreeningAppName)
                .setCallScreeningComponentName(callScreeningComponentName)
                .build();
    }


+7 −6
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import com.android.server.telecom.ParcelableCallUtils;
import com.android.server.telecom.PhoneAccountRegistrar;
import com.android.server.telecom.TelecomServiceImpl;
import com.android.server.telecom.TelecomSystem;
import com.android.server.telecom.callfiltering.CallFilteringResult.Builder;

/**
 * This class supports binding to the various {@link android.telecom.CallScreeningService}:
@@ -66,12 +67,12 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi
    private Call mCall;
    private CallFilterResultCallback mCallback;

    private CallFilteringResult mResult = new CallFilteringResult(
            true, // shouldAllowCall
            false, // shouldReject
            true, // shouldAddToCallLog
            true // shouldShowNotification
    );
    private CallFilteringResult mResult = new Builder()
            .setShouldAllowCall(true)
            .setShouldReject(false)
            .setShouldAddToCallLog(true)
            .setShouldShowNotification(true)
            .build();

    private boolean mIsFinished;
    private boolean mIsCarrierFinished;
+32 −31
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ import android.os.IBinder;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.CallLog;
import android.provider.CallLog.Calls;
import android.provider.Settings;
import android.telecom.Log;
import android.telecom.TelecomManager;
@@ -41,6 +41,7 @@ import com.android.server.telecom.ParcelableCallUtils;
import com.android.server.telecom.PhoneAccountRegistrar;
import com.android.server.telecom.TelecomServiceImpl.SettingsSecureAdapter;
import com.android.server.telecom.TelecomSystem;
import com.android.server.telecom.callfiltering.CallFilteringResult.Builder;

/**
 * Binds to {@link ICallScreeningService} to allow call blocking. A single instance of this class
@@ -96,13 +97,13 @@ public class CallScreeningServiceFilter {
                synchronized (mTelecomLock) {
                    Log.d(this, "allowCall(%s)", callId);
                    if (mCall != null && mCall.getId().equals(callId)) {
                        mResult = new CallFilteringResult(
                                true, // shouldAllowCall
                                false, //shouldReject
                                false, //shouldSilence
                                true, //shouldAddToCallLog
                                true // shouldShowNotification
                        );
                        mResult = new Builder()
                                .setShouldAllowCall(true)
                                .setShouldReject(false)
                                .setShouldSilence(false)
                                .setShouldAddToCallLog(true)
                                .setShouldShowNotification(true)
                                .build();
                    } else {
                        Log.w(this, "allowCall, unknown call id: %s", callId);
                    }
@@ -131,16 +132,16 @@ public class CallScreeningServiceFilter {
                                    + "shouldShowNotification: %b", callId, shouldReject,
                            isServiceRequestingLogging, shouldShowNotification);
                    if (mCall != null && mCall.getId().equals(callId)) {
                        mResult = new CallFilteringResult(
                                false, // shouldAllowCall
                                shouldReject, //shouldReject
                                false, // shouldSilenceCall
                                isServiceRequestingLogging, //shouldAddToCallLog
                                shouldShowNotification, // shouldShowNotification
                                CallLog.Calls.BLOCK_REASON_CALL_SCREENING_SERVICE, //callBlockReason
                                mAppName, //callScreeningAppName
                                componentName.flattenToString() //callScreeningComponentName
                        );
                        mResult = new Builder()
                                .setShouldAllowCall(false)
                                .setShouldReject(shouldReject)
                                .setShouldSilence(false)
                                .setShouldAddToCallLog(isServiceRequestingLogging)
                                .setShouldShowNotification(shouldShowNotification)
                                .setCallBlockReason(Calls.BLOCK_REASON_CALL_SCREENING_SERVICE)
                                .setCallScreeningAppName(mAppName)
                                .setCallScreeningComponentName(componentName.flattenToString())
                                .build();
                    } else {
                        Log.w(this, "disallowCall, unknown call id: %s", callId);
                    }
@@ -160,13 +161,13 @@ public class CallScreeningServiceFilter {
                synchronized (mTelecomLock) {
                    Log.d(this, "silenceCall(%s)", callId);
                    if (mCall != null && mCall.getId().equals(callId)) {
                        mResult = new CallFilteringResult(
                                true, // shouldAllowCall
                                false, //shouldReject
                                true, //shouldSilence
                                true, //shouldAddToCallLog
                                true // shouldShowNotification
                        );
                        mResult = new Builder()
                                .setShouldAllowCall(true)
                                .setShouldReject(false)
                                .setShouldSilence(true)
                                .setShouldAddToCallLog(true)
                                .setShouldShowNotification(true)
                                .build();
                    } else {
                        Log.w(this, "silenceCall, unknown call id: %s", callId);
                    }
@@ -199,12 +200,12 @@ public class CallScreeningServiceFilter {
    private boolean mHasFinished = false;
    private int mCallScreeningServiceType;

    private CallFilteringResult mResult = new CallFilteringResult(
            true, // shouldAllowCall
            false, //shouldReject
            true, //shouldAddToCallLog
            true // shouldShowNotification
    );
    private CallFilteringResult mResult = new Builder()
            .setShouldAllowCall(true)
            .setShouldReject(false)
            .setShouldAddToCallLog(true)
            .setShouldShowNotification(true)
            .build();

    public CallScreeningServiceFilter(
            Context context,
Loading