diff options
Diffstat (limited to 'java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java')
-rw-r--r-- | java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java | 84 |
1 files changed, 74 insertions, 10 deletions
diff --git a/java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java b/java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java index 0007d1863..58fe6fa2c 100644 --- a/java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java +++ b/java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java @@ -31,6 +31,7 @@ import android.os.PersistableBundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; +import android.support.annotation.WorkerThread; import android.support.v4.os.BuildCompat; import android.support.v4.util.Pair; import android.telecom.PhoneAccount; @@ -48,21 +49,25 @@ import com.android.dialer.app.R; import com.android.dialer.app.calllog.CallLogNotificationsQueryHelper.NewCall; import com.android.dialer.app.contactinfo.ContactPhotoLoader; import com.android.dialer.app.list.DialtactsPagerAdapter; +import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler; 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"; @@ -76,17 +81,30 @@ public class DefaultVoicemailNotifier { private final Context context; private final CallLogNotificationsQueryHelper queryHelper; + private final FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler; @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) - DefaultVoicemailNotifier(Context context, CallLogNotificationsQueryHelper queryHelper) { + DefaultVoicemailNotifier( + Context context, + CallLogNotificationsQueryHelper queryHelper, + FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler) { this.context = context; this.queryHelper = queryHelper; + this.filteredNumberAsyncQueryHandler = filteredNumberAsyncQueryHandler; } - /** Returns an instance of {@link DefaultVoicemailNotifier}. */ - public static DefaultVoicemailNotifier getInstance(Context context) { - return new DefaultVoicemailNotifier( - context, CallLogNotificationsQueryHelper.getInstance(context)); + 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; } /** @@ -97,7 +115,10 @@ public class DefaultVoicemailNotifier { * * <p>It is not safe to call this method from the main thread. */ - public void updateNotification() { + @VisibleForTesting + @WorkerThread + void updateNotification() { + Assert.isWorkerThread(); // Lookup the list of new voicemails to include in the notification. final List<NewCall> newCalls = queryHelper.getNewVoicemails(); @@ -121,13 +142,15 @@ public class DefaultVoicemailNotifier { NewCall newCall = itr.next(); // Skip notifying for numbers which are blocked. - if (FilteredNumbersUtil.shouldBlockVoicemail( - context, newCall.number, newCall.countryIso, newCall.dateMs)) { + if (!FilteredNumbersUtil.hasRecentEmergencyCall(context) + && filteredNumberAsyncQueryHandler.getBlockedIdSynchronous( + newCall.number, newCall.countryIso) + != null) { itr.remove(); if (newCall.voicemailUri != null) { // Delete the voicemail. - context.getContentResolver().delete(newCall.voicemailUri, null, null); + CallLogAsyncTaskUtil.deleteVoicemailSynchronous(context, newCall.voicemailUri); } continue; } @@ -165,6 +188,10 @@ public class DefaultVoicemailNotifier { .setGroupSummary(true) .setContentIntent(newVoicemailIntent(null)); + if (BuildCompat.isAtLeastO()) { + groupSummary.setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN); + } + NotificationChannelManager.applyChannel( groupSummary, context, @@ -379,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); + } } |