Merge Android 14

Bug: 298295554
Merged-In: I639c9595b4b5696de735ab0339ec5d40b1cd90a1
Change-Id: I362919167610c5427d11b36a1e9147e314b36508
diff --git a/java/com/android/dialer/app/calllog/MissedCallNotifier.java b/java/com/android/dialer/app/calllog/MissedCallNotifier.java
index f2d2af8..64536c8 100644
--- a/java/com/android/dialer/app/calllog/MissedCallNotifier.java
+++ b/java/com/android/dialer/app/calllog/MissedCallNotifier.java
@@ -17,6 +17,7 @@
 
 import static com.android.dialer.app.DevicePolicyResources.NOTIFICATION_MISSED_WORK_CALL_TITLE;
 
+import android.app.BroadcastOptions;
 import android.app.Notification;
 import android.app.Notification.Builder;
 import android.app.PendingIntent;
@@ -27,6 +28,7 @@
 import android.graphics.Bitmap;
 import android.graphics.drawable.Icon;
 import android.net.Uri;
+import android.os.Bundle;
 import android.provider.CallLog.Calls;
 import android.service.notification.StatusBarNotification;
 import android.support.annotation.NonNull;
@@ -44,6 +46,7 @@
 import android.text.TextDirectionHeuristics;
 import android.text.TextUtils;
 import android.util.ArraySet;
+
 import com.android.contacts.common.ContactsUtils;
 import com.android.dialer.app.MainComponent;
 import com.android.dialer.app.R;
@@ -68,6 +71,7 @@
 import com.android.dialer.theme.base.ThemeComponent;
 import com.android.dialer.util.DialerUtils;
 import com.android.dialer.util.IntentUtil;
+
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -500,6 +504,12 @@
 
   /** Closes open system dialogs and the notification shade. */
   private void closeSystemDialogs(Context context) {
-    context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
+    final Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)
+            .addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
+    final Bundle options = BroadcastOptions.makeBasic()
+            .setDeliveryGroupPolicy(BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT)
+            .setDeferralPolicy(BroadcastOptions.DEFERRAL_POLICY_UNTIL_ACTIVE)
+            .toBundle();
+    context.sendBroadcast(intent, null /* receiverPermission */, options);
   }
 }
diff --git a/java/com/android/incallui/NotificationBroadcastReceiver.java b/java/com/android/incallui/NotificationBroadcastReceiver.java
index 241d8ed..91421ea 100644
--- a/java/com/android/incallui/NotificationBroadcastReceiver.java
+++ b/java/com/android/incallui/NotificationBroadcastReceiver.java
@@ -16,14 +16,17 @@
 
 package com.android.incallui;
 
+import android.app.BroadcastOptions;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.os.Build.VERSION_CODES;
+import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.support.annotation.RequiresApi;
 import android.telecom.CallAudioState;
 import android.telecom.VideoProfile;
+
 import com.android.dialer.common.LogUtil;
 import com.android.dialer.common.concurrent.DialerExecutorComponent;
 import com.android.dialer.logging.DialerImpression;
@@ -32,6 +35,7 @@
 import com.android.incallui.call.DialerCall;
 import com.android.incallui.call.TelecomAdapter;
 import com.android.incallui.speakeasy.SpeakEasyCallManager;
+
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -97,7 +101,7 @@
     } else if (action.equals(ACTION_DECLINE_VIDEO_UPGRADE_REQUEST)) {
       declineUpgradeRequest();
     } else if (action.equals(ACTION_PULL_EXTERNAL_CALL)) {
-      context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
+      closeSystemDialogs(context);
       int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1);
       InCallPresenter.getInstance().getExternalCallNotifier().pullExternalCall(notificationId);
     } else if (action.equals(ACTION_TURN_ON_SPEAKER)) {
@@ -220,4 +224,15 @@
       }
     }
   }
+
+  /** Closes open system dialogs and the notification shade. */
+  private void closeSystemDialogs(Context context) {
+    final Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)
+            .addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
+    final Bundle options = BroadcastOptions.makeBasic()
+            .setDeliveryGroupPolicy(BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT)
+            .setDeferralPolicy(BroadcastOptions.DEFERRAL_POLICY_UNTIL_ACTIVE)
+            .toBundle();
+    context.sendBroadcast(intent, null /* receiverPermission */, options);
+  }
 }