Bug 1208587 - SUTAgent: Inline isIPv4Address(). r=jmaher

This commit is contained in:
Sebastian Kaspari 2015-10-02 13:54:28 +02:00
parent 971f0bf482
commit b0f0b82a3a

View File

@ -9,7 +9,6 @@ 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;
@ -19,6 +18,7 @@ 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;
@ -56,6 +56,8 @@ 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;
@ -810,6 +812,10 @@ public class SUTAgentAndroid extends Activity
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();)
@ -818,7 +824,7 @@ public class SUTAgentAndroid extends Activity
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;
}