diff options
author | Eric Erfanian <erfanian@google.com> | 2017-05-16 00:09:31 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-05-16 00:09:31 +0000 |
commit | c57430a61eab62e88372f386c75989dab6332608 (patch) | |
tree | b606f1899f80fcd0ea3ee753ce799883d5a673ab /java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java | |
parent | 9842b4a7fd1d852b1353af806da4913b4298d516 (diff) | |
parent | 0c9dbf507b53a12bdf577ff3e55c1686a2e089de (diff) |
Merge "Update Dialer to v10 RC32" into oc-dev
am: 0c9dbf507b
Change-Id: I5f90090090c6e430d83fcdd294082c1f5237ade8
Diffstat (limited to 'java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java')
-rw-r--r-- | java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java | 61 |
1 files changed, 56 insertions, 5 deletions
diff --git a/java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java b/java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java index d67f12266..58fe6fa2c 100644 --- a/java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java +++ b/java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java @@ -54,17 +54,20 @@ import com.android.dialer.blocking.FilteredNumbersUtil; import com.android.dialer.calllogutils.PhoneAccountUtils; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; +import com.android.dialer.common.concurrent.DialerExecutor.Worker; +import com.android.dialer.common.concurrent.DialerExecutors; import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; import com.android.dialer.notification.NotificationChannelManager; import com.android.dialer.notification.NotificationChannelManager.Channel; import com.android.dialer.phonenumbercache.ContactInfo; +import com.android.dialer.telecom.TelecomUtil; import java.util.Iterator; import java.util.List; import java.util.Map; /** Shows a voicemail notification in the status bar. */ -public class DefaultVoicemailNotifier { +public class DefaultVoicemailNotifier implements Worker<Void, Void> { public static final String TAG = "VoicemailNotifier"; @@ -90,14 +93,20 @@ public class DefaultVoicemailNotifier { this.filteredNumberAsyncQueryHandler = filteredNumberAsyncQueryHandler; } - /** Returns an instance of {@link DefaultVoicemailNotifier}. */ - public static DefaultVoicemailNotifier getInstance(Context context) { - return new DefaultVoicemailNotifier( + public DefaultVoicemailNotifier(Context context) { + this( context, CallLogNotificationsQueryHelper.getInstance(context), new FilteredNumberAsyncQueryHandler(context)); } + @Nullable + @Override + public Void doInBackground(@Nullable Void input) throws Throwable { + updateNotification(); + return null; + } + /** * Updates the notification and notifies of the call with the given URI. * @@ -106,8 +115,9 @@ public class DefaultVoicemailNotifier { * * <p>It is not safe to call this method from the main thread. */ + @VisibleForTesting @WorkerThread - public void updateNotification() { + void updateNotification() { Assert.isWorkerThread(); // Lookup the list of new voicemails to include in the notification. final List<NewCall> newCalls = queryHelper.getNewVoicemails(); @@ -178,6 +188,10 @@ public class DefaultVoicemailNotifier { .setGroupSummary(true) .setContentIntent(newVoicemailIntent(null)); + if (BuildCompat.isAtLeastO()) { + groupSummary.setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN); + } + NotificationChannelManager.applyChannel( groupSummary, context, @@ -392,4 +406,41 @@ public class DefaultVoicemailNotifier { intent.putExtra(DialtactsActivity.EXTRA_CLEAR_NEW_VOICEMAILS, true); return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } + + /** + * Updates the voicemail notifications displayed. + * + * @param runnable Called when the async update task completes no matter if it succeeds or fails. + * May be null. + */ + static void updateVoicemailNotifications(Context context, Runnable runnable) { + if (!TelecomUtil.isDefaultDialer(context)) { + LogUtil.i( + "DefaultVoicemailNotifier.updateVoicemailNotifications", + "not default dialer, not scheduling update to voicemail notifications"); + return; + } + + DialerExecutors.createNonUiTaskBuilder(new DefaultVoicemailNotifier(context)) + .onSuccess( + output -> { + LogUtil.i( + "DefaultVoicemailNotifier.updateVoicemailNotifications", + "update voicemail notifications successful"); + if (runnable != null) { + runnable.run(); + } + }) + .onFailure( + throwable -> { + LogUtil.i( + "DefaultVoicemailNotifier.updateVoicemailNotifications", + "update voicemail notifications failed"); + if (runnable != null) { + runnable.run(); + } + }) + .build() + .executeParallel(null); + } } |