Merge changes from topic "caitlinshk-csi-setlockscreenuser" into udc-qpr-dev
* changes: [CS] 6/N=6: Remove CSI's wallpaper tracking & CS#setLockscreenUser. [CS] 5/N: Move WallpaperController to WallpaperRepo. [CS] 4/N: Remove wallpaperSupportsAmbientMode from shade window.
This commit is contained in:
committed by
Android (Google) Code Review
commit
11f114e48f
@@ -543,7 +543,6 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
|
|||||||
state.forceUserActivity,
|
state.forceUserActivity,
|
||||||
state.launchingActivityFromNotification,
|
state.launchingActivityFromNotification,
|
||||||
state.mediaBackdropShowing,
|
state.mediaBackdropShowing,
|
||||||
state.wallpaperSupportsAmbientMode,
|
|
||||||
state.windowNotTouchable,
|
state.windowNotTouchable,
|
||||||
state.componentsForcingTopUi,
|
state.componentsForcingTopUi,
|
||||||
state.forceOpenTokens,
|
state.forceOpenTokens,
|
||||||
@@ -734,12 +733,6 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
|
|||||||
apply(mCurrentState);
|
apply(mCurrentState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setWallpaperSupportsAmbientMode(boolean supportsAmbientMode) {
|
|
||||||
mCurrentState.wallpaperSupportsAmbientMode = supportsAmbientMode;
|
|
||||||
apply(mCurrentState);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param state The {@link StatusBarStateController} of the status bar.
|
* @param state The {@link StatusBarStateController} of the status bar.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ class NotificationShadeWindowState(
|
|||||||
@JvmField var forceUserActivity: Boolean = false,
|
@JvmField var forceUserActivity: Boolean = false,
|
||||||
@JvmField var launchingActivityFromNotification: Boolean = false,
|
@JvmField var launchingActivityFromNotification: Boolean = false,
|
||||||
@JvmField var mediaBackdropShowing: Boolean = false,
|
@JvmField var mediaBackdropShowing: Boolean = false,
|
||||||
@JvmField var wallpaperSupportsAmbientMode: Boolean = false,
|
|
||||||
@JvmField var windowNotTouchable: Boolean = false,
|
@JvmField var windowNotTouchable: Boolean = false,
|
||||||
@JvmField var componentsForcingTopUi: MutableSet<String> = mutableSetOf(),
|
@JvmField var componentsForcingTopUi: MutableSet<String> = mutableSetOf(),
|
||||||
@JvmField var forceOpenTokens: MutableSet<Any> = mutableSetOf(),
|
@JvmField var forceOpenTokens: MutableSet<Any> = mutableSetOf(),
|
||||||
@@ -84,7 +83,6 @@ class NotificationShadeWindowState(
|
|||||||
forceUserActivity.toString(),
|
forceUserActivity.toString(),
|
||||||
launchingActivityFromNotification.toString(),
|
launchingActivityFromNotification.toString(),
|
||||||
mediaBackdropShowing.toString(),
|
mediaBackdropShowing.toString(),
|
||||||
wallpaperSupportsAmbientMode.toString(),
|
|
||||||
windowNotTouchable.toString(),
|
windowNotTouchable.toString(),
|
||||||
componentsForcingTopUi.toString(),
|
componentsForcingTopUi.toString(),
|
||||||
forceOpenTokens.toString(),
|
forceOpenTokens.toString(),
|
||||||
@@ -124,7 +122,6 @@ class NotificationShadeWindowState(
|
|||||||
forceUserActivity: Boolean,
|
forceUserActivity: Boolean,
|
||||||
launchingActivity: Boolean,
|
launchingActivity: Boolean,
|
||||||
backdropShowing: Boolean,
|
backdropShowing: Boolean,
|
||||||
wallpaperSupportsAmbientMode: Boolean,
|
|
||||||
notTouchable: Boolean,
|
notTouchable: Boolean,
|
||||||
componentsForcingTopUi: MutableSet<String>,
|
componentsForcingTopUi: MutableSet<String>,
|
||||||
forceOpenTokens: MutableSet<Any>,
|
forceOpenTokens: MutableSet<Any>,
|
||||||
@@ -153,7 +150,6 @@ class NotificationShadeWindowState(
|
|||||||
this.forceUserActivity = forceUserActivity
|
this.forceUserActivity = forceUserActivity
|
||||||
this.launchingActivityFromNotification = launchingActivity
|
this.launchingActivityFromNotification = launchingActivity
|
||||||
this.mediaBackdropShowing = backdropShowing
|
this.mediaBackdropShowing = backdropShowing
|
||||||
this.wallpaperSupportsAmbientMode = wallpaperSupportsAmbientMode
|
|
||||||
this.windowNotTouchable = notTouchable
|
this.windowNotTouchable = notTouchable
|
||||||
this.componentsForcingTopUi.clear()
|
this.componentsForcingTopUi.clear()
|
||||||
this.componentsForcingTopUi.addAll(componentsForcingTopUi)
|
this.componentsForcingTopUi.addAll(componentsForcingTopUi)
|
||||||
@@ -200,7 +196,6 @@ class NotificationShadeWindowState(
|
|||||||
"forceUserActivity",
|
"forceUserActivity",
|
||||||
"launchingActivity",
|
"launchingActivity",
|
||||||
"backdropShowing",
|
"backdropShowing",
|
||||||
"wallpaperSupportsAmbientMode",
|
|
||||||
"notTouchable",
|
"notTouchable",
|
||||||
"componentsForcingTopUi",
|
"componentsForcingTopUi",
|
||||||
"forceOpenTokens",
|
"forceOpenTokens",
|
||||||
|
|||||||
@@ -112,9 +112,6 @@ public interface NotificationShadeWindowController extends RemoteInputController
|
|||||||
/** Sets the state of whether heads up is showing or not. */
|
/** Sets the state of whether heads up is showing or not. */
|
||||||
default void setHeadsUpShowing(boolean showing) {}
|
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. */
|
/** Gets whether the wallpaper is showing or not. */
|
||||||
default boolean isShowingWallpaper() {
|
default boolean isShowingWallpaper() {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -259,8 +259,6 @@ public interface CentralSurfaces extends Dumpable, LifecycleOwner {
|
|||||||
|
|
||||||
void readyForKeyguardDone();
|
void readyForKeyguardDone();
|
||||||
|
|
||||||
void setLockscreenUser(int newUserId);
|
|
||||||
|
|
||||||
void showKeyguard();
|
void showKeyguard();
|
||||||
|
|
||||||
boolean hideKeyguard();
|
boolean hideKeyguard();
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ import android.app.PendingIntent;
|
|||||||
import android.app.StatusBarManager;
|
import android.app.StatusBarManager;
|
||||||
import android.app.TaskInfo;
|
import android.app.TaskInfo;
|
||||||
import android.app.UiModeManager;
|
import android.app.UiModeManager;
|
||||||
import android.app.WallpaperInfo;
|
|
||||||
import android.app.WallpaperManager;
|
import android.app.WallpaperManager;
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
@@ -980,16 +979,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
|
|||||||
|
|
||||||
createAndAddWindows(result);
|
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()
|
// Set up the initial notification state. This needs to happen before CommandQueue.disable()
|
||||||
setUpPresenter();
|
setUpPresenter();
|
||||||
|
|
||||||
@@ -2163,18 +2152,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.
|
* Reload some of our resources when the configuration changes.
|
||||||
*
|
*
|
||||||
@@ -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() {
|
private final ConfigurationListener mConfigurationListener = new ConfigurationListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onConfigChanged(Configuration newConfig) {
|
public void onConfigChanged(Configuration newConfig) {
|
||||||
|
|||||||
@@ -208,7 +208,6 @@ class StatusBarNotificationPresenter implements NotificationPresenter, CommandQu
|
|||||||
// End old BaseStatusBar.userSwitched
|
// End old BaseStatusBar.userSwitched
|
||||||
mCommandQueue.animateCollapsePanels();
|
mCommandQueue.animateCollapsePanels();
|
||||||
mMediaManager.clearCurrentMediaNotification();
|
mMediaManager.clearCurrentMediaNotification();
|
||||||
mCentralSurfaces.setLockscreenUser(newUserId);
|
|
||||||
updateMediaMetaData(true, false);
|
updateMediaMetaData(true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,32 +16,34 @@
|
|||||||
|
|
||||||
package com.android.systemui.util
|
package com.android.systemui.util
|
||||||
|
|
||||||
import android.app.WallpaperInfo
|
|
||||||
import android.app.WallpaperManager
|
import android.app.WallpaperManager
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.android.systemui.dagger.SysUISingleton
|
import com.android.systemui.dagger.SysUISingleton
|
||||||
|
import com.android.systemui.wallpapers.data.repository.WallpaperRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
|
||||||
private const val TAG = "WallpaperController"
|
private const val TAG = "WallpaperController"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller for wallpaper-related logic.
|
||||||
|
*
|
||||||
|
* Note: New logic should be added to [WallpaperRepository], not this class.
|
||||||
|
*/
|
||||||
@SysUISingleton
|
@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
|
var rootView: View? = null
|
||||||
|
|
||||||
private var notificationShadeZoomOut: Float = 0f
|
private var notificationShadeZoomOut: Float = 0f
|
||||||
private var unfoldTransitionZoomOut: Float = 0f
|
private var unfoldTransitionZoomOut: Float = 0f
|
||||||
|
|
||||||
private var wallpaperInfo: WallpaperInfo? = null
|
|
||||||
|
|
||||||
fun onWallpaperInfoUpdated(wallpaperInfo: WallpaperInfo?) {
|
|
||||||
this.wallpaperInfo = wallpaperInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
private val shouldUseDefaultUnfoldTransition: Boolean
|
private val shouldUseDefaultUnfoldTransition: Boolean
|
||||||
get() = wallpaperInfo?.shouldUseDefaultUnfoldTransition()
|
get() = wallpaperRepository.wallpaperInfo.value?.shouldUseDefaultUnfoldTransition()
|
||||||
?: true
|
?: true
|
||||||
|
|
||||||
fun setNotificationShadeZoom(zoomOut: Float) {
|
fun setNotificationShadeZoom(zoomOut: Float) {
|
||||||
|
|||||||
@@ -16,9 +16,11 @@
|
|||||||
|
|
||||||
package com.android.systemui.wallpapers.data.repository
|
package com.android.systemui.wallpapers.data.repository
|
||||||
|
|
||||||
|
import android.app.WallpaperInfo
|
||||||
import com.android.systemui.dagger.SysUISingleton
|
import com.android.systemui.dagger.SysUISingleton
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,5 +31,6 @@ import kotlinx.coroutines.flow.asStateFlow
|
|||||||
*/
|
*/
|
||||||
@SysUISingleton
|
@SysUISingleton
|
||||||
class NoopWallpaperRepository @Inject constructor() : WallpaperRepository {
|
class NoopWallpaperRepository @Inject constructor() : WallpaperRepository {
|
||||||
|
override val wallpaperInfo: StateFlow<WallpaperInfo?> = MutableStateFlow(null).asStateFlow()
|
||||||
override val wallpaperSupportsAmbientMode = MutableStateFlow(false).asStateFlow()
|
override val wallpaperSupportsAmbientMode = MutableStateFlow(false).asStateFlow()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.systemui.wallpapers.data.repository
|
package com.android.systemui.wallpapers.data.repository
|
||||||
|
|
||||||
|
import android.app.WallpaperInfo
|
||||||
import android.app.WallpaperManager
|
import android.app.WallpaperManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
@@ -36,11 +37,15 @@ import kotlinx.coroutines.flow.StateFlow
|
|||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.filter
|
import kotlinx.coroutines.flow.filter
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.onStart
|
import kotlinx.coroutines.flow.onStart
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
|
||||||
/** A repository storing information about the current wallpaper. */
|
/** A repository storing information about the current wallpaper. */
|
||||||
interface WallpaperRepository {
|
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. */
|
/** Emits true if the current user's current wallpaper supports ambient mode. */
|
||||||
val wallpaperSupportsAmbientMode: StateFlow<Boolean>
|
val wallpaperSupportsAmbientMode: StateFlow<Boolean>
|
||||||
}
|
}
|
||||||
@@ -78,28 +83,35 @@ constructor(
|
|||||||
// Only update the wallpaper status once the user selection has finished.
|
// Only update the wallpaper status once the user selection has finished.
|
||||||
.filter { it.selectionStatus == SelectionStatus.SELECTION_COMPLETE }
|
.filter { it.selectionStatus == SelectionStatus.SELECTION_COMPLETE }
|
||||||
|
|
||||||
override val wallpaperSupportsAmbientMode: StateFlow<Boolean> =
|
override val wallpaperInfo: StateFlow<WallpaperInfo?> =
|
||||||
if (!wallpaperManager.isWallpaperSupported || !deviceSupportsAodWallpaper) {
|
if (!wallpaperManager.isWallpaperSupported || !deviceSupportsAodWallpaper) {
|
||||||
MutableStateFlow(false).asStateFlow()
|
MutableStateFlow(null).asStateFlow()
|
||||||
} else {
|
} else {
|
||||||
combine(wallpaperChanged, selectedUser) { _, selectedUser ->
|
combine(wallpaperChanged, selectedUser) { _, selectedUser ->
|
||||||
doesWallpaperSupportAmbientMode(selectedUser)
|
getWallpaper(selectedUser)
|
||||||
}
|
}
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
// Always be listening for wallpaper changes.
|
// Always be listening for wallpaper changes.
|
||||||
SharingStarted.Eagerly,
|
SharingStarted.Eagerly,
|
||||||
initialValue =
|
initialValue = getWallpaper(userRepository.selectedUser.value),
|
||||||
doesWallpaperSupportAmbientMode(userRepository.selectedUser.value),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doesWallpaperSupportAmbientMode(selectedUser: SelectedUserModel): Boolean {
|
override val wallpaperSupportsAmbientMode: StateFlow<Boolean> =
|
||||||
return wallpaperManager
|
wallpaperInfo
|
||||||
.getWallpaperInfoForUser(
|
.map {
|
||||||
selectedUser.userInfo.id,
|
// 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import android.view.ViewRootImpl
|
|||||||
import androidx.test.filters.SmallTest
|
import androidx.test.filters.SmallTest
|
||||||
import com.android.systemui.SysuiTestCase
|
import com.android.systemui.SysuiTestCase
|
||||||
import com.android.systemui.util.mockito.eq
|
import com.android.systemui.util.mockito.eq
|
||||||
|
import com.android.systemui.wallpapers.data.repository.FakeWallpaperRepository
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@@ -56,6 +57,7 @@ class WallpaperControllerTest : SysuiTestCase() {
|
|||||||
private lateinit var viewRootImpl: ViewRootImpl
|
private lateinit var viewRootImpl: ViewRootImpl
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var windowToken: IBinder
|
private lateinit var windowToken: IBinder
|
||||||
|
private val wallpaperRepository = FakeWallpaperRepository()
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
@Rule
|
@Rule
|
||||||
@@ -69,7 +71,7 @@ class WallpaperControllerTest : SysuiTestCase() {
|
|||||||
`when`(root.windowToken).thenReturn(windowToken)
|
`when`(root.windowToken).thenReturn(windowToken)
|
||||||
`when`(root.isAttachedToWindow).thenReturn(true)
|
`when`(root.isAttachedToWindow).thenReturn(true)
|
||||||
|
|
||||||
wallaperController = WallpaperController(wallpaperManager)
|
wallaperController = WallpaperController(wallpaperManager, wallpaperRepository)
|
||||||
|
|
||||||
wallaperController.rootView = root
|
wallaperController.rootView = root
|
||||||
}
|
}
|
||||||
@@ -90,9 +92,9 @@ class WallpaperControllerTest : SysuiTestCase() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun setUnfoldTransitionZoom_defaultUnfoldTransitionIsDisabled_doesNotUpdateWallpaperZoom() {
|
fun setUnfoldTransitionZoom_defaultUnfoldTransitionIsDisabled_doesNotUpdateWallpaperZoom() {
|
||||||
wallaperController.onWallpaperInfoUpdated(createWallpaperInfo(
|
wallpaperRepository.wallpaperInfo.value = createWallpaperInfo(
|
||||||
useDefaultTransition = false
|
useDefaultTransition = false
|
||||||
))
|
)
|
||||||
|
|
||||||
wallaperController.setUnfoldTransitionZoom(0.5f)
|
wallaperController.setUnfoldTransitionZoom(0.5f)
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,11 @@
|
|||||||
|
|
||||||
package com.android.systemui.wallpapers.data.repository
|
package com.android.systemui.wallpapers.data.repository
|
||||||
|
|
||||||
|
import android.app.WallpaperInfo
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|
||||||
/** Fake implementation of the wallpaper repository. */
|
/** Fake implementation of the wallpaper repository. */
|
||||||
class FakeWallpaperRepository : WallpaperRepository {
|
class FakeWallpaperRepository : WallpaperRepository {
|
||||||
|
override val wallpaperInfo = MutableStateFlow<WallpaperInfo?>(null)
|
||||||
override val wallpaperSupportsAmbientMode = MutableStateFlow(false)
|
override val wallpaperSupportsAmbientMode = MutableStateFlow(false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,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
|
@Test
|
||||||
fun wallpaperSupportsAmbientMode_nullInfo_false() =
|
fun wallpaperSupportsAmbientMode_nullInfo_false() =
|
||||||
testScope.runTest {
|
testScope.runTest {
|
||||||
@@ -190,14 +355,12 @@ class WallpaperRepositoryImplTest : SysuiTestCase() {
|
|||||||
testScope.runTest {
|
testScope.runTest {
|
||||||
val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode)
|
val latest by collectLastValue(underTest.wallpaperSupportsAmbientMode)
|
||||||
|
|
||||||
val info: WallpaperInfo = mock()
|
whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(UNSUPPORTED_WP)
|
||||||
whenever(info.supportsAmbientMode()).thenReturn(false)
|
|
||||||
whenever(wallpaperManager.getWallpaperInfoForUser(any())).thenReturn(info)
|
|
||||||
|
|
||||||
assertThat(latest).isFalse()
|
assertThat(latest).isFalse()
|
||||||
|
|
||||||
// WHEN the info now supports ambient mode and a broadcast is sent
|
// 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(
|
fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly(
|
||||||
context,
|
context,
|
||||||
Intent(Intent.ACTION_WALLPAPER_CHANGED),
|
Intent(Intent.ACTION_WALLPAPER_CHANGED),
|
||||||
|
|||||||
Reference in New Issue
Block a user