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

Commit 5fe49a68 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I3d1952ae,I42f5d4b1 into tm-dev

* changes:
  [Media] Add logging for NearbyMediaDevicesManager.
  [Media] Add logging to MediaMuteAwaitConnectionManager.
parents 62649a71 1f94d22a
Loading
Loading
Loading
Loading
+23 −0
Original line number Original line Diff line number Diff line
@@ -176,6 +176,29 @@ 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
     * {@link com.android.systemui.media.muteawait.MediaMuteAwaitConnectionManager}.
     */
    @Provides
    @SysUISingleton
    @MediaMuteAwaitLog
    public static LogBuffer provideMediaMuteAwaitLogBuffer(LogBufferFactory factory) {
        return factory.create("MediaMuteAwaitLog", 20);
    }

    /**
     * Provides a logging buffer for logs related to the media mute-await connections. See
     * {@link com.android.systemui.media.nearby.NearbyMediaDevicesManager}.
     */
    @Provides
    @SysUISingleton
    @NearbyMediaDevicesLog
    public static LogBuffer provideNearbyMediaDevicesLogBuffer(LogBufferFactory factory) {
        return factory.create("NearbyMediaDevicesLog", 20);
    }

    /** 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
+36 −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.muteawait.MediaMuteAwaitConnectionManager}.
 */
@Qualifier
@Documented
@Retention(RUNTIME)
public @interface MediaMuteAwaitLog {
}
+33 −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.nearby.NearbyMediaDevicesManager}. */
@Qualifier
@Documented
@Retention(RUNTIME)
public @interface NearbyMediaDevicesLog {
}
+11 −5
Original line number Original line Diff line number Diff line
@@ -33,14 +33,13 @@ import java.util.concurrent.Executor
 * will be notified.
 * will be notified.
 *
 *
 * See [AudioManager.muteAwaitConnection] and b/206614671 for more details.
 * See [AudioManager.muteAwaitConnection] and b/206614671 for more details.
 *
 * TODO(b/206614671): Add logging.
 */
 */
class MediaMuteAwaitConnectionManager constructor(
class MediaMuteAwaitConnectionManager constructor(
    @Main private val mainExecutor: Executor,
    @Main private val mainExecutor: Executor,
    private val localMediaManager: LocalMediaManager,
    private val localMediaManager: LocalMediaManager,
    private val context: Context,
    private val context: Context,
    private val deviceIconUtil: DeviceIconUtil
    private val deviceIconUtil: DeviceIconUtil,
    private val logger: MediaMuteAwaitLogger
) {
) {
    var currentMutedDevice: AudioDeviceAttributes? = null
    var currentMutedDevice: AudioDeviceAttributes? = null


@@ -48,7 +47,8 @@ class MediaMuteAwaitConnectionManager constructor(


    val muteAwaitConnectionChangeListener = object : AudioManager.MuteAwaitConnectionCallback() {
    val muteAwaitConnectionChangeListener = object : AudioManager.MuteAwaitConnectionCallback() {
        override fun onMutedUntilConnection(device: AudioDeviceAttributes, mutedUsages: IntArray) {
        override fun onMutedUntilConnection(device: AudioDeviceAttributes, mutedUsages: IntArray) {
            if (USAGE_MEDIA in mutedUsages) {
            logger.logMutedDeviceAdded(device.address, device.name, mutedUsages.hasMedia())
            if (mutedUsages.hasMedia()) {
                // There should only be one device that's mutedUntilConnection at a time, so we can
                // There should only be one device that's mutedUntilConnection at a time, so we can
                // safely override any previous value.
                // safely override any previous value.
                currentMutedDevice = device
                currentMutedDevice = device
@@ -63,7 +63,11 @@ class MediaMuteAwaitConnectionManager constructor(
            device: AudioDeviceAttributes,
            device: AudioDeviceAttributes,
            mutedUsages: IntArray
            mutedUsages: IntArray
        ) {
        ) {
            if (currentMutedDevice == device && USAGE_MEDIA in mutedUsages) {
            val isMostRecentDevice = currentMutedDevice == device
            logger.logMutedDeviceRemoved(
                device.address, device.name, mutedUsages.hasMedia(), isMostRecentDevice
            )
            if (isMostRecentDevice && mutedUsages.hasMedia()) {
                currentMutedDevice = null
                currentMutedDevice = null
                localMediaManager.dispatchAboutToConnectDeviceRemoved()
                localMediaManager.dispatchAboutToConnectDeviceRemoved()
            }
            }
@@ -92,4 +96,6 @@ class MediaMuteAwaitConnectionManager constructor(
    private fun AudioDeviceAttributes.getIcon(): Drawable {
    private fun AudioDeviceAttributes.getIcon(): Drawable {
        return deviceIconUtil.getIconFromAudioDeviceType(this.type, context)
        return deviceIconUtil.getIconFromAudioDeviceType(this.type, context)
    }
    }

    private fun IntArray.hasMedia() = USAGE_MEDIA in this
}
}
+2 −1
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@ import javax.inject.Inject
class MediaMuteAwaitConnectionManagerFactory @Inject constructor(
class MediaMuteAwaitConnectionManagerFactory @Inject constructor(
    private val mediaFlags: MediaFlags,
    private val mediaFlags: MediaFlags,
    private val context: Context,
    private val context: Context,
    private val logger: MediaMuteAwaitLogger,
    @Main private val mainExecutor: Executor
    @Main private val mainExecutor: Executor
) {
) {
    private val deviceIconUtil = DeviceIconUtil()
    private val deviceIconUtil = DeviceIconUtil()
@@ -40,7 +41,7 @@ class MediaMuteAwaitConnectionManagerFactory @Inject constructor(
            return null
            return null
        }
        }
        return MediaMuteAwaitConnectionManager(
        return MediaMuteAwaitConnectionManager(
                mainExecutor, localMediaManager, context, deviceIconUtil
                mainExecutor, localMediaManager, context, deviceIconUtil, logger
        )
        )
    }
    }
}
}
Loading