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

Commit 3db74bd8 authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Formalize BlockedNumberContract.SystemContract APIs

Formalize the BlockedNumberContract.SystemContract APIs as part of the
Telecom modularization. There are several hidden APIs that are being
referenced from Telecom that need to be resolved. The
blockStatusToString() implementation is being copied over to Telecom
while the other dependencies are being formalized into system APIs as
part of BlockedNumberContract (the hidden references have been
unchanged).

Bug: 308208071
Bug: 311773409
Test: atest BlockedNumberContractTest
Change-Id: Ia9f3a523d867caed0e49563caa587bc203375f1a
parent 4248bcd5
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.BlockedNumberContract;
import android.provider.BlockedNumberContract.SystemContract;
import android.provider.BlockedNumberContract.BlockedNumbers;
import android.provider.CallLog.Calls;
import android.provider.Settings;
import android.sysprop.TelephonyProperties;
@@ -556,7 +556,7 @@ public class CallsManager extends Call.ListenerBase
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED.equals(action)
                    || SystemContract.ACTION_BLOCK_SUPPRESSION_STATE_CHANGED.equals(action)) {
                    || BlockedNumbers.ACTION_BLOCK_SUPPRESSION_STATE_CHANGED.equals(action)) {
                updateEmergencyCallNotificationAsync(context);
            }
        }
@@ -749,7 +749,7 @@ public class CallsManager extends Call.ListenerBase
        IntentFilter intentFilter = new IntentFilter(
                CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
        intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        intentFilter.addAction(SystemContract.ACTION_BLOCK_SUPPRESSION_STATE_CHANGED);
        intentFilter.addAction(BlockedNumbers.ACTION_BLOCK_SUPPRESSION_STATE_CHANGED);
        context.registerReceiver(mReceiver, intentFilter, Context.RECEIVER_EXPORTED);
        mGraphHandlerThreads = new LinkedList<>();

@@ -2924,7 +2924,7 @@ public class CallsManager extends Call.ListenerBase

        if (call.isEmergencyCall()) {
            Executors.defaultThreadFactory().newThread(() ->
                    BlockedNumberContract.SystemContract.notifyEmergencyContact(mContext))
                    BlockedNumberContract.BlockedNumbers.notifyEmergencyContact(mContext))
                    .start();
        }

+1 −1
Original line number Diff line number Diff line
@@ -1951,7 +1951,7 @@ public class TelecomServiceImpl {
                synchronized (mLock) {
                    long token = Binder.clearCallingIdentity();
                    try {
                        BlockedNumberContract.SystemContract.endBlockSuppression(mContext);
                        BlockedNumberContract.BlockedNumbers.endBlockSuppression(mContext);
                    } finally {
                        Binder.restoreCallingIdentity(token);
                    }
+12 −10
Original line number Diff line number Diff line
@@ -34,22 +34,24 @@ public class BlockCheckerAdapter {
     *
     * @param context the context of the caller.
     * @param phoneNumber the number to check.
     * @param extras the extra attribute of the number.
     * @param numberPresentation the presentation code associated with the call.
     * @param isNumberInContacts indicates if the provided number exists as a contact.
     * @return result code indicating if the number should be blocked, and if so why.
     *         Valid values are: {@link BlockedNumberContract#STATUS_NOT_BLOCKED},
     *         {@link BlockedNumberContract#STATUS_BLOCKED_IN_LIST},
     *         {@link BlockedNumberContract#STATUS_BLOCKED_NOT_IN_CONTACTS},
     *         {@link BlockedNumberContract#STATUS_BLOCKED_PAYPHONE},
     *         {@link BlockedNumberContract#STATUS_BLOCKED_RESTRICTED},
     *         {@link BlockedNumberContract#STATUS_BLOCKED_UNKNOWN_NUMBER}.
     *         Valid values are: {@link BlockCheckerFilter#STATUS_NOT_BLOCKED},
     *         {@link BlockCheckerFilter#STATUS_BLOCKED_IN_LIST},
     *         {@link BlockCheckerFilter#STATUS_BLOCKED_NOT_IN_CONTACTS},
     *         {@link BlockCheckerFilter#STATUS_BLOCKED_PAYPHONE},
     *         {@link BlockCheckerFilter#STATUS_BLOCKED_RESTRICTED},
     *         {@link BlockCheckerFilter#STATUS_BLOCKED_UNKNOWN_NUMBER}.
     */
    public int getBlockStatus(Context context, String phoneNumber, Bundle extras) {
    public int getBlockStatus(Context context, String phoneNumber,
            int numberPresentation, boolean isNumberInContacts) {
        int blockStatus = BlockedNumberContract.STATUS_NOT_BLOCKED;
        long startTimeNano = System.nanoTime();

        try {
            blockStatus = BlockedNumberContract.SystemContract.shouldSystemBlockNumber(
                    context, phoneNumber, extras);
            blockStatus = BlockedNumberContract.BlockedNumbers.shouldSystemBlockNumber(
                    context, phoneNumber, numberPresentation, isNumberInContacts);
            if (blockStatus != BlockedNumberContract.STATUS_NOT_BLOCKED) {
                Log.d(TAG, phoneNumber + " is blocked.");
            }
+102 −17
Original line number Diff line number Diff line
@@ -48,6 +48,61 @@ public class BlockCheckerFilter extends CallFilter {

    public static final long CALLER_INFO_QUERY_TIMEOUT = 5000;

    /**
     * Integer reason indicating whether a call was blocked, and if so why.
     * @hide
     */
    public static final String RES_BLOCK_STATUS = "block_status";

    /**
     * Integer reason code used with {@link #RES_BLOCK_STATUS} to indicate that a call was not
     * blocked.
     * @hide
     */
    public static final int STATUS_NOT_BLOCKED = 0;

    /**
     * Integer reason code used with {@link #RES_BLOCK_STATUS} to indicate that a call was blocked
     * because it is in the list of blocked numbers maintained by the provider.
     * @hide
     */
    public static final int STATUS_BLOCKED_IN_LIST = 1;

    /**
     * Integer reason code used with {@link #RES_BLOCK_STATUS} to indicate that a call was blocked
     * because it is from a restricted number.
     * @hide
     */
    public static final int STATUS_BLOCKED_RESTRICTED = 2;

    /**
     * Integer reason code used with {@link #RES_BLOCK_STATUS} to indicate that a call was blocked
     * because it is from an unknown number.
     * @hide
     */
    public static final int STATUS_BLOCKED_UNKNOWN_NUMBER = 3;

    /**
     * Integer reason code used with {@link #RES_BLOCK_STATUS} to indicate that a call was blocked
     * because it is from a pay phone.
     * @hide
     */
    public static final int STATUS_BLOCKED_PAYPHONE = 4;

    /**
     * Integer reason code used with {@link #RES_BLOCK_STATUS} to indicate that a call was blocked
     * because it is from a number not in the users contacts.
     * @hide
     */
    public static final int STATUS_BLOCKED_NOT_IN_CONTACTS = 5;

    /**
     * Integer reason code used with {@link #RES_BLOCK_STATUS} to indicate that a call was blocked
     * because it is from a number not available.
     * @hide
     */
    public static final int STATUS_BLOCKED_UNAVAILABLE = 6;

    public BlockCheckerFilter(Context context, Call call,
            CallerInfoLookupHelper callerInfoLookupHelper,
            BlockCheckerAdapter blockCheckerAdapter) {
@@ -96,14 +151,21 @@ public class BlockCheckerFilter extends CallFilter {

    private void getBlockStatus(
            CompletableFuture<CallFilteringResult> resultFuture) {
        // Set extras
        Bundle extras = new Bundle();
        // 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)) {
            int presentation = mCall.getHandlePresentation();
            extras.putInt(BlockedNumberContract.EXTRA_CALL_PRESENTATION, presentation);
            if (presentation == TelecomManager.PRESENTATION_ALLOWED) {
                extras.putBoolean(BlockedNumberContract.EXTRA_CONTACT_EXIST, mContactExists);
            presentation = mCall.getHandlePresentation();
        } else {
            presentation = 0;
        }

        if (presentation == TelecomManager.PRESENTATION_ALLOWED) {
            isNumberInContacts = mContactExists;
        } else {
            isNumberInContacts = false;
        }

        // Set number
@@ -111,7 +173,8 @@ public class BlockCheckerFilter extends CallFilter {
                mCall.getHandle().getSchemeSpecificPart();

        CompletableFuture.supplyAsync(
                () -> mBlockCheckerAdapter.getBlockStatus(mContext, number, extras),
                () -> mBlockCheckerAdapter.getBlockStatus(mContext, number,
                        presentation, isNumberInContacts),
                new LoggedHandlerExecutor(mHandler, "BCF.gBS", null))
                .thenApplyAsync((x) -> completeResult(resultFuture, x),
                        new LoggedHandlerExecutor(mHandler, "BCF.gBS", null));
@@ -120,7 +183,7 @@ public class BlockCheckerFilter extends CallFilter {
    private int completeResult(CompletableFuture<CallFilteringResult> resultFuture,
            int blockStatus) {
        CallFilteringResult result;
        if (blockStatus != BlockedNumberContract.STATUS_NOT_BLOCKED) {
        if (blockStatus != STATUS_NOT_BLOCKED) {
            result = new CallFilteringResult.Builder()
                    .setShouldAllowCall(false)
                    .setShouldReject(true)
@@ -143,8 +206,7 @@ public class BlockCheckerFilter extends CallFilter {
                    .build();
        }
        Log.addEvent(mCall, LogUtils.Events.BLOCK_CHECK_FINISHED,
                BlockedNumberContract.SystemContract.blockStatusToString(blockStatus) + " "
                        + result);
                blockStatusToString(blockStatus) + " " + result);
        resultFuture.complete(result);
        mHandlerThread.quitSafely();
        return blockStatus;
@@ -152,20 +214,20 @@ public class BlockCheckerFilter extends CallFilter {

    private int getBlockReason(int blockStatus) {
        switch (blockStatus) {
            case BlockedNumberContract.STATUS_BLOCKED_IN_LIST:
            case STATUS_BLOCKED_IN_LIST:
                return CallLog.Calls.BLOCK_REASON_BLOCKED_NUMBER;

            case BlockedNumberContract.STATUS_BLOCKED_UNKNOWN_NUMBER:
            case BlockedNumberContract.STATUS_BLOCKED_UNAVAILABLE:
            case STATUS_BLOCKED_UNKNOWN_NUMBER:
            case STATUS_BLOCKED_UNAVAILABLE:
                return CallLog.Calls.BLOCK_REASON_UNKNOWN_NUMBER;

            case BlockedNumberContract.STATUS_BLOCKED_RESTRICTED:
            case STATUS_BLOCKED_RESTRICTED:
                return CallLog.Calls.BLOCK_REASON_RESTRICTED_NUMBER;

            case BlockedNumberContract.STATUS_BLOCKED_PAYPHONE:
            case STATUS_BLOCKED_PAYPHONE:
                return CallLog.Calls.BLOCK_REASON_PAY_PHONE;

            case BlockedNumberContract.STATUS_BLOCKED_NOT_IN_CONTACTS:
            case STATUS_BLOCKED_NOT_IN_CONTACTS:
                return CallLog.Calls.BLOCK_REASON_NOT_IN_CONTACTS;

            default:
@@ -174,4 +236,27 @@ public class BlockCheckerFilter extends CallFilter {
                return CallLog.Calls.BLOCK_REASON_BLOCKED_NUMBER;
        }
    }

    /**
     * Converts a block status constant to a string equivalent for logging.
     */
    private String blockStatusToString(int blockStatus) {
        switch (blockStatus) {
            case STATUS_NOT_BLOCKED:
                return "not blocked";
            case STATUS_BLOCKED_IN_LIST:
                return "blocked - in list";
            case STATUS_BLOCKED_RESTRICTED:
                return "blocked - restricted";
            case STATUS_BLOCKED_UNKNOWN_NUMBER:
                return "blocked - unknown";
            case STATUS_BLOCKED_PAYPHONE:
                return "blocked - payphone";
            case STATUS_BLOCKED_NOT_IN_CONTACTS:
                return "blocked - not in contacts";
            case STATUS_BLOCKED_UNAVAILABLE:
                return "blocked - unavailable";
        }
        return "unknown";
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import android.content.Context;

/**
 * Adapter interface that wraps methods from
 * {@link android.provider.BlockedNumberContract.SystemContract} and
 * {@link android.provider.BlockedNumberContract.BlockedNumbers} and
 * {@link com.android.server.telecom.settings.BlockedNumbersUtil} to make things testable.
 */
public interface BlockedNumbersAdapter {
Loading