From 592c60559623280b57636b3def687d6fb9f31d7a Mon Sep 17 00:00:00 2001 From: junyulai Date: Wed, 29 Apr 2020 16:09:01 +0800 Subject: [PATCH] [SM17] Remove ratType field in MobileBytesTransfer(ByFgBg) Currently, ratType field has been added into MobileBytesTransfer(ByFgBg) atoms. However, add such dimension is not backward compatible since callers might expect a complete NetworkStats for specific uid in the metrics, but actually the NetworkStats were distributed into metrics with different ratType. This change provide minimum modification that reverts the behavior of MobileBytesTransfer, but related APIs will be needed in subsequent changes. Test: adb shell cmd stats pull-source 10000~10003 Test: atest android.cts.statsd.atom.UidAtomTests#testMobileBytesTransfer Test: atest android.cts.statsd.atom.UidAtomTests#testMobileBytesTransferByFgBg Bug: 129082217 Change-Id: I591f9fff2322c343479eb8587f14e48f878080b4 --- cmds/statsd/src/atoms.proto | 4 -- .../stats/pull/StatsPullAtomService.java | 41 ++++++++----------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto index 1f090fda2ce76..602fcc3c7af65 100644 --- a/cmds/statsd/src/atoms.proto +++ b/cmds/statsd/src/atoms.proto @@ -4872,8 +4872,6 @@ message MobileBytesTransfer { optional int64 tx_bytes = 4; optional int64 tx_packets = 5; - - optional int32 rat_type = 6; } /** @@ -4896,8 +4894,6 @@ message MobileBytesTransferByFgBg { optional int64 tx_bytes = 5; optional int64 tx_packets = 6; - - optional int32 rat_type = 7; } /** diff --git a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java index 288c22a94b453..f59debc1c4248 100644 --- a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java +++ b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java @@ -21,7 +21,7 @@ import static android.app.AppOpsManager.OP_FLAG_TRUSTED_PROXY; import static android.app.usage.NetworkStatsManager.FLAG_AUGMENT_WITH_SUBSCRIPTION_PLAN; import static android.content.pm.PackageInfo.REQUESTED_PERMISSION_GRANTED; import static android.content.pm.PermissionInfo.PROTECTION_DANGEROUS; -import static android.net.NetworkTemplate.getAllCollapsedRatTypes; +import static android.net.NetworkTemplate.NETWORK_TYPE_ALL; import static android.os.Debug.getIonHeapsSizeKb; import static android.os.Process.getUidForPid; import static android.os.storage.VolumeInfo.TYPE_PRIVATE; @@ -722,27 +722,25 @@ public class StatsPullAtomService extends SystemService { int atomTag, @NonNull List pulledData, boolean withFgbg) { final NetworkTemplate template = NetworkTemplate.buildTemplateWifiWildcard(); final NetworkStats stats = getUidNetworkStatsSinceBoot(template, withFgbg); - if (stats != null) { - addNetworkStats(atomTag, pulledData, stats, withFgbg, 0 /* ratType */); - return StatsManager.PULL_SUCCESS; - } - return StatsManager.PULL_SKIP; + + // Return with PULL_SKIP to indicate there is an error. + if (stats == null) return StatsManager.PULL_SKIP; + + addNetworkStats(atomTag, pulledData, stats, withFgbg, 0 /* ratType */); + return StatsManager.PULL_SUCCESS; } private int pullMobileBytesTransfer( int atomTag, @NonNull List pulledData, boolean withFgbg) { - int ret = StatsManager.PULL_SKIP; - for (final int ratType : getAllCollapsedRatTypes()) { - final NetworkTemplate template = - NetworkTemplate.buildTemplateMobileWithRatType(null, ratType); - final NetworkStats stats = getUidNetworkStatsSinceBoot(template, withFgbg); - if (stats != null) { - addNetworkStats(atomTag, pulledData, stats, withFgbg, ratType); - ret = StatsManager.PULL_SUCCESS; // If any of them is not null, then success. - } - } - // If there is no data return PULL_SKIP to avoid wasting performance adding empty stats. - return ret; + final NetworkTemplate template = + NetworkTemplate.buildTemplateMobileWithRatType(null, NETWORK_TYPE_ALL); + final NetworkStats stats = getUidNetworkStatsSinceBoot(template, withFgbg); + + // Return with PULL_SKIP to indicate there is an error. + if (stats == null) return StatsManager.PULL_SKIP; + + addNetworkStats(atomTag, pulledData, stats, withFgbg, NETWORK_TYPE_ALL); + return StatsManager.PULL_SUCCESS; } private void addNetworkStats(int atomTag, @NonNull List ret, @@ -762,13 +760,6 @@ public class StatsPullAtomService extends SystemService { e.writeLong(entry.rxPackets); e.writeLong(entry.txBytes); e.writeLong(entry.txPackets); - switch (atomTag) { - case FrameworkStatsLog.MOBILE_BYTES_TRANSFER: - case FrameworkStatsLog.MOBILE_BYTES_TRANSFER_BY_FG_BG: - e.writeInt(ratType); - break; - default: - } ret.add(e.build()); } }