DrmInfoRequest.java revision 5c96c65f692f8c2297d213c88450dd601d2b5c1f
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 17package android.drm; 18 19import java.util.HashMap; 20import java.util.Iterator; 21 22/** 23 * This is an entity class used to pass required parameters to get 24 * the necessary information to communicate with online DRM server 25 * 26 * An instance of this class is passed to {@link DrmManagerClient#acquireDrmInfo(DrmInfoRequest)} 27 * to get the instance of {@link DrmInfo} 28 * 29 */ 30public class DrmInfoRequest { 31 // Changes in following constants should be in sync with DrmInfoRequest.h 32 /** 33 * Constants defines the type of {@link DrmInfoRequest} 34 */ 35 public static final int TYPE_REGISTRATION_INFO = 1; 36 public static final int TYPE_UNREGISTRATION_INFO = 2; 37 public static final int TYPE_RIGHTS_ACQUISITION_INFO = 3; 38 public static final int TYPE_RIGHTS_ACQUISITION_PROGRESS_INFO = 4; 39 40 /** 41 * Key to pass the unique id for the account or the user 42 */ 43 public static final String ACCOUNT_ID = "account_id"; 44 45 /** 46 * Key to pass the unique id used for subscription 47 */ 48 public static final String SUBSCRIPTION_ID = "subscription_id"; 49 50 private final int mInfoType; 51 private final String mMimeType; 52 private final HashMap<String, Object> mRequestInformation = new HashMap<String, Object>(); 53 54 /** 55 * constructor to create DrmInfoRequest object with type and mimetype 56 * 57 * @param infoType Type of information 58 * @param mimeType MIME type 59 */ 60 public DrmInfoRequest(int infoType, String mimeType) { 61 mInfoType = infoType; 62 mMimeType = mimeType; 63 } 64 65 /** 66 * Returns the mimetype associated with this object 67 * 68 * @return MIME type 69 */ 70 public String getMimeType() { 71 return mMimeType; 72 } 73 74 /** 75 * Returns Information type associated with this instance 76 * 77 * @return Information type 78 */ 79 public int getInfoType() { 80 return mInfoType; 81 } 82 83 /** 84 * Adds optional information as <key, value> pair to this object. 85 * 86 * @param key Key to add 87 * @param value Value to add 88 */ 89 public void put(String key, Object value) { 90 mRequestInformation.put(key, value); 91 } 92 93 /** 94 * Retrieves the value of given key, if not found returns null 95 * 96 * @param key Key whose value to be retrieved 97 * @return The value or null 98 */ 99 public Object get(String key) { 100 return mRequestInformation.get(key); 101 } 102 103 /** 104 * Returns Iterator object to walk through the keys associated with this instance 105 * 106 * @return Iterator object 107 */ 108 public Iterator<String> keyIterator() { 109 return mRequestInformation.keySet().iterator(); 110 } 111 112 /** 113 * Returns Iterator object to walk through the values associated with this instance 114 * 115 * @return Iterator object 116 */ 117 public Iterator<Object> iterator() { 118 return mRequestInformation.values().iterator(); 119 } 120 121 /** 122 * Returns whether this instance is valid or not 123 * 124 * @return 125 * true if valid 126 * false if invalid 127 */ 128 boolean isValid() { 129 return (null != mMimeType && !mMimeType.equals("") 130 && null != mRequestInformation && isValidType(mInfoType)); 131 } 132 133 /* package */ static boolean isValidType(int infoType) { 134 boolean isValid = false; 135 136 switch (infoType) { 137 case TYPE_REGISTRATION_INFO: 138 case TYPE_UNREGISTRATION_INFO: 139 case TYPE_RIGHTS_ACQUISITION_INFO: 140 case TYPE_RIGHTS_ACQUISITION_PROGRESS_INFO: 141 isValid = true; 142 break; 143 } 144 return isValid; 145 } 146} 147 148