Clean up class members in Tethering.TetherInterfaceSM

( cherry-pick of 7b30e548a58ac96a23033db43c7aac79c86e938c )

Mark final fields as such.
Group mutex protected fields together with the mutex that protects them.
Always access mutex protected fields under the mutex.

Bug: 28798823
Change-Id: I96cdd5e063babb73e9f124107c5576c47801f34b
Test: Compiles, Wifi tethering continues to work on angler.
diff --git a/services/core/java/com/android/server/connectivity/Tethering.java b/services/core/java/com/android/server/connectivity/Tethering.java
index 7c19736..87dcfd3 100644
--- a/services/core/java/com/android/server/connectivity/Tethering.java
+++ b/services/core/java/com/android/server/connectivity/Tethering.java
@@ -264,7 +264,7 @@
             TetherInterfaceSM sm = mIfaces.get(iface);
             if (up) {
                 if (sm == null) {
-                    sm = new TetherInterfaceSM(iface, mLooper, usb);
+                    sm = new TetherInterfaceSM(iface, mLooper, usb, mPublicSync);
                     mIfaces.put(iface, sm);
                     sm.start();
                 }
@@ -339,7 +339,7 @@
                 if (VDBG) Log.d(TAG, "active iface (" + iface + ") reported as added, ignoring");
                 return;
             }
-            sm = new TetherInterfaceSM(iface, mLooper, usb);
+            sm = new TetherInterfaceSM(iface, mLooper, usb, mPublicSync);
             mIfaces.put(iface, sm);
             sm.start();
         }
@@ -1041,28 +1041,26 @@
         // the upstream connection has changed
         static final int CMD_TETHER_CONNECTION_CHANGED   = BASE_IFACE + 12;
 
-        private State mDefaultState;
+        private final State mInitialState;
+        private final State mStartingState;
+        private final State mTetheredState;
+        private final State mUnavailableState;
 
-        private State mInitialState;
-        private State mStartingState;
-        private State mTetheredState;
+        private final boolean mUsb;
+        private final String mIfaceName;
 
-        private State mUnavailableState;
-
+        private final Object mMutex;  // Protects the fields below.
         private boolean mAvailable;
         private boolean mTethered;
-        int mLastError;
+        private int mLastError;
+        private String mMyUpstreamIfaceName;  // may change over time
 
-        String mIfaceName;
-        String mMyUpstreamIfaceName;  // may change over time
-
-        boolean mUsb;
-
-        TetherInterfaceSM(String name, Looper looper, boolean usb) {
+        TetherInterfaceSM(String name, Looper looper, boolean usb, Object mutex) {
             super(name, looper);
             mIfaceName = name;
             mUsb = usb;
             setLastError(ConnectivityManager.TETHER_ERROR_NO_ERROR);
+            mMutex = mutex;
 
             mInitialState = new InitialState();
             addState(mInitialState);
@@ -1085,20 +1083,20 @@
             if (current == mStartingState) res += "StartingState";
             if (current == mTetheredState) res += "TetheredState";
             if (current == mUnavailableState) res += "UnavailableState";
-            if (mAvailable) res += " - Available";
-            if (mTethered) res += " - Tethered";
-            res += " - lastError =" + mLastError;
+            if (isAvailable()) res += " - Available";
+            if (isTethered()) res += " - Tethered";
+            res += " - lastError =" + getLastError();
             return res;
         }
 
         public int getLastError() {
-            synchronized (Tethering.this.mPublicSync) {
+            synchronized (mMutex) {
                 return mLastError;
             }
         }
 
         private void setLastError(int error) {
-            synchronized (Tethering.this.mPublicSync) {
+            synchronized (mMutex) {
                 mLastError = error;
 
                 if (isErrored()) {
@@ -1112,31 +1110,31 @@
         }
 
         public boolean isAvailable() {
-            synchronized (Tethering.this.mPublicSync) {
+            synchronized (mMutex) {
                 return mAvailable;
             }
         }
 
         private void setAvailable(boolean available) {
-            synchronized (Tethering.this.mPublicSync) {
+            synchronized (mMutex) {
                 mAvailable = available;
             }
         }
 
         public boolean isTethered() {
-            synchronized (Tethering.this.mPublicSync) {
+            synchronized (mMutex) {
                 return mTethered;
             }
         }
 
         private void setTethered(boolean tethered) {
-            synchronized (Tethering.this.mPublicSync) {
+            synchronized (mMutex) {
                 mTethered = tethered;
             }
         }
 
         public boolean isErrored() {
-            synchronized (Tethering.this.mPublicSync) {
+            synchronized (mMutex) {
                 return (mLastError != ConnectivityManager.TETHER_ERROR_NO_ERROR);
             }
         }