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

Commit 2690b2c1 authored by Hawkwood Glazier's avatar Hawkwood Glazier
Browse files

Prevent default blueprint changes from triggering refreshes

Bug: 336400157
Test: abtd run to verify perf improvement
Flag: ACONFIG com.android.systemui.migrate_clocks_to_blueprint STAGING
Change-Id: I6c56b1ebf762c81e9626de082154eb4e2f891b82
parent c809b034
Loading
Loading
Loading
Loading
+5 −25
Original line number Diff line number Diff line
@@ -59,20 +59,6 @@ constructor(
    val refreshTransition = MutableSharedFlow<Config>(extraBufferCapacity = 1)
    private var targetTransitionConfig: Config? = null

    /**
     * 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.
     *
@@ -81,27 +67,21 @@ constructor(
     */
    fun applyBlueprint(blueprintId: String?): Boolean {
        val blueprint = blueprintIdMap[blueprintId]
        return if (blueprint != null) {
            applyBlueprint(blueprint)
            true
        } else {
        if (blueprint == null) {
            Log.e(
                TAG,
                "Could not find blueprint with id: $blueprintId. " +
                    "Perhaps it was not added to KeyguardBlueprintModule?"
            )
            false
        }
            return false
        }

    /** Emits the blueprint value to the collectors. */
    fun applyBlueprint(blueprint: KeyguardBlueprint?) {
        if (blueprint == this.blueprint.value) {
            refreshBlueprint()
            return
            return true
        }

        blueprint?.let { this.blueprint.value = it }
        this.blueprint.value = blueprint
        return true
    }

    /**
+8 −3
Original line number Diff line number Diff line
@@ -82,12 +82,17 @@ constructor(
    }

    /**
     * Transitions to a blueprint.
     * Transitions to a blueprint, or refreshes it if already applied.
     *
     * @param blueprintId
     * @return whether the transition has succeeded.
     */
    fun transitionToBlueprint(blueprintId: String): Boolean {
    fun transitionOrRefreshBlueprint(blueprintId: String): Boolean {
        if (blueprintId == blueprint.value.id) {
            refreshBlueprint()
            return true
        }

        return keyguardBlueprintRepository.applyBlueprint(blueprintId)
    }

@@ -97,7 +102,7 @@ constructor(
     * @param blueprintId
     * @return whether the transition has succeeded.
     */
    fun transitionToBlueprint(blueprintId: Int): Boolean {
    fun transitionToBlueprint(blueprintId: String): Boolean {
        return keyguardBlueprintRepository.applyBlueprint(blueprintId)
    }

+8 −9
Original line number Diff line number Diff line
@@ -46,17 +46,16 @@ constructor(
                return
            }

            if (
                arg.isDigitsOnly() && keyguardBlueprintInteractor.transitionToBlueprint(arg.toInt())
            ) {
                pw.println("Transition succeeded!")
            } else if (keyguardBlueprintInteractor.transitionToBlueprint(arg)) {
            when {
                arg.isDigitsOnly() -> pw.println("Invalid argument! Use string ids.")
                keyguardBlueprintInteractor.transitionOrRefreshBlueprint(arg) ->
                    pw.println("Transition succeeded!")
            } else {
                else -> {
                    pw.println("Invalid argument! To see available blueprint ids, run:")
                    pw.println("$ adb shell cmd statusbar blueprint help")
                }
            }
        }

        override fun help(pw: PrintWriter) {
            pw.println("Usage: $ adb shell cmd statusbar blueprint <blueprintId>")
+22 −36
Original line number Diff line number Diff line
@@ -19,24 +19,20 @@

package com.android.systemui.keyguard.data.repository

import android.os.fakeExecutorHandler
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.ui.data.repository.ConfigurationRepository
import com.android.systemui.concurrency.fakeExecutor
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.ui.view.layout.blueprints.DefaultKeyguardBlueprint
import com.android.systemui.keyguard.ui.view.layout.blueprints.DefaultKeyguardBlueprint.Companion.DEFAULT
import com.android.systemui.keyguard.ui.view.layout.blueprints.SplitShadeKeyguardBlueprint
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.android.systemui.util.ThreadAssert
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
@@ -50,31 +46,32 @@ import org.mockito.MockitoAnnotations
class KeyguardBlueprintRepositoryTest : SysuiTestCase() {
    private lateinit var underTest: KeyguardBlueprintRepository
    @Mock lateinit var configurationRepository: ConfigurationRepository
    @Mock lateinit var defaultLockscreenBlueprint: DefaultKeyguardBlueprint
    @Mock lateinit var threadAssert: ThreadAssert

    private val testScope = TestScope(StandardTestDispatcher())
    private val kosmos: Kosmos = testKosmos()

    @Before
    fun setup() {
        MockitoAnnotations.initMocks(this)
        with(kosmos) {
            whenever(defaultLockscreenBlueprint.id).thenReturn(DEFAULT)
            underTest =
                KeyguardBlueprintRepository(
                    setOf(defaultLockscreenBlueprint),
                    fakeExecutorHandler,
                    threadAssert,
                )
        }
        underTest = kosmos.keyguardBlueprintRepository
    }

    @Test
    fun testApplyBlueprint_DefaultLayout() {
        testScope.runTest {
            val blueprint by collectLastValue(underTest.blueprint)
            underTest.applyBlueprint(defaultLockscreenBlueprint)
            assertThat(blueprint).isEqualTo(defaultLockscreenBlueprint)
            underTest.applyBlueprint(DefaultKeyguardBlueprint.DEFAULT)
            assertThat(blueprint).isEqualTo(kosmos.defaultKeyguardBlueprint)
        }
    }

    @Test
    fun testApplyBlueprint_SplitShadeLayout() {
        testScope.runTest {
            val blueprint by collectLastValue(underTest.blueprint)
            underTest.applyBlueprint(SplitShadeKeyguardBlueprint.ID)
            assertThat(blueprint).isEqualTo(kosmos.splitShadeBlueprint)
        }
    }

@@ -83,33 +80,22 @@ class KeyguardBlueprintRepositoryTest : SysuiTestCase() {
        testScope.runTest {
            val blueprint by collectLastValue(underTest.blueprint)
            underTest.refreshBlueprint()
            assertThat(blueprint).isEqualTo(defaultLockscreenBlueprint)
            assertThat(blueprint).isEqualTo(kosmos.defaultKeyguardBlueprint)
        }
    }

    @Test
    fun testTransitionToLayout_validId() {
        assertThat(underTest.applyBlueprint(DEFAULT)).isTrue()
    fun testTransitionToDefaultLayout_validId() {
        assertThat(underTest.applyBlueprint(DefaultKeyguardBlueprint.DEFAULT)).isTrue()
    }

    @Test
    fun testTransitionToLayout_invalidId() {
        assertThat(underTest.applyBlueprint("abc")).isFalse()
    fun testTransitionToSplitShadeLayout_validId() {
        assertThat(underTest.applyBlueprint(SplitShadeKeyguardBlueprint.ID)).isTrue()
    }

    @Test
    fun testTransitionToSameBlueprint_refreshesBlueprint() =
        with(kosmos) {
            testScope.runTest {
                val transition by collectLastValue(underTest.refreshTransition)
                fakeExecutor.runAllReady()
                runCurrent()

                underTest.applyBlueprint(defaultLockscreenBlueprint)
                fakeExecutor.runAllReady()
                runCurrent()

                assertThat(transition).isNotNull()
            }
    fun testTransitionToLayout_invalidId() {
        assertThat(underTest.applyBlueprint("abc")).isFalse()
    }
}
+3 −9
Original line number Diff line number Diff line
@@ -66,25 +66,19 @@ class KeyguardBlueprintCommandListenerTest : SysuiTestCase() {
    fun testHelp() {
        command().execute(pw, listOf("help"))
        verify(pw, atLeastOnce()).println(anyString())
        verify(keyguardBlueprintInteractor, never()).transitionToBlueprint(anyString())
        verify(keyguardBlueprintInteractor, never()).transitionOrRefreshBlueprint(anyString())
    }

    @Test
    fun testBlank() {
        command().execute(pw, listOf())
        verify(pw, atLeastOnce()).println(anyString())
        verify(keyguardBlueprintInteractor, never()).transitionToBlueprint(anyString())
        verify(keyguardBlueprintInteractor, never()).transitionOrRefreshBlueprint(anyString())
    }

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

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