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.content.pm.PackageManager;
22 import android.content.pm.ResolveInfo;
23 import android.os.Bundle;
24 import android.os.RemoteException;
25 import android.os.ServiceManager;
26 import android.os.UserHandle;
27 
28 import com.android.internal.statusbar.IStatusBarService;
29 import com.android.systemui.SystemUI;
30 import com.android.systemui.assist.AssistManager;
31 import com.android.systemui.statusbar.CommandQueue;
32 import com.android.systemui.statusbar.tv.micdisclosure.AudioRecordingDisclosureBar;
33 
34 import javax.inject.Inject;
35 import javax.inject.Singleton;
36 
37 import dagger.Lazy;
38 
39 /**
40  * Status bar implementation for "large screen" products that mostly present no on-screen nav.
41  * Serves as a collection of UI components, rather than showing its own UI.
42  * The following is the list of elements that constitute the TV-specific status bar:
43  * <ul>
44  * <li> {@link AudioRecordingDisclosureBar} - shown whenever applications are conducting audio
45  * recording, discloses the responsible applications </li>
46  * </ul>
47  */
48 @Singleton
49 public class TvStatusBar extends SystemUI implements CommandQueue.Callbacks {
50 
51     private static final String ACTION_OPEN_TV_NOTIFICATIONS_PANEL =
52             "com.android.tv.action.OPEN_NOTIFICATIONS_PANEL";
53 
54     private final CommandQueue mCommandQueue;
55     private final Lazy<AssistManager> mAssistManagerLazy;
56 
57     @Inject
TvStatusBar(Context context, CommandQueue commandQueue, Lazy<AssistManager> assistManagerLazy)58     public TvStatusBar(Context context, CommandQueue commandQueue,
59             Lazy<AssistManager> assistManagerLazy) {
60         super(context);
61         mCommandQueue = commandQueue;
62         mAssistManagerLazy = assistManagerLazy;
63     }
64 
65     @Override
start()66     public void start() {
67         final IStatusBarService barService = IStatusBarService.Stub.asInterface(
68                 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
69         mCommandQueue.addCallback(this);
70         try {
71             barService.registerStatusBar(mCommandQueue);
72         } catch (RemoteException ex) {
73             // If the system process isn't there we're doomed anyway.
74         }
75     }
76 
77     @Override
animateExpandNotificationsPanel()78     public void animateExpandNotificationsPanel() {
79         startSystemActivity(new Intent(ACTION_OPEN_TV_NOTIFICATIONS_PANEL));
80     }
81 
startSystemActivity(Intent intent)82     private void startSystemActivity(Intent intent) {
83         PackageManager pm = mContext.getPackageManager();
84         ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_SYSTEM_ONLY);
85         if (ri != null && ri.activityInfo != null) {
86             intent.setPackage(ri.activityInfo.packageName);
87             mContext.startActivityAsUser(intent, UserHandle.CURRENT);
88         }
89     }
90 
91     @Override
startAssist(Bundle args)92     public void startAssist(Bundle args) {
93         mAssistManagerLazy.get().startAssist(args);
94     }
95 }
96