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

Commit 542955e8 authored by Santiago Seifert's avatar Santiago Seifert Committed by Android (Google) Code Review
Browse files

Merge "[Media Router Metrics] Log Scanning Start/Stopped events" into main

parents b4c8ecdc ed5f3caa
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import static android.media.MediaRouter2.SCANNING_STATE_SCANNING_FULL;
import static android.media.MediaRouter2.SCANNING_STATE_WHILE_INTERACTIVE;
import static android.media.MediaRouter2Utils.getOriginalId;
import static android.media.MediaRouter2Utils.getProviderId;

import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;
import static com.android.server.media.MediaRouterStatsLog.MEDIA_ROUTER_EVENT_REPORTED__EVENT_TYPE__EVENT_TYPE_CREATE_SESSION;
import static com.android.server.media.MediaRouterStatsLog.MEDIA_ROUTER_EVENT_REPORTED__EVENT_TYPE__EVENT_TYPE_DESELECT_ROUTE;
@@ -78,14 +77,12 @@ import android.util.ArrayMap;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.function.pooled.PooledLambda;
import com.android.media.flags.Flags;
import com.android.server.LocalServices;
import com.android.server.pm.UserManagerInternal;
import com.android.server.statusbar.StatusBarManagerInternal;

import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
@@ -3857,6 +3854,16 @@ class MediaRouter2ServiceImpl {
                        && activelyScanningPackages.equals(mUserRecord.mActivelyScanningPackages)) {
                    return false;
                }

                var oldShouldPerformActiveScan =
                        mUserRecord.mCompositeDiscoveryPreference.shouldPerformActiveScan();
                var newShouldPerformActiveScan = newPreference.shouldPerformActiveScan();
                if (oldShouldPerformActiveScan != newShouldPerformActiveScan) {
                    // State access is synchronized with service.mLock.
                    // Linter still fails due to b/323906305#comment3
                    mMediaRouterMetricLogger.updateScanningState(newShouldPerformActiveScan);
                }

                mUserRecord.mCompositeDiscoveryPreference = newPreference;
                mUserRecord.mActivelyScanningPackages = activelyScanningPackages;
            }
+29 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.media;

import static com.android.server.media.MediaRouterStatsLog.MEDIA_ROUTER_EVENT_REPORTED__EVENT_TYPE__EVENT_TYPE_SCANNING_STARTED;
import static com.android.server.media.MediaRouterStatsLog.MEDIA_ROUTER_EVENT_REPORTED__EVENT_TYPE__EVENT_TYPE_SCANNING_STOPPED;
import static com.android.server.media.MediaRouterStatsLog.MEDIA_ROUTER_EVENT_REPORTED__RESULT__RESULT_FAILED_TO_REROUTE_SYSTEM_MEDIA;
import static com.android.server.media.MediaRouterStatsLog.MEDIA_ROUTER_EVENT_REPORTED__RESULT__RESULT_INVALID_COMMAND;
import static com.android.server.media.MediaRouterStatsLog.MEDIA_ROUTER_EVENT_REPORTED__RESULT__RESULT_NETWORK_ERROR;
@@ -113,6 +115,33 @@ final class MediaRouterMetricLogger {
        removeRequestInfo(uniqueRequestId);
    }

    /**
     * Logs the overall scanning state.
     *
     * @param isScanning The scanning state for the user.
     */
    public void updateScanningState(boolean isScanning) {
        if (!isScanning) {
            logScanningStopped();
        } else {
            logScanningStarted();
        }
    }

    /** Logs the scanning started event. */
    private void logScanningStarted() {
        logMediaRouterEvent(
                MEDIA_ROUTER_EVENT_REPORTED__EVENT_TYPE__EVENT_TYPE_SCANNING_STARTED,
                MEDIA_ROUTER_EVENT_REPORTED__RESULT__RESULT_UNSPECIFIED);
    }

    /** Logs the scanning stopped event. */
    private void logScanningStopped() {
        logMediaRouterEvent(
                MEDIA_ROUTER_EVENT_REPORTED__EVENT_TYPE__EVENT_TYPE_SCANNING_STOPPED,
                MEDIA_ROUTER_EVENT_REPORTED__RESULT__RESULT_UNSPECIFIED);
    }

    /**
     * Converts a reason code from {@link MediaRoute2ProviderService} to a result code for logging.
     *