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

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

Merge "Define BundleSession for MediaMetrics"

parents ef8c1218 a4c545a3
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -24377,6 +24377,12 @@ package android.media.effect {
package android.media.metrics {
  public final class BundleSession implements java.lang.AutoCloseable {
    method public void close();
    method @NonNull public android.media.metrics.LogSessionId getSessionId();
    method public void reportBundleMetrics(@NonNull android.os.PersistableBundle);
  }
  public final class EditingSession implements java.lang.AutoCloseable {
    method public void close();
    method @NonNull public android.media.metrics.LogSessionId getSessionId();
@@ -24393,6 +24399,7 @@ package android.media.metrics {
  }
  public final class MediaMetricsManager {
    method @NonNull public android.media.metrics.BundleSession createBundleSession();
    method @NonNull public android.media.metrics.EditingSession createEditingSession();
    method @NonNull public android.media.metrics.PlaybackSession createPlaybackSession();
    method @NonNull public android.media.metrics.RecordingSession createRecordingSession();
+72 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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 android.media.metrics;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.PersistableBundle;

import com.android.internal.util.AnnotationValidations;

import java.util.Objects;

/**
 * An instances of this class represents a session with data stored in a bundle.
 */
public final class BundleSession implements AutoCloseable {
    private final @NonNull String mId;
    private final @NonNull MediaMetricsManager mManager;
    private final @NonNull LogSessionId mLogSessionId;

    /** @hide */
    public BundleSession(@NonNull String id, @NonNull MediaMetricsManager manager) {
        mId = id;
        mManager = manager;
        AnnotationValidations.validate(NonNull.class, null, mId);
        AnnotationValidations.validate(NonNull.class, null, mManager);
        mLogSessionId = new LogSessionId(mId);
    }

    /**
     * Reports metrics via bundle.
     *
     */
    public void reportBundleMetrics(@NonNull PersistableBundle metrics) {
        mManager.reportBundleMetrics(mId, metrics);
    }

    public @NonNull LogSessionId getSessionId() {
        return mLogSessionId;
    }

    @Override
    public boolean equals(@Nullable Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        BundleSession that = (BundleSession) o;
        return Objects.equals(mId, that.mId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(mId);
    }

    @Override
    public void close() {
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.media.metrics.PlaybackErrorEvent;
import android.media.metrics.PlaybackMetrics;
import android.media.metrics.PlaybackStateEvent;
import android.media.metrics.TrackChangeEvent;
import android.os.PersistableBundle;

/**
 * Interface to the playback manager service.
@@ -38,4 +39,6 @@ interface IMediaMetricsManager {

    String getTranscodingSessionId(int userId);
    String getEditingSessionId(int userId);
    String getBundleSessionId(int userId);
    void reportBundleMetrics(in String sessionId, in PersistableBundle metrics, int userId);
}
+26 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.media.metrics;
import android.annotation.NonNull;
import android.annotation.SystemService;
import android.content.Context;
import android.os.PersistableBundle;
import android.os.RemoteException;

/**
@@ -52,6 +53,17 @@ public final class MediaMetricsManager {
            throw e.rethrowFromSystemServer();
        }
    }
    /**
     * Reports bundle metrics.
     * @hide
     */
    public void reportBundleMetrics(@NonNull String sessionId, PersistableBundle metrics) {
        try {
            mService.reportBundleMetrics(sessionId, metrics, mUserId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
    /**
     * Reports network event.
     * @hide
@@ -144,6 +156,20 @@ public final class MediaMetricsManager {
        }
    }

    /**
     * Creates a generic bundle session.
     */
    @NonNull
    public BundleSession createBundleSession() {
        try {
            String id = mService.getBundleSessionId(mUserId);
            BundleSession session = new BundleSession(id, this);
            return session;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Reports error event.
     * @hide
+20 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.media.metrics.PlaybackMetrics;
import android.media.metrics.PlaybackStateEvent;
import android.media.metrics.TrackChangeEvent;
import android.os.Binder;
import android.os.PersistableBundle;
import android.provider.DeviceConfig;
import android.provider.DeviceConfig.Properties;
import android.util.Base64;
@@ -180,6 +181,20 @@ public final class MediaMetricsManagerService extends SystemService {
            StatsLog.write(statsEvent);
        }

        public void reportBundleMetrics(String sessionId, PersistableBundle metrics, int userId) {
            int level = loggingLevel();
            if (level == LOGGING_LEVEL_BLOCKED) {
                return;
            }

            int atomid = metrics.getInt("KEY_STATSD_ATOM_NUMBER");
            switch (atomid) {
                default:
                    return;
                // to be extended as we define statsd atoms
            }
        }

        @Override
        public void reportPlaybackStateEvent(
                String sessionId, PlaybackStateEvent event, int userId) {
@@ -231,6 +246,11 @@ public final class MediaMetricsManagerService extends SystemService {
            return getSessionIdInternal(userId);
        }

        @Override
        public String getBundleSessionId(int userId) {
            return getSessionIdInternal(userId);
        }

        @Override
        public void reportPlaybackErrorEvent(
                String sessionId, PlaybackErrorEvent event, int userId) {