Add LogBuffer to SystemStatusAnimationScheduler

Bug: 285556960
Test: Manual, i.e. running adb bugreport and checking logs
Change-Id: I7ce7c9858a4acc39845f7f1083eb3995a9533e94
This commit is contained in:
Johannes Gallmann
2023-06-02 12:30:34 +02:00
parent e0abf2628f
commit 5bbaf1533a
5 changed files with 146 additions and 25 deletions

View File

@@ -22,6 +22,8 @@ import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.dump.DumpManager
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogBufferFactory
import com.android.systemui.statusbar.window.StatusBarWindowController
import com.android.systemui.util.concurrency.DelayableExecutor
import com.android.systemui.util.time.SystemClock
@@ -34,6 +36,13 @@ interface StatusBarEventsModule {
companion object {
@Provides
@SysUISingleton
@SystemStatusAnimationSchedulerLog
fun provideSystemStatusAnimationSchedulerLogBuffer(factory: LogBufferFactory): LogBuffer {
return factory.create("SystemStatusAnimationSchedulerLog", 60)
}
@Provides
@SysUISingleton
fun provideSystemStatusAnimationScheduler(
@@ -44,7 +53,8 @@ interface StatusBarEventsModule {
dumpManager: DumpManager,
systemClock: SystemClock,
@Application coroutineScope: CoroutineScope,
@Main executor: DelayableExecutor
@Main executor: DelayableExecutor,
logger: SystemStatusAnimationSchedulerLogger
): SystemStatusAnimationScheduler {
return if (featureFlags.isEnabled(Flags.PLUG_IN_STATUS_BAR_CHIP)) {
SystemStatusAnimationSchedulerImpl(
@@ -53,7 +63,8 @@ interface StatusBarEventsModule {
statusBarWindowController,
dumpManager,
systemClock,
coroutineScope
coroutineScope,
logger
)
} else {
SystemStatusAnimationSchedulerLegacyImpl(

View File

@@ -18,7 +18,6 @@ package com.android.systemui.statusbar.events
import android.os.Process
import android.provider.DeviceConfig
import android.util.Log
import androidx.core.animation.Animator
import androidx.core.animation.AnimatorListenerAdapter
import androidx.core.animation.AnimatorSet
@@ -69,7 +68,8 @@ constructor(
private val statusBarWindowController: StatusBarWindowController,
dumpManager: DumpManager,
private val systemClock: SystemClock,
@Application private val coroutineScope: CoroutineScope
@Application private val coroutineScope: CoroutineScope,
private val logger: SystemStatusAnimationSchedulerLogger?
) : SystemStatusAnimationScheduler {
companion object {
@@ -121,6 +121,10 @@ constructor(
}
}
}
coroutineScope.launch {
animationState.collect { logger?.logAnimationStateUpdate(it) }
}
}
@SystemAnimationState override fun getAnimationState(): Int = animationState.value
@@ -140,32 +144,17 @@ constructor(
) {
// a event can only be scheduled if no other event is in progress or it has a higher
// priority. If a persistent dot is currently displayed, don't schedule the event.
if (DEBUG) {
Log.d(TAG, "scheduling event $event")
}
logger?.logScheduleEvent(event)
scheduleEvent(event)
} else if (currentlyDisplayedEvent?.shouldUpdateFromEvent(event) == true) {
if (DEBUG) {
Log.d(
TAG,
"updating current event from: $event. animationState=${animationState.value}"
)
}
logger?.logUpdateEvent(event, animationState.value)
currentlyDisplayedEvent?.updateFromEvent(event)
if (event.forceVisible) hasPersistentDot = true
} else if (scheduledEvent.value?.shouldUpdateFromEvent(event) == true) {
if (DEBUG) {
Log.d(
TAG,
"updating scheduled event from: $event. animationState=${animationState.value}"
)
}
logger?.logUpdateEvent(event, animationState.value)
scheduledEvent.value?.updateFromEvent(event)
} else {
if (DEBUG) {
Log.d(TAG, "ignoring event $event")
}
logger?.logIgnoreEvent(event)
}
}
@@ -356,6 +345,7 @@ constructor(
}
private fun notifyTransitionToPersistentDot(): Animator? {
logger?.logTransitionToPersistentDotCallbackInvoked()
val anims: List<Animator> =
listeners.mapNotNull {
it.onSystemStatusAnimationTransitionToPersistentDot(
@@ -373,6 +363,7 @@ constructor(
private fun notifyHidePersistentDot(): Animator? {
Assert.isMainThread()
logger?.logHidePersistentDotCallbackInvoked()
val anims: List<Animator> = listeners.mapNotNull { it.onHidePersistentDot() }
if (animationState.value == SHOWING_PERSISTENT_DOT) {
@@ -424,5 +415,4 @@ constructor(
}
}
private const val DEBUG = false
private const val TAG = "SystemStatusAnimationSchedulerImpl"

View File

@@ -0,0 +1,25 @@
/*
* 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.statusbar.events
import javax.inject.Qualifier
/** Logs for the SystemStatusAnimationScheduler. */
@Qualifier
@MustBeDocumented
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME)
annotation class SystemStatusAnimationSchedulerLog

View File

@@ -0,0 +1,92 @@
package com.android.systemui.statusbar.events
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogLevel
import javax.inject.Inject
/** Logs for the SystemStatusAnimationScheduler. */
@SysUISingleton
class SystemStatusAnimationSchedulerLogger
@Inject
constructor(
@SystemStatusAnimationSchedulerLog private val logBuffer: LogBuffer,
) {
fun logScheduleEvent(event: StatusEvent) {
logBuffer.log(
TAG,
LogLevel.DEBUG,
{
str1 = event.javaClass.simpleName
int1 = event.priority
bool1 = event.forceVisible
bool2 = event.showAnimation
},
{ "Scheduling event: $str1(forceVisible=$bool1, priority=$int1, showAnimation=$bool2)" }
)
}
fun logUpdateEvent(event: StatusEvent, @SystemAnimationState animationState: Int) {
logBuffer.log(
TAG,
LogLevel.DEBUG,
{
str1 = event.javaClass.simpleName
int1 = event.priority
bool1 = event.forceVisible
bool2 = event.showAnimation
int2 = animationState
},
{
"Updating current event from: $str1(forceVisible=$bool1, priority=$int1, " +
"showAnimation=$bool2), animationState=${animationState.name()}"
}
)
}
fun logIgnoreEvent(event: StatusEvent) {
logBuffer.log(
TAG,
LogLevel.DEBUG,
{
str1 = event.javaClass.simpleName
int1 = event.priority
bool1 = event.forceVisible
bool2 = event.showAnimation
},
{ "Ignore event: $str1(forceVisible=$bool1, priority=$int1, showAnimation=$bool2)" }
)
}
fun logHidePersistentDotCallbackInvoked() {
logBuffer.log(TAG, LogLevel.DEBUG, "Hide persistent dot callback invoked")
}
fun logTransitionToPersistentDotCallbackInvoked() {
logBuffer.log(TAG, LogLevel.DEBUG, "Transition to persistent dot callback invoked")
}
fun logAnimationStateUpdate(@SystemAnimationState animationState: Int) {
logBuffer.log(
TAG,
LogLevel.DEBUG,
{ int1 = animationState },
{ "AnimationState update: ${int1.name()}" }
)
animationState.name()
}
private fun @receiver:SystemAnimationState Int.name() =
when (this) {
IDLE -> "IDLE"
ANIMATION_QUEUED -> "ANIMATION_QUEUED"
ANIMATING_IN -> "ANIMATING_IN"
RUNNING_CHIP_ANIM -> "RUNNING_CHIP_ANIM"
ANIMATING_OUT -> "ANIMATING_OUT"
SHOWING_PERSISTENT_DOT -> "SHOWING_PERSISTENT_DOT"
else -> "UNKNOWN_ANIMATION_STATE"
}
}
private const val TAG = "SystemStatusAnimationSchedulerLog"

View File

@@ -69,6 +69,8 @@ class SystemStatusAnimationSchedulerImplTest : SysuiTestCase() {
@Mock private lateinit var listener: SystemStatusAnimationCallback
@Mock private lateinit var logger: SystemStatusAnimationSchedulerLogger
private lateinit var systemClock: FakeSystemClock
private lateinit var chipAnimationController: SystemEventChipAnimationController
private lateinit var systemStatusAnimationScheduler: SystemStatusAnimationScheduler
@@ -538,7 +540,8 @@ class SystemStatusAnimationSchedulerImplTest : SysuiTestCase() {
statusBarWindowController,
dumpManager,
systemClock,
CoroutineScope(StandardTestDispatcher(testScope.testScheduler))
CoroutineScope(StandardTestDispatcher(testScope.testScheduler)),
logger
)
// add a mock listener
systemStatusAnimationScheduler.addCallback(listener)