summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/app/calllog/MissedCallNotifier.java
diff options
context:
space:
mode:
authorzachh <zachh@google.com>2018-02-12 16:49:00 -0800
committerCopybara-Service <copybara-piper@google.com>2018-02-14 17:49:49 -0800
commit39009b4ad73d5017295b30fb18a77224195f06af (patch)
treefb432a423f670969da57a4900b5ff7dcc35d2f8c /java/com/android/dialer/app/calllog/MissedCallNotifier.java
parentc266566db55647ac1e27f686b6f03440c5eee36b (diff)
Mark calls as read in new call log.
Playing with the existing app, the missed call becomes unbolded when: 1) Expanding the row. The closest analog of this is in the new UI is opening the bottom sheet, I've done that. 2) Swiping away from the call history tab. This can't be done in NewCallLogFragment because it doesn't know if the user is selected a new tab or pressed Home. So, I implemented this in NewMainActivityPeer. 3) After viewing the call log for 3(ish) seconds and leaving the activity pressing Home/Back. This is best done in NewCallLogFragment#onResume since MainActivity doesn't always know when the fragment is being displayed (it could be done after the user comes back to the app after pressing Home for example). Note that the notification is also removed in all of these cases. Also note that dismissing the notification makes the call unbolded (but this case already appears to be handled via the system call log content observer). Also, as part of writing tests for this, I made TestCallLogProvider more realistic. Bug: 70989622 Test: manual PiperOrigin-RevId: 185457438 Change-Id: Ib360d3bc73083bd1a018ed98e2b7d9a69fb7fafb
Diffstat (limited to 'java/com/android/dialer/app/calllog/MissedCallNotifier.java')
-rw-r--r--java/com/android/dialer/app/calllog/MissedCallNotifier.java59
1 files changed, 17 insertions, 42 deletions
diff --git a/java/com/android/dialer/app/calllog/MissedCallNotifier.java b/java/com/android/dialer/app/calllog/MissedCallNotifier.java
index 417f8f0f9..14bbdfa56 100644
--- a/java/com/android/dialer/app/calllog/MissedCallNotifier.java
+++ b/java/com/android/dialer/app/calllog/MissedCallNotifier.java
@@ -58,7 +58,9 @@ import com.android.dialer.duo.DuoConstants;
import com.android.dialer.enrichedcall.FuzzyPhoneNumberMatcher;
import com.android.dialer.notification.DialerNotificationManager;
import com.android.dialer.notification.NotificationChannelId;
-import com.android.dialer.notification.NotificationManagerUtils;
+import com.android.dialer.notification.missedcalls.MissedCallConstants;
+import com.android.dialer.notification.missedcalls.MissedCallNotificationCanceller;
+import com.android.dialer.notification.missedcalls.MissedCallNotificationTags;
import com.android.dialer.phonenumbercache.ContactInfo;
import com.android.dialer.phonenumberutil.PhoneNumberHelper;
import com.android.dialer.precall.PreCall;
@@ -71,18 +73,6 @@ import java.util.Set;
/** Creates a notification for calls that the user missed (neither answered nor rejected). */
public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> {
- /** Prefix used to generate a unique tag for each missed call notification. */
- private static final String NOTIFICATION_TAG_PREFIX = "MissedCall_";
- /** Common ID for all missed call notifications. */
- private static final int NOTIFICATION_ID = 1;
- /** Tag for the group summary notification. */
- private static final String GROUP_SUMMARY_NOTIFICATION_TAG = "GroupSummary_MissedCall";
- /**
- * Key used to associate all missed call notifications and the summary as belonging to a single
- * group.
- */
- private static final String GROUP_KEY = "MissedCallGroup";
-
private final Context context;
private final CallLogNotificationsQueryHelper callLogNotificationsQueryHelper;
@@ -126,7 +116,7 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> {
if ((newCalls != null && newCalls.isEmpty()) || count == 0) {
// No calls to notify about: clear the notification.
CallLogNotificationsQueryHelper.markAllMissedCallsInCallLogAsRead(context);
- cancelAllMissedCallNotifications(context);
+ MissedCallNotificationCanceller.cancelAll(context);
return;
}
@@ -226,7 +216,10 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> {
LogUtil.i("MissedCallNotifier.updateMissedCallNotification", "adding missed call notification");
DialerNotificationManager.notify(
- context, GROUP_SUMMARY_NOTIFICATION_TAG, NOTIFICATION_ID, notification);
+ context,
+ MissedCallConstants.GROUP_SUMMARY_NOTIFICATION_TAG,
+ MissedCallConstants.NOTIFICATION_ID,
+ notification);
if (useCallList) {
// Do not repost active notifications to prevent erasing post call notes.
@@ -240,7 +233,10 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> {
String callTag = getNotificationTagForCall(call);
if (!activeTags.contains(callTag)) {
DialerNotificationManager.notify(
- context, callTag, NOTIFICATION_ID, getNotificationForCall(call, null));
+ context,
+ callTag,
+ MissedCallConstants.NOTIFICATION_ID,
+ getNotificationForCall(call, null));
}
}
}
@@ -286,29 +282,8 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> {
}
}
- public static void cancelAllMissedCallNotifications(@NonNull Context context) {
- NotificationManagerUtils.cancelAllInGroup(context, GROUP_KEY);
- }
-
- public static void cancelSingleMissedCallNotification(
- @NonNull Context context, @Nullable Uri callUri) {
- if (callUri == null) {
- LogUtil.e(
- "MissedCallNotifier.cancelSingleMissedCallNotification",
- "unable to cancel notification, uri is null");
- return;
- }
- // This will also dismiss the group summary if there are no more missed call notifications.
- DialerNotificationManager.cancel(
- context, getNotificationTagForCallUri(callUri), NOTIFICATION_ID);
- }
-
private static String getNotificationTagForCall(@NonNull NewCall call) {
- return getNotificationTagForCallUri(call.callsUri);
- }
-
- private static String getNotificationTagForCallUri(@NonNull Uri callUri) {
- return NOTIFICATION_TAG_PREFIX + callUri;
+ return MissedCallNotificationTags.getNotificationTagForCallUri(call.callsUri);
}
@WorkerThread
@@ -324,7 +299,7 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> {
DialerNotificationManager.notify(
context,
getNotificationTagForCall(call),
- NOTIFICATION_ID,
+ MissedCallConstants.NOTIFICATION_ID,
getNotificationForCall(call, note));
return;
}
@@ -408,7 +383,7 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> {
private Notification.Builder createNotificationBuilder() {
return new Notification.Builder(context)
- .setGroup(GROUP_KEY)
+ .setGroup(MissedCallConstants.GROUP_KEY)
.setSmallIcon(android.R.drawable.stat_notify_missed_call)
.setColor(context.getResources().getColor(R.color.dialer_theme_color, null))
.setAutoCancel(true)
@@ -437,7 +412,7 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> {
public void callBackFromMissedCall(String number, Uri callUri) {
closeSystemDialogs(context);
CallLogNotificationsQueryHelper.markSingleMissedCallInCallLogAsRead(context, callUri);
- cancelSingleMissedCallNotification(context, callUri);
+ MissedCallNotificationCanceller.cancelSingle(context, callUri);
DialerUtils.startActivityWithErrorToast(
context,
PreCall.getIntent(
@@ -450,7 +425,7 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> {
public void sendSmsFromMissedCall(String number, Uri callUri) {
closeSystemDialogs(context);
CallLogNotificationsQueryHelper.markSingleMissedCallInCallLogAsRead(context, callUri);
- cancelSingleMissedCallNotification(context, callUri);
+ MissedCallNotificationCanceller.cancelSingle(context, callUri);
DialerUtils.startActivityWithErrorToast(
context, IntentUtil.getSendSmsIntent(number).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}