Loading packages/SystemUI/multivalentTests/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepositoryTest.kt +28 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.topwindoweffects.data.repository import android.os.Bundle import android.os.Handler import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags Loading @@ -23,6 +24,7 @@ import android.provider.Settings.Global.POWER_BUTTON_LONG_PRESS import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.assist.AssistManager import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest Loading @@ -39,6 +41,12 @@ import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.MockitoAnnotations private fun createAssistantSettingBundle(enableAssistantSetting: Boolean) = Bundle().apply { putString(AssistManager.ACTION_KEY, SET_INVOCATION_EFFECT_PARAMETERS_ACTION) putBoolean(IS_INVOCATION_EFFECT_ENABLED_KEY, enableAssistantSetting) } @SmallTest @RunWith(AndroidJUnit4::class) class SqueezeEffectRepositoryTest : SysuiTestCase() { Loading @@ -65,8 +73,11 @@ class SqueezeEffectRepositoryTest : SysuiTestCase() { @DisableFlags(Flags.FLAG_ENABLE_LPP_ASSIST_INVOCATION_EFFECT) @Test fun testSqueezeEffectDisabled_WhenFlagDisabled() = fun testSqueezeEffectDisabled_WhenOtherwiseEnabled_FlagDisabled() = kosmos.runTest { globalSettings.putInt(POWER_BUTTON_LONG_PRESS, 5) underTest.tryHandleSetUiHints(createAssistantSettingBundle(true)) val isSqueezeEffectEnabled by collectLastValue(underTest.isSqueezeEffectEnabled) assertThat(isSqueezeEffectEnabled).isFalse() Loading @@ -74,8 +85,9 @@ class SqueezeEffectRepositoryTest : SysuiTestCase() { @EnableFlags(Flags.FLAG_ENABLE_LPP_ASSIST_INVOCATION_EFFECT) @Test fun testSqueezeEffectDisabled_WhenFlagEnabled_GlobalSettingsDisabled() = fun testSqueezeEffectDisabled_WhenOtherwiseEnabled_GlobalSettingDisabled() = kosmos.runTest { underTest.tryHandleSetUiHints(createAssistantSettingBundle(true)) globalSettings.putInt(POWER_BUTTON_LONG_PRESS, 0) val isSqueezeEffectEnabled by collectLastValue(underTest.isSqueezeEffectEnabled) Loading @@ -85,9 +97,22 @@ class SqueezeEffectRepositoryTest : SysuiTestCase() { @EnableFlags(Flags.FLAG_ENABLE_LPP_ASSIST_INVOCATION_EFFECT) @Test fun testSqueezeEffectEnabled_WhenFlagEnabled_GlobalSettingEnabled() = fun testSqueezeEffectDisabled_WhenOtherwiseEnabled_AssistantSettingDisabled() = kosmos.runTest { globalSettings.putInt(POWER_BUTTON_LONG_PRESS, 5) underTest.tryHandleSetUiHints(createAssistantSettingBundle(false)) val isSqueezeEffectEnabled by collectLastValue(underTest.isSqueezeEffectEnabled) assertThat(isSqueezeEffectEnabled).isFalse() } @EnableFlags(Flags.FLAG_ENABLE_LPP_ASSIST_INVOCATION_EFFECT) @Test fun testSqueezeEffectEnabled_AllSettingsEnabled() = kosmos.runTest { globalSettings.putInt(POWER_BUTTON_LONG_PRESS, 5) underTest.tryHandleSetUiHints(createAssistantSettingBundle(true)) val isSqueezeEffectEnabled by collectLastValue(underTest.isSqueezeEffectEnabled) Loading packages/SystemUI/src/com/android/systemui/assist/AssistManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ public class AssistManager { private static final String INVOCATION_TIME_MS_KEY = "invocation_time_ms"; private static final String INVOCATION_PHONE_STATE_KEY = "invocation_phone_state"; protected static final String ACTION_KEY = "action"; public static final String ACTION_KEY = "action"; protected static final String SET_ASSIST_GESTURE_CONSTRAINED_ACTION = "set_assist_gesture_constrained"; protected static final String CONSTRAINED_KEY = "should_constrain"; Loading packages/SystemUI/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepositoryImpl.kt +44 −13 Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ import android.util.DisplayUtils import android.view.DisplayInfo import androidx.annotation.ArrayRes import androidx.annotation.DrawableRes import com.android.internal.annotations.VisibleForTesting import com.android.systemui.assist.AssistManager import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application Loading @@ -38,8 +40,14 @@ import javax.inject.Inject import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.flowOn @VisibleForTesting const val SET_INVOCATION_EFFECT_PARAMETERS_ACTION = "set_invocation_effect_parameters" @VisibleForTesting const val IS_INVOCATION_EFFECT_ENABLED_KEY = "is_invocation_effect_enabled" @SysUISingleton class SqueezeEffectRepositoryImpl @Inject Loading @@ -50,32 +58,28 @@ constructor( private val globalSettings: GlobalSettings, ) : SqueezeEffectRepository, InvocationEffectSetUiHintsHandler { override val isSqueezeEffectEnabled: Flow<Boolean> = private val isPowerButtonLongPressConfiguredToLaunchAssistantFlow: Flow<Boolean> = conflatedCallbackFlow { val observer = object : ContentObserver(bgHandler) { override fun onChange(selfChange: Boolean) { trySendWithFailureLogging( squeezeEffectEnabled, getIsPowerButtonLongPressConfiguredToLaunchAssistant(), TAG, "updated isSqueezeEffectEnabled", "updated isPowerButtonLongPressConfiguredToLaunchAssistantFlow", ) } } trySendWithFailureLogging(squeezeEffectEnabled, TAG, "init isSqueezeEffectEnabled") trySendWithFailureLogging( getIsPowerButtonLongPressConfiguredToLaunchAssistant(), TAG, "init isPowerButtonLongPressConfiguredToLaunchAssistantFlow", ) globalSettings.registerContentObserverAsync(POWER_BUTTON_LONG_PRESS, observer) awaitClose { globalSettings.unregisterContentObserverAsync(observer) } } .flowOn(bgCoroutineContext) private val squeezeEffectEnabled get() = Flags.enableLppAssistInvocationEffect() && globalSettings.getInt( POWER_BUTTON_LONG_PRESS, com.android.internal.R.integer.config_longPressOnPowerBehavior, ) == 5 // 5 corresponds to launch assistant in config_longPressOnPowerBehavior override suspend fun getRoundedCornersResourceId(): SqueezeEffectCornerResourceId { val displayInfo = DisplayInfo() context.display.getDisplayInfo(displayInfo) Loading Loading @@ -116,7 +120,34 @@ constructor( return drawableResource } override fun tryHandleSetUiHints(hints: Bundle) = false private val isInvocationEffectEnabledForCurrentAssistantFlow = MutableStateFlow(true) override val isSqueezeEffectEnabled: Flow<Boolean> = combine( isPowerButtonLongPressConfiguredToLaunchAssistantFlow, isInvocationEffectEnabledForCurrentAssistantFlow, ) { prerequisites -> prerequisites.all { it } && Flags.enableLppAssistInvocationEffect() } private fun getIsPowerButtonLongPressConfiguredToLaunchAssistant() = globalSettings.getInt( POWER_BUTTON_LONG_PRESS, com.android.internal.R.integer.config_longPressOnPowerBehavior, ) == 5 // 5 corresponds to launch assistant in PhoneWindowManager.java override fun tryHandleSetUiHints(hints: Bundle): Boolean { return when (hints.getString(AssistManager.ACTION_KEY)) { SET_INVOCATION_EFFECT_PARAMETERS_ACTION -> { if (hints.containsKey(IS_INVOCATION_EFFECT_ENABLED_KEY)) { isInvocationEffectEnabledForCurrentAssistantFlow.value = hints.getBoolean(IS_INVOCATION_EFFECT_ENABLED_KEY) } true } else -> false } } companion object { private const val TAG = "SqueezeEffectRepository" Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepositoryTest.kt +28 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.topwindoweffects.data.repository import android.os.Bundle import android.os.Handler import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags Loading @@ -23,6 +24,7 @@ import android.provider.Settings.Global.POWER_BUTTON_LONG_PRESS import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.assist.AssistManager import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest Loading @@ -39,6 +41,12 @@ import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.MockitoAnnotations private fun createAssistantSettingBundle(enableAssistantSetting: Boolean) = Bundle().apply { putString(AssistManager.ACTION_KEY, SET_INVOCATION_EFFECT_PARAMETERS_ACTION) putBoolean(IS_INVOCATION_EFFECT_ENABLED_KEY, enableAssistantSetting) } @SmallTest @RunWith(AndroidJUnit4::class) class SqueezeEffectRepositoryTest : SysuiTestCase() { Loading @@ -65,8 +73,11 @@ class SqueezeEffectRepositoryTest : SysuiTestCase() { @DisableFlags(Flags.FLAG_ENABLE_LPP_ASSIST_INVOCATION_EFFECT) @Test fun testSqueezeEffectDisabled_WhenFlagDisabled() = fun testSqueezeEffectDisabled_WhenOtherwiseEnabled_FlagDisabled() = kosmos.runTest { globalSettings.putInt(POWER_BUTTON_LONG_PRESS, 5) underTest.tryHandleSetUiHints(createAssistantSettingBundle(true)) val isSqueezeEffectEnabled by collectLastValue(underTest.isSqueezeEffectEnabled) assertThat(isSqueezeEffectEnabled).isFalse() Loading @@ -74,8 +85,9 @@ class SqueezeEffectRepositoryTest : SysuiTestCase() { @EnableFlags(Flags.FLAG_ENABLE_LPP_ASSIST_INVOCATION_EFFECT) @Test fun testSqueezeEffectDisabled_WhenFlagEnabled_GlobalSettingsDisabled() = fun testSqueezeEffectDisabled_WhenOtherwiseEnabled_GlobalSettingDisabled() = kosmos.runTest { underTest.tryHandleSetUiHints(createAssistantSettingBundle(true)) globalSettings.putInt(POWER_BUTTON_LONG_PRESS, 0) val isSqueezeEffectEnabled by collectLastValue(underTest.isSqueezeEffectEnabled) Loading @@ -85,9 +97,22 @@ class SqueezeEffectRepositoryTest : SysuiTestCase() { @EnableFlags(Flags.FLAG_ENABLE_LPP_ASSIST_INVOCATION_EFFECT) @Test fun testSqueezeEffectEnabled_WhenFlagEnabled_GlobalSettingEnabled() = fun testSqueezeEffectDisabled_WhenOtherwiseEnabled_AssistantSettingDisabled() = kosmos.runTest { globalSettings.putInt(POWER_BUTTON_LONG_PRESS, 5) underTest.tryHandleSetUiHints(createAssistantSettingBundle(false)) val isSqueezeEffectEnabled by collectLastValue(underTest.isSqueezeEffectEnabled) assertThat(isSqueezeEffectEnabled).isFalse() } @EnableFlags(Flags.FLAG_ENABLE_LPP_ASSIST_INVOCATION_EFFECT) @Test fun testSqueezeEffectEnabled_AllSettingsEnabled() = kosmos.runTest { globalSettings.putInt(POWER_BUTTON_LONG_PRESS, 5) underTest.tryHandleSetUiHints(createAssistantSettingBundle(true)) val isSqueezeEffectEnabled by collectLastValue(underTest.isSqueezeEffectEnabled) Loading
packages/SystemUI/src/com/android/systemui/assist/AssistManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ public class AssistManager { private static final String INVOCATION_TIME_MS_KEY = "invocation_time_ms"; private static final String INVOCATION_PHONE_STATE_KEY = "invocation_phone_state"; protected static final String ACTION_KEY = "action"; public static final String ACTION_KEY = "action"; protected static final String SET_ASSIST_GESTURE_CONSTRAINED_ACTION = "set_assist_gesture_constrained"; protected static final String CONSTRAINED_KEY = "should_constrain"; Loading
packages/SystemUI/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepositoryImpl.kt +44 −13 Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ import android.util.DisplayUtils import android.view.DisplayInfo import androidx.annotation.ArrayRes import androidx.annotation.DrawableRes import com.android.internal.annotations.VisibleForTesting import com.android.systemui.assist.AssistManager import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application Loading @@ -38,8 +40,14 @@ import javax.inject.Inject import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.flowOn @VisibleForTesting const val SET_INVOCATION_EFFECT_PARAMETERS_ACTION = "set_invocation_effect_parameters" @VisibleForTesting const val IS_INVOCATION_EFFECT_ENABLED_KEY = "is_invocation_effect_enabled" @SysUISingleton class SqueezeEffectRepositoryImpl @Inject Loading @@ -50,32 +58,28 @@ constructor( private val globalSettings: GlobalSettings, ) : SqueezeEffectRepository, InvocationEffectSetUiHintsHandler { override val isSqueezeEffectEnabled: Flow<Boolean> = private val isPowerButtonLongPressConfiguredToLaunchAssistantFlow: Flow<Boolean> = conflatedCallbackFlow { val observer = object : ContentObserver(bgHandler) { override fun onChange(selfChange: Boolean) { trySendWithFailureLogging( squeezeEffectEnabled, getIsPowerButtonLongPressConfiguredToLaunchAssistant(), TAG, "updated isSqueezeEffectEnabled", "updated isPowerButtonLongPressConfiguredToLaunchAssistantFlow", ) } } trySendWithFailureLogging(squeezeEffectEnabled, TAG, "init isSqueezeEffectEnabled") trySendWithFailureLogging( getIsPowerButtonLongPressConfiguredToLaunchAssistant(), TAG, "init isPowerButtonLongPressConfiguredToLaunchAssistantFlow", ) globalSettings.registerContentObserverAsync(POWER_BUTTON_LONG_PRESS, observer) awaitClose { globalSettings.unregisterContentObserverAsync(observer) } } .flowOn(bgCoroutineContext) private val squeezeEffectEnabled get() = Flags.enableLppAssistInvocationEffect() && globalSettings.getInt( POWER_BUTTON_LONG_PRESS, com.android.internal.R.integer.config_longPressOnPowerBehavior, ) == 5 // 5 corresponds to launch assistant in config_longPressOnPowerBehavior override suspend fun getRoundedCornersResourceId(): SqueezeEffectCornerResourceId { val displayInfo = DisplayInfo() context.display.getDisplayInfo(displayInfo) Loading Loading @@ -116,7 +120,34 @@ constructor( return drawableResource } override fun tryHandleSetUiHints(hints: Bundle) = false private val isInvocationEffectEnabledForCurrentAssistantFlow = MutableStateFlow(true) override val isSqueezeEffectEnabled: Flow<Boolean> = combine( isPowerButtonLongPressConfiguredToLaunchAssistantFlow, isInvocationEffectEnabledForCurrentAssistantFlow, ) { prerequisites -> prerequisites.all { it } && Flags.enableLppAssistInvocationEffect() } private fun getIsPowerButtonLongPressConfiguredToLaunchAssistant() = globalSettings.getInt( POWER_BUTTON_LONG_PRESS, com.android.internal.R.integer.config_longPressOnPowerBehavior, ) == 5 // 5 corresponds to launch assistant in PhoneWindowManager.java override fun tryHandleSetUiHints(hints: Bundle): Boolean { return when (hints.getString(AssistManager.ACTION_KEY)) { SET_INVOCATION_EFFECT_PARAMETERS_ACTION -> { if (hints.containsKey(IS_INVOCATION_EFFECT_ENABLED_KEY)) { isInvocationEffectEnabledForCurrentAssistantFlow.value = hints.getBoolean(IS_INVOCATION_EFFECT_ENABLED_KEY) } true } else -> false } } companion object { private const val TAG = "SqueezeEffectRepository" Loading