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

Commit 9e4770e7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make UserTrackerImpl.userInfo thread-safe." into main

parents 227c6c4f 85c8c448
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -103,11 +103,8 @@ internal constructor(
    override val userContentResolver: ContentResolver
        get() = userContext.contentResolver

    override val userInfo: UserInfo
        get() {
            val user = userId
            return userProfiles.first { it.id == user }
        }
    override var userInfo: UserInfo by SynchronizedDelegate(UserInfo(context.userId, "", 0))
        protected set

    /**
     * Returns a [List<UserInfo>] of all profiles associated with the current user.
@@ -187,6 +184,7 @@ internal constructor(
            userHandle = handle
            userContext = ctx
            userProfiles = profiles.map { UserInfo(it) }
            userInfo = profiles.first { it.id == user }
        }
        return ctx to profiles
    }
+15 −15
Original line number Diff line number Diff line
@@ -79,21 +79,6 @@ class UserTrackerImplReceiveTest : SysuiTestCase() {

    @Test
    fun callsCallbackAndUpdatesProfilesWhenAnIntentReceived() = runTest {
        tracker =
            UserTrackerImpl(
                context,
                { fakeFeatures },
                userManager,
                iActivityManager,
                dumpManager,
                this,
                testDispatcher,
                handler
            )
        tracker.initialize(0)
        tracker.addCallback(callback, executor)
        val profileID = tracker.userId + 10

        `when`(userManager.getProfiles(anyInt())).thenAnswer { invocation ->
            val id = invocation.getArgument<Int>(0)
            val info = UserInfo(id, "", UserInfo.FLAG_FULL)
@@ -109,6 +94,21 @@ class UserTrackerImplReceiveTest : SysuiTestCase() {
            listOf(info, infoProfile)
        }

        tracker =
            UserTrackerImpl(
                context,
                { fakeFeatures },
                userManager,
                iActivityManager,
                dumpManager,
                this,
                testDispatcher,
                handler
            )
        tracker.initialize(0)
        tracker.addCallback(callback, executor)
        val profileID = tracker.userId + 10

        tracker.onReceive(context, Intent(intentAction))

        verify(callback, times(0)).onUserChanged(anyInt(), any())