firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.23k stars 565 forks source link

onMessageReceived wasn't called with secondary process #3676

Closed wangjianpeng closed 2 years ago

wangjianpeng commented 2 years ago

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

I found many ANR that related with "Reason: Broadcast of Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.redtech.hivisualer cmp=com.redtech.hivisualer/com.google.firebase.iid.FirebaseInstanceIdReceiver (has extras) }" . someone said if set FCM Service to seondary process in the manifest , this ANR will be reduced ,So I try this method ,but onMessageReceived was never called when I push msg to my android device, notification icon was not shown on my phone too.

Relevant Code:

 @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        // TODO(developer): Handle FCM messages here.
        // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
        Log.d(TAG, "From: " + remoteMessage.getFrom());

        // Check if message contains a data payload.
        if (remoteMessage.getData().size() > 0) {
            Log.d(TAG, "Message data payload: " + remoteMessage.getData());
        }

        // Check if message contains a notification payload.
        if (remoteMessage.getNotification() != null) {
            Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
        }
    }
<service
    android:name=".HiVisualerFCMService"
    android:exported="false"
    android:process=":light"
    tools:node="replace">

    <intent-filter android:priority="-500">
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

<receiver
    android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
    android:exported="true"
    android:permission="com.google.android.c2dm.permission.SEND"
    android:process=":light"
    tools:node="replace">

    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    </intent-filter>
</receiver>
google-oss-bot commented 2 years ago

I found a few problems with this issue:

argzdev commented 2 years ago

Hi @wangjianpeng, I tried using the code snippet you've provided in our Firebase quickstarts. Here's the results:

  1. Scenario A:
    • Add android:priority=-500 on intent filters
      • Result: Still receiving notifications, onMessageReceived is called.
  2. Scenario B:
    • Add android:priority=-500 on intent filters
    • Add com.google.firebase.iid.FirebaseInstanceIdReceiver as receiver
      • Result: No notifications are received.

Unfortunately, I'm unable to reproduce the same behavior that you're experiencing. Could you provide a minimal repro of this issue? Thanks.

May I also ask why are you adding com.google.firebase.iid.FirebaseInstanceIdReceiver as receiver?

wangjianpeng commented 2 years ago

@argzdev thank you for your reply. and you should add android:process=":light" to the manifest for secondary process with FCM. because I want to reduce the following ANR: Reason: Broadcast of Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.redtech.hivisualer cmp=com.redtech.hivisualer/com.google.firebase.iid.FirebaseInstanceIdReceiver (has extras) }

I have google too many and find the solution from this blog reduce ANR,but when I modify my manifest with android:process ,onMessageReceived was not called, FCM didn't work as before. my project was attached in the below: hivisualer.zip

argzdev commented 2 years ago

Hello @wangjianpeng, thanks for the minimal repro. From what I've tested, I'm still experiencing the same issue (I'm not able to receive any notifications) with your app.

I understand that you're trying to lessen the ANRs in your app, however this type of experimental configuration is not officially documented, hence is not supported.

As to quote from the blog:

There are no official guides or documentation on how to do this and potentially it can be broken at any point in the future.

Unfortunately, there's not much I can do since I don't think the current versions of FCM supports this type of setup. That being said, I'll be closing this now.

gsakakihara commented 2 years ago

As mentioned, this is not officially supported, but I will note that your app-specific FirebaseMessagingService (HiVisualerFCMService) should probably be using the default priority (nothing specifically set in the manifest) instead of being set at -500 priority.