diff options
author | James Dong <jdong@google.com> | 2012-03-12 10:33:38 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-03-12 10:33:38 -0700 |
commit | f67fdc6d8bb31226ffeeecbff6aca610befd0110 (patch) | |
tree | d9040fa17452df1d10c51ea18f9bff5e8f8843b8 /drm/libdrmframework | |
parent | d64f3a376536a993fe6d81730b8b7b738500435e (diff) | |
parent | bd2f13ddbe7a9e7550205f6b53880329e09b9457 (diff) | |
download | frameworks_av-f67fdc6d8bb31226ffeeecbff6aca610befd0110.zip frameworks_av-f67fdc6d8bb31226ffeeecbff6aca610befd0110.tar.gz frameworks_av-f67fdc6d8bb31226ffeeecbff6aca610befd0110.tar.bz2 |
Merge "Avoid checking supported mime types or file suffixes in multiple places"
Diffstat (limited to 'drm/libdrmframework')
3 files changed, 55 insertions, 53 deletions
diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h index 34804cf..c0e408e 100644 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h @@ -499,6 +499,14 @@ ssize_t onPread(int uniqueId, private: + static const String8 Description; + static const String8 FileSuffixes[]; + static const String8 MimeTypes[]; + static bool IsFileSuffixSupported(const String8& suffix); + static bool IsMimeTypeSupported(const String8& mime); + static void AddSupportedMimeTypes(DrmSupportInfo *info); + static void AddSupportedFileSuffixes(DrmSupportInfo *info); + /** * Session Class for Forward Lock Conversion. An object of this class is created * for every conversion. diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngineConst.h b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngineConst.h deleted file mode 100644 index da95d60..0000000 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngineConst.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __FWDLOCKENGINECONST_H__ -#define __FWDLOCKENGINECONST_H__ - -namespace android { - -/** - * Constants for forward Lock Engine used for exposing engine's capabilities. - */ -#define FWDLOCK_EXTENSION_FL ("FL") -#define FWDLOCK_DOTEXTENSION_FL (".fl") -#define FWDLOCK_MIMETYPE_FL ("application/x-android-drm-fl") - -#define FWDLOCK_EXTENSION_DM ("DM") -#define FWDLOCK_DOTEXTENSION_DM (".dm") -#define FWDLOCK_MIMETYPE_DM ("application/vnd.oma.drm.message") - -#define FWDLOCK_DESCRIPTION ("OMA V1 Forward Lock") - -}; - -#endif /* __FWDLOCKENGINECONST_H__ */ diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp index 0273a4b..5ee41e6 100644 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp @@ -35,7 +35,6 @@ #include "FwdLockConv.h" #include "FwdLockFile.h" #include "FwdLockGlue.h" -#include "FwdLockEngineConst.h" #include "MimeTypeUtil.h" #undef LOG_TAG @@ -160,6 +159,48 @@ android::status_t FwdLockEngine::onTerminate(int uniqueId) { return DRM_NO_ERROR; } +const String8 FwdLockEngine::FileSuffixes[] = { + String8(".fl"), + String8(".dm"), +}; + +const String8 FwdLockEngine::MimeTypes[] = { + String8("application/x-android-drm-fl"), + String8("application/vnd.oma.drm.message"), +}; + +const String8 FwdLockEngine::Description("OMA V1 Forward Lock"); + +void FwdLockEngine::AddSupportedMimeTypes(DrmSupportInfo *info) { + for (size_t i = 0, n = sizeof(MimeTypes)/sizeof(MimeTypes[0]); i < n; ++i) { + info->addMimeType(MimeTypes[i]); + } +} + +void FwdLockEngine::AddSupportedFileSuffixes(DrmSupportInfo *info) { + for (size_t i = 0, n = sizeof(FileSuffixes)/sizeof(FileSuffixes[0]); i < n; ++i) { + info->addFileSuffix(FileSuffixes[i]); + } +} + +bool FwdLockEngine::IsMimeTypeSupported(const String8& mime) { + for (size_t i = 0, n = sizeof(MimeTypes)/sizeof(MimeTypes[0]); i < n; ++i) { + if (mime == MimeTypes[i]) { + return true; + } + } + return false; +} + +bool FwdLockEngine::IsFileSuffixSupported(const String8& suffix) { + for (size_t i = 0, n = sizeof(FileSuffixes)/sizeof(FileSuffixes[0]); i < n; ++i) { + if (suffix == FileSuffixes[i]) { + return true; + } + } + return false; +} + DrmSupportInfo* FwdLockEngine::onGetSupportInfo(int uniqueId) { DrmSupportInfo* pSupportInfo = new DrmSupportInfo(); @@ -167,12 +208,9 @@ DrmSupportInfo* FwdLockEngine::onGetSupportInfo(int uniqueId) { // fill all Forward Lock mimetypes and extensions if (NULL != pSupportInfo) { - pSupportInfo->addMimeType(String8(FWDLOCK_MIMETYPE_FL)); - pSupportInfo->addFileSuffix(String8(FWDLOCK_DOTEXTENSION_FL)); - pSupportInfo->addMimeType(String8(FWDLOCK_MIMETYPE_DM)); - pSupportInfo->addFileSuffix(String8(FWDLOCK_DOTEXTENSION_DM)); - - pSupportInfo->setDescription(String8(FWDLOCK_DESCRIPTION)); + AddSupportedMimeTypes(pSupportInfo); + AddSupportedFileSuffixes(pSupportInfo); + pSupportInfo->setDescription(Description); } return pSupportInfo; @@ -182,14 +220,8 @@ bool FwdLockEngine::onCanHandle(int uniqueId, const String8& path) { bool result = false; String8 extString = path.getPathExtension(); - extString.toLower(); - - if ((extString == String8(FWDLOCK_DOTEXTENSION_FL)) || - (extString == String8(FWDLOCK_DOTEXTENSION_DM))) { - result = true; - } - return result; + return IsFileSuffixSupported(extString); } DrmInfoStatus* FwdLockEngine::onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo) { @@ -308,8 +340,7 @@ int FwdLockEngine::onGetDrmObjectType(int uniqueId, * (regardless of the relation between them to make it compatible with other DRM Engines) */ if (((0 == path.length()) || onCanHandle(uniqueId, path)) && - ((0 == mimeType.length()) || ((mimeStr == String8(FWDLOCK_MIMETYPE_FL)) || - (mimeStr == String8(FWDLOCK_MIMETYPE_DM)))) && (mimeType != path) ) { + ((0 == mimeType.length()) || IsMimeTypeSupported(mimeType)) && (mimeType != path) ) { return DrmObjectType::CONTENT; } |