From bc513d666ecbca427e64705c9d41ea549ef5f8e6 Mon Sep 17 00:00:00 2001 From: Anthonyy232 <60626873+Anthonyy232@users.noreply.github.com> Date: Tue, 28 Jul 2026 21:50:27 -0700 Subject: [PATCH] fix: stabilize synchronized changes and foldable rendering --- .github/workflows/android-release.yml | 2 +- app/build.gradle.kts | 4 +- .../paperize/core/util/WallpaperUtil.kt | 52 +++++++++++++- .../wallpaper/WallpaperChangeService.kt | 69 ++++++++++++------- .../service/worker/WallpaperChangeWorker.kt | 60 +++++++++------- .../core/util/ScreenMetricsCompatTest.kt | 45 ++++++++++++ gradle/libs.versions.toml | 28 ++++---- renovate.json | 26 +++++-- 8 files changed, 213 insertions(+), 73 deletions(-) create mode 100644 app/src/test/java/com/anthonyla/paperize/core/util/ScreenMetricsCompatTest.kt diff --git a/.github/workflows/android-release.yml b/.github/workflows/android-release.yml index 6e24ef6..7a69e8c 100644 --- a/.github/workflows/android-release.yml +++ b/.github/workflows/android-release.yml @@ -145,7 +145,7 @@ jobs: - name: Create Draft Release # Publishes a new release to GitHub. `draft: true` ensures the release is not made # public until it has been manually reviewed and published. - uses: softprops/action-gh-release@v2 + uses: softprops/action-gh-release@v3 with: files: ./apk-artifact/paperize-v*.apk draft: true diff --git a/app/build.gradle.kts b/app/build.gradle.kts index d70b245..54f2a98 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -119,9 +119,11 @@ dependencies { testImplementation(libs.junit) testImplementation(libs.mockk) testImplementation(libs.kotlinx.coroutines.test) + androidTestImplementation(platform(libs.androidx.compose.bom)) androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) androidTestImplementation(libs.androidx.ui.test.junit4) + debugImplementation(platform(libs.androidx.compose.bom)) debugImplementation(libs.androidx.ui.tooling) debugImplementation(libs.androidx.ui.test.manifest) implementation(libs.hilt.android) @@ -133,4 +135,4 @@ dependencies { implementation(libs.dfc) implementation (libs.kotlinx.serialization.json) implementation(libs.toolbar.compose) -} \ No newline at end of file +} diff --git a/app/src/main/java/com/anthonyla/paperize/core/util/WallpaperUtil.kt b/app/src/main/java/com/anthonyla/paperize/core/util/WallpaperUtil.kt index a875897..fe83e6d 100644 --- a/app/src/main/java/com/anthonyla/paperize/core/util/WallpaperUtil.kt +++ b/app/src/main/java/com/anthonyla/paperize/core/util/WallpaperUtil.kt @@ -21,11 +21,13 @@ import android.graphics.RadialGradient import android.graphics.RenderEffect import android.graphics.RenderNode import android.graphics.Shader +import android.hardware.display.DisplayManager import android.hardware.HardwareBuffer import android.media.ImageReader import android.net.Uri import android.util.Log import android.util.Size +import android.view.Display import android.view.WindowManager import android.view.WindowMetrics import androidx.compose.ui.util.fastRoundToInt @@ -126,10 +128,50 @@ object ScreenMetricsCompat { fun getScreenSize(context: Context): Size { val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager val metrics: WindowMetrics = windowManager.currentWindowMetrics - return Size(metrics.bounds.width(), metrics.bounds.height()) + val candidates = buildList { + add(metrics.bounds.width() to metrics.bounds.height()) + + // Foldables may expose the cover and inner panels as separate internal displays. + // Include every supported internal-display mode so a wallpaper changed while folded + // is still rendered sharply enough for the larger unfolded panel. External displays + // are deliberately excluded so a connected monitor cannot inflate wallpaper memory. + val displayManager = context.getSystemService(DisplayManager::class.java) + displayManager?.displays + ?.asSequence() + ?.filter { display -> + display.flags and Display.FLAG_PRESENTATION == 0 && + display.flags and Display.FLAG_PRIVATE == 0 + } + ?.flatMap { display -> + display.supportedModes.asSequence().map { mode -> + mode.physicalWidth to mode.physicalHeight + } + } + ?.forEach(::add) + } + val largest = selectLargestDisplayDimensions(candidates) + return largest?.let { Size(it.first, it.second) } + ?: Size(metrics.bounds.width(), metrics.bounds.height()) } } +/** + * Select the highest-resolution display dimensions. + * + * Kept platform-independent so foldable sizing behavior is covered by local unit tests. + */ +internal fun selectLargestDisplayDimensions( + candidates: Iterable> +): Pair? = candidates + .filter { (width, height) -> width > 0 && height > 0 } + .maxWithOrNull( + compareBy>( + { (width, height) -> width.toLong() * height.toLong() }, + { (width, height) -> maxOf(width, height) }, + { (width, height) -> minOf(width, height) } + ) + ) + /** * Get device screen size with orientation */ @@ -169,8 +211,12 @@ fun getWallpaperRenderSize(context: Context, screenType: com.anthonyla.paperize. val desiredW = wm.desiredMinimumWidth val desiredH = wm.desiredMinimumHeight // desiredMinimumWidth/Height return 0 when the launcher hasn't set a preference yet. - // Fall back to physical screen size in that case. - if (desiredW > 0 && desiredH > 0) Size(desiredW, desiredH) else screen + // Never render below the largest internal panel's resolution on a foldable. + if (desiredW > 0 && desiredH > 0) { + Size(maxOf(desiredW, screen.width), maxOf(desiredH, screen.height)) + } else { + screen + } } else -> screen } diff --git a/app/src/main/java/com/anthonyla/paperize/service/wallpaper/WallpaperChangeService.kt b/app/src/main/java/com/anthonyla/paperize/service/wallpaper/WallpaperChangeService.kt index 7f76de4..2ae115f 100644 --- a/app/src/main/java/com/anthonyla/paperize/service/wallpaper/WallpaperChangeService.kt +++ b/app/src/main/java/com/anthonyla/paperize/service/wallpaper/WallpaperChangeService.kt @@ -157,14 +157,31 @@ class WallpaperChangeService : Service() { throw IllegalStateException("Bitmap has been recycled") } - // Set for home screen (rendered at parallax canvas size) - wallpaperManager.setBitmap( - bitmap, - null, - true, - WallpaperManager.FLAG_SYSTEM - ) - Log.d(TAG, "Home wallpaper set in BOTH mode") + val canSetAtomically = + settings.homeEffects == settings.lockEffects && + settings.homeScalingType == settings.lockScalingType + + if (canSetAtomically) { + // A single platform transaction prevents home and lock + // from diverging (or one side reverting to the stock + // wallpaper) if a second setBitmap call fails. + wallpaperManager.setBitmap( + bitmap, + null, + true, + WallpaperManager.FLAG_SYSTEM or WallpaperManager.FLAG_LOCK + ) + Log.d(TAG, "Home and lock wallpaper set atomically") + } else { + // Different effects/scaling require distinct render sizes. + wallpaperManager.setBitmap( + bitmap, + null, + true, + WallpaperManager.FLAG_SYSTEM + ) + Log.d(TAG, "Home wallpaper set in BOTH mode") + } // Keep LOCK queue in sync with HOME so that if the user later // switches to separate schedules, both screens continue from @@ -196,25 +213,25 @@ class WallpaperChangeService : Service() { bitmap.recycle() } - // Render a separate bitmap for the lock screen at physical - // screen dimensions. The HOME bitmap was sized for the - // launcher's parallax canvas which is typically wider than - // the screen; reusing it for LOCK would let Android - // center-crop it, defeating FIT/NONE scaling modes. - val lockResult = reapplyEffectsUseCase(homeAlbumId, ScreenType.LOCK) - lockResult.onSuccess { lockBitmap -> - try { - wallpaperManager.setBitmap( - lockBitmap, null, true, WallpaperManager.FLAG_LOCK - ) - Log.d(TAG, "Lock wallpaper set separately in BOTH mode") - } catch (e: Exception) { - Log.e(TAG, "Error setting lock wallpaper in BOTH mode", e) - } finally { - lockBitmap.recycle() + if (settings.homeEffects != settings.lockEffects || + settings.homeScalingType != settings.lockScalingType) { + // Render a separate bitmap only when the user deliberately + // configured different lock-screen presentation settings. + val lockResult = reapplyEffectsUseCase(homeAlbumId, ScreenType.LOCK) + lockResult.onSuccess { lockBitmap -> + try { + wallpaperManager.setBitmap( + lockBitmap, null, true, WallpaperManager.FLAG_LOCK + ) + Log.d(TAG, "Lock wallpaper set separately in BOTH mode") + } catch (e: Exception) { + Log.e(TAG, "Error setting lock wallpaper in BOTH mode", e) + } finally { + lockBitmap.recycle() + } + }.onError { error -> + Log.w(TAG, "Lock rerender failed in BOTH mode: ${error.message}") } - }.onError { error -> - Log.w(TAG, "Lock rerender failed in BOTH mode: ${error.message}") } }.onError { error -> if (error is EmptyAlbumException) { diff --git a/app/src/main/java/com/anthonyla/paperize/service/worker/WallpaperChangeWorker.kt b/app/src/main/java/com/anthonyla/paperize/service/worker/WallpaperChangeWorker.kt index f37637a..b0fbc05 100644 --- a/app/src/main/java/com/anthonyla/paperize/service/worker/WallpaperChangeWorker.kt +++ b/app/src/main/java/com/anthonyla/paperize/service/worker/WallpaperChangeWorker.kt @@ -113,14 +113,27 @@ class WallpaperChangeWorker @AssistedInject constructor( Log.d(TAG, "Setting both screens - size: ${bitmap.width}x${bitmap.height}, config: ${bitmap.config}") - // Set HOME (rendered at parallax canvas size) - wallpaperManager.setBitmap( - bitmap, - null, - true, - WallpaperManager.FLAG_SYSTEM - ) - Log.d(TAG, "Home wallpaper set in BOTH mode") + val canSetAtomically = + settings.homeEffects == settings.lockEffects && + settings.homeScalingType == settings.lockScalingType + + if (canSetAtomically) { + wallpaperManager.setBitmap( + bitmap, + null, + true, + WallpaperManager.FLAG_SYSTEM or WallpaperManager.FLAG_LOCK + ) + Log.d(TAG, "Home and lock wallpaper set atomically") + } else { + wallpaperManager.setBitmap( + bitmap, + null, + true, + WallpaperManager.FLAG_SYSTEM + ) + Log.d(TAG, "Home wallpaper set in BOTH mode") + } // Keep LOCK queue in sync with HOME so that if the user later // switches to separate schedules, both screens continue from @@ -151,22 +164,23 @@ class WallpaperChangeWorker @AssistedInject constructor( bitmap.recycle() } - // Render a separate bitmap for the lock screen at physical - // screen dimensions (no parallax on lock screen). - val lockResult = reapplyEffectsUseCase(homeAlbumId, ScreenType.LOCK) - lockResult.onSuccess { lockBitmap -> - try { - wallpaperManager.setBitmap( - lockBitmap, null, true, WallpaperManager.FLAG_LOCK - ) - Log.d(TAG, "Lock wallpaper set separately in BOTH mode") - } catch (e: Exception) { - Log.e(TAG, "Error setting lock wallpaper in BOTH mode", e) - } finally { - lockBitmap.recycle() + if (settings.homeEffects != settings.lockEffects || + settings.homeScalingType != settings.lockScalingType) { + val lockResult = reapplyEffectsUseCase(homeAlbumId, ScreenType.LOCK) + lockResult.onSuccess { lockBitmap -> + try { + wallpaperManager.setBitmap( + lockBitmap, null, true, WallpaperManager.FLAG_LOCK + ) + Log.d(TAG, "Lock wallpaper set separately in BOTH mode") + } catch (e: Exception) { + Log.e(TAG, "Error setting lock wallpaper in BOTH mode", e) + } finally { + lockBitmap.recycle() + } + }.onError { error -> + Log.w(TAG, "Lock rerender failed in BOTH mode: ${error.message}") } - }.onError { error -> - Log.w(TAG, "Lock rerender failed in BOTH mode: ${error.message}") } }.onError { error -> if (error is EmptyAlbumException) { diff --git a/app/src/test/java/com/anthonyla/paperize/core/util/ScreenMetricsCompatTest.kt b/app/src/test/java/com/anthonyla/paperize/core/util/ScreenMetricsCompatTest.kt new file mode 100644 index 0000000..7d7b3f0 --- /dev/null +++ b/app/src/test/java/com/anthonyla/paperize/core/util/ScreenMetricsCompatTest.kt @@ -0,0 +1,45 @@ +package com.anthonyla.paperize.core.util + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Test + +class ScreenMetricsCompatTest { + + @Test + fun `largest internal display wins even when current window is folded`() { + val result = selectLargestDisplayDimensions( + listOf( + 1080 to 2092, + 1840 to 2208, + 920 to 1104 + ) + ) + + assertEquals(1840 to 2208, result) + } + + @Test + fun `selection uses pixel area instead of only one dimension`() { + val result = selectLargestDisplayDimensions( + listOf( + 2400 to 800, + 1800 to 1400 + ) + ) + + assertEquals(1800 to 1400, result) + } + + @Test + fun `invalid dimensions are ignored`() { + val result = selectLargestDisplayDimensions( + listOf( + 0 to 2208, + -1 to 1080 + ) + ) + + assertNull(result) + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 750c684..d3925e0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,8 +9,8 @@ coil = "3.4.0" [libraries] accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version = "0.37.3" } androidx-activity-compose = { module = "androidx.activity:activity-compose", version = "1.13.0" } -androidx-animation = { module = "androidx.compose.animation:animation", version = "1.10.6" } -androidx-compose-bom = { module = "androidx.compose:compose-bom", version = "2026.03.01" } +androidx-animation = { module = "androidx.compose.animation:animation" } +androidx-compose-bom = { module = "androidx.compose:compose-bom", version = "2026.06.00" } androidx-core-ktx = { module = "androidx.core:core-ktx", version = "1.18.0" } androidx-core-splashscreen = { module = "androidx.core:core-splashscreen", version = "1.2.0" } androidx-datastore-preferences = { module = "androidx.datastore:datastore-preferences", version = "1.2.1" } @@ -18,27 +18,29 @@ androidx-datastore = { module = "androidx.datastore:datastore", version = "1.2.1 androidx-documentfile = { module = "androidx.documentfile:documentfile", version = "1.1.0" } androidx-espresso-core = { module = "androidx.test.espresso:espresso-core", version = "3.7.0" } androidx-exifinterface = { module = "androidx.exifinterface:exifinterface", version = "1.4.2" } -androidx-foundation = { module = "androidx.compose.foundation:foundation", version = "1.10.6" } +androidx-foundation = { module = "androidx.compose.foundation:foundation" } androidx-hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version = "1.3.0" } androidx-hilt-work = { module = "androidx.hilt:hilt-work", version = "1.3.0" } androidx-hilt-compiler = { module = "androidx.hilt:hilt-compiler", version = "1.3.0" } androidx-junit = { module = "androidx.test.ext:junit", version = "1.3.0" } androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version = "2.10.0" } androidx-lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version = "2.10.0" } -androidx-material = { module = "androidx.compose.material:material", version = "1.10.6" } -androidx-material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version = "1.7.8" } +androidx-material = { module = "androidx.compose.material:material" } +androidx-material-icons-extended = { module = "androidx.compose.material:material-icons-extended" } +# v4 uses Material 3 expressive APIs that are not available in the stable 1.4 line. +# Keep this known-good alpha pinned until the expressive API reaches stable. androidx-material3 = { module = "androidx.compose.material3:material3", version = "1.5.0-alpha16" } androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version = "2.9.8" } androidx-profileinstaller = { module = "androidx.profileinstaller:profileinstaller", version = "1.4.1" } androidx-room-ktx = { module = "androidx.room:room-ktx", version = "2.8.4" } androidx-room-compiler = { module = "androidx.room:room-compiler", version = "2.8.4" } androidx-room-runtime = { module = "androidx.room:room-runtime", version = "2.8.4" } -androidx-ui = { module = "androidx.compose.ui:ui", version = "1.10.6" } -androidx-ui-graphics = { module = "androidx.compose.ui:ui-graphics", version = "1.10.6" } -androidx-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4", version = "1.10.6" } -androidx-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest", version = "1.10.6" } -androidx-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version = "1.10.6" } -androidx-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version = "1.10.6" } +androidx-ui = { module = "androidx.compose.ui:ui" } +androidx-ui-graphics = { module = "androidx.compose.ui:ui-graphics" } +androidx-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4" } +androidx-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" } +androidx-ui-tooling = { module = "androidx.compose.ui:ui-tooling" } +androidx-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" } androidx-work-runtime-ktx = { module = "androidx.work:work-runtime-ktx", version = "2.11.2" } coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil" } coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp", version.ref = "coil" } @@ -52,12 +54,12 @@ hilt-android-compiler = { group = "com.google.dagger", name = "hilt-android-comp junit = { module = "junit:junit", version = "4.13.2" } mockk = { module = "io.mockk:mockk", version = "1.14.9" } kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version = "1.10.2" } -kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.10.0" } +kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.11.0" } lazycolumnscrollbar = { module = "com.github.nanihadesuka:LazyColumnScrollbar", version = "2.2.0" } lottie-compose = { module = "com.airbnb.android:lottie-compose", version = "6.7.1" } toolbar-compose = { module = "me.onebone:toolbar-compose", version = "2.3.5" } zoomable = { module = "net.engawapg.lib:zoomable", version = "2.11.1" } -reorderable = { group = "sh.calvin.reorderable", name = "reorderable", version = "3.0.0" } +reorderable = { group = "sh.calvin.reorderable", name = "reorderable", version = "3.1.0" } [plugins] androidApplication = { id = "com.android.application", version.ref = "androidGradlePlugin" } diff --git a/renovate.json b/renovate.json index 8ea318e..757c831 100644 --- a/renovate.json +++ b/renovate.json @@ -1,16 +1,30 @@ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "config:recommended" - ], + "extends": ["config:best-practices"], + "minimumReleaseAge": "14 days", "packageRules": [ { - "matchUpdateTypes": ["minor", "patch", "pin", "digest"], + "description": ["Automerge aged low-risk updates after CI passes"], + "matchUpdateTypes": ["patch", "pin", "digest"], "automerge": true }, { - "matchDepTypes": ["devDependencies"], - "automerge": true + "description": ["Review Compose as one compatible platform update"], + "matchPackageNames": ["androidx.compose:**"], + "groupName": "Jetpack Compose", + "automerge": false + }, + { + "description": ["Coordinate AGP and Gradle compatibility manually"], + "matchPackageNames": ["com.android.tools.build:gradle", "gradle"], + "groupName": "Android build toolchain", + "automerge": false + }, + { + "description": ["Require an explicit maintainer decision for major updates"], + "matchUpdateTypes": ["major"], + "dependencyDashboardApproval": true, + "automerge": false } ], "platformAutomerge": true