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

Commit e90606d9 authored by Will Leshner's avatar Will Leshner
Browse files

Fix a crash when registering/unregistering a smartspace timer listener.

Bug: 322860683
Fix: 322860683
Test: atest CommunalSmartspaceControllerTest
Test: atest CommunalInteractorTest
Flag: ACONFIG com.android.systemui.communal_hub STAGING

Change-Id: I6b3eadb3529ecf86d23b8777705d54fe742b34b1
parent 9dc01e8b
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -21,7 +21,9 @@ import android.os.Parcelable
import android.widget.RemoteViews
import com.android.systemui.communal.smartspace.CommunalSmartspaceController
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.plugins.BcSmartspaceDataPlugin
import java.util.concurrent.Executor
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
@@ -41,6 +43,7 @@ class SmartspaceRepositoryImpl
@Inject
constructor(
    private val communalSmartspaceController: CommunalSmartspaceController,
    @Main private val uiExecutor: Executor,
) : SmartspaceRepository, BcSmartspaceDataPlugin.SmartspaceTargetListener {

    override val isSmartspaceRemoteViewsEnabled: Boolean
@@ -51,13 +54,19 @@ constructor(
    override val communalSmartspaceTargets: Flow<List<SmartspaceTarget>> =
        _communalSmartspaceTargets
            .onStart {
                communalSmartspaceController.addListener(listener = this@SmartspaceRepositoryImpl)
                uiExecutor.execute {
                    communalSmartspaceController.addListener(
                        listener = this@SmartspaceRepositoryImpl
                    )
                }
            }
            .onCompletion {
                uiExecutor.execute {
                    communalSmartspaceController.removeListener(
                        listener = this@SmartspaceRepositoryImpl
                    )
                }
            }

    override fun onSmartspaceTargetsUpdated(targetsNullable: MutableList<out Parcelable>?) {
        targetsNullable?.let { targets ->