Merge "Add LogBuffer to SystemStatusAnimationScheduler" into udc-qpr-dev am: b1aa946049
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23727651
Change-Id: I85e3a8ce9614ec2c24183fd82ed80050a30f571c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
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 3d6d489..84796f9 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.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 @@
@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 @@
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 @@
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 56ea703..6fc715a 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 @@
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 @@
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 @@
}
}
}
+
+ coroutineScope.launch {
+ animationState.collect { logger?.logAnimationStateUpdate(it) }
+ }
}
@SystemAnimationState override fun getAnimationState(): Int = animationState.value
@@ -140,32 +144,17 @@
) {
// 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 @@
}
private fun notifyTransitionToPersistentDot(): Animator? {
+ logger?.logTransitionToPersistentDotCallbackInvoked()
val anims: List<Animator> =
listeners.mapNotNull {
it.onSystemStatusAnimationTransitionToPersistentDot(
@@ -373,6 +363,7 @@
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 @@
}
}
-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 0000000..4ac94a6
--- /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 0000000..29de4d8
--- /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 914301f..2af0ceb 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 @@
@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 @@
statusBarWindowController,
dumpManager,
systemClock,
- CoroutineScope(StandardTestDispatcher(testScope.testScheduler))
+ CoroutineScope(StandardTestDispatcher(testScope.testScheduler)),
+ logger
)
// add a mock listener
systemStatusAnimationScheduler.addCallback(listener)