Loading src/java/com/android/internal/telephony/AsyncEmergencyContactNotifier.java +3 −19 Original line number Original line Diff line number Diff line Loading @@ -24,7 +24,8 @@ import com.android.telephony.Rlog; /** /** * An {@link AsyncTask} that notifies the Blocked number provider that emergency services were * An {@link AsyncTask} that notifies the Blocked number provider that emergency services were * contacted. * contacted. See {@link BlockedNumberContract.SystemContract#notifyEmergencyContact(Context)} * for details. * {@hide} * {@hide} */ */ public class AsyncEmergencyContactNotifier extends AsyncTask<Void, Void, Void> { public class AsyncEmergencyContactNotifier extends AsyncTask<Void, Void, Void> { Loading @@ -39,27 +40,10 @@ public class AsyncEmergencyContactNotifier extends AsyncTask<Void, Void, Void> { @Override @Override protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) { try { try { notifyEmergencyContact(mContext); BlockedNumberContract.SystemContract.notifyEmergencyContact(mContext); } catch (Exception e) { } catch (Exception e) { Rlog.e(TAG, "Exception notifying emergency contact: " + e); Rlog.e(TAG, "Exception notifying emergency contact: " + e); } } return null; return null; } } /** * Notifies the provider that emergency services were contacted by the user. */ private void notifyEmergencyContact(Context context) { try { Rlog.i("notifyEmergencyContact; caller=%s", context.getOpPackageName()); context.getContentResolver().call( BlockedNumberContract.AUTHORITY_URI, BlockedNumberContract.METHOD_NOTIFY_EMERGENCY_CONTACT, null, null); } catch (NullPointerException | IllegalArgumentException ex) { // The content resolver can throw an NPE or IAE; we don't want to crash Telecom if // either of these happen. Rlog.w(null, "notifyEmergencyContact: provider not ready."); } } } } src/java/com/android/internal/telephony/BlockChecker.java +2 −60 Original line number Original line Diff line number Diff line Loading @@ -68,7 +68,8 @@ public class BlockChecker { long startTimeNano = System.nanoTime(); long startTimeNano = System.nanoTime(); try { try { blockStatus = shouldSystemBlockNumber(context, phoneNumber, extras); blockStatus = BlockedNumberContract.SystemContract.shouldSystemBlockNumber( context, phoneNumber, extras); if (blockStatus != BlockedNumberContract.STATUS_NOT_BLOCKED) { if (blockStatus != BlockedNumberContract.STATUS_NOT_BLOCKED) { Rlog.d(TAG, phoneNumber + " is blocked."); Rlog.d(TAG, phoneNumber + " is blocked."); } } Loading @@ -81,63 +82,4 @@ public class BlockChecker { } } return blockStatus; return blockStatus; } } /** * Returns {@code true} if {@code phoneNumber} is blocked taking * {@link #notifyEmergencyContact(Context)} into consideration. If emergency services * have not been contacted recently and enhanced call blocking not been enabled, this * method is equivalent to {@link #isBlocked(Context, String)}. * * @param context the context of the caller. * @param phoneNumber the number to check. * @param extras the extra attribute of the number. * @return result code indicating if the number should be blocked, and if so why. * Valid values are: {@link #STATUS_NOT_BLOCKED}, {@link #STATUS_BLOCKED_IN_LIST}, * {@link #STATUS_BLOCKED_NOT_IN_CONTACTS}, {@link #STATUS_BLOCKED_PAYPHONE}, * {@link #STATUS_BLOCKED_RESTRICTED}, {@link #STATUS_BLOCKED_UNKNOWN_NUMBER}. */ private static int shouldSystemBlockNumber(Context context, String phoneNumber, Bundle extras) { try { String caller = context.getOpPackageName(); final Bundle res = context.getContentResolver().call( BlockedNumberContract.AUTHORITY_URI, BlockedNumberContract.METHOD_SHOULD_SYSTEM_BLOCK_NUMBER, phoneNumber, extras); int blockResult = res != null ? res.getInt(BlockedNumberContract.RES_BLOCK_STATUS, BlockedNumberContract.STATUS_NOT_BLOCKED) : BlockedNumberContract.STATUS_NOT_BLOCKED; Rlog.d(TAG, "shouldSystemBlockNumber: number=" + Rlog.pii(TAG, phoneNumber) + "caller=" + caller + "result=" + blockStatusToString(blockResult)); return blockResult; } catch (NullPointerException | IllegalArgumentException ex) { // The content resolver can throw an NPE or IAE; we don't want to crash Telecom if // either of these happen. Rlog.w(null, "shouldSystemBlockNumber: provider not ready."); return BlockedNumberContract.STATUS_NOT_BLOCKED; } } /** * Converts a block status constant to a string equivalent for logging. * @hide */ private static String blockStatusToString(int blockStatus) { switch (blockStatus) { case BlockedNumberContract.STATUS_NOT_BLOCKED: return "not blocked"; case BlockedNumberContract.STATUS_BLOCKED_IN_LIST: return "blocked - in list"; case BlockedNumberContract.STATUS_BLOCKED_RESTRICTED: return "blocked - restricted"; case BlockedNumberContract.STATUS_BLOCKED_UNKNOWN_NUMBER: return "blocked - unknown"; case BlockedNumberContract.STATUS_BLOCKED_PAYPHONE: return "blocked - payphone"; case BlockedNumberContract.STATUS_BLOCKED_NOT_IN_CONTACTS: return "blocked - not in contacts"; } return "unknown"; } } } tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -680,14 +680,14 @@ public abstract class TelephonyTest { @Override @Override public Bundle call(String method, String arg, Bundle extras) { public Bundle call(String method, String arg, Bundle extras) { switch (method) { switch (method) { case BlockedNumberContract.METHOD_SHOULD_SYSTEM_BLOCK_NUMBER: case BlockedNumberContract.SystemContract.METHOD_SHOULD_SYSTEM_BLOCK_NUMBER: Bundle bundle = new Bundle(); Bundle bundle = new Bundle(); int blockStatus = mBlockedNumbers.contains(arg) int blockStatus = mBlockedNumbers.contains(arg) ? BlockedNumberContract.STATUS_BLOCKED_IN_LIST ? BlockedNumberContract.STATUS_BLOCKED_IN_LIST : BlockedNumberContract.STATUS_NOT_BLOCKED; : BlockedNumberContract.STATUS_NOT_BLOCKED; bundle.putInt(BlockedNumberContract.RES_BLOCK_STATUS, blockStatus); bundle.putInt(BlockedNumberContract.RES_BLOCK_STATUS, blockStatus); return bundle; return bundle; case BlockedNumberContract.METHOD_NOTIFY_EMERGENCY_CONTACT: case BlockedNumberContract.SystemContract.METHOD_NOTIFY_EMERGENCY_CONTACT: mNumEmergencyContactNotifications++; mNumEmergencyContactNotifications++; return new Bundle(); return new Bundle(); default: default: Loading Loading
src/java/com/android/internal/telephony/AsyncEmergencyContactNotifier.java +3 −19 Original line number Original line Diff line number Diff line Loading @@ -24,7 +24,8 @@ import com.android.telephony.Rlog; /** /** * An {@link AsyncTask} that notifies the Blocked number provider that emergency services were * An {@link AsyncTask} that notifies the Blocked number provider that emergency services were * contacted. * contacted. See {@link BlockedNumberContract.SystemContract#notifyEmergencyContact(Context)} * for details. * {@hide} * {@hide} */ */ public class AsyncEmergencyContactNotifier extends AsyncTask<Void, Void, Void> { public class AsyncEmergencyContactNotifier extends AsyncTask<Void, Void, Void> { Loading @@ -39,27 +40,10 @@ public class AsyncEmergencyContactNotifier extends AsyncTask<Void, Void, Void> { @Override @Override protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) { try { try { notifyEmergencyContact(mContext); BlockedNumberContract.SystemContract.notifyEmergencyContact(mContext); } catch (Exception e) { } catch (Exception e) { Rlog.e(TAG, "Exception notifying emergency contact: " + e); Rlog.e(TAG, "Exception notifying emergency contact: " + e); } } return null; return null; } } /** * Notifies the provider that emergency services were contacted by the user. */ private void notifyEmergencyContact(Context context) { try { Rlog.i("notifyEmergencyContact; caller=%s", context.getOpPackageName()); context.getContentResolver().call( BlockedNumberContract.AUTHORITY_URI, BlockedNumberContract.METHOD_NOTIFY_EMERGENCY_CONTACT, null, null); } catch (NullPointerException | IllegalArgumentException ex) { // The content resolver can throw an NPE or IAE; we don't want to crash Telecom if // either of these happen. Rlog.w(null, "notifyEmergencyContact: provider not ready."); } } } }
src/java/com/android/internal/telephony/BlockChecker.java +2 −60 Original line number Original line Diff line number Diff line Loading @@ -68,7 +68,8 @@ public class BlockChecker { long startTimeNano = System.nanoTime(); long startTimeNano = System.nanoTime(); try { try { blockStatus = shouldSystemBlockNumber(context, phoneNumber, extras); blockStatus = BlockedNumberContract.SystemContract.shouldSystemBlockNumber( context, phoneNumber, extras); if (blockStatus != BlockedNumberContract.STATUS_NOT_BLOCKED) { if (blockStatus != BlockedNumberContract.STATUS_NOT_BLOCKED) { Rlog.d(TAG, phoneNumber + " is blocked."); Rlog.d(TAG, phoneNumber + " is blocked."); } } Loading @@ -81,63 +82,4 @@ public class BlockChecker { } } return blockStatus; return blockStatus; } } /** * Returns {@code true} if {@code phoneNumber} is blocked taking * {@link #notifyEmergencyContact(Context)} into consideration. If emergency services * have not been contacted recently and enhanced call blocking not been enabled, this * method is equivalent to {@link #isBlocked(Context, String)}. * * @param context the context of the caller. * @param phoneNumber the number to check. * @param extras the extra attribute of the number. * @return result code indicating if the number should be blocked, and if so why. * Valid values are: {@link #STATUS_NOT_BLOCKED}, {@link #STATUS_BLOCKED_IN_LIST}, * {@link #STATUS_BLOCKED_NOT_IN_CONTACTS}, {@link #STATUS_BLOCKED_PAYPHONE}, * {@link #STATUS_BLOCKED_RESTRICTED}, {@link #STATUS_BLOCKED_UNKNOWN_NUMBER}. */ private static int shouldSystemBlockNumber(Context context, String phoneNumber, Bundle extras) { try { String caller = context.getOpPackageName(); final Bundle res = context.getContentResolver().call( BlockedNumberContract.AUTHORITY_URI, BlockedNumberContract.METHOD_SHOULD_SYSTEM_BLOCK_NUMBER, phoneNumber, extras); int blockResult = res != null ? res.getInt(BlockedNumberContract.RES_BLOCK_STATUS, BlockedNumberContract.STATUS_NOT_BLOCKED) : BlockedNumberContract.STATUS_NOT_BLOCKED; Rlog.d(TAG, "shouldSystemBlockNumber: number=" + Rlog.pii(TAG, phoneNumber) + "caller=" + caller + "result=" + blockStatusToString(blockResult)); return blockResult; } catch (NullPointerException | IllegalArgumentException ex) { // The content resolver can throw an NPE or IAE; we don't want to crash Telecom if // either of these happen. Rlog.w(null, "shouldSystemBlockNumber: provider not ready."); return BlockedNumberContract.STATUS_NOT_BLOCKED; } } /** * Converts a block status constant to a string equivalent for logging. * @hide */ private static String blockStatusToString(int blockStatus) { switch (blockStatus) { case BlockedNumberContract.STATUS_NOT_BLOCKED: return "not blocked"; case BlockedNumberContract.STATUS_BLOCKED_IN_LIST: return "blocked - in list"; case BlockedNumberContract.STATUS_BLOCKED_RESTRICTED: return "blocked - restricted"; case BlockedNumberContract.STATUS_BLOCKED_UNKNOWN_NUMBER: return "blocked - unknown"; case BlockedNumberContract.STATUS_BLOCKED_PAYPHONE: return "blocked - payphone"; case BlockedNumberContract.STATUS_BLOCKED_NOT_IN_CONTACTS: return "blocked - not in contacts"; } return "unknown"; } } }
tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -680,14 +680,14 @@ public abstract class TelephonyTest { @Override @Override public Bundle call(String method, String arg, Bundle extras) { public Bundle call(String method, String arg, Bundle extras) { switch (method) { switch (method) { case BlockedNumberContract.METHOD_SHOULD_SYSTEM_BLOCK_NUMBER: case BlockedNumberContract.SystemContract.METHOD_SHOULD_SYSTEM_BLOCK_NUMBER: Bundle bundle = new Bundle(); Bundle bundle = new Bundle(); int blockStatus = mBlockedNumbers.contains(arg) int blockStatus = mBlockedNumbers.contains(arg) ? BlockedNumberContract.STATUS_BLOCKED_IN_LIST ? BlockedNumberContract.STATUS_BLOCKED_IN_LIST : BlockedNumberContract.STATUS_NOT_BLOCKED; : BlockedNumberContract.STATUS_NOT_BLOCKED; bundle.putInt(BlockedNumberContract.RES_BLOCK_STATUS, blockStatus); bundle.putInt(BlockedNumberContract.RES_BLOCK_STATUS, blockStatus); return bundle; return bundle; case BlockedNumberContract.METHOD_NOTIFY_EMERGENCY_CONTACT: case BlockedNumberContract.SystemContract.METHOD_NOTIFY_EMERGENCY_CONTACT: mNumEmergencyContactNotifications++; mNumEmergencyContactNotifications++; return new Bundle(); return new Bundle(); default: default: Loading