Loading packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepository.kt +25 −25 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.systemui.keyguard.data.repository import android.content.Context import android.os.UserHandle import android.util.LayoutDirection import com.android.systemui.Dumpable import com.android.systemui.R import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging Loading Loading @@ -113,30 +114,6 @@ constructor( initialValue = emptyMap(), ) private val _slotPickerRepresentations: List<KeyguardSlotPickerRepresentation> by lazy { fun parseSlot(unparsedSlot: String): Pair<String, Int> { val split = unparsedSlot.split(SLOT_CONFIG_DELIMITER) check(split.size == 2) val slotId = split[0] val slotCapacity = split[1].toInt() return slotId to slotCapacity } val unparsedSlots = appContext.resources.getStringArray(R.array.config_keyguardQuickAffordanceSlots) val seenSlotIds = mutableSetOf<String>() unparsedSlots.mapNotNull { unparsedSlot -> val (slotId, slotCapacity) = parseSlot(unparsedSlot) check(!seenSlotIds.contains(slotId)) { "Duplicate slot \"$slotId\"!" } seenSlotIds.add(slotId) KeyguardSlotPickerRepresentation( id = slotId, maxSelectedAffordances = slotCapacity, ) } } init { legacySettingSyncer.startSyncing() dumpManager.registerDumpable("KeyguardQuickAffordances", Dumpster()) Loading Loading @@ -211,7 +188,30 @@ constructor( * each slot and select which affordance(s) is/are installed in each slot on the keyguard. */ fun getSlotPickerRepresentations(): List<KeyguardSlotPickerRepresentation> { return _slotPickerRepresentations fun parseSlot(unparsedSlot: String): Pair<String, Int> { val split = unparsedSlot.split(SLOT_CONFIG_DELIMITER) check(split.size == 2) val slotId = split[0] val slotCapacity = split[1].toInt() return slotId to slotCapacity } val unparsedSlots = appContext.resources.getStringArray(R.array.config_keyguardQuickAffordanceSlots) if (appContext.resources.configuration.layoutDirection == LayoutDirection.RTL) { unparsedSlots.reverse() } val seenSlotIds = mutableSetOf<String>() return unparsedSlots.mapNotNull { unparsedSlot -> val (slotId, slotCapacity) = parseSlot(unparsedSlot) check(!seenSlotIds.contains(slotId)) { "Duplicate slot \"$slotId\"!" } seenSlotIds.add(slotId) KeyguardSlotPickerRepresentation( id = slotId, maxSelectedAffordances = slotCapacity, ) } } private inner class Dumpster : Dumpable { Loading packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepositoryTest.kt +36 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever import com.android.systemui.util.settings.FakeSettings import com.google.common.truth.Truth.assertThat import java.util.Locale import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.TestScope Loading @@ -67,6 +68,7 @@ class KeyguardQuickAffordanceRepositoryTest : SysuiTestCase() { @Before fun setUp() { context.resources.configuration.setLayoutDirection(Locale.US) config1 = FakeKeyguardQuickAffordanceConfig(FakeCustomizationProviderClient.AFFORDANCE_1) config2 = FakeKeyguardQuickAffordanceConfig(FakeCustomizationProviderClient.AFFORDANCE_2) val testDispatcher = StandardTestDispatcher() Loading Loading @@ -221,6 +223,40 @@ class KeyguardQuickAffordanceRepositoryTest : SysuiTestCase() { ) } @Test fun getSlotPickerRepresentations_rightToLeft_slotsReversed() { context.resources.configuration.setLayoutDirection(Locale("he", "IL")) val slot1 = "slot1" val slot2 = "slot2" val slot3 = "slot3" context.orCreateTestableResources.addOverride( R.array.config_keyguardQuickAffordanceSlots, 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, ), ) ) } @Test fun `selections for secondary user`() = testScope.runTest { Loading Loading
packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepository.kt +25 −25 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.systemui.keyguard.data.repository import android.content.Context import android.os.UserHandle import android.util.LayoutDirection import com.android.systemui.Dumpable import com.android.systemui.R import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging Loading Loading @@ -113,30 +114,6 @@ constructor( initialValue = emptyMap(), ) private val _slotPickerRepresentations: List<KeyguardSlotPickerRepresentation> by lazy { fun parseSlot(unparsedSlot: String): Pair<String, Int> { val split = unparsedSlot.split(SLOT_CONFIG_DELIMITER) check(split.size == 2) val slotId = split[0] val slotCapacity = split[1].toInt() return slotId to slotCapacity } val unparsedSlots = appContext.resources.getStringArray(R.array.config_keyguardQuickAffordanceSlots) val seenSlotIds = mutableSetOf<String>() unparsedSlots.mapNotNull { unparsedSlot -> val (slotId, slotCapacity) = parseSlot(unparsedSlot) check(!seenSlotIds.contains(slotId)) { "Duplicate slot \"$slotId\"!" } seenSlotIds.add(slotId) KeyguardSlotPickerRepresentation( id = slotId, maxSelectedAffordances = slotCapacity, ) } } init { legacySettingSyncer.startSyncing() dumpManager.registerDumpable("KeyguardQuickAffordances", Dumpster()) Loading Loading @@ -211,7 +188,30 @@ constructor( * each slot and select which affordance(s) is/are installed in each slot on the keyguard. */ fun getSlotPickerRepresentations(): List<KeyguardSlotPickerRepresentation> { return _slotPickerRepresentations fun parseSlot(unparsedSlot: String): Pair<String, Int> { val split = unparsedSlot.split(SLOT_CONFIG_DELIMITER) check(split.size == 2) val slotId = split[0] val slotCapacity = split[1].toInt() return slotId to slotCapacity } val unparsedSlots = appContext.resources.getStringArray(R.array.config_keyguardQuickAffordanceSlots) if (appContext.resources.configuration.layoutDirection == LayoutDirection.RTL) { unparsedSlots.reverse() } val seenSlotIds = mutableSetOf<String>() return unparsedSlots.mapNotNull { unparsedSlot -> val (slotId, slotCapacity) = parseSlot(unparsedSlot) check(!seenSlotIds.contains(slotId)) { "Duplicate slot \"$slotId\"!" } seenSlotIds.add(slotId) KeyguardSlotPickerRepresentation( id = slotId, maxSelectedAffordances = slotCapacity, ) } } private inner class Dumpster : Dumpable { Loading
packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepositoryTest.kt +36 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever import com.android.systemui.util.settings.FakeSettings import com.google.common.truth.Truth.assertThat import java.util.Locale import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.TestScope Loading @@ -67,6 +68,7 @@ class KeyguardQuickAffordanceRepositoryTest : SysuiTestCase() { @Before fun setUp() { context.resources.configuration.setLayoutDirection(Locale.US) config1 = FakeKeyguardQuickAffordanceConfig(FakeCustomizationProviderClient.AFFORDANCE_1) config2 = FakeKeyguardQuickAffordanceConfig(FakeCustomizationProviderClient.AFFORDANCE_2) val testDispatcher = StandardTestDispatcher() Loading Loading @@ -221,6 +223,40 @@ class KeyguardQuickAffordanceRepositoryTest : SysuiTestCase() { ) } @Test fun getSlotPickerRepresentations_rightToLeft_slotsReversed() { context.resources.configuration.setLayoutDirection(Locale("he", "IL")) val slot1 = "slot1" val slot2 = "slot2" val slot3 = "slot3" context.orCreateTestableResources.addOverride( R.array.config_keyguardQuickAffordanceSlots, 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, ), ) ) } @Test fun `selections for secondary user`() = testScope.runTest { Loading