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 } 71 72 /** 73 * Retrieves the MIME type associated with this object. 74 * 75 * @return The MIME type. 76 */ getMimeType()77 public String getMimeType() { 78 return mMimeType; 79 } 80 81 /** 82 * Retrieves the information type associated with this object. 83 * 84 * @return The information type. 85 */ getInfoType()86 public int getInfoType() { 87 return mInfoType; 88 } 89 90 /** 91 * Adds optional information as key-value pairs to this object. 92 * 93 * @param key The key to add. 94 * @param value The value to add. 95 */ put(String key, Object value)96 public void put(String key, Object value) { 97 mRequestInformation.put(key, value); 98 } 99 100 /** 101 * Retrieves the value of a given key. 102 * 103 * @param key The key whose value is being retrieved. 104 * 105 * @return The value of the key that is being retrieved. Returns null if the key cannot be 106 * found. 107 */ get(String key)108 public Object get(String key) { 109 return mRequestInformation.get(key); 110 } 111 112 /** 113 * Retrieves an iterator object that you can use to iterate over the keys associated with 114 * this <code>DrmInfoRequest</code> object. 115 * 116 * @return The iterator object. 117 */ keyIterator()118 public Iterator<String> keyIterator() { 119 return mRequestInformation.keySet().iterator(); 120 } 121 122 /** 123 * Retrieves an iterator object that you can use to iterate over the values associated with 124 * this <code>DrmInfoRequest</code> object. 125 * 126 * @return The iterator object. 127 */ iterator()128 public Iterator<Object> iterator() { 129 return mRequestInformation.values().iterator(); 130 } 131 132 /** 133 * Returns whether this instance is valid or not 134 * 135 * @return 136 * true if valid 137 * false if invalid 138 */ isValid()139 boolean isValid() { 140 return (null != mMimeType && !mMimeType.equals("") 141 && null != mRequestInformation && isValidType(mInfoType)); 142 } 143 isValidType(int infoType)144 /* package */ static boolean isValidType(int infoType) { 145 boolean isValid = false; 146 147 switch (infoType) { 148 case TYPE_REGISTRATION_INFO: 149 case TYPE_UNREGISTRATION_INFO: 150 case TYPE_RIGHTS_ACQUISITION_INFO: 151 case TYPE_RIGHTS_ACQUISITION_PROGRESS_INFO: 152 isValid = true; 153 break; 154 } 155 return isValid; 156 } 157 } 158 159