-
Notifications
You must be signed in to change notification settings - Fork 9
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
fix: push opened metrics tracked on Android 12 #184
Conversation
Pull request title looks good 👍! If this pull request gets merged, it will cause a new release of the software. Example: If this project's latest release version is All merged pull requests will eventually get deployed. But some types of pull requests will trigger a deployment (such as features and bug fixes) while some pull requests will wait to get deployed until a later time. This project uses a special format for pull requests titles. Expand this section to learn more (expand by clicking the ᐅ symbol on the left side of this sentence)...This project uses a special format for pull requests titles. Don't worry, it's easy! This pull request title should be in this format:
If your pull request introduces breaking changes to the code, use this format:
where
Examples:
Need more examples? Want to learn more about this format? Check out the official docs. Note: If your pull request does multiple things such as adding a feature and makes changes to the CI server and fixes some bugs then you might want to consider splitting this pull request up into multiple smaller pull requests. |
Codecov Report
@@ Coverage Diff @@
## main #184 +/- ##
============================================
- Coverage 63.52% 63.01% -0.52%
Complexity 218 218
============================================
Files 91 91
Lines 2051 2082 +31
Branches 263 270 +7
============================================
+ Hits 1303 1312 +9
- Misses 646 667 +21
- Partials 102 103 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Build available to test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found a small improvement 😄
messagingpush/src/main/java/io/customer/messagingpush/CustomerIOFirebaseMessagingService.kt
Outdated
Show resolved
Hide resolved
…IOFirebaseMessagingService.kt Co-authored-by: Shahroz Khan <[email protected]>
* attempts to initialize with messaging push module so the module classes | ||
* are initialized as well. | ||
*/ | ||
private fun getSDKInstanceOrNull(context: Context): CustomerIO? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this function added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whenever we initialize SDK instance using context
from CustomerIOFirebaseMessagingService
, we should ideally initialize push-messaging module as well. For all instances in service requesting SDK initialization, they can call this method instead of copying the code again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From looking at the pull request diff, it looks like the SDK is currently calling CustomerIO.instanceOrNull(context)
. For example, in handleNewToken
in this file, the code today is CustomerIO.instanceOrNull(context)
but this PR is changing it to using this function.
What problem does CustomerIO.instanceOrNull(context, listOf(ModuleMessagingPushFCM()))
solve instead of using what the code has today: CustomerIO.instanceOrNull(context)
? I am assuming that the SDK works as intended today, so why change this code?
If there is no problem that this change fixes, I suggest that we remove this function and stick with the simplified code as it is today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By initializing the module early, we can register activity lifecycle callback required by messaging push module whenever we initialize SDK using context from the service. So this is actually what fixes the problem for notifications received when app was in terminated state. Also, since this file is part of messaging push module, so requesting initialization of module with SDK from these files is actually the correct behavior in my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that explanation you gave is really good! Can you add this explanation as a comment to the getSDKInstanceOrNull
function explaining what problem that function solves in it's implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, updated docs on getSDKInstanceOrNull
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks.
I think we should still ship this PR if it works, but I did have an idea for a refactor.
The purpose of getSDKInstanceOrNull
is to make sure that Activity lifecycle callbacks get registered with the SDK on initialization. The complexity exists because Activity lifecycle callbacks are in the messaging push module.
If we were to make the tracking module register empty Activity lifecycle callbacks during SDK initialization and then using some sort of communication mechanism (event bus, callback functions) we can make the messaging push module get code executed when the methods in the tracking module's Activity lifecycle callback get called.
If we were to make the SDK always register Activity lifecycle callbacks during SDK initialization, then that makes me think that this could replace something such as getSDKInstanceOrNull
and make the SDK more stable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure Levi. Since this apparently has worked well for us and fixes the bug, we'll ship this as soon as testing is complete. If you have ideas for refactoring, please feel free to create a ticket and suggest the changes in a separate PR.
I modified the title of the PR to explain why this commit exists instead of what it is doing in the code. |
// Cancelling queue timer as the new queue timer will take care of running queue tasks. | ||
// If we do not cancel old timer, it results in multiple timers being run and accessing | ||
// the same tasks. | ||
it.diGraph.queue.cancelTimer() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this along with a comment explaining why this is here.
In a call together, we talked about a long-term solution where CustomerIO.Builder.build()
can be called 2+ times and the SDK config is the only thing that gets modified but the SDK instance or any dependencies do not get modified.
Do we have a ticket to capture that refactor? I want to make sure before we introduce code like this that we need to maintain in the meantime before we do the refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's still the long term plan. But I haven't seen any issue for it yet, we probably need to create one for it 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created a ticket for this work https://github.com/customerio/issues/issues/9915
### [3.4.1](3.4.0...3.4.1) (2023-04-20) ### Bug Fixes * push opened metrics tracked on Android 12 ([#184](#184)) ([d2e52fa](d2e52fa))
fixes: https://github.com/customerio/issues/issues/9483
Changes
instanceOrNull
method to support modules initializationCustomerIOFirebaseMessagingService
to initialize push module when we initialize SDK usingcontext