summaryrefslogtreecommitdiff
path: root/java/com/android/incallui/ExternalCallNotifier.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/incallui/ExternalCallNotifier.java')
-rw-r--r--java/com/android/incallui/ExternalCallNotifier.java126
1 files changed, 55 insertions, 71 deletions
diff --git a/java/com/android/incallui/ExternalCallNotifier.java b/java/com/android/incallui/ExternalCallNotifier.java
index 0c2493c60..9e7805236 100644
--- a/java/com/android/incallui/ExternalCallNotifier.java
+++ b/java/com/android/incallui/ExternalCallNotifier.java
@@ -18,7 +18,6 @@ package com.android.incallui;
import android.annotation.TargetApi;
import android.app.Notification;
-import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -29,6 +28,7 @@ import android.net.Uri;
import android.os.Build.VERSION_CODES;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import android.support.v4.os.BuildCompat;
import android.telecom.Call;
import android.telecom.PhoneAccount;
import android.telecom.VideoProfile;
@@ -39,10 +39,11 @@ import android.util.ArrayMap;
import com.android.contacts.common.ContactsUtils;
import com.android.contacts.common.compat.CallCompat;
import com.android.contacts.common.preference.ContactsPreferences;
-import com.android.contacts.common.util.BitmapUtil;
import com.android.contacts.common.util.ContactDisplayUtils;
-import com.android.dialer.notification.NotificationChannelManager;
-import com.android.dialer.notification.NotificationChannelManager.Channel;
+import com.android.dialer.common.Assert;
+import com.android.dialer.contactphoto.BitmapUtil;
+import com.android.dialer.notification.DialerNotificationManager;
+import com.android.dialer.notification.NotificationChannelId;
import com.android.incallui.call.DialerCall;
import com.android.incallui.call.DialerCallDelegate;
import com.android.incallui.call.ExternalCallList;
@@ -58,16 +59,25 @@ import java.util.Map;
*/
public class ExternalCallNotifier implements ExternalCallList.ExternalCallListener {
- /** Tag used with the notification manager to uniquely identify external call notifications. */
- private static final int NOTIFICATION_ID = R.id.notification_external_call;
+ /**
+ * Common tag for all external call notifications. Unlike other grouped notifications in Dialer,
+ * external call notifications are uniquely identified by ID.
+ */
+ private static final String NOTIFICATION_TAG = "EXTERNAL_CALL";
+
+ private static final int GROUP_SUMMARY_NOTIFICATION_ID = -1;
+ private static final String GROUP_SUMMARY_NOTIFICATION_TAG = "GroupSummary_ExternalCall";
+ /**
+ * Key used to associate all external call notifications and the summary as belonging to a single
+ * group.
+ */
+ private static final String GROUP_KEY = "ExternalCallGroup";
- private static final String NOTIFICATION_GROUP = "ExternalCallNotifier";
private final Context mContext;
private final ContactInfoCache mContactInfoCache;
private Map<Call, NotificationInfo> mNotifications = new ArrayMap<>();
private int mNextUniqueNotificationId;
private ContactsPreferences mContactsPreferences;
- private boolean mShowingSummary;
/** Initializes a new instance of the external call notifier. */
public ExternalCallNotifier(
@@ -84,9 +94,7 @@ public class ExternalCallNotifier implements ExternalCallList.ExternalCallListen
@Override
public void onExternalCallAdded(android.telecom.Call call) {
Log.i(this, "onExternalCallAdded " + call);
- if (mNotifications.containsKey(call)) {
- throw new IllegalArgumentException();
- }
+ Assert.checkArgument(!mNotifications.containsKey(call));
NotificationInfo info = new NotificationInfo(call, mNextUniqueNotificationId++);
mNotifications.put(call, info);
@@ -107,9 +115,7 @@ public class ExternalCallNotifier implements ExternalCallList.ExternalCallListen
/** Handles updates to an external call. */
@Override
public void onExternalCallUpdated(Call call) {
- if (!mNotifications.containsKey(call)) {
- throw new IllegalArgumentException();
- }
+ Assert.checkArgument(mNotifications.containsKey(call));
postNotification(mNotifications.get(call));
}
@@ -182,29 +188,13 @@ public class ExternalCallNotifier implements ExternalCallList.ExternalCallListen
/** Dismisses a notification for an external call. */
private void dismissNotification(Call call) {
- if (!mNotifications.containsKey(call)) {
- throw new IllegalArgumentException();
- }
+ Assert.checkArgument(mNotifications.containsKey(call));
- NotificationManager notificationManager =
- (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
- notificationManager.cancel(
- String.valueOf(mNotifications.get(call).getNotificationId()), NOTIFICATION_ID);
+ // This will also dismiss the group summary if there are no more external call notifications.
+ DialerNotificationManager.cancel(
+ mContext, NOTIFICATION_TAG, mNotifications.get(call).getNotificationId());
mNotifications.remove(call);
-
- if (mShowingSummary && mNotifications.size() <= 1) {
- // Where a summary notification is showing and there is now not enough notifications to
- // necessitate a summary, cancel the summary.
- notificationManager.cancel(NOTIFICATION_GROUP, NOTIFICATION_ID);
- mShowingSummary = false;
-
- // If there is still a single call requiring a notification, re-post the notification as a
- // standalone notification without a summary notification.
- if (mNotifications.size() == 1) {
- postNotification(mNotifications.values().iterator().next());
- }
- }
}
/**
@@ -237,7 +227,7 @@ public class ExternalCallNotifier implements ExternalCallList.ExternalCallListen
builder.setOngoing(true);
// Make the notification prioritized over the other normal notifications.
builder.setPriority(Notification.PRIORITY_HIGH);
- builder.setGroup(NOTIFICATION_GROUP);
+ builder.setGroup(GROUP_KEY);
boolean isVideoCall = VideoProfile.isVideo(info.getCall().getDetails().getVideoState());
// Set the content ("Ongoing call on another device")
@@ -251,9 +241,9 @@ public class ExternalCallNotifier implements ExternalCallList.ExternalCallListen
builder.setLargeIcon(info.getLargeIcon());
builder.setColor(mContext.getResources().getColor(R.color.dialer_theme_color));
builder.addPerson(info.getPersonReference());
-
- NotificationChannelManager.applyChannel(
- builder, mContext, Channel.EXTERNAL_CALL, info.getCall().getDetails().getAccountHandle());
+ if (BuildCompat.isAtLeastO()) {
+ builder.setChannelId(NotificationChannelId.DEFAULT);
+ }
// Where the external call supports being transferred to the local device, add an action
// to the notification to initiate the call pull process.
@@ -286,38 +276,17 @@ public class ExternalCallNotifier implements ExternalCallList.ExternalCallListen
Notification.Builder publicBuilder = new Notification.Builder(mContext);
publicBuilder.setSmallIcon(R.drawable.quantum_ic_call_white_24);
publicBuilder.setColor(mContext.getResources().getColor(R.color.dialer_theme_color));
-
- NotificationChannelManager.applyChannel(
- publicBuilder,
- mContext,
- Channel.EXTERNAL_CALL,
- info.getCall().getDetails().getAccountHandle());
+ if (BuildCompat.isAtLeastO()) {
+ publicBuilder.setChannelId(NotificationChannelId.DEFAULT);
+ }
builder.setPublicVersion(publicBuilder.build());
Notification notification = builder.build();
- NotificationManager notificationManager =
- (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
- notificationManager.notify(
- String.valueOf(info.getNotificationId()), NOTIFICATION_ID, notification);
-
- if (!mShowingSummary && mNotifications.size() > 1) {
- // If the number of notifications shown is > 1, and we're not already showing a group summary,
- // build one now. This will ensure the like notifications are grouped together.
-
- Notification.Builder summary = new Notification.Builder(mContext);
- // Set notification as ongoing since calls are long-running versus a point-in-time notice.
- summary.setOngoing(true);
- // Make the notification prioritized over the other normal notifications.
- summary.setPriority(Notification.PRIORITY_HIGH);
- summary.setGroup(NOTIFICATION_GROUP);
- summary.setGroupSummary(true);
- summary.setSmallIcon(R.drawable.quantum_ic_call_white_24);
- NotificationChannelManager.applyChannel(
- summary, mContext, Channel.EXTERNAL_CALL, info.getCall().getDetails().getAccountHandle());
- notificationManager.notify(NOTIFICATION_GROUP, NOTIFICATION_ID, summary.build());
- mShowingSummary = true;
- }
+ DialerNotificationManager.notify(
+ mContext, NOTIFICATION_TAG, info.getNotificationId(), notification);
+
+ showGroupSummaryNotification(mContext);
}
/**
@@ -384,11 +353,10 @@ public class ExternalCallNotifier implements ExternalCallList.ExternalCallListen
ContactInfoCache.ContactCacheEntry contactInfo,
android.telecom.Call call) {
- if (call.getDetails().hasProperty(android.telecom.Call.Details.PROPERTY_CONFERENCE)
- && !call.getDetails()
- .hasProperty(android.telecom.Call.Details.PROPERTY_GENERIC_CONFERENCE)) {
-
- return context.getResources().getString(R.string.conference_call_name);
+ if (call.getDetails().hasProperty(android.telecom.Call.Details.PROPERTY_CONFERENCE)) {
+ return CallerInfoUtils.getConferenceString(
+ context,
+ call.getDetails().hasProperty(android.telecom.Call.Details.PROPERTY_GENERIC_CONFERENCE));
}
String preferredName =
@@ -479,4 +447,20 @@ public class ExternalCallNotifier implements ExternalCallList.ExternalCallListen
mPersonReference = personReference;
}
}
+
+ private static void showGroupSummaryNotification(@NonNull Context context) {
+ Notification.Builder summary = new Notification.Builder(context);
+ // Set notification as ongoing since calls are long-running versus a point-in-time notice.
+ summary.setOngoing(true);
+ // Make the notification prioritized over the other normal notifications.
+ summary.setPriority(Notification.PRIORITY_HIGH);
+ summary.setGroup(GROUP_KEY);
+ summary.setGroupSummary(true);
+ summary.setSmallIcon(R.drawable.quantum_ic_call_white_24);
+ if (BuildCompat.isAtLeastO()) {
+ summary.setChannelId(NotificationChannelId.DEFAULT);
+ }
+ DialerNotificationManager.notify(
+ context, GROUP_SUMMARY_NOTIFICATION_TAG, GROUP_SUMMARY_NOTIFICATION_ID, summary.build());
+ }
}