[SP26.2] add a method in NetworkStats that removes empty entries am: 5d9bc0c75e am: ba57ab6eb9

Change-Id: I388b1d3677d362da2595739913880efa9a643a03
This commit is contained in:
junyulai
2020-04-02 02:40:42 +00:00
committed by Automerger Merge Worker

View File

@@ -1195,18 +1195,24 @@ public final class NetworkStats implements Parcelable {
/** /**
* Remove all rows that match one of specified UIDs. * Remove all rows that match one of specified UIDs.
* This mutates the original structure in place.
* @hide * @hide
*/ */
public void removeUids(int[] uids) { public void removeUids(int[] uids) {
int nextOutputEntry = 0; filter(e -> !ArrayUtils.contains(uids, e.uid));
for (int i = 0; i < size; i++) {
if (!ArrayUtils.contains(uids, uid[i])) {
maybeCopyEntry(nextOutputEntry, i);
nextOutputEntry++;
}
} }
size = nextOutputEntry; /**
* Remove all rows that match one of specified UIDs.
* @return the result object.
* @hide
*/
@NonNull
public NetworkStats removeEmptyEntries() {
final NetworkStats ret = this.clone();
ret.filter(e -> e.rxBytes != 0 || e.rxPackets != 0 || e.txBytes != 0 || e.txPackets != 0
|| e.operations != 0);
return ret;
} }
/** /**