動態註冊broadcast的安全考慮

1、android service通知activity更新
方式有
1. service 經過廣播的形式發送broadcast,向這個activity的內部類發廣播的消息來更新界面
2. service直接向activity發intent,把activity的launchMode設置爲singleInstancehtml

2、安全性
這邊關注第1種方式的廣播和接收intent安全,若是不對廣播的發送和接收進行判斷,會有很大的安全隱患
在個人場景中,是動態註冊broadcast,考慮安全以下:android

A、針對sendBroadcast
1.一般採用的安全方式有setPackage設置包名
intent.setAction("com.example.tianqitong.recv");
intent.setPackage("com.example.tianqitong");
sendBroadcast(intent);安全

2.能夠經過使用LocalBroadcastManager,確保了應用程序外部的任何組件都收不到你廣播的Intent.net

3.設置權限
sendBroadcast(intent,"broadcast.permission");htm

還要加上android:protectionLevel權限級別blog

<uses-permission android:name="broadcast.permission" /> //聲明使用權限
<permission android:name="broadcast.permission" android:protectionLevel="signature" /> //自定義權限接口

B、針對Receive
1.能夠經過使用LocalBroadcastManager,使其餘應用程序也不能向你的接收器發送廣播ip

2.對於動態註冊的廣播能夠經過相似registerReceiver(BroadcastReceiver, IntentFilter, String, android.os.Handler)的接口指定發送者必須具有的permission
其中string爲指定的permission,必須加android:protectionLevel
譬如:
<permission android:name="broadcast.permission" android:protectionLevel="signature" />string


參考:
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.htmit

相關文章
相關標籤/搜索