Bug 768957 - Fall back to getting mac address using wifiman on older versions of Android;r=jmaher

This commit is contained in:
William Lachance 2012-07-11 12:51:44 -04:00
Родитель 404c6d88fc
Коммит 1067ad6676
1 изменённых файлов: 35 добавлений и 18 удалений

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

@ -33,6 +33,7 @@ import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager.WifiLock;
import android.os.BatteryManager;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Handler;
import android.telephony.TelephonyManager;
@ -125,6 +126,7 @@ public class SUTAgentAndroid extends Activity
setUpNetwork(sIniFile);
String macAddress = "Unknown";
if (android.os.Build.VERSION.SDK_INT > 8) {
try {
NetworkInterface iface = NetworkInterface.getByInetAddress(InetAddress.getAllByName(getLocalIpAddress())[0]);
if (iface != null)
@ -144,6 +146,21 @@ public class SUTAgentAndroid extends Activity
}
catch (UnknownHostException ex) {}
catch (SocketException ex) {}
}
else
{
// Fall back to getting info from wifiman on older versions of Android,
// which don't support the NetworkInterface interface
WifiManager wifiMan = (WifiManager)getSystemService(Context.WIFI_SERVICE);
if (wifiMan != null)
{
WifiInfo wifi = wifiMan.getConnectionInfo();
if (wifi != null)
macAddress = wifi.getMacAddress();
if (macAddress != null)
sUniqueID = macAddress;
}
}
if (sUniqueID == null)
{