Media metrics APIs: changes based on API review

1. Added the IntDef annotation for PlaybackStateEvent#getState
2. Made event construtors private go/android-api-guidelines#parcelable-creator.
3. Improved the JavaDoc of time-related methods
4. Added the JavaDoc for TrackChangeEvent#getTrackType
5. Made MediaMetricsManager final

Fix: 183940704
Fix: 185121406

Test: atest android.media.metrics.cts
Change-Id: I9f1edc23b4e78e3ebee358945ce16539b83e1830
This commit is contained in:
shubang
2021-04-19 00:16:04 -07:00
parent bd3d2e9a7f
commit ccb090feaf
8 changed files with 49 additions and 31 deletions

View File

@@ -24637,7 +24637,6 @@ package android.media.effect {
package android.media.metrics {
public abstract class Event {
ctor protected Event(long);
method @NonNull public android.os.Bundle getMetricsBundle();
method @IntRange(from=0xffffffff) public long getTimeSinceCreatedMillis();
}
@@ -24647,7 +24646,7 @@ package android.media.metrics {
field @NonNull public static final android.media.metrics.LogSessionId LOG_SESSION_ID_NONE;
}
public class MediaMetricsManager {
public final class MediaMetricsManager {
method @NonNull public android.media.metrics.PlaybackSession createPlaybackSession();
method @NonNull public android.media.metrics.RecordingSession createRecordingSession();
field public static final long INVALID_TIMESTAMP = -1L; // 0xffffffffffffffffL

View File

@@ -32,19 +32,17 @@ public abstract class Event {
mTimeSinceCreatedMillis = MediaMetricsManager.INVALID_TIMESTAMP;
}
// TODO: remove
protected Event(long timeSinceCreatedMillis) {
mTimeSinceCreatedMillis = timeSinceCreatedMillis;
}
/* package */ Event(long timeSinceCreatedMillis, Bundle extras) {
mTimeSinceCreatedMillis = timeSinceCreatedMillis;
mMetricsBundle = extras;
}
/**
* Gets time since the corresponding instance is created in millisecond.
* Gets time since the corresponding log session is created in millisecond.
* @return the timestamp since the instance is created, or -1 if unknown.
* @see LogSessionId
* @see PlaybackSession
* @see RecordingSession
*/
@IntRange(from = -1)
public long getTimeSinceCreatedMillis() {

View File

@@ -25,7 +25,7 @@ import android.os.RemoteException;
* This class gives information about, and interacts with media metrics.
*/
@SystemService(Context.MEDIA_METRICS_SERVICE)
public class MediaMetricsManager {
public final class MediaMetricsManager {
public static final long INVALID_TIMESTAMP = -1;
private static final String TAG = "MediaMetricsManager";

View File

@@ -105,10 +105,8 @@ public final class NetworkEvent extends Event implements Parcelable {
/**
* Creates a new NetworkEvent.
*
* @hide
*/
public NetworkEvent(@NetworkType int type, long timeSinceCreatedMillis,
private NetworkEvent(@NetworkType int type, long timeSinceCreatedMillis,
@NonNull Bundle extras) {
this.mNetworkType = type;
this.mTimeSinceCreatedMillis = timeSinceCreatedMillis;
@@ -124,8 +122,11 @@ public final class NetworkEvent extends Event implements Parcelable {
}
/**
* Gets timestamp since the creation in milliseconds.
* Gets timestamp since the creation of the log session in milliseconds.
* @return the timestamp since the creation in milliseconds, or -1 if unknown.
* @see LogSessionId
* @see PlaybackSession
* @see RecordingSession
*/
@Override
@IntRange(from = -1)
@@ -177,8 +178,7 @@ public final class NetworkEvent extends Event implements Parcelable {
return 0;
}
/** @hide */
/* package-private */ NetworkEvent(@NonNull android.os.Parcel in) {
private NetworkEvent(@NonNull android.os.Parcel in) {
int type = in.readInt();
long timeSinceCreatedMillis = in.readLong();
Bundle extras = in.readBundle();
@@ -230,6 +230,7 @@ public final class NetworkEvent extends Event implements Parcelable {
* Sets timestamp since the creation in milliseconds.
* @param value the timestamp since the creation in milliseconds.
* -1 indicates the value is unknown.
* @see #getTimeSinceCreatedMillis()
*/
public @NonNull Builder setTimeSinceCreatedMillis(@IntRange(from = -1) long value) {
mTimeSinceCreatedMillis = value;

View File

@@ -150,10 +150,8 @@ public final class PlaybackErrorEvent extends Event implements Parcelable {
/**
* Creates a new PlaybackErrorEvent.
*
* @hide
*/
public PlaybackErrorEvent(
private PlaybackErrorEvent(
@Nullable String exceptionStack,
int errorCode,
int subErrorCode,
@@ -191,8 +189,10 @@ public final class PlaybackErrorEvent extends Event implements Parcelable {
}
/**
* Gets the timestamp since creation in milliseconds.
* Gets the timestamp since creation of the playback session in milliseconds.
* @return the timestamp since the playback is created, or -1 if unknown.
* @see LogSessionId
* @see PlaybackSession
*/
@Override
@IntRange(from = -1)
@@ -254,8 +254,7 @@ public final class PlaybackErrorEvent extends Event implements Parcelable {
return 0;
}
/** @hide */
/* package-private */ PlaybackErrorEvent(@NonNull Parcel in) {
private PlaybackErrorEvent(@NonNull Parcel in) {
byte flg = in.readByte();
String exceptionStack = (flg & 0x1) == 0 ? null : in.readString();
int errorCode = in.readInt();
@@ -330,6 +329,7 @@ public final class PlaybackErrorEvent extends Event implements Parcelable {
* Set the timestamp since creation in milliseconds.
* @param value the timestamp since the creation in milliseconds.
* -1 indicates the value is unknown.
* @see #getTimeSinceCreatedMillis()
*/
public @NonNull Builder setTimeSinceCreatedMillis(@IntRange(from = -1) long value) {
mTimeSinceCreatedMillis = value;

View File

@@ -213,6 +213,7 @@ public final class PlaybackMetrics implements Parcelable {
/**
* Gets the media duration in milliseconds.
* <p>Media duration is the length of the media.
* @return the media duration in milliseconds, or -1 if unknown.
*/
@IntRange(from = -1)
@@ -328,6 +329,8 @@ public final class PlaybackMetrics implements Parcelable {
/**
* Gets network transfer duration in milliseconds.
* <p>Total transfer time spent reading from the network in ms. For parallel requests, the
* overlapping time intervals are counted only once.
*/
@IntRange(from = -1)
public long getNetworkTransferDurationMillis() {
@@ -523,6 +526,7 @@ public final class PlaybackMetrics implements Parcelable {
/**
* Sets the media duration in milliseconds.
* @param value the media duration in milliseconds. -1 indicates the value is unknown.
* @see #getMediaDurationMillis()
*/
public @NonNull Builder setMediaDurationMillis(@IntRange(from = -1) long value) {
mMediaDurationMillis = value;
@@ -645,6 +649,7 @@ public final class PlaybackMetrics implements Parcelable {
* Sets the network transfer duration in milliseconds.
* @param value the network transfer duration in milliseconds.
* -1 indicates the value is unknown.
* @see #getNetworkTransferDurationMillis()
*/
public @NonNull Builder setNetworkTransferDurationMillis(@IntRange(from = -1) long value) {
mNetworkTransferDurationMillis = value;

View File

@@ -132,10 +132,8 @@ public final class PlaybackStateEvent extends Event implements Parcelable {
/**
* Creates a new PlaybackStateEvent.
*
* @hide
*/
public PlaybackStateEvent(
private PlaybackStateEvent(
int state,
long timeSinceCreatedMillis,
@NonNull Bundle extras) {
@@ -147,13 +145,16 @@ public final class PlaybackStateEvent extends Event implements Parcelable {
/**
* Gets playback state.
*/
@State
public int getState() {
return mState;
}
/**
* Gets time since the corresponding playback is created in millisecond.
* Gets time since the corresponding playback session is created in millisecond.
* @return the timestamp since the playback is created, or -1 if unknown.
* @see LogSessionId
* @see PlaybackSession
*/
@Override
@IntRange(from = -1)
@@ -197,8 +198,7 @@ public final class PlaybackStateEvent extends Event implements Parcelable {
return 0;
}
/** @hide */
/* package-private */ PlaybackStateEvent(@NonNull Parcel in) {
private PlaybackStateEvent(@NonNull Parcel in) {
int state = in.readInt();
long timeSinceCreatedMillis = in.readLong();
Bundle extras = in.readBundle();
@@ -247,6 +247,7 @@ public final class PlaybackStateEvent extends Event implements Parcelable {
* Sets timestamp since the creation in milliseconds.
* @param value the timestamp since the creation in milliseconds.
* -1 indicates the value is unknown.
* @see #getTimeSinceCreatedMillis()
*/
public @NonNull Builder setTimeSinceCreatedMillis(@IntRange(from = -1) long value) {
mTimeSinceCreatedMillis = value;

View File

@@ -184,8 +184,11 @@ public final class TrackChangeEvent extends Event implements Parcelable {
}
/**
* Gets timestamp since the creation in milliseconds.
* Gets timestamp since the creation of the log session in milliseconds.
* @return the timestamp since the creation in milliseconds, or -1 if unknown.
* @see LogSessionId
* @see PlaybackSession
* @see RecordingSession
*/
@Override
@IntRange(from = -1)
@@ -193,6 +196,11 @@ public final class TrackChangeEvent extends Event implements Parcelable {
return mTimeSinceCreatedMillis;
}
/**
* Gets the track type.
* <p>The track type must be one of {@link #TRACK_TYPE_AUDIO}, {@link #TRACK_TYPE_VIDEO},
* {@link #TRACK_TYPE_TEXT}.
*/
@TrackType
public int getTrackType() {
return mType;
@@ -302,8 +310,7 @@ public final class TrackChangeEvent extends Event implements Parcelable {
return 0;
}
/** @hide */
/* package-private */ TrackChangeEvent(@NonNull Parcel in) {
private TrackChangeEvent(@NonNull Parcel in) {
int flg = in.readInt();
int state = in.readInt();
int reason = in.readInt();
@@ -429,8 +436,14 @@ public final class TrackChangeEvent extends Event implements Parcelable {
/**
* Creates a new Builder.
* @param type the track type. It must be one of {@link #TRACK_TYPE_AUDIO},
* {@link #TRACK_TYPE_VIDEO}, {@link #TRACK_TYPE_TEXT}.
*/
public Builder(int type) {
public Builder(@TrackType int type) {
if (type != TRACK_TYPE_AUDIO && type != TRACK_TYPE_VIDEO && type != TRACK_TYPE_TEXT) {
throw new IllegalArgumentException("track type must be one of TRACK_TYPE_AUDIO, "
+ "TRACK_TYPE_VIDEO, TRACK_TYPE_TEXT.");
}
mType = type;
}
@@ -499,6 +512,7 @@ public final class TrackChangeEvent extends Event implements Parcelable {
* Sets timestamp since the creation in milliseconds.
* @param value the timestamp since the creation in milliseconds.
* -1 indicates the value is unknown.
* @see #getTimeSinceCreatedMillis()
*/
public @NonNull Builder setTimeSinceCreatedMillis(@IntRange(from = -1) long value) {
checkNotUsed();