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

Commit d23f2a9b authored by Dave Mankoff's avatar Dave Mankoff Committed by Cherrypicker Worker
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
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:349c46c498eeca75823d1853057193f60595db04)
Merged-In: I6752fbd677a63e72f16edcaebb678a4272432e3b
Change-Id: I6752fbd677a63e72f16edcaebb678a4272432e3b
parent 0d9eb30b
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