2

Description

The WorkManager lib schedules and alarm to track if it was force stopped. This happens in the ForceStopRunnable class (see also: https://android.googlesource.com/platform/frameworks/support/+/a9ac247af2afd4115c3eb6d16c05bc92737d6305/work/workmanager/src/main/java/androidx/work/impl/utils/ForceStopRunnable.java) which will run during initialization of the WorkManager. On some Samsung devices this will trigger a SecurityException, and as far as I know Samsung throws this exceptions when your apps schedules more than 500 alarms. The app isn't full of alarms, so i think FLAG_UPDATE_CURRENT will keep an old instance in memory of the cancelled version. But I haven't been able to reproduce this, and I don't see multiple copies of the alarm scheduled either.

Happens only on SDK 28 and some rare cases on SDK 29

Question

Does anyone else here have the same experience working with the WorkManager Library and knows a way how to reproduce this issue?

Is there a work-around for this issue?

Crashlog

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$2.set (AlarmManagerService.java:2100) at android.app.IAlarmManager$Stub.onTransact (IAlarmManager.java:92) at android.os.Binder.execTransact (Binder.java:739)

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

Luciano
  • 2,691
  • 4
  • 38
  • 64
  • try scheduling > 500 jobs and you should be able to reproduce it. Looking at the source code, the file ExposureNotificationJob.kt schedules job without an ID and UPDATE/CANCEL flags. Do you really intend that? Could that be the one scheduling too many jobs? – Rahul Shukla Jan 28 '21 at 12:16

2 Answers2

1

This usually happens if the application is creating too many alarms. This is not an WorkManager issue.

Rahul
  • 19,744
  • 1
  • 25
  • 29
  • Thanks for the reply, I don't get any crashes from other alarms in the app. The only crashes I see are are coming from the ForceStopRunnable: see androidx.work.impl.utils.ForceStopRunnable.setAlarm (ForceStopRunnable.java:292) The ForceStopRunnable is is part of the WorkManager. How would you explain that? – Luciano Jan 20 '21 at 08:37
  • The alarm itself here is kind of irrelevant. This crash only occurs when you have > 500 alarms scheduled. It could be that `WorkManager` scheduled the 500th alarm. But that still means that the app scheduled the rest (which is the problem here). – Rahul Jan 25 '21 at 06:40
  • @Rahul this not answer the question, in our case, even though we use ExistingWorkPolicy.REPLACE, the issue still persists on Samsung. what's your recommendation on this? shall we use ExistingWorkPolicy.KEEP? – raditya gumay Mar 29 '21 at 02:51
  • Hi @Rahul, this is not related to this question. I have another question. https://stackoverflow.com/questions/74514057/how-to-fix-crash-illegalstateexception-the-file-system-on-the-device-is-in-a-ba I want to know when ForceStoppableRunnable class is used. The description at the top of the class is not very clear. Please help me understand. – Vikas Pandey Nov 25 '22 at 03:25
0

Updating WorkManager to version 2.6.0+ solved this issue. See following release notes: https://developer.android.com/jetpack/androidx/releases/work#2.6.0-alpha01

Luciano
  • 2,691
  • 4
  • 38
  • 64