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
This commit is contained in:
Alejandro Nijamkin
2022-09-28 16:52:55 -07:00
parent ea92f14c6a
commit 2caeebc5df
9 changed files with 54 additions and 36 deletions

View File

@@ -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`.
*
* <p>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.
*
* <p>When this is {@code true}, the controller does not directly access framework APIs.
* Instead, it goes through the interactor.
*
* <p>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

View File

@@ -37,8 +37,9 @@ constructor(
@Suppress("DEPRECATION") private val oldImpl: Lazy<UserSwitcherControllerOldImpl>,
) : 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<UserRecord>
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<Boolean>
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<BaseUserSwitcherAdapter>) {
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<out String>) {
if (isNewImpl) {
if (useInteractor) {
notYetImplemented()
} else {
_oldImpl.dump(pw, args)

View File

@@ -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<UserSwitcherSettingsModel?>(null)
override val userSwitcherSettings: Flow<UserSwitcherSettingsModel> =

View File

@@ -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() =

View File

@@ -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
}

View File

@@ -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<List<UserViewModel>> =

View File

@@ -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 {

View File

@@ -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,

View File

@@ -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(