bug 768957 - Make SUTAgent able to get MAC address from ethernet connection. r=ctalbert

This commit is contained in:
Ted Mielczarek 2012-06-29 14:39:15 -04:00
Родитель e3271824f0
Коммит b770060b2d
1 изменённых файлов: 19 добавлений и 10 удалений

Просмотреть файл

@ -10,7 +10,9 @@ 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.util.Enumeration;
import java.util.Formatter;
import java.util.List;
import java.util.Timer;
@ -122,19 +124,26 @@ public class SUTAgentAndroid extends Activity
if (getLocalIpAddress() == null)
setUpNetwork(sIniFile);
WifiInfo wifi;
WifiManager wifiMan = (WifiManager)getSystemService(Context.WIFI_SERVICE);
String macAddress = "Unknown";
if (wifiMan != null)
{
wifi = wifiMan.getConnectionInfo();
if (wifi != null)
try {
NetworkInterface iface = NetworkInterface.getByInetAddress(InetAddress.getAllByName(getLocalIpAddress())[0]);
if (iface != null)
{
macAddress = wifi.getMacAddress();
if (macAddress != null)
sUniqueID = macAddress;
byte[] mac = iface.getHardwareAddress();
if (mac != null)
{
StringBuilder sb = new StringBuilder();
Formatter f = new Formatter(sb);
for (int i = 0; i < mac.length; i++)
{
f.format("%02x%s", mac[i], (i < mac.length - 1) ? ":" : "");
}
macAddress = sUniqueID = sb.toString();
}
}
}
}
catch (UnknownHostException ex) {}
catch (SocketException ex) {}
if (sUniqueID == null)
{