Repository navigation
GCM: Make heartbeat more stable - #74
Merged
Merged
Conversation
This changes how the alarms for heartbeat pings are scheduled. Instead of a repeating, inexact alarm that may be delayed (at least up to 15 minutes), either an exact alarm (below Android 4.4) or an interval is used which ensures that the alarm fires between half the configured interval and the configured interval. This interval allows the OS to optimize alarms a bit. For Android 6.0 further adjustments are probably necessary.
This stores the timestamp of the last ack message that has been received. The connection is considered to be dead if the last ack message has been received more than twice the configured interval ago.
Closed
mar-v-in
added a commit
that referenced
this pull request
Jan 12, 2016
GCM: Make heartbeat more stable
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.
This changes how the heartbeat ping is scheduled in order to have a guaranteed maximum time that passes between two heartbeat pings. Further the connection is considered to be dead when no acknowledgment has been received for twice the configured interval.
In my experience the previously used repeating alarm can be delayed as much as 15 minutes, after that time the connection is gone on my phone. With these changes I get a stable connection for at least 8 hours when configuring the interval to be 5 minutes (which results in intervals between 2.5 and 5 minutes in order to give the OS a bit flexibility concerning battery-friendly scheduling) both via WiFi and UMTS.
What I haven't tested is the behavior below KitKat (which should use a different method) and I'm relatively sure that this is still broken on Marshmellow because of the new idle mode. While using setExactAndAllowWhileIdle might fix this partially, apparently apps are not allowed to get an alarm in this way more often then every 15 minutes (see here for some discussion) and I couldn't get the connection to be stable with intervals of 8 minutes and above. I don't know if this can be fixed using some parameters on the connection or if this is simply impossible depending on the internet connection (I tested mainly with Wifi).