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

Commit 28bfe550 authored by Helen Cheuk's avatar Helen Cheuk Committed by Android (Google) Code Review
Browse files

Merge "[Action Corner] Call LauncherProxyService to notify launcher of active...

Merge "[Action Corner] Call LauncherProxyService to notify launcher of active action corner" into main
parents 1dace026 96ba607b
Loading
Loading
Loading
Loading
+75 −0
Original line number Diff line number Diff line
/*
 * Copyright 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.actioncorner.domain.interactor

import android.view.Display.DEFAULT_DISPLAY
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.LauncherProxyService
import com.android.systemui.SysuiTestCase
import com.android.systemui.actioncorner.data.model.ActionCornerRegion.BOTTOM_LEFT
import com.android.systemui.actioncorner.data.model.ActionCornerRegion.BOTTOM_RIGHT
import com.android.systemui.actioncorner.data.model.ActionCornerState
import com.android.systemui.actioncorner.data.repository.FakeActionCornerRepository
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.Kosmos.Fixture
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.lifecycle.activateIn
import com.android.systemui.shared.system.actioncorner.ActionCornerConstants.HOME
import com.android.systemui.shared.system.actioncorner.ActionCornerConstants.OVERVIEW
import com.android.systemui.testKosmos
import kotlin.test.Test
import org.junit.Before
import org.junit.runner.RunWith
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify

@SmallTest
@RunWith(AndroidJUnit4::class)
class ActionCornerInteractorTest : SysuiTestCase() {
    private val kosmos = testKosmos().useUnconfinedTestDispatcher()
    private val Kosmos.actionCornerRepository by Fixture { FakeActionCornerRepository() }
    private val Kosmos.launcherProxyService by Fixture { mock<LauncherProxyService>() }
    private val Kosmos.underTest by Fixture {
        ActionCornerInteractor(kosmos.actionCornerRepository, kosmos.launcherProxyService)
    }

    @Before
    fun setUp() {
        kosmos.underTest.activateIn(kosmos.testScope)
    }

    @Test
    fun bottomLeftCornerActivated_notifyLauncherOfOverviewAction() =
        kosmos.runTest {
            actionCornerRepository.addState(
                ActionCornerState.ActiveActionCorner(BOTTOM_LEFT, DEFAULT_DISPLAY)
            )
            verify(launcherProxyService).onActionCornerActivated(OVERVIEW, DEFAULT_DISPLAY)
        }

    @Test
    fun bottomRightCornerActivated_notifyLauncherOfHomeAction() =
        kosmos.runTest {
            actionCornerRepository.addState(
                ActionCornerState.ActiveActionCorner(BOTTOM_RIGHT, DEFAULT_DISPLAY)
            )
            verify(launcherProxyService).onActionCornerActivated(HOME, DEFAULT_DISPLAY)
        }
}
+20 −4
Original line number Diff line number Diff line
@@ -17,10 +17,17 @@
package com.android.systemui.actioncorner.domain.interactor

import com.android.systemui.LauncherProxyService
import com.android.systemui.actioncorner.data.model.ActionCornerRegion.BOTTOM_LEFT
import com.android.systemui.actioncorner.data.model.ActionCornerRegion.BOTTOM_RIGHT
import com.android.systemui.actioncorner.data.model.ActionCornerState
import com.android.systemui.actioncorner.data.repository.ActionCornerRepository
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.lifecycle.ExclusiveActivatable
import com.android.systemui.shared.system.actioncorner.ActionCornerConstants.HOME
import com.android.systemui.shared.system.actioncorner.ActionCornerConstants.OVERVIEW
import javax.inject.Inject
import kotlinx.coroutines.awaitCancellation
import kotlinx.coroutines.flow.filterIsInstance

@SysUISingleton
class ActionCornerInteractor
@@ -31,9 +38,18 @@ constructor(
) : ExclusiveActivatable() {

    override suspend fun onActivated(): Nothing {
        repository.actionCornerState.collect {
            // TODO: call methods in LauncherProxyService to send action to launcher when the APIs
            // are ready
        repository.actionCornerState
            .filterIsInstance<ActionCornerState.ActiveActionCorner>()
            .collect {
                // TODO(b/410791828): Read corresponding action from Action Corner Setting page
                when (it.region) {
                    BOTTOM_LEFT ->
                        launcherProxyService.onActionCornerActivated(OVERVIEW, it.displayId)
                    BOTTOM_RIGHT -> launcherProxyService.onActionCornerActivated(HOME, it.displayId)
                    // TODO(b/411091884): Handle actions for notification shade and QS
                    else -> {}
                }
            }
        awaitCancellation()
    }
}
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright 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.actioncorner.data.repository

import com.android.systemui.actioncorner.data.model.ActionCornerState
import com.android.systemui.actioncorner.data.model.ActionCornerState.InactiveActionCorner
import kotlinx.coroutines.flow.MutableStateFlow

class FakeActionCornerRepository : ActionCornerRepository {
    override val actionCornerState = MutableStateFlow<ActionCornerState>(InactiveActionCorner)

    fun addState(state: ActionCornerState) {
        actionCornerState.value = state
    }
}