当前位置:网站首页>systemui shield notification bar
systemui shield notification bar
2022-08-10 14:54:00 【Indulge _ iraqis】
背景描述
The client said to block notifications in an app,But not all of them are blocked,Only block some notifications for the specified app.
很奇怪,This thing needs to be done by the system,Wouldn't it be nice if the app didn't send notifications?
但是没办法,甲方爸爸的需求,唉(:
需求实现
方案1 ------ systemuiBlock notifications
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/notification/NotificationFilter.java的shouldFilterOutAdd filtering to the method
/** * "packageName/channelId" * 表示 This is the package namechannelIDnotifications can be displayed,All others are blocked,Judgment logic see{@link notificationHide} * */
private static void initNotificationFilterList(){
notificationFilterList.add("com.aaa.bbb/background_download");
notificationFilterList.add("com.aaaa.ccc/background__upgrade");
}
/** * @return true/false When marking, specify whether hiding is required at the same time * @param key 指定应用的包名 * @param channelId Displays the specified notification,All other notifications are filtered * */
public static boolean notificationHide(String key,String channelId){
if (notificationFilterList.size() == 0){
initNotificationFilterList();
}
if (key != null && key.length() > 0 && channelId != null && channelId.length() > 0){
for (int i=0;i < notificationFilterList.size();i++){
String index = notificationFilterList.get(i);
String packageName ;
String cId ;
if (index != null && index.length() > 0){
String[] dex = index.split("/");
if (dex !=null && dex.length == 2){
packageName = dex[0];
cId = dex[1];
if (key.contains(packageName)
&& !channelId.equals(cId)) {
return true;
}
}
}
}
}
return false;
}
/** * @return true if the provided notification should NOT be shown right now. */
public boolean shouldFilterOut(NotificationEntry entry) {
final StatusBarNotification sbn = entry.getSbn();
...
if (sbn != null){
if (notificationHide(sbn.getKey(),sbn.getNotification().getChannelId())){
//Block app notifications
return true;
}
}
...
return false;
}
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java的onNotificationPosted中
@Override
public void onNotificationPosted(final StatusBarNotification sbn,
final RankingMap rankingMap) {
if (DEBUG) Log.d(TAG, "onNotificationPosted: " + sbn);
if (sbn != null){
//Block app notifications
if (NotificationFilter.notificationHide(sbn.getKey(),sbn.getNotification().getChannelId())){
return ;
}
}
if (sbn != null && !onPluginNotificationPosted(sbn, rankingMap)) {
mMainHandler.post(() -> {
processForRemoteInput(sbn.getNotification(), mContext);
for (NotificationHandler handler : mNotificationHandlers) {
handler.onNotificationPosted(sbn, rankingMap);
}
});
}
}
The above method can be blockedsystemuiNotice below,Implement the specified application to display only the specified notification,All other notifications are required to be hidden.
but
This effect just doesn't show the notification,The notification itself is still there.
1、比如launcher's notification dot,Problems such as the notification display of long-pressing the desktop icon.
frameworks/base/core/java/android/service/notification/NotificationListenerService.java
的getActiveNotifications方法获取通知.
2、其它应用可以通过
frameworks/base/services/core/java/com/android/server/notification/NotificationManagerService.java的getNotificationRecord、getActiveNotificationsFromListenerOr other methods to get the notification content.
Re-trigger another way of thinking
We should fundamentally remove those notifications to block,Or just leave it out in the first placeadd到NotificationManagerService中去.
方案2 ------ framework中屏蔽
frameworks/base/services/core/java/com/android/server/notification/NotificationManagerService.java中
The acquisition of notifications is mainly in
@GuardedBy("mNotificationLock")
final ArrayList<NotificationRecord> mNotificationList = new ArrayList<>();
@GuardedBy("mNotificationLock")
final ArrayMap<String, NotificationRecord> mNotificationsByKey = new ArrayMap<>();
The two lists summap中存储.We want to implement blocking add,Implements blocking of specific notifications.
1、track above2个add和put数据的地方
2、PostNotificationRunnable的run方法中进行add和put通知数据
3、EnqueueNotificationRunnable中启动的PostNotificationRunnable
4、enqueueNotificationInternal方法中启动EnqueueNotificationRunnable,But later found that there are other places also enabledEnqueueNotificationRunnable.
所以我们在enqueueNotificationInternal和EnqueueNotificationRunnable 2Every place has added some shielding processing.
void enqueueNotificationInternal(...){
...
if (notificationHide(pkg,channelId)){
//过滤通知
return;
}
if (channel == null) {
final String noChannelStr = "No Channel found for "
}
...
}
内部类EnqueueNotificationRunnable的run方法中
public void run() {
...
if (contextId != null) {
(new SnoozeNotificationRunnable(r.getSbn().getKey(),
0, contextId)).snoozeLocked(r);
return;
}
//Block notifications
if(r != null && r.getSbn() !=null && r.getSbn().getNotification() !=null){
String key = r.getSbn().getKey();
String channelId = r.getSbn().getNotification().getChannelId();
if (notificationHide(key,channelId)){
return;
}
}
mEnqueuedNotifications.add(r);
...
}
这样修改之后,can be completely blocked,Notifications are no longer added to the list.
结尾
The above process is onlynotificationA small part of the notification process
Full notification sent----framework添加通知----systemui显示通知.etc. The process is not fully tracked.
如果有理解不到位的地方,欢迎留言~
补充
通知的使用:https://blog.csdn.net/jppipai/article/details/122864465
1、App sends notifications------framework中serviceManage notification data
NotificationManager.notify------NotificationManagerService.enqueueNotificationWithTag------NotificationManagerService.enqueueNotificationInternal
这里就和上面serviceThe place to block notifications echoed.
//manageras an interface to the upper layer,It will eventually fallserviceManage notification data
frameworks/base/core/java/android/app/NotificationManager.java
public void notify(int id, Notification notification)
{
notify(null, id, notification);
}
public void notify(String tag, int id, Notification notification)
{
notifyAsUser(tag, id, notification, mContext.getUser());
}
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();
}
}
//serviceManage notification data
frameworks/base/services/core/java/com/android/server/notification/NotificationManagerService.java
@Override
public void enqueueNotificationWithTag(String pkg, String opPkg, String tag, int id,
Notification notification, int userId) throws RemoteException {
enqueueNotificationInternal(pkg, opPkg, Binder.getCallingUid(),
Binder.getCallingPid(), tag, id, notification, userId);
}
边栏推荐
- Lack of comparators, op amps come to the rescue!(Op amp is recorded as a comparator circuit)
- MQTT服务器搭建
- 自定义picker滚动选择器样式
- Summary of Force Buckle Solution 640 - Solving Equations
- 电脑重装系统提示activex部件不能创建对象如何解决
- 容器化 | 在 S3 实现定时备份
- Websocket realizes real-time change of chart content
- 2022-08-10日报: Swin Transformer作者曹越加入智源,开展视觉基础模型研究
- 产品使用说明书小程序开发制作说明
- CSP-J1 CSP-S1 初赛 第1轮(2022.08.09)
猜你喜欢
fatal error C1083 无法打开包括文件'io.h' No such file
Based on Azuki Series: NFT Valuation Analysis Framework "DRIC"
Flask框架——基于Celery的后台任务
正则表达式(包含各种括号,echo,正则三剑客以及各种正则工具)
统信 UOS V20 专业版(1050update2)发布:文件共享、全局搜索等优化
【MindSpore易点通机器人-02】设计与技术选型
图式图例规范尺寸
MySQL 原理与优化:Update 优化
【Gazebo入门教程】第三讲 SDF文件的静/动态编程建模
使用决策树对鸢尾花进行分类
随机推荐
QOS功能介绍
Using data intelligence, Amazon cloud technology helps companies build endogenous brand growth
兆骑科创高层次人才创业大赛平台,投融资对接,双创服务
TestLink导出用例转换工具
Parallels 将扩展桌面平台产品,以进一步改善在 Mac 上运行 Windows 的用户体验和工作效率
【吴恩达来信】强化学习的发展!
laravel 抛错给钉钉
宝塔面板开放Redis给指定外网机器
解题-->在线OJ(十九)
win2012安装Oraclerac失败
使用Uiautomator2进行APP自动化测试
leetcode 739. Daily Temperatures Daily Temperatures (Moderate)
第五讲 测试技术与用例设计
"Thesis Reading" PLATO: Pre-trained Dialogue Generation Model with Discrete Latent Variable
快速了解大端模式和小端模式
【语义分割】DeepLab系列
文件系统设计
How does IT Xiaobai learn PHP systematically
Epoll learn to think: a high performance server processing framework
SWIG tutorial "two"