Loading src/com/android/server/telecom/CallsManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -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, Loading src/com/android/server/telecom/callfiltering/AsyncBlockCheckFilter.java +15 −3 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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(); } Loading @@ -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 Loading @@ -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(); Loading src/com/android/server/telecom/callfiltering/BlockCheckerAdapter.java +9 −3 Original line number Diff line number Diff line Loading @@ -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); } } src/com/android/server/telecom/callfiltering/CallBlockListener.java 0 → 100644 +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); } tests/src/com/android/server/telecom/tests/AsyncBlockCheckFilterTest.java +12 −9 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading Loading
src/com/android/server/telecom/CallsManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -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, Loading
src/com/android/server/telecom/callfiltering/AsyncBlockCheckFilter.java +15 −3 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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(); } Loading @@ -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 Loading @@ -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(); Loading
src/com/android/server/telecom/callfiltering/BlockCheckerAdapter.java +9 −3 Original line number Diff line number Diff line Loading @@ -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); } }
src/com/android/server/telecom/callfiltering/CallBlockListener.java 0 → 100644 +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); }
tests/src/com/android/server/telecom/tests/AsyncBlockCheckFilterTest.java +12 −9 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading