Leverage NetworkCallback improvements in NetworkChangeNotifier |
||
Issue descriptionNetworkChangeNotifier mostly uses Lollipop-era APIs, so it has to work around a number of limitations: 1. There is no way to get the default network. NCN relies on getting the legacy type of the active network and then trying to find a matching legacy type in the return value of getAllNetworks(). Thus, getDefaultNetId can return NetId.INVALID if the default network switches while it is running, even if there has been no disconnect. It also does not work if more than one network of the same legacy type is connected (e.g., two APNs that both have the INTERNET capability). 2. The only way to know if the default network has changed is CONNECTIVITY_ACTION. This broadcast is not strictly ordered with other callbacks, since it is delivered by other threads and can be delayed if the broadcast queue is busy. Additionally, the broadcast doesn't contain a netId so it has the same problems as getDefaultNetId above. 3. There is no race-free way of tracking changes in a network's LinkProperties or NetworkCapabilities. There are synchronous calls to fetch them, and callbacks to hear about changes in them, but there is no race-free way of combining the two because the synchronous call and the callback are not ordered with respect to each other. 4. getAllNetworks doesn't redact networks that the caller doesn't have permission to use, so in the case of background networks (e.g., mobile data always on, if the app doesn't have CHANGE_NETWORK_STATE), NCN might think mobile data is always available. Android APIs introduced in N and O can make the code more reliable. Specifically: 1. In N and above we have registerDefaultNetworkCallback. This allows us to move away from CONNECTIVITY_ACTION, which is not ordered in any way with respect to the other callbacks. NCN could keep one of these always active and update a member variable whenever the default network changes, and getDefaultNetId could simply return the variable. 2. Since O, onAvailable is guaranteed to be followed by onCapabilitiesChanged and onLinkPropertiesChanged (and if applicable onSuspended). This means that we're guaranteed to have an in-order notification of the capabilities of each network (including whether it's wifi or cell, metered or not, etc.) as soon as a network becomes available. Previously we'd have to call ConnectivityManager#getNetworkCapabilities, which introduces races and ordering issues.
,
Oct 13 2017
,
Sep 27
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/5adf37cfebecab32512d95bcaa67a591130b6774 commit 5adf37cfebecab32512d95bcaa67a591130b6774 Author: Paul Jensen <pauljensen@chromium.org> Date: Thu Sep 27 16:05:12 2018 Listen to default network callbacks for Android Pie. Listening for LinkProperties changes is required so we can detect if private DNS is enabled. Register a default-network callback so NetworkChangeNotifierAutoDetect on Android can listen for these LinkProperties changes. Use this default-network callback in place of CONNECTIVITY_ACTION which is deprecated. Bug: 885291, 774497 Change-Id: I0e6457f9cb970f1e010171af6c030638b1a667e6 Reviewed-on: https://chromium-review.googlesource.com/1243343 Commit-Queue: Paul Jensen <pauljensen@chromium.org> Reviewed-by: Cathy Li <chili@chromium.org> Reviewed-by: Misha Efimov <mef@chromium.org> Cr-Commit-Position: refs/heads/master@{#594739} [modify] https://crrev.com/5adf37cfebecab32512d95bcaa67a591130b6774/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/prefetch/PrefetchFlowTest.java [modify] https://crrev.com/5adf37cfebecab32512d95bcaa67a591130b6774/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java [modify] https://crrev.com/5adf37cfebecab32512d95bcaa67a591130b6774/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java [modify] https://crrev.com/5adf37cfebecab32512d95bcaa67a591130b6774/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java |
||
►
Sign in to add a comment |
||
Comment 1 by pauljensen@chromium.org
, Oct 13 2017Labels: -OS-Linux OS-Android