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.media.dialog;
18 
19 import android.annotation.MainThread;
20 import android.content.Context;
21 import android.text.TextUtils;
22 import android.util.Log;
23 
24 import com.android.systemui.CoreStartable;
25 import com.android.systemui.dagger.SysUISingleton;
26 import com.android.systemui.statusbar.CommandQueue;
27 
28 import javax.inject.Inject;
29 
30 /** Controls display of media output switcher. */
31 @SysUISingleton
32 public class MediaOutputSwitcherDialogUI implements CoreStartable, CommandQueue.Callbacks {
33 
34     private static final String TAG = "MediaOutputSwitcherDialogUI";
35 
36     private final CommandQueue mCommandQueue;
37     private final MediaOutputDialogFactory mMediaOutputDialogFactory;
38 
39     @Inject
MediaOutputSwitcherDialogUI( Context context, CommandQueue commandQueue, MediaOutputDialogFactory mediaOutputDialogFactory)40     public MediaOutputSwitcherDialogUI(
41             Context context,
42             CommandQueue commandQueue,
43             MediaOutputDialogFactory mediaOutputDialogFactory) {
44         mCommandQueue = commandQueue;
45         mMediaOutputDialogFactory = mediaOutputDialogFactory;
46     }
47 
48     @Override
start()49     public void start() {
50         mCommandQueue.addCallback(this);
51     }
52 
53     @Override
54     @MainThread
showMediaOutputSwitcher(String packageName)55     public void showMediaOutputSwitcher(String packageName) {
56         if (!TextUtils.isEmpty(packageName)) {
57             mMediaOutputDialogFactory.create(packageName, false, null);
58         } else {
59             Log.e(TAG, "Unable to launch media output dialog. Package name is empty.");
60         }
61     }
62 }
63