Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4f1ed0e8 authored by James Dong's avatar James Dong
Browse files

Avoid checking supported mime types or file suffixes in multiple places

Change-Id: I47d24070c7bda385cd1d7fa1f6a75dbb1f82b476
parent aa6816a8
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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.
+0 −37
Original line number Diff line number Diff line
/*
 * 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__ */
+47 −16
Original line number Diff line number Diff line
@@ -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;
    }