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

Commit 3f991063 authored by Aaron Huang's avatar Aaron Huang Committed by Gerrit Code Review
Browse files

Merge "Remove NetworkStats hidden API dependencies from StatsPullAtomService"

parents fbc849e9 60586e64
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -1168,13 +1168,14 @@ public class StatsPullAtomService extends SystemService {
                Slog.e(TAG, "baseline is null for " + atomTag + ", return.");
                return StatsManager.PULL_SKIP;
            }

            final NetworkStatsExt diff = new NetworkStatsExt(
                    item.stats.subtract(baseline.stats).removeEmptyEntries(), item.transports,
                    removeEmptyEntries(item.stats.subtract(baseline.stats)), item.transports,
                    item.slicedByFgbg, item.slicedByTag, item.slicedByMetered, item.ratType,
                    item.subInfo, item.oemManaged);

            // If no diff, skip.
            if (diff.stats.size() == 0) continue;
            if (!diff.stats.iterator().hasNext()) continue;

            switch (atomTag) {
                case FrameworkStatsLog.BYTES_TRANSFER_BY_TAG_AND_METERED:
@@ -1193,6 +1194,17 @@ public class StatsPullAtomService extends SystemService {
        return StatsManager.PULL_SUCCESS;
    }

    @NonNull private static NetworkStats removeEmptyEntries(NetworkStats stats) {
        NetworkStats ret = new NetworkStats(0, 1);
        for (NetworkStats.Entry e : stats) {
            if (e.getRxBytes() != 0 || e.getRxPackets() != 0 || e.getTxBytes() != 0
                    || e.getTxPackets() != 0 || e.getOperations() != 0) {
                ret = ret.addEntry(e);
            }
        }
        return ret;
    }

    private void addNetworkStats(int atomTag, @NonNull List<StatsEvent> ret,
            @NonNull NetworkStatsExt statsExt) {
        for (NetworkStats.Entry entry : statsExt.stats) {
@@ -1444,12 +1456,8 @@ public class StatsPullAtomService extends SystemService {
    @NonNull private NetworkStats sliceNetworkStats(@NonNull NetworkStats stats,
            @NonNull Function<NetworkStats.Entry, NetworkStats.Entry> slicer) {
        NetworkStats ret = new NetworkStats(0, 1);
        NetworkStats.Entry entry = new NetworkStats.Entry();
        for (NetworkStats.Entry e : stats) {
            if (slicer != null) {
                entry = slicer.apply(e);
            }
            ret = ret.addEntry(entry);
            ret = ret.addEntry(slicer.apply(e));
        }
        return ret;
    }