1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.media; 17 18 import android.annotation.NonNull; 19 import android.media.MediaDrm; 20 21 import java.util.Arrays; 22 import java.util.Objects; 23 import java.util.UUID; 24 25 /** 26 * Encapsulates initialization data required by a {@link MediaDrm} instance. 27 */ 28 public abstract class DrmInitData { 29 30 /** 31 * Prevent public constuctor access 32 */ DrmInitData()33 /* package private */ DrmInitData() { 34 } 35 36 /** 37 * Retrieves initialization data for a given DRM scheme, specified by its UUID. 38 * 39 * @param schemeUuid The DRM scheme's UUID. 40 * @return The initialization data for the scheme, or null if the scheme is not supported. 41 * @deprecated Use {@link #getSchemeInitDataCount} and {@link #getSchemeInitDataAt} instead. 42 */ 43 @Deprecated get(UUID schemeUuid)44 public abstract SchemeInitData get(UUID schemeUuid); 45 46 /** 47 * Returns the number of {@link SchemeInitData} elements available through {@link 48 * #getSchemeInitDataAt}. 49 */ getSchemeInitDataCount()50 public int getSchemeInitDataCount() { 51 return 0; 52 } 53 54 /** 55 * Returns the {@link SchemeInitData} with the given {@code index}. 56 * 57 * @param index The index of the {@link SchemeInitData} to return. 58 * @return The {@link SchemeInitData} associated with the given {@code index}. 59 * @throws IndexOutOfBoundsException If the given {@code index} is negative or greater than 60 * {@link #getSchemeInitDataCount}{@code - 1}. 61 */ getSchemeInitDataAt(int index)62 @NonNull public SchemeInitData getSchemeInitDataAt(int index) { 63 throw new IndexOutOfBoundsException(); 64 } 65 66 /** 67 * Scheme initialization data. 68 */ 69 public static final class SchemeInitData { 70 71 /** 72 * The Nil UUID, as defined in RFC 4122, section 4.1.7. 73 */ 74 @NonNull public static final UUID UUID_NIL = new UUID(0, 0); 75 76 /** 77 * The UUID associated with this scheme initialization data. May be {@link #UUID_NIL} if 78 * unknown or not applicable. 79 */ 80 @NonNull public final UUID uuid; 81 /** 82 * The mimeType of {@link #data}. 83 */ 84 public final String mimeType; 85 /** 86 * The initialization data. 87 */ 88 public final byte[] data; 89 90 /** 91 * Creates a new instance with the given values. 92 * 93 * @param uuid The UUID associated with this scheme initialization data. 94 * @param mimeType The mimeType of the initialization data. 95 * @param data The initialization data. 96 */ SchemeInitData(@onNull UUID uuid, @NonNull String mimeType, @NonNull byte[] data)97 public SchemeInitData(@NonNull UUID uuid, @NonNull String mimeType, @NonNull byte[] data) { 98 this.uuid = Objects.requireNonNull(uuid); 99 this.mimeType = Objects.requireNonNull(mimeType); 100 this.data = Objects.requireNonNull(data); 101 } 102 103 @Override equals(Object obj)104 public boolean equals(Object obj) { 105 if (!(obj instanceof SchemeInitData)) { 106 return false; 107 } 108 if (obj == this) { 109 return true; 110 } 111 112 SchemeInitData other = (SchemeInitData) obj; 113 return uuid.equals(other.uuid) 114 && mimeType.equals(other.mimeType) 115 && Arrays.equals(data, other.data); 116 } 117 118 @Override hashCode()119 public int hashCode() { 120 return uuid.hashCode() + 31 * (mimeType.hashCode() + 31 * Arrays.hashCode(data)); 121 } 122 123 } 124 125 } 126