Linkproperties update via unsol data call state change.

Handles the scenario of radio technology handover with IP continuity.
Once RIL/Modem finished a handover operation, an unsol data call state
change will be send up to FW notifying all link propertes changes.
FW will then re-configure the device with new link properties
including iptable used by Tethering.

Change-Id: I05e29f66ac3db8ba4274d3662642607742ba1d12
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java
index 9bc7a9f..f88b188 100644
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -1391,6 +1391,12 @@
             } else {
                 addPrivateDnsRoutes(mNetTrackers[netType]);
             }
+
+            /** Notify TetheringService if interface name has been changed. */
+            if (TextUtils.equals(mNetTrackers[netType].getNetworkInfo().getReason(),
+                                 Phone.REASON_LINK_PROPERTIES_CHANGED)) {
+                handleTetherIfaceChange(netType);
+            }
         } else {
             if (mNetConfigs[netType].isDefault()) {
                 removeDefaultRoute(mNetTrackers[netType]);
@@ -2203,6 +2209,14 @@
         }
     }
 
+    private void handleTetherIfaceChange(int type) {
+        String iface = mNetTrackers[type].getLinkProperties().getInterfaceName();
+
+        if (isTetheringSupported()) {
+            mTethering.handleTetherIfaceChange(iface);
+        }
+    }
+
     private void log(String s) {
         Slog.d(TAG, s);
     }
diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java
index 9ff5233..ffadc65 100644
--- a/services/java/com/android/server/connectivity/Tethering.java
+++ b/services/java/com/android/server/connectivity/Tethering.java
@@ -668,6 +668,16 @@
         return retVal;
     }
 
+    public void handleTetherIfaceChange(String iface) {
+        // check if iface is white listed
+        for (String regex : mUpstreamIfaceRegexs) {
+            if (iface.matches(regex)) {
+                if (DEBUG) Log.d(TAG, "Tethering got Interface Change");
+                mTetherMasterSM.sendMessage(TetherMasterSM.CMD_IFACE_CHANGED, iface);
+                break;
+            }
+        }
+    }
 
     class TetherInterfaceSM extends StateMachine {
         // notification from the master SM that it's not in tether mode
@@ -1076,6 +1086,8 @@
         static final int CMD_CELL_CONNECTION_RENEW   = 4;
         // we don't have a valid upstream conn, check again after a delay
         static final int CMD_RETRY_UPSTREAM          = 5;
+        // received an indication that upstream interface has changed
+        static final int CMD_IFACE_CHANGED           = 6;
 
         // This indicates what a timeout event relates to.  A state that
         // sends itself a delayed timeout event and handles incoming timeout events
@@ -1429,13 +1441,18 @@
                             turnOnMobileConnection();
                         }
                         break;
-                   case CMD_RETRY_UPSTREAM:
-                       chooseUpstreamType(mTryCell);
-                       mTryCell = !mTryCell;
-                       break;
-                   default:
-                       retValue = false;
-                       break;
+                    case CMD_RETRY_UPSTREAM:
+                        chooseUpstreamType(mTryCell);
+                        mTryCell = !mTryCell;
+                        break;
+                    case CMD_IFACE_CHANGED:
+                        String iface = (String)message.obj;
+                        if (DEBUG) Log.d(TAG, "Activie upstream interface changed: " + iface);
+                        notifyTetheredOfNewUpstreamIface(iface);
+                        break;
+                    default:
+                        retValue = false;
+                        break;
                 }
                 return retValue;
             }