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

Commit b5e00bda authored by Yoshihiko Ikenaga's avatar Yoshihiko Ikenaga Committed by Irfan Sheriff
Browse files

Fix key handling



putListener() returns 0 when the argument is null. And The key value of listener
registered first is always 0. For this reason, if the p2p functions are called continuously
and first call is without listener and the second call is with listener, then the message
against first call wrongly pick up the second call's listener because the key value is
the same. In order to avoid this issue, we don't use 0 as the valid listener key.

Change-Id: I0cc960b2ad37f17cf7f528d839b39aa272b83670
Signed-off-by: default avatarYoshihiko Ikenaga <yoshihiko.ikenaga@jp.sony.com>
parent c111d1ca
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -380,6 +380,7 @@ public class WifiP2pManager {
            mHandler = new P2pHandler(looper);
            mChannelListener = l;
        }
        private final static int INVALID_LISTENER_KEY = 0;
        private ChannelListener mChannelListener;
        private HashMap<Integer, Object> mListenerMap = new HashMap<Integer, Object>();
        private Object mListenerMapLock = new Object();
@@ -450,16 +451,19 @@ public class WifiP2pManager {
        }

        int putListener(Object listener) {
            if (listener == null) return 0;
            if (listener == null) return INVALID_LISTENER_KEY;
            int key;
            synchronized (mListenerMapLock) {
                do {
                    key = mListenerKey++;
                } while (key == INVALID_LISTENER_KEY);
                mListenerMap.put(key, listener);
            }
            return key;
        }

        Object getListener(int key) {
            if (key == INVALID_LISTENER_KEY) return null;
            synchronized (mListenerMapLock) {
                return mListenerMap.remove(key);
            }