Merge "Refactor Clocks to use MessageBuffer + Logger" into udc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
aaff159b06
@@ -33,8 +33,8 @@ import com.android.internal.annotations.VisibleForTesting
|
||||
import com.android.systemui.animation.GlyphCallback
|
||||
import com.android.systemui.animation.TextAnimator
|
||||
import com.android.systemui.customization.R
|
||||
import com.android.systemui.log.LogBuffer
|
||||
import com.android.systemui.log.core.LogLevel.DEBUG
|
||||
import com.android.systemui.log.core.Logger
|
||||
import com.android.systemui.log.core.MessageBuffer
|
||||
import java.io.PrintWriter
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
@@ -51,7 +51,12 @@ class AnimatableClockView @JvmOverloads constructor(
|
||||
defStyleAttr: Int = 0,
|
||||
defStyleRes: Int = 0
|
||||
) : 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()
|
||||
|
||||
@@ -129,7 +134,7 @@ class AnimatableClockView @JvmOverloads constructor(
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
logBuffer?.log(TAG, DEBUG, "onAttachedToWindow")
|
||||
logger?.d("onAttachedToWindow")
|
||||
refreshFormat()
|
||||
}
|
||||
|
||||
@@ -145,39 +150,32 @@ class AnimatableClockView @JvmOverloads constructor(
|
||||
time.timeInMillis = timeOverrideInMillis ?: System.currentTimeMillis()
|
||||
contentDescription = DateFormat.format(descFormat, time)
|
||||
val formattedText = DateFormat.format(format, time)
|
||||
logBuffer?.log(TAG, DEBUG,
|
||||
{ str1 = formattedText?.toString() },
|
||||
{ "refreshTime: new formattedText=$str1" }
|
||||
)
|
||||
logger?.d({ "refreshTime: new formattedText=$str1" }) { str1 = formattedText?.toString() }
|
||||
// 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
|
||||
// relayout if the text didn't actually change.
|
||||
if (!TextUtils.equals(text, formattedText)) {
|
||||
text = formattedText
|
||||
logBuffer?.log(TAG, DEBUG,
|
||||
{ str1 = formattedText?.toString() },
|
||||
{ "refreshTime: done setting new time text to: $str1" }
|
||||
)
|
||||
logger?.d({ "refreshTime: done setting new time text to: $str1" }) {
|
||||
str1 = formattedText?.toString()
|
||||
}
|
||||
// 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
|
||||
// crash will occur on the next invocation of setTextStyle if the layout is mutated
|
||||
// without being notified TextInterpolator being notified.
|
||||
if (layout != null) {
|
||||
textAnimator?.updateLayout(layout)
|
||||
logBuffer?.log(TAG, DEBUG, "refreshTime: done updating textAnimator layout")
|
||||
logger?.d("refreshTime: done updating textAnimator layout")
|
||||
}
|
||||
requestLayout()
|
||||
logBuffer?.log(TAG, DEBUG, "refreshTime: after requestLayout")
|
||||
logger?.d("refreshTime: after requestLayout")
|
||||
}
|
||||
}
|
||||
|
||||
fun onTimeZoneChanged(timeZone: TimeZone?) {
|
||||
time.timeZone = timeZone
|
||||
refreshFormat()
|
||||
logBuffer?.log(TAG, DEBUG,
|
||||
{ str1 = timeZone?.toString() },
|
||||
{ "onTimeZoneChanged newTimeZone=$str1" }
|
||||
)
|
||||
logger?.d({ "onTimeZoneChanged newTimeZone=$str1" }) { str1 = timeZone?.toString() }
|
||||
}
|
||||
|
||||
@SuppressLint("DrawAllocation")
|
||||
@@ -191,7 +189,7 @@ class AnimatableClockView @JvmOverloads constructor(
|
||||
} else {
|
||||
animator.updateLayout(layout)
|
||||
}
|
||||
logBuffer?.log(TAG, DEBUG, "onMeasure")
|
||||
logger?.d("onMeasure")
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
@@ -203,12 +201,12 @@ class AnimatableClockView @JvmOverloads constructor(
|
||||
} else {
|
||||
super.onDraw(canvas)
|
||||
}
|
||||
logBuffer?.log(TAG, DEBUG, "onDraw")
|
||||
logger?.d("onDraw")
|
||||
}
|
||||
|
||||
override fun invalidate() {
|
||||
super.invalidate()
|
||||
logBuffer?.log(TAG, DEBUG, "invalidate")
|
||||
logger?.d("invalidate")
|
||||
}
|
||||
|
||||
override fun onTextChanged(
|
||||
@@ -218,10 +216,7 @@ class AnimatableClockView @JvmOverloads constructor(
|
||||
lengthAfter: Int
|
||||
) {
|
||||
super.onTextChanged(text, start, lengthBefore, lengthAfter)
|
||||
logBuffer?.log(TAG, DEBUG,
|
||||
{ str1 = text.toString() },
|
||||
{ "onTextChanged text=$str1" }
|
||||
)
|
||||
logger?.d({ "onTextChanged text=$str1" }) { str1 = text.toString() }
|
||||
}
|
||||
|
||||
fun setLineSpacingScale(scale: Float) {
|
||||
@@ -235,7 +230,7 @@ class AnimatableClockView @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
fun animateColorChange() {
|
||||
logBuffer?.log(TAG, DEBUG, "animateColorChange")
|
||||
logger?.d("animateColorChange")
|
||||
setTextStyle(
|
||||
weight = lockScreenWeight,
|
||||
textSize = -1f,
|
||||
@@ -257,7 +252,7 @@ class AnimatableClockView @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
fun animateAppearOnLockscreen() {
|
||||
logBuffer?.log(TAG, DEBUG, "animateAppearOnLockscreen")
|
||||
logger?.d("animateAppearOnLockscreen")
|
||||
setTextStyle(
|
||||
weight = dozingWeight,
|
||||
textSize = -1f,
|
||||
@@ -283,7 +278,7 @@ class AnimatableClockView @JvmOverloads constructor(
|
||||
if (isAnimationEnabled && textAnimator == null) {
|
||||
return
|
||||
}
|
||||
logBuffer?.log(TAG, DEBUG, "animateFoldAppear")
|
||||
logger?.d("animateFoldAppear")
|
||||
setTextStyle(
|
||||
weight = lockScreenWeightInternal,
|
||||
textSize = -1f,
|
||||
@@ -310,7 +305,7 @@ class AnimatableClockView @JvmOverloads constructor(
|
||||
// Skip charge animation if dozing animation is already playing.
|
||||
return
|
||||
}
|
||||
logBuffer?.log(TAG, DEBUG, "animateCharge")
|
||||
logger?.d("animateCharge")
|
||||
val startAnimPhase2 = Runnable {
|
||||
setTextStyle(
|
||||
weight = if (isDozing()) dozingWeight else lockScreenWeight,
|
||||
@@ -334,7 +329,7 @@ class AnimatableClockView @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
fun animateDoze(isDozing: Boolean, animate: Boolean) {
|
||||
logBuffer?.log(TAG, DEBUG, "animateDoze")
|
||||
logger?.d("animateDoze")
|
||||
setTextStyle(
|
||||
weight = if (isDozing) dozingWeight else lockScreenWeight,
|
||||
textSize = -1f,
|
||||
@@ -453,10 +448,7 @@ class AnimatableClockView @JvmOverloads constructor(
|
||||
isSingleLineInternal && !use24HourFormat -> Patterns.sClockView12
|
||||
else -> DOUBLE_LINE_FORMAT_12_HOUR
|
||||
}
|
||||
logBuffer?.log(TAG, DEBUG,
|
||||
{ str1 = format?.toString() },
|
||||
{ "refreshFormat format=$str1" }
|
||||
)
|
||||
logger?.d({ "refreshFormat format=$str1" }) { str1 = format?.toString() }
|
||||
|
||||
descFormat = if (use24HourFormat) Patterns.sClockView24 else Patterns.sClockView12
|
||||
refreshTime()
|
||||
|
||||
@@ -23,10 +23,11 @@ import android.os.UserHandle
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import androidx.annotation.OpenForTesting
|
||||
import com.android.systemui.log.LogBuffer
|
||||
import com.android.systemui.log.LogMessageImpl
|
||||
import com.android.systemui.log.core.LogLevel
|
||||
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.MessagePrinter
|
||||
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 inline fun LogBuffer?.tryLog(
|
||||
private inline fun Logger?.tryLog(
|
||||
tag: String,
|
||||
level: LogLevel,
|
||||
messageInitializer: MessageInitializer,
|
||||
@@ -84,7 +85,7 @@ private inline fun LogBuffer?.tryLog(
|
||||
) {
|
||||
if (this != null) {
|
||||
// Wrap messagePrinter to convert it from crossinline to noinline
|
||||
this.log(tag, level, messageInitializer, messagePrinter, ex)
|
||||
this.log(level, messagePrinter, ex, messageInitializer)
|
||||
} else {
|
||||
messageInitializer(TMP_MESSAGE)
|
||||
val msg = messagePrinter(TMP_MESSAGE)
|
||||
@@ -110,7 +111,7 @@ open class ClockRegistry(
|
||||
val handleAllUsers: Boolean,
|
||||
defaultClockProvider: ClockProvider,
|
||||
val fallbackClockId: ClockId = DEFAULT_CLOCK_ID,
|
||||
val logBuffer: LogBuffer? = null,
|
||||
messageBuffer: MessageBuffer? = null,
|
||||
val keepAllLoaded: Boolean,
|
||||
subTag: String,
|
||||
var isTransitClockEnabled: Boolean = false,
|
||||
@@ -124,6 +125,7 @@ open class ClockRegistry(
|
||||
fun onAvailableClocksChanged() {}
|
||||
}
|
||||
|
||||
private val logger: Logger? = if (messageBuffer != null) Logger(messageBuffer, TAG) else null
|
||||
private val availableClocks = ConcurrentHashMap<ClockId, ClockInfo>()
|
||||
private val clockChangeListeners = mutableListOf<ClockChangeListener>()
|
||||
private val settingObserver =
|
||||
@@ -150,7 +152,7 @@ open class ClockRegistry(
|
||||
|
||||
val knownClocks = KNOWN_PLUGINS.get(manager.getPackage())
|
||||
if (knownClocks == null) {
|
||||
logBuffer.tryLog(
|
||||
logger.tryLog(
|
||||
TAG,
|
||||
LogLevel.WARNING,
|
||||
{ str1 = manager.getPackage() },
|
||||
@@ -159,7 +161,7 @@ open class ClockRegistry(
|
||||
return true
|
||||
}
|
||||
|
||||
logBuffer.tryLog(
|
||||
logger.tryLog(
|
||||
TAG,
|
||||
LogLevel.INFO,
|
||||
{ str1 = manager.getPackage() },
|
||||
@@ -176,7 +178,7 @@ open class ClockRegistry(
|
||||
}
|
||||
|
||||
if (manager != info.manager) {
|
||||
logBuffer.tryLog(
|
||||
logger.tryLog(
|
||||
TAG,
|
||||
LogLevel.ERROR,
|
||||
{ str1 = id },
|
||||
@@ -216,7 +218,7 @@ open class ClockRegistry(
|
||||
}
|
||||
|
||||
if (manager != info.manager) {
|
||||
logBuffer.tryLog(
|
||||
logger.tryLog(
|
||||
TAG,
|
||||
LogLevel.ERROR,
|
||||
{ str1 = id },
|
||||
@@ -244,7 +246,7 @@ open class ClockRegistry(
|
||||
val id = clock.clockId
|
||||
val info = availableClocks[id]
|
||||
if (info?.manager != manager) {
|
||||
logBuffer.tryLog(
|
||||
logger.tryLog(
|
||||
TAG,
|
||||
LogLevel.ERROR,
|
||||
{ str1 = id },
|
||||
@@ -319,7 +321,7 @@ open class ClockRegistry(
|
||||
|
||||
ClockSettings.deserialize(json)
|
||||
} 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
|
||||
}
|
||||
settings = result
|
||||
@@ -348,7 +350,7 @@ open class ClockRegistry(
|
||||
)
|
||||
}
|
||||
} 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
|
||||
}
|
||||
@@ -508,9 +510,9 @@ open class ClockRegistry(
|
||||
}
|
||||
|
||||
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) {
|
||||
logBuffer.tryLog(
|
||||
logger.tryLog(
|
||||
TAG,
|
||||
LogLevel.INFO,
|
||||
{ str1 = clockId },
|
||||
@@ -520,10 +522,10 @@ open class ClockRegistry(
|
||||
}
|
||||
|
||||
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) {
|
||||
logBuffer.tryLog(
|
||||
logger.tryLog(
|
||||
TAG,
|
||||
LogLevel.INFO,
|
||||
{ str1 = clockId },
|
||||
@@ -534,10 +536,10 @@ open class ClockRegistry(
|
||||
}
|
||||
|
||||
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) {
|
||||
logBuffer.tryLog(
|
||||
logger.tryLog(
|
||||
TAG,
|
||||
LogLevel.WARNING,
|
||||
{ str1 = clockId },
|
||||
@@ -548,10 +550,10 @@ open class ClockRegistry(
|
||||
}
|
||||
|
||||
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) {
|
||||
logBuffer.tryLog(
|
||||
logger.tryLog(
|
||||
TAG,
|
||||
LogLevel.WARNING,
|
||||
{ str1 = clockId },
|
||||
@@ -597,22 +599,17 @@ open class ClockRegistry(
|
||||
if (isEnabled && clockId.isNotEmpty()) {
|
||||
val clock = createClock(clockId)
|
||||
if (clock != null) {
|
||||
logBuffer.tryLog(
|
||||
TAG,
|
||||
LogLevel.INFO,
|
||||
{ str1 = clockId },
|
||||
{ "Rendering clock $str1" }
|
||||
)
|
||||
logger.tryLog(TAG, LogLevel.INFO, { str1 = clockId }, { "Rendering clock $str1" })
|
||||
return clock
|
||||
} else if (availableClocks.containsKey(clockId)) {
|
||||
logBuffer.tryLog(
|
||||
logger.tryLog(
|
||||
TAG,
|
||||
LogLevel.WARNING,
|
||||
{ str1 = clockId },
|
||||
{ "Clock $str1 not loaded; using default" }
|
||||
)
|
||||
} else {
|
||||
logBuffer.tryLog(
|
||||
logger.tryLog(
|
||||
TAG,
|
||||
LogLevel.ERROR,
|
||||
{ str1 = clockId },
|
||||
|
||||
@@ -24,7 +24,7 @@ import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import androidx.annotation.VisibleForTesting
|
||||
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.ClockConfig
|
||||
import com.android.systemui.plugins.ClockController
|
||||
@@ -108,10 +108,10 @@ class DefaultClockController(
|
||||
|
||||
override val config = ClockFaceConfig()
|
||||
|
||||
override var logBuffer: LogBuffer?
|
||||
get() = view.logBuffer
|
||||
override var messageBuffer: MessageBuffer?
|
||||
get() = view.messageBuffer
|
||||
set(value) {
|
||||
view.logBuffer = value
|
||||
view.messageBuffer = value
|
||||
}
|
||||
|
||||
override var animations: DefaultClockAnimations = DefaultClockAnimations(view, 0f, 0f)
|
||||
|
||||
@@ -18,7 +18,7 @@ import android.graphics.Rect
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.View
|
||||
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 java.io.PrintWriter
|
||||
import java.util.Locale
|
||||
@@ -95,7 +95,7 @@ interface ClockFaceController {
|
||||
val animations: ClockAnimations
|
||||
|
||||
/** Some clocks may log debug information */
|
||||
var logBuffer: LogBuffer?
|
||||
var messageBuffer: MessageBuffer?
|
||||
}
|
||||
|
||||
/** Events that should call when various rendering parameters change */
|
||||
|
||||
@@ -65,15 +65,7 @@
|
||||
# The plugins, log & common subpackages act as shared libraries that might be referenced in
|
||||
# dynamically-loaded plugin APKs.
|
||||
-keep class com.android.systemui.plugins.** { *; }
|
||||
-keep class com.android.systemui.log.ConstantStringsLoggerImpl { *; }
|
||||
-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.log.core.** { *; }
|
||||
-keep class com.android.systemui.fragments.FragmentService$FragmentCreator {
|
||||
*;
|
||||
}
|
||||
|
||||
@@ -91,9 +91,9 @@ constructor(
|
||||
field = value
|
||||
if (value != null) {
|
||||
smallLogBuffer?.log(TAG, DEBUG, {}, { "New Clock" })
|
||||
value.smallClock.logBuffer = smallLogBuffer
|
||||
value.smallClock.messageBuffer = smallLogBuffer
|
||||
largeLogBuffer?.log(TAG, DEBUG, {}, { "New Clock" })
|
||||
value.largeClock.logBuffer = largeLogBuffer
|
||||
value.largeClock.messageBuffer = largeLogBuffer
|
||||
|
||||
value.initialize(resources, dozeAmount, 0f)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user