summaryrefslogtreecommitdiffstats
path: root/wifi/java/android/net/wifi/p2p
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-09-09 13:56:17 -0700
committerJeff Brown <jeffbrown@google.com>2012-09-09 14:08:52 -0700
commitd8544a51482c86b12da3ac82ea77b83045f689b7 (patch)
treeab1c3abf59b2db7429afbe16956a301368d09f63 /wifi/java/android/net/wifi/p2p
parent21c7153d30071dcbeb92daa1fd48ed181e42aef3 (diff)
downloadframeworks_base-d8544a51482c86b12da3ac82ea77b83045f689b7.zip
frameworks_base-d8544a51482c86b12da3ac82ea77b83045f689b7.tar.gz
frameworks_base-d8544a51482c86b12da3ac82ea77b83045f689b7.tar.bz2
Copy all mutable state before sending to clients.
This resolves an issue with ConcurrentModificationException or inconsistent data being perceived by clients. Fixed an NPE in the WifiP2pDeviceList copy constructor. Bug: 7133752 Change-Id: I37a4d004f7b1ca21d490f131039d81695db2ba42
Diffstat (limited to 'wifi/java/android/net/wifi/p2p')
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java4
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pGroupList.java16
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pService.java17
3 files changed, 23 insertions, 14 deletions
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java
index 48cdbc2..157dc50 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java
@@ -35,10 +35,9 @@ import java.util.HashMap;
*/
public class WifiP2pDeviceList implements Parcelable {
- private HashMap<String, WifiP2pDevice> mDevices;
+ private final HashMap<String, WifiP2pDevice> mDevices = new HashMap<String, WifiP2pDevice>();
public WifiP2pDeviceList() {
- mDevices = new HashMap<String, WifiP2pDevice>();
}
/** copy constructor */
@@ -52,7 +51,6 @@ public class WifiP2pDeviceList implements Parcelable {
/** @hide */
public WifiP2pDeviceList(ArrayList<WifiP2pDevice> devices) {
- mDevices = new HashMap<String, WifiP2pDevice>();
for (WifiP2pDevice device : devices) {
if (device.deviceAddress != null) {
mDevices.put(device.deviceAddress, device);
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pGroupList.java b/wifi/java/android/net/wifi/p2p/WifiP2pGroupList.java
index 3459a5a..98f0972 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pGroupList.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pGroupList.java
@@ -16,6 +16,7 @@
package android.net.wifi.p2p;
import java.util.Collection;
+import java.util.Map;
import android.os.Parcel;
import android.os.Parcelable;
@@ -32,8 +33,9 @@ public class WifiP2pGroupList implements Parcelable {
private static final int CREDENTIAL_MAX_NUM = 32;
- private LruCache<Integer, WifiP2pGroup> mGroups;
- private GroupDeleteListener mListener;
+ private final LruCache<Integer, WifiP2pGroup> mGroups;
+ private final GroupDeleteListener mListener;
+
private boolean isClearCalled = false;
public interface GroupDeleteListener {
@@ -41,10 +43,10 @@ public class WifiP2pGroupList implements Parcelable {
}
WifiP2pGroupList() {
- this(null);
+ this(null, null);
}
- WifiP2pGroupList(GroupDeleteListener listener) {
+ WifiP2pGroupList(WifiP2pGroupList source, GroupDeleteListener listener) {
mListener = listener;
mGroups = new LruCache<Integer, WifiP2pGroup>(CREDENTIAL_MAX_NUM) {
@Override
@@ -55,6 +57,12 @@ public class WifiP2pGroupList implements Parcelable {
}
}
};
+
+ if (source != null) {
+ for (Map.Entry<Integer, WifiP2pGroup> item : source.mGroups.snapshot().entrySet()) {
+ mGroups.put(item.getKey(), item.getValue());
+ }
+ }
}
/**
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
index a6770bd..3575d97 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
@@ -359,8 +359,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
private WifiNative mWifiNative = new WifiNative(mInterface);
private WifiMonitor mWifiMonitor = new WifiMonitor(this, mWifiNative);
- private WifiP2pDeviceList mPeers = new WifiP2pDeviceList();
- private WifiP2pGroupList mGroups = new WifiP2pGroupList(
+ private final WifiP2pDeviceList mPeers = new WifiP2pDeviceList();
+ private final WifiP2pGroupList mGroups = new WifiP2pGroupList(null,
new GroupDeleteListener() {
@Override
public void onDeleteGroup(int netId) {
@@ -370,7 +370,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
sendP2pPersistentGroupsChangedBroadcast();
}
});
- private WifiP2pInfo mWifiP2pInfo = new WifiP2pInfo();
+ private final WifiP2pInfo mWifiP2pInfo = new WifiP2pInfo();
private WifiP2pGroup mGroup;
// Saved WifiP2pConfig for a peer connection
@@ -501,17 +501,20 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
WifiP2pManager.BUSY);
break;
case WifiP2pManager.REQUEST_PEERS:
- replyToMessage(message, WifiP2pManager.RESPONSE_PEERS, mPeers);
+ replyToMessage(message, WifiP2pManager.RESPONSE_PEERS,
+ new WifiP2pDeviceList(mPeers));
break;
case WifiP2pManager.REQUEST_CONNECTION_INFO:
- replyToMessage(message, WifiP2pManager.RESPONSE_CONNECTION_INFO, mWifiP2pInfo);
+ replyToMessage(message, WifiP2pManager.RESPONSE_CONNECTION_INFO,
+ new WifiP2pInfo(mWifiP2pInfo));
break;
case WifiP2pManager.REQUEST_GROUP_INFO:
- replyToMessage(message, WifiP2pManager.RESPONSE_GROUP_INFO, mGroup);
+ replyToMessage(message, WifiP2pManager.RESPONSE_GROUP_INFO,
+ mGroup != null ? new WifiP2pGroup(mGroup) : null);
break;
case WifiP2pManager.REQUEST_PERSISTENT_GROUP_INFO:
replyToMessage(message, WifiP2pManager.RESPONSE_PERSISTENT_GROUP_INFO,
- mGroups);
+ new WifiP2pGroupList(mGroups, null));
break;
case WifiP2pManager.SET_DIALOG_LISTENER:
String appPkgName = (String)message.getData().getString(