From 2caeebc5df64bb1e1bf235d9ed688f8d98e0408a Mon Sep 17 00:00:00 2001 From: Alejandro Nijamkin Date: Wed, 28 Sep 2022 16:52:55 -0700 Subject: [PATCH] Splits up the flag. We need two flags: 1. Whether the interactor and repository depend on the controller (which is what is being checked by the logic in the CLs in this chain). Currently true, can be set to false once we finish removing the controller dependency from the interactor and repository. 2. Whether the controller depends on the interactor (currently false, cannot be turned on until after the previous flag is eliminated). This way, we can roll out the logic that severs the dependency on the controller in repo and interactors without touching legacy code which still wants to depend on the old controller (extensions of the BaseUserSwitcherAdapter class do this - a next step would be to replace those with adapters that can deal with the new data schema). Bug: 246631653 Test: manually verified the operations of the full-screen user switcher, the smaller dialog, the footer in quick settings, and the dropdown switcher on the lock-screen bouncer. Change-Id: I8b7ba0aa043aab39266e1e8fbde69697ddf235d0 --- .../src/com/android/systemui/flags/Flags.java | 23 ++++++-- .../policy/UserSwitcherControllerImpl.kt | 53 ++++++++++--------- .../user/data/repository/UserRepository.kt | 2 +- .../user/domain/interactor/UserInteractor.kt | 2 +- .../dialog/UserSwitcherDialogCoordinator.kt | 2 +- .../ui/viewmodel/UserSwitcherViewModel.kt | 2 +- .../data/repository/UserRepositoryImplTest.kt | 2 +- .../domain/interactor/UserInteractorTest.kt | 2 +- .../ui/viewmodel/UserSwitcherViewModelTest.kt | 2 +- 9 files changed, 54 insertions(+), 36 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/flags/Flags.java b/packages/SystemUI/src/com/android/systemui/flags/Flags.java index 48f5f9eda9092..ad2549b9d567d 100644 --- a/packages/SystemUI/src/com/android/systemui/flags/Flags.java +++ b/packages/SystemUI/src/com/android/systemui/flags/Flags.java @@ -104,9 +104,26 @@ public class Flags { public static final UnreleasedFlag MODERN_USER_SWITCHER_ACTIVITY = new UnreleasedFlag(209, true); - /** Whether the new implementation of UserSwitcherController should be used. */ - public static final UnreleasedFlag REFACTORED_USER_SWITCHER_CONTROLLER = - new UnreleasedFlag(210, false); + /** + * Whether the user interactor and repository should use `UserSwitcherController`. + * + *

If this is {@code false}, the interactor and repo skip the controller and directly access + * the framework APIs. + */ + public static final UnreleasedFlag USER_INTERACTOR_AND_REPO_USE_CONTROLLER = + new UnreleasedFlag(210, true); + + /** + * Whether `UserSwitcherController` should use the user interactor. + * + *

When this is {@code true}, the controller does not directly access framework APIs. + * Instead, it goes through the interactor. + * + *

Note: do not set this to true if {@link #USER_INTERACTOR_AND_REPO_USE_CONTROLLER} is + * {@code true} as it would created a cycle between controller -> interactor -> controller. + */ + public static final UnreleasedFlag USER_CONTROLLER_USES_INTERACTOR = + new UnreleasedFlag(211, false); /***************************************/ // 300 - power menu diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherControllerImpl.kt index e283413d566c4..4932a6544d05f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherControllerImpl.kt @@ -37,8 +37,9 @@ constructor( @Suppress("DEPRECATION") private val oldImpl: Lazy, ) : UserSwitcherController { - private val isNewImpl: Boolean - get() = flags.isEnabled(Flags.REFACTORED_USER_SWITCHER_CONTROLLER) + private val useInteractor: Boolean = + flags.isEnabled(Flags.USER_CONTROLLER_USES_INTERACTOR) && + !flags.isEnabled(Flags.USER_INTERACTOR_AND_REPO_USE_CONTROLLER) private val _oldImpl: UserSwitcherControllerOldImpl get() = oldImpl.get() @@ -48,7 +49,7 @@ constructor( override val users: ArrayList get() = - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.users @@ -56,14 +57,14 @@ constructor( override val isSimpleUserSwitcher: Boolean get() = - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.isSimpleUserSwitcher } override fun init(view: View) { - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.init(view) @@ -72,7 +73,7 @@ constructor( override val currentUserRecord: UserRecord? get() = - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.currentUserRecord @@ -80,7 +81,7 @@ constructor( override val currentUserName: String? get() = - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.currentUserName @@ -90,7 +91,7 @@ constructor( userId: Int, dialogShower: UserSwitchDialogController.DialogShower? ) { - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.onUserSelected(userId, dialogShower) @@ -99,7 +100,7 @@ constructor( override val isAddUsersFromLockScreenEnabled: Flow get() = - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.isAddUsersFromLockScreenEnabled @@ -107,7 +108,7 @@ constructor( override val isGuestUserAutoCreated: Boolean get() = - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.isGuestUserAutoCreated @@ -115,7 +116,7 @@ constructor( override val isGuestUserResetting: Boolean get() = - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.isGuestUserResetting @@ -124,7 +125,7 @@ constructor( override fun createAndSwitchToGuestUser( dialogShower: UserSwitchDialogController.DialogShower?, ) { - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.createAndSwitchToGuestUser(dialogShower) @@ -132,7 +133,7 @@ constructor( } override fun showAddUserDialog(dialogShower: UserSwitchDialogController.DialogShower?) { - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.showAddUserDialog(dialogShower) @@ -140,7 +141,7 @@ constructor( } override fun startSupervisedUserActivity() { - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.startSupervisedUserActivity() @@ -148,7 +149,7 @@ constructor( } override fun onDensityOrFontScaleChanged() { - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.onDensityOrFontScaleChanged() @@ -156,7 +157,7 @@ constructor( } override fun addAdapter(adapter: WeakReference) { - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.addAdapter(adapter) @@ -167,7 +168,7 @@ constructor( record: UserRecord, dialogShower: UserSwitchDialogController.DialogShower?, ) { - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.onUserListItemClicked(record, dialogShower) @@ -175,7 +176,7 @@ constructor( } override fun removeGuestUser(guestUserId: Int, targetUserId: Int) { - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.removeGuestUser(guestUserId, targetUserId) @@ -187,7 +188,7 @@ constructor( targetUserId: Int, forceRemoveGuestOnExit: Boolean ) { - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.exitGuestUser(guestUserId, targetUserId, forceRemoveGuestOnExit) @@ -195,7 +196,7 @@ constructor( } override fun schedulePostBootGuestCreation() { - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.schedulePostBootGuestCreation() @@ -204,14 +205,14 @@ constructor( override val isKeyguardShowing: Boolean get() = - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.isKeyguardShowing } override fun startActivity(intent: Intent) { - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.startActivity(intent) @@ -219,7 +220,7 @@ constructor( } override fun refreshUsers(forcePictureLoadForId: Int) { - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.refreshUsers(forcePictureLoadForId) @@ -227,7 +228,7 @@ constructor( } override fun addUserSwitchCallback(callback: UserSwitcherController.UserSwitchCallback) { - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.addUserSwitchCallback(callback) @@ -235,7 +236,7 @@ constructor( } override fun removeUserSwitchCallback(callback: UserSwitcherController.UserSwitchCallback) { - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.removeUserSwitchCallback(callback) @@ -243,7 +244,7 @@ constructor( } override fun dump(pw: PrintWriter, args: Array) { - if (isNewImpl) { + if (useInteractor) { notYetImplemented() } else { _oldImpl.dump(pw, args) diff --git a/packages/SystemUI/src/com/android/systemui/user/data/repository/UserRepository.kt b/packages/SystemUI/src/com/android/systemui/user/data/repository/UserRepository.kt index b85e85d01b692..3014f39c17f83 100644 --- a/packages/SystemUI/src/com/android/systemui/user/data/repository/UserRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/user/data/repository/UserRepository.kt @@ -134,7 +134,7 @@ constructor( ) : UserRepository { private val isNewImpl: Boolean - get() = featureFlags.isEnabled(Flags.REFACTORED_USER_SWITCHER_CONTROLLER) + get() = !featureFlags.isEnabled(Flags.USER_INTERACTOR_AND_REPO_USE_CONTROLLER) private val _userSwitcherSettings = MutableStateFlow(null) override val userSwitcherSettings: Flow = diff --git a/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserInteractor.kt b/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserInteractor.kt index 7d2d1224fc370..e6bb9bcbc2645 100644 --- a/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserInteractor.kt @@ -102,7 +102,7 @@ constructor( } private val isNewImpl: Boolean - get() = featureFlags.isEnabled(Flags.REFACTORED_USER_SWITCHER_CONTROLLER) + get() = !featureFlags.isEnabled(Flags.USER_INTERACTOR_AND_REPO_USE_CONTROLLER) private val supervisedUserPackageName: String? get() = diff --git a/packages/SystemUI/src/com/android/systemui/user/ui/dialog/UserSwitcherDialogCoordinator.kt b/packages/SystemUI/src/com/android/systemui/user/ui/dialog/UserSwitcherDialogCoordinator.kt index 690e987bd9ab2..6e7b5232d818b 100644 --- a/packages/SystemUI/src/com/android/systemui/user/ui/dialog/UserSwitcherDialogCoordinator.kt +++ b/packages/SystemUI/src/com/android/systemui/user/ui/dialog/UserSwitcherDialogCoordinator.kt @@ -53,7 +53,7 @@ constructor( private var currentDialog: Dialog? = null override fun start() { - if (!featureFlags.isEnabled(Flags.REFACTORED_USER_SWITCHER_CONTROLLER)) { + if (featureFlags.isEnabled(Flags.USER_INTERACTOR_AND_REPO_USE_CONTROLLER)) { return } diff --git a/packages/SystemUI/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModel.kt b/packages/SystemUI/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModel.kt index dbb8200d57d8d..5b83df7b4a368 100644 --- a/packages/SystemUI/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModel.kt @@ -45,7 +45,7 @@ private constructor( ) : ViewModel() { private val isNewImpl: Boolean - get() = featureFlags.isEnabled(Flags.REFACTORED_USER_SWITCHER_CONTROLLER) + get() = !featureFlags.isEnabled(Flags.USER_INTERACTOR_AND_REPO_USE_CONTROLLER) /** On-device users. */ val users: Flow> = diff --git a/packages/SystemUI/tests/src/com/android/systemui/user/data/repository/UserRepositoryImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/user/data/repository/UserRepositoryImplTest.kt index 6568f5f680e77..dcea83a55a747 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/user/data/repository/UserRepositoryImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/user/data/repository/UserRepositoryImplTest.kt @@ -47,7 +47,7 @@ abstract class UserRepositoryImplTest : SysuiTestCase() { globalSettings = FakeSettings() tracker = FakeUserTracker() featureFlags = FakeFeatureFlags() - featureFlags.set(Flags.REFACTORED_USER_SWITCHER_CONTROLLER, isRefactored) + featureFlags.set(Flags.USER_INTERACTOR_AND_REPO_USE_CONTROLLER, !isRefactored) } protected fun create(scope: CoroutineScope = TestCoroutineScope()): UserRepositoryImpl { diff --git a/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt index d57f84b5704a6..8465f4f46d62b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt @@ -81,7 +81,7 @@ abstract class UserInteractorTest : SysuiTestCase() { ), featureFlags = FakeFeatureFlags().apply { - set(Flags.REFACTORED_USER_SWITCHER_CONTROLLER, isRefactored()) + set(Flags.USER_INTERACTOR_AND_REPO_USE_CONTROLLER, !isRefactored()) }, manager = manager, applicationScope = testCoroutineScope, diff --git a/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt index 7fd29af2a80a1..0344e3f991e2d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt @@ -84,7 +84,7 @@ class UserSwitcherViewModelTest : SysuiTestCase() { keyguardRepository = FakeKeyguardRepository() powerRepository = FakePowerRepository() val featureFlags = FakeFeatureFlags() - featureFlags.set(Flags.REFACTORED_USER_SWITCHER_CONTROLLER, false) + featureFlags.set(Flags.USER_INTERACTOR_AND_REPO_USE_CONTROLLER, true) val scope = TestCoroutineScope() val refreshUsersScheduler = RefreshUsersScheduler(