From e512b2691323a6619a79bbec38182ed33ad86016 Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Thu, 11 Apr 2019 21:24:28 +0800 Subject: Migrate NetworkStack metrics off StatsLog.write Now that the new metrics API can be used, NetworkStack metrics need to migrate off the legacy StatsLog.write. Bug: 130323000 Test: Test with ./out/host/linux-x86/bin/statsd_testdrive 121 to ensure log properly Test: Ensure NetworkStackStatsLog will be generated as expected Test: atest NetworkStackTest Change-Id: I8c70503cf1d9f1d06f30a1936d2d88857d0cff53 --- cmds/statsd/src/atoms.proto | 4 +- core/java/android/util/StatsLog.java | 5 - packages/NetworkStack/Android.bp | 9 + .../net/metrics/DataStallDetectionStats.java | 228 --------------------- .../android/net/metrics/DataStallStatsUtils.java | 77 ------- .../metrics/DataStallDetectionStats.java | 228 +++++++++++++++++++++ .../networkstack/metrics/DataStallStatsUtils.java | 73 +++++++ .../server/connectivity/NetworkMonitor.java | 4 +- .../server/connectivity/NetworkMonitorTest.java | 5 +- 9 files changed, 317 insertions(+), 316 deletions(-) delete mode 100644 packages/NetworkStack/src/android/net/metrics/DataStallDetectionStats.java delete mode 100644 packages/NetworkStack/src/android/net/metrics/DataStallStatsUtils.java create mode 100644 packages/NetworkStack/src/com/android/networkstack/metrics/DataStallDetectionStats.java create mode 100644 packages/NetworkStack/src/com/android/networkstack/metrics/DataStallStatsUtils.java diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto index 90ba7ce0c812..f4e4a0b60adb 100644 --- a/cmds/statsd/src/atoms.proto +++ b/cmds/statsd/src/atoms.proto @@ -208,7 +208,7 @@ message Atom { 119 [(log_from_module) = "docsui"]; DocsUISearchTypeReported docs_ui_search_type_reported = 120 [(log_from_module) = "docsui"]; - DataStallEvent data_stall_event = 121; + DataStallEvent data_stall_event = 121 [(log_from_module) = "network_stack"]; RescuePartyResetReported rescue_party_reset_reported = 122; SignedConfigReported signed_config_reported = 123; GnssNiEventReported gnss_ni_event_reported = 124; @@ -269,7 +269,7 @@ message Atom { StyleUIChanged style_ui_changed = 179; PrivacyIndicatorsInteracted privacy_indicators_interacted = 180; AppInstallOnExternalStorageReported app_install_on_external_storage_reported = 181; - NetworkStackReported network_stack_reported = 182; + NetworkStackReported network_stack_reported = 182 [(log_from_module) = "network_stack"]; AppMovedStorageReported app_moved_storage_reported = 183; BiometricEnrolled biometric_enrolled = 184; SystemServerWatchdogOccurred system_server_watchdog_occurred = 185; diff --git a/core/java/android/util/StatsLog.java b/core/java/android/util/StatsLog.java index dd22a26d61af..9da29c0c334e 100644 --- a/core/java/android/util/StatsLog.java +++ b/core/java/android/util/StatsLog.java @@ -198,11 +198,6 @@ public final class StatsLog extends StatsLogInternal { write(id, (long) params[0], (int) params[1], (String) params[2], (String) params[3], (boolean) params[4], (int) params[5]); break; - case DATA_STALL_EVENT: - // Refer to the defintion in frameworks/base/cmds/statsd/src/atoms.proto. - write(id, (int) params[0], (int) params[1], (int) params[2], (byte[]) params[3], - (byte[]) params[4], (byte[]) params[5]); - break; } } diff --git a/packages/NetworkStack/Android.bp b/packages/NetworkStack/Android.bp index 5817118bc861..e0bb862c5362 100644 --- a/packages/NetworkStack/Android.bp +++ b/packages/NetworkStack/Android.bp @@ -37,6 +37,7 @@ android_library { "src/**/*.java", ":framework-networkstack-shared-srcs", ":services-networkstack-shared-srcs", + ":statslog-networkstack-java-gen", ], static_libs: [ "androidx.annotation_annotation", @@ -104,3 +105,11 @@ android_app { certificate: "networkstack", manifest: "AndroidManifest.xml", } + +genrule { + name: "statslog-networkstack-java-gen", + tools: ["stats-log-api-gen"], + cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" + + " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog", + out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"], +} diff --git a/packages/NetworkStack/src/android/net/metrics/DataStallDetectionStats.java b/packages/NetworkStack/src/android/net/metrics/DataStallDetectionStats.java deleted file mode 100644 index 225dc0f4bfdc..000000000000 --- a/packages/NetworkStack/src/android/net/metrics/DataStallDetectionStats.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.metrics; - -import android.annotation.NonNull; -import android.annotation.Nullable; -import android.net.util.NetworkStackUtils; -import android.net.wifi.WifiInfo; - -import com.android.internal.util.HexDump; -import com.android.server.connectivity.nano.CellularData; -import com.android.server.connectivity.nano.DataStallEventProto; -import com.android.server.connectivity.nano.DnsEvent; -import com.android.server.connectivity.nano.WifiData; - -import com.google.protobuf.nano.MessageNano; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -/** - * Class to record the stats of detection level information for data stall. - * - * @hide - */ -public final class DataStallDetectionStats { - private static final int UNKNOWN_SIGNAL_STRENGTH = -1; - @NonNull - final byte[] mCellularInfo; - @NonNull - final byte[] mWifiInfo; - @NonNull - final byte[] mDns; - final int mEvaluationType; - final int mNetworkType; - - public DataStallDetectionStats(@Nullable byte[] cell, @Nullable byte[] wifi, - @NonNull int[] returnCode, @NonNull long[] dnsTime, int evalType, int netType) { - mCellularInfo = emptyCellDataIfNull(cell); - mWifiInfo = emptyWifiInfoIfNull(wifi); - - DnsEvent dns = new DnsEvent(); - dns.dnsReturnCode = returnCode; - dns.dnsTime = dnsTime; - mDns = MessageNano.toByteArray(dns); - mEvaluationType = evalType; - mNetworkType = netType; - } - - private byte[] emptyCellDataIfNull(@Nullable byte[] cell) { - if (cell != null) return cell; - - CellularData data = new CellularData(); - data.ratType = DataStallEventProto.RADIO_TECHNOLOGY_UNKNOWN; - data.networkMccmnc = ""; - data.simMccmnc = ""; - data.signalStrength = UNKNOWN_SIGNAL_STRENGTH; - return MessageNano.toByteArray(data); - } - - private byte[] emptyWifiInfoIfNull(@Nullable byte[] wifi) { - if (wifi != null) return wifi; - - WifiData data = new WifiData(); - data.wifiBand = DataStallEventProto.AP_BAND_UNKNOWN; - data.signalStrength = UNKNOWN_SIGNAL_STRENGTH; - return MessageNano.toByteArray(data); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("type: ").append(mNetworkType) - .append(", evaluation type: ") - .append(mEvaluationType) - .append(", wifi info: ") - .append(HexDump.toHexString(mWifiInfo)) - .append(", cell info: ") - .append(HexDump.toHexString(mCellularInfo)) - .append(", dns: ") - .append(HexDump.toHexString(mDns)); - return sb.toString(); - } - - @Override - public boolean equals(@Nullable final Object o) { - if (!(o instanceof DataStallDetectionStats)) return false; - final DataStallDetectionStats other = (DataStallDetectionStats) o; - return (mNetworkType == other.mNetworkType) - && (mEvaluationType == other.mEvaluationType) - && Arrays.equals(mWifiInfo, other.mWifiInfo) - && Arrays.equals(mCellularInfo, other.mCellularInfo) - && Arrays.equals(mDns, other.mDns); - } - - @Override - public int hashCode() { - return Objects.hash(mNetworkType, mEvaluationType, mWifiInfo, mCellularInfo, mDns); - } - - /** - * Utility to create an instance of {@Link DataStallDetectionStats} - * - * @hide - */ - public static class Builder { - @Nullable - private byte[] mCellularInfo; - @Nullable - private byte[] mWifiInfo; - @NonNull - private final List mDnsReturnCode = new ArrayList(); - @NonNull - private final List mDnsTimeStamp = new ArrayList(); - private int mEvaluationType; - private int mNetworkType; - - /** - * Add a dns event into Builder. - * - * @param code the return code of the dns event. - * @param timeMs the elapsedRealtime in ms that the the dns event was received from netd. - * @return {@code this} {@link Builder} instance. - */ - public Builder addDnsEvent(int code, long timeMs) { - mDnsReturnCode.add(code); - mDnsTimeStamp.add(timeMs); - return this; - } - - /** - * Set the dns evaluation type into Builder. - * - * @param type the return code of the dns event. - * @return {@code this} {@link Builder} instance. - */ - public Builder setEvaluationType(int type) { - mEvaluationType = type; - return this; - } - - /** - * Set the network type into Builder. - * - * @param type the network type of the logged network. - * @return {@code this} {@link Builder} instance. - */ - public Builder setNetworkType(int type) { - mNetworkType = type; - return this; - } - - /** - * Set the wifi data into Builder. - * - * @param info a {@link WifiInfo} of the connected wifi network. - * @return {@code this} {@link Builder} instance. - */ - public Builder setWiFiData(@Nullable final WifiInfo info) { - WifiData data = new WifiData(); - data.wifiBand = getWifiBand(info); - data.signalStrength = (info != null) ? info.getRssi() : UNKNOWN_SIGNAL_STRENGTH; - mWifiInfo = MessageNano.toByteArray(data); - return this; - } - - private static int getWifiBand(@Nullable final WifiInfo info) { - if (info == null) return DataStallEventProto.AP_BAND_UNKNOWN; - - int freq = info.getFrequency(); - // Refer to ScanResult.is5GHz() and ScanResult.is24GHz(). - if (freq > 4900 && freq < 5900) { - return DataStallEventProto.AP_BAND_5GHZ; - } else if (freq > 2400 && freq < 2500) { - return DataStallEventProto.AP_BAND_2GHZ; - } else { - return DataStallEventProto.AP_BAND_UNKNOWN; - } - } - - /** - * Set the cellular data into Builder. - * - * @param radioType the radio technology of the logged cellular network. - * @param roaming a boolean indicates if logged cellular network is roaming or not. - * @param networkMccmnc the mccmnc of the camped network. - * @param simMccmnc the mccmnc of the sim. - * @return {@code this} {@link Builder} instance. - */ - public Builder setCellData(int radioType, boolean roaming, - @NonNull String networkMccmnc, @NonNull String simMccmnc, int ss) { - CellularData data = new CellularData(); - data.ratType = radioType; - data.isRoaming = roaming; - data.networkMccmnc = networkMccmnc; - data.simMccmnc = simMccmnc; - data.signalStrength = ss; - mCellularInfo = MessageNano.toByteArray(data); - return this; - } - - /** - * Create a new {@Link DataStallDetectionStats}. - */ - public DataStallDetectionStats build() { - return new DataStallDetectionStats(mCellularInfo, mWifiInfo, - NetworkStackUtils.convertToIntArray(mDnsReturnCode), - NetworkStackUtils.convertToLongArray(mDnsTimeStamp), - mEvaluationType, mNetworkType); - } - } -} diff --git a/packages/NetworkStack/src/android/net/metrics/DataStallStatsUtils.java b/packages/NetworkStack/src/android/net/metrics/DataStallStatsUtils.java deleted file mode 100644 index e23f10f243dc..000000000000 --- a/packages/NetworkStack/src/android/net/metrics/DataStallStatsUtils.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.metrics; - -import android.annotation.NonNull; -import android.annotation.Nullable; -import android.net.captiveportal.CaptivePortalProbeResult; -import android.util.Log; -import android.util.StatsLog; - -import com.android.internal.util.HexDump; -import com.android.server.connectivity.nano.DataStallEventProto; - -/** - * Collection of utilities for data stall metrics. - * - * To see if the logs are properly sent to statsd, execute following command. - * - * $ adb shell cmd stats print-logs - * $ adb logcat | grep statsd OR $ adb logcat -b stats - * - * @hide - */ -public class DataStallStatsUtils { - private static final String TAG = DataStallStatsUtils.class.getSimpleName(); - private static final int DATA_STALL_EVENT_ID = 121; - private static final boolean DBG = false; - - private static int probeResultToEnum(@Nullable final CaptivePortalProbeResult result) { - if (result == null) return DataStallEventProto.INVALID; - - // TODO: Add partial connectivity support. - if (result.isSuccessful()) { - return DataStallEventProto.VALID; - } else if (result.isPortal()) { - return DataStallEventProto.PORTAL; - } else if (result.isPartialConnectivity()) { - return DataStallEventProto.PARTIAL; - } else { - return DataStallEventProto.INVALID; - } - } - - /** - * Write the metric to {@link StatsLog}. - */ - public static void write(@NonNull final DataStallDetectionStats stats, - @NonNull final CaptivePortalProbeResult result) { - int validationResult = probeResultToEnum(result); - if (DBG) { - Log.d(TAG, "write: " + stats + " with result: " + validationResult - + ", dns: " + HexDump.toHexString(stats.mDns)); - } - // TODO(b/124613085): Update API once the public StatsLog API is ready. - StatsLog.write(DATA_STALL_EVENT_ID, - stats.mEvaluationType, - validationResult, - stats.mNetworkType, - stats.mWifiInfo, - stats.mCellularInfo, - stats.mDns); - } -} diff --git a/packages/NetworkStack/src/com/android/networkstack/metrics/DataStallDetectionStats.java b/packages/NetworkStack/src/com/android/networkstack/metrics/DataStallDetectionStats.java new file mode 100644 index 000000000000..2523ecd4ea20 --- /dev/null +++ b/packages/NetworkStack/src/com/android/networkstack/metrics/DataStallDetectionStats.java @@ -0,0 +1,228 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.networkstack.metrics; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.net.util.NetworkStackUtils; +import android.net.wifi.WifiInfo; + +import com.android.internal.util.HexDump; +import com.android.server.connectivity.nano.CellularData; +import com.android.server.connectivity.nano.DataStallEventProto; +import com.android.server.connectivity.nano.DnsEvent; +import com.android.server.connectivity.nano.WifiData; + +import com.google.protobuf.nano.MessageNano; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +/** + * Class to record the stats of detection level information for data stall. + * + * @hide + */ +public final class DataStallDetectionStats { + private static final int UNKNOWN_SIGNAL_STRENGTH = -1; + @NonNull + final byte[] mCellularInfo; + @NonNull + final byte[] mWifiInfo; + @NonNull + final byte[] mDns; + final int mEvaluationType; + final int mNetworkType; + + public DataStallDetectionStats(@Nullable byte[] cell, @Nullable byte[] wifi, + @NonNull int[] returnCode, @NonNull long[] dnsTime, int evalType, int netType) { + mCellularInfo = emptyCellDataIfNull(cell); + mWifiInfo = emptyWifiInfoIfNull(wifi); + + DnsEvent dns = new DnsEvent(); + dns.dnsReturnCode = returnCode; + dns.dnsTime = dnsTime; + mDns = MessageNano.toByteArray(dns); + mEvaluationType = evalType; + mNetworkType = netType; + } + + private byte[] emptyCellDataIfNull(@Nullable byte[] cell) { + if (cell != null) return cell; + + CellularData data = new CellularData(); + data.ratType = DataStallEventProto.RADIO_TECHNOLOGY_UNKNOWN; + data.networkMccmnc = ""; + data.simMccmnc = ""; + data.signalStrength = UNKNOWN_SIGNAL_STRENGTH; + return MessageNano.toByteArray(data); + } + + private byte[] emptyWifiInfoIfNull(@Nullable byte[] wifi) { + if (wifi != null) return wifi; + + WifiData data = new WifiData(); + data.wifiBand = DataStallEventProto.AP_BAND_UNKNOWN; + data.signalStrength = UNKNOWN_SIGNAL_STRENGTH; + return MessageNano.toByteArray(data); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("type: ").append(mNetworkType) + .append(", evaluation type: ") + .append(mEvaluationType) + .append(", wifi info: ") + .append(HexDump.toHexString(mWifiInfo)) + .append(", cell info: ") + .append(HexDump.toHexString(mCellularInfo)) + .append(", dns: ") + .append(HexDump.toHexString(mDns)); + return sb.toString(); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (!(o instanceof DataStallDetectionStats)) return false; + final DataStallDetectionStats other = (DataStallDetectionStats) o; + return (mNetworkType == other.mNetworkType) + && (mEvaluationType == other.mEvaluationType) + && Arrays.equals(mWifiInfo, other.mWifiInfo) + && Arrays.equals(mCellularInfo, other.mCellularInfo) + && Arrays.equals(mDns, other.mDns); + } + + @Override + public int hashCode() { + return Objects.hash(mNetworkType, mEvaluationType, mWifiInfo, mCellularInfo, mDns); + } + + /** + * Utility to create an instance of {@Link DataStallDetectionStats} + * + * @hide + */ + public static class Builder { + @Nullable + private byte[] mCellularInfo; + @Nullable + private byte[] mWifiInfo; + @NonNull + private final List mDnsReturnCode = new ArrayList(); + @NonNull + private final List mDnsTimeStamp = new ArrayList(); + private int mEvaluationType; + private int mNetworkType; + + /** + * Add a dns event into Builder. + * + * @param code the return code of the dns event. + * @param timeMs the elapsedRealtime in ms that the the dns event was received from netd. + * @return {@code this} {@link Builder} instance. + */ + public Builder addDnsEvent(int code, long timeMs) { + mDnsReturnCode.add(code); + mDnsTimeStamp.add(timeMs); + return this; + } + + /** + * Set the dns evaluation type into Builder. + * + * @param type the return code of the dns event. + * @return {@code this} {@link Builder} instance. + */ + public Builder setEvaluationType(int type) { + mEvaluationType = type; + return this; + } + + /** + * Set the network type into Builder. + * + * @param type the network type of the logged network. + * @return {@code this} {@link Builder} instance. + */ + public Builder setNetworkType(int type) { + mNetworkType = type; + return this; + } + + /** + * Set the wifi data into Builder. + * + * @param info a {@link WifiInfo} of the connected wifi network. + * @return {@code this} {@link Builder} instance. + */ + public Builder setWiFiData(@Nullable final WifiInfo info) { + WifiData data = new WifiData(); + data.wifiBand = getWifiBand(info); + data.signalStrength = (info != null) ? info.getRssi() : UNKNOWN_SIGNAL_STRENGTH; + mWifiInfo = MessageNano.toByteArray(data); + return this; + } + + private static int getWifiBand(@Nullable final WifiInfo info) { + if (info == null) return DataStallEventProto.AP_BAND_UNKNOWN; + + int freq = info.getFrequency(); + // Refer to ScanResult.is5GHz() and ScanResult.is24GHz(). + if (freq > 4900 && freq < 5900) { + return DataStallEventProto.AP_BAND_5GHZ; + } else if (freq > 2400 && freq < 2500) { + return DataStallEventProto.AP_BAND_2GHZ; + } else { + return DataStallEventProto.AP_BAND_UNKNOWN; + } + } + + /** + * Set the cellular data into Builder. + * + * @param radioType the radio technology of the logged cellular network. + * @param roaming a boolean indicates if logged cellular network is roaming or not. + * @param networkMccmnc the mccmnc of the camped network. + * @param simMccmnc the mccmnc of the sim. + * @return {@code this} {@link Builder} instance. + */ + public Builder setCellData(int radioType, boolean roaming, + @NonNull String networkMccmnc, @NonNull String simMccmnc, int ss) { + CellularData data = new CellularData(); + data.ratType = radioType; + data.isRoaming = roaming; + data.networkMccmnc = networkMccmnc; + data.simMccmnc = simMccmnc; + data.signalStrength = ss; + mCellularInfo = MessageNano.toByteArray(data); + return this; + } + + /** + * Create a new {@Link DataStallDetectionStats}. + */ + public DataStallDetectionStats build() { + return new DataStallDetectionStats(mCellularInfo, mWifiInfo, + NetworkStackUtils.convertToIntArray(mDnsReturnCode), + NetworkStackUtils.convertToLongArray(mDnsTimeStamp), + mEvaluationType, mNetworkType); + } + } +} diff --git a/packages/NetworkStack/src/com/android/networkstack/metrics/DataStallStatsUtils.java b/packages/NetworkStack/src/com/android/networkstack/metrics/DataStallStatsUtils.java new file mode 100644 index 000000000000..93089017fd47 --- /dev/null +++ b/packages/NetworkStack/src/com/android/networkstack/metrics/DataStallStatsUtils.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.networkstack.metrics; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.net.captiveportal.CaptivePortalProbeResult; +import android.util.Log; + +import com.android.internal.util.HexDump; +import com.android.server.connectivity.nano.DataStallEventProto; + +/** + * Collection of utilities for data stall metrics. + * + * To see if the logs are properly sent to statsd, execute following command. + * + * $ adb shell cmd stats print-logs + * $ adb logcat | grep statsd OR $ adb logcat -b stats + * + * @hide + */ +public class DataStallStatsUtils { + private static final String TAG = DataStallStatsUtils.class.getSimpleName(); + private static final boolean DBG = false; + + private static int probeResultToEnum(@Nullable final CaptivePortalProbeResult result) { + if (result == null) return DataStallEventProto.INVALID; + + if (result.isSuccessful()) { + return DataStallEventProto.VALID; + } else if (result.isPortal()) { + return DataStallEventProto.PORTAL; + } else if (result.isPartialConnectivity()) { + return DataStallEventProto.PARTIAL; + } else { + return DataStallEventProto.INVALID; + } + } + + /** + * Write the metric to {@link StatsLog}. + */ + public static void write(@NonNull final DataStallDetectionStats stats, + @NonNull final CaptivePortalProbeResult result) { + int validationResult = probeResultToEnum(result); + if (DBG) { + Log.d(TAG, "write: " + stats + " with result: " + validationResult + + ", dns: " + HexDump.toHexString(stats.mDns)); + } + NetworkStackStatsLog.write(NetworkStackStatsLog.DATA_STALL_EVENT, + stats.mEvaluationType, + validationResult, + stats.mNetworkType, + stats.mWifiInfo, + stats.mCellularInfo, + stats.mDns); + } +} diff --git a/packages/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java b/packages/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java index 588dcf2a83f5..2a612503620f 100644 --- a/packages/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java +++ b/packages/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java @@ -65,8 +65,6 @@ import android.net.TrafficStats; import android.net.Uri; import android.net.captiveportal.CaptivePortalProbeResult; import android.net.captiveportal.CaptivePortalProbeSpec; -import android.net.metrics.DataStallDetectionStats; -import android.net.metrics.DataStallStatsUtils; import android.net.metrics.IpConnectivityLog; import android.net.metrics.NetworkEvent; import android.net.metrics.ValidationProbeEvent; @@ -101,6 +99,8 @@ import com.android.internal.util.RingBufferIndices; import com.android.internal.util.State; import com.android.internal.util.StateMachine; import com.android.networkstack.R; +import com.android.networkstack.metrics.DataStallDetectionStats; +import com.android.networkstack.metrics.DataStallStatsUtils; import java.io.IOException; import java.net.HttpURLConnection; diff --git a/packages/NetworkStack/tests/src/com/android/server/connectivity/NetworkMonitorTest.java b/packages/NetworkStack/tests/src/com/android/server/connectivity/NetworkMonitorTest.java index fa41284317bb..910bdc7e600f 100644 --- a/packages/NetworkStack/tests/src/com/android/server/connectivity/NetworkMonitorTest.java +++ b/packages/NetworkStack/tests/src/com/android/server/connectivity/NetworkMonitorTest.java @@ -59,8 +59,6 @@ import android.net.Network; import android.net.NetworkCapabilities; import android.net.NetworkInfo; import android.net.captiveportal.CaptivePortalProbeResult; -import android.net.metrics.DataStallDetectionStats; -import android.net.metrics.DataStallStatsUtils; import android.net.metrics.IpConnectivityLog; import android.net.util.SharedLog; import android.net.wifi.WifiInfo; @@ -78,6 +76,9 @@ import android.util.ArrayMap; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; +import com.android.networkstack.metrics.DataStallDetectionStats; +import com.android.networkstack.metrics.DataStallStatsUtils; + import org.junit.After; import org.junit.Before; import org.junit.Test; -- cgit v1.2.3-59-g8ed1b