android:exported="false" 在声明了意图过滤器的广播接收器中

use*_*887 1 android broadcastreceiver android-broadcast android-broadcastreceiver

我想声明一个广播接收器,它可以监听系统广播,例如PACKAGE_ADDED,,,PACKAGE_REPLACED例如

 <receiver
    android:name="com.sample.cli.xyz.XyzReceiver"
    android:exported="true"
    android:enabled="false">
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_ADDED"/>
        <action android:name="android.intent.action.PACKAGE_REPLACED"/>
        <action android:name="android.intent.action.PACKAGE_REMOVED"/>
    </intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)

如果我保留exported="true"在这里,任何应用程序都可以发送广播,这可能是一个安全问题。根据 Android 文档,如果我们在接收器标记中甚至有 1 个意图过滤器,那么导出的默认值将被视为“true”。

我的问题是,如果我明确将此属性声明为“false”( android:exported="false") 以及意图过滤器,是否会使其更安全并使其只能由系统而不是其他应用程序访问?

use*_*887 5

在示例应用程序中尝试了有问题的组合(导出=“假”以及接收器中声明的意图过滤器),发现接收器仍然可以侦听系统事件,例如 PACKAGE_ADDED、PACKAGE_REMOVED 等。