blob: 621da413bf97c8f8202e32a1222fbc18826240b5 [file] [log] [blame]
aimitakeshid074e302010-07-29 10:12:27 +09001/*
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/**
Bill Gruber0e092f82011-03-17 16:04:18 -070023 * 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}.
aimitakeshid074e302010-07-29 10:12:27 +090026 *
27 */
28public class DrmInfoRequest {
Gloria Wang5c96c652011-03-15 10:52:28 -070029 // Changes in following constants should be in sync with DrmInfoRequest.h
aimitakeshid074e302010-07-29 10:12:27 +090030 /**
Bill Gruber0e092f82011-03-17 16:04:18 -070031 * Acquires DRM server registration information.
aimitakeshid074e302010-07-29 10:12:27 +090032 */
33 public static final int TYPE_REGISTRATION_INFO = 1;
Bill Gruber0e092f82011-03-17 16:04:18 -070034 /**
Gloria Wang2980a212011-06-15 10:27:52 -070035 * Acquires information for unregistering the DRM server.
36 */
aimitakeshid074e302010-07-29 10:12:27 +090037 public static final int TYPE_UNREGISTRATION_INFO = 2;
Bill Gruber0e092f82011-03-17 16:04:18 -070038 /**
Gloria Wang2980a212011-06-15 10:27:52 -070039 * Acquires rights information.
40 */
aimitakeshid074e302010-07-29 10:12:27 +090041 public static final int TYPE_RIGHTS_ACQUISITION_INFO = 3;
Bill Gruber0e092f82011-03-17 16:04:18 -070042 /**
Gloria Wang2980a212011-06-15 10:27:52 -070043 * Acquires the progress of the rights acquisition.
44 */
aimitakeshid074e302010-07-29 10:12:27 +090045 public static final int TYPE_RIGHTS_ACQUISITION_PROGRESS_INFO = 4;
46
47 /**
Bill Gruber0e092f82011-03-17 16:04:18 -070048 * Key that is used to pass the unique session ID for the account or the user.
aimitakeshid074e302010-07-29 10:12:27 +090049 */
50 public static final String ACCOUNT_ID = "account_id";
51
52 /**
Bill Gruber0e092f82011-03-17 16:04:18 -070053 * Key that is used to pass the unique session ID for the subscription.
aimitakeshid074e302010-07-29 10:12:27 +090054 */
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 Gruber0e092f82011-03-17 16:04:18 -070062 * Creates a <code>DrmInfoRequest</code> object with type and MIME type.
aimitakeshid074e302010-07-29 10:12:27 +090063 *
Bill Gruber0e092f82011-03-17 16:04:18 -070064 * @param infoType Type of information.
65 * @param mimeType MIME type.
aimitakeshid074e302010-07-29 10:12:27 +090066 */
67 public DrmInfoRequest(int infoType, String mimeType) {
68 mInfoType = infoType;
69 mMimeType = mimeType;
James Dong6c95d4f2012-02-14 16:27:38 -080070 if (!isValid()) {
71 final String msg = "infoType: " + infoType + "," +
72 "mimeType: " + mimeType;
73 throw new IllegalArgumentException(msg);
74 }
aimitakeshid074e302010-07-29 10:12:27 +090075 }
76
77 /**
Bill Gruber0e092f82011-03-17 16:04:18 -070078 * Retrieves the MIME type associated with this object.
aimitakeshid074e302010-07-29 10:12:27 +090079 *
Bill Gruber0e092f82011-03-17 16:04:18 -070080 * @return The MIME type.
aimitakeshid074e302010-07-29 10:12:27 +090081 */
82 public String getMimeType() {
83 return mMimeType;
84 }
85
86 /**
Bill Gruber0e092f82011-03-17 16:04:18 -070087 * Retrieves the information type associated with this object.
aimitakeshid074e302010-07-29 10:12:27 +090088 *
Bill Gruber0e092f82011-03-17 16:04:18 -070089 * @return The information type.
aimitakeshid074e302010-07-29 10:12:27 +090090 */
91 public int getInfoType() {
92 return mInfoType;
93 }
94
95 /**
Bill Gruber0e092f82011-03-17 16:04:18 -070096 * Adds optional information as key-value pairs to this object.
aimitakeshid074e302010-07-29 10:12:27 +090097 *
Bill Gruber0e092f82011-03-17 16:04:18 -070098 * @param key The key to add.
99 * @param value The value to add.
aimitakeshid074e302010-07-29 10:12:27 +0900100 */
101 public void put(String key, Object value) {
102 mRequestInformation.put(key, value);
103 }
104
105 /**
Bill Gruber0e092f82011-03-17 16:04:18 -0700106 * Retrieves the value of a given key.
aimitakeshid074e302010-07-29 10:12:27 +0900107 *
Bill Gruber0e092f82011-03-17 16:04:18 -0700108 * @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.
aimitakeshid074e302010-07-29 10:12:27 +0900112 */
113 public Object get(String key) {
114 return mRequestInformation.get(key);
115 }
116
117 /**
Bill Gruber0e092f82011-03-17 16:04:18 -0700118 * Retrieves an iterator object that you can use to iterate over the keys associated with
119 * this <code>DrmInfoRequest</code> object.
aimitakeshid074e302010-07-29 10:12:27 +0900120 *
Bill Gruber0e092f82011-03-17 16:04:18 -0700121 * @return The iterator object.
aimitakeshid074e302010-07-29 10:12:27 +0900122 */
123 public Iterator<String> keyIterator() {
124 return mRequestInformation.keySet().iterator();
125 }
126
127 /**
Bill Gruber0e092f82011-03-17 16:04:18 -0700128 * Retrieves an iterator object that you can use to iterate over the values associated with
129 * this <code>DrmInfoRequest</code> object.
aimitakeshid074e302010-07-29 10:12:27 +0900130 *
Bill Gruber0e092f82011-03-17 16:04:18 -0700131 * @return The iterator object.
aimitakeshid074e302010-07-29 10:12:27 +0900132 */
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