Fix a crash when application put to background restriction by re…#1731
Conversation
…ndering normal notification instead of CallStyle notification
PR checklist ✅All required conditions are satisfied:
🎉 Great job! This PR is ready for review. |
WalkthroughA new internal ChangesBackground restriction detection and notification gating
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/BackgroundRestrictions.kt`:
- Around line 25-32: The isRestricted() function calls getSystemService() which
can return null, but the returned ActivityManager object is used directly
without null-checking. Add null-safe handling by using the safe-call operator
when accessing the isBackgroundRestricted property on the ActivityManager
instance. When the ActivityManager is null, the expression should default to
false to maintain the current behavior for API levels below P.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 981c5233-e99c-4900-bff1-2fad243b86bb
📒 Files selected for processing (2)
stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/BackgroundRestrictions.ktstream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/handlers/StreamDefaultNotificationHandler.kt
SDK Size Comparison 📏
|
…l-disabled-regression' into bugfix/rahullohra/battery-restrictions
|


Goal
Closes #AND-1251
Stacked on top of PR: #1729
This change improves notification handling when the application is subject to background restrictions.
CallStylenotifications may fail to be posted as foreground service notifications on restricted devices, resulting in aCannotPostForegroundServiceNotificationException("Bad notification for startForeground").See GH Issue: Demo app always crashes with restricted battery settings
Implementation
To avoid this issue, the SDK now detects when the application is background-restricted and falls back to a standard notification instead of using CallStyle.
Changes
🎨 UI Changes
None
Testing
Additional Notes
Summary by CodeRabbit