Use the correct host route function in MMS.

Currently, MMS sets up host routes using requestRouteToHost().
This function is deprecated, and takes an int, so MMS has a
lookupHost() function that converts an IP addresses to an int.
lookupHost has a bug that returns corrupt data in the presence
of IPv6 addresses, so MMS doesn't work over IPv6.

Fix this by using the new requestRouteToHostAddress instead of
requestRouteToHost, and delete the function.

This shouldn't break anything, because the result of the lookup
is never used outside the function, it's only passed to
ConnectivityService to set up the host route, so the rest of the
MMS code won't see any change in behaviour.

Bug: 8276725
Change-Id: If6656a33fdea01c6fba178b34ef818d48cf7a395
diff --git a/src/com/android/mms/transaction/Transaction.java b/src/com/android/mms/transaction/Transaction.java
index adc1722..ddfe8df 100644
--- a/src/com/android/mms/transaction/Transaction.java
+++ b/src/com/android/mms/transaction/Transaction.java
@@ -211,57 +211,31 @@
         ConnectivityManager connMgr =
                 (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
 
-        int inetAddr;
+        InetAddress inetAddr;
         if (settings.isProxySet()) {
             String proxyAddr = settings.getProxyAddress();
-            inetAddr = lookupHost(proxyAddr);
-            if (inetAddr == -1) {
-                throw new IOException("Cannot establish route for " + url + ": Unknown host");
-            } else {
-                if (!connMgr.requestRouteToHost(
-                        ConnectivityManager.TYPE_MOBILE_MMS, inetAddr)) {
-                    throw new IOException("Cannot establish route to proxy " + inetAddr);
-                }
+            try {
+              inetAddr = InetAddress.getByName(proxyAddr);
+            } catch (UnknownHostException e) {
+                throw new IOException("Cannot establish route for " + url +
+                                      ": Unknown proxy " + proxyAddr);
+            }
+            if (!connMgr.requestRouteToHostAddress(ConnectivityManager.TYPE_MOBILE_MMS, inetAddr)) {
+                throw new IOException("Cannot establish route to proxy " + inetAddr);
             }
         } else {
             Uri uri = Uri.parse(url);
-            inetAddr = lookupHost(uri.getHost());
-            if (inetAddr == -1) {
+            try {
+                inetAddr = InetAddress.getByName(uri.getHost());
+            } catch (UnknownHostException e) {
                 throw new IOException("Cannot establish route for " + url + ": Unknown host");
-            } else {
-                if (!connMgr.requestRouteToHost(
-                        ConnectivityManager.TYPE_MOBILE_MMS, inetAddr)) {
-                    throw new IOException("Cannot establish route to " + inetAddr + " for " + url);
-                }
+            }
+            if (!connMgr.requestRouteToHostAddress(ConnectivityManager.TYPE_MOBILE_MMS, inetAddr)) {
+                throw new IOException("Cannot establish route to " + inetAddr + " for " + url);
             }
         }
     }
 
-    /**
-     * Look up a host name and return the result as an int. Works if the argument
-     * is an IP address in dot notation. Obviously, this can only be used for IPv4
-     * addresses.
-     * @param hostname the name of the host (or the IP address)
-     * @return the IP address as an {@code int} in network byte order
-     */
-    // TODO: move this to android-common
-    public static int lookupHost(String hostname) {
-        InetAddress inetAddress;
-        try {
-            inetAddress = InetAddress.getByName(hostname);
-        } catch (UnknownHostException e) {
-            return -1;
-        }
-        byte[] addrBytes;
-        int addr;
-        addrBytes = inetAddress.getAddress();
-        addr = ((addrBytes[3] & 0xff) << 24)
-                | ((addrBytes[2] & 0xff) << 16)
-                | ((addrBytes[1] & 0xff) << 8)
-                |  (addrBytes[0] & 0xff);
-        return addr;
-    }
-
     @Override
     public String toString() {
         return getClass().getName() + ": serviceId=" + mServiceId;