| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 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 | /** |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 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}. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 26 | * |
| 27 | */ |
| 28 | public class DrmInfoRequest { |
| Gloria Wang | 5c96c65 | 2011-03-15 10:52:28 -0700 | [diff] [blame] | 29 | // Changes in following constants should be in sync with DrmInfoRequest.h |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 30 | /** |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 31 | * Acquires DRM server registration information. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 32 | */ |
| 33 | public static final int TYPE_REGISTRATION_INFO = 1; |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 34 | /** |
| Gloria Wang | 2980a21 | 2011-06-15 10:27:52 -0700 | [diff] [blame] | 35 | * Acquires information for unregistering the DRM server. |
| 36 | */ |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 37 | public static final int TYPE_UNREGISTRATION_INFO = 2; |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 38 | /** |
| Gloria Wang | 2980a21 | 2011-06-15 10:27:52 -0700 | [diff] [blame] | 39 | * Acquires rights information. |
| 40 | */ |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 41 | public static final int TYPE_RIGHTS_ACQUISITION_INFO = 3; |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 42 | /** |
| Gloria Wang | 2980a21 | 2011-06-15 10:27:52 -0700 | [diff] [blame] | 43 | * Acquires the progress of the rights acquisition. |
| 44 | */ |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 45 | public static final int TYPE_RIGHTS_ACQUISITION_PROGRESS_INFO = 4; |
| 46 | |
| 47 | /** |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 48 | * Key that is used to pass the unique session ID for the account or the user. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 49 | */ |
| 50 | public static final String ACCOUNT_ID = "account_id"; |
| 51 | |
| 52 | /** |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 53 | * Key that is used to pass the unique session ID for the subscription. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 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 | /** |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 62 | * Creates a <code>DrmInfoRequest</code> object with type and MIME type. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 63 | * |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 64 | * @param infoType Type of information. |
| 65 | * @param mimeType MIME type. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 66 | */ |
| 67 | public DrmInfoRequest(int infoType, String mimeType) { |
| 68 | mInfoType = infoType; |
| 69 | mMimeType = mimeType; |
| James Dong | 6c95d4f | 2012-02-14 16:27:38 -0800 | [diff] [blame] | 70 | if (!isValid()) { |
| 71 | final String msg = "infoType: " + infoType + "," + |
| 72 | "mimeType: " + mimeType; |
| 73 | throw new IllegalArgumentException(msg); |
| 74 | } |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /** |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 78 | * Retrieves the MIME type associated with this object. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 79 | * |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 80 | * @return The MIME type. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 81 | */ |
| 82 | public String getMimeType() { |
| 83 | return mMimeType; |
| 84 | } |
| 85 | |
| 86 | /** |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 87 | * Retrieves the information type associated with this object. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 88 | * |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 89 | * @return The information type. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 90 | */ |
| 91 | public int getInfoType() { |
| 92 | return mInfoType; |
| 93 | } |
| 94 | |
| 95 | /** |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 96 | * Adds optional information as key-value pairs to this object. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 97 | * |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 98 | * @param key The key to add. |
| 99 | * @param value The value to add. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 100 | */ |
| 101 | public void put(String key, Object value) { |
| 102 | mRequestInformation.put(key, value); |
| 103 | } |
| 104 | |
| 105 | /** |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 106 | * Retrieves the value of a given key. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 107 | * |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 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. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 112 | */ |
| 113 | public Object get(String key) { |
| 114 | return mRequestInformation.get(key); |
| 115 | } |
| 116 | |
| 117 | /** |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 118 | * Retrieves an iterator object that you can use to iterate over the keys associated with |
| 119 | * this <code>DrmInfoRequest</code> object. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 120 | * |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 121 | * @return The iterator object. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 122 | */ |
| 123 | public Iterator<String> keyIterator() { |
| 124 | return mRequestInformation.keySet().iterator(); |
| 125 | } |
| 126 | |
| 127 | /** |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 128 | * Retrieves an iterator object that you can use to iterate over the values associated with |
| 129 | * this <code>DrmInfoRequest</code> object. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 130 | * |
| Bill Gruber | 0e092f8 | 2011-03-17 16:04:18 -0700 | [diff] [blame] | 131 | * @return The iterator object. |
| aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 132 | */ |
| 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 | */ |
| 144 | boolean isValid() { |
| 145 | return (null != mMimeType && !mMimeType.equals("") |
| 146 | && null != mRequestInformation && isValidType(mInfoType)); |
| 147 | } |
| 148 | |
| 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 | |