diff options
author | Remi NGUYEN VAN <reminv@google.com> | 2020-06-25 03:41:56 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-06-25 03:41:56 +0000 |
commit | 53831f2b67188016f8b8b3f7af675130a5b08cf6 (patch) | |
tree | acc1a70752843a55c0201c1de4db20e3e396fc12 /src/android/net/ip/IpClientLinkObserver.java | |
parent | c2cdb2c76459fd41a6307de517dbb21d41cef311 (diff) | |
parent | 9e9451f3b5a5115924c031f99a89861d0ba8445a (diff) |
Merge "Send normal termination metrics on wifi off" into rvc-dev am: 9e9451f3b5
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/NetworkStack/+/11970035
Change-Id: I1e50ae3894e56d7ced7e59cfa07d07b8e89431a0
Diffstat (limited to 'src/android/net/ip/IpClientLinkObserver.java')
-rw-r--r-- | src/android/net/ip/IpClientLinkObserver.java | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/src/android/net/ip/IpClientLinkObserver.java b/src/android/net/ip/IpClientLinkObserver.java index dcbca94..46b3844 100644 --- a/src/android/net/ip/IpClientLinkObserver.java +++ b/src/android/net/ip/IpClientLinkObserver.java @@ -89,8 +89,13 @@ public class IpClientLinkObserver implements NetworkObserver { public interface Callback { /** * Called when some properties of the link were updated. + * + * @param linkState Whether the interface link state is up as per the latest + * {@link #onInterfaceLinkStateChanged(String, boolean)} callback. This + * should only be used for metrics purposes, as it could be inconsistent + * with {@link #getLinkProperties()} in particular. */ - void update(); + void update(boolean linkState); } /** Configuration parameters for IpClientLinkObserver. */ @@ -105,6 +110,7 @@ public class IpClientLinkObserver implements NetworkObserver { private final String mInterfaceName; private final Callback mCallback; private final LinkProperties mLinkProperties; + private boolean mInterfaceLinkState; private DnsServerRepository mDnsServerRepository; private final AlarmManager mAlarmManager; private final Configuration mConfig; @@ -121,6 +127,7 @@ public class IpClientLinkObserver implements NetworkObserver { mLinkProperties = new LinkProperties(); mLinkProperties.setInterfaceName(mInterfaceName); mConfig = config; + mInterfaceLinkState = true; // Assume up by default mDnsServerRepository = new DnsServerRepository(config.minRdnssLifetime); mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); mNetlinkMonitor = new MyNetlinkMonitor(h, log, mTag); @@ -149,7 +156,15 @@ public class IpClientLinkObserver implements NetworkObserver { // interface-specific messages (e.g., RTM_DELADDR) will not reach us, because the netd // code that parses them will not be able to resolve the ifindex to an interface name. clearLinkProperties(); - mCallback.update(); + mCallback.update(getInterfaceLinkState()); + } + } + + @Override + public void onInterfaceLinkStateChanged(String iface, boolean state) { + if (mInterfaceName.equals(iface)) { + maybeLog("interfaceLinkStateChanged", iface + (state ? " up" : " down")); + setInterfaceLinkState(state); } } @@ -162,7 +177,7 @@ public class IpClientLinkObserver implements NetworkObserver { changed = mLinkProperties.addLinkAddress(address); } if (changed) { - mCallback.update(); + mCallback.update(getInterfaceLinkState()); } } } @@ -176,7 +191,7 @@ public class IpClientLinkObserver implements NetworkObserver { changed = mLinkProperties.removeLinkAddress(address); } if (changed) { - mCallback.update(); + mCallback.update(getInterfaceLinkState()); } } } @@ -190,7 +205,7 @@ public class IpClientLinkObserver implements NetworkObserver { changed = mLinkProperties.addRoute(route); } if (changed) { - mCallback.update(); + mCallback.update(getInterfaceLinkState()); } } } @@ -204,7 +219,7 @@ public class IpClientLinkObserver implements NetworkObserver { changed = mLinkProperties.removeRoute(route); } if (changed) { - mCallback.update(); + mCallback.update(getInterfaceLinkState()); } } } @@ -218,7 +233,7 @@ public class IpClientLinkObserver implements NetworkObserver { synchronized (this) { mDnsServerRepository.setDnsServersOn(mLinkProperties); } - mCallback.update(); + mCallback.update(getInterfaceLinkState()); } } } @@ -243,6 +258,14 @@ public class IpClientLinkObserver implements NetworkObserver { mLinkProperties.setInterfaceName(mInterfaceName); } + private synchronized boolean getInterfaceLinkState() { + return mInterfaceLinkState; + } + + private synchronized void setInterfaceLinkState(boolean state) { + mInterfaceLinkState = state; + } + /** Notifies this object of new interface parameters. */ public void setInterfaceParams(InterfaceParams params) { mNetlinkMonitor.setIfindex(params.index); @@ -355,7 +378,7 @@ public class IpClientLinkObserver implements NetworkObserver { cancelPref64Alarm(); } - mCallback.update(); + mCallback.update(getInterfaceLinkState()); } private void processPref64Option(StructNdOptPref64 opt, final long now) { |