Loading packages/SystemUI/multivalentTests/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepositoryTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -146,7 +146,7 @@ class SqueezeEffectRepositoryTest : SysuiTestCase() { userIndex: Int, assistantName: String, ) { underTest // "poke" class to ensure it's initialized collectLastValue(underTest.isSqueezeEffectEnabled) // ensure flow is started userRepository.setUserInfos(userInfos) userRepository.setSelectedUserInfo(userInfos[userIndex]) verify(roleManager) Loading packages/SystemUI/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepositoryImpl.kt +39 −16 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.annotation.SuppressLint import android.app.role.OnRoleHoldersChangedListener import android.app.role.RoleManager import android.content.Context import android.content.SharedPreferences import android.database.ContentObserver import android.hardware.input.InputManager import android.hardware.input.KeyGestureEvent Loading Loading @@ -52,7 +53,6 @@ import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine Loading @@ -79,7 +79,6 @@ constructor( private val sharedPreferences by lazy { context.getSharedPreferences(SHARED_PREFERENCES_FILE_NAME, Context.MODE_PRIVATE) } private val isInvocationEffectEnabledByAssistantFlow = MutableStateFlow<Boolean?>(null) private val selectedAssistantName: StateFlow<String> = conflatedCallbackFlow { Loading Loading @@ -119,21 +118,46 @@ constructor( initialValue = roleManager.getCurrentAssistantFor(userRepository.selectedUserHandle), ) private val selectedAssistantNameAndUserFlow = selectedAssistantName .combine(userRepository.selectedUser) { a, b -> Pair(a, b) } .distinctUntilChanged() private val isInvocationEffectEnabledByAssistantFlow: Flow<Boolean> = conflatedCallbackFlow { val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key -> if (key == IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE) { trySendWithFailureLogging( loadIsInvocationEffectEnabledByAssistant(), TAG, "updated isInvocationEffectEnabledByAssistantFlow due to enabled status change", ) } } sharedPreferences.registerOnSharedPreferenceChangeListener(listener) init { coroutineScope.launch { selectedAssistantNameAndUserFlow.collect { // Assistant or user changed, reload enabled state isInvocationEffectEnabledByAssistantFlow.value = loadIsInvocationEffectEnabledByAssistant() userRepository.selectedUser.collect { trySendWithFailureLogging( loadIsInvocationEffectEnabledByAssistant(), TAG, "updated isInvocationEffectEnabledByAssistantFlow due to user change", ) } } coroutineScope.launch { selectedAssistantName.collect { trySendWithFailureLogging( loadIsInvocationEffectEnabledByAssistant(), TAG, "updated isInvocationEffectEnabledByAssistantFlow due to assistant change", ) } } awaitClose { sharedPreferences.unregisterOnSharedPreferenceChangeListener(listener) } } .flowOn(coroutineContext) private val isPowerButtonLongPressConfiguredToLaunchAssistantFlow: Flow<Boolean> = conflatedCallbackFlow { val observer = Loading Loading @@ -277,7 +301,7 @@ constructor( isPowerButtonLongPressConfiguredToLaunchAssistantFlow, isInvocationEffectEnabledByAssistantFlow, ) { prerequisites -> prerequisites.all { it ?: false } && Flags.enableLppAssistInvocationEffect() prerequisites.all { it } && Flags.enableLppAssistInvocationEffect() } private fun getIsPowerButtonLongPressConfiguredToLaunchAssistant() = Loading Loading @@ -314,7 +338,6 @@ constructor( private fun setIsInvocationEffectEnabledByAssistant(enabled: Boolean) { coroutineScope.launch { isInvocationEffectEnabledByAssistantFlow.value = enabled sharedPreferences.edit { putBoolean(IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE, enabled) putString(PERSISTED_FOR_ASSISTANT_PREFERENCE, selectedAssistantName.value) Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepositoryTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -146,7 +146,7 @@ class SqueezeEffectRepositoryTest : SysuiTestCase() { userIndex: Int, assistantName: String, ) { underTest // "poke" class to ensure it's initialized collectLastValue(underTest.isSqueezeEffectEnabled) // ensure flow is started userRepository.setUserInfos(userInfos) userRepository.setSelectedUserInfo(userInfos[userIndex]) verify(roleManager) Loading
packages/SystemUI/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepositoryImpl.kt +39 −16 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.annotation.SuppressLint import android.app.role.OnRoleHoldersChangedListener import android.app.role.RoleManager import android.content.Context import android.content.SharedPreferences import android.database.ContentObserver import android.hardware.input.InputManager import android.hardware.input.KeyGestureEvent Loading Loading @@ -52,7 +53,6 @@ import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine Loading @@ -79,7 +79,6 @@ constructor( private val sharedPreferences by lazy { context.getSharedPreferences(SHARED_PREFERENCES_FILE_NAME, Context.MODE_PRIVATE) } private val isInvocationEffectEnabledByAssistantFlow = MutableStateFlow<Boolean?>(null) private val selectedAssistantName: StateFlow<String> = conflatedCallbackFlow { Loading Loading @@ -119,21 +118,46 @@ constructor( initialValue = roleManager.getCurrentAssistantFor(userRepository.selectedUserHandle), ) private val selectedAssistantNameAndUserFlow = selectedAssistantName .combine(userRepository.selectedUser) { a, b -> Pair(a, b) } .distinctUntilChanged() private val isInvocationEffectEnabledByAssistantFlow: Flow<Boolean> = conflatedCallbackFlow { val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key -> if (key == IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE) { trySendWithFailureLogging( loadIsInvocationEffectEnabledByAssistant(), TAG, "updated isInvocationEffectEnabledByAssistantFlow due to enabled status change", ) } } sharedPreferences.registerOnSharedPreferenceChangeListener(listener) init { coroutineScope.launch { selectedAssistantNameAndUserFlow.collect { // Assistant or user changed, reload enabled state isInvocationEffectEnabledByAssistantFlow.value = loadIsInvocationEffectEnabledByAssistant() userRepository.selectedUser.collect { trySendWithFailureLogging( loadIsInvocationEffectEnabledByAssistant(), TAG, "updated isInvocationEffectEnabledByAssistantFlow due to user change", ) } } coroutineScope.launch { selectedAssistantName.collect { trySendWithFailureLogging( loadIsInvocationEffectEnabledByAssistant(), TAG, "updated isInvocationEffectEnabledByAssistantFlow due to assistant change", ) } } awaitClose { sharedPreferences.unregisterOnSharedPreferenceChangeListener(listener) } } .flowOn(coroutineContext) private val isPowerButtonLongPressConfiguredToLaunchAssistantFlow: Flow<Boolean> = conflatedCallbackFlow { val observer = Loading Loading @@ -277,7 +301,7 @@ constructor( isPowerButtonLongPressConfiguredToLaunchAssistantFlow, isInvocationEffectEnabledByAssistantFlow, ) { prerequisites -> prerequisites.all { it ?: false } && Flags.enableLppAssistInvocationEffect() prerequisites.all { it } && Flags.enableLppAssistInvocationEffect() } private fun getIsPowerButtonLongPressConfiguredToLaunchAssistant() = Loading Loading @@ -314,7 +338,6 @@ constructor( private fun setIsInvocationEffectEnabledByAssistant(enabled: Boolean) { coroutineScope.launch { isInvocationEffectEnabledByAssistantFlow.value = enabled sharedPreferences.edit { putBoolean(IS_INVOCATION_EFFECT_ENABLED_BY_ASSISTANT_PREFERENCE, enabled) putString(PERSISTED_FOR_ASSISTANT_PREFERENCE, selectedAssistantName.value) Loading