GetStream / stream-video-android

📲 Android Video SDK. Stream's versatile Core + Compose UI component libraries that allow you to build video calling, audio room, and, live streaming apps based on Webrtc running on Stream's global edge network.
https://getstream.io/video/docs/android
Other
381 stars 39 forks source link

ForegroundServiceStartNotAllowedException: Sometimes incoming call notification is not shown #1213

Open Miara opened 2 weeks ago

Miara commented 2 weeks ago

Business context Before going to the production with GetStream SDK, I need to have some business proof that calls change will be beneficial for users. We have 2 major issues with old implementation. One with Samsung Fold (already reported here ) and this issue with foreground service notification.

Describe the bug Sometimes, when the application is in the background, incoming call is not shown.

It's hard to recreate these restrictions set in natural way, because even when battery optimization is enabled for the specific app, it doesn't mean that it always will throw Exception when trying to start foreground service from the background. You would have to use other apps, and then android system see that you need system resources for other apps, and put your app into deep sleep.

When there is no optimization enabled at all - this bug also appears, but very rarely and it's very hard to reproduce, however on production with many users it appears hundreds times per week.

However don't worry, I have some hacks below 😄

SDK version

To Reproduce Steps to reproduce the behavior:

  1. Log In to some test user Thierry in demo-app on deviceA, and go into the background
  2. Set background restrictions on deviceA using adb:
    adb shell device_config put activity_manager \
    default_fgs_starts_restriction_notification_enabled true
  3. Go to the background on deviceA
  4. It looks like you don't catch exception in your SDK, because i don't see any error in logcat, so you can think about adding it, and meanwhile you can observe the error using:
    adb logcat -T 1 | grep ActivityManager

    In logcat

  5. Log In to some test user Alex in demo-app on deviceB and call Thierry
  6. There is no incoming push notification on deviceA

Expected behavior Incoming push notification should appear on deviceA

Suggestion regarding solution You could detect whether starting foreground service for incoming call crashes, and then you can use normal push notification (without foreground service), and after clicking on notification and opening the app, you could ensure that foreground service is started - if it wasn't started already.

Device:

aleksandar-apostolov commented 1 week ago

Hi @Miara

Thanks for letting us know. We will look into your suggestion about improving the notification handling. On the other hand we are working on integrating the telecom framework which will handle this part with the service / notification.

Regards, Alex