Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1647764 - Swift: Check and reset dirty flag on startup #1476

Merged
merged 1 commit into from
Feb 1, 2021

Conversation

badboy
Copy link
Member

@badboy badboy commented Feb 1, 2021

This will avoid sending a dirty startup ping if the previous run of the application didn't
successfully and completely initialize Glean.

Unfortunately this is impossible to really test.
Because we currently consider initialization as a "foreground notification" (for the lack of other signals)
we immediately re-set the dirty flag to true.
So once the initialization completes we can't observe the previous
state anymore.


@mdboom because he did the original implementation.
@travis79 for the Swift review.

I'm going to post another PR for discussion around the notifications shortly. Not gonna land this before we discussed that one.

@badboy badboy added the blocked Blocked pull requests and issues label Feb 1, 2021
@auto-assign auto-assign bot requested a review from Dexterp37 February 1, 2021 10:24
@Dexterp37 Dexterp37 removed their request for review February 1, 2021 10:28
badboy added a commit that referenced this pull request Feb 1, 2021
`applicationWillEnterForeground`[1] is posted _before_ the app is actually
in the foreground, when it leaves the background stae.
This notification is NOT posted on first app launch (because it doesn't
leave a _background_ state).

Therefore we previously triggered `handleForegroundEvent` in the
constructor to work accordingly.
That's not wrong for all current uses of Glean (I assume),
but has two things worth pointing out:

1. It's different from Android behavior, where we do
   `handleForegroundEvent` only on an event (`ON_START`).
2. Because of that Android tests won't trigger `handleForegroundEvent`
   in unit tests, but only within a real app. We therefore can observe
   state after `Glean.initialize` but before `handleForegroundEvent`.
   We can't observe that currently in iOS.

`didBecomeActiveNotification`[2] on the other hand is posted when the
application is really active.
It can be observed on first startup.
Which should more closely match the behavior we also have on Android.

See also #1476, which we are currently unable to test.
We might be able to test it with this change.

[1]: https://developer.apple.com/documentation/uikit/uiapplication/1622944-willenterforegroundnotification
[2]: https://developer.apple.com/documentation/uikit/uiapplication/1622953-didbecomeactivenotification
Copy link
Contributor

@mdboom mdboom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine -- it's at least in line with the change on the Android side which has existed in the wild for quite some time.

Copy link
Member

@travis79 travis79 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

This will avoid sending a dirty startup ping if the previous run of the application didn't
successfully and completely initialize Glean.

Unfortunately this is impossible to really test.
Because we currently consider initialization as a "foreground notification" (for the lack of other signals)
we immediately re-set the dirty flag to true.
So once the `initialization` completes we can't observe the previous
state anymore.
@badboy badboy removed the blocked Blocked pull requests and issues label Feb 1, 2021
@badboy badboy merged commit 70444f6 into main Feb 1, 2021
@badboy badboy deleted the dirty-startup-fix-swift branch February 1, 2021 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants