For #26511: Avoid waiting to set no wallpaper

This should squeeze the most performance for users who haven't set a wallpaper.
This commit is contained in:
Mugurell 2022-09-08 13:23:13 +03:00 committed by mergify[bot]
parent ce3a7152f9
commit 4a88dbf1f1
2 changed files with 32 additions and 5 deletions

View File

@ -115,6 +115,7 @@ import org.mozilla.fenix.tabstray.TabsTrayAccessPoint
import org.mozilla.fenix.utils.Settings.Companion.TOP_SITES_PROVIDER_MAX_THRESHOLD
import org.mozilla.fenix.utils.ToolbarPopupWindow
import org.mozilla.fenix.utils.allowUndo
import org.mozilla.fenix.wallpapers.WallpaperManager
import java.lang.ref.WeakReference
import kotlin.math.min
@ -412,7 +413,8 @@ class HomeFragment : Fragment() {
getMenuButton()?.dismissMenu()
if (shouldEnableWallpaper()) {
val isDefaultTheCurrentWallpaper = WallpaperManager.isDefaultTheCurrentWallpaper(requireContext().settings())
if (shouldEnableWallpaper() && !isDefaultTheCurrentWallpaper) {
// Running this on the Main thread helps to ensure that the just updated configuration
// will be used when the wallpaper is scaled to match.
// Otherwise the portrait wallpaper may remain shown on landscape,
@ -758,7 +760,8 @@ class HomeFragment : Fragment() {
requireComponents.reviewPromptController.promptReview(requireActivity())
}
if (shouldEnableWallpaper()) {
val isDefaultTheCurrentWallpaper = WallpaperManager.isDefaultTheCurrentWallpaper(requireContext().settings())
if (shouldEnableWallpaper() && !isDefaultTheCurrentWallpaper) {
runBlockingIncrement {
wallpapersObserver?.applyCurrentWallpaper()
}

View File

@ -8,6 +8,7 @@ import android.content.Context
import io.mockk.coVerify
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.mockkStatic
import io.mockk.spyk
import io.mockk.verify
@ -31,6 +32,8 @@ import org.mozilla.fenix.ext.components
import org.mozilla.fenix.home.HomeFragment.Companion.AMAZON_SPONSORED_TITLE
import org.mozilla.fenix.home.HomeFragment.Companion.EBAY_SPONSORED_TITLE
import org.mozilla.fenix.utils.Settings
import org.mozilla.fenix.wallpapers.WallpaperManager
import org.mozilla.fenix.wallpapers.WallpaperManager.Companion.isDefaultTheCurrentWallpaper
class HomeFragmentTest {
@ -109,7 +112,7 @@ class HomeFragmentTest {
}
@Test
fun `GIVEN the user is in normal mode WHEN configuration changes THEN the wallpaper is reapplied`() = runTest {
fun `GIVEN the user is in normal mode and has a custom wallpaper chosen WHEN configuration changes THEN the wallpaper is reapplied`() = runTest {
homeFragment.getMenuButton = { null }
val observer: WallpapersObserver = mockk(relaxed = true)
homeFragment.wallpapersObserver = observer
@ -117,10 +120,31 @@ class HomeFragmentTest {
every { themeManager.currentTheme.isPrivate } returns false
}
every { homeFragment.activity } returns activity
mockkObject(WallpaperManager.Companion) {
every { isDefaultTheCurrentWallpaper(any()) } returns false
homeFragment.onConfigurationChanged(mockk(relaxed = true))
homeFragment.onConfigurationChanged(mockk(relaxed = true))
coVerify { observer.applyCurrentWallpaper() }
coVerify { observer.applyCurrentWallpaper() }
}
}
@Test
fun `GIVEN the user is in normal mode and has no custom wallpaper chosen WHEN configuration changes THEN do no try to apply a wallpaper`() = runTest {
homeFragment.getMenuButton = { null }
val observer: WallpapersObserver = mockk(relaxed = true)
homeFragment.wallpapersObserver = observer
val activity: HomeActivity = mockk {
every { themeManager.currentTheme.isPrivate } returns false
}
every { homeFragment.activity } returns activity
mockkObject(WallpaperManager.Companion) {
every { isDefaultTheCurrentWallpaper(any()) } returns true
homeFragment.onConfigurationChanged(mockk(relaxed = true))
coVerify(exactly = 0) { observer.applyCurrentWallpaper() }
}
}
@Test