1 /* 2 * Copyright (C) 2010 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 17 package android.drm; 18 19 import java.util.HashMap; 20 import java.util.Iterator; 21 22 /** 23 * An entity class that is used to pass information to an online DRM server. An instance of this 24 * class is passed to the {@link DrmManagerClient#acquireDrmInfo acquireDrmInfo()} method to get an 25 * instance of a {@link DrmInfo}. 26 * 27 * @deprecated Please use {@link android.media.MediaDrm} 28 */ 29 @Deprecated 30 public class DrmInfoRequest { 31 // Changes in following constants should be in sync with DrmInfoRequest.h 32 /** 33 * Acquires DRM server registration information. 34 */ 35 public static final int TYPE_REGISTRATION_INFO = 1; 36 /** 37 * Acquires information for unregistering the DRM server. 38 */ 39 public static final int TYPE_UNREGISTRATION_INFO = 2; 40 /** 41 * Acquires rights information. 42 */ 43 public static final int TYPE_RIGHTS_ACQUISITION_INFO = 3; 44 /** 45 * Acquires the progress of the rights acquisition. 46 */ 47 public static final int TYPE_RIGHTS_ACQUISITION_PROGRESS_INFO = 4; 48 49 /** 50 * Key that is used to pass the unique session ID for the account or the user. 51 */ 52 public static final String ACCOUNT_ID = "account_id"; 53 54 /** 55 * Key that is used to pass the unique session ID for the subscription. 56 */ 57 public static final String SUBSCRIPTION_ID = "subscription_id"; 58 59 private final int mInfoType; 60 private final String mMimeType; 61 private final HashMap<String, Object> mRequestInformation = new HashMap<String, Object>(); 62 63 /** 64 * Creates a <code>DrmInfoRequest</code> object with type and MIME type. 65 * 66 * @param infoType Type of information. 67 * @param mimeType MIME type. 68 */ DrmInfoRequest(int infoType, String mimeType)69 public DrmInfoRequest(int infoType, String mimeType) { 70 mInfoType = infoType; 71 mMimeType = mimeType; 72 if (!isValid()) { 73 final String msg = "infoType: " + infoType + "," + 74 "mimeType: " + mimeType; 75 throw new IllegalArgumentException(msg); 76 } 77 } 78 79 /** 80 * Retrieves the MIME type associated with this object. 81 * 82 * @return The MIME type. 83 */ getMimeType()84 public String getMimeType() { 85 return mMimeType; 86 } 87 88 /** 89 * Retrieves the information type associated with this object. 90 * 91 * @return The information type. 92 */ getInfoType()93 public int getInfoType() { 94 return mInfoType; 95 } 96 97 /** 98 * Adds optional information as key-value pairs to this object. 99 * 100 * @param key The key to add. 101 * @param value The value to add. 102 */ put(String key, Object value)103 public void put(String key, Object value) { 104 mRequestInformation.put(key, value); 105 } 106 107 /** 108 * Retrieves the value of a given key. 109 * 110 * @param key The key whose value is being retrieved. 111 * 112 * @return The value of the key that is being retrieved. Returns null if the key cannot be 113 * found. 114 */ get(String key)115 public Object get(String key) { 116 return mRequestInformation.get(key); 117 } 118 119 /** 120 * Retrieves an iterator object that you can use to iterate over the keys associated with 121 * this <code>DrmInfoRequest</code> object. 122 * 123 * @return The iterator object. 124 */ keyIterator()125 public Iterator<String> keyIterator() { 126 return mRequestInformation.keySet().iterator(); 127 } 128 129 /** 130 * Retrieves an iterator object that you can use to iterate over the values associated with 131 * this <code>DrmInfoRequest</code> object. 132 * 133 * @return The iterator object. 134 */ iterator()135 public Iterator<Object> iterator() { 136 return mRequestInformation.values().iterator(); 137 } 138 139 /** 140 * Returns whether this instance is valid or not 141 * 142 * @return 143 * true if valid 144 * false if invalid 145 */ isValid()146 boolean isValid() { 147 return (null != mMimeType && !mMimeType.equals("") 148 && null != mRequestInformation && isValidType(mInfoType)); 149 } 150 isValidType(int infoType)151 /* package */ static boolean isValidType(int infoType) { 152 boolean isValid = false; 153 154 switch (infoType) { 155 case TYPE_REGISTRATION_INFO: 156 case TYPE_UNREGISTRATION_INFO: 157 case TYPE_RIGHTS_ACQUISITION_INFO: 158 case TYPE_RIGHTS_ACQUISITION_PROGRESS_INFO: 159 isValid = true; 160 break; 161 } 162 return isValid; 163 } 164 } 165 166