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

Commit 713bec7e authored by Tyler Gunn's avatar Tyler Gunn Committed by android-build-merger
Browse files

CallScreeningService behavior changes and improvements.

am: 5a2f6feb

Change-Id: I9fb50f83de91bc646fbe61ade4e173ba675738d0
parents 76e09db3 5a2f6feb
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.media.AudioManager;
import android.media.AudioSystem;
@@ -607,7 +609,21 @@ public class CallsManager extends Call.ListenerBase
                mCallerInfoLookupHelper, null));
        filters.add(new CallScreeningServiceController(mContext, this, mPhoneAccountRegistrar,
                new ParcelableCallUtils.Converter(), mLock,
                new TelecomServiceImpl.SettingsSecureAdapterImpl(), mCallerInfoLookupHelper));
                new TelecomServiceImpl.SettingsSecureAdapterImpl(), mCallerInfoLookupHelper,
                new CallScreeningServiceController.AppLabelProxy() {
                    @Override
                    public String getAppLabel(String packageName) {
                        PackageManager pm = mContext.getPackageManager();
                        try {
                            ApplicationInfo info = pm.getApplicationInfo(packageName, 0);
                            return (String) pm.getApplicationLabel(info);
                        } catch (PackageManager.NameNotFoundException nnfe) {
                            Log.w(this, "Could not determine package name.");
                        }

                        return null;
                    }
                }));
        new IncomingCallFilter(mContext, this, incomingCall, mLock,
                mTimeoutsAdapter, filters).performFiltering();
    }
+53 −0
Original line number Diff line number Diff line
@@ -18,11 +18,13 @@ package com.android.server.telecom;

import android.net.Uri;
import android.telecom.Connection;
import android.telecom.DisconnectCause;
import android.telecom.ParcelableCall;
import android.telecom.ParcelableRttCall;
import android.telecom.TelecomManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
@@ -37,6 +39,10 @@ public class ParcelableCallUtils {
            return ParcelableCallUtils.toParcelableCall(
                    call, includeVideoProvider, phoneAccountRegistrar, false, false);
        }

        public ParcelableCall toParcelableCallForScreening(Call call) {
            return ParcelableCallUtils.toParcelableCallForScreening(call);
        }
    }

    /**
@@ -191,6 +197,53 @@ public class ParcelableCallUtils {
                call.getCreationTimeMillis());
    }

    /**
     * Creates a ParcelableCall with the bare minimum properties required for a
     * {@link android.telecom.CallScreeningService}.  We ONLY expose the following:
     * <ul>
     *     <li>Call Id (not exposed to public, but needed to associated calls)</li>
     *     <li>Call state</li>
     *     <li>Creation time</li>
     *     <li>Connection time</li>
     *     <li>Handle (phone number)</li>
     *     <li>Handle (phone number) presentation</li>
     * </ul>
     * All other fields are nulled or set to 0 values.
     * @param call The telecom call to send to a call screening service.
     * @return Minimal {@link ParcelableCall} to send to the call screening service.
     */
    public static ParcelableCall toParcelableCallForScreening(Call call) {
        Uri handle = call.getHandlePresentation() == TelecomManager.PRESENTATION_ALLOWED ?
                call.getHandle() : null;
        return new ParcelableCall(
                call.getId(),
                getParcelableState(call, false /* supportsExternalCalls */),
                new DisconnectCause(DisconnectCause.UNKNOWN),
                null, /* cannedSmsResponses */
                0, /* capabilities */
                0, /* properties */
                0, /* supportedAudioRoutes */
                call.getConnectTimeMillis(),
                handle,
                call.getHandlePresentation(),
                null, /* callerDisplayName */
                0 /* callerDisplayNamePresentation */,
                null, /* gatewayInfo */
                null, /* targetPhoneAccount */
                false, /* includeVideoProvider */
                null, /* videoProvider */
                false, /* includeRttCall */
                null, /* rttCall */
                null, /* parentCallId */
                null, /* childCallIds */
                null, /* statusHints */
                0, /* videoState */
                Collections.emptyList(), /* conferenceableCallIds */
                null, /* intentExtras */
                null, /* callExtras */
                call.getCreationTimeMillis());
    }

    private static int getParcelableState(Call call, boolean supportsExternalCalls) {
        int state = CallState.NEW;
        switch (call.getState()) {
+2 −3
Original line number Diff line number Diff line
@@ -196,7 +196,8 @@ public class TelecomSystem {
            IncomingCallNotifier incomingCallNotifier,
            InCallTonePlayer.ToneGeneratorFactory toneGeneratorFactory,
            CallAudioRouteStateMachine.Factory callAudioRouteStateMachineFactory,
            ClockProxy clockProxy) {
            ClockProxy clockProxy,
            RoleManagerAdapter roleManagerAdapter) {
        mContext = context.getApplicationContext();
        LogUtils.initLogging(mContext);
        DefaultDialerManagerAdapter defaultDialerAdapter =
@@ -261,8 +262,6 @@ public class TelecomSystem {
            }
        };

        RoleManagerAdapter roleManagerAdapter = new RoleManagerAdapterImpl();

        mCallsManager = new CallsManager(
                mContext,
                mLock,
+21 −16
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.telecom.callfiltering;

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
@@ -50,6 +51,14 @@ import com.android.server.telecom.TelecomSystem;
public class CallScreeningServiceController implements IncomingCallFilter.CallFilter,
        CallScreeningServiceFilter.CallScreeningFilterResultCallback {

    /**
     * Abstracts away dependency on the {@link PackageManager} required to fetch the label for an
     * app.
     */
    public interface AppLabelProxy {
        String getAppLabel(String packageName);
    }

    private final Context mContext;
    private final CallsManager mCallsManager;
    private final PhoneAccountRegistrar mPhoneAccountRegistrar;
@@ -57,6 +66,7 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi
    private final TelecomSystem.SyncRoot mTelecomLock;
    private final TelecomServiceImpl.SettingsSecureAdapter mSettingsSecureAdapter;
    private final CallerInfoLookupHelper mCallerInfoLookupHelper;
    private final AppLabelProxy mAppLabelProxy;

    private final int CARRIER_CALL_FILTERING_TIMED_OUT = 2000; // 2 seconds
    private final int CALL_FILTERING_TIMED_OUT = 4500; // 4.5 seconds
@@ -85,7 +95,8 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi
            ParcelableCallUtils.Converter parcelableCallUtilsConverter,
            TelecomSystem.SyncRoot lock,
            TelecomServiceImpl.SettingsSecureAdapter settingsSecureAdapter,
            CallerInfoLookupHelper callerInfoLookupHelper) {
            CallerInfoLookupHelper callerInfoLookupHelper,
            AppLabelProxy appLabelProxy) {
        mContext = context;
        mCallsManager = callsManager;
        mPhoneAccountRegistrar = phoneAccountRegistrar;
@@ -93,6 +104,7 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi
        mTelecomLock = lock;
        mSettingsSecureAdapter = settingsSecureAdapter;
        mCallerInfoLookupHelper = callerInfoLookupHelper;
        mAppLabelProxy = appLabelProxy;
    }

    @Override
@@ -119,8 +131,8 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi
    }

    @Override
    public void onCallScreeningFilterComplete(Call call, CallFilteringResult result, String
            packageName) {
    public void onCallScreeningFilterComplete(Call call, CallFilteringResult result,
            String packageName) {
        synchronized (mTelecomLock) {
            mResult = result.combine(mResult);
            if (!TextUtils.isEmpty(packageName) && packageName.equals(getCarrierPackageName())) {
@@ -154,7 +166,7 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi
            bindDefaultDialerAndUserChosenService();
        } else {
            createCallScreeningServiceFilter().startCallScreeningFilter(mCall, this,
                    carrierPackageName);
                    carrierPackageName, mAppLabelProxy.getAppLabel(carrierPackageName));
        }

        // Carrier filtering timed out
@@ -176,7 +188,8 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi
                mIsDefaultDialerFinished = true;
            } else {
                createCallScreeningServiceFilter().startCallScreeningFilter(mCall,
                        CallScreeningServiceController.this, dialerPackageName);
                        CallScreeningServiceController.this, dialerPackageName,
                        mAppLabelProxy.getAppLabel(dialerPackageName));
            }

            String userChosenPackageName = getUserChosenPackageName();
@@ -184,7 +197,8 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi
                mIsUserChosenFinished = true;
            } else {
                createCallScreeningServiceFilter().startCallScreeningFilter(mCall,
                        CallScreeningServiceController.this, userChosenPackageName);
                        CallScreeningServiceController.this, userChosenPackageName,
                        mAppLabelProxy.getAppLabel(userChosenPackageName));
            }

            if (mIsDefaultDialerFinished && mIsUserChosenFinished) {
@@ -250,15 +264,6 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi
    }

    private String getUserChosenPackageName() {
        ComponentName componentName = null;
        String defaultCallScreeningApplication = mSettingsSecureAdapter.getStringForUser(mContext
                .getContentResolver(), Settings.Secure.CALL_SCREENING_DEFAULT_COMPONENT,
                UserHandle.USER_CURRENT);

        if (!TextUtils.isEmpty(defaultCallScreeningApplication)) {
            componentName = ComponentName.unflattenFromString(defaultCallScreeningApplication);
        }

        return componentName != null ? componentName.getPackageName() : null;
        return mCallsManager.getRoleManagerAdapter().getDefaultCallScreeningApp();
    }
}
+8 −8
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.provider.CallLog;
import android.provider.Settings;
import android.telecom.CallScreeningService;
import android.telecom.Log;
import android.telecom.ParcelableCall;
import android.telecom.TelecomManager;
import android.telephony.CarrierConfigManager;
import android.text.TextUtils;
@@ -136,7 +137,7 @@ public class CallScreeningServiceFilter {
                                isServiceRequestingLogging, //shouldAddToCallLog
                                shouldShowNotification, // shouldShowNotification
                                CallLog.Calls.BLOCK_REASON_CALL_SCREENING_SERVICE, //callBlockReason
                                componentName.getPackageName(), //callScreeningAppName
                                mAppName, //callScreeningAppName
                                componentName.flattenToString() //callScreeningComponentName
                        );
                    } else {
@@ -152,7 +153,6 @@ public class CallScreeningServiceFilter {
    }

    private final Context mContext;
    private final PhoneAccountRegistrar mPhoneAccountRegistrar;
    private final CallsManager mCallsManager;
    private final ParcelableCallUtils.Converter mParcelableCallUtilsConverter;
    private final TelecomSystem.SyncRoot mTelecomLock;
@@ -163,6 +163,7 @@ public class CallScreeningServiceFilter {
    private ICallScreeningService mService;
    private ServiceConnection mConnection;
    private String mPackageName;
    private String mAppName;
    private boolean mHasFinished = false;

    private CallFilteringResult mResult = new CallFilteringResult(
@@ -180,7 +181,6 @@ public class CallScreeningServiceFilter {
            TelecomSystem.SyncRoot lock,
            SettingsSecureAdapter settingsSecureAdapter) {
        mContext = context;
        mPhoneAccountRegistrar = phoneAccountRegistrar;
        mCallsManager = callsManager;
        mParcelableCallUtilsConverter = parcelableCallUtilsConverter;
        mTelecomLock = lock;
@@ -189,7 +189,8 @@ public class CallScreeningServiceFilter {

    public void startCallScreeningFilter(Call call,
                                         CallScreeningFilterResultCallback callback,
                                         String packageName) {
                                         String packageName,
                                         String appName) {
        if (mHasFinished) {
            Log.w(this, "Attempting to reuse CallScreeningServiceFilter. Ignoring.");
            return;
@@ -198,6 +199,7 @@ public class CallScreeningServiceFilter {
        mCall = call;
        mCallback = callback;
        mPackageName = packageName;
        mAppName = appName;
        if (!bindService()) {
            Log.i(this, "Could not bind to call screening service");
            finishCallScreening();
@@ -268,11 +270,9 @@ public class CallScreeningServiceFilter {
    private void onServiceBound(ICallScreeningService service) {
        mService = service;
        try {
            // Important: Only send a minimal subset of the call to the screening service.
            mService.screenCall(new CallScreeningAdapter(),
                    mParcelableCallUtilsConverter.toParcelableCall(
                            mCall,
                            false, /* includeVideoProvider */
                            mPhoneAccountRegistrar));
                    mParcelableCallUtilsConverter.toParcelableCallForScreening(mCall));
        } catch (RemoteException e) {
            Log.e(this, e, "Failed to set the call screening adapter.");
            finishCallScreening();
Loading