diff options
| author | 2023-07-18 18:38:40 +0000 | |
|---|---|---|
| committer | 2023-07-18 18:38:40 +0000 | |
| commit | 4e74b3d61f50d304f3497ffce14420c911c75fcc (patch) | |
| tree | 2c60e2a8961d2bd5b92e9fa7ee17a2cde6901b5b | |
| parent | 7df848bb82ae351391462371806b9a1d4c3f8a33 (diff) | |
| parent | 86a7d4675c2e6c677bde460ecd0fdd42b8c5979f (diff) | |
Merge changes from topic "caitlinshk-csi-setlockscreenuser" into udc-qpr-dev am: 11f114e48f am: 86a7d4675c
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23984932
Change-Id: Id21ab58584264c51626a8536a05eddd98a5ba80a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
12 files changed, 211 insertions, 94 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowControllerImpl.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowControllerImpl.java index bb2be66cffda..b328c5564590 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowControllerImpl.java @@ -543,7 +543,6 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW state.forceUserActivity, state.launchingActivityFromNotification, state.mediaBackdropShowing, - state.wallpaperSupportsAmbientMode, state.windowNotTouchable, state.componentsForcingTopUi, state.forceOpenTokens, @@ -734,12 +733,6 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW apply(mCurrentState); } - @Override - public void setWallpaperSupportsAmbientMode(boolean supportsAmbientMode) { - mCurrentState.wallpaperSupportsAmbientMode = supportsAmbientMode; - apply(mCurrentState); - } - /** * @param state The {@link StatusBarStateController} of the status bar. */ diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowState.kt b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowState.kt index 7812f07fc59c..d25294343d2f 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowState.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowState.kt @@ -46,7 +46,6 @@ class NotificationShadeWindowState( @JvmField var forceUserActivity: Boolean = false, @JvmField var launchingActivityFromNotification: Boolean = false, @JvmField var mediaBackdropShowing: Boolean = false, - @JvmField var wallpaperSupportsAmbientMode: Boolean = false, @JvmField var windowNotTouchable: Boolean = false, @JvmField var componentsForcingTopUi: MutableSet<String> = mutableSetOf(), @JvmField var forceOpenTokens: MutableSet<Any> = mutableSetOf(), @@ -84,7 +83,6 @@ class NotificationShadeWindowState( forceUserActivity.toString(), launchingActivityFromNotification.toString(), mediaBackdropShowing.toString(), - wallpaperSupportsAmbientMode.toString(), windowNotTouchable.toString(), componentsForcingTopUi.toString(), forceOpenTokens.toString(), @@ -124,7 +122,6 @@ class NotificationShadeWindowState( forceUserActivity: Boolean, launchingActivity: Boolean, backdropShowing: Boolean, - wallpaperSupportsAmbientMode: Boolean, notTouchable: Boolean, componentsForcingTopUi: MutableSet<String>, forceOpenTokens: MutableSet<Any>, @@ -153,7 +150,6 @@ class NotificationShadeWindowState( this.forceUserActivity = forceUserActivity this.launchingActivityFromNotification = launchingActivity this.mediaBackdropShowing = backdropShowing - this.wallpaperSupportsAmbientMode = wallpaperSupportsAmbientMode this.windowNotTouchable = notTouchable this.componentsForcingTopUi.clear() this.componentsForcingTopUi.addAll(componentsForcingTopUi) @@ -200,7 +196,6 @@ class NotificationShadeWindowState( "forceUserActivity", "launchingActivity", "backdropShowing", - "wallpaperSupportsAmbientMode", "notTouchable", "componentsForcingTopUi", "forceOpenTokens", diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeWindowController.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeWindowController.java index 47a4641bcdd9..5ac542b3530f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeWindowController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeWindowController.java @@ -112,9 +112,6 @@ public interface NotificationShadeWindowController extends RemoteInputController /** Sets the state of whether heads up is showing or not. */ default void setHeadsUpShowing(boolean showing) {} - /** Sets whether the wallpaper supports ambient mode or not. */ - default void setWallpaperSupportsAmbientMode(boolean supportsAmbientMode) {} - /** Gets whether the wallpaper is showing or not. */ default boolean isShowingWallpaper() { return false; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java index 2b9c3d33e9b8..acd6e49fe8c1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java @@ -259,8 +259,6 @@ public interface CentralSurfaces extends Dumpable, LifecycleOwner { void readyForKeyguardDone(); - void setLockscreenUser(int newUserId); - void showKeyguard(); boolean hideKeyguard(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java index ce1ec16d3140..8361d6ba1801 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java @@ -51,7 +51,6 @@ import android.app.PendingIntent; import android.app.StatusBarManager; import android.app.TaskInfo; import android.app.UiModeManager; -import android.app.WallpaperInfo; import android.app.WallpaperManager; import android.app.admin.DevicePolicyManager; import android.content.BroadcastReceiver; @@ -980,16 +979,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces { createAndAddWindows(result); - if (mWallpaperSupported) { - // Make sure we always have the most current wallpaper info. - IntentFilter wallpaperChangedFilter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED); - mBroadcastDispatcher.registerReceiver(mWallpaperChangedReceiver, wallpaperChangedFilter, - null /* handler */, UserHandle.ALL); - mWallpaperChangedReceiver.onReceive(mContext, null); - } else if (DEBUG) { - Log.v(TAG, "start(): no wallpaper service "); - } - // Set up the initial notification state. This needs to happen before CommandQueue.disable() setUpPresenter(); @@ -2164,18 +2153,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces { }; /** - * Notify the shade controller that the current user changed - * - * @param newUserId userId of the new user - */ - @Override - public void setLockscreenUser(int newUserId) { - if (mWallpaperSupported) { - mWallpaperChangedReceiver.onReceive(mContext, null); - } - } - - /** * Reload some of our resources when the configuration changes. * * We don't reload everything when the configuration changes -- we probably @@ -3549,32 +3526,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces { } }; - /** - * @deprecated See {@link com.android.systemui.wallpapers.data.repository.WallpaperRepository} - * instead. - */ - private final BroadcastReceiver mWallpaperChangedReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (!mWallpaperSupported) { - // Receiver should not have been registered at all... - Log.wtf(TAG, "WallpaperManager not supported"); - return; - } - WallpaperInfo info = mWallpaperManager.getWallpaperInfoForUser( - mUserTracker.getUserId()); - mWallpaperController.onWallpaperInfoUpdated(info); - - final boolean deviceSupportsAodWallpaper = mContext.getResources().getBoolean( - com.android.internal.R.bool.config_dozeSupportsAodWallpaper); - // If WallpaperInfo is null, it must be ImageWallpaper. - final boolean supportsAmbientMode = deviceSupportsAodWallpaper - && (info != null && info.supportsAmbientMode()); - - mNotificationShadeWindowController.setWallpaperSupportsAmbientMode(supportsAmbientMode); - } - }; - private final ConfigurationListener mConfigurationListener = new ConfigurationListener() { @Override public void onConfigChanged(Configuration newConfig) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java index e63fecd33383..a9135ac91e44 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java @@ -208,7 +208,6 @@ class StatusBarNotificationPresenter implements NotificationPresenter, CommandQu // End old BaseStatusBar.userSwitched mCommandQueue.animateCollapsePanels(); mMediaManager.clearCurrentMediaNotification(); - mCentralSurfaces.setLockscreenUser(newUserId); updateMediaMetaData(true, false); } diff --git a/packages/SystemUI/src/com/android/systemui/util/WallpaperController.kt b/packages/SystemUI/src/com/android/systemui/util/WallpaperController.kt index db2aca873d0c..65a02184f96d 100644 --- a/packages/SystemUI/src/com/android/systemui/util/WallpaperController.kt +++ b/packages/SystemUI/src/com/android/systemui/util/WallpaperController.kt @@ -16,32 +16,34 @@ package com.android.systemui.util -import android.app.WallpaperInfo import android.app.WallpaperManager import android.util.Log import android.view.View import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.wallpapers.data.repository.WallpaperRepository import javax.inject.Inject import kotlin.math.max private const val TAG = "WallpaperController" +/** + * Controller for wallpaper-related logic. + * + * Note: New logic should be added to [WallpaperRepository], not this class. + */ @SysUISingleton -class WallpaperController @Inject constructor(private val wallpaperManager: WallpaperManager) { +class WallpaperController @Inject constructor( + private val wallpaperManager: WallpaperManager, + private val wallpaperRepository: WallpaperRepository, +) { var rootView: View? = null private var notificationShadeZoomOut: Float = 0f private var unfoldTransitionZoomOut: Float = 0f - private var wallpaperInfo: WallpaperInfo? = null - - fun onWallpaperInfoUpdated(wallpaperInfo: WallpaperInfo?) { - this.wallpaperInfo = wallpaperInfo - } - private val shouldUseDefaultUnfoldTransition: Boolean - get() = wallpaperInfo?.shouldUseDefaultUnfoldTransition() + get() = wallpaperRepository.wallpaperInfo.value?.shouldUseDefaultUnfoldTransition() ?: true fun setNotificationShadeZoom(zoomOut: Float) { diff --git a/packages/SystemUI/src/com/android/systemui/wallpapers/data/repository/NoopWallpaperRepository.kt b/packages/SystemUI/src/com/android/systemui/wallpapers/data/repository/NoopWallpaperRepository.kt index a64058968581..b45b8cd15bf5 100644 --- a/packages/SystemUI/src/com/android/systemui/wallpapers/data/repository/NoopWallpaperRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/wallpapers/data/repository/NoopWallpaperRepository.kt @@ -16,9 +16,11 @@ package com.android.systemui.wallpapers.data.repository +import android.app.WallpaperInfo import com.android.systemui.dagger.SysUISingleton import javax.inject.Inject import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow /** @@ -29,5 +31,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() } diff --git a/packages/SystemUI/src/com/android/systemui/wallpapers/data/repository/WallpaperRepository.kt b/packages/SystemUI/src/com/android/systemui/wallpapers/data/repository/WallpaperRepository.kt index 48895ffcacb9..b8f95832b852 100644 --- a/packages/SystemUI/src/com/android/systemui/wallpapers/data/repository/WallpaperRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/wallpapers/data/repository/WallpaperRepository.kt @@ -16,6 +16,7 @@ package com.android.systemui.wallpapers.data.repository +import android.app.WallpaperInfo import android.app.WallpaperManager import android.content.Context import android.content.Intent @@ -36,11 +37,15 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.filter +import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn /** A repository storing information about the current wallpaper. */ interface WallpaperRepository { + /** Emits the current user's current wallpaper. */ + val wallpaperInfo: StateFlow<WallpaperInfo?> + /** Emits true if the current user's current wallpaper supports ambient mode. */ val wallpaperSupportsAmbientMode: StateFlow<Boolean> } @@ -78,28 +83,35 @@ constructor( // Only update the wallpaper status once the user selection has finished. .filter { it.selectionStatus == SelectionStatus.SELECTION_COMPLETE } - override val wallpaperSupportsAmbientMode: StateFlow<Boolean> = + override val wallpaperInfo: StateFlow<WallpaperInfo?> = if (!wallpaperManager.isWallpaperSupported || !deviceSupportsAodWallpaper) { - MutableStateFlow(false).asStateFlow() + MutableStateFlow(null).asStateFlow() } else { combine(wallpaperChanged, selectedUser) { _, selectedUser -> - doesWallpaperSupportAmbientMode(selectedUser) + getWallpaper(selectedUser) } .stateIn( scope, // Always be listening for wallpaper changes. SharingStarted.Eagerly, - initialValue = - doesWallpaperSupportAmbientMode(userRepository.selectedUser.value), + initialValue = getWallpaper(userRepository.selectedUser.value), ) } - private fun doesWallpaperSupportAmbientMode(selectedUser: SelectedUserModel): Boolean { - return wallpaperManager - .getWallpaperInfoForUser( - selectedUser.userInfo.id, + override val wallpaperSupportsAmbientMode: StateFlow<Boolean> = + wallpaperInfo + .map { + // 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 = wallpaperInfo.value?.supportsAmbientMode() == true, ) - // If WallpaperInfo is null, it's ImageWallpaper which never supports ambient mode. - ?.supportsAmbientMode() == true + + private fun getWallpaper(selectedUser: SelectedUserModel): WallpaperInfo? { + return wallpaperManager.getWallpaperInfoForUser(selectedUser.userInfo.id) } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/util/WallpaperControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/util/WallpaperControllerTest.kt index d8e418a7815c..b13cb72dc944 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/util/WallpaperControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/util/WallpaperControllerTest.kt @@ -26,6 +26,7 @@ import android.view.ViewRootImpl import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.util.mockito.eq +import com.android.systemui.wallpapers.data.repository.FakeWallpaperRepository import org.junit.Before import org.junit.Rule import org.junit.Test @@ -56,6 +57,7 @@ class WallpaperControllerTest : SysuiTestCase() { private lateinit var viewRootImpl: ViewRootImpl @Mock private lateinit var windowToken: IBinder + private val wallpaperRepository = FakeWallpaperRepository() @JvmField @Rule @@ -69,7 +71,7 @@ class WallpaperControllerTest : SysuiTestCase() { `when`(root.windowToken).thenReturn(windowToken) `when`(root.isAttachedToWindow).thenReturn(true) - wallaperController = WallpaperController(wallpaperManager) + wallaperController = WallpaperController(wallpaperManager, wallpaperRepository) wallaperController.rootView = root } @@ -90,9 +92,9 @@ class WallpaperControllerTest : SysuiTestCase() { @Test fun setUnfoldTransitionZoom_defaultUnfoldTransitionIsDisabled_doesNotUpdateWallpaperZoom() { - wallaperController.onWallpaperInfoUpdated(createWallpaperInfo( + wallpaperRepository.wallpaperInfo.value = createWallpaperInfo( useDefaultTransition = false - )) + ) wallaperController.setUnfoldTransitionZoom(0.5f) diff --git a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/data/repository/FakeWallpaperRepository.kt b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/data/repository/FakeWallpaperRepository.kt index 6fc36b08250b..fe5024fdc0a3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/data/repository/FakeWallpaperRepository.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/data/repository/FakeWallpaperRepository.kt @@ -16,9 +16,11 @@ package com.android.systemui.wallpapers.data.repository +import android.app.WallpaperInfo import kotlinx.coroutines.flow.MutableStateFlow /** Fake implementation of the wallpaper repository. */ class FakeWallpaperRepository : WallpaperRepository { + override val wallpaperInfo = MutableStateFlow<WallpaperInfo?>(null) override val wallpaperSupportsAmbientMode = MutableStateFlow(false) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/data/repository/WallpaperRepositoryImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/data/repository/WallpaperRepositoryImplTest.kt index 132b9b4a02e1..f8b096a7579b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/data/repository/WallpaperRepositoryImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/data/repository/WallpaperRepositoryImplTest.kt @@ -65,6 +65,171 @@ class WallpaperRepositoryImplTest : SysuiTestCase() { } @Test + fun wallpaperInfo_nullInfo() = + testScope.runTest { + val latest by collectLastValue(underTest.wallpaperInfo) + + whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(null) + + fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( + context, + Intent(Intent.ACTION_WALLPAPER_CHANGED), + ) + + assertThat(latest).isNull() + } + + @Test + fun wallpaperInfo_hasInfoFromManager() = + testScope.runTest { + val latest by collectLastValue(underTest.wallpaperInfo) + + whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(UNSUPPORTED_WP) + + fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( + context, + Intent(Intent.ACTION_WALLPAPER_CHANGED), + ) + + assertThat(latest).isEqualTo(UNSUPPORTED_WP) + } + + @Test + fun wallpaperInfo_initialValueIsFetched() = + 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) + + // WHEN the repo initially starts up (underTest is lazy), then it fetches the current + // value for the wallpaper + assertThat(underTest.wallpaperInfo.value).isEqualTo(SUPPORTED_WP) + } + + @Test + fun wallpaperInfo_updatesOnUserChanged() = + testScope.runTest { + val latest by collectLastValue(underTest.wallpaperInfo) + + val user3 = UserInfo(/* id= */ 3, /* name= */ "user3", /* flags= */ 0) + val user3Wp = mock<WallpaperInfo>() + whenever(wallpaperManager.getWallpaperInfoForUser(user3.id)).thenReturn(user3Wp) + + val user4 = UserInfo(/* id= */ 4, /* name= */ "user4", /* flags= */ 0) + val user4Wp = mock<WallpaperInfo>() + whenever(wallpaperManager.getWallpaperInfoForUser(user4.id)).thenReturn(user4Wp) + + userRepository.setUserInfos(listOf(user3, user4)) + + // WHEN user3 is selected + userRepository.setSelectedUserInfo(user3) + + // THEN user3's wallpaper is used + assertThat(latest).isEqualTo(user3Wp) + + // WHEN the user is switched to user4 + userRepository.setSelectedUserInfo(user4) + + // THEN user4's wallpaper is used + assertThat(latest).isEqualTo(user4Wp) + } + + @Test + fun wallpaperInfo_doesNotUpdateOnUserChanging() = + testScope.runTest { + val latest by collectLastValue(underTest.wallpaperInfo) + + val user3 = UserInfo(/* id= */ 3, /* name= */ "user3", /* flags= */ 0) + val user3Wp = mock<WallpaperInfo>() + whenever(wallpaperManager.getWallpaperInfoForUser(user3.id)).thenReturn(user3Wp) + + val user4 = UserInfo(/* id= */ 4, /* name= */ "user4", /* flags= */ 0) + val user4Wp = mock<WallpaperInfo>() + whenever(wallpaperManager.getWallpaperInfoForUser(user4.id)).thenReturn(user4Wp) + + userRepository.setUserInfos(listOf(user3, user4)) + + // WHEN user3 is selected + userRepository.setSelectedUserInfo(user3) + + // THEN user3's wallpaper is used + assertThat(latest).isEqualTo(user3Wp) + + // WHEN the user has started switching to user4 but hasn't finished yet + userRepository.selectedUser.value = + SelectedUserModel(user4, SelectionStatus.SELECTION_IN_PROGRESS) + + // THEN the wallpaper still matches user3 + assertThat(latest).isEqualTo(user3Wp) + } + + @Test + fun wallpaperInfo_updatesOnIntent() = + testScope.runTest { + val latest by collectLastValue(underTest.wallpaperInfo) + + val wp1 = mock<WallpaperInfo>() + whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(wp1) + + assertThat(latest).isEqualTo(wp1) + + // WHEN the info is new and a broadcast is sent + val wp2 = mock<WallpaperInfo>() + whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(wp2) + fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( + context, + Intent(Intent.ACTION_WALLPAPER_CHANGED), + ) + + // THEN the flow updates + assertThat(latest).isEqualTo(wp2) + } + + @Test + fun wallpaperInfo_wallpaperNotSupported_alwaysNull() = + testScope.runTest { + whenever(wallpaperManager.isWallpaperSupported).thenReturn(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 wallpaperInfo_deviceDoesNotSupportAmbientWallpaper_alwaysFalse() = + testScope.runTest { + context.orCreateTestableResources.addOverride( + com.android.internal.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) @@ -190,14 +355,12 @@ class WallpaperRepositoryImplTest : SysuiTestCase() { testScope.runTest { val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode) - val info: WallpaperInfo = mock() - whenever(info.supportsAmbientMode()).thenReturn(false) - whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(info) + whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(UNSUPPORTED_WP) assertThat(latest).isFalse() // WHEN the info now supports ambient mode and a broadcast is sent - whenever(info.supportsAmbientMode()).thenReturn(true) + whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(SUPPORTED_WP) fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_WALLPAPER_CHANGED), |