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

Commit 9b05d154 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Add support for receiving blocking reason from provider.

Adding support new status integer returned by the blocked number provider.
This integer tells Telecom why the call was blocked.
Adding a CallBlockListener in Telecom which can be used in the future to
handle informing an interested party of the reason why a call was blocked.

Test: Manual, update unit tests
Bug: 63966743
Change-Id: I4b33fa1d74396b82e364953834b27f88781170b2
parent a780c6ed
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -536,7 +536,7 @@ public class CallsManager extends Call.ListenerBase
        List<IncomingCallFilter.CallFilter> filters = new ArrayList<>();
        filters.add(new DirectToVoicemailCallFilter(mCallerInfoLookupHelper));
        filters.add(new AsyncBlockCheckFilter(mContext, new BlockCheckerAdapter(),
                mCallerInfoLookupHelper));
                mCallerInfoLookupHelper, null));
        filters.add(new CallScreeningServiceFilter(mContext, this, mPhoneAccountRegistrar,
                mDefaultDialerCache, new ParcelableCallUtils.Converter(), mLock));
        new IncomingCallFilter(mContext, this, incomingCall, mLock,
+15 −3
Original line number Diff line number Diff line
@@ -40,17 +40,20 @@ public class AsyncBlockCheckFilter extends AsyncTask<String, Void, Boolean>
        implements IncomingCallFilter.CallFilter {
    private final Context mContext;
    private final BlockCheckerAdapter mBlockCheckerAdapter;
    private final CallBlockListener mCallBlockListener;
    private Call mIncomingCall;
    private Session mBackgroundTaskSubsession;
    private Session mPostExecuteSubsession;
    private CallFilterResultCallback mCallback;
    private CallerInfoLookupHelper mCallerInfoLookupHelper;
    private int mBlockStatus = BlockedNumberContract.STATUS_NOT_BLOCKED;

    public AsyncBlockCheckFilter(Context context, BlockCheckerAdapter blockCheckerAdapter,
            CallerInfoLookupHelper callerInfoLookupHelper) {
            CallerInfoLookupHelper callerInfoLookupHelper, CallBlockListener callBlockListener) {
        mContext = context;
        mBlockCheckerAdapter = blockCheckerAdapter;
        mCallerInfoLookupHelper = callerInfoLookupHelper;
        mCallBlockListener = callBlockListener;
    }

    @Override
@@ -104,7 +107,8 @@ public class AsyncBlockCheckFilter extends AsyncTask<String, Void, Boolean>
                extras.putBoolean(BlockedNumberContract.EXTRA_CONTACT_EXIST,
                        Boolean.valueOf(params[2]));
            }
            return mBlockCheckerAdapter.isBlocked(mContext, params[0], extras);
            mBlockStatus = mBlockCheckerAdapter.getBlockStatus(mContext, params[0], extras);
            return mBlockStatus != BlockedNumberContract.STATUS_NOT_BLOCKED;
        } finally {
            Log.endSession();
        }
@@ -122,6 +126,12 @@ public class AsyncBlockCheckFilter extends AsyncTask<String, Void, Boolean>
                        false, //shouldAddToCallLog
                        false // shouldShowNotification
                );
                if (mCallBlockListener != null) {
                    String number = mIncomingCall.getHandle() == null ? null
                            : mIncomingCall.getHandle().getSchemeSpecificPart();
                    mCallBlockListener.onCallBlocked(mBlockStatus, number,
                            mIncomingCall.getInitiatingUser());
                }
            } else {
                result = new CallFilteringResult(
                        true, // shouldAllowCall
@@ -130,7 +140,9 @@ public class AsyncBlockCheckFilter extends AsyncTask<String, Void, Boolean>
                        true // shouldShowNotification
                );
            }
            Log.addEvent(mIncomingCall, LogUtils.Events.BLOCK_CHECK_FINISHED, result);
            Log.addEvent(mIncomingCall, LogUtils.Events.BLOCK_CHECK_FINISHED,
                    BlockedNumberContract.SystemContract.blockStatusToString(mBlockStatus) + " "
                            + result);
            mCallback.onCallFilteringComplete(mIncomingCall, result);
        } finally {
            Log.endSession();
+9 −3
Original line number Diff line number Diff line
@@ -30,9 +30,15 @@ public class BlockCheckerAdapter {
     * @param context the context of the caller.
     * @param number the number to check.
     * @param extras the extra attribute of the number.
     * @return {@code true} if the number is blocked. {@code false} otherwise.
     * @return result code indicating if the number should be blocked, and if so why.
     *         Valid values are: {@link android.provider.BlockedNumberContract#STATUS_NOT_BLOCKED},
     *         {@link android.provider.BlockedNumberContract#STATUS_BLOCKED_IN_LIST},
     *         {@link android.provider.BlockedNumberContract#STATUS_BLOCKED_NOT_IN_CONTACTS},
     *         {@link android.provider.BlockedNumberContract#STATUS_BLOCKED_PAYPHONE},
     *         {@link android.provider.BlockedNumberContract#STATUS_BLOCKED_RESTRICTED},
     *         {@link android.provider.BlockedNumberContract#STATUS_BLOCKED_UNKNOWN_NUMBER}.
     */
    public boolean isBlocked(Context context, String number, Bundle extras) {
        return BlockChecker.isBlocked(context, number, extras);
    public int getBlockStatus(Context context, String number, Bundle extras) {
        return BlockChecker.getBlockStatus(context, number, extras);
    }
}
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.server.telecom.callfiltering;

import android.os.UserHandle;

/**
 * Listener for components which wish to be notified when a call is blocked.
 */
public interface CallBlockListener {
    void onCallBlocked(int blockStatus, String number, UserHandle userHandle);
}
+12 −9
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.server.telecom.tests;

import static android.provider.BlockedNumberContract.STATUS_BLOCKED_IN_LIST;
import static android.provider.BlockedNumberContract.STATUS_NOT_BLOCKED;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
@@ -79,7 +82,7 @@ public class AsyncBlockCheckFilterTest extends TelecomTestCase {
        super.setUp();
        when(mCall.getHandle()).thenReturn(TEST_HANDLE);
        mFilter = new AsyncBlockCheckFilter(mContext, mBlockCheckerAdapter,
                mCallerInfoLookupHelper);
                mCallerInfoLookupHelper, null);
    }

    @SmallTest
@@ -88,9 +91,9 @@ public class AsyncBlockCheckFilterTest extends TelecomTestCase {
        final CountDownLatch latch = new CountDownLatch(1);
        doAnswer(invocation -> {
            latch.countDown();
            return true;
            return STATUS_BLOCKED_IN_LIST;
        }).when(mBlockCheckerAdapter)
                .isBlocked(any(Context.class), eq(TEST_HANDLE.getSchemeSpecificPart()),
                .getBlockStatus(any(Context.class), eq(TEST_HANDLE.getSchemeSpecificPart()),
                        any(Bundle.class));

        setEnhancedBlockingEnabled(false);
@@ -107,9 +110,9 @@ public class AsyncBlockCheckFilterTest extends TelecomTestCase {
        final CountDownLatch latch = new CountDownLatch(1);
        doAnswer(invocation -> {
            latch.countDown();
            return true;
            return STATUS_BLOCKED_IN_LIST;
        }).when(mBlockCheckerAdapter)
                .isBlocked(any(Context.class), eq(TEST_HANDLE.getSchemeSpecificPart()),
                .getBlockStatus(any(Context.class), eq(TEST_HANDLE.getSchemeSpecificPart()),
                        any(Bundle.class));

        setEnhancedBlockingEnabled(true);
@@ -127,9 +130,9 @@ public class AsyncBlockCheckFilterTest extends TelecomTestCase {
        final CountDownLatch latch = new CountDownLatch(1);
        doAnswer(invocation -> {
            latch.countDown();
            return false;
            return STATUS_NOT_BLOCKED;
        }).when(mBlockCheckerAdapter)
                .isBlocked(any(Context.class), eq(TEST_HANDLE.getSchemeSpecificPart()),
                .getBlockStatus(any(Context.class), eq(TEST_HANDLE.getSchemeSpecificPart()),
                        any(Bundle.class));

        setEnhancedBlockingEnabled(false);
@@ -146,9 +149,9 @@ public class AsyncBlockCheckFilterTest extends TelecomTestCase {
        final CountDownLatch latch = new CountDownLatch(1);
        doAnswer(invocation -> {
            latch.countDown();
            return false;
            return STATUS_NOT_BLOCKED;
        }).when(mBlockCheckerAdapter)
                .isBlocked(any(Context.class), eq(TEST_HANDLE.getSchemeSpecificPart()),
                .getBlockStatus(any(Context.class), eq(TEST_HANDLE.getSchemeSpecificPart()),
                        any(Bundle.class));

        setEnhancedBlockingEnabled(true);