Merge "Defensively copy callback collections before invoking" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-07-14 18:39:55 +00:00
committed by Android (Google) Code Review
4 changed files with 21 additions and 16 deletions

View File

@@ -87,7 +87,7 @@ public class KeyguardBouncer {
private final Runnable mResetRunnable = ()-> { private final Runnable mResetRunnable = ()-> {
if (mKeyguardViewController != null) { if (mKeyguardViewController != null) {
mKeyguardViewController.resetSecurityContainer(); mKeyguardViewController.resetSecurityContainer();
for (KeyguardResetCallback callback : mResetCallbacks) { for (KeyguardResetCallback callback : new ArrayList<>(mResetCallbacks)) {
callback.onKeyguardReset(); callback.onKeyguardReset();
} }
} }

View File

@@ -55,16 +55,18 @@ import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener; import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.google.android.collect.Lists;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
@@ -100,7 +102,7 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
private ForcePluginOpenListener mForcePluginOpenListener; private ForcePluginOpenListener mForcePluginOpenListener;
private Consumer<Integer> mScrimsVisibilityListener; private Consumer<Integer> mScrimsVisibilityListener;
private final ArrayList<WeakReference<StatusBarWindowCallback>> private final ArrayList<WeakReference<StatusBarWindowCallback>>
mCallbacks = Lists.newArrayList(); mCallbacks = new ArrayList<>();
private final SysuiColorExtractor mColorExtractor; private final SysuiColorExtractor mColorExtractor;
private final UnlockedScreenOffAnimationController mUnlockedScreenOffAnimationController; private final UnlockedScreenOffAnimationController mUnlockedScreenOffAnimationController;
@@ -464,15 +466,17 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
@Override @Override
public void notifyStateChangedCallbacks() { public void notifyStateChangedCallbacks() {
for (int i = 0; i < mCallbacks.size(); i++) { // Copy callbacks to separate ArrayList to avoid concurrent modification
StatusBarWindowCallback cb = mCallbacks.get(i).get(); List<StatusBarWindowCallback> activeCallbacks = mCallbacks.stream()
if (cb != null) { .map(Reference::get)
.filter(Objects::nonNull)
.collect(Collectors.toList());
for (StatusBarWindowCallback cb : activeCallbacks) {
cb.onStateChanged(mCurrentState.mKeyguardShowing, cb.onStateChanged(mCurrentState.mKeyguardShowing,
mCurrentState.mKeyguardOccluded, mCurrentState.mKeyguardOccluded,
mCurrentState.mBouncerShowing); mCurrentState.mBouncerShowing);
} }
} }
}
private void applyModalFlag(State state) { private void applyModalFlag(State state) {
if (state.mHeadsUpShowing) { if (state.mHeadsUpShowing) {

View File

@@ -41,6 +41,7 @@ import com.android.systemui.statusbar.notification.row.NotificationRowContentBin
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
/** /**
@@ -157,7 +158,7 @@ public abstract class HeadsUpManager extends AlertingNotificationManager {
NotificationPeekEvent.NOTIFICATION_PEEK, entry.getSbn().getUid(), NotificationPeekEvent.NOTIFICATION_PEEK, entry.getSbn().getUid(),
entry.getSbn().getPackageName(), entry.getSbn().getInstanceId()); entry.getSbn().getPackageName(), entry.getSbn().getInstanceId());
} }
for (OnHeadsUpChangedListener listener : mListeners) { for (OnHeadsUpChangedListener listener : new ArrayList<>(mListeners)) {
if (isPinned) { if (isPinned) {
listener.onHeadsUpPinned(entry); listener.onHeadsUpPinned(entry);
} else { } else {
@@ -177,7 +178,7 @@ public abstract class HeadsUpManager extends AlertingNotificationManager {
entry.setHeadsUp(true); entry.setHeadsUp(true);
setEntryPinned((HeadsUpEntry) alertEntry, shouldHeadsUpBecomePinned(entry)); setEntryPinned((HeadsUpEntry) alertEntry, shouldHeadsUpBecomePinned(entry));
EventLogTags.writeSysuiHeadsUpStatus(entry.getKey(), 1 /* visible */); EventLogTags.writeSysuiHeadsUpStatus(entry.getKey(), 1 /* visible */);
for (OnHeadsUpChangedListener listener : mListeners) { for (OnHeadsUpChangedListener listener : new ArrayList<>(mListeners)) {
listener.onHeadsUpStateChanged(entry, true); listener.onHeadsUpStateChanged(entry, true);
} }
} }
@@ -188,7 +189,7 @@ public abstract class HeadsUpManager extends AlertingNotificationManager {
entry.setHeadsUp(false); entry.setHeadsUp(false);
setEntryPinned((HeadsUpEntry) alertEntry, false /* isPinned */); setEntryPinned((HeadsUpEntry) alertEntry, false /* isPinned */);
EventLogTags.writeSysuiHeadsUpStatus(entry.getKey(), 0 /* visible */); EventLogTags.writeSysuiHeadsUpStatus(entry.getKey(), 0 /* visible */);
for (OnHeadsUpChangedListener listener : mListeners) { for (OnHeadsUpChangedListener listener : new ArrayList<>(mListeners)) {
listener.onHeadsUpStateChanged(entry, false); listener.onHeadsUpStateChanged(entry, false);
} }
} }
@@ -206,7 +207,7 @@ public abstract class HeadsUpManager extends AlertingNotificationManager {
if (mHasPinnedNotification) { if (mHasPinnedNotification) {
MetricsLogger.count(mContext, "note_peek", 1); MetricsLogger.count(mContext, "note_peek", 1);
} }
for (OnHeadsUpChangedListener listener : mListeners) { for (OnHeadsUpChangedListener listener : new ArrayList<>(mListeners)) {
listener.onHeadsUpPinnedModeChanged(hasPinnedNotification); listener.onHeadsUpPinnedModeChanged(hasPinnedNotification);
} }
} }

View File

@@ -807,7 +807,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
} }
private void onEditTextFocusChanged(RemoteEditText remoteEditText, boolean focused) { private void onEditTextFocusChanged(RemoteEditText remoteEditText, boolean focused) {
for (View.OnFocusChangeListener listener : mEditTextFocusChangeListeners) { for (View.OnFocusChangeListener listener : new ArrayList<>(mEditTextFocusChangeListeners)) {
listener.onFocusChange(remoteEditText, focused); listener.onFocusChange(remoteEditText, focused);
} }
} }