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

Commit 109ce60c authored by Massimo Carli's avatar Massimo Carli Committed by Android (Google) Code Review
Browse files

Merge "[76/n] Integrate RoundedCorners behind flag" into main

parents 4a7694e7 f066df23
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -19,8 +19,10 @@ package com.android.wm.shell.compatui.letterbox
import android.view.SurfaceControl
import android.view.SurfaceControl.Transaction
import android.window.WindowContainerToken
import com.android.window.flags.Flags
import com.android.wm.shell.compatui.letterbox.LetterboxControllerStrategy.LetterboxMode.MULTIPLE_SURFACES
import com.android.wm.shell.compatui.letterbox.LetterboxControllerStrategy.LetterboxMode.SINGLE_SURFACE
import com.android.wm.shell.compatui.letterbox.roundedcorners.RoundedCornersLetterboxController
import com.android.wm.shell.dagger.WMSingleton
import javax.inject.Inject

@@ -32,14 +34,17 @@ import javax.inject.Inject
class MixedLetterboxController
@Inject
constructor(
    private val letterboxConfiguration: LetterboxConfiguration,
    private val singleSurfaceController: SingleSurfaceLetterboxController,
    private val multipleSurfaceController: MultiSurfaceLetterboxController,
    private val controllerStrategy: LetterboxControllerStrategy,
    private val inputController: LetterboxInputController,
    private val roundedCornersController: RoundedCornersLetterboxController,
) :
    LetterboxController by singleSurfaceController
        .append(multipleSurfaceController)
        .append(inputController) {
        .append(inputController)
        .append(roundedCornersController) {

    override fun createLetterboxSurface(
        key: LetterboxKey,
@@ -68,5 +73,18 @@ constructor(
        } else {
            inputController.destroyLetterboxSurface(key, transaction)
        }
        // Handle RoundedCorners Controller.
        if (Flags.appCompatRefactoringRoundedCorners()) {
            if (letterboxConfiguration.isLetterboxActivityCornersRounded()) {
                roundedCornersController.createLetterboxSurface(
                    key,
                    transaction,
                    parentLeash,
                    token,
                )
            } else {
                roundedCornersController.destroyLetterboxSurface(key, transaction)
            }
        }
    }
}
+72 −3
Original line number Diff line number Diff line
@@ -16,10 +16,15 @@

package com.android.wm.shell.compatui.letterbox

import android.content.Context
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.testing.AndroidTestingRunner
import androidx.test.filters.SmallTest
import com.android.internal.hidden_from_bootclasspath.com.android.window.flags.Flags
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.compatui.letterbox.LetterboxControllerStrategy.LetterboxMode
import com.android.wm.shell.compatui.letterbox.roundedcorners.RoundedCornersLetterboxController
import java.util.function.Consumer
import org.junit.Test
import org.junit.runner.RunWith
@@ -79,20 +84,65 @@ class MixedLetterboxControllerTest : ShellTestCase() {
        }
    }

    @Test
    @EnableFlags(Flags.FLAG_APP_COMPAT_REFACTORING_ROUNDED_CORNERS)
    fun `Corners are created when enabled with radius more than zero`() {
        runTestScenario { r ->
            r.configureStrategyFor(LetterboxMode.SINGLE_SURFACE)
            r.configureStrategyFor { configuration ->
                configuration.setLetterboxActivityCornersRadius(10)
            }
            r.sendCreateSurfaceRequest()
            r.checkCreateInvokedOnRoundedCornersController(times = 1)
            r.checkDestroyInvokedOnRoundedCornersController(times = 0)
        }
    }

    @Test
    @EnableFlags(Flags.FLAG_APP_COMPAT_REFACTORING_ROUNDED_CORNERS)
    fun `Corners are destroyed when enabled with radius less or equals to zero`() {
        runTestScenario { r ->
            r.configureStrategyFor(LetterboxMode.SINGLE_SURFACE)
            r.configureStrategyFor { configuration ->
                configuration.setLetterboxActivityCornersRadius(0)
            }
            r.sendCreateSurfaceRequest()
            r.checkCreateInvokedOnRoundedCornersController(times = 0)
            r.checkDestroyInvokedOnRoundedCornersController(times = 1)
        }
    }

    @Test
    @DisableFlags(Flags.FLAG_APP_COMPAT_REFACTORING_ROUNDED_CORNERS)
    fun `Corners are not created when disabled even with radius more than zero`() {
        runTestScenario { r ->
            r.configureStrategyFor(LetterboxMode.SINGLE_SURFACE)
            r.configureStrategyFor { configuration ->
                configuration.setLetterboxActivityCornersRadius(10)
            }
            r.sendCreateSurfaceRequest()
            r.checkCreateInvokedOnRoundedCornersController(times = 0)
            r.checkDestroyInvokedOnRoundedCornersController(times = 0)
        }
    }

    /**
     * Runs a test scenario providing a Robot.
     */
    fun runTestScenario(consumer: Consumer<MixedLetterboxControllerRobotTest>) {
        consumer.accept(MixedLetterboxControllerRobotTest().apply { initController() })
        consumer.accept(MixedLetterboxControllerRobotTest(mContext).apply { initController() })
    }

    class MixedLetterboxControllerRobotTest : LetterboxControllerRobotTest() {
    class MixedLetterboxControllerRobotTest(ctx: Context) : LetterboxControllerRobotTest() {
        val letterboxConfiguration: LetterboxConfiguration = LetterboxConfiguration(ctx)
        val singleLetterboxController: SingleSurfaceLetterboxController =
            mock<SingleSurfaceLetterboxController>()
        val multipleLetterboxController: MultiSurfaceLetterboxController =
            mock<MultiSurfaceLetterboxController>()
        val controllerStrategy: LetterboxControllerStrategy = mock<LetterboxControllerStrategy>()
        val inputController: LetterboxInputController = mock<LetterboxInputController>()
        val roundedCornersController: RoundedCornersLetterboxController =
            mock<RoundedCornersLetterboxController>()

        fun configureStrategyFor(letterboxMode: LetterboxMode) {
            doReturn(letterboxMode).`when`(controllerStrategy).getLetterboxImplementationMode()
@@ -104,6 +154,10 @@ class MixedLetterboxControllerTest : ShellTestCase() {
            ).`when`(controllerStrategy).shouldSupportInputSurface()
        }

        fun configureStrategyFor(consumer: (LetterboxConfiguration) -> Unit) {
            consumer(letterboxConfiguration)
        }

        fun checkCreateInvokedOnSingleController(times: Int = 1) {
            verify(singleLetterboxController, times(times)).createLetterboxSurface(
                any(),
@@ -131,6 +185,15 @@ class MixedLetterboxControllerTest : ShellTestCase() {
            )
        }

        fun checkCreateInvokedOnRoundedCornersController(times: Int = 1) {
            verify(roundedCornersController, times(times)).createLetterboxSurface(
                any(),
                any(),
                any(),
                any()
            )
        }

        fun checkDestroyInvokedOnSingleController(times: Int = 1) {
            verify(singleLetterboxController, times(times)).destroyLetterboxSurface(any(), any())
        }
@@ -143,11 +206,17 @@ class MixedLetterboxControllerTest : ShellTestCase() {
            verify(multipleLetterboxController, times(times)).destroyLetterboxSurface(any(), any())
        }

        fun checkDestroyInvokedOnRoundedCornersController(times: Int = 1) {
            verify(roundedCornersController, times(times)).destroyLetterboxSurface(any(), any())
        }

        override fun buildController(): LetterboxController = MixedLetterboxController(
            letterboxConfiguration,
            singleLetterboxController,
            multipleLetterboxController,
            controllerStrategy,
            inputController
            inputController,
            roundedCornersController
        )
    }
}