1 /* 2 * Copyright (C) 2020 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.app.KeyguardManager 20 import android.content.Context 21 import android.media.AudioManager 22 import android.media.session.MediaSessionManager 23 import android.os.PowerExemptionManager 24 import android.view.View 25 import com.android.internal.jank.InteractionJankMonitor 26 import com.android.internal.logging.UiEventLogger 27 import com.android.settingslib.bluetooth.LocalBluetoothManager 28 import com.android.systemui.animation.DialogCuj 29 import com.android.systemui.animation.DialogLaunchAnimator 30 import com.android.systemui.broadcast.BroadcastSender 31 import com.android.systemui.flags.FeatureFlags 32 import com.android.systemui.media.nearby.NearbyMediaDevicesManager 33 import com.android.systemui.plugins.ActivityStarter 34 import com.android.systemui.settings.UserTracker 35 import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection 36 import javax.inject.Inject 37 38 /** 39 * Factory to create [MediaOutputDialog] objects. 40 */ 41 class MediaOutputDialogFactory @Inject constructor( 42 private val context: Context, 43 private val mediaSessionManager: MediaSessionManager, 44 private val lbm: LocalBluetoothManager?, 45 private val starter: ActivityStarter, 46 private val broadcastSender: BroadcastSender, 47 private val notifCollection: CommonNotifCollection, 48 private val uiEventLogger: UiEventLogger, 49 private val dialogLaunchAnimator: DialogLaunchAnimator, 50 private val nearbyMediaDevicesManager: NearbyMediaDevicesManager, 51 private val audioManager: AudioManager, 52 private val powerExemptionManager: PowerExemptionManager, 53 private val keyGuardManager: KeyguardManager, 54 private val featureFlags: FeatureFlags, 55 private val userTracker: UserTracker 56 ) { 57 companion object { 58 private const val INTERACTION_JANK_TAG = "media_output" 59 var mediaOutputDialog: MediaOutputDialog? = null 60 } 61 62 /** Creates a [MediaOutputDialog] for the given package. */ 63 fun create(packageName: String, aboveStatusBar: Boolean, view: View? = null) { 64 // Dismiss the previous dialog, if any. 65 mediaOutputDialog?.dismiss() 66 67 val controller = MediaOutputController( 68 context, packageName, 69 mediaSessionManager, lbm, starter, notifCollection, 70 dialogLaunchAnimator, nearbyMediaDevicesManager, audioManager, 71 powerExemptionManager, keyGuardManager, featureFlags, userTracker) 72 val dialog = 73 MediaOutputDialog(context, aboveStatusBar, broadcastSender, controller, 74 dialogLaunchAnimator, uiEventLogger) 75 mediaOutputDialog = dialog 76 77 // Show the dialog. 78 if (view != null) { 79 dialogLaunchAnimator.showFromView( 80 dialog, view, 81 cuj = DialogCuj( 82 InteractionJankMonitor.CUJ_SHADE_DIALOG_OPEN, 83 INTERACTION_JANK_TAG 84 ) 85 ) 86 } else { 87 dialog.show() 88 } 89 } 90 91 /** dismiss [MediaOutputDialog] if exist. */ 92 fun dismiss() { 93 mediaOutputDialog?.dismiss() 94 mediaOutputDialog = null 95 } 96 } 97