Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 592c6055 authored by junyulai's avatar junyulai
Browse files

[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
parent cde07e5d
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -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;
}

/**
+16 −25
Original line number Diff line number Diff line
@@ -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<StatsEvent> pulledData, boolean withFgbg) {
        final NetworkTemplate template = NetworkTemplate.buildTemplateWifiWildcard();
        final NetworkStats stats = getUidNetworkStatsSinceBoot(template, withFgbg);
        if (stats != null) {

        // 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;
    }
        return StatsManager.PULL_SKIP;
    }

    private int pullMobileBytesTransfer(
            int atomTag, @NonNull List<StatsEvent> pulledData, boolean withFgbg) {
        int ret = StatsManager.PULL_SKIP;
        for (final int ratType : getAllCollapsedRatTypes()) {
        final NetworkTemplate template =
                    NetworkTemplate.buildTemplateMobileWithRatType(null, ratType);
                NetworkTemplate.buildTemplateMobileWithRatType(null, NETWORK_TYPE_ALL);
        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;

        // 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<StatsEvent> 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());
        }
    }