summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortwyen <twyen@google.com>2018-04-30 15:33:07 -0700
committerCopybara-Service <copybara-piper@google.com>2018-04-30 18:19:26 -0700
commita7f50f29f0a762acc7d80691a939cd54207b7533 (patch)
tree16ab39fe7c61cc352d9e81624e4771bd03bc7345
parent277d88f0f375a6bcf9f72402367370469a682829 (diff)
Cancel all legacy voicemail notification when SIMs are removed on multi-SIM devices
When the SIM is removed, telephony will signal cancel notifications on the "null" account (the framework doen't know what was there.). Previously this has no effect. In this CL, all legacy voicemail notifications are removed since all SIM will be removed together. TEST=TAP Bug: 78446801 Test: TAP PiperOrigin-RevId: 194856211 Change-Id: I5df97f0c73e0644daa46ab182f19e60044e39d96
-rw-r--r--java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java22
-rw-r--r--java/com/android/dialer/notification/DialerNotificationManager.java10
2 files changed, 26 insertions, 6 deletions
diff --git a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java
index f37d52d68..f142399d7 100644
--- a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java
+++ b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java
@@ -145,10 +145,10 @@ public final class LegacyVoicemailNotifier {
return phoneAccount.getShortDescription().toString();
}
}
- return String.format(
- context.getString(R.string.notification_voicemail_text_format),
- PhoneNumberHelper.formatNumber(
- context, voicemailNumber, GeoUtil.getCurrentCountryIso(context)));
+ return String.format(
+ context.getString(R.string.notification_voicemail_text_format),
+ PhoneNumberHelper.formatNumber(
+ context, voicemailNumber, GeoUtil.getCurrentCountryIso(context)));
}
public static void cancelNotification(
@@ -156,8 +156,18 @@ public final class LegacyVoicemailNotifier {
LogUtil.enterBlock("LegacyVoicemailNotifier.cancelNotification");
Assert.checkArgument(BuildCompat.isAtLeastO());
Assert.isNotNull(phoneAccountHandle);
- DialerNotificationManager.cancel(
- context, getNotificationTag(context, phoneAccountHandle), NOTIFICATION_ID);
+ if ("null".equals(phoneAccountHandle.getId())) {
+ // while PhoneAccountHandle itself will never be null, telephony may still construct a "null"
+ // handle if the SIM is no longer available. Usually both SIM will be removed at the sames
+ // time, so just clear all notifications.
+ LogUtil.i(
+ "LegacyVoicemailNotifier.cancelNotification",
+ "'null' id, canceling all legacy voicemail notifications");
+ DialerNotificationManager.cancelAll(context, NOTIFICATION_TAG);
+ } else {
+ DialerNotificationManager.cancel(
+ context, getNotificationTag(context, phoneAccountHandle), NOTIFICATION_ID);
+ }
}
@NonNull
diff --git a/java/com/android/dialer/notification/DialerNotificationManager.java b/java/com/android/dialer/notification/DialerNotificationManager.java
index 0e3420169..2a66cd5ac 100644
--- a/java/com/android/dialer/notification/DialerNotificationManager.java
+++ b/java/com/android/dialer/notification/DialerNotificationManager.java
@@ -83,6 +83,16 @@ public final class DialerNotificationManager {
notificationManager.cancel(tag, id);
}
+ public static void cancelAll(Context context, String prefix) {
+ NotificationManager notificationManager = getNotificationManager(context);
+ StatusBarNotification[] notifications = notificationManager.getActiveNotifications();
+ for (StatusBarNotification notification : notifications) {
+ if (notification.getTag() != null && notification.getTag().startsWith(prefix)) {
+ notificationManager.cancel(notification.getTag(), notification.getId());
+ }
+ }
+ }
+
public static StatusBarNotification[] getActiveNotifications(@NonNull Context context) {
Assert.isNotNull(context);
return getNotificationManager(context).getActiveNotifications();