From aec0aa5f040c3d192ddb46e63f5383d35d918f36 Mon Sep 17 00:00:00 2001 From: twyen Date: Mon, 31 Jul 2017 12:07:04 -0700 Subject: Save dismissed state for legacy voicemail notification TelephonyManager will resend legacy voicemail notifications during connectivity changes with a "is_refresh" flag. Such notifications has already been shown before and should not alert the user. Previously the notification will be set to onlyAlertOnce, but if the user dismissed it it will be shown again. In this CL, if the notification is dismissed, the state will be persisted and the notification will not be shown again. The state will be cleared when a new voicemail arrived and the user will be notified again. Since telephony sends is_refresh=false during boot up, the state will also be cleared with a reboot. Bug: 62229933 Test: LegacyVoicemailNotificationReceieverTest PiperOrigin-RevId: 163728161 Change-Id: I7ec6b5a88fed26e0a4459b8803eeba9a37b7b32b --- .../app/calllog/CallLogNotificationsService.java | 20 ++++++++++++++++++++ .../dialer/app/calllog/LegacyVoicemailNotifier.java | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'java/com/android/dialer/app/calllog') diff --git a/java/com/android/dialer/app/calllog/CallLogNotificationsService.java b/java/com/android/dialer/app/calllog/CallLogNotificationsService.java index 84aedf880..536255a2a 100644 --- a/java/com/android/dialer/app/calllog/CallLogNotificationsService.java +++ b/java/com/android/dialer/app/calllog/CallLogNotificationsService.java @@ -25,6 +25,8 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; import android.support.annotation.WorkerThread; +import android.telecom.PhoneAccountHandle; +import com.android.dialer.app.voicemail.LegacyVoicemailNotificationReceiver; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.DialerExecutor.Worker; @@ -68,6 +70,10 @@ public class CallLogNotificationsService extends IntentService { public static final String ACTION_CALL_BACK_FROM_MISSED_CALL_NOTIFICATION = "com.android.dialer.calllog.CALL_BACK_FROM_MISSED_CALL_NOTIFICATION"; + /** Action mark legacy voicemail as dismissed. */ + public static final String ACTION_LEGACY_VOICEMAIL_DISMISSED = + "com.android.dialer.calllog.ACTION_LEGACY_VOICEMAIL_DISMISSED"; + /** * Extra to be included with {@link #ACTION_INCOMING_POST_CALL} to represent a post call note. * @@ -83,6 +89,8 @@ public class CallLogNotificationsService extends IntentService { */ private static final String EXTRA_POST_CALL_NUMBER = "POST_CALL_NUMBER"; + private static final String EXTRA_PHONE_ACCOUNT_HANDLE = "PHONE_ACCOUNT_HANDLE"; + public static final int UNKNOWN_MISSED_CALL_COUNT = -1; public CallLogNotificationsService() { @@ -149,6 +157,14 @@ public class CallLogNotificationsService extends IntentService { return PendingIntent.getService(context, 0, intent, 0); } + public static PendingIntent createLegacyVoicemailDismissedPendingIntent( + @NonNull Context context, PhoneAccountHandle phoneAccountHandle) { + Intent intent = new Intent(context, CallLogNotificationsService.class); + intent.setAction(ACTION_LEGACY_VOICEMAIL_DISMISSED); + intent.putExtra(EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle); + return PendingIntent.getService(context, 0, intent, 0); + } + @Override protected void onHandleIntent(Intent intent) { if (intent == null) { @@ -174,6 +190,10 @@ public class CallLogNotificationsService extends IntentService { VoicemailQueryHandler.markSingleNewVoicemailAsRead(this, voicemailUri); VisualVoicemailNotifier.cancelSingleVoicemailNotification(this, voicemailUri); break; + case ACTION_LEGACY_VOICEMAIL_DISMISSED: + LegacyVoicemailNotificationReceiver.setDismissed( + this, intent.getParcelableExtra(EXTRA_PHONE_ACCOUNT_HANDLE), true); + break; case ACTION_INCOMING_POST_CALL: String note = intent.getStringExtra(EXTRA_POST_CALL_NOTE); String phoneNumber = intent.getStringExtra(EXTRA_POST_CALL_NUMBER); diff --git a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java index 428c71677..c64e03e4e 100644 --- a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java +++ b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java @@ -122,7 +122,10 @@ public final class LegacyVoicemailNotifier { .setSound(pinnedTelephonyManager.getVoicemailRingtoneUri(handle)) .setOngoing(isOngoing) .setOnlyAlertOnce(isRefresh) - .setChannelId(NotificationChannelManager.getVoicemailChannelId(context, handle)); + .setChannelId(NotificationChannelManager.getVoicemailChannelId(context, handle)) + .setDeleteIntent( + CallLogNotificationsService.createLegacyVoicemailDismissedPendingIntent( + context, handle)); if (pinnedTelephonyManager.isVoicemailVibrationEnabled(handle)) { builder.setDefaults(Notification.DEFAULT_VIBRATE); -- cgit v1.2.3