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

Commit a266f9af authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove old weak references to callbacks when iterating over callbacks in Communal logic."

parents 4baf504f ed40b277
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.google.android.collect.Lists;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;

import javax.inject.Inject;

@@ -103,9 +104,12 @@ public class CommunalSourceMonitor {

    private void executeOnSourceAvailableCallbacks() {
        // If the new source is valid, inform registered Callbacks of its presence.
        for (WeakReference<Callback> callback : mCallbacks) {
            Callback cb = callback.get();
            if (cb != null) {
        Iterator<WeakReference<Callback>> itr = mCallbacks.iterator();
        while (itr.hasNext()) {
            Callback cb = itr.next().get();
            if (cb == null) {
                itr.remove();
            } else {
                cb.onSourceAvailable(
                        (mCommunalEnabled && mCurrentSource != null) ? new WeakReference<>(
                                mCurrentSource) : null);