diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 49204e0c2098e..2e65bf3f15c55 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -5016,6 +5016,7 @@ package android.media.tv.tuner { public class Descrambler implements java.lang.AutoCloseable { method public int addPid(int, int, @Nullable android.media.tv.tuner.filter.Filter); method public void close(); + method public static boolean isValidKeyToken(@NonNull byte[]); method public int removePid(int, int, @Nullable android.media.tv.tuner.filter.Filter); method public int setKeyToken(@NonNull byte[]); field public static final int PID_TYPE_MMTP = 2; // 0x2 @@ -5090,7 +5091,6 @@ package android.media.tv.tuner { field public static final int INVALID_FIRST_MACROBLOCK_IN_SLICE = -1; // 0xffffffff field public static final int INVALID_FRONTEND_ID = -1; // 0xffffffff field public static final int INVALID_FRONTEND_SETTING_FREQUENCY = -1; // 0xffffffff - field @NonNull public static final byte[] INVALID_KEYTOKEN; field public static final int INVALID_LTS_ID = -1; // 0xffffffff field public static final int INVALID_MMTP_RECORD_EVENT_MPT_SEQUENCE_NUM = -1; // 0xffffffff field public static final int INVALID_STREAM_ID = 65535; // 0xffff @@ -5106,6 +5106,7 @@ package android.media.tv.tuner { field public static final int SCAN_TYPE_AUTO = 1; // 0x1 field public static final int SCAN_TYPE_BLIND = 2; // 0x2 field public static final int SCAN_TYPE_UNDEFINED = 0; // 0x0 + field @NonNull public static final byte[] VOID_KEYTOKEN; } public static interface Tuner.OnResourceLostListener { diff --git a/media/java/android/media/tv/tuner/Descrambler.java b/media/java/android/media/tv/tuner/Descrambler.java index 2217eb3a1dc11..700e7beb06c67 100644 --- a/media/java/android/media/tv/tuner/Descrambler.java +++ b/media/java/android/media/tv/tuner/Descrambler.java @@ -110,14 +110,16 @@ public class Descrambler implements AutoCloseable { } /** - * Set a key token to link descrambler to a key slot + * Set a key token to link descrambler to a key slot. Use {@link isValidKeyToken(byte[])} to + * validate the key token format. Invalid key token would cause no-op and return + * {@link Tuner.RESULT_INVALID_ARGUMENT}. * *
A descrambler instance can have only one key slot to link, but a key slot can hold a few - * keys for different purposes. + * keys for different purposes. {@link Tuner.VOID_KEYTOKEN} is considered valid. * - * @param keyToken the token to be used to link the key slot. Use {@link Tuner.INVALID_KEYTOKEN} + * @param keyToken the token to be used to link the key slot. Use {@link Tuner.VOID_KEYTOKEN} * to remove the current key from descrambler. If the current keyToken comes from a - * MediaCas session, use {@link Tuner.INVALID_KEYTOKEN} to remove current key before + * MediaCas session, use {@link Tuner.VOID_KEYTOKEN} to remove current key before * closing the MediaCas session. * @return result status of the operation. */ @@ -133,6 +135,22 @@ public class Descrambler implements AutoCloseable { } } + /** + * Validate the key token format as the parameter of {@link setKeyToken(byte[])}. + * + *
The key token is expected to be less than 128 bits. + * + * @param keyToken the token to be validated. + * @return true if the given key token is a valid one. + */ + public static boolean isValidKeyToken(@NonNull byte[] keyToken) { + if (keyToken.length == 0 || keyToken.length > 16) { + Log.d(TAG, "Invalid key token size: " + (keyToken.length * 8) + " bit."); + return false; + } + return true; + } + /** * Release the descrambler instance. */ @@ -150,18 +168,4 @@ public class Descrambler implements AutoCloseable { } } } - - private boolean isValidKeyToken(byte[] keyToken) { - if (keyToken.length == 0 || keyToken.length > 16) { - Log.d(TAG, "Invalid key token size: " + (keyToken.length * 8) + " bit."); - return false; - } - for (int i = 0; i < keyToken.length; i++) { - if (keyToken[i] < 0) { - Log.d(TAG, "Invalid key token."); - return false; - } - } - return true; - } } diff --git a/media/java/android/media/tv/tuner/Tuner.java b/media/java/android/media/tv/tuner/Tuner.java index da14ee1f32123..d094c2cd3c631 100644 --- a/media/java/android/media/tv/tuner/Tuner.java +++ b/media/java/android/media/tv/tuner/Tuner.java @@ -167,13 +167,13 @@ public class Tuner implements AutoCloseable { public static final int INVALID_LNB_ID = android.hardware.tv.tuner.V1_1.Constants.Constant.INVALID_LNB_ID; /** - * Invalid key token. It is used to remove the current key from descrambler. + * A void key token. It is used to remove the current key from descrambler. * *
If the current keyToken comes from a MediaCas session, App is recommended to * to use this constant to remove current key before closing MediaCas session. */ @NonNull - public static final byte[] INVALID_KEYTOKEN = + public static final byte[] VOID_KEYTOKEN = {android.hardware.tv.tuner.V1_1.Constants.Constant.INVALID_KEYTOKEN}; /** @hide */