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

Commit 02e26a50 authored by Grant Menke's avatar Grant Menke
Browse files

Retrieve the main user and associated context in BlockCheckerFilter.

This CL ensures the context associated with the main user is being used when we check if a number is blocked in BlockCheckerFilter#startFilterLookup. This CL also adds a flag to guard this change.

Test: ConnectionServiceTest#testCallLogForBlockedNumberIncomingCall
Flag: com.android.server.telecom.flags.telecom_main_user_in_block_check
Bug: 369062239
Change-Id: I31586b5c519ee75e71a774ddb30a7ff36ae70e5e
parent 3d5a63c5
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -12,3 +12,15 @@ flag {
        purpose: PURPOSE_BUGFIX
      }
}

# OWNER=grantmenke TARGET=25Q1
flag {
    name: "telecom_main_user_in_block_check"
    is_exported: true
    namespace: "telecom"
    description: "Support HSUM mode by using the main user when checking if a number is blocked."
    bug: "369062239"
    metadata {
        purpose: PURPOSE_BUGFIX
      }
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -938,7 +938,7 @@ public class CallsManager extends Call.ListenerBase
        DirectToVoicemailFilter voicemailFilter = new DirectToVoicemailFilter(incomingCall,
                mCallerInfoLookupHelper);
        BlockCheckerFilter blockCheckerFilter = new BlockCheckerFilter(mContext, incomingCall,
                mCallerInfoLookupHelper, new BlockCheckerAdapter(mFeatureFlags));
                mCallerInfoLookupHelper, new BlockCheckerAdapter(mFeatureFlags), mFeatureFlags);
        DndCallFilter dndCallFilter = new DndCallFilter(incomingCall, getRinger());
        CallScreeningServiceFilter carrierCallScreeningServiceFilter =
                new CallScreeningServiceFilter(incomingCall, carrierPackageName,
+18 −8
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.UserManager;
import android.provider.BlockedNumberContract;
import android.provider.CallLog;
import android.telecom.CallerInfo;
@@ -29,6 +30,7 @@ import android.telecom.TelecomManager;

import com.android.server.telecom.Call;
import com.android.server.telecom.CallerInfoLookupHelper;
import com.android.server.telecom.flags.FeatureFlags;
import com.android.server.telecom.LogUtils;
import com.android.server.telecom.LoggedHandlerExecutor;
import com.android.server.telecom.settings.BlockedNumbersUtil;
@@ -45,6 +47,7 @@ public class BlockCheckerFilter extends CallFilter {
    private boolean mContactExists;
    private HandlerThread mHandlerThread;
    private Handler mHandler;
    private FeatureFlags mFeatureFlags;

    public static final long CALLER_INFO_QUERY_TIMEOUT = 5000;

@@ -105,7 +108,7 @@ public class BlockCheckerFilter extends CallFilter {

    public BlockCheckerFilter(Context context, Call call,
            CallerInfoLookupHelper callerInfoLookupHelper,
            BlockCheckerAdapter blockCheckerAdapter) {
            BlockCheckerAdapter blockCheckerAdapter, FeatureFlags featureFlags) {
        mCall = call;
        mContext = context;
        mCallerInfoLookupHelper = callerInfoLookupHelper;
@@ -114,6 +117,7 @@ public class BlockCheckerFilter extends CallFilter {
        mHandlerThread = new HandlerThread(TAG);
        mHandlerThread.start();
        mHandler = new Handler(mHandlerThread.getLooper());
        mFeatureFlags = featureFlags;
    }

    @Override
@@ -121,7 +125,13 @@ public class BlockCheckerFilter extends CallFilter {
        Log.addEvent(mCall, LogUtils.Events.BLOCK_CHECK_INITIATED);
        CompletableFuture<CallFilteringResult> resultFuture = new CompletableFuture<>();
        Bundle extras = new Bundle();
        if (BlockedNumbersUtil.isEnhancedCallBlockingEnabledByPlatform(mContext)) {
        final Context userContext;
        if (mFeatureFlags.telecomMainUserInBlockCheck()) {
            userContext = mContext.createContextAsUser(mCall.getAssociatedUser(), 0);
        } else {
            userContext = mContext;
        }
        if (BlockedNumbersUtil.isEnhancedCallBlockingEnabledByPlatform(userContext)) {
            int presentation = mCall.getHandlePresentation();
            extras.putInt(BlockedNumberContract.EXTRA_CALL_PRESENTATION, presentation);
            if (presentation == TelecomManager.PRESENTATION_ALLOWED) {
@@ -132,7 +142,7 @@ public class BlockCheckerFilter extends CallFilter {
                                if (info != null && info.contactExists) {
                                    mContactExists = true;
                                }
                                getBlockStatus(resultFuture);
                                getBlockStatus(resultFuture, userContext);
                            }

                            @Override
@@ -141,22 +151,22 @@ public class BlockCheckerFilter extends CallFilter {
                            }
                        });
            } else {
                getBlockStatus(resultFuture);
                getBlockStatus(resultFuture, userContext);
            }
        } else {
            getBlockStatus(resultFuture);
            getBlockStatus(resultFuture, userContext);
        }
        return resultFuture;
    }

    private void getBlockStatus(
            CompletableFuture<CallFilteringResult> resultFuture) {
            CompletableFuture<CallFilteringResult> resultFuture, Context userContext) {
        // Set presentation and if contact exists. Used in determining if the system should block
        // the passed in number. Use default values as they would be returned if the keys didn't
        // exist in the extras to maintain existing behavior.
        int presentation;
        boolean isNumberInContacts;
        if (BlockedNumbersUtil.isEnhancedCallBlockingEnabledByPlatform(mContext)) {
        if (BlockedNumbersUtil.isEnhancedCallBlockingEnabledByPlatform(userContext)) {
            presentation = mCall.getHandlePresentation();
        } else {
            presentation = 0;
@@ -173,7 +183,7 @@ public class BlockCheckerFilter extends CallFilter {
                mCall.getHandle().getSchemeSpecificPart();

        CompletableFuture.supplyAsync(
                () -> mBlockCheckerAdapter.getBlockStatus(mContext, number,
                () -> mBlockCheckerAdapter.getBlockStatus(userContext, number,
                        presentation, isNumberInContacts),
                new LoggedHandlerExecutor(mHandler, "BCF.gBS", null))
                .thenApplyAsync((x) -> completeResult(resultFuture, x),
+1 −1
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ public class BlockCheckerFilterTest extends TelecomTestCase {
        super.setUp();
        when(mCall.getHandle()).thenReturn(TEST_HANDLE);
        mFilter = new BlockCheckerFilter(mContext, mCall, mCallerInfoLookupHelper,
                mBlockCheckerAdapter);
                mBlockCheckerAdapter, mFeatureFlags);
    }

    @SmallTest