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

Commit 84f36038 authored by Beth Thibodeau's avatar Beth Thibodeau Committed by Android (Google) Code Review
Browse files

Revert "Add LogBuffer for media device changes"

This reverts commit b7699e75.

Reason for revert: b/363398124

Change-Id: I1fa6d5d042091ba1f91cf026ea1513cb44e4a880
parent b7699e75
Loading
Loading
Loading
Loading
+0 −10
Original line number Original line Diff line number Diff line
@@ -382,16 +382,6 @@ public class LogModule {
        return factory.create("MediaLog", 20);
        return factory.create("MediaLog", 20);
    }
    }


    /**
     * Provides a buffer for media device changes
     */
    @Provides
    @SysUISingleton
    @MediaDeviceLog
    public static LogBuffer providesMediaDeviceLogBuffer(LogBufferFactory factory) {
        return factory.create("MediaDeviceLog", 50);
    }

    /** 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
+0 −26
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2024 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 com.android.systemui.log.LogBuffer
import javax.inject.Qualifier

/** A [LogBuffer] for [com.android.systemui.media.controls.domain.pipeline.MediaDeviceLogger] */
@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
annotation class MediaDeviceLog
+0 −116
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2024 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.domain.pipeline

import android.media.session.MediaController
import com.android.settingslib.media.MediaDevice
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.dagger.MediaDeviceLog
import com.android.systemui.media.controls.shared.model.MediaDeviceData
import javax.inject.Inject

/** A [LogBuffer] for media device changes */
class MediaDeviceLogger @Inject constructor(@MediaDeviceLog private val buffer: LogBuffer) {

    fun logBroadcastEvent(event: String, reason: Int, broadcastId: Int) {
        buffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                str1 = event
                int1 = reason
                int2 = broadcastId
            },
            { "$str1, reason = $int1, broadcastId = $int2" }
        )
    }

    fun logBroadcastEvent(event: String, reason: Int) {
        buffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                str1 = event
                int1 = reason
            },
            { "$str1, reason = $int1" }
        )
    }

    fun logBroadcastMetadataChanged(broadcastId: Int, metadata: String) {
        buffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                int1 = broadcastId
                str1 = metadata
            },
            { "onBroadcastMetadataChanged, broadcastId = $int1, metadata = $str1" }
        )
    }

    fun logNewDeviceName(name: String?) {
        buffer.log(TAG, LogLevel.DEBUG, { str1 = name }, { "New device name $str1" })
    }

    fun logLocalDevice(sassDevice: MediaDeviceData?, connectedDevice: MediaDeviceData?) {
        buffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                str1 = sassDevice?.name?.toString()
                str2 = connectedDevice?.name?.toString()
            },
            { "Local device: $str1 or $str2" }
        )
    }

    fun logRemoteDevice(routingSessionName: CharSequence?, connectedDevice: MediaDeviceData?) {
        buffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                str1 = routingSessionName?.toString()
                str2 = connectedDevice?.name?.toString()
            },
            { "Remote device: $str1 or $str2 or unknown" }
        )
    }

    fun logDeviceName(
        device: MediaDevice?,
        controller: MediaController?,
        routingSessionName: CharSequence?,
        selectedRouteName: CharSequence?
    ) {
        buffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                str1 = "device $device, controller: $controller"
                str2 = routingSessionName?.toString()
                str3 = selectedRouteName?.toString()
            },
            { "$str1, routingSession $str2 or selected route $str3" }
        )
    }

    companion object {
        private const val TAG = "MediaDeviceLog"
    }
}
+40 −20
Original line number Original line Diff line number Diff line
@@ -71,7 +71,6 @@ constructor(
    private val localBluetoothManager: Lazy<LocalBluetoothManager?>,
    private val localBluetoothManager: Lazy<LocalBluetoothManager?>,
    @Main private val fgExecutor: Executor,
    @Main private val fgExecutor: Executor,
    @Background private val bgExecutor: Executor,
    @Background private val bgExecutor: Executor,
    private val logger: MediaDeviceLogger,
) : MediaDataManager.Listener {
) : MediaDataManager.Listener {


    private val listeners: MutableSet<Listener> = mutableSetOf()
    private val listeners: MutableSet<Listener> = mutableSetOf()
@@ -282,38 +281,59 @@ constructor(
        }
        }


        override fun onBroadcastStarted(reason: Int, broadcastId: Int) {
        override fun onBroadcastStarted(reason: Int, broadcastId: Int) {
            logger.logBroadcastEvent("onBroadcastStarted", reason, broadcastId)
            if (DEBUG) {
                Log.d(TAG, "onBroadcastStarted(), reason = $reason , broadcastId = $broadcastId")
            }
            updateCurrent()
            updateCurrent()
        }
        }


        override fun onBroadcastStartFailed(reason: Int) {
        override fun onBroadcastStartFailed(reason: Int) {
            logger.logBroadcastEvent("onBroadcastStartFailed", reason)
            if (DEBUG) {
                Log.d(TAG, "onBroadcastStartFailed(), reason = $reason")
            }
        }
        }


        override fun onBroadcastMetadataChanged(
        override fun onBroadcastMetadataChanged(
            broadcastId: Int,
            broadcastId: Int,
            metadata: BluetoothLeBroadcastMetadata
            metadata: BluetoothLeBroadcastMetadata
        ) {
        ) {
            logger.logBroadcastMetadataChanged(broadcastId, metadata.toString())
            if (DEBUG) {
                Log.d(
                    TAG,
                    "onBroadcastMetadataChanged(), broadcastId = $broadcastId , " +
                        "metadata = $metadata"
                )
            }
            updateCurrent()
            updateCurrent()
        }
        }


        override fun onBroadcastStopped(reason: Int, broadcastId: Int) {
        override fun onBroadcastStopped(reason: Int, broadcastId: Int) {
            logger.logBroadcastEvent("onBroadcastStopped", reason, broadcastId)
            if (DEBUG) {
                Log.d(TAG, "onBroadcastStopped(), reason = $reason , broadcastId = $broadcastId")
            }
            updateCurrent()
            updateCurrent()
        }
        }


        override fun onBroadcastStopFailed(reason: Int) {
        override fun onBroadcastStopFailed(reason: Int) {
            logger.logBroadcastEvent("onBroadcastStopFailed", reason)
            if (DEBUG) {
                Log.d(TAG, "onBroadcastStopFailed(), reason = $reason")
            }
        }
        }


        override fun onBroadcastUpdated(reason: Int, broadcastId: Int) {
        override fun onBroadcastUpdated(reason: Int, broadcastId: Int) {
            logger.logBroadcastEvent("onBroadcastUpdated", reason, broadcastId)
            if (DEBUG) {
                Log.d(TAG, "onBroadcastUpdated(), reason = $reason , broadcastId = $broadcastId")
            }
            updateCurrent()
            updateCurrent()
        }
        }


        override fun onBroadcastUpdateFailed(reason: Int, broadcastId: Int) {
        override fun onBroadcastUpdateFailed(reason: Int, broadcastId: Int) {
            logger.logBroadcastEvent("onBroadcastUpdateFailed", reason, broadcastId)
            if (DEBUG) {
                Log.d(
                    TAG,
                    "onBroadcastUpdateFailed(), reason = $reason , " + "broadcastId = $broadcastId"
                )
            }
        }
        }


        override fun onPlaybackStarted(reason: Int, broadcastId: Int) {}
        override fun onPlaybackStarted(reason: Int, broadcastId: Int) {}
@@ -361,16 +381,12 @@ constructor(
                                name = context.getString(R.string.media_seamless_other_device),
                                name = context.getString(R.string.media_seamless_other_device),
                                showBroadcastButton = false
                                showBroadcastButton = false
                            )
                            )
                    logger.logRemoteDevice(routingSession?.name, connectedDevice)
                } else {
                } else {
                    // Prefer SASS if available when playback is local.
                    // Prefer SASS if available when playback is local.
                    val sassDevice = getSassDevice()
                    activeDevice = getSassDevice() ?: connectedDevice
                    activeDevice = sassDevice ?: connectedDevice
                    logger.logLocalDevice(sassDevice, connectedDevice)
                }
                }


                current = activeDevice ?: EMPTY_AND_DISABLED_MEDIA_DEVICE_DATA
                current = activeDevice ?: EMPTY_AND_DISABLED_MEDIA_DEVICE_DATA
                logger.logNewDeviceName(current?.name?.toString())
            } else {
            } else {
                val aboutToConnect = aboutToConnectDeviceOverride
                val aboutToConnect = aboutToConnectDeviceOverride
                if (
                if (
@@ -391,7 +407,9 @@ constructor(
                val enabled = device != null && (controller == null || routingSession != null)
                val enabled = device != null && (controller == null || routingSession != null)


                val name = getDeviceName(device, routingSession)
                val name = getDeviceName(device, routingSession)
                logger.logNewDeviceName(name)
                if (DEBUG) {
                    Log.d(TAG, "new device name $name")
                }
                current =
                current =
                    MediaDeviceData(
                    MediaDeviceData(
                        enabled,
                        enabled,
@@ -445,12 +463,14 @@ constructor(
        ): String? {
        ): String? {
            val selectedRoutes = routingSession?.let { mr2manager.get().getSelectedRoutes(it) }
            val selectedRoutes = routingSession?.let { mr2manager.get().getSelectedRoutes(it) }


            logger.logDeviceName(
            if (DEBUG) {
                device,
                Log.d(
                controller,
                    TAG,
                routingSession?.name,
                    "device is $device, controller $controller," +
                selectedRoutes?.firstOrNull()?.name
                        " routingSession ${routingSession?.name}" +
                        " or ${selectedRoutes?.firstOrNull()?.name}"
                )
                )
            }


            if (controller == null) {
            if (controller == null) {
                // In resume state, we don't have a controller - just use the device name
                // In resume state, we don't have a controller - just use the device name
+0 −4
Original line number Original line Diff line number Diff line
@@ -54,7 +54,6 @@ import com.android.systemui.media.muteawait.MediaMuteAwaitConnectionManager
import com.android.systemui.media.muteawait.MediaMuteAwaitConnectionManagerFactory
import com.android.systemui.media.muteawait.MediaMuteAwaitConnectionManagerFactory
import com.android.systemui.res.R
import com.android.systemui.res.R
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.testKosmos
import com.android.systemui.util.concurrency.FakeExecutor
import com.android.systemui.util.concurrency.FakeExecutor
import com.android.systemui.util.time.FakeSystemClock
import com.android.systemui.util.time.FakeSystemClock
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth.assertThat
@@ -126,8 +125,6 @@ public class MediaDeviceManagerTest : SysuiTestCase() {
    private lateinit var mediaData: MediaData
    private lateinit var mediaData: MediaData
    @JvmField @Rule val mockito = MockitoJUnit.rule()
    @JvmField @Rule val mockito = MockitoJUnit.rule()


    private val kosmos = testKosmos()

    @Before
    @Before
    fun setUp() {
    fun setUp() {
        fakeFgExecutor = FakeExecutor(FakeSystemClock())
        fakeFgExecutor = FakeExecutor(FakeSystemClock())
@@ -144,7 +141,6 @@ public class MediaDeviceManagerTest : SysuiTestCase() {
                { localBluetoothManager },
                { localBluetoothManager },
                fakeFgExecutor,
                fakeFgExecutor,
                fakeBgExecutor,
                fakeBgExecutor,
                kosmos.mediaDeviceLogger,
            )
            )
        manager.addListener(listener)
        manager.addListener(listener)


Loading