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

Commit d12183e0 authored by brycelee's avatar brycelee Committed by Bryce Lee
Browse files

DreamOverlayInteractor Introduction.

This changelist introduces DreamOverlayInteractor to interface with
DreamOverlayStateController.

Bug: 407646672
Test: atest DreamOverlayInteractorTest
Flag: EXEMPT refactor
Change-Id: I6225641a2765c1609db2666d8e6699a1d519e69e
parent de527e5d
Loading
Loading
Loading
Loading
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.dreams.domain.interactor

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.complication.Complication.COMPLICATION_TYPE_TIME
import com.android.systemui.dreams.dreamOverlayStateController
import com.android.systemui.flags.Flags
import com.android.systemui.flags.fake
import com.android.systemui.flags.featureFlagsClassic
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class DreamOverlayInteractorTest : SysuiTestCase() {
    private val kosmos = testKosmos().useUnconfinedTestDispatcher()

    private val Kosmos.underTest by Kosmos.Fixture { dreamOverlayInteractor }

    @Before
    fun setup() {
        kosmos.featureFlagsClassic.fake.set(Flags.ALWAYS_SHOW_HOME_CONTROLS_ON_DREAMS, false)
    }

    @Test
    fun testAvailableTypes() =
        kosmos.runTest {
            val lastValue by collectLastValue(underTest.availableComplicationTypes)

            dreamOverlayStateController.availableComplicationTypes = COMPLICATION_TYPE_TIME

            assertThat(lastValue).isEqualTo(COMPLICATION_TYPE_TIME)
        }
}
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.dreams.domain.interactor

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dreams.DreamOverlayStateController
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.flowOn

@SysUISingleton
class DreamOverlayInteractor
@Inject
constructor(
    dreamOverlayStateController: DreamOverlayStateController,
    @Background private val bgDispatcher: CoroutineDispatcher,
) {
    val availableComplicationTypes: Flow<Int> =
        callbackFlow {
                val callback =
                    object : DreamOverlayStateController.Callback {
                        override fun onAvailableComplicationTypesChanged() {
                            trySend(dreamOverlayStateController.availableComplicationTypes)
                        }
                    }
                dreamOverlayStateController.addCallback(callback)
                callback.onAvailableComplicationTypesChanged()

                awaitClose { dreamOverlayStateController.removeCallback(callback) }
            }
            .flowOn(bgDispatcher)
}
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.dreams.domain.interactor

import com.android.systemui.dreams.dreamOverlayStateController
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.Kosmos.Fixture
import com.android.systemui.kosmos.testDispatcher

val Kosmos.dreamOverlayInteractor by Fixture {
    DreamOverlayInteractor(
        bgDispatcher = testDispatcher,
        dreamOverlayStateController = dreamOverlayStateController,
    )
}