Add dismiss intent and method for MediaOutputDialog

-Add filter in Manifest
-Add dismiss method in MediaOutputDialogFactory

Bug: 155822415
Test: build pass
Merged-In: Ica5b5a22e0fa20ffec5ab9ea291f72c06e39c2fe
Change-Id: Ica5b5a22e0fa20ffec5ab9ea291f72c06e39c2fe
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
index f20d05c..ce1eea0 100644
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -785,6 +785,7 @@
                   android:exported="true">
             <intent-filter>
                 <action android:name="com.android.systemui.action.LAUNCH_MEDIA_OUTPUT_DIALOG" />
+                <action android:name="com.android.systemui.action.DISMISS_MEDIA_OUTPUT_DIALOG" />
             </intent-filter>
         </receiver>
 
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogFactory.kt b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogFactory.kt
index bc1dca5..4cdca4c 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogFactory.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogFactory.kt
@@ -33,10 +33,22 @@
     private val shadeController: ShadeController,
     private val starter: ActivityStarter
 ) {
+    companion object {
+        var mediaOutputDialog: MediaOutputDialog? = null
+    }
+
     /** Creates a [MediaOutputDialog] for the given package. */
     fun create(packageName: String, aboveStatusBar: Boolean) {
-        MediaOutputController(context, packageName, mediaSessionManager, lbm, shadeController,
-                starter).run {
+        mediaOutputDialog?.dismiss()
+
+        mediaOutputDialog = MediaOutputController(context, packageName, mediaSessionManager, lbm,
+                shadeController, starter).run {
             MediaOutputDialog(context, aboveStatusBar, this) }
     }
+
+    /** dismiss [MediaOutputDialog] if exist. */
+    fun dismiss() {
+        mediaOutputDialog?.dismiss()
+        mediaOutputDialog = null
+    }
 }