status_t FwdLockEngine::onOpenDecryptSession(int uniqueId, DecryptHandle* decryptHandle, const char* uri) { status_t result = DRM_ERROR_CANNOT_HANDLE; const char fileTag [] = "file://"; if (NULL != decryptHandle && NULL != uri && strlen(uri) > sizeof(fileTag)) { String8 uriTag = String8(uri); uriTag.toLower(); if (0 == strncmp(uriTag.string(), fileTag, sizeof(fileTag) - 1)) { const char *filePath = strchr(uri + sizeof(fileTag) - 1, '/'); if (NULL != filePath && onCanHandle(uniqueId, String8(filePath))) { int fd = open(filePath, O_RDONLY); if (-1 < fd) { // offset is always 0 and length is not used. so any positive size. result = onOpenDecryptSession(uniqueId, decryptHandle, fd, 0, 1); // fd is duplicated already if success. closing the file close(fd); } } } } return result; }
String8 FwdLockEngine::onGetOriginalMimeType(int /* uniqueId */, const String8& /* path */, int fd) { LOG_VERBOSE("FwdLockEngine::onGetOriginalMimeType"); String8 mimeString = String8(""); int fileDesc = dup(fd); if (-1 < fileDesc) { if (FwdLockFile_attach(fileDesc) < 0) { close(fileDesc); return mimeString; } const char* pMimeType = FwdLockFile_GetContentType(fileDesc); if (NULL != pMimeType) { String8 contentType = String8(pMimeType); contentType.toLower(); mimeString = MimeTypeUtil::convertMimeType(contentType); } FwdLockFile_close(fileDesc); } return mimeString; }
status_t FwdLockEngine::onOpenDecryptSession(int uniqueId, DecryptHandle* decryptHandle, int fd, off64_t offset, off64_t length) { #else status_t FwdLockEngine::onOpenDecryptSession(int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) { #endif status_t result = DRM_ERROR_CANNOT_HANDLE; int fileDesc = -1; LOG_VERBOSE("FwdLockEngine::onOpenDecryptSession"); if ((-1 < fd) && (NULL != decryptHandle) && (!decodeSessionMap.isCreated(decryptHandle->decryptId))) { fileDesc = dup(fd); } else { ALOGE("FwdLockEngine::onOpenDecryptSession parameter error"); return result; } if (-1 < fileDesc && -1 < ::lseek(fileDesc, offset, SEEK_SET) && -1 < FwdLockFile_attach(fileDesc)) { // check for file integrity. This must be done to protect the content mangling. int retVal = FwdLockFile_CheckHeaderIntegrity(fileDesc); DecodeSession* decodeSession = new DecodeSession(fileDesc); if (retVal && NULL != decodeSession) { decodeSessionMap.addValue(decryptHandle->decryptId, decodeSession); const char *pmime= FwdLockFile_GetContentType(fileDesc); String8 contentType = String8(pmime == NULL ? "" : pmime); contentType.toLower(); decryptHandle->mimeType = MimeTypeUtil::convertMimeType(contentType); decryptHandle->decryptApiType = DecryptApiType::CONTAINER_BASED; decryptHandle->status = RightsStatus::RIGHTS_VALID; decryptHandle->decryptInfo = NULL; result = DRM_NO_ERROR; } else { LOG_VERBOSE("FwdLockEngine::onOpenDecryptSession Integrity Check failed for the fd"); FwdLockFile_detach(fileDesc); delete decodeSession; } } if (DRM_NO_ERROR != result && -1 < fileDesc) { ::close(fileDesc); } LOG_VERBOSE("FwdLockEngine::onOpenDecryptSession Exit. result = %d", result); return result; }
String8 FwdLockEngine::onGetOriginalMimeType(int uniqueId, const String8& path) { LOG_VERBOSE("FwdLockEngine::onGetOriginalMimeType"); String8 mimeString = String8(""); int fileDesc = FwdLockFile_open(path.string()); if (-1 < fileDesc) { const char* pMimeType = FwdLockFile_GetContentType(fileDesc); if (NULL != pMimeType) { String8 contentType = String8(pMimeType); contentType.toLower(); mimeString = MimeTypeUtil::convertMimeType(contentType); } FwdLockFile_close(fileDesc); } return mimeString; }
bool DrmPassthruPlugIn::onCanHandle(int uniqueId, const String8& path) { ALOGV("DrmPassthruPlugIn::canHandle: %s ", path.string()); String8 extension = path.getPathExtension(); extension.toLower(); return (String8(".passthru") == extension); }