diff --git a/core/java/android/os/BinderProxy.java b/core/java/android/os/BinderProxy.java index 97c0a13e7a2b2..c35b05f104986 100644 --- a/core/java/android/os/BinderProxy.java +++ b/core/java/android/os/BinderProxy.java @@ -241,32 +241,37 @@ public final class BinderProxy implements IBinder { } Map counts = new HashMap<>(); - for (ArrayList> a : mMainIndexValues) { - if (a != null) { - for (WeakReference weakRef : a) { - BinderProxy bp = weakRef.get(); - String key; - if (bp == null) { - key = ""; - } else { - try { - key = bp.getInterfaceDescriptor(); - if ((key == null || key.isEmpty()) && !bp.isBinderAlive()) { - key = ""; - } - } catch (Throwable t) { - key = ""; - } - } - Integer i = counts.get(key); - if (i == null) { - counts.put(key, 1); - } else { - counts.put(key, i + 1); - } + final ArrayList> proxiesToQuery = + new ArrayList>(); + synchronized (sProxyMap) { + for (ArrayList> a : mMainIndexValues) { + if (a != null) { + proxiesToQuery.addAll(a); } } } + for (WeakReference weakRef : proxiesToQuery) { + BinderProxy bp = weakRef.get(); + String key; + if (bp == null) { + key = ""; + } else { + try { + key = bp.getInterfaceDescriptor(); + if ((key == null || key.isEmpty()) && !bp.isBinderAlive()) { + key = ""; + } + } catch (Throwable t) { + key = ""; + } + } + Integer i = counts.get(key); + if (i == null) { + counts.put(key, 1); + } else { + counts.put(key, i + 1); + } + } Map.Entry[] sorted = counts.entrySet().toArray( new Map.Entry[counts.size()]); @@ -354,9 +359,7 @@ public final class BinderProxy implements IBinder { * @hide */ public static InterfaceCount[] getSortedInterfaceCounts(int num) { - synchronized (sProxyMap) { - return sProxyMap.getSortedInterfaceCounts(num); - } + return sProxyMap.getSortedInterfaceCounts(num); } /** @@ -376,10 +379,8 @@ public final class BinderProxy implements IBinder { */ public static void dumpProxyDebugInfo() { if (Build.IS_DEBUGGABLE) { - synchronized (sProxyMap) { - sProxyMap.dumpProxyInterfaceCounts(); - sProxyMap.dumpPerUidProxyCounts(); - } + sProxyMap.dumpProxyInterfaceCounts(); + sProxyMap.dumpPerUidProxyCounts(); } }