Merge "MediaDrm: error detail apis"

This commit is contained in:
Robert Shih
2022-12-17 07:17:01 +00:00
committed by Gerrit Code Review
10 changed files with 243 additions and 19 deletions

View File

@@ -21304,7 +21304,7 @@ package android.media {
field public static final int ERROR_RECLAIMED = 1101; // 0x44d
}
public static final class MediaCodec.CryptoException extends java.lang.RuntimeException {
public static final class MediaCodec.CryptoException extends java.lang.RuntimeException implements android.media.MediaDrmThrowable {
ctor public MediaCodec.CryptoException(int, @Nullable String);
method public int getErrorCode();
field @Deprecated public static final int ERROR_FRAME_TOO_LARGE = 8; // 0x8
@@ -21804,7 +21804,7 @@ package android.media {
method public void setMediaDrmSession(@NonNull byte[]) throws android.media.MediaCryptoException;
}
public final class MediaCryptoException extends java.lang.Exception {
public final class MediaCryptoException extends java.lang.Exception implements android.media.MediaDrmThrowable {
ctor public MediaCryptoException(@Nullable String);
}
@@ -22027,7 +22027,7 @@ package android.media {
method public long getTimestampMillis();
}
public static final class MediaDrm.MediaDrmStateException extends java.lang.IllegalStateException {
public static final class MediaDrm.MediaDrmStateException extends java.lang.IllegalStateException implements android.media.MediaDrmThrowable {
method @NonNull public String getDiagnosticInfo();
method public int getErrorCode();
method public boolean isTransient();
@@ -22100,7 +22100,7 @@ package android.media {
@Deprecated @IntDef({android.media.MediaDrm.SECURITY_LEVEL_UNKNOWN, android.media.MediaDrm.SECURITY_LEVEL_SW_SECURE_CRYPTO, android.media.MediaDrm.SECURITY_LEVEL_SW_SECURE_DECODE, android.media.MediaDrm.SECURITY_LEVEL_HW_SECURE_CRYPTO, android.media.MediaDrm.SECURITY_LEVEL_HW_SECURE_DECODE, android.media.MediaDrm.SECURITY_LEVEL_HW_SECURE_ALL}) @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) public static @interface MediaDrm.SecurityLevel {
}
public static final class MediaDrm.SessionException extends java.lang.RuntimeException {
public static final class MediaDrm.SessionException extends java.lang.RuntimeException implements android.media.MediaDrmThrowable {
ctor public MediaDrm.SessionException(int, @Nullable String);
method @Deprecated public int getErrorCode();
method public boolean isTransient();
@@ -22108,14 +22108,20 @@ package android.media {
field @Deprecated public static final int ERROR_UNKNOWN = 0; // 0x0
}
public class MediaDrmException extends java.lang.Exception {
public class MediaDrmException extends java.lang.Exception implements android.media.MediaDrmThrowable {
ctor public MediaDrmException(String);
}
public class MediaDrmResetException extends java.lang.IllegalStateException {
public class MediaDrmResetException extends java.lang.IllegalStateException implements android.media.MediaDrmThrowable {
ctor public MediaDrmResetException(String);
}
public interface MediaDrmThrowable {
method public default int getErrorContext();
method public default int getOemError();
method public default int getVendorError();
}
public final class MediaExtractor {
ctor public MediaExtractor();
method public boolean advance();

View File

@@ -24,4 +24,11 @@ public final class DeniedByServerException extends MediaDrmException {
public DeniedByServerException(String detailMessage) {
super(detailMessage);
}
/**
* @hide
*/
public DeniedByServerException(String message, int vendorError, int oemError, int context) {
super(message, vendorError, oemError, context);
}
}

View File

@@ -2472,10 +2472,22 @@ final public class MediaCodec {
/**
* Thrown when a crypto error occurs while queueing a secure input buffer.
*/
public final static class CryptoException extends RuntimeException {
public final static class CryptoException extends RuntimeException
implements MediaDrmThrowable {
public CryptoException(int errorCode, @Nullable String detailMessage) {
super(detailMessage);
this(detailMessage, errorCode, 0, 0, 0);
}
/**
* @hide
*/
public CryptoException(String message, int errorCode, int vendorError, int oemError,
int errorContext) {
super(message);
mErrorCode = errorCode;
mVendorError = vendorError;
mOemError = oemError;
mErrorContext = errorContext;
}
/**
@@ -2594,7 +2606,22 @@ final public class MediaCodec {
return mErrorCode;
}
private int mErrorCode;
@Override
public int getVendorError() {
return mVendorError;
}
@Override
public int getOemError() {
return mOemError;
}
@Override
public int getErrorContext() {
return mErrorContext;
}
private final int mErrorCode, mVendorError, mOemError, mErrorContext;
}
/**

View File

@@ -22,8 +22,35 @@ import android.annotation.Nullable;
* Exception thrown if MediaCrypto object could not be instantiated or
* if unable to perform an operation on the MediaCrypto object.
*/
public final class MediaCryptoException extends Exception {
public final class MediaCryptoException extends Exception implements MediaDrmThrowable {
public MediaCryptoException(@Nullable String detailMessage) {
super(detailMessage);
this(detailMessage, 0, 0, 0);
}
/**
* @hide
*/
public MediaCryptoException(String message, int vendorError, int oemError, int errorContext) {
super(message);
mVendorError = vendorError;
mOemError = oemError;
mErrorContext = errorContext;
}
@Override
public int getVendorError() {
return mVendorError;
}
@Override
public int getOemError() {
return mOemError;
}
@Override
public int getErrorContext() {
return mErrorContext;
}
private final int mVendorError, mOemError, mErrorContext;
}

View File

@@ -664,21 +664,33 @@ public final class MediaDrm implements AutoCloseable {
* strategy and details about each possible return value from {@link
* MediaDrmStateException#getErrorCode()}.
*/
public static final class MediaDrmStateException extends java.lang.IllegalStateException {
private final int mErrorCode;
public static final class MediaDrmStateException extends java.lang.IllegalStateException
implements MediaDrmThrowable {
private final int mErrorCode, mVendorError, mOemError, mErrorContext;
private final String mDiagnosticInfo;
/**
* @hide
*/
public MediaDrmStateException(int errorCode, @Nullable String detailMessage) {
this(detailMessage, errorCode, 0, 0, 0);
}
/**
* @hide
*/
public MediaDrmStateException(String detailMessage, int errorCode,
int vendorError, int oemError, int errorContext) {
super(detailMessage);
mErrorCode = errorCode;
mVendorError = vendorError;
mOemError = oemError;
mErrorContext = errorContext;
// TODO get this from DRM session
final String sign = errorCode < 0 ? "neg_" : "";
mDiagnosticInfo =
"android.media.MediaDrm.error_" + sign + Math.abs(errorCode);
"android.media.MediaDrm.error_" + sign + Math.abs(errorCode);
}
@@ -696,6 +708,21 @@ public final class MediaDrm implements AutoCloseable {
return mErrorCode;
}
@Override
public int getVendorError() {
return mVendorError;
}
@Override
public int getOemError() {
return mOemError;
}
@Override
public int getErrorContext() {
return mErrorContext;
}
/**
* Returns true if the {@link MediaDrmStateException} is a transient
* issue, perhaps due to resource constraints, and that the operation
@@ -727,10 +754,22 @@ public final class MediaDrm implements AutoCloseable {
* {@link #isTransient()} to determine whether the app should retry the
* failing operation.
*/
public static final class SessionException extends RuntimeException {
public static final class SessionException extends RuntimeException
implements MediaDrmThrowable {
public SessionException(int errorCode, @Nullable String detailMessage) {
this(detailMessage, errorCode, 0, 0, 0);
}
/**
* @hide
*/
public SessionException(String detailMessage, int errorCode, int vendorError, int oemError,
int errorContext) {
super(detailMessage);
mErrorCode = errorCode;
mVendorError = vendorError;
mOemError = oemError;
mErrorContext = errorContext;
}
/**
@@ -769,6 +808,21 @@ public final class MediaDrm implements AutoCloseable {
return mErrorCode;
}
@Override
public int getVendorError() {
return mVendorError;
}
@Override
public int getOemError() {
return mOemError;
}
@Override
public int getErrorContext() {
return mErrorContext;
}
/**
* Returns true if the {@link SessionException} is a transient
* issue, perhaps due to resource constraints, and that the operation
@@ -779,7 +833,7 @@ public final class MediaDrm implements AutoCloseable {
return mErrorCode == ERROR_RESOURCE_CONTENTION;
}
private final int mErrorCode;
private final int mErrorCode, mVendorError, mOemError, mErrorContext;
}
/**

View File

@@ -19,8 +19,35 @@ package android.media;
/**
* Base class for MediaDrm exceptions
*/
public class MediaDrmException extends Exception {
public class MediaDrmException extends Exception implements MediaDrmThrowable {
public MediaDrmException(String detailMessage) {
super(detailMessage);
this(detailMessage, 0, 0, 0);
}
/**
* @hide
*/
public MediaDrmException(String message, int vendorError, int oemError, int errorContext) {
super(message);
mVendorError = vendorError;
mOemError = oemError;
mErrorContext = errorContext;
}
@Override
public int getVendorError() {
return mVendorError;
}
@Override
public int getOemError() {
return mOemError;
}
@Override
public int getErrorContext() {
return mErrorContext;
}
private final int mVendorError, mOemError, mErrorContext;
}

View File

@@ -21,7 +21,7 @@ package android.media;
* due to a restart of the mediaserver process. To continue, the app must
* release the MediaDrm object, then create and initialize a new one.
*/
public class MediaDrmResetException extends IllegalStateException {
public class MediaDrmResetException extends IllegalStateException implements MediaDrmThrowable {
public MediaDrmResetException(String detailMessage) {
super(detailMessage);
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.media;
/**
* A @{@link Throwable} thrown from {@link MediaDrm} or @{@link MediaCrypto} APIs
*/
public interface MediaDrmThrowable {
/**
* Returns {@link MediaDrm} plugin vendor defined error code associated with this {@link
* MediaDrmThrowable}.
* <p>
* Please consult the {@link MediaDrm} plugin vendor for details on the error code.
*
* @return an error code defined by the {@link MediaDrm} plugin vendor if available,
* otherwise 0.
*/
public default int getVendorError() {
return 0;
}
/**
* Returns OEM or SOC specific error code associated with this {@link
* MediaDrmThrowable}.
* <p>
* Please consult the {@link MediaDrm} plugin, chip, or device vendor for details on the
* error code.
*
* @return an OEM or SOC specific error code if available, otherwise 0.
*/
public default int getOemError() {
return 0;
}
/**
* Returns {@link MediaDrm} plugin vendor defined error context associated with this {@link
* MediaDrmThrowable}.
* <p>
* Please consult the {@link MediaDrm} plugin vendor for details on the error context.
*
* @return an opaque integer that would help the @{@link MediaDrm} vendor locate the
* source of the error if available, otherwise 0.
*/
public default int getErrorContext() {
return 0;
}
}

View File

@@ -26,4 +26,11 @@ public final class NotProvisionedException extends MediaDrmException {
public NotProvisionedException(String detailMessage) {
super(detailMessage);
}
/**
* @hide
*/
public NotProvisionedException(String message, int vendorError, int oemError, int context) {
super(message, vendorError, oemError, context);
}
}

View File

@@ -24,4 +24,11 @@ public final class ResourceBusyException extends MediaDrmException {
public ResourceBusyException(String detailMessage) {
super(detailMessage);
}
/**
* @hide
*/
public ResourceBusyException(String message, int vendorError, int oemError, int context) {
super(message, vendorError, oemError, context);
}
}