-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[Android] Add NetworkChange implementation using PeriodicTimer #80548
[Android] Add NetworkChange implementation using PeriodicTimer #80548
Conversation
Tagging subscribers to 'arch-android': @steveisok, @akoeplinger Issue DetailsWIP - this code needs more testing before it will be ready for review. We can't use netlink sockets to monitor network changes on Android anymore due to changes to permissions in recent Android versions. There doesn't seem to be a native Android API that could be used to implement the Ref #77822
|
/azp run runtime-android |
Azure Pipelines successfully started running 1 pipeline(s). |
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.
LGTM. I think a 2 sec poll is reasonable for those who want to opt in. I don't think there are any other good alternatives.
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.
A few nits, but overall looks good to me!
Out of curiosity, were there statistics to use 2 seconds polling? I'm not familiar, but is there a general frequency to network changes, and is the impact on battery life mainly from CheckIfAddressChanged
firing? How long does it take for CheckIfAddressChanged
to finish?
src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj
Outdated
Show resolved
Hide resolved
...tem.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Android.cs
Show resolved
Hide resolved
...tem.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Android.cs
Outdated
Show resolved
Hide resolved
@mdh1418 The 2s is my estimate of what is "almost immediately" but at the same time "not all the time". I tried being as conservative as possible with the frequency. I didn't measure how long |
Gotcha, I was wondering if the impact of battery life would be more directly related to the duty cycle of What might be more helpful to determine polling frequency than duty cycle might be what happens if we miss a network change? Is it problematic if there were multiple network changes within the 2 seconds? Is it problematic if there was a change that cancelled itself out within 2 seconds (i.e. a network becomes available and then becomes unavailable all before the next poll)? |
@mdh1418 So on my Samsung Galaxy phone running Android 13 I don't think it's too important to detect these short network availability spikes, although there might be customers who might need this kind of information. The use case for this API in a mobile app I can imagine is to wait for network availability and only when the device is online, attempt to send a HTTP request. This implementation would IMO be suitable for that use case. it wouldn't be useful to monitor and diagnose network stability of an Android device. I think there are more suitable native APIs for that use case. |
/azp run runtime-android |
Azure Pipelines successfully started running 1 pipeline(s). |
Failing tests are unrelated to this PR. |
…t#80548) * Add NetworkChange implementation using PeriodicTimer * Code cleanup * Rename functions * Update csproj
/backport to release/7.0 |
Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/4043009267 |
@simonrozsival backporting to release/7.0 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Add NetworkChange implementation using PeriodicTimer
Using index info to reconstruct a base tree...
M src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj
CONFLICT (content): Merge conflict in src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Add NetworkChange implementation using PeriodicTimer
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
@simonrozsival an error occurred while backporting to release/7.0, please check the run log for details! Error: git am failed, most likely due to a merge conflict. |
…t#80548) * Add NetworkChange implementation using PeriodicTimer * Code cleanup * Rename functions * Update csproj
…t#80548) * Add NetworkChange implementation using PeriodicTimer * Code cleanup * Rename functions * Update csproj
… (#81349) * Add NetworkChange implementation using PeriodicTimer * Code cleanup * Rename functions * Update csproj
… (#81350) * Add NetworkChange implementation using PeriodicTimer * Code cleanup * Rename functions * Update csproj
We can't use netlink sockets to monitor network changes on Android anymore due to changes to permissions in recent Android versions. There doesn't seem to be a native Android API that could be used to implement the
NetworkChange
API in .NET. Instead, this PR implements the functionality usingPeriodicTimer
and manually diffing the IP addresses of all network interfaces. The period is set to 2s to limit the impact on battery life of mobile devices.Ref #77822