Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f1ea2351 authored by Beth Thibodeau's avatar Beth Thibodeau
Browse files

Add debug logging for media view events

Test: manual; verify present in bugreport
Bug: 198319256
Change-Id: I416d532758cc280a6ea05f45bccdb3dcd81abe34
parent bfab1707
Loading
Loading
Loading
Loading
+10 −1
Original line number Original line Diff line number Diff line
@@ -176,7 +176,6 @@ public class LogModule {
        return factory.create("MediaTttReceiver", 20);
        return factory.create("MediaTttReceiver", 20);
    }
    }



    /**
    /**
     * Provides a logging buffer for logs related to the media mute-await connections. See
     * Provides a logging buffer for logs related to the media mute-await connections. See
     * {@link com.android.systemui.media.muteawait.MediaMuteAwaitConnectionManager}.
     * {@link com.android.systemui.media.muteawait.MediaMuteAwaitConnectionManager}.
@@ -199,6 +198,16 @@ public class LogModule {
        return factory.create("NearbyMediaDevicesLog", 20);
        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. */
    /** Allows logging buffers to be tweaked via adb on debug builds but not on prod builds. */
    @Provides
    @Provides
    @SysUISingleton
    @SysUISingleton
+35 −0
Original line number Original line Diff line number Diff line
/*
 * 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 {
}
+8 −1
Original line number Original line Diff line number Diff line
@@ -35,7 +35,8 @@ import javax.inject.Inject
class MediaViewController @Inject constructor(
class MediaViewController @Inject constructor(
    private val context: Context,
    private val context: Context,
    private val configurationController: ConfigurationController,
    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
            // is cheap
            setGutsViewState(result)
            setGutsViewState(result)
            viewStates[cacheKey] = result
            viewStates[cacheKey] = result
            logger.logMediaSize("measured new viewState", result.width, result.height)
        } else {
        } else {
            // This is an interpolated state
            // This is an interpolated state
            val startState = state.copy().also { it.expansion = 0.0f }
            val startState = state.copy().also { it.expansion = 0.0f }
@@ -344,6 +346,7 @@ class MediaViewController @Inject constructor(
                    startViewState,
                    startViewState,
                    endViewState,
                    endViewState,
                    state.expansion)
                    state.expansion)
            logger.logMediaSize("interpolated viewState", result.width, result.height)
        }
        }
        if (state.squishFraction < 1f) {
        if (state.squishFraction < 1f) {
            return squishViewState(result, state.squishFraction)
            return squishViewState(result, state.squishFraction)
@@ -371,6 +374,7 @@ class MediaViewController @Inject constructor(
     */
     */
    fun attach(transitionLayout: TransitionLayout, type: TYPE) {
    fun attach(transitionLayout: TransitionLayout, type: TYPE) {
        updateMediaViewControllerType(type)
        updateMediaViewControllerType(type)
        logger.logMediaLocation("attach", currentStartLocation, currentEndLocation)
        this.transitionLayout = transitionLayout
        this.transitionLayout = transitionLayout
        layoutController.attach(transitionLayout)
        layoutController.attach(transitionLayout)
        if (currentEndLocation == -1) {
        if (currentEndLocation == -1) {
@@ -409,6 +413,7 @@ class MediaViewController @Inject constructor(
        currentEndLocation = endLocation
        currentEndLocation = endLocation
        currentStartLocation = startLocation
        currentStartLocation = startLocation
        currentTransitionProgress = transitionProgress
        currentTransitionProgress = transitionProgress
        logger.logMediaLocation("setCurrentState", startLocation, endLocation)


        val shouldAnimate = animateNextStateChange && !applyImmediately
        val shouldAnimate = animateNextStateChange && !applyImmediately


@@ -461,6 +466,7 @@ class MediaViewController @Inject constructor(
            result = layoutController.getInterpolatedState(startViewState, endViewState,
            result = layoutController.getInterpolatedState(startViewState, endViewState,
                    transitionProgress, tmpState)
                    transitionProgress, tmpState)
        }
        }
        logger.logMediaSize("setCurrentState", result.width, result.height)
        layoutController.setState(result, applyImmediately, shouldAnimate, animationDuration,
        layoutController.setState(result, applyImmediately, shouldAnimate, animationDuration,
                animationDelay)
                animationDelay)
    }
    }
@@ -478,6 +484,7 @@ class MediaViewController @Inject constructor(
            result.height = Math.max(it.measuredHeight, result.height)
            result.height = Math.max(it.measuredHeight, result.height)
            result.width = Math.max(it.measuredWidth, result.width)
            result.width = Math.max(it.measuredWidth, result.width)
        }
        }
        logger.logMediaSize("update to carousel", result.width, result.height)
        return result
        return result
    }
    }


+63 −0
Original line number Original line Diff line number Diff line
/*
 * 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
+13 −2
Original line number Original line Diff line number Diff line
@@ -12,6 +12,8 @@ import junit.framework.Assert.assertTrue
import org.junit.Before
import org.junit.Before
import org.junit.Test
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.MockitoAnnotations


/**
/**
 * Tests for {@link MediaViewController}.
 * Tests for {@link MediaViewController}.
@@ -20,16 +22,25 @@ import org.junit.runner.RunWith
@RunWith(AndroidTestingRunner::class)
@RunWith(AndroidTestingRunner::class)
@TestableLooper.RunWithLooper
@TestableLooper.RunWithLooper
class MediaViewControllerTest : SysuiTestCase() {
class MediaViewControllerTest : SysuiTestCase() {
    @Mock
    private lateinit var logger: MediaViewLogger

    private val configurationController =
    private val configurationController =
            com.android.systemui.statusbar.phone.ConfigurationControllerImpl(context)
            com.android.systemui.statusbar.phone.ConfigurationControllerImpl(context)
    private val mediaHostStatesManager = MediaHostStatesManager()
    private val mediaHostStatesManager = MediaHostStatesManager()
    private val mediaViewController =
    private lateinit var mediaViewController: MediaViewController
            MediaViewController(context, configurationController, mediaHostStatesManager)
    private val mediaHostStateHolder = MediaHost.MediaHostStateHolder()
    private val mediaHostStateHolder = MediaHost.MediaHostStateHolder()
    private var transitionLayout = TransitionLayout(context, /* attrs */ null, /* defStyleAttr */ 0)
    private var transitionLayout = TransitionLayout(context, /* attrs */ null, /* defStyleAttr */ 0)


    @Before
    @Before
    fun setUp() {
    fun setUp() {
        MockitoAnnotations.initMocks(this)
        mediaViewController = MediaViewController(
                context,
                configurationController,
                mediaHostStatesManager,
                logger
        )
        mediaViewController.attach(transitionLayout, MediaViewController.TYPE.PLAYER)
        mediaViewController.attach(transitionLayout, MediaViewController.TYPE.PLAYER)
    }
    }