Merge "Fix device address and interface address usage"

This commit is contained in:
repo sync
2011-08-19 16:08:50 -07:00
committed by Android (Google) Code Review
3 changed files with 48 additions and 17 deletions

View File

@@ -304,4 +304,28 @@ public class WifiNative {
return doBooleanCommand("P2P_INVITE group=" + group.getInterface()
+ " peer=" + deviceAddress + " go_dev_addr=" + group.getOwner().deviceAddress);
}
public static String p2pGetInterfaceAddress(String deviceAddress) {
if (deviceAddress == null) return null;
// "p2p_peer deviceAddress" returns a multi-line result containing
// intended_addr=fa:7b:7a:42:82:13
String peerInfo = p2pPeer(deviceAddress);
if (peerInfo == null) return null;
String[] tokens= peerInfo.split("\n");
for (String token : tokens) {
//TODO: update from interface_addr when wpa_supplicant implementation is fixed
if (token.startsWith("intended_addr=")) {
String[] nameValue = token.split("=");
if (nameValue.length != 2) break;
return nameValue[1];
}
}
return null;
}
public static String p2pPeer(String deviceAddress) {
return doStringCommand("P2P_PEER " + deviceAddress);
}
}

View File

@@ -158,9 +158,6 @@ public class WifiP2pDevice implements Parcelable {
return;
}
Pattern p = Pattern.compile("(?:[0-9a-f]{2}:){5}[0-9a-f]{2}", Pattern.CASE_INSENSITIVE);
if (p.matcher(tokens[1]).matches()) interfaceAddress = tokens[1];
for (String token : tokens) {
String[] nameValue = token.split("=");
if (nameValue.length != 2) continue;
@@ -177,6 +174,7 @@ public class WifiP2pDevice implements Parcelable {
if (nameValue[0].equals("name")) {
deviceName = trimQuotes(nameValue[1]);
continue;
}
if (nameValue[0].equals("config_methods")) {
@@ -213,9 +211,7 @@ public class WifiP2pDevice implements Parcelable {
if (other == null || other.deviceAddress == null) {
return (deviceAddress == null);
}
//STOPSHIP: fix later
//return other.deviceAddress.equals(deviceAddress);
return other.deviceAddress.startsWith(deviceAddress.substring(0,8));
return other.deviceAddress.equals(deviceAddress);
}
public String toString() {

View File

@@ -663,17 +663,20 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
if (DBG) Slog.d(TAG, getName() + message.toString());
switch (message.what) {
case WifiMonitor.AP_STA_CONNECTED_EVENT:
String address = (String) message.obj;
mGroup.addClient(address);
updateDeviceStatus(address, Status.CONNECTED);
//After a GO setup, STA connected event comes with interface address
String interfaceAddress = (String) message.obj;
String deviceAddress = getDeviceAddress(interfaceAddress);
mGroup.addClient(deviceAddress);
updateDeviceStatus(deviceAddress, Status.CONNECTED);
if (DBG) Slog.d(TAG, getName() + " ap sta connected");
sendP2pPeersChangedBroadcast();
break;
case WifiMonitor.AP_STA_DISCONNECTED_EVENT:
address = (String) message.obj;
updateDeviceStatus(address, Status.AVAILABLE);
if (mGroup.removeClient(address)) {
if (DBG) Slog.d(TAG, "Removed client " + address);
interfaceAddress = (String) message.obj;
deviceAddress = getDeviceAddress(interfaceAddress);
updateDeviceStatus(deviceAddress, Status.AVAILABLE);
if (mGroup.removeClient(deviceAddress)) {
if (DBG) Slog.d(TAG, "Removed client " + deviceAddress);
if (mGroup.isClientListEmpty()) {
Slog.d(TAG, "Client list empty, killing p2p connection");
sendMessage(WifiP2pManager.REMOVE_GROUP);
@@ -682,7 +685,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
sendP2pPeersChangedBroadcast();
}
} else {
if (DBG) Slog.d(TAG, "Failed to remove client " + address);
if (DBG) Slog.d(TAG, "Failed to remove client " + deviceAddress);
for (WifiP2pDevice c : mGroup.getClientList()) {
if (DBG) Slog.d(TAG,"client " + c.deviceAddress);
}
@@ -1005,12 +1008,20 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
private void updateDeviceStatus(String deviceAddress, Status status) {
for (WifiP2pDevice d : mPeers.getDeviceList()) {
// TODO: fix later
// if (d.deviceAddress.equals(deviceAddress)) {
if (d.deviceAddress.startsWith(deviceAddress.substring(0, 8))) {
if (d.deviceAddress.equals(deviceAddress)) {
d.status = status;
}
}
}
private String getDeviceAddress(String interfaceAddress) {
for (WifiP2pDevice d : mPeers.getDeviceList()) {
if (interfaceAddress.equals(WifiNative.p2pGetInterfaceAddress(d.deviceAddress))) {
return d.deviceAddress;
}
}
return null;
}
}
}