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

Commit 2caeebc5 authored by Alejandro Nijamkin's avatar Alejandro Nijamkin
Browse files

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
parent ea92f14c
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -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
+27 −26
Original line number Diff line number Diff line
@@ -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)
+1 −1
Original line number Diff line number Diff line
@@ -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> =
+1 −1
Original line number Diff line number Diff line
@@ -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() =
+1 −1
Original line number Diff line number Diff line
@@ -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
        }

Loading