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

Commit 53471fa4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update blueprint code paths to use Logbuffer" into main

parents 6bd36094 e7f48aab
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.systemui.log.core.MessageBuffer
import com.android.systemui.plugins.clocks.ClockController
import com.android.systemui.plugins.clocks.ClockFontAxis
import com.android.systemui.plugins.clocks.ClockFontAxisSetting
import com.android.systemui.plugins.clocks.ClockLogger
import com.android.systemui.plugins.clocks.ClockMessageBuffers
import com.android.systemui.plugins.clocks.ClockMetadata
import com.android.systemui.plugins.clocks.ClockPickerConfig
@@ -62,7 +63,7 @@ class DefaultClockProvider(
        }

        return if (isClockReactiveVariantsEnabled) {
            val buffers = messageBuffers ?: ClockMessageBuffers(LogUtil.DEFAULT_MESSAGE_BUFFER)
            val buffers = messageBuffers ?: ClockMessageBuffers(ClockLogger.DEFAULT_MESSAGE_BUFFER)
            val fontAxes = ClockFontAxis.merge(FlexClockController.FONT_AXES, settings.axes)
            val clockSettings = settings.copy(axes = fontAxes.map { it.toSetting() })
            val typefaceCache =
+0 −32
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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

import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.core.LogcatOnlyMessageBuffer
import com.android.systemui.log.core.Logger

object LogUtil {
    // Used when MessageBuffers are not provided by the host application
    val DEFAULT_MESSAGE_BUFFER = LogcatOnlyMessageBuffer(LogLevel.INFO)

    // Only intended for use during initialization steps where the correct logger doesn't exist yet
    val FALLBACK_INIT_LOGGER = Logger(LogcatOnlyMessageBuffer(LogLevel.ERROR), "CLOCK_INIT")

    // Debug is primarially used for tests, but can also be used for tracking down hard issues.
    val DEBUG_MESSAGE_BUFFER = LogcatOnlyMessageBuffer(LogLevel.DEBUG)
}
+12 −43
Original line number Diff line number Diff line
@@ -27,11 +27,10 @@ import android.widget.RelativeLayout
import androidx.annotation.VisibleForTesting
import com.android.app.animation.Interpolators
import com.android.systemui.customization.R
import com.android.systemui.log.core.Logger
import com.android.systemui.plugins.clocks.ClockFontAxisSetting
import com.android.systemui.plugins.clocks.ClockLogger
import com.android.systemui.shared.clocks.ClockContext
import com.android.systemui.shared.clocks.DigitTranslateAnimator
import com.android.systemui.shared.clocks.LogUtil
import java.util.Locale
import kotlin.math.abs
import kotlin.math.max
@@ -40,8 +39,8 @@ import kotlin.math.min
fun clamp(value: Float, minVal: Float, maxVal: Float): Float = max(min(value, maxVal), minVal)

class FlexClockView(clockCtx: ClockContext) : FrameLayout(clockCtx.context) {
    protected val logger = Logger(clockCtx.messageBuffer, this::class.simpleName!!)
        get() = field ?: LogUtil.FALLBACK_INIT_LOGGER
    protected val logger = ClockLogger(this, clockCtx.messageBuffer, this::class.simpleName!!)
        get() = field ?: ClockLogger.INIT_LOGGER

    @VisibleForTesting
    var isAnimationEnabled = true
@@ -121,11 +120,7 @@ class FlexClockView(clockCtx: ClockContext) : FrameLayout(clockCtx.context) {

    override fun addView(child: View?) {
        if (child == null) return
        logger.d({ "addView($str1 @$int1)" }) {
            str1 = child::class.simpleName!!
            int1 = child.id
        }

        logger.addView(child)
        super.addView(child)
        (child as? SimpleDigitalClockTextView)?.let {
            it.digitTranslateAnimator = DigitTranslateAnimator(::invalidate)
@@ -135,58 +130,32 @@ class FlexClockView(clockCtx: ClockContext) : FrameLayout(clockCtx.context) {
    }

    fun refreshTime() {
        logger.d("refreshTime()")
        logger.refreshTime()
        digitalClockTextViewMap.forEach { (_, textView) -> textView.refreshText() }
    }

    override fun setVisibility(visibility: Int) {
        if (visibility != this.visibility) {
            logger.d({ "setVisibility(${str1 ?: int1})" }) {
                int1 = visibility
                str1 =
                    when (visibility) {
                        VISIBLE -> "VISIBLE"
                        INVISIBLE -> "INVISIBLE"
                        GONE -> "GONE"
                        else -> null
                    }
            }
        }

        logger.setVisibility(visibility)
        super.setVisibility(visibility)
    }

    private var loggedAlpha = 1000f

    override fun setAlpha(alpha: Float) {
        val delta = if (alpha <= 0f || alpha >= 1f) 0.001f else 0.5f
        if (abs(loggedAlpha - alpha) >= delta) {
            loggedAlpha = alpha
            logger.d({ "setAlpha($double1)" }) { double1 = alpha.toDouble() }
        }
        logger.setAlpha(alpha)
        super.setAlpha(alpha)
    }

    private val isDrawn: Boolean
        get() = (mPrivateFlags and 0x20 /* PFLAG_DRAWN */) > 0

    override fun invalidate() {
        if (isDrawn && visibility == VISIBLE) {
            logger.d("invalidate()")
        }

        logger.invalidate()
        super.invalidate()
    }

    override fun requestLayout() {
        if (!isLayoutRequested()) {
            logger.d("requestLayout()")
        }
        logger.requestLayout()
        super.requestLayout()
    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        logger.d("onMeasure()")
        logger.onMeasure()
        calculateSize(widthMeasureSpec, heightMeasureSpec)?.let { size ->
            setMeasuredDimension(size.x, size.y)
        } ?: run { super.onMeasure(widthMeasureSpec, heightMeasureSpec) }
@@ -198,12 +167,12 @@ class FlexClockView(clockCtx: ClockContext) : FrameLayout(clockCtx.context) {
    }

    override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
        logger.d("onLayout()")
        logger.onLayout()
        super.onLayout(changed, left, top, right, bottom)
    }

    override fun onDraw(canvas: Canvas) {
        logger.d("onDraw()")
        logger.onDraw()
        super.onDraw(canvas)

        digitalClockTextViewMap.forEach { (id, textView) ->
+10 −38
Original line number Diff line number Diff line
@@ -37,15 +37,13 @@ import com.android.internal.annotations.VisibleForTesting
import com.android.systemui.animation.GSFAxes
import com.android.systemui.animation.TextAnimator
import com.android.systemui.customization.R
import com.android.systemui.log.core.Logger
import com.android.systemui.plugins.clocks.ClockFontAxisSetting
import com.android.systemui.plugins.clocks.ClockLogger
import com.android.systemui.shared.clocks.ClockContext
import com.android.systemui.shared.clocks.DigitTranslateAnimator
import com.android.systemui.shared.clocks.DimensionParser
import com.android.systemui.shared.clocks.FontTextStyle
import com.android.systemui.shared.clocks.LogUtil
import java.lang.Thread
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

@@ -95,8 +93,8 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe
    private val prevTextBounds = Rect()
    // targetTextBounds holds the state we are interpolating to
    private val targetTextBounds = Rect()
    protected val logger = Logger(clockCtx.messageBuffer, this::class.simpleName!!)
        get() = field ?: LogUtil.FALLBACK_INIT_LOGGER
    protected val logger = ClockLogger(this, clockCtx.messageBuffer, this::class.simpleName!!)
        get() = field ?: ClockLogger.INIT_LOGGER

    private var aodDozingInterpolator: Interpolator? = null

@@ -147,7 +145,7 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe
    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        logger.d("onMeasure()")
        logger.onMeasure()
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)

        val layout = this.layout
@@ -208,9 +206,7 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe
    }

    override fun onDraw(canvas: Canvas) {
        logger.d({ "onDraw(${str1?.replace("\n", "\\n")})" }) {
            str1 = textAnimator.textInterpolator.shapedText
        }
        logger.onDraw(textAnimator.textInterpolator.shapedText)

        val translation = getLocalTranslation()
        canvas.translate(translation.x.toFloat(), translation.y.toFloat())
@@ -227,47 +223,23 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe
    }

    override fun setVisibility(visibility: Int) {
        if (visibility != this.visibility) {
            logger.d({ "setVisibility(${str1 ?: int1})" }) {
                int1 = visibility
                str1 =
                    when (visibility) {
                        VISIBLE -> "VISIBLE"
                        INVISIBLE -> "INVISIBLE"
                        GONE -> "GONE"
                        else -> null
                    }
            }
        }

        logger.setVisibility(visibility)
        super.setVisibility(visibility)
    }

    private var loggedAlpha = 1000f

    override fun setAlpha(alpha: Float) {
        val delta = if (alpha <= 0f || alpha >= 1f) 0.001f else 0.5f
        if (abs(loggedAlpha - alpha) >= delta) {
            loggedAlpha = alpha
            logger.d({ "setAlpha($double1)" }) { double1 = alpha.toDouble() }
        }
        logger.setAlpha(alpha)
        super.setAlpha(alpha)
    }

    private val isDrawn: Boolean
        get() = (mPrivateFlags and 0x20 /* PFLAG_DRAWN */) > 0

    override fun invalidate() {
        if (isDrawn && visibility == VISIBLE) {
            logger.d("invalidate()")
        }

        logger.invalidate()
        super.invalidate()
        (parent as? FlexClockView)?.invalidate()
    }

    fun refreshTime() {
        logger.d("refreshTime()")
        logger.refreshTime()
        refreshText()
    }

@@ -472,7 +444,7 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe
        maxSingleDigitWidth = 0

        for (i in 0..9) {
            lockScreenPaint.getTextBounds(i.toString(), 0, 1, rectForCalculate)
            lockScreenPaint.getTextBounds("$i", 0, 1, rectForCalculate)
            maxSingleDigitHeight = max(maxSingleDigitHeight, rectForCalculate.height())
            maxSingleDigitWidth = max(maxSingleDigitWidth, rectForCalculate.width())
        }
+2 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.keyguard.domain.interactor.KeyguardBlueprintInteractor
import com.android.systemui.keyguard.domain.interactor.keyguardTransitionInteractor
import com.android.systemui.log.logcatLogBuffer
import com.android.systemui.testKosmos
import org.junit.Before
import org.junit.Test
@@ -46,6 +47,7 @@ class KeyguardBlueprintViewModelTest : SysuiTestCase() {
                handler = kosmos.fakeExecutorHandler,
                keyguardBlueprintInteractor = keyguardBlueprintInteractor,
                keyguardTransitionInteractor = kosmos.keyguardTransitionInteractor,
                blueprintLog = logcatLogBuffer("blueprints"),
            )
    }

Loading