首页 > 其他分享 >Anroid 11 关于NotificationManager && NotificationManagerService

Anroid 11 关于NotificationManager && NotificationManagerService

时间:2024-07-20 14:39:56浏览次数:10  
标签:11 NotificationManager NotificationManagerService int notification void record p

frameworks/base/core/java/android/app/NotificationManager.java
几个比较重要的函数:

//移除mContext.getUser发送的通知
public void cancel(@Nullable String tag, int id)
    {
        cancelAsUser(tag, id, mContext.getUser());
    }
//移除所有通知 
public void cancelAll()
    {
        INotificationManager service = getService();
        String pkg = mContext.getPackageName();
        if (localLOGV) Log.v(TAG, pkg + ": cancelAll()");
        try {
            service.cancelAllNotifications(pkg, mContext.getUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

//发送通知,这里可以做判断屏蔽不发送通知
public void notify(int id, Notification notification)
public void notify(String tag, int id, Notification notification)
public void notifyAsUser(String tag, int id, Notification notification, UserHandle user)
    {
        INotificationManager service = getService();
        String pkg = mContext.getPackageName();

        try {
            if (localLOGV) Log.v(TAG, pkg + ": notify(" + id + ", " + notification + ")");
            service.enqueueNotificationWithTag(pkg, mContext.getOpPackageName(), tag, id,
                    fixNotification(notification), user.getIdentifier());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

frameworks/base/services/core/java/com/android/server/notification/NotificationManagerService.java

enqueueNotificationInternal(...)
{
    mHandler.post(new EnqueueNotificationRunnable(userId, r, isAppForeground));
}
-> postPostNotificationRunnableMaybeDelayedLocked(r, new PostNotificationRunnable(r.getKey()));
->class PostNotificationRunnable implements Runnable 
{   
        @Override
        public void run() {
            //通知放在通知队列中,按照顺序处理
            synchronized (mNotificationLock) {
                try {
                    NotificationRecord r = null;
                    int N = mEnqueuedNotifications.size();
                    for (int i = 0; i < N; i++) {
                        final NotificationRecord enqueued = mEnqueuedNotifications.get(i);
                        if (Objects.equals(key, enqueued.getKey())) {
                            r = enqueued;
                            break;
                        }
                    }
                    if (r == null) {
                        Slog.i(TAG, "Cannot find enqueued record for key: " + key);
                        return;
                    }

                    if (isBlocked(r)) {
                        Slog.i(TAG, "notification blocked by assistant request");
                        return;
                    }
}


//负责处理通知声音的函数.
//判断通知是否应尝试发出噪音、振动或闪烁LED,
//@return buzzBeepBlink - bitfield (buzz ? 1 : 0) | (beep ? 2 : 0) | (blink ? 4 : 0)

int buzzBeepBlinkLocked(NotificationRecord record) {
    if (mIsAutomotive && !mNotificationEffectsEnabledForAutomotive) {
            return 0;
        }
        boolean buzz = false;
        boolean beep = false;
        boolean blink = false;
    ...
        if (hasAudibleAlert && !shouldMuteNotificationLocked(record)) {
                    if (!sentAccessibilityEvent) {
                        sendAccessibilityEvent(record);
                        sentAccessibilityEvent = true;
                    }
                    if (DBG) Slog.v(TAG, "Interrupting!");
                    if (hasValidSound) {
                        if (isInCall()) {
                            playInCallNotification();//电话铃声?
                            beep = true;
                        } else {
                            beep = playSound(record, soundUri);//播放通知的声音函数,soundUri.getPath()通知声音文件路径
                        }
                        if(beep) {
                            mSoundNotificationKey = key;
                        }
                    }

                    final boolean ringerModeSilent =
                            mAudioManager.getRingerModeInternal()
                                    == AudioManager.RINGER_MODE_SILENT;
                    if (!isInCall() && hasValidVibrate && !ringerModeSilent) {
                        buzz = playVibration(record, vibration, hasValidSound);
                        if(buzz) {
                            mVibrateNotificationKey = key;
                        }
                    }
                } else if ((record.getFlags() & Notification.FLAG_INSISTENT) != 0) {
                    hasValidSound = false;
                }
            }
            ...
}

标签:11,NotificationManager,NotificationManagerService,int,notification,void,record,p
From: https://www.cnblogs.com/kato-T/p/18313092

相关文章

  • docker 创建 oracle 11g
    参考【DB宝11】在Docker中只需2步即可拥有Oracle11g企业版环境(11.2.0.3)拉取镜像#从Dockerhub下载,网络不好时,一般比较慢dockerpulllhrbest/oracle_11g_ee_lhr_11.2.0.3:1.0#可以选择从阿里云下载dockerpullregistry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_......
  • win10访问共享打印机提示0x0000011b错误原因分析及解决方法
          2024年十大技术难题之“共享打印机报0x0000011b错误”该问题一直存在,该问题是由于Win10更新补丁后大面积出现打印机无法共享。即使目前最新的Win1022h2镜像还是没有修复打印机共享BUG,虽然微软发布了最新更新补丁,越更新越有问题。不过此工具可以修复最近出现......
  • Win11系统提示找不到LocationWinPalMisc.dll文件的解决办法
    其实很多用户玩单机游戏或者安装软件的时候就出现过这种问题,如果是新手第一时间会认为是软件或游戏出错了,其实并不是这样,其主要原因就是你电脑系统的该dll文件丢失了或没有安装一些系统软件平台所需要的动态链接库,这时你可以下载这个LocationWinPalMisc.dll文件(挑选合适的版本......
  • Win11系统提示找不到LogCollector.Resources.dll文件的解决办法
    其实很多用户玩单机游戏或者安装软件的时候就出现过这种问题,如果是新手第一时间会认为是软件或游戏出错了,其实并不是这样,其主要原因就是你电脑系统的该dll文件丢失了或没有安装一些系统软件平台所需要的动态链接库,这时你可以下载这个LogCollector.Resources.dll文件(挑选合适的......
  • Oracle(11)Oracle有哪些常见的数据类型?
    Oracle数据库提供了多种数据类型,用于存储不同类型的数据。以下是一些常见的Oracle数据类型,并结合代码进行详细说明:VARCHAR2:存储可变长度的字符串,最大长度为4000字节。CREATETABLEemployees(employee_idNUMBER,first_nameVARCHAR2(50),last_nameVAR......
  • [lnsyoj110/luoguP2024]食物链
    题意原题链接三类元素\(a,b,c\)满足\(a\tob\),\(b\toc\),\(c\toa\)。现在共有\(n\)个元素,给出\(m\)条关系\(x\toy\)或\(x\)与\(y\)种类相同,输出非法或与前面所属关系相矛盾的关系数量sol并查集可以处理“朋友的朋友是朋友”这样的传递关系,却不能处理“敌人......
  • 线程池(C++11)
    已经有现成的实现,本博客摘抄讲解附源码链接。参考的博客质量已经非常高,避免找来找去。1、避免频繁创建、销毁线程,实现复用。思路如下:2、线程函数多种多样,如何封装成统一的函数类型void()第一次封装我们使用bind()函数将多个参数的函数封装为没有形参的package_task对象,因为p......
  • P1182 数列分段 Section II
    传送锚点:数列分段SectionII-洛谷题目描述对于给定的一个长度为\(N\)的正整数数列\(A_{1\simN}\),现要将其分成\(M\)(\(M\leqN\))段,并要求每段连续,且每段和的最大值最小。关于最大值最小:例如一数列\(4\2\4\5\1\)要分成\(3\)段。将其如下分段:\([4\2][4\5][1......
  • CodeForces - 1139D
    题目大意序列每次随机添加一个\([1,m]\)的整数,直到序列\(gcd=1\)停止,求期望操作次数。分析模拟过程发现只关心整个序列的\(gcd\)与下一次会添加什么,那么根据期望\(dp\)套路可得状态\(f_{i}\)表示当前序列\(gcd=i\),期望还操作多少次使得\(gcd=1\)。考虑枚举下一个......
  • G69 前缀线性基+贪心法 CF1100F Ivan and Burgers
    视频链接:G69前缀线性基+贪心法CF1100FIvanandBurgers_哔哩哔哩_bilibili   IvanandBurgers-洛谷|计算机科学教育新生态(luogu.com.cn)//前缀线性基+贪心法O(30*n)#include<iostream>#include<cstring>#include<algorithm>usingnamespacestd;......