mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 768597 Fall back to getting mac address using wifiman on older versions of Android;r=jmaher
This commit is contained in:
parent
61af7a9160
commit
47e4bd5c90
@ -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,25 +126,41 @@ public class SUTAgentAndroid extends Activity
|
||||
setUpNetwork(sIniFile);
|
||||
|
||||
String macAddress = "Unknown";
|
||||
try {
|
||||
NetworkInterface iface = NetworkInterface.getByInetAddress(InetAddress.getAllByName(getLocalIpAddress())[0]);
|
||||
if (iface != null)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
if (android.os.Build.VERSION.SDK_INT > 8) {
|
||||
try {
|
||||
NetworkInterface iface = NetworkInterface.getByInetAddress(InetAddress.getAllByName(getLocalIpAddress())[0]);
|
||||
if (iface != null)
|
||||
{
|
||||
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) {}
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user