Widevine drm aidl: address API review

Interface update in change 16810770

Bug: 214410088
Test: atest VtsAidlHalDrmTargetTest
Change-Id: I19da51ef75952f5ff6c7c02e0393f574e69ee30b
This commit is contained in:
Edwin
2022-02-08 16:16:12 -08:00
parent 6112060529
commit 9654d29be6
15 changed files with 150 additions and 292 deletions

View File

@@ -15,10 +15,6 @@ std::shared_ptr<WVDrmFactory> createDrmFactory() {
return std::make_shared<WVDrmFactory>();
}
std::shared_ptr<WVCryptoFactory> createCryptoFactory() {
return std::make_shared<WVCryptoFactory>();
}
} // namespace widevine
} // namespace drm
} // namespace hardware

View File

@@ -1,65 +0,0 @@
//
// Copyright 2021 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
//#define LOG_NDEBUG 0
#define LOG_TAG "WVCdm"
#include "WVCryptoFactory.h"
#include <android/binder_ibinder_platform.h>
#include <binder/IPCThreadState.h>
#include <utils/Log.h>
#include "Utils.h"
#include "WVCDMSingleton.h"
#include "WVCryptoPlugin.h"
#include "WVUUID.h"
namespace wvdrm {
namespace hardware {
namespace drm {
namespace widevine {
using ::aidl::android::hardware::drm::Status;
using ::aidl::android::hardware::drm::Uuid;
::ndk::ScopedAStatus WVCryptoFactory::isCryptoSchemeSupported(
const Uuid& in_uuid, bool* _aidl_return) {
*_aidl_return = isWidevineUUID(in_uuid.uuid.data());
return ::ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus WVCryptoFactory::createPlugin(
const ::aidl::android::hardware::drm::Uuid& in_uuid,
const std::vector<uint8_t>& in_initData,
std::shared_ptr<::aidl::android::hardware::drm::ICryptoPlugin>*
_aidl_return) {
const auto& self = android::IPCThreadState::self();
const char* sid = self->getCallingSid();
sid = sid ? (std::strstr(sid, "mediadrmserver") ? sid : "app") : "nullptr";
ALOGI("[%s] calling %s", sid, __PRETTY_FUNCTION__);
bool isSupported = false;
isCryptoSchemeSupported(in_uuid, &isSupported);
if (!isSupported) {
ALOGE(
"Widevine Drm HAL: failed to create crypto plugin, "
"invalid crypto scheme");
*_aidl_return = nullptr;
return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE);
}
std::shared_ptr<WVCryptoPlugin> plugin =
::ndk::SharedRefBase::make<WVCryptoPlugin>(in_initData.data(),
in_initData.size(), getCDM());
AIBinder_setRequestingSid(plugin->asBinder().get(), true);
*_aidl_return = std::move(plugin);
return toNdkScopedAStatus(Status::OK);
}
} // namespace widevine
} // namespace drm
} // namespace hardware
} // namespace wvdrm

View File

@@ -15,6 +15,7 @@
#include "Utils.h"
#include "WVCDMSingleton.h"
#include "WVCryptoPlugin.h"
#include "WVDrmPlugin.h"
#include "WVUUID.h"
#include "android-base/properties.h"
@@ -31,6 +32,7 @@ namespace widevine {
using std::string;
using std::vector;
using ::aidl::android::hardware::drm::CryptoSchemes;
using ::aidl::android::hardware::drm::SecurityLevel;
using ::aidl::android::hardware::drm::Status;
using ::aidl::android::hardware::drm::Uuid;
@@ -41,40 +43,33 @@ bool WVDrmFactory::isCryptoSchemeSupported(const Uuid& in_uuid) {
return isWidevineUUID(in_uuid.uuid.data());
}
::ndk::ScopedAStatus WVDrmFactory::isCryptoSchemeSupported(
const Uuid& in_uuid, const string& in_mimeType,
SecurityLevel in_securityLevel, bool* _aidl_return) {
bool isMimeTypeSupported = false;
isContentTypeSupported(in_mimeType, &isMimeTypeSupported);
if (!isWidevineUUID(in_uuid.uuid.data()) || !isMimeTypeSupported) {
*_aidl_return = false;
return ::ndk::ScopedAStatus::ok();
::ndk::ScopedAStatus WVDrmFactory::createCryptoPlugin(
const ::aidl::android::hardware::drm::Uuid& in_uuid,
const std::vector<uint8_t>& in_initData,
std::shared_ptr<::aidl::android::hardware::drm::ICryptoPlugin>*
_aidl_return) {
const auto& self = android::IPCThreadState::self();
const char* sid = self->getCallingSid();
sid = sid ? (std::strstr(sid, "mediadrmserver") ? sid : "app") : "nullptr";
ALOGI("[%s] calling %s", sid, __PRETTY_FUNCTION__);
if (!isCryptoSchemeSupported(in_uuid)) {
ALOGE(
"Widevine Drm HAL: failed to create crypto plugin, "
"invalid crypto scheme");
*_aidl_return = nullptr;
return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE);
}
if (wvcdm::WvContentDecryptionModule::IsSecurityLevelSupported(
wvcdm::kSecurityLevelL1)) {
if (wvcdm::WvContentDecryptionModule::IsAudio(in_mimeType)) {
if (in_securityLevel < SecurityLevel::HW_SECURE_ALL) {
*_aidl_return = true;
return ::ndk::ScopedAStatus::ok();
}
} else {
*_aidl_return = true;
return ::ndk::ScopedAStatus::ok();
}
}
*_aidl_return = in_securityLevel <= SecurityLevel::SW_SECURE_DECODE;
return ::ndk::ScopedAStatus::ok();
std::shared_ptr<WVCryptoPlugin> plugin =
::ndk::SharedRefBase::make<WVCryptoPlugin>(in_initData.data(),
in_initData.size(), getCDM());
AIBinder_setRequestingSid(plugin->asBinder().get(), true);
*_aidl_return = std::move(plugin);
return toNdkScopedAStatus(Status::OK);
}
::ndk::ScopedAStatus WVDrmFactory::isContentTypeSupported(
const string& in_mimeType, bool* _aidl_return) {
*_aidl_return =
wvcdm::WvContentDecryptionModule::IsSupported(in_mimeType.c_str());
return ::ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus WVDrmFactory::createPlugin(
::ndk::ScopedAStatus WVDrmFactory::createDrmPlugin(
const Uuid& in_uuid, const string& in_appPackageName,
std::shared_ptr<::aidl::android::hardware::drm::IDrmPlugin>* _aidl_return) {
const auto& self = ::android::IPCThreadState::self();
@@ -130,13 +125,22 @@ int32_t WVDrmFactory::firstApiLevel() {
}
::ndk::ScopedAStatus WVDrmFactory::getSupportedCryptoSchemes(
vector<Uuid>* _aidl_return) {
vector<Uuid> schemes;
Uuid scheme;
CryptoSchemes* _aidl_return) {
CryptoSchemes schemes{};
for (const auto& uuid : wvdrm::getSupportedCryptoSchemes()) {
scheme.uuid.assign(uuid.begin(), uuid.end());
schemes.push_back(scheme);
schemes.uuids.push_back({uuid});
}
schemes.minLevel = schemes.maxLevel = SecurityLevel::SW_SECURE_CRYPTO;
if (wvcdm::WvContentDecryptionModule::IsSecurityLevelSupported(
wvcdm::kSecurityLevelL1)) {
schemes.maxLevel = SecurityLevel::HW_SECURE_ALL;
}
schemes.mimeTypes = {
wvcdm::ISO_BMFF_VIDEO_MIME_TYPE, wvcdm::ISO_BMFF_AUDIO_MIME_TYPE,
wvcdm::WEBM_VIDEO_MIME_TYPE, wvcdm::WEBM_AUDIO_MIME_TYPE,
wvcdm::CENC_INIT_DATA_FORMAT, wvcdm::HLS_INIT_DATA_FORMAT,
wvcdm::WEBM_INIT_DATA_FORMAT};
*_aidl_return = schemes;
return ::ndk::ScopedAStatus::ok();
}

View File

@@ -2,7 +2,6 @@ on property:init.svc.mediadrm=running
mkdir /data/vendor/mediadrm 0770 media mediadrm
service vendor.drm-widevine-hal /vendor/bin/hw/android.hardware.drm-service.widevine
interface aidl android.hardware.drm::ICryptoFactory/widevine
interface aidl android.hardware.drm::IDrmFactory/widevine
class hal
user media

View File

@@ -22,12 +22,9 @@
#include <binder/ProcessState.h>
#include "WVCreatePluginFactories.h"
#include "WVCryptoFactory.h"
#include "WVDrmFactory.h"
using ::wvdrm::hardware::drm::widevine::createCryptoFactory;
using ::wvdrm::hardware::drm::widevine::createDrmFactory;
using ::wvdrm::hardware::drm::widevine::WVCryptoFactory;
using ::wvdrm::hardware::drm::widevine::WVDrmFactory;
int main(int /* argc */, char** /* argv */) {
@@ -41,13 +38,5 @@ int main(int /* argc */, char** /* argv */) {
CHECK(status == STATUS_OK)
<< "Failed to add Widevine Factory HAL, status=" << status;
std::shared_ptr<WVCryptoFactory> cryptoFactory = createCryptoFactory();
const std::string cryptoInstance =
std::string(WVCryptoFactory::descriptor) + "/widevine";
status = AServiceManager_addService(cryptoFactory->asBinder().get(),
cryptoInstance.c_str());
CHECK(status == STATUS_OK)
<< "Failed to add Widevine Crypto HAL, status=" << status;
ABinderProcess_joinThreadPool();
}