blob: 23b2950e902b64fd6ea81f4dc3d698bc72da8a8c [file] [log] [blame]
aimitakeshi27ed8ad2010-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
17#ifndef __DRM_INFO_EVENT_H__
18#define __DRM_INFO_EVENT_H__
19
Takeshi Aimi5ff78362012-07-11 17:09:21 +090020#include "drm_framework_common.h"
21
aimitakeshi27ed8ad2010-07-29 10:12:27 +090022namespace android {
23
24class String8;
25
26/**
27 * This is an entity class which would be passed to caller in
28 * DrmManagerClient::OnInfoListener::onInfo(const DrmInfoEvent&).
29 */
30class DrmInfoEvent {
31public:
Takeshi Aimi2272ee22010-09-20 23:40:41 +090032 /**
33 * The following constant values should be in sync with DrmInfoEvent.java
34 */
aimitakeshi27ed8ad2010-07-29 10:12:27 +090035 //! TYPE_ALREADY_REGISTERED_BY_ANOTHER_ACCOUNT, when registration has been
36 //! already done by another account ID.
Takeshi Aimi2272ee22010-09-20 23:40:41 +090037 static const int TYPE_ALREADY_REGISTERED_BY_ANOTHER_ACCOUNT = 1;
aimitakeshi27ed8ad2010-07-29 10:12:27 +090038 //! TYPE_REMOVE_RIGHTS, when the rights needs to be removed completely.
Takeshi Aimi2272ee22010-09-20 23:40:41 +090039 static const int TYPE_REMOVE_RIGHTS = 2;
aimitakeshi27ed8ad2010-07-29 10:12:27 +090040 //! TYPE_RIGHTS_INSTALLED, when the rights are downloaded and installed ok.
Takeshi Aimi2272ee22010-09-20 23:40:41 +090041 static const int TYPE_RIGHTS_INSTALLED = 3;
aimitakeshi27ed8ad2010-07-29 10:12:27 +090042 //! TYPE_WAIT_FOR_RIGHTS, rights object is on it's way to phone,
43 //! wait before calling checkRights again
Takeshi Aimi2272ee22010-09-20 23:40:41 +090044 static const int TYPE_WAIT_FOR_RIGHTS = 4;
45 //! TYPE_ACCOUNT_ALREADY_REGISTERED, when registration has been
46 //! already done for the given account.
47 static const int TYPE_ACCOUNT_ALREADY_REGISTERED = 5;
Gloria Wang505bd992011-03-14 12:04:15 -070048 //! TYPE_RIGHTS_REMOVED, when the rights has been removed.
49 static const int TYPE_RIGHTS_REMOVED = 6;
Takeshi Aimi2272ee22010-09-20 23:40:41 +090050
51 /**
52 * The following constant values should be in sync with DrmErrorEvent.java
53 */
54 //! TYPE_RIGHTS_NOT_INSTALLED, when something went wrong installing the rights
55 static const int TYPE_RIGHTS_NOT_INSTALLED = 2001;
56 //! TYPE_RIGHTS_RENEWAL_NOT_ALLOWED, when the server rejects renewal of rights
57 static const int TYPE_RIGHTS_RENEWAL_NOT_ALLOWED = 2002;
58 //! TYPE_NOT_SUPPORTED, when answer from server can not be handled by the native agent
59 static const int TYPE_NOT_SUPPORTED = 2003;
aimitakeshi27ed8ad2010-07-29 10:12:27 +090060 //! TYPE_OUT_OF_MEMORY, when memory allocation fail during renewal.
61 //! Can in the future perhaps be used to trigger garbage collector
Takeshi Aimi2272ee22010-09-20 23:40:41 +090062 static const int TYPE_OUT_OF_MEMORY = 2004;
aimitakeshi27ed8ad2010-07-29 10:12:27 +090063 //! TYPE_NO_INTERNET_CONNECTION, when the Internet connection is missing and no attempt
64 //! can be made to renew rights
Takeshi Aimi2272ee22010-09-20 23:40:41 +090065 static const int TYPE_NO_INTERNET_CONNECTION = 2005;
Takeshi Aimie943f842010-10-08 23:05:49 +090066 //! TYPE_PROCESS_DRM_INFO_FAILED, when failed to process DrmInfo.
67 static const int TYPE_PROCESS_DRM_INFO_FAILED = 2006;
Gloria Wang505bd992011-03-14 12:04:15 -070068 //! TYPE_REMOVE_ALL_RIGHTS_FAILED, when failed to remove all the rights objects
69 //! associated with all DRM schemes.
70 static const int TYPE_REMOVE_ALL_RIGHTS_FAILED = 2007;
71 //! TYPE_ACQUIRE_DRM_INFO_FAILED, when failed to acquire DrmInfo.
72 static const int TYPE_ACQUIRE_DRM_INFO_FAILED = 2008;
aimitakeshi27ed8ad2010-07-29 10:12:27 +090073
74public:
75 /**
Takeshi Aimi5ff78362012-07-11 17:09:21 +090076 * Constructor for DrmInfoEvent.
77 * Data in drmBuffer are copied to newly allocated buffer.
aimitakeshi27ed8ad2010-07-29 10:12:27 +090078 *
79 * @param[in] uniqueId Unique session identifier
80 * @param[in] infoType Type of information
81 * @param[in] message Message description
Takeshi Aimi5ff78362012-07-11 17:09:21 +090082 * @param[in] drmBuffer Binary information
aimitakeshi27ed8ad2010-07-29 10:12:27 +090083 */
Gloria Wang79cbc132011-03-17 15:02:34 -070084 DrmInfoEvent(int uniqueId, int infoType, const String8 message);
Takeshi Aimi5ff78362012-07-11 17:09:21 +090085 DrmInfoEvent(int uniqueId, int infoType, const String8 message, const DrmBuffer& drmBuffer);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090086
87 /**
88 * Destructor for DrmInfoEvent
89 */
Takeshi Aimi5ff78362012-07-11 17:09:21 +090090 ~DrmInfoEvent();
91
92public:
93 /**
94 * Iterator for key
95 */
96 class KeyIterator {
97 friend class DrmInfoEvent;
98
99 private:
100 KeyIterator(const DrmInfoEvent* drmInfoEvent)
101 : mDrmInfoEvent(const_cast <DrmInfoEvent*> (drmInfoEvent)), mIndex(0) {}
102
103 public:
104 KeyIterator(const KeyIterator& keyIterator);
105 KeyIterator& operator=(const KeyIterator& keyIterator);
106 virtual ~KeyIterator() {}
107
108 public:
109 bool hasNext();
110 const String8& next();
111
112 private:
113 DrmInfoEvent* mDrmInfoEvent;
114 unsigned int mIndex;
115 };
116
117 /**
118 * Iterator
119 */
120 class Iterator {
121 friend class DrmInfoEvent;
122
123 private:
124 Iterator(const DrmInfoEvent* drmInfoEvent)
125 : mDrmInfoEvent(const_cast <DrmInfoEvent*> (drmInfoEvent)), mIndex(0) {}
126
127 public:
128 Iterator(const Iterator& iterator);
129 Iterator& operator=(const Iterator& iterator);
130 virtual ~Iterator() {}
131
132 public:
133 bool hasNext();
134 const String8& next();
135
136 private:
137 DrmInfoEvent* mDrmInfoEvent;
138 unsigned int mIndex;
139 };
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900140
141public:
142 /**
143 * Returns the Unique Id associated with this instance
144 *
145 * @return Unique Id
146 */
147 int getUniqueId() const;
148
149 /**
150 * Returns the Type of information associated with this object
151 *
152 * @return Type of information
153 */
154 int getType() const;
155
156 /**
157 * Returns the message description associated with this object
158 *
159 * @return Message description
160 */
Gloria Wang79cbc132011-03-17 15:02:34 -0700161 const String8 getMessage() const;
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900162
Takeshi Aimi5ff78362012-07-11 17:09:21 +0900163 /**
164 * Returns the number of attributes contained in this instance
165 *
166 * @return Number of attributes
167 */
168 int getCount() const;
169
170 /**
171 * Adds optional information as <key, value> pair to this instance
172 *
173 * @param[in] key Key to add
174 * @param[in] value Value to add
175 * @return Returns the error code
176 */
177 status_t put(const String8& key, String8& value);
178
179 /**
180 * Retrieves the value of given key
181 *
182 * @param key Key whose value to be retrieved
183 * @return The value
184 */
185 const String8 get(const String8& key) const;
186
187 /**
188 * Returns KeyIterator object to walk through the keys associated with this instance
189 *
190 * @return KeyIterator object
191 */
192 KeyIterator keyIterator() const;
193
194 /**
195 * Returns Iterator object to walk through the values associated with this instance
196 *
197 * @return Iterator object
198 */
199 Iterator iterator() const;
200
201 /**
202 * Returns the Binary information associated with this instance
203 *
204 * @return Binary information
205 */
206 const DrmBuffer& getData() const;
207
208 /**
209 * Sets the Binary information associated with this instance.
210 * Data in drmBuffer are copied to newly allocated buffer.
211 *
212 * @param[in] drmBuffer Binary information associated with this instance
213 */
214 void setData(const DrmBuffer& drmBuffer);
215
216private:
217 DrmInfoEvent(const DrmInfoEvent& ref);
218 const DrmInfoEvent& operator=(const DrmInfoEvent& ref);
219
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900220private:
221 int mUniqueId;
222 int mInfoType;
Gloria Wang79cbc132011-03-17 15:02:34 -0700223 const String8 mMessage;
Takeshi Aimi5ff78362012-07-11 17:09:21 +0900224 KeyedVector<String8, String8> mAttributes;
225 DrmBuffer mDrmBuffer;
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900226};
227
228};
229
230#endif /* __DRM_INFO_EVENT_H__ */
231