diff options
| author | 2023-06-02 12:30:34 +0200 | |
|---|---|---|
| committer | 2023-06-19 13:04:22 +0000 | |
| commit | 5bbaf1533a3e94e2a9de300457ad7fcec22aacec (patch) | |
| tree | 231889fabede92b7760a6f39db8574a8626e9a0e | |
| parent | e0abf2628f5593402c33c7d0fd5dd485ac161f9a (diff) | |
Add LogBuffer to SystemStatusAnimationScheduler
Bug: 285556960
Test: Manual, i.e. running adb bugreport and checking logs
Change-Id: I7ce7c9858a4acc39845f7f1083eb3995a9533e94
5 files changed, 146 insertions, 25 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/events/StatusBarEventsModule.kt b/packages/SystemUI/src/com/android/systemui/statusbar/events/StatusBarEventsModule.kt index 3d6d48917dd3..84796f9acbc0 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/events/StatusBarEventsModule.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/events/StatusBarEventsModule.kt @@ -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 @@ -36,6 +38,13 @@ interface StatusBarEventsModule { @Provides @SysUISingleton + @SystemStatusAnimationSchedulerLog + fun provideSystemStatusAnimationSchedulerLogBuffer(factory: LogBufferFactory): LogBuffer { + return factory.create("SystemStatusAnimationSchedulerLog", 60) + } + + @Provides + @SysUISingleton fun provideSystemStatusAnimationScheduler( featureFlags: FeatureFlags, coordinator: SystemEventCoordinator, @@ -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( diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImpl.kt index 56ea703668d0..6fc715a2b578 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImpl.kt @@ -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" diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerLog.kt b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerLog.kt new file mode 100644 index 000000000000..4ac94a60d4c6 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerLog.kt @@ -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 diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerLogger.kt new file mode 100644 index 000000000000..29de4d8d3919 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerLogger.kt @@ -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" diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImplTest.kt index 914301f2e830..2af0cebf3519 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImplTest.kt @@ -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) |