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