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

Commit 430d8155 authored by Anton Potapov's avatar Anton Potapov Committed by Android (Google) Code Review
Browse files

Merge "Add FakeDevicePostureController" into main

parents 3122ef7c 53ec1aca
Loading
Loading
Loading
Loading
+51 −0
Original line number Original line 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.volume.dialog.domain.interactor

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
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.plugins.fakeVolumeDialogController
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class VolumeDialogStateInteractorTest : SysuiTestCase() {

    private val kosmos: Kosmos = testKosmos().useUnconfinedTestDispatcher()

    private val underTest: VolumeDialogStateInteractor
        get() = kosmos.volumeDialogStateInteractor

    @Test
    fun dialogState_collectedEagerly() =
        kosmos.runTest {
            val nonDefaultActiveStream = 123
            fakeVolumeDialogController.setActiveStream(123)

            val volumeDialogStateModel by collectLastValue(underTest.volumeDialogState)

            assertThat(volumeDialogStateModel?.activeStream).isEqualTo(nonDefaultActiveStream)
        }
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.buffer
import kotlinx.coroutines.flow.buffer
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.flow.shareIn


private const val BUFFER_CAPACITY = 16
private const val BUFFER_CAPACITY = 16
@@ -60,6 +61,7 @@ constructor(
            }
            }
            .buffer(capacity = BUFFER_CAPACITY, onBufferOverflow = BufferOverflow.DROP_OLDEST)
            .buffer(capacity = BUFFER_CAPACITY, onBufferOverflow = BufferOverflow.DROP_OLDEST)
            .shareIn(replay = 0, scope = coroutineScope, started = SharingStarted.WhileSubscribed())
            .shareIn(replay = 0, scope = coroutineScope, started = SharingStarted.WhileSubscribed())
            .onStart { emit(VolumeDialogEventModel.SubscribedToEvents) }


    private class VolumeDialogEventModelProducer(
    private class VolumeDialogEventModelProducer(
        private val scope: ProducerScope<VolumeDialogEventModel>
        private val scope: ProducerScope<VolumeDialogEventModel>
+1 −1
Original line number Original line Diff line number Diff line
@@ -22,7 +22,7 @@ import com.android.systemui.kosmos.testScope
import com.android.systemui.shared.settings.data.repository.secureSettingsRepository
import com.android.systemui.shared.settings.data.repository.secureSettingsRepository
import com.android.systemui.shared.settings.data.repository.systemSettingsRepository
import com.android.systemui.shared.settings.data.repository.systemSettingsRepository


val Kosmos.notificationSettingsRepository by
var Kosmos.notificationSettingsRepository by
    Kosmos.Fixture {
    Kosmos.Fixture {
        NotificationSettingsRepository(
        NotificationSettingsRepository(
            backgroundScope = testScope.backgroundScope,
            backgroundScope = testScope.backgroundScope,
+2 −1
Original line number Original line Diff line number Diff line
@@ -19,4 +19,5 @@ package com.android.systemui.statusbar.policy
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.mock


val Kosmos.devicePostureController by Kosmos.Fixture { mock<DevicePostureController>() }
val Kosmos.fakeDevicePostureController by Kosmos.Fixture { FakeDevicePostureController() }
var Kosmos.devicePostureController by Kosmos.Fixture { mock<DevicePostureController>() }
+39 −0
Original line number Original line 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.statusbar.policy

import com.android.systemui.statusbar.policy.DevicePostureController.DevicePostureInt

class FakeDevicePostureController : DevicePostureController {

    private var devicePosture: Int = DevicePostureController.DEVICE_POSTURE_OPENED
    val callbacks: MutableCollection<DevicePostureController.Callback> = mutableSetOf()

    override fun addCallback(listener: DevicePostureController.Callback) {
        callbacks.add(listener)
    }

    override fun removeCallback(listener: DevicePostureController.Callback) {
        callbacks.add(listener)
    }

    fun setDevicePosture(@DevicePostureInt posture: Int) {
        devicePosture = posture
    }

    @DevicePostureInt override fun getDevicePosture(): Int = devicePosture
}
Loading