1.com.android.server
framework/base/services/java/com/android/server/SystemServer.java
系统启动的时候所需要启动的服务都在这里添加
LightsService lights = null;
PowerManagerService power = null;
BatteryService battery = null;
ConnectivityService connectivity = null;
IPackageManager pm = null;
Context context = null;
WindowManagerService wm = null;
BluetoothService bluetooth = null;
BluetoothA2dpService bluetoothA2dp = null;
HeadsetObserver headset = null;
DockObserver dock = null;
UsbObserver usb = null;
UiModeManagerService uiMode = null;
RecognitionManagerService recognition = null;
ThrottleService throttle = null
DevicePolicyManagerService devicePolicy = null;
StatusBarManagerService statusBar = null;
InputMethodManagerService imm = null;
AppWidgetService appWidget = null;
NotificationManagerService notification = null;
WallpaperManagerService wallpaper = null;
LocationManagerService location = null;
try {
Slog.i(TAG, "Status Bar");
statusBar = new StatusBarManagerService(context);
ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
} catch (Throwable e) {
Slog.e(TAG, "Failure starting StatusBarManagerService", e);
}
2.StatusBarManagerService.java frameworks\base\services\java\com\android\server
有addNotification,removeNotification,updateNotification等方法用于管理传递给他的通知对象。这个类是一些管理方法,实际执行相关动作的是在IStatusBar.java里面,这个是framework/base/core/java/com/android/internal/statusbar/IStatusBar.aidl自动生成的用于IPC的类。
public IBinder addNotification(StatusBarNotification notification) {
synchronized (mNotifications) {
IBinder key = new Binder();
mNotifications.put(key, notification);
if (mBar != null) {
try {
mBar.addNotification(key, notification);
} catch (RemoteException ex) {
}
}
return key;
}
}
StatusBarService.java
mCommandQueue = new CommandQueue(this, iconList);//StatusBarService实现了CommandQueue中的CommandQueue.Callbacks接口
mBarService = IStatusBarService.Stub.asInterface(
ServiceManager.getService(Context.STATUS_BAR_SERVICE));
try {
//将IStatusBar实现类的对象传递到StatusBarManagerService.java中,这里的mCommandQueue就是上面对应的mBar啦。
mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications);
} catch (RemoteException ex) {
// If the system process isn't there we're doomed anyway.
}
最终执行状态栏更新通知等事件都是在实现的CommandQueue.Callbacks里面执行。还是以addNotification
public void addNotification(IBinder key, StatusBarNotification notification) {
boolean shouldTick = true;
if (notification.notification.fullScreenIntent != null) {
shouldTick = false;
Slog.d(TAG, "Notification has fullScreenIntent; sending fullScreenIntent");
try {
notification.notification.fullScreenIntent.send();
} catch (PendingIntent.CanceledException e) {
}
}
StatusBarIconView iconView = addNotificationViews(key, notification);
if (iconView == null) return;
//。。。以下省略N字。
调用StatusBarManagerService.java中的addNotification方法
->(mBar不为空的话)执行mBar.addNotification(key, notification);
->对应的是CommandQueue中的addNotification(IBinder key, StatusBarNotification notification)
->CommandQueue中的mCallbacks.addNotification(ne.key, ne.notification);
->StatusBarService中的addNotification。
3.具体的notification的管理类是framework/base/services/java/com/android/server/NotificationManagerService.java
4.notification常量
notification.defaults
INT DEFAULT_ALL 使用所有默认值(如适用)。
INT DEFAULT_LIGHTS 使用默认的通知灯。
INT DEFAULT_SOUND 使用默认的通知声音。
INT DEFAULT_VIBRATE 使用默认的通知振动。
notification.flags
INT FLAG_AUTO_CANCEL 位被位或标志字段,如果当它被点击的用户,应该取消的通知,应设置。
INT FLAG_FOREGROUND_SERVICE 位位或到标志字段,应设置通知,如果这代表了当前正在运行的服务。
INT FLAG_HIGH_PRIORITY 位位或到标志字段,如果该通知表示,应设置一个高优先级的事件,可能显示给用户,即使通知,否则不可用(即,当隐藏状态栏)。
INT FLAG_INSISTENT 位被按位或到标志字段,如果设置,音频会被重复,直到被取消的通知,或通知窗口打开。
INT FLAG_NO_CLEAR 位被位或标志字段,应设置当用户单击全部清除“按钮,如果不应该取消通知。
INT FLAG_ONGOING_EVENT 位被位或标志字段,如果这个通知是在参考的东西是持续的,就像一个电话,应设置。
INT FLAG_ONLY_ALERT_ONCE 位被按位或进入的领域,如果你想要的声音和/或振动,发挥每个发送通知的时间,即使并没有被取消之前,应设置标志。
INT FLAG_SHOW_LIGHTS 位被按位或如果你想上的LED此通知应设置进入的标志字段。
notification.audioStreamType
INT STREAM_DEFAULT 使用此常数的值audioStreamType要求使用默认的流类型的通知。
5.创建一个简单的notification
notification=new Notification(R.drawable.ic_launcher,//图标
"notification notification ",//信息
System.currentTimeMillis());//什么时候显示
// notification.contentIntent=new PendingIntent();
notification.flags |= Notification.FLAG_NO_CLEAR;//点击清除通知时候是否被清除
notification.flags |= Notification.FLAG_ONGOING_EVENT; //允许处理点击事件
notification.flags |= Notification.FLAG_AUTO_CANCEL; //点击后自动取消
notification.setLatestEventInfo(getActivity(),//更新通知用的,在已经设置好了notification后在调用这个方法,那就可以更新了
"contentTitle",
"notification",
PendingIntent.getActivity(getActivity(),
0,
new Intent(getActivity(),//启动activity的 intent 注意是否需要 Intent.FLAG_ACTIVITY_NEW_TASK
AHomeActivity.class),
PendingIntent.FLAG_UPDATE_CURRENT));
//在拉下来后显示的nogoing的界面,点击处理点击事件的view
notification.contentView=new RemoteViews(getActivity().getPackageName(), R.layout.test);
// notification.when=System.currentTimeMillis();
// notification.icon=R.drawable.ic_launcher;
// notification.tickerText="notification notification notification notification";
manager=(NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
//一个id只能是标识一个notification
manager.notify(v.getId(), notification);