Skip to content
Commit 879c0eb0 authored by Lorenzo Colitti's avatar Lorenzo Colitti
Browse files

Refactor the Nat464Xlat function for simplicity.

This makes the code easier to understand by making state
transitions more explicit. It also makes it easier to address a
TODO to turn the class into a StateMachine.

This should be an exact no-op refactoring. The current cases
covered by the code (all mutually exclusive) are:

1. requiresClat && !isPrefixDiscoveryStarted
   Action: startPrefixDiscovery()
   Equivalent to IDLE && requiresClat, because
   isPrefixDiscoveryStarted returns true for every state except
   IDLE.

2. requiresClat && isPrefixDiscoveryStarted && shouldStartClat
   Action: start()
   Equivalent to DISCOVERING && shouldStartClat,
   because isPrefixDiscoveryStarted is true in DISCOVERING,
   STARTING, and RUNNING, but start() does nothing if mState is
   STARTING or RUNNING.

3. requiresClat && isPrefixDiscoveryStarted && !shouldStartClat
   Action: stop()
   Equivalent to (STARTING or RUNNING) && !shouldStartClat,
   because isPrefixDiscoveryStarted is true in DISCOVERING,
   STARTING, and RUNNING, but stop() does nothing if mState is
   not STARTING or RUNNING.

4. !requiresClat && isStarted
   Action: stop()
   Equivalent to (STARTING or RUNNING) && !requiresClat,
   because isStarted() is only true in STARTING and RUNNING.

5. !requiresClat && !isStarted && isPrefixDiscoveryStarted
   Action: leaveStartedState()
   Equivalent to DISCOVERING && !requiresClat, because
   the only state with isPrefixDiscoveryStarted and !isStarted
   is DISCOVERING.

Also, simplify case #5. In this case, calling leaveStartedState
is superfluous, because in the DISCOVERING state:
- There is no need to call unregisterObserver, since the observer
  is only registered when entering STARTING and is unregistered
  when going back to DISCOVERING or IDLE.
- mIface and mBaseIface don't need to be set to null because they
  are only set to non-null when entering STARTING and nulled out
  when going back to DISCOVERING or IDLE.

Bug: 126113090
Bug: 150648313
Test: covered by existing ConnectivityServiceTest and Nat464XlatTest
Merged-In: Ice536bcb269cc8b040c6e7a72c15d0bc8b5bd235
Change-Id: Ice536bcb269cc8b040c6e7a72c15d0bc8b5bd235
parent a775f45d
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment