summaryrefslogtreecommitdiffstats
path: root/wifi/java/android/net/wifi/p2p
diff options
context:
space:
mode:
authorIrfan Sheriff <isheriff@google.com>2012-12-07 15:51:34 -0800
committerIrfan Sheriff <isheriff@google.com>2012-12-11 22:00:14 -0800
commit3a67e2515bff73fab57621b1f9966662e83b7881 (patch)
tree3510da17e5ab4b891cbf54f3f105a0238b98c125 /wifi/java/android/net/wifi/p2p
parent6f0c7b50684a44eb058691799e03ff0f0417b102 (diff)
downloadframeworks_base-3a67e2515bff73fab57621b1f9966662e83b7881.zip
frameworks_base-3a67e2515bff73fab57621b1f9966662e83b7881.tar.gz
frameworks_base-3a67e2515bff73fab57621b1f9966662e83b7881.tar.bz2
Expose more details in broadcasts
Expose details in broadcasts and do the necessary clean up alongside Change-Id: I9011d51675a233aa3542f097c8a489c2095103b1
Diffstat (limited to 'wifi/java/android/net/wifi/p2p')
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pDevice.java25
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java37
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pGroup.java4
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pManager.java41
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pService.java75
5 files changed, 127 insertions, 55 deletions
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java b/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java
index 7d71539..ad52585 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java
@@ -26,6 +26,7 @@ import java.util.regex.Matcher;
/**
* A class representing a Wi-Fi p2p device
*
+ * Note that the operations are not thread safe
* {@see WifiP2pManager}
*/
public class WifiP2pDevice implements Parcelable {
@@ -260,9 +261,29 @@ public class WifiP2pDevice implements Parcelable {
return (groupCapability & GROUP_CAPAB_GROUP_LIMIT) != 0;
}
- /** @hide */
+ /**
+ * Update device details. This will be throw an exception if the device address
+ * does not match.
+ * @param device to be updated
+ * @throws IllegalArgumentException if the device is null or device address does not match
+ * @hide
+ */
public void update(WifiP2pDevice device) {
- if (device == null || device.deviceAddress == null) return;
+ updateSupplicantDetails(device);
+ status = device.status;
+ }
+
+ /** Updates details obtained from supplicant @hide */
+ void updateSupplicantDetails(WifiP2pDevice device) {
+ if (device == null) {
+ throw new IllegalArgumentException("device is null");
+ }
+ if (device.deviceAddress == null) {
+ throw new IllegalArgumentException("deviceAddress is null");
+ }
+ if (!deviceAddress.equals(device.deviceAddress)) {
+ throw new IllegalArgumentException("deviceAddress does not match");
+ }
deviceName = device.deviceName;
primaryDeviceType = device.primaryDeviceType;
secondaryDeviceType = device.secondaryDeviceType;
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java
index f14c305..f7bceac 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java
@@ -58,16 +58,28 @@ public class WifiP2pDeviceList implements Parcelable {
}
}
- /** @hide */
+ /** Clear the list @hide */
public boolean clear() {
if (mDevices.isEmpty()) return false;
mDevices.clear();
return true;
}
- /** @hide */
+ /**
+ * Add/update a device to the list. If the device is not found, a new device entry
+ * is created. If the device is already found, the device details are updated
+ * @param device to be updated
+ * @hide
+ */
public void update(WifiP2pDevice device) {
if (device == null || device.deviceAddress == null) return;
+ updateSupplicantDetails(device);
+ mDevices.get(device.deviceAddress).status = device.status;
+ }
+
+ /** Only updates details fetched from the supplicant @hide */
+ void updateSupplicantDetails(WifiP2pDevice device) {
+ if (device == null || device.deviceAddress == null) return;
WifiP2pDevice d = mDevices.get(device.deviceAddress);
if (d != null) {
d.deviceName = device.deviceName;
@@ -84,7 +96,7 @@ public class WifiP2pDeviceList implements Parcelable {
}
/** @hide */
- public void updateGroupCapability(String deviceAddress, int groupCapab) {
+ void updateGroupCapability(String deviceAddress, int groupCapab) {
if (TextUtils.isEmpty(deviceAddress)) return;
WifiP2pDevice d = mDevices.get(deviceAddress);
if (d != null) {
@@ -93,7 +105,7 @@ public class WifiP2pDeviceList implements Parcelable {
}
/** @hide */
- public void updateStatus(String deviceAddress, int status) {
+ void updateStatus(String deviceAddress, int status) {
if (TextUtils.isEmpty(deviceAddress)) return;
WifiP2pDevice d = mDevices.get(deviceAddress);
if (d != null) {
@@ -101,7 +113,11 @@ public class WifiP2pDeviceList implements Parcelable {
}
}
- /** @hide */
+ /**
+ * Fetch a device from the list
+ * @param deviceAddress is the address of the device
+ * @return WifiP2pDevice device found, or null if none found
+ */
public WifiP2pDevice get(String deviceAddress) {
if (deviceAddress == null) return null;
@@ -114,6 +130,17 @@ public class WifiP2pDeviceList implements Parcelable {
return mDevices.remove(device.deviceAddress) != null;
}
+ /**
+ * Remove a device from the list
+ * @param deviceAddress is the address of the device
+ * @return WifiP2pDevice device removed, or null if none removed
+ * @hide
+ */
+ public WifiP2pDevice remove(String deviceAddress) {
+ if (deviceAddress == null) return null;
+ return mDevices.remove(deviceAddress);
+ }
+
/** Returns true if any device the list was removed @hide */
public boolean remove(WifiP2pDeviceList list) {
boolean ret = false;
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java b/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java
index cf7604d..ca737f9 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java
@@ -27,7 +27,9 @@ import java.util.regex.Pattern;
import java.util.regex.Matcher;
/**
- * A class representing a Wi-Fi P2p group
+ * A class representing a Wi-Fi P2p group. A p2p group consists of a single group
+ * owner and one or more clients. In the case of a group with only two devices, one
+ * will be the group owner and the other will be a group client.
*
* {@see WifiP2pManager}
*/
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
index d79421f..5bd0349 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
@@ -171,10 +171,12 @@ public class WifiP2pManager {
* Broadcast intent action indicating that the state of Wi-Fi p2p connectivity
* has changed. One extra {@link #EXTRA_WIFI_P2P_INFO} provides the p2p connection info in
* the form of a {@link WifiP2pInfo} object. Another extra {@link #EXTRA_NETWORK_INFO} provides
- * the network info in the form of a {@link android.net.NetworkInfo}.
+ * the network info in the form of a {@link android.net.NetworkInfo}. A third extra provides
+ * the details of the group.
*
* @see #EXTRA_WIFI_P2P_INFO
* @see #EXTRA_NETWORK_INFO
+ * @see #EXTRA_WIFI_P2P_GROUP
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String WIFI_P2P_CONNECTION_CHANGED_ACTION =
@@ -188,41 +190,46 @@ public class WifiP2pManager {
/**
* The lookup key for a {@link android.net.NetworkInfo} object associated with the
- * Wi-Fi network. Retrieve with
+ * p2p network. Retrieve with
* {@link android.content.Intent#getParcelableExtra(String)}.
*/
public static final String EXTRA_NETWORK_INFO = "networkInfo";
/**
- * The lookup key for a {@link android.net.LinkProperties} object associated with the
- * network. Retrieve with
+ * The lookup key for a {@link android.net.wifi.p2p.WifiP2pGroup} object
+ * associated with the p2p network. Retrieve with
* {@link android.content.Intent#getParcelableExtra(String)}.
- * @hide
*/
- public static final String EXTRA_LINK_PROPERTIES = "linkProperties";
+ public static final String EXTRA_WIFI_P2P_GROUP = "p2pGroupInfo";
/**
- * The lookup key for a {@link android.net.LinkCapabilities} object associated with the
- * network. Retrieve with
- * {@link android.content.Intent#getParcelableExtra(String)}.
- * @hide
- */
- public static final String EXTRA_LINK_CAPABILITIES = "linkCapabilities";
-
- /**
- * Broadcast intent action indicating that the available peer list has changed. Fetch
- * the changed list of peers with {@link #requestPeers}
+ * Broadcast intent action indicating that the available peer list has changed. This
+ * can be sent as a result of peers being found, lost or updated.
+ *
+ * <p> An extra {@link #EXTRA_P2P_DEVICE_LIST} provides the full list of
+ * current peers. The full list of peers can also be obtained any time with
+ * {@link #requestPeers}.
+ *
+ * @see #EXTRA_P2P_DEVICE_LIST
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String WIFI_P2P_PEERS_CHANGED_ACTION =
"android.net.wifi.p2p.PEERS_CHANGED";
+ /**
+ * The lookup key for a {@link android.net.wifi.p2p.WifiP2pDeviceList} object representing
+ * the new peer list when {@link #WIFI_P2P_PEERS_CHANGED_ACTION} broadcast is sent.
+ *
+ * <p>Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
+ */
+ public static final String EXTRA_P2P_DEVICE_LIST = "wifiP2pDeviceList";
+
/**
* Broadcast intent action indicating that peer discovery has either started or stopped.
* One extra {@link #EXTRA_DISCOVERY_STATE} indicates whether discovery has started
* or stopped.
*
- * Note that discovery will be stopped during a connection setup. If the application tries
+ * <p>Note that discovery will be stopped during a connection setup. If the application tries
* to re-initiate discovery during this time, it can fail.
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
index ccd983d..c1d177d 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
@@ -791,7 +791,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
//Nothing to do
break;
case WifiStateMachine.CMD_DISABLE_P2P_REQ:
- if (mPeers.clear()) sendP2pPeersChangedBroadcast();
+ if (mPeers.clear()) {
+ sendPeersChangedBroadcast();
+ }
if (mGroups.clear()) sendP2pPersistentGroupsChangedBroadcast();
mWifiNative.closeSupplicantConnection();
@@ -859,12 +861,16 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
case WifiMonitor.P2P_DEVICE_FOUND_EVENT:
WifiP2pDevice device = (WifiP2pDevice) message.obj;
if (mThisDevice.deviceAddress.equals(device.deviceAddress)) break;
- mPeers.update(device);
- sendP2pPeersChangedBroadcast();
+ mPeers.updateSupplicantDetails(device);
+ sendPeersChangedBroadcast();
break;
case WifiMonitor.P2P_DEVICE_LOST_EVENT:
device = (WifiP2pDevice) message.obj;
- if (mPeers.remove(device)) sendP2pPeersChangedBroadcast();
+ // Gets current details for the one removed
+ device = mPeers.remove(device.deviceAddress);
+ if (device != null) {
+ sendPeersChangedBroadcast();
+ }
break;
case WifiP2pManager.ADD_LOCAL_SERVICE:
if (DBG) logd(getName() + " add service");
@@ -960,7 +966,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
break;
}
mPeers.updateStatus(mSavedPeerConfig.deviceAddress, WifiP2pDevice.INVITED);
- sendP2pPeersChangedBroadcast();
+ sendPeersChangedBroadcast();
replyToMessage(message, WifiP2pManager.CONNECT_SUCCEEDED);
if (connectRet == NEEDS_PROVISION_REQ) {
if (DBG) logd("Sending prov disc");
@@ -1106,7 +1112,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
}
// Do nothing
if (DBG) logd("Add device to lost list " + device);
- mPeersLostDuringConnection.update(device);
+ mPeersLostDuringConnection.updateSupplicantDetails(device);
break;
case WifiP2pManager.DISCOVER_PEERS:
/* Discovery will break negotiation */
@@ -1150,7 +1156,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
break;
}
mPeers.updateStatus(mSavedPeerConfig.deviceAddress, WifiP2pDevice.INVITED);
- sendP2pPeersChangedBroadcast();
+ sendPeersChangedBroadcast();
transitionTo(mGroupNegotiationState);
break;
case PEER_CONNECTION_USER_REJECT:
@@ -1282,9 +1288,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_START_DHCP);
WifiP2pDevice groupOwner = mGroup.getOwner();
/* update group owner details with the ones found at discovery */
- groupOwner.update(mPeers.get(groupOwner.deviceAddress));
+ groupOwner.updateSupplicantDetails(mPeers.get(groupOwner.deviceAddress));
mPeers.updateStatus(groupOwner.deviceAddress, WifiP2pDevice.CONNECTED);
- sendP2pPeersChangedBroadcast();
+ sendPeersChangedBroadcast();
}
mSavedPeerConfig = null;
transitionTo(mGroupCreatedState);
@@ -1477,7 +1483,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
}
mPeers.updateStatus(deviceAddress, WifiP2pDevice.CONNECTED);
if (DBG) logd(getName() + " ap sta connected");
- sendP2pPeersChangedBroadcast();
+ sendPeersChangedBroadcast();
} else {
loge("Connect on null device address, ignore");
}
@@ -1505,7 +1511,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
if (DBG) logd("client " + c.deviceAddress);
}
}
- sendP2pPeersChangedBroadcast();
+ sendPeersChangedBroadcast();
if (DBG) logd(getName() + " ap sta disconnected");
} else {
loge("Disconnect on unknown device: " + device);
@@ -1558,7 +1564,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
//Device loss for a connected device indicates it is not in discovery any more
if (mGroup.contains(device)) {
if (DBG) logd("Add device to lost list " + device);
- mPeersLostDuringConnection.update(device);
+ mPeersLostDuringConnection.updateSupplicantDetails(device);
return HANDLED;
}
// Do the regular device lost handling
@@ -1595,7 +1601,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
mSavedPeerConfig = config;
if (mWifiNative.p2pInvite(mGroup, config.deviceAddress)) {
mPeers.updateStatus(config.deviceAddress, WifiP2pDevice.INVITED);
- sendP2pPeersChangedBroadcast();
+ sendPeersChangedBroadcast();
replyToMessage(message, WifiP2pManager.CONNECT_SUCCEEDED);
} else {
replyToMessage(message, WifiP2pManager.CONNECT_FAILED,
@@ -1771,8 +1777,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
}
- private void sendP2pPeersChangedBroadcast() {
+ private void sendPeersChangedBroadcast() {
final Intent intent = new Intent(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
+ intent.putExtra(WifiP2pManager.EXTRA_P2P_DEVICE_LIST, mPeers);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
}
@@ -1784,6 +1791,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
| Intent.FLAG_RECEIVER_REPLACE_PENDING);
intent.putExtra(WifiP2pManager.EXTRA_WIFI_P2P_INFO, new WifiP2pInfo(mWifiP2pInfo));
intent.putExtra(WifiP2pManager.EXTRA_NETWORK_INFO, new NetworkInfo(mNetworkInfo));
+ intent.putExtra(WifiP2pManager.EXTRA_WIFI_P2P_GROUP, new WifiP2pGroup(mGroup));
mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
mWifiChannel.sendMessage(WifiP2pService.P2P_CONNECTION_CHANGED,
new NetworkInfo(mNetworkInfo));
@@ -2311,26 +2319,24 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
resetWifiP2pInfo();
mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.FAILED, null, null);
sendP2pConnectionChangedBroadcast();
+
+ // Remove only the peer we failed to connect to so that other devices discovered
+ // that have not timed out still remain in list for connection
+ boolean peersChanged = mPeers.remove(mPeersLostDuringConnection);
+ if (mSavedPeerConfig != null && mPeers.remove(mSavedPeerConfig.deviceAddress) != null) {
+ peersChanged = true;
+ }
+ if (peersChanged) {
+ sendPeersChangedBroadcast();
+ }
+
mSavedPeerConfig = null;
- /* After cancelling group formation, new connections on existing peers can fail
- * at supplicant. Flush and restart discovery */
- mWifiNative.p2pFlush();
- if (mPeers.remove(mPeersLostDuringConnection)) sendP2pPeersChangedBroadcast();
mPeersLostDuringConnection.clear();
mServiceDiscReqId = null;
sendMessage(WifiP2pManager.DISCOVER_PEERS);
}
private void handleGroupRemoved() {
- Collection <WifiP2pDevice> devices = mGroup.getClientList();
- boolean changed = false;
- for (WifiP2pDevice d : mPeers.getDeviceList()) {
- if (devices.contains(d) || mGroup.getOwner().equals(d)) {
- d.status = WifiP2pDevice.AVAILABLE;
- changed = true;
- }
- }
-
if (mGroup.isGroupOwner()) {
stopDhcpServer(mGroup.getInterface());
} else {
@@ -2351,12 +2357,21 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
// that reuse the main p2p interface for a created group.
mWifiNative.setP2pGroupIdle(mGroup.getInterface(), 0);
+ boolean peersChanged = false;
+ // Remove only peers part of the group, so that other devices discovered
+ // that have not timed out still remain in list for connection
+ for (WifiP2pDevice d : mGroup.getClientList()) {
+ if (mPeers.remove(d)) peersChanged = true;
+ }
+ if (mPeers.remove(mGroup.getOwner())) peersChanged = true;
+ if (mPeers.remove(mPeersLostDuringConnection)) peersChanged = true;
+ if (peersChanged) {
+ sendPeersChangedBroadcast();
+ }
+
mGroup = null;
- mWifiNative.p2pFlush();
- if (mPeers.remove(mPeersLostDuringConnection)) sendP2pPeersChangedBroadcast();
mPeersLostDuringConnection.clear();
mServiceDiscReqId = null;
- if (changed) sendP2pPeersChangedBroadcast();
if (mTempoarilyDisconnectedWifi) {
mWifiChannel.sendMessage(WifiP2pService.DISCONNECT_WIFI_REQUEST, 0);