aimitakeshi | 27ed8ad | 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 | #ifndef __DRM_INFO_EVENT_H__ |
| 18 | #define __DRM_INFO_EVENT_H__ |
| 19 | |
Takeshi Aimi | 5ff7836 | 2012-07-11 17:09:21 +0900 | [diff] [blame] | 20 | #include "drm_framework_common.h" |
| 21 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 22 | namespace android { |
| 23 | |
| 24 | class String8; |
| 25 | |
| 26 | /** |
| 27 | * This is an entity class which would be passed to caller in |
| 28 | * DrmManagerClient::OnInfoListener::onInfo(const DrmInfoEvent&). |
| 29 | */ |
| 30 | class DrmInfoEvent { |
| 31 | public: |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 32 | /** |
| 33 | * The following constant values should be in sync with DrmInfoEvent.java |
| 34 | */ |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 35 | //! TYPE_ALREADY_REGISTERED_BY_ANOTHER_ACCOUNT, when registration has been |
| 36 | //! already done by another account ID. |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 37 | static const int TYPE_ALREADY_REGISTERED_BY_ANOTHER_ACCOUNT = 1; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 38 | //! TYPE_REMOVE_RIGHTS, when the rights needs to be removed completely. |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 39 | static const int TYPE_REMOVE_RIGHTS = 2; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 40 | //! TYPE_RIGHTS_INSTALLED, when the rights are downloaded and installed ok. |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 41 | static const int TYPE_RIGHTS_INSTALLED = 3; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 42 | //! TYPE_WAIT_FOR_RIGHTS, rights object is on it's way to phone, |
| 43 | //! wait before calling checkRights again |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 44 | 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 Wang | 505bd99 | 2011-03-14 12:04:15 -0700 | [diff] [blame] | 48 | //! TYPE_RIGHTS_REMOVED, when the rights has been removed. |
| 49 | static const int TYPE_RIGHTS_REMOVED = 6; |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 50 | |
| 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; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 60 | //! TYPE_OUT_OF_MEMORY, when memory allocation fail during renewal. |
| 61 | //! Can in the future perhaps be used to trigger garbage collector |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 62 | static const int TYPE_OUT_OF_MEMORY = 2004; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 63 | //! TYPE_NO_INTERNET_CONNECTION, when the Internet connection is missing and no attempt |
| 64 | //! can be made to renew rights |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 65 | static const int TYPE_NO_INTERNET_CONNECTION = 2005; |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 66 | //! TYPE_PROCESS_DRM_INFO_FAILED, when failed to process DrmInfo. |
| 67 | static const int TYPE_PROCESS_DRM_INFO_FAILED = 2006; |
Gloria Wang | 505bd99 | 2011-03-14 12:04:15 -0700 | [diff] [blame] | 68 | //! 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; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 73 | |
| 74 | public: |
| 75 | /** |
Takeshi Aimi | 5ff7836 | 2012-07-11 17:09:21 +0900 | [diff] [blame] | 76 | * Constructor for DrmInfoEvent. |
| 77 | * Data in drmBuffer are copied to newly allocated buffer. |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 78 | * |
| 79 | * @param[in] uniqueId Unique session identifier |
| 80 | * @param[in] infoType Type of information |
| 81 | * @param[in] message Message description |
Takeshi Aimi | 5ff7836 | 2012-07-11 17:09:21 +0900 | [diff] [blame] | 82 | * @param[in] drmBuffer Binary information |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 83 | */ |
Gloria Wang | 79cbc13 | 2011-03-17 15:02:34 -0700 | [diff] [blame] | 84 | DrmInfoEvent(int uniqueId, int infoType, const String8 message); |
Takeshi Aimi | 5ff7836 | 2012-07-11 17:09:21 +0900 | [diff] [blame] | 85 | DrmInfoEvent(int uniqueId, int infoType, const String8 message, const DrmBuffer& drmBuffer); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * Destructor for DrmInfoEvent |
| 89 | */ |
Takeshi Aimi | 5ff7836 | 2012-07-11 17:09:21 +0900 | [diff] [blame] | 90 | ~DrmInfoEvent(); |
| 91 | |
| 92 | public: |
| 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 | }; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 140 | |
| 141 | public: |
| 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 Wang | 79cbc13 | 2011-03-17 15:02:34 -0700 | [diff] [blame] | 161 | const String8 getMessage() const; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 162 | |
Takeshi Aimi | 5ff7836 | 2012-07-11 17:09:21 +0900 | [diff] [blame] | 163 | /** |
| 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 | |
| 216 | private: |
| 217 | DrmInfoEvent(const DrmInfoEvent& ref); |
| 218 | const DrmInfoEvent& operator=(const DrmInfoEvent& ref); |
| 219 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 220 | private: |
| 221 | int mUniqueId; |
| 222 | int mInfoType; |
Gloria Wang | 79cbc13 | 2011-03-17 15:02:34 -0700 | [diff] [blame] | 223 | const String8 mMessage; |
Takeshi Aimi | 5ff7836 | 2012-07-11 17:09:21 +0900 | [diff] [blame] | 224 | KeyedVector<String8, String8> mAttributes; |
| 225 | DrmBuffer mDrmBuffer; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 226 | }; |
| 227 | |
| 228 | }; |
| 229 | |
| 230 | #endif /* __DRM_INFO_EVENT_H__ */ |
| 231 | |