diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/com/android/dialer/app/calllog/MissedCallNotifier.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/java/com/android/dialer/app/calllog/MissedCallNotifier.java b/java/com/android/dialer/app/calllog/MissedCallNotifier.java index eb7fab8fc..8a986dc41 100644 --- a/java/com/android/dialer/app/calllog/MissedCallNotifier.java +++ b/java/com/android/dialer/app/calllog/MissedCallNotifier.java @@ -18,6 +18,7 @@ package com.android.dialer.app.calllog; import android.app.Notification; import android.app.Notification.Builder; import android.app.PendingIntent; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; @@ -32,6 +33,9 @@ import android.support.annotation.WorkerThread; import android.support.v4.os.BuildCompat; import android.support.v4.os.UserManagerCompat; import android.support.v4.util.Pair; +import android.telecom.PhoneAccount; +import android.telecom.PhoneAccountHandle; +import android.telecom.TelecomManager; import android.text.BidiFormatter; import android.text.TextDirectionHeuristics; import android.text.TextUtils; @@ -57,6 +61,7 @@ import com.android.dialer.phonenumbercache.ContactInfo; import com.android.dialer.phonenumberutil.PhoneNumberHelper; import com.android.dialer.util.DialerUtils; import com.android.dialer.util.IntentUtil; +import java.util.Iterator; import java.util.List; import java.util.Set; @@ -113,6 +118,8 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { List<NewCall> newCalls = callLogNotificationsQueryHelper.getNewMissedCalls(); + removeSelfManagedCalls(newCalls); + if ((newCalls != null && newCalls.isEmpty()) || count == 0) { // No calls to notify about: clear the notification. CallLogNotificationsQueryHelper.markAllMissedCallsInCallLogAsRead(context); @@ -236,6 +243,39 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { } } + /** + * Remove self-managed calls from {@code newCalls}. If a {@link PhoneAccount} declared it is + * {@link PhoneAccount#CAPABILITY_SELF_MANAGED}, it should handle the in call UI and notifications + * itself, but might still write to call log with {@link + * PhoneAccount#EXTRA_LOG_SELF_MANAGED_CALLS}. + */ + private void removeSelfManagedCalls(@Nullable List<NewCall> newCalls) { + if (newCalls == null) { + return; + } + TelecomManager telecomManager = context.getSystemService(TelecomManager.class); + Iterator<NewCall> iterator = newCalls.iterator(); + while (iterator.hasNext()) { + NewCall call = iterator.next(); + if (call.accountComponentName == null || call.accountId == null) { + continue; + } + PhoneAccountHandle phoneAccountHandle = + new PhoneAccountHandle( + ComponentName.unflattenFromString(call.accountComponentName), call.accountId); + PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccountHandle); + if (phoneAccount == null) { + continue; + } + if (phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)) { + LogUtil.i( + "MissedCallNotifier.removeSelfManagedCalls", + "ignoring self-managed call " + call.callsUri); + iterator.remove(); + } + } + } + public static void cancelAllMissedCallNotifications(@NonNull Context context) { NotificationManagerUtils.cancelAllInGroup(context, GROUP_KEY); } |