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)
上一篇 2022年6月23日 下午11:36
下一篇 2022年6月23日 下午11:46


相关推荐

  • 数据挖掘工程师-需要掌握的技术

    数据挖掘工程师-需要掌握的技术了解 LR GBDT XGBOOST DNN 和 NLP 等常用模型的开源工具 熟悉语言 SAS 统计分析软件 Python Scala 编程语言等 熟练掌握数据挖掘 机器学习 优化算法的基础理论和方法 了解 Embbeding 等方法理念 熟悉 Hadoop Hive Spark Yarn Kafka Flink 等常用大数据生态系统的使用 熟悉 Linux 熟悉 Shell 脚本 熟悉深度学习框架 如 Tensorflow Caffe Theano MXNet PyTorch 等 以上是 boss 直聘上面开

    2025年7月5日
    5
  • ubuntu更换国内源

    ubuntu更换国内源ubuntu16.04和18.04更换国内源写在前面:安装好ubuntu双系统后,默认的软件更新源是国外的,在国内使用速度很慢,用”aptinstallxxx”安装软件时可能出现”网络不可达”、”你的网络需要认证吗”、”无法定位软件包”等错误,所以我们需要更换成国内的源,这样才能正常安装和更新软件。一、ubuntu16.04更换国内源1.备份原始源文件source.list桌面…

    2022年6月4日
    103
  • Interp1 c++实现

    Interp1 c++实现在网上找了一下,有是有但是我下载下来用的时候结果不对。想修改一下但是搞得迷迷糊糊的,就干脆写了一个,不过只有最简单的线性插值的实现,新手可以直接拿过去用。也希望老鸟也可以不吝赐教,提高一下效率或者优化下结构。cpp文件//—————————————————————————#pragmahdrstop#include”Interpfun.h”//————————

    2022年5月2日
    42
  • Android中BindService和StartService「建议收藏」

    Android中BindService和StartService「建议收藏」一、首先,让我们确认下什么是service?       service就是android系统中的服务,它有这么几个特点:它无法与用户直接进行交互、它必须由用户或者其他程序显式的启动、它的优先级比较高,它比处于前台的应用优先级低,但是比后台的其他应用优先级高,这就决定了当系统因为缺少内存而销毁某些没被利用的资源时,它被销毁的概率很小哦。二、那么,什么时候,我们需要使用s

    2022年5月18日
    41
  • upstream模块详解

    upstream模块详解upstream 模块 upstream 模块 100 nginx 模块一般被分成三大类 handler filter 和 upstream 前面的章节中 读者已经了解了 handler filter 利用这两类模块 可以使 nginx 轻松完成任何单机工作 而本章介绍的 upstream 模块 将使 nginx 跨越单机的限制 完成网络数据的接收 处理和转发 数据转发功能 为 nginx 提供了跨越单机的横向处理能力 使

    2026年3月18日
    21
  • c语言实现简单的socket通信

    c语言实现简单的socket通信一 通讯示意图 nbsp 二 函数详解 1 socket 函数 intsocket intdomain inttype intprotocol socket 函数对应于普通文件的打开操作 普通文件的打开操作返回一个文件描述字 而 socket 用于创建一个 socket 描述符 socketdescri 它唯一标识一个 socket 这个 socket 描述字跟文件描

    2025年6月24日
    6

发表回复

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

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