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

Commit 5759a7bf authored by Takeshi Tanigawa's avatar Takeshi Tanigawa Committed by Tyler Gunn
Browse files

Notify PhoneAccountHandle to CallScreeningService

Add PhoneAccountHandle to ParcelableCall for CallScreeningService to
support call screening per SIM. Only include PhoneAccountHandle when
the caller has permission READ_PRIVILEGED_PHONE_STATE.

Test: Manual
Test: atest ParcelableCallUtilsTest
Flag: com.android.server.telecom.flags.resolve_hidden_dependencies_two
Bug: 262190902
Change-Id: I4aa291e9bde20addf737a74dfba172e862e7141e
parent 11242d1a
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -117,10 +117,12 @@ public class CallScreeningServiceHelper {
                Log.continueSession(mLoggingSession, "CSSH.oSC");
                try {
                    try {
                        // Note: for outgoing calls, never include the restricted extras.
                        // Note: for outgoing calls, never include the restricted extras
                        // and PhoneAccountHandle
                        screeningService.screenCall(new CallScreeningAdapter(this),
                                mParcelableCallUtilsConverter.toParcelableCallForScreening(mCall,
                                        false /* areRestrictedExtrasIncluded */));
                                        false /* areRestrictedExtrasIncluded */,
                                        false /* includePhoneAccountHandle */));
                    } catch (RemoteException e) {
                        Log.w(CallScreeningServiceHelper.this,
                                "Cancelling call id due to remote exception");
+3 −3
Original line number Diff line number Diff line
@@ -1043,18 +1043,18 @@ public class CallsManager extends Call.ListenerBase
        CallScreeningServiceFilter carrierCallScreeningServiceFilter =
                new CallScreeningServiceFilter(incomingCall, carrierPackageName,
                        CallScreeningServiceFilter.PACKAGE_TYPE_CARRIER, mContext, this,
                        appLabelProxy, converter);
                        appLabelProxy, converter, mFeatureFlags);
        CallScreeningServiceFilter callScreeningServiceFilter;
        if ((userChosenPackageName != null)
                && (!userChosenPackageName.equals(defaultDialerPackageName))) {
            callScreeningServiceFilter = new CallScreeningServiceFilter(incomingCall,
                    userChosenPackageName, CallScreeningServiceFilter.PACKAGE_TYPE_USER_CHOSEN,
                    mContext, this, appLabelProxy, converter);
                    mContext, this, appLabelProxy, converter, mFeatureFlags);
        } else {
            callScreeningServiceFilter = new CallScreeningServiceFilter(incomingCall,
                    defaultDialerPackageName,
                    CallScreeningServiceFilter.PACKAGE_TYPE_DEFAULT_DIALER,
                    mContext, this, appLabelProxy, converter);
                    mContext, this, appLabelProxy, converter, mFeatureFlags);
        }
        graph.addFilter(voicemailFilter);
        graph.addFilter(dndCallFilter);
+9 −5
Original line number Diff line number Diff line
@@ -74,9 +74,9 @@ public class ParcelableCallUtils {
        }

        public ParcelableCall toParcelableCallForScreening(Call call,
                boolean areRestrictedExtrasIncluded) {
                boolean areRestrictedExtrasIncluded, boolean includePhoneAccountHandle) {
            return ParcelableCallUtils.toParcelableCallForScreening(call,
                    areRestrictedExtrasIncluded);
                    areRestrictedExtrasIncluded, includePhoneAccountHandle);
        }
    }

@@ -315,11 +315,12 @@ public class ParcelableCallUtils {
     * {@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 directoin</li>
     *     <li>Call direction</li>
     *     <li>Creation time</li>
     *     <li>Connection time</li>
     *     <li>Handle (phone number)</li>
     *     <li>Handle (phone number) presentation</li>
     *     <li>{@code PhoneAccountHandle}</li>
     *     <li>Caller number verification status (verstat)</li>
     * </ul>
     * All other fields are nulled or set to 0 values.
@@ -330,10 +331,12 @@ public class ParcelableCallUtils {
     * @param areRestrictedExtrasIncluded {@code true} if the set of restricted extras defined in
     *                                    {@link #RESTRICTED_CALL_SCREENING_EXTRA_KEYS} are to
     *                                    be included in the parceled call, {@code false} otherwise.
     * @param includePhoneAccountHandle {@code true} if {@code PhoneAccountHandle} to be included
     *                                    in the parceled call, {@code false} otherwise.
     * @return Minimal {@link ParcelableCall} to send to the call screening service.
     */
    public static ParcelableCall toParcelableCallForScreening(Call call,
            boolean areRestrictedExtrasIncluded) {
            boolean areRestrictedExtrasIncluded, boolean includePhoneAccountHandle) {
        Uri handle = call.getHandlePresentation() == TelecomManager.PRESENTATION_ALLOWED ?
                call.getHandle() : null;
        int callDirection;
@@ -366,7 +369,8 @@ public class ParcelableCallUtils {
                .setCallerDisplayName(null)
                .setCallerDisplayNamePresentation(0)
                .setGatewayInfo(null)
                .setAccountHandle(null)
                .setAccountHandle(includePhoneAccountHandle ?
                        call.getDelegatePhoneAccountHandle() : null)
                .setIsVideoCallProviderChanged(false)
                .setVideoCallProvider(null)
                .setIsRttCallChanged(false)
+16 −2
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.telecom.TelecomManager;

import com.android.internal.telecom.ICallScreeningAdapter;
import com.android.internal.telecom.ICallScreeningService;
import com.android.server.telecom.flags.FeatureFlags;
import com.android.server.telecom.AppLabelProxy;
import com.android.server.telecom.Call;
import com.android.server.telecom.CallScreeningServiceHelper;
@@ -57,6 +58,7 @@ public class CallScreeningServiceFilter extends CallFilter {
    private final CallsManager mCallsManager;
    private CharSequence mAppName;
    private final ParcelableCallUtils.Converter mParcelableCallUtilsConverter;
    private final FeatureFlags mFeatureFlags;

    private class CallScreeningAdapter extends ICallScreeningAdapter.Stub {
        private CompletableFuture<CallFilteringResult> mResultFuture;
@@ -223,7 +225,8 @@ public class CallScreeningServiceFilter extends CallFilter {
            try {
                callScreeningService.screenCall(new CallScreeningAdapter(mResultFuture),
                        mParcelableCallUtilsConverter.
                                toParcelableCallForScreening(mCall, isSystemDialer()));
                                toParcelableCallForScreening(mCall, isSystemDialer(),
                                        hasReadPrivilegedPhoneStatePermission()));
            } catch (RemoteException e) {
                Log.e(this, e, "Failed to set the call screening adapter");
                mResultFuture.complete(mPriorStageResult);
@@ -261,7 +264,8 @@ public class CallScreeningServiceFilter extends CallFilter {
            Context context,
            CallsManager callsManager,
            AppLabelProxy appLabelProxy,
            ParcelableCallUtils.Converter parcelableCallUtilsConverter) {
            ParcelableCallUtils.Converter parcelableCallUtilsConverter,
            FeatureFlags featureFlags) {
        super();
        mCall = call;
        mPackageName = packageName;
@@ -272,6 +276,7 @@ public class CallScreeningServiceFilter extends CallFilter {
        mAppName = appLabelProxy.getAppLabel(mPackageName,
                mCall.getAssociatedUser());
        mParcelableCallUtilsConverter = parcelableCallUtilsConverter;
        mFeatureFlags = featureFlags;
    }

    @Override
@@ -315,6 +320,15 @@ public class CallScreeningServiceFilter extends CallFilter {
        return permission == PackageManager.PERMISSION_GRANTED;
    }

    private boolean hasReadPrivilegedPhoneStatePermission() {
        if (!mFeatureFlags.resolveHiddenDependenciesTwo()) {
            return false;
        }
        return mPackageManager != null
                && mPackageManager.checkPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
                        mPackageName) == PackageManager.PERMISSION_GRANTED;
    }

    private void bindCallScreeningService(
            CompletableFuture<CallFilteringResult> resultFuture) {
        CallScreeningServiceConnection connection = new CallScreeningServiceConnection(
+13 −12
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import androidx.test.filters.SmallTest;

import com.android.internal.telecom.ICallScreeningAdapter;
import com.android.internal.telecom.ICallScreeningService;
import com.android.server.telecom.flags.FeatureFlagsImpl;
import com.android.server.telecom.AppLabelProxy;
import com.android.server.telecom.Call;
import com.android.server.telecom.CallsManager;
@@ -152,7 +153,7 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {
    public void testNoPackageName() throws Exception {
        CallScreeningServiceFilter filter = new CallScreeningServiceFilter(mCall, null,
                CallScreeningServiceFilter.PACKAGE_TYPE_CARRIER, mContext, mCallsManager,
                mAppLabelProxy, mParcelableCallUtilsConverter);
                mAppLabelProxy, mParcelableCallUtilsConverter, new FeatureFlagsImpl());
        assertEquals(PASS_RESULT,
                filter.startFilterLookup(inputResult).toCompletableFuture().get(
                        CallScreeningServiceFilter.CALL_SCREENING_FILTER_TIMEOUT,
@@ -166,7 +167,7 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {
                anyInt(), eq(PA_HANDLE.getUserHandle()))).thenReturn(false);
        CallScreeningServiceFilter filter = new CallScreeningServiceFilter(mCall, PKG_NAME,
                CallScreeningServiceFilter.PACKAGE_TYPE_CARRIER, mContext, mCallsManager,
                mAppLabelProxy, mParcelableCallUtilsConverter);
                mAppLabelProxy, mParcelableCallUtilsConverter, new FeatureFlagsImpl());
        assertEquals(PASS_RESULT,
                filter.startFilterLookup(inputResult).toCompletableFuture().get(
                        CallScreeningServiceFilter.CALL_SCREENING_FILTER_TIMEOUT,
@@ -180,7 +181,7 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {
                .thenReturn(Collections.emptyList());
        CallScreeningServiceFilter filter = new CallScreeningServiceFilter(mCall, PKG_NAME,
                CallScreeningServiceFilter.PACKAGE_TYPE_CARRIER, mContext, mCallsManager,
                mAppLabelProxy, mParcelableCallUtilsConverter);
                mAppLabelProxy, mParcelableCallUtilsConverter, new FeatureFlagsImpl());
        assertEquals(PASS_RESULT,
                filter.startFilterLookup(inputResult).toCompletableFuture().get(
                        CallScreeningServiceFilter.CALL_SCREENING_FILTER_TIMEOUT,
@@ -193,7 +194,7 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {
        mResolveInfo.serviceInfo = null;
        CallScreeningServiceFilter filter = new CallScreeningServiceFilter(mCall, PKG_NAME,
                CallScreeningServiceFilter.PACKAGE_TYPE_CARRIER, mContext, mCallsManager,
                mAppLabelProxy, mParcelableCallUtilsConverter);
                mAppLabelProxy, mParcelableCallUtilsConverter, new FeatureFlagsImpl());
        assertEquals(PASS_RESULT,
                filter.startFilterLookup(inputResult).toCompletableFuture().get(
                        CallScreeningServiceFilter.CALL_SCREENING_FILTER_TIMEOUT,
@@ -212,7 +213,7 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {
        inputResult.contactExists = true;
        CallScreeningServiceFilter filter = new CallScreeningServiceFilter(mCall, PKG_NAME,
                CallScreeningServiceFilter.PACKAGE_TYPE_USER_CHOSEN, mContext, mCallsManager,
                mAppLabelProxy, mParcelableCallUtilsConverter);
                mAppLabelProxy, mParcelableCallUtilsConverter, new FeatureFlagsImpl());
        filter.startFilterLookup(inputResult);
    }

@@ -224,7 +225,7 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {
        inputResult.contactExists = true;
        CallScreeningServiceFilter filter = new CallScreeningServiceFilter(mCall, PKG_NAME,
                CallScreeningServiceFilter.PACKAGE_TYPE_CARRIER, mContext, mCallsManager,
                mAppLabelProxy, mParcelableCallUtilsConverter);
                mAppLabelProxy, mParcelableCallUtilsConverter, new FeatureFlagsImpl());
        filter.startFilterLookup(inputResult);
        ServiceConnection connection = verifyBindingIntent();
        connection.onServiceDisconnected(COMPONENT_NAME);
@@ -238,7 +239,7 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {
                .unbindService(nullable(ServiceConnection.class));
        CallScreeningServiceFilter filter = new CallScreeningServiceFilter(mCall, PKG_NAME,
                CallScreeningServiceFilter.PACKAGE_TYPE_CARRIER, mContext, mCallsManager,
                mAppLabelProxy, mParcelableCallUtilsConverter);
                mAppLabelProxy, mParcelableCallUtilsConverter, new FeatureFlagsImpl());
        CompletableFuture<CallFilteringResult> result = filter.startFilterLookup(inputResult)
                .toCompletableFuture();

@@ -253,7 +254,7 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {
        // Use an empty package name here, which fails in the bindCallScreeningService.
        CallScreeningServiceFilter filter = new CallScreeningServiceFilter(mCall, "",
                CallScreeningServiceFilter.PACKAGE_TYPE_CARRIER, mContext, mCallsManager,
                mAppLabelProxy, mParcelableCallUtilsConverter);
                mAppLabelProxy, mParcelableCallUtilsConverter, new FeatureFlagsImpl());

        CompletableFuture<CallFilteringResult> result = filter.startFilterLookup(inputResult)
                .toCompletableFuture();
@@ -266,7 +267,7 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {
    public void testAllowCall() throws Exception {
        CallScreeningServiceFilter filter = new CallScreeningServiceFilter(mCall, PKG_NAME,
                CallScreeningServiceFilter.PACKAGE_TYPE_CARRIER, mContext, mCallsManager,
                mAppLabelProxy, mParcelableCallUtilsConverter);
                mAppLabelProxy, mParcelableCallUtilsConverter, new FeatureFlagsImpl());
        CompletionStage<CallFilteringResult> resultFuture = filter.startFilterLookup(inputResult);

        ServiceConnection serviceConnection = verifyBindingIntent();
@@ -302,7 +303,7 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {
                .build();
        CallScreeningServiceFilter filter = new CallScreeningServiceFilter(mCall, PKG_NAME,
                CallScreeningServiceFilter.PACKAGE_TYPE_CARRIER, mContext, mCallsManager,
                mAppLabelProxy, mParcelableCallUtilsConverter);
                mAppLabelProxy, mParcelableCallUtilsConverter, new FeatureFlagsImpl());
        CompletionStage<CallFilteringResult> resultFuture = filter.startFilterLookup(inputResult);

        ServiceConnection serviceConnection = verifyBindingIntent();
@@ -339,7 +340,7 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {
                .build();
        CallScreeningServiceFilter filter = new CallScreeningServiceFilter(mCall, PKG_NAME,
                CallScreeningServiceFilter.PACKAGE_TYPE_CARRIER, mContext, mCallsManager,
                mAppLabelProxy, mParcelableCallUtilsConverter);
                mAppLabelProxy, mParcelableCallUtilsConverter, new FeatureFlagsImpl());
        CompletionStage<CallFilteringResult> resultFuture = filter.startFilterLookup(inputResult);

        ServiceConnection serviceConnection = verifyBindingIntent();
@@ -374,7 +375,7 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {
                .build();
        CallScreeningServiceFilter filter = new CallScreeningServiceFilter(mCall, PKG_NAME,
                CallScreeningServiceFilter.PACKAGE_TYPE_DEFAULT_DIALER, mContext, mCallsManager,
                mAppLabelProxy, mParcelableCallUtilsConverter);
                mAppLabelProxy, mParcelableCallUtilsConverter, new FeatureFlagsImpl());
        CompletionStage<CallFilteringResult> resultFuture = filter.startFilterLookup(inputResult);

        ServiceConnection serviceConnection = verifyBindingIntent();
Loading