Merge "Unhide media metrics APIs part 2: Error event" into sc-dev

This commit is contained in:
Shubang Lu
2021-02-17 18:06:09 +00:00
committed by Android (Google) Code Review
4 changed files with 67 additions and 33 deletions

View File

@@ -24100,9 +24100,30 @@ package android.media.metrics {
field public static final long INVALID_TIMESTAMP = -1L; // 0xffffffffffffffffL field public static final long INVALID_TIMESTAMP = -1L; // 0xffffffffffffffffL
} }
public final class PlaybackErrorEvent extends android.media.metrics.Event implements android.os.Parcelable {
method public int describeContents();
method public int getErrorCode();
method @IntRange(from=java.lang.Integer.MIN_VALUE, to=java.lang.Integer.MAX_VALUE) public int getSubErrorCode();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.media.metrics.PlaybackErrorEvent> CREATOR;
field public static final int ERROR_CODE_OTHER = 1; // 0x1
field public static final int ERROR_CODE_RUNTIME = 2; // 0x2
field public static final int ERROR_CODE_UNKNOWN = 0; // 0x0
}
public static final class PlaybackErrorEvent.Builder {
ctor public PlaybackErrorEvent.Builder();
method @NonNull public android.media.metrics.PlaybackErrorEvent build();
method @NonNull public android.media.metrics.PlaybackErrorEvent.Builder setErrorCode(int);
method @NonNull public android.media.metrics.PlaybackErrorEvent.Builder setException(@NonNull Exception);
method @NonNull public android.media.metrics.PlaybackErrorEvent.Builder setSubErrorCode(@IntRange(from=java.lang.Integer.MIN_VALUE, to=java.lang.Integer.MAX_VALUE) int);
method @NonNull public android.media.metrics.PlaybackErrorEvent.Builder setTimeSinceCreatedMillis(@IntRange(from=0xffffffff) long);
}
public final class PlaybackSession implements java.lang.AutoCloseable { public final class PlaybackSession implements java.lang.AutoCloseable {
method public void close(); method public void close();
method @NonNull public String getId(); method @NonNull public String getId();
method public void reportPlaybackErrorEvent(@NonNull android.media.metrics.PlaybackErrorEvent);
method public void reportPlaybackStateEvent(@NonNull android.media.metrics.PlaybackStateEvent); method public void reportPlaybackStateEvent(@NonNull android.media.metrics.PlaybackStateEvent);
} }

View File

@@ -17,8 +17,10 @@
package android.media.metrics; package android.media.metrics;
import android.annotation.IntDef; import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
@@ -27,17 +29,19 @@ import java.util.Objects;
/** /**
* Playback error event. * Playback error event.
* @hide
*/ */
public final class PlaybackErrorEvent implements Parcelable { public final class PlaybackErrorEvent extends Event implements Parcelable {
/** Unknown error code. */
public static final int ERROR_CODE_UNKNOWN = 0; public static final int ERROR_CODE_UNKNOWN = 0;
/** Error code for other errors */
public static final int ERROR_CODE_OTHER = 1; public static final int ERROR_CODE_OTHER = 1;
/** Error code for runtime errors */
public static final int ERROR_CODE_RUNTIME = 2; public static final int ERROR_CODE_RUNTIME = 2;
private final @Nullable String mExceptionStack; private final @Nullable String mExceptionStack;
private final int mErrorCode; private final int mErrorCode;
private final int mSubErrorCode; private final int mSubErrorCode;
private final long mTimeSincePlaybackCreatedMillis; private final long mTimeSinceCreatedMillis;
/** @hide */ /** @hide */
@@ -59,11 +63,11 @@ public final class PlaybackErrorEvent implements Parcelable {
@Nullable String exceptionStack, @Nullable String exceptionStack,
int errorCode, int errorCode,
int subErrorCode, int subErrorCode,
long timeSincePlaybackCreatedMillis) { long timeSinceCreatedMillis) {
this.mExceptionStack = exceptionStack; this.mExceptionStack = exceptionStack;
this.mErrorCode = errorCode; this.mErrorCode = errorCode;
this.mSubErrorCode = subErrorCode; this.mSubErrorCode = subErrorCode;
this.mTimeSincePlaybackCreatedMillis = timeSincePlaybackCreatedMillis; this.mTimeSinceCreatedMillis = timeSinceCreatedMillis;
} }
/** @hide */ /** @hide */
@@ -72,17 +76,32 @@ public final class PlaybackErrorEvent implements Parcelable {
return mExceptionStack; return mExceptionStack;
} }
/**
* Gets error code.
*/
@ErrorCode @ErrorCode
public int getErrorCode() { public int getErrorCode() {
return mErrorCode; return mErrorCode;
} }
/**
* Gets sub error code.
*/
@IntRange(from = Integer.MIN_VALUE, to = Integer.MAX_VALUE)
public int getSubErrorCode() { public int getSubErrorCode() {
return mSubErrorCode; return mSubErrorCode;
} }
public long getTimeSincePlaybackCreatedMillis() { /**
return mTimeSincePlaybackCreatedMillis; * Gets the timestamp since creation in milliseconds.
* @return the timestamp since the playback is created, or -1 if unknown.
*/
@Override
@IntRange(from = -1)
public long getTimeSinceCreatedMillis() {
return mTimeSinceCreatedMillis;
} }
@Override @Override
@@ -91,7 +110,7 @@ public final class PlaybackErrorEvent implements Parcelable {
+ "exceptionStack = " + mExceptionStack + ", " + "exceptionStack = " + mExceptionStack + ", "
+ "errorCode = " + mErrorCode + ", " + "errorCode = " + mErrorCode + ", "
+ "subErrorCode = " + mSubErrorCode + ", " + "subErrorCode = " + mSubErrorCode + ", "
+ "timeSincePlaybackCreatedMillis = " + mTimeSincePlaybackCreatedMillis + "timeSinceCreatedMillis = " + mTimeSinceCreatedMillis
+ " }"; + " }";
} }
@@ -103,13 +122,13 @@ public final class PlaybackErrorEvent implements Parcelable {
return Objects.equals(mExceptionStack, that.mExceptionStack) return Objects.equals(mExceptionStack, that.mExceptionStack)
&& mErrorCode == that.mErrorCode && mErrorCode == that.mErrorCode
&& mSubErrorCode == that.mSubErrorCode && mSubErrorCode == that.mSubErrorCode
&& mTimeSincePlaybackCreatedMillis == that.mTimeSincePlaybackCreatedMillis; && mTimeSinceCreatedMillis == that.mTimeSinceCreatedMillis;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(mExceptionStack, mErrorCode, mSubErrorCode, return Objects.hash(mExceptionStack, mErrorCode, mSubErrorCode,
mTimeSincePlaybackCreatedMillis); mTimeSinceCreatedMillis);
} }
@Override @Override
@@ -120,7 +139,7 @@ public final class PlaybackErrorEvent implements Parcelable {
if (mExceptionStack != null) dest.writeString(mExceptionStack); if (mExceptionStack != null) dest.writeString(mExceptionStack);
dest.writeInt(mErrorCode); dest.writeInt(mErrorCode);
dest.writeInt(mSubErrorCode); dest.writeInt(mSubErrorCode);
dest.writeLong(mTimeSincePlaybackCreatedMillis); dest.writeLong(mTimeSinceCreatedMillis);
} }
@Override @Override
@@ -134,14 +153,15 @@ public final class PlaybackErrorEvent implements Parcelable {
String exceptionStack = (flg & 0x1) == 0 ? null : in.readString(); String exceptionStack = (flg & 0x1) == 0 ? null : in.readString();
int errorCode = in.readInt(); int errorCode = in.readInt();
int subErrorCode = in.readInt(); int subErrorCode = in.readInt();
long timeSincePlaybackCreatedMillis = in.readLong(); long timeSinceCreatedMillis = in.readLong();
this.mExceptionStack = exceptionStack; this.mExceptionStack = exceptionStack;
this.mErrorCode = errorCode; this.mErrorCode = errorCode;
this.mSubErrorCode = subErrorCode; this.mSubErrorCode = subErrorCode;
this.mTimeSincePlaybackCreatedMillis = timeSincePlaybackCreatedMillis; this.mTimeSinceCreatedMillis = timeSinceCreatedMillis;
} }
public static final @NonNull Parcelable.Creator<PlaybackErrorEvent> CREATOR = public static final @NonNull Parcelable.Creator<PlaybackErrorEvent> CREATOR =
new Parcelable.Creator<PlaybackErrorEvent>() { new Parcelable.Creator<PlaybackErrorEvent>() {
@Override @Override
@@ -162,27 +182,18 @@ public final class PlaybackErrorEvent implements Parcelable {
private @Nullable Exception mException; private @Nullable Exception mException;
private int mErrorCode; private int mErrorCode;
private int mSubErrorCode; private int mSubErrorCode;
private long mTimeSincePlaybackCreatedMillis; private long mTimeSinceCreatedMillis = -1;
/** /**
* Creates a new Builder. * Creates a new Builder.
*
* @hide
*/ */
public Builder( public Builder() {
@Nullable Exception exception,
int errorCode,
int subErrorCode,
long timeSincePlaybackCreatedMillis) {
mException = exception;
mErrorCode = errorCode;
mSubErrorCode = subErrorCode;
mTimeSincePlaybackCreatedMillis = timeSincePlaybackCreatedMillis;
} }
/** /**
* Sets the {@link Exception} object. * Sets the {@link Exception} object.
*/ */
@SuppressLint("MissingGetterMatchingBuilder") // Exception is not parcelable.
public @NonNull Builder setException(@NonNull Exception value) { public @NonNull Builder setException(@NonNull Exception value) {
mException = value; mException = value;
return this; return this;
@@ -199,16 +210,19 @@ public final class PlaybackErrorEvent implements Parcelable {
/** /**
* Sets sub error code. * Sets sub error code.
*/ */
public @NonNull Builder setSubErrorCode(int value) { public @NonNull Builder setSubErrorCode(
@IntRange(from = Integer.MIN_VALUE, to = Integer.MAX_VALUE) int value) {
mSubErrorCode = value; mSubErrorCode = value;
return this; return this;
} }
/** /**
* Set the timestamp in milliseconds. * Set the timestamp since creation in milliseconds.
* @param value the timestamp since the creation in milliseconds.
* -1 indicates the value is unknown.
*/ */
public @NonNull Builder setTimeSincePlaybackCreatedMillis(long value) { public @NonNull Builder setTimeSinceCreatedMillis(@IntRange(from = -1) long value) {
mTimeSincePlaybackCreatedMillis = value; mTimeSinceCreatedMillis = value;
return this; return this;
} }
@@ -227,7 +241,7 @@ public final class PlaybackErrorEvent implements Parcelable {
stack, stack,
mErrorCode, mErrorCode,
mSubErrorCode, mSubErrorCode,
mTimeSincePlaybackCreatedMillis); mTimeSinceCreatedMillis);
return o; return o;
} }
} }

View File

@@ -53,9 +53,8 @@ public final class PlaybackSession implements AutoCloseable {
/** /**
* Reports error event. * Reports error event.
* @hide
*/ */
public void reportPlaybackErrorEvent(PlaybackErrorEvent event) { public void reportPlaybackErrorEvent(@NonNull PlaybackErrorEvent event) {
mManager.reportPlaybackErrorEvent(mId, event); mManager.reportPlaybackErrorEvent(mId, event);
} }

View File

@@ -110,7 +110,7 @@ public final class MediaMetricsManagerService extends SystemService {
.writeString(event.getExceptionStack()) .writeString(event.getExceptionStack())
.writeInt(event.getErrorCode()) .writeInt(event.getErrorCode())
.writeInt(event.getSubErrorCode()) .writeInt(event.getSubErrorCode())
.writeLong(event.getTimeSincePlaybackCreatedMillis()) .writeLong(event.getTimeSinceCreatedMillis())
.usePooledBuffer() .usePooledBuffer()
.build(); .build();
StatsLog.write(statsEvent); StatsLog.write(statsEvent);