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