Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d8544a51 authored by Jeff Brown's avatar Jeff Brown
Browse files

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
parent 21c7153d
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -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);
+12 −4
Original line number Diff line number Diff line
@@ -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());
            }
        }
    }

    /**
+10 −7
Original line number Diff line number Diff line
@@ -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(