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

Commit ca120d0f authored by Ibrahim Yilmaz's avatar Ibrahim Yilmaz Committed by Android (Google) Code Review
Browse files

Merge "Log KeyguardMediaController refreshMediaPosition" into main

parents b020ad15 a6f3b71b
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
/*
 * 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.log.dagger

import javax.inject.Qualifier

/** A [com.android.systemui.log.LogBuffer] for KeyguardMediaController. */
@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
annotation class KeyguardMediaControllerLog
+8 −0
Original line number Diff line number Diff line
@@ -156,6 +156,14 @@ public class LogModule {
        return factory.create("NotifRemoteInputLog", 50 /* maxSize */, false /* systrace */);
    }

    /** Provides a logging buffer for all logs related to keyguard media controller. */
    @Provides
    @SysUISingleton
    @KeyguardMediaControllerLog
    public static LogBuffer provideKeyguardMediaControllerLogBuffer(LogBufferFactory factory) {
        return factory.create("KeyguardMediaControllerLog", 50 /* maxSize */, false /* systrace */);
    }

    /** Provides a logging buffer for all logs related to unseen notifications. */
    @Provides
    @SysUISingleton
+36 −31
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.net.Uri
import android.os.Handler
import android.os.UserHandle
import android.provider.Settings
import android.util.Log
import android.view.View
import android.view.ViewGroup
import androidx.annotation.VisibleForTesting
@@ -63,22 +62,21 @@ constructor(
    @Main private val handler: Handler,
    configurationController: ConfigurationController,
    private val splitShadeStateController: SplitShadeStateController,
    private val logger: KeyguardMediaControllerLogger,
    dumpManager: DumpManager,
) : Dumpable {
    /** It's added for debugging purpose to directly see last received StatusBarState. */
    private var lastReceivedStatusBarState = -1
    private var lastUsedStatusBarState = -1

    init {
        dumpManager.registerDumpable(this)
        statusBarStateController.addCallback(
            object : StatusBarStateController.StateListener {
                override fun onStateChanged(newState: Int) {
                    lastReceivedStatusBarState = newState
                    refreshMediaPosition()
                    refreshMediaPosition(reason = "StatusBarState.onStateChanged")
                }

                override fun onDozingChanged(isDozing: Boolean) {
                    refreshMediaPosition()
                    refreshMediaPosition(reason = "StatusBarState.onDozingChanged")
                }
            }
        )
@@ -100,7 +98,7 @@ constructor(
                                true,
                                UserHandle.USER_CURRENT
                            )
                        refreshMediaPosition()
                        refreshMediaPosition(reason = "allowMediaPlayerOnLockScreen changed")
                    }
                }
            }
@@ -132,7 +130,7 @@ constructor(
            }
            field = value
            reattachHostView()
            refreshMediaPosition()
            refreshMediaPosition(reason = "useSplitShade changed")
        }

    /** Is the media player visible? */
@@ -147,7 +145,7 @@ constructor(
    var isDozeWakeUpAnimationWaiting: Boolean = false
        set(value) {
            field = value
            refreshMediaPosition()
            refreshMediaPosition(reason = "isDozeWakeUpAnimationWaiting changed")
        }

    /** single pane media container placed at the top of the notifications list */
@@ -181,7 +179,7 @@ constructor(

    /** Called whenever the media hosts visibility changes */
    private fun onMediaHostVisibilityChanged(visible: Boolean) {
        refreshMediaPosition()
        refreshMediaPosition(reason = "onMediaHostVisibilityChanged")
        if (visible) {
            mediaHost.hostView.layoutParams.apply {
                height = ViewGroup.LayoutParams.WRAP_CONTENT
@@ -194,7 +192,7 @@ constructor(
    fun attachSplitShadeContainer(container: ViewGroup) {
        splitShadeContainer = container
        reattachHostView()
        refreshMediaPosition()
        refreshMediaPosition(reason = "attachSplitShadeContainer")
    }

    private fun reattachHostView() {
@@ -217,30 +215,41 @@ constructor(
        }
    }

    fun refreshMediaPosition() {
    fun refreshMediaPosition(reason: String) {
        val currentState = statusBarStateController.state
        if (lastReceivedStatusBarState != -1 && currentState != lastReceivedStatusBarState) {
            Log.wtfStack(
                TAG,
                "currentState[${StatusBarState.toString(currentState)}] is " +
                    "different from the last " +
                    "received one[${StatusBarState.toString(lastReceivedStatusBarState)}]."
            )
        }

        val keyguardOrUserSwitcher = (currentState == StatusBarState.KEYGUARD)
        // mediaHost.visible required for proper animations handling
        val isMediaHostVisible = mediaHost.visible
        val isBypassNotEnabled = !bypassController.bypassEnabled
        val currentAllowMediaPlayerOnLockScreen = allowMediaPlayerOnLockScreen
        val useSplitShade = useSplitShade
        val shouldBeVisibleForSplitShade = shouldBeVisibleForSplitShade()

        visible =
            mediaHost.visible &&
                !bypassController.bypassEnabled &&
            isMediaHostVisible &&
                isBypassNotEnabled &&
                keyguardOrUserSwitcher &&
                allowMediaPlayerOnLockScreen &&
                shouldBeVisibleForSplitShade()
                currentAllowMediaPlayerOnLockScreen &&
                shouldBeVisibleForSplitShade
        if (visible) {
            showMediaPlayer()
        } else {
            hideMediaPlayer()
        }
        logger.logRefreshMediaPosition(
            reason = reason,
            visible = visible,
            useSplitShade = useSplitShade,
            currentState = currentState,
            keyguardOrUserSwitcher = keyguardOrUserSwitcher,
            mediaHostVisible = isMediaHostVisible,
            bypassNotEnabled = isBypassNotEnabled,
            currentAllowMediaPlayerOnLockScreen = currentAllowMediaPlayerOnLockScreen,
            shouldBeVisibleForSplitShade = shouldBeVisibleForSplitShade
        )

        lastUsedStatusBarState = currentState
    }

    private fun shouldBeVisibleForSplitShade(): Boolean {
@@ -298,10 +307,10 @@ constructor(
                println("isDozeWakeUpAnimationWaiting", isDozeWakeUpAnimationWaiting)
                println("singlePaneContainer", singlePaneContainer)
                println("splitShadeContainer", splitShadeContainer)
                if (lastReceivedStatusBarState != -1) {
                if (lastUsedStatusBarState != -1) {
                    println(
                        "lastReceivedStatusBarState",
                        StatusBarState.toString(lastReceivedStatusBarState)
                        "lastUsedStatusBarState",
                        StatusBarState.toString(lastUsedStatusBarState)
                    )
                }
                println(
@@ -311,8 +320,4 @@ constructor(
            }
        }
    }

    private companion object {
        private const val TAG = "KeyguardMediaController"
    }
}
+70 −0
Original line number Diff line number Diff line
/*
 * 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.media.controls.ui

import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel.DEBUG
import com.android.systemui.log.dagger.KeyguardMediaControllerLog
import com.android.systemui.statusbar.StatusBarState
import javax.inject.Inject

/** Logger class for [KeyguardMediaController]. */
open class KeyguardMediaControllerLogger
@Inject
constructor(@KeyguardMediaControllerLog private val logBuffer: LogBuffer) {

    fun logRefreshMediaPosition(
        reason: String,
        visible: Boolean,
        useSplitShade: Boolean,
        currentState: Int,
        keyguardOrUserSwitcher: Boolean,
        mediaHostVisible: Boolean,
        bypassNotEnabled: Boolean,
        currentAllowMediaPlayerOnLockScreen: Boolean,
        shouldBeVisibleForSplitShade: Boolean
    ) =
        logBuffer.log(
            TAG,
            DEBUG,
            {
                str1 = reason
                bool1 = visible
                bool2 = useSplitShade
                int1 = currentState
                bool3 = keyguardOrUserSwitcher
                bool4 = mediaHostVisible
                int2 = if (bypassNotEnabled) 1 else 0
                str2 = currentAllowMediaPlayerOnLockScreen.toString()
                str3 = shouldBeVisibleForSplitShade.toString()
            },
            {
                "refreshMediaPosition(reason=$str1, " +
                    "currentState=${StatusBarState.toString(int1)}, " +
                    "visible=$bool1, useSplitShade=$bool2, " +
                    "keyguardOrUserSwitcher=$bool3, " +
                    "mediaHostVisible=$bool4, " +
                    "bypassNotEnabled=${int2 == 1}, " +
                    "currentAllowMediaPlayerOnLockScreen=$str2, " +
                    "shouldBeVisibleForSplitShade=$str3)"
            }
        )

    private companion object {
        private const val TAG = "KeyguardMediaControllerLog"
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -1309,7 +1309,8 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
        mQsController.updateResources();
        mNotificationsQSContainerController.updateResources();
        updateKeyguardStatusViewAlignment(/* animate= */false);
        mKeyguardMediaController.refreshMediaPosition();
        mKeyguardMediaController.refreshMediaPosition(
                "NotificationPanelViewController.updateResources");

        if (splitShadeChanged) {
            onSplitShadeEnabledChanged();
Loading