summaryrefslogtreecommitdiffstats
path: root/wifi/java/android/net
diff options
context:
space:
mode:
authorIrfan Sheriff <isheriff@google.com>2011-12-21 09:26:36 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-12-21 09:26:36 -0800
commitcbc46d145a799121424f677b62a0d438feb4f911 (patch)
treedd1e5c9c52c1004eaea67d85293ec8be6f9215c7 /wifi/java/android/net
parent0f933c9a32dfdc10dbb14fa11c7815541efe22bb (diff)
parentbfed2d6c618e0bf2c271dad1f4acf6d29ebbea51 (diff)
downloadframeworks_base-cbc46d145a799121424f677b62a0d438feb4f911.zip
frameworks_base-cbc46d145a799121424f677b62a0d438feb4f911.tar.gz
frameworks_base-cbc46d145a799121424f677b62a0d438feb4f911.tar.bz2
Merge "p2p fixes"
Diffstat (limited to 'wifi/java/android/net')
-rw-r--r--wifi/java/android/net/wifi/WifiMonitor.java12
-rw-r--r--wifi/java/android/net/wifi/WifiNative.java4
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pDevice.java8
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java13
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pService.java74
5 files changed, 85 insertions, 26 deletions
diff --git a/wifi/java/android/net/wifi/WifiMonitor.java b/wifi/java/android/net/wifi/WifiMonitor.java
index 80963a8..05b8fe1 100644
--- a/wifi/java/android/net/wifi/WifiMonitor.java
+++ b/wifi/java/android/net/wifi/WifiMonitor.java
@@ -196,7 +196,7 @@ public class WifiMonitor {
private static final String P2P_PROV_DISC_SHOW_PIN_STR = "P2P-PROV-DISC-SHOW-PIN";
private static final String HOST_AP_EVENT_PREFIX_STR = "AP";
- /* AP-STA-CONNECTED 42:fc:89:a8:96:09 */
+ /* AP-STA-CONNECTED 42:fc:89:a8:96:09 dev_addr=02:90:4c:a0:92:54 */
private static final String AP_STA_CONNECTED_STR = "AP-STA-CONNECTED";
/* AP-STA-DISCONNECTED 42:fc:89:a8:96:09 */
private static final String AP_STA_DISCONNECTED_STR = "AP-STA-DISCONNECTED";
@@ -504,9 +504,17 @@ public class WifiMonitor {
*/
private void handleHostApEvents(String dataString) {
String[] tokens = dataString.split(" ");
+ /* AP-STA-CONNECTED 42:fc:89:a8:96:09 dev_addr=02:90:4c:a0:92:54 */
if (tokens[0].equals(AP_STA_CONNECTED_STR)) {
- mStateMachine.sendMessage(AP_STA_CONNECTED_EVENT, tokens[1]);
+ String[] nameValue = tokens[2].split("=");
+ if (nameValue.length != 2) return;
+ WifiP2pDevice device = new WifiP2pDevice();
+ device.interfaceAddress = tokens[1];
+ device.deviceAddress = nameValue[1];
+ mStateMachine.sendMessage(AP_STA_CONNECTED_EVENT, device);
+ /* AP-STA-DISCONNECTED 42:fc:89:a8:96:09 */
} else if (tokens[0].equals(AP_STA_DISCONNECTED_STR)) {
+ //TODO: fix this once wpa_supplicant reports this consistently
mStateMachine.sendMessage(AP_STA_DISCONNECTED_EVENT, tokens[1]);
}
}
diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java
index 0fc0a45..4c06558 100644
--- a/wifi/java/android/net/wifi/WifiNative.java
+++ b/wifi/java/android/net/wifi/WifiNative.java
@@ -307,9 +307,11 @@ public class WifiNative {
if (joinExistingGroup) args.add("join");
+ //TODO: This can be adapted based on device plugged in state and
+ //device battery state
int groupOwnerIntent = config.groupOwnerIntent;
if (groupOwnerIntent < 0 || groupOwnerIntent > 15) {
- groupOwnerIntent = 3; //default value
+ groupOwnerIntent = 7; //default value
}
args.add("go_intent=" + groupOwnerIntent);
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java b/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java
index b47e098..7471a2d 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java
@@ -34,12 +34,12 @@ public class WifiP2pDevice implements Parcelable {
/**
* The device name is a user friendly string to identify a Wi-Fi p2p device
*/
- public String deviceName;
+ public String deviceName = "";
/**
* The device MAC address uniquely identifies a Wi-Fi p2p device
*/
- public String deviceAddress;
+ public String deviceAddress = "";
/**
* interfaceAddress
@@ -134,7 +134,7 @@ public class WifiP2pDevice implements Parcelable {
* @hide
*/
public WifiP2pDevice(String string) throws IllegalArgumentException {
- String[] tokens = string.split(" ");
+ String[] tokens = string.split("[ \n]");
if (tokens.length < 1) {
throw new IllegalArgumentException("Malformed supplicant event");
@@ -166,7 +166,7 @@ public class WifiP2pDevice implements Parcelable {
continue;
}
- if (nameValue[0].equals("name")) {
+ if (nameValue[0].equals("name") || nameValue[0].equals("device_name")) {
deviceName = trimQuotes(nameValue[1]);
continue;
}
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java
index 9ce2545..cbb4e81 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java
@@ -80,6 +80,19 @@ public class WifiP2pDeviceList implements Parcelable {
}
/** @hide */
+ public void updateInterfaceAddress(WifiP2pDevice device) {
+ for (WifiP2pDevice d : mDevices) {
+ //Found, update interface address
+ if (d.equals(device)) {
+ d.interfaceAddress = device.interfaceAddress;
+ return;
+ }
+ }
+ //Not found, add a new one
+ mDevices.add(device);
+ }
+
+ /** @hide */
public boolean remove(WifiP2pDevice device) {
if (device == null) return false;
return mDevices.remove(device);
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
index dede1b5..84a4fe0 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
@@ -727,6 +727,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
case WifiP2pManager.CONNECT:
if (DBG) logd(getName() + " sending connect");
mSavedPeerConfig = (WifiP2pConfig) message.obj;
+ String updatedPeerDetails = WifiNative.p2pPeer(mSavedPeerConfig.deviceAddress);
+ mPeers.update(new WifiP2pDevice(updatedPeerDetails));
mPersistGroup = false;
int netId = configuredNetworkId(mSavedPeerConfig.deviceAddress);
if (netId >= 0) {
@@ -736,13 +738,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
//If peer is a GO, we do not need to send provisional discovery,
//the supplicant takes care of it.
if (isGroupOwner(mSavedPeerConfig.deviceAddress)) {
- String pin = WifiNative.p2pConnect(mSavedPeerConfig, JOIN_GROUP);
- try {
- Integer.parseInt(pin);
- notifyInvitationSent(pin, mSavedPeerConfig.deviceAddress);
- } catch (NumberFormatException ignore) {
- // do nothing if p2pConnect did not return a pin
- }
+ p2pConnectWithPinDisplay(mSavedPeerConfig, JOIN_GROUP);
transitionTo(mGroupNegotiationState);
} else {
transitionTo(mProvisionDiscoveryState);
@@ -758,8 +754,27 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
break;
case WifiMonitor.P2P_INVITATION_RECEIVED_EVENT:
WifiP2pGroup group = (WifiP2pGroup) message.obj;
- //TODO: fix p2p invitation to handle as a regular config
- //and update mSavedPeerConfig
+ WifiP2pDevice owner = group.getOwner();
+
+ if (owner == null) {
+ if (DBG) loge("Ignored invitation from null owner");
+ break;
+ }
+
+ mSavedPeerConfig = new WifiP2pConfig();
+ mSavedPeerConfig.deviceAddress = group.getOwner().deviceAddress;
+
+ //Check if we have the owner in peer list and use appropriate
+ //wps method. Default is to use PBC.
+ if ((owner = getDeviceFromPeerList(owner.deviceAddress)) != null) {
+ if (owner.wpsPbcSupported()) {
+ mSavedPeerConfig.wps.setup = WpsInfo.PBC;
+ } else if (owner.wpsKeypadSupported()) {
+ mSavedPeerConfig.wps.setup = WpsInfo.KEYPAD;
+ } else if (owner.wpsDisplaySupported()) {
+ mSavedPeerConfig.wps.setup = WpsInfo.DISPLAY;
+ }
+ }
transitionTo(mUserAuthorizingInvitationState);
break;
case WifiMonitor.P2P_PROV_DISC_PBC_REQ_EVENT:
@@ -853,9 +868,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
case PEER_CONNECTION_USER_ACCEPT:
//TODO: handle persistence
if (isGroupOwner(mSavedPeerConfig.deviceAddress)) {
- WifiNative.p2pConnect(mSavedPeerConfig, JOIN_GROUP);
+ p2pConnectWithPinDisplay(mSavedPeerConfig, JOIN_GROUP);
} else {
- WifiNative.p2pConnect(mSavedPeerConfig, FORM_GROUP);
+ p2pConnectWithPinDisplay(mSavedPeerConfig, FORM_GROUP);
}
updateDeviceStatus(mSavedPeerConfig.deviceAddress, WifiP2pDevice.INVITED);
sendP2pPeersChangedBroadcast();
@@ -1007,20 +1022,22 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
if (DBG) logd(getName() + message.toString());
switch (message.what) {
case WifiMonitor.AP_STA_CONNECTED_EVENT:
- //After a GO setup, STA connected event comes with interface address
- String interfaceAddress = (String) message.obj;
- String deviceAddress = getDeviceAddress(interfaceAddress);
+ WifiP2pDevice device = (WifiP2pDevice) message.obj;
+ String deviceAddress = device.deviceAddress;
if (deviceAddress != null) {
mGroup.addClient(deviceAddress);
+ mPeers.updateInterfaceAddress(device);
updateDeviceStatus(deviceAddress, WifiP2pDevice.CONNECTED);
if (DBG) logd(getName() + " ap sta connected");
sendP2pPeersChangedBroadcast();
} else {
- loge("Connect on unknown device address : " + interfaceAddress);
+ loge("Connect on null device address, ignore");
}
break;
case WifiMonitor.AP_STA_DISCONNECTED_EVENT:
- interfaceAddress = (String) message.obj;
+ //TODO: the disconnection event is still inconsistent and reports
+ //interface address. Fix this after wpa_supplicant is fixed.
+ String interfaceAddress = (String) message.obj;
deviceAddress = getDeviceAddress(interfaceAddress);
if (deviceAddress != null) {
updateDeviceStatus(deviceAddress, WifiP2pDevice.AVAILABLE);
@@ -1039,7 +1056,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
sendP2pPeersChangedBroadcast();
if (DBG) loge(getName() + " ap sta disconnected");
} else {
- loge("Disconnect on unknown device address : " + interfaceAddress);
+ loge("Disconnect on unknown interface address : " + interfaceAddress);
}
break;
case DhcpStateMachine.CMD_POST_DHCP_ACTION:
@@ -1087,7 +1104,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
transitionTo(mInactiveState);
break;
case WifiMonitor.P2P_DEVICE_LOST_EVENT:
- WifiP2pDevice device = (WifiP2pDevice) message.obj;
+ device = (WifiP2pDevice) message.obj;
//Device loss for a connected device indicates it is not in discovery any more
if (mGroup.contains(device)) {
if (DBG) logd("Lost " + device +" , do nothing");
@@ -1388,13 +1405,32 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
private String getDeviceAddress(String interfaceAddress) {
for (WifiP2pDevice d : mPeers.getDeviceList()) {
- if (interfaceAddress.equals(WifiNative.p2pGetInterfaceAddress(d.deviceAddress))) {
+ if (interfaceAddress.equals(d.interfaceAddress)) {
return d.deviceAddress;
}
}
return null;
}
+ private WifiP2pDevice getDeviceFromPeerList(String deviceAddress) {
+ for (WifiP2pDevice d : mPeers.getDeviceList()) {
+ if (d.deviceAddress.equals(deviceAddress)) {
+ return d;
+ }
+ }
+ return null;
+ }
+
+ private void p2pConnectWithPinDisplay(WifiP2pConfig config, boolean join) {
+ String pin = WifiNative.p2pConnect(config, join);
+ try {
+ Integer.parseInt(pin);
+ notifyInvitationSent(pin, config.deviceAddress);
+ } catch (NumberFormatException ignore) {
+ // do nothing if p2pConnect did not return a pin
+ }
+ }
+
private void initializeP2pSettings() {
WifiNative.setPersistentReconnect(true);
WifiNative.setDeviceName(mThisDevice.deviceName);