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));
}
}
}
}
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);
}
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));
}
}
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;
}
Aggregations