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

Commit 88f89a0f authored by junyulai's avatar junyulai Committed by Junyu Lai
Browse files

[SP24] Rename functions that add Entry unconditionally

Currently, in NetworkStats, there are many methods to manipulate
the records. However, some methods are similar and ambiguous,
such as addEntry, addValues, setValues, addIfaceValues,
combineValues and combineAllValues.

Thus, properly grouping and renaming methods are necessary.
In this change, for methods that add one record unconditionally,
name them insertEntry.
  setIfaceValues -> insertEntry
  addEntry -> insertEntry

Test: atest FrameworksNetTests ImsPhoneCallTrackerTest TetheringTests
Test: m doc-comment-check-docs
Bug: 148895143
Change-Id: I801ddc49e283a254b9586700c9b597c0adb0d459
Merged-In: I801ddc49e283a254b9586700c9b597c0adb0d459
(cherry picked from aosp/1256352)
parent 90a118d4
Loading
Loading
Loading
Loading
+12 −12
Original line number Original line Diff line number Diff line
@@ -503,7 +503,7 @@ public final class NetworkStats implements Parcelable {
        NetworkStats.Entry entry = null;
        NetworkStats.Entry entry = null;
        for (int i = 0; i < size; i++) {
        for (int i = 0; i < size; i++) {
            entry = getValues(i, entry);
            entry = getValues(i, entry);
            clone.addEntry(entry);
            clone.insertEntry(entry);
        }
        }
        return clone;
        return clone;
    }
    }
@@ -530,26 +530,26 @@ public final class NetworkStats implements Parcelable {


    /** @hide */
    /** @hide */
    @VisibleForTesting
    @VisibleForTesting
    public NetworkStats addIfaceValues(
    public NetworkStats insertEntry(
            String iface, long rxBytes, long rxPackets, long txBytes, long txPackets) {
            String iface, long rxBytes, long rxPackets, long txBytes, long txPackets) {
        return addEntry(
        return insertEntry(
                iface, UID_ALL, SET_DEFAULT, TAG_NONE, rxBytes, rxPackets, txBytes, txPackets, 0L);
                iface, UID_ALL, SET_DEFAULT, TAG_NONE, rxBytes, rxPackets, txBytes, txPackets, 0L);
    }
    }


    /** @hide */
    /** @hide */
    @VisibleForTesting
    @VisibleForTesting
    public NetworkStats addEntry(String iface, int uid, int set, int tag, long rxBytes,
    public NetworkStats insertEntry(String iface, int uid, int set, int tag, long rxBytes,
            long rxPackets, long txBytes, long txPackets, long operations) {
            long rxPackets, long txBytes, long txPackets, long operations) {
        return addEntry(new Entry(
        return insertEntry(new Entry(
                iface, uid, set, tag, rxBytes, rxPackets, txBytes, txPackets, operations));
                iface, uid, set, tag, rxBytes, rxPackets, txBytes, txPackets, operations));
    }
    }


    /** @hide */
    /** @hide */
    @VisibleForTesting
    @VisibleForTesting
    public NetworkStats addEntry(String iface, int uid, int set, int tag, int metered, int roaming,
    public NetworkStats insertEntry(String iface, int uid, int set, int tag, int metered,
            int defaultNetwork, long rxBytes, long rxPackets, long txBytes, long txPackets,
            int roaming, int defaultNetwork, long rxBytes, long rxPackets, long txBytes,
            long operations) {
            long txPackets, long operations) {
        return addEntry(new Entry(
        return insertEntry(new Entry(
                iface, uid, set, tag, metered, roaming, defaultNetwork, rxBytes, rxPackets,
                iface, uid, set, tag, metered, roaming, defaultNetwork, rxBytes, rxPackets,
                txBytes, txPackets, operations));
                txBytes, txPackets, operations));
    }
    }
@@ -559,7 +559,7 @@ public final class NetworkStats implements Parcelable {
     * object can be recycled across multiple calls.
     * object can be recycled across multiple calls.
     * @hide
     * @hide
     */
     */
    public NetworkStats addEntry(Entry entry) {
    public NetworkStats insertEntry(Entry entry) {
        if (size >= capacity) {
        if (size >= capacity) {
            final int newLength = Math.max(size, 10) * 3 / 2;
            final int newLength = Math.max(size, 10) * 3 / 2;
            iface = Arrays.copyOf(iface, newLength);
            iface = Arrays.copyOf(iface, newLength);
@@ -702,7 +702,7 @@ public final class NetworkStats implements Parcelable {
                entry.roaming, entry.defaultNetwork);
                entry.roaming, entry.defaultNetwork);
        if (i == -1) {
        if (i == -1) {
            // only create new entry when positive contribution
            // only create new entry when positive contribution
            addEntry(entry);
            insertEntry(entry);
        } else {
        } else {
            rxBytes[i] += entry.rxBytes;
            rxBytes[i] += entry.rxBytes;
            rxPackets[i] += entry.rxPackets;
            rxPackets[i] += entry.rxPackets;
@@ -1040,7 +1040,7 @@ public final class NetworkStats implements Parcelable {
                entry.operations = Math.max(entry.operations, 0);
                entry.operations = Math.max(entry.operations, 0);
            }
            }


            result.addEntry(entry);
            result.insertEntry(entry);
        }
        }


        return result;
        return result;
+1 −1
Original line number Original line Diff line number Diff line
@@ -268,7 +268,7 @@ public class BandwidthTest extends InstrumentationTestCase {
        File snd_stat = new File (root_filepath + "tcp_snd");
        File snd_stat = new File (root_filepath + "tcp_snd");
        int tx = BandwidthTestUtil.parseIntValueFromFile(snd_stat);
        int tx = BandwidthTestUtil.parseIntValueFromFile(snd_stat);
        NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 1);
        NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 1);
        stats.addEntry(NetworkStats.IFACE_ALL, uid, NetworkStats.SET_DEFAULT,
        stats.insertEntry(NetworkStats.IFACE_ALL, uid, NetworkStats.SET_DEFAULT,
                NetworkStats.TAG_NONE, rx, 0, tx, 0, 0);
                NetworkStats.TAG_NONE, rx, 0, tx, 0, 0);
        return stats;
        return stats;
    }
    }
+2 −2
Original line number Original line Diff line number Diff line
@@ -54,7 +54,7 @@ public class NetworkStatsBenchmark {
            recycle.txBytes = 150000;
            recycle.txBytes = 150000;
            recycle.txPackets = 1500;
            recycle.txPackets = 1500;
            recycle.operations = 0;
            recycle.operations = 0;
            mNetworkStats.addEntry(recycle);
            mNetworkStats.insertEntry(recycle);
            if (recycle.set == 1) {
            if (recycle.set == 1) {
                uid++;
                uid++;
            }
            }
@@ -70,7 +70,7 @@ public class NetworkStatsBenchmark {
            recycle.txBytes = 180000 * mSize;
            recycle.txBytes = 180000 * mSize;
            recycle.txPackets = 1200 * mSize;
            recycle.txPackets = 1200 * mSize;
            recycle.operations = 0;
            recycle.operations = 0;
            mNetworkStats.addEntry(recycle);
            mNetworkStats.insertEntry(recycle);
        }
        }
    }
    }


+3 −3
Original line number Original line Diff line number Diff line
@@ -229,7 +229,7 @@ public class NetworkStatsFactory {
                    entry.txPackets += reader.nextLong();
                    entry.txPackets += reader.nextLong();
                }
                }


                stats.addEntry(entry);
                stats.insertEntry(entry);
                reader.finishLine();
                reader.finishLine();
            }
            }
        } catch (NullPointerException|NumberFormatException e) {
        } catch (NullPointerException|NumberFormatException e) {
@@ -279,7 +279,7 @@ public class NetworkStatsFactory {
                entry.txBytes = reader.nextLong();
                entry.txBytes = reader.nextLong();
                entry.txPackets = reader.nextLong();
                entry.txPackets = reader.nextLong();


                stats.addEntry(entry);
                stats.insertEntry(entry);
                reader.finishLine();
                reader.finishLine();
            }
            }
        } catch (NullPointerException|NumberFormatException e) {
        } catch (NullPointerException|NumberFormatException e) {
@@ -439,7 +439,7 @@ public class NetworkStatsFactory {
                if ((limitIfaces == null || ArrayUtils.contains(limitIfaces, entry.iface))
                if ((limitIfaces == null || ArrayUtils.contains(limitIfaces, entry.iface))
                        && (limitUid == UID_ALL || limitUid == entry.uid)
                        && (limitUid == UID_ALL || limitUid == entry.uid)
                        && (limitTag == TAG_ALL || limitTag == entry.tag)) {
                        && (limitTag == TAG_ALL || limitTag == entry.tag)) {
                    stats.addEntry(entry);
                    stats.insertEntry(entry);
                }
                }


                reader.finishLine();
                reader.finishLine();
+1 −1
Original line number Original line Diff line number Diff line
@@ -759,7 +759,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
        final NetworkStatsHistory.Entry entry = history.getValues(start, end, now, null);
        final NetworkStatsHistory.Entry entry = history.getValues(start, end, now, null);


        final NetworkStats stats = new NetworkStats(end - start, 1);
        final NetworkStats stats = new NetworkStats(end - start, 1);
        stats.addEntry(new NetworkStats.Entry(IFACE_ALL, UID_ALL, SET_ALL, TAG_NONE,
        stats.insertEntry(new NetworkStats.Entry(IFACE_ALL, UID_ALL, SET_ALL, TAG_NONE,
                METERED_ALL, ROAMING_ALL, DEFAULT_NETWORK_ALL, entry.rxBytes, entry.rxPackets,
                METERED_ALL, ROAMING_ALL, DEFAULT_NETWORK_ALL, entry.rxBytes, entry.rxPackets,
                entry.txBytes, entry.txPackets, entry.operations));
                entry.txBytes, entry.txPackets, entry.operations));
        return stats;
        return stats;
Loading