Merge "Refactor Clocks to use MessageBuffer + Logger" into udc-qpr-dev

This commit is contained in:
Treehugger Robot
2023-07-07 13:41:07 +00:00
committed by Android (Google) Code Review
6 changed files with 59 additions and 78 deletions

View File

@@ -33,8 +33,8 @@ import com.android.internal.annotations.VisibleForTesting
import com.android.systemui.animation.GlyphCallback import com.android.systemui.animation.GlyphCallback
import com.android.systemui.animation.TextAnimator import com.android.systemui.animation.TextAnimator
import com.android.systemui.customization.R import com.android.systemui.customization.R
import com.android.systemui.log.LogBuffer import com.android.systemui.log.core.Logger
import com.android.systemui.log.core.LogLevel.DEBUG import com.android.systemui.log.core.MessageBuffer
import java.io.PrintWriter import java.io.PrintWriter
import java.util.Calendar import java.util.Calendar
import java.util.Locale import java.util.Locale
@@ -51,7 +51,12 @@ class AnimatableClockView @JvmOverloads constructor(
defStyleAttr: Int = 0, defStyleAttr: Int = 0,
defStyleRes: Int = 0 defStyleRes: Int = 0
) : TextView(context, attrs, defStyleAttr, defStyleRes) { ) : TextView(context, attrs, defStyleAttr, defStyleRes) {
var logBuffer: LogBuffer? = null var messageBuffer: MessageBuffer? = null
set(value) {
logger = if (value != null) Logger(value, TAG) else null
}
private var logger: Logger? = null
private val time = Calendar.getInstance() private val time = Calendar.getInstance()
@@ -129,7 +134,7 @@ class AnimatableClockView @JvmOverloads constructor(
override fun onAttachedToWindow() { override fun onAttachedToWindow() {
super.onAttachedToWindow() super.onAttachedToWindow()
logBuffer?.log(TAG, DEBUG, "onAttachedToWindow") logger?.d("onAttachedToWindow")
refreshFormat() refreshFormat()
} }
@@ -145,39 +150,32 @@ class AnimatableClockView @JvmOverloads constructor(
time.timeInMillis = timeOverrideInMillis ?: System.currentTimeMillis() time.timeInMillis = timeOverrideInMillis ?: System.currentTimeMillis()
contentDescription = DateFormat.format(descFormat, time) contentDescription = DateFormat.format(descFormat, time)
val formattedText = DateFormat.format(format, time) val formattedText = DateFormat.format(format, time)
logBuffer?.log(TAG, DEBUG, logger?.d({ "refreshTime: new formattedText=$str1" }) { str1 = formattedText?.toString() }
{ str1 = formattedText?.toString() },
{ "refreshTime: new formattedText=$str1" }
)
// Setting text actually triggers a layout pass (because the text view is set to // Setting text actually triggers a layout pass (because the text view is set to
// wrap_content width and TextView always relayouts for this). Avoid needless // wrap_content width and TextView always relayouts for this). Avoid needless
// relayout if the text didn't actually change. // relayout if the text didn't actually change.
if (!TextUtils.equals(text, formattedText)) { if (!TextUtils.equals(text, formattedText)) {
text = formattedText text = formattedText
logBuffer?.log(TAG, DEBUG, logger?.d({ "refreshTime: done setting new time text to: $str1" }) {
{ str1 = formattedText?.toString() }, str1 = formattedText?.toString()
{ "refreshTime: done setting new time text to: $str1" } }
)
// Because the TextLayout may mutate under the hood as a result of the new text, we // Because the TextLayout may mutate under the hood as a result of the new text, we
// notify the TextAnimator that it may have changed and request a measure/layout. A // notify the TextAnimator that it may have changed and request a measure/layout. A
// crash will occur on the next invocation of setTextStyle if the layout is mutated // crash will occur on the next invocation of setTextStyle if the layout is mutated
// without being notified TextInterpolator being notified. // without being notified TextInterpolator being notified.
if (layout != null) { if (layout != null) {
textAnimator?.updateLayout(layout) textAnimator?.updateLayout(layout)
logBuffer?.log(TAG, DEBUG, "refreshTime: done updating textAnimator layout") logger?.d("refreshTime: done updating textAnimator layout")
} }
requestLayout() requestLayout()
logBuffer?.log(TAG, DEBUG, "refreshTime: after requestLayout") logger?.d("refreshTime: after requestLayout")
} }
} }
fun onTimeZoneChanged(timeZone: TimeZone?) { fun onTimeZoneChanged(timeZone: TimeZone?) {
time.timeZone = timeZone time.timeZone = timeZone
refreshFormat() refreshFormat()
logBuffer?.log(TAG, DEBUG, logger?.d({ "onTimeZoneChanged newTimeZone=$str1" }) { str1 = timeZone?.toString() }
{ str1 = timeZone?.toString() },
{ "onTimeZoneChanged newTimeZone=$str1" }
)
} }
@SuppressLint("DrawAllocation") @SuppressLint("DrawAllocation")
@@ -191,7 +189,7 @@ class AnimatableClockView @JvmOverloads constructor(
} else { } else {
animator.updateLayout(layout) animator.updateLayout(layout)
} }
logBuffer?.log(TAG, DEBUG, "onMeasure") logger?.d("onMeasure")
} }
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {
@@ -203,12 +201,12 @@ class AnimatableClockView @JvmOverloads constructor(
} else { } else {
super.onDraw(canvas) super.onDraw(canvas)
} }
logBuffer?.log(TAG, DEBUG, "onDraw") logger?.d("onDraw")
} }
override fun invalidate() { override fun invalidate() {
super.invalidate() super.invalidate()
logBuffer?.log(TAG, DEBUG, "invalidate") logger?.d("invalidate")
} }
override fun onTextChanged( override fun onTextChanged(
@@ -218,10 +216,7 @@ class AnimatableClockView @JvmOverloads constructor(
lengthAfter: Int lengthAfter: Int
) { ) {
super.onTextChanged(text, start, lengthBefore, lengthAfter) super.onTextChanged(text, start, lengthBefore, lengthAfter)
logBuffer?.log(TAG, DEBUG, logger?.d({ "onTextChanged text=$str1" }) { str1 = text.toString() }
{ str1 = text.toString() },
{ "onTextChanged text=$str1" }
)
} }
fun setLineSpacingScale(scale: Float) { fun setLineSpacingScale(scale: Float) {
@@ -235,7 +230,7 @@ class AnimatableClockView @JvmOverloads constructor(
} }
fun animateColorChange() { fun animateColorChange() {
logBuffer?.log(TAG, DEBUG, "animateColorChange") logger?.d("animateColorChange")
setTextStyle( setTextStyle(
weight = lockScreenWeight, weight = lockScreenWeight,
textSize = -1f, textSize = -1f,
@@ -257,7 +252,7 @@ class AnimatableClockView @JvmOverloads constructor(
} }
fun animateAppearOnLockscreen() { fun animateAppearOnLockscreen() {
logBuffer?.log(TAG, DEBUG, "animateAppearOnLockscreen") logger?.d("animateAppearOnLockscreen")
setTextStyle( setTextStyle(
weight = dozingWeight, weight = dozingWeight,
textSize = -1f, textSize = -1f,
@@ -283,7 +278,7 @@ class AnimatableClockView @JvmOverloads constructor(
if (isAnimationEnabled && textAnimator == null) { if (isAnimationEnabled && textAnimator == null) {
return return
} }
logBuffer?.log(TAG, DEBUG, "animateFoldAppear") logger?.d("animateFoldAppear")
setTextStyle( setTextStyle(
weight = lockScreenWeightInternal, weight = lockScreenWeightInternal,
textSize = -1f, textSize = -1f,
@@ -310,7 +305,7 @@ class AnimatableClockView @JvmOverloads constructor(
// Skip charge animation if dozing animation is already playing. // Skip charge animation if dozing animation is already playing.
return return
} }
logBuffer?.log(TAG, DEBUG, "animateCharge") logger?.d("animateCharge")
val startAnimPhase2 = Runnable { val startAnimPhase2 = Runnable {
setTextStyle( setTextStyle(
weight = if (isDozing()) dozingWeight else lockScreenWeight, weight = if (isDozing()) dozingWeight else lockScreenWeight,
@@ -334,7 +329,7 @@ class AnimatableClockView @JvmOverloads constructor(
} }
fun animateDoze(isDozing: Boolean, animate: Boolean) { fun animateDoze(isDozing: Boolean, animate: Boolean) {
logBuffer?.log(TAG, DEBUG, "animateDoze") logger?.d("animateDoze")
setTextStyle( setTextStyle(
weight = if (isDozing) dozingWeight else lockScreenWeight, weight = if (isDozing) dozingWeight else lockScreenWeight,
textSize = -1f, textSize = -1f,
@@ -453,10 +448,7 @@ class AnimatableClockView @JvmOverloads constructor(
isSingleLineInternal && !use24HourFormat -> Patterns.sClockView12 isSingleLineInternal && !use24HourFormat -> Patterns.sClockView12
else -> DOUBLE_LINE_FORMAT_12_HOUR else -> DOUBLE_LINE_FORMAT_12_HOUR
} }
logBuffer?.log(TAG, DEBUG, logger?.d({ "refreshFormat format=$str1" }) { str1 = format?.toString() }
{ str1 = format?.toString() },
{ "refreshFormat format=$str1" }
)
descFormat = if (use24HourFormat) Patterns.sClockView24 else Patterns.sClockView12 descFormat = if (use24HourFormat) Patterns.sClockView24 else Patterns.sClockView12
refreshTime() refreshTime()

View File

@@ -23,10 +23,11 @@ import android.os.UserHandle
import android.provider.Settings import android.provider.Settings
import android.util.Log import android.util.Log
import androidx.annotation.OpenForTesting import androidx.annotation.OpenForTesting
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogMessageImpl import com.android.systemui.log.LogMessageImpl
import com.android.systemui.log.core.LogLevel import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.core.LogMessage import com.android.systemui.log.core.LogMessage
import com.android.systemui.log.core.Logger
import com.android.systemui.log.core.MessageBuffer
import com.android.systemui.log.core.MessageInitializer import com.android.systemui.log.core.MessageInitializer
import com.android.systemui.log.core.MessagePrinter import com.android.systemui.log.core.MessagePrinter
import com.android.systemui.plugins.ClockController import com.android.systemui.plugins.ClockController
@@ -75,7 +76,7 @@ private fun <TKey, TVal> ConcurrentHashMap<TKey, TVal>.concurrentGetOrPut(
private val TMP_MESSAGE: LogMessage by lazy { LogMessageImpl.Factory.create() } private val TMP_MESSAGE: LogMessage by lazy { LogMessageImpl.Factory.create() }
private inline fun LogBuffer?.tryLog( private inline fun Logger?.tryLog(
tag: String, tag: String,
level: LogLevel, level: LogLevel,
messageInitializer: MessageInitializer, messageInitializer: MessageInitializer,
@@ -84,7 +85,7 @@ private inline fun LogBuffer?.tryLog(
) { ) {
if (this != null) { if (this != null) {
// Wrap messagePrinter to convert it from crossinline to noinline // Wrap messagePrinter to convert it from crossinline to noinline
this.log(tag, level, messageInitializer, messagePrinter, ex) this.log(level, messagePrinter, ex, messageInitializer)
} else { } else {
messageInitializer(TMP_MESSAGE) messageInitializer(TMP_MESSAGE)
val msg = messagePrinter(TMP_MESSAGE) val msg = messagePrinter(TMP_MESSAGE)
@@ -110,7 +111,7 @@ open class ClockRegistry(
val handleAllUsers: Boolean, val handleAllUsers: Boolean,
defaultClockProvider: ClockProvider, defaultClockProvider: ClockProvider,
val fallbackClockId: ClockId = DEFAULT_CLOCK_ID, val fallbackClockId: ClockId = DEFAULT_CLOCK_ID,
val logBuffer: LogBuffer? = null, messageBuffer: MessageBuffer? = null,
val keepAllLoaded: Boolean, val keepAllLoaded: Boolean,
subTag: String, subTag: String,
var isTransitClockEnabled: Boolean = false, var isTransitClockEnabled: Boolean = false,
@@ -124,6 +125,7 @@ open class ClockRegistry(
fun onAvailableClocksChanged() {} fun onAvailableClocksChanged() {}
} }
private val logger: Logger? = if (messageBuffer != null) Logger(messageBuffer, TAG) else null
private val availableClocks = ConcurrentHashMap<ClockId, ClockInfo>() private val availableClocks = ConcurrentHashMap<ClockId, ClockInfo>()
private val clockChangeListeners = mutableListOf<ClockChangeListener>() private val clockChangeListeners = mutableListOf<ClockChangeListener>()
private val settingObserver = private val settingObserver =
@@ -150,7 +152,7 @@ open class ClockRegistry(
val knownClocks = KNOWN_PLUGINS.get(manager.getPackage()) val knownClocks = KNOWN_PLUGINS.get(manager.getPackage())
if (knownClocks == null) { if (knownClocks == null) {
logBuffer.tryLog( logger.tryLog(
TAG, TAG,
LogLevel.WARNING, LogLevel.WARNING,
{ str1 = manager.getPackage() }, { str1 = manager.getPackage() },
@@ -159,7 +161,7 @@ open class ClockRegistry(
return true return true
} }
logBuffer.tryLog( logger.tryLog(
TAG, TAG,
LogLevel.INFO, LogLevel.INFO,
{ str1 = manager.getPackage() }, { str1 = manager.getPackage() },
@@ -176,7 +178,7 @@ open class ClockRegistry(
} }
if (manager != info.manager) { if (manager != info.manager) {
logBuffer.tryLog( logger.tryLog(
TAG, TAG,
LogLevel.ERROR, LogLevel.ERROR,
{ str1 = id }, { str1 = id },
@@ -216,7 +218,7 @@ open class ClockRegistry(
} }
if (manager != info.manager) { if (manager != info.manager) {
logBuffer.tryLog( logger.tryLog(
TAG, TAG,
LogLevel.ERROR, LogLevel.ERROR,
{ str1 = id }, { str1 = id },
@@ -244,7 +246,7 @@ open class ClockRegistry(
val id = clock.clockId val id = clock.clockId
val info = availableClocks[id] val info = availableClocks[id]
if (info?.manager != manager) { if (info?.manager != manager) {
logBuffer.tryLog( logger.tryLog(
TAG, TAG,
LogLevel.ERROR, LogLevel.ERROR,
{ str1 = id }, { str1 = id },
@@ -319,7 +321,7 @@ open class ClockRegistry(
ClockSettings.deserialize(json) ClockSettings.deserialize(json)
} catch (ex: Exception) { } catch (ex: Exception) {
logBuffer.tryLog(TAG, LogLevel.ERROR, {}, { "Failed to parse clock settings" }, ex) logger.tryLog(TAG, LogLevel.ERROR, {}, { "Failed to parse clock settings" }, ex)
null null
} }
settings = result settings = result
@@ -348,7 +350,7 @@ open class ClockRegistry(
) )
} }
} catch (ex: Exception) { } catch (ex: Exception) {
logBuffer.tryLog(TAG, LogLevel.ERROR, {}, { "Failed to set clock settings" }, ex) logger.tryLog(TAG, LogLevel.ERROR, {}, { "Failed to set clock settings" }, ex)
} }
settings = value settings = value
} }
@@ -508,9 +510,9 @@ open class ClockRegistry(
} }
private fun onConnected(clockId: ClockId) { private fun onConnected(clockId: ClockId) {
logBuffer.tryLog(TAG, LogLevel.DEBUG, { str1 = clockId }, { "Connected $str1" }) logger.tryLog(TAG, LogLevel.DEBUG, { str1 = clockId }, { "Connected $str1" })
if (currentClockId == clockId) { if (currentClockId == clockId) {
logBuffer.tryLog( logger.tryLog(
TAG, TAG,
LogLevel.INFO, LogLevel.INFO,
{ str1 = clockId }, { str1 = clockId },
@@ -520,10 +522,10 @@ open class ClockRegistry(
} }
private fun onLoaded(clockId: ClockId) { private fun onLoaded(clockId: ClockId) {
logBuffer.tryLog(TAG, LogLevel.DEBUG, { str1 = clockId }, { "Loaded $str1" }) logger.tryLog(TAG, LogLevel.DEBUG, { str1 = clockId }, { "Loaded $str1" })
if (currentClockId == clockId) { if (currentClockId == clockId) {
logBuffer.tryLog( logger.tryLog(
TAG, TAG,
LogLevel.INFO, LogLevel.INFO,
{ str1 = clockId }, { str1 = clockId },
@@ -534,10 +536,10 @@ open class ClockRegistry(
} }
private fun onUnloaded(clockId: ClockId) { private fun onUnloaded(clockId: ClockId) {
logBuffer.tryLog(TAG, LogLevel.DEBUG, { str1 = clockId }, { "Unloaded $str1" }) logger.tryLog(TAG, LogLevel.DEBUG, { str1 = clockId }, { "Unloaded $str1" })
if (currentClockId == clockId) { if (currentClockId == clockId) {
logBuffer.tryLog( logger.tryLog(
TAG, TAG,
LogLevel.WARNING, LogLevel.WARNING,
{ str1 = clockId }, { str1 = clockId },
@@ -548,10 +550,10 @@ open class ClockRegistry(
} }
private fun onDisconnected(clockId: ClockId) { private fun onDisconnected(clockId: ClockId) {
logBuffer.tryLog(TAG, LogLevel.DEBUG, { str1 = clockId }, { "Disconnected $str1" }) logger.tryLog(TAG, LogLevel.DEBUG, { str1 = clockId }, { "Disconnected $str1" })
if (currentClockId == clockId) { if (currentClockId == clockId) {
logBuffer.tryLog( logger.tryLog(
TAG, TAG,
LogLevel.WARNING, LogLevel.WARNING,
{ str1 = clockId }, { str1 = clockId },
@@ -597,22 +599,17 @@ open class ClockRegistry(
if (isEnabled && clockId.isNotEmpty()) { if (isEnabled && clockId.isNotEmpty()) {
val clock = createClock(clockId) val clock = createClock(clockId)
if (clock != null) { if (clock != null) {
logBuffer.tryLog( logger.tryLog(TAG, LogLevel.INFO, { str1 = clockId }, { "Rendering clock $str1" })
TAG,
LogLevel.INFO,
{ str1 = clockId },
{ "Rendering clock $str1" }
)
return clock return clock
} else if (availableClocks.containsKey(clockId)) { } else if (availableClocks.containsKey(clockId)) {
logBuffer.tryLog( logger.tryLog(
TAG, TAG,
LogLevel.WARNING, LogLevel.WARNING,
{ str1 = clockId }, { str1 = clockId },
{ "Clock $str1 not loaded; using default" } { "Clock $str1 not loaded; using default" }
) )
} else { } else {
logBuffer.tryLog( logger.tryLog(
TAG, TAG,
LogLevel.ERROR, LogLevel.ERROR,
{ str1 = clockId }, { str1 = clockId },

View File

@@ -24,7 +24,7 @@ import android.view.View
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting
import com.android.systemui.customization.R import com.android.systemui.customization.R
import com.android.systemui.log.LogBuffer import com.android.systemui.log.core.MessageBuffer
import com.android.systemui.plugins.ClockAnimations import com.android.systemui.plugins.ClockAnimations
import com.android.systemui.plugins.ClockConfig import com.android.systemui.plugins.ClockConfig
import com.android.systemui.plugins.ClockController import com.android.systemui.plugins.ClockController
@@ -108,10 +108,10 @@ class DefaultClockController(
override val config = ClockFaceConfig() override val config = ClockFaceConfig()
override var logBuffer: LogBuffer? override var messageBuffer: MessageBuffer?
get() = view.logBuffer get() = view.messageBuffer
set(value) { set(value) {
view.logBuffer = value view.messageBuffer = value
} }
override var animations: DefaultClockAnimations = DefaultClockAnimations(view, 0f, 0f) override var animations: DefaultClockAnimations = DefaultClockAnimations(view, 0f, 0f)

View File

@@ -18,7 +18,7 @@ import android.graphics.Rect
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.view.View import android.view.View
import com.android.internal.annotations.Keep import com.android.internal.annotations.Keep
import com.android.systemui.log.LogBuffer import com.android.systemui.log.core.MessageBuffer
import com.android.systemui.plugins.annotations.ProvidesInterface import com.android.systemui.plugins.annotations.ProvidesInterface
import java.io.PrintWriter import java.io.PrintWriter
import java.util.Locale import java.util.Locale
@@ -95,7 +95,7 @@ interface ClockFaceController {
val animations: ClockAnimations val animations: ClockAnimations
/** Some clocks may log debug information */ /** Some clocks may log debug information */
var logBuffer: LogBuffer? var messageBuffer: MessageBuffer?
} }
/** Events that should call when various rendering parameters change */ /** Events that should call when various rendering parameters change */

View File

@@ -65,15 +65,7 @@
# The plugins, log & common subpackages act as shared libraries that might be referenced in # The plugins, log & common subpackages act as shared libraries that might be referenced in
# dynamically-loaded plugin APKs. # dynamically-loaded plugin APKs.
-keep class com.android.systemui.plugins.** { *; } -keep class com.android.systemui.plugins.** { *; }
-keep class com.android.systemui.log.ConstantStringsLoggerImpl { *; } -keep class com.android.systemui.log.core.** { *; }
-keep class com.android.systemui.log.ConstantStringsLogger { *; }
-keep class com.android.systemui.log.LogBuffer { *; }
-keep class com.android.systemui.log.LogcatEchoTrackerDebug { *; }
-keep class com.android.systemui.log.LogcatEchoTracker { *; }
-keep class com.android.systemui.log.LogcatEchoTrackerProd { *; }
-keep class com.android.systemui.log.LogLevel { *; }
-keep class com.android.systemui.log.LogMessageImpl { *; }
-keep class com.android.systemui.log.LogMessage { *; }
-keep class com.android.systemui.fragments.FragmentService$FragmentCreator { -keep class com.android.systemui.fragments.FragmentService$FragmentCreator {
*; *;
} }

View File

@@ -91,9 +91,9 @@ constructor(
field = value field = value
if (value != null) { if (value != null) {
smallLogBuffer?.log(TAG, DEBUG, {}, { "New Clock" }) smallLogBuffer?.log(TAG, DEBUG, {}, { "New Clock" })
value.smallClock.logBuffer = smallLogBuffer value.smallClock.messageBuffer = smallLogBuffer
largeLogBuffer?.log(TAG, DEBUG, {}, { "New Clock" }) largeLogBuffer?.log(TAG, DEBUG, {}, { "New Clock" })
value.largeClock.logBuffer = largeLogBuffer value.largeClock.messageBuffer = largeLogBuffer
value.initialize(resources, dozeAmount, 0f) value.initialize(resources, dozeAmount, 0f)