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

Commit 6d638a89 authored by Alejandro Nijamkin's avatar Alejandro Nijamkin
Browse files

Makes camera config dep. lazy.

This was needed because of a Dagger-related crash when querying the
content provider while a secondary user is selected. I don't understand
why it was happening, but this fixes it and is a safe fix.

Also formats the file using `ktfmt`.

Bug: 254333599
Test: when signed in with a secondary user and querying the quick
affordance content provider from the wallpaper picker experience, we no
longer see a crash.

Change-Id: Ie195b21934179576051371181560c2263284b98c
parent 94f82c67
Loading
Loading
Loading
Loading
+21 −12
Original line number Diff line number Diff line
@@ -26,14 +26,17 @@ import com.android.systemui.common.shared.model.ContentDescription
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import dagger.Lazy
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import javax.inject.Inject

@SysUISingleton
class CameraQuickAffordanceConfig @Inject constructor(
class CameraQuickAffordanceConfig
@Inject
constructor(
    @Application private val context: Context,
        private val cameraGestureHelper: CameraGestureHelper,
    private val cameraGestureHelper: Lazy<CameraGestureHelper>,
) : KeyguardQuickAffordanceConfig {

    override val key: String
@@ -46,17 +49,23 @@ class CameraQuickAffordanceConfig @Inject constructor(
        get() = com.android.internal.R.drawable.perm_group_camera

    override val lockScreenState: Flow<KeyguardQuickAffordanceConfig.LockScreenState>
        get() = flowOf(
        get() =
            flowOf(
                KeyguardQuickAffordanceConfig.LockScreenState.Visible(
                    icon = Icon.Resource(
                    icon =
                        Icon.Resource(
                            com.android.internal.R.drawable.perm_group_camera,
                            ContentDescription.Resource(R.string.accessibility_camera_button)
                        )
                )
            )

    override fun onTriggered(expandable: Expandable?): KeyguardQuickAffordanceConfig.OnTriggeredResult {
        cameraGestureHelper.launchCamera(StatusBarManager.CAMERA_LAUNCH_SOURCE_QUICK_AFFORDANCE)
    override fun onTriggered(
        expandable: Expandable?
    ): KeyguardQuickAffordanceConfig.OnTriggeredResult {
        cameraGestureHelper
            .get()
            .launchCamera(StatusBarManager.CAMERA_LAUNCH_SOURCE_QUICK_AFFORDANCE)
        return KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled
    }
}
+11 −7
Original line number Diff line number Diff line
@@ -37,23 +37,27 @@ class CameraQuickAffordanceConfigTest : SysuiTestCase() {

    @Mock private lateinit var cameraGestureHelper: CameraGestureHelper
    @Mock private lateinit var context: Context

    private lateinit var underTest: CameraQuickAffordanceConfig

    @Before
    fun setUp() {
        MockitoAnnotations.initMocks(this)
        underTest = CameraQuickAffordanceConfig(

        underTest =
            CameraQuickAffordanceConfig(
                context,
                cameraGestureHelper,
        )
            ) {
                cameraGestureHelper
            }
    }

    @Test
    fun `affordance triggered -- camera launch called`() {
        //when
        // When
        val result = underTest.onTriggered(null)

        //then
        // Then
        verify(cameraGestureHelper)
            .launchCamera(StatusBarManager.CAMERA_LAUNCH_SOURCE_QUICK_AFFORDANCE)
        assertEquals(KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled, result)