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

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

Merge changes from topics "call-screening-refactor", "composer-call-screening" into sc-dev

* changes:
  Delete call composer attachments when specified
  Refactor CallScreeningService
parents d249372b 34e42b7f
Loading
Loading
Loading
Loading
+2 −17
Original line number Diff line number Diff line
@@ -55,23 +55,8 @@ public class CallScreeningServiceHelper {
        }

        @Override
        public void allowCall(String s) throws RemoteException {
            unbindCallScreeningService();
        }

        @Override
        public void silenceCall(String s) throws RemoteException {
            unbindCallScreeningService();
        }

        @Override
        public void screenCallFurther(String callId) throws RemoteException {
            unbindCallScreeningService();
        }

        @Override
        public void disallowCall(String s, boolean b, boolean b1, boolean b2,
                ComponentName componentName) throws RemoteException {
        public void onScreeningResponse(String callId, ComponentName componentName,
                CallScreeningService.ParcelableCallResponse callResponse) {
            unbindCallScreeningService();
        }

+23 −1
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import android.provider.CallLog.Calls;
import android.provider.Settings;
import android.sysprop.TelephonyProperties;
import android.telecom.CallAudioState;
import android.telecom.CallScreeningService;
import android.telecom.CallerInfo;
import android.telecom.Conference;
import android.telecom.Connection;
@@ -764,7 +765,28 @@ public class CallsManager extends Call.ListenerBase
            boolean isInContacts = incomingCall.getCallerInfo() != null
                    && incomingCall.getCallerInfo().contactExists;
            incomingCall.getConnectionService().onCallFilteringCompleted(incomingCall,
                    !result.shouldAllowCall, isInContacts);
                    !result.shouldAllowCall, isInContacts, result.mCallScreeningResponse,
                    result.mIsResponseFromSystemDialer);
        }

        // Get rid of the call composer attachments that aren't wanted
        if (result.mIsResponseFromSystemDialer && result.mCallScreeningResponse != null
                && result.mCallScreeningResponse.getCallComposerAttachmentsToShow() >= 0) {
            int attachmentMask = result.mCallScreeningResponse.getCallComposerAttachmentsToShow();
            if ((attachmentMask
                    & CallScreeningService.CallResponse.CALL_COMPOSER_ATTACHMENT_LOCATION) == 0) {
                incomingCall.getExtras().remove(TelecomManager.EXTRA_LOCATION);
            }

            if ((attachmentMask
                    & CallScreeningService.CallResponse.CALL_COMPOSER_ATTACHMENT_SUBJECT) == 0) {
                incomingCall.getExtras().remove(TelecomManager.EXTRA_CALL_SUBJECT);
            }

            if ((attachmentMask
                    & CallScreeningService.CallResponse.CALL_COMPOSER_ATTACHMENT_PRIORITY) == 0) {
                incomingCall.getExtras().remove(TelecomManager.EXTRA_PRIORITY);
            }
        }

        if (result.shouldAllowCall) {
+5 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.UserHandle;
import android.telecom.CallAudioState;
import android.telecom.CallScreeningService;
import android.telecom.Connection;
import android.telecom.ConnectionRequest;
import android.telecom.ConnectionService;
@@ -1864,7 +1865,9 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
        }
    }

    void onCallFilteringCompleted(Call call, boolean isBlocked, boolean isInContacts) {
    void onCallFilteringCompleted(Call call, boolean isBlocked, boolean isInContacts,
            CallScreeningService.ParcelableCallResponse callScreeningResponse,
            boolean isResponseFromSystemDialer) {
        final String callId = mCallIdMapper.getCallId(call);
        if (callId != null && isServiceValid("onCallFilteringCompleted")) {
            try {
@@ -1874,6 +1877,7 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
                                getComponentName().getPackageName());
                if (contactsPermission == PackageManager.PERMISSION_GRANTED) {
                    mServiceInterface.onCallFilteringCompleted(callId, isBlocked, isInContacts,
                            callScreeningResponse, isResponseFromSystemDialer,
                            Log.getExternalSession(TELECOM_ABBREVIATION));
                } else {
                    logOutgoing("Skipping call filtering complete message for %s due"
+48 −16
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.telecom.callfiltering;

import android.provider.CallLog;
import android.provider.CallLog.Calls;
import android.telecom.CallScreeningService;
import android.text.TextUtils;

import java.util.Objects;
@@ -34,6 +35,8 @@ public class CallFilteringResult {
        private int mCallBlockReason = Calls.BLOCK_REASON_NOT_BLOCKED;
        private CharSequence mCallScreeningAppName = null;
        private String mCallScreeningComponentName = null;
        private CallScreeningService.ParcelableCallResponse mCallScreeningResponse = null;
        private boolean mIsResponseFromSystemDialer = false;

        public Builder setShouldAllowCall(boolean shouldAllowCall) {
            mShouldAllowCall = shouldAllowCall;
@@ -80,6 +83,13 @@ public class CallFilteringResult {
            return this;
        }

        public Builder setCallScreeningResponse(
                CallScreeningService.ParcelableCallResponse response, boolean isFromSystemDialer) {
            mCallScreeningResponse = response;
            mIsResponseFromSystemDialer = isFromSystemDialer;
            return this;
        }

        public Builder setContactExists(boolean contactExists) {
            mContactExists = contactExists;
            return this;
@@ -96,14 +106,16 @@ public class CallFilteringResult {
                    .setShouldScreenViaAudio(result.shouldScreenViaAudio)
                    .setCallScreeningAppName(result.mCallScreeningAppName)
                    .setCallScreeningComponentName(result.mCallScreeningComponentName)
                    .setCallScreeningResponse(result.mCallScreeningResponse,
                            result.mIsResponseFromSystemDialer)
                    .setContactExists(result.contactExists);
        }

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

@@ -116,11 +128,15 @@ public class CallFilteringResult {
    public int mCallBlockReason;
    public CharSequence mCallScreeningAppName;
    public String mCallScreeningComponentName;
    public CallScreeningService.ParcelableCallResponse mCallScreeningResponse;
    public boolean mIsResponseFromSystemDialer;
    public boolean contactExists;

    private CallFilteringResult(boolean shouldAllowCall, boolean shouldReject, boolean
            shouldSilence, boolean shouldAddToCallLog, boolean shouldShowNotification, int
            callBlockReason, CharSequence callScreeningAppName, String callScreeningComponentName,
            CallScreeningService.ParcelableCallResponse callScreeningResponse,
            boolean isResponseFromSystemDialer,
            boolean shouldScreenViaAudio, boolean contactExists) {
        this.shouldAllowCall = shouldAllowCall;
        this.shouldReject = shouldReject;
@@ -131,6 +147,8 @@ public class CallFilteringResult {
        this.mCallBlockReason = callBlockReason;
        this.mCallScreeningAppName = callScreeningAppName;
        this.mCallScreeningComponentName = callScreeningComponentName;
        this.mCallScreeningResponse = callScreeningResponse;
        this.mIsResponseFromSystemDialer = isResponseFromSystemDialer;
        this.contactExists = contactExists;
    }

@@ -177,15 +195,16 @@ public class CallFilteringResult {
                    other.mCallScreeningAppName, other.mCallScreeningComponentName);
        }

        return new Builder()
        Builder b = new Builder()
                .setShouldAllowCall(shouldAllowCall && other.shouldAllowCall)
                .setShouldReject(shouldReject || other.shouldReject)
                .setShouldSilence(shouldSilence || other.shouldSilence)
                .setShouldAddToCallLog(shouldAddToCallLog && other.shouldAddToCallLog)
                .setShouldShowNotification(shouldShowNotification && other.shouldShowNotification)
                .setShouldScreenViaAudio(shouldScreenViaAudio || other.shouldScreenViaAudio)
                .setContactExists(contactExists || other.contactExists)
                .build();
                .setContactExists(contactExists || other.contactExists);
        combineScreeningResponses(b, this, other);
        return b.build();
    }

    private boolean isBlockedByProvider(int blockReason) {
@@ -201,8 +220,9 @@ public class CallFilteringResult {
    }

    private CallFilteringResult getCombinedCallFilteringResult(CallFilteringResult other,
        int callBlockReason, CharSequence callScreeningAppName, String callScreeningComponentName) {
        return new Builder()
            int callBlockReason, CharSequence callScreeningAppName,
            String callScreeningComponentName) {
        Builder b = new Builder()
                .setShouldAllowCall(shouldAllowCall && other.shouldAllowCall)
                .setShouldReject(shouldReject || other.shouldReject)
                .setShouldSilence(shouldSilence || other.shouldSilence)
@@ -212,10 +232,22 @@ public class CallFilteringResult {
                .setCallBlockReason(callBlockReason)
                .setCallScreeningAppName(callScreeningAppName)
                .setCallScreeningComponentName(callScreeningComponentName)
                .setContactExists(contactExists || other.contactExists)
                .build();
                .setContactExists(contactExists || other.contactExists);
        combineScreeningResponses(b, this, other);
        return b.build();
    }

    private static void combineScreeningResponses(Builder builder, CallFilteringResult r1,
            CallFilteringResult r2) {
        if (r1.mIsResponseFromSystemDialer) {
            builder.setCallScreeningResponse(r1.mCallScreeningResponse, true);
        } else if (r2.mIsResponseFromSystemDialer) {
            builder.setCallScreeningResponse(r2.mCallScreeningResponse, true);
        } else {
            builder.setCallScreeningResponse(r1.mCallScreeningResponse == null
                    ? r2.mCallScreeningResponse : r1.mCallScreeningResponse, false);
        }
    }

    @Override
    public boolean equals(Object o) {
+49 −15
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
import android.provider.CallLog;
import android.telecom.CallScreeningService;
import android.telecom.Log;
import android.telecom.TelecomManager;

@@ -64,15 +65,44 @@ public class CallScreeningServiceFilter extends CallFilter {
        }

        @Override
        public void allowCall(String callId) {
            Long token = Binder.clearCallingIdentity();
        public void onScreeningResponse(String callId, ComponentName componentName,
                CallScreeningService.ParcelableCallResponse callResponse) {
            if (callResponse == null) {
                Log.w(this, "Null responses are only supposed to happen for outgoing calls");
                return;
            }
            if (callResponse.shouldDisallowCall()) {
                disallowCall(callId, componentName, callResponse);
            } else if (callResponse.shouldSilenceCall()) {
                silenceCall(callId, componentName, callResponse);
            } else if (callResponse.shouldScreenCallViaAudioProcessing()) {
                screenCallFurther(callId, componentName, callResponse);
            } else {
                allowCall(callId, componentName, callResponse);
            }
        }

        public void allowCall(String callId, ComponentName componentName,
                CallScreeningService.ParcelableCallResponse response) {
            long token = Binder.clearCallingIdentity();
            Log.startSession("NCSSF.aC");
            try {
                if (mCall == null || (!mCall.getId().equals(callId))) {
                    Log.w(this, "allowCall, unknown call id: %s", callId);
                }
                Log.addEvent(mCall, LogUtils.Events.SCREENING_COMPLETED, mPriorStageResult);
                mResultFuture.complete(mPriorStageResult);
                CallFilteringResult result = new CallFilteringResult.Builder()
                        .setShouldAllowCall(true)
                        .setShouldReject(false)
                        .setShouldSilence(false)
                        .setShouldAddToCallLog(mPriorStageResult.shouldAddToCallLog)
                        .setShouldShowNotification(mPriorStageResult.shouldShowNotification)
                        .setCallScreeningAppName(mAppName)
                        .setCallScreeningComponentName(componentName.flattenToString())
                        .setCallScreeningResponse(response, isSystemDialer())
                        .setContactExists(mPriorStageResult.contactExists)
                        .build();
                Log.addEvent(mCall, LogUtils.Events.SCREENING_COMPLETED, result);
                mResultFuture.complete(result);
            } finally {
                unbindCallScreeningService();
                Binder.restoreCallingIdentity(token);
@@ -80,24 +110,23 @@ public class CallScreeningServiceFilter extends CallFilter {
            }
        }

        @Override
        public void disallowCall(String callId, boolean shouldReject,
                boolean shouldAddToCallLog, boolean shouldShowNotification,
                ComponentName componentName) {
        public void disallowCall(String callId, ComponentName componentName,
                CallScreeningService.ParcelableCallResponse response) {
            long token = Binder.clearCallingIdentity();
            Log.startSession("NCSSF.dC");
            try {
                if (mCall != null && mCall.getId().equals(callId)) {
                    CallFilteringResult result = new CallFilteringResult.Builder()
                            .setShouldAllowCall(false)
                            .setShouldReject(shouldReject)
                            .setShouldReject(response.shouldRejectCall())
                            .setShouldSilence(false)
                            .setShouldAddToCallLog(shouldAddToCallLog
                            .setShouldAddToCallLog(!response.shouldSkipCallLog()
                                    || packageTypeShouldAdd(mPackagetype))
                            .setShouldShowNotification(shouldShowNotification)
                            .setShouldShowNotification(!response.shouldSkipNotification())
                            .setCallBlockReason(CallLog.Calls.BLOCK_REASON_CALL_SCREENING_SERVICE)
                            .setCallScreeningAppName(mAppName)
                            .setCallScreeningComponentName(componentName.flattenToString())
                            .setCallScreeningResponse(response, isSystemDialer())
                            .setContactExists(mPriorStageResult.contactExists)
                            .build();
                    Log.addEvent(mCall, LogUtils.Events.SCREENING_COMPLETED, result);
@@ -113,8 +142,8 @@ public class CallScreeningServiceFilter extends CallFilter {
            }
        }

        @Override
        public void silenceCall(String callId) {
        public void silenceCall(String callId, ComponentName componentName,
                CallScreeningService.ParcelableCallResponse response) {
            long token = Binder.clearCallingIdentity();
            Log.startSession("NCSSF.sC");
            try {
@@ -125,6 +154,9 @@ public class CallScreeningServiceFilter extends CallFilter {
                            .setShouldSilence(true)
                            .setShouldAddToCallLog(true)
                            .setShouldShowNotification(true)
                            .setCallScreeningResponse(response, isSystemDialer())
                            .setCallScreeningAppName(mAppName)
                            .setCallScreeningComponentName(componentName.flattenToString())
                            .setContactExists(mPriorStageResult.contactExists)
                            .build();
                    Log.addEvent(mCall, LogUtils.Events.SCREENING_COMPLETED, result);
@@ -140,8 +172,8 @@ public class CallScreeningServiceFilter extends CallFilter {
            }
        }

        @Override
        public void screenCallFurther(String callId) {
        public void screenCallFurther(String callId, ComponentName componentName,
                CallScreeningService.ParcelableCallResponse response) {
            if (mPackagetype != PACKAGE_TYPE_DEFAULT_DIALER) {
                throw new SecurityException("Only the default/system dialer may request screen via"
                    + "background call audio");
@@ -158,6 +190,8 @@ public class CallScreeningServiceFilter extends CallFilter {
                            .setShouldSilence(false)
                            .setShouldScreenViaAudio(true)
                            .setCallScreeningAppName(mAppName)
                            .setCallScreeningComponentName(componentName.flattenToString())
                            .setCallScreeningResponse(response, isSystemDialer())
                            .setContactExists(mPriorStageResult.contactExists)
                            .build();
                    Log.addEvent(mCall, LogUtils.Events.SCREENING_COMPLETED, result);
Loading