blob: a64c3e779ffa38dd053543a495818f55c4d018b8 [file] [log] [blame]
Joe Onorato2314aab2010-04-08 16:41:23 -05001/*
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
Joe Onorato79de0c52010-05-26 17:03:26 -040017package com.android.systemui.statusbar;
Joe Onorato2314aab2010-04-08 16:41:23 -050018
19import android.app.Service;
Joe Onorato808182d2010-07-09 18:52:06 -040020import android.content.Context;
21import android.content.Intent;
22import android.content.res.Resources;
23import android.graphics.PixelFormat;
24import android.os.IBinder;
25import android.os.RemoteException;
26import android.os.ServiceManager;
27import android.util.Slog;
28import android.util.Log;
29import android.view.Gravity;
30import android.view.View;
31import android.view.ViewGroup;
32import android.view.WindowManager;
33import android.view.WindowManagerImpl;
34
35import java.util.ArrayList;
36
Joe Onorato0cbda992010-05-02 16:28:15 -070037import com.android.internal.statusbar.IStatusBar;
38import com.android.internal.statusbar.IStatusBarService;
39import com.android.internal.statusbar.StatusBarIcon;
40import com.android.internal.statusbar.StatusBarIconList;
Joe Onorato75199e32010-05-29 17:22:51 -040041import com.android.internal.statusbar.StatusBarNotification;
42
Joe Onorato1c95ecb2010-06-28 17:19:12 -040043import com.android.systemui.R;
Joe Onorato1c95ecb2010-06-28 17:19:12 -040044
Joe Onorato808182d2010-07-09 18:52:06 -040045public abstract class StatusBarService extends Service implements CommandQueue.Callbacks {
Joe Onorato1c95ecb2010-06-28 17:19:12 -040046 static final String TAG = "StatusBarService";
Joe Onorato1c95ecb2010-06-28 17:19:12 -040047
Joe Onorato808182d2010-07-09 18:52:06 -040048 protected CommandQueue mCommandQueue;
49 protected IStatusBarService mBarService;
Joe Onorato1c95ecb2010-06-28 17:19:12 -040050
Joe Onorato808182d2010-07-09 18:52:06 -040051 // Up-call methods
52 protected abstract View makeStatusBarView();
53 protected abstract int getStatusBarGravity();
Joe Onorato1c95ecb2010-06-28 17:19:12 -040054
Joe Onorato808182d2010-07-09 18:52:06 -040055 /**
56 * Nobody binds to us.
57 */
58 @Override
59 public IBinder onBind(Intent intent) {
60 return null;
Joe Onorato1c95ecb2010-06-28 17:19:12 -040061 }
62
Joe Onorato2314aab2010-04-08 16:41:23 -050063 @Override
64 public void onCreate() {
Joe Onorato1c95ecb2010-06-28 17:19:12 -040065 // First set up our views and stuff.
Joe Onorato808182d2010-07-09 18:52:06 -040066 View sb = makeStatusBarView();
Joe Onorato1c95ecb2010-06-28 17:19:12 -040067
Joe Onorato2314aab2010-04-08 16:41:23 -050068 // Connect in to the status bar manager service
Joe Onorato0cbda992010-05-02 16:28:15 -070069 StatusBarIconList iconList = new StatusBarIconList();
Joe Onorato75199e32010-05-29 17:22:51 -040070 ArrayList<IBinder> notificationKeys = new ArrayList<IBinder>();
71 ArrayList<StatusBarNotification> notifications = new ArrayList<StatusBarNotification>();
Joe Onorato66d7d012010-05-14 10:05:10 -070072 mCommandQueue = new CommandQueue(this, iconList);
Joe Onorato25f95f92010-04-08 18:37:10 -050073 mBarService = IStatusBarService.Stub.asInterface(
Joe Onorato2314aab2010-04-08 16:41:23 -050074 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
75 try {
Joe Onorato75199e32010-05-29 17:22:51 -040076 mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications);
Joe Onorato2314aab2010-04-08 16:41:23 -050077 } catch (RemoteException ex) {
78 // If the system process isn't there we're doomed anyway.
79 }
Joe Onorato0cbda992010-05-02 16:28:15 -070080
81 // Set up the initial icon state
Joe Onorato75199e32010-05-29 17:22:51 -040082 int N = iconList.size();
Joe Onorato0cbda992010-05-02 16:28:15 -070083 int viewIndex = 0;
84 for (int i=0; i<N; i++) {
85 StatusBarIcon icon = iconList.getIcon(i);
86 if (icon != null) {
87 addIcon(iconList.getSlot(i), i, viewIndex, icon);
88 viewIndex++;
89 }
90 }
91
Joe Onorato75199e32010-05-29 17:22:51 -040092 // Set up the initial notification state
93 N = notificationKeys.size();
Joe Onorato75199e32010-05-29 17:22:51 -040094 if (N == notifications.size()) {
95 for (int i=0; i<N; i++) {
96 addNotification(notificationKeys.get(i), notifications.get(i));
97 }
98 } else {
99 Log.wtf(TAG, "Notification list length mismatch: keys=" + N
100 + " notifications=" + notifications.size());
101 }
102
Joe Onorato0cbda992010-05-02 16:28:15 -0700103 // Put up the view
Joe Onorato808182d2010-07-09 18:52:06 -0400104 final Resources res = getResources();
Joe Onorato1c95ecb2010-06-28 17:19:12 -0400105 final int height= res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
106
Joe Onorato808182d2010-07-09 18:52:06 -0400107 final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
Joe Onorato1c95ecb2010-06-28 17:19:12 -0400108 ViewGroup.LayoutParams.MATCH_PARENT,
109 height,
110 WindowManager.LayoutParams.TYPE_STATUS_BAR,
111 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
112 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING,
113 PixelFormat.RGBX_8888);
Joe Onorato808182d2010-07-09 18:52:06 -0400114 lp.gravity = getStatusBarGravity();
Joe Onorato1c95ecb2010-06-28 17:19:12 -0400115 lp.setTitle("StatusBar");
116 // TODO lp.windowAnimations = R.style.Animation_StatusBar;
Joe Onorato808182d2010-07-09 18:52:06 -0400117 WindowManagerImpl.getDefault().addView(sb, lp);
Joe Onorato1c95ecb2010-06-28 17:19:12 -0400118
Joe Onorato808182d2010-07-09 18:52:06 -0400119 Slog.d(TAG, "Added status bar view w/ gravity 0x" + Integer.toHexString(lp.gravity));
Joe Onorato1c95ecb2010-06-28 17:19:12 -0400120 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500121}
122