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

Commit b3405641 authored by Sherry Zhou's avatar Sherry Zhou Committed by Android (Google) Code Review
Browse files

Merge "Add clocks to Aod BurnInLayer" into main

parents 0c7bac3f a80d367f
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ class DefaultClockController(
    private val resources: Resources,
    private val settings: ClockSettings?,
    private val hasStepClockAnimation: Boolean = false,
    private val migratedClocks: Boolean = false,
) : ClockController {
    override val smallClock: DefaultClockFaceController
    override val largeClock: LargeClockFaceController
@@ -195,6 +196,10 @@ class DefaultClockController(
        }

        override fun recomputePadding(targetRegion: Rect?) {
            // TODO(b/310989341): remove after changing migrate_clocks_to_blueprint to aconfig
            if (migratedClocks) {
                return
            }
            // We center the view within the targetRegion instead of within the parent
            // view by computing the difference and adding that to the padding.
            val lp = view.getLayoutParams() as FrameLayout.LayoutParams
+3 −1
Original line number Diff line number Diff line
@@ -32,7 +32,8 @@ class DefaultClockProvider(
    val ctx: Context,
    val layoutInflater: LayoutInflater,
    val resources: Resources,
    val hasStepClockAnimation: Boolean = false
    val hasStepClockAnimation: Boolean = false,
    val migratedClocks: Boolean = false
) : ClockProvider {
    override fun getClocks(): List<ClockMetadata> = listOf(ClockMetadata(DEFAULT_CLOCK_ID))

@@ -47,6 +48,7 @@ class DefaultClockProvider(
            resources,
            settings,
            hasStepClockAnimation,
            migratedClocks,
        )
    }

+3 −2
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;

import com.android.systemui.res.R;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Application;
import com.android.systemui.dagger.qualifiers.Background;
@@ -30,6 +29,7 @@ import com.android.systemui.flags.Flags;
import com.android.systemui.log.LogBuffer;
import com.android.systemui.log.dagger.KeyguardClockLog;
import com.android.systemui.plugins.PluginManager;
import com.android.systemui.res.R;
import com.android.systemui.shared.clocks.ClockRegistry;
import com.android.systemui.shared.clocks.DefaultClockProvider;

@@ -67,7 +67,8 @@ public abstract class ClockRegistryModule {
                        context,
                        layoutInflater,
                        resources,
                        featureFlags.isEnabled(Flags.STEP_CLOCK_ANIMATION)),
                        featureFlags.isEnabled(Flags.STEP_CLOCK_ANIMATION),
                        featureFlags.isEnabled(Flags.MIGRATE_CLOCKS_TO_BLUEPRINT)),
                context.getString(R.string.lockscreen_clock_id_fallback),
                logBuffer,
                /* keepAllLoaded = */ false,
+51 −6
Original line number Diff line number Diff line
@@ -19,34 +19,71 @@ package com.android.systemui.keyguard.data.repository
import android.os.UserHandle
import android.provider.Settings
import androidx.annotation.VisibleForTesting
import com.android.keyguard.KeyguardClockSwitch.SMALL
import com.android.keyguard.ClockEventController
import com.android.keyguard.KeyguardClockSwitch.ClockSize
import com.android.keyguard.KeyguardClockSwitch.LARGE
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.keyguard.shared.model.SettingsClockSize
import com.android.systemui.plugins.ClockController
import com.android.systemui.plugins.ClockId
import com.android.systemui.shared.clocks.ClockRegistry
import com.android.systemui.util.settings.SecureSettings
import com.android.systemui.util.settings.SettingsProxyExt.observerFlow
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.withContext

interface KeyguardClockRepository {
    /** clock size determined by notificationPanelViewController, LARGE or SMALL */
    val clockSize: StateFlow<Int>

    /** clock size selected in picker, DYNAMIC or SMALL */
    val selectedClockSize: Flow<SettingsClockSize>

    /** clock id, selected from clock carousel in wallpaper picker */
    val currentClockId: Flow<ClockId>

    val currentClock: StateFlow<ClockController?>

    val clockEventController: ClockEventController
    fun setClockSize(@ClockSize size: Int)
}

@SysUISingleton
class KeyguardClockRepository
class KeyguardClockRepositoryImpl
@Inject
constructor(
    private val secureSettings: SecureSettings,
    private val clockRegistry: ClockRegistry,
    override val clockEventController: ClockEventController,
    @Background private val backgroundDispatcher: CoroutineDispatcher,
) {
    @Application private val applicationScope: CoroutineScope,
) : KeyguardClockRepository {

    /** Receive SMALL or LARGE clock should be displayed on keyguard. */
    private val _clockSize: MutableStateFlow<Int> = MutableStateFlow(LARGE)
    override val clockSize: StateFlow<Int> = _clockSize.asStateFlow()

    val selectedClockSize: Flow<SettingsClockSize> =
    override fun setClockSize(size: Int) {
        _clockSize.value = size
    }

    override val selectedClockSize: Flow<SettingsClockSize> =
        secureSettings
            .observerFlow(
                names = arrayOf(Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK),
@@ -55,7 +92,7 @@ constructor(
            .onStart { emit(Unit) } // Forces an initial update.
            .map { getClockSize() }

    val currentClockId: Flow<ClockId> =
    override val currentClockId: Flow<ClockId> =
        callbackFlow {
                fun send() {
                    trySend(clockRegistry.currentClockId)
@@ -72,8 +109,16 @@ constructor(
                awaitClose { clockRegistry.unregisterClockChangeListener(listener) }
            }
            .mapNotNull { it }
            .distinctUntilChanged()

    val currentClock = currentClockId.map { clockRegistry.createCurrentClock() }
    override val currentClock: StateFlow<ClockController?> =
        currentClockId
            .map { clockRegistry.createCurrentClock() }
            .stateIn(
                scope = applicationScope,
                started = SharingStarted.WhileSubscribed(),
                initialValue = clockRegistry.createCurrentClock()
            )

    @VisibleForTesting
    suspend fun getClockSize(): SettingsClockSize {
+0 −14
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package com.android.systemui.keyguard.data.repository

import android.graphics.Point
import android.hardware.biometrics.BiometricSourceType
import com.android.keyguard.KeyguardClockSwitch.ClockSize
import com.android.keyguard.KeyguardClockSwitch.LARGE
import com.android.keyguard.KeyguardUpdateMonitor
import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.systemui.biometrics.AuthController
@@ -192,9 +190,6 @@ interface KeyguardRepository {
    /** Observable updated when keyguardDone should be called either now or soon. */
    val keyguardDone: Flow<KeyguardDone>

    /** Receive SMALL or LARGE clock should be displayed on keyguard. */
    val clockSize: Flow<Int>

    /** Receive whether clock should be centered on lockscreen. */
    val clockShouldBeCentered: Flow<Boolean>

@@ -247,8 +242,6 @@ interface KeyguardRepository {

    suspend fun setKeyguardDone(keyguardDoneType: KeyguardDone)

    fun setClockSize(@ClockSize size: Int)

    fun setClockShouldBeCentered(shouldBeCentered: Boolean)
}

@@ -293,9 +286,6 @@ constructor(
    private val _clockPosition = MutableStateFlow(Position(0, 0))
    override val clockPosition = _clockPosition.asStateFlow()

    private val _clockSize = MutableStateFlow(LARGE)
    override val clockSize: Flow<Int> = _clockSize.asStateFlow()

    private val _clockShouldBeCentered = MutableStateFlow(true)
    override val clockShouldBeCentered: Flow<Boolean> = _clockShouldBeCentered.asStateFlow()

@@ -681,10 +671,6 @@ constructor(
        _isActiveDreamLockscreenHosted.value = isLockscreenHosted
    }

    override fun setClockSize(@ClockSize size: Int) {
        _clockSize.value = size
    }

    override fun setClockShouldBeCentered(shouldBeCentered: Boolean) {
        _clockShouldBeCentered.value = shouldBeCentered
    }
Loading