-
Notifications
You must be signed in to change notification settings - Fork 376
Description
Description:
In version 4.4.1 and above, when OneSignal receives a push notification, an exception that occurs within OneSignal SDK to crashes the app.
We have updated the SDK from 4.4.0 to 4.6.0 and released the app. Since then, we've been receiving a lot of crash reports.
After investigating the cause, it was found that it was due to the changes of #1356. And SDK containing it was released in version 4.4.1.
What's wrong with #1356?
TLDR;
After 4.4.1, The thread being OneSignal notification process is not catching the exception properly.
In #1356, implementation of OSNotificationWorkerManager.NotificationWorker
changed Worker
to ListenableWorker
.
Worker
's doWork()
runs on worker-thread, while ListenableWorker
's startWork()
runs on main-thread.
That difference causes a change in the subsequent processing. (probably not intended)
Both processes call processNotificationData()
, and then reaches OSNotificationReceivedEvent.complete()
. OSNotificationReceivedEvent.complete()
is the part that causes this issue.
Here exist code that if call on main-thread, execute process on other thread. code
Below 4.4.1, this if statement is false
. So, continue processing on current-thread (= worker-thread).
After 4.4.1, this statement is true
, run in other thread made on instant.
If the method OSNotificationReceivedEvent.processNotification()
is execute on worker-thread, the exception thrown here will be caught byWorker.startWorker()
. However, if the method is execute on instant thread, the exception will not be caught. App crashes when actual exception thrown.
Do you really throw some exception in this method? to anwer YES.
Many of the exceptions are caused by Android NotificationManager API and device platform bugs.
For example, on some devices such as Samsung, LG, the system notification service was killed (reason don't know why), NotificationManager throw DeadSystemException.
Environment
Device OS : Android 7.0, 7.1.1, 8.0, 8.1 (at least)
OneSignal SDK : 4.4.1+
Steps to Reproduce Issue:
Confirm that execution-thread has changed around 4.4.1 before-after.
- Enabled Debug
- mark breakpoint
OSNotificationReceivedEvent.complete()#L71~
- monitor
Looper.getMainLooper().isCurrentThread()
- send OneSignal push notification (ex. OneSignal dashboard)
- below 4.4.1 monitoring value is
false
, above 4.4.1 istrue
Below 4.4.1 | After 4.4.1 |
---|---|
![]() |
![]() |
It is difficult to raise an exception, but you can see the app behavior by throw exception using the debugger during this process.
Anything else:
A simple fix is to try-catch exception into the Runnable at OSNotificationReceivedEvent.complete()#L81-88
.