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

Commit 017ecfe2 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov Committed by Android (Google) Code Review
Browse files

Merge changes Iab5fda19,I2b192ee8 into main

* changes:
  [SB][Screen Chips] Add logs for chip & dialog interactions.
  [SB][Screen Chips] Finish adding logs to repo, interactor, and VM flows.
parents 464060da 0ff31a6d
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -69,7 +69,11 @@ constructor(
    }

    override suspend fun stopProjecting() {
        withContext(backgroundDispatcher) { mediaProjectionManager.stopActiveProjection() }
        withContext(backgroundDispatcher) {
            // TODO(b/332662551): Convert Logcat to LogBuffer.
            Log.d(TAG, "Requesting MediaProjectionManager#stopActiveProjection")
            mediaProjectionManager.stopActiveProjection()
        }
    }

    override val mediaProjectionState: Flow<MediaProjectionState> =
+25 −0
Original line number 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.mediarouter

import javax.inject.Qualifier

/** Logs for events related to MediaRouter APIs. */
@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
annotation class MediaRouterLog
+13 −0
Original line number Diff line number Diff line
@@ -16,12 +16,25 @@

package com.android.systemui.mediarouter

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogBufferFactory
import com.android.systemui.mediarouter.data.repository.MediaRouterRepository
import com.android.systemui.mediarouter.data.repository.MediaRouterRepositoryImpl
import dagger.Binds
import dagger.Module
import dagger.Provides

@Module
interface MediaRouterModule {
    @Binds fun mediaRouterRepository(impl: MediaRouterRepositoryImpl): MediaRouterRepository

    companion object {
        @Provides
        @SysUISingleton
        @MediaRouterLog
        fun provideMediaRouterLogBuffer(factory: LogBufferFactory): LogBuffer {
            return factory.create("MediaRouter", 50)
        }
    }
}
+20 −8
Original line number Diff line number Diff line
@@ -18,6 +18,9 @@ package com.android.systemui.mediarouter.data.repository

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.mediarouter.MediaRouterLog
import com.android.systemui.statusbar.policy.CastController
import com.android.systemui.statusbar.policy.CastDevice
import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow
@@ -26,6 +29,9 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn

/** A repository for data coming from MediaRouter APIs. */
@@ -43,23 +49,29 @@ class MediaRouterRepositoryImpl
constructor(
    @Application private val scope: CoroutineScope,
    private val castController: CastController,
    @MediaRouterLog private val logger: LogBuffer,
) : MediaRouterRepository {
    override val castDevices: StateFlow<List<CastDevice>> =
        conflatedCallbackFlow {
                val callback =
                    CastController.Callback {
                        val mediaRouterCastDevices =
                            castController.castDevices.filter {
                                it.origin == CastDevice.CastOrigin.MediaRouter
                            }
                        trySend(mediaRouterCastDevices)
                    }
                val callback = CastController.Callback { trySend(castController.castDevices) }
                castController.addCallback(callback)
                awaitClose { castController.removeCallback(callback) }
            }
            // The CastController.Callback is pretty noisy and sends the same values multiple times
            // in a row, so use a distinctUntilChanged before logging.
            .distinctUntilChanged()
            .onEach { allDevices ->
                val logString = allDevices.map { it.shortLogString }.toString()
                logger.log(TAG, LogLevel.INFO, { str1 = logString }, { "All cast devices: $str1" })
            }
            .map { it.filter { device -> device.origin == CastDevice.CastOrigin.MediaRouter } }
            .stateIn(scope, SharingStarted.WhileSubscribed(), emptyList())

    override fun stopCasting(device: CastDevice) {
        castController.stopCasting(device)
    }

    companion object {
        private const val TAG = "MediaRouterRepo"
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -258,6 +258,7 @@ public class RecordingController
     * Stop the recording
     */
    public void stopRecording() {
        // TODO(b/332662551): Convert Logcat to LogBuffer.
        try {
            if (mStopIntent != null) {
                mStopIntent.send(mInteractiveBroadcastOption);
Loading