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


相关推荐

  • 微信小程序实现下载功能(以下载视频为例)「建议收藏」

    微信小程序实现下载功能(以下载视频为例)「建议收藏」一、wx.downloadFile()方法:访问视频对应的Url,回调函数返回一个该视频文件的临时路径。wx.downloadFile({url:app.serverUrl+me.data.videoInfo.videoPath,success:function(res){//只要服务器有响应数据,就会把响应内容写入文件并进入success回调,业务需要自行判断是否下载到了想要的内容

    2022年6月22日
    311
  • Effective JavaScript Item 51 在类数组对象上重用数组方法「建议收藏」

    Effective JavaScript Item 51 在类数组对象上重用数组方法

    2022年2月5日
    48
  • centos创建samba共享_docker共享目录

    centos创建samba共享_docker共享目录内容大纲:samba简介centos上部署samba服务samba服务的配置详解samba服务的共享资源部署samba服务的共享资源权限设置samba服务共享帐号映射一、介绍Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成。SMB(ServerMessagesBlock,信息服务块)是一种在局域网上共…

    2022年9月24日
    0
  • 蓝桥杯历年真题及详细解答

    蓝桥杯历年真题及详细解答这里是蓝桥杯历年的题目汇总,后面将会陆续更新将往年真题以及解答发布出来,目前先更新C语言B组的,欢迎各位小伙伴关注我吖,你们的关注就是给我最好的动力!!!蓝桥杯历年省赛真题Java语言A组省赛真题Java语言B组省赛真题C语言A组省赛真题C语言B组省赛真题Java语言A组省赛真题2012第三届JavaA组蓝桥杯省赛真题2013第四届JavaA组蓝桥杯省赛真题2014第五届JavaA组蓝桥杯省赛真题2015第六届JavaA组蓝桥杯省赛真题2016第七届JavaA组蓝.

    2022年7月16日
    13
  • Godot 2D 和 3D 游戏引擎[通俗易懂]

    Godot 2D 和 3D 游戏引擎[通俗易懂]Godot是一个全新开发的游戏引擎,其功能集类似知名的跨平台游戏引擎Unity,可用于开发PC、主机、移动和Web游戏。开发者引擎的2D和动画支持要强于Unity,表示在功能和特性上没有其它开源游戏引擎能相媲美。Godot引擎内置了类似Unity的编辑器,GUI工具包,2D/3D物理支持,支持OpenGLES2.0功能集的3D渲染器,易于学习的语言和API,支持用ASM.js或GoogleNativeClient输出HTML5代码,支持Linux、Windows和OSX开发平台…

    2022年5月25日
    33
  • java连接MySQL数据库的驱动jar包

    java连接MySQL数据库的驱动jar包mysql官网:https://dev.mysql.com/步骤1步骤2步骤3步骤4或者直接点击这个链接直接到这个页面https://dev.mysql.com/downloads/connector/j/在这个页面再点击弹出的下拉列表这个点击PlatformIndependent然后点击第二个下载在出现的页面点击Nothanks,juststartmydownload即可下载不用登陆我们只下载就行然后将下载的压缩文件导入idea中即可了!手动截图不易点

    2022年5月21日
    35

发表回复

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

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