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

Commit 3be1d54c authored by Vova Sharaienko's avatar Vova Sharaienko
Browse files

Added max stats guardrail for AggregatedMobileDataStatsPuller

Bug: 309512867
Test: adb shell cmd stats print-stats | grep 10204
Change-Id: Ic2bbe335e2658eaae929ec33c874fc14310ff3c4
parent c53f952f
Loading
Loading
Loading
Loading
+20 −9
Original line number Diff line number Diff line
@@ -125,6 +125,11 @@ class AggregatedMobileDataStatsPuller {
    @GuardedBy("mLock")
    private final Map<UidProcState, MobileDataStats> mUidStats;

    // No reason to keep more dimensions than 3000. The 3000 is the hard top for the statsd metrics
    // dimensions guardrail. It also will keep the result binder transaction size capped to
    // approximately 220kB for 3000 atoms
    private static final int UID_STATS_MAX_SIZE = 3000;

    private final SparseIntArray mUidPreviousState;

    private NetworkStats mLastMobileUidStats = new NetworkStats(0, -1);
@@ -188,15 +193,19 @@ class AggregatedMobileDataStatsPuller {
        }

        final UidProcState statsKey = new UidProcState(uid, previousState);
        MobileDataStats stats;
        if (mUidStats.containsKey(statsKey)) {
            stats = mUidStats.get(statsKey);
        } else {
            stats = new MobileDataStats();
            mUidStats.put(statsKey, stats);
            return mUidStats.get(statsKey);
        }
        if (mUidStats.size() < UID_STATS_MAX_SIZE) {
            MobileDataStats stats = new MobileDataStats();
            mUidStats.put(statsKey, stats);
            return stats;
        }
        if (DEBUG) {
            Slog.w(TAG, "getUidStatsForPreviousStateLocked() UID_STATS_MAX_SIZE reached");
        }
        return null;
    }

    private void noteUidProcessStateImpl(int uid, int state) {
        if (mRateLimiter.tryAcquire()) {
@@ -252,6 +261,7 @@ class AggregatedMobileDataStatsPuller {
                    continue;
                }
                MobileDataStats stats = getUidStatsForPreviousStateLocked(entry.getUid());
                if (stats != null) {
                    stats.addTxBytes(entry.getTxBytes());
                    stats.addRxBytes(entry.getRxBytes());
                    stats.addTxPackets(entry.getTxPackets());
@@ -259,6 +269,7 @@ class AggregatedMobileDataStatsPuller {
                }
            }
        }
    }

    @GuardedBy("mLock")
    private int pullDataBytesTransferLocked(List<StatsEvent> pulledData) {