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

Commit 91486c33 authored by William Xiao's avatar William Xiao
Browse files

Apply ktfmt

Separate CL to aid code review

Bug: N/A
Test: N/A
Flag: EXEMPT just formatting
Change-Id: I4268cfad8e6c2e8d3176564bc3875882df30dac9
parent 19e53473
Loading
Loading
Loading
Loading
+25 −101
Original line number Diff line number Diff line
@@ -110,27 +110,13 @@ class KeyguardQuickAffordanceLocalUserSelectionManagerTest : SysuiTestCase() {
        val affordanceId2 = "affordance2"
        val affordanceId3 = "affordance3"

        underTest.setSelections(
            slotId = slotId1,
            affordanceIds = listOf(affordanceId1),
        )
        assertSelections(
            affordanceIdsBySlotId.last(),
            mapOf(
                slotId1 to listOf(affordanceId1),
            ),
        )
        underTest.setSelections(slotId = slotId1, affordanceIds = listOf(affordanceId1))
        assertSelections(affordanceIdsBySlotId.last(), mapOf(slotId1 to listOf(affordanceId1)))

        underTest.setSelections(
            slotId = slotId2,
            affordanceIds = listOf(affordanceId2),
        )
        underTest.setSelections(slotId = slotId2, affordanceIds = listOf(affordanceId2))
        assertSelections(
            affordanceIdsBySlotId.last(),
            mapOf(
                slotId1 to listOf(affordanceId1),
                slotId2 to listOf(affordanceId2),
            )
            mapOf(slotId1 to listOf(affordanceId1), slotId2 to listOf(affordanceId2)),
        )

        underTest.setSelections(
@@ -139,34 +125,19 @@ class KeyguardQuickAffordanceLocalUserSelectionManagerTest : SysuiTestCase() {
        )
        assertSelections(
            affordanceIdsBySlotId.last(),
            mapOf(
                slotId1 to listOf(affordanceId1, affordanceId3),
                slotId2 to listOf(affordanceId2),
            )
            mapOf(slotId1 to listOf(affordanceId1, affordanceId3), slotId2 to listOf(affordanceId2)),
        )

        underTest.setSelections(
            slotId = slotId1,
            affordanceIds = listOf(affordanceId3),
        )
        underTest.setSelections(slotId = slotId1, affordanceIds = listOf(affordanceId3))
        assertSelections(
            affordanceIdsBySlotId.last(),
            mapOf(
                slotId1 to listOf(affordanceId3),
                slotId2 to listOf(affordanceId2),
            )
            mapOf(slotId1 to listOf(affordanceId3), slotId2 to listOf(affordanceId2)),
        )

        underTest.setSelections(
            slotId = slotId2,
            affordanceIds = listOf(),
        )
        underTest.setSelections(slotId = slotId2, affordanceIds = listOf())
        assertSelections(
            affordanceIdsBySlotId.last(),
            mapOf(
                slotId1 to listOf(affordanceId3),
                slotId2 to listOf(),
            )
            mapOf(slotId1 to listOf(affordanceId3), slotId2 to listOf()),
        )

        job.cancel()
@@ -174,10 +145,7 @@ class KeyguardQuickAffordanceLocalUserSelectionManagerTest : SysuiTestCase() {

    @Test
    fun remembersSelectionsByUser() = runTest {
        overrideResource(
            R.array.config_keyguardQuickAffordanceDefaults,
            arrayOf<String>(),
        )
        overrideResource(R.array.config_keyguardQuickAffordanceDefaults, arrayOf<String>())
        val slot1 = "slot_1"
        val slot2 = "slot_2"
        val affordance1 = "affordance_1"
@@ -195,60 +163,28 @@ class KeyguardQuickAffordanceLocalUserSelectionManagerTest : SysuiTestCase() {
                UserInfo(/* id= */ 0, "zero", /* flags= */ 0),
                UserInfo(/* id= */ 1, "one", /* flags= */ 0),
            )
        userTracker.set(
            userInfos = userInfos,
            selectedUserIndex = 0,
        )
        underTest.setSelections(
            slotId = slot1,
            affordanceIds = listOf(affordance1),
        )
        underTest.setSelections(
            slotId = slot2,
            affordanceIds = listOf(affordance2),
        )
        userTracker.set(userInfos = userInfos, selectedUserIndex = 0)
        underTest.setSelections(slotId = slot1, affordanceIds = listOf(affordance1))
        underTest.setSelections(slotId = slot2, affordanceIds = listOf(affordance2))

        // Switch to user 1
        userTracker.set(
            userInfos = userInfos,
            selectedUserIndex = 1,
        )
        userTracker.set(userInfos = userInfos, selectedUserIndex = 1)
        // We never set selections on user 1, so it should be empty.
        assertSelections(
            observed = affordanceIdsBySlotId.last(),
            expected = emptyMap(),
        )
        assertSelections(observed = affordanceIdsBySlotId.last(), expected = emptyMap())
        // Now, let's set selections on user 1.
        underTest.setSelections(
            slotId = slot1,
            affordanceIds = listOf(affordance2),
        )
        underTest.setSelections(
            slotId = slot2,
            affordanceIds = listOf(affordance3),
        )
        underTest.setSelections(slotId = slot1, affordanceIds = listOf(affordance2))
        underTest.setSelections(slotId = slot2, affordanceIds = listOf(affordance3))
        assertSelections(
            observed = affordanceIdsBySlotId.last(),
            expected =
                mapOf(
                    slot1 to listOf(affordance2),
                    slot2 to listOf(affordance3),
                ),
            expected = mapOf(slot1 to listOf(affordance2), slot2 to listOf(affordance3)),
        )

        // Switch back to user 0.
        userTracker.set(
            userInfos = userInfos,
            selectedUserIndex = 0,
        )
        userTracker.set(userInfos = userInfos, selectedUserIndex = 0)
        // Assert that we still remember the old selections for user 0.
        assertSelections(
            observed = affordanceIdsBySlotId.last(),
            expected =
                mapOf(
                    slot1 to listOf(affordance1),
                    slot2 to listOf(affordance2),
                ),
            expected = mapOf(slot1 to listOf(affordance1), slot2 to listOf(affordance2)),
        )

        job.cancel()
@@ -276,10 +212,7 @@ class KeyguardQuickAffordanceLocalUserSelectionManagerTest : SysuiTestCase() {

        assertSelections(
            affordanceIdsBySlotId.last(),
            mapOf(
                slotId1 to listOf(affordanceId1, affordanceId3),
                slotId2 to listOf(affordanceId2),
            ),
            mapOf(slotId1 to listOf(affordanceId1, affordanceId3), slotId2 to listOf(affordanceId2)),
        )

        job.cancel()
@@ -308,10 +241,7 @@ class KeyguardQuickAffordanceLocalUserSelectionManagerTest : SysuiTestCase() {
        underTest.setSelections(slotId1, listOf(affordanceId2))
        assertSelections(
            affordanceIdsBySlotId.last(),
            mapOf(
                slotId1 to listOf(affordanceId2),
                slotId2 to listOf(affordanceId2),
            ),
            mapOf(slotId1 to listOf(affordanceId2), slotId2 to listOf(affordanceId2)),
        )

        job.cancel()
@@ -340,10 +270,7 @@ class KeyguardQuickAffordanceLocalUserSelectionManagerTest : SysuiTestCase() {
        underTest.setSelections(slotId1, listOf())
        assertSelections(
            affordanceIdsBySlotId.last(),
            mapOf(
                slotId1 to listOf(),
                slotId2 to listOf(affordanceId2),
            ),
            mapOf(slotId1 to listOf(), slotId2 to listOf(affordanceId2)),
        )

        job.cancel()
@@ -373,15 +300,12 @@ class KeyguardQuickAffordanceLocalUserSelectionManagerTest : SysuiTestCase() {
        overrideResource(R.bool.custom_lockscreen_shortcuts_enabled, false)
        overrideResource(
            R.array.config_keyguardQuickAffordanceDefaults,
            arrayOf("leftTest:testShortcut1", "rightTest:testShortcut2")
            arrayOf("leftTest:testShortcut1", "rightTest:testShortcut2"),
        )

        assertThat(underTest.getSelections())
            .isEqualTo(
                mapOf(
                    "leftTest" to listOf("testShortcut1"),
                    "rightTest" to listOf("testShortcut2"),
                )
                mapOf("leftTest" to listOf("testShortcut1"), "rightTest" to listOf("testShortcut2"))
            )
    }

+19 −83
Original line number Diff line number Diff line
@@ -84,13 +84,7 @@ class KeyguardQuickAffordanceRepositoryTest : SysuiTestCase() {
                context = context,
                userFileManager =
                    mock<UserFileManager>().apply {
                        whenever(
                                getSharedPreferences(
                                    anyString(),
                                    anyInt(),
                                    anyInt(),
                                )
                            )
                        whenever(getSharedPreferences(anyString(), anyInt(), anyInt()))
                            .thenReturn(FakeSharedPreferences())
                    },
                userTracker = userTracker,
@@ -103,9 +97,8 @@ class KeyguardQuickAffordanceRepositoryTest : SysuiTestCase() {
                scope = testScope.backgroundScope,
                userTracker = userTracker,
                clientFactory =
                    FakeKeyguardQuickAffordanceProviderClientFactory(
                        userTracker,
                    ) { selectedUserId ->
                    FakeKeyguardQuickAffordanceProviderClientFactory(userTracker) { selectedUserId
                        ->
                        when (selectedUserId) {
                            SECONDARY_USER_1 -> client1
                            SECONDARY_USER_2 -> client2
@@ -115,10 +108,7 @@ class KeyguardQuickAffordanceRepositoryTest : SysuiTestCase() {
                userHandle = UserHandle.SYSTEM,
            )

        overrideResource(
            R.array.config_keyguardQuickAffordanceDefaults,
            arrayOf<String>(),
        )
        overrideResource(R.array.config_keyguardQuickAffordanceDefaults, arrayOf<String>())

        underTest =
            KeyguardQuickAffordanceRepository(
@@ -155,30 +145,19 @@ class KeyguardQuickAffordanceRepositoryTest : SysuiTestCase() {
            val slotId2 = "slot2"

            underTest.setSelections(slotId1, listOf(config1.key))
            assertSelections(
                configsBySlotId(),
                mapOf(
                    slotId1 to listOf(config1),
                ),
            )
            assertSelections(configsBySlotId(), mapOf(slotId1 to listOf(config1)))

            underTest.setSelections(slotId2, listOf(config2.key))
            assertSelections(
                configsBySlotId(),
                mapOf(
                    slotId1 to listOf(config1),
                    slotId2 to listOf(config2),
                ),
                mapOf(slotId1 to listOf(config1), slotId2 to listOf(config2)),
            )

            underTest.setSelections(slotId1, emptyList())
            underTest.setSelections(slotId2, listOf(config1.key))
            assertSelections(
                configsBySlotId(),
                mapOf(
                    slotId1 to emptyList(),
                    slotId2 to listOf(config1),
                ),
                mapOf(slotId1 to emptyList(), slotId2 to listOf(config1)),
            )
        }

@@ -209,28 +188,15 @@ class KeyguardQuickAffordanceRepositoryTest : SysuiTestCase() {
        val slot3 = "slot3"
        context.orCreateTestableResources.addOverride(
            R.array.config_keyguardQuickAffordanceSlots,
            arrayOf(
                "$slot1:2",
                "$slot2:4",
                "$slot3:5",
            ),
            arrayOf("$slot1:2", "$slot2:4", "$slot3:5"),
        )

        assertThat(underTest.getSlotPickerRepresentations())
            .isEqualTo(
                listOf(
                    KeyguardSlotPickerRepresentation(
                        id = slot1,
                        maxSelectedAffordances = 2,
                    ),
                    KeyguardSlotPickerRepresentation(
                        id = slot2,
                        maxSelectedAffordances = 4,
                    ),
                    KeyguardSlotPickerRepresentation(
                        id = slot3,
                        maxSelectedAffordances = 5,
                    ),
                    KeyguardSlotPickerRepresentation(id = slot1, maxSelectedAffordances = 2),
                    KeyguardSlotPickerRepresentation(id = slot2, maxSelectedAffordances = 4),
                    KeyguardSlotPickerRepresentation(id = slot3, maxSelectedAffordances = 5),
                )
            )
    }
@@ -243,28 +209,15 @@ class KeyguardQuickAffordanceRepositoryTest : SysuiTestCase() {
        val slot3 = "slot3"
        context.orCreateTestableResources.addOverride(
            R.array.config_keyguardQuickAffordanceSlots,
            arrayOf(
                "$slot1:2",
                "$slot2:4",
                "$slot3:5",
            ),
            arrayOf("$slot1:2", "$slot2:4", "$slot3:5"),
        )

        assertThat(underTest.getSlotPickerRepresentations())
            .isEqualTo(
                listOf(
                    KeyguardSlotPickerRepresentation(
                        id = slot3,
                        maxSelectedAffordances = 5,
                    ),
                    KeyguardSlotPickerRepresentation(
                        id = slot2,
                        maxSelectedAffordances = 4,
                    ),
                    KeyguardSlotPickerRepresentation(
                        id = slot1,
                        maxSelectedAffordances = 2,
                    ),
                    KeyguardSlotPickerRepresentation(id = slot3, maxSelectedAffordances = 5),
                    KeyguardSlotPickerRepresentation(id = slot2, maxSelectedAffordances = 4),
                    KeyguardSlotPickerRepresentation(id = slot1, maxSelectedAffordances = 2),
                )
            )
    }
@@ -275,21 +228,9 @@ class KeyguardQuickAffordanceRepositoryTest : SysuiTestCase() {
            userTracker.set(
                userInfos =
                    listOf(
                        UserInfo(
                            UserHandle.USER_SYSTEM,
                            "Primary",
                            /* flags= */ 0,
                        ),
                        UserInfo(
                            SECONDARY_USER_1,
                            "Secondary 1",
                            /* flags= */ 0,
                        ),
                        UserInfo(
                            SECONDARY_USER_2,
                            "Secondary 2",
                            /* flags= */ 0,
                        ),
                        UserInfo(UserHandle.USER_SYSTEM, "Primary", /* flags= */ 0),
                        UserInfo(SECONDARY_USER_1, "Secondary 1", /* flags= */ 0),
                        UserInfo(SECONDARY_USER_2, "Secondary 2", /* flags= */ 0),
                    ),
                selectedUserIndex = 2,
            )
@@ -302,12 +243,7 @@ class KeyguardQuickAffordanceRepositoryTest : SysuiTestCase() {
            assertSelections(
                observed = observed(),
                expected =
                    mapOf(
                        KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START to
                            listOf(
                                config2,
                            ),
                    )
                    mapOf(KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START to listOf(config2)),
            )
        }

+2 −6
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.res.R
import com.android.systemui.settings.UserFileManager
import com.android.systemui.settings.UserTracker
@@ -102,7 +101,7 @@ constructor(
                    // common case anyway as restoration really only happens on initial device
                    // setup).
                    emit(Unit)
                }
                },
            ) { _, _ ->
            }
            .flatMapLatest {
@@ -164,10 +163,7 @@ constructor(
        return result
    }

    override fun setSelections(
        slotId: String,
        affordanceIds: List<String>,
    ) {
    override fun setSelections(slotId: String, affordanceIds: List<String>) {
        val key = "$KEY_PREFIX_SLOT$slotId"
        val value = affordanceIds.joinToString(AFFORDANCE_DELIMITER)
        sharedPrefs.edit().putString(key, value).apply()