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

Commit e88c27b0 authored by Nate Myren's avatar Nate Myren
Browse files

Fix ConcurrentModification with service observers

Ensure that when notifying stale observers, and calling their onChanged
methods, we iterate over a static list copy, as some observers (notably
service observers) remove themselves from the observer list in their
onChanged method.

Fixes: 146349140
Test: Navigate to the Permission settings tab, while some phone
permissions are granted to some apps. The Permission controller summary
should say "Apps using phone" (or include phone in a list of permisions)

Change-Id: I89c35b916ef1c4e00328d017ab82be0f04d95d9f
parent bba589ff
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package com.android.permissioncontroller.permission.data

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.Lifecycle.State.STARTED
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
@@ -69,12 +69,11 @@ abstract class SmartUpdateMediatorLiveData<T> : MediatorLiveData<T>(),
            super.setValue(newValue)
        } else if (isStale) {
            isStale = false
            // We are no longer stale- notify stale listeners we are up-to-date
            for ((owner, observer) in staleObservers) {
                if (owner.lifecycle.currentState >= Lifecycle.State.STARTED) {
            // We are no longer stale- notify active stale observers we are up-to-date
            val liveObservers = staleObservers.filter { it.first.lifecycle.currentState >= STARTED }
            for ((_, observer) in liveObservers) {
                observer.onChanged(newValue)
            }
            }

            for ((liveData, observer, shouldUpdate) in children) {
                if (liveData.hasActiveObservers() && shouldUpdate) {