BaseStatusBar.java revision fa7887bebf57f3dcb8283d73e69ba1daa115225f
1/* 2 * Copyright (C) 2010 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 17package com.android.systemui.statusbar; 18 19import java.util.ArrayList; 20 21import android.content.Context; 22import android.os.IBinder; 23import android.os.RemoteException; 24import android.os.ServiceManager; 25import android.util.Log; 26import android.util.Slog; 27import android.view.Display; 28import android.view.IWindowManager; 29import android.view.View; 30import android.view.WindowManager; 31 32import com.android.internal.statusbar.IStatusBarService; 33import com.android.internal.statusbar.StatusBarIcon; 34import com.android.internal.statusbar.StatusBarIconList; 35import com.android.internal.statusbar.StatusBarNotification; 36import com.android.systemui.SystemUI; 37import com.android.systemui.statusbar.CommandQueue; 38 39import com.android.systemui.R; 40 41public abstract class BaseStatusBar extends SystemUI implements CommandQueue.Callbacks { 42 static final String TAG = "StatusBar"; 43 private static final boolean DEBUG = false; 44 45 protected CommandQueue mCommandQueue; 46 protected IStatusBarService mBarService; 47 48 // UI-specific methods 49 50 /** 51 * Create all windows necessary for the status bar (including navigation, overlay panels, etc) 52 * and add them to the window manager. 53 */ 54 protected abstract void createAndAddWindows(); 55 56 protected Display mDisplay; 57 private IWindowManager mWindowManager; 58 59 60 public IWindowManager getWindowManager() { 61 return mWindowManager; 62 } 63 64 public Display getDisplay() { 65 return mDisplay; 66 } 67 68 public IStatusBarService getStatusBarService() { 69 return mBarService; 70 } 71 72 public void start() { 73 mDisplay = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)) 74 .getDefaultDisplay(); 75 76 mWindowManager = IWindowManager.Stub.asInterface( 77 ServiceManager.getService(Context.WINDOW_SERVICE)); 78 79 mBarService = IStatusBarService.Stub.asInterface( 80 ServiceManager.getService(Context.STATUS_BAR_SERVICE)); 81 82 // Connect in to the status bar manager service 83 StatusBarIconList iconList = new StatusBarIconList(); 84 ArrayList<IBinder> notificationKeys = new ArrayList<IBinder>(); 85 ArrayList<StatusBarNotification> notifications = new ArrayList<StatusBarNotification>(); 86 mCommandQueue = new CommandQueue(this, iconList); 87 88 int[] switches = new int[7]; 89 ArrayList<IBinder> binders = new ArrayList<IBinder>(); 90 try { 91 mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications, 92 switches, binders); 93 } catch (RemoteException ex) { 94 // If the system process isn't there we're doomed anyway. 95 } 96 97 createAndAddWindows(); 98 99 disable(switches[0]); 100 setSystemUiVisibility(switches[1]); 101 topAppWindowChanged(switches[2] != 0); 102 // StatusBarManagerService has a back up of IME token and it's restored here. 103 setImeWindowStatus(binders.get(0), switches[3], switches[4]); 104 setHardKeyboardStatus(switches[5] != 0, switches[6] != 0); 105 106 // Set up the initial icon state 107 int N = iconList.size(); 108 int viewIndex = 0; 109 for (int i=0; i<N; i++) { 110 StatusBarIcon icon = iconList.getIcon(i); 111 if (icon != null) { 112 addIcon(iconList.getSlot(i), i, viewIndex, icon); 113 viewIndex++; 114 } 115 } 116 117 // Set up the initial notification state 118 N = notificationKeys.size(); 119 if (N == notifications.size()) { 120 for (int i=0; i<N; i++) { 121 addNotification(notificationKeys.get(i), notifications.get(i)); 122 } 123 } else { 124 Log.wtf(TAG, "Notification list length mismatch: keys=" + N 125 + " notifications=" + notifications.size()); 126 } 127 128 if (DEBUG) { 129 Slog.d(TAG, String.format( 130 "init: icons=%d disabled=0x%08x lights=0x%08x menu=0x%08x imeButton=0x%08x", 131 iconList.size(), 132 switches[0], 133 switches[1], 134 switches[2], 135 switches[3] 136 )); 137 } 138 } 139 140 protected View updateNotificationVetoButton(View row, StatusBarNotification n) { 141 View vetoButton = row.findViewById(R.id.veto); 142 if (n.isClearable()) { 143 final String _pkg = n.pkg; 144 final String _tag = n.tag; 145 final int _id = n.id; 146 vetoButton.setOnClickListener(new View.OnClickListener() { 147 public void onClick(View v) { 148 try { 149 mBarService.onNotificationClear(_pkg, _tag, _id); 150 } catch (RemoteException ex) { 151 // system process is dead if we're here. 152 } 153 } 154 }); 155 vetoButton.setVisibility(View.VISIBLE); 156 } else { 157 vetoButton.setVisibility(View.GONE); 158 } 159 return vetoButton; 160 } 161 162 public void dismissIntruder() { 163 // pass 164 } 165} 166