Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d25a45b1 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[CS] 5/N: Move WallpaperController to WallpaperRepo.

Bug: 277762009
Bug: 277764509
Test: on fold device, set a wallpaper with and without default unfold
transition. Verify WallpaperController has the correct value.
Test: atest WallpaperRepositoryImplTest WallpaperControllerTest
Change-Id: I85321f996a18cb5f01f14087d4d8cc557bcb6237

Change-Id: I457758e223ab651ea7ba725f3f5a05f20398bf2d
parent 5feaa616
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -3564,7 +3564,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
            }
            WallpaperInfo info = mWallpaperManager.getWallpaperInfoForUser(
                    mUserTracker.getUserId());
            mWallpaperController.onWallpaperInfoUpdated(info);
        }
    };

+11 −9
Original line number Diff line number Diff line
@@ -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) {
+3 −0
Original line number Diff line number Diff line
@@ -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()
}
+23 −11
Original line number Diff line number Diff line
@@ -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.
            ?.supportsAmbientMode() == true
                it?.supportsAmbientMode() == true
            }
            .stateIn(
                scope,
                // Always be listening for wallpaper changes.
                SharingStarted.Eagerly,
                initialValue = wallpaperInfo.value?.supportsAmbientMode() == true,
            )

    private fun getWallpaper(selectedUser: SelectedUserModel): WallpaperInfo? {
        return wallpaperManager.getWallpaperInfoForUser(selectedUser.userInfo.id)
    }
}
+5 −3
Original line number Diff line number Diff line
@@ -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)

Loading