summaryrefslogtreecommitdiff
path: root/src/com
diff options
context:
space:
mode:
authorAndrew Lee <anwlee@google.com>2015-10-27 17:31:31 -0700
committerAndrew Lee <anwlee@google.com>2015-10-28 14:58:53 -0700
commit9155416b1679a84b184959ce83c81d42d2dc7380 (patch)
tree84b8bc6f74829d31eb9719b28b4154c122fc2003 /src/com
parentdc07e74a17aceb566b5a78a8b553ac437102b91a (diff)
Notify for call blocking disabled by E911.
+ Add method and listener to FilteredNumberAsyncQueryHandler to query for whether there are any blocked numbers. + Added utility function for showing a notification, which points to the blocked numbers setting screen. This notification will only be shown if the user has blocked numbers. + Add a boolean flag to track whether we have shown this notification after an emergency call. This is to address the (edge) case where the user makes an emergency call when they have not blocked any numbers, but then later blocks a number. + Added strings for notification. Bug: 25327365 Change-Id: I3179f3884271ea0a504ef8c9a61bf9dfbd18ef10
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java23
-rw-r--r--src/com/android/dialer/filterednumber/FilterNumberDialogFragment.java6
-rw-r--r--src/com/android/dialer/filterednumber/FilteredNumbersUtil.java76
3 files changed, 98 insertions, 7 deletions
diff --git a/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java b/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java
index 25613a6f8..e875f12e5 100644
--- a/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java
+++ b/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java
@@ -78,6 +78,14 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler {
public void onUnblockComplete(int rows, ContentValues values);
}
+ public interface OnHasBlockedNumbersListener {
+ /**
+ * @param hasBlockedNumbers {@code true} if any blocked numbers are stored.
+ * {@code false} otherwise.
+ */
+ public void onHasBlockedNumbers(boolean hasBlockedNumbers);
+ }
+
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
if (cookie != null) {
@@ -120,6 +128,21 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler {
null, null, null);
}
+ public final void hasBlockedNumbersAsync(final OnHasBlockedNumbersListener listener) {
+ startQuery(NO_TOKEN,
+ new Listener() {
+ @Override
+ protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
+ listener.onHasBlockedNumbers(cursor.getCount() > 0);
+ }
+ },
+ getContentUri(null),
+ new String[]{ FilteredNumberColumns._ID },
+ FilteredNumberColumns.TYPE + "=" + FilteredNumberTypes.BLOCKED_NUMBER,
+ null,
+ null);
+ }
+
/**
* Check if the number + country iso given has been blocked.
* This method normalizes the number for the lookup if normalizedNumber is null.
diff --git a/src/com/android/dialer/filterednumber/FilterNumberDialogFragment.java b/src/com/android/dialer/filterednumber/FilterNumberDialogFragment.java
index 8473e324a..4b4af4d2a 100644
--- a/src/com/android/dialer/filterednumber/FilterNumberDialogFragment.java
+++ b/src/com/android/dialer/filterednumber/FilterNumberDialogFragment.java
@@ -21,6 +21,7 @@ import android.app.Dialog;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.content.ContentValues;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.net.Uri;
@@ -187,6 +188,7 @@ public class FilterNumberDialogFragment extends DialogFragment {
final String undoMessage = getUnblockedMessage();
final Callback callback = mCallback;
final int actionTextColor = getActionTextColor();
+ final Context context = getContext();
final OnUnblockNumberListener onUndoListener = new OnUnblockNumberListener() {
@Override
@@ -217,6 +219,10 @@ public class FilterNumberDialogFragment extends DialogFragment {
if (callback != null) {
callback.onChangeFilteredNumberSuccess();
}
+
+ if (context != null && FilteredNumbersUtil.hasRecentEmergencyCall(context)) {
+ FilteredNumbersUtil.maybeNotifyCallBlockingDisabled(context);
+ }
}
};
diff --git a/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java b/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java
index 45fa6b73d..ce7cf8edf 100644
--- a/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java
+++ b/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java
@@ -15,8 +15,12 @@
*/
package com.android.dialer.filterednumber;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
import android.content.ContentValues;
import android.content.Context;
+import android.content.Intent;
import android.database.Cursor;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
@@ -35,6 +39,7 @@ import java.util.List;
import com.android.contacts.common.testing.NeededForTesting;
import com.android.dialer.R;
import com.android.dialer.database.FilteredNumberAsyncQueryHandler;
+import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnHasBlockedNumbersListener;
import com.android.dialer.database.FilteredNumberContract.FilteredNumber;
import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns;
@@ -43,13 +48,21 @@ import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns;
*/
public class FilteredNumbersUtil {
- private static final String HIDE_BLOCKED_CALLS_PREF_KEY = "hide_blocked_calls";
- // Pref key for storing the time, in milliseconds after epoch, of end of the last emergency call.
- private static final String LAST_EMERGENCY_CALL_PREF_KEY = "last_emergency_call";
-
// Disable incoming call blocking if there was a call within the past 2 days.
private static final long RECENT_EMERGENCY_CALL_THRESHOLD_MS = 1000 * 60 * 60 * 24 * 2;
+ private static final String HIDE_BLOCKED_CALLS_PREF_KEY = "hide_blocked_calls";
+ // Pref key for storing the time of end of the last emergency call in milliseconds after epoch.
+ private static final String LAST_EMERGENCY_CALL_MS_PREF_KEY = "last_emergency_call_ms";
+
+ // Pref key for storing whether a notification has been dispatched to notify the user that call
+ // blocking has been disabled because of a recent emergency call.
+ private static final String NOTIFIED_CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_PREF_KEY =
+ "notified_call_blocking_disabled_by_emergency_call";
+
+ public static final String CALL_BLOCKING_NOTIFICATION_TAG = "call_blocking";
+ public static final int CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_NOTIFICATION_ID = 10;
+
/**
* Used for testing to specify that a custom threshold should be used instead of the default.
* This custom threshold will only be used when setting this log tag to VERBOSE:
@@ -256,7 +269,7 @@ public class FilteredNumbersUtil {
return false;
}
return PreferenceManager.getDefaultSharedPreferences(context)
- .getBoolean(FilteredNumbersUtil.HIDE_BLOCKED_CALLS_PREF_KEY, false);
+ .getBoolean(HIDE_BLOCKED_CALLS_PREF_KEY, false);
}
public static void setShouldHideBlockedCalls(Context context, boolean shouldHide) {
@@ -275,7 +288,7 @@ public class FilteredNumbersUtil {
}
Long lastEmergencyCallTime = PreferenceManager.getDefaultSharedPreferences(context)
- .getLong(LAST_EMERGENCY_CALL_PREF_KEY, 0);
+ .getLong(LAST_EMERGENCY_CALL_MS_PREF_KEY, 0);
if (lastEmergencyCallTime == 0) {
return false;
}
@@ -288,10 +301,59 @@ public class FilteredNumbersUtil {
if (context == null) {
return;
}
+
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
- .putLong(LAST_EMERGENCY_CALL_PREF_KEY, System.currentTimeMillis())
+ .putLong(LAST_EMERGENCY_CALL_MS_PREF_KEY, System.currentTimeMillis())
+ .putBoolean(NOTIFIED_CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_PREF_KEY, false)
.apply();
+
+ maybeNotifyCallBlockingDisabled(context);
+ }
+
+ public static void maybeNotifyCallBlockingDisabled(final Context context) {
+ // Skip if the user has already received a notification for the most recent emergency call.
+ if (PreferenceManager.getDefaultSharedPreferences(context)
+ .getBoolean(NOTIFIED_CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_PREF_KEY, false)) {
+ return;
+ }
+
+ // If the user has blocked numbers, notify that call blocking is temporarily disabled.
+ FilteredNumberAsyncQueryHandler queryHandler =
+ new FilteredNumberAsyncQueryHandler(context.getContentResolver());
+ queryHandler.hasBlockedNumbersAsync(new OnHasBlockedNumbersListener() {
+ @Override
+ public void onHasBlockedNumbers(boolean hasBlockedNumbers) {
+ if (context == null || !hasBlockedNumbers) {
+ return;
+ }
+
+ NotificationManager notificationManager = (NotificationManager)
+ context.getSystemService(Context.NOTIFICATION_SERVICE);
+ Notification.Builder builder = new Notification.Builder(context)
+ .setSmallIcon(R.drawable.ic_block_24dp)
+ .setContentTitle(context.getString(
+ R.string.call_blocking_disabled_notification_title))
+ .setContentText(context.getString(
+ R.string.call_blocking_disabled_notification_text));
+
+ final Intent contentIntent =
+ new Intent(context, ManageBlockedNumbersActivity.class);
+ builder.setContentIntent(PendingIntent.getActivity(
+ context, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT));
+
+ notificationManager.notify(
+ CALL_BLOCKING_NOTIFICATION_TAG,
+ CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_NOTIFICATION_ID,
+ builder.build());
+
+ // Record that the user has been notified for this emergency call.
+ PreferenceManager.getDefaultSharedPreferences(context)
+ .edit()
+ .putBoolean(NOTIFIED_CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_PREF_KEY, true)
+ .apply();
+ }
+ });
}
public static boolean canBlockNumber(Context context, String number) {