Update Dialer source to latest internal Google revision.

Previously, Android's Dialer app was developed in an internal Google
source control system and only exported to public during AOSP drops.

The Dialer team is now switching to a public development model similar
to the telephony team.

This CL represents all internal Google changes that were committed to
Dialer between the public O release and today's tip of tree on internal
master. This CL squashes those changes into a single commit.
In subsequent changes, changes will be exported on a per-commit basis.

(cherry picked from commit 2ca4318cc1ee57dda907ba2069bd61d162b1baef
and amended to match paths of dependencies under
prebuilts/maven_repo/bumptech/com/github/bumptech/glide/.)

This CL was generated using these commands from a repository at
stage-stage-master at revision ea7b4dc89590ffa3332766a531e0eab6ffb9aebd
("Merge "Update Dialer source to latest internal Google revision." am: c39ea3c55f -s ours"):

  git diff --binary 2ca4318cc1ee57dda907ba2069bd61d162b1baef | git apply -R --index
  git commit -c 2ca4318cc1ee57dda907ba2069bd61d162b1baef

Test: make, flash install, run
Change-Id: I529aaeb88535b9533c0ae4ef4e6c1222d4e0f1c8
PiperOrigin-RevId: 167068436
diff --git a/java/com/android/incallui/ExternalCallNotifier.java b/java/com/android/incallui/ExternalCallNotifier.java
index f01a294..9e78052 100644
--- a/java/com/android/incallui/ExternalCallNotifier.java
+++ b/java/com/android/incallui/ExternalCallNotifier.java
@@ -18,7 +18,6 @@
 
 import android.annotation.TargetApi;
 import android.app.Notification;
-import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.content.Context;
 import android.content.Intent;
@@ -40,8 +39,10 @@
 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.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;
@@ -58,17 +59,25 @@
  */
 public class ExternalCallNotifier implements ExternalCallList.ExternalCallListener {
 
-  /** Tag used with the notification manager to uniquely identify external call notifications. */
+  /**
+   * 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 NOTIFICATION_SUMMARY_ID = -1;
+  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 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(
@@ -85,9 +94,7 @@
   @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);
 
@@ -108,9 +115,7 @@
   /** 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));
   }
 
@@ -183,28 +188,13 @@
 
   /** 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(NOTIFICATION_TAG, mNotifications.get(call).getNotificationId());
+    // 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_TAG, NOTIFICATION_SUMMARY_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 @@
     builder.setOngoing(true);
     // Make the notification prioritized over the other normal notifications.
     builder.setPriority(Notification.PRIORITY_HIGH);
-    builder.setGroup(NOTIFICATION_TAG);
+    builder.setGroup(GROUP_KEY);
 
     boolean isVideoCall = VideoProfile.isVideo(info.getCall().getDetails().getVideoState());
     // Set the content ("Ongoing call on another device")
@@ -293,28 +283,10 @@
     builder.setPublicVersion(publicBuilder.build());
     Notification notification = builder.build();
 
-    NotificationManager notificationManager =
-        (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
-    notificationManager.notify(NOTIFICATION_TAG, info.getNotificationId(), notification);
+    DialerNotificationManager.notify(
+        mContext, NOTIFICATION_TAG, info.getNotificationId(), 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_TAG);
-      summary.setGroupSummary(true);
-      summary.setSmallIcon(R.drawable.quantum_ic_call_white_24);
-      if (BuildCompat.isAtLeastO()) {
-        summary.setChannelId(NotificationChannelId.DEFAULT);
-      }
-      notificationManager.notify(NOTIFICATION_TAG, NOTIFICATION_SUMMARY_ID, summary.build());
-      mShowingSummary = true;
-    }
+    showGroupSummaryNotification(mContext);
   }
 
   /**
@@ -475,4 +447,20 @@
       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());
+  }
 }