Merge "Fix crash from concurrent modification" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e3f2f29cde
@@ -36,11 +36,13 @@ import android.service.notification.Condition;
|
|||||||
import android.service.notification.IConditionListener;
|
import android.service.notification.IConditionListener;
|
||||||
import android.service.notification.ZenModeConfig;
|
import android.service.notification.ZenModeConfig;
|
||||||
import android.service.notification.ZenModeConfig.ZenRule;
|
import android.service.notification.ZenModeConfig.ZenRule;
|
||||||
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
import com.android.systemui.qs.GlobalSetting;
|
import com.android.systemui.qs.GlobalSetting;
|
||||||
import com.android.systemui.settings.CurrentUserTracker;
|
import com.android.systemui.settings.CurrentUserTracker;
|
||||||
|
import com.android.systemui.util.Utils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@@ -169,45 +171,32 @@ public class ZenModeControllerImpl extends CurrentUserTracker implements ZenMode
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void fireNextAlarmChanged() {
|
private void fireNextAlarmChanged() {
|
||||||
for (Callback cb : mCallbacks) {
|
Utils.safeForeach(mCallbacks, c -> c.onNextAlarmChanged());
|
||||||
cb.onNextAlarmChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireEffectsSuppressorChanged() {
|
private void fireEffectsSuppressorChanged() {
|
||||||
for (Callback cb : mCallbacks) {
|
Utils.safeForeach(mCallbacks, c -> c.onEffectsSupressorChanged());
|
||||||
cb.onEffectsSupressorChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireZenChanged(int zen) {
|
private void fireZenChanged(int zen) {
|
||||||
for (Callback cb : mCallbacks) {
|
Utils.safeForeach(mCallbacks, c -> c.onZenChanged(zen));
|
||||||
cb.onZenChanged(zen);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireZenAvailableChanged(boolean available) {
|
private void fireZenAvailableChanged(boolean available) {
|
||||||
for (Callback cb : mCallbacks) {
|
Utils.safeForeach(mCallbacks, c -> c.onZenAvailableChanged(available));
|
||||||
cb.onZenAvailableChanged(available);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireConditionsChanged(Condition[] conditions) {
|
private void fireConditionsChanged(Condition[] conditions) {
|
||||||
for (Callback cb : mCallbacks) {
|
Utils.safeForeach(mCallbacks, c -> c.onConditionsChanged(conditions));
|
||||||
cb.onConditionsChanged(conditions);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireManualRuleChanged(ZenRule rule) {
|
private void fireManualRuleChanged(ZenRule rule) {
|
||||||
for (Callback cb : mCallbacks) {
|
Utils.safeForeach(mCallbacks, c -> c.onManualRuleChanged(rule));
|
||||||
cb.onManualRuleChanged(rule);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireConfigChanged(ZenModeConfig config) {
|
@VisibleForTesting
|
||||||
for (Callback cb : mCallbacks) {
|
protected void fireConfigChanged(ZenModeConfig config) {
|
||||||
cb.onConfigChanged(config);
|
Utils.safeForeach(mCallbacks, c -> c.onConfigChanged(config));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateConditions(Condition[] conditions) {
|
private void updateConditions(Condition[] conditions) {
|
||||||
|
|||||||
31
packages/SystemUI/src/com/android/systemui/util/Utils.java
Normal file
31
packages/SystemUI/src/com/android/systemui/util/Utils.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
||||||
|
* except in compliance with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed under the
|
||||||
|
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the specific language governing
|
||||||
|
* permissions and limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.systemui.util;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class Utils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows lambda iteration over a list. It is done in reverse order so it is safe
|
||||||
|
* to add or remove items during the iteration.
|
||||||
|
*/
|
||||||
|
public static <T> void safeForeach(List<T> list, Consumer<T> c) {
|
||||||
|
for (int i = list.size() - 1; i >= 0; i--) {
|
||||||
|
c.accept(list.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
||||||
|
* except in compliance with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed under the
|
||||||
|
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the specific language governing
|
||||||
|
* permissions and limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.systemui.statusbar.policy;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.service.notification.ZenModeConfig;
|
||||||
|
import android.support.test.filters.SmallTest;
|
||||||
|
import android.testing.AndroidTestingRunner;
|
||||||
|
import android.testing.TestableLooper.RunWithLooper;
|
||||||
|
|
||||||
|
import com.android.systemui.SysuiTestCase;
|
||||||
|
import com.android.systemui.statusbar.policy.ZenModeController.Callback;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
@SmallTest
|
||||||
|
@RunWith(AndroidTestingRunner.class)
|
||||||
|
@RunWithLooper
|
||||||
|
public class ZenModeControllerImplTest extends SysuiTestCase {
|
||||||
|
|
||||||
|
private Callback mCallback;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveDuringCallback() {
|
||||||
|
ZenModeControllerImpl controller = new ZenModeControllerImpl(mContext, new Handler());
|
||||||
|
mCallback = new Callback() {
|
||||||
|
@Override
|
||||||
|
public void onConfigChanged(ZenModeConfig config) {
|
||||||
|
controller.removeCallback(mCallback);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
controller.addCallback(mCallback);
|
||||||
|
Callback mockCallback = mock(Callback.class);
|
||||||
|
controller.addCallback(mockCallback);
|
||||||
|
controller.fireConfigChanged(null);
|
||||||
|
verify(mockCallback).onConfigChanged(eq(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user