Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 766a9446 authored by Riddle Hsu's avatar Riddle Hsu Committed by Automerger Merge Worker
Browse files

Merge "Invoke service connection consumer outside the object lock" into udc-dev am: 009defe3

parents 52b16933 009defe3
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -99,13 +99,15 @@ public class ActivityServiceConnectionsHolder<T> {
    }

    public void forEachConnection(Consumer<T> consumer) {
        final ArraySet<T> connections;
        synchronized (mActivity) {
            if (mConnections == null || mConnections.isEmpty()) {
                return;
            }
            for (int i = mConnections.size() - 1; i >= 0; i--) {
                consumer.accept(mConnections.valueAt(i));
            connections = new ArraySet<>(mConnections);
        }
        for (int i = connections.size() - 1; i >= 0; i--) {
            consumer.accept(connections.valueAt(i));
        }
    }

+4 −1
Original line number Diff line number Diff line
@@ -2399,7 +2399,10 @@ public class ActivityRecordTests extends WindowTestsBase {
        holder.addConnection(connection);
        assertTrue(holder.isActivityVisible());
        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);
        assertEquals(1, count[0]);