为什么 android:exported 在用于接收 Firebase 推送通知的服务中为 false?

Why android:exported is false in the Service used to receive Firebase push notification?

基于https://developer.android.com/guide/topics/manifest/service-element

关于android:exported

的意思

Whether or not components of other applications can invoke the service or interact with it — "true" if they can, and "false" if not. When the value is "false", only components of the same application or applications with the same user ID can start the service or bind to it.

当我看代码的时候https://firebase.google.com/docs/cloud-messaging/android/client

<service
    android:name=".java.MyFirebaseMessagingService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

我以为当我们收到推送通知时,是外部Android系统(被视为“其他应用程序”)调用了我们的应用程序代码。如果是这样,为什么 android:exported 在上述情况下为假?

如果是调用我们应用代码的外部应用不应该是这样吗?

谢谢。

确切地说:afaik Google Play 服务应用程序正在分发推送(“其他应用程序”)。所以是的,如果它是接收器,这个 Service 应该是 exported。但是您确定这个 developer-side 声明的 Service 是直接从某个外部 source/app 获取推送数据吗?我敢打赌,推送消息的“真正接收者”是在 Firebase 库内部声明的,是 exported 并且做了一些艰苦的工作来防止注入 + 读取一些额外的元数据等。最后它将推送数据发送到 developer-declared Service,它在相同的 process/app 中工作,因此这可能不是 exported(出于安全目的甚至可能不应该)

只是猜测,但看起来 Google-style 也是合理的方法。无权访问资源 ;) 可以查看 Android Studio 中的合并清单,它将显示所有声明的活动、服务、广播、权限等 - 您的条目和所有导入的库的总和(好吧,“合并")

如果你去查看 firebase-message 的 Android 清单,你会发现 FirebaseInstanceIdReceiver 是用于接收消息的实际 Service

另请查看此 PR https://github.com/firebase/quickstart-android/pull/850

Set FirebaseMessagingServices to exported="false" to explicitly prevent other apps from being able to send messages to it.