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

Commit ec287c08 authored by Aaron Liu's avatar Aaron Liu
Browse files

Update users when locale changes.

When system language changes, make sure we refresh users.

Fixes: 261185091
Test: Change system language.

Change-Id: I28adc747500c6d31306bc9f1e6a956e9e0d6d0b3
parent fcb9745a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@ open class UserTrackerImpl internal constructor(
        setUserIdInternal(startingUser)

        val filter = IntentFilter().apply {
            addAction(Intent.ACTION_LOCALE_CHANGED)
            addAction(Intent.ACTION_USER_INFO_CHANGED)
            // These get called when a managed profile goes in or out of quiet mode.
            addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE)
@@ -149,6 +150,7 @@ open class UserTrackerImpl internal constructor(

    override fun onReceive(context: Context, intent: Intent) {
        when (intent.action) {
            Intent.ACTION_LOCALE_CHANGED,
            Intent.ACTION_USER_INFO_CHANGED,
            Intent.ACTION_MANAGED_PROFILE_AVAILABLE,
            Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE,
+2 −0
Original line number Diff line number Diff line
@@ -325,6 +325,7 @@ constructor(
                            addAction(Intent.ACTION_USER_SWITCHED)
                            addAction(Intent.ACTION_USER_STOPPED)
                            addAction(Intent.ACTION_USER_UNLOCKED)
                            addAction(Intent.ACTION_LOCALE_CHANGED)
                        },
                    user = UserHandle.SYSTEM,
                    map = { intent, _ -> intent },
@@ -615,6 +616,7 @@ constructor(
    ) {
        val shouldRefreshAllUsers =
            when (intent.action) {
                Intent.ACTION_LOCALE_CHANGED -> true
                Intent.ACTION_USER_SWITCHED -> {
                    dismissDialog()
                    val selectedUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1)
+1 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ class UserTrackerImplReceiveTest : SysuiTestCase() {
        @Parameterized.Parameters
        fun data(): Iterable<String> =
            listOf(
                Intent.ACTION_LOCALE_CHANGED,
                Intent.ACTION_USER_INFO_CHANGED,
                Intent.ACTION_MANAGED_PROFILE_AVAILABLE,
                Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE,
+2 −1
Original line number Diff line number Diff line
@@ -177,7 +177,8 @@ class UserTrackerImplTest : SysuiTestCase() {
        verify(context)
                .registerReceiverForAllUsers(eq(tracker), capture(captor), isNull(), eq(handler))
        with(captor.value) {
            assertThat(countActions()).isEqualTo(6)
            assertThat(countActions()).isEqualTo(7)
            assertThat(hasAction(Intent.ACTION_LOCALE_CHANGED)).isTrue()
            assertThat(hasAction(Intent.ACTION_USER_INFO_CHANGED)).isTrue()
            assertThat(hasAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE)).isTrue()
            assertThat(hasAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE)).isTrue()
+20 −0
Original line number Diff line number Diff line
@@ -731,6 +731,26 @@ class UserInteractorTest : SysuiTestCase() {
        }
    }

    @Test
    fun localeChanged_refreshUsers() {
        createUserInteractor()
        testScope.runTest {
            val userInfos = createUserInfos(count = 2, includeGuest = false)
            userRepository.setUserInfos(userInfos)
            userRepository.setSelectedUserInfo(userInfos[0])
            runCurrent()
            val refreshUsersCallCount = userRepository.refreshUsersCallCount

            fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly(
                spyContext,
                Intent(Intent.ACTION_LOCALE_CHANGED)
            )
            runCurrent()

            assertThat(userRepository.refreshUsersCallCount).isEqualTo(refreshUsersCallCount + 1)
        }
    }

    @Test
    fun nonSystemUserUnlockedBroadcast_doNotRefreshUsers() {
        createUserInteractor()