зеркало из https://github.com/mozilla/pjs.git
bug 768957 - Make SUTAgent able to get MAC address from ethernet connection. r=ctalbert
This commit is contained in:
Родитель
e3271824f0
Коммит
b770060b2d
|
@ -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)
|
||||
try {
|
||||
NetworkInterface iface = NetworkInterface.getByInetAddress(InetAddress.getAllByName(getLocalIpAddress())[0]);
|
||||
if (iface != null)
|
||||
{
|
||||
wifi = wifiMan.getConnectionInfo();
|
||||
if (wifi != null)
|
||||
byte[] mac = iface.getHardwareAddress();
|
||||
if (mac != null)
|
||||
{
|
||||
macAddress = wifi.getMacAddress();
|
||||
if (macAddress != null)
|
||||
sUniqueID = macAddress;
|
||||
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)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче