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

Commit 681369e2 authored by Beth Thibodeau's avatar Beth Thibodeau Committed by Automerger Merge Worker
Browse files

Merge "Add debug logging for media view events" into tm-dev am: db41a61d

parents 6cd01730 db41a61d
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -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
+35 −0
Original line number 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 Diff line number Diff line
@@ -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
    }

+63 −0
Original line number 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 Diff line number Diff line
@@ -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)
    }