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() return doBooleanCommand("P2P_INVITE group=" + group.getInterface()
+ " peer=" + deviceAddress + " go_dev_addr=" + group.getOwner().deviceAddress); + " 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; 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) { for (String token : tokens) {
String[] nameValue = token.split("="); String[] nameValue = token.split("=");
if (nameValue.length != 2) continue; if (nameValue.length != 2) continue;
@@ -177,6 +174,7 @@ public class WifiP2pDevice implements Parcelable {
if (nameValue[0].equals("name")) { if (nameValue[0].equals("name")) {
deviceName = trimQuotes(nameValue[1]); deviceName = trimQuotes(nameValue[1]);
continue;
} }
if (nameValue[0].equals("config_methods")) { if (nameValue[0].equals("config_methods")) {
@@ -213,9 +211,7 @@ public class WifiP2pDevice implements Parcelable {
if (other == null || other.deviceAddress == null) { if (other == null || other.deviceAddress == null) {
return (deviceAddress == null); return (deviceAddress == null);
} }
//STOPSHIP: fix later return other.deviceAddress.equals(deviceAddress);
//return other.deviceAddress.equals(deviceAddress);
return other.deviceAddress.startsWith(deviceAddress.substring(0,8));
} }
public String toString() { public String toString() {

View File

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