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

Commit 7fb65cc6 authored by Andreas Agvard's avatar Andreas Agvard
Browse files

Floaty config calls using the wrong type should be ignored

Bug: 420543535
Test: Unit and Manual
Flag: com.android.systemui.shared.enable_lpp_assist_invocation_effect
Change-Id: I391bcdc8da64521d23b509d2a2c3d1af521a8218
parent 0d08facd
Loading
Loading
Loading
Loading
+40 −2
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPre
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.DEFAULT_OUTWARD_EFFECT_DURATION_MS
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.INVOCATION_EFFECT_ANIMATION_IN_DURATION_PADDING_MS
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.INVOCATION_EFFECT_ANIMATION_OUT_DURATION_MS
import com.android.systemui.topwindoweffects.data.repository.SqueezeEffectRepositoryImpl.Companion.IS_INVOCATION_EFFECT_ENABLED_KEY
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT
import com.android.systemui.topwindoweffects.data.repository.SqueezeEffectRepositoryImpl.Companion.SET_INVOCATION_EFFECT_PARAMETERS_ACTION
import com.android.systemui.util.settings.FakeGlobalSettings
import com.google.common.truth.Truth.assertThat
@@ -282,6 +282,42 @@ class SqueezeEffectRepositoryTest : SysuiTestCase() {
                .isTrue()
        }

    @EnableFlags(Flags.FLAG_ENABLE_LPP_ASSIST_INVOCATION_EFFECT)
    @Test
    fun testSetUiHints_whenSuppliedWrongConfigType_setsDefault() =
        kosmos.runTest {
            fakeInvocationEffectPreferences.activeUserId = 1
            fakeInvocationEffectPreferences.activeAssistant = "A"

            assertThat(fakeInvocationEffectPreferences.isCurrentUserAndAssistantPersisted())
                .isFalse()

            underTest.tryHandleSetUiHints(
                createAssistantSettingBundle(
                    enableAssistantSetting =
                        !DEFAULT_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE,
                    inwardsPaddingDuration = 501L,
                    outwardsAnimationDuration = 502L,
                )
            )

            underTest.tryHandleSetUiHints(
                Bundle().apply {
                    putString(AssistManager.ACTION_KEY, SET_INVOCATION_EFFECT_PARAMETERS_ACTION)
                    putInt(IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT, 123)
                    putInt(INVOCATION_EFFECT_ANIMATION_IN_DURATION_PADDING_MS, 456)
                    putInt(INVOCATION_EFFECT_ANIMATION_OUT_DURATION_MS, 789)
                }
            )

            assertThat(fakeInvocationEffectPreferences.isInvocationEffectEnabledInPreferences())
                .isEqualTo(DEFAULT_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE)
            assertThat(fakeInvocationEffectPreferences.getInwardAnimationPaddingDurationMillis())
                .isEqualTo(DEFAULT_INWARD_EFFECT_PADDING_DURATION_MS)
            assertThat(fakeInvocationEffectPreferences.getOutwardAnimationDurationMillis())
                .isEqualTo(DEFAULT_OUTWARD_EFFECT_DURATION_MS)
        }

    private fun createAssistantSettingBundle(
        enableAssistantSetting: Boolean? = null,
        inwardsPaddingDuration: Long? = null,
@@ -289,7 +325,9 @@ class SqueezeEffectRepositoryTest : SysuiTestCase() {
    ) =
        Bundle().apply {
            putString(AssistManager.ACTION_KEY, SET_INVOCATION_EFFECT_PARAMETERS_ACTION)
            enableAssistantSetting?.let { putBoolean(IS_INVOCATION_EFFECT_ENABLED_KEY, it) }
            enableAssistantSetting?.let {
                putBoolean(IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT, it)
            }
            inwardsPaddingDuration?.let {
                putLong(INVOCATION_EFFECT_ANIMATION_IN_DURATION_PADDING_MS, it)
            }
+4 −8
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ constructor(
                conflatedCallbackFlow {
                        val listener =
                            SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
                                if (key == IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE) {
                                if (key == IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT) {
                                    trySendWithFailureLogging(
                                        isInvocationEffectEnabledByAssistant(),
                                        TAG,
@@ -191,7 +191,7 @@ constructor(

    override fun isInvocationEffectEnabledInPreferences(): Boolean =
        getOrDefault<Boolean>(
            key = IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE,
            key = IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT,
            default = DEFAULT_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE,
            checkUserAndAssistant = true,
        )
@@ -208,10 +208,7 @@ constructor(
                }

                if (config.isEnabled != isInvocationEffectEnabledInPreferences()) {
                    putBoolean(
                        IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE,
                        config.isEnabled,
                    )
                    putBoolean(IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT, config.isEnabled)
                }

                if (
@@ -305,8 +302,7 @@ constructor(
        private const val SHARED_PREFERENCES_FILE_NAME = "assistant_invocation_effect_preferences"
        @VisibleForTesting const val PERSISTED_FOR_ASSISTANT_PREFERENCE = "persisted_for_assistant"
        @VisibleForTesting const val PERSISTED_FOR_USER_PREFERENCE = "persisted_for_user"
        const val IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE =
            "is_invocation_effect_enabled"
        const val IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT = "is_invocation_effect_enabled"
        const val INVOCATION_EFFECT_ANIMATION_IN_DURATION_PADDING_MS =
            "invocation_effect_animation_in_duration_padding_ms"
        const val INVOCATION_EFFECT_ANIMATION_OUT_DURATION_MS =
+17 −9
Original line number Diff line number Diff line
@@ -29,9 +29,12 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.shared.Flags
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.DEFAULT_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.DEFAULT_INWARD_EFFECT_PADDING_DURATION_MS
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.DEFAULT_OUTWARD_EFFECT_DURATION_MS
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.INVOCATION_EFFECT_ANIMATION_IN_DURATION_PADDING_MS
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.INVOCATION_EFFECT_ANIMATION_OUT_DURATION_MS
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT
import com.android.systemui.util.settings.GlobalSettings
import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow
import java.io.PrintWriter
@@ -113,22 +116,31 @@ constructor(
            SET_INVOCATION_EFFECT_PARAMETERS_ACTION -> {

                val isEnabled: Boolean? =
                    if (hints.containsKey(IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE)) {
                        hints.getBoolean(IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE)
                    if (hints.containsKey(IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT)) {
                        hints.getBoolean(
                            IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT,
                            DEFAULT_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE,
                        )
                    } else {
                        null
                    }

                val inwardsEffectDurationPadding: Long? =
                    if (hints.containsKey(INVOCATION_EFFECT_ANIMATION_IN_DURATION_PADDING_MS)) {
                        hints.getLong(INVOCATION_EFFECT_ANIMATION_IN_DURATION_PADDING_MS)
                        hints.getLong(
                            INVOCATION_EFFECT_ANIMATION_IN_DURATION_PADDING_MS,
                            DEFAULT_INWARD_EFFECT_PADDING_DURATION_MS,
                        )
                    } else {
                        null
                    }

                val outwardsEffectDuration: Long? =
                    if (hints.containsKey(INVOCATION_EFFECT_ANIMATION_OUT_DURATION_MS)) {
                        hints.getLong(INVOCATION_EFFECT_ANIMATION_OUT_DURATION_MS)
                        hints.getLong(
                            INVOCATION_EFFECT_ANIMATION_OUT_DURATION_MS,
                            DEFAULT_OUTWARD_EFFECT_DURATION_MS,
                        )
                    } else {
                        null
                    }
@@ -228,10 +240,6 @@ constructor(

        @VisibleForTesting
        const val SET_INVOCATION_EFFECT_PARAMETERS_ACTION = "set_invocation_effect_parameters"
        @VisibleForTesting
        const val IS_INVOCATION_EFFECT_ENABLED_KEY = "is_invocation_effect_enabled"

        @VisibleForTesting const val IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_DEFAULT_VALUE = true
    }
}

+3 −3
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPre
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.DEFAULT_OUTWARD_EFFECT_DURATION_MS
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.INVOCATION_EFFECT_ANIMATION_IN_DURATION_PADDING_MS
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.INVOCATION_EFFECT_ANIMATION_OUT_DURATION_MS
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.PERSISTED_FOR_ASSISTANT_PREFERENCE
import com.android.systemui.topwindoweffects.data.repository.InvocationEffectPreferencesImpl.Companion.PERSISTED_FOR_USER_PREFERENCE
import java.io.PrintWriter
@@ -46,7 +46,7 @@ class FakeInvocationEffectPreferences : InvocationEffectPreferences {

    override fun isInvocationEffectEnabledInPreferences(): Boolean {
        return fakeSharedPreferences.getBoolean(
            IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE,
            IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT,
            DEFAULT_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE,
        )
    }
@@ -97,7 +97,7 @@ class FakeInvocationEffectPreferences : InvocationEffectPreferences {
                INVOCATION_EFFECT_ANIMATION_IN_DURATION_PADDING_MS,
                config.inwardsEffectDurationPadding,
            )
            putBoolean(IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE, config.isEnabled)
            putBoolean(IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT, config.isEnabled)
        }
    }