动态注册broadcast的安全考虑

一、android service通知activity更新
方式有
1. service 通过广播的形式发送broadcast,向这个activity的内部类发广播的消息来更新界面
2. service直接向activity发intent,把activity的launchMode设置为singleInstance

二、安全性
这边关注第1种方式的广播和接收intent安全,如果不对广播的发送和接收进行判断,会有很大的安全隐患
在我的场景中,是动态注册broadcast,考虑安全如下:

A、针对sendBroadcast
1.通常采用的安全方式有setPackage设置包名
intent.setAction("com.example.tianqitong.recv");
intent.setPackage("com.example.tianqitong");
sendBroadcast(intent);

2.可以通过使用LocalBroadcastManager,确保了应用程序外部的任何组件都收不到你广播的Intent

3.设置权限
sendBroadcast(intent,"broadcast.permission");

还要加上android:protectionLevel权限级别

<uses-permission android:name="broadcast.permission" /> //声明使用权限
<permission android:name="broadcast.permission" android:protectionLevel="signature" /> //自定义权限

B、针对Receive
1.可以通过使用LocalBroadcastManager,使其他应用程序也不能向你的接收器发送广播

2.对于动态注册的广播可以通过类似registerReceiver(BroadcastReceiver, IntentFilter, String, android.os.Handler)的接口指定发送者必须具备的permission
其中string为指定的permission,必须加android:protectionLevel
譬如:
<permission android:name="broadcast.permission" android:protectionLevel="signature" />


参考:
http://blog.csdn.net/t12x3456/article/details/9256609
http://blog.csdn.net/hotdogzu/article/details/7940820
http://blog.csdn.net/abc13939746593/article/details/8186916
http://my.eoe.cn/weiblog/archive/4590.html
http://www.sectop.com/?p=187
https://developer.android.com/training/articles/security-tips.html
https://developer.android.com/reference/android/content/BroadcastReceiver.html#Security
http://book.51cto.com/art/201304/389200.htm

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值