Fix some IpV4-only code.

InterfaceConfiguration changed to use InetAddress and stop with the string->int->string
conversions.

bug:2542681
Change-Id: I11c4954547333c43bb840fa0469ddde57b0d043b
diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java
index 8dbd3e7..4290ce7 100644
--- a/services/java/com/android/server/NetworkManagementService.java
+++ b/services/java/com/android/server/NetworkManagementService.java
@@ -219,28 +219,6 @@
         }
     }
 
-    private static int stringToIpAddr(String addrString) throws UnknownHostException {
-        try {
-            String[] parts = addrString.split("\\.");
-            if (parts.length != 4) {
-                throw new UnknownHostException(addrString);
-            }
-
-            int a = Integer.parseInt(parts[0]) << 24;
-            int b = Integer.parseInt(parts[1]) << 16;
-            int c = Integer.parseInt(parts[2]) <<  8;
-            int d = Integer.parseInt(parts[3])      ;
-
-            return a | b | c | d;
-        } catch (NumberFormatException ex) {
-            throw new UnknownHostException(addrString);
-        }
-    }
-
-    public static String intToIpString(int i) {
-        return ((i >> 24 ) & 0xFF) + "." + ((i >> 16 ) & 0xFF) + "." + ((i >>  8 ) & 0xFF) + "." +
-               (i & 0xFF);
-    }
 
     //
     // INetworkManagementService members
@@ -288,18 +266,17 @@
             cfg = new InterfaceConfiguration();
             cfg.hwAddr = st.nextToken(" ");
             try {
-                cfg.ipAddr = stringToIpAddr(st.nextToken(" "));
+                cfg.addr = InetAddress.getByName(st.nextToken(" "));
             } catch (UnknownHostException uhe) {
                 Slog.e(TAG, "Failed to parse ipaddr", uhe);
-                cfg.ipAddr = 0;
             }
 
             try {
-                cfg.netmask = stringToIpAddr(st.nextToken(" "));
+                cfg.mask = InetAddress.getByName(st.nextToken(" "));
             } catch (UnknownHostException uhe) {
                 Slog.e(TAG, "Failed to parse netmask", uhe);
-                cfg.netmask = 0;
             }
+
             cfg.interfaceFlags = st.nextToken("]").trim() +"]";
         } catch (NoSuchElementException nsee) {
             throw new IllegalStateException(
@@ -312,7 +289,8 @@
     public void setInterfaceConfig(
             String iface, InterfaceConfiguration cfg) throws IllegalStateException {
         String cmd = String.format("interface setcfg %s %s %s %s", iface,
-                intToIpString(cfg.ipAddr), intToIpString(cfg.netmask), cfg.interfaceFlags);
+                cfg.addr.getHostAddress(), cfg.mask.getHostAddress(),
+                cfg.interfaceFlags);
         try {
             mConnector.doCommand(cmd);
         } catch (NativeDaemonConnectorException e) {
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index 07813b0..ff703fd 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -58,6 +58,7 @@
 import android.text.TextUtils;
 import android.util.Slog;
 
+import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
@@ -347,8 +348,8 @@
                         ifcg = service.getInterfaceConfig(intf);
                         if (ifcg != null) {
                             /* IP/netmask: 192.168.43.1/255.255.255.0 */
-                            ifcg.ipAddr = (192 << 24) + (168 << 16) + (43 << 8) + 1;
-                            ifcg.netmask = (255 << 24) + (255 << 16) + (255 << 8) + 0;
+                            ifcg.addr = InetAddress.getByName("192.168.43.1");
+                            ifcg.mask = InetAddress.getByName("255.255.255.0");
                             ifcg.interfaceFlags = "[up]";
 
                             service.setInterfaceConfig(intf, ifcg);
diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java
index 75a0e82..d742d4c 100644
--- a/services/java/com/android/server/connectivity/Tethering.java
+++ b/services/java/com/android/server/connectivity/Tethering.java
@@ -51,6 +51,7 @@
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
+import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedList;
@@ -585,16 +586,8 @@
                 try {
                     ifcg = service.getInterfaceConfig(iface);
                     if (ifcg != null) {
-                        String[] addr = USB_NEAR_IFACE_ADDR.split("\\.");
-                        ifcg.ipAddr = (Integer.parseInt(addr[0]) << 24) +
-                                (Integer.parseInt(addr[1]) << 16) +
-                                (Integer.parseInt(addr[2]) << 8) +
-                                (Integer.parseInt(addr[3]));
-                        addr = USB_NETMASK.split("\\.");
-                        ifcg.netmask = (Integer.parseInt(addr[0]) << 24) +
-                                (Integer.parseInt(addr[1]) << 16) +
-                                (Integer.parseInt(addr[2]) << 8) +
-                                (Integer.parseInt(addr[3]));
+                        ifcg.addr = InetAddress.getByName(USB_NEAR_IFACE_ADDR);
+                        ifcg.mask = InetAddress.getByName(USB_NETMASK);
                         if (enabled) {
                             ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
                         } else {