Add debug logging for media view events

Test: manual; verify present in bugreport
Bug: 198319256
Change-Id: I416d532758cc280a6ea05f45bccdb3dcd81abe34
This commit is contained in:
Beth Thibodeau
2022-04-19 01:38:53 +00:00
parent bfab17072d
commit f1ea23510a
5 changed files with 129 additions and 4 deletions

View File

@@ -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

View File

@@ -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 {
}

View File

@@ -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
}

View File

@@ -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"
}
)
}
}

View File

@@ -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)
}