Fix for WorkManager not Initialized Crash #2052
Merged
Conversation
* Before using WorkManager, check for its existence. Else, in rare cases that caused crashing, initialize it ourselves. * Additionally, as another layer to handling this issue, when initializing WorkManager ourselves, surround it in a try-catch as it is may be the slightest bit possible for another thread to initialize it in the interim between checking and initializing. * Provides a method to check if WorkManager is initialized in this process. - This is effectively the `WorkManager.isInitialized()` public method introduced in `androidx.work:work-*:2.8.0-alpha02`. - Please see https://android-review.googlesource.com/c/platform/frameworks/support/+/1941186 for the library's implementation
jkasten2
requested changes
Apr 12, 2024
...tifications/src/main/java/com/onesignal/notifications/internal/common/OSWorkManagerHelper.kt
Outdated
Show resolved
Hide resolved
jkasten2
approved these changes
Apr 12, 2024
...tifications/src/main/java/com/onesignal/notifications/internal/common/OSWorkManagerHelper.kt
Outdated
Show resolved
Hide resolved
d2c0d51 to
329fb23
Compare
jkasten2
approved these changes
Apr 12, 2024
Merged
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
This is a fix for the non-reproducible WorkManager is not Initialized Crash we did in
v4already, with one small change in a try-catch.Details
Motivation
Based on the the fix we made for
v4at #1721The change I added was an additional try-catch after this comment from an SDK user after we made the
v4fix. They ran into the "WorkManager is already initialized" exception.At the time that PR was made, the fixes were speculative and we didn't completely understand this crash. By now, and seeing other reports from SDK authors at our submitted Google Issue Tracker, I believe it is a bug in the library.
Scope
WorkManager.isInitialized()public method introduced inandroidx.work:work-*:2.8.0-alpha02.v4of the SDKTesting
Unit testing
No unit testing
Manual testing
Limited ability to test manually due to unable to reproduce
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is