From f1ea23510ad8b8b5b614cca4980c1335a1eb4d39 Mon Sep 17 00:00:00 2001 From: Beth Thibodeau Date: Tue, 19 Apr 2022 01:38:53 +0000 Subject: [PATCH] Add debug logging for media view events Test: manual; verify present in bugreport Bug: 198319256 Change-Id: I416d532758cc280a6ea05f45bccdb3dcd81abe34 --- .../systemui/log/dagger/LogModule.java | 11 +++- .../systemui/log/dagger/MediaViewLog.java | 35 +++++++++++ .../systemui/media/MediaViewController.kt | 9 ++- .../android/systemui/media/MediaViewLogger.kt | 63 +++++++++++++++++++ .../systemui/media/MediaViewControllerTest.kt | 15 ++++- 5 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 packages/SystemUI/src/com/android/systemui/log/dagger/MediaViewLog.java create mode 100644 packages/SystemUI/src/com/android/systemui/media/MediaViewLogger.kt diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java index 79ac9e8b09867..39f00f45aac2b 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java @@ -176,7 +176,6 @@ public class LogModule { return factory.create("MediaTttReceiver", 20); } - /** * Provides a logging buffer for logs related to the media mute-await connections. See * {@link com.android.systemui.media.muteawait.MediaMuteAwaitConnectionManager}. @@ -199,6 +198,16 @@ public class LogModule { return factory.create("NearbyMediaDevicesLog", 20); } + /** + * Provides a buffer for logs related to media view events + */ + @Provides + @SysUISingleton + @MediaViewLog + public static LogBuffer provideMediaViewLogBuffer(LogBufferFactory factory) { + return factory.create("MediaView", 100); + } + /** Allows logging buffers to be tweaked via adb on debug builds but not on prod builds. */ @Provides @SysUISingleton diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaViewLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaViewLog.java new file mode 100644 index 0000000000000..75a34fc22c3c1 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaViewLog.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2022 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.log.dagger; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import com.android.systemui.log.LogBuffer; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; + +import javax.inject.Qualifier; + +/** + * A {@link LogBuffer} for {@link com.android.systemui.media.MediaViewLogger} + */ +@Qualifier +@Documented +@Retention(RUNTIME) +public @interface MediaViewLog { +} diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaViewController.kt b/packages/SystemUI/src/com/android/systemui/media/MediaViewController.kt index 5210499ca3119..327268bcbd475 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaViewController.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaViewController.kt @@ -35,7 +35,8 @@ import javax.inject.Inject class MediaViewController @Inject constructor( private val context: Context, private val configurationController: ConfigurationController, - private val mediaHostStatesManager: MediaHostStatesManager + private val mediaHostStatesManager: MediaHostStatesManager, + private val logger: MediaViewLogger ) { /** @@ -330,6 +331,7 @@ class MediaViewController @Inject constructor( // is cheap setGutsViewState(result) viewStates[cacheKey] = result + logger.logMediaSize("measured new viewState", result.width, result.height) } else { // This is an interpolated state val startState = state.copy().also { it.expansion = 0.0f } @@ -344,6 +346,7 @@ class MediaViewController @Inject constructor( startViewState, endViewState, state.expansion) + logger.logMediaSize("interpolated viewState", result.width, result.height) } if (state.squishFraction < 1f) { return squishViewState(result, state.squishFraction) @@ -371,6 +374,7 @@ class MediaViewController @Inject constructor( */ fun attach(transitionLayout: TransitionLayout, type: TYPE) { updateMediaViewControllerType(type) + logger.logMediaLocation("attach", currentStartLocation, currentEndLocation) this.transitionLayout = transitionLayout layoutController.attach(transitionLayout) if (currentEndLocation == -1) { @@ -409,6 +413,7 @@ class MediaViewController @Inject constructor( currentEndLocation = endLocation currentStartLocation = startLocation currentTransitionProgress = transitionProgress + logger.logMediaLocation("setCurrentState", startLocation, endLocation) val shouldAnimate = animateNextStateChange && !applyImmediately @@ -461,6 +466,7 @@ class MediaViewController @Inject constructor( result = layoutController.getInterpolatedState(startViewState, endViewState, transitionProgress, tmpState) } + logger.logMediaSize("setCurrentState", result.width, result.height) layoutController.setState(result, applyImmediately, shouldAnimate, animationDuration, animationDelay) } @@ -478,6 +484,7 @@ class MediaViewController @Inject constructor( result.height = Math.max(it.measuredHeight, result.height) result.width = Math.max(it.measuredWidth, result.width) } + logger.logMediaSize("update to carousel", result.width, result.height) return result } diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaViewLogger.kt b/packages/SystemUI/src/com/android/systemui/media/MediaViewLogger.kt new file mode 100644 index 0000000000000..73868189b362d --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/media/MediaViewLogger.kt @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2022 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.media + +import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.log.LogBuffer +import com.android.systemui.log.LogLevel +import com.android.systemui.log.dagger.MediaViewLog +import javax.inject.Inject + +private const val TAG = "MediaView" + +/** + * A buffered log for media view events that are too noisy for regular logging + */ +@SysUISingleton +class MediaViewLogger @Inject constructor( + @MediaViewLog private val buffer: LogBuffer +) { + fun logMediaSize(reason: String, width: Int, height: Int) { + buffer.log( + TAG, + LogLevel.DEBUG, + { + str1 = reason + int1 = width + int2 = height + }, + { + "size ($str1): $int1 x $int2" + } + ) + } + + fun logMediaLocation(reason: String, startLocation: Int, endLocation: Int) { + buffer.log( + TAG, + LogLevel.DEBUG, + { + str1 = reason + int1 = startLocation + int2 = endLocation + }, + { + "location ($str1): $int1 -> $int2" + } + ) + } +} \ No newline at end of file diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/MediaViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/MediaViewControllerTest.kt index b7d5ba170e6d6..604e1f3ac9eb4 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/MediaViewControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/MediaViewControllerTest.kt @@ -12,6 +12,8 @@ import junit.framework.Assert.assertTrue import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.MockitoAnnotations /** * Tests for {@link MediaViewController}. @@ -20,16 +22,25 @@ import org.junit.runner.RunWith @RunWith(AndroidTestingRunner::class) @TestableLooper.RunWithLooper class MediaViewControllerTest : SysuiTestCase() { + @Mock + private lateinit var logger: MediaViewLogger + private val configurationController = com.android.systemui.statusbar.phone.ConfigurationControllerImpl(context) private val mediaHostStatesManager = MediaHostStatesManager() - private val mediaViewController = - MediaViewController(context, configurationController, mediaHostStatesManager) + private lateinit var mediaViewController: MediaViewController private val mediaHostStateHolder = MediaHost.MediaHostStateHolder() private var transitionLayout = TransitionLayout(context, /* attrs */ null, /* defStyleAttr */ 0) @Before fun setUp() { + MockitoAnnotations.initMocks(this) + mediaViewController = MediaViewController( + context, + configurationController, + mediaHostStatesManager, + logger + ) mediaViewController.attach(transitionLayout, MediaViewController.TYPE.PLAYER) }