From 5763f3a1f458b66692b0753f07f82455c92a626b Mon Sep 17 00:00:00 2001 From: Nicolo' Mazzucato Date: Tue, 15 Feb 2022 16:02:13 +0100 Subject: [PATCH] Assert add/removeCallbacks are from main thread in DevicePostureControllerImpl There have been bugs associated to concurrent modifications of mListeners, but we're not able to reproduce them. With this cl, there will be a more obvious error message in future bugs, if there will be any. Bug: 219510239 Test: Manually tried to trigger the assert, failing. Change-Id: I9dd5e0fd45227b133b17f5a6680b35c89b183ce8 --- .../statusbar/policy/DevicePostureControllerImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DevicePostureControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DevicePostureControllerImpl.java index 8471e0aa1640f..a32a5ab13748c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DevicePostureControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DevicePostureControllerImpl.java @@ -25,6 +25,7 @@ import androidx.annotation.NonNull; import com.android.internal.R; import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.dagger.qualifiers.Main; +import com.android.systemui.util.Assert; import java.util.ArrayList; import java.util.List; @@ -70,6 +71,7 @@ public class DevicePostureControllerImpl implements DevicePostureController { } deviceStateManager.registerCallback(executor, state -> { + Assert.isMainThread(); mCurrentDevicePosture = mDeviceStateToPostureMap.get(state, DEVICE_POSTURE_UNKNOWN); @@ -79,11 +81,13 @@ public class DevicePostureControllerImpl implements DevicePostureController { @Override public void addCallback(@NonNull Callback listener) { + Assert.isMainThread(); mListeners.add(listener); } @Override public void removeCallback(@NonNull Callback listener) { + Assert.isMainThread(); mListeners.remove(listener); }