WorkManager 在某些三星设备上抛出 SecurityException

WorkManager throws SecurityException on some Samsung devices

描述

WorkManager 库计划和警报以跟踪它是否被强制停止。这发生在 ForceStopRunnable class(另请参阅:https://android.googlesource.com/platform/frameworks/support/+/a9ac247af2afd4115c3eb6d16c05bc92737d6305/work/workmanager/src/main/java/androidx/work/impl/utils/ForceStopRunnable.java)中,它将在 WorkManager 初始化期间 运行。在某些三星设备上,这会触发 SecurityException,据我所知,当您的应用程序安排超过 500 个警报时,三星会抛出此异常。该应用程序并没有充满警报,所以我认为 FLAG_UPDATE_CURRENT 会在已取消版本的内存中保留一个旧实例。但我无法重现这一点,而且我也没有看到安排的警报的多个副本。

仅在 SDK 28 上出现,在 SDK 29 上出现一些罕见情况

问题

这里是否还有其他人有使用 WorkManager 库的相同经验并且知道如何重现此问题?

是否有解决此问题的方法?

崩溃日志

java.lang.SecurityException: at android.os.Parcel.createException (Parcel.java:1966) at android.os.Parcel.readException (Parcel.java:1934) at android.os.Parcel.readException (Parcel.java:1884) at android.app.IAlarmManager$Stub$Proxy.set (IAlarmManager.java:240) at android.app.AlarmManager.setImpl (AlarmManager.java:722) at android.app.AlarmManager.setExact (AlarmManager.java:571) at androidx.work.impl.utils.ForceStopRunnable.setAlarm (ForceStopRunnable.java:292) at androidx.work.impl.utils.ForceStopRunnable.isForceStopped (ForceStopRunnable.java:151) at androidx.work.impl.utils.ForceStopRunnable.forceStopRunnable (ForceStopRunnable.java:169) at androidx.work.impl.utils.ForceStopRunnable.run (ForceStopRunnable.java:101) at androidx.work.impl.utils.SerialExecutor$Task.run (SerialExecutor.java:91) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641) at java.lang.Thread.run (Thread.java:764) Caused by: android.os.RemoteException: at com.android.server.SamsungAlarmManagerService.checkMaliciousAppLocked (SamsungAlarmManagerService.java:333) at com.android.server.AlarmManagerService.setImpl (AlarmManagerService.java:1758) at com.android.server.AlarmManagerService.set (AlarmManagerService.java:2100) at android.app.IAlarmManager$Stub.onTransact (IAlarmManager.java:92) at android.os.Binder.execTransact (Binder.java:739)

来源: https://github.com/minvws/nl-covid19-notification-app-android

如果应用程序创建了太多警报,通常会发生这种情况。这不是 WorkManager 问题。

将 WorkManager 更新到版本 2.6.0+ 解决了这个问题。请参阅以下发行说明:https://developer.android.com/jetpack/androidx/releases/work#2.6.0-alpha01