summaryrefslogtreecommitdiff
path: root/lowpan
diff options
context:
space:
mode:
authorRobert Quattlebaum <rquattle@google.com>2017-10-11 18:05:39 -0700
committerRobert Quattlebaum <rquattle@google.com>2018-02-02 21:38:36 +0000
commit4240e019d86d4d6d6dad93b81f20b79802d9a0a5 (patch)
treed1b807fe1fa33f0ab84d9f5a3c1ab8dc18894041 /lowpan
parentfdd755df14e79b99c6c79a28eea1999b27df9718 (diff)
lowpan: Use IBinder for comparison instead of interface
This change fixes a bug where the onInterfaceRemoved() callback for LowpanManager was not working properly and causing crashes. This was because we were using the ILowpanInterface objects as the key in a map to for looking up the associated LowpanInterface objects. This doesn't work because there may be more than one ILowpanInterface object for a given IBinder---thus subsequent attempts to resolve ILowpanInterface objects would always come up empty. The solution was to use the underlying IBinder object as the map key. (Cherry-picked from commit aa07c47441ae1e37f87248492459bef336b43155) Bug: b/67718495 Test: manual Change-Id: I7575743268cf67c6c2c24d8f327ce38d88d354c7
Diffstat (limited to 'lowpan')
-rw-r--r--lowpan/java/android/net/lowpan/LowpanManager.java24
1 files changed, 19 insertions, 5 deletions
diff --git a/lowpan/java/android/net/lowpan/LowpanManager.java b/lowpan/java/android/net/lowpan/LowpanManager.java
index 2d974ee79e40..76876ce01c96 100644
--- a/lowpan/java/android/net/lowpan/LowpanManager.java
+++ b/lowpan/java/android/net/lowpan/LowpanManager.java
@@ -57,7 +57,7 @@ public class LowpanManager {
* This design pattern allows us to skip removal of items
* from this Map without leaking memory.
*/
- private final Map<ILowpanInterface, WeakReference<LowpanInterface>> mBinderCache =
+ private final Map<IBinder, WeakReference<LowpanInterface>> mBinderCache =
new WeakHashMap<>();
private final ILowpanManager mService;
@@ -109,13 +109,27 @@ public class LowpanManager {
/** @hide */
@Nullable
+ public LowpanInterface getInterfaceNoCreate(@NonNull ILowpanInterface ifaceService) {
+ LowpanInterface iface = null;
+
+ synchronized (mBinderCache) {
+ if (mBinderCache.containsKey(ifaceService.asBinder())) {
+ iface = mBinderCache.get(ifaceService.asBinder()).get();
+ }
+ }
+
+ return iface;
+ }
+
+ /** @hide */
+ @Nullable
public LowpanInterface getInterface(@NonNull ILowpanInterface ifaceService) {
LowpanInterface iface = null;
try {
synchronized (mBinderCache) {
- if (mBinderCache.containsKey(ifaceService)) {
- iface = mBinderCache.get(ifaceService).get();
+ if (mBinderCache.containsKey(ifaceService.asBinder())) {
+ iface = mBinderCache.get(ifaceService.asBinder()).get();
}
if (iface == null) {
@@ -127,7 +141,7 @@ public class LowpanManager {
mInterfaceCache.put(iface.getName(), iface);
}
- mBinderCache.put(ifaceService, new WeakReference(iface));
+ mBinderCache.put(ifaceService.asBinder(), new WeakReference(iface));
/* Make sure we remove the object from the
* interface cache if the associated service
@@ -260,7 +274,7 @@ public class LowpanManager {
public void onInterfaceRemoved(ILowpanInterface ifaceService) {
Runnable runnable =
() -> {
- LowpanInterface iface = getInterface(ifaceService);
+ LowpanInterface iface = getInterfaceNoCreate(ifaceService);
if (iface != null) {
cb.onInterfaceRemoved(iface);