diff options
| author | 2016-02-10 11:15:08 -0800 | |
|---|---|---|
| committer | 2016-02-10 12:06:45 -0800 | |
| commit | b87c90ce9fe007043de43f5370e7775d590f11a7 (patch) | |
| tree | 7b8783d3f9ce9b813d6f45d6c324b6bb9f03a85e | |
| parent | f61a847881ad251593e15e322dae39cc9bd1cd10 (diff) | |
Add hidden APIs for number blocking which will be used by the system.
These APIs will ensure that blocking is suppressed after the user contacts emergency services.
BUG: 26989170
Change-Id: Ib78c9faa31a6d4bfb62b690f97d5ca8084d69927
| -rw-r--r-- | core/java/android/provider/BlockedNumberContract.java | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/core/java/android/provider/BlockedNumberContract.java b/core/java/android/provider/BlockedNumberContract.java index ea54f9203873..4d3bea441a3f 100644 --- a/core/java/android/provider/BlockedNumberContract.java +++ b/core/java/android/provider/BlockedNumberContract.java @@ -223,4 +223,98 @@ public class BlockedNumberContract { return res != null && res.getBoolean(RES_CAN_BLOCK_NUMBERS, false); } + /** + * <p> + * The contract between the blockednumber provider and the system. + * </p> + * <p>This is a wrapper over {@link BlockedNumberContract} that also manages the blocking + * behavior when the user contacts emergency services. See + * {@link #notifyEmergencyContact(Context)} for details. All methods are protected by + * {@link android.Manifest.permission#READ_BLOCKED_NUMBERS} and + * {@link android.Manifest.permission#WRITE_BLOCKED_NUMBERS} appropriately which ensure that + * only system can access the methods defined here. + * </p> + * @hide + */ + public static class SystemContract { + /** + * A protected broadcast intent action for letting components with + * {@link android.Manifest.permission#READ_BLOCKED_NUMBERS} know that the block suppressal + * status as returned by {@link #getBlockSuppressalStatus(Context)} has been updated. + */ + public static final String ACTION_BLOCK_SUPPRESSAL_STATE_CHANGED = + "android.provider.action.BLOCK_SUPPRESSAL_STATE_CHANGED"; + + public static final String METHOD_NOTIFY_EMERGENCY_CONTACT = "notify_emergency_contact"; + + public static final String METHOD_END_BLOCK_SUPPRESSAL = "end_block_suppressal"; + + public static final String METHOD_SHOULD_SYSTEM_BLOCK_NUMBER = "should_system_block_number"; + + public static final String METHOD_GET_BLOCK_SUPPRESSAL_STATUS = + "get_block_suppresal_status"; + + public static final String RES_IS_BLOCKING_SUPPRESSED = "blocking_suppressed"; + + public static final String RES_BLOCKING_SUPPRESSED_UNTIL_TIMESTAMP = + "blocking_suppressed_until_timestamp"; + + /** + * Notifies the provider that emergency services were contacted by the user. + * <p> This results in {@link #shouldSystemBlockNumber} returning {@code false} independent + * of the contents of the provider for a duration defined by + * {@link android.telephony.CarrierConfigManager#KEY_DURATION_BLOCKING_DISABLED_AFTER_EMERGENCY_INT} + * the provider unless {@link #endBlockSuppressal(Context)} is called. + */ + public static void notifyEmergencyContact(Context context) { + context.getContentResolver().call( + AUTHORITY_URI, METHOD_NOTIFY_EMERGENCY_CONTACT, null, null); + } + + /** + * Notifies the provider to disable suppressing blocking. If emergency services were not + * contacted recently at all, calling this method is a no-op. + */ + public static void endBlockSuppressal(Context context) { + context.getContentResolver().call( + AUTHORITY_URI, METHOD_END_BLOCK_SUPPRESSAL, null, null); + } + + /** + * Returns {@code true} if {@code phoneNumber} is blocked taking + * {@link #notifyEmergencyContact(Context)} into consideration. If emergency services have + * not been contacted recently, this method is equivalent to + * {@link #isBlocked(Context, String)}. + */ + public static boolean shouldSystemBlockNumber(Context context, String phoneNumber) { + final Bundle res = context.getContentResolver().call( + AUTHORITY_URI, METHOD_SHOULD_SYSTEM_BLOCK_NUMBER, phoneNumber, null); + return res != null && res.getBoolean(RES_NUMBER_IS_BLOCKED, false); + } + + public static BlockSuppressalStatus getBlockSuppressalStatus(Context context) { + final Bundle res = context.getContentResolver().call( + AUTHORITY_URI, METHOD_GET_BLOCK_SUPPRESSAL_STATUS, null, null); + return new BlockSuppressalStatus(res.getBoolean(RES_IS_BLOCKING_SUPPRESSED, false), + res.getLong(RES_BLOCKING_SUPPRESSED_UNTIL_TIMESTAMP, 0)); + } + + /** + * Represents the current status of {@link #shouldSystemBlockNumber(Context, String)}. If + * emergency services have been contacted recently, {@link #isSuppressed} is {@code true}, + * and blocking is disabled until the timestamp {@link #untilTimestampMillis}. + */ + public static class BlockSuppressalStatus { + public final boolean isSuppressed; + /** + * Timestamp in milliseconds from epoch. + */ + public final long untilTimestampMillis; + + BlockSuppressalStatus(boolean isSuppressed, long untilTimestampMillis) { + this.isSuppressed = isSuppressed; + this.untilTimestampMillis = untilTimestampMillis; + } + } + } } |