创建隐式 Intent 时,Android 系统通过将 Intent 的内容与在设备上其他应用的清单文件中声明的 Intent 过滤器进行比较,从而找到要启动的相应组件。如果 Intent 与 Intent 过滤器匹配,则系统将启动该组件,并将其传递给对象。如果多个 Intent 过滤器兼容,则系统会显示一个对话框,支持用户选取要使用的应用。
为了确保应用的安全性,启动 Service 时,请始终使用显式 Intent,且不要为服务声明 Intent 过滤器。使用隐式 Intent 启动服务存在安全隐患,因为您无法确定哪些服务将响应 Intent,且用户无法看到哪些服务已启动。从 Android 5.0(API 级别 21)开始,如果使用隐式 Intent 调用 bindService(),系统会抛出异常。
提醒
全部。从 Android 5.0(API 级别 21)开始,如果使用隐式 Intent 调用 bindService(),系统会抛出异常。
检测类型;静态分析
首先检测exported属性,再检测permission及其对应的protectionLevel属性,最后检测组件是否有设置intent-filter设置过滤action
Service组件 |
exported=”true” |
设置了android:permission |
protectionLevel=”signature”或”signatureOrSystem” |
pass |
|
protectionLevel=”normal”或”dangerous” |
intent-filter有action |
中危 |
|||
intent-filter无action |
pass |
||||
未设置android:permission |
|
intent-filter有action |
中危 |
||
intent-filter无action |
pass |
||||
exported=”false” |
pass |
||||
exported未设置 |
设置了android:permission |
protectionLevel=”signature”或”signatureOrSystem” |
pass |
||
protectionLevel=”normal”或”dangerous” |
intent-filter有action |
中危 |
|||
intent-filter无action |
pass |
||||
未设置android:permission |
|
intent-filter有action |
中危 |
||
intent-filter无action |
pass |
为了确保应用的安全性,启动 Service 时,请始终使用显式 Intent,且不要为服务声明 Intent 过滤器。使用隐式 Intent 启动服务存在安全隐患,因为您无法确定哪些服务将响应 Intent,且用户无法看到哪些服务已启动。从 Android 5.0(API 级别 21)开始,如果使用隐式 Intent 调用 bindService(),系统会抛出异常。
https://developer.android.com/guide/components/intents-filters.html#Types