Loading core/res/res/values/config.xml +1 −1 Original line number Diff line number Diff line Loading @@ -2889,7 +2889,7 @@ <bool name="config_dozeAlwaysOnEnabled">true</bool> <!-- If AOD can show an ambient version of the wallpaper --> <bool name="config_dozeSupportsAodWallpaper">true</bool> <bool name="config_dozeSupportsAodWallpaper">false</bool> <!-- Whether the display blanks itself when transitioning from a doze to a non-doze state --> <bool name="config_displayBlanksAfterDoze">false</bool> Loading packages/SystemUI/multivalentTests/src/com/android/systemui/wallpapers/data/repository/FakeWallpaperRepository.kt +2 −1 Original line number Diff line number Diff line Loading @@ -19,10 +19,11 @@ package com.android.systemui.wallpapers.data.repository import android.app.WallpaperInfo import android.view.View import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.flowOf /** Fake implementation of the wallpaper repository. */ class FakeWallpaperRepository : WallpaperRepository { override val wallpaperInfo = MutableStateFlow<WallpaperInfo?>(null) override val wallpaperSupportsAmbientMode = MutableStateFlow(false) override val wallpaperSupportsAmbientMode = flowOf(false) override var rootView: View? = null } packages/SystemUI/multivalentTests/src/com/android/systemui/wallpapers/data/repository/WallpaperRepositoryImplTest.kt +10 −197 Original line number Diff line number Diff line Loading @@ -24,11 +24,13 @@ import android.content.pm.UserInfo import android.platform.test.annotations.EnableFlags import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.internal.R import com.android.systemui.Flags import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyguard.data.repository.FakeKeyguardClockRepository import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository import com.android.systemui.shared.Flags as SharedFlags import com.android.systemui.user.data.model.SelectedUserModel import com.android.systemui.user.data.model.SelectionStatus import com.android.systemui.user.data.repository.FakeUserRepository Loading Loading @@ -74,10 +76,6 @@ class WallpaperRepositoryImplTest : SysuiTestCase() { @Before fun setUp() { whenever(wallpaperManager.isWallpaperSupported).thenReturn(true) context.orCreateTestableResources.addOverride( com.android.internal.R.bool.config_dozeSupportsAodWallpaper, true, ) } @Test Loading Loading @@ -225,214 +223,29 @@ class WallpaperRepositoryImplTest : SysuiTestCase() { } @Test fun wallpaperInfo_deviceDoesNotSupportAmbientWallpaper_alwaysFalse() = @EnableFlags(SharedFlags.FLAG_AMBIENT_AOD) fun wallpaperSupportsAmbientMode_deviceDoesNotSupport_false() = testScope.runTest { context.orCreateTestableResources.addOverride( com.android.internal.R.bool.config_dozeSupportsAodWallpaper, R.bool.config_dozeSupportsAodWallpaper, false, ) val latest by collectLastValue(underTest.wallpaperInfo) assertThat(latest).isNull() // Even WHEN there *is* current wallpaper val wp1 = mock<WallpaperInfo>() whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(wp1) fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) // THEN the value is still null because wallpaper isn't supported assertThat(latest).isNull() } @Test fun wallpaperSupportsAmbientMode_nullInfo_false() = testScope.runTest { val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(null) fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) assertThat(latest).isFalse() } @Test fun wallpaperSupportsAmbientMode_infoDoesNotSupport_false() = testScope.runTest { val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(UNSUPPORTED_WP) fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) assertThat(latest).isFalse() } @Test fun wallpaperSupportsAmbientMode_infoSupports_true() = testScope.runTest { val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(SUPPORTED_WP) fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) assertThat(latest).isTrue() } @Test fun wallpaperSupportsAmbientMode_initialValueIsFetched_true() = testScope.runTest { whenever(wallpaperManager.getWallpaperInfoForUser(USER_WITH_SUPPORTED_WP.id)) .thenReturn(SUPPORTED_WP) userRepository.setUserInfos(listOf(USER_WITH_SUPPORTED_WP)) userRepository.setSelectedUserInfo(USER_WITH_SUPPORTED_WP) // Start up the repo and let it run the initial fetch underTest.wallpaperSupportsAmbientMode runCurrent() // WHEN the repo initially starts up (underTest is lazy), then it fetches the current // value for the wallpaper assertThat(underTest.wallpaperSupportsAmbientMode.value).isTrue() } @Test fun wallpaperSupportsAmbientMode_initialValueIsFetched_false() = testScope.runTest { whenever(wallpaperManager.getWallpaperInfoForUser(USER_WITH_UNSUPPORTED_WP.id)) .thenReturn(UNSUPPORTED_WP) userRepository.setUserInfos(listOf(USER_WITH_UNSUPPORTED_WP)) userRepository.setSelectedUserInfo(USER_WITH_UNSUPPORTED_WP) // WHEN the repo initially starts up (underTest is lazy), then it fetches the current // value for the wallpaper assertThat(underTest.wallpaperSupportsAmbientMode.value).isFalse() } @Test fun wallpaperSupportsAmbientMode_updatesOnUserChanged() = testScope.runTest { val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) whenever(wallpaperManager.getWallpaperInfoForUser(USER_WITH_SUPPORTED_WP.id)) .thenReturn(SUPPORTED_WP) whenever(wallpaperManager.getWallpaperInfoForUser(USER_WITH_UNSUPPORTED_WP.id)) .thenReturn(UNSUPPORTED_WP) userRepository.setUserInfos(listOf(USER_WITH_SUPPORTED_WP, USER_WITH_UNSUPPORTED_WP)) // WHEN a user with supported wallpaper is selected userRepository.setSelectedUserInfo(USER_WITH_SUPPORTED_WP) // THEN it's true assertThat(latest).isTrue() // WHEN the user is switched to a user with unsupported wallpaper userRepository.setSelectedUserInfo(USER_WITH_UNSUPPORTED_WP) // THEN it's false assertThat(latest).isFalse() } @Test fun wallpaperSupportsAmbientMode_doesNotUpdateOnUserChanging() = testScope.runTest { val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) whenever(wallpaperManager.getWallpaperInfoForUser(USER_WITH_SUPPORTED_WP.id)) .thenReturn(SUPPORTED_WP) whenever(wallpaperManager.getWallpaperInfoForUser(USER_WITH_UNSUPPORTED_WP.id)) .thenReturn(UNSUPPORTED_WP) userRepository.setUserInfos(listOf(USER_WITH_SUPPORTED_WP, USER_WITH_UNSUPPORTED_WP)) // WHEN a user with supported wallpaper is selected userRepository.setSelectedUserInfo(USER_WITH_SUPPORTED_WP) // THEN it's true assertThat(latest).isTrue() // WHEN the user has started switching to a user with unsupported wallpaper but hasn't // finished yet userRepository.selectedUser.value = SelectedUserModel(USER_WITH_UNSUPPORTED_WP, SelectionStatus.SELECTION_IN_PROGRESS) // THEN it still matches the old user assertThat(latest).isTrue() } @Test fun wallpaperSupportsAmbientMode_updatesOnIntent() = testScope.runTest { val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(UNSUPPORTED_WP) assertThat(latest).isFalse() // WHEN the info now supports ambient mode and a broadcast is sent whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(SUPPORTED_WP) fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) // THEN the flow updates assertThat(latest).isTrue() } @Test fun wallpaperSupportsAmbientMode_wallpaperNotSupported_alwaysFalse() = testScope.runTest { whenever(wallpaperManager.isWallpaperSupported).thenReturn(false) val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) assertThat(latest).isFalse() // Even WHEN the current wallpaper *does* support ambient mode whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(SUPPORTED_WP) fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) // THEN the value is still false because wallpaper isn't supported assertThat(latest).isFalse() } @Test fun wallpaperSupportsAmbientMode_deviceDoesNotSupportAmbientWallpaper_alwaysFalse() = @EnableFlags(SharedFlags.FLAG_AMBIENT_AOD) fun wallpaperSupportsAmbientMode_deviceDoesSupport_true() = testScope.runTest { context.orCreateTestableResources.addOverride( com.android.internal.R.bool.config_dozeSupportsAodWallpaper, false, R.bool.config_dozeSupportsAodWallpaper, true, ) val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) assertThat(latest).isFalse() // Even WHEN the current wallpaper *does* support ambient mode whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(SUPPORTED_WP) fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) // THEN the value is still false because the device doesn't support it assertThat(latest).isFalse() assertThat(latest).isTrue() } @Test Loading packages/SystemUI/src/com/android/systemui/wallpapers/data/repository/NoopWallpaperRepository.kt +2 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import javax.inject.Inject import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.flowOf /** * A no-op implementation of [WallpaperRepository]. Loading @@ -33,6 +34,6 @@ import kotlinx.coroutines.flow.asStateFlow @SysUISingleton class NoopWallpaperRepository @Inject constructor() : WallpaperRepository { override val wallpaperInfo: StateFlow<WallpaperInfo?> = MutableStateFlow(null).asStateFlow() override val wallpaperSupportsAmbientMode = MutableStateFlow(false).asStateFlow() override val wallpaperSupportsAmbientMode = flowOf(false) override var rootView: View? = null } packages/SystemUI/src/com/android/systemui/wallpapers/data/repository/WallpaperRepository.kt +7 −25 Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ import android.os.Bundle import android.os.UserHandle import android.view.View import androidx.annotation.VisibleForTesting import com.android.app.tracing.coroutines.launchTraced as launch import com.android.internal.R import com.android.systemui.Flags import com.android.systemui.broadcast.BroadcastDispatcher import com.android.systemui.dagger.SysUISingleton Loading @@ -47,10 +49,10 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn import com.android.app.tracing.coroutines.launchTraced as launch import kotlinx.coroutines.withContext /** A repository storing information about the current wallpaper. */ Loading @@ -59,7 +61,7 @@ interface WallpaperRepository { val wallpaperInfo: StateFlow<WallpaperInfo?> /** Emits true if the current user's current wallpaper supports ambient mode. */ val wallpaperSupportsAmbientMode: StateFlow<Boolean> val wallpaperSupportsAmbientMode: Flow<Boolean> /** Set rootView to get its windowToken afterwards */ var rootView: View? Loading @@ -78,9 +80,6 @@ constructor( private val wallpaperManager: WallpaperManager, context: Context, ) : WallpaperRepository { private val deviceSupportsAodWallpaper = context.resources.getBoolean(com.android.internal.R.bool.config_dozeSupportsAodWallpaper) private val wallpaperChanged: Flow<Unit> = broadcastDispatcher .broadcastFlow(IntentFilter(Intent.ACTION_WALLPAPER_CHANGED), user = UserHandle.ALL) Loading Loading @@ -121,7 +120,7 @@ constructor( ) override val wallpaperInfo: StateFlow<WallpaperInfo?> = if (!wallpaperManager.isWallpaperSupported || !deviceSupportsAodWallpaper) { if (!wallpaperManager.isWallpaperSupported) { MutableStateFlow(null).asStateFlow() } else { combine(wallpaperChanged, selectedUser, ::Pair) Loading @@ -136,25 +135,8 @@ constructor( ) } override val wallpaperSupportsAmbientMode: StateFlow<Boolean> = wallpaperInfo .map { if (ambientAod()) { // Force this mode for now, until ImageWallpaper supports it directly // TODO(b/371236225) true } else { // If WallpaperInfo is null, it's ImageWallpaper which never supports ambient // mode. it?.supportsAmbientMode() == true } } .stateIn( scope, // Always be listening for wallpaper changes. SharingStarted.Eagerly, initialValue = if (ambientAod()) true else false, ) override val wallpaperSupportsAmbientMode: Flow<Boolean> = flowOf(context.resources.getBoolean(R.bool.config_dozeSupportsAodWallpaper) && ambientAod()) override var rootView: View? = null Loading Loading
core/res/res/values/config.xml +1 −1 Original line number Diff line number Diff line Loading @@ -2889,7 +2889,7 @@ <bool name="config_dozeAlwaysOnEnabled">true</bool> <!-- If AOD can show an ambient version of the wallpaper --> <bool name="config_dozeSupportsAodWallpaper">true</bool> <bool name="config_dozeSupportsAodWallpaper">false</bool> <!-- Whether the display blanks itself when transitioning from a doze to a non-doze state --> <bool name="config_displayBlanksAfterDoze">false</bool> Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/wallpapers/data/repository/FakeWallpaperRepository.kt +2 −1 Original line number Diff line number Diff line Loading @@ -19,10 +19,11 @@ package com.android.systemui.wallpapers.data.repository import android.app.WallpaperInfo import android.view.View import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.flowOf /** Fake implementation of the wallpaper repository. */ class FakeWallpaperRepository : WallpaperRepository { override val wallpaperInfo = MutableStateFlow<WallpaperInfo?>(null) override val wallpaperSupportsAmbientMode = MutableStateFlow(false) override val wallpaperSupportsAmbientMode = flowOf(false) override var rootView: View? = null }
packages/SystemUI/multivalentTests/src/com/android/systemui/wallpapers/data/repository/WallpaperRepositoryImplTest.kt +10 −197 Original line number Diff line number Diff line Loading @@ -24,11 +24,13 @@ import android.content.pm.UserInfo import android.platform.test.annotations.EnableFlags import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.internal.R import com.android.systemui.Flags import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyguard.data.repository.FakeKeyguardClockRepository import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository import com.android.systemui.shared.Flags as SharedFlags import com.android.systemui.user.data.model.SelectedUserModel import com.android.systemui.user.data.model.SelectionStatus import com.android.systemui.user.data.repository.FakeUserRepository Loading Loading @@ -74,10 +76,6 @@ class WallpaperRepositoryImplTest : SysuiTestCase() { @Before fun setUp() { whenever(wallpaperManager.isWallpaperSupported).thenReturn(true) context.orCreateTestableResources.addOverride( com.android.internal.R.bool.config_dozeSupportsAodWallpaper, true, ) } @Test Loading Loading @@ -225,214 +223,29 @@ class WallpaperRepositoryImplTest : SysuiTestCase() { } @Test fun wallpaperInfo_deviceDoesNotSupportAmbientWallpaper_alwaysFalse() = @EnableFlags(SharedFlags.FLAG_AMBIENT_AOD) fun wallpaperSupportsAmbientMode_deviceDoesNotSupport_false() = testScope.runTest { context.orCreateTestableResources.addOverride( com.android.internal.R.bool.config_dozeSupportsAodWallpaper, R.bool.config_dozeSupportsAodWallpaper, false, ) val latest by collectLastValue(underTest.wallpaperInfo) assertThat(latest).isNull() // Even WHEN there *is* current wallpaper val wp1 = mock<WallpaperInfo>() whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(wp1) fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) // THEN the value is still null because wallpaper isn't supported assertThat(latest).isNull() } @Test fun wallpaperSupportsAmbientMode_nullInfo_false() = testScope.runTest { val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(null) fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) assertThat(latest).isFalse() } @Test fun wallpaperSupportsAmbientMode_infoDoesNotSupport_false() = testScope.runTest { val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(UNSUPPORTED_WP) fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) assertThat(latest).isFalse() } @Test fun wallpaperSupportsAmbientMode_infoSupports_true() = testScope.runTest { val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(SUPPORTED_WP) fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) assertThat(latest).isTrue() } @Test fun wallpaperSupportsAmbientMode_initialValueIsFetched_true() = testScope.runTest { whenever(wallpaperManager.getWallpaperInfoForUser(USER_WITH_SUPPORTED_WP.id)) .thenReturn(SUPPORTED_WP) userRepository.setUserInfos(listOf(USER_WITH_SUPPORTED_WP)) userRepository.setSelectedUserInfo(USER_WITH_SUPPORTED_WP) // Start up the repo and let it run the initial fetch underTest.wallpaperSupportsAmbientMode runCurrent() // WHEN the repo initially starts up (underTest is lazy), then it fetches the current // value for the wallpaper assertThat(underTest.wallpaperSupportsAmbientMode.value).isTrue() } @Test fun wallpaperSupportsAmbientMode_initialValueIsFetched_false() = testScope.runTest { whenever(wallpaperManager.getWallpaperInfoForUser(USER_WITH_UNSUPPORTED_WP.id)) .thenReturn(UNSUPPORTED_WP) userRepository.setUserInfos(listOf(USER_WITH_UNSUPPORTED_WP)) userRepository.setSelectedUserInfo(USER_WITH_UNSUPPORTED_WP) // WHEN the repo initially starts up (underTest is lazy), then it fetches the current // value for the wallpaper assertThat(underTest.wallpaperSupportsAmbientMode.value).isFalse() } @Test fun wallpaperSupportsAmbientMode_updatesOnUserChanged() = testScope.runTest { val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) whenever(wallpaperManager.getWallpaperInfoForUser(USER_WITH_SUPPORTED_WP.id)) .thenReturn(SUPPORTED_WP) whenever(wallpaperManager.getWallpaperInfoForUser(USER_WITH_UNSUPPORTED_WP.id)) .thenReturn(UNSUPPORTED_WP) userRepository.setUserInfos(listOf(USER_WITH_SUPPORTED_WP, USER_WITH_UNSUPPORTED_WP)) // WHEN a user with supported wallpaper is selected userRepository.setSelectedUserInfo(USER_WITH_SUPPORTED_WP) // THEN it's true assertThat(latest).isTrue() // WHEN the user is switched to a user with unsupported wallpaper userRepository.setSelectedUserInfo(USER_WITH_UNSUPPORTED_WP) // THEN it's false assertThat(latest).isFalse() } @Test fun wallpaperSupportsAmbientMode_doesNotUpdateOnUserChanging() = testScope.runTest { val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) whenever(wallpaperManager.getWallpaperInfoForUser(USER_WITH_SUPPORTED_WP.id)) .thenReturn(SUPPORTED_WP) whenever(wallpaperManager.getWallpaperInfoForUser(USER_WITH_UNSUPPORTED_WP.id)) .thenReturn(UNSUPPORTED_WP) userRepository.setUserInfos(listOf(USER_WITH_SUPPORTED_WP, USER_WITH_UNSUPPORTED_WP)) // WHEN a user with supported wallpaper is selected userRepository.setSelectedUserInfo(USER_WITH_SUPPORTED_WP) // THEN it's true assertThat(latest).isTrue() // WHEN the user has started switching to a user with unsupported wallpaper but hasn't // finished yet userRepository.selectedUser.value = SelectedUserModel(USER_WITH_UNSUPPORTED_WP, SelectionStatus.SELECTION_IN_PROGRESS) // THEN it still matches the old user assertThat(latest).isTrue() } @Test fun wallpaperSupportsAmbientMode_updatesOnIntent() = testScope.runTest { val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(UNSUPPORTED_WP) assertThat(latest).isFalse() // WHEN the info now supports ambient mode and a broadcast is sent whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(SUPPORTED_WP) fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) // THEN the flow updates assertThat(latest).isTrue() } @Test fun wallpaperSupportsAmbientMode_wallpaperNotSupported_alwaysFalse() = testScope.runTest { whenever(wallpaperManager.isWallpaperSupported).thenReturn(false) val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) assertThat(latest).isFalse() // Even WHEN the current wallpaper *does* support ambient mode whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(SUPPORTED_WP) fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) // THEN the value is still false because wallpaper isn't supported assertThat(latest).isFalse() } @Test fun wallpaperSupportsAmbientMode_deviceDoesNotSupportAmbientWallpaper_alwaysFalse() = @EnableFlags(SharedFlags.FLAG_AMBIENT_AOD) fun wallpaperSupportsAmbientMode_deviceDoesSupport_true() = testScope.runTest { context.orCreateTestableResources.addOverride( com.android.internal.R.bool.config_dozeSupportsAodWallpaper, false, R.bool.config_dozeSupportsAodWallpaper, true, ) val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) assertThat(latest).isFalse() // Even WHEN the current wallpaper *does* support ambient mode whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(SUPPORTED_WP) fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) // THEN the value is still false because the device doesn't support it assertThat(latest).isFalse() assertThat(latest).isTrue() } @Test Loading
packages/SystemUI/src/com/android/systemui/wallpapers/data/repository/NoopWallpaperRepository.kt +2 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import javax.inject.Inject import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.flowOf /** * A no-op implementation of [WallpaperRepository]. Loading @@ -33,6 +34,6 @@ import kotlinx.coroutines.flow.asStateFlow @SysUISingleton class NoopWallpaperRepository @Inject constructor() : WallpaperRepository { override val wallpaperInfo: StateFlow<WallpaperInfo?> = MutableStateFlow(null).asStateFlow() override val wallpaperSupportsAmbientMode = MutableStateFlow(false).asStateFlow() override val wallpaperSupportsAmbientMode = flowOf(false) override var rootView: View? = null }
packages/SystemUI/src/com/android/systemui/wallpapers/data/repository/WallpaperRepository.kt +7 −25 Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ import android.os.Bundle import android.os.UserHandle import android.view.View import androidx.annotation.VisibleForTesting import com.android.app.tracing.coroutines.launchTraced as launch import com.android.internal.R import com.android.systemui.Flags import com.android.systemui.broadcast.BroadcastDispatcher import com.android.systemui.dagger.SysUISingleton Loading @@ -47,10 +49,10 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn import com.android.app.tracing.coroutines.launchTraced as launch import kotlinx.coroutines.withContext /** A repository storing information about the current wallpaper. */ Loading @@ -59,7 +61,7 @@ interface WallpaperRepository { val wallpaperInfo: StateFlow<WallpaperInfo?> /** Emits true if the current user's current wallpaper supports ambient mode. */ val wallpaperSupportsAmbientMode: StateFlow<Boolean> val wallpaperSupportsAmbientMode: Flow<Boolean> /** Set rootView to get its windowToken afterwards */ var rootView: View? Loading @@ -78,9 +80,6 @@ constructor( private val wallpaperManager: WallpaperManager, context: Context, ) : WallpaperRepository { private val deviceSupportsAodWallpaper = context.resources.getBoolean(com.android.internal.R.bool.config_dozeSupportsAodWallpaper) private val wallpaperChanged: Flow<Unit> = broadcastDispatcher .broadcastFlow(IntentFilter(Intent.ACTION_WALLPAPER_CHANGED), user = UserHandle.ALL) Loading Loading @@ -121,7 +120,7 @@ constructor( ) override val wallpaperInfo: StateFlow<WallpaperInfo?> = if (!wallpaperManager.isWallpaperSupported || !deviceSupportsAodWallpaper) { if (!wallpaperManager.isWallpaperSupported) { MutableStateFlow(null).asStateFlow() } else { combine(wallpaperChanged, selectedUser, ::Pair) Loading @@ -136,25 +135,8 @@ constructor( ) } override val wallpaperSupportsAmbientMode: StateFlow<Boolean> = wallpaperInfo .map { if (ambientAod()) { // Force this mode for now, until ImageWallpaper supports it directly // TODO(b/371236225) true } else { // If WallpaperInfo is null, it's ImageWallpaper which never supports ambient // mode. it?.supportsAmbientMode() == true } } .stateIn( scope, // Always be listening for wallpaper changes. SharingStarted.Eagerly, initialValue = if (ambientAod()) true else false, ) override val wallpaperSupportsAmbientMode: Flow<Boolean> = flowOf(context.resources.getBoolean(R.bool.config_dozeSupportsAodWallpaper) && ambientAod()) override var rootView: View? = null Loading