Bug 1208587 - SUTAgent: Inline isIPv4Address(). r=jmaher
authorSebastian Kaspari <s.kaspari@gmail.com>
Fri, 02 Oct 2015 13:54:28 +0200
changeset 265658 43e9af14107814b83f01a16d13616e6533d47ee3
parent 265657 488526a93c271b7194a816c91a003a021daf862a
child 265659 a2227abb5c3fabf97fc6d5e6df46fa14966306f7
push id15473
push users.kaspari@gmail.com
push dateFri, 02 Oct 2015 11:56:55 +0000
treeherderfx-team@43e9af141078 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1208587
milestone44.0a1
Bug 1208587 - SUTAgent: Inline isIPv4Address(). r=jmaher
build/mobile/sutagent/android/SUTAgentAndroid.java
--- a/build/mobile/sutagent/android/SUTAgentAndroid.java
+++ b/build/mobile/sutagent/android/SUTAgentAndroid.java
@@ -4,26 +4,26 @@
 
 package com.mozilla.SUTAgentAndroid;
 
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.net.InetAddress;
-import org.apache.http.conn.util.InetAddressUtils;
 import java.net.NetworkInterface;
 import java.net.SocketException;
 import java.net.UnknownHostException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Enumeration;
 import java.util.Formatter;
 import java.util.List;
+import java.util.regex.Pattern;
 import java.util.Timer;
 
 import com.mozilla.SUTAgentAndroid.service.ASMozStub;
 import com.mozilla.SUTAgentAndroid.service.DoCommand;
 import android.app.Activity;
 import android.bluetooth.BluetoothAdapter;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -51,16 +51,18 @@ import android.view.View.OnClickListener
 import android.widget.Button;
 import android.widget.TextView;
 import android.widget.Toast;
 
 public class SUTAgentAndroid extends Activity
     {
     final Handler mHandler = new Handler();
 
+    private static final Pattern IPV4_PATTERN = Pattern.compile("^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$");
+
     public static final int START_PRG = 1959;
     MenuItem mExitMenuItem;
     Timer timer = null;
 
     public static String sUniqueID = null;
     public static String sLocalIPAddr = null;
     public static String sACStatus = null;
     public static String sPowerStatus = null;
@@ -805,25 +807,29 @@ public class SUTAgentAndroid extends Act
         if (sHWID != null)
             return sHWID;
 
         sHWID = "0011223344556677";
 
         return sHWID;
     }
 
+    public static boolean isIPv4Address(final String input) {
+        return IPV4_PATTERN.matcher(input).matches();
+    }
+
     public static InetAddress getLocalInetAddress() throws SocketException
         {
         for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();)
             {
             NetworkInterface intf = en.nextElement();
             for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();)
                 {
                 InetAddress inetAddress = enumIpAddr.nextElement();
-                if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress()))
+                if (!inetAddress.isLoopbackAddress() && isIPv4Address(inetAddress.getHostAddress()))
                     {
                         return inetAddress;
                     }
                 }
             }
 
         return null;
         }