Search in sources :

Example 1 with NewCall

use of com.android.dialer.app.calllog.CallLogNotificationsQueryHelper.NewCall in project android_packages_apps_Dialer by LineageOS.

the class MissedCallNotifier method updateMissedCallNotification.

/**
 * Update missed call notifications from the call log. Accepts default information in case call
 * log cannot be accessed.
 *
 * @param count the number of missed calls to display if call log cannot be accessed. May be
 *     {@link CallLogNotificationsService#UNKNOWN_MISSED_CALL_COUNT} if unknown.
 * @param number the phone number of the most recent call to display if the call log cannot be
 *     accessed. May be null if unknown.
 */
@VisibleForTesting
@WorkerThread
void updateMissedCallNotification(int count, @Nullable String number) {
    final int titleResId;
    // The text in the notification's line 1 and 2.
    CharSequence expandedText;
    List<NewCall> newCalls = callLogNotificationsQueryHelper.getNewMissedCalls();
    if ((newCalls != null && newCalls.isEmpty()) || count == 0) {
        // No calls to notify about: clear the notification.
        CallLogNotificationsQueryHelper.markAllMissedCallsInCallLogAsRead(context);
        cancelAllMissedCallNotifications(context);
        return;
    }
    if (newCalls != null) {
        if (count != CallLogNotificationsService.UNKNOWN_MISSED_CALL_COUNT && count != newCalls.size()) {
            LogUtil.w("MissedCallNotifier.updateMissedCallNotification", "Call count does not match call log count." + " count: " + count + " newCalls.size(): " + newCalls.size());
        }
        count = newCalls.size();
    }
    if (count == CallLogNotificationsService.UNKNOWN_MISSED_CALL_COUNT) {
        // call log, then no notification can be shown.
        return;
    }
    Notification.Builder groupSummary = createNotificationBuilder();
    boolean useCallList = newCalls != null;
    if (count == 1) {
        NewCall call = useCallList ? newCalls.get(0) : new NewCall(null, null, number, Calls.PRESENTATION_ALLOWED, null, null, null, null, System.currentTimeMillis());
        // TODO: look up caller ID that is not in contacts.
        ContactInfo contactInfo = callLogNotificationsQueryHelper.getContactInfo(call.number, call.numberPresentation, call.countryIso);
        titleResId = contactInfo.userType == ContactsUtils.USER_TYPE_WORK ? R.string.notification_missedWorkCallTitle : R.string.notification_missedCallTitle;
        if (TextUtils.equals(contactInfo.name, contactInfo.formattedNumber) || TextUtils.equals(contactInfo.name, contactInfo.number)) {
            expandedText = PhoneNumberUtilsCompat.createTtsSpannable(BidiFormatter.getInstance().unicodeWrap(contactInfo.name, TextDirectionHeuristics.LTR));
        } else {
            expandedText = contactInfo.name;
        }
        ContactPhotoLoader loader = new ContactPhotoLoader(context, contactInfo);
        Bitmap photoIcon = loader.loadPhotoIcon();
        if (photoIcon != null) {
            groupSummary.setLargeIcon(photoIcon);
        }
    } else {
        titleResId = R.string.notification_missedCallsTitle;
        expandedText = context.getString(R.string.notification_missedCallsMsg, count);
    }
    // Create a public viewable version of the notification, suitable for display when sensitive
    // notification content is hidden.
    Notification.Builder publicSummaryBuilder = createNotificationBuilder();
    publicSummaryBuilder.setContentTitle(context.getText(titleResId)).setContentIntent(createCallLogPendingIntent()).setDeleteIntent(CallLogNotificationsService.createCancelAllMissedCallsPendingIntent(context));
    // Create the notification summary suitable for display when sensitive information is showing.
    groupSummary.setContentTitle(context.getText(titleResId)).setContentText(expandedText).setContentIntent(createCallLogPendingIntent()).setDeleteIntent(CallLogNotificationsService.createCancelAllMissedCallsPendingIntent(context)).setGroupSummary(useCallList).setOnlyAlertOnce(useCallList).setPublicVersion(publicSummaryBuilder.build());
    if (BuildCompat.isAtLeastO()) {
        groupSummary.setChannelId(NotificationChannelId.MISSED_CALL);
    }
    Notification notification = groupSummary.build();
    configureLedOnNotification(notification);
    LogUtil.i("MissedCallNotifier.updateMissedCallNotification", "adding missed call notification");
    getNotificationMgr().notify(getNotificationTagForGroupSummary(), NOTIFICATION_ID, notification);
    if (useCallList) {
        // Do not repost active notifications to prevent erasing post call notes.
        NotificationManager manager = getNotificationMgr();
        Set<String> activeTags = new ArraySet<>();
        for (StatusBarNotification activeNotification : manager.getActiveNotifications()) {
            activeTags.add(activeNotification.getTag());
        }
        for (NewCall call : newCalls) {
            String callTag = getNotificationTagForCall(call);
            if (!activeTags.contains(callTag)) {
                manager.notify(callTag, NOTIFICATION_ID, getNotificationForCall(call, null));
            }
        }
    }
}
Also used : ArraySet(android.util.ArraySet) Builder(android.app.Notification.Builder) NotificationManager(android.app.NotificationManager) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification) NewCall(com.android.dialer.app.calllog.CallLogNotificationsQueryHelper.NewCall) Bitmap(android.graphics.Bitmap) StatusBarNotification(android.service.notification.StatusBarNotification) ContactPhotoLoader(com.android.dialer.app.contactinfo.ContactPhotoLoader) ContactInfo(com.android.dialer.phonenumbercache.ContactInfo) VisibleForTesting(android.support.annotation.VisibleForTesting) WorkerThread(android.support.annotation.WorkerThread)

Example 2 with NewCall

use of com.android.dialer.app.calllog.CallLogNotificationsQueryHelper.NewCall in project android_packages_apps_Dialer by LineageOS.

the class VisualVoicemailUpdateTask method updateNotification.

/**
 * Updates the notification and notifies of the call with the given URI.
 *
 * <p>Clears the notification if there are no new voicemails, and notifies if the given URI
 * corresponds to a new voicemail.
 */
@WorkerThread
private static void updateNotification(Context context, CallLogNotificationsQueryHelper queryHelper, FilteredNumberAsyncQueryHandler queryHandler) {
    Assert.isWorkerThread();
    List<NewCall> newCalls = queryHelper.getNewVoicemails();
    if (newCalls == null) {
        return;
    }
    newCalls = filterBlockedNumbers(context, queryHandler, newCalls);
    if (newCalls.isEmpty()) {
        return;
    }
    // This represents a list of names to include in the notification.
    String callers = null;
    // Maps each number into a name: if a number is in the map, it has already left a more
    // recent voicemail.
    Map<String, ContactInfo> contactInfos = new ArrayMap<>();
    for (NewCall newCall : newCalls) {
        if (!contactInfos.containsKey(newCall.number)) {
            ContactInfo contactInfo = queryHelper.getContactInfo(newCall.number, newCall.numberPresentation, newCall.countryIso);
            contactInfos.put(newCall.number, contactInfo);
            // This is a new caller. Add it to the back of the list of callers.
            if (TextUtils.isEmpty(callers)) {
                callers = contactInfo.name;
            } else {
                callers = context.getString(R.string.notification_voicemail_callers_list, callers, contactInfo.name);
            }
        }
    }
    VisualVoicemailNotifier.showNotifications(context, newCalls, contactInfos, callers);
}
Also used : NewCall(com.android.dialer.app.calllog.CallLogNotificationsQueryHelper.NewCall) ArrayMap(android.util.ArrayMap) ContactInfo(com.android.dialer.phonenumbercache.ContactInfo) WorkerThread(android.support.annotation.WorkerThread)

Example 3 with NewCall

use of com.android.dialer.app.calllog.CallLogNotificationsQueryHelper.NewCall in project android_packages_apps_Dialer by LineageOS.

the class VisualVoicemailNotifier method showNotifications.

public static void showNotifications(@NonNull Context context, @NonNull List<NewCall> newCalls, @NonNull Map<String, ContactInfo> contactInfos, @Nullable String callers) {
    LogUtil.enterBlock("VisualVoicemailNotifier.showNotifications");
    PendingIntent deleteIntent = CallLogNotificationsService.createMarkAllNewVoicemailsAsOldIntent(context);
    String contentTitle = context.getResources().getQuantityString(R.plurals.notification_voicemail_title, newCalls.size(), newCalls.size());
    Notification.Builder groupSummary = createNotificationBuilder(context).setContentTitle(contentTitle).setContentText(callers).setDeleteIntent(deleteIntent).setGroupSummary(true).setContentIntent(newVoicemailIntent(context, null));
    if (BuildCompat.isAtLeastO()) {
        groupSummary.setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN);
        PhoneAccountHandle handle = getAccountForCall(context, newCalls.get(0));
        groupSummary.setChannelId(NotificationChannelManager.getVoicemailChannelId(context, handle));
    }
    NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
    notificationManager.notify(getNotificationTagForGroupSummary(), NOTIFICATION_ID, groupSummary.build());
    for (NewCall voicemail : newCalls) {
        notificationManager.notify(getNotificationTagForVoicemail(voicemail), NOTIFICATION_ID, createNotificationForVoicemail(context, voicemail, contactInfos));
    }
}
Also used : NewCall(com.android.dialer.app.calllog.CallLogNotificationsQueryHelper.NewCall) PhoneAccountHandle(android.telecom.PhoneAccountHandle) NotificationManager(android.app.NotificationManager) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification)

Example 4 with NewCall

use of com.android.dialer.app.calllog.CallLogNotificationsQueryHelper.NewCall in project android_packages_apps_Dialer by LineageOS.

the class VisualVoicemailUpdateTask method filterBlockedNumbers.

@WorkerThread
private static List<NewCall> filterBlockedNumbers(Context context, FilteredNumberAsyncQueryHandler queryHandler, List<NewCall> newCalls) {
    Assert.isWorkerThread();
    if (FilteredNumbersUtil.hasRecentEmergencyCall(context)) {
        LogUtil.i("VisualVoicemailUpdateTask.filterBlockedNumbers", "not filtering due to recent emergency call");
        return newCalls;
    }
    List<NewCall> result = new ArrayList<>();
    for (NewCall newCall : newCalls) {
        if (queryHandler.getBlockedIdSynchronous(newCall.number, newCall.countryIso) != null) {
            LogUtil.i("VisualVoicemailUpdateTask.filterBlockedNumbers", "found voicemail from blocked number, deleting");
            if (newCall.voicemailUri != null) {
                // Delete the voicemail.
                CallLogAsyncTaskUtil.deleteVoicemailSynchronous(context, newCall.voicemailUri);
            }
        } else {
            result.add(newCall);
        }
    }
    return result;
}
Also used : NewCall(com.android.dialer.app.calllog.CallLogNotificationsQueryHelper.NewCall) ArrayList(java.util.ArrayList) WorkerThread(android.support.annotation.WorkerThread)

Aggregations

NewCall (com.android.dialer.app.calllog.CallLogNotificationsQueryHelper.NewCall)4 WorkerThread (android.support.annotation.WorkerThread)3 Notification (android.app.Notification)2 NotificationManager (android.app.NotificationManager)2 StatusBarNotification (android.service.notification.StatusBarNotification)2 ContactInfo (com.android.dialer.phonenumbercache.ContactInfo)2 Builder (android.app.Notification.Builder)1 PendingIntent (android.app.PendingIntent)1 Bitmap (android.graphics.Bitmap)1 VisibleForTesting (android.support.annotation.VisibleForTesting)1 PhoneAccountHandle (android.telecom.PhoneAccountHandle)1 ArrayMap (android.util.ArrayMap)1 ArraySet (android.util.ArraySet)1 ContactPhotoLoader (com.android.dialer.app.contactinfo.ContactPhotoLoader)1 ArrayList (java.util.ArrayList)1