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

Commit 61274aba authored by Alejandro Nijamkin's avatar Alejandro Nijamkin
Browse files

Changes quick affordance key to string.

Before this change, the key that uniquely identifies each quick
affordance was the class of that key. Since we're about to embark on a
project where we'll have many implementations that share the same class,
this is no longer sufficient.

Previously, I was reluctant to use a string because there was no easy
way to guarantee uniqueness. Now that we see that we can't guarantee
uniqueness through the class typing system, we have to compromise.

Bug: 254858696
Test: unit tests updated and all passing. Manually verified that
affordances work and that clicking on one doesn't trigger the other.

Change-Id: I2d1ec382c04604c8478737720eb92410eec479f8
parent 04cbb0e2
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.settings.UserTracker
import com.android.systemui.statusbar.policy.KeyguardStateController
import javax.inject.Inject
import kotlin.reflect.KClass
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.onStart
@@ -70,10 +69,10 @@ constructor(
     * @param expandable An optional [Expandable] for the activity- or dialog-launch animation
     */
    fun onQuickAffordanceClicked(
        configKey: KClass<out KeyguardQuickAffordanceConfig>,
        configKey: String,
        expandable: Expandable?,
    ) {
        @Suppress("UNCHECKED_CAST") val config = registry.get(configKey as KClass<Nothing>)
        @Suppress("UNCHECKED_CAST") val config = registry.get(configKey)
        when (val result = config.onQuickAffordanceClicked(expandable)) {
            is KeyguardQuickAffordanceConfig.OnClickedResult.StartActivity ->
                launchQuickAffordance(
@@ -102,7 +101,7 @@ constructor(
            if (index != -1) {
                val visibleState = states[index] as KeyguardQuickAffordanceConfig.State.Visible
                KeyguardQuickAffordanceModel.Visible(
                    configKey = configs[index]::class,
                    configKey = configs[index].key,
                    icon = visibleState.icon,
                    toggle = visibleState.toggle,
                )
+1 −3
Original line number Diff line number Diff line
@@ -18,9 +18,7 @@
package com.android.systemui.keyguard.domain.model

import com.android.systemui.common.shared.model.Icon
import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceConfig
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordanceToggleState
import kotlin.reflect.KClass

/**
 * Models a "quick affordance" in the keyguard bottom area (for example, a button on the
@@ -33,7 +31,7 @@ sealed class KeyguardQuickAffordanceModel {
    /** A affordance is visible. */
    data class Visible(
        /** Identifier for the affordance this is modeling. */
        val configKey: KClass<out KeyguardQuickAffordanceConfig>,
        val configKey: String,
        /** An icon for the affordance. */
        val icon: Icon,
        /** The toggle state for the affordance. */
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.android.systemui.keyguard.domain.quickaffordance

/**
 * Unique identifier keys for all known built-in quick affordances.
 *
 * Please ensure uniqueness by never associating more than one class with each key.
 */
object BuiltInKeyguardQuickAffordanceKeys {
    // Please keep alphabetical order of const names to simplify future maintenance.
    const val HOME_CONTROLS = "home"
    const val QR_CODE_SCANNER = "qr_code_scanner"
    const val QUICK_ACCESS_WALLET = "wallet"
    // Please keep alphabetical order of const names to simplify future maintenance.
}
+2 −0
Original line number Diff line number Diff line
@@ -51,6 +51,8 @@ constructor(

    private val appContext = context.applicationContext

    override val key: String = BuiltInKeyguardQuickAffordanceKeys.HOME_CONTROLS

    override val state: Flow<KeyguardQuickAffordanceConfig.State> =
        component.canShowWhileLockedSetting.flatMapLatest { canShowWhileLocked ->
            if (canShowWhileLocked) {
+10 −0
Original line number Diff line number Diff line
@@ -26,8 +26,18 @@ import kotlinx.coroutines.flow.Flow
/** Defines interface that can act as data source for a single quick affordance model. */
interface KeyguardQuickAffordanceConfig {

    /** Unique identifier for this quick affordance. It must be globally unique. */
    val key: String

    /** The observable [State] of the affordance. */
    val state: Flow<State>

    /**
     * Notifies that the affordance was clicked by the user.
     *
     * @param expandable An [Expandable] to use when animating dialogs or activities
     * @return An [OnClickedResult] telling the caller what to do next
     */
    fun onQuickAffordanceClicked(expandable: Expandable?): OnClickedResult

    /**
Loading