diff options
author | Remi NGUYEN VAN <reminv@google.com> | 2020-06-23 00:15:45 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-06-23 00:15:45 +0000 |
commit | f61f0a785f01d4bb445d3f7952053131a2ed8b37 (patch) | |
tree | c4f407136ce9934f2bd67ed5fa204d8de2965089 /src/android/net/dhcp/DhcpClient.java | |
parent | 59e4621953ff863cc3f62440ad8ba273f84c5895 (diff) | |
parent | c0009497b1c8a20d72af616d8bba4253959948ab (diff) |
Merge "Injecting network ip provision stats into statsd" into rvc-dev
Diffstat (limited to 'src/android/net/dhcp/DhcpClient.java')
-rw-r--r-- | src/android/net/dhcp/DhcpClient.java | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/android/net/dhcp/DhcpClient.java b/src/android/net/dhcp/DhcpClient.java index 4404273..4fedf30 100644 --- a/src/android/net/dhcp/DhcpClient.java +++ b/src/android/net/dhcp/DhcpClient.java @@ -80,6 +80,7 @@ import android.os.Message; import android.os.PowerManager; import android.os.SystemClock; import android.provider.Settings; +import android.stats.connectivity.DhcpFeature; import android.system.ErrnoException; import android.system.Os; import android.util.EventLog; @@ -101,6 +102,7 @@ import com.android.networkstack.apishim.CaptivePortalDataShimImpl; import com.android.networkstack.apishim.SocketUtilsShimImpl; import com.android.networkstack.apishim.common.ShimUtils; import com.android.networkstack.arp.ArpPacket; +import com.android.networkstack.metrics.IpProvisioningMetrics; import java.io.FileDescriptor; import java.io.IOException; @@ -305,6 +307,8 @@ public class DhcpClient extends StateMachine { private final Context mContext; private final Random mRandom; private final IpConnectivityLog mMetricsLog = new IpConnectivityLog(); + @NonNull + private final IpProvisioningMetrics mMetrics; // We use a UDP socket to send, so the kernel handles ARP and routing for us (DHCP servers can // be off-link as well as on-link). @@ -378,9 +382,11 @@ public class DhcpClient extends StateMachine { */ public static class Dependencies { private final NetworkStackIpMemoryStore mNetworkStackIpMemoryStore; + private final IpProvisioningMetrics mMetrics; - public Dependencies(NetworkStackIpMemoryStore store) { + public Dependencies(NetworkStackIpMemoryStore store, IpProvisioningMetrics metrics) { mNetworkStackIpMemoryStore = store; + mMetrics = metrics; } /** @@ -407,6 +413,13 @@ public class DhcpClient extends StateMachine { } /** + * Get a IpProvisioningMetrics instance. + */ + public IpProvisioningMetrics getIpProvisioningMetrics() { + return mMetrics; + } + + /** * Return whether a feature guarded by a feature flag is enabled. * @see NetworkStackUtils#isFeatureEnabled(Context, String, String) */ @@ -444,6 +457,7 @@ public class DhcpClient extends StateMachine { mController = controller; mIfaceName = iface; mIpMemoryStore = deps.getIpMemoryStore(); + mMetrics = deps.getIpProvisioningMetrics(); // CHECKSTYLE:OFF IndentationCheck addState(mStoppedState); @@ -484,6 +498,7 @@ public class DhcpClient extends StateMachine { final boolean sendHostname = deps.getSendHostnameOption(context); mHostname = sendHostname ? new HostnameTransliterator().transliterate( deps.getDeviceName(mContext)) : null; + mMetrics.setHostnameTransinfo(sendHostname, mHostname != null); } public void registerForPreDhcpNotification() { @@ -529,6 +544,15 @@ public class DhcpClient extends StateMachine { false /* defaultEnabled */); } + private void recordMetricEnabledFeatures() { + if (isDhcpLeaseCacheEnabled()) mMetrics.setDhcpEnabledFeature(DhcpFeature.DF_INITREBOOT); + if (isDhcpRapidCommitEnabled()) mMetrics.setDhcpEnabledFeature(DhcpFeature.DF_RAPIDCOMMIT); + if (isDhcpIpConflictDetectEnabled()) mMetrics.setDhcpEnabledFeature(DhcpFeature.DF_DAD); + if (mConfiguration.isPreconnectionEnabled) { + mMetrics.setDhcpEnabledFeature(DhcpFeature.DF_FILS); + } + } + private void confirmDhcpLease(DhcpPacket packet, DhcpResults results) { setDhcpLeaseExpiry(packet); acceptDhcpResults(results, "Confirmed"); @@ -610,6 +634,7 @@ public class DhcpClient extends StateMachine { EventLog.writeEvent(snetTagId, bugId, uid, data); } mMetricsLog.log(mIfaceName, new DhcpErrorEvent(e.errorCode)); + mMetrics.addDhcpErrorCode(e.errorCode); } } @@ -687,6 +712,7 @@ public class DhcpClient extends StateMachine { final ByteBuffer packet = DhcpPacket.buildDiscoverPacket( DhcpPacket.ENCAP_L2, mTransactionId, getSecs(), mHwAddr, DO_UNICAST, getRequestedParams(), isDhcpRapidCommitEnabled(), mHostname); + mMetrics.incrementCountForDiscover(); return transmitPacket(packet, "DHCPDISCOVER", DhcpPacket.ENCAP_L2, INADDR_BROADCAST); } @@ -705,6 +731,7 @@ public class DhcpClient extends StateMachine { String description = "DHCPREQUEST ciaddr=" + clientAddress.getHostAddress() + " request=" + requestedAddress.getHostAddress() + " serverid=" + serverStr; + mMetrics.incrementCountForRequest(); return transmitPacket(packet, description, encap, to); } @@ -937,6 +964,7 @@ public class DhcpClient extends StateMachine { } else { startInitRebootOrInit(); } + recordMetricEnabledFeatures(); return HANDLED; default: return NOT_HANDLED; @@ -1422,6 +1450,7 @@ public class DhcpClient extends StateMachine { try { final ArpPacket packet = ArpPacket.parseArpPacket(recvbuf, length); if (hasIpAddressConflict(packet, mTargetIp)) { + mMetrics.incrementCountForIpConflict(); sendMessage(EVENT_IP_CONFLICT); } } catch (ArpPacket.ParseException e) { |