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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • STM32——软件SPI控制AD7705[通俗易懂]

    一、AD7705简介AD7705为差分输入的16位ADC,拥有两组差分输入通道。自带可编程增益,增益可在1到128调节。支持SPI接口。AD7705功能框图如图所示:AD7705的主要寄存器有通信寄存器(CommunicationRegister)、时钟寄存器(ClockRegister)、建立寄存器(SetupRegister)和数据寄存器(DataRegister)。在这些寄存器中,只有数据寄存器是16位的。通信寄存器负责寄存器寻址、读写控制…

    2022年4月15日
  • 鸿蒙(HarmonyOS)支持低代码开发,无需HTML知识,就可以设计复杂界面

    鸿蒙(HarmonyOS)支持低代码开发,无需HTML知识,就可以设计复杂界面鸿蒙的最新IDE支持可视化开发。几乎不需要编写一行代码,就可以设计非常复杂的界面。当然,如果要实现业务逻辑,还是需要编写代码的。所以我们把这些功能称为低代码开发,也就是说,可以让我们少编写一些代码。

    2022年7月12日
  • VS2008序列号_苹果序列号过期什么意思

    VS2008序列号_苹果序列号过期什么意思转自:http://lanmaodream.blog.163.com/blog/static/212569007201291874945494/今天打开VS2008突然弹出图如下:为什么会出现上图这种情况呢?嘿嘿,咱使用的是试用版本哦!!!我的是Win7系统,其实各个系统都一样!不过在要输入序列号时,你会发现没有地方可以输入,这时你需要给VS2008打个补丁!!!打

    2022年8月10日
  • c语言中static关键字用法详解

    c语言中static关键字用法详解概述static关键字在c语言中比较常用,使用恰当能够大大提高程序的模块化特性,有利于扩展和维护。但是对于c语言初学者,static由于使用灵活,并不容易掌握。本文就static在c语言中的应用进行总结,供参考使用。错漏之处,请不吝指正。在程序中使用static变量1.局部变量普通局部变量是再熟悉不过的变量了,在任何一个函数内部定义的变量(不加static修饰…

    2022年4月30日
  • 初识SQL Server2017 图数据库(一)

    初识SQL Server2017 图数据库(一)

    2021年11月24日
  • ArcGIS server 10.2安装教程详细版

    ArcGIS server 10.2安装教程详细版详细讲述arcgisserver10.2的安装教程。默认已经安装arcgisDesktop10.2。提供一个arcgisserver下载地址:链接:https://pan.baidu.com/s/1iXol6v3RiqjU2MLvbnwNFA提取码:7fzf(失效了请和我说)一、所需文件1.ArcgisServer10.2安装文件。2.ArcgisSer…

    2022年5月25日

发表回复

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

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