Xiaomi Android 11 SecurityException Too many PendingIntent created
Asked Answered
C

1

8

Our application has been receiving this new kind of crash since the beginning of the year.

Firebase shows it repeats only on Xiaomi with Android 11. It repeats in different parts of the application. And it seems unrelated to the application code. So I assume it is related to Xiaomi Android 11 update with broken code or new restrictions without clear explanation.

The obvious idea is pending intent creation spam, but I can't find any evidence that this method is frequently called, only several times.

Did anyone come out with a hack for that? Suppressing throwable is not a good option since the functionality won't work.

Code snippet:

val intent = Intent(context, SomeClass::class.java).apply {
    this.action = action
    this.putExtra(EXTRA_IDENTITY, identity)
}
PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)

Stacktrace:

Fatal Exception: java.lang.SecurityException: Too many PendingIntent created for uid 10273, aborting Key{broadcastIntent pkg=<package> intent=act=<action name> cmp=<class> flags=0x0 u=0} requestCode=0
   at android.os.Parcel.createExceptionOrNull(Parcel.java:2376)
   at android.os.Parcel.createException(Parcel.java:2360)
   at android.os.Parcel.readException(Parcel.java:2343)
   at android.os.Parcel.readException(Parcel.java:2285)
   at android.app.IActivityManager$Stub$Proxy.getIntentSenderWithFeature(IActivityManager.java:6898)
   at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:578)
   at android.app.PendingIntent.getBroadcast(PendingIntent.java:561)
   ...
Cyrano answered 25/2, 2022 at 13:49 Comment(3)
The question might not be the amount of PendingIntent, but the amount of Broadcast received.Oatcake
@IvanShafran were you able to fix this? Are you using firebase in your app?Microvolt
@IshitaGarg Unfortunately, not. We just wrapped it with try catch and handled negative scenario of creating PendingIntentCyrano
C
1

I'll answer the question since I haven't received any answer from SO, and our application has been getting this crash in different parts of the code without any noticeable connections.

So, you find this problem with such symptoms:

  • crash occurs only on Xiami with 11 Android
  • same stack trace as posted in the question

I would say it is caused by a bug or "restriction feature" on Xiaomi 11 update.

As a result, the best you can do is to wrap it with a try-catch.

P.s. if your crash looks different, you probably need to check other answers. Try catch is good, but ideally, you would like to fix the reason behind it.

Cyrano answered 22/10, 2023 at 17:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.