Broadcasts —–Security considerations and best practices「建议收藏」

Broadcasts —–Security considerations and best practices「建议收藏」Herearesomesecurityconsiderationsandbestpracticesforsendingandreceivingbroadcasts:Ifyoudon’tneedtosendbroadcaststocomponentsoutsideofyourapp,thensendandreceivelocal

大家好,又见面了,我是你们的朋友全栈君。

Here are some security considerations and best practices for sending and receiving broadcasts:

  • If you don’t need to send broadcasts to components outside of your app, then send and receive local broadcasts with the LocalBroadcastManager which is available in the Support Library. The LocalBroadcastManager is much more efficient (no interprocess communication needed) and allows you to avoid thinking about any security issues related to other apps being able to receive or send your broadcasts. Local Broadcasts can be used as a general purpose pub/sub event bus in your app without any overheads of system wide broadcasts.

  • If many apps have registered to receive the same broadcast in their manifest, it can cause the system to launch a lot of apps, causing a substantial impact on both device performance and user experience. To avoid this, prefer using context registration over manifest declaration. Sometimes, the Android system itself enforces the use of context-registered receivers. For example, the CONNECTIVITY_ACTION broadcast is delivered only to context-registered receivers.

  • Do not broadcast sensitive information using an implicit intent. The information can be read by any app that registers to receive the broadcast. There are three ways to control who can receive your broadcasts:

    • You can specify a permission when sending a broadcast.
    • In Android 4.0 and higher, you can specify a package with setPackage(String) when sending a broadcast. The system restricts the broadcast to the set of apps that match the package.
    • You can send local broadcasts with LocalBroadcastManager.
  • When you register a receiver, any app can send potentially malicious broadcasts to your app’s receiver. There are three ways to limit the broadcasts that your app receives:

    • You can specify a permission when registering a broadcast receiver.
    • For manifest-declared receivers, you can set the android:exported attribute to “false” in the manifest. The receiver does not receive broadcasts from sources outside of the app.
    • You can limit yourself to only local broadcasts with LocalBroadcastManager.
  • The namespace for broadcast actions is global. Make sure that action names and other strings are written in a namespace you own, or else you may inadvertently conflict with other apps.

  • Because a receiver’s onReceive(Context, Intent) method runs on the main thread, it should execute and return quickly. If you need to perform long running work, be careful about spawning threads or starting background services because the system can kill the entire process after onReceive() returns. For more information, see Effect on process state To perform long running work, we recommend:

    • Calling goAsync() in your receiver’s onReceive() method and passing the BroadcastReceiver.PendingResult to a background thread. This keeps the broadcast active after returning from onReceive(). However, even with this approach the system expects you to finish with the broadcast very quickly (under 10 seconds). It does allow you to move work to another thread to avoid glitching the main thread.
    • Scheduling a job with the JobScheduler. For more information, see Intelligent Job Scheduling.
  • Do not start activities from broadcast receivers because the user experience is jarring; especially if there is more than one receiver. Instead, consider displaying a notification.



版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/149655.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 只有使用 ACL 的 通配符掩码 才可以使用一条语句就可以 匹配出,奇数vlan的网段和 偶数vlan的网段,odd 奇数, even 偶数[通俗易懂]

    只有使用 ACL 的 通配符掩码 才可以使用一条语句就可以 匹配出,奇数vlan的网段和 偶数vlan的网段,odd 奇数, even 偶数[通俗易懂]只有使用ACL的通配符掩码才可以使用一条语句就可以匹配出,奇数vlan的网段和偶数vlan的网段,odd奇数,even偶数!

    2022年7月19日
    33
  • ssm/php/java/net/python中小学生视频在线网站「建议收藏」

    本系统带文档lw1万字+答辩PPT+查重如果这个题目不合适,可以去我上传的资源里面找题目,找不到的话,评论留下题目,或者站内私信我,有时间看到机会给你发系统设计.1系统体系结构中小学生视频在线网站的结构图-1所示:图-1系统结构登录系统结构图,如图-2所示:图-2登录结构图管理员结构图,如图-3所示。图-3管理员结构图.2开发流程设计系统流程的分析是通过调查系统所涉及问题的识别、可行性、可操作性、系统分析处理能力等具体环节来调节、整理系统的设计方案以确保系统能达到理

    2022年4月7日
    63
  • MySQL 重置 root 密码以及修改密码时报错password字段不存在

    MySQL 重置 root 密码以及修改密码时报错password字段不存在

    2022年2月18日
    54
  • 最大似然估计的分布函数_二项分布的最大似然估计值怎么求

    最大似然估计的分布函数_二项分布的最大似然估计值怎么求原因今天晚上,老师在看LDA数学八卦的时候,问我一个问题,如下图所示:这个多项式分布的参数,采用极大估计是怎么求的呢?当时想了想还真不知道,于是在网上找了资料,学习了一下,特此记录。公式推导很多情况下,假定一个变量XX有kk个状态,其中k>2k>2,每个状态假定的可能性为p1,p2,⋯,pkp_{1},p_{2},\cdots,p_{k},且∑ki=1pi=1\sum_{i=1}

    2022年10月12日
    3
  • 在线网站技术分析工具

    在线网站技术分析工具Wappalyzer:在线网站技术分析工具Wappalyzer网站是一个可以分析不同网站所使用的各种技术的工具,对于有自身经验的网站开发者而言可以通过代码开分析网站的构架和所采用的技术,不过现在你可以通过工具来获得网站技术的参数报告了。Wappalyzer工具致支持分析目标网站所采用的平台构架、网站环境、服务器配置环境、JavaScript框架、编程语言等参数,同时

    2022年5月4日
    48
  • linux rsyslog配置_syslog配置

    linux rsyslog配置_syslog配置在centos7中,默认的日志系统是rsyslog,它是一个类unix计算机系统上使用的开源工具,用于在ip网络中转发日志信息。rsyslog采用模块化设计,是syslog的替代品。rsyslog具有如下特点:实现了基本的syslog协议。直接兼容syslogd的syslog.conf配置文件在同一台机器上支持多个rsyslogd进程丰富的过滤功能,可将消息过滤后再转发灵活的配置选项,配置文件中可…

    2022年9月25日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号