Unhide media metrics APIs part 2: Error event

Bug: 167036690
Test: mmm
Change-Id: I4cdc70eab8a9c92b35d745441008e330c53b7622
This commit is contained in:
shubang
2021-01-27 18:16:23 -08:00
parent 857efd19a4
commit 9fa5a1ac92
4 changed files with 67 additions and 33 deletions

View File

@@ -24085,9 +24085,30 @@ package android.media.metrics {
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 {
method public void close();
method @NonNull public String getId();
method public void reportPlaybackErrorEvent(@NonNull android.media.metrics.PlaybackErrorEvent);
method public void reportPlaybackStateEvent(@NonNull android.media.metrics.PlaybackStateEvent);
}

View File

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

View File

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

View File

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