1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.media.dialog 18 19 import android.content.Context 20 import android.view.View 21 import com.android.systemui.animation.DialogTransitionAnimator 22 import com.android.systemui.broadcast.BroadcastSender 23 import javax.inject.Inject 24 25 /** Manager to create and show a [MediaOutputBroadcastDialog]. */ 26 class MediaOutputBroadcastDialogManager 27 @Inject 28 constructor( 29 private val context: Context, 30 private val broadcastSender: BroadcastSender, 31 private val dialogTransitionAnimator: DialogTransitionAnimator, 32 private val mediaOutputControllerFactory: MediaOutputController.Factory 33 ) { 34 var mediaOutputBroadcastDialog: MediaOutputBroadcastDialog? = null 35 36 /** Creates a [MediaOutputBroadcastDialog] for the given package. */ createAndShownull37 fun createAndShow(packageName: String, aboveStatusBar: Boolean, view: View? = null) { 38 // Dismiss the previous dialog, if any. 39 mediaOutputBroadcastDialog?.dismiss() 40 41 // TODO: b/321969740 - Populate the userHandle parameter. The user handle is necessary to 42 // disambiguate the same package running on different users. 43 val controller = 44 mediaOutputControllerFactory.create( 45 packageName, 46 /* userHandle= */ null, 47 /* token */ null, 48 ) 49 val dialog = 50 MediaOutputBroadcastDialog(context, aboveStatusBar, broadcastSender, controller) 51 mediaOutputBroadcastDialog = dialog 52 53 // Show the dialog. 54 if (view != null) { 55 dialogTransitionAnimator.showFromView(dialog, view) 56 } else { 57 dialog.show() 58 } 59 } 60 61 /** dismiss [MediaOutputBroadcastDialog] if exist. */ dismissnull62 fun dismiss() { 63 mediaOutputBroadcastDialog?.dismiss() 64 mediaOutputBroadcastDialog = null 65 } 66 } 67