Hi, recently we got this crash report on Crashlytics:
Fatal Exception: java.lang.RuntimeException: Unable to start receiver com.onesignal.GcmBroadcastReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.package.name/com.onesignal.GcmIntentService (has extras) }: app is in background uid UidRecord{10dd267 u0a217 RCVR idle procs:1 seq(0,0,0)}
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3397)
at android.app.ActivityThread.-wrap18(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1780)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.package.name/com.onesignal.GcmIntentService (has extras) }: app is in background uid UidRecord{10dd267 u0a217 RCVR idle procs:1 seq(0,0,0)}
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1538)
at android.app.ContextImpl.startService(ContextImpl.java:1484)
at android.content.ContextWrapper.startService(ContextWrapper.java:663)
at android.content.ContextWrapper.startService(ContextWrapper.java:663)
at android.support.v4.content.WakefulBroadcastReceiver.startWakefulService(WakefulBroadcastReceiver.java:99)
at com.onesignal.GcmBroadcastReceiver.startGCMService(GcmBroadcastReceiver.java:158)
at com.onesignal.GcmBroadcastReceiver.processOrderBroadcast(GcmBroadcastReceiver.java:116)
at com.onesignal.GcmBroadcastReceiver.onReceive(GcmBroadcastReceiver.java:67)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3390)
at android.app.ActivityThread.-wrap18(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1780)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
The crash affects Android 8 (99%) and Samsung devices (62%).
This crash has affected more than 1% of all users in last 30 days. The crash to users ratio is less than 2, so I doubt that this crash is recurring, but the huge number of crashes is a concern.
I have searched for related issues and is seemingly fixed in Onesignal 3.6.5, but we use OneSignal 3.8.3 in affected versions of our apps. We dont extend your NotificationExtenderService , but we have our own class that extends FirebaseMessagingService, that mainly handles other pushes directly from our own backend. Is this a problem?
Please help us fix this, even a temp solution is ok.
@eriuzo Could you let us know the payload you sent that reproduced this issue? Or if it was through our dashboard let us know the full options there. The issue could be related to if you use high priority or not and if you have any remote URLs for images. We tested a number of combinations and haven't been able to reproduce this issue on an Android 8.1 device.
The GcmBroadcastReceiver class hasn't changed since our 3.6.2 release, other parts of the SDK were updated after for Android Oreo support but this one of the first updated with support.
Lastly could you let us know what you have set for targetSdkVersion in your app/build.gradle?
Hi, targetSdkVersion is 27
Here is dashboard parameters

According to the image, yes we use high prio and remote image url.
For combinations, here is device crash statistics

Let me know if you need more info
@eriuzo Thanks, this lowers the scope of what we need to test for. I believe I did test this scenario on Android 8.1 but we will double check this.
Have you been able to reproduce the issue yourself on your own devices?
I did try to reproduce, but havent been able to, because I thought any push will trigger this, so I make a quick text only push instead of high prio and remote url.
On the other hand, we do this push daily, but I have not had a crash yet (I have Oreo device and production build)
Hello there,
We have the same problem with our lastest version.
The only changes made that seems to make sense with the problem are:

@benbenmushi I believe the link is related. It notes that a high priority FCM / GCM message puts the app into a temporary whitelist for several minutes which should allow the service to start with a wake lock.
Can you provide the full stacktraces from your screenshot as well?
@jkasten2 Hi !
here is one of our typical notifications

I have noticed there is 2 similar errors which occurs on differents devices:
The first one:

The second one:

And 2 differents stacktraces:
UpgradeReceiver:

BootUpReceiver:

Note that we find the 2 stacktraces on both errors reports (the first one with mostly Samsung as well as the second one)
Also note that both stacktraces can occurs on the same device.
There is also another error repport (which is more rare). The 4 stacktrace reports are identicals

Hope it helps !
@benbenmushi Thanks for all the details on the 3 different crashes you are seeing. The first two with UpgradeReceiver and BootUpReceiver is something we can prevent by always using a JobService from these events. There are just replaying these Intents to put notifications back into the shade during these 2 events
However the last one is odd, as I noted before we do start a service on Android 8 instead of a job but only if it was high priority where the app will be whitelisted temporarily to allow this. We will look into this to see if there are any other restrictions where this could be prevented.
Hello Folks,
We faced the same issues recently on Android 8 (Oreo). Waiting for you guys to do something about that, i just changed the line:
appContext.startService(new Intent(appContext, SyncService.class));
to:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
appContext.startForegroundService(new Intent(appContext, SyncService.class));
} else {
appContext.startService(new Intent(appContext, SyncService.class));
}
Anyone taking care of it?
@suntehnik Sorry for the delay, this bug is still on our radar to fix. I'll provide more details soon
I am currently digging into this crash.
@suntehnik @medJemmoudi @eriuzo Are you still able to reproduce this crash on our latest 3.9.2.
@benbenmushi I checked some of your stacktraces and this is what I found
app/build.gradle? I recommend re-syncing gradle from Android Studio to make sure it gets the latest version if you have a version range.@eriuzo I added a catch for your specific stacktrace in the commit above. It will be included in the next release
hi @jkasten2 do you still need a repro using 3.9.2 or can we just wait for next release (im assuming 3.9.3) ?
@eriuzo We added a catch for the IllegalStateException which might only throw in some rare cases if the device is resending the broadcast. I think the issue is more related to the state of the device rather than a specific project / app setup. Thanks for the repo offer though.
Yes this exception handling will be included in the next SDK release sometime next week.
I麓m pretty sure this is due to the Background Execution Limits of Oreo: https://developer.android.com/about/versions/oreo/background#services
Version 3.9.3 has now been released which contains a fix for this.
What is the Unity SDK version that contains this fix?
hi, after deploying with 3.9.3 we are still experiencing same kind of crash, but with different stack trace:
Fatal Exception: java.lang.RuntimeException: Unable to start receiver com.onesignal.GcmBroadcastReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.product.name/com.onesignal.GcmIntentService (has extras) }: app is in background uid UidRecord{d210396 u0a102 RCVR idle change:uncached procs:1 seq(0,0,0)}
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3208)
at android.app.ActivityThread.-wrap17(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1684)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:172)
at android.app.ActivityThread.main(ActivityThread.java:6590)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.product.name/com.onesignal.GcmIntentService (has extras) }: app is in background uid UidRecord{d210396 u0a102 RCVR idle change:uncached procs:1 seq(0,0,0)}
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1521)
at android.app.ContextImpl.startService(ContextImpl.java:1477)
at android.content.ContextWrapper.startService(ContextWrapper.java:650)
at android.content.ContextWrapper.startService(ContextWrapper.java:650)
at android.support.v4.content.WakefulBroadcastReceiver.startWakefulService(WakefulBroadcastReceiver.java:99)
at com.onesignal.GcmBroadcastReceiver.startGCMServiceWithWakefulService(GcmBroadcastReceiver.java:178)
at com.onesignal.GcmBroadcastReceiver.startGCMService(GcmBroadcastReceiver.java:142)
at com.onesignal.GcmBroadcastReceiver.processOrderBroadcast(GcmBroadcastReceiver.java:119)
at com.onesignal.GcmBroadcastReceiver.onReceive(GcmBroadcastReceiver.java:70)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3201)
at android.app.ActivityThread.-wrap17(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1684)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:172)
at android.app.ActivityThread.main(ActivityThread.java:6590)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
relevant
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "io.realm:realm-gradle-plugin:5.1.0"
classpath 'com.google.gms:google-services:3.2.0'
}
minSdkVersion = 15
targetSdkVersion = 27
compileSdkVersion = 27
buildToolsVersion = '28.0.1'
supportLibraryVersion = '27.1.1'
looking at the stacktrace, i found this
https://github.com/OneSignal/OneSignal-Android-SDK/blob/3cc4c311d01a8cc003210f312d864c801355052d/OneSignalSDK/onesignal/src/main/java/com/onesignal/GcmBroadcastReceiver.java#L142
boolean isHighPriority = Integer.parseInt(bundle.getString("pri", "0")) > 9;
if (!isHighPriority && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
startGCMServiceWithJobScheduler(context, bundle);
else {
try {
startGCMServiceWithWakefulService(context, bundle);
} catch (IllegalStateException e) {
// If the high priority FCM message failed to add this app to the temporary whitelist
// https://github.com/OneSignal/OneSignal-Android-SDK/issues/498
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
startGCMServiceWithWakefulService(context, bundle);
else
throw e;
}
}
why startGCMServiceWithWakefulService(context, bundle); called twice (in try block and again in catch block) ?
@eriuzo Thanks for the catch, the catch block should be calling startGCMServiceWithJobScheduler as a fallback. We will get patched into the next release.
thanks, looking forward to next release
is this issue has solve?
@aderinto05 Yes, there was a 2nd update 3.10.0 after 3.9.3 that fully fixed this issue.
As of April 10, 2018, Google has deprecated GCM. The GCM server and client APIs are deprecated and will be removed as soon as April 11, 2019. Migrate GCM apps to Firebase Cloud Messaging (FCM), which inherits the reliable and scalable GCM infrastructure, plus many new features.https://developers.google.com/cloud-messaging/android/android-migrate-fcm