From 4aaaca7ad2b570b43f3446abe6b0b96194d441c3 Mon Sep 17 00:00:00 2001 From: twyen Date: Tue, 10 Oct 2017 13:39:17 -0700 Subject: Ignore self-manged calls for missed call notification If a PhoneAccount declared it is CAPABILITY_SELF_MANAGED, it should handle the in call UI and notifications itself, but might still write to call log with EXTRA_LOG_SELF_MANAGED_CALLS}. Bug: 66946794 Test: MissedCallNotifierTest PiperOrigin-RevId: 171727177 Change-Id: I34444857d432d6bb72983c0ba919bcfef885192b --- .../dialer/app/calllog/MissedCallNotifier.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'java') 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, Void> { List 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, 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 newCalls) { + if (newCalls == null) { + return; + } + TelecomManager telecomManager = context.getSystemService(TelecomManager.class); + Iterator 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); } -- cgit v1.2.3