Publish Descrambler.isValidKeyToken as a static system API

Test: atest TunerTests
Bug: 173713008
Change-Id: I92fbd22f0e6a4c82d7ca1a326369fa9aa5ece17e
This commit is contained in:
Amy Zhang
2020-12-04 14:13:22 -08:00
parent 59fa0874c7
commit 8a5c57551c
3 changed files with 26 additions and 21 deletions

View File

@@ -4991,6 +4991,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
@@ -5065,7 +5066,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
@@ -5081,6 +5081,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 {

View File

@@ -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}.
*
* <p>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[])}.
*
* <p>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;
}
}

View File

@@ -166,13 +166,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.
*
* <p>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 */