通知大致流程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
NotificationManager.java    (framework)
| notify()
| notifyAsUser()
| service.enqueueNotificationWithTag( , , , , fixNotification (), )

NotificationManagerService.java (framework)
| enqueueNotificationWithTag()
| enqueueNotificationInternal()
| enqueueNotificationInternal( , , )
| enqueueNotificationInternal( , , , , )
| fixNotification()
| StatusBarNotification // SystemUI 会用
| NotificationChannel
| NotificationRecord // framework 用
| checkDisqualifyingFeatures()
| mHandler.post(new EnqueueNotificationRunnable(userId, r, isAppForeground, tracker));

EnqueueNotificationRunnable implements Runnable
| enqueueNotification()
| PostNotificationRunnable

PostNotificationRunnable
| postNotification()
| notifyListenersPostedAndLogLocked()
| prepareNotifyPostedLocked() --> NotificationListeners#prepareNotifyPostedLocked()




class NotificationListeners (NotificationManagerService.java里)
// notifyRemoved
// This notification became invisible -> remove the old one.
if (oldSbnVisible && !sbnVisible) {
final StatusBarNotification oldSbnLightClone = oldSbn.cloneLight();
listenerCalls.add(() -> notifyRemoved(
info, oldSbnLightClone, update, null, REASON_USER_STOPPED));
continue;
}
// notifyPosted
final StatusBarNotification sbnToPost = trimCache.ForListener(info);
listenerCalls.add(() -> notifyPosted(info, sbnToPost, update));


private void notifyPosted(final ManagedServiceInfo info,
final StatusBarNotification sbn, NotificationRankingUpdate rankingUpdate) {
final INotificationListener listener = (INotificationListener) info.service;
StatusBarNotificationHolder sbnHolder = new StatusBarNotificationHolder(sbn);
try {
listener.onNotificationPosted(sbnHolder, rankingUpdate);
} catch (android.os.DeadObjectException ex) {
Slog.wtf(TAG, "unable to notify listener (posted): " + info, ex);
} catch (RemoteException ex) {
Slog.e(TAG, "unable to notify listener (posted): " + info, ex);
}
}

NotificationListener.java (SystemUI)
onNotificationPosted()

interface NotificationHandler (是NotificationListener.java 内部接口)
onNotificationPosted()

本文作者:Dorian

本文链接:https://blog.daiyan.org/2025/07/07/%E9%80%9A%E7%9F%A5%E5%A4%A7%E8%87%B4%E6%B5%81%E7%A8%8B/

版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!

ESC 关闭 | 导航 | Enter 打开
输入关键词开始搜索