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.statusbar;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.os.RemoteException;
23 import android.os.ServiceManager;
24 
25 import com.android.internal.statusbar.IStatusBarService;
26 import com.android.systemui.CoreStartable;
27 import com.android.systemui.assist.AssistManager;
28 import com.android.systemui.dagger.SysUISingleton;
29 import com.android.systemui.statusbar.CommandQueue;
30 import com.android.systemui.statusbar.KeyboardShortcuts;
31 
32 import dagger.Lazy;
33 
34 import javax.inject.Inject;
35 
36 /**
37  * Status bar implementation for "large screen" products that mostly present no on-screen nav.
38  * Serves as a collection of UI components, rather than showing its own UI.
39  */
40 @SysUISingleton
41 public class TvStatusBar implements CoreStartable, CommandQueue.Callbacks {
42 
43     private static final String ACTION_SHOW_PIP_MENU =
44             "com.android.wm.shell.pip.tv.notification.action.SHOW_PIP_MENU";
45     private static final String SYSTEMUI_PERMISSION = "com.android.systemui.permission.SELF";
46 
47     private final Context mContext;
48     private final CommandQueue mCommandQueue;
49     private final Lazy<AssistManager> mAssistManagerLazy;
50 
51     @Inject
TvStatusBar(Context context, CommandQueue commandQueue, Lazy<AssistManager> assistManagerLazy)52     public TvStatusBar(Context context, CommandQueue commandQueue,
53             Lazy<AssistManager> assistManagerLazy) {
54         mContext = context;
55         mCommandQueue = commandQueue;
56         mAssistManagerLazy = assistManagerLazy;
57     }
58 
59     @Override
start()60     public void start() {
61         final IStatusBarService barService = IStatusBarService.Stub.asInterface(
62                 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
63         mCommandQueue.addCallback(this);
64         try {
65             barService.registerStatusBar(mCommandQueue);
66         } catch (RemoteException ex) {
67             // If the system process isn't there we're doomed anyway.
68         }
69     }
70 
71     @Override
startAssist(Bundle args)72     public void startAssist(Bundle args) {
73         mAssistManagerLazy.get().startAssist(args);
74     }
75 
76     @Override
showPictureInPictureMenu()77     public void showPictureInPictureMenu() {
78         mContext.sendBroadcast(
79                 new Intent(ACTION_SHOW_PIP_MENU).setPackage(mContext.getPackageName()),
80                 SYSTEMUI_PERMISSION);
81     }
82 
83     @Override
toggleKeyboardShortcutsMenu(int deviceId)84     public void toggleKeyboardShortcutsMenu(int deviceId) {
85         KeyboardShortcuts.show(mContext, deviceId);
86     }
87 }
88