Wait for activity to be set rather than immediately return in waitUntilSystemConditionsAvailable #1926
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
Wait for activity to be set rather than immediately return in waitUntilSystemConditionsAvailable
Details
IApplicationService.waitUntilSystemConditionsAvailable
is used by theInAppMessagesManager
when attempting to display an IAM, to ensure the IAM can be displayed based on system conditions. If triggering of an IAM occurs during the foreground process, it's possible for evaluation to happen prior to the activity being started. And when this happens, the IAM will not be displayed.An example of code that can drive this behavior pretty frequently is below, the key is to add a trigger (which drives IAM evaluation/display) early in the foregrounding process:
This updates
waitUntilSystemConditionsAvailable
to wait up to 5 seconds for an activity to be set before determining the system conditions will never be available. This gives any other threads (such as the main thread) to appropriately start the activity. Note that ifwaitUntilSystemConditionsAvailable
is called on the main thread, we do not wait the 5 seconds for the activity to become set, as it cannot happen givenonActivityStarted
is called on the main thread.Motivation
Reliability to show IAMs in all scenarios
Scope
This functionality is limited to whether to an IAM can be displayed to the user, based on the current application state.
Testing
Unit testing
2 additional tests were added against
waitUntilSystemConditionsAvailable
to validate setting the activity within the 5 second limit, and outside of the 5 second limit.Manual testing
Ran the example app on an Android emulator with the example code above. It does not hit the condition every time, but using additional logging I was able to confirm
waitUntilSystemConditionsAvailable
will successfully wait (and time out) if the activity isn't set, or wait and pick up the newly set activity.Affected code checklist
Checklist
Overview
Testing
Final pass
This change is