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

Commit 166271d5 authored by Aaron Liu's avatar Aaron Liu
Browse files

Augment blueprint command line tool

Leverage treemap to allow the use of indexes to make transitions.

When printing out blueprints, we will see that it corresponds to an
integer value. The blueprints are alphabetically ordered. We can use the
integer value as an argument. i.e. $ blueprint 0

Fixes: 299516004
Test: use command line tool
Change-Id: I02646ed959783a938bbbf10882a351436524811b
parent 94dabaf8
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import com.android.systemui.keyguard.shared.model.KeyguardBlueprint
import com.android.systemui.keyguard.ui.view.layout.blueprints.DefaultKeyguardBlueprint.Companion.DEFAULT
import com.android.systemui.keyguard.ui.view.layout.blueprints.KeyguardBlueprintModule
import java.io.PrintWriter
import java.util.TreeMap
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
@@ -52,17 +53,32 @@ constructor(
    blueprints: Set<@JvmSuppressWildcards KeyguardBlueprint>,
    @Application private val applicationScope: CoroutineScope,
) {
    private val blueprintIdMap: Map<String, KeyguardBlueprint> = blueprints.associateBy { it.id }
    private val blueprintIdMap: TreeMap<String, KeyguardBlueprint> = TreeMap()
    private val _blueprint: MutableSharedFlow<KeyguardBlueprint> = MutableSharedFlow(replay = 1)
    val blueprint: Flow<KeyguardBlueprint> = _blueprint.asSharedFlow()

    init {
        blueprintIdMap.putAll(blueprints.associateBy { it.id })
        applyBlueprint(blueprintIdMap[DEFAULT]!!)
        applicationScope.launch {
            configurationRepository.onAnyConfigurationChange.collect { refreshBlueprint() }
        }
    }

    /**
     * Emits the blueprint value to the collectors.
     *
     * @param blueprintId
     * @return whether the transition has succeeded.
     */
    fun applyBlueprint(index: Int): Boolean {
        ArrayList(blueprintIdMap.values)[index]?.let {
            applyBlueprint(it)
            return true
        }
        return false
    }

    /**
     * Emits the blueprint value to the collectors.
     *
@@ -89,6 +105,6 @@ constructor(

    /** Prints all available blueprints to the PrintWriter. */
    fun printBlueprints(pw: PrintWriter) {
        blueprintIdMap.forEach { entry -> pw.println("${entry.key}") }
        blueprintIdMap.onEachIndexed { index, entry -> pw.println("$index: ${entry.key}") }
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -37,6 +37,16 @@ constructor(private val keyguardBlueprintRepository: KeyguardBlueprintRepository
        return keyguardBlueprintRepository.applyBlueprint(blueprintId)
    }

    /**
     * Transitions to a blueprint.
     *
     * @param blueprintId
     * @return whether the transition has succeeded.
     */
    fun transitionToBlueprint(blueprintId: Int): Boolean {
        return keyguardBlueprintRepository.applyBlueprint(blueprintId)
    }

    /** Re-emits the blueprint value to the collectors. */
    fun refreshBlueprint() {
        keyguardBlueprintRepository.refreshBlueprint()
+6 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.keyguard.ui.view.layout

import androidx.core.text.isDigitsOnly
import com.android.systemui.keyguard.data.repository.KeyguardBlueprintRepository
import com.android.systemui.keyguard.domain.interactor.KeyguardBlueprintInteractor
import com.android.systemui.statusbar.commandline.Command
@@ -45,7 +46,11 @@ constructor(
                return
            }

            if (keyguardBlueprintInteractor.transitionToBlueprint(arg)) {
            if (
                arg.isDigitsOnly() && keyguardBlueprintInteractor.transitionToBlueprint(arg.toInt())
            ) {
                pw.println("Transition succeeded!")
            } else if (keyguardBlueprintInteractor.transitionToBlueprint(arg)) {
                pw.println("Transition succeeded!")
            } else {
                pw.println("Invalid argument! To see available blueprint ids, run:")
+1 −1
Original line number Diff line number Diff line
@@ -58,6 +58,6 @@ constructor(
        )

    companion object {
        const val SHORTCUTS_BESIDE_UDFPS = "shortcutsBesideUdfps"
        const val SHORTCUTS_BESIDE_UDFPS = "shortcuts-besides-udfps"
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -81,4 +81,10 @@ class KeyguardBlueprintCommandListenerTest : SysuiTestCase() {
        command().execute(pw, listOf("fake"))
        verify(keyguardBlueprintInteractor).transitionToBlueprint("fake")
    }

    @Test
    fun testValidArg_Int() {
        command().execute(pw, listOf("1"))
        verify(keyguardBlueprintInteractor).transitionToBlueprint(1)
    }
}