Merge "Update the transport types of metrics" am: 70be96ffbf am: 49620a7f08

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1884199

Change-Id: I167c4c4608c3f26aeb02a1c89d7b873bb0d074a4
This commit is contained in:
Lucas Lin
2021-12-06 02:40:35 +00:00
committed by Automerger Merge Worker

View File

@@ -171,25 +171,28 @@ public class NetdEventListenerService extends INetdEventListener.Stub {
} }
private NetworkMetrics getMetricsForNetwork(long timeMs, int netId) { private NetworkMetrics getMetricsForNetwork(long timeMs, int netId) {
collectPendingMetricsSnapshot(timeMs);
NetworkMetrics metrics = mNetworkMetrics.get(netId); NetworkMetrics metrics = mNetworkMetrics.get(netId);
if (metrics == null) { final NetworkCapabilities nc = mCallback.getNetworkCapabilities(netId);
// TODO: allow to change transport for a given netid. final long transports = (nc != null) ? BitUtils.packBits(nc.getTransportTypes()) : 0;
metrics = new NetworkMetrics(netId, getTransports(netId), mConnectTb); final boolean forceCollect =
(metrics != null && nc != null && metrics.transports != transports);
collectPendingMetricsSnapshot(timeMs, forceCollect);
if (metrics == null || forceCollect) {
metrics = new NetworkMetrics(netId, transports, mConnectTb);
mNetworkMetrics.put(netId, metrics); mNetworkMetrics.put(netId, metrics);
} }
return metrics; return metrics;
} }
private NetworkMetricsSnapshot[] getNetworkMetricsSnapshots() { private NetworkMetricsSnapshot[] getNetworkMetricsSnapshots() {
collectPendingMetricsSnapshot(System.currentTimeMillis()); collectPendingMetricsSnapshot(System.currentTimeMillis(), false /* forceCollect */);
return mNetworkMetricsSnapshots.toArray(); return mNetworkMetricsSnapshots.toArray();
} }
private void collectPendingMetricsSnapshot(long timeMs) { private void collectPendingMetricsSnapshot(long timeMs, boolean forceCollect) {
// Detects time differences larger than the snapshot collection period. // Detects time differences larger than the snapshot collection period.
// This is robust against clock jumps and long inactivity periods. // This is robust against clock jumps and long inactivity periods.
if (Math.abs(timeMs - mLastSnapshot) <= METRICS_SNAPSHOT_SPAN_MS) { if (!forceCollect && Math.abs(timeMs - mLastSnapshot) <= METRICS_SNAPSHOT_SPAN_MS) {
return; return;
} }
mLastSnapshot = projectSnapshotTime(timeMs); mLastSnapshot = projectSnapshotTime(timeMs);
@@ -394,14 +397,6 @@ public class NetdEventListenerService extends INetdEventListener.Stub {
return list; return list;
} }
private long getTransports(int netId) {
final NetworkCapabilities nc = mCallback.getNetworkCapabilities(netId);
if (nc == null) {
return 0;
}
return BitUtils.packBits(nc.getTransportTypes());
}
/** Helper class for buffering summaries of NetworkMetrics at regular time intervals */ /** Helper class for buffering summaries of NetworkMetrics at regular time intervals */
static class NetworkMetricsSnapshot { static class NetworkMetricsSnapshot {