| /* |
| * Copyright (C) 2010 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package com.android.systemui.statusbar; |
| |
| import java.util.ArrayList; |
| |
| import android.content.Context; |
| import android.os.IBinder; |
| import android.os.RemoteException; |
| import android.os.ServiceManager; |
| import android.util.Log; |
| import android.util.Slog; |
| import android.view.Display; |
| import android.view.IWindowManager; |
| import android.view.View; |
| import android.view.WindowManager; |
| |
| import com.android.internal.statusbar.IStatusBarService; |
| import com.android.internal.statusbar.StatusBarIcon; |
| import com.android.internal.statusbar.StatusBarIconList; |
| import com.android.internal.statusbar.StatusBarNotification; |
| import com.android.systemui.SystemUI; |
| import com.android.systemui.statusbar.CommandQueue; |
| |
| import com.android.systemui.R; |
| |
| public abstract class BaseStatusBar extends SystemUI implements CommandQueue.Callbacks { |
| static final String TAG = "StatusBar"; |
| private static final boolean DEBUG = false; |
| |
| protected CommandQueue mCommandQueue; |
| protected IStatusBarService mBarService; |
| |
| // UI-specific methods |
| |
| /** |
| * Create all windows necessary for the status bar (including navigation, overlay panels, etc) |
| * and add them to the window manager. |
| */ |
| protected abstract void createAndAddWindows(); |
| |
| protected Display mDisplay; |
| private IWindowManager mWindowManager; |
| |
| |
| public IWindowManager getWindowManager() { |
| return mWindowManager; |
| } |
| |
| public Display getDisplay() { |
| return mDisplay; |
| } |
| |
| public IStatusBarService getStatusBarService() { |
| return mBarService; |
| } |
| |
| public void start() { |
| mDisplay = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)) |
| .getDefaultDisplay(); |
| |
| mWindowManager = IWindowManager.Stub.asInterface( |
| ServiceManager.getService(Context.WINDOW_SERVICE)); |
| |
| mBarService = IStatusBarService.Stub.asInterface( |
| ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
| |
| // Connect in to the status bar manager service |
| StatusBarIconList iconList = new StatusBarIconList(); |
| ArrayList<IBinder> notificationKeys = new ArrayList<IBinder>(); |
| ArrayList<StatusBarNotification> notifications = new ArrayList<StatusBarNotification>(); |
| mCommandQueue = new CommandQueue(this, iconList); |
| |
| int[] switches = new int[7]; |
| ArrayList<IBinder> binders = new ArrayList<IBinder>(); |
| try { |
| mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications, |
| switches, binders); |
| } catch (RemoteException ex) { |
| // If the system process isn't there we're doomed anyway. |
| } |
| |
| createAndAddWindows(); |
| |
| disable(switches[0]); |
| setSystemUiVisibility(switches[1]); |
| topAppWindowChanged(switches[2] != 0); |
| // StatusBarManagerService has a back up of IME token and it's restored here. |
| setImeWindowStatus(binders.get(0), switches[3], switches[4]); |
| setHardKeyboardStatus(switches[5] != 0, switches[6] != 0); |
| |
| // Set up the initial icon state |
| int N = iconList.size(); |
| int viewIndex = 0; |
| for (int i=0; i<N; i++) { |
| StatusBarIcon icon = iconList.getIcon(i); |
| if (icon != null) { |
| addIcon(iconList.getSlot(i), i, viewIndex, icon); |
| viewIndex++; |
| } |
| } |
| |
| // Set up the initial notification state |
| N = notificationKeys.size(); |
| if (N == notifications.size()) { |
| for (int i=0; i<N; i++) { |
| addNotification(notificationKeys.get(i), notifications.get(i)); |
| } |
| } else { |
| Log.wtf(TAG, "Notification list length mismatch: keys=" + N |
| + " notifications=" + notifications.size()); |
| } |
| |
| if (DEBUG) { |
| Slog.d(TAG, String.format( |
| "init: icons=%d disabled=0x%08x lights=0x%08x menu=0x%08x imeButton=0x%08x", |
| iconList.size(), |
| switches[0], |
| switches[1], |
| switches[2], |
| switches[3] |
| )); |
| } |
| } |
| |
| protected View updateNotificationVetoButton(View row, StatusBarNotification n) { |
| View vetoButton = row.findViewById(R.id.veto); |
| if (n.isClearable()) { |
| final String _pkg = n.pkg; |
| final String _tag = n.tag; |
| final int _id = n.id; |
| vetoButton.setOnClickListener(new View.OnClickListener() { |
| public void onClick(View v) { |
| try { |
| mBarService.onNotificationClear(_pkg, _tag, _id); |
| } catch (RemoteException ex) { |
| // system process is dead if we're here. |
| } |
| } |
| }); |
| vetoButton.setVisibility(View.VISIBLE); |
| } else { |
| vetoButton.setVisibility(View.GONE); |
| } |
| return vetoButton; |
| } |
| } |