fix: Remove throwing "initWithContext was not called or timed out", introduced in 5.4.0 #2412
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
Revert throwing if things wait on init take too long that was introduced in 5.4.0.
Details
Starting in 5.4.0 calls such as OneSignal.Notification or OneSignal.Location would throw if they waited on the SDK into to long. This PR changes this to wait forever until init is complete, and log instead if the time is taking longer than expected. If these calls were done from the main thread an ANR is the lesser of two evils and the app can recover, where an uncaught throw it can not.
This commit will bring the behavior similar to 5.1.x. The only difference is you will now never see an ANR with initWithContext, however if you call other parts of the SDK from the main thread, such as OneSignal.Notification, you will continue to see ANRs, just at a different stacktrace. To avoid these ANRs completely call all other SDK methods outside of the main thread.
Related Issues
Motivation
A behavior change wasn't intended in a non-major release.
Scope
Removes throwing and timeout state when things are waiting on SDK initialization.
Testing
Unit testing
Updated existing unit tests to expect waiting without a timeout.
Manual testing
Tested on an Android 14 emulator. Added an artificial 10 second delay with
Thread.Sleepjust beforelatch.countDown()to ensure the SDK still initializes correctly.Affected code checklist
Checklist
Overview
Testing
Final pass
This change is