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

Commit 38aeb2aa authored by Catherine Liang's avatar Catherine Liang
Browse files

Fix crash from resetting shortcuts to none

Wallpaper picker crashes from resetting both shortcuts to none, and
behaves incorrectly when resetting one shortcut to none, because slots
without a selection were not accounted for in the snapshot restorer.

Flag: NONE
Bug: 305156127
Test: Manually verified different shortcut reset scenarios
Change-Id: Ib218dccf3f34509b64662eafdf7ac301884ec066
parent 4a06fae7
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ class KeyguardQuickAffordancePickerInteractor(
    }

    /** Unselects all affordances from the slot with the given ID. */
    suspend fun unselectAll(slotId: String) {
    suspend fun unselectAllFromSlot(slotId: String) {
        client.deleteAllSelections(
            slotId = slotId,
        )
@@ -72,6 +72,11 @@ class KeyguardQuickAffordancePickerInteractor(
        snapshotRestorer.get().storeSnapshot()
    }

    /** Unselects all affordances from all slots. */
    suspend fun unselectAll() {
        client.querySlots().forEach { client.deleteAllSelections(it.id) }
    }

    /** Returns a [Drawable] for the given resource ID, from the system UI package. */
    suspend fun getAffordanceIcon(
        @DrawableRes iconResourceId: Int,
+7 −2
Original line number Diff line number Diff line
@@ -42,9 +42,14 @@ class KeyguardQuickAffordanceSnapshotRestorer(
    }

    override suspend fun restoreToSnapshot(snapshot: RestorableSnapshot) {
        // reset all current selections
        interactor.unselectAll()

        val allSelections = checkNotNull(snapshot.args[KEY_SELECTIONS])
        if (allSelections.isEmpty()) return

        val selections: List<Pair<String, String>> =
            checkNotNull(snapshot.args[KEY_SELECTIONS]).split(SELECTION_SEPARATOR).map { selection
                ->
            allSelections.split(SELECTION_SEPARATOR).map { selection ->
                val (slotId, affordanceId) = selection.split(SLOT_AFFORDANCE_SEPARATOR)
                slotId to affordanceId
            }
+3 −1
Original line number Diff line number Diff line
@@ -217,7 +217,9 @@ private constructor(
                            if (!isSelected) {
                                {
                                    viewModelScope.launch {
                                        quickAffordanceInteractor.unselectAll(selectedSlotId)
                                        quickAffordanceInteractor.unselectAllFromSlot(
                                            selectedSlotId
                                        )
                                        logger.logShortcutApplied(
                                            shortcut = "none",
                                            shortcutSlotId = selectedSlotId,
+1 −1
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ class KeyguardQuickAffordancePickerInteractorTest {
                affordanceId = FakeCustomizationProviderClient.AFFORDANCE_3,
            )

            underTest.unselectAll(
            underTest.unselectAllFromSlot(
                slotId = KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END,
            )