Loading packages/SystemUI/multivalentTests/src/com/android/systemui/wallpapers/data/repository/WallpaperRepositoryImplTest.kt +51 −4 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.systemui.wallpapers.data.repository import android.app.WallpaperInfo import android.app.WallpaperManager import android.app.WallpaperManager.FLAG_LOCK import android.content.ComponentName import android.content.Intent import android.content.pm.UserInfo Loading Loading @@ -45,6 +46,7 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentMatchers.eq import org.mockito.kotlin.any import org.mockito.kotlin.doAnswer import org.mockito.kotlin.mock Loading Loading @@ -285,17 +287,17 @@ class WallpaperRepositoryImplTest : SysuiTestCase() { @Test @EnableFlags(SharedFlags.FLAG_EXTENDED_WALLPAPER_EFFECTS) fun shouldSendNotificationLayout_setExtendedEffectsWallpaper_launchSendLayoutJob() = fun shouldSendNotificationLayout_setExtendedEffectsWallpaper() = testScope.runTest { underTest = kosmos.wallpaperRepository val latest by collectLastValue(underTest.shouldSendFocalArea) val extedendEffectsWallpaper = val extendedEffectsWallpaper = mock<WallpaperInfo>().apply { whenever(this.component).thenReturn(ComponentName(context, focalAreaTarget)) } whenever(kosmos.wallpaperManager.getWallpaperInfoForUser(any())) .thenReturn(extedendEffectsWallpaper) .thenReturn(extendedEffectsWallpaper) broadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), Loading @@ -305,7 +307,7 @@ class WallpaperRepositoryImplTest : SysuiTestCase() { @Test @EnableFlags(SharedFlags.FLAG_EXTENDED_WALLPAPER_EFFECTS) fun shouldSendNotificationLayout_setNotExtendedEffectsWallpaper_cancelSendLayoutJob() = fun shouldSendNotificationLayout_setNotExtendedEffectsWallpaper() = testScope.runTest { underTest = kosmos.wallpaperRepository val latest by collectLastValue(underTest.shouldSendFocalArea) Loading @@ -332,6 +334,51 @@ class WallpaperRepositoryImplTest : SysuiTestCase() { assertThat(latest).isFalse() } @Test @EnableFlags(SharedFlags.FLAG_EXTENDED_WALLPAPER_EFFECTS) fun shouldSendNotificationLayout_setExtendedEffectsWallpaperOnlyForHomescreen() = testScope.runTest { underTest = kosmos.wallpaperRepository val latest by collectLastValue(underTest.shouldSendFocalArea) val extendedEffectsWallpaper = mock<WallpaperInfo>().apply { whenever(this.component).thenReturn(ComponentName("", focalAreaTarget)) } whenever(kosmos.wallpaperManager.lockScreenWallpaperExists()).thenReturn(true) whenever(kosmos.wallpaperManager.getWallpaperInfoForUser(any())) .thenReturn(extendedEffectsWallpaper) whenever(kosmos.wallpaperManager.getWallpaperInfo(eq(FLAG_LOCK), any())) .thenReturn(UNSUPPORTED_WP) broadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) assertThat(latest).isFalse() } @Test @EnableFlags(SharedFlags.FLAG_EXTENDED_WALLPAPER_EFFECTS) fun shouldSendNotificationLayout_setExtendedEffectsWallpaperOnlyForLockscreen() = testScope.runTest { underTest = kosmos.wallpaperRepository val latest by collectLastValue(underTest.shouldSendFocalArea) val extendedEffectsWallpaper = mock<WallpaperInfo>().apply { whenever(this.component).thenReturn(ComponentName("", focalAreaTarget)) } whenever(kosmos.wallpaperManager.lockScreenWallpaperExists()).thenReturn(true) whenever(kosmos.wallpaperManager.getWallpaperInfoForUser(any())) .thenReturn(UNSUPPORTED_WP) whenever(kosmos.wallpaperManager.getWallpaperInfo(eq(FLAG_LOCK), any())) .thenReturn(extendedEffectsWallpaper) broadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) assertThat(latest).isTrue() } private companion object { val USER_WITH_UNSUPPORTED_WP = UserInfo(/* id= */ 3, /* name= */ "user3", /* flags= */ 0) val UNSUPPORTED_WP = Loading packages/SystemUI/src/com/android/systemui/wallpapers/data/repository/NoopWallpaperRepository.kt +2 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ import kotlinx.coroutines.flow.flowOf @SysUISingleton class NoopWallpaperRepository @Inject constructor() : WallpaperRepository { override val wallpaperInfo: StateFlow<WallpaperInfo?> = MutableStateFlow(null).asStateFlow() override val lockscreenWallpaperInfo: StateFlow<WallpaperInfo?> = MutableStateFlow(null).asStateFlow() override val wallpaperSupportsAmbientMode = flowOf(false) override var rootView: View? = null override val shouldSendFocalArea: StateFlow<Boolean> = MutableStateFlow(false).asStateFlow() Loading packages/SystemUI/src/com/android/systemui/wallpapers/data/repository/WallpaperRepository.kt +37 −20 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.systemui.wallpapers.data.repository import android.app.WallpaperInfo import android.app.WallpaperManager import android.app.WallpaperManager.FLAG_LOCK import android.app.WallpaperManager.FLAG_SYSTEM import android.content.Context import android.content.Intent import android.content.IntentFilter Loading Loading @@ -65,6 +67,12 @@ interface WallpaperRepository { /** Emits the current user's current wallpaper. */ val wallpaperInfo: StateFlow<WallpaperInfo?> /** * Emits the current user's lockscreen wallpaper. This will emit the same value as * [wallpaperInfo] if the wallpaper is shared between home and lock screen. */ val lockscreenWallpaperInfo: StateFlow<WallpaperInfo?> /** Emits true if the current user's current wallpaper supports ambient mode. */ val wallpaperSupportsAmbientMode: Flow<Boolean> Loading @@ -83,7 +91,7 @@ interface WallpaperRepository { class WallpaperRepositoryImpl @Inject constructor( @Background scope: CoroutineScope, @Background private val scope: CoroutineScope, @Background private val bgDispatcher: CoroutineDispatcher, broadcastDispatcher: BroadcastDispatcher, userRepository: UserRepository, Loading @@ -109,22 +117,8 @@ constructor( // Only update the wallpaper status once the user selection has finished. .filter { it.selectionStatus == SelectionStatus.SELECTION_COMPLETE } override val wallpaperInfo: StateFlow<WallpaperInfo?> = if (!wallpaperManager.isWallpaperSupported) { MutableStateFlow(null).asStateFlow() } else { combine(wallpaperChanged, selectedUser, ::Pair) .mapLatestConflated { (_, selectedUser) -> getWallpaper(selectedUser) } .stateIn( scope, // Always be listening for wallpaper changes. SharingStarted.Eagerly, // The initial value is null, but it should get updated pretty quickly because // the `combine` should immediately kick off a fetch. initialValue = null, ) } override val wallpaperInfo: StateFlow<WallpaperInfo?> = getWallpaperInfo(FLAG_SYSTEM) override val lockscreenWallpaperInfo: StateFlow<WallpaperInfo?> = getWallpaperInfo(FLAG_LOCK) override val wallpaperSupportsAmbientMode: Flow<Boolean> = combine( secureSettings Loading Loading @@ -182,7 +176,7 @@ constructor( } override val shouldSendFocalArea = wallpaperInfo lockscreenWallpaperInfo .map { val focalAreaTarget = context.resources.getString(SysUIR.string.focal_area_target) val shouldSendNotificationLayout = it?.component?.className == focalAreaTarget Loading @@ -194,11 +188,34 @@ constructor( initialValue = extendedWallpaperEffects(), ) private suspend fun getWallpaper(selectedUser: SelectedUserModel): WallpaperInfo? { private suspend fun getWallpaper( selectedUser: SelectedUserModel, which: Int = FLAG_SYSTEM, ): WallpaperInfo? { return withContext(bgDispatcher) { if (which == FLAG_LOCK && wallpaperManager.lockScreenWallpaperExists()) { wallpaperManager.getWallpaperInfo(FLAG_LOCK, selectedUser.userInfo.id) } else { wallpaperManager.getWallpaperInfoForUser(selectedUser.userInfo.id) } } } private fun getWallpaperInfo(which: Int): StateFlow<WallpaperInfo?> = if (!wallpaperManager.isWallpaperSupported) { MutableStateFlow(null).asStateFlow() } else { combine(wallpaperChanged, selectedUser, ::Pair) .mapLatestConflated { (_, selectedUser) -> getWallpaper(selectedUser, which) } .stateIn( scope, // Always be listening for wallpaper changes. SharingStarted.Eagerly, // The initial value is null, but it should get updated pretty quickly because // the `combine` should immediately kick off a fetch. initialValue = null, ) } companion object { private val TAG = WallpaperRepositoryImpl::class.simpleName Loading packages/SystemUI/tests/utils/src/com/android/systemui/wallpapers/data/repository/FakeWallpaperRepository.kt +3 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,9 @@ import kotlinx.coroutines.flow.asStateFlow class FakeWallpaperRepository : WallpaperRepository { private val _wallpaperInfo: MutableStateFlow<WallpaperInfo?> = MutableStateFlow(null) override val wallpaperInfo: StateFlow<WallpaperInfo?> = _wallpaperInfo.asStateFlow() private val _lockscreenWallpaperInfo: MutableStateFlow<WallpaperInfo?> = MutableStateFlow(null) override val lockscreenWallpaperInfo: StateFlow<WallpaperInfo?> = _lockscreenWallpaperInfo.asStateFlow() private val _wallpaperSupportsAmbientMode = MutableStateFlow(false) override val wallpaperSupportsAmbientMode: Flow<Boolean> = _wallpaperSupportsAmbientMode.asStateFlow() Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/wallpapers/data/repository/WallpaperRepositoryImplTest.kt +51 −4 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.systemui.wallpapers.data.repository import android.app.WallpaperInfo import android.app.WallpaperManager import android.app.WallpaperManager.FLAG_LOCK import android.content.ComponentName import android.content.Intent import android.content.pm.UserInfo Loading Loading @@ -45,6 +46,7 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentMatchers.eq import org.mockito.kotlin.any import org.mockito.kotlin.doAnswer import org.mockito.kotlin.mock Loading Loading @@ -285,17 +287,17 @@ class WallpaperRepositoryImplTest : SysuiTestCase() { @Test @EnableFlags(SharedFlags.FLAG_EXTENDED_WALLPAPER_EFFECTS) fun shouldSendNotificationLayout_setExtendedEffectsWallpaper_launchSendLayoutJob() = fun shouldSendNotificationLayout_setExtendedEffectsWallpaper() = testScope.runTest { underTest = kosmos.wallpaperRepository val latest by collectLastValue(underTest.shouldSendFocalArea) val extedendEffectsWallpaper = val extendedEffectsWallpaper = mock<WallpaperInfo>().apply { whenever(this.component).thenReturn(ComponentName(context, focalAreaTarget)) } whenever(kosmos.wallpaperManager.getWallpaperInfoForUser(any())) .thenReturn(extedendEffectsWallpaper) .thenReturn(extendedEffectsWallpaper) broadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), Loading @@ -305,7 +307,7 @@ class WallpaperRepositoryImplTest : SysuiTestCase() { @Test @EnableFlags(SharedFlags.FLAG_EXTENDED_WALLPAPER_EFFECTS) fun shouldSendNotificationLayout_setNotExtendedEffectsWallpaper_cancelSendLayoutJob() = fun shouldSendNotificationLayout_setNotExtendedEffectsWallpaper() = testScope.runTest { underTest = kosmos.wallpaperRepository val latest by collectLastValue(underTest.shouldSendFocalArea) Loading @@ -332,6 +334,51 @@ class WallpaperRepositoryImplTest : SysuiTestCase() { assertThat(latest).isFalse() } @Test @EnableFlags(SharedFlags.FLAG_EXTENDED_WALLPAPER_EFFECTS) fun shouldSendNotificationLayout_setExtendedEffectsWallpaperOnlyForHomescreen() = testScope.runTest { underTest = kosmos.wallpaperRepository val latest by collectLastValue(underTest.shouldSendFocalArea) val extendedEffectsWallpaper = mock<WallpaperInfo>().apply { whenever(this.component).thenReturn(ComponentName("", focalAreaTarget)) } whenever(kosmos.wallpaperManager.lockScreenWallpaperExists()).thenReturn(true) whenever(kosmos.wallpaperManager.getWallpaperInfoForUser(any())) .thenReturn(extendedEffectsWallpaper) whenever(kosmos.wallpaperManager.getWallpaperInfo(eq(FLAG_LOCK), any())) .thenReturn(UNSUPPORTED_WP) broadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) assertThat(latest).isFalse() } @Test @EnableFlags(SharedFlags.FLAG_EXTENDED_WALLPAPER_EFFECTS) fun shouldSendNotificationLayout_setExtendedEffectsWallpaperOnlyForLockscreen() = testScope.runTest { underTest = kosmos.wallpaperRepository val latest by collectLastValue(underTest.shouldSendFocalArea) val extendedEffectsWallpaper = mock<WallpaperInfo>().apply { whenever(this.component).thenReturn(ComponentName("", focalAreaTarget)) } whenever(kosmos.wallpaperManager.lockScreenWallpaperExists()).thenReturn(true) whenever(kosmos.wallpaperManager.getWallpaperInfoForUser(any())) .thenReturn(UNSUPPORTED_WP) whenever(kosmos.wallpaperManager.getWallpaperInfo(eq(FLAG_LOCK), any())) .thenReturn(extendedEffectsWallpaper) broadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), ) assertThat(latest).isTrue() } private companion object { val USER_WITH_UNSUPPORTED_WP = UserInfo(/* id= */ 3, /* name= */ "user3", /* flags= */ 0) val UNSUPPORTED_WP = Loading
packages/SystemUI/src/com/android/systemui/wallpapers/data/repository/NoopWallpaperRepository.kt +2 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ import kotlinx.coroutines.flow.flowOf @SysUISingleton class NoopWallpaperRepository @Inject constructor() : WallpaperRepository { override val wallpaperInfo: StateFlow<WallpaperInfo?> = MutableStateFlow(null).asStateFlow() override val lockscreenWallpaperInfo: StateFlow<WallpaperInfo?> = MutableStateFlow(null).asStateFlow() override val wallpaperSupportsAmbientMode = flowOf(false) override var rootView: View? = null override val shouldSendFocalArea: StateFlow<Boolean> = MutableStateFlow(false).asStateFlow() Loading
packages/SystemUI/src/com/android/systemui/wallpapers/data/repository/WallpaperRepository.kt +37 −20 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.systemui.wallpapers.data.repository import android.app.WallpaperInfo import android.app.WallpaperManager import android.app.WallpaperManager.FLAG_LOCK import android.app.WallpaperManager.FLAG_SYSTEM import android.content.Context import android.content.Intent import android.content.IntentFilter Loading Loading @@ -65,6 +67,12 @@ interface WallpaperRepository { /** Emits the current user's current wallpaper. */ val wallpaperInfo: StateFlow<WallpaperInfo?> /** * Emits the current user's lockscreen wallpaper. This will emit the same value as * [wallpaperInfo] if the wallpaper is shared between home and lock screen. */ val lockscreenWallpaperInfo: StateFlow<WallpaperInfo?> /** Emits true if the current user's current wallpaper supports ambient mode. */ val wallpaperSupportsAmbientMode: Flow<Boolean> Loading @@ -83,7 +91,7 @@ interface WallpaperRepository { class WallpaperRepositoryImpl @Inject constructor( @Background scope: CoroutineScope, @Background private val scope: CoroutineScope, @Background private val bgDispatcher: CoroutineDispatcher, broadcastDispatcher: BroadcastDispatcher, userRepository: UserRepository, Loading @@ -109,22 +117,8 @@ constructor( // Only update the wallpaper status once the user selection has finished. .filter { it.selectionStatus == SelectionStatus.SELECTION_COMPLETE } override val wallpaperInfo: StateFlow<WallpaperInfo?> = if (!wallpaperManager.isWallpaperSupported) { MutableStateFlow(null).asStateFlow() } else { combine(wallpaperChanged, selectedUser, ::Pair) .mapLatestConflated { (_, selectedUser) -> getWallpaper(selectedUser) } .stateIn( scope, // Always be listening for wallpaper changes. SharingStarted.Eagerly, // The initial value is null, but it should get updated pretty quickly because // the `combine` should immediately kick off a fetch. initialValue = null, ) } override val wallpaperInfo: StateFlow<WallpaperInfo?> = getWallpaperInfo(FLAG_SYSTEM) override val lockscreenWallpaperInfo: StateFlow<WallpaperInfo?> = getWallpaperInfo(FLAG_LOCK) override val wallpaperSupportsAmbientMode: Flow<Boolean> = combine( secureSettings Loading Loading @@ -182,7 +176,7 @@ constructor( } override val shouldSendFocalArea = wallpaperInfo lockscreenWallpaperInfo .map { val focalAreaTarget = context.resources.getString(SysUIR.string.focal_area_target) val shouldSendNotificationLayout = it?.component?.className == focalAreaTarget Loading @@ -194,11 +188,34 @@ constructor( initialValue = extendedWallpaperEffects(), ) private suspend fun getWallpaper(selectedUser: SelectedUserModel): WallpaperInfo? { private suspend fun getWallpaper( selectedUser: SelectedUserModel, which: Int = FLAG_SYSTEM, ): WallpaperInfo? { return withContext(bgDispatcher) { if (which == FLAG_LOCK && wallpaperManager.lockScreenWallpaperExists()) { wallpaperManager.getWallpaperInfo(FLAG_LOCK, selectedUser.userInfo.id) } else { wallpaperManager.getWallpaperInfoForUser(selectedUser.userInfo.id) } } } private fun getWallpaperInfo(which: Int): StateFlow<WallpaperInfo?> = if (!wallpaperManager.isWallpaperSupported) { MutableStateFlow(null).asStateFlow() } else { combine(wallpaperChanged, selectedUser, ::Pair) .mapLatestConflated { (_, selectedUser) -> getWallpaper(selectedUser, which) } .stateIn( scope, // Always be listening for wallpaper changes. SharingStarted.Eagerly, // The initial value is null, but it should get updated pretty quickly because // the `combine` should immediately kick off a fetch. initialValue = null, ) } companion object { private val TAG = WallpaperRepositoryImpl::class.simpleName Loading
packages/SystemUI/tests/utils/src/com/android/systemui/wallpapers/data/repository/FakeWallpaperRepository.kt +3 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,9 @@ import kotlinx.coroutines.flow.asStateFlow class FakeWallpaperRepository : WallpaperRepository { private val _wallpaperInfo: MutableStateFlow<WallpaperInfo?> = MutableStateFlow(null) override val wallpaperInfo: StateFlow<WallpaperInfo?> = _wallpaperInfo.asStateFlow() private val _lockscreenWallpaperInfo: MutableStateFlow<WallpaperInfo?> = MutableStateFlow(null) override val lockscreenWallpaperInfo: StateFlow<WallpaperInfo?> = _lockscreenWallpaperInfo.asStateFlow() private val _wallpaperSupportsAmbientMode = MutableStateFlow(false) override val wallpaperSupportsAmbientMode: Flow<Boolean> = _wallpaperSupportsAmbientMode.asStateFlow() Loading