1 package com.android.internal.telephony;
2 
3 import android.content.Context;
4 import android.provider.BlockedNumberContract;
5 import android.telephony.Rlog;
6 
7 /**
8  * {@hide} Checks for blocked phone numbers against {@link BlockedNumberContract}
9  */
10 public class BlockChecker {
11     private static final String TAG = "BlockChecker";
12     private static final boolean VDBG = false; // STOPSHIP if true.
13 
14     /**
15      * Returns {@code true} if {@code phoneNumber} is blocked.
16      * <p>
17      * This method catches all underlying exceptions to ensure that this method never throws any
18      * exception.
19      */
isBlocked(Context context, String phoneNumber)20     public static boolean isBlocked(Context context, String phoneNumber) {
21         boolean isBlocked = false;
22         long startTimeNano = System.nanoTime();
23 
24         try {
25             if (BlockedNumberContract.SystemContract.shouldSystemBlockNumber(
26                     context, phoneNumber)) {
27                 Rlog.d(TAG, phoneNumber + " is blocked.");
28                 isBlocked = true;
29             }
30         } catch (Exception e) {
31             Rlog.e(TAG, "Exception checking for blocked number: " + e);
32         }
33 
34         int durationMillis = (int) ((System.nanoTime() - startTimeNano) / 1000000);
35         if (durationMillis > 500 || VDBG) {
36             Rlog.d(TAG, "Blocked number lookup took: " + durationMillis + " ms.");
37         }
38         return isBlocked;
39     }
40 }
41