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

Commit b37f9cc6 authored by Shawn Lin's avatar Shawn Lin
Browse files

Support onBeforeUserSwitching in UserTracker.Callback

Bug: 303589201
Test: atest KeyguardZenAlarmViewControllerTest NextClockAlarmControllerTest
Change-Id: I9ecc23bd7a04569897b9a031f3b246a637736b30
parent 641f6fab
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -68,6 +68,10 @@ interface UserTracker : UserContentResolverProvider, UserContextProvider {
     */
    @WeaklyReferencedCallback
    interface Callback {
        /**
         * Notifies that the current user will be changed.
         */
        fun onBeforeUserSwitching(newUser: Int) {}

        /**
         * Same as {@link onUserChanging(Int, Context, Runnable)} but the callback will be
+7 −0
Original line number Diff line number Diff line
@@ -226,6 +226,13 @@ open class UserTrackerImpl internal constructor(
    protected open fun handleBeforeUserSwitching(newUserId: Int) {
        Assert.isNotMainThread()
        setUserIdInternal(newUserId)

        val list = synchronized(callbacks) {
            callbacks.toList()
        }
        list.forEach {
            it.callback.get()?.onBeforeUserSwitching(newUserId)
        }
    }

    @WorkerThread
+6 −0
Original line number Diff line number Diff line
@@ -69,10 +69,16 @@ class FakeUserTracker(
        _userId = _userInfo.id
        _userHandle = UserHandle.of(_userId)

        onBeforeUserSwitching()
        onUserChanging()
        onUserChanged()
    }

    fun onBeforeUserSwitching(userId: Int = _userId) {
        val copy = callbacks.toList()
        copy.forEach { it.onBeforeUserSwitching(userId) }
    }

    fun onUserChanging(userId: Int = _userId) {
        val copy = callbacks.toList()
        copy.forEach { it.onUserChanging(userId, userContext) {} }