diff --git a/core/api/current.txt b/core/api/current.txt index 1cced82ac65a4..0e64a9d14fae5 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -24100,9 +24100,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 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); } diff --git a/media/java/android/media/metrics/PlaybackErrorEvent.java b/media/java/android/media/metrics/PlaybackErrorEvent.java index db7000536299b..5a0820d16cb9e 100644 --- a/media/java/android/media/metrics/PlaybackErrorEvent.java +++ b/media/java/android/media/metrics/PlaybackErrorEvent.java @@ -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 CREATOR = new Parcelable.Creator() { @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; } } diff --git a/media/java/android/media/metrics/PlaybackSession.java b/media/java/android/media/metrics/PlaybackSession.java index 7f3450bcd12ff..4cb957f4e597d 100644 --- a/media/java/android/media/metrics/PlaybackSession.java +++ b/media/java/android/media/metrics/PlaybackSession.java @@ -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); } diff --git a/services/core/java/com/android/server/media/metrics/MediaMetricsManagerService.java b/services/core/java/com/android/server/media/metrics/MediaMetricsManagerService.java index 76bdf44e9df21..4f4b4f259762b 100644 --- a/services/core/java/com/android/server/media/metrics/MediaMetricsManagerService.java +++ b/services/core/java/com/android/server/media/metrics/MediaMetricsManagerService.java @@ -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);