Hold wifi and mobile interfaces since boot in NetworkStatsService

In current design, the interface will be removed from the list if
the network disconnected which will cause getUidStatsForTransport()
returns unexpected snapshot to caller since the list is empty.

This change also remove interface name from all entries before
the method returns the result.

Bug: 231514741
Test: FrameworksNetTests
      manual test
Change-Id: Ie60829a65d0d9b5b63ad353695a820c0586e3665
Merged-In: Ie60829a65d0d9b5b63ad353695a820c0586e3665
This commit is contained in:
Aaron Huang
2022-06-01 23:48:29 +08:00
parent 9424810659
commit f4f5de3993
3 changed files with 70 additions and 15 deletions

View File

@@ -1299,6 +1299,17 @@ public final class NetworkStats implements Parcelable, Iterable<NetworkStats.Ent
return ret;
}
/**
* Removes the interface name from all entries.
* This mutates the original structure in place.
* @hide
*/
public void clearInterfaces() {
for (int i = 0; i < size; i++) {
iface[i] = null;
}
}
/**
* Only keep entries that match all specified filters.
*