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

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

Merge changes I76776abd,Iaeed7078,Iab36b4df into main

* changes:
  [SB][Screen Chips] Convert MediaProjectionRepo logs to LogBuffer.
  [SB][Screen Chips] Convert RecordingController logs to LogBuffer.
  [SB][Screen Chips] Convert CastController logs to LogBuffer.
parents c4a9755d 3b17f3fd
Loading
Loading
Loading
Loading
+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.mediaprojection

import javax.inject.Qualifier

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

package com.android.systemui.mediaprojection

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogBufferFactory
import com.android.systemui.mediaprojection.data.repository.MediaProjectionManagerRepository
import com.android.systemui.mediaprojection.data.repository.MediaProjectionRepository
import dagger.Binds
import dagger.Module
import dagger.Provides

@Module
interface MediaProjectionModule {
    @Binds fun mediaRepository(impl: MediaProjectionManagerRepository): MediaProjectionRepository

    companion object {
        @Provides
        @SysUISingleton
        @MediaProjectionLog
        fun provideMediaProjectionLogBuffer(factory: LogBufferFactory): LogBuffer {
            return factory.create("MediaProjection", 50)
        }
    }
}
+30 −8
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.hardware.display.DisplayManager
import android.media.projection.MediaProjectionInfo
import android.media.projection.MediaProjectionManager
import android.os.Handler
import android.util.Log
import android.view.ContentRecordingSession
import android.view.ContentRecordingSession.RECORD_CONTENT_DISPLAY
import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging
@@ -29,6 +28,9 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.mediaprojection.MediaProjectionLog
import com.android.systemui.mediaprojection.MediaProjectionServiceHelper
import com.android.systemui.mediaprojection.data.model.MediaProjectionState
import com.android.systemui.mediaprojection.taskswitcher.data.repository.TasksRepository
@@ -56,22 +58,27 @@ constructor(
    @Background private val backgroundDispatcher: CoroutineDispatcher,
    private val tasksRepository: TasksRepository,
    private val mediaProjectionServiceHelper: MediaProjectionServiceHelper,
    @MediaProjectionLog private val logger: LogBuffer,
) : MediaProjectionRepository {

    override suspend fun switchProjectedTask(task: RunningTaskInfo) {
        withContext(backgroundDispatcher) {
            if (mediaProjectionServiceHelper.updateTaskRecordingSession(task.token)) {
                Log.d(TAG, "Successfully switched projected task")
                logger.log(TAG, LogLevel.DEBUG, {}, { "Successfully switched projected task" })
            } else {
                Log.d(TAG, "Failed to switch projected task")
                logger.log(TAG, LogLevel.WARNING, {}, { "Failed to switch projected task" })
            }
        }
    }

    override suspend fun stopProjecting() {
        withContext(backgroundDispatcher) {
            // TODO(b/332662551): Convert Logcat to LogBuffer.
            Log.d(TAG, "Requesting MediaProjectionManager#stopActiveProjection")
            logger.log(
                TAG,
                LogLevel.DEBUG,
                {},
                { "Requesting MediaProjectionManager#stopActiveProjection" },
            )
            mediaProjectionManager.stopActiveProjection()
        }
    }
@@ -81,12 +88,22 @@ constructor(
                val callback =
                    object : MediaProjectionManager.Callback() {
                        override fun onStart(info: MediaProjectionInfo?) {
                            Log.d(TAG, "MediaProjectionManager.Callback#onStart")
                            logger.log(
                                TAG,
                                LogLevel.DEBUG,
                                {},
                                { "MediaProjectionManager.Callback#onStart" },
                            )
                            trySendWithFailureLogging(CallbackEvent.OnStart, TAG)
                        }

                        override fun onStop(info: MediaProjectionInfo?) {
                            Log.d(TAG, "MediaProjectionManager.Callback#onStop")
                            logger.log(
                                TAG,
                                LogLevel.DEBUG,
                                {},
                                { "MediaProjectionManager.Callback#onStop" },
                            )
                            trySendWithFailureLogging(CallbackEvent.OnStop, TAG)
                        }

@@ -94,7 +111,12 @@ constructor(
                            info: MediaProjectionInfo,
                            session: ContentRecordingSession?
                        ) {
                            Log.d(TAG, "MediaProjectionManager.Callback#onSessionStarted: $session")
                            logger.log(
                                TAG,
                                LogLevel.DEBUG,
                                { str1 = session.toString() },
                                { "MediaProjectionManager.Callback#onSessionStarted: $str1" },
                            )
                            trySendWithFailureLogging(
                                CallbackEvent.OnRecordingSessionSet(info, session),
                                TAG,
+13 −10
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Process;
import android.os.UserHandle;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -60,8 +59,6 @@ import javax.inject.Inject;
@SysUISingleton
public class RecordingController
        implements CallbackController<RecordingController.RecordingStateChangeCallback> {
    private static final String TAG = "RecordingController";

    private boolean mIsStarting;
    private boolean mIsRecording;
    private PendingIntent mStopIntent;
@@ -71,6 +68,7 @@ public class RecordingController
    private final BroadcastDispatcher mBroadcastDispatcher;
    private final FeatureFlags mFlags;
    private final UserTracker mUserTracker;
    private final RecordingControllerLogger mRecordingControllerLogger;
    private final MediaProjectionMetricsLogger mMediaProjectionMetricsLogger;
    private final ScreenCaptureDisabledDialogDelegate mScreenCaptureDisabledDialogDelegate;
    private final ScreenRecordDialogDelegate.Factory mScreenRecordDialogFactory;
@@ -102,9 +100,10 @@ public class RecordingController
            if (intent != null && INTENT_UPDATE_STATE.equals(intent.getAction())) {
                if (intent.hasExtra(EXTRA_STATE)) {
                    boolean state = intent.getBooleanExtra(EXTRA_STATE, false);
                    mRecordingControllerLogger.logIntentStateUpdated(state);
                    updateState(state);
                } else {
                    Log.e(TAG, "Received update intent with no state");
                    mRecordingControllerLogger.logIntentMissingState();
                }
            }
        }
@@ -120,6 +119,7 @@ public class RecordingController
            FeatureFlags flags,
            Lazy<ScreenCaptureDevicePolicyResolver> devicePolicyResolver,
            UserTracker userTracker,
            RecordingControllerLogger recordingControllerLogger,
            MediaProjectionMetricsLogger mediaProjectionMetricsLogger,
            ScreenCaptureDisabledDialogDelegate screenCaptureDisabledDialogDelegate,
            ScreenRecordDialogDelegate.Factory screenRecordDialogFactory,
@@ -130,6 +130,7 @@ public class RecordingController
        mDevicePolicyResolver = devicePolicyResolver;
        mBroadcastDispatcher = broadcastDispatcher;
        mUserTracker = userTracker;
        mRecordingControllerLogger = recordingControllerLogger;
        mMediaProjectionMetricsLogger = mediaProjectionMetricsLogger;
        mScreenCaptureDisabledDialogDelegate = screenCaptureDisabledDialogDelegate;
        mScreenRecordDialogFactory = screenRecordDialogFactory;
@@ -212,9 +213,9 @@ public class RecordingController
                    IntentFilter stateFilter = new IntentFilter(INTENT_UPDATE_STATE);
                    mBroadcastDispatcher.registerReceiver(mStateChangeReceiver, stateFilter, null,
                            UserHandle.ALL);
                    Log.d(TAG, "sent start intent");
                    mRecordingControllerLogger.logSentStartIntent();
                } catch (PendingIntent.CanceledException e) {
                    Log.e(TAG, "Pending intent was cancelled: " + e.getMessage());
                    mRecordingControllerLogger.logPendingIntentCancelled(e);
                }
            }
        };
@@ -227,9 +228,10 @@ public class RecordingController
     */
    public void cancelCountdown() {
        if (mCountDownTimer != null) {
            mRecordingControllerLogger.logCountdownCancelled();
            mCountDownTimer.cancel();
        } else {
            Log.e(TAG, "Timer was null");
            mRecordingControllerLogger.logCountdownCancelErrorNoTimer();
        }
        mIsStarting = false;

@@ -258,16 +260,16 @@ public class RecordingController
     * Stop the recording
     */
    public void stopRecording() {
        // TODO(b/332662551): Convert Logcat to LogBuffer.
        try {
            if (mStopIntent != null) {
                mRecordingControllerLogger.logRecordingStopped();
                mStopIntent.send(mInteractiveBroadcastOption);
            } else {
                Log.e(TAG, "Stop intent was null");
                mRecordingControllerLogger.logRecordingStopErrorNoStopIntent();
            }
            updateState(false);
        } catch (PendingIntent.CanceledException e) {
            Log.e(TAG, "Error stopping: " + e.getMessage());
            mRecordingControllerLogger.logRecordingStopError(e);
        }
    }

@@ -276,6 +278,7 @@ public class RecordingController
     * @param isRecording
     */
    public synchronized void updateState(boolean isRecording) {
        mRecordingControllerLogger.logStateUpdated(isRecording);
        if (!isRecording && mIsRecording) {
            // Unregister receivers if we have stopped recording
            mUserTracker.removeCallback(mUserChangedCallback);
+28 −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.screenrecord

import javax.inject.Qualifier

/**
 * Logs for screen record events. See [com.android.systemui.screenrecord.RecordingController] and
 * [com.android.systemui.screenrecord.RecordingControllerLogger].
 */
@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
annotation class RecordingControllerLog
Loading