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

Commit 48a9b957 authored by Tyler Gunn's avatar Tyler Gunn Committed by android-build-merger
Browse files

Add support for receiving blocking reason from provider.

am: 9b05d154

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


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


    @Override
    @Override
@@ -104,7 +107,8 @@ public class AsyncBlockCheckFilter extends AsyncTask<String, Void, Boolean>
                extras.putBoolean(BlockedNumberContract.EXTRA_CONTACT_EXIST,
                extras.putBoolean(BlockedNumberContract.EXTRA_CONTACT_EXIST,
                        Boolean.valueOf(params[2]));
                        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 {
        } finally {
            Log.endSession();
            Log.endSession();
        }
        }
@@ -122,6 +126,12 @@ public class AsyncBlockCheckFilter extends AsyncTask<String, Void, Boolean>
                        false, //shouldAddToCallLog
                        false, //shouldAddToCallLog
                        false // shouldShowNotification
                        false // shouldShowNotification
                );
                );
                if (mCallBlockListener != null) {
                    String number = mIncomingCall.getHandle() == null ? null
                            : mIncomingCall.getHandle().getSchemeSpecificPart();
                    mCallBlockListener.onCallBlocked(mBlockStatus, number,
                            mIncomingCall.getInitiatingUser());
                }
            } else {
            } else {
                result = new CallFilteringResult(
                result = new CallFilteringResult(
                        true, // shouldAllowCall
                        true, // shouldAllowCall
@@ -130,7 +140,9 @@ public class AsyncBlockCheckFilter extends AsyncTask<String, Void, Boolean>
                        true // shouldShowNotification
                        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);
            mCallback.onCallFilteringComplete(mIncomingCall, result);
        } finally {
        } finally {
            Log.endSession();
            Log.endSession();
+9 −3
Original line number Original line Diff line number Diff line
@@ -30,9 +30,15 @@ public class BlockCheckerAdapter {
     * @param context the context of the caller.
     * @param context the context of the caller.
     * @param number the number to check.
     * @param number the number to check.
     * @param extras the extra attribute of the number.
     * @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) {
    public int getBlockStatus(Context context, String number, Bundle extras) {
        return BlockChecker.isBlocked(context, number, extras);
        return BlockChecker.getBlockStatus(context, number, extras);
    }
    }
}
}
+26 −0
Original line number Original line 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 Original line Diff line number Diff line
@@ -16,6 +16,9 @@


package com.android.server.telecom.tests;
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.content.Context;
import android.net.Uri;
import android.net.Uri;
import android.os.Bundle;
import android.os.Bundle;
@@ -79,7 +82,7 @@ public class AsyncBlockCheckFilterTest extends TelecomTestCase {
        super.setUp();
        super.setUp();
        when(mCall.getHandle()).thenReturn(TEST_HANDLE);
        when(mCall.getHandle()).thenReturn(TEST_HANDLE);
        mFilter = new AsyncBlockCheckFilter(mContext, mBlockCheckerAdapter,
        mFilter = new AsyncBlockCheckFilter(mContext, mBlockCheckerAdapter,
                mCallerInfoLookupHelper);
                mCallerInfoLookupHelper, null);
    }
    }


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


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


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


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


        setEnhancedBlockingEnabled(true);
        setEnhancedBlockingEnabled(true);