diff options
author | Christopher Lane <lanechr@google.com> | 2014-04-25 18:39:07 -0700 |
---|---|---|
committer | Christopher Lane <lanechr@google.com> | 2014-04-25 18:57:23 -0700 |
commit | 5a577903d366ff07b3c4ec6359e4757154f49790 (patch) | |
tree | 3d13b079022dd7e5372e9b26a955281f38e6d700 /services | |
parent | 97efc15b32b61a5deb1f54c6c08844b788785c39 (diff) | |
download | frameworks_base-5a577903d366ff07b3c4ec6359e4757154f49790.zip frameworks_base-5a577903d366ff07b3c4ec6359e4757154f49790.tar.gz frameworks_base-5a577903d366ff07b3c4ec6359e4757154f49790.tar.bz2 |
Fix incorrect "listener no longer active" errors
Was incorrectly using .indexOfValue to search for Integer objects in the
client map.
Change-Id: I54e2e1725e0fff0a7d35a22376714cc8266a9eee
Diffstat (limited to 'services')
-rw-r--r-- | services/core/java/com/android/server/NsdService.java | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/services/core/java/com/android/server/NsdService.java b/services/core/java/com/android/server/NsdService.java index fa803e2..fe97c71 100644 --- a/services/core/java/com/android/server/NsdService.java +++ b/services/core/java/com/android/server/NsdService.java @@ -421,11 +421,8 @@ public class NsdService extends INsdManager.Stub { } /* This goes in response as msg.arg2 */ - int clientId = -1; - int keyId = clientInfo.mClientIds.indexOfValue(id); - if (keyId != -1) { - clientId = clientInfo.mClientIds.keyAt(keyId); - } else { + int clientId = clientInfo.getClientId(id); + if (clientId < 0) { // This can happen because of race conditions. For example, // SERVICE_FOUND may race with STOP_SERVICE_DISCOVERY, // and we may get in this situation. @@ -904,5 +901,18 @@ public class NsdService extends INsdManager.Stub { mClientRequests.clear(); } + // mClientIds is a sparse array of listener id -> mDnsClient id. For a given mDnsClient id, + // return the corresponding listener id. mDnsClient id is also called a global id. + private int getClientId(final int globalId) { + // This doesn't use mClientIds.indexOfValue because indexOfValue uses == (not .equals) + // while also coercing the int primitives to Integer objects. + for (int i = 0, nSize = mClientIds.size(); i < nSize; i++) { + int mDnsId = mClientIds.valueAt(i); + if (globalId == mDnsId) { + return mClientIds.keyAt(i); + } + } + return -1; + } } } |