Android9.0 SystemUI通知显示流程

系统会通过两个方法将通知上报给SystemUI的NotificationListener类:

@Override
public void onListenerConnected() {
    if (DEBUG) Log.d(TAG, "onListenerConnected");
    onPluginConnected();
    final StatusBarNotification[] notifications = getActiveNotifications();
    if (notifications == null) {
        Log.w(TAG, "onListenerConnected unable to get active notifications.");
        return;
    }
    final RankingMap currentRanking = getCurrentRanking();
    mPresenter.getHandler().post(() -> {
        for (StatusBarNotification sbn : notifications) {
            mEntryManager.addNotification(sbn, currentRanking);
        }
    });
}
 
@Override
public void onNotificationPosted(final StatusBarNotification sbn,
        final RankingMap rankingMap) {
    if (DEBUG) Log.d(TAG, "onNotificationPosted: " + sbn);
    if (sbn != null && !onPluginNotificationPosted(sbn, rankingMap)) {
        //......省略部分代码......
    }
}

通知显示流程图如下:

androidP通知显示流程图.png

如果我们要对一些通知进行屏蔽,可在NotificationData类的filterAndSort()方法中进行处理,即修改shouldFilterOut()方法。如代码所示屏蔽android包的USB channel通知。

public void filterAndSort() {
    mSortedAndFiltered.clear();
 
    synchronized (mEntries) {
        final int N = mEntries.size();
        for (int i = 0; i < N; i++) {
            Entry entry = mEntries.valueAt(i);
 
            if (shouldFilterOut(entry)) {
                continue;
            }
 
            mSortedAndFiltered.add(entry);
        }
    }
 
    Collections.sort(mSortedAndFiltered, mRankingComparator);
}
 
**
 * @return true if this notification should NOT be shown right now
 */
public boolean shouldFilterOut(Entry entry) {
    final StatusBarNotification sbn = entry.notification;
    //屏蔽android包channelId为USB的通知.
    try {
        if(sbn.getPackageName().equals("android") && sbn.getNotification().getChannelId().equals("USB")){
            Logger.d(TAG,"block notification channel-USB  of package-android.");
            return true;
        }
    }catch (Exception e){
        e.printStackTrace();
        //do nothing.
    }
 
    if (!(mEnvironment.isDeviceProvisioned() ||
            showNotificationEvenIfUnprovisioned(sbn))) {
        return true;
    }
    //......省略部分代码......
}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,我们可以了解到Android 9.0系统源码中SwipeHelper.java的位置为frameworks/base/packages/SystemUI/src/com/android/systemui/SwipeHelper.java。SwipeHelper.java是一个帮助类,用于处理滑动手势的事件。下面是SwipeHelper.java源码分析的流程: 1.首先,我们需要了解SwipeHelper.java的作用和功能。SwipeHelper.java是一个帮助类,用于处理滑动手势的事件。它可以检测用户的手势方向,并根据手势方向执行相应的操作。 2.接下来,我们需要了解SwipeHelper.java的主要方法和变量。SwipeHelper.java包含了一些重要的方法和变量,例如: - mSwipeDirection:表示滑动的方向,可以是上、下、左、右等方向。 - mSwipeThreshold:表示滑动的阈值,当用户滑动的距离超过这个阈值时,才会触发滑动事件。 - onInterceptTouchEvent:用于拦截触摸事件,判断是否需要处理滑动事件。 - onTouchEvent:用于处理触摸事件,根据手势方向执行相应的操作。 3.然后,我们需要了解SwipeHelper.java的具体实现。SwipeHelper.java主要实现了以下几个方法: - onInterceptTouchEvent:该方法用于拦截触摸事件,判断是否需要处理滑动事件。在该方法中,SwipeHelper会根据触摸事件的类型和位置,判断是否需要处理滑动事件。如果需要处理滑动事件,则返回true,否则返回false。 - onTouchEvent:该方法用于处理触摸事件,根据手势方向执行相应的操作。在该方法中,SwipeHelper会根据触摸事件的类型和位置,判断用户的手势方向,并根据手势方向执行相应的操作。例如,如果用户向左滑动,则会执行onSwipeLeft方法。 - onSwipeLeft:该方法用于处理向左滑动事件。在该方法中,SwipeHelper会执行一些操作,例如关闭通知栏、打开侧边栏等。 - onSwipeRight:该方法用于处理向右滑动事件。在该方法中,SwipeHelper会执行一些操作,例如打开通知栏、关闭侧边栏等。 - onSwipeUp:该方法用于处理向上滑动事件。在该方法中,SwipeHelper会执行一些操作,例如打开最近任务列表、打开应用程序列表等。 - onSwipeDown:该方法用于处理向下滑动事件。在该方法中,SwipeHelper会执行一些操作,例如关闭最近任务列表、关闭应用程序列表等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值