Merge "Invoke service connection consumer outside the object lock" into udc-dev
This commit is contained in:
@@ -99,13 +99,15 @@ public class ActivityServiceConnectionsHolder<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void forEachConnection(Consumer<T> consumer) {
|
public void forEachConnection(Consumer<T> consumer) {
|
||||||
|
final ArraySet<T> connections;
|
||||||
synchronized (mActivity) {
|
synchronized (mActivity) {
|
||||||
if (mConnections == null || mConnections.isEmpty()) {
|
if (mConnections == null || mConnections.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = mConnections.size() - 1; i >= 0; i--) {
|
connections = new ArraySet<>(mConnections);
|
||||||
consumer.accept(mConnections.valueAt(i));
|
}
|
||||||
}
|
for (int i = connections.size() - 1; i >= 0; i--) {
|
||||||
|
consumer.accept(connections.valueAt(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2399,7 +2399,10 @@ public class ActivityRecordTests extends WindowTestsBase {
|
|||||||
holder.addConnection(connection);
|
holder.addConnection(connection);
|
||||||
assertTrue(holder.isActivityVisible());
|
assertTrue(holder.isActivityVisible());
|
||||||
final int[] count = new int[1];
|
final int[] count = new int[1];
|
||||||
final Consumer<Object> c = conn -> count[0]++;
|
final Consumer<Object> c = conn -> {
|
||||||
|
count[0]++;
|
||||||
|
assertFalse(Thread.holdsLock(activity));
|
||||||
|
};
|
||||||
holder.forEachConnection(c);
|
holder.forEachConnection(c);
|
||||||
assertEquals(1, count[0]);
|
assertEquals(1, count[0]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user