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

Commit 7bc91dce authored by Lucas Silva's avatar Lucas Silva
Browse files

Remove key filter from shared preferences listener

If multiple keys are batched in a single write, it seems like the
callback is only called once with a single key instead of once for each
key that was written. This is causing the home panel component to not be
updated correctly.

Generally remove the ability to filter by key inside the shared
preferences flow helper in order to avoid falling into this trap.

Bug: 339095997
Test: atest SelectedComponentRepositoryTest
Test: manually verified not able to reproduce home panel bug with this
fix
Flag: NONE

Change-Id: Iac85cd2a276aba7c9590fd96aa7ff74e7b36f8d3
parent 119272db
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import com.android.systemui.controls.panels.SelectedComponentRepository
import com.android.systemui.controls.panels.authorizedPanelsRepository
import com.android.systemui.controls.panels.selectedComponentRepository
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.dreams.homecontrols.domain.interactor.HomeControlsComponentInteractor
import com.android.systemui.dreams.homecontrols.domain.interactor.HomeControlsComponentInteractor.Companion.MAX_UPDATE_CORRELATION_DELAY
import com.android.systemui.kosmos.testScope
import com.android.systemui.settings.fakeUserTracker
@@ -64,7 +63,7 @@ class HomeControlsComponentInteractorTest : SysuiTestCase() {

    private val kosmos = testKosmos()

    private lateinit var underTest: HomeControlsComponentInteractor
    private val underTest by lazy { kosmos.homeControlsComponentInteractor }

    @Before
    fun setUp() =
@@ -73,8 +72,7 @@ class HomeControlsComponentInteractorTest : SysuiTestCase() {
            fakeUserRepository.setUserInfos(listOf(PRIMARY_USER, ANOTHER_USER))
            whenever(controlsComponent.getControlsListingController())
                .thenReturn(Optional.of(controlsListingController))

            underTest = homeControlsComponentInteractor
            Unit
        }

    @Test
+1 −1
Original line number Diff line number Diff line
@@ -126,7 +126,7 @@ constructor(

    private fun observeCtaDismissState(user: UserInfo): Flow<Boolean> =
        getSharedPrefsForUser(user)
            .observe(CTA_DISMISSED_STATE)
            .observe()
            // Emit at the start of collection to ensure we get an initial value
            .onStart { emit(Unit) }
            .map { getCtaDismissedState() }
+2 −2
Original line number Diff line number Diff line
@@ -25,10 +25,10 @@ import com.android.systemui.settings.UserFileManager
import com.android.systemui.settings.UserTracker
import com.android.systemui.statusbar.policy.DeviceControlsControllerImpl
import com.android.systemui.util.kotlin.SharedPreferencesExt.observe
import com.android.systemui.util.kotlin.emitOnStart
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart

class AuthorizedPanelsRepositoryImpl
@Inject
@@ -40,7 +40,7 @@ constructor(

    override fun observeAuthorizedPanels(user: UserHandle): Flow<Set<String>> {
        val prefs = instantiateSharedPrefs(user)
        return prefs.observe(KEY).onStart { emit(Unit) }.map { getAuthorizedPanelsInternal(prefs) }
        return prefs.observe().emitOnStart().map { getAuthorizedPanelsInternal(prefs) }
    }

    override fun getAuthorizedPanels(): Set<String> {
+3 −3
Original line number Diff line number Diff line
@@ -26,12 +26,12 @@ import com.android.systemui.settings.UserFileManager
import com.android.systemui.settings.UserTracker
import com.android.systemui.statusbar.policy.DeviceControlsControllerImpl
import com.android.systemui.util.kotlin.SharedPreferencesExt.observe
import com.android.systemui.util.kotlin.emitOnStart
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart

@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
@SysUISingleton
@@ -63,8 +63,8 @@ constructor(
    ): Flow<SelectedComponentRepository.SelectedComponent?> {
        val prefs = getSharedPreferencesForUser(userHandle.identifier)
        return prefs
            .observe(PREF_COMPONENT)
            .onStart { emit(Unit) }
            .observe()
            .emitOnStart()
            .map { getSelectedComponent(userHandle) }
            .flowOn(bgDispatcher)
    }
+2 −2
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.app.DreamManager
import android.content.ComponentName
import android.os.PowerManager
import android.os.UserHandle
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.common.domain.interactor.PackageChangeInteractor
import com.android.systemui.common.shared.model.PackageChangeModel
import com.android.systemui.controls.ControlsServiceInfo
@@ -36,6 +35,7 @@ import com.android.systemui.util.kotlin.getOrNull
import com.android.systemui.util.kotlin.pairwiseBy
import com.android.systemui.util.kotlin.sample
import com.android.systemui.util.time.SystemClock
import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow
import javax.inject.Inject
import kotlin.math.abs
import kotlin.time.Duration.Companion.milliseconds
@@ -132,7 +132,7 @@ constructor(
                        ?: panels.firstOrNull()
                item?.panelActivity
            }
            .stateIn(bgScope, SharingStarted.WhileSubscribed(), null)
            .stateIn(bgScope, SharingStarted.Eagerly, null)

    private val taskFragmentFinished =
        MutableSharedFlow<Long>(replay = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
Loading