Rematch requests first and listens second.

This CL splits rematching in two parts: first rematch requests,
then rematch listens. This will allow us to change a network's
capabilities depending on what requests are on that network, and
properly dispatch callbacks depending on those capabilities.

The behaviour changes are as follows:

- Before this CL, callbacks for requests and listens were sent
  intermingled. After this CL, all request callbacks will be
  grouped together, and all listen callbacks will be grouped
  together.
- Before this CL, the order was:
    1. Send onLost callbacks.
    2. If applicable, switch the default network.
    3. Send onAvailable callbacks.
  After this CL, the order is:
    1. Send onLost callbacks for requests.
    2. If applicable, switch the default network.
    3. Send onLost callbacks for listens.
    4. Send onAvailable callbacks for listens.
    5. Send onAvailable callbacks for requests.

These changes shouldn't affect any apps because:

1. The order of callbacks continues to be first all onLost,
   then all onAvailable.
2. Both the old and the new code send callbacks in no particular
   order. Thus, the possible ordering combinations of callbacks
   in the new code are a strict subset of the possible ordering
   combinations of the old code.
3. The default network is switched before any onAvailable
   callback is sent.
4. Even though the new code does not send all onLost callbacks
   before switching the default network, even before this CL
   there was no guarantee that those callbacks would be received
   before the default network switch anyway, because callbacks
   are asynchronous.

Bug: 23113288
Change-Id: Ia08900c50db9ff43895047e2f4f36b6c6c31a1f9
1 file changed
tree: 5452f2625d9315cc7816eef5f5b99380bda3f20a
  1. core/
  2. services/
  3. tests/