diff options
| author | 2022-12-05 13:38:09 -0800 | |
|---|---|---|
| committer | 2022-12-16 11:22:49 -0800 | |
| commit | 3754ac81bbafbe9f7903527fc1059ef4b43a0144 (patch) | |
| tree | 9c715caeeb4523019329b149014caf689df13ce5 | |
| parent | eefbc6216c39aa94ba79a7315cca670e518dbac3 (diff) | |
MediaDrm: error detail apis
Bug: 249941041
Test: MediaDrmTest
Change-Id: Ie0629051b8e5754d6326a9c51d1be94f876a844c
| -rw-r--r-- | core/api/current.txt | 18 | ||||
| -rw-r--r-- | media/java/android/media/DeniedByServerException.java | 7 | ||||
| -rw-r--r-- | media/java/android/media/MediaCodec.java | 33 | ||||
| -rw-r--r-- | media/java/android/media/MediaCryptoException.java | 31 | ||||
| -rw-r--r-- | media/java/android/media/MediaDrm.java | 64 | ||||
| -rw-r--r-- | media/java/android/media/MediaDrmException.java | 31 | ||||
| -rw-r--r-- | media/java/android/media/MediaDrmResetException.java | 2 | ||||
| -rw-r--r-- | media/java/android/media/MediaDrmThrowable.java | 62 | ||||
| -rw-r--r-- | media/java/android/media/NotProvisionedException.java | 7 | ||||
| -rw-r--r-- | media/java/android/media/ResourceBusyException.java | 7 |
10 files changed, 243 insertions, 19 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 7acd940e1c57..e3ec90ed4e55 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -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(); diff --git a/media/java/android/media/DeniedByServerException.java b/media/java/android/media/DeniedByServerException.java index 9c1633adca97..98903ec1439f 100644 --- a/media/java/android/media/DeniedByServerException.java +++ b/media/java/android/media/DeniedByServerException.java @@ -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); + } } diff --git a/media/java/android/media/MediaCodec.java b/media/java/android/media/MediaCodec.java index 220232d6e38f..8e8ed6c7acec 100644 --- a/media/java/android/media/MediaCodec.java +++ b/media/java/android/media/MediaCodec.java @@ -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; } /** diff --git a/media/java/android/media/MediaCryptoException.java b/media/java/android/media/MediaCryptoException.java index 32ddf4733b55..2a472fbfdfc3 100644 --- a/media/java/android/media/MediaCryptoException.java +++ b/media/java/android/media/MediaCryptoException.java @@ -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; } diff --git a/media/java/android/media/MediaDrm.java b/media/java/android/media/MediaDrm.java index 2a04ebb1efec..a3fa43d687c3 100644 --- a/media/java/android/media/MediaDrm.java +++ b/media/java/android/media/MediaDrm.java @@ -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; } /** diff --git a/media/java/android/media/MediaDrmException.java b/media/java/android/media/MediaDrmException.java index d547574e177b..58c5dd057731 100644 --- a/media/java/android/media/MediaDrmException.java +++ b/media/java/android/media/MediaDrmException.java @@ -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; } diff --git a/media/java/android/media/MediaDrmResetException.java b/media/java/android/media/MediaDrmResetException.java index 3b2da1e8bd25..ccd723bb614b 100644 --- a/media/java/android/media/MediaDrmResetException.java +++ b/media/java/android/media/MediaDrmResetException.java @@ -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); } diff --git a/media/java/android/media/MediaDrmThrowable.java b/media/java/android/media/MediaDrmThrowable.java new file mode 100644 index 000000000000..38480d79c3b3 --- /dev/null +++ b/media/java/android/media/MediaDrmThrowable.java @@ -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; + } + +} diff --git a/media/java/android/media/NotProvisionedException.java b/media/java/android/media/NotProvisionedException.java index 32b8151a4d47..4b5a816c6642 100644 --- a/media/java/android/media/NotProvisionedException.java +++ b/media/java/android/media/NotProvisionedException.java @@ -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); + } } diff --git a/media/java/android/media/ResourceBusyException.java b/media/java/android/media/ResourceBusyException.java index a5abe2119e00..7aaf7ebc1142 100644 --- a/media/java/android/media/ResourceBusyException.java +++ b/media/java/android/media/ResourceBusyException.java @@ -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); + } } |