有同事遇到发送广播接收不到的问题,分析log发现是system进程发送non-protected广播的问题。Ams在发送广播时,对于systemApp会要求广播必须是声明在frameworks\base\core\res\AndroidManifest.xml里面的protected-broadcast。这样可以避免三方垃圾应用也发送这些广播来捣蛋。

03-30 09:35:31.829  3827  4459 E ActivityManager: Sending non-protected broadcast
droidlogic.hdr.policy.source_1 from system 4556:com.android.tv.settings/1000 pkg
com.android.tv.settings

检查system进程权限的函数

private void checkBroadcastFromSystem(Intent intent, ProcessRecord callerApp,String callerPackage, int callingUid, boolean isProtectedBroadcast, List receivers) {if ((intent.getFlags() & Intent.FLAG_RECEIVER_FROM_SHELL) != 0) {// Don't yell about broadcasts sent via shellreturn;}final String action = intent.getAction();if (isProtectedBroadcast|| Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)|| Intent.ACTION_DISMISS_KEYBOARD_SHORTCUTS.equals(action)|| Intent.ACTION_MEDIA_BUTTON.equals(action)|| Intent.ACTION_MEDIA_SCANNER_SCAN_FILE.equals(action)|| Intent.ACTION_SHOW_KEYBOARD_SHORTCUTS.equals(action)|| Intent.ACTION_MASTER_CLEAR.equals(action)|| Intent.ACTION_FACTORY_RESET.equals(action)|| AppWidgetManager.ACTION_APPWIDGET_CONFIGURE.equals(action)|| AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)|| LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION.equals(action)|| TelephonyIntents.ACTION_REQUEST_OMADM_CONFIGURATION_UPDATE.equals(action)|| SuggestionSpan.ACTION_SUGGESTION_PICKED.equals(action)|| AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION.equals(action)|| AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION.equals(action)) {// Broadcast is either protected, or it's a public action that// we've relaxed, so it's fine for system internals to send.return;}// This broadcast may be a problem...  but there are often system components that// want to send an internal broadcast to themselves, which is annoying to have to// explicitly list each action as a protected broadcast, so we will check for that// one safe case and allow it: an explicit broadcast, only being received by something// that has protected itself.if (intent.getPackage() != null || intent.getComponent() != null) {if (receivers == null || receivers.size() == 0) {// Intent is explicit and there's no receivers.// This happens, e.g. , when a system component sends a broadcast to// its own runtime receiver, and there's no manifest receivers for it,// because this method is called twice for each broadcast,// for runtime receivers and manifest receivers and the later check would find// no receivers.return;}boolean allProtected = true;for (int i = receivers.size()-1; i >= 0; i--) {Object target = receivers.get(i);if (target instanceof ResolveInfo) {ResolveInfo ri = (ResolveInfo)target;if (ri.activityInfo.exported && ri.activityInfo.permission == null) {allProtected = false;break;}} else {BroadcastFilter bf = (BroadcastFilter)target;if (bf.requiredPermission == null) {allProtected = false;break;}}}if (allProtected) {// All safe!return;}}// The vast majority of broadcasts sent from system internals// should be protected to avoid security holes, so yell loudly// to ensure we examine these cases.if (callerApp != null) {Log.wtf(TAG, "Sending non-protected broadcast " + action+ " from system " + callerApp.toShortString() + " pkg " + callerPackage,new Throwable());} else {Log.wtf(TAG, "Sending non-protected broadcast " + action+ " from system uid " + UserHandle.formatUid(callingUid)+ " pkg " + callerPackage,new Throwable());}}

AndroidManifest.xml的位置

<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="android" coreApp="true" android:sharedUserId="android.uid.system"android:sharedUserLabel="@string/android_system_label"><!-- ================================================ --><!-- Special broadcasts that only the system can send --><!-- ================================================ --><eat-comment /><protected-broadcast android:name="android.intent.action.SCREEN_OFF" /><protected-broadcast android:name="android.intent.action.SCREEN_ON" /><protected-broadcast android:name="android.intent.action.USER_PRESENT" /><protected-broadcast android:name="android.intent.action.TIME_SET" /><protected-broadcast android:name="android.intent.action.TIME_TICK" /><protected-broadcast android:name="android.intent.action.TIMEZONE_CHANGED" /><protected-broadcast android:name="android.intent.action.DATE_CHANGED" /><protected-broadcast android:name="android.intent.action.PRE_BOOT_COMPLETED" />

[Q]Sending non-protected broadcast问题分析相关推荐

  1. Android Q 10.1 KeyMaster源码分析(二) - 各家方案的实现

    写在之前 这两篇文章是我2021年3月初看KeyMaster的笔记,本来打算等分析完KeyMaster和KeyStore以后再一起做成一系列贴出来,后来KeyStore的分析中断了,这一系列的文章就变 ...

  2. Android 11 Sending non-protected broadcast问题分析

    带android:sharedUserId="android.uid.system" 发送广播时,会出现 Sending non-protected broadcast 异常提醒: ...

  3. mysql索引无效且sending data耗时巨大原因分析

    一朋友最近新上线一个项目,本地测试环境跑得好好的,部署到线上却慢得像蜗牛一样.后来查询了一下发现一个sql执行了16秒,有些长的甚至80秒.本地运行都是毫秒级别的查询.下面记录一下困扰了两天的,其中一 ...

  4. 小Q同学的微信账单可视化分析(Tableau)

    Tableau微信账单可视化分析 先用python对小Q同学在2019-11.2019-12.2020-01三个月的微信账单数据进行简单的描述性分析,并将结果输出到excel文件中,再将excel文件 ...

  5. RemoteServiceException: can‘t deliver broadcast 问题分析

    一.问题背景 最近测试跑monkey连续压测,报了一个应用稳定性的问题.因为该问题比较典型,并且需要我们编码上也要注意规避该问题.我在分析过程中一直没找到根因,最后求助于leader,非常感谢不吝指教 ...

  6. Android Q 基站刷新接口源码分析 适配双卡手机基站刷新逻辑

    目录 一.获取基站信息的两个关键方法 getAllCellInfo调用流程总结 requestCellInfoUpdate 流程总结 问题 二.双卡手机适配 Android Q requestCell ...

  7. Android Broadcast原理分析之registerReceiver(一)

    目录 BroadcastReceiver概述 BroadcastReceiver分类 registerReceiver流程图 源码解析 总结 1. BroadcastReceiver概述 广播作为四大 ...

  8. Sending non-protected broadcast

    Android发送广播时报错: Sending non-protected broadcast xxxxxxx from system xxxxxxxxxx 原因: Ams在发送广播时,对于syste ...

  9. Android Sending non-protected broadcast,sendBroadcastAsUser方式发送广播

    有同事遇到发送广播接收不到的问题,分析log发现是system进程发送non-protected广播的问题.Ams在发送广播时,对于systemApp会要求广播必须是声明在frameworks\bas ...

最新文章

  1. 独家 | 在PyTorch中用图像混合(Mixup)增强神经网络(附链接)
  2. Linux 还能这么玩,10 个非常有趣的命令!
  3. CSS基础必备知识点04
  4. Page 和Ability之间区别
  5. 福建首个区块链赋能教育信息化项目上线
  6. cad卸载_盘点那些年用过的神级CAD插件,每一款都舍不得卸载
  7. 粒子群优化算法(PSO)附代码
  8. 录音文件下载_录音啦(文字语音转换)软件安装教程
  9. 服务器草稿位置在c盘可以吗,T+增加凭证的时候保存草稿,保存到那里去了
  10. 极限理论总结04:Delta方法
  11. sql cai bird教程学习记录
  12. 笔记本电脑f11功能键_笔记本电脑按键功能详细图解_笔记本电脑键盘功能详细介绍是什么-win7之家...
  13. 清橙A1210. 光棱坦克
  14. 《通信原理》(2):信息量及平均信息量
  15. SpringCloud搭建微服务之Hystrix熔断器
  16. 百度Paddle团队招聘算法实习生
  17. html中一条单线这么设置,html单线表格制作方法
  18. android MapBox地图基于openstreetmap开发
  19. python 中运行 pip 或者 easy_install 时出现 error: unable to find vcvarsall.bat 的解决办法
  20. python求解多元多次方程组或非线性方程组

热门文章

  1. 平台团购活动商品同步功能
  2. 基于django的前端天气查询网站
  3. word粘贴时只有保留文本,没有其他选项?
  4. 关于戴尔电脑频繁屏幕卡死问题的自我研究
  5. iPhone SE不会淡出视野:苹果还需要它
  6. 辍学的了应该如何自我努力?
  7. html+css页面内容设置水平垂直居中
  8. dw网页注册登录源码php,DW网页设计:验证用户注册
  9. python3编程基础:操作excel(一)
  10. 流下的眼泪,却没有骗到自己_感人的伤感短语