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

Commit f7e2a1a4 authored by Hawkwood's avatar Hawkwood
Browse files

Correctly update preview clock size when requested

Previously we were only updating the smartspace position, and the clock
preview binder was not listening to the appropriate signal. This fixes
that issue by moving the source of the override flow. This bug was
latent until we enabled the new wallpaper flow in picker.

As part of this, I've started a refactor of how our preview data is
organized to better match modern architecture guidelines. More work here
is needed as much of the data is still accessed directly by, or set
directly on KeyguardPreviewRenderer itself. Ideally this could be
treated much more like a View or Binder instead of doing so much
directly.

Bug: 375207082
Bug: 407131820
Test: Manually checked preview behavior
Flag: build.RELEASE_PACKAGE_MAGIC_PORTRAIT_WALLPAPERS
Change-Id: Idc8b3c736b62ff9bbae10d693e3062566744402d
parent 8558d846
Loading
Loading
Loading
Loading
+0 −22
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.android.systemui.shared.clocks.shared.model

object ClockPreviewConstants {
    const val KEY_HIDE_CLOCK = "hide_clock"
}
+2 −0
Original line number Diff line number Diff line
@@ -31,8 +31,10 @@ object KeyguardPreviewConstants {
    const val KEY_QUICK_AFFORDANCE_ID = "quick_affordance_id"
    const val KEY_SLOT_ID = "slot_id"
    const val KEY_CLOCK_SIZE = "clock_size"
    const val KEY_HIDE_CLOCK = "hide_clock"

    const val KEYGUARD_QUICK_AFFORDANCE_ID_NONE = "none"
    const val CLOCK_SIZE_DYNAMIC = "clock_size_dynamic"
    const val CLOCK_SIZE_SMALL = "clock_size_small"
    const val DIM_ALPHA = 0.3f
}
+2 −2
Original line number Diff line number Diff line
@@ -22,10 +22,10 @@ class KeyguardRemotePreviewManagerTest : SysuiTestCase() {
    @Test
    fun onDestroy_clearsReferencesToRenderer() =
        testScope.runTest {
            val renderer = mock<KeyguardPreviewRenderer>()
            val preview = KeyguardPreview(mock(), mock(), mock(), mock(), mock(), mock())
            val onDestroy: (PreviewLifecycleObserver) -> Unit = {}

            val observer = PreviewLifecycleObserver(this, testDispatcher, renderer, onDestroy)
            val observer = PreviewLifecycleObserver(this, testDispatcher, preview, onDestroy)

            // Precondition check.
            assertThat(observer.renderer).isNotNull()
+0 −10
Original line number Diff line number Diff line
@@ -67,8 +67,6 @@ interface KeyguardClockRepository {

    val currentClock: StateFlow<ClockController?>

    val previewClock: Flow<ClockController>

    val clockEventController: ClockEventController

    val shouldForceSmallClock: Boolean
@@ -142,14 +140,6 @@ constructor(
                initialValue = null,
            )

    override val previewClock: Flow<ClockController> =
        currentClockId.map {
            // We should create a new instance for each collect call
            // cause in preview, the same clock will be attached to different view
            // at the same time
            clockRegistry.createCurrentClock()
        }

    override val shouldForceSmallClock: Boolean
        get() =
            featureFlags.isEnabled(Flags.LOCKSCREEN_ENABLE_LANDSCAPE) &&
+79 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.keyguard.data.repository

import android.app.WallpaperColors
import android.hardware.display.DisplayManager
import android.os.Bundle
import android.os.IBinder
import android.view.Display
import android.view.Display.DEFAULT_DISPLAY
import com.android.systemui.keyguard.shared.model.ClockSizeSetting
import com.android.systemui.plugins.clocks.ClockController
import com.android.systemui.shared.clocks.ClockRegistry
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.KEY_HIDE_CLOCK
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.KEY_HIGHLIGHT_QUICK_AFFORDANCES
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.map

@AssistedFactory
interface KeyguardPreviewRepositoryFactory {
    fun create(bundle: Bundle): KeyguardPreviewRepository
}

class KeyguardPreviewRepository
@AssistedInject
constructor(
    private val clockRepository: KeyguardClockRepository,
    private val clockRegistry: ClockRegistry,
    private val displayManager: DisplayManager,
    @Assisted val request: Bundle,
) {
    val hostToken: IBinder? = request.getBinder(KEY_HOST_TOKEN)
    val targetWidth: Int = request.getInt(KEY_VIEW_WIDTH)
    val targetHeight: Int = request.getInt(KEY_VIEW_HEIGHT)
    val shouldHighlightSelectedAffordance: Boolean =
        request.getBoolean(KEY_HIGHLIGHT_QUICK_AFFORDANCES, false)

    val displayId = request.getInt(KEY_DISPLAY_ID, DEFAULT_DISPLAY)
    val display: Display? = displayManager.getDisplay(displayId)

    /** [shouldHideClock] here means that we never create and bind the clock views */
    val shouldHideClock: Boolean = request.getBoolean(KEY_HIDE_CLOCK, false)
    val wallpaperColors: WallpaperColors? = request.getParcelable(KEY_COLORS)

    val requestedClockSize: MutableStateFlow<ClockSizeSetting?> = MutableStateFlow(null)

    val previewClock: Flow<ClockController> =
        clockRepository.currentClockId.map {
            // We should create a new instance for each collect call cause in preview, the same
            // clock will be attached to a different parent view at the same time.
            clockRegistry.createCurrentClock()
        }

    companion object {
        private const val KEY_HOST_TOKEN = "host_token"
        private const val KEY_VIEW_WIDTH = "width"
        private const val KEY_VIEW_HEIGHT = "height"
        private const val KEY_DISPLAY_ID = "display_id"
        private const val KEY_COLORS = "wallpaper_colors"
    }
}
Loading