Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 799b044d authored by Amy Zhang's avatar Amy Zhang Committed by Android (Google) Code Review
Browse files

Merge "Publish Descrambler.isValidKeyToken as a static system API"

parents d033f30a 8a5c5755
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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 {
+22 −18
Original line number Diff line number Diff line
@@ -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;
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -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.
     *
     * <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 */