Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

ANR error "Broadcast of Intent { act=com.google.firebase.INSTANCE_ID_EVENT" ... "FirebaseInstanceIdInternalReceiver" for Android 7.1 and 8.0

We have an Android app that have many ANR errors reported lately. This only occurs on Android 7.1 and 8.0 (not on e.g. 4.4, 5.0 or 6.0). The ANR is:

Broadcast of Intent { act=com.google.firebase.INSTANCE_ID_EVENT flg=0x14 cmp=com.our.package.name/com.google.firebase.iid.FirebaseInstanceIdInternalReceiver (has extras) }

The question is: Why do we get this ANR, and what can we do to avoid this? Note that this works fine on earlier Android-versions, which in my opinion proves that we do not do any of the rookie-mistakes causing ANR.

I am having a really hard time reproducing this bug. Since it is only on Android 7.1 and 8.0 I think it may have to do with the new doze mode and battery saving, but even using adb shell dumpsys deviceidle force-idle etc. while testing does not reproduce this issue, neither does putting in SystemClock.sleep(20000); several places.

Our code for InstanceIdService is:

public class InstanceIdService extends FirebaseInstanceIdService {
    private Analytics mAnalytics;

    @Override
    public void onCreate() {
        super.onCreate();

        mAnalytics = new AnalyticsImpl();
        boolean isFullVersion = getApplicationContext().getPackageName().endsWith("full");
        mAnalytics.init(getApplicationContext(), isFullVersion);
    }

    @Override
    public void onTokenRefresh() {
        boolean initialLoginSucceeded = OurAppNameApplication.getInstance().getSettings().getInitialLoginSucceeded();
        mAnalytics.logEvent("FCM_Token_Refresh_Triggered", "initialLoginSucceeded", String.valueOf(initialLoginSucceeded));

        if (initialLoginSucceeded) { // We only report the FCM token to our server if the user has logged in at least once
            OurAppNameApplication.getInstance().getOurAppNameService().registerDeviceWithRetry();
        }
    }
}

We use Google Play Services and Firebase version 11.2.0. Our targetSdkVersion is 25.

PS: The code mAnalytics.init(...) above gives us a StrictMode warning, as this initializes Flurry. But this is disk access, not network traffic. And putting in SystemClock.sleep(20000); at this location does not trigger any ANR.

Why do we get an ANR, and what can we do to avoid this?

--

Edit: As per the suggestion in the comment from Bob Snyder, I have tried to test with adb shell cmd appops set com.our.package.name RUN_IN_BACKGROUND ignore. However, this does not produce any ANR, it only stops our Broadcast receiver from running, as shown in logcat:

09-21 10:39:25.314 943-6730/? W/ActivityManager: Background start not allowed: service Intent { act=com.google.firebase.INSTANCE_ID_EVENT pkg=com.our.package.name cmp=com.our.package.name/com.our.package.service.notifications.InstanceIdService (has extras) } to com.our.package.name/com.our.package.service.notifications.InstanceIdService from pid=4062 uid=10139 pkg=com.our.package.name
09-21 10:39:25.314 4062-4062/com.our.package.name E/FirebaseInstanceId: Error while delivering the message: ServiceIntent not found.

My conclusion is that this may not be a correct way to reproduce this ANR error.

For completeness sake: All ADB commands used when testing are:

adb shell dumpsys deviceidle force-idle
adb shell dumpsys battery unplug
adb shell am set-inactive com.our.package.name true
adb install -r our-app.apk
adb shell cmd appops set com.our.package.name RUN_IN_BACKGROUND ignore

(Actually - the last line is run many times in parallel with the adb install so that we are sure it takes effect before the installation and restore (of settings) is done and Firebase registration token is automatically refreshed after the installation.)

question from:https://stackoverflow.com/questions/46317504/anr-error-broadcast-of-intent-act-com-google-firebase-instance-id-event

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is a bug that was fixed in the September 18 release of the FCM SDK:

Fixed an issue that would occasionally cause apps to crash with Android Not Responding (ANR) errors when receiving a message.

Updating to com.google.firebase:firebase-messaging:17.3.2 or later should fix the issue. If it doesn't, please contact support.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...