Loading libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterbox/MixedLetterboxController.kt +19 −1 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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, Loading Loading @@ -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) } } } } libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/letterbox/MixedLetterboxControllerTest.kt +72 −3 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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() Loading @@ -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(), Loading Loading @@ -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()) } Loading @@ -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 ) } } Loading
libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterbox/MixedLetterboxController.kt +19 −1 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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, Loading Loading @@ -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) } } } }
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/letterbox/MixedLetterboxControllerTest.kt +72 −3 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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() Loading @@ -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(), Loading Loading @@ -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()) } Loading @@ -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 ) } }