Skip to content

Commit 5139ef3

Browse files
committed
fix: skip ShortcutBadger on API 26+ to prevent SIGSEGV on Xiaomi devices
On Android 8+ (API 26), notification channels handle app icon badges natively, making ShortcutBadger unnecessary. ShortcutBadger's DefaultBadger fallback causes native SIGSEGV crashes on certain Xiaomi devices (Redmi 10C, Redmi 9A) where MIUI's broadcast receiver has buggy native code that cannot be caught at the Java level. Fixes OneSignal/react-native-onesignal#1766 Made-with: Cursor
1 parent 58a786a commit 5139ef3

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

  • OneSignalSDK/onesignal/notifications/src/main/java/com/onesignal/notifications/internal/badges/impl

OneSignalSDK/onesignal/notifications/src/main/java/com/onesignal/notifications/internal/badges/impl/BadgeCountUpdater.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ internal class BadgeCountUpdater(
5050

5151
override fun update() {
5252
if (!areBadgesEnabled()) return
53+
// On API 26+ the system handles badges via NotificationChannel, and
54+
// ShortcutBadger can cause native SIGSEGV crashes on some OEM devices
55+
// (e.g. Xiaomi Redmi) where the broadcast receiver has buggy native code.
56+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) return
5357
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
5458
updateStandard()
5559
} else {
@@ -83,6 +87,7 @@ internal class BadgeCountUpdater(
8387

8488
override fun updateCount(count: Int) {
8589
if (!areBadgeSettingsEnabled()) return
90+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) return
8691
try {
8792
ShortcutBadger.applyCountOrThrow(_applicationService.appContext, count)
8893
} catch (e: ShortcutBadgeException) {

0 commit comments

Comments
 (0)