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