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 #include <drm/DrmConstraints.h> 18 19 using namespace android; 20 21 const String8 DrmConstraints::MAX_REPEAT_COUNT("max_repeat_count"); 22 const String8 DrmConstraints::REMAINING_REPEAT_COUNT("remaining_repeat_count"); 23 const String8 DrmConstraints::LICENSE_START_TIME("license_start_time"); 24 const String8 DrmConstraints::LICENSE_EXPIRY_TIME("license_expiry_time"); 25 const String8 DrmConstraints::LICENSE_AVAILABLE_TIME("license_available_time"); 26 const String8 DrmConstraints::EXTENDED_METADATA("extended_metadata"); 27 28 int DrmConstraints::getCount(void) const { 29 return mConstraintMap.size(); 30 } 31 32 status_t DrmConstraints::put(const String8* key, const char* value) { 33 int length = strlen(value); 34 char* charValue = new char[length + 1]; 35 if (NULL != charValue) { 36 strncpy(charValue, value, length); 37 charValue[length] = '\0'; 38 mConstraintMap.add(*key, charValue); 39 } 40 return DRM_NO_ERROR; 41 } 42 43 String8 DrmConstraints::get(const String8& key) const { 44 if (NULL != getValue(&key)) { 45 return String8(getValue(&key)); 46 } 47 return String8(""); 48 } 49 50 const char* DrmConstraints::getValue(const String8* key) const { 51 if (NAME_NOT_FOUND != mConstraintMap.indexOfKey(*key)) { 52 return mConstraintMap.valueFor(*key); 53 } 54 return NULL; 55 } 56 57 const char* DrmConstraints::getAsByteArray(const String8* key) const { 58 return getValue(key); 59 } 60 61 bool DrmConstraints::KeyIterator::hasNext() { 62 return mIndex < mDrmConstraints->mConstraintMap.size(); 63 } 64 65 const String8& DrmConstraints::KeyIterator::next() { 66 const String8& key = mDrmConstraints->mConstraintMap.keyAt(mIndex); 67 mIndex++; 68 return key; 69 } 70 71 DrmConstraints::KeyIterator DrmConstraints::keyIterator() { 72 return KeyIterator(this); 73 } 74 75 DrmConstraints::KeyIterator::KeyIterator(const DrmConstraints::KeyIterator& keyIterator) 76 : mDrmConstraints(keyIterator.mDrmConstraints), 77 mIndex(keyIterator.mIndex) { 78 } 79 80 DrmConstraints::KeyIterator& DrmConstraints::KeyIterator::operator=( 81 const DrmConstraints::KeyIterator& keyIterator) { 82 mDrmConstraints = keyIterator.mDrmConstraints; 83 mIndex = keyIterator.mIndex; 84 return *this; 85 } 86 87 88 DrmConstraints::Iterator DrmConstraints::iterator() { 89 return Iterator(this); 90 } 91 92 DrmConstraints::Iterator::Iterator(const DrmConstraints::Iterator& iterator) : 93 mDrmConstraints(iterator.mDrmConstraints), 94 mIndex(iterator.mIndex) { 95 } 96 97 DrmConstraints::Iterator& DrmConstraints::Iterator::operator=( 98 const DrmConstraints::Iterator& iterator) { 99 mDrmConstraints = iterator.mDrmConstraints; 100 mIndex = iterator.mIndex; 101 return *this; 102 } 103 104 bool DrmConstraints::Iterator::hasNext() { 105 return mIndex < mDrmConstraints->mConstraintMap.size(); 106 } 107 108 String8 DrmConstraints::Iterator::next() { 109 String8 value = String8(mDrmConstraints->mConstraintMap.editValueAt(mIndex)); 110 mIndex++; 111 return value; 112 } 113 114