SystemServer啓動(main方法被調用)
public final class SystemServer {
public static void main(String[] args) {
new SystemServer().run();
}
private void run() {
mSystemServiceManager = new SystemServiceManager(mSystemContext);
mSystemServiceManager.startService(NotificationManagerService.class);
}
}
NotificationManagerService啓動(onStart方法被調用)
public class SystemServiceManager {
public SystemService startService(String className) {
1. 反射建立NotificationManagerService對象
2. 調用NotificationManagerService#onStart()方法
}
}
NotificationManagerService#onStart()初始化
public class NotificationManagerService extends SystemService {
private final IBinder mService = new INotificationManager.Stub() {}
@Override
public void onStart() {
1. 公佈mService,添加到ServiceManager
}
}
NotificationManager#getService()拿到INotificationManager對象
public class NotificationManager {
private static INotificationManager sService
static public INotificationManager getService() {
if (sService != null) {
return sService;
}
IBinder b = ServiceManager.getService("notification");
sService = INotificationManager.Stub.asInterface(b);
return sService;
}
}
NotificationManager經過INotificationManager接口調用NotificationManagerService裏的INotificationManager.Stub()對象
public class NotificationManagerService extends SystemService {
private final IBinder mService = new INotificationManager.Stub() {
1. 取消通知
2. 獲取當前通知
3. 註冊監聽器NotificationListenerService#INotificationListener
3. 取消監聽器NotificationListenerService#INotificationListener
}
}
NotificationListenerService 裏封裝了INotificationListener對象
NotificationListenerService extends Service {
private INotificationListenerWrapper mWrapper = null;
private class INotificationListenerWrapper extends INotificationListener.Stub {}
1. 建立INotificationListenerWrapper對象
2. 經過INotificationManager註冊INotificationListener
}
實現INotificationListener回調接口
oneway interface INotificationListener
{
void onListenerConnected(in NotificationRankingUpdate update);
void onNotificationPosted(in IStatusBarNotificationHolder notificationHolder,
in NotificationRankingUpdate update);
void onNotificationRemoved(in IStatusBarNotificationHolder notificationHolder,
in NotificationRankingUpdate update);
void onNotificationRankingUpdate(in NotificationRankingUpdate update);
void onListenerHintsChanged(int hints);
void onInterruptionFilterChanged(int interruptionFilter);
}
app