1 /* 2 * Copyright (C) 2023 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.tv.media 18 19 import android.content.Context 20 import android.content.Intent 21 import android.media.session.MediaSession 22 import android.os.UserHandle 23 import android.util.Log 24 import android.view.View 25 import com.android.internal.logging.UiEventLogger 26 import com.android.settingslib.media.flags.Flags 27 import com.android.systemui.animation.DialogTransitionAnimator 28 import com.android.systemui.broadcast.BroadcastSender 29 import com.android.systemui.media.dialog.MediaOutputController 30 import com.android.systemui.media.dialog.MediaOutputDialogManager 31 import javax.inject.Inject 32 33 /** 34 * Manager to create and show [TvMediaOutputDialogActivity]. 35 */ 36 class TvMediaOutputDialogManager @Inject constructor( 37 private val context: Context, 38 broadcastSender: BroadcastSender, 39 uiEventLogger: UiEventLogger, 40 dialogTransitionAnimator: DialogTransitionAnimator, 41 mediaOutputControllerFactory: MediaOutputController.Factory, 42 ) : MediaOutputDialogManager( 43 context, 44 broadcastSender, 45 uiEventLogger, 46 dialogTransitionAnimator, 47 mediaOutputControllerFactory 48 ) { 49 companion object { 50 private const val TAG = "TvMediaOutputDialogFactory" 51 } 52 53 /** 54 * Creates a [TvMediaOutputDialog]. 55 * 56 * <p>Note that neither the package name nor the user handle are used. The reason is that the TV 57 * output dialog does not control a specific app, but rather the system's media output. 58 */ createAndShownull59 override fun createAndShow( 60 unusedPackageName: String, 61 aboveStatusBar: Boolean, 62 view: View?, 63 unusedUserHandle: UserHandle?, 64 token: MediaSession.Token?, 65 ) { 66 if (!Flags.enableTvMediaOutputDialog()) { 67 // Not showing any media output dialog since the mobile version is not navigable on TV. 68 Log.w(TAG, "enable_tv_media_output_dialog flag is disabled") 69 return 70 } 71 72 val intent = Intent(context, TvMediaOutputDialogActivity::class.java) 73 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 74 context.startActivity(intent) 75 } 76 77 /** Dismiss the [TvMediaOutputDialog] if it exists. */ dismissnull78 override fun dismiss() { 79 // NOOP 80 } 81 } 82