Make iterating over mNetworkAgentInfos safer.

This CL provides convenience methods to iterate over all
networks.
- forEachNetworkAgentInfo takes a consumer and runs it on all
  networks in mNetworkAgentInfos. The consumer is allowed to
  remove any number of networks. This is needed because some
  loops over mNetworkAgentInfos result in disconnecting networks,
  which removes them from the set.
- anyNetworkAgentInfo takes a predicate and returns true iff it
  returns true on any element in mNetworkAgentInfos. The
  predicate is not allowed to modify the set in any way.

Bug: 288149251
Test: simple refactor, covered by existing unit tests
Change-Id: I5d8b38503895d33abc2d96daaa1c96372befce64
1 file changed