Fix the race between ip reachability and provisioning failure.

Per current implementation an IP provisioning failure event failure
from the legacy IpClientCallbacks instance immediately after IP
reachability failure event will still trigger wifi disconnection,
for example:

    - IpClient sends onReachabilityFailure callback, wifi receives the
      callback and posts CMD_IP_REACHABILITY_FAILURE, then returns;
    - IpClient sends an immediate onProvisioningFailure callback, wifi
      receives the callback and posts CMD_IP_CONFIGURATION_LOST, then
      returns;
    - state machine processes CMD_IP_REACHABILITY_FAILURE first and
      eventually transition to WaitBeforeL3ProvisioningState and
      recreates an IpClient instance there.
    - state machine receives CMD_IP_CONFIGURATION_LOST from message
      queue at WaitBeforeL3ProvisioningState, but defers the command to
      its parent state when transition to L3ProvisioningState.
    - CMD_IP_CONFIGURATION_LOST is processed at L2ConnectedState
      eventually, and triggers WiFi disconnection there.

This patch fixes the race by assoicating an integer token with each
IpClientCallbacks instance, check if the posted messages come from the
current instance by comparing the token.

Bug: 286338765
Test: atest com.android.server.wifi
Change-Id: I7002849b97e82f8ed5d4fac662fcf594c5ce5c59
2 files changed