Oreo notification feature: A critical issue that could restart your Android phone.

Ali Asadi
ProAndroidDev
Published in
4 min readOct 30, 2018

--

With the release of Android Oreo, Google has focused on providing users with a comprehensive set of customization options, and they’ve taken it a step further with two new features: notification channels and notification dots.

We released a new version with Oreo features, but we received a lot of negative feedback and reviews on the Playstore after only a few days. The app, according to users, caused their phones to restart.

At first glance, having this issue in production appears illogical, given that we have 100,000+ monthly active users (and we received no warning from Crashlytics about any issues with the new version). As a result of the Playstore reviews, we made it a top priority to look into that case. We gathered the necessary information in order to reproduce the issue and figure out what happened to these users, and it turns out that this is indeed the case: the phone restarts after certain actions. We were able to reproduce the issue on a Nexus 5X running Oreo version API 26.

Error tracking

We did not receive any warnings from Crashlytics because the device went into restart mode immediately after the crash.

The goal was to show the user the notification without sound or vibrations.

Let’s look at the code. We used to do it this way before the Oreo version:

You’ll be forced to change that code after updating your targetSdkVersion to 26+.

Let’s move on to the Oreo version. As previously stated, Google has announced a new feature that gives you complete control over notification settings. (Android Oreo will make you love notifications again)

We did it this way to support the Oreo feature:

This code causes the phone to restart; further investigation revealed that line 8 causes the phone to crash and restart; it will throw a DeadSystemException after calling the createNotification() method.

The Android Developer docs for DeadSystemException says the following:

The core Android system has died and is going through a runtime restart. All running apps will be promptly killed.

After a deeper look, I have noticed that there is another exception being thrown before DeadSystemException, an ArrayOutOfBoundsException. It comes from the NotificationManager class. When tracking the reason of the exception It turned out that setVibrationPattern() the main factor for all these exceptions.

channel.setVibrationPattern(new long[0]);

The Android Developer docs for setVibrationPattern says the following:

setVibrationPattern method description

And this is what the method does:

After filling out the vibration pattern with the array, there is a function inside the NotificationChannel called toJson. That tries to convert the local members into a JSON object.

toJson method

By invoking the createNotificationChannel(channel) method it also calls the toJson method which is converting the vibration array into a string in order to save it into a JSON object (line 684), in order to convert the array into a string we use a static method called longArrayToString, to be able to use the method we should pass an array as an argument and it will return a string as a result.

This is what longArrayToString method actually does.

If you look carefully into the method, you can identify that the method can leads for ArrayOutOfBoundException if we are sending an array with a zero size at line 7, when this happens the system throws DeadSystemException and restart the phone.

How to prevent the issue?

To prevent the issue simply don’t use the setVibrationPattern() if you still wanna use it, you can by sending a null.

The bug occurs in:
LG Nexus 5X - only on a real device on the emulator it's not happening.
Motorola Moto Z2
LG G7 (LM-G710)
LG V30 (H932)
LG G6 (H870)

All the devices using Android 8.0.0.

~Happy Coding.

--

--