diff options
author | 2024-05-07 18:23:29 +0000 | |
---|---|---|
committer | 2024-05-29 03:47:33 +0000 | |
commit | d23f2a9bbbe9d9ecebe34b16b2d8a7f6b02d0418 (patch) | |
tree | 5e9ed8c74a6bf036481143aa16c8d81e6677910a /packages | |
parent | 0d9eb30b3835f8db3813fbd8a09410208eb68326 (diff) |
Synchronize listeners in ConfigurationControllerImpl
An array was being modified at the same time it was being copied.
This causes nulls to be copied into the new destination, resulting in
unexpected NPEs when accessed.
Flag: NA
Test: NA
Fixes: 280463030
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:349c46c498eeca75823d1853057193f60595db04)
Merged-In: I6752fbd677a63e72f16edcaebb678a4272432e3b
Change-Id: I6752fbd677a63e72f16edcaebb678a4272432e3b
Diffstat (limited to 'packages')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/ConfigurationControllerImpl.kt | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ConfigurationControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ConfigurationControllerImpl.kt index dea94162ad0e..2e1ab383538f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ConfigurationControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ConfigurationControllerImpl.kt @@ -59,7 +59,10 @@ class ConfigurationControllerImpl @Inject constructor( } override fun notifyThemeChanged() { - val listeners = ArrayList(listeners) + // Avoid concurrent modification exception + val listeners = synchronized(this.listeners) { + ArrayList(this.listeners) + } listeners.filterForEach({ this.listeners.contains(it) }) { it.onThemeChanged() @@ -68,8 +71,9 @@ class ConfigurationControllerImpl @Inject constructor( override fun onConfigurationChanged(newConfig: Configuration) { // Avoid concurrent modification exception - val listeners = ArrayList(listeners) - + val listeners = synchronized(this.listeners) { + ArrayList(this.listeners) + } listeners.filterForEach({ this.listeners.contains(it) }) { it.onConfigChanged(newConfig) } @@ -148,12 +152,16 @@ class ConfigurationControllerImpl @Inject constructor( } override fun addCallback(listener: ConfigurationListener) { - listeners.add(listener) + synchronized(listeners) { + listeners.add(listener) + } listener.onDensityOrFontScaleChanged() } override fun removeCallback(listener: ConfigurationListener) { - listeners.remove(listener) + synchronized(listeners) { + listeners.remove(listener) + } } override fun isLayoutRtl(): Boolean { |