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 | #include <drm/DrmSupportInfo.h> |
| 18 | |
| 19 | using namespace android; |
| 20 | |
| 21 | DrmSupportInfo::DrmSupportInfo() { |
| 22 | |
| 23 | } |
| 24 | |
| 25 | DrmSupportInfo::DrmSupportInfo(const DrmSupportInfo& drmSupportInfo): |
| 26 | mMimeTypeVector(drmSupportInfo.mMimeTypeVector), |
| 27 | mFileSuffixVector(drmSupportInfo.mFileSuffixVector), |
| 28 | mDescription(drmSupportInfo.mDescription) { |
| 29 | |
| 30 | } |
| 31 | |
| 32 | bool DrmSupportInfo::operator<(const DrmSupportInfo& drmSupportInfo) const { |
| 33 | // Do we need to check mMimeTypeVector & mFileSuffixVector ? |
| 34 | // Note Vector doesn't overrides "<" operator |
| 35 | return mDescription < drmSupportInfo.mDescription; |
| 36 | } |
| 37 | |
| 38 | bool DrmSupportInfo::operator==(const DrmSupportInfo& drmSupportInfo) const { |
| 39 | // Do we need to check mMimeTypeVector & mFileSuffixVector ? |
| 40 | // Note Vector doesn't overrides "==" operator |
| 41 | return (mDescription == drmSupportInfo.mDescription); |
| 42 | } |
| 43 | |
| 44 | bool DrmSupportInfo::isSupportedMimeType(const String8& mimeType) const { |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 45 | for (unsigned int i = 0; i < mMimeTypeVector.size(); i++) { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 46 | const String8 item = mMimeTypeVector.itemAt(i); |
| 47 | |
| 48 | if (String8("") != mimeType && item.find(mimeType) != -1) { |
| 49 | return true; |
| 50 | } |
| 51 | } |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | bool DrmSupportInfo::isSupportedFileSuffix(const String8& fileType) const { |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 56 | for (unsigned int i = 0; i < mFileSuffixVector.size(); i++) { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 57 | const String8 item = mFileSuffixVector.itemAt(i); |
| 58 | |
Gloria Wang | 289401b | 2011-03-02 12:33:00 -0800 | [diff] [blame] | 59 | if (item.find(fileType) != -1) { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 60 | return true; |
| 61 | } |
| 62 | } |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | DrmSupportInfo& DrmSupportInfo::operator=(const DrmSupportInfo& drmSupportInfo) { |
| 67 | mMimeTypeVector = drmSupportInfo.mMimeTypeVector; |
| 68 | mFileSuffixVector = drmSupportInfo.mFileSuffixVector; |
| 69 | mDescription = drmSupportInfo.mDescription; |
| 70 | return *this; |
| 71 | } |
| 72 | |
| 73 | int DrmSupportInfo::getMimeTypeCount(void) const { |
| 74 | return mMimeTypeVector.size(); |
| 75 | } |
| 76 | |
| 77 | int DrmSupportInfo::getFileSuffixCount(void) const { |
| 78 | return mFileSuffixVector.size(); |
| 79 | } |
| 80 | |
| 81 | status_t DrmSupportInfo::addMimeType(const String8& mimeType) { |
| 82 | mMimeTypeVector.push(mimeType); |
| 83 | return DRM_NO_ERROR; |
| 84 | } |
| 85 | |
| 86 | status_t DrmSupportInfo::addFileSuffix(const String8& fileSuffix) { |
| 87 | mFileSuffixVector.push(fileSuffix); |
| 88 | return DRM_NO_ERROR; |
| 89 | } |
| 90 | |
| 91 | status_t DrmSupportInfo::setDescription(const String8& description) { |
| 92 | mDescription = description; |
| 93 | return DRM_NO_ERROR; |
| 94 | } |
| 95 | |
| 96 | String8 DrmSupportInfo::getDescription() const { |
| 97 | return mDescription; |
| 98 | } |
| 99 | |
| 100 | DrmSupportInfo::FileSuffixIterator DrmSupportInfo::getFileSuffixIterator() { |
| 101 | return FileSuffixIterator(this); |
| 102 | } |
| 103 | |
| 104 | DrmSupportInfo::MimeTypeIterator DrmSupportInfo::getMimeTypeIterator() { |
| 105 | return MimeTypeIterator(this); |
| 106 | } |
| 107 | |
| 108 | DrmSupportInfo::FileSuffixIterator::FileSuffixIterator( |
| 109 | const DrmSupportInfo::FileSuffixIterator& iterator) : |
| 110 | mDrmSupportInfo(iterator.mDrmSupportInfo), |
| 111 | mIndex(iterator.mIndex) { |
| 112 | |
| 113 | } |
| 114 | |
| 115 | DrmSupportInfo::FileSuffixIterator& DrmSupportInfo::FileSuffixIterator::operator=( |
| 116 | const DrmSupportInfo::FileSuffixIterator& iterator) { |
| 117 | mDrmSupportInfo = iterator.mDrmSupportInfo; |
| 118 | mIndex = iterator.mIndex; |
| 119 | return *this; |
| 120 | } |
| 121 | |
| 122 | bool DrmSupportInfo::FileSuffixIterator::hasNext() { |
| 123 | return mIndex < mDrmSupportInfo->mFileSuffixVector.size(); |
| 124 | } |
| 125 | |
| 126 | String8& DrmSupportInfo::FileSuffixIterator::next() { |
| 127 | String8& value = mDrmSupportInfo->mFileSuffixVector.editItemAt(mIndex); |
| 128 | mIndex++; |
| 129 | return value; |
| 130 | } |
| 131 | |
| 132 | DrmSupportInfo::MimeTypeIterator::MimeTypeIterator( |
| 133 | const DrmSupportInfo::MimeTypeIterator& iterator) : |
| 134 | mDrmSupportInfo(iterator.mDrmSupportInfo), |
| 135 | mIndex(iterator.mIndex) { |
| 136 | |
| 137 | } |
| 138 | |
| 139 | DrmSupportInfo::MimeTypeIterator& DrmSupportInfo::MimeTypeIterator::operator=( |
| 140 | const DrmSupportInfo::MimeTypeIterator& iterator) { |
| 141 | mDrmSupportInfo = iterator.mDrmSupportInfo; |
| 142 | mIndex = iterator.mIndex; |
| 143 | return *this; |
| 144 | } |
| 145 | |
| 146 | bool DrmSupportInfo::MimeTypeIterator::hasNext() { |
| 147 | return mIndex < mDrmSupportInfo->mMimeTypeVector.size(); |
| 148 | } |
| 149 | |
| 150 | String8& DrmSupportInfo::MimeTypeIterator::next() { |
| 151 | String8& value = mDrmSupportInfo->mMimeTypeVector.editItemAt(mIndex); |
| 152 | mIndex++; |
| 153 | return value; |
| 154 | } |
| 155 | |