diff options
author | lifr <lifr@google.com> | 2020-06-18 02:52:44 +0000 |
---|---|---|
committer | lifr <lifr@google.com> | 2020-06-23 04:00:21 +0800 |
commit | c0009497b1c8a20d72af616d8bba4253959948ab (patch) | |
tree | 87fa0c44378c03469ae68a65e2c91f677cd3d09b /src/android/net/util/NetworkStackUtils.java | |
parent | def2536afacaa22f1fe4e8c21f496a8c641b5e8e (diff) |
Injecting network ip provision stats into statsd
1. Fill in each field of the NetworkIpProvisioningReported
2. Write the NetworkIpProvisioningReported into statsd
Bug: 151796056
Test: atest NetworkStackIntegrationTests NetworkStackTests
Test: atest FrameworksNetTests
Test: Manual test with statsd_testdrive
Original-Change: https://android-review.googlesource.com/1313574
Merged-In: If4bc6af1b794a8620a08858d6cfd85e661865bd7
Change-Id: If4bc6af1b794a8620a08858d6cfd85e661865bd7
Diffstat (limited to 'src/android/net/util/NetworkStackUtils.java')
-rwxr-xr-x | src/android/net/util/NetworkStackUtils.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/android/net/util/NetworkStackUtils.java b/src/android/net/util/NetworkStackUtils.java index 99563ee..19ca4b5 100755 --- a/src/android/net/util/NetworkStackUtils.java +++ b/src/android/net/util/NetworkStackUtils.java @@ -436,4 +436,22 @@ public class NetworkStackUtils { return addr instanceof Inet6Address && ((addr.getAddress()[0] & 0xfe) == 0xfc); } + + /** + * Returns the {@code int} nearest in value to {@code value}. + * + * @param value any {@code long} value + * @return the same value cast to {@code int} if it is in the range of the {@code int} + * type, {@link Integer#MAX_VALUE} if it is too large, or {@link Integer#MIN_VALUE} if + * it is too small + */ + public static int saturatedCast(long value) { + if (value > Integer.MAX_VALUE) { + return Integer.MAX_VALUE; + } + if (value < Integer.MIN_VALUE) { + return Integer.MIN_VALUE; + } + return (int) value; + } } |