Integrate feedback from MediaMetrics API reviews

observations about missing action in close().
javadoc on some KEY_* fields.
Implement PlaybackStateEvent within BundleSession as example.

Bug: 220129161
Test: atest CtsMediaHostTestCases  (with corresponding CLs for cts)
Change-Id: I09a8be6d3f2780ca97b6b08cd33ccf35b02c245f
This commit is contained in:
Ray Essick
2022-03-22 09:35:48 -07:00
parent fdd691c352
commit 2ee37d3d6a
10 changed files with 70 additions and 1 deletions

View File

@@ -24461,6 +24461,7 @@ package android.media.metrics {
method public void close();
method @NonNull public android.media.metrics.LogSessionId getSessionId();
method public void reportBundleMetrics(@NonNull android.os.PersistableBundle);
field public static final String KEY_STATSD_ATOM = "bundlesession-statsd-atom";
}
public final class EditingSession implements java.lang.AutoCloseable {
@@ -24484,6 +24485,7 @@ package android.media.metrics {
method @NonNull public android.media.metrics.PlaybackSession createPlaybackSession();
method @NonNull public android.media.metrics.RecordingSession createRecordingSession();
method @NonNull public android.media.metrics.TranscodingSession createTranscodingSession();
method @NonNull public void releaseSessionId(@NonNull String);
field public static final long INVALID_TIMESTAMP = -1L; // 0xffffffffffffffffL
}

View File

@@ -32,6 +32,15 @@ public final class BundleSession implements AutoCloseable {
private final @NonNull MediaMetricsManager mManager;
private final @NonNull LogSessionId mLogSessionId;
/**
* A key describing the statsd atom into which to place this bundle's other contents.
* The associated value is an integer.
*
* @see #reportBundleMetrics
*/
public static final String KEY_STATSD_ATOM = "bundlesession-statsd-atom";
/** @hide */
public BundleSession(@NonNull String id, @NonNull MediaMetricsManager manager) {
mId = id;
@@ -44,6 +53,10 @@ public final class BundleSession implements AutoCloseable {
/**
* Reports metrics via bundle.
*
* The key {@link #KEY_STATSD_ATOM} references an integer value that
* indicates the statsd atom for the data in this bundle. Other keys
* and their types are defined on a per-atom basis.
*
*/
public void reportBundleMetrics(@NonNull PersistableBundle metrics) {
mManager.reportBundleMetrics(mId, metrics);
@@ -68,5 +81,6 @@ public final class BundleSession implements AutoCloseable {
@Override
public void close() {
mManager.releaseSessionId(mLogSessionId.getStringId());
}
}

View File

@@ -59,5 +59,6 @@ public final class EditingSession implements AutoCloseable {
@Override
public void close() {
mManager.releaseSessionId(mLogSessionId.getStringId());
}
}

View File

@@ -41,4 +41,6 @@ interface IMediaMetricsManager {
String getEditingSessionId(int userId);
String getBundleSessionId(int userId);
void reportBundleMetrics(in String sessionId, in PersistableBundle metrics, int userId);
void releaseSessionId(in String sessionId, int userId);
}

View File

@@ -170,6 +170,18 @@ public final class MediaMetricsManager {
}
}
/**
* Creates a generic bundle session.
*/
@NonNull
public void releaseSessionId(@NonNull String sessionId) {
try {
mService.releaseSessionId(sessionId, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Reports error event.
* @hide

View File

@@ -100,5 +100,6 @@ public final class PlaybackSession implements AutoCloseable {
@Override
public void close() {
mClosed = true;
mManager.releaseSessionId(mLogSessionId.getStringId());
}
}

View File

@@ -31,6 +31,11 @@ import java.util.Objects;
* Playback state event.
*/
public final class PlaybackStateEvent extends Event implements Parcelable {
// RBE -- we should be getting these values from the proto, not doing them
// hand-coded values here.
// frameorks/proto_logging/stats/message/mediametrics_message.pb.h
// package libstatslog?
/** Playback has not started (initial state) */
public static final int STATE_NOT_STARTED = 0;
/** Playback is buffering in the background for initial playback start */

View File

@@ -61,5 +61,6 @@ public final class RecordingSession implements AutoCloseable {
@Override
public void close() {
mClosed = true;
mManager.releaseSessionId(mLogSessionId.getStringId());
}
}

View File

@@ -59,5 +59,6 @@ public final class TranscodingSession implements AutoCloseable {
@Override
public void close() {
mManager.releaseSessionId(mLogSessionId.getStringId());
}
}

View File

@@ -19,6 +19,7 @@ package com.android.server.media.metrics;
import android.content.Context;
import android.content.pm.PackageManager;
import android.media.MediaMetrics;
import android.media.metrics.BundleSession;
import android.media.metrics.IMediaMetricsManager;
import android.media.metrics.NetworkEvent;
import android.media.metrics.PlaybackErrorEvent;
@@ -187,11 +188,33 @@ public final class MediaMetricsManagerService extends SystemService {
return;
}
int atomid = metrics.getInt("KEY_STATSD_ATOM_NUMBER");
int atomid = metrics.getInt(BundleSession.KEY_STATSD_ATOM);
switch (atomid) {
default:
return;
// to be extended as we define statsd atoms
case 322: // MediaPlaybackStateEvent
// pattern for the keys:
// <statsd event> - <fieldname>
// match types to what stats will want
String _sessionId = metrics.getString("playbackstateevent-sessionid");
int _state = metrics.getInt("playbackstateevent-state", -1);
long _lifetime = metrics.getLong("playbackstateevent-lifetime", -1);
if (_sessionId == null || _state < 0 || _lifetime < 0) {
Slog.d(TAG, "dropping incomplete data for atom 322: _sessionId: "
+ _sessionId + " _state: " + _state
+ " _lifetime: " + _lifetime);
return;
}
StatsEvent statsEvent = StatsEvent.newBuilder()
.setAtomId(322)
.writeString(_sessionId)
.writeInt(_state)
.writeLong(_lifetime)
.usePooledBuffer()
.build();
StatsLog.write(statsEvent);
return;
}
}
@@ -226,6 +249,13 @@ public final class MediaMetricsManagerService extends SystemService {
return id;
}
@Override
public void releaseSessionId(String sessionId, int userId) {
// De-authorize this session-id in the native mediametrics service.
// TODO: plumbing to the native mediametrics service
Slog.v(TAG, "Releasing sessionId " + sessionId + " for userId " + userId + " [NOP]");
}
@Override
public String getPlaybackSessionId(int userId) {
return getSessionIdInternal(userId);