diff options
| author | Yoshihiko Ikenaga <yoshihiko.ikenaga@jp.sony.com> | 2012-04-02 17:34:38 +0900 |
|---|---|---|
| committer | Irfan Sheriff <isheriff@google.com> | 2012-04-04 11:55:06 -0700 |
| commit | b5e00bda40398b8738192abfe9b745464a54865a (patch) | |
| tree | 902d14d92834513311299a021e1b570910c32627 /wifi/java/android | |
| parent | c111d1caa8d4cc5d2139b5abd4d2db1f78560eff (diff) | |
| download | frameworks_base-b5e00bda40398b8738192abfe9b745464a54865a.zip frameworks_base-b5e00bda40398b8738192abfe9b745464a54865a.tar.gz frameworks_base-b5e00bda40398b8738192abfe9b745464a54865a.tar.bz2 | |
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: Yoshihiko Ikenaga <yoshihiko.ikenaga@jp.sony.com>
Diffstat (limited to 'wifi/java/android')
| -rw-r--r-- | wifi/java/android/net/wifi/p2p/WifiP2pManager.java | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java index 2fc6c20..c7f6bf0 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java @@ -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) { - key = mListenerKey++; + 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); } |
