From 639943a7668ad4229942e1207128045d49e9ed02 Mon Sep 17 00:00:00 2001 From: twyen Date: Tue, 17 Oct 2017 18:13:45 -0700 Subject: Support bulk inserted voicemails. Bulk insert is implemented in ag/3073902 When more than one voicemail is inserted into the VoicemailProvider, the URI type is Voicemails.DIR_TYPE instead of ITEM_TYPE. This CL adds support to the new type. Previously when multiple voicemails are being notified, each one of them will generate a ringtone because the notifiction is set to alert children. In this CL, the summary will have alert instead, and will only alert when new voicemails are received. Bug: 21281858 Test: VisualVoicemailNotifierTest PiperOrigin-RevId: 172546076 Change-Id: I4df6098fc3a793139e3d4e77fe1339efdc001944 --- java/com/android/dialer/app/AndroidManifest.xml | 5 +++++ .../dialer/app/calllog/VisualVoicemailNotifier.java | 18 ++++++++++++++++-- .../dialer/app/calllog/VisualVoicemailUpdateTask.java | 5 +++-- .../dialer/simulator/impl/SimulatorNotifications.java | 15 ++++++++++----- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/java/com/android/dialer/app/AndroidManifest.xml b/java/com/android/dialer/app/AndroidManifest.xml index 2ef5dad14..ad771496d 100644 --- a/java/com/android/dialer/app/AndroidManifest.xml +++ b/java/com/android/dialer/app/AndroidManifest.xml @@ -86,6 +86,11 @@ android:mimeType="vnd.android.cursor.item/voicemail" android:scheme="content" /> + diff --git a/java/com/android/dialer/app/calllog/VisualVoicemailNotifier.java b/java/com/android/dialer/app/calllog/VisualVoicemailNotifier.java index 2fd9a2161..4fc956fa8 100644 --- a/java/com/android/dialer/app/calllog/VisualVoicemailNotifier.java +++ b/java/com/android/dialer/app/calllog/VisualVoicemailNotifier.java @@ -64,11 +64,16 @@ final class VisualVoicemailNotifier { */ private static final String GROUP_KEY = "VisualVoicemailGroup"; + /** + * @param shouldAlert whether ringtone or vibration should be made when the notification is posted + * or updated. Should only be true when there is a real new voicemail. + */ public static void showNotifications( @NonNull Context context, @NonNull List newCalls, @NonNull Map contactInfos, - @Nullable String callers) { + @Nullable String callers, + boolean shouldAlert) { LogUtil.enterBlock("VisualVoicemailNotifier.showNotifications"); PendingIntent deleteIntent = CallLogNotificationsService.createMarkAllNewVoicemailsAsOldIntent(context); @@ -86,7 +91,15 @@ final class VisualVoicemailNotifier { .setContentIntent(newVoicemailIntent(context, null)); if (VERSION.SDK_INT >= VERSION_CODES.O) { - groupSummary.setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN); + if (shouldAlert) { + groupSummary.setOnlyAlertOnce(false); + // Group summary will alert when posted/updated + groupSummary.setGroupAlertBehavior(Notification.GROUP_ALERT_ALL); + } else { + // Only children will alert. but since all children are set to "only alert summary" it is + // effectively silenced. + groupSummary.setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN); + } PhoneAccountHandle handle = getAccountForCall(context, newCalls.get(0)); groupSummary.setChannelId(NotificationChannelManager.getVoicemailChannelId(context, handle)); } @@ -203,6 +216,7 @@ final class VisualVoicemailNotifier { if (VERSION.SDK_INT >= VERSION_CODES.O) { builder.setChannelId(NotificationChannelManager.getVoicemailChannelId(context, handle)); + builder.setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY); } ContactPhotoLoader loader = new ContactPhotoLoader(context, contactInfo); diff --git a/java/com/android/dialer/app/calllog/VisualVoicemailUpdateTask.java b/java/com/android/dialer/app/calllog/VisualVoicemailUpdateTask.java index e30623bb2..77b4c1113 100644 --- a/java/com/android/dialer/app/calllog/VisualVoicemailUpdateTask.java +++ b/java/com/android/dialer/app/calllog/VisualVoicemailUpdateTask.java @@ -67,7 +67,7 @@ class VisualVoicemailUpdateTask implements Worker voicemails = new ArrayList<>(); for (int i = NOTIFICATION_COUNT; i > 0; i--) { VoicemailPopulator.Voicemail voicemail = VoicemailPopulator.Voicemail.builder() @@ -54,11 +58,12 @@ final class SimulatorNotifications { .setIsRead(false) .setTimeMillis(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(i)) .build(); - context - .getContentResolver() - .insert( - Voicemails.buildSourceUri(context.getPackageName()), - voicemail.getAsContentValues(context)); + voicemails.add(voicemail.getAsContentValues(context)); } + context + .getContentResolver() + .bulkInsert( + Voicemails.buildSourceUri(context.getPackageName()), + voicemails.toArray(new ContentValues[voicemails.size()])); } } -- cgit v1.2.3