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

Commit 349c46c4 authored by Dave Mankoff's avatar Dave Mankoff
Browse files

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
Change-Id: I6752fbd677a63e72f16edcaebb678a4272432e3b
parent 99c0de24
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -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,13 +152,17 @@ class ConfigurationControllerImpl @Inject constructor(
    }

    override fun addCallback(listener: ConfigurationListener) {
        synchronized(listeners) {
            listeners.add(listener)
        }
        listener.onDensityOrFontScaleChanged()
    }

    override fun removeCallback(listener: ConfigurationListener) {
        synchronized(listeners) {
            listeners.remove(listener)
        }
    }

    override fun isLayoutRtl(): Boolean {
        return layoutDirection == LAYOUT_DIRECTION_RTL