diff --git a/packages/SystemUI/src/com/android/systemui/bouncer/shared/flag/ComposeBouncerFlags.kt b/packages/SystemUI/src/com/android/systemui/bouncer/shared/flag/ComposeBouncerFlags.kt new file mode 100644 index 0000000000000000000000000000000000000000..e789475b7877468a22a07e597f525b6b9c03766d --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/bouncer/shared/flag/ComposeBouncerFlags.kt @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2024 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.bouncer.shared.flag + +import com.android.systemui.Flags +import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.scene.shared.flag.SceneContainerFlags +import dagger.Module +import dagger.Provides + +interface ComposeBouncerFlags { + + /** + * Returns `true` if the Compose bouncer is enabled or if the scene container framework is + * enabled; `false` otherwise. + */ + fun isComposeBouncerOrSceneContainerEnabled(): Boolean + + /** + * Returns `true` if only compose bouncer is enabled and scene container framework is not + * enabled. + */ + @Deprecated( + "Avoid using this, this is meant to be used only by the glue code " + + "that includes compose bouncer in legacy keyguard.", + replaceWith = ReplaceWith("isComposeBouncerOrSceneContainerEnabled()") + ) + fun isOnlyComposeBouncerEnabled(): Boolean +} + +class ComposeBouncerFlagsImpl(private val sceneContainerFlags: SceneContainerFlags) : + ComposeBouncerFlags { + + override fun isComposeBouncerOrSceneContainerEnabled(): Boolean { + return sceneContainerFlags.isEnabled() || Flags.composeBouncer() + } + + @Deprecated( + "Avoid using this, this is meant to be used only by the glue code " + + "that includes compose bouncer in legacy keyguard.", + replaceWith = ReplaceWith("isComposeBouncerOrSceneContainerEnabled()") + ) + override fun isOnlyComposeBouncerEnabled(): Boolean { + return !sceneContainerFlags.isEnabled() && Flags.composeBouncer() + } +} + +@Module +object ComposeBouncerFlagsModule { + @Provides + @SysUISingleton + fun impl(sceneContainerFlags: SceneContainerFlags): ComposeBouncerFlags { + return ComposeBouncerFlagsImpl(sceneContainerFlags) + } +} diff --git a/packages/SystemUI/src/com/android/systemui/bouncer/ui/binder/BouncerViewBinder.kt b/packages/SystemUI/src/com/android/systemui/bouncer/ui/binder/BouncerViewBinder.kt index dd253a8f6eff32591af2062ddcf88b96b6f67f37..36d3ed52b6555618d3ecc35598211ab8f7b5206b 100644 --- a/packages/SystemUI/src/com/android/systemui/bouncer/ui/binder/BouncerViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/bouncer/ui/binder/BouncerViewBinder.kt @@ -4,10 +4,10 @@ import android.view.ViewGroup import com.android.keyguard.KeyguardMessageAreaController import com.android.keyguard.ViewMediatorCallback import com.android.keyguard.dagger.KeyguardBouncerComponent -import com.android.systemui.Flags import com.android.systemui.authentication.domain.interactor.AuthenticationInteractor import com.android.systemui.bouncer.domain.interactor.BouncerMessageInteractor import com.android.systemui.bouncer.domain.interactor.PrimaryBouncerInteractor +import com.android.systemui.bouncer.shared.flag.ComposeBouncerFlags import com.android.systemui.bouncer.ui.BouncerDialogFactory import com.android.systemui.bouncer.ui.viewmodel.BouncerViewModel import com.android.systemui.bouncer.ui.viewmodel.KeyguardBouncerViewModel @@ -55,12 +55,15 @@ constructor( class BouncerViewBinder @Inject constructor( + private val composeBouncerFlags: ComposeBouncerFlags, private val legacyBouncerDependencies: Lazy<LegacyBouncerDependencies>, private val composeBouncerDependencies: Lazy<ComposeBouncerDependencies>, ) { fun bind(view: ViewGroup) { if ( - ComposeFacade.isComposeAvailable() && Flags.composeBouncer() && COMPOSE_BOUNCER_ENABLED + COMPOSE_BOUNCER_ENABLED && + composeBouncerFlags.isOnlyComposeBouncerEnabled() && + ComposeFacade.isComposeAvailable() ) { val deps = composeBouncerDependencies.get() ComposeBouncerViewBinder.bind( diff --git a/packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/BouncerViewModel.kt b/packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/BouncerViewModel.kt index 4466cbbe05beb6d20cd1518e3b5075c36e2cc8ac..62875783ef5f31c61b72a4fbd47de514550849b1 100644 --- a/packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/BouncerViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/BouncerViewModel.kt @@ -28,6 +28,7 @@ import com.android.systemui.authentication.shared.model.AuthenticationWipeModel import com.android.systemui.bouncer.domain.interactor.BouncerActionButtonInteractor import com.android.systemui.bouncer.domain.interactor.BouncerInteractor import com.android.systemui.bouncer.domain.interactor.SimBouncerInteractor +import com.android.systemui.bouncer.shared.flag.ComposeBouncerFlags import com.android.systemui.bouncer.shared.model.BouncerActionButtonModel import com.android.systemui.common.shared.model.Icon import com.android.systemui.common.shared.model.Text @@ -35,7 +36,6 @@ import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.inputmethod.domain.interactor.InputMethodInteractor -import com.android.systemui.scene.shared.flag.SceneContainerFlags import com.android.systemui.user.domain.interactor.SelectedUserInteractor import com.android.systemui.user.ui.viewmodel.UserActionViewModel import com.android.systemui.user.ui.viewmodel.UserSwitcherViewModel @@ -72,7 +72,7 @@ class BouncerViewModel( private val simBouncerInteractor: SimBouncerInteractor, private val authenticationInteractor: AuthenticationInteractor, private val selectedUserInteractor: SelectedUserInteractor, - flags: SceneContainerFlags, + flags: ComposeBouncerFlags, selectedUser: Flow<UserViewModel>, users: Flow<List<UserViewModel>>, userSwitcherMenu: Flow<List<UserActionViewModel>>, @@ -233,7 +233,7 @@ class BouncerViewModel( private var lockoutCountdownJob: Job? = null init { - if (flags.isEnabled()) { + if (flags.isComposeBouncerOrSceneContainerEnabled()) { // Keeps the lockout dialog up-to-date. applicationScope.launch { bouncerInteractor.onLockoutStarted.collect { @@ -478,7 +478,7 @@ object BouncerViewModelModule { actionButtonInteractor: BouncerActionButtonInteractor, authenticationInteractor: AuthenticationInteractor, selectedUserInteractor: SelectedUserInteractor, - flags: SceneContainerFlags, + flags: ComposeBouncerFlags, userSwitcherViewModel: UserSwitcherViewModel, clock: SystemClock, devicePolicyManager: DevicePolicyManager, diff --git a/packages/SystemUI/src/com/android/systemui/scene/SceneContainerFrameworkModule.kt b/packages/SystemUI/src/com/android/systemui/scene/SceneContainerFrameworkModule.kt index c7d3a4af24c9ad00e7dc39d08489da3ef7343c09..7d2468b2f01690a514af04579826f9764226f425 100644 --- a/packages/SystemUI/src/com/android/systemui/scene/SceneContainerFrameworkModule.kt +++ b/packages/SystemUI/src/com/android/systemui/scene/SceneContainerFrameworkModule.kt @@ -17,6 +17,7 @@ package com.android.systemui.scene import com.android.systemui.CoreStartable +import com.android.systemui.bouncer.shared.flag.ComposeBouncerFlagsModule import com.android.systemui.scene.domain.interactor.WindowRootViewVisibilityInteractor import com.android.systemui.scene.domain.startable.SceneContainerStartable import com.android.systemui.scene.shared.flag.SceneContainerFlagsModule @@ -34,6 +35,7 @@ import dagger.multibindings.IntoMap [ BouncerSceneModule::class, CommunalSceneModule::class, + ComposeBouncerFlagsModule::class, EmptySceneModule::class, GoneSceneModule::class, LockscreenSceneModule::class, diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/shared/flag/ComposeBouncerFlagsKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/shared/flag/ComposeBouncerFlagsKosmos.kt new file mode 100644 index 0000000000000000000000000000000000000000..5c3e1f410e63b2f583aae177bfd6477bf608e08f --- /dev/null +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/shared/flag/ComposeBouncerFlagsKosmos.kt @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2024 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.bouncer.shared.flag + +import com.android.systemui.kosmos.Kosmos +import com.android.systemui.scene.shared.flag.fakeSceneContainerFlags + +var Kosmos.fakeComposeBouncerFlags by + Kosmos.Fixture { FakeComposeBouncerFlags(fakeSceneContainerFlags) } +val Kosmos.composeBouncerFlags by Kosmos.Fixture<ComposeBouncerFlags> { fakeComposeBouncerFlags } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/shared/flag/FakeComposeBouncerFlags.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/shared/flag/FakeComposeBouncerFlags.kt new file mode 100644 index 0000000000000000000000000000000000000000..c116bbd32f9e511a7025e889a09a902e85087694 --- /dev/null +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/shared/flag/FakeComposeBouncerFlags.kt @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2024 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.bouncer.shared.flag + +import com.android.systemui.scene.shared.flag.SceneContainerFlags + +class FakeComposeBouncerFlags( + private val sceneContainerFlags: SceneContainerFlags, + var composeBouncerEnabled: Boolean = false +) : ComposeBouncerFlags { + override fun isComposeBouncerOrSceneContainerEnabled(): Boolean { + return sceneContainerFlags.isEnabled() || composeBouncerEnabled + } + + @Deprecated( + "Avoid using this, this is meant to be used only by the glue code " + + "that includes compose bouncer in legacy keyguard.", + replaceWith = ReplaceWith("isComposeBouncerOrSceneContainerEnabled()") + ) + override fun isOnlyComposeBouncerEnabled(): Boolean = composeBouncerEnabled +} diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/ui/viewmodel/BouncerViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/ui/viewmodel/BouncerViewModelKosmos.kt index 99dfe94af3dfa0e1da7261102c002be7f7146a98..6d97238ba48b49cf1b52abec0133342a5730d1f8 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/ui/viewmodel/BouncerViewModelKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/ui/viewmodel/BouncerViewModelKosmos.kt @@ -21,12 +21,12 @@ import com.android.systemui.authentication.domain.interactor.authenticationInter import com.android.systemui.bouncer.domain.interactor.bouncerActionButtonInteractor import com.android.systemui.bouncer.domain.interactor.bouncerInteractor import com.android.systemui.bouncer.domain.interactor.simBouncerInteractor +import com.android.systemui.bouncer.shared.flag.composeBouncerFlags import com.android.systemui.inputmethod.domain.interactor.inputMethodInteractor import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.Kosmos.Fixture import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope -import com.android.systemui.scene.shared.flag.sceneContainerFlags import com.android.systemui.user.domain.interactor.selectedUserInteractor import com.android.systemui.user.ui.viewmodel.userSwitcherViewModel import com.android.systemui.util.mockito.mock @@ -42,7 +42,7 @@ val Kosmos.bouncerViewModel by Fixture { simBouncerInteractor = simBouncerInteractor, authenticationInteractor = authenticationInteractor, selectedUserInteractor = selectedUserInteractor, - flags = sceneContainerFlags, + flags = composeBouncerFlags, selectedUser = userSwitcherViewModel.selectedUser, users = userSwitcherViewModel.users, userSwitcherMenu = userSwitcherViewModel.menu,