Remove hidl support.

Merged from http://go/wvgerrit/161857

Test: streaming(Netflix, Play Movies & TV)
Test: ./build_and_run_all_unit_tests.sh
Test: adb shell ps | grep drm
Test: metrics_dump
Test: hardware/interfaces/drm/aidl/vts$ atest VtsAidlHalDrmTargetTest

Bug: 259299992
Change-Id: I76bcc82bbfb3fc60987b66265a580946a16c341d
This commit is contained in:
Edwin Wong
2022-11-19 04:52:25 +00:00
parent c13a1981c4
commit 6d3457b9d9
64 changed files with 339 additions and 12113 deletions

View File

@@ -89,31 +89,6 @@ common_widevine_service {
}, },
} }
cc_defaults {
name: "common_widevine_service-multilib-defaults@1.3",
owner: "widevine",
proprietary: true,
relative_install_path: "hw",
include_dirs: [
"vendor/widevine/libwvdrmengine/include_hidl",
"vendor/widevine/libwvdrmengine/mediadrm/include_hidl",
"vendor/widevine/libwvdrmengine/oemcrypto/include",
],
header_libs: ["libstagefright_foundation_headers"],
shared_libs: [
"android.hardware.drm@1.0",
"android.hardware.drm@1.1",
"android.hardware.drm@1.2",
"android.hardware.drm@1.3",
"libbase",
"libbinder",
"libhidlbase",
"liblog",
"libutils",
],
}
cc_defaults { cc_defaults {
name: "common_widevine_service-multilib-defaults-aidl", name: "common_widevine_service-multilib-defaults-aidl",
owner: "widevine", owner: "widevine",
@@ -136,118 +111,6 @@ cc_defaults {
], ],
} }
cc_defaults {
name: "common_widevine_service-multilib-defaults",
defaults: [
"common_widevine_service-multilib-defaults@1.3",
],
shared_libs: [
"android.hardware.drm@1.4",
"libwvhidl",
],
}
// ----------------------------------------------------------------------------
// Builds android.hardware.drm@1.2-service.widevine
//
cc_binary {
name: "android.hardware.drm@1.2-service.widevine",
defaults: [
"common_widevine_service-multilib-first",
"common_widevine_service-multilib-defaults",
],
srcs: ["src_hidl/service.cpp"],
init_rc: ["src_hidl/android.hardware.drm@1.2-service.widevine.rc"],
vintf_fragments: ["manifest_android.hardware.drm@1.2-service.widevine.xml"],
}
// ----------------------------------------------------------------------------
// Builds android.hardware.drm@1.2-service-lazy.widevine
//
cc_binary {
name: "android.hardware.drm@1.2-service-lazy.widevine",
defaults: [
"common_widevine_service-multilib-first",
"common_widevine_service-multilib-defaults",
],
srcs: ["src_hidl/serviceLazy.cpp"],
overrides: ["android.hardware.drm@1.2-service.widevine"],
init_rc: ["src_hidl/android.hardware.drm@1.2-service-lazy.widevine.rc"],
vintf_fragments: ["manifest_android.hardware.drm@1.2-service.widevine.xml"],
}
// ----------------------------------------------------------------------------
// Builds android.hardware.drm@1.3-service.widevine
//
cc_binary {
name: "android.hardware.drm@1.3-service.widevine",
defaults: [
"common_widevine_service-multilib-first",
"common_widevine_service-multilib-defaults@1.3",
],
srcs: ["src_hidl/service@1.3.cpp"],
shared_libs: ["libwvhidl@1.3"],
init_rc: ["src_hidl/android.hardware.drm@1.3-service.widevine.rc"],
vintf_fragments: ["manifest_android.hardware.drm@1.3-service.widevine.xml"],
}
// ----------------------------------------------------------------------------
// Builds android.hardware.drm@1.3-service-lazy.widevine
//
cc_binary {
name: "android.hardware.drm@1.3-service-lazy.widevine",
defaults: [
"common_widevine_service-multilib-first",
"common_widevine_service-multilib-defaults",
],
srcs: ["src_hidl/serviceLazy.cpp"],
overrides: ["android.hardware.drm@1.3-service.widevine"],
init_rc: ["src_hidl/android.hardware.drm@1.3-service-lazy.widevine.rc"],
vintf_fragments: ["manifest_android.hardware.drm@1.4-service.widevine.xml"],
}
// ----------------------------------------------------------------------------
// Builds android.hardware.drm@1.4-service.widevine
//
cc_binary {
name: "android.hardware.drm@1.4-service.widevine",
defaults: [
"common_widevine_service-multilib-first",
"common_widevine_service-multilib-defaults",
],
srcs: ["src_hidl/service.cpp"],
init_rc: ["src_hidl/android.hardware.drm@1.4-service.widevine.rc"],
vintf_fragments: ["manifest_android.hardware.drm@1.4-service.widevine.xml"],
}
// ----------------------------------------------------------------------------
// Builds android.hardware.drm@1.4-service-lazy.widevine
//
cc_binary {
name: "android.hardware.drm@1.4-service-lazy.widevine",
defaults: [
"common_widevine_service-multilib-first",
"common_widevine_service-multilib-defaults",
],
srcs: ["src_hidl/serviceLazy.cpp"],
overrides: ["android.hardware.drm@1.4-service.widevine"],
init_rc: ["src_hidl/android.hardware.drm@1.4-service-lazy.widevine.rc"],
vintf_fragments: ["manifest_android.hardware.drm@1.4-service.widevine.xml"],
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Builds android.hardware.drm-service.widevine // Builds android.hardware.drm-service.widevine
// //
@@ -293,64 +156,30 @@ cc_binary {
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Builds libcdm_utils.a and libcdm_utils_hidl.a // Builds libcdm_utils.a
// //
cdm_util_src_files = [
"cdm/core/src/properties.cpp",
"cdm/src/properties_android.cpp",
"cdm/src/timer.cpp",
"cdm/util/src/cdm_random.cpp",
"cdm/util/src/clock.cpp",
"cdm/util/src/error_string_util.cpp",
"cdm/util/src/file_store.cpp",
"cdm/util/src/file_utils.cpp",
"cdm/util/src/log.cpp",
"cdm/util/src/platform.cpp",
"cdm/util/src/rw_lock.cpp",
"cdm/util/src/string_conversions.cpp",
"cdm/util/src/string_format.cpp",
]
cc_library_static {
name: "libcdm_utils_hidl",
proprietary: true,
include_dirs: [
"vendor/widevine/libwvdrmengine/cdm/core/include",
"vendor/widevine/libwvdrmengine/cdm/include",
"vendor/widevine/libwvdrmengine/cdm/util/include",
"vendor/widevine/libwvdrmengine/oemcrypto/include",
],
header_libs: [
"libbase_headers",
"libutils_headers",
],
shared_libs: [
"libbinder_ndk",
"libcrypto",
"libhidlbase",
"liblog",
],
cflags: [
"-DIS_HIDL",
],
srcs: cdm_util_src_files,
}
cc_library_static { cc_library_static {
name: "libcdm_utils", name: "libcdm_utils",
proprietary: true, proprietary: true,
srcs: [
"cdm/core/src/properties.cpp",
"cdm/src/properties_android.cpp",
"cdm/src/timer.cpp",
"cdm/util/src/cdm_random.cpp",
"cdm/util/src/clock.cpp",
"cdm/util/src/error_string_util.cpp",
"cdm/util/src/file_store.cpp",
"cdm/util/src/file_utils.cpp",
"cdm/util/src/log.cpp",
"cdm/util/src/platform.cpp",
"cdm/util/src/rw_lock.cpp",
"cdm/util/src/string_conversions.cpp",
"cdm/util/src/string_format.cpp",
],
include_dirs: [ include_dirs: [
"vendor/widevine/libwvdrmengine/cdm/core/include", "vendor/widevine/libwvdrmengine/cdm/core/include",
"vendor/widevine/libwvdrmengine/cdm/include", "vendor/widevine/libwvdrmengine/cdm/include",
@@ -366,117 +195,8 @@ cc_library_static {
shared_libs: [ shared_libs: [
"libbinder_ndk", "libbinder_ndk",
"libcrypto", "libcrypto",
"libhidlbase",
"liblog", "liblog",
], ],
srcs: cdm_util_src_files,
}
// ----------------------------------------------------------------------------
// Builds libwvhidl.so
//
cc_library_shared {
name: "libwvhidl",
srcs: [
"src/WVCDMSingleton.cpp",
"src/WVUUID.cpp",
"src_hidl/wv_metrics.cpp",
"src_hidl/WVCreatePluginFactories.cpp",
"src_hidl/WVCryptoFactory.cpp",
"src_hidl/WVDrmFactory.cpp",
],
include_dirs: [
"frameworks/av/include",
"frameworks/native/include",
"vendor/widevine/libwvdrmengine/cdm/core/include",
"vendor/widevine/libwvdrmengine/cdm/metrics/include",
"vendor/widevine/libwvdrmengine/cdm/util/include",
"vendor/widevine/libwvdrmengine/cdm/include",
"vendor/widevine/libwvdrmengine/include",
"vendor/widevine/libwvdrmengine/include_hidl",
"vendor/widevine/libwvdrmengine/mediacrypto/include_hidl",
"vendor/widevine/libwvdrmengine/mediadrm/include_hidl",
"vendor/widevine/libwvdrmengine/oemcrypto/include",
],
static_libs: [
"libcdm",
"libcdm_protos",
"libcdm_utils_hidl",
"libjsmn",
"libwvdrmcryptoplugin_hidl",
"libwvdrmdrmplugin_hidl",
"libwvlevel3",
"libwv_odk",
],
shared_libs: [
"android.hardware.drm@1.0",
"android.hardware.drm@1.1",
"android.hardware.drm@1.2",
"android.hardware.drm@1.3",
"android.hardware.drm@1.4",
"android.hidl.memory@1.0",
"libbase",
"libcrypto",
"libcutils",
"libdl",
"libhidlbase",
"libhidlmemory",
"liblog",
"libprotobuf-cpp-lite",
"libutils",
],
header_libs: ["libstagefright_foundation_headers"],
owner: "widevine",
proprietary: true,
}
cc_prebuilt_library_shared {
name: "libwvhidl@1.3",
target: {
android_arm: {
srcs: ["prebuilts_hidl/arm/libwvhidl@1.3.so"],
},
android_arm64: {
srcs: ["prebuilts_hidl/arm64/libwvhidl@1.3.so"],
},
android_x86: {
srcs: ["prebuilts_hidl/x86/libwvhidl@1.3.so"],
},
android_x86_64: {
srcs: ["prebuilts_hidl/x86_64/libwvhidl@1.3.so"],
},
},
shared_libs: [
"android.hardware.drm@1.0",
"android.hardware.drm@1.1",
"android.hardware.drm@1.2",
"android.hardware.drm@1.3",
"android.hidl.memory@1.0",
"libbase",
"libcrypto",
"libcutils",
"libdl",
"libhidlbase",
"libhidlmemory",
"liblog",
"libprotobuf-cpp-lite",
"libutils",
],
owner: "widevine",
proprietary: true,
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -9,12 +9,9 @@ fi
# Read arguments in case the user wants to do a multicore build or # Read arguments in case the user wants to do a multicore build or
# copy files to a specific android device by providing a serial number. # copy files to a specific android device by providing a serial number.
# The default build target is for AIDL service, use "-t hidl" to
# build for HIDL service.
WV_UNITTESTS_BUILD_TARGET=""
NUM_CORES=1 NUM_CORES=1
SERIAL_NUM="" SERIAL_NUM=""
while getopts "j:s:t:" opt; do while getopts "j:s:" opt; do
case $opt in case $opt in
j) j)
NUM_CORES=$OPTARG NUM_CORES=$OPTARG
@@ -22,9 +19,6 @@ while getopts "j:s:t:" opt; do
s) s)
SERIAL_NUM="-s $OPTARG" SERIAL_NUM="-s $OPTARG"
;; ;;
t)
WV_UNITTESTS_BUILD_TARGET="WV_UNITTESTS_BUILD_TARGET=$OPTARG"
;;
esac esac
done done
@@ -81,7 +75,7 @@ WV_UNITTESTS="base64_test \
cd $ANDROID_BUILD_TOP cd $ANDROID_BUILD_TOP
pwd pwd
m -j $NUM_CORES $WV_UNITTESTS $WV_UNITTESTS_BUILD_TARGET m -j $NUM_CORES $WV_UNITTESTS
# Detect the device and check if Verity is going to stop the script from working # Detect the device and check if Verity is going to stop the script from working

View File

@@ -61,11 +61,8 @@ constexpr char ATSC_APP_PACKAGE_NAME[] = "org.atsc";
// Define query keys, values here. // Define query keys, values here.
// To expose these query items to Android update: // To expose these query items to Android update:
// android/mediadrm/src/WVDrmPlugin.cpp // android/mediadrm/src/WVDrmPlugin.cpp
// android/mediadrm/src_hidl/WVDrmPlugin.cpp
// Update test QueryStatus and QueryStatusL3 test for all possible outputs: // Update test QueryStatus and QueryStatusL3 test for all possible outputs:
// android/cdm/test/request_license_test.cpp // android/cdm/test/request_license_test.cpp
// Update HIDL debug output:
// android/src_hidl/WVDrmFactory.cpp
static const std::string QUERY_KEY_LICENSE_TYPE = static const std::string QUERY_KEY_LICENSE_TYPE =
"LicenseType"; // "Streaming", "Offline" "LicenseType"; // "Streaming", "Offline"
static const std::string QUERY_KEY_PLAY_ALLOWED = static const std::string QUERY_KEY_PLAY_ALLOWED =

View File

@@ -445,7 +445,6 @@ enum CdmResponseType : int32_t {
// Don't forget to add new values to // Don't forget to add new values to
// * core/test/test_printers.cpp. // * core/test/test_printers.cpp.
// * android/include/mapErrors-inl.h // * android/include/mapErrors-inl.h
// * android/include_hidl/HidlMapErrors-inl.h
}; };
enum CdmKeyStatus : int32_t { enum CdmKeyStatus : int32_t {

View File

@@ -3,15 +3,6 @@
# #
include $(CLEAR_VARS) include $(CLEAR_VARS)
WV_UNITTESTS_BUILD_TARGET?=
ifeq ($(WV_UNITTESTS_BUILD_TARGET), hidl)
HIDL_EXTENSION := _hidl
LIB_BINDER := libhidlbase
else
HIDL_EXTENSION :=
LIB_BINDER := libbinder_ndk
endif
LOCAL_LICENSE_CONDITIONS := by_exception_only LOCAL_LICENSE_CONDITIONS := by_exception_only
LOCAL_LICENSE_KINDS := legacy_by_exception_only LOCAL_LICENSE_KINDS := legacy_by_exception_only
LOCAL_MODULE := cdm_coverage_test LOCAL_MODULE := cdm_coverage_test
@@ -69,7 +60,7 @@ LOCAL_C_INCLUDES += external/protobuf/src
LOCAL_STATIC_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \
libcdm \ libcdm \
libcdm_protos \ libcdm_protos \
libcdm_utils$(HIDL_EXTENSION) \ libcdm_utils \
libjsmn \ libjsmn \
libgmock \ libgmock \
libgtest \ libgtest \
@@ -81,7 +72,7 @@ LOCAL_SHARED_LIBRARIES := \
libbase \ libbase \
libcrypto \ libcrypto \
libdl \ libdl \
$(LIB_BINDER) \ libbinder_ndk \
liblog \ liblog \
libmedia_omx \ libmedia_omx \
libprotobuf-cpp-lite \ libprotobuf-cpp-lite \

View File

@@ -6,15 +6,6 @@ $(call assert-not-null,test_name)
include $(CLEAR_VARS) include $(CLEAR_VARS)
WV_UNITTESTS_BUILD_TARGET?=
ifeq ($(WV_UNITTESTS_BUILD_TARGET), hidl)
HIDL_EXTENSION := _hidl
LIB_BINDER := libhidlbase
else
HIDL_EXTENSION :=
LIB_BINDER := libbinder_ndk
endif
LOCAL_MODULE := $(test_name) LOCAL_MODULE := $(test_name)
LOCAL_LICENSE_KINDS := legacy_by_exception_only LOCAL_LICENSE_KINDS := legacy_by_exception_only
LOCAL_LICENSE_CONDITIONS := by_exception_only LOCAL_LICENSE_CONDITIONS := by_exception_only
@@ -59,7 +50,7 @@ LOCAL_C_INCLUDES += external/protobuf/src
LOCAL_STATIC_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \
libcdm \ libcdm \
libcdm_protos \ libcdm_protos \
libcdm_utils$(HIDL_EXTENSION) \ libcdm_utils \
libjsmn \ libjsmn \
libgmock \ libgmock \
libgtest \ libgtest \
@@ -71,7 +62,7 @@ LOCAL_SHARED_LIBRARIES := \
libbase \ libbase \
libcrypto \ libcrypto \
libdl \ libdl \
$(LIB_BINDER) \ libbinder_ndk \
liblog \ liblog \
libmedia_omx \ libmedia_omx \
libprotobuf-cpp-lite \ libprotobuf-cpp-lite \

View File

@@ -6,15 +6,6 @@ $(call assert-not-null,test_name)
include $(CLEAR_VARS) include $(CLEAR_VARS)
WV_UNITTESTS_BUILD_TARGET?=
ifeq ($(WV_UNITTESTS_BUILD_TARGET), hidl)
HIDL_EXTENSION := _hidl
LIB_BINDER := libhidlbase
else
HIDL_EXTENSION :=
LIB_BINDER := libbinder_ndk
endif
LOCAL_MODULE := $(test_name) LOCAL_MODULE := $(test_name)
LOCAL_LICENSE_KINDS := legacy_by_exception_only LOCAL_LICENSE_KINDS := legacy_by_exception_only
LOCAL_LICENSE_CONDITIONS := by_exception_only LOCAL_LICENSE_CONDITIONS := by_exception_only
@@ -52,7 +43,7 @@ LOCAL_C_INCLUDES += external/protobuf/src
LOCAL_STATIC_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \
libcdm \ libcdm \
libcdm_protos \ libcdm_protos \
libcdm_utils$(HIDL_EXTENSION) \ libcdm_utils \
libjsmn \ libjsmn \
libgmock \ libgmock \
libgtest \ libgtest \
@@ -63,8 +54,7 @@ LOCAL_SHARED_LIBRARIES := \
libbase \ libbase \
libcrypto \ libcrypto \
libdl \ libdl \
libhidlbase \ libbinder_ndk \
$(LIB_BINDER) \
liblog \ liblog \
libmedia_omx \ libmedia_omx \
libprotobuf-cpp-lite \ libprotobuf-cpp-lite \

View File

@@ -23,11 +23,7 @@
#include "log.h" #include "log.h"
#ifdef IS_HIDL #include <android/binder_ibinder.h>
# include <hwbinder/IPCThreadState.h>
#else // AIDL is the default
# include <android/binder_ibinder.h>
#endif
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <sys/time.h> #include <sys/time.h>
@@ -80,12 +76,7 @@ void ClearLoggingUid() {
uint32_t GetLoggingUid() { return tl_logging_uid_; } uint32_t GetLoggingUid() { return tl_logging_uid_; }
uint32_t GetIpcCallingUid() { uint32_t GetIpcCallingUid() {
#ifdef IS_HIDL
const auto self = android::hardware::IPCThreadState::selfOrNull();
return self ? self->getCallingUid() : UNKNOWN_UID;
#else // AIDL is the default
return AIBinder_getCallingUid(); return AIBinder_getCallingUid();
#endif
} }
void InitLogging() {} void InitLogging() {}

View File

@@ -1,753 +0,0 @@
//
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
#ifndef WV_MAP_ERRORS_H_
#define WV_MAP_ERRORS_H_
#include "media/stagefright/MediaErrors.h"
#include "utils/Errors.h"
#include "wv_cdm_types.h"
#include "HidlTypes.h"
#include "WVErrors.h"
namespace wvdrm {
static Status mapCdmResponseType_1_0(wvcdm::CdmResponseType res) {
switch (res) {
case wvcdm::KEY_ADDED:
case wvcdm::KEY_MESSAGE:
case wvcdm::KEY_CANCELED:
// KEY_ADDED, KEY_MESSAGE, and KEY_CANCELLED are all alternative
// success messages for certain CDM methods instead of NO_ERROR.
case wvcdm::NO_ERROR:
return Status::OK;
case wvcdm::DECRYPT_NOT_READY:
case wvcdm::KEY_NOT_FOUND_IN_SESSION:
case wvcdm::NEED_KEY:
case wvcdm::NO_MATCHING_ENTITLEMENT_KEY:
// TODO(http://b/119690361): there are several NO_CONTENT_* errors.
// that should probably all turn into NO_LICENSE. Here, and below, and
// everywhere.
case wvcdm::NO_CONTENT_KEY_3:
return Status::ERROR_DRM_NO_LICENSE;
case wvcdm::NEED_PROVISIONING:
return Status::ERROR_DRM_NOT_PROVISIONED;
case wvcdm::DEVICE_REVOKED:
return Status::ERROR_DRM_DEVICE_REVOKED;
case wvcdm::INSUFFICIENT_CRYPTO_RESOURCES:
return Status::ERROR_DRM_RESOURCE_BUSY;
case wvcdm::RELEASE_USAGE_INFO_ERROR:
case wvcdm::RELEASE_USAGE_INFO_FAILED:
case wvcdm::SYSTEM_INVALIDATED_ERROR:
return Status::ERROR_DRM_INVALID_STATE;
case wvcdm::SESSION_NOT_FOUND_FOR_DECRYPT:
case wvcdm::SESSION_NOT_FOUND_1:
case wvcdm::SESSION_NOT_FOUND_2:
case wvcdm::SESSION_NOT_FOUND_3:
case wvcdm::SESSION_NOT_FOUND_4:
case wvcdm::SESSION_NOT_FOUND_5:
case wvcdm::SESSION_NOT_FOUND_6:
case wvcdm::SESSION_NOT_FOUND_7:
case wvcdm::SESSION_NOT_FOUND_8:
case wvcdm::SESSION_NOT_FOUND_9:
case wvcdm::SESSION_NOT_FOUND_10:
case wvcdm::SESSION_NOT_FOUND_18:
case wvcdm::SESSION_NOT_FOUND_19:
case wvcdm::SESSION_NOT_FOUND_20:
case wvcdm::SESSION_NOT_FOUND_21:
case wvcdm::SESSION_NOT_FOUND_22:
case wvcdm::SESSION_NOT_FOUND_23:
return Status::ERROR_DRM_SESSION_NOT_OPENED;
case wvcdm::DECRYPT_ERROR:
case wvcdm::SECURE_BUFFER_REQUIRED:
return Status::ERROR_DRM_CANNOT_HANDLE;
case wvcdm::ANALOG_OUTPUT_ERROR:
case wvcdm::KEY_PROHIBITED_FOR_SECURITY_LEVEL:
case wvcdm::INSUFFICIENT_OUTPUT_PROTECTION:
return Status::ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION;
case wvcdm::KEYSET_ID_NOT_FOUND_4:
return Status::BAD_VALUE;
// The following cases follow the order in wv_cdm_types.h
// to make it easier to keep track of newly defined errors.
case wvcdm::KEY_ERROR:
case wvcdm::ADD_KEY_ERROR:
case wvcdm::CERT_PROVISIONING_EMPTY_SERVICE_CERTIFICATE:
case wvcdm::CERT_PROVISIONING_GET_KEYBOX_ERROR_1:
case wvcdm::CERT_PROVISIONING_INVALID_CERT_TYPE:
case wvcdm::CERT_PROVISIONING_REQUEST_ERROR_1:
case wvcdm::CERT_PROVISIONING_NONCE_GENERATION_ERROR:
case wvcdm::CERT_PROVISIONING_REQUEST_ERROR_4:
case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_1:
case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_2:
case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_3:
case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_4:
case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_7:
case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_8:
case wvcdm::DEVICE_CERTIFICATE_ERROR_1:
case wvcdm::DEVICE_CERTIFICATE_ERROR_2:
case wvcdm::DEVICE_CERTIFICATE_ERROR_3:
case wvcdm::DEVICE_CERTIFICATE_ERROR_4:
case wvcdm::EMPTY_KEY_DATA_1:
case wvcdm::EMPTY_KEY_DATA_2:
case wvcdm::EMPTY_KEYSET_ID:
case wvcdm::EMPTY_KEYSET_ID_ENG_1:
case wvcdm::EMPTY_KEYSET_ID_ENG_2:
case wvcdm::EMPTY_KEYSET_ID_ENG_3:
case wvcdm::EMPTY_KEYSET_ID_ENG_4:
case wvcdm::EMPTY_LICENSE_RENEWAL:
case wvcdm::EMPTY_LICENSE_RESPONSE_1:
case wvcdm::EMPTY_LICENSE_RESPONSE_2:
case wvcdm::EMPTY_PROVISIONING_CERTIFICATE_1:
case wvcdm::EMPTY_PROVISIONING_RESPONSE:
case wvcdm::EMPTY_SESSION_ID:
case wvcdm::GENERATE_DERIVED_KEYS_ERROR:
case wvcdm::LICENSE_RENEWAL_NONCE_GENERATION_ERROR:
case wvcdm::GENERATE_USAGE_REPORT_ERROR:
case wvcdm::GET_LICENSE_ERROR:
case wvcdm::GET_RELEASED_LICENSE_ERROR:
case wvcdm::GET_USAGE_INFO_ERROR_1:
case wvcdm::GET_USAGE_INFO_ERROR_2:
case wvcdm::GET_USAGE_INFO_ERROR_3:
case wvcdm::GET_USAGE_INFO_ERROR_4:
case wvcdm::INIT_DATA_NOT_FOUND:
case wvcdm::INVALID_DECRYPT_PARAMETERS_ENG_1:
case wvcdm::INVALID_DECRYPT_PARAMETERS_ENG_2:
case wvcdm::INVALID_DECRYPT_PARAMETERS_ENG_3:
case wvcdm::INVALID_DECRYPT_PARAMETERS_ENG_4:
case wvcdm::INVALID_DEVICE_CERTIFICATE_TYPE:
case wvcdm::INVALID_KEY_SYSTEM:
case wvcdm::INVALID_LICENSE_RESPONSE:
case wvcdm::INVALID_LICENSE_TYPE:
case wvcdm::PARAMETER_NULL:
case wvcdm::INVALID_PARAMETERS_LIC_1:
case wvcdm::INVALID_PARAMETERS_LIC_2:
case wvcdm::INVALID_PROVISIONING_PARAMETERS_1:
case wvcdm::INVALID_PROVISIONING_PARAMETERS_2:
case wvcdm::INVALID_PROVISIONING_REQUEST_PARAM_1:
case wvcdm::INVALID_PROVISIONING_REQUEST_PARAM_2:
case wvcdm::INVALID_QUERY_KEY:
case wvcdm::INVALID_SESSION_ID:
case wvcdm::KEY_REQUEST_ERROR_1:
case wvcdm::KEY_SIZE_ERROR_1:
case wvcdm::KEY_SIZE_ERROR_2:
case wvcdm::KEYSET_ID_NOT_FOUND_1:
case wvcdm::KEYSET_ID_NOT_FOUND_2:
case wvcdm::KEYSET_ID_NOT_FOUND_3:
case wvcdm::LICENSE_ID_NOT_FOUND:
case wvcdm::LICENSE_PARSER_INIT_ERROR:
case wvcdm::LICENSE_PARSER_NOT_INITIALIZED_1:
case wvcdm::LICENSE_PARSER_NOT_INITIALIZED_2:
case wvcdm::LICENSE_PARSER_NOT_INITIALIZED_3:
case wvcdm::LICENSE_RESPONSE_NOT_SIGNED:
case wvcdm::LICENSE_RESPONSE_PARSE_ERROR_1:
case wvcdm::LICENSE_RESPONSE_PARSE_ERROR_2:
case wvcdm::LICENSE_RESPONSE_PARSE_ERROR_3:
case wvcdm::LOAD_KEY_ERROR:
case wvcdm::NO_CONTENT_KEY:
case wvcdm::REFRESH_KEYS_ERROR:
case wvcdm::REMOVE_ALL_USAGE_INFO_ERROR_1:
case wvcdm::REMOVE_ALL_USAGE_INFO_ERROR_2:
case wvcdm::RELEASE_KEY_ERROR:
case wvcdm::RELEASE_KEY_REQUEST_ERROR:
case wvcdm::RELEASE_LICENSE_ERROR_1:
case wvcdm::RELEASE_LICENSE_ERROR_2:
case wvcdm::RENEW_KEY_ERROR_1:
case wvcdm::RENEW_KEY_ERROR_2:
case wvcdm::RESTORE_OFFLINE_LICENSE_ERROR_2:
case wvcdm::RESTORE_OFFLINE_LICENSE_ERROR_3:
case wvcdm::NOT_INITIALIZED_ERROR:
case wvcdm::REINIT_ERROR:
case wvcdm::SESSION_KEYS_NOT_FOUND:
case wvcdm::SIGNATURE_NOT_FOUND:
case wvcdm::STORE_LICENSE_ERROR_1:
case wvcdm::STORE_LICENSE_ERROR_2:
case wvcdm::STORE_USAGE_INFO_ERROR:
case wvcdm::UNPROVISION_ERROR_1:
case wvcdm::UNPROVISION_ERROR_2:
case wvcdm::UNPROVISION_ERROR_3:
case wvcdm::UNPROVISION_ERROR_4:
case wvcdm::UNSUPPORTED_INIT_DATA:
case wvcdm::USAGE_INFO_NOT_FOUND:
case wvcdm::PARSE_SERVICE_CERTIFICATE_ERROR:
case wvcdm::CLIENT_ID_GENERATE_RANDOM_ERROR:
case wvcdm::CLIENT_ID_AES_INIT_ERROR:
case wvcdm::CLIENT_ID_AES_ENCRYPT_ERROR:
case wvcdm::CLIENT_ID_RSA_INIT_ERROR:
case wvcdm::CLIENT_ID_RSA_ENCRYPT_ERROR:
case wvcdm::LICENSE_PARSER_NOT_INITIALIZED_4:
case wvcdm::INVALID_PARAMETERS_LIC_3:
case wvcdm::INVALID_PARAMETERS_LIC_4:
case wvcdm::INVALID_PARAMETERS_LIC_6:
case wvcdm::INVALID_PARAMETERS_LIC_7:
case wvcdm::CENC_INIT_DATA_UNAVAILABLE:
case wvcdm::PREPARE_CENC_CONTENT_ID_FAILED:
case wvcdm::WEBM_INIT_DATA_UNAVAILABLE:
case wvcdm::PREPARE_WEBM_CONTENT_ID_FAILED:
case wvcdm::UNSUPPORTED_INIT_DATA_FORMAT:
case wvcdm::LICENSE_REQUEST_NONCE_GENERATION_ERROR:
case wvcdm::LICENSE_REQUEST_SERVICE_CERTIFICATE_GENERATION_ERROR:
case wvcdm::EMPTY_LICENSE_REQUEST:
case wvcdm::DUPLICATE_SESSION_ID_SPECIFIED:
case wvcdm::LICENSE_RENEWAL_PROHIBITED:
case wvcdm::EMPTY_PROVISIONING_CERTIFICATE_2:
case wvcdm::OFFLINE_LICENSE_PROHIBITED:
case wvcdm::STORAGE_PROHIBITED:
case wvcdm::EMPTY_KEYSET_ID_ENG_5:
case wvcdm::SESSION_NOT_FOUND_11:
case wvcdm::LOAD_USAGE_INFO_FILE_ERROR:
case wvcdm::LOAD_USAGE_INFO_MISSING:
case wvcdm::SESSION_FILE_HANDLE_INIT_ERROR:
case wvcdm::INCORRECT_CRYPTO_MODE:
case wvcdm::INVALID_PARAMETERS_ENG_5:
case wvcdm::SESSION_NOT_FOUND_12:
case wvcdm::KEY_NOT_FOUND_1:
case wvcdm::KEY_NOT_FOUND_2:
case wvcdm::KEY_CONFLICT_1:
case wvcdm::SESSION_NOT_FOUND_13:
case wvcdm::SESSION_NOT_FOUND_14:
case wvcdm::SESSION_NOT_FOUND_15:
case wvcdm::SESSION_NOT_FOUND_16:
case wvcdm::KEY_NOT_FOUND_3:
case wvcdm::KEY_NOT_FOUND_4:
case wvcdm::KEY_NOT_FOUND_5:
case wvcdm::KEY_NOT_FOUND_6:
case wvcdm::INVALID_SESSION_1:
case wvcdm::NO_DEVICE_KEY_1:
case wvcdm::NO_CONTENT_KEY_2:
case wvcdm::INVALID_PARAMETERS_ENG_13:
case wvcdm::INVALID_PARAMETERS_ENG_14:
case wvcdm::INVALID_PARAMETERS_ENG_15:
case wvcdm::INVALID_PARAMETERS_ENG_16:
case wvcdm::CLIENT_IDENTIFICATION_TOKEN_ERROR_1:
case wvcdm::UNKNOWN_SELECT_KEY_ERROR_1:
case wvcdm::UNKNOWN_SELECT_KEY_ERROR_2:
case wvcdm::CREATE_USAGE_TABLE_ERROR:
case wvcdm::LOAD_USAGE_HEADER_GENERATION_SKEW:
case wvcdm::LOAD_USAGE_HEADER_SIGNATURE_FAILURE:
case wvcdm::LOAD_USAGE_HEADER_BAD_MAGIC:
case wvcdm::LOAD_USAGE_HEADER_UNKNOWN_ERROR:
case wvcdm::CREATE_USAGE_ENTRY_UNKNOWN_ERROR:
case wvcdm::LOAD_USAGE_ENTRY_GENERATION_SKEW:
case wvcdm::LOAD_USAGE_ENTRY_SIGNATURE_FAILURE:
case wvcdm::LOAD_USAGE_ENTRY_UNKNOWN_ERROR:
case wvcdm::UPDATE_USAGE_ENTRY_UNKNOWN_ERROR:
case wvcdm::SHRINK_USAGE_TABLE_HEADER_UNKNOWN_ERROR:
case wvcdm::MOVE_USAGE_ENTRY_UNKNOWN_ERROR:
case wvcdm::COPY_OLD_USAGE_ENTRY_UNKNOWN_ERROR:
case wvcdm::INVALID_PARAMETERS_ENG_22:
case wvcdm::INVALID_PARAMETERS_ENG_23:
case wvcdm::USAGE_INFORMATION_SUPPORT_FAILED:
case wvcdm::USAGE_SUPPORT_GET_API_FAILED:
case wvcdm::UNEXPECTED_EMPTY_USAGE_ENTRY:
case wvcdm::INVALID_USAGE_ENTRY_NUMBER_MODIFICATION:
case wvcdm::USAGE_INVALID_NEW_ENTRY:
case wvcdm::USAGE_INVALID_PARAMETERS_1:
case wvcdm::USAGE_ENTRY_NUMBER_MISMATCH:
case wvcdm::USAGE_GET_ENTRY_RETRIEVE_INVALID_STORAGE_TYPE:
case wvcdm::USAGE_GET_ENTRY_RETRIEVE_LICENSE_FAILED:
case wvcdm::USAGE_GET_ENTRY_RETRIEVE_USAGE_INFO_FAILED:
case wvcdm::USAGE_STORE_ENTRY_RETRIEVE_INVALID_STORAGE_TYPE:
case wvcdm::USAGE_STORE_ENTRY_RETRIEVE_LICENSE_FAILED:
case wvcdm::USAGE_STORE_ENTRY_RETRIEVE_USAGE_INFO_FAILED:
case wvcdm::USAGE_STORE_LICENSE_FAILED:
case wvcdm::USAGE_STORE_USAGE_INFO_FAILED:
case wvcdm::USAGE_INVALID_LOAD_ENTRY:
case wvcdm::REMOVE_ALL_USAGE_INFO_ERROR_5:
case wvcdm::REMOVE_ALL_USAGE_INFO_ERROR_6:
case wvcdm::REMOVE_ALL_USAGE_INFO_ERROR_7:
case wvcdm::INCORRECT_USAGE_SUPPORT_TYPE_1:
case wvcdm::INCORRECT_USAGE_SUPPORT_TYPE_2:
case wvcdm::NO_USAGE_ENTRIES:
case wvcdm::LIST_LICENSE_ERROR_1:
case wvcdm::LIST_LICENSE_ERROR_2:
case wvcdm::LIST_USAGE_ERROR_1:
case wvcdm::LIST_USAGE_ERROR_2:
case wvcdm::DELETE_USAGE_ERROR_1:
case wvcdm::DELETE_USAGE_ERROR_2:
case wvcdm::DELETE_USAGE_ERROR_3:
case wvcdm::PRIVACY_MODE_ERROR_1:
case wvcdm::PRIVACY_MODE_ERROR_2:
case wvcdm::PRIVACY_MODE_ERROR_3:
case wvcdm::EMPTY_RESPONSE_ERROR_1:
case wvcdm::INVALID_PARAMETERS_ENG_24:
case wvcdm::PARSE_RESPONSE_ERROR_1:
case wvcdm::PARSE_RESPONSE_ERROR_2:
case wvcdm::PARSE_RESPONSE_ERROR_3:
case wvcdm::PARSE_RESPONSE_ERROR_4:
case wvcdm::LOAD_SYSTEM_ID_ERROR:
case wvcdm::REMOVE_USAGE_INFO_ERROR_1:
case wvcdm::REMOVE_USAGE_INFO_ERROR_2:
case wvcdm::REMOVE_USAGE_INFO_ERROR_3:
case wvcdm::NOT_AN_ENTITLEMENT_SESSION:
case wvcdm::LOAD_ENTITLED_CONTENT_KEYS_ERROR:
case wvcdm::GET_PROVISIONING_METHOD_ERROR:
case wvcdm::INVALID_SESSION_2:
case wvcdm::DEVICE_CANNOT_REPROVISION:
case wvcdm::SET_DECRYPT_HASH_ERROR:
case wvcdm::GET_DECRYPT_HASH_ERROR:
case wvcdm::INVALID_DECRYPT_HASH_FORMAT:
case wvcdm::EMPTY_LICENSE_REQUEST_2:
case wvcdm::EMPTY_LICENSE_REQUEST_3:
case wvcdm::EMPTY_LICENSE_RESPONSE_3:
case wvcdm::EMPTY_LICENSE_RESPONSE_4:
case wvcdm::PARSE_REQUEST_ERROR_1:
case wvcdm::PARSE_REQUEST_ERROR_2:
case wvcdm::INVALID_LICENSE_REQUEST_TYPE_1:
case wvcdm::INVALID_LICENSE_REQUEST_TYPE_2:
case wvcdm::LICENSE_RESPONSE_PARSE_ERROR_4:
case wvcdm::LICENSE_RESPONSE_PARSE_ERROR_5:
case wvcdm::INVALID_LICENSE_TYPE_2:
case wvcdm::SIGNATURE_NOT_FOUND_2:
case wvcdm::SESSION_KEYS_NOT_FOUND_2:
case wvcdm::GET_OFFLINE_LICENSE_STATE_ERROR_1:
case wvcdm::GET_OFFLINE_LICENSE_STATE_ERROR_2:
case wvcdm::REMOVE_OFFLINE_LICENSE_ERROR_1:
case wvcdm::REMOVE_OFFLINE_LICENSE_ERROR_2:
case wvcdm::OUTPUT_TOO_LARGE_ERROR:
case wvcdm::SESSION_LOST_STATE_ERROR:
case wvcdm::GENERATE_DERIVED_KEYS_ERROR_2:
case wvcdm::LOAD_DEVICE_RSA_KEY_ERROR:
case wvcdm::NONCE_GENERATION_ERROR:
case wvcdm::GENERATE_SIGNATURE_ERROR:
case wvcdm::UNKNOWN_CLIENT_TOKEN_TYPE:
case wvcdm::DEACTIVATE_USAGE_ENTRY_ERROR:
case wvcdm::SERVICE_CERTIFICATE_PROVIDER_ID_EMPTY:
case wvcdm::OPEN_CRYPTO_SESSION_ERROR:
case wvcdm::LOAD_SRM_ERROR:
case wvcdm::RANDOM_GENERATION_ERROR:
case wvcdm::CRYPTO_SESSION_NOT_INITIALIZED:
case wvcdm::GET_DEVICE_ID_ERROR:
case wvcdm::GET_TOKEN_FROM_OEM_CERT_ERROR:
case wvcdm::CRYPTO_SESSION_NOT_OPEN:
case wvcdm::GET_TOKEN_FROM_KEYBOX_ERROR:
case wvcdm::KEYBOX_TOKEN_TOO_SHORT:
case wvcdm::EXTRACT_SYSTEM_ID_FROM_OEM_CERT_ERROR:
case wvcdm::RSA_SIGNATURE_GENERATION_ERROR:
case wvcdm::GET_HDCP_CAPABILITY_FAILED:
case wvcdm::GET_NUMBER_OF_OPEN_SESSIONS_ERROR:
case wvcdm::GET_MAX_NUMBER_OF_OPEN_SESSIONS_ERROR:
case wvcdm::NOT_IMPLEMENTED_ERROR:
case wvcdm::GET_SRM_VERSION_ERROR:
case wvcdm::REWRAP_DEVICE_RSA_KEY_ERROR:
case wvcdm::INVALID_SRM_LIST:
case wvcdm::USAGE_INVALID_PARAMETERS_2:
case wvcdm::CORE_MESSAGE_NOT_FOUND:
case wvcdm::LOAD_PROVISIONING_ERROR:
case wvcdm::LOAD_LICENSE_ERROR:
case wvcdm::LOAD_RENEWAL_ERROR:
case wvcdm::CANNOT_DECRYPT_ZERO_SAMPLES:
case wvcdm::CANNOT_DECRYPT_ZERO_SUBSAMPLES:
case wvcdm::SAMPLE_AND_SUBSAMPLE_SIZE_MISMATCH:
case wvcdm::INVALID_IV_SIZE:
case wvcdm::LOAD_USAGE_ENTRY_INVALID_SESSION:
case wvcdm::MOVE_USAGE_ENTRY_DESTINATION_IN_USE:
case wvcdm::SHRINK_USAGE_TABLE_HEADER_ENTRY_IN_USE:
case wvcdm::LICENSE_USAGE_ENTRY_MISSING:
case wvcdm::PROVISIONING_NOT_ALLOWED_FOR_ATSC:
case wvcdm::NO_SRM_VERSION:
case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_9:
case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_10:
case wvcdm::CLIENT_TOKEN_NOT_SET:
case wvcdm::USAGE_ENTRY_ALREADY_LOADED:
case wvcdm::PARSE_OKP_RESPONSE_ERROR:
case wvcdm::OKP_ALREADY_PROVISIONED:
case wvcdm::PROVISIONING_TYPE_IS_NOT_BOOT_CERTIFICATE_CHAIN_ERROR:
case wvcdm::GET_BOOT_CERTIFICATE_CHAIN_ERROR:
case wvcdm::GENERATE_CERTIFICATE_KEY_PAIR_ERROR:
case wvcdm::GENERATE_CERTIFICATE_KEY_PAIR_UNKNOWN_TYPE_ERROR:
case wvcdm::LOAD_OEM_CERTIFICATE_PRIVATE_KEY_ERROR:
case wvcdm::PROVISIONING_4_CRYPTO_SESSION_NOT_OPEN:
case wvcdm::PROVISIONING_4_FILE_SYSTEM_IS_NULL:
case wvcdm::PROVISIONING_4_FAILED_TO_INITIALIZE_DEVICE_FILES:
case wvcdm::PROVISIONING_4_RESPONSE_FAILED_TO_PARSE_MESSAGE:
case wvcdm::PROVISIONING_4_RESPONSE_HAS_ERROR_STATUS:
case wvcdm::PROVISIONING_4_RESPONSE_HAS_NO_CERTIFICATE:
case wvcdm::PROVISIONING_4_NO_PRIVATE_KEY:
case wvcdm::PROVISIONING_4_FAILED_TO_INITIALIZE_DEVICE_FILES_2:
case wvcdm::PROVISIONING_4_FAILED_TO_STORE_OEM_CERTIFICATE:
case wvcdm::PROVISIONING_4_FAILED_TO_STORE_DRM_CERTIFICATE:
case wvcdm::PROVISIONING_4_FAILED_TO_INITIALIZE_DEVICE_FILES_3:
ALOGW("Returns UNKNOWN error for legacy status: %d", res);
return Status::ERROR_DRM_UNKNOWN;
case wvcdm::UNKNOWN_ERROR:
return Status::ERROR_DRM_UNKNOWN;
}
// Return here instead of as a default case so that the compiler will warn
// us if we forget to include an enum member in the switch statement.
return Status::ERROR_DRM_UNKNOWN;
}
static Status_V1_2 mapCdmResponseType_1_2(
wvcdm::CdmResponseType res) {
switch(res) {
case wvcdm::KEY_PROHIBITED_FOR_SECURITY_LEVEL:
return Status_V1_2::ERROR_DRM_INSUFFICIENT_SECURITY;
case wvcdm::OUTPUT_TOO_LARGE_ERROR:
return Status_V1_2::ERROR_DRM_FRAME_TOO_LARGE;
case wvcdm::SESSION_LOST_STATE_ERROR:
return Status_V1_2::ERROR_DRM_SESSION_LOST_STATE;
case wvcdm::LICENSE_REQUEST_NONCE_GENERATION_ERROR:
case wvcdm::LICENSE_RENEWAL_NONCE_GENERATION_ERROR:
case wvcdm::CERT_PROVISIONING_NONCE_GENERATION_ERROR:
case wvcdm::NONCE_GENERATION_ERROR:
// These are likely nonce flood errors
return Status_V1_2::ERROR_DRM_RESOURCE_CONTENTION;
default:
return static_cast<Status_V1_2>(mapCdmResponseType_1_0(res));
}
}
template<typename S=Status>
static S mapCdmResponseType(wvcdm::CdmResponseType res) {
::drm::V1_4::Status err = ::drm::V1_4::Status::ERROR_DRM_UNKNOWN;
switch(res) {
case wvcdm::CANNOT_DECRYPT_ZERO_SUBSAMPLES:
err = ::drm::V1_4::Status::CANNOT_DECRYPT_ZERO_SUBSAMPLES;
break;
case wvcdm::CLIENT_ID_AES_ENCRYPT_ERROR:
case wvcdm::CLIENT_ID_AES_INIT_ERROR:
case wvcdm::CLIENT_ID_RSA_ENCRYPT_ERROR:
err = ::drm::V1_4::Status::CRYPTO_LIBRARY_ERROR;
break;
case wvcdm::PROVISIONING_NOT_ALLOWED_FOR_ATSC:
err = ::drm::V1_4::Status::ERROR_DRM_CANNOT_HANDLE;
break;
case wvcdm::CERT_PROVISIONING_REQUEST_ERROR_4:
case wvcdm::CLIENT_IDENTIFICATION_TOKEN_ERROR_1:
case wvcdm::CREATE_USAGE_ENTRY_UNKNOWN_ERROR:
case wvcdm::CREATE_USAGE_TABLE_ERROR:
case wvcdm::DEACTIVATE_USAGE_ENTRY_ERROR:
case wvcdm::EMPTY_LICENSE_RENEWAL:
case wvcdm::EMPTY_LICENSE_REQUEST:
case wvcdm::EXTRACT_SYSTEM_ID_FROM_OEM_CERT_ERROR:
case wvcdm::GENERATE_DERIVED_KEYS_ERROR:
case wvcdm::GENERATE_DERIVED_KEYS_ERROR_2:
case wvcdm::GENERATE_SIGNATURE_ERROR:
case wvcdm::GENERATE_USAGE_REPORT_ERROR:
case wvcdm::GET_DECRYPT_HASH_ERROR:
case wvcdm::GET_DEVICE_ID_ERROR:
case wvcdm::GET_HDCP_CAPABILITY_FAILED:
case wvcdm::GET_MAX_NUMBER_OF_OPEN_SESSIONS_ERROR:
case wvcdm::GET_NUMBER_OF_OPEN_SESSIONS_ERROR:
case wvcdm::GET_PROVISIONING_METHOD_ERROR:
case wvcdm::GET_SRM_VERSION_ERROR:
case wvcdm::GET_TOKEN_FROM_KEYBOX_ERROR:
case wvcdm::GET_TOKEN_FROM_OEM_CERT_ERROR:
case wvcdm::INVALID_DECRYPT_HASH_FORMAT:
case wvcdm::INVALID_SESSION_1:
case wvcdm::INVALID_SESSION_2:
case wvcdm::KEYBOX_TOKEN_TOO_SHORT:
case wvcdm::LOAD_USAGE_ENTRY_UNKNOWN_ERROR:
case wvcdm::LOAD_USAGE_HEADER_UNKNOWN_ERROR:
case wvcdm::MOVE_USAGE_ENTRY_UNKNOWN_ERROR:
case wvcdm::OPEN_CRYPTO_SESSION_ERROR:
case wvcdm::RANDOM_GENERATION_ERROR:
case wvcdm::SET_DECRYPT_HASH_ERROR:
case wvcdm::SHRINK_USAGE_TABLE_HEADER_UNKNOWN_ERROR:
case wvcdm::UNKNOWN_CLIENT_TOKEN_TYPE:
case wvcdm::UNKNOWN_SELECT_KEY_ERROR_1:
case wvcdm::UNKNOWN_SELECT_KEY_ERROR_2:
case wvcdm::UPDATE_USAGE_ENTRY_UNKNOWN_ERROR:
case wvcdm::USAGE_SUPPORT_GET_API_FAILED:
err = ::drm::V1_4::Status::GENERAL_OEM_ERROR;
break;
case wvcdm::CANNOT_DECRYPT_ZERO_SAMPLES:
case wvcdm::CERT_PROVISIONING_REQUEST_ERROR_1:
case wvcdm::CLIENT_TOKEN_NOT_SET:
case wvcdm::CRYPTO_SESSION_NOT_INITIALIZED:
case wvcdm::CRYPTO_SESSION_NOT_OPEN:
case wvcdm::DEVICE_CANNOT_REPROVISION:
case wvcdm::DEVICE_CERTIFICATE_ERROR_1:
case wvcdm::DUPLICATE_SESSION_ID_SPECIFIED:
case wvcdm::EMPTY_KEYSET_ID_ENG_5:
case wvcdm::EMPTY_RESPONSE_ERROR_1:
case wvcdm::EMPTY_SESSION_ID:
case wvcdm::GENERATE_CERTIFICATE_KEY_PAIR_ERROR:
case wvcdm::GENERATE_CERTIFICATE_KEY_PAIR_UNKNOWN_TYPE_ERROR:
case wvcdm::GET_BOOT_CERTIFICATE_CHAIN_ERROR:
case wvcdm::INCORRECT_USAGE_SUPPORT_TYPE_1:
case wvcdm::INCORRECT_USAGE_SUPPORT_TYPE_2:
case wvcdm::INVALID_IV_SIZE:
case wvcdm::INVALID_KEY_SYSTEM:
case wvcdm::INVALID_PARAMETERS_ENG_22:
case wvcdm::INVALID_PARAMETERS_ENG_23:
case wvcdm::INVALID_PARAMETERS_ENG_24:
case wvcdm::INVALID_PARAMETERS_LIC_1:
case wvcdm::INVALID_PARAMETERS_LIC_2:
case wvcdm::INVALID_PARAMETERS_LIC_6:
case wvcdm::INVALID_PARAMETERS_LIC_7:
case wvcdm::INVALID_PROVISIONING_PARAMETERS_1:
case wvcdm::INVALID_PROVISIONING_PARAMETERS_2:
case wvcdm::INVALID_PROVISIONING_REQUEST_PARAM_1:
case wvcdm::INVALID_PROVISIONING_REQUEST_PARAM_2:
case wvcdm::INVALID_SESSION_ID:
case wvcdm::KEYSET_ID_NOT_FOUND_1:
case wvcdm::KEYSET_ID_NOT_FOUND_2:
case wvcdm::KEYSET_ID_NOT_FOUND_3:
case wvcdm::KEY_CONFLICT_1:
case wvcdm::KEY_NOT_FOUND_2:
case wvcdm::KEY_REQUEST_ERROR_1:
case wvcdm::LICENSE_PARSER_NOT_INITIALIZED_1:
case wvcdm::LICENSE_PARSER_NOT_INITIALIZED_2:
case wvcdm::LICENSE_PARSER_NOT_INITIALIZED_3:
case wvcdm::LICENSE_PARSER_NOT_INITIALIZED_4:
case wvcdm::LICENSE_REQUEST_SERVICE_CERTIFICATE_GENERATION_ERROR:
case wvcdm::LICENSE_USAGE_ENTRY_MISSING:
case wvcdm::LOAD_ENTITLED_CONTENT_KEYS_ERROR:
case wvcdm::LOAD_OEM_CERTIFICATE_PRIVATE_KEY_ERROR:
case wvcdm::LOAD_USAGE_ENTRY_GENERATION_SKEW:
case wvcdm::LOAD_USAGE_ENTRY_INVALID_SESSION:
case wvcdm::LOAD_USAGE_ENTRY_SIGNATURE_FAILURE:
case wvcdm::LOAD_USAGE_HEADER_BAD_MAGIC:
case wvcdm::LOAD_USAGE_HEADER_GENERATION_SKEW:
case wvcdm::LOAD_USAGE_HEADER_SIGNATURE_FAILURE:
case wvcdm::LOAD_USAGE_INFO_MISSING:
case wvcdm::MOVE_USAGE_ENTRY_DESTINATION_IN_USE:
case wvcdm::NOT_IMPLEMENTED_ERROR:
case wvcdm::NOT_INITIALIZED_ERROR:
case wvcdm::NO_SRM_VERSION:
case wvcdm::NO_USAGE_ENTRIES:
case wvcdm::PARAMETER_NULL:
case wvcdm::PREPARE_CENC_CONTENT_ID_FAILED:
case wvcdm::PREPARE_WEBM_CONTENT_ID_FAILED:
case wvcdm::PROVISIONING_4_CRYPTO_SESSION_NOT_OPEN:
case wvcdm::PROVISIONING_4_FAILED_TO_INITIALIZE_DEVICE_FILES:
case wvcdm::PROVISIONING_4_FILE_SYSTEM_IS_NULL:
case wvcdm::PROVISIONING_4_NO_PRIVATE_KEY:
case wvcdm::PROVISIONING_TYPE_IS_NOT_BOOT_CERTIFICATE_CHAIN_ERROR:
case wvcdm::REINIT_ERROR:
case wvcdm::REMOVE_OFFLINE_LICENSE_ERROR_2:
case wvcdm::REMOVE_USAGE_INFO_ERROR_3:
case wvcdm::SESSION_NOT_FOUND_11:
case wvcdm::SESSION_NOT_FOUND_12:
case wvcdm::SESSION_NOT_FOUND_13:
case wvcdm::SESSION_NOT_FOUND_14:
case wvcdm::SESSION_NOT_FOUND_15:
case wvcdm::SESSION_NOT_FOUND_16:
case wvcdm::SHRINK_USAGE_TABLE_HEADER_ENTRY_IN_USE:
case wvcdm::STORAGE_PROHIBITED:
case wvcdm::STORE_LICENSE_ERROR_2:
case wvcdm::USAGE_ENTRY_NUMBER_MISMATCH:
case wvcdm::USAGE_GET_ENTRY_RETRIEVE_INVALID_STORAGE_TYPE:
case wvcdm::USAGE_INFORMATION_SUPPORT_FAILED:
case wvcdm::USAGE_INVALID_LOAD_ENTRY:
case wvcdm::USAGE_INVALID_NEW_ENTRY:
case wvcdm::USAGE_INVALID_PARAMETERS_1:
case wvcdm::USAGE_INVALID_PARAMETERS_2:
case wvcdm::USAGE_STORE_ENTRY_RETRIEVE_INVALID_STORAGE_TYPE:
err = ::drm::V1_4::Status::GENERAL_PLUGIN_ERROR;
break;
case wvcdm::CLIENT_ID_GENERATE_RANDOM_ERROR:
err = ::drm::V1_4::Status::ERROR_DRM_RESOURCE_CONTENTION;
break;
case wvcdm::CENC_INIT_DATA_UNAVAILABLE:
case wvcdm::INIT_DATA_NOT_FOUND:
case wvcdm::INVALID_PARAMETERS_LIC_3:
case wvcdm::INVALID_PARAMETERS_LIC_4:
case wvcdm::UNSUPPORTED_INIT_DATA:
case wvcdm::UNSUPPORTED_INIT_DATA_FORMAT:
case wvcdm::WEBM_INIT_DATA_UNAVAILABLE:
err = ::drm::V1_4::Status::INIT_DATA_INVALID;
break;
case wvcdm::EMPTY_KEYSET_ID:
case wvcdm::EMPTY_KEYSET_ID_ENG_1:
case wvcdm::EMPTY_KEYSET_ID_ENG_2:
case wvcdm::EMPTY_KEYSET_ID_ENG_3:
case wvcdm::EMPTY_KEYSET_ID_ENG_4:
case wvcdm::EMPTY_LICENSE_RESPONSE_1:
case wvcdm::EMPTY_LICENSE_RESPONSE_2:
case wvcdm::EMPTY_PROVISIONING_RESPONSE:
case wvcdm::INVALID_PARAMETERS_ENG_13:
case wvcdm::INVALID_PARAMETERS_ENG_14:
case wvcdm::INVALID_PARAMETERS_ENG_15:
case wvcdm::INVALID_PARAMETERS_ENG_16:
case wvcdm::INVALID_QUERY_KEY:
case wvcdm::KEY_NOT_FOUND_1:
case wvcdm::SAMPLE_AND_SUBSAMPLE_SIZE_MISMATCH:
err = ::drm::V1_4::Status::BAD_VALUE;
break;
case wvcdm::KEY_NOT_FOUND_3:
case wvcdm::KEY_NOT_FOUND_4:
case wvcdm::KEY_NOT_FOUND_5:
case wvcdm::KEY_NOT_FOUND_6:
err = ::drm::V1_4::Status::KEY_NOT_LOADED;
break;
case wvcdm::ADD_KEY_ERROR:
case wvcdm::CORE_MESSAGE_NOT_FOUND:
case wvcdm::EMPTY_KEY_DATA_1:
case wvcdm::EMPTY_KEY_DATA_2:
case wvcdm::INVALID_LICENSE_RESPONSE:
case wvcdm::INVALID_LICENSE_TYPE:
case wvcdm::INVALID_SRM_LIST:
case wvcdm::KEY_SIZE_ERROR_1:
case wvcdm::KEY_SIZE_ERROR_2:
case wvcdm::LICENSE_ID_NOT_FOUND:
case wvcdm::LICENSE_RESPONSE_NOT_SIGNED:
case wvcdm::LICENSE_RESPONSE_PARSE_ERROR_1:
case wvcdm::LICENSE_RESPONSE_PARSE_ERROR_2:
case wvcdm::LICENSE_RESPONSE_PARSE_ERROR_3:
case wvcdm::LICENSE_RESPONSE_PARSE_ERROR_4:
case wvcdm::LICENSE_RESPONSE_PARSE_ERROR_5:
case wvcdm::LOAD_KEY_ERROR:
case wvcdm::LOAD_LICENSE_ERROR:
case wvcdm::LOAD_RENEWAL_ERROR:
case wvcdm::LOAD_SRM_ERROR:
case wvcdm::NOT_AN_ENTITLEMENT_SESSION:
case wvcdm::NO_CONTENT_KEY:
case wvcdm::NO_CONTENT_KEY_2:
case wvcdm::NO_DEVICE_KEY_1:
case wvcdm::PROVISIONING_4_RESPONSE_FAILED_TO_PARSE_MESSAGE:
case wvcdm::REFRESH_KEYS_ERROR:
case wvcdm::SESSION_KEYS_NOT_FOUND:
case wvcdm::SIGNATURE_NOT_FOUND:
err = ::drm::V1_4::Status::LICENSE_PARSE_ERROR;
break;
case wvcdm::LICENSE_RENEWAL_PROHIBITED:
case wvcdm::OFFLINE_LICENSE_PROHIBITED:
err = ::drm::V1_4::Status::LICENSE_POLICY_ERROR;
break;
case wvcdm::PARSE_REQUEST_ERROR_2:
case wvcdm::RELEASE_LICENSE_ERROR_1:
case wvcdm::SESSION_KEYS_NOT_FOUND_2:
err = ::drm::V1_4::Status::LICENSE_RELEASE_ERROR;
break;
case wvcdm::KEY_ERROR:
case wvcdm::RELEASE_KEY_ERROR:
case wvcdm::RENEW_KEY_ERROR_1:
err = ::drm::V1_4::Status::LICENSE_REQUEST_REJECTED;
break;
case wvcdm::EMPTY_LICENSE_REQUEST_2:
case wvcdm::EMPTY_LICENSE_REQUEST_3:
case wvcdm::EMPTY_LICENSE_RESPONSE_3:
case wvcdm::EMPTY_LICENSE_RESPONSE_4:
case wvcdm::INVALID_LICENSE_REQUEST_TYPE_1:
case wvcdm::INVALID_LICENSE_REQUEST_TYPE_2:
case wvcdm::INVALID_LICENSE_TYPE_2:
case wvcdm::PARSE_REQUEST_ERROR_1:
case wvcdm::RESTORE_OFFLINE_LICENSE_ERROR_2:
case wvcdm::SIGNATURE_NOT_FOUND_2:
err = ::drm::V1_4::Status::LICENSE_RESTORE_ERROR;
break;
case wvcdm::GET_RELEASED_LICENSE_ERROR:
case wvcdm::RESTORE_OFFLINE_LICENSE_ERROR_3:
case wvcdm::USAGE_ENTRY_ALREADY_LOADED:
err = ::drm::V1_4::Status::LICENSE_STATE_ERROR;
break;
case wvcdm::DEVICE_CERTIFICATE_ERROR_2:
case wvcdm::DEVICE_CERTIFICATE_ERROR_3:
case wvcdm::DEVICE_CERTIFICATE_ERROR_4:
case wvcdm::LICENSE_PARSER_INIT_ERROR:
case wvcdm::PARSE_RESPONSE_ERROR_1:
case wvcdm::PARSE_RESPONSE_ERROR_2:
case wvcdm::PARSE_RESPONSE_ERROR_3:
case wvcdm::PARSE_RESPONSE_ERROR_4:
err = ::drm::V1_4::Status::MALFORMED_CERTIFICATE;
break;
case wvcdm::INVALID_DECRYPT_PARAMETERS_ENG_2:
case wvcdm::INVALID_DECRYPT_PARAMETERS_ENG_4:
err = ::drm::V1_4::Status::MEDIA_FRAMEWORK_ERROR;
break;
case wvcdm::PRIVACY_MODE_ERROR_1:
case wvcdm::PRIVACY_MODE_ERROR_2:
case wvcdm::PRIVACY_MODE_ERROR_3:
err = ::drm::V1_4::Status::MISSING_CERTIFICATE;
break;
case wvcdm::LOAD_DEVICE_RSA_KEY_ERROR:
err = ::drm::V1_4::Status::PROVISIONING_CERTIFICATE_ERROR;
break;
case wvcdm::CERT_PROVISIONING_EMPTY_SERVICE_CERTIFICATE:
case wvcdm::PROVISIONING_4_RESPONSE_HAS_NO_CERTIFICATE:
case wvcdm::SERVICE_CERTIFICATE_PROVIDER_ID_EMPTY:
err = ::drm::V1_4::Status::PROVISIONING_CONFIGURATION_ERROR;
break;
case wvcdm::CERT_PROVISIONING_INVALID_CERT_TYPE:
case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_1:
case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_2:
case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_3:
case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_4:
case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_9:
case wvcdm::LOAD_PROVISIONING_ERROR:
err = ::drm::V1_4::Status::PROVISIONING_PARSE_ERROR;
break;
case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_10:
case wvcdm::PROVISIONING_4_RESPONSE_HAS_ERROR_STATUS:
err = ::drm::V1_4::Status::PROVISIONING_REQUEST_REJECTED;
break;
case wvcdm::EMPTY_PROVISIONING_CERTIFICATE_1:
case wvcdm::EMPTY_PROVISIONING_CERTIFICATE_2:
err = ::drm::V1_4::Status::RETRYABLE_PROVISIONING_ERROR;
break;
case wvcdm::RELEASE_LICENSE_ERROR_2:
err = ::drm::V1_4::Status::SECURE_STOP_RELEASE_ERROR;
break;
case wvcdm::GET_LICENSE_ERROR:
case wvcdm::GET_OFFLINE_LICENSE_STATE_ERROR_1:
case wvcdm::GET_OFFLINE_LICENSE_STATE_ERROR_2:
case wvcdm::GET_USAGE_INFO_ERROR_1:
case wvcdm::GET_USAGE_INFO_ERROR_2:
case wvcdm::GET_USAGE_INFO_ERROR_3:
case wvcdm::GET_USAGE_INFO_ERROR_4:
case wvcdm::LIST_LICENSE_ERROR_1:
case wvcdm::LIST_LICENSE_ERROR_2:
case wvcdm::LIST_USAGE_ERROR_1:
case wvcdm::LIST_USAGE_ERROR_2:
case wvcdm::LOAD_USAGE_INFO_FILE_ERROR:
case wvcdm::REMOVE_OFFLINE_LICENSE_ERROR_1:
case wvcdm::REMOVE_USAGE_INFO_ERROR_2:
case wvcdm::SESSION_FILE_HANDLE_INIT_ERROR:
case wvcdm::UNPROVISION_ERROR_1:
case wvcdm::USAGE_GET_ENTRY_RETRIEVE_LICENSE_FAILED:
case wvcdm::USAGE_GET_ENTRY_RETRIEVE_USAGE_INFO_FAILED:
case wvcdm::USAGE_INFO_NOT_FOUND:
case wvcdm::USAGE_STORE_ENTRY_RETRIEVE_LICENSE_FAILED:
case wvcdm::USAGE_STORE_ENTRY_RETRIEVE_USAGE_INFO_FAILED:
err = ::drm::V1_4::Status::STORAGE_READ_FAILURE;
break;
case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_7:
case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_8:
case wvcdm::DELETE_USAGE_ERROR_1:
case wvcdm::DELETE_USAGE_ERROR_2:
case wvcdm::PROVISIONING_4_FAILED_TO_INITIALIZE_DEVICE_FILES_2:
case wvcdm::PROVISIONING_4_FAILED_TO_STORE_DRM_CERTIFICATE:
case wvcdm::PROVISIONING_4_FAILED_TO_STORE_OEM_CERTIFICATE:
case wvcdm::RELEASE_KEY_REQUEST_ERROR:
case wvcdm::REMOVE_ALL_USAGE_INFO_ERROR_5:
case wvcdm::REMOVE_USAGE_INFO_ERROR_1:
case wvcdm::RENEW_KEY_ERROR_2:
case wvcdm::STORE_LICENSE_ERROR_1:
case wvcdm::STORE_USAGE_INFO_ERROR:
case wvcdm::UNPROVISION_ERROR_2:
case wvcdm::UNPROVISION_ERROR_3:
case wvcdm::USAGE_STORE_LICENSE_FAILED:
case wvcdm::USAGE_STORE_USAGE_INFO_FAILED:
err = ::drm::V1_4::Status::STORAGE_WRITE_FAILURE;
break;
default:
return static_cast<S>(mapCdmResponseType_1_2(res));
}
return static_cast<S>(err);
}
static inline bool isCdmResponseTypeSuccess(wvcdm::CdmResponseType res) {
return mapCdmResponseType(res) == Status::OK;
}
} // namespace wvdrm
#endif // WV_MAP_ERRORS_H_

View File

@@ -1,66 +0,0 @@
//
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
#ifndef HIDL_TYPES_H_
#define HIDL_TYPES_H_
#include <android/hardware/drm/1.1/types.h>
#include <android/hardware/drm/1.2/types.h>
#include <android/hardware/drm/1.2/IDrmPluginListener.h>
#include <android/hardware/drm/1.4/types.h>
#include <android/hardware/drm/1.4/ICryptoFactory.h>
#include <android/hardware/drm/1.4/ICryptoPlugin.h>
#include <android/hardware/drm/1.4/IDrmFactory.h>
#include <android/hardware/drm/1.4/IDrmPlugin.h>
#include <hidl/HidlTransportSupport.h>
using ::android::hardware::configureRpcThreadpool;
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_handle;
using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::joinRpcThreadpool;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::sp;
namespace drm = ::android::hardware::drm;
using drm::V1_0::BufferType;
using drm::V1_0::DestinationBuffer;
using drm::V1_0::EventType;
using drm::V1_0::IDrmPluginListener;
using drm::V1_0::KeyRequestType;
using drm::V1_0::KeyStatus;
using drm::V1_0::KeyStatusType;
using drm::V1_0::KeyType;
using drm::V1_0::KeyValue;
using drm::V1_0::Mode;
using drm::V1_0::Pattern;
using drm::V1_0::SecureStop;
using drm::V1_0::SecureStopId;
using drm::V1_0::SharedBuffer;
using drm::V1_0::Status;
using drm::V1_0::SubSample;
using drm::V1_1::DrmMetricGroup;
using drm::V1_1::HdcpLevel;
using drm::V1_1::SecureStopRelease;
using drm::V1_1::SecurityLevel;
using drm::V1_2::ICryptoPlugin;
using drm::V1_2::IDrmPlugin;
using drm::V1_2::KeySetId;
using drm::V1_2::OfflineLicenseState;
using drm::V1_3::ICryptoFactory;
using drm::V1_3::IDrmFactory;
typedef drm::V1_1::KeyRequestType KeyRequestType_V1_1;
typedef drm::V1_2::KeyStatus KeyStatus_V1_2;
typedef drm::V1_2::KeyStatusType KeyStatusType_V1_2;
typedef drm::V1_2::IDrmPluginListener IDrmPluginListener_V1_2;
typedef drm::V1_2::Status Status_V1_2;
typedef drm::V1_2::HdcpLevel HdcpLevel_V1_2;
#endif

View File

@@ -1,28 +0,0 @@
//
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
#ifndef WV_CREATE_PLUGIN_FACTORIES_H_
#define WV_CREATE_PLUGIN_FACTORIES_H_
#include "HidlTypes.h"
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_4 {
namespace widevine {
extern "C" {
::drm::V1_4::IDrmFactory* createDrmFactory();
::drm::V1_4::ICryptoFactory* createCryptoFactory();
}
} // namespace widevine
} // namespace V1_4
} // namespace drm
} // namespace hardware
} // namespace wvdrm
#endif // WV_CREATE_PLUGIN_FACTORIES_H_

View File

@@ -1,68 +0,0 @@
//
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
#ifndef WV_DRM_FACTORY_H_
#define WV_DRM_FACTORY_H_
#include "HidlTypes.h"
#include "HidlWVTypes.h"
#include "WVGenericCryptoInterface.h"
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_4 {
namespace widevine {
using ::android::hardware::hidl_handle;
using ::android::hardware::hidl_vec;
struct WVDrmFactory : public ::drm::V1_4::IDrmFactory {
WVDrmFactory() {}
virtual ~WVDrmFactory() {}
Return<bool> isCryptoSchemeSupported(
const hidl_array<uint8_t, 16>& uuid) override;
Return<bool> isCryptoSchemeSupported_1_2(const hidl_array<uint8_t, 16>& uuid,
const hidl_string& mimeType,
SecurityLevel level) override;
Return<bool> isContentTypeSupported(const hidl_string& mimeType) override;
Return<void> createPlugin(const hidl_array<uint8_t, 16>& uuid,
const hidl_string& appPackageName,
createPlugin_cb _hidl_cb) override;
Return<void> getSupportedCryptoSchemes(
getSupportedCryptoSchemes_cb _hidl_cb) override;
Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args);
private:
WVDRM_DISALLOW_COPY_AND_ASSIGN(WVDrmFactory);
static WVGenericCryptoInterface sOemCryptoInterface;
static bool areSpoidsEnabled();
static bool isBlankAppPackageNameAllowed();
static int32_t firstApiLevel();
static std::string stringToHex(const std::string& input);
static void printCdmMetrics(FILE* out);
static void printCdmProperties(FILE* out);
friend class WVDrmFactoryTestPeer;
};
extern "C" IDrmFactory* HIDL_FETCH_IDrmFactory(const char* name);
} // namespace widevine
} // namespace V1_4
} // namespace drm
} // namespace hardware
} // namespace wvdrm
#endif // WV_DRM_FACTORY_H_

View File

@@ -1,22 +0,0 @@
//
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
#ifndef WV_TYPES_H_
#define WV_TYPES_H_
namespace wvdrm {
#define WVDRM_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&) = delete; \
void operator=(const TypeName&) = delete;
#define WVDRM_DISALLOW_COPY_AND_ASSIGN_AND_NEW(TypeName) \
TypeName() = delete; \
TypeName(const TypeName&) = delete; \
void operator=(const TypeName&) = delete;
} // namespace wvdrm
#endif // WV_TYPES_H_

View File

@@ -1,119 +0,0 @@
/*
* Copyright (C) 2017 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 WVDRM_ANDROID_HARDWARE_DRM_V1_1_TYPECONVERT
#define WVDRM_ANDROID_HARDWARE_DRM_V1_1_TYPECONVERT
#include <vector>
#include "HidlTypes.h"
#include "log.h"
#include "media/stagefright/MediaErrors.h"
#include "utils/Errors.h"
namespace android {
namespace hardware {
namespace drm {
namespace V1_2 {
namespace widevine {
inline ::drm::V1_4::LogPriority toHidlPriority(wvutil::LogPriority p) {
switch (p) {
case wvutil::LogPriority::CDM_LOG_ERROR:
return ::drm::V1_4::LogPriority::ERROR;
case wvutil::LogPriority::CDM_LOG_WARN:
return ::drm::V1_4::LogPriority::WARN;
case wvutil::LogPriority::CDM_LOG_INFO:
return ::drm::V1_4::LogPriority::INFO;
case wvutil::LogPriority::CDM_LOG_DEBUG:
return ::drm::V1_4::LogPriority::DEBUG;
case wvutil::LogPriority::CDM_LOG_VERBOSE:
return ::drm::V1_4::LogPriority::VERBOSE;
default:
return ::drm::V1_4::LogPriority::UNKNOWN;
}
return ::drm::V1_4::LogPriority::UNKNOWN;
}
template <typename T, typename U>
hidl_vec<T> toHidlVec(const std::vector<U> &vec);
template<>
inline hidl_vec<::drm::V1_4::LogMessage> toHidlVec(const std::vector<wvutil::LogMessage> &vec) {
uint32_t uid = wvutil::GetIpcCallingUid();
std::vector<::drm::V1_4::LogMessage> vec2;
for (auto msg : vec) {
if (uid == msg.uid_) {
vec2.push_back({
msg.time_ms_,
toHidlPriority(msg.priority_),
msg.message_,
});
}
}
return hidl_vec<::drm::V1_4::LogMessage>(vec2);
}
template <typename T>
const hidl_vec<T> toHidlVec(const std::vector<T> &vec) {
hidl_vec<T> hVec;
hVec.setToExternal(const_cast<T *>(vec.data()), vec.size());
return hVec;
}
template <typename T>
hidl_vec<T> toHidlVec(std::vector<T> &vec) {
hidl_vec<T> hVec;
hVec.setToExternal(vec.data(), vec.size());
return hVec;
}
template <typename T>
const std::vector<T> toVector(const hidl_vec<T> &hVec) {
std::vector<T> vec;
vec.assign(hVec.data(), hVec.data() + hVec.size());
return *const_cast<const std::vector<T> *>(&vec);
}
template <typename T>
std::vector<T> toVector(hidl_vec<T> &hVec) {
std::vector<T> vec;
vec.assign(hVec.data(), hVec.data() + hVec.size());
return vec;
}
template <typename T, size_t SIZE>
const std::vector<T> toVector(const hidl_array<T, SIZE> &hArray) {
std::vector<T> vec;
vec.assign(hArray.data(), hArray.data() + hArray.size());
return vec;
}
template <typename T, size_t SIZE>
std::vector<T> toVector(hidl_array<T, SIZE> &hArray) {
std::vector<T> vec;
vec.assign(hArray.data(), hArray.data() + hArray.size());
return vec;
}
} // namespace widevine
} // namespace V1_2
} // namespace drm
} // namespace hardware
} // namespace android
#endif // WVDRM_ANDROID_HARDWARE_DRM_V1_0_TYPECONVERT

View File

@@ -1,42 +0,0 @@
//
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
#ifndef WV_CRYPTO_FACTORY_H_
#define WV_CRYPTO_FACTORY_H_
#include "HidlTypes.h"
#include "HidlWVTypes.h"
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_4 {
namespace widevine {
struct WVCryptoFactory : public ::drm::V1_4::ICryptoFactory {
public:
WVCryptoFactory() {}
virtual ~WVCryptoFactory() {}
Return<bool> isCryptoSchemeSupported(const hidl_array<uint8_t, 16>& uuid)
override;
Return<void> createPlugin(
const hidl_array<uint8_t, 16>& uuid,
const hidl_vec<uint8_t>& initData,
createPlugin_cb _hidl_cb) override;
private:
WVDRM_DISALLOW_COPY_AND_ASSIGN(WVCryptoFactory);
};
} // namespace widevine
} // namespace V1_4
} // namespace drm
} // namespace hardware
} // namespace wvdrm
#endif // WV_CRYPTO_FACTORY_H_

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2019 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.
-->
<manifest version="1.0" type="device">
<hal format="hidl">
<name>android.hardware.drm</name>
<transport>hwbinder</transport>
<fqname>@1.2::ICryptoFactory/widevine</fqname>
<fqname>@1.2::IDrmFactory/widevine</fqname>
</hal>
</manifest>

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2019 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.
-->
<manifest version="1.0" type="device">
<hal format="hidl">
<name>android.hardware.drm</name>
<transport>hwbinder</transport>
<fqname>@1.3::ICryptoFactory/widevine</fqname>
<fqname>@1.3::IDrmFactory/widevine</fqname>
</hal>
</manifest>

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2021 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.
-->
<manifest version="1.0" type="device">
<hal format="hidl">
<name>android.hardware.drm</name>
<transport>hwbinder</transport>
<fqname>@1.4::ICryptoFactory/widevine</fqname>
<fqname>@1.4::IDrmFactory/widevine</fqname>
</hal>
</manifest>

View File

@@ -22,50 +22,6 @@ package {
default_applicable_licenses: ["vendor_widevine_license"], default_applicable_licenses: ["vendor_widevine_license"],
} }
// Builds libwvdrmcryptoplugin_hidl
//
cc_library_static {
name: "libwvdrmcryptoplugin_hidl",
srcs: ["src_hidl/WVCryptoPlugin.cpp"],
include_dirs: [
"frameworks/av/include",
"frameworks/native/include",
"vendor/widevine/libwvdrmengine/cdm/core/include",
"vendor/widevine/libwvdrmengine/cdm/include",
"vendor/widevine/libwvdrmengine/cdm/metrics/include",
"vendor/widevine/libwvdrmengine/cdm/util/include",
"vendor/widevine/libwvdrmengine/include",
"vendor/widevine/libwvdrmengine/include_hidl",
"vendor/widevine/libwvdrmengine/mediacrypto/include_hidl",
"vendor/widevine/libwvdrmengine/oemcrypto/include",
],
header_libs: [
"libstagefright_headers",
"libutils_headers",
],
static_libs: ["libcdm_protos"],
shared_libs: [
"android.hardware.drm@1.0",
"android.hardware.drm@1.1",
"android.hardware.drm@1.2",
"android.hardware.drm@1.3",
"android.hardware.drm@1.4",
"android.hidl.memory@1.0",
"libcrypto",
"libhidlmemory",
"liblog",
],
cflags: ["-Wthread-safety"],
proprietary: true,
}
// Builds libwvdrmcryptoplugin_aidl // Builds libwvdrmcryptoplugin_aidl
// //
cc_library_static { cc_library_static {

View File

@@ -1,97 +0,0 @@
//
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
#ifndef WV_CRYPTO_PLUGIN_H_
#define WV_CRYPTO_PLUGIN_H_
#include <android-base/thread_annotations.h>
#include <android/hidl/memory/1.0/IMemory.h>
#include <mutex>
#include "HidlTypes.h"
#include "HidlWVTypes.h"
#include "log.h"
#include "wv_content_decryption_module.h"
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_4 {
namespace widevine {
using ::android::hidl::memory::V1_0::IMemory;
struct WVCryptoPlugin : public ::drm::V1_4::ICryptoPlugin {
WVCryptoPlugin(const void* data, size_t size,
const sp<wvcdm::WvContentDecryptionModule>& cdm);
virtual ~WVCryptoPlugin();
Return<bool> requiresSecureDecoderComponent(const hidl_string& mime)
override;
Return<void> notifyResolution(uint32_t width, uint32_t height) override;
Return<Status> setMediaDrmSession(const hidl_vec<uint8_t>& sessionId)
override;
Return<void> setSharedBufferBase(const hidl_memory& base,
uint32_t bufferId) override;
Return<void> decrypt(
bool secure,
const hidl_array<uint8_t, 16>& keyId,
const hidl_array<uint8_t, 16>& iv,
Mode mode,
const Pattern& pattern,
const hidl_vec<SubSample>& subSamples,
const SharedBuffer& source,
uint64_t offset,
const DestinationBuffer& destination,
decrypt_cb _hidl_cb) override;
Return<void> decrypt_1_2(
bool secure,
const hidl_array<uint8_t, 16>& keyId,
const hidl_array<uint8_t, 16>& iv,
Mode mode,
const Pattern& pattern,
const hidl_vec<SubSample>& subSamples,
const SharedBuffer& source,
uint64_t offset,
const DestinationBuffer& destination,
decrypt_1_2_cb _hidl_cb) override NO_THREAD_SAFETY_ANALYSIS; // use unique_lock
Return<void> getLogMessages(
getLogMessages_cb _hidl_cb) override;
private:
WVDRM_DISALLOW_COPY_AND_ASSIGN_AND_NEW(WVCryptoPlugin);
// List this field first so it is destructed last; ensure logging uid
// is cleared right before plugin is destructed.
wvutil::LoggingUidSetter mLoggingUidSetter;
wvcdm::CdmSessionId mSessionId;
std::map<uint32_t, sp<IMemory> > mSharedBufferMap GUARDED_BY(mSharedBufferLock);
sp<wvcdm::WvContentDecryptionModule> const mCDM;
uint32_t mUserId;
Status_V1_2 attemptDecrypt(
const wvcdm::CdmDecryptionParametersV16& params,
bool haveEncryptedSubsamples, std::string* errorDetailMsg);
std::mutex mSharedBufferLock;
};
} // namespace widevine
} // namespace V1_4
} // namespace drm
} // namespace hardware
} // namespace wvdrm
#endif // WV_CRYPTO_PLUGIN_H_

View File

@@ -1,372 +0,0 @@
//
// Copyright 2018 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 <utils/Log.h>
#include "WVCryptoPlugin.h"
#include <algorithm>
#include <hidlmemory/mapping.h>
#include <iterator>
#include "HidlMapErrors-inl.h"
#include "HidlTypes.h"
#include "log.h"
#include "OEMCryptoCENC.h"
#include "openssl/sha.h"
#include "TypeConvert.h"
#include "wv_cdm_constants.h"
#include "WVErrors.h"
namespace {
inline Status toStatus_1_0(Status_V1_2 status) {
switch (status) {
case Status_V1_2::ERROR_DRM_INSUFFICIENT_SECURITY:
case Status_V1_2::ERROR_DRM_FRAME_TOO_LARGE:
case Status_V1_2::ERROR_DRM_SESSION_LOST_STATE:
return Status::ERROR_DRM_UNKNOWN;
default:
return static_cast<Status>(status);
}
}
} // namespace
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_4 {
namespace widevine {
using android::hardware::drm::V1_2::widevine::toHidlVec;
using android::hardware::drm::V1_2::widevine::toVector;
using wvcdm::CdmDecryptionParametersV16;
using wvcdm::CdmDecryptionSample;
using wvcdm::CdmDecryptionSubsample;
using wvcdm::CdmQueryMap;
using wvcdm::CdmResponseType;
using wvcdm::CdmSessionId;
using wvcdm::KeyId;
using wvcdm::WvContentDecryptionModule;
WVCryptoPlugin::WVCryptoPlugin(const void* data, size_t size,
const sp<WvContentDecryptionModule>& cdm)
: mCDM(cdm),
mUserId(wvutil::UNKNOWN_UID) {
if (data != NULL) {
mSessionId.assign(static_cast<const char *>(data), size);
}
if (!mCDM->IsOpenSession(mSessionId)) {
mSessionId.clear();
} else {
mCDM->GetSessionUserId(mSessionId, &mUserId);
}
}
WVCryptoPlugin::~WVCryptoPlugin() {
if (wvutil::UNKNOWN_UID != mUserId) {
wvutil::SetLoggingUid(mUserId);
}
}
Return<bool> WVCryptoPlugin::requiresSecureDecoderComponent(
const hidl_string& mime) {
if (!strncasecmp(mime.c_str(), "video/", 6)) {
// Type is video, so query CDM to see if we require a secure decoder.
CdmQueryMap status;
CdmResponseType res = mCDM->QuerySessionStatus(mSessionId, &status);
if (!isCdmResponseTypeSuccess(res)) {
ALOGE("Error querying CDM status: %u", res);
return false;
}
return status[wvcdm::QUERY_KEY_SECURITY_LEVEL] ==
wvcdm::QUERY_VALUE_SECURITY_LEVEL_L1;
} else {
// Type is not video, so never require a secure decoder.
return false;
}
}
Return<void> WVCryptoPlugin::notifyResolution(
uint32_t width, uint32_t height) {
mCDM->NotifyResolution(mSessionId, width, height);
return Void();
}
Return<Status> WVCryptoPlugin::setMediaDrmSession(
const hidl_vec<uint8_t>& sessionId) {
if (sessionId.size() == 0) {
return Status::BAD_VALUE;
}
const std::vector<uint8_t> sId = toVector(sessionId);
CdmSessionId cdmSessionId(sId.begin(), sId.end());
if (!mCDM->IsOpenSession(cdmSessionId)) {
return Status::ERROR_DRM_SESSION_NOT_OPENED;
} else {
mSessionId = cdmSessionId;
return Status::OK;
}
}
Return<void> WVCryptoPlugin::setSharedBufferBase(
const hidl_memory& base, uint32_t bufferId) {
sp<IMemory> hidlMemory = mapMemory(base);
std::lock_guard<std::mutex> shared_buffer_lock(mSharedBufferLock);
// allow mapMemory to return nullptr
mSharedBufferMap[bufferId] = hidlMemory;
return Void();
}
Return<void> WVCryptoPlugin::decrypt(
bool secure,
const hidl_array<uint8_t, 16>& keyId,
const hidl_array<uint8_t, 16>& iv,
Mode mode,
const Pattern& pattern,
const hidl_vec<SubSample>& subSamples,
const SharedBuffer& source,
uint64_t offset,
const DestinationBuffer& destination,
decrypt_cb _hidl_cb) {
Status status = Status::ERROR_DRM_UNKNOWN;
hidl_string detailedError;
uint32_t bytesWritten = 0;
Return<void> hResult = decrypt_1_2(
secure, keyId, iv, mode, pattern, subSamples, source, offset, destination,
[&](Status_V1_2 hStatus, uint32_t hBytesWritten, hidl_string hDetailedError) {
status = toStatus_1_0(hStatus);
if (status == Status::OK) {
bytesWritten = hBytesWritten;
detailedError = hDetailedError;
}
}
);
status = hResult.isOk() ? status : Status::ERROR_DRM_CANNOT_HANDLE;
_hidl_cb(status, bytesWritten, detailedError);
return Void();
}
Return<void> WVCryptoPlugin::decrypt_1_2(
bool secure,
const hidl_array<uint8_t, 16>& keyId,
const hidl_array<uint8_t, 16>& iv,
Mode mode,
const Pattern& pattern,
const hidl_vec<SubSample>& subSamples,
const SharedBuffer& source,
uint64_t offset,
const DestinationBuffer& destination,
decrypt_1_2_cb _hidl_cb) {
std::unique_lock<std::mutex> lock(mSharedBufferLock);
if (mSharedBufferMap.find(source.bufferId) == mSharedBufferMap.end()) {
_hidl_cb(Status_V1_2::ERROR_DRM_CANNOT_HANDLE, 0,
"source decrypt buffer base not set");
return Void();
}
if (destination.type == BufferType::SHARED_MEMORY) {
const SharedBuffer& dest = destination.nonsecureMemory;
if (mSharedBufferMap.find(dest.bufferId) == mSharedBufferMap.end()) {
_hidl_cb(Status_V1_2::ERROR_DRM_CANNOT_HANDLE, 0,
"destination decrypt buffer base not set");
return Void();
}
}
if (mode != Mode::UNENCRYPTED &&
mode != Mode::AES_CTR &&
mode != Mode::AES_CBC) {
_hidl_cb(Status_V1_2::BAD_VALUE, 0,
"The requested encryption mode is not supported by Widevine CDM.");
return Void();
} else if (mode == Mode::AES_CTR &&
(pattern.encryptBlocks != 0 || pattern.skipBlocks != 0)) {
_hidl_cb(Status_V1_2::BAD_VALUE, 0,
"The 'cens' schema is not supported by Widevine CDM.");
return Void();
}
// Convert parameters to the form the CDM wishes to consume them in.
const KeyId cryptoKey(
reinterpret_cast<const char*>(keyId.data()), wvcdm::KEY_ID_SIZE);
std::vector<uint8_t> ivVector(iv.data(), iv.data() + wvcdm::KEY_IV_SIZE);
std::string errorDetailMsg;
sp<IMemory> sourceBase = mSharedBufferMap[source.bufferId];
if (sourceBase == nullptr) {
_hidl_cb(Status_V1_2::ERROR_DRM_CANNOT_HANDLE, 0, "source is a nullptr");
return Void();
}
size_t totalSrcSize = 0;
if (__builtin_add_overflow(source.offset, offset, &totalSrcSize) ||
__builtin_add_overflow(totalSrcSize, source.size, &totalSrcSize) ||
totalSrcSize > sourceBase->getSize()) {
android_errorWriteLog(0x534e4554, "176496160");
_hidl_cb(Status_V1_2::ERROR_DRM_CANNOT_HANDLE, 0, "invalid buffer size");
return Void();
}
uint8_t *base = static_cast<uint8_t *>
(static_cast<void *>(sourceBase->getPointer()));
uint8_t* srcPtr = static_cast<uint8_t *>(base + source.offset + offset);
void* destPtr = NULL;
if (destination.type == BufferType::SHARED_MEMORY) {
const SharedBuffer& destBuffer = destination.nonsecureMemory;
sp<IMemory> destBase = mSharedBufferMap[destBuffer.bufferId];
if (destBase == nullptr) {
_hidl_cb(Status_V1_2::ERROR_DRM_CANNOT_HANDLE, 0, "destination is a nullptr");
return Void();
}
size_t totalDstSize = 0;
if (__builtin_add_overflow(destBuffer.offset, destBuffer.size, &totalDstSize) ||
totalDstSize > destBase->getSize()) {
android_errorWriteLog(0x534e4554, "176444622");
_hidl_cb(Status_V1_2::ERROR_DRM_FRAME_TOO_LARGE, 0, "invalid buffer size");
return Void();
}
destPtr = static_cast<void *>(base + destination.nonsecureMemory.offset);
} else if (destination.type == BufferType::NATIVE_HANDLE) {
native_handle_t *handle = const_cast<native_handle_t *>(
destination.secureMemory.getNativeHandle());
destPtr = static_cast<void *>(handle);
}
// release mSharedBufferLock
lock.unlock();
// Set up the decrypt params
CdmDecryptionParametersV16 params;
params.key_id = cryptoKey;
params.is_secure = secure;
if (mode == Mode::AES_CTR) {
params.cipher_mode = wvcdm::kCipherModeCtr;
} else if (mode == Mode::AES_CBC) {
params.cipher_mode = wvcdm::kCipherModeCbc;
}
params.pattern.encrypt_blocks = pattern.encryptBlocks;
params.pattern.skip_blocks = pattern.skipBlocks;
// Set up the sample
// Android's API only supports one at a time
params.samples.emplace_back();
CdmDecryptionSample& sample = params.samples.back();
sample.encrypt_buffer = srcPtr;
sample.decrypt_buffer = destPtr;
sample.decrypt_buffer_offset = 0;
sample.iv = ivVector;
// Set up the subsamples
// We abuse std::transform() here to also do some side-effects: Tallying the
// total size of the sample and checking if any of the data is protected.
size_t totalSize = 0;
bool hasProtectedData = false;
sample.subsamples.reserve(subSamples.size());
std::transform(subSamples.data(), subSamples.data() + subSamples.size(),
std::back_inserter(sample.subsamples),
[&](const SubSample& subSample) -> CdmDecryptionSubsample {
totalSize +=
subSample.numBytesOfClearData + subSample.numBytesOfEncryptedData;
hasProtectedData |= subSample.numBytesOfEncryptedData > 0;
return CdmDecryptionSubsample(subSample.numBytesOfClearData,
subSample.numBytesOfEncryptedData);
});
sample.encrypt_buffer_length = totalSize;
sample.decrypt_buffer_size = totalSize;
if (mode == Mode::UNENCRYPTED && hasProtectedData) {
_hidl_cb(Status_V1_2::ERROR_DRM_CANNOT_HANDLE, 0,
"Protected ranges found in allegedly clear data.");
return Void();
}
// Decrypt
Status_V1_2 res = attemptDecrypt(params, hasProtectedData, &errorDetailMsg);
if (res != Status_V1_2::OK) {
_hidl_cb(res, 0, errorDetailMsg.c_str());
return Void();
}
_hidl_cb(Status_V1_2::OK, totalSize, errorDetailMsg.c_str());
return Void();
}
Status_V1_2 WVCryptoPlugin::attemptDecrypt(
const CdmDecryptionParametersV16& params, bool hasProtectedData,
std::string* errorDetailMsg) {
CdmResponseType res = mCDM->DecryptV16(mSessionId, hasProtectedData,
params);
if (isCdmResponseTypeSuccess(res)) {
return Status_V1_2::OK;
} else {
ALOGE("Decrypt error in session %s during a sample %s protected data: %d",
mSessionId.c_str(),
hasProtectedData ? "with" : "without",
res);
switch (res) {
case wvcdm::INSUFFICIENT_CRYPTO_RESOURCES:
errorDetailMsg->assign(
"Error decrypting data: insufficient crypto resources");
break;
case wvcdm::NEED_KEY:
case wvcdm::KEY_NOT_FOUND_IN_SESSION:
errorDetailMsg->assign(
"Error decrypting data: requested key has not been loaded");
break;
case wvcdm::DECRYPT_NOT_READY:
errorDetailMsg->assign(
"Error decrypting data: license validity period is in the future");
break;
case wvcdm::SESSION_NOT_FOUND_FOR_DECRYPT:
errorDetailMsg->assign(
"Error decrypting data: session not found, possibly reclaimed");
break;
case wvcdm::DECRYPT_ERROR:
errorDetailMsg->assign(
"Error decrypting data: unspecified error");
break;
case wvcdm::INSUFFICIENT_OUTPUT_PROTECTION:
case wvcdm::ANALOG_OUTPUT_ERROR:
errorDetailMsg->assign(
"Error decrypting data: insufficient output protection");
break;
case wvcdm::KEY_PROHIBITED_FOR_SECURITY_LEVEL:
errorDetailMsg->assign(
"Error decrypting data: key prohibited for security level");
break;
default:
break;
}
return mapCdmResponseType<Status_V1_2>(res);
}
}
Return<void> WVCryptoPlugin::getLogMessages(getLogMessages_cb _hidl_cb) {
const std::vector<wvutil::LogMessage> &logs(wvutil::g_logbuf.getLogs());
_hidl_cb(::drm::V1_4::Status::OK, toHidlVec<::drm::V1_4::LogMessage>(logs));
return Void();
}
} // namespace widevine
} // namespace V1_4
} // namespace drm
} // namespace hardware
} // namespace wvdrm

View File

@@ -4,56 +4,7 @@ LOCAL_PATH := $(call my-dir)
# #
include $(CLEAR_VARS) include $(CLEAR_VARS)
WV_UNITTESTS_BUILD_TARGET?=
ifeq ($(WV_UNITTESTS_BUILD_TARGET), hidl)
LOCAL_SRC_FILES := \
hidl/WVCryptoPlugin_test.cpp \
LOCAL_C_INCLUDES := \
frameworks/av/include \
frameworks/native/include \
vendor/widevine/libwvdrmengine/cdm/core/include \
vendor/widevine/libwvdrmengine/cdm/include \
vendor/widevine/libwvdrmengine/cdm/metrics/include \
vendor/widevine/libwvdrmengine/cdm/util/include \
vendor/widevine/libwvdrmengine/include_hidl \
vendor/widevine/libwvdrmengine/mediacrypto/include_hidl \
vendor/widevine/libwvdrmengine/oemcrypto/include \
LOCAL_STATIC_LIBRARIES := \
libcdm \
libcdm_protos \
libcdm_utils_hidl \
libjsmn \
libgmock \
libgmock_main \
libgtest \
libwvlevel3 \
libwvdrmcryptoplugin_hidl \
libwv_odk \
LOCAL_SHARED_LIBRARIES := \
android.hardware.drm@1.0 \
android.hardware.drm@1.1 \
android.hardware.drm@1.2 \
android.hardware.drm@1.3 \
android.hardware.drm@1.4 \
android.hidl.memory@1.0 \
libbase \
libbinder \
libcrypto \
libcutils \
libdl \
libhidlbase \
libhidlmemory \
liblog \
libprotobuf-cpp-lite \
libutils \
# build unit tests for Aidl # build unit tests for Aidl
else
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
WVCryptoPlugin_hal_test.cpp \ WVCryptoPlugin_hal_test.cpp \
@@ -92,9 +43,6 @@ LOCAL_SHARED_LIBRARIES := \
libprotobuf-cpp-lite \ libprotobuf-cpp-lite \
libutils \ libutils \
# endif $(WV_UNITTESTS_BUILD_TARGET)
endif
LOCAL_HEADER_LIBRARIES := \ LOCAL_HEADER_LIBRARIES := \
libstagefright_headers \ libstagefright_headers \

View File

@@ -1,643 +0,0 @@
//
// Copyright 2018 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 "WVCryptoPluginTest"
#include <utils/Log.h>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>
#include <binder/MemoryDealer.h>
#include <hidl/Status.h>
#include <hidlmemory/mapping.h>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "wv_cdm_constants.h"
#include "wv_cdm_types.h"
#include "wv_content_decryption_module.h"
#include "HidlTypes.h"
#include "OEMCryptoCENC.h"
#include "TypeConvert.h"
#include "WVCryptoPlugin.h"
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_4 {
namespace widevine {
using ::android::MemoryDealer;
using ::testing::_;
using ::testing::DefaultValue;
using ::testing::DoAll;
using ::testing::ElementsAreArray;
using ::testing::Field;
using ::testing::InSequence;
using ::testing::Matcher;
using ::testing::SetArgPointee;
using ::testing::StrictMock;
using ::testing::Test;
using ::testing::Truly;
using ::testing::Value;
using ::testing::internal::ElementsAreArrayMatcher;
using wvcdm::kCipherModeCtr;
using wvcdm::kCipherModeCbc;
using wvcdm::CdmCipherMode;
using wvcdm::CdmDecryptionParametersV16;
using wvcdm::CdmDecryptionSample;
using wvcdm::CdmDecryptionSubsample;
using wvcdm::CdmQueryMap;
using wvcdm::CdmResponseType;
using wvcdm::CdmSessionId;
using wvcdm::KeyId;
using wvcdm::KEY_ID_SIZE;
using wvcdm::KEY_IV_SIZE;
using wvcdm::QUERY_KEY_SECURITY_LEVEL;
using wvcdm::QUERY_VALUE_SECURITY_LEVEL_L1;
using wvcdm::QUERY_VALUE_SECURITY_LEVEL_L3;
class MockCDM : public wvcdm::WvContentDecryptionModule {
public:
MOCK_METHOD(bool, IsOpenSession, (const CdmSessionId&), (override));
MOCK_METHOD(CdmResponseType, DecryptV16, (const CdmSessionId&, bool,
const CdmDecryptionParametersV16&), (override));
MOCK_METHOD(CdmResponseType, QuerySessionStatus, (const CdmSessionId&,
CdmQueryMap*), (override));
};
class WVCryptoPluginTest : public Test {
protected:
static const uint32_t kSessionIdSize = 16;
uint8_t* pDest = nullptr;
uint8_t* pSrc = nullptr;
uint8_t sessionId[kSessionIdSize];
uint32_t nextBufferId = 0;
std::map<void *, uint32_t> heapBases;
virtual void SetUp() {
FILE* fp = fopen("/dev/urandom", "r");
fread(sessionId, sizeof(uint8_t), kSessionIdSize, fp);
fclose(fp);
// Set default CdmResponseType value for gMock
DefaultValue<CdmResponseType>::Set(wvcdm::NO_ERROR);
heapBases.clear();
}
void setHeapBase(WVCryptoPlugin& plugin,
const sp<android::IMemoryHeap>& heap) {
ASSERT_NE(heap, nullptr);
void* heapBase = heap->getBase();
ASSERT_NE(heapBase, nullptr);
native_handle_t* nativeHandle = native_handle_create(1, 0);
ASSERT_NE(nativeHandle, nullptr);
nativeHandle->data[0] = heap->getHeapID();
auto hidlHandle = hidl_handle(nativeHandle);
auto hidlMemory = hidl_memory("ashmem", hidlHandle, heap->getSize());
heapBases.insert(
std::pair<void*, uint32_t>(heapBase, nextBufferId));
Return<void> hResult =
plugin.setSharedBufferBase(hidlMemory, nextBufferId++);
ALOGE_IF(!hResult.isOk(), "setHeapBase failed setSharedBufferBase");
}
void toSharedBuffer(WVCryptoPlugin& plugin,
const sp<android::IMemory>& memory,
SharedBuffer* buffer) {
ssize_t offset;
size_t size;
ASSERT_NE(memory, nullptr);
ASSERT_NE(buffer, nullptr);
sp<android::IMemoryHeap> heap = memory->getMemory(&offset, &size);
ASSERT_NE(heap, nullptr);
setHeapBase(plugin, heap);
buffer->bufferId = heapBases[heap->getBase()];
buffer->offset = offset >= 0 ? offset : 0;
buffer->size = size;
}
};
TEST_F(WVCryptoPluginTest, CorrectlyReportsSecureBuffers) {
android::sp<StrictMock<MockCDM>> cdm = new StrictMock<MockCDM>();
CdmQueryMap l1Map;
l1Map[QUERY_KEY_SECURITY_LEVEL] = QUERY_VALUE_SECURITY_LEVEL_L1;
CdmQueryMap l3Map;
l3Map[QUERY_KEY_SECURITY_LEVEL] = QUERY_VALUE_SECURITY_LEVEL_L3;
// Provide the expected behavior for IsOpenSession
EXPECT_CALL(*cdm, IsOpenSession(_))
.WillRepeatedly(testing::Return(true));
// Specify the expected calls to QuerySessionStatus
EXPECT_CALL(*cdm, QuerySessionStatus(_, _))
.WillOnce(DoAll(SetArgPointee<1>(l1Map),
testing::Return(wvcdm::NO_ERROR)))
.WillOnce(DoAll(SetArgPointee<1>(l3Map),
testing::Return(wvcdm::NO_ERROR)));
WVCryptoPlugin plugin(sessionId, kSessionIdSize, cdm.get());
EXPECT_TRUE(plugin.requiresSecureDecoderComponent("video/mp4")) <<
"WVCryptoPlugin incorrectly allows an insecure video decoder on L1";
EXPECT_FALSE(plugin.requiresSecureDecoderComponent("video/mp4")) <<
"WVCryptoPlugin incorrectly expects a secure video decoder on L3";
EXPECT_FALSE(plugin.requiresSecureDecoderComponent("audio/aac")) <<
"WVCryptoPlugin incorrectly expects a secure audio decoder";
}
// TODO(b/28295739):
// Add New MediaCrypto Unit Tests for CBC & Pattern Mode in cdmPatternDesc.
// Predicate that validates that the fields of a passed-in
// CdmDecryptionParametersV16 match the values it was given at construction
// time.
//
// This could be done with a huge pile of gMock matchers, but it is ugly and
// unmaintainable, particularly once you get into validating the subsamples. The
// logic here is complex enough to warrant a custom matcher for this one test.
class CDPMatcher {
public:
// TODO(b/35259313): Uncomment the removed parameters once the matcher can
// convert them from HIDL accesses to physical addresses.
CDPMatcher(const uint8_t* keyId, bool isSecure, Mode cipherMode,
const Pattern& pattern,
const uint8_t* /* input */, size_t inputLength,
const uint8_t* /* output */, size_t outputLength, const uint8_t* iv,
const SubSample* subsamples, size_t subsamplesLength)
: mKeyId(keyId, keyId + KEY_ID_SIZE), mIsSecure(isSecure),
mCipherMode(cipherMode), mPattern(pattern), /* mInput(input), */
mInputLength(inputLength), /* mOutput(output), */
mOutputLength(outputLength), mIv(iv, iv + KEY_IV_SIZE),
mSubsamples(subsamples, subsamples + subsamplesLength) {}
bool operator()(const CdmDecryptionParametersV16& params) const {
if (mCipherMode == Mode::AES_CTR &&
params.cipher_mode != kCipherModeCtr) {
return false;
} else if (mCipherMode == Mode::AES_CBC &&
params.cipher_mode != kCipherModeCbc) {
return false;
}
if (params.key_id != mKeyId ||
params.is_secure != mIsSecure ||
params.pattern.encrypt_blocks != mPattern.encryptBlocks ||
params.pattern.skip_blocks != mPattern.skipBlocks ||
params.samples.size() != 1) {
return false;
}
const CdmDecryptionSample& sample = params.samples[0];
if (// TODO(b/35259313): Convert from a HIDL access to a physical address.
// sample.encrypt_buffer != mInput ||
sample.encrypt_buffer_length != mInputLength ||
// TODO(b/35259313): Convert from a HIDL access to a physical address.
// sample.decrypt_buffer != mOutput ||
sample.decrypt_buffer_size != mOutputLength ||
sample.decrypt_buffer_offset != 0 ||
sample.iv != mIv ||
sample.subsamples.size() != mSubsamples.size()) {
return false;
}
for (size_t i = 0; i < mSubsamples.size(); ++i) {
const SubSample& androidSubsample = mSubsamples[i];
const CdmDecryptionSubsample& cdmSubsample = sample.subsamples[i];
if (cdmSubsample.clear_bytes != androidSubsample.numBytesOfClearData ||
cdmSubsample.protected_bytes != androidSubsample.numBytesOfEncryptedData) {
return false;
}
}
return true;
}
private:
const KeyId mKeyId;
const bool mIsSecure;
const Mode mCipherMode;
const Pattern mPattern;
// TODO(b/35259313): Uncomment this field once the matcher can convert this
// from a HIDL access to a physical address.
// const uint8_t* const mInput;
const size_t mInputLength;
// TODO(b/35259313): Uncomment this field once the matcher can convert this
// from a HIDL access to a physical address.
// const uint8_t* const mOutput;
const size_t mOutputLength;
const std::vector<uint8_t> mIv;
const std::vector<SubSample> mSubsamples;
};
TEST_F(WVCryptoPluginTest, AttemptsToDecrypt) {
android::sp<StrictMock<MockCDM>> cdm = new StrictMock<MockCDM>();
constexpr size_t kSubSampleCount = 6;
SubSample subSamples[kSubSampleCount];
memset(subSamples, 0, sizeof(subSamples));
subSamples[0].numBytesOfEncryptedData = 16;
subSamples[1].numBytesOfClearData = 16;
subSamples[1].numBytesOfEncryptedData = 16;
subSamples[2].numBytesOfEncryptedData = 8;
subSamples[3].numBytesOfClearData = 29;
subSamples[3].numBytesOfEncryptedData = 24;
subSamples[4].numBytesOfEncryptedData = 60;
subSamples[5].numBytesOfEncryptedData = 16;
std::vector<SubSample> subSamplesVector(
subSamples, subSamples + sizeof(subSamples) / sizeof(subSamples[0]));
auto hSubSamples = hidl_vec<SubSample>(subSamplesVector);
uint8_t keyId[KEY_ID_SIZE];
uint8_t iv[KEY_IV_SIZE];
static const size_t kDataSize = 185;
uint8_t inputData[kDataSize];
FILE* fp = fopen("/dev/urandom", "r");
fread(keyId, sizeof(uint8_t), KEY_ID_SIZE, fp);
fread(iv, sizeof(uint8_t), KEY_IV_SIZE, fp);
fread(inputData, sizeof(uint8_t), kDataSize, fp);
fclose(fp);
sp<MemoryDealer> memDealer = new MemoryDealer(
kDataSize * 2, "WVCryptoPlugin_test");
sp<android::IMemory> source = memDealer->allocate(kDataSize);
ASSERT_NE(source, nullptr);
pSrc = static_cast<uint8_t*>(
static_cast<void*>(source->unsecurePointer()));
ASSERT_NE(pSrc, nullptr);
memcpy(pSrc, inputData, source->size());
sp<android::IMemory> destination = memDealer->allocate(kDataSize);
ASSERT_NE(destination, nullptr);
pDest = static_cast<uint8_t*>(
static_cast<void*>(destination->unsecurePointer()));
ASSERT_NE(pDest, nullptr);
Pattern noPattern = { 0, 0 };
// Provide the expected behavior for IsOpenSession
EXPECT_CALL(*cdm, IsOpenSession(_))
.WillRepeatedly(testing::Return(true));
// Specify the expected calls to Decrypt
CDPMatcher paramsMatcher(keyId, false, Mode::AES_CTR, noPattern, pSrc,
kDataSize, pDest, kDataSize, iv, subSamples,
kSubSampleCount);
EXPECT_CALL(*cdm, DecryptV16(ElementsAreArray(sessionId, kSessionIdSize),
true,
Truly(paramsMatcher)))
.Times(1);
WVCryptoPlugin plugin(sessionId, kSessionIdSize, cdm.get());
uint32_t bytesWritten = 0;
std::string errorDetailMessage;
DestinationBuffer hDestination;
hDestination.type = BufferType::SHARED_MEMORY;
toSharedBuffer(plugin, destination, &hDestination.nonsecureMemory);
SharedBuffer sourceBuffer;
toSharedBuffer(plugin, source, &sourceBuffer);
plugin.decrypt(
false, hidl_array<uint8_t, 16>(keyId), hidl_array<uint8_t, 16>(iv),
Mode::AES_CTR, noPattern, hSubSamples, sourceBuffer, 0, hDestination,
[&](Status status, uint32_t hBytesWritten, hidl_string hDetailedError) {
EXPECT_EQ(status, Status::OK);
bytesWritten = hBytesWritten;
errorDetailMessage.assign(hDetailedError.c_str());
});
EXPECT_EQ(kDataSize, bytesWritten) <<
"WVCryptoPlugin decrypted the wrong number of bytes";
EXPECT_EQ(0u, errorDetailMessage.size()) <<
"WVCryptoPlugin reported a detailed error message.";
}
TEST_F(WVCryptoPluginTest, RejectsCens) {
android::sp<StrictMock<MockCDM>> cdm = new StrictMock<MockCDM>();
constexpr size_t kSubSampleCount = 2;
SubSample subSamples[kSubSampleCount];
memset(subSamples, 0, sizeof(subSamples));
subSamples[0].numBytesOfEncryptedData = 16;
subSamples[1].numBytesOfClearData = 16;
subSamples[1].numBytesOfEncryptedData = 16;
std::vector<SubSample> subSamplesVector(
subSamples, subSamples + sizeof(subSamples) / sizeof(subSamples[0]));
auto hSubSamples = hidl_vec<SubSample>(subSamplesVector);
uint8_t keyId[KEY_ID_SIZE];
uint8_t iv[KEY_IV_SIZE];
static const size_t kDataSize = 48;
uint8_t inputData[kDataSize];
FILE* fp = fopen("/dev/urandom", "r");
fread(keyId, sizeof(uint8_t), KEY_ID_SIZE, fp);
fread(iv, sizeof(uint8_t), KEY_IV_SIZE, fp);
fread(inputData, sizeof(uint8_t), kDataSize, fp);
fclose(fp);
sp<MemoryDealer> memDealer = new MemoryDealer(
kDataSize * 2, "WVCryptoPlugin_test");
sp<android::IMemory> source = memDealer->allocate(kDataSize);
ASSERT_NE(source, nullptr);
pSrc = static_cast<uint8_t*>(
static_cast<void*>(source->unsecurePointer()));
ASSERT_NE(pSrc, nullptr);
memcpy(pSrc, inputData, source->size());
sp<android::IMemory> destination = memDealer->allocate(kDataSize);
ASSERT_NE(destination, nullptr);
pDest = static_cast<uint8_t*>(
static_cast<void*>(destination->unsecurePointer()));
ASSERT_NE(pDest, nullptr);
Pattern recommendedPattern = { 1, 9 };
// Provide the expected behavior for IsOpenSession
EXPECT_CALL(*cdm, IsOpenSession(_))
.WillRepeatedly(testing::Return(true));
// Refuse calls to Decrypt
EXPECT_CALL(*cdm, DecryptV16(_, _, _))
.Times(0);
WVCryptoPlugin plugin(sessionId, kSessionIdSize, cdm.get());
DestinationBuffer hDestination;
hDestination.type = BufferType::SHARED_MEMORY;
toSharedBuffer(plugin, destination, &hDestination.nonsecureMemory);
SharedBuffer sourceBuffer;
toSharedBuffer(plugin, source, &sourceBuffer);
plugin.decrypt(
false, hidl_array<uint8_t, 16>(keyId), hidl_array<uint8_t, 16>(iv),
Mode::AES_CTR, recommendedPattern, hSubSamples, sourceBuffer, 0,
hDestination,
[&](Status status, uint32_t bytesWritten,
hidl_string /* errorDetailMessage */) {
EXPECT_EQ(status, Status::BAD_VALUE);
EXPECT_EQ(bytesWritten, 0);
});
}
TEST_F(WVCryptoPluginTest, CommunicatesSecureBufferRequest) {
android::sp<StrictMock<MockCDM>> cdm = new StrictMock<MockCDM>();
uint8_t keyId[KEY_ID_SIZE];
uint8_t iv[KEY_IV_SIZE];
static const size_t kDataSize = 32;
uint8_t in[kDataSize];
FILE* fp = fopen("/dev/urandom", "r");
fread(keyId, sizeof(uint8_t), KEY_ID_SIZE, fp);
fread(iv, sizeof(uint8_t), KEY_IV_SIZE, fp);
fread(in, sizeof(uint8_t), kDataSize, fp);
fclose(fp);
SubSample subSample;
subSample.numBytesOfClearData = 16;
subSample.numBytesOfEncryptedData = 16;
std::vector<SubSample> subSampleVector;
subSampleVector.push_back(subSample);
auto hSubSamples = hidl_vec<SubSample>(subSampleVector);
// Provide the expected behavior for IsOpenSession
EXPECT_CALL(*cdm, IsOpenSession(_))
.WillRepeatedly(testing::Return(true));
// Specify the expected calls to Decrypt
{
InSequence calls;
typedef CdmDecryptionParametersV16 CDP;
EXPECT_CALL(*cdm, DecryptV16(_, _, Field(&CDP::is_secure, false)))
.Times(1);
EXPECT_CALL(*cdm, DecryptV16(_, _, Field(&CDP::is_secure, true)))
.Times(1);
}
sp<MemoryDealer> memDealer = new MemoryDealer(
kDataSize * 2, "WVCryptoPlugin_test");
sp<android::IMemory> source = memDealer->allocate(kDataSize);
ASSERT_NE(source, nullptr);
pSrc = static_cast<uint8_t*>(
static_cast<void*>(source->unsecurePointer()));
ASSERT_NE(pSrc, nullptr);
memcpy(pSrc, in, source->size());
sp<android::IMemory> destination = memDealer->allocate(kDataSize);
ASSERT_NE(destination, nullptr);
pDest = static_cast<uint8_t*>(
static_cast<void*>(destination->unsecurePointer()));
ASSERT_NE(pDest, nullptr);
WVCryptoPlugin plugin(sessionId, kSessionIdSize, cdm.get());
uint32_t bytesWritten = 0;
std::string errorDetailMessage;
DestinationBuffer hDestination;
hDestination.type = BufferType::SHARED_MEMORY;
toSharedBuffer(plugin, destination, &hDestination.nonsecureMemory);
Pattern noPattern = { 0, 0 };
SharedBuffer sourceBuffer;
toSharedBuffer(plugin, source, &sourceBuffer);
plugin.decrypt(
false, hidl_array<uint8_t, 16>(keyId), hidl_array<uint8_t, 16>(iv),
Mode::AES_CTR, noPattern, hSubSamples, sourceBuffer, 0, hDestination,
[&](Status status, uint32_t hBytesWritten, hidl_string hDetailedError) {
EXPECT_EQ(status, Status::OK);
bytesWritten = hBytesWritten;
errorDetailMessage.assign(hDetailedError.c_str());
});
EXPECT_EQ(0u, errorDetailMessage.size()) <<
"WVCryptoPlugin reported a detailed error message.";
plugin.decrypt(
true, hidl_array<uint8_t, 16>(keyId), hidl_array<uint8_t, 16>(iv),
Mode::AES_CTR, noPattern, hSubSamples, sourceBuffer, 0, hDestination,
[&](Status status, uint32_t hBytesWritten, hidl_string hDetailedError) {
EXPECT_EQ(status, Status::OK);
bytesWritten = hBytesWritten;
errorDetailMessage.assign(hDetailedError.c_str());
});
EXPECT_EQ(0u, errorDetailMessage.size()) <<
"WVCryptoPlugin reported a detailed error message.";
}
TEST_F(WVCryptoPluginTest, AllowsSessionIdChanges) {
android::sp<StrictMock<MockCDM>> cdm = new StrictMock<MockCDM>();
uint8_t keyId[KEY_ID_SIZE];
uint8_t iv[KEY_IV_SIZE];
uint8_t sessionId2[kSessionIdSize];
static const size_t kDataSize = 32;
uint8_t in[kDataSize];
FILE* fp = fopen("/dev/urandom", "r");
fread(keyId, sizeof(uint8_t), KEY_ID_SIZE, fp);
fread(iv, sizeof(uint8_t), KEY_IV_SIZE, fp);
fread(sessionId2, sizeof(uint8_t), kSessionIdSize, fp);
fread(in, sizeof(uint8_t), kDataSize, fp);
fclose(fp);
SubSample subSample;
subSample.numBytesOfClearData = 16;
subSample.numBytesOfEncryptedData = 16;
std::vector<SubSample> subSampleVector;
subSampleVector.push_back(subSample);
auto hSubSamples = hidl_vec<SubSample>(subSampleVector);
std::vector<uint8_t> sessionIdVector(sessionId, sessionId + kSessionIdSize);
std::vector<uint8_t> sessionId2Vector(sessionId2,
sessionId2 + kSessionIdSize);
// Provide the expected behavior for IsOpenSession
EXPECT_CALL(*cdm, IsOpenSession(_))
.WillRepeatedly(testing::Return(true));
// Specify the expected calls to Decrypt
{
InSequence calls;
EXPECT_CALL(*cdm,
DecryptV16(ElementsAreArray(sessionId, kSessionIdSize), _, _))
.Times(1);
EXPECT_CALL(*cdm,
DecryptV16(ElementsAreArray(sessionId2, kSessionIdSize), _, _))
.Times(1);
}
sp<MemoryDealer> memDealer = new MemoryDealer(
kDataSize * 2, "WVCryptoPlugin_test");
sp<android::IMemory> source = memDealer->allocate(kDataSize);
ASSERT_NE(source, nullptr);
pSrc = static_cast<uint8_t*>(
static_cast<void*>(source->unsecurePointer()));
ASSERT_NE(pSrc, nullptr);
memcpy(pSrc, in, source->size());
sp<android::IMemory> destination = memDealer->allocate(kDataSize);
ASSERT_NE(destination, nullptr);
pDest = static_cast<uint8_t*>(
static_cast<void*>(destination->unsecurePointer()));
ASSERT_NE(pDest, nullptr);
uint8_t blank[1]; // Some compilers will not accept 0.
WVCryptoPlugin plugin(blank, 0, cdm.get());
uint32_t bytesWritten = 0;
std::string errorDetailMessage;
DestinationBuffer hDestination;
hDestination.type = BufferType::SHARED_MEMORY;
toSharedBuffer(plugin, destination, &hDestination.nonsecureMemory);
Pattern noPattern = { 0, 0 };
SharedBuffer sourceBuffer;
toSharedBuffer(plugin, source, &sourceBuffer);
Status status = plugin.setMediaDrmSession(sessionIdVector);
EXPECT_EQ(status, Status::OK);
plugin.decrypt(
false, hidl_array<uint8_t, 16>(keyId), hidl_array<uint8_t, 16>(iv),
Mode::AES_CTR, noPattern, hSubSamples, sourceBuffer, 0, hDestination,
[&](Status status, uint32_t hBytesWritten, hidl_string hDetailedError) {
EXPECT_EQ(status, Status::OK);
bytesWritten = hBytesWritten;
errorDetailMessage.assign(hDetailedError.c_str());
});
EXPECT_EQ(0u, errorDetailMessage.size()) <<
"WVCryptoPlugin reported a detailed error message.";
status = plugin.setMediaDrmSession(sessionId2Vector);
EXPECT_EQ(status, Status::OK);
plugin.decrypt(
false, hidl_array<uint8_t, 16>(keyId), hidl_array<uint8_t, 16>(iv),
Mode::AES_CTR, noPattern, hSubSamples, sourceBuffer, 0, hDestination,
[&](Status status, uint32_t hBytesWritten, hidl_string hDetailedError) {
EXPECT_EQ(status, Status::OK);
bytesWritten = hBytesWritten;
errorDetailMessage.assign(hDetailedError.c_str());
});
EXPECT_EQ(0u, errorDetailMessage.size()) <<
"WVCryptoPlugin reported a detailed error message.";
}
TEST_F(WVCryptoPluginTest, DisallowsUnopenedSessionIdChanges) {
android::sp<StrictMock<MockCDM>> cdm = new StrictMock<MockCDM>();
uint8_t blank[1]; // Some compilers will not accept 0.
std::vector<uint8_t> sessionIdVector(sessionId, sessionId + kSessionIdSize);
// Specify the expected calls to IsOpenSession
{
InSequence calls;
EXPECT_CALL(*cdm, IsOpenSession(ElementsAreArray(blank, 0)))
.WillOnce(testing::Return(false));
EXPECT_CALL(*cdm, IsOpenSession(ElementsAreArray(sessionId, kSessionIdSize)))
.WillOnce(testing::Return(false))
.WillOnce(testing::Return(true));
}
WVCryptoPlugin plugin(blank, 0, cdm.get());
Status status = plugin.setMediaDrmSession(sessionIdVector);
EXPECT_EQ(status, Status::ERROR_DRM_SESSION_NOT_OPENED);
status = plugin.setMediaDrmSession(sessionIdVector);
EXPECT_EQ(status, Status::OK);
}
} // namespace widevine
} // namespace V1_4
} // namespace drm
} // namespace hardware
} // namespace wvdrm

View File

@@ -22,52 +22,6 @@ package {
default_applicable_licenses: ["vendor_widevine_license"], default_applicable_licenses: ["vendor_widevine_license"],
} }
// Builds libwvdrmdrmplugin_hidl
//
cc_library_static {
name: "libwvdrmdrmplugin_hidl",
srcs: [
"src_hidl/WVDrmPlugin.cpp",
"src_hidl/WVGenericCryptoInterface.cpp",
"src_hidl/hidl_metrics_adapter.cpp",
],
include_dirs: [
"frameworks/av/include",
"frameworks/native/include",
"vendor/widevine/libwvdrmengine/cdm/core/include",
"vendor/widevine/libwvdrmengine/cdm/include",
"vendor/widevine/libwvdrmengine/cdm/metrics/include",
"vendor/widevine/libwvdrmengine/cdm/util/include",
"vendor/widevine/libwvdrmengine/include_hidl",
"vendor/widevine/libwvdrmengine/include",
"vendor/widevine/libwvdrmengine/mediadrm/include_hidl",
"vendor/widevine/libwvdrmengine/oemcrypto/include",
],
header_libs: [
"libstagefright_headers",
"libstagefright_foundation_headers",
"libutils_headers",
],
static_libs: ["libcdm_protos"],
shared_libs: [
"android.hardware.drm@1.0",
"android.hardware.drm@1.1",
"android.hardware.drm@1.2",
"android.hardware.drm@1.3",
"android.hardware.drm@1.4",
"android.hidl.memory@1.0",
"libcrypto",
"liblog",
],
proprietary: true,
}
// Builds libwvdrmdrmplugin_aidl // Builds libwvdrmdrmplugin_aidl
// //
cc_library_static { cc_library_static {

View File

@@ -175,7 +175,7 @@ class WVDrmPlugin : public ::aidl::android::hardware::drm::BnDrmPlugin,
const std::vector<uint8_t>& in_signature, const std::vector<uint8_t>& in_signature,
bool* _aidl_return) override; bool* _aidl_return) override;
// The following methods do not use hidl interface, it is used internally. // The following methods do not use HAL interface, it is used internally.
virtual Status unprovisionDevice(); virtual Status unprovisionDevice();
virtual void OnSessionRenewalNeeded(const CdmSessionId& cdmSessionId); virtual void OnSessionRenewalNeeded(const CdmSessionId& cdmSessionId);

View File

@@ -1,510 +0,0 @@
//
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
#ifndef WV_DRM_PLUGIN_H_
#define WV_DRM_PLUGIN_H_
#include <utils/Mutex.h>
#include <list>
#include <map>
#include "HidlTypes.h"
#include "HidlWVTypes.h"
#include "OEMCryptoCENC.h"
#include "WVGenericCryptoInterface.h"
#include "cdm_client_property_set.h"
#include "cdm_identifier.h"
#include "log.h"
#include "wv_cdm_event_listener.h"
#include "wv_content_decryption_module.h"
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_4 {
namespace widevine {
using android::Mutex;
using std::map;
using wvcdm::CdmIdentifier;
using wvcdm::CdmKeyStatusMap;
using wvcdm::CdmResponseType;
using wvcdm::CdmSessionId;
using wvcdm::WvContentDecryptionModule;
const OEMCrypto_Algorithm kInvalidCryptoAlgorithm =
static_cast<OEMCrypto_Algorithm>(-1);
struct WVDrmPlugin : public ::drm::V1_4::IDrmPlugin,
IDrmPluginListener,
wvcdm::WvCdmEventListener {
WVDrmPlugin(const sp<WvContentDecryptionModule>& cdm,
const std::string& appPackageName,
WVGenericCryptoInterface* crypto, bool useSpoid);
virtual ~WVDrmPlugin();
void Close();
Return<void> openSession(openSession_cb _hidl_cb) override;
Return<void> openSession_1_1(SecurityLevel securityLevel,
openSession_1_1_cb _hidl_cb) override;
Return<Status> closeSession(const hidl_vec<uint8_t>& sessionId) override;
Return<void> getKeyRequest(const hidl_vec<uint8_t>& scope,
const hidl_vec<uint8_t>& initData,
const hidl_string& mimeType, KeyType keyType,
const hidl_vec<KeyValue>& optionalParameters,
getKeyRequest_cb _hidl_cb) override;
Return<void> getKeyRequest_1_1(const hidl_vec<uint8_t>& scope,
const hidl_vec<uint8_t>& initData,
const hidl_string& mimeType, KeyType keyType,
const hidl_vec<KeyValue>& optionalParameters,
getKeyRequest_1_1_cb _hidl_cb) override;
Return<void> getKeyRequest_1_2(const hidl_vec<uint8_t>& scope,
const hidl_vec<uint8_t>& initData,
const hidl_string& mimeType, KeyType keyType,
const hidl_vec<KeyValue>& optionalParameters,
getKeyRequest_1_2_cb _hidl_cb) override;
Return<void> provideKeyResponse(const hidl_vec<uint8_t>& scope,
const hidl_vec<uint8_t>& response,
provideKeyResponse_cb _hidl_cb) override;
Return<Status> removeKeys(const hidl_vec<uint8_t>& sessionId) override;
Return<Status> restoreKeys(const hidl_vec<uint8_t>& sessionId,
const hidl_vec<uint8_t>& keySetId) override;
Return<void> queryKeyStatus(const hidl_vec<uint8_t>& sessionId,
queryKeyStatus_cb _hidl_cb) override;
Return<void> getProvisionRequest(const hidl_string& certificateType,
const hidl_string& certificateAuthority,
getProvisionRequest_cb _hidl_cb) override;
Return<void> getProvisionRequest_1_2(
const hidl_string& certificateType,
const hidl_string& certificateAuthority,
getProvisionRequest_1_2_cb _hidl_cb) override;
Return<void> provideProvisionResponse(
const hidl_vec<uint8_t>& response,
provideProvisionResponse_cb _hidl_cb) override;
Return<void> getSecureStops(getSecureStops_cb _hidl_cb) override;
Return<void> getSecureStop(const hidl_vec<uint8_t>& secureStopId,
getSecureStop_cb _hidl_cb) override;
Return<Status> releaseAllSecureStops() override;
Return<Status> releaseSecureStop(
const hidl_vec<uint8_t>& secureStopId) override;
Return<void> getMetrics(getMetrics_cb _hidl_cb);
Return<void> getSecureStopIds(getSecureStopIds_cb _hidl_cb) override;
Return<Status> releaseSecureStops(
const SecureStopRelease& ssRelease) override;
Return<Status> removeSecureStop(
const hidl_vec<uint8_t>& secureStopId) override;
Return<Status> removeAllSecureStops() override;
Return<void> getHdcpLevels(getHdcpLevels_cb _hidl_cb) override;
Return<void> getHdcpLevels_1_2(getHdcpLevels_1_2_cb _hidl_cb) override;
Return<void> getNumberOfSessions(getNumberOfSessions_cb _hidl_cb) override;
Return<void> getSecurityLevel(const hidl_vec<uint8_t>& sessionId,
getSecurityLevel_cb _hidl_cb) override;
Return<void> getOfflineLicenseKeySetIds(
getOfflineLicenseKeySetIds_cb _hidl_cb) override;
Return<Status> removeOfflineLicense(const KeySetId& keySetId) override;
Return<void> getOfflineLicenseState(
const KeySetId& keySetId, getOfflineLicenseState_cb _hidl_cb) override;
Return<void> getPropertyString(const hidl_string& propertyName,
getPropertyString_cb _hidl_cb) override;
Return<void> getPropertyByteArray(const hidl_string& propertyName,
getPropertyByteArray_cb _hidl_cb) override;
Return<Status> setPropertyString(const hidl_string& propertyName,
const hidl_string& value) override;
Return<Status> setPropertyByteArray(const hidl_string& propertyName,
const hidl_vec<uint8_t>& value) override;
Return<Status> setCipherAlgorithm(const hidl_vec<uint8_t>& sessionId,
const hidl_string& algorithm) override;
Return<Status> setMacAlgorithm(const hidl_vec<uint8_t>& sessionId,
const hidl_string& algorithm) override;
Return<void> encrypt(const hidl_vec<uint8_t>& sessionId,
const hidl_vec<uint8_t>& keyId,
const hidl_vec<uint8_t>& input,
const hidl_vec<uint8_t>& iv,
encrypt_cb _hidl_cb) override;
Return<void> decrypt(const hidl_vec<uint8_t>& sessionId,
const hidl_vec<uint8_t>& keyId,
const hidl_vec<uint8_t>& input,
const hidl_vec<uint8_t>& iv,
decrypt_cb _hidl_cb) override;
Return<void> sign(const hidl_vec<uint8_t>& sessionId,
const hidl_vec<uint8_t>& keyId,
const hidl_vec<uint8_t>& message,
sign_cb _hidl_cb) override;
Return<void> verify(const hidl_vec<uint8_t>& sessionId,
const hidl_vec<uint8_t>& keyId,
const hidl_vec<uint8_t>& message,
const hidl_vec<uint8_t>& signature,
verify_cb _hidl_cb) override;
Return<void> signRSA(const hidl_vec<uint8_t>& sessionId,
const hidl_string& algorithm,
const hidl_vec<uint8_t>& message,
const hidl_vec<uint8_t>& wrappedkey,
signRSA_cb _hidl_cb) override;
Return<void> setListener(const sp<IDrmPluginListener>& listener) override;
Return<void> sendEvent(EventType eventType,
const hidl_vec<uint8_t>& sessionId,
const hidl_vec<uint8_t>& data) override;
Return<void> sendExpirationUpdate(const hidl_vec<uint8_t>& sessionId,
int64_t expiryTimeInMS) override;
Return<void> sendKeysChange(const hidl_vec<uint8_t>& sessionId,
const hidl_vec<KeyStatus>& keyStatusList,
bool hasNewUsableKey) override;
Return<void> sendKeysChange_1_2(const hidl_vec<uint8_t>& sessionId,
const hidl_vec<KeyStatus_V1_2>& keyStatusList,
bool hasNewUsableKey) override;
Return<void> sendSessionLostState(
const hidl_vec<uint8_t>& sessionId) override;
Return<void> getLogMessages(getLogMessages_cb _hidl_cb) override;
Return<bool> requiresSecureDecoder(const hidl_string& mime,
SecurityLevel level) override;
Return<bool> requiresSecureDecoderDefault(const hidl_string& mime) override;
Return<::drm::V1_0::Status> setPlaybackId(
const hidl_vec<uint8_t>& sessionId,
const hidl_string& playbackId) override;
// The following methods do not use hidl interface, it is used internally.
virtual Status unprovisionDevice();
virtual void OnSessionRenewalNeeded(const CdmSessionId& cdmSessionId);
template <typename KS>
void _sendKeysChange(const hidl_vec<uint8_t>& sessionId,
const hidl_vec<KS>& keyStatusList, bool hasNewUsableKey);
template <typename KS>
void _OnSessionKeysChange(const CdmSessionId&, const CdmKeyStatusMap&,
bool hasNewUsableKey);
virtual void OnSessionKeysChange(const CdmSessionId& cdmSessionId,
const CdmKeyStatusMap& cdmKeysStatus,
bool hasNewUsableKey);
virtual void OnExpirationUpdate(const CdmSessionId& cdmSessionId,
int64_t newExpiryTimeSeconds);
virtual void OnSessionLostState(const CdmSessionId& cdmSessionId);
private:
WVDRM_DISALLOW_COPY_AND_ASSIGN_AND_NEW(WVDrmPlugin);
// List this field first so it is destructed last; ensure logging uid
// is cleared right before plugin is destructed.
wvutil::LoggingUidSetter mLoggingUidSetter;
struct CryptoSession {
public:
CryptoSession()
: mOecSessionId(-1),
mCipherAlgorithm(kInvalidCryptoAlgorithm),
mMacAlgorithm(kInvalidCryptoAlgorithm) {}
CryptoSession(OEMCrypto_SESSION sessionId)
: mOecSessionId(sessionId),
mCipherAlgorithm(kInvalidCryptoAlgorithm),
mMacAlgorithm(kInvalidCryptoAlgorithm) {}
OEMCrypto_SESSION oecSessionId() const { return mOecSessionId; }
OEMCrypto_Algorithm cipherAlgorithm() const { return mCipherAlgorithm; }
void setCipherAlgorithm(OEMCrypto_Algorithm newAlgorithm) {
mCipherAlgorithm = newAlgorithm;
}
OEMCrypto_Algorithm macAlgorithm() const { return mMacAlgorithm; }
void setMacAlgorithm(OEMCrypto_Algorithm newAlgorithm) {
mMacAlgorithm = newAlgorithm;
}
private:
OEMCrypto_SESSION mOecSessionId;
OEMCrypto_Algorithm mCipherAlgorithm;
OEMCrypto_Algorithm mMacAlgorithm;
};
class WVClientPropertySet : public wvcdm::CdmClientPropertySet {
public:
WVClientPropertySet()
: mUsePrivacyMode(false),
mShareKeys(false),
mSessionSharingId(0),
mUseAtscMode(false) {}
virtual ~WVClientPropertySet() {}
virtual const std::string& security_level() const { return mSecurityLevel; }
void set_security_level(const std::string& securityLevel) {
mSecurityLevel = securityLevel;
}
virtual bool use_privacy_mode() const { return mUsePrivacyMode; }
void set_use_privacy_mode(bool usePrivacyMode) {
mUsePrivacyMode = usePrivacyMode;
}
virtual const std::string& service_certificate() const {
return mServiceCertificate;
}
virtual void set_service_certificate(
const std::string& serviceCertificate) {
mServiceCertificate = serviceCertificate;
}
virtual const std::string& device_provisioning_service_certificate() const {
// Android does not support service certificates for provisioning.
return mEmptyString;
}
virtual void set_device_provisioning_service_certificate(
const std::string&) {
// Ignore. Android does not support service certificates for provisioning
// TODO(b/69562876): Android SHOULD support service cert for provisioning
}
virtual bool is_session_sharing_enabled() const { return mShareKeys; }
void set_is_session_sharing_enabled(bool shareKeys) {
mShareKeys = shareKeys;
}
virtual uint32_t session_sharing_id() const { return mSessionSharingId; }
virtual void set_session_sharing_id(uint32_t id) { mSessionSharingId = id; }
virtual const std::string& app_id() const { return mAppId; }
void set_app_id(const std::string& appId) { mAppId = appId; }
virtual bool use_atsc_mode() const { return mUseAtscMode; }
void set_use_atsc_mode(bool useAtscMode) { mUseAtscMode = useAtscMode; }
private:
DISALLOW_EVIL_CONSTRUCTORS(WVClientPropertySet);
std::string mSecurityLevel;
bool mUsePrivacyMode;
std::string mServiceCertificate;
bool mShareKeys;
uint32_t mSessionSharingId;
std::string mAppId;
bool mUseAtscMode;
const std::string mEmptyString;
} mPropertySet;
class CdmIdentifierBuilder {
public:
CdmIdentifierBuilder(bool useSpoid, const WVDrmPlugin& parent,
const std::string& appPackageName);
// Fills in the passed-in struct with the CDM Identifier for the current
// combination of Origin, Application, and Device. This is needed by some
// calls into the CDM in order to identify which CDM instance should receive
// the call. Calling this will seal the CDM Identifier Builder, thus making
// it an error to change the origin.
Status getCdmIdentifier(CdmIdentifier* identifier);
// Gets the application-safe device-unique ID. On non-SPOID devices, this is
// the device-unique ID from OEMCrypto. On SPOID devices, this is the SPOID.
// On SPOID devices, calling this will seal the CDM Identifier Builder, thus
// making it an error to change the origin.
Status getDeviceUniqueId(std::string* id);
Status getProvisioningUniqueId(std::string* id);
const std::string& origin() const { return mCdmIdentifier.origin; }
bool set_origin(const std::string& id);
// This sets the app package name to allow apps to access ATSC licenses
bool set_use_atsc_mode(bool enable);
// Indicates whether the builder can still be modified. This returns false
// until a call to getCdmIdentifier.
bool is_sealed() { return mIsIdentifierSealed; }
uint32_t user_id() const { return mCdmIdentifier.user_id; }
private:
WVDRM_DISALLOW_COPY_AND_ASSIGN(CdmIdentifierBuilder);
CdmIdentifier mCdmIdentifier;
bool mIsIdentifierSealed;
bool mUseSpoid;
std::string mAppPackageName;
const WVDrmPlugin& mParent;
Status calculateSpoid();
Status calculateSpoid(const std::string& deviceID, std::string* spoid);
// Gets the device-unique ID from OEMCrypto. This must be private, since
// this value must not be exposed to applications on SPOID devices. Code
// outside this class should use getDeviceUniqueId() to get the
// application-safe device-unique ID.
Status getOemcryptoDeviceId(std::string* id);
Status getOemcryptoDeviceId(wvcdm::RequestedSecurityLevel securityLevel,
std::string* id);
// The unique identifier is meant to ensure that two clients with the
// same spoid, origin and app package name still get different cdm engine
// instances. This is a stepping stone to simplifying the implementation.
// Note that we do not have a lock or mutex around this object. We assume
// that locking is handled external to this object.
uint32_t getNextUniqueId();
} mCdmIdentifierBuilder;
// Properly close plugins on SIGTERM then exit
class Terminator {
public:
static void Register(WVDrmPlugin* plugin) { instance().DoRegister(plugin); }
static void Forget(WVDrmPlugin* plugin) { instance().DoForget(plugin); }
static void Terminate(int /*signal*/) { instance().DoTerminate(); }
private:
WVDRM_DISALLOW_COPY_AND_ASSIGN(Terminator);
Terminator() { signal(SIGTERM, Terminate); }
static Terminator& instance() {
static Terminator instance;
return instance;
}
void DoRegister(WVDrmPlugin* plugin) {
Mutex::Autolock lock(mLock);
mPlugins.push_back(plugin);
}
void DoForget(WVDrmPlugin* plugin) {
Mutex::Autolock lock(mLock);
mPlugins.remove(plugin);
}
void DoTerminate() {
Mutex::Autolock lock(mLock);
for_each(mPlugins.begin(), mPlugins.end(), [] (WVDrmPlugin* plugin) {
ALOGI("WVDrmPlugin::Terminating plugin %p", (void*)plugin);
plugin->Close();
});
exit(0);
}
std::list<WVDrmPlugin*> mPlugins;
Mutex mLock;
};
sp<wvcdm::WvContentDecryptionModule> const mCDM;
WVGenericCryptoInterface* mCrypto;
map<CdmSessionId, CryptoSession> mCryptoSessions;
sp<IDrmPluginListener> mListener;
sp<IDrmPluginListener_V1_2> mListenerV1_2;
std::string mProvisioningServiceCertificate;
wvcdm::CdmSessionId mDecryptHashSessionId;
std::string mAppPackageName;
Status queryProperty(const std::string& property,
std::string& stringValue) const;
Status queryProperty(wvcdm::RequestedSecurityLevel securityLevel,
const std::string& property,
std::string& stringValue) const;
Status queryProperty(const std::string& property,
std::vector<uint8_t>& vector_value) const;
bool isProvisioned(wvcdm::CdmSecurityLevel securityLevel,
const std::string& origin, const std::string& spoid,
bool atsc_mode_enabled) const;
Status mapAndNotifyOfCdmResponseType(const std::vector<uint8_t>& sessionId,
CdmResponseType res);
Status_V1_2 mapAndNotifyOfCdmResponseType_1_2(
const std::vector<uint8_t>& sessionId, CdmResponseType res);
void notifyOfCdmResponseType(const std::vector<uint8_t>& sessionId,
CdmResponseType res);
Status mapAndNotifyOfOEMCryptoResult(const std::vector<uint8_t>& sessionId,
OEMCryptoResult res);
Status mapOEMCryptoResult(OEMCryptoResult res);
SecurityLevel mapSecurityLevel(const std::string& level);
wvcdm::RequestedSecurityLevel getRequestedSecurityLevel() const;
Status openSessionCommon(std::vector<uint8_t>& sessionId);
bool initDataResemblesPSSH(const std::vector<uint8_t>& initData);
Status unprovision(const CdmIdentifier& identifier);
};
} // namespace widevine
} // namespace V1_4
} // namespace drm
} // namespace hardware
} // namespace wvdrm
#endif // WV_DRM_PLUGIN_H_

View File

@@ -1,98 +0,0 @@
//
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
#ifndef WV_GENERIC_CRYPTO_INTERFACE_H_
#define WV_GENERIC_CRYPTO_INTERFACE_H_
#include <stdint.h>
#include <vector>
#include "OEMCryptoCENC.h"
#include "media/stagefright/foundation/ABase.h"
namespace wvdrm {
class WVGenericCryptoInterface {
public:
WVGenericCryptoInterface() {}
virtual ~WVGenericCryptoInterface() {}
virtual OEMCryptoResult selectKey(const OEMCrypto_SESSION session,
const uint8_t* key_id,
size_t key_id_length) {
return OEMCrypto_SelectKey(session, key_id, key_id_length,
OEMCrypto_CipherMode_CBCS);
}
virtual OEMCryptoResult encrypt(OEMCrypto_SESSION session,
const uint8_t* in_buffer,
size_t buffer_length, const uint8_t* iv,
OEMCrypto_Algorithm algorithm,
uint8_t* out_buffer) {
return OEMCrypto_Generic_Encrypt(session, in_buffer, buffer_length, iv,
algorithm, out_buffer);
}
virtual OEMCryptoResult decrypt(OEMCrypto_SESSION session,
const uint8_t* in_buffer,
size_t buffer_length, const uint8_t* iv,
OEMCrypto_Algorithm algorithm,
uint8_t* out_buffer) {
return OEMCrypto_Generic_Decrypt(session, in_buffer, buffer_length, iv,
algorithm, out_buffer);
}
virtual OEMCryptoResult sign(OEMCrypto_SESSION session,
const uint8_t* in_buffer, size_t buffer_length,
OEMCrypto_Algorithm algorithm,
uint8_t* signature, size_t* signature_length) {
return OEMCrypto_Generic_Sign(session, in_buffer, buffer_length, algorithm,
signature, signature_length);
}
virtual OEMCryptoResult verify(OEMCrypto_SESSION session,
const uint8_t* in_buffer, size_t buffer_length,
OEMCrypto_Algorithm algorithm,
const uint8_t* signature,
size_t signature_length) {
return OEMCrypto_Generic_Verify(session, in_buffer, buffer_length,
algorithm, signature, signature_length);
}
virtual OEMCryptoResult signRSA(const uint8_t* wrapped_rsa_key,
size_t wrapped_rsa_key_length,
const uint8_t* message,
size_t message_length,
std::vector<uint8_t>& signature,
RSA_Padding_Scheme padding_scheme);
virtual OEMCryptoResult loadDeviceRSAKey(OEMCrypto_SESSION session,
const uint8_t* wrapped_rsa_key,
size_t wrapped_rsa_key_length) {
return OEMCrypto_LoadDRMPrivateKey(session, OEMCrypto_RSA_Private_Key,
wrapped_rsa_key, wrapped_rsa_key_length);
}
virtual OEMCryptoResult generateRSASignature(
OEMCrypto_SESSION session,
const uint8_t* message,
size_t message_length,
uint8_t* signature,
size_t* signature_length,
RSA_Padding_Scheme padding_scheme) {
return OEMCrypto_GenerateRSASignature(session, message, message_length,
signature, signature_length,
padding_scheme);
}
private:
DISALLOW_EVIL_CONSTRUCTORS(WVGenericCryptoInterface);
};
} // namespace wvdrm
#endif // WV_GENERIC_CRYPTO_INTERFACE_H_

View File

@@ -1,113 +0,0 @@
//
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
#ifndef CDM_HIDL_METRICS_ADAPTER_H_
#define CDM_HIDL_METRICS_ADAPTER_H_
#include <vector>
#include <android/hardware/drm/1.1/types.h>
#include "wv_metrics.pb.h"
namespace wvcdm {
// Convenience alias. Used only in the declaration of HidlMetricsGroup.
namespace internal {
using DrmMetricGroup = android::hardware::drm::V1_1::DrmMetricGroup;
} // namespace internal
class HidlMetricsAdapter;
// This class is used to convert from the metrics.proto format for metrics
// to the format specified in the android.hardware.drm@1.1 DrmMetricGroup
// type. This class converts the common metric types into a single group.
//
// Example:
// drm_metrics::DistributionMetric distribution;
// distribution.set_operation_count(1);
// HidlMetricsGroupBuilder builder;
// builder.AddDistributions("test distribution", { distribution });
//
// DrmMetricGroup group = builder.Build();
class HidlMetricsGroupBuilder {
public:
// Adds a group of distributions with the given base name.
void AddDistributions(
const std::string& name,
const google::protobuf::RepeatedPtrField<
drm_metrics::DistributionMetric>& distributions);
// Adds a group of counter metrics with the given base name.
void AddCounters(
const std::string& name,
const google::protobuf::RepeatedPtrField<
drm_metrics::CounterMetric>& counters);
// Adds a value metric.
void AddValue(const std::string& name,
const drm_metrics::ValueMetric& value_or_error);
// Builds the metric group containing all of the previously added metrics.
internal::DrmMetricGroup Build();
private:
friend class HidlMetricsAdapter;
std::vector<internal::DrmMetricGroup::Metric> metrics_;
HidlMetricsGroupBuilder();
// Adds a distribution with the given name and distribution values.
void AddDistribution(const std::string& name,
const drm_metrics::DistributionMetric& distribution);
// Adds a counter metric
void AddCounter(const std::string& name,
const drm_metrics::CounterMetric& counter);
void AddAttributes(
const drm_metrics::Attributes& attributes_proto,
::android::hardware::hidl_vec<internal::DrmMetricGroup::Attribute>*
attributes);
};
// This class handles adding the engine and session metric collections. This
// will generate one DrmMetricGroup for each EngineMetric added and one for
// each SessionMetric added. This class also supports a static utility method to
// convert a WvCdmMetrics proto to a vector of DrmMetricGroup instances.
class HidlMetricsAdapter {
public:
// Utility method to quickly convert a WvCdmMetrics proto to a DrmMetricGroup
// vector.
static void ToHidlMetrics(
const drm_metrics::WvCdmMetrics& proto_metrics,
android::hardware::hidl_vec<internal::DrmMetricGroup>* hidl_metrics);
HidlMetricsAdapter();
~HidlMetricsAdapter();
// Adds the EngineMetrics instance to the Adapter. It will be converted and
// stored. The converted metrics can be fetched via GetHidlGroupVector.
void AddEngineMetrics(
const drm_metrics::WvCdmMetrics::EngineMetrics& proto_metrics);
// Adds the SessionMetrics instance to the Adapter. It will be converted and
// stored. The converted metrics can be fetched via GetHidlGroupVector.
void AddSessionMetrics(
const drm_metrics::WvCdmMetrics::SessionMetrics& proto_metrics);
// Returns the converted DrmMetricGroup vector containing all of the
// previously added engine and session metrics collections.
const android::hardware::hidl_vec<internal::DrmMetricGroup>
GetHidlGroupVector();
private:
void AddCryptoMetrics(
const drm_metrics::WvCdmMetrics::CryptoMetrics& proto_metrics,
HidlMetricsGroupBuilder* group_builder);
std::vector<internal::DrmMetricGroup> group_vector_;
};
} // namespace wvcdm
#endif // CDM_HIDL_METRICS_ADAPTER_H_

File diff suppressed because it is too large Load Diff

View File

@@ -1,50 +0,0 @@
//
// Copyright 2018 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 <log/log.h>
#include "WVGenericCryptoInterface.h"
#include "wv_cdm_constants.h"
namespace wvdrm {
using namespace std;
using namespace wvcdm;
OEMCryptoResult WVGenericCryptoInterface::signRSA(const uint8_t* wrapped_rsa_key,
size_t wrapped_rsa_key_length,
const uint8_t* message,
size_t message_length,
std::vector<uint8_t>& signature,
RSA_Padding_Scheme padding_scheme) {
OEMCrypto_SESSION session;
OEMCryptoResult sts = OEMCrypto_OpenSession(&session);
if (sts != OEMCrypto_SUCCESS) return sts;
sts = OEMCrypto_LoadDRMPrivateKey(session, OEMCrypto_RSA_Private_Key,
wrapped_rsa_key, wrapped_rsa_key_length);
if (sts == OEMCrypto_SUCCESS) {
size_t signatureSize = 0;
sts = OEMCrypto_GenerateRSASignature(session, message, message_length,
NULL, &signatureSize,
padding_scheme);
if (sts == OEMCrypto_SUCCESS) {
// Should be short buffer.
sts = OEMCrypto_ERROR_UNKNOWN_FAILURE;
} else if (sts == OEMCrypto_ERROR_SHORT_BUFFER) {
signature.resize(signatureSize);
sts = OEMCrypto_GenerateRSASignature(session, message, message_length,
signature.data(), &signatureSize,
padding_scheme);
}
}
OEMCrypto_CloseSession(session);
return sts;
}
} // namespace wvdrm

View File

@@ -1,650 +0,0 @@
//
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
#include "hidl_metrics_adapter.h"
#include <android/hardware/drm/1.1/types.h>
#include "wv_metrics.pb.h"
using android::hardware::hidl_vec;
using android::hardware::drm::V1_1::DrmMetricGroup;
using drm_metrics::CounterMetric;
using drm_metrics::DistributionMetric;
using google::protobuf::RepeatedPtrField;
namespace wvcdm {
namespace {
const char kAttributeErrorCode[] = "error_code";
const char kAttributeErrorCodeBool[] = "error_code_bool";
const char kAttributeCdmSecurityLevel[] = "cdm_security_level";
const char kAttributeSecurityLevel[] = "security_level";
const char kAttributeLength[] = "length";
const char kAttributeEncryptionAlgorithm[] = "encryption_algorithm";
const char kAttributeSigningAlgorithm[] = "signing_algorithm";
const char kAttributeOemCryptoResult[] = "oem_crypto_result";
const char kAttributeKeyStatusType[] = "key_status_type";
const char kAttributeEventType[] = "event_type";
const char kAttributeKeyRequestType[] = "key_request_type";
const char kAttributeLicenseType[] = "license_type";
template<typename T>
void SetValue(const T& value, DrmMetricGroup::Attribute* attribute);
template<>
void SetValue(const int& value, DrmMetricGroup::Attribute* attribute) {
attribute->int64Value = value;
}
template<>
void SetValue(const bool& value, DrmMetricGroup::Attribute* attribute) {
attribute->int64Value = value;
}
template<>
void SetValue(const unsigned int& value,
DrmMetricGroup::Attribute* attribute) {
attribute->int64Value = value;
}
template<>
__attribute__((unused))
void SetValue(const unsigned long& value,
DrmMetricGroup::Attribute* attribute) {
attribute->int64Value = value;
}
template<>
__attribute__((unused))
void SetValue(const unsigned long long& value,
DrmMetricGroup::Attribute* attribute) {
attribute->int64Value = value;
}
template<typename T>
void AddAttribute(
const std::string& name, DrmMetricGroup::ValueType vt, T value,
std::vector<DrmMetricGroup::Attribute>* attribute_vector) {
// Set the default values.
DrmMetricGroup::Attribute attribute = { name, vt, 0, 0, "" };
SetValue(value, &attribute);
attribute_vector->push_back(attribute);
}
} // anonymous namespace
void HidlMetricsGroupBuilder::AddDistributions(
const std::string& name,
const RepeatedPtrField<drm_metrics::DistributionMetric>& distributions) {
for (const auto& metric : distributions) {
AddDistribution(name, metric);
}
}
void HidlMetricsGroupBuilder::AddCounters(
const std::string& name,
const RepeatedPtrField<drm_metrics::CounterMetric>& counters) {
for (const auto& counter : counters) {
AddCounter(name, counter);
}
}
void HidlMetricsGroupBuilder::AddDistribution(
const std::string& name, const drm_metrics::DistributionMetric& distribution) {
DrmMetricGroup::Metric metric;
metric.name = name;
AddAttributes(distribution.attributes(), &(metric.attributes));
DrmMetricGroup::Value mean = {
"mean", DrmMetricGroup::ValueType::DOUBLE_TYPE,
0, distribution.mean(), "" };
DrmMetricGroup::Value count = {
"count", DrmMetricGroup::ValueType::INT64_TYPE,
(int64_t) distribution.operation_count(), 0, "" };
if (distribution.operation_count() == 1) {
metric.values.resize(2);
metric.values[0] = mean;
metric.values[1] = count;
} else {
DrmMetricGroup::Value min = {
"min", DrmMetricGroup::ValueType::DOUBLE_TYPE,
0, distribution.min(), "" };
DrmMetricGroup::Value max = {
"max", DrmMetricGroup::ValueType::DOUBLE_TYPE,
0, distribution.max(), "" };
DrmMetricGroup::Value variance {
"variance", DrmMetricGroup::ValueType::DOUBLE_TYPE,
0, distribution.variance(), "" };
metric.values.resize(5);
metric.values[0] = mean;
metric.values[1] = count;
metric.values[2] = min;
metric.values[3] = max;
metric.values[4] = variance;
}
metrics_.push_back(metric);
}
void HidlMetricsGroupBuilder::AddCounter(
const std::string& name, const drm_metrics::CounterMetric& counter) {
DrmMetricGroup::Metric metric;
metric.name = name;
AddAttributes(counter.attributes(), &(metric.attributes));
DrmMetricGroup::Value value = {
"count", DrmMetricGroup::ValueType::INT64_TYPE, counter.count(), 0, "" };
metric.values.resize(1);
metric.values[0] = value;
metrics_.push_back(metric);
}
void HidlMetricsGroupBuilder::AddValue(
const std::string& name, const drm_metrics::ValueMetric& value_or_error) {
DrmMetricGroup::Metric metric;
DrmMetricGroup::Value value;
metric.name = name;
if (value_or_error.has_error_code()) {
value = { "error_code", DrmMetricGroup::ValueType::INT64_TYPE,
value_or_error.error_code(), 0, "" };
} else if (value_or_error.has_int_value()) {
value = { "value", DrmMetricGroup::ValueType::INT64_TYPE,
value_or_error.int_value(), 0, "" };
} else if (value_or_error.has_double_value()) {
value = { "value", DrmMetricGroup::ValueType::DOUBLE_TYPE,
0, value_or_error.double_value(), "" };
} else if (value_or_error.has_string_value()) {
value = { "value", DrmMetricGroup::ValueType::STRING_TYPE,
0, 0, value_or_error.string_value() };
} else {
value = { "error", DrmMetricGroup::ValueType::STRING_TYPE,
0, 0, "Unexpected value type." };
}
metric.values.resize(1);
metric.values[0] = value;
metrics_.push_back(metric);
}
void HidlMetricsGroupBuilder::AddAttributes(
const drm_metrics::Attributes& attributes_proto,
hidl_vec<DrmMetricGroup::Attribute>*
attributes) {
std::vector<DrmMetricGroup::Attribute>
attribute_vector;
if (attributes_proto.has_error_code()) {
AddAttribute(
kAttributeErrorCode,
DrmMetricGroup::ValueType::INT64_TYPE,
attributes_proto.error_code(), &attribute_vector);
}
if (attributes_proto.has_error_code_bool()) {
AddAttribute(
kAttributeErrorCodeBool,
DrmMetricGroup::ValueType::INT64_TYPE,
attributes_proto.error_code_bool(), &attribute_vector);
}
if (attributes_proto.has_cdm_security_level()) {
AddAttribute(
kAttributeCdmSecurityLevel,
DrmMetricGroup::ValueType::INT64_TYPE,
attributes_proto.cdm_security_level(), &attribute_vector);
}
if (attributes_proto.has_security_level()) {
AddAttribute(
kAttributeSecurityLevel,
DrmMetricGroup::ValueType::INT64_TYPE,
attributes_proto.security_level(), &attribute_vector);
}
if (attributes_proto.has_length()) {
AddAttribute(
kAttributeLength,
DrmMetricGroup::ValueType::INT64_TYPE,
attributes_proto.length(), &attribute_vector);
}
if (attributes_proto.has_encryption_algorithm()) {
AddAttribute(
kAttributeEncryptionAlgorithm,
DrmMetricGroup::ValueType::INT64_TYPE,
attributes_proto.encryption_algorithm(), &attribute_vector);
}
if (attributes_proto.has_signing_algorithm()) {
AddAttribute(
kAttributeSigningAlgorithm,
DrmMetricGroup::ValueType::INT64_TYPE,
attributes_proto.signing_algorithm(), &attribute_vector);
}
if (attributes_proto.has_oem_crypto_result()) {
AddAttribute(
kAttributeOemCryptoResult,
DrmMetricGroup::ValueType::INT64_TYPE,
attributes_proto.oem_crypto_result(), &attribute_vector);
}
if (attributes_proto.has_key_status_type()) {
AddAttribute(
kAttributeKeyStatusType,
DrmMetricGroup::ValueType::INT64_TYPE,
attributes_proto.key_status_type(), &attribute_vector);
}
if (attributes_proto.has_event_type()) {
AddAttribute(
kAttributeEventType,
DrmMetricGroup::ValueType::INT64_TYPE,
attributes_proto.event_type(), &attribute_vector);
}
if (attributes_proto.has_key_request_type()) {
AddAttribute(
kAttributeKeyRequestType,
DrmMetricGroup::ValueType::INT64_TYPE,
attributes_proto.key_request_type(), &attribute_vector);
}
if (attributes_proto.has_license_type()) {
AddAttribute(
kAttributeLicenseType,
DrmMetricGroup::ValueType::INT64_TYPE,
attributes_proto.license_type(), &attribute_vector);
}
*attributes = attribute_vector;
}
DrmMetricGroup HidlMetricsGroupBuilder::Build() {
DrmMetricGroup metric_group;
metric_group.metrics = metrics_;
return metric_group;
}
HidlMetricsGroupBuilder::HidlMetricsGroupBuilder() {}
HidlMetricsAdapter::HidlMetricsAdapter() {}
HidlMetricsAdapter::~HidlMetricsAdapter() {}
void HidlMetricsAdapter::AddEngineMetrics(
const drm_metrics::WvCdmMetrics::EngineMetrics& proto_metrics) {
HidlMetricsGroupBuilder group_builder;
AddCryptoMetrics(proto_metrics.crypto_metrics(), &group_builder);
if (proto_metrics.has_oemcrypto_initialization_mode()) {
group_builder.AddValue(
"oemcrypto_initialization_mode",
proto_metrics.oemcrypto_initialization_mode());
}
if (proto_metrics.has_oemcrypto_l1_api_version()) {
group_builder.AddValue(
"oemcrypto_l1_api_version",
proto_metrics.oemcrypto_l1_api_version());
}
if (proto_metrics.has_oemcrypto_l1_min_api_version()) {
group_builder.AddValue(
"oemcrypto_l1_min_api_version",
proto_metrics.oemcrypto_l1_min_api_version());
}
if (proto_metrics.has_app_package_name()) {
group_builder.AddValue(
"app_package_name",
proto_metrics.app_package_name());
}
group_builder.AddDistributions(
"cdm_engine_add_key_time_us",
proto_metrics.cdm_engine_add_key_time_us());
if (proto_metrics.has_cdm_engine_cdm_version()) {
group_builder.AddValue(
"cdm_engine_cdm_version",
proto_metrics.cdm_engine_cdm_version());
}
group_builder.AddCounters(
"cdm_engine_close_session",
proto_metrics.cdm_engine_close_session());
if (proto_metrics.has_cdm_engine_creation_time_millis()) {
group_builder.AddValue(
"cdm_engine_creation_time_millis",
proto_metrics.cdm_engine_creation_time_millis());
}
group_builder.AddDistributions(
"cdm_engine_decrypt_time_us",
proto_metrics.cdm_engine_decrypt_time_us());
group_builder.AddCounters(
"cdm_engine_find_session_for_key",
proto_metrics.cdm_engine_find_session_for_key());
group_builder.AddDistributions(
"cdm_engine_generate_key_request_time_us",
proto_metrics.cdm_engine_generate_key_request_time_us());
group_builder.AddDistributions(
"cdm_engine_get_provisioning_request_time_us",
proto_metrics.cdm_engine_get_provisioning_request_time_us());
group_builder.AddCounters(
"cdm_engine_get_secure_stop_ids",
proto_metrics.cdm_engine_get_secure_stop_ids());
group_builder.AddDistributions(
"cdm_engine_get_usage_info_time_us",
proto_metrics.cdm_engine_get_usage_info_time_us());
group_builder.AddDistributions(
"cdm_engine_handle_provisioning_response_time_us",
proto_metrics.cdm_engine_handle_provisioning_response_time_us());
if (proto_metrics.has_cdm_engine_life_span_ms()) {
group_builder.AddValue(
"cdm_engine_life_span_ms",
proto_metrics.cdm_engine_life_span_ms());
}
group_builder.AddCounters(
"cdm_engine_open_key_set_session",
proto_metrics.cdm_engine_open_key_set_session());
group_builder.AddCounters(
"cdm_engine_open_session",
proto_metrics.cdm_engine_open_session());
group_builder.AddDistributions(
"cdm_engine_query_key_status_time_us",
proto_metrics.cdm_engine_query_key_status_time_us());
group_builder.AddCounters(
"cdm_engine_release_all_usage_info",
proto_metrics.cdm_engine_release_all_usage_info());
group_builder.AddCounters(
"cdm_engine_release_usage_info",
proto_metrics.cdm_engine_release_usage_info());
group_builder.AddCounters(
"cdm_engine_remove_all_usage_info",
proto_metrics.cdm_engine_remove_all_usage_info());
group_builder.AddCounters(
"cdm_engine_remove_keys",
proto_metrics.cdm_engine_remove_keys());
group_builder.AddCounters(
"cdm_engine_remove_usage_info",
proto_metrics.cdm_engine_remove_usage_info());
group_builder.AddDistributions(
"cdm_engine_restore_key_time_us",
proto_metrics.cdm_engine_restore_key_time_us());
group_builder.AddCounters(
"cdm_engine_unprovision",
proto_metrics.cdm_engine_unprovision());
if (proto_metrics.has_level3_oemcrypto_initialization_error()) {
group_builder.AddValue(
"level3_oemcrypto_initialization_error",
proto_metrics.level3_oemcrypto_initialization_error());
}
if (proto_metrics.has_previous_oemcrypto_initialization_failure()) {
group_builder.AddValue(
"previous_oemcrypto_initialization_failure",
proto_metrics.previous_oemcrypto_initialization_failure());
}
group_vector_.emplace_back(group_builder.Build());
}
void HidlMetricsAdapter::AddSessionMetrics(
const drm_metrics::WvCdmMetrics::SessionMetrics& proto_metrics) {
HidlMetricsGroupBuilder group_builder;
AddCryptoMetrics(proto_metrics.crypto_metrics(), &group_builder);
if (proto_metrics.has_session_id()) {
group_builder.AddValue(
"session_id",
proto_metrics.session_id());
}
if (proto_metrics.has_cdm_session_life_span_ms()) {
group_builder.AddValue(
"cdm_session_life_span_ms",
proto_metrics.cdm_session_life_span_ms());
}
group_builder.AddDistributions(
"cdm_session_renew_key_time_us",
proto_metrics.cdm_session_renew_key_time_us());
group_builder.AddCounters(
"cdm_session_restore_offline_session",
proto_metrics.cdm_session_restore_offline_session());
group_builder.AddCounters(
"cdm_session_restore_usage_session",
proto_metrics.cdm_session_restore_usage_session());
group_builder.AddDistributions(
"cdm_session_license_request_latency_ms",
proto_metrics.cdm_session_license_request_latency_ms());
if (proto_metrics.has_oemcrypto_build_info()) {
group_builder.AddValue(
"oemcrypto_build_info",
proto_metrics.oemcrypto_build_info());
}
if (proto_metrics.has_license_sdk_version()) {
group_builder.AddValue(
"license_sdk_version",
proto_metrics.license_sdk_version());
}
if (proto_metrics.has_license_service_version()) {
group_builder.AddValue(
"license_service_version",
proto_metrics.license_service_version());
}
if (proto_metrics.has_playback_id()) {
group_builder.AddValue(
"playback_id",
proto_metrics.playback_id());
}
group_vector_.emplace_back(group_builder.Build());
}
void HidlMetricsAdapter::AddCryptoMetrics(
const drm_metrics::WvCdmMetrics::CryptoMetrics& proto_metrics,
HidlMetricsGroupBuilder* group_builder) {
if (proto_metrics.has_crypto_session_security_level()) {
group_builder->AddValue(
"crypto_session_security_level",
proto_metrics.crypto_session_security_level());
}
group_builder->AddCounters(
"crypto_session_delete_all_usage_reports",
proto_metrics.crypto_session_delete_all_usage_reports());
group_builder->AddCounters(
"crypto_session_delete_multiple_usage_information",
proto_metrics.crypto_session_delete_multiple_usage_information());
group_builder->AddDistributions(
"crypto_session_generic_decrypt_time_us",
proto_metrics.crypto_session_generic_decrypt_time_us());
group_builder->AddDistributions(
"crypto_session_generic_encrypt_time_us",
proto_metrics.crypto_session_generic_encrypt_time_us());
group_builder->AddDistributions(
"crypto_session_generic_sign_time_us",
proto_metrics.crypto_session_generic_sign_time_us());
group_builder->AddDistributions(
"crypto_session_generic_verify_time_us",
proto_metrics.crypto_session_generic_verify_time_us());
group_builder->AddCounters(
"crypto_session_get_device_unique_id",
proto_metrics.crypto_session_get_device_unique_id());
group_builder->AddCounters(
"crypto_session_get_token",
proto_metrics.crypto_session_get_token());
if (proto_metrics.has_crypto_session_life_span()) {
group_builder->AddValue("crypto_session_life_span",
proto_metrics.crypto_session_life_span());
}
group_builder->AddDistributions(
"crypto_session_load_certificate_private_key_time_us",
proto_metrics.crypto_session_load_certificate_private_key_time_us());
group_builder->AddDistributions(
"crypto_session_open_time_us",
proto_metrics.crypto_session_open_time_us());
if (proto_metrics.has_crypto_session_system_id()) {
group_builder->AddValue("crypto_session_system_id",
proto_metrics.crypto_session_system_id());
}
group_builder->AddDistributions(
"crypto_session_update_usage_information_time_us",
proto_metrics.crypto_session_update_usage_information_time_us());
if (proto_metrics.has_crypto_session_usage_information_support()) {
group_builder->AddValue("crypto_session_usage_information_support",
proto_metrics.crypto_session_usage_information_support());
}
if (proto_metrics.has_usage_table_header_initial_size()) {
group_builder->AddValue("usage_table_header_initial_size",
proto_metrics.usage_table_header_initial_size());
}
group_builder->AddCounters(
"usage_table_header_add_entry",
proto_metrics.usage_table_header_add_entry());
group_builder->AddCounters(
"usage_table_header_delete_entry",
proto_metrics.usage_table_header_delete_entry());
group_builder->AddDistributions(
"usage_table_header_update_entry_time_us",
proto_metrics.usage_table_header_update_entry_time_us());
group_builder->AddCounters(
"usage_table_header_load_entry",
proto_metrics.usage_table_header_load_entry());
if (proto_metrics.has_oemcrypto_api_version()) {
group_builder->AddValue("oemcrypto_api_version",
proto_metrics.oemcrypto_api_version());
}
group_builder->AddCounters(
"oemcrypto_close_session",
proto_metrics.oemcrypto_close_session());
group_builder->AddDistributions(
"oemcrypto_copy_buffer_time_us",
proto_metrics.oemcrypto_copy_buffer_time_us());
if (proto_metrics.has_oemcrypto_current_hdcp_capability()) {
group_builder->AddValue("oemcrypto_current_hdcp_capability",
proto_metrics.oemcrypto_current_hdcp_capability());
}
group_builder->AddCounters(
"oemcrypto_deactivate_usage_entry",
proto_metrics.oemcrypto_deactivate_usage_entry());
group_builder->AddDistributions(
"oemcrypto_decrypt_cenc_time_us",
proto_metrics.oemcrypto_decrypt_cenc_time_us());
group_builder->AddCounters(
"oemcrypto_delete_usage_entry",
proto_metrics.oemcrypto_delete_usage_entry());
group_builder->AddCounters(
"oemcrypto_delete_usage_table",
proto_metrics.oemcrypto_delete_usage_table());
group_builder->AddDistributions(
"oemcrypto_derive_keys_from_session_key_time_us",
proto_metrics.oemcrypto_derive_keys_from_session_key_time_us());
group_builder->AddCounters(
"oemcrypto_force_delete_usage_entry",
proto_metrics.oemcrypto_force_delete_usage_entry());
group_builder->AddDistributions(
"oemcrypto_generate_derived_keys_time_us",
proto_metrics.oemcrypto_generate_derived_keys_time_us());
group_builder->AddCounters(
"oemcrypto_generate_nonce",
proto_metrics.oemcrypto_generate_nonce());
group_builder->AddDistributions(
"oemcrypto_generate_rsa_signature_time_us",
proto_metrics.oemcrypto_generate_rsa_signature_time_us());
group_builder->AddDistributions(
"oemcrypto_generate_signature_time_us",
proto_metrics.oemcrypto_generate_signature_time_us());
group_builder->AddDistributions(
"oemcrypto_generic_decrypt_time_us",
proto_metrics.oemcrypto_generic_decrypt_time_us());
group_builder->AddDistributions(
"oemcrypto_generic_encrypt_time_us",
proto_metrics.oemcrypto_generic_encrypt_time_us());
group_builder->AddDistributions(
"oemcrypto_generic_sign_time_us",
proto_metrics.oemcrypto_generic_sign_time_us());
group_builder->AddDistributions(
"oemcrypto_generic_verify_time_us",
proto_metrics.oemcrypto_generic_verify_time_us());
group_builder->AddCounters(
"oemcrypto_get_device_id",
proto_metrics.oemcrypto_get_device_id());
group_builder->AddDistributions(
"oemcrypto_get_key_data_time_us",
proto_metrics.oemcrypto_get_key_data_time_us());
group_builder->AddCounters(
"oemcrypto_get_oem_public_certificate",
proto_metrics.oemcrypto_get_oem_public_certificate());
group_builder->AddCounters(
"oemcrypto_get_random",
proto_metrics.oemcrypto_get_random());
group_builder->AddDistributions(
"oemcrypto_initialize_time_us",
proto_metrics.oemcrypto_initialize_time_us());
if (proto_metrics.has_oemcrypto_is_anti_rollback_hw_present()) {
group_builder->AddValue(
"oemcrypto_is_anti_rollback_hw_present",
proto_metrics.oemcrypto_is_anti_rollback_hw_present());
}
if (proto_metrics.has_oemcrypto_is_keybox_valid()) {
group_builder->AddValue("oemcrypto_is_keybox_valid",
proto_metrics.oemcrypto_is_keybox_valid());
}
group_builder->AddDistributions(
"oemcrypto_load_device_drm_key_time_us",
proto_metrics.oemcrypto_load_device_drm_key_time_us());
group_builder->AddDistributions(
"oemcrypto_load_entitled_keys_time_us",
proto_metrics.oemcrypto_load_entitled_keys_time_us());
group_builder->AddDistributions(
"oemcrypto_load_keys_time_us",
proto_metrics.oemcrypto_load_keys_time_us());
if (proto_metrics.has_oemcrypto_max_hdcp_capability()) {
group_builder->AddValue("oemcrypto_max_hdcp_capability",
proto_metrics.oemcrypto_max_hdcp_capability());
}
if (proto_metrics.has_oemcrypto_max_number_of_sessions()) {
group_builder->AddValue("oemcrypto_max_number_of_sessions",
proto_metrics.oemcrypto_max_number_of_sessions());
}
if (proto_metrics.has_oemcrypto_number_of_open_sessions()) {
group_builder->AddValue("oemcrypto_number_of_open_sessions",
proto_metrics.oemcrypto_number_of_open_sessions());
}
if (proto_metrics.has_oemcrypto_provisioning_method()) {
group_builder->AddValue("oemcrypto_provisioning_method",
proto_metrics.oemcrypto_provisioning_method());
}
group_builder->AddDistributions(
"oemcrypto_refresh_keys_time_us",
proto_metrics.oemcrypto_refresh_keys_time_us());
group_builder->AddCounters(
"oemcrypto_report_usage",
proto_metrics.oemcrypto_report_usage());
group_builder->AddDistributions(
"oemcrypto_rewrap_device_rsa_key_time_us",
proto_metrics.oemcrypto_rewrap_device_rsa_key_time_us());
group_builder->AddDistributions(
"oemcrypto_rewrap_device_rsa_key_30_time_us",
proto_metrics.oemcrypto_rewrap_device_rsa_key_30_time_us());
if (proto_metrics.has_oemcrypto_security_patch_level()) {
group_builder->AddValue("oemcrypto_security_patch_level",
proto_metrics.oemcrypto_security_patch_level());
}
group_builder->AddDistributions(
"oemcrypto_select_key_time_us",
proto_metrics.oemcrypto_select_key_time_us());
if (proto_metrics.has_oemcrypto_usage_table_support()) {
group_builder->AddValue("oemcrypto_usage_table_support",
proto_metrics.oemcrypto_usage_table_support());
}
group_builder->AddCounters(
"oemcrypto_update_usage_table",
proto_metrics.oemcrypto_update_usage_table());
group_builder->AddCounters(
"oemcrypto_update_usage_entry",
proto_metrics.oemcrypto_update_usage_entry());
}
const android::hardware::hidl_vec<
DrmMetricGroup>
HidlMetricsAdapter::GetHidlGroupVector() {
return group_vector_;
}
void HidlMetricsAdapter::ToHidlMetrics(
const drm_metrics::WvCdmMetrics& proto_metrics,
hidl_vec<DrmMetricGroup>* hidl_metrics) {
// Convert the engine level metrics
HidlMetricsAdapter adapter;
if (proto_metrics.has_engine_metrics()) {
adapter.AddEngineMetrics(proto_metrics.engine_metrics());
}
for (const auto& session_metrics : proto_metrics.session_metrics()) {
adapter.AddSessionMetrics(session_metrics);
}
*hidl_metrics = adapter.GetHidlGroupVector();
}
} // namespace wvcdm

View File

@@ -5,56 +5,7 @@ LOCAL_PATH := $(call my-dir)
# #
include $(CLEAR_VARS) include $(CLEAR_VARS)
WV_UNITTESTS_BUILD_TARGET?=
ifeq ($(WV_UNITTESTS_BUILD_TARGET), hidl)
LOCAL_SRC_FILES := \
hidl/WVDrmPlugin_test.cpp \
LOCAL_C_INCLUDES := \
frameworks/av/include \
frameworks/native/include \
vendor/widevine/libwvdrmengine/cdm/core/include \
vendor/widevine/libwvdrmengine/cdm/include \
vendor/widevine/libwvdrmengine/cdm/metrics/include \
vendor/widevine/libwvdrmengine/cdm/util/include \
vendor/widevine/libwvdrmengine/include_hidl \
vendor/widevine/libwvdrmengine/include \
vendor/widevine/libwvdrmengine/mediadrm/include_hidl \
vendor/widevine/libwvdrmengine/oemcrypto/include \
LOCAL_STATIC_LIBRARIES := \
libcdm \
libcdm_protos \
libcdm_utils \
libjsmn \
libgmock \
libgmock_main \
libgtest \
libwvlevel3 \
libwvdrmdrmplugin_hidl \
libwv_odk \
LOCAL_SHARED_LIBRARIES := \
android.hardware.drm@1.0 \
android.hardware.drm@1.1 \
android.hardware.drm@1.2 \
android.hardware.drm@1.3 \
android.hardware.drm@1.4 \
android.hidl.memory@1.0 \
libbinder_ndk \
libbase \
libcrypto \
libdl \
libhidlbase \
libhidlmemory \
liblog \
libprotobuf-cpp-lite \
libutils \
# build unit tests for Aidl # build unit tests for Aidl
else
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
WVDrmPlugin_hal_test.cpp \ WVDrmPlugin_hal_test.cpp \
@@ -90,8 +41,6 @@ LOCAL_SHARED_LIBRARIES := \
liblog \ liblog \
libprotobuf-cpp-lite \ libprotobuf-cpp-lite \
libutils \ libutils \
# endif $(WV_UNITTESTS_BUILD_TARGET)
endif
LOCAL_HEADER_LIBRARIES := \ LOCAL_HEADER_LIBRARIES := \
libstagefright_headers \ libstagefright_headers \
@@ -119,53 +68,10 @@ endif
include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE)
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Builds hidl hal_metrics_adapter_unittest # Builds hal_metrics_adapter_unittest
# #
include $(CLEAR_VARS) include $(CLEAR_VARS)
WV_UNITTESTS_BUILD_TARGET?=
ifeq ($(WV_UNITTESTS_BUILD_TARGET), hidl)
LOCAL_SRC_FILES := \
hidl/hidl_metrics_adapter_unittest.cpp \
LOCAL_C_INCLUDES := \
vendor/widevine/libwvdrmengine/cdm/core/include \
vendor/widevine/libwvdrmengine/cdm/include \
vendor/widevine/libwvdrmengine/cdm/metrics/include \
vendor/widevine/libwvdrmengine/cdm/util/include \
vendor/widevine/libwvdrmengine/include_hidl \
vendor/widevine/libwvdrmengine/include \
vendor/widevine/libwvdrmengine/mediadrm/include_hidl \
vendor/widevine/libwvdrmengine/oemcrypto/include \
LOCAL_STATIC_LIBRARIES := \
libcdm \
libcdm_protos \
libcdm_utils \
libgtest \
libgtest_main \
libjsmn \
libwvdrmdrmplugin_hidl \
libwvlevel3 \
libwv_odk \
LOCAL_SHARED_LIBRARIES := \
android.hardware.drm@1.0 \
android.hardware.drm@1.1 \
android.hardware.drm@1.2 \
android.hidl.memory@1.0 \
libcrypto \
libhidlbase \
libhidlmemory \
liblog \
libprotobuf-cpp-lite \
LOCAL_C_INCLUDES += \
external/protobuf/src \
# build unit tests for Aidl
else
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
hal_metrics_adapter_unittest.cpp \ hal_metrics_adapter_unittest.cpp \
@@ -199,9 +105,6 @@ LOCAL_SHARED_LIBRARIES := \
LOCAL_C_INCLUDES += \ LOCAL_C_INCLUDES += \
external/protobuf/src \ external/protobuf/src \
# endif $(WV_UNITTESTS_BUILD_TARGET)
endif
LOCAL_MODULE := hal_metrics_adapter_unittest LOCAL_MODULE := hal_metrics_adapter_unittest
LOCAL_LICENSE_KINDS := legacy_by_exception_only LOCAL_LICENSE_KINDS := legacy_by_exception_only
LOCAL_LICENSE_CONDITIONS := by_exception_only LOCAL_LICENSE_CONDITIONS := by_exception_only

View File

@@ -305,7 +305,7 @@ TEST(HalMetricsAdapterTest, AddAllAttrbitues) {
{DrmMetricValue::make<DrmMetricValue::int64Value>(59)}}}, {DrmMetricValue::make<DrmMetricValue::int64Value>(59)}}},
{{"count", {DrmMetricValue::make<DrmMetricValue::int64Value>(13)}}}}; {{"count", {DrmMetricValue::make<DrmMetricValue::int64Value>(13)}}}};
// Confirm that all of the attributes exist in the hidl data. // Confirm that all of the attributes exist in the HAL data.
std::vector<DrmMetricGroup> metrics; std::vector<DrmMetricGroup> metrics;
WvMetricsAdapter::ToWvMetrics(metrics_proto, &metrics); WvMetricsAdapter::ToWvMetrics(metrics_proto, &metrics);
EXPECT_TRUE(HasMetric(expected_counter_metric, metrics[0])) EXPECT_TRUE(HasMetric(expected_counter_metric, metrics[0]))

File diff suppressed because it is too large Load Diff

View File

@@ -1,459 +0,0 @@
//
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This file contains unit tests for the HidlMetricsAdapter.
#include "hidl_metrics_adapter.h"
#include <android/hardware/drm/1.1/types.h>
#include <sstream>
#include <utils/Log.h>
#include "gtest/gtest.h"
#include "wv_metrics.pb.h"
using android::hardware::hidl_vec;
using android::hardware::drm::V1_1::DrmMetricGroup;
using drm_metrics::CounterMetric;
using drm_metrics::DistributionMetric;
namespace {
template<typename T>
std::string ToString(const T& attribute_or_value) {
std::ostringstream os;
switch (attribute_or_value.type) {
case DrmMetricGroup::ValueType::DOUBLE_TYPE:
os << "DOUBLE_TYPE. value: " << attribute_or_value.doubleValue;
break;
case DrmMetricGroup::ValueType::INT64_TYPE:
os << "INT64_TYPE. value: " << attribute_or_value.int64Value;
break;
case DrmMetricGroup::ValueType::STRING_TYPE:
os << "STRING_TYPE. value: " << attribute_or_value.stringValue;
break;
default:
os << "UNKNOWN TYPE!!: " << (int64_t) attribute_or_value.type;
break;
}
os << " (" << attribute_or_value.int64Value << ","
<< attribute_or_value.doubleValue << ",\""
<< attribute_or_value.stringValue << "\")";
return os.str();
}
std::string ToString(const DrmMetricGroup::Metric& metric) {
std::ostringstream os;
os << "metric: " << metric.name << std::endl;
os << " attributes:" << std::endl;
for (unsigned a = 0; a < metric.attributes.size(); a++) {
os << " " << metric.attributes[a].name << ". "
<< ToString(metric.attributes[a]) << std::endl;
}
os << " values:" << std::endl;
for (unsigned v = 0; v < metric.values.size(); v++) {
os << " " << metric.values[v].componentName << ". "
<< ToString(metric.values[v]) << std::endl;
}
return os.str();
}
std::string ToString(const hidl_vec<DrmMetricGroup>& metrics_vector) {
std::ostringstream os;
os << "hidl metrics..." << std::endl;
os << "group count: " << metrics_vector.size() << std::endl;
for (unsigned g = 0; g < metrics_vector.size(); g++) {
os << "group " << g << ". metric count: "
<< metrics_vector[g].metrics.size() << std::endl;
for (unsigned m = 0; m < metrics_vector[g].metrics.size(); m++) {
const DrmMetricGroup::Metric metric = metrics_vector[g].metrics[m];
os << ToString(metric);
}
}
return os.str();
}
bool HasMetric(const DrmMetricGroup::Metric& expected,
const DrmMetricGroup& actual_metrics) {
DrmMetricGroup::Metric metric;
auto it = std::find(actual_metrics.metrics.begin(),
actual_metrics.metrics.end(), expected);
if (it == actual_metrics.metrics.end()) {
ALOGE("COULDN'T FIND THE METRIC! %s", ToString(expected).c_str());
for (auto it = actual_metrics.metrics.begin();
it < actual_metrics.metrics.end(); it++) {
if (expected.name == it->name) {
ALOGE("Names match.");
}
if (expected.attributes == it->attributes) {
ALOGE("attributes match.");
}
if (expected.values == it->values) {
ALOGE("values match.");
} else {
ALOGE("values length match? %zu, %zu",
expected.values.size(), it->values.size());
if (expected.values.size() == it->values.size()) {
for (unsigned int i = 0; i < expected.values.size(); i++) {
ALOGE("value %u match? %d", i, expected.values[i] == it->values[i]);
if (expected.values[i] != it->values[i]) {
ALOGE("value component mismatch. %u. %s, %s",
i, expected.values[i].componentName.c_str(),
it->values[i].componentName.c_str());
}
}
}
}
}
} else {
ALOGE("Found metric: %s", ToString(*it).c_str());
}
return it != actual_metrics.metrics.end();
}
} // anonymous namespace
namespace wvcdm {
TEST(HidlMetricsAdapterTest, EmptyMetrics) {
drm_metrics::WvCdmMetrics metrics_proto;
hidl_vec<DrmMetricGroup> hidl_metrics;
HidlMetricsAdapter::ToHidlMetrics(metrics_proto, &hidl_metrics);
ASSERT_EQ(0U, hidl_metrics.size()) << ToString(hidl_metrics);
}
// Adds a metric from each type - Value, counter and distribution.
TEST(HidlMetricsAdapterTest, AllMetricTypes) {
drm_metrics::WvCdmMetrics metrics_proto;
// Value metric - error.
metrics_proto
.mutable_engine_metrics()
->mutable_crypto_metrics()
->mutable_crypto_session_security_level()
->set_error_code(7);
DrmMetricGroup::Metric expected_value_metric_1 = {
"crypto_session_security_level",
{},
{ { "error_code", DrmMetricGroup::ValueType::INT64_TYPE, 7, 0, "" } }
};
// Value metric - integer.
metrics_proto
.mutable_engine_metrics()
->mutable_oemcrypto_initialization_mode()
->set_int_value(11);
DrmMetricGroup::Metric expected_value_metric_2 = {
"oemcrypto_initialization_mode",
{},
{ { "value", DrmMetricGroup::ValueType::INT64_TYPE, 11, 0, "" } }
};
// Value metric - double.
metrics_proto
.mutable_engine_metrics()
->mutable_cdm_engine_life_span_ms()
->set_double_value(3.14159);
DrmMetricGroup::Metric expected_value_metric_3 = {
"cdm_engine_life_span_ms",
{},
{ { "value", DrmMetricGroup::ValueType::DOUBLE_TYPE, 0, 3.14159, "" } }
};
// Value metric - string.
metrics_proto
.mutable_engine_metrics()
->mutable_cdm_engine_cdm_version()
->set_string_value("test");
DrmMetricGroup::Metric expected_value_metric_4 = {
"cdm_engine_cdm_version",
{},
{ { "value", DrmMetricGroup::ValueType::STRING_TYPE, 0, 0, "test" } }
};
// Counter metric
CounterMetric* counter = metrics_proto.mutable_engine_metrics()
->mutable_crypto_metrics()->add_crypto_session_get_token();
counter->set_count(13);
counter->mutable_attributes()->set_error_code(17);
DrmMetricGroup::Metric expected_counter_metric_1 = {
"crypto_session_get_token",
{ { "error_code", DrmMetricGroup::ValueType::INT64_TYPE, 17, 0, "" } },
{ { "count", DrmMetricGroup::ValueType::INT64_TYPE, 13, 0, "" } }
};
// Add a second counter.
counter = metrics_proto.mutable_engine_metrics()
->mutable_crypto_metrics()->add_crypto_session_get_token();
counter->set_count(19);
counter->mutable_attributes()->set_error_code(23);
DrmMetricGroup::Metric expected_counter_metric_2 = {
"crypto_session_get_token",
{ { "error_code", DrmMetricGroup::ValueType::INT64_TYPE, 23, 0, "" } },
{ { "count", DrmMetricGroup::ValueType::INT64_TYPE, 19, 0, "" } }
};
// Distribution metric
DistributionMetric* distribution = metrics_proto.mutable_engine_metrics()
->mutable_crypto_metrics()->add_crypto_session_open_time_us();
distribution->set_min(1.0);
distribution->set_max(1.2);
distribution->set_mean(1.1);
distribution->set_variance(.01);
distribution->set_operation_count(2);
distribution->mutable_attributes()->set_error_code(0);
DrmMetricGroup::Metric expected_distribution_metric_1 = {
"crypto_session_open_time_us",
{ { "error_code", DrmMetricGroup::ValueType::INT64_TYPE, 0, 0, "" } },
{ { "mean", DrmMetricGroup::ValueType::DOUBLE_TYPE, 0, 1.1f, "" },
{ "count", DrmMetricGroup::ValueType::INT64_TYPE, 2, 0, "" },
{ "min", DrmMetricGroup::ValueType::DOUBLE_TYPE, 0, 1.0, "" },
{ "max", DrmMetricGroup::ValueType::DOUBLE_TYPE, 0, 1.2f, "" },
{ "variance", DrmMetricGroup::ValueType::DOUBLE_TYPE, 0, 0.01, "" } }
};
// Add a second distribution
distribution = metrics_proto.mutable_engine_metrics()
->mutable_crypto_metrics()->add_crypto_session_open_time_us();
distribution->set_mean(0.7);
distribution->set_operation_count(1);
distribution->mutable_attributes()->set_error_code(27);
DrmMetricGroup::Metric expected_distribution_metric_2 = {
"crypto_session_open_time_us",
{ { "error_code", DrmMetricGroup::ValueType::INT64_TYPE, 27, 0, "" } },
{ { "mean", DrmMetricGroup::ValueType::DOUBLE_TYPE, 0, 0.7f, "" },
{ "count", DrmMetricGroup::ValueType::INT64_TYPE, 1, 0, "" } }
};
hidl_vec<DrmMetricGroup> hidl_metrics;
HidlMetricsAdapter::ToHidlMetrics(metrics_proto, &hidl_metrics);
ASSERT_EQ(1U, hidl_metrics.size());
ASSERT_EQ(8U, hidl_metrics[0].metrics.size()) << ToString(hidl_metrics);
EXPECT_TRUE(HasMetric(expected_value_metric_1, hidl_metrics[0]))
<< "Missing value_metric_1. " << ToString(expected_value_metric_1)
<< std::endl << "In metrics: " << ToString(hidl_metrics);
EXPECT_TRUE(HasMetric(expected_value_metric_2, hidl_metrics[0]))
<< "Missing value_metric_2. " << ToString(expected_value_metric_2)
<< std::endl << "In metrics: " << ToString(hidl_metrics);
EXPECT_TRUE(HasMetric(expected_value_metric_3, hidl_metrics[0]))
<< "Missing value_metric_3." << ToString(expected_value_metric_3)
<< std::endl << "In metrics: " << ToString(hidl_metrics);
EXPECT_TRUE(HasMetric(expected_value_metric_4, hidl_metrics[0]))
<< "Missing value_metric_4. " << ToString(expected_value_metric_4)
<< std::endl << "In metrics: " << ToString(hidl_metrics);
EXPECT_TRUE(HasMetric(expected_counter_metric_1, hidl_metrics[0]))
<< "Missing counter_metric_1. " << ToString(expected_counter_metric_1)
<< std::endl << "In metrics: " << ToString(hidl_metrics);
EXPECT_TRUE(HasMetric(expected_counter_metric_2, hidl_metrics[0]))
<< "Missing counter_metric_2. " << ToString(expected_counter_metric_2)
<< std::endl << "In metrics: " << ToString(hidl_metrics);
EXPECT_TRUE(HasMetric(expected_distribution_metric_1, hidl_metrics[0]))
<< "Missing distribution_metric_1. "
<< ToString(expected_distribution_metric_1) << std::endl
<< "In metrics: " << ToString(hidl_metrics);
EXPECT_TRUE(HasMetric(expected_distribution_metric_2, hidl_metrics[0]))
<< "Missing distribution_metric_2. "
<< ToString(expected_distribution_metric_2) << std::endl
<< "In metrics: " << ToString(hidl_metrics);
}
// Add a single metric with all attributes to confirm that all attributes
// can be converted.
TEST(HidlMetricsAdapterTest, AddAllAttrbitues) {
// Create a test attribute proto with all attributes set.
drm_metrics::WvCdmMetrics metrics_proto;
CounterMetric* counter = metrics_proto.mutable_engine_metrics()
->mutable_crypto_metrics()->add_crypto_session_get_token();
counter->set_count(13);
drm_metrics::Attributes* attributes = counter->mutable_attributes();
attributes->set_error_code(17);
attributes->set_error_code_bool(true);
attributes->set_cdm_security_level(19);
attributes->set_security_level(23);
attributes->set_length(29);
attributes->set_encryption_algorithm(31);
attributes->set_signing_algorithm(37);
attributes->set_oem_crypto_result(41);
attributes->set_key_status_type(43);
attributes->set_event_type(47);
attributes->set_key_request_type(53);
attributes->set_license_type(59);
DrmMetricGroup::Metric expected_counter_metric = {
"crypto_session_get_token",
{ { "error_code", DrmMetricGroup::ValueType::INT64_TYPE, 17, 0, "" },
{ "error_code_bool",
DrmMetricGroup::ValueType::INT64_TYPE, true, 0, "" },
{ "cdm_security_level",
DrmMetricGroup::ValueType::INT64_TYPE, 19, 0, "" },
{ "security_level",
DrmMetricGroup::ValueType::INT64_TYPE, 23, 0, "" },
{ "length", DrmMetricGroup::ValueType::INT64_TYPE, 29, 0, "" },
{ "encryption_algorithm",
DrmMetricGroup::ValueType::INT64_TYPE, 31, 0, "" },
{ "signing_algorithm",
DrmMetricGroup::ValueType::INT64_TYPE, 37, 0, "" },
{ "oem_crypto_result",
DrmMetricGroup::ValueType::INT64_TYPE, 41, 0, "" },
{ "key_status_type",
DrmMetricGroup::ValueType::INT64_TYPE, 43, 0, "" },
{ "event_type", DrmMetricGroup::ValueType::INT64_TYPE, 47, 0, "" },
{ "key_request_type",
DrmMetricGroup::ValueType::INT64_TYPE, 53, 0, "" },
{ "license_type",
DrmMetricGroup::ValueType::INT64_TYPE, 59, 0, "" } },
{ { "count", DrmMetricGroup::ValueType::INT64_TYPE, 13, 0, "" } } };
// Confirm that all of the attributes exist in the hidl data.
hidl_vec<DrmMetricGroup> hidl_metrics;
HidlMetricsAdapter::ToHidlMetrics(metrics_proto, &hidl_metrics);
EXPECT_TRUE(HasMetric(expected_counter_metric, hidl_metrics[0]))
<< "Missing expected_counter_metrc. "
<< ToString(expected_counter_metric) << std::endl
<< "In metrics: " << ToString(hidl_metrics);
}
// Add all session and engine metrics to cofirm that all are converted.
// Only check the counts since other tests confirm that metrics are converted
// properly.
TEST(HidlMetricsAdapterTest, EngineAndSessionAllMetrics) {
// Set all CryptoSession metrics.
drm_metrics::WvCdmMetrics::CryptoMetrics crypto_metrics;
crypto_metrics.mutable_crypto_session_security_level()->set_int_value(1);
crypto_metrics.add_crypto_session_delete_all_usage_reports()->set_count(13);
crypto_metrics.add_crypto_session_delete_multiple_usage_information
()->set_count(13);
crypto_metrics.add_crypto_session_generic_decrypt_time_us()->set_min(1.0f);
crypto_metrics.add_crypto_session_generic_encrypt_time_us()->set_min(1.0f);
crypto_metrics.add_crypto_session_generic_sign_time_us()->set_min(1.0f);
crypto_metrics.add_crypto_session_generic_verify_time_us()->set_min(1.0f);
crypto_metrics.add_crypto_session_get_device_unique_id()->set_count(13);
crypto_metrics.add_crypto_session_get_token()->set_count(13);
crypto_metrics.mutable_crypto_session_life_span()->set_int_value(1);
crypto_metrics.add_crypto_session_load_certificate_private_key_time_us
()->set_min(1.0f);
crypto_metrics.add_crypto_session_open_time_us()->set_min(1.0f);
crypto_metrics.mutable_crypto_session_system_id()->set_int_value(1);
crypto_metrics.add_crypto_session_update_usage_information_time_us
()->set_min(1.0f);
crypto_metrics.mutable_crypto_session_usage_information_support
()->set_int_value(1);
// Usage Table Metrics
crypto_metrics.mutable_usage_table_header_initial_size()->set_int_value(1);
crypto_metrics.add_usage_table_header_add_entry()->set_count(13);
crypto_metrics.add_usage_table_header_delete_entry()->set_count(13);
crypto_metrics.add_usage_table_header_update_entry_time_us()->set_min(1.0f);
crypto_metrics.add_usage_table_header_load_entry()->set_count(13);
// OemCrypto metrics.
crypto_metrics.mutable_oemcrypto_api_version()->set_int_value(1);
crypto_metrics.add_oemcrypto_close_session()->set_count(13);
crypto_metrics.add_oemcrypto_copy_buffer_time_us()->set_min(1.0f);
crypto_metrics.mutable_oemcrypto_current_hdcp_capability()->set_int_value(1);
crypto_metrics.add_oemcrypto_deactivate_usage_entry()->set_count(13);
crypto_metrics.add_oemcrypto_decrypt_cenc_time_us()->set_min(1.0f);
crypto_metrics.add_oemcrypto_delete_usage_entry()->set_count(13);
crypto_metrics.add_oemcrypto_delete_usage_table()->set_count(13);
crypto_metrics.add_oemcrypto_derive_keys_from_session_key_time_us
()->set_min(1.0f);
crypto_metrics.add_oemcrypto_force_delete_usage_entry()->set_count(13);
crypto_metrics.add_oemcrypto_generate_derived_keys_time_us()->set_min(1.0f);
crypto_metrics.add_oemcrypto_generate_nonce()->set_count(13);
crypto_metrics.add_oemcrypto_generate_rsa_signature_time_us()->set_min(1.0f);
crypto_metrics.add_oemcrypto_generate_signature_time_us()->set_min(1.0f);
crypto_metrics.add_oemcrypto_generic_decrypt_time_us()->set_min(1.0f);
crypto_metrics.add_oemcrypto_generic_encrypt_time_us()->set_min(1.0f);
crypto_metrics.add_oemcrypto_generic_sign_time_us()->set_min(1.0f);
crypto_metrics.add_oemcrypto_generic_verify_time_us()->set_min(1.0f);
crypto_metrics.add_oemcrypto_get_device_id()->set_count(13);
crypto_metrics.add_oemcrypto_get_key_data_time_us()->set_min(1.0f);
crypto_metrics.add_oemcrypto_get_oem_public_certificate()->set_count(13);
crypto_metrics.add_oemcrypto_get_random()->set_count(13);
crypto_metrics.add_oemcrypto_initialize_time_us()->set_min(1.0f);
crypto_metrics.mutable_oemcrypto_is_anti_rollback_hw_present
()->set_int_value(1);
crypto_metrics.mutable_oemcrypto_is_keybox_valid()->set_int_value(1);
crypto_metrics.add_oemcrypto_load_device_drm_key_time_us()->set_min(1.0f);
crypto_metrics.add_oemcrypto_load_entitled_keys_time_us()->set_min(1.0f);
crypto_metrics.add_oemcrypto_load_keys_time_us()->set_min(1.0f);
crypto_metrics.mutable_oemcrypto_max_hdcp_capability()->set_int_value(1);
crypto_metrics.mutable_oemcrypto_max_number_of_sessions()->set_int_value(1);
crypto_metrics.mutable_oemcrypto_number_of_open_sessions()->set_int_value(1);
crypto_metrics.mutable_oemcrypto_provisioning_method()->set_int_value(1);
crypto_metrics.add_oemcrypto_refresh_keys_time_us()->set_min(1.0f);
crypto_metrics.add_oemcrypto_report_usage()->set_count(13);
crypto_metrics.add_oemcrypto_rewrap_device_rsa_key_time_us()->set_min(1.0f);
crypto_metrics.add_oemcrypto_rewrap_device_rsa_key_30_time_us()
->set_min(1.0f);
crypto_metrics.mutable_oemcrypto_security_patch_level()->set_int_value(1);
crypto_metrics.add_oemcrypto_select_key_time_us()->set_min(1.0f);
crypto_metrics.mutable_oemcrypto_usage_table_support()->set_int_value(1);
crypto_metrics.add_oemcrypto_update_usage_table()->set_count(13);
crypto_metrics.add_oemcrypto_update_usage_entry()->set_count(13);
drm_metrics::WvCdmMetrics::SessionMetrics session_metrics;
session_metrics.mutable_session_id()->set_string_value("test");
*(session_metrics.mutable_crypto_metrics()) = crypto_metrics;
session_metrics.mutable_cdm_session_life_span_ms()->set_double_value(1.0f);
session_metrics.add_cdm_session_renew_key_time_us()->set_min(1.0f);
session_metrics.add_cdm_session_restore_offline_session()->set_count(13);
session_metrics.add_cdm_session_restore_usage_session()->set_count(13);
session_metrics.add_cdm_session_license_request_latency_ms()->set_min(1.0);
session_metrics.mutable_oemcrypto_build_info()->set_string_value("test");
session_metrics.mutable_license_sdk_version()->set_string_value("test sdk");
session_metrics.mutable_license_service_version()->set_string_value("test service");
drm_metrics::WvCdmMetrics::EngineMetrics engine_metrics;
*(engine_metrics.mutable_crypto_metrics()) = crypto_metrics;
// OEMCrypto Initialize Metrics.
engine_metrics.mutable_level3_oemcrypto_initialization_error()
->set_int_value(1);
engine_metrics.mutable_oemcrypto_initialization_mode()->set_int_value(1);
engine_metrics.mutable_previous_oemcrypto_initialization_failure()
->set_int_value(1);
engine_metrics.mutable_oemcrypto_l1_api_version()->set_int_value(1);
engine_metrics.mutable_oemcrypto_l1_min_api_version()->set_int_value(1);
// CdmEngine Metrics.
engine_metrics.mutable_app_package_name()->set_int_value(1);
engine_metrics.add_cdm_engine_add_key_time_us()->set_min(1.0f);
engine_metrics.mutable_cdm_engine_cdm_version()->set_int_value(1);
engine_metrics.add_cdm_engine_close_session()->set_count(13);
engine_metrics.mutable_cdm_engine_creation_time_millis()->set_int_value(1);
engine_metrics.add_cdm_engine_decrypt_time_us()->set_min(1.0f);
engine_metrics.add_cdm_engine_find_session_for_key()->set_count(13);
engine_metrics.add_cdm_engine_generate_key_request_time_us()->set_min(1.0f);
engine_metrics.add_cdm_engine_get_provisioning_request_time_us()
->set_min(1.0f);
engine_metrics.add_cdm_engine_get_secure_stop_ids()->set_count(13);
engine_metrics.add_cdm_engine_get_usage_info_time_us()->set_min(1.0f);
engine_metrics.add_cdm_engine_handle_provisioning_response_time_us()
->set_min(1.0f);
engine_metrics.mutable_cdm_engine_life_span_ms()->set_int_value(1);
engine_metrics.add_cdm_engine_open_key_set_session()->set_count(13);
engine_metrics.add_cdm_engine_open_session()->set_count(13);
engine_metrics.add_cdm_engine_query_key_status_time_us()->set_min(1.0f);
engine_metrics.add_cdm_engine_release_all_usage_info()->set_count(13);
engine_metrics.add_cdm_engine_release_usage_info()->set_count(13);
engine_metrics.add_cdm_engine_remove_all_usage_info()->set_count(13);
engine_metrics.add_cdm_engine_remove_keys()->set_count(13);
engine_metrics.add_cdm_engine_remove_usage_info()->set_count(13);
engine_metrics.add_cdm_engine_restore_key_time_us()->set_min(1.0f);
engine_metrics.add_cdm_engine_unprovision()->set_count(13);
drm_metrics::WvCdmMetrics metrics_proto;
*(metrics_proto.add_session_metrics()) = session_metrics;
*(metrics_proto.mutable_engine_metrics()) = engine_metrics;
hidl_vec<DrmMetricGroup> hidl_metrics;
HidlMetricsAdapter::ToHidlMetrics(metrics_proto, &hidl_metrics);
ASSERT_EQ(2U, hidl_metrics.size());
EXPECT_EQ(89U, hidl_metrics[0].metrics.size()) << ToString(hidl_metrics);
EXPECT_EQ(70U, hidl_metrics[1].metrics.size()) << ToString(hidl_metrics);
}
} // namespace wvcdm

View File

@@ -0,0 +1,306 @@
// Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This code is semi-auto-generated, do not edit unless you know what you are
// doing. The script oemcrypto/lock-api-for-release will append to this file.
//
// If this file does not build, then you have modified an OEMCrypto API
// function. Instead, you should rename the old function and give the modified
// function a new oecc number.
#include "OEMCryptoCENC.h"
// This initial generation of this file was for v16.4, so older functions will
// not have an accurate version number.
OEMCryptoResult _oecc84(const uint8_t* sandbox_id, size_t sandbox_id_length);
OEMCryptoResult _oecc01(void);
OEMCryptoResult _oecc02(void);
OEMCryptoResult _oecc09(OEMCrypto_SESSION* session);
OEMCryptoResult _oecc10(OEMCrypto_SESSION session);
OEMCryptoResult _oecc95(OEMCrypto_SESSION session,
const OEMCrypto_SharedMemory* mac_key_context,
size_t mac_key_context_length,
const OEMCrypto_SharedMemory* enc_key_context,
size_t enc_key_context_length);
OEMCryptoResult _oecc21(OEMCrypto_SESSION session,
const uint8_t* derivation_key,
size_t derivation_key_length,
const OEMCrypto_SharedMemory* mac_key_context,
size_t mac_key_context_length,
const OEMCrypto_SharedMemory* enc_key_context,
size_t enc_key_context_length);
OEMCryptoResult _oecc14(OEMCrypto_SESSION session, uint32_t* nonce);
OEMCryptoResult _oecc96(OEMCrypto_SESSION session, uint8_t* message,
size_t message_length, size_t* core_message_size,
uint8_t* signature, size_t* signature_length);
OEMCryptoResult _oecc97(OEMCrypto_SESSION session, uint8_t* message,
size_t message_length, size_t* core_message_size,
uint8_t* signature, size_t* signature_length);
OEMCryptoResult _oecc98(OEMCrypto_SESSION session, uint8_t* message,
size_t message_length, size_t* core_message_size,
uint8_t* signature, size_t* signature_length);
OEMCryptoResult _oecc55(const uint8_t* buffer, size_t buffer_length);
OEMCryptoResult _oecc83(
OEMCrypto_SESSION session, const uint8_t* message, size_t message_length,
const uint8_t* signature, size_t signature_length,
OEMCrypto_Substring enc_mac_keys_iv, OEMCrypto_Substring enc_mac_keys,
size_t key_array_length, const OEMCrypto_KeyObject* key_array,
OEMCrypto_Substring pst, OEMCrypto_Substring srm_restriction_data,
OEMCrypto_LicenseType license_type);
OEMCryptoResult _oecc99(OEMCrypto_SESSION session, const uint8_t* message,
size_t message_length, size_t core_message_length,
const uint8_t* signature, size_t signature_length);
OEMCryptoResult _oecc92(
OEMCrypto_SESSION session, const uint8_t* message, size_t message_length,
size_t key_array_length,
const OEMCrypto_EntitledContentKeyObject_V16* key_array);
OEMCryptoResult _oecc91(OEMCrypto_SESSION session, const uint8_t* message,
size_t message_length, const uint8_t* signature,
size_t signature_length, size_t num_keys,
const OEMCrypto_KeyRefreshObject* key_array);
OEMCryptoResult _oecc101(OEMCrypto_SESSION session, const uint8_t* message,
size_t message_length, size_t core_message_length,
const uint8_t* signature, size_t signature_length);
OEMCryptoResult _oecc41(OEMCrypto_SESSION session,
const uint8_t* content_key_id,
size_t content_key_id_length,
uint8_t* key_control_block,
size_t* key_control_block_length);
OEMCryptoResult _oecc81(OEMCrypto_SESSION session,
const uint8_t* content_key_id,
size_t content_key_id_length,
OEMCryptoCipherMode cipher_mode);
OEMCryptoResult _oecc105(
OEMCrypto_SESSION session,
const OEMCrypto_SampleDescription* samples, // an array of samples.
size_t samples_length, // the number of samples.
const OEMCrypto_CENCEncryptPatternDesc* pattern);
OEMCryptoResult _oecc93(OEMCrypto_SESSION session,
const OEMCrypto_SharedMemory* data_addr,
size_t data_addr_length,
const OEMCrypto_DestBufferDesc* out_buffer_descriptor,
uint8_t subsample_flags);
OEMCryptoResult _oecc24(OEMCrypto_SESSION session,
const OEMCrypto_SharedMemory* in_buffer,
size_t in_buffer_length, const uint8_t* iv,
OEMCrypto_Algorithm algorithm,
OEMCrypto_SharedMemory* out_buffer);
OEMCryptoResult _oecc25(OEMCrypto_SESSION session,
const OEMCrypto_SharedMemory* in_buffer,
size_t in_buffer_length, const uint8_t* iv,
OEMCrypto_Algorithm algorithm,
OEMCrypto_SharedMemory* out_buffer);
OEMCryptoResult _oecc26(OEMCrypto_SESSION session,
const OEMCrypto_SharedMemory* buffer,
size_t buffer_length, OEMCrypto_Algorithm algorithm,
OEMCrypto_SharedMemory* signature,
size_t* signature_length);
OEMCryptoResult _oecc27(OEMCrypto_SESSION session,
const OEMCrypto_SharedMemory* buffer,
size_t buffer_length, OEMCrypto_Algorithm algorithm,
const OEMCrypto_SharedMemory* signature,
size_t signature_length);
OEMCryptoResult _oecc08(const uint8_t* keybox_or_cert,
size_t keybox_or_cert_length,
uint8_t* wrapped_keybox_or_cert,
size_t* wrapped_keybox_or_cert_length,
const uint8_t* transport_key,
size_t transport_key_length);
OEMCryptoResult _oecc03(const uint8_t* keybox_or_cert,
size_t keybox_or_cert_length);
OEMCrypto_ProvisioningMethod _oecc49(void);
OEMCryptoResult _oecc05(void);
OEMCryptoResult _oecc07(uint8_t* device_id, size_t* device_id_length);
OEMCryptoResult _oecc04(uint8_t* key_data, size_t* key_data_length);
OEMCryptoResult _oecc78(const uint8_t* buffer, size_t buffer_length);
OEMCryptoResult _oecc103(OEMCrypto_SESSION session);
OEMCryptoResult _oecc104(uint8_t* public_cert, size_t* public_cert_length);
OEMCryptoResult _oecc06(uint8_t* random_data, size_t random_data_length);
uint32_t _oecc22(void);
uint32_t _oecc108(void);
uint8_t _oecc46(void);
OEMCryptoResult _oecc44(OEMCrypto_HDCP_Capability* current,
OEMCrypto_HDCP_Capability* maximum);
bool _oecc29(void);
size_t _oecc94(void);
bool _oecc39(void);
OEMCryptoResult _oecc38(size_t* count);
OEMCryptoResult _oecc37(size_t* max);
uint32_t _oecc52(void);
bool _oecc53(void);
OEMCryptoResult _oecc54(uint16_t* version);
uint32_t _oecc71(void);
uint32_t _oecc85(void);
OEMCryptoResult _oecc102(OEMCrypto_SESSION session, const uint8_t* message,
size_t message_length, size_t core_message_length,
const uint8_t* signature, size_t signature_length,
uint8_t* wrapped_private_key,
size_t* wrapped_private_key_length);
OEMCryptoResult _oecc107(OEMCrypto_SESSION session,
OEMCrypto_PrivateKeyType key_type,
const uint8_t* wrapped_private_key,
size_t wrapped_private_key_length);
OEMCryptoResult _oecc45(void);
OEMCryptoResult _oecc36(OEMCrypto_SESSION session, const uint8_t* message,
size_t message_length, uint8_t* signature,
size_t* signature_length,
RSA_Padding_Scheme padding_scheme);
OEMCryptoResult _oecc61(uint8_t* header_buffer, size_t* header_buffer_length);
OEMCryptoResult _oecc62(const uint8_t* buffer, size_t buffer_length);
OEMCryptoResult _oecc63(OEMCrypto_SESSION session,
uint32_t* usage_entry_number);
OEMCryptoResult _oecc64(OEMCrypto_SESSION session, uint32_t usage_entry_number,
const uint8_t* buffer, size_t buffer_length);
OEMCryptoResult _oecc65(OEMCrypto_SESSION session,
OEMCrypto_SharedMemory* header_buffer,
size_t* header_buffer_length,
OEMCrypto_SharedMemory* entry_buffer,
size_t* entry_buffer_length);
OEMCryptoResult _oecc66(OEMCrypto_SESSION session, const uint8_t* pst,
size_t pst_length);
OEMCryptoResult _oecc32(OEMCrypto_SESSION session, const uint8_t* pst,
size_t pst_length, uint8_t* buffer,
size_t* buffer_length);
OEMCryptoResult _oecc68(OEMCrypto_SESSION session, uint32_t new_index);
OEMCryptoResult _oecc67(uint32_t new_entry_count, uint8_t* header_buffer,
size_t* header_buffer_length);
OEMCryptoResult _oecc57(void);
uint32_t _oecc86(void);
OEMCryptoResult _oecc88(OEMCrypto_SESSION session, uint32_t frame_number,
const uint8_t* hash, size_t hash_length);
OEMCryptoResult _oecc89(OEMCrypto_SESSION session,
uint32_t* failed_frame_number);
OEMCryptoResult _oecc109(OEMCrypto_SESSION session, size_t buffer_size,
OEMCrypto_DestBufferDesc* output_descriptor,
int* secure_fd);
OEMCryptoResult _oecc110(OEMCrypto_SESSION session,
OEMCrypto_DestBufferDesc* output_descriptor,
int secure_fd);
OEMCryptoResult _oecc115(uint32_t* ree_major, uint32_t* ree_minor,
uint32_t* tee_major, uint32_t* tee_minor);
OEMCryptoResult _oecc113(OEMCrypto_SESSION session, uint8_t* buffer,
size_t* buffer_length, uint32_t use_test_key);
OEMCryptoResult _oecc114(OEMCrypto_SESSION session, const uint8_t* buffer,
size_t buffer_length, uint32_t use_test_key);
OEMCryptoResult _oecc13(OEMCrypto_SESSION session, const uint8_t* message,
size_t message_length, uint8_t* signature,
size_t* signature_length);
OEMCryptoResult _oecc51(OEMCrypto_SESSION session,
const uint32_t* unaligned_nonce,
const uint8_t* encrypted_message_key,
size_t encrypted_message_key_length,
const uint8_t* enc_rsa_key, size_t enc_rsa_key_length,
const uint8_t* enc_rsa_key_iv, uint8_t* wrapped_rsa_key,
size_t* wrapped_rsa_key_length);
OEMCryptoResult _oecc18(OEMCrypto_SESSION session, const uint8_t* message,
size_t message_length, const uint8_t* signature,
size_t signature_length,
const uint32_t* unaligned_nonce,
const uint8_t* enc_rsa_key, size_t enc_rsa_key_length,
const uint8_t* enc_rsa_key_iv, uint8_t* wrapped_rsa_key,
size_t* wrapped_rsa_key_length);
OEMCryptoResult _oecc30(void);
OEMCryptoResult _oecc33(OEMCrypto_SESSION session, const uint8_t* pst,
size_t pst_length, const uint8_t* message,
size_t message_length, const uint8_t* signature,
size_t signature_length);
OEMCryptoResult _oecc43(const uint8_t* pst, size_t pst_length);
OEMCryptoResult _oecc69(OEMCrypto_SESSION session, const uint8_t* pst,
size_t pst_length);
OEMCryptoResult _oecc34(void);
OEMCryptoResult _oecc70(uint64_t time_since_license_received,
uint64_t time_since_first_decrypt,
uint64_t time_since_last_decrypt,
OEMCrypto_Usage_Entry_Status status,
uint8_t* server_mac_key, uint8_t* client_mac_key,
const uint8_t* pst, size_t pst_length);
OEMCryptoResult _oecc12(OEMCrypto_SESSION session,
const uint8_t* mac_key_context,
uint32_t mac_key_context_length,
const uint8_t* enc_key_context,
uint32_t enc_key_context_length);
OEMCryptoResult _oecc48(OEMCrypto_SESSION session, const uint8_t* data_addr,
size_t data_addr_length, bool is_encrypted,
const uint8_t* iv,
size_t block_offset, // used for CTR "cenc" mode only.
OEMCrypto_DestBufferDesc* out_buffer,
const OEMCrypto_CENCEncryptPatternDesc_V15* pattern,
uint8_t subsample_flags);
OEMCryptoResult _oecc50(OEMCrypto_SESSION session, uint8_t* public_cert,
size_t* public_cert_length);
OEMCryptoResult _oecc19(OEMCrypto_SESSION session,
const uint8_t* wrapped_rsa_key,
size_t wrapped_rsa_key_length);
// OEMCrypto_Idle defined in v17.1
OEMCryptoResult _oecc123(OEMCrypto_IdleState state, uint32_t os_specific_code);
// OEMCrypto_Wake defined in v17.1
OEMCryptoResult _oecc124(void);
// OEMCrypto_CreateEntitledKeySession defined in v17.1
OEMCryptoResult _oecc111(OEMCrypto_SESSION oec_session,
OEMCrypto_SESSION* key_session);
// OEMCrypto_RemoveEntitledKeySession defined in v17.1
OEMCryptoResult _oecc112(OEMCrypto_SESSION key_session);
// OEMCrypto_LoadEntitledContentKeys defined in v17.1
OEMCryptoResult _oecc121(OEMCrypto_SESSION session, const uint8_t* message,
size_t message_length, size_t key_array_length,
const OEMCrypto_EntitledContentKeyObject* key_array);
// OEMCrypto_BuildInformation defined in v17.1
OEMCryptoResult _oecc125(char* buffer, size_t* buffer_length);
// OEMCrypto_SecurityLevel defined in v17.1
OEMCrypto_Security_Level _oecc126(void);
// OEMCrypto_GetDTCP2Capability defined in v17.1
OEMCryptoResult _oecc128(OEMCrypto_DTCP2_Capability* capability);
// OEMCrypto_ProductionReady defined in v17.1
OEMCryptoResult _oecc122(void);
// OEMCrypto_GetWatermarkingSupport defined in v17.1
OEMCrypto_WatermarkingSupport _oecc129(void);
// OEMCrypto_ReuseUsageEntry defined in v17.1
OEMCryptoResult _oecc127(OEMCrypto_SESSION session,
uint32_t usage_entry_number);
// OEMCrypto_GetBootCertificateChain defined in v17.1
OEMCryptoResult _oecc116(uint8_t* bcc, size_t* bcc_length,
uint8_t* additional_signature,
size_t* additional_signature_length);
// OEMCrypto_GenerateCertificateKeyPair defined in v17.1
OEMCryptoResult _oecc117(OEMCrypto_SESSION session, uint8_t* public_key,
size_t* public_key_length,
uint8_t* public_key_signature,
size_t* public_key_signature_length,
uint8_t* wrapped_private_key,
size_t* wrapped_private_key_length,
OEMCrypto_PrivateKeyType* key_type);
// OEMCrypto_InstallOemPrivateKey defined in v17.1
OEMCryptoResult _oecc118(OEMCrypto_SESSION session,
OEMCrypto_PrivateKeyType key_type,
const uint8_t* wrapped_private_key,
size_t wrapped_private_key_length);
// OEMCrypto_ReassociateEntitledKeySession defined in v17.1
OEMCryptoResult _oecc119(OEMCrypto_SESSION key_session,
OEMCrypto_SESSION oec_session);
// OEMCrypto_LoadCasECMKeys defined in v17.1
OEMCryptoResult _oecc120(OEMCrypto_SESSION session, const uint8_t* message,
size_t message_length,
const OEMCrypto_EntitledContentKeyObject* even_key,
const OEMCrypto_EntitledContentKeyObject* odd_key);
// OEMCrypto_GetOEMKeyToken defined in v17.2
OEMCryptoResult _oecc130(OEMCrypto_SESSION key_session, uint8_t* key_token,
size_t* key_token_length);

View File

@@ -1,14 +1,5 @@
LOCAL_PATH:= $(call my-dir) LOCAL_PATH:= $(call my-dir)
WV_UNITTESTS_BUILD_TARGET?=
ifeq ($(WV_UNITTESTS_BUILD_TARGET), hidl)
HIDL_EXTENSION := _hidl
LIB_BINDER := libhidlbase
else
HIDL_EXTENSION :=
LIB_BINDER := libbinder_ndk
endif
ifeq ($(filter mips mips64, $(TARGET_ARCH)),) ifeq ($(filter mips mips64, $(TARGET_ARCH)),)
# Tests need to be compatible with devices that do not support gnu hash-style # Tests need to be compatible with devices that do not support gnu hash-style
LOCAL_LDFLAGS+=-Wl,--hash-style=both LOCAL_LDFLAGS+=-Wl,--hash-style=both
@@ -18,6 +9,7 @@ endif
LOCAL_CFLAGS += -DTEST_OEMCRYPTO_V15 LOCAL_CFLAGS += -DTEST_OEMCRYPTO_V15
LOCAL_SRC_FILES:= \ LOCAL_SRC_FILES:= \
GEN_api_lock_file.c \
oec_device_features.cpp \ oec_device_features.cpp \
oec_decrypt_fallback_chain.cpp \ oec_decrypt_fallback_chain.cpp \
oec_key_deriver.cpp \ oec_key_deriver.cpp \
@@ -50,7 +42,7 @@ LOCAL_STATIC_LIBRARIES := \
libgtest_main \ libgtest_main \
libwvlevel3 \ libwvlevel3 \
libcdm_protos \ libcdm_protos \
libcdm_utils$(HIDL_EXTENSION) \ libcdm_utils \
libwv_kdo \ libwv_kdo \
libwv_odk \ libwv_odk \
@@ -58,7 +50,7 @@ LOCAL_SHARED_LIBRARIES := \
libbase \ libbase \
libcrypto \ libcrypto \
libdl \ libdl \
$(LIB_BINDER) \ libbinder_ndk \
liblog \ liblog \
libmedia_omx \ libmedia_omx \
libprotobuf-cpp-lite \ libprotobuf-cpp-lite \

View File

@@ -128,9 +128,3 @@ adb_shell_run timer_unittest
adb_shell_run usage_table_header_unittest adb_shell_run usage_table_header_unittest
adb_shell_run value_metric_unittest adb_shell_run value_metric_unittest
adb_shell_run wv_cdm_metrics_test adb_shell_run wv_cdm_metrics_test
# Run the Treble test on Treble devices
if adb $SERIAL_NUM shell ls /vendor/lib/libwvhidl.so &> /dev/null ||
adb $SERIAL_NUM shell ls /vendor/lib64/libwvhidl.so &> /dev/null; then
adb_shell_run libwvdrmengine_hal_test
fi

View File

@@ -1,33 +0,0 @@
//
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
#include "HidlWVCreatePluginFactories.h"
#include "HidlWVDrmFactory.h"
#include "WVCryptoFactory.h"
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_4 {
namespace widevine {
extern "C" {
::drm::V1_4::IDrmFactory* createDrmFactory() {
return new WVDrmFactory();
}
::drm::V1_4::ICryptoFactory* createCryptoFactory() {
return new WVCryptoFactory();
}
} // extern "C"
} // namespace widevine
} // namespace V1_4
} // namespace drm
} // namespace hardware
} // namespace wvdrm

View File

@@ -1,60 +0,0 @@
//
// Copyright 2018 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 <hwbinder/IPCThreadState.h>
#include <utils/Log.h>
#include "WVCryptoFactory.h"
#include "HidlTypes.h"
#include "WVCDMSingleton.h"
#include "WVCryptoPlugin.h"
#include "WVUUID.h"
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_4 {
namespace widevine {
using wvdrm::hardware::drm::V1_4::widevine::WVCryptoPlugin;
Return<bool> WVCryptoFactory::isCryptoSchemeSupported(
const hidl_array<uint8_t, 16>& uuid) {
return isWidevineUUID(uuid.data());
}
Return<void> WVCryptoFactory::createPlugin(
const hidl_array<uint8_t, 16>& uuid,
const hidl_vec<uint8_t>& initData,
createPlugin_cb _hidl_cb) {
const auto& self = android::hardware::IPCThreadState::self();
const char* sid = self->getCallingSid();
sid = sid ? (strstr(sid, "mediadrmserver") ? sid : "app") : "nullptr";
ALOGI("[%s] calling %s", sid, __PRETTY_FUNCTION__);
sp<ICryptoPlugin> plugin;
if (!isCryptoSchemeSupported(uuid.data())) {
ALOGE("Widevine Drm HAL: failed to create crypto plugin, " \
"invalid crypto scheme");
_hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, plugin);
return Void();
}
plugin = new WVCryptoPlugin(initData.data(), initData.size(), getCDM());
android::hardware::setRequestingSid(plugin, true);
_hidl_cb(Status::OK, plugin);
return Void();
}
} // namespace widevine
} // namespace V1_4
} // namespace drm
} // namespace hardware
} // namespace wvdrm

View File

@@ -1,277 +0,0 @@
//
// Copyright 2018 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 "HidlWVDrmFactory.h"
#include <hwbinder/IPCThreadState.h>
#include <utils/Log.h>
#include "HidlTypes.h"
#include "WVCDMSingleton.h"
#include "WVDrmPlugin.h"
#include "WVUUID.h"
#include "android-base/properties.h"
#include "cutils/properties.h"
#include "wv_cdm_constants.h"
#include "wv_content_decryption_module.h"
#include "wv_metrics.h"
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_4 {
namespace widevine {
using wvdrm::hardware::drm::V1_4::widevine::WVDrmPlugin;
WVGenericCryptoInterface WVDrmFactory::sOemCryptoInterface;
Return<bool> WVDrmFactory::isCryptoSchemeSupported(
const hidl_array<uint8_t, 16>& uuid) {
return isWidevineUUID(uuid.data());
}
Return<bool> WVDrmFactory::isCryptoSchemeSupported_1_2(
const hidl_array<uint8_t, 16>& uuid, const hidl_string& initDataType,
SecurityLevel level) {
if (!isWidevineUUID(uuid.data()) || !isContentTypeSupported(initDataType)) {
return false;
}
if (wvcdm::WvContentDecryptionModule::IsSecurityLevelSupported(
wvcdm::kSecurityLevelL1)) {
if (wvcdm::WvContentDecryptionModule::IsAudio(initDataType)) {
if (level < SecurityLevel::HW_SECURE_ALL) {
return true;
}
} else {
return true;
}
}
return level <= SecurityLevel::SW_SECURE_DECODE;
}
Return<bool> WVDrmFactory::isContentTypeSupported(
const hidl_string& initDataType) {
return wvcdm::WvContentDecryptionModule::IsSupported(initDataType.c_str());
}
Return<void> WVDrmFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid,
const hidl_string& appPackageName,
createPlugin_cb _hidl_cb) {
const auto& self = android::hardware::IPCThreadState::self();
const char* sid = self->getCallingSid();
sid = sid ? (strstr(sid, "mediadrmserver") ? sid : "app") : "nullptr";
ALOGI("[%s][%s] calling %s", sid, appPackageName.c_str(),
__PRETTY_FUNCTION__);
sp<IDrmPlugin> plugin;
if (!isCryptoSchemeSupported(uuid.data())) {
ALOGE(
"Widevine Drm HAL: failed to create drm plugin, "
"invalid crypto scheme");
_hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, plugin);
return Void();
}
if (!isBlankAppPackageNameAllowed() && appPackageName.empty()) {
ALOGE(
"Widevine Drm HAL: Failed to create DRM Plugin, blank App Package "
"Name disallowed.");
_hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, plugin);
return Void();
}
plugin = new WVDrmPlugin(getCDM(), appPackageName.c_str(),
&sOemCryptoInterface, areSpoidsEnabled());
android::hardware::setRequestingSid(plugin, true);
_hidl_cb(Status::OK, plugin);
return Void();
}
bool WVDrmFactory::areSpoidsEnabled() {
return firstApiLevel() >= 26; // Android O
}
bool WVDrmFactory::isBlankAppPackageNameAllowed() {
return firstApiLevel() < 29; // Android Q
}
int32_t WVDrmFactory::firstApiLevel() {
// Check what this device's first API level was.
int32_t firstApiLevel =
android::base::GetIntProperty<int32_t>("ro.product.first_api_level", 0);
if (firstApiLevel == 0) {
// First API Level is 0 on factory ROMs, but we can assume the current SDK
// version is the first if it's a factory ROM.
firstApiLevel =
android::base::GetIntProperty<int32_t>("ro.build.version.sdk", 0);
}
return firstApiLevel;
}
Return<void> WVDrmFactory::getSupportedCryptoSchemes(
getSupportedCryptoSchemes_cb _hidl_cb) {
std::vector<hidl_array<uint8_t, 16>> schemes;
for (const auto& scheme : wvdrm::getSupportedCryptoSchemes()) {
schemes.push_back(scheme);
}
_hidl_cb(schemes);
return Void();
}
std::string WVDrmFactory::stringToHex(const std::string& input) {
// If input contains punctuations that are not part of
// a valid server url, we need to convert it to hex.
const std::string validChars = "/-._~%:";
bool toHex = false;
for (const char ch : input) {
if (ispunct(ch) != 0 && validChars.find(ch) == std::string::npos) {
toHex = true;
break;
}
}
if (!toHex) return input;
static constexpr char hex[] = "0123456789ABCDEF";
std::string output;
output.reserve(input.length() * 2);
for (const unsigned char ch : input) {
output.push_back(hex[ch >> 4]);
output.push_back(hex[ch & 15]);
}
return output;
}
void WVDrmFactory::printCdmMetrics(FILE* out) {
fprintf(out, "\n**** Widevine Cdm Metrics ****\n");
// Verify that the version of the library that we linked against is
// compatible with the version of the headers we compiled against.
GOOGLE_PROTOBUF_VERIFY_VERSION;
sp<wvcdm::WvContentDecryptionModule> cdm(getCDM());
std::vector<drm_metrics::WvCdmMetrics> metrics;
bool full_list_returned = true;
wvcdm::CdmResponseType result =
cdm->GetMetrics(&metrics, &full_list_returned);
if (metrics.empty()) {
fprintf(out,
"Metrics not available, please retry while streaming a video\n");
} else if (!full_list_returned) {
fprintf(out,
"Not all metrics are returned due to some GetMetric error, "
"please check logcat for possible GetMetric errors.\n");
}
if (result == wvcdm::NO_ERROR) {
for (auto& metric : metrics) {
fprintf(out, "*** Metric size=%zu\n", metric.DebugString().size());
std::string formatted;
wv_metrics::FormatWvCdmMetrics(metric, formatted);
fprintf(out, "%s\n", formatted.c_str());
}
} else {
fprintf(out, "GetMetrics failed, error=%d\n", result);
}
}
void WVDrmFactory::printCdmProperties(FILE* out) {
fprintf(out, "\n**** Widevine CDM properties ****\n");
sp<wvcdm::WvContentDecryptionModule> cdm(getCDM());
const bool isLevel1 =
cdm->IsSecurityLevelSupported(wvcdm::CdmSecurityLevel::kSecurityLevelL1);
fprintf(out, "default security level: [%s]\n", isLevel1 ? "L1" : "L3");
const std::map<std::string, std::string> cdmProperties = {
{"version- Widevine CDM:", wvcdm::QUERY_KEY_WVCDM_VERSION},
{"version- current SRM:", wvcdm::QUERY_KEY_CURRENT_SRM_VERSION},
{"version(major)- OEM Crypto API:",
wvcdm::QUERY_KEY_OEMCRYPTO_API_VERSION},
{"version(minor)- OEM Crypto API:",
wvcdm::QUERY_KEY_OEMCRYPTO_API_MINOR_VERSION},
{"id- device:", wvcdm::QUERY_KEY_DEVICE_ID},
{"id- system:", wvcdm::QUERY_KEY_SYSTEM_ID},
{"renewal server url:", wvcdm::QUERY_KEY_RENEWAL_SERVER_URL},
{"hdcp level- max:", wvcdm::QUERY_KEY_MAX_HDCP_LEVEL},
{"hdcp level- current:", wvcdm::QUERY_KEY_CURRENT_HDCP_LEVEL},
{"num sessions- max supported:", wvcdm::QUERY_KEY_MAX_NUMBER_OF_SESSIONS},
{"num sessions- opened:", wvcdm::QUERY_KEY_NUMBER_OF_OPEN_SESSIONS},
{"resource rating tier:", wvcdm::QUERY_KEY_RESOURCE_RATING_TIER},
{"support decrypt hash:", wvcdm::QUERY_KEY_DECRYPT_HASH_SUPPORT},
{"support SRM update:", wvcdm::QUERY_KEY_SRM_UPDATE_SUPPORT},
{"support usage table:", wvcdm::QUERY_KEY_USAGE_SUPPORT},
{"max usage table entries:", wvcdm::QUERY_KEY_MAX_USAGE_TABLE_ENTRIES},
{"OEM Crypto build info:", wvcdm::QUERY_KEY_OEMCRYPTO_BUILD_INFORMATION},
{"provisioning id:", wvcdm::QUERY_KEY_PROVISIONING_ID},
{"provisioning model:", wvcdm::QUERY_KEY_PROVISIONING_MODEL},
{"analog capabilities:", wvcdm::QUERY_KEY_ANALOG_OUTPUT_CAPABILITIES},
{"can disable analog output:",
wvcdm::QUERY_KEY_CAN_DISABLE_ANALOG_OUTPUT},
{"watermarking support:", wvcdm::QUERY_KEY_WATERMARKING_SUPPORT},
{"production ready:", wvcdm::QUERY_KEY_PRODUCTION_READY},
};
std::string value;
for (const auto& property : cdmProperties) {
cdm->QueryStatus(wvcdm::RequestedSecurityLevel::kLevelDefault,
property.second, &value);
std::string outString = stringToHex(value);
fprintf(out, "%s [%s]\n", property.first.c_str(), outString.c_str());
value.clear();
}
}
Return<void> WVDrmFactory::debug(const hidl_handle& fd,
const hidl_vec<hidl_string>& args) {
if (fd.getNativeHandle() == nullptr || fd->numFds < 1) {
ALOGE("%s: missing fd for writing", __FUNCTION__);
return Void();
}
FILE* out = fdopen(dup(fd->data[0]), "w");
fprintf(out, "\nDefault to print all info if no arguments are used.\n");
fprintf(out, "Optional arguments are:\n");
fprintf(out, "\tm:cdm metrics | p:cdm properties\n");
fprintf(out,
"Usage: adb shell lshal debug "
"android.hardware.drm@1.3::IDrmFactory/widevine [m|p]\n");
bool dumpCdmProperties, dumpCdmMetrics = false;
if (args.size() == 0) {
// default to print all info if no arguments are given
dumpCdmProperties = dumpCdmMetrics = true;
} else {
for (auto& str : args) {
fprintf(out, "args: %s\n", str.c_str());
std::string option = str.c_str();
if (option.find('m') != std::string::npos ||
option.find('M') != std::string::npos) {
dumpCdmMetrics = true;
}
if (option.find('p') != std::string::npos ||
option.find('P') != std::string::npos) {
dumpCdmProperties = true;
}
}
}
if (dumpCdmMetrics) printCdmMetrics(out);
if (dumpCdmProperties) printCdmProperties(out);
fclose(out);
return Void();
}
} // namespace widevine
} // namespace V1_4
} // namespace drm
} // namespace hardware
} // namespace wvdrm

View File

@@ -1,26 +0,0 @@
on property:init.svc.mediadrm=running
mkdir /data/vendor/mediadrm 0770 media mediadrm
start vendor.move_data_sh
service vendor.move_data_sh /system/bin/move_widevine_data.sh
class late_start
user media
group media mediadrm system
disabled
oneshot
service vendor.drm-widevine-hal-1-2 /vendor/bin/hw/android.hardware.drm@1.2-service-lazy.widevine
interface android.hardware.drm@1.0::ICryptoFactory widevine
interface android.hardware.drm@1.0::IDrmFactory widevine
interface android.hardware.drm@1.1::ICryptoFactory widevine
interface android.hardware.drm@1.1::IDrmFactory widevine
interface android.hardware.drm@1.2::ICryptoFactory widevine
interface android.hardware.drm@1.2::IDrmFactory widevine
interface android.hidl.base@1.0::IBase widevine
oneshot
disabled
class hal
user media
group media mediadrm drmrpc system
ioprio rt 4
task_profiles ProcessCapacityHigh

View File

@@ -1,25 +0,0 @@
on property:init.svc.mediadrm=running
mkdir /data/vendor/mediadrm 0770 media mediadrm
start vendor.move_data_sh
service vendor.move_data_sh /system/bin/move_widevine_data.sh
class late_start
user media
group media mediadrm system
disabled
oneshot
service vendor.drm-widevine-hal-1-2 /vendor/bin/hw/android.hardware.drm@1.2-service.widevine
interface android.hardware.drm@1.0::ICryptoFactory widevine
interface android.hardware.drm@1.0::IDrmFactory widevine
interface android.hardware.drm@1.1::ICryptoFactory widevine
interface android.hardware.drm@1.1::IDrmFactory widevine
interface android.hardware.drm@1.2::ICryptoFactory widevine
interface android.hardware.drm@1.2::IDrmFactory widevine
interface android.hidl.base@1.0::IBase widevine
disabled
class hal
user media
group media mediadrm drmrpc system
ioprio rt 4
task_profiles ProcessCapacityHigh

View File

@@ -1,29 +0,0 @@
on property:init.svc.mediadrm=running
mkdir /data/vendor/mediadrm 0770 media mediadrm
start vendor.move_data_sh
service vendor.move_data_sh /system/bin/move_widevine_data.sh
class late_start
user media
group media mediadrm system
disabled
oneshot
service vendor.drm-widevine-hal-1-3 /vendor/bin/hw/android.hardware.drm@1.3-service-lazy.widevine
interface android.hardware.drm@1.0::ICryptoFactory widevine
interface android.hardware.drm@1.0::IDrmFactory widevine
interface android.hardware.drm@1.1::ICryptoFactory widevine
interface android.hardware.drm@1.1::IDrmFactory widevine
interface android.hardware.drm@1.2::ICryptoFactory widevine
interface android.hardware.drm@1.2::IDrmFactory widevine
interface android.hardware.drm@1.3::ICryptoFactory widevine
interface android.hardware.drm@1.3::IDrmFactory widevine
interface android.hidl.base@1.0::IBase widevine
oneshot
disabled
class hal
user media
group media mediadrm drmrpc system
ioprio rt 4
task_profiles ProcessCapacityHigh
capabilities SYS_NICE

View File

@@ -1,27 +0,0 @@
on property:init.svc.mediadrm=running
mkdir /data/vendor/mediadrm 0770 media mediadrm
start vendor.move_data_sh
service vendor.move_data_sh /system/bin/move_widevine_data.sh
class late_start
user media
group media mediadrm system
disabled
oneshot
service vendor.drm-widevine-hal-1-3 /vendor/bin/hw/android.hardware.drm@1.3-service.widevine
interface android.hardware.drm@1.0::ICryptoFactory widevine
interface android.hardware.drm@1.0::IDrmFactory widevine
interface android.hardware.drm@1.1::ICryptoFactory widevine
interface android.hardware.drm@1.1::IDrmFactory widevine
interface android.hardware.drm@1.2::ICryptoFactory widevine
interface android.hardware.drm@1.2::IDrmFactory widevine
interface android.hardware.drm@1.3::ICryptoFactory widevine
interface android.hardware.drm@1.3::IDrmFactory widevine
interface android.hidl.base@1.0::IBase widevine
class hal
user media
group media mediadrm drmrpc system
ioprio rt 4
task_profiles ProcessCapacityHigh
capabilities SYS_NICE

View File

@@ -1,30 +0,0 @@
on property:init.svc.mediadrm=running
mkdir /data/vendor/mediadrm 0770 media mediadrm
start vendor.move_data_sh
service vendor.move_data_sh /system/bin/move_widevine_data.sh
class late_start
user media
group media mediadrm system
disabled
oneshot
service vendor.drm-widevine-hal-1-4 /vendor/bin/hw/android.hardware.drm@1.4-service-lazy.widevine
interface android.hardware.drm@1.0::ICryptoFactory widevine
interface android.hardware.drm@1.0::IDrmFactory widevine
interface android.hardware.drm@1.1::ICryptoFactory widevine
interface android.hardware.drm@1.1::IDrmFactory widevine
interface android.hardware.drm@1.2::ICryptoFactory widevine
interface android.hardware.drm@1.2::IDrmFactory widevine
interface android.hardware.drm@1.3::ICryptoFactory widevine
interface android.hardware.drm@1.3::IDrmFactory widevine
interface android.hardware.drm@1.4::ICryptoFactory widevine
interface android.hardware.drm@1.4::IDrmFactory widevine
interface android.hidl.base@1.0::IBase widevine
oneshot
disabled
class hal
user media
group media mediadrm drmrpc system
ioprio rt 4
task_profiles ProcessCapacityHigh

View File

@@ -1,28 +0,0 @@
on property:init.svc.mediadrm=running
mkdir /data/vendor/mediadrm 0770 media mediadrm
start vendor.move_data_sh
service vendor.move_data_sh /system/bin/move_widevine_data.sh
class late_start
user media
group media mediadrm system
disabled
oneshot
service vendor.drm-widevine-hal-1-4 /vendor/bin/hw/android.hardware.drm@1.4-service.widevine
interface android.hardware.drm@1.0::ICryptoFactory widevine
interface android.hardware.drm@1.0::IDrmFactory widevine
interface android.hardware.drm@1.1::ICryptoFactory widevine
interface android.hardware.drm@1.1::IDrmFactory widevine
interface android.hardware.drm@1.2::ICryptoFactory widevine
interface android.hardware.drm@1.2::IDrmFactory widevine
interface android.hardware.drm@1.3::ICryptoFactory widevine
interface android.hardware.drm@1.3::IDrmFactory widevine
interface android.hardware.drm@1.4::ICryptoFactory widevine
interface android.hardware.drm@1.4::IDrmFactory widevine
interface android.hidl.base@1.0::IBase widevine
class hal
user media
group media mediadrm drmrpc system
ioprio rt 4
task_profiles ProcessCapacityHigh

View File

@@ -1,44 +0,0 @@
/*
* Copyright 2017 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.
*/
#define LOG_TAG "WidevineHidlService"
#include <android-base/logging.h>
#include <binder/ProcessState.h>
#include <hidl/HidlTransportSupport.h>
#include "HidlWVDrmFactory.h"
#include "WVCryptoFactory.h"
using wvdrm::hardware::drm::V1_4::widevine::WVCryptoFactory;
using wvdrm::hardware::drm::V1_4::widevine::WVDrmFactory;
int main(int /* argc */, char** /* argv */) {
sp<IDrmFactory> drmFactory = new WVDrmFactory;
sp<ICryptoFactory> cryptoFactory = new WVCryptoFactory;
configureRpcThreadpool(8, true /* callerWillJoin */);
android::hardware::setRequestingSid(drmFactory, true);
android::hardware::setRequestingSid(cryptoFactory, true);
// Setup hwbinder service
CHECK_EQ(drmFactory->registerAsService("widevine"), android::NO_ERROR)
<< "Failed to register Widevine Factory HAL";
CHECK_EQ(cryptoFactory->registerAsService("widevine"), android::NO_ERROR)
<< "Failed to register Widevine Crypto HAL";
joinRpcThreadpool();
}

View File

@@ -1,108 +0,0 @@
/*
* Copyright 2021 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.
*/
#include "hidl/HidlSupport.h"
#define LOG_TAG "WidevineHidlService"
#include <android-base/logging.h>
#include <android/hardware/drm/1.3/ICryptoFactory.h>
#include <android/hardware/drm/1.3/IDrmFactory.h>
#include <binder/ProcessState.h>
#include <hidl/HidlTransportSupport.h>
#include "HidlWVTypes.h"
namespace drm = ::android::hardware::drm;
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_3 {
namespace widevine {
using ::android::hardware::Return;
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::drm::V1_1::SecurityLevel;
struct WVCryptoFactory : public ::drm::V1_3::ICryptoFactory {
public:
WVCryptoFactory() {}
virtual ~WVCryptoFactory() {}
Return<bool> isCryptoSchemeSupported(const hidl_array<uint8_t, 16>& uuid)
override;
Return<void> createPlugin(
const hidl_array<uint8_t, 16>& uuid,
const hidl_vec<uint8_t>& initData,
createPlugin_cb _hidl_cb) override;
private:
WVDRM_DISALLOW_COPY_AND_ASSIGN(WVCryptoFactory);
};
struct WVDrmFactory : public ::drm::V1_3::IDrmFactory {
WVDrmFactory() {}
virtual ~WVDrmFactory() {}
Return<bool> isCryptoSchemeSupported(
const hidl_array<uint8_t, 16>& uuid) override;
Return<bool> isCryptoSchemeSupported_1_2(const hidl_array<uint8_t, 16>& uuid,
const hidl_string& mimeType,
SecurityLevel level) override;
Return<bool> isContentTypeSupported(const hidl_string& mimeType) override;
Return<void> createPlugin(const hidl_array<uint8_t, 16>& uuid,
const hidl_string& appPackageName,
createPlugin_cb _hidl_cb) override;
Return<void> getSupportedCryptoSchemes(
getSupportedCryptoSchemes_cb _hidl_cb) override;
private:
WVDRM_DISALLOW_COPY_AND_ASSIGN(WVDrmFactory);
};
} // namespace widevine
} // namespace V1_3
} // namespace drm
} // namespace hardware
} // namespace wvdrm
int main(int /* argc */, char** /* argv */) {
using ::android::sp;
using ::wvdrm::hardware::drm::V1_3::widevine::WVCryptoFactory;
using ::wvdrm::hardware::drm::V1_3::widevine::WVDrmFactory;
sp<::drm::V1_3::IDrmFactory> drmFactory = new WVDrmFactory;
sp<::drm::V1_3::ICryptoFactory> cryptoFactory = new WVCryptoFactory;
android::hardware::configureRpcThreadpool(8, true /* callerWillJoin */);
android::hardware::setRequestingSid(drmFactory, true);
android::hardware::setRequestingSid(cryptoFactory, true);
// Setup hwbinder service
CHECK_EQ(drmFactory->registerAsService("widevine"), android::NO_ERROR)
<< "Failed to register Widevine Factory HAL";
CHECK_EQ(cryptoFactory->registerAsService("widevine"), android::NO_ERROR)
<< "Failed to register Widevine Crypto HAL";
android::hardware::joinRpcThreadpool();
}

View File

@@ -1,47 +0,0 @@
/*
* Copyright 2019 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.
*/
#define LOG_TAG "WidevineHidlService"
#include <android-base/logging.h>
#include <binder/ProcessState.h>
#include <hidl/HidlLazyUtils.h>
#include <hidl/HidlTransportSupport.h>
#include "HidlWVDrmFactory.h"
#include "WVCryptoFactory.h"
using wvdrm::hardware::drm::V1_4::widevine::WVCryptoFactory;
using wvdrm::hardware::drm::V1_4::widevine::WVDrmFactory;
using android::hardware::LazyServiceRegistrar;
int main(int /* argc */, char** /* argv */) {
sp<IDrmFactory> drmFactory = new WVDrmFactory;
sp<ICryptoFactory> cryptoFactory = new WVCryptoFactory;
configureRpcThreadpool(8, true /* callerWillJoin */);
android::hardware::setRequestingSid(drmFactory, true);
android::hardware::setRequestingSid(cryptoFactory, true);
// Setup hwbinder service
auto serviceRegistrar = LazyServiceRegistrar::getInstance();
CHECK_EQ(serviceRegistrar.registerService(drmFactory, "widevine"), android::NO_ERROR)
<< "Failed to register Widevine Factory HAL";
CHECK_EQ(serviceRegistrar.registerService(cryptoFactory, "widevine"), android::NO_ERROR)
<< "Failed to register Widevine Crypto HAL";
joinRpcThreadpool();
}

View File

@@ -1,451 +0,0 @@
// Copyright 2020 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// Format widevine protobuf metrics
#include "wv_metrics.h"
#include <fstream>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include "OEMCryptoCENC.h"
#include "wv_cdm_types.h"
using namespace drm_metrics;
using std::string;
using std::to_string;
namespace {
const string kIndentPerLine = " ";
string FormatCdmErrorTranslation(int error_code) {
std::stringstream os;
os << static_cast<wvcdm::CdmResponseType>(error_code);
return " " + os.str();
}
string FormatOEMCryptoResult(int oemcrypto_result) {
std::stringstream os;
os << static_cast<OEMCryptoResult>(oemcrypto_result);
return " " + os.str();
}
string FormatOEMCryptoInitializeMode(const ValueMetric& vm) {
std::map<int, string> translations = {
{0, "USING_IN_APP"},
{1, "FORCING_L3"},
{2, "USING_L3_NO_L1_LIBRARY_PATH"},
{3, "USING_L3_L1_OPEN_FAILED"},
{4, "USING_L3_L1_LOAD_FAILED"},
{5, "USING_L3_COULD_NOT_INITIALIZE_L1"},
{6, "USING_L3_WRONG_L1_VERSION"},
{7, "USING_L1_WITH_KEYBOX"},
{8, "USING_L1_WITH_CERTIFICATE"},
{9, "USING_L1_CERTIFICATE_MIX"},
{10, "USING_L3_BAD_KEYBOX"},
{11, "USING_L3_COULD_NOT_OPEN_FACTORY_KEYBOX"},
{12, "USING_L3_COULD_NOT_INSTALL_KEYBOX"},
{13, "USING_L1_INSTALLED_KEYBOX"},
{14, "USING_L3_INVALID_L1"},
{15, "USING_L1_WITH_PROVISIONING_3_0"},
{16, "L3_INITIALIZATION_GENERAL_FAILED"},
{17, "L3_INITIALIZATION_RNG_FAILED"},
{18, "L3_INITIALIZATION_SAVE_DEVICE_KEYS_FAILED"},
{19, "L3_INITIALIZATION_READ_DEVICE_KEYS_FAILED"},
{20, "L3_INITIALIZATION_VERIFY_DEVIE_KEYS_FAILED"}};
return translations[vm.int_value()];
}
string FormatOEMCryptoHdcpCapability(const ValueMetric& vm) {
std::map<int, string> translations = {
{0, "HDCP_NONE"}, {1, "HDCP_V1"}, {2, "HDCP_V2"},
{3, "HDCP_V2_1"}, {4, "HDCP_V2_2"}, {5, "HDCP_V2_3"},
{0xff, "NO_DIGITAL_OUTPUT"}};
return translations[vm.int_value()];
}
string FormatOEMCryptoProvisioningMethod(const ValueMetric& vm) {
std::map<int, string> translations = {{0, "PROVISIONING_ERROR"},
{1, "DRM_CERTIFICATE"},
{2, "KEYBOX"},
{3, "OEM_CERTIFICATE"}};
return translations[vm.int_value()];
}
string FormatAttributes(const Attributes& attributes) {
string result;
if (attributes.has_error_code()) {
result.append("error_code:");
result.append(to_string(attributes.error_code()));
result.append(FormatCdmErrorTranslation(attributes.error_code()));
}
if (attributes.has_error_code_bool()) {
if (result.size()) result.append(",");
result.append("success:");
result.append(attributes.error_code_bool() ? "true" : "false");
}
if (attributes.has_cdm_security_level()) {
if (result.size()) result.append(",");
result.append("cdm_security_level:");
result.append(to_string(attributes.cdm_security_level()));
}
if (attributes.has_security_level()) {
if (result.size()) result.append(",");
result.append("security_level:");
result.append(to_string(attributes.security_level()));
}
if (attributes.has_length()) {
if (result.size()) result.append(",");
result.append("length:");
result.append(to_string(attributes.length()));
}
if (attributes.has_encryption_algorithm()) {
if (result.size()) result.append(",");
result.append("encryption_algorithm:");
result.append(to_string(attributes.encryption_algorithm()));
}
if (attributes.has_signing_algorithm()) {
if (result.size()) result.append(",");
result.append("signing_algorithm:");
result.append(to_string(attributes.signing_algorithm()));
}
if (attributes.has_oem_crypto_result()) {
if (result.size()) result.append(",");
result.append("oemcrypto_result:");
result.append(to_string(attributes.oem_crypto_result()));
result.append(FormatOEMCryptoResult(attributes.oem_crypto_result()));
}
if (attributes.has_key_status_type()) {
if (result.size()) result.append(",");
result.append("key_status_type:");
result.append(to_string(attributes.key_status_type()));
}
if (attributes.has_event_type()) {
if (result.size()) result.append(",");
result.append("event_type:");
result.append(to_string(attributes.event_type()));
}
if (attributes.has_key_request_type()) {
if (result.size()) result.append(",");
result.append("key_request_type:");
result.append(to_string(attributes.key_request_type()));
}
if (attributes.has_license_type()) {
if (result.size()) result.append(",");
result.append("license_type:");
result.append(to_string(attributes.license_type()));
}
if (result.size()) {
return string(" {") + result + "}";
} else {
return "";
}
}
string FormatCounterMetric(const CounterMetric& cm) {
string result;
if (cm.has_count()) {
result = string("count=") + to_string(cm.count());
if (cm.has_attributes()) {
result.append(FormatAttributes(cm.attributes()));
}
}
return result;
}
string FormatDistributionMetric(const DistributionMetric& dm) {
string result;
if (dm.has_min()) {
std::ostringstream buffer;
buffer << dm.min();
result = string("min=") + buffer.str();
}
if (dm.has_max()) {
std::ostringstream buffer;
buffer << dm.max();
if (result.size()) result.append(" ");
result += string("max=") + buffer.str();
}
if (dm.has_mean()) {
std::ostringstream buffer;
buffer << dm.mean();
if (result.size()) result.append(" ");
result += string("mean=") + buffer.str();
}
if (dm.has_variance()) {
std::ostringstream buffer;
buffer << dm.variance();
if (result.size()) result.append(" ");
result += string("variance=") + buffer.str();
}
if (dm.has_operation_count()) {
if (result.size()) result.append(" ");
result += string("count=") + to_string(dm.operation_count());
}
if (dm.has_attributes()) {
result.append(FormatAttributes(dm.attributes()));
}
return result;
}
string FormatValueMetric(const ValueMetric& vm) {
string result;
if (vm.has_error_code()) {
result.append("error(" + to_string(vm.error_code()));
result.append(FormatCdmErrorTranslation(vm.error_code()));
result.append(")");
}
if (vm.has_int_value()) {
result.append(to_string(vm.int_value()));
}
if (vm.has_double_value()) {
std::ostringstream buffer;
buffer << vm.double_value();
result.append(buffer.str());
}
if (vm.has_string_value()) {
result.append("\"");
result.append(vm.string_value());
result.append("\"");
}
return result;
}
#define FORMAT_REPEATED_DISTRIBUTION(NAME, INDENT) \
if (metrics.NAME##_size() == 1) { \
result.append(INDENT + #NAME + ": "); \
result.append(FormatDistributionMetric(metrics.NAME(0)) + "\n"); \
} else { \
for (int i = 0; i < metrics.NAME##_size(); i++) { \
result.append(INDENT + #NAME "[" + to_string(i) + "]: "); \
result.append(FormatDistributionMetric(metrics.NAME(i)) + "\n"); \
} \
}
#define FORMAT_REPEATED_COUNTER(NAME, INDENT) \
if (metrics.NAME##_size() == 1) { \
result.append(INDENT + #NAME ": "); \
result.append(FormatCounterMetric(metrics.NAME(0)) + "\n"); \
} else { \
for (int i = 0; i < metrics.NAME##_size(); i++) { \
result.append(INDENT + #NAME "[" + to_string(i) + "]: "); \
result.append(FormatCounterMetric(metrics.NAME(i)) + "\n"); \
} \
}
#define FORMAT_OPTIONAL_VALUE(NAME, INDENT) \
if (metrics.has_##NAME()) { \
result.append(INDENT + #NAME ": " + FormatValueMetric(metrics.NAME()) + \
"\n"); \
}
#define FORMAT_OPTIONAL_INITIALIZATION_MODE(NAME, INDENT) \
if (metrics.has_##NAME()) { \
result.append(INDENT + #NAME ": "); \
result.append(FormatOEMCryptoInitializeMode(metrics.NAME()) + "\n"); \
}
#define FORMAT_OPTIONAL_HDCP_CAPABILITY(NAME, INDENT) \
if (metrics.has_##NAME()) { \
result.append(INDENT + #NAME ": "); \
result.append(FormatOEMCryptoHdcpCapability(metrics.NAME()) + "\n"); \
}
#define FORMAT_OPTIONAL_PROVISIONING_METHOD(NAME, INDENT) \
if (metrics.has_##NAME()) { \
result.append(INDENT + #NAME ": "); \
result.append(FormatOEMCryptoProvisioningMethod(metrics.NAME()) + "\n"); \
}
#define FORMAT_OPTIONAL_CRYPTO_METRICS(NAME, INDENT) \
if (metrics.has_##NAME()) { \
FormatCryptoMetrics(metrics.NAME(), INDENT + kIndentPerLine, result); \
}
void FormatCryptoMetrics(const WvCdmMetrics_CryptoMetrics metrics,
const string& indent, string& result) {
// Crypto Session Metrics.
FORMAT_OPTIONAL_VALUE(crypto_session_security_level, indent);
FORMAT_REPEATED_COUNTER(crypto_session_delete_all_usage_reports, indent);
FORMAT_REPEATED_COUNTER(crypto_session_delete_multiple_usage_information,
indent);
FORMAT_REPEATED_DISTRIBUTION(crypto_session_generic_decrypt_time_us, indent);
FORMAT_REPEATED_DISTRIBUTION(crypto_session_generic_encrypt_time_us, indent);
FORMAT_REPEATED_DISTRIBUTION(crypto_session_generic_sign_time_us, indent);
FORMAT_REPEATED_DISTRIBUTION(crypto_session_generic_verify_time_us, indent);
FORMAT_REPEATED_COUNTER(crypto_session_get_device_unique_id, indent);
FORMAT_REPEATED_COUNTER(crypto_session_get_token, indent);
FORMAT_OPTIONAL_VALUE(crypto_session_life_span, indent);
FORMAT_REPEATED_DISTRIBUTION(
crypto_session_load_certificate_private_key_time_us, indent);
FORMAT_REPEATED_DISTRIBUTION(crypto_session_open_time_us, indent);
FORMAT_OPTIONAL_VALUE(crypto_session_system_id, indent);
FORMAT_REPEATED_DISTRIBUTION(crypto_session_update_usage_information_time_us,
indent);
FORMAT_OPTIONAL_VALUE(crypto_session_usage_information_support, indent);
// Usage Table Metrics
FORMAT_OPTIONAL_VALUE(usage_table_header_initial_size, indent);
FORMAT_REPEATED_COUNTER(usage_table_header_add_entry, indent);
FORMAT_REPEATED_COUNTER(usage_table_header_delete_entry, indent);
FORMAT_REPEATED_DISTRIBUTION(usage_table_header_update_entry_time_us, indent);
FORMAT_REPEATED_COUNTER(usage_table_header_load_entry, indent);
// Usage Table LRU Metrics
FORMAT_OPTIONAL_VALUE(usage_table_header_lru_usage_info_count, indent);
FORMAT_OPTIONAL_VALUE(usage_table_header_lru_offline_license_count, indent);
FORMAT_OPTIONAL_VALUE(usage_table_header_lru_evicted_entry_staleness_s,
indent);
// |usage_table_header_lru_evicted_entry_type| refers to the enumeration
// CdmUsageEntryStorageType in wv_cdm_types.h.
FORMAT_OPTIONAL_VALUE(usage_table_header_lru_evicted_entry_type, indent);
// OemCrypto metrics.
FORMAT_OPTIONAL_VALUE(oemcrypto_api_version, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_close_session, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_copy_buffer_time_us, indent);
FORMAT_OPTIONAL_HDCP_CAPABILITY(oemcrypto_current_hdcp_capability, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_deactivate_usage_entry, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_decrypt_cenc_time_us, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_delete_usage_entry, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_delete_usage_table, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_derive_keys_from_session_key_time_us,
indent);
FORMAT_REPEATED_COUNTER(oemcrypto_force_delete_usage_entry, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_generate_derived_keys_time_us, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_generate_nonce, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_generate_rsa_signature_time_us,
indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_generate_signature_time_us, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_generic_decrypt_time_us, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_generic_encrypt_time_us, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_generic_sign_time_us, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_generic_verify_time_us, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_get_device_id, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_get_key_data_time_us, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_get_oem_public_certificate, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_get_random, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_initialize_time_us, indent);
FORMAT_OPTIONAL_VALUE(oemcrypto_is_anti_rollback_hw_present, indent);
FORMAT_OPTIONAL_VALUE(oemcrypto_is_keybox_valid, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_load_device_drm_key_time_us, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_load_entitled_keys_time_us, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_load_keys_time_us, indent);
FORMAT_OPTIONAL_HDCP_CAPABILITY(oemcrypto_max_hdcp_capability, indent);
FORMAT_OPTIONAL_VALUE(oemcrypto_max_number_of_sessions, indent);
FORMAT_OPTIONAL_VALUE(oemcrypto_number_of_open_sessions, indent);
FORMAT_OPTIONAL_PROVISIONING_METHOD(oemcrypto_provisioning_method, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_refresh_keys_time_us, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_report_usage, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_rewrap_device_rsa_key_time_us, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_rewrap_device_rsa_key_30_time_us,
indent);
FORMAT_OPTIONAL_VALUE(oemcrypto_security_patch_level, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_select_key_time_us, indent);
FORMAT_OPTIONAL_VALUE(oemcrypto_usage_table_support, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_update_usage_table, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_update_usage_entry, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_create_usage_table_header, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_load_usage_table_header, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_shrink_usage_table_header, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_create_new_usage_entry, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_load_usage_entry, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_move_entry, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_create_old_usage_entry, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_copy_old_usage_entry, indent);
FORMAT_OPTIONAL_VALUE(oemcrypto_set_sandbox, indent);
FORMAT_REPEATED_COUNTER(oemcrypto_set_decrypt_hash, indent);
FORMAT_OPTIONAL_VALUE(oemcrypto_resource_rating_tier, indent);
// Oemcrypto V16 metrics below
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_prep_and_sign_license_request_time_us,
indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_prep_and_sign_renewal_request_time_us,
indent);
FORMAT_REPEATED_DISTRIBUTION(
oemcrypto_prep_and_sign_provisioning_request_time_us, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_load_license_time_us, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_load_renewal_time_us, indent);
FORMAT_REPEATED_DISTRIBUTION(oemcrypto_load_provisioning_time_us, indent);
FORMAT_OPTIONAL_VALUE(oemcrypto_minor_api_version, indent);
FORMAT_OPTIONAL_VALUE(oemcrypto_maximum_usage_table_header_size, indent);
// OEMCrypto V17 metrics below.
FORMAT_OPTIONAL_VALUE(oemcrypto_watermarking_support, indent);
}
void FormatSessionMetrics(const WvCdmMetrics_SessionMetrics& metrics,
const string& indent, string& result) {
FORMAT_OPTIONAL_VALUE(session_id, indent);
FORMAT_OPTIONAL_CRYPTO_METRICS(crypto_metrics, indent);
FORMAT_OPTIONAL_VALUE(cdm_session_life_span_ms, indent);
FORMAT_REPEATED_DISTRIBUTION(cdm_session_renew_key_time_us, indent);
FORMAT_REPEATED_COUNTER(cdm_session_restore_offline_session, indent);
FORMAT_REPEATED_COUNTER(cdm_session_restore_usage_session, indent);
FORMAT_REPEATED_DISTRIBUTION(cdm_session_license_request_latency_ms, indent);
FORMAT_OPTIONAL_VALUE(oemcrypto_build_info, indent);
FORMAT_OPTIONAL_VALUE(license_sdk_version, indent);
FORMAT_OPTIONAL_VALUE(license_service_version, indent);
}
void FormatEngineMetrics(const WvCdmMetrics_EngineMetrics& metrics,
const string& indent, string& result) {
FORMAT_OPTIONAL_CRYPTO_METRICS(crypto_metrics, indent);
// OEMCrypto Initialize Metrics.
FORMAT_OPTIONAL_INITIALIZATION_MODE(oemcrypto_initialization_mode, indent);
FORMAT_OPTIONAL_VALUE(oemcrypto_l1_api_version, indent);
FORMAT_OPTIONAL_VALUE(oemcrypto_l1_min_api_version, indent);
FORMAT_OPTIONAL_VALUE(level3_oemcrypto_initialization_error, indent);
FORMAT_OPTIONAL_VALUE(previous_oemcrypto_initialization_failure, indent);
// CdmEngine Metrics.
FORMAT_OPTIONAL_VALUE(app_package_name, indent);
FORMAT_REPEATED_DISTRIBUTION(cdm_engine_add_key_time_us, indent);
FORMAT_OPTIONAL_VALUE(cdm_engine_cdm_version, indent);
FORMAT_REPEATED_COUNTER(cdm_engine_close_session, indent);
FORMAT_OPTIONAL_VALUE(cdm_engine_creation_time_millis, indent);
FORMAT_REPEATED_DISTRIBUTION(cdm_engine_decrypt_time_us, indent);
FORMAT_REPEATED_COUNTER(cdm_engine_find_session_for_key, indent);
FORMAT_REPEATED_DISTRIBUTION(cdm_engine_generate_key_request_time_us, indent);
FORMAT_REPEATED_DISTRIBUTION(cdm_engine_get_provisioning_request_time_us,
indent);
FORMAT_REPEATED_COUNTER(cdm_engine_get_secure_stop_ids, indent);
FORMAT_REPEATED_DISTRIBUTION(cdm_engine_get_usage_info_time_us, indent);
FORMAT_REPEATED_DISTRIBUTION(cdm_engine_handle_provisioning_response_time_us,
indent);
FORMAT_OPTIONAL_VALUE(cdm_engine_life_span_ms, indent);
FORMAT_REPEATED_COUNTER(cdm_engine_open_key_set_session, indent);
FORMAT_REPEATED_COUNTER(cdm_engine_open_session, indent);
FORMAT_REPEATED_DISTRIBUTION(cdm_engine_query_key_status_time_us, indent);
FORMAT_REPEATED_COUNTER(cdm_engine_release_all_usage_info, indent);
FORMAT_REPEATED_COUNTER(cdm_engine_release_usage_info, indent);
FORMAT_REPEATED_COUNTER(cdm_engine_remove_all_usage_info, indent);
FORMAT_REPEATED_COUNTER(cdm_engine_remove_keys, indent);
FORMAT_REPEATED_COUNTER(cdm_engine_remove_usage_info, indent);
FORMAT_REPEATED_DISTRIBUTION(cdm_engine_restore_key_time_us, indent);
FORMAT_REPEATED_COUNTER(cdm_engine_unprovision, indent);
}
} // anonymous namespace
namespace wv_metrics {
void FormatWvCdmMetrics(const WvCdmMetrics& metrics, string& result) {
string indent = kIndentPerLine;
string next_indent = indent + kIndentPerLine;
result.append("engine_metrics\n");
if (metrics.has_engine_metrics()) {
FormatEngineMetrics(metrics.engine_metrics(), indent, result);
}
result.append("session_metrics\n");
for (int i = 0; i < metrics.session_metrics_size(); i++) {
result.append(indent + "session[" + to_string(i) + "]\n");
FormatSessionMetrics(metrics.session_metrics(i), next_indent, result);
}
}
} // namespace wv_metrics

View File

@@ -5,46 +5,6 @@ LOCAL_PATH:= $(call my-dir)
# #
include $(CLEAR_VARS) include $(CLEAR_VARS)
WV_UNITTESTS_BUILD_TARGET?=
ifeq ($(WV_UNITTESTS_BUILD_TARGET), hidl)
LOCAL_SRC_FILES := \
hidl/WVCreatePluginFactories_test.cpp \
hidl/WVCryptoFactory_test.cpp \
hidl/WVDrmFactory_test.cpp \
LOCAL_C_INCLUDES := \
frameworks/av/include \
frameworks/native/include \
vendor/widevine/libwvdrmengine/include_hidl \
vendor/widevine/libwvdrmengine/include \
vendor/widevine/libwvdrmengine/mediadrm/include_hidl \
vendor/widevine/libwvdrmengine/oemcrypto/include \
LOCAL_STATIC_LIBRARIES := \
libgtest \
libgtest_main \
LOCAL_SHARED_LIBRARIES := \
android.hardware.drm@1.0 \
android.hardware.drm@1.1 \
android.hardware.drm@1.2 \
android.hardware.drm@1.3 \
android.hardware.drm@1.4 \
libbase \
libcrypto \
libdl \
libhidlbase \
libhidlmemory \
liblog \
libutils \
libwvhidl \
LOCAL_HEADER_LIBRARIES := \
libstagefright_foundation_headers \
# build unit tests for Aidl
else
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
WVCreatePluginFactories_hal_test.cpp \ WVCreatePluginFactories_hal_test.cpp \
WVCryptoFactory_hal_test.cpp \ WVCryptoFactory_hal_test.cpp \
@@ -74,9 +34,6 @@ LOCAL_SHARED_LIBRARIES := \
LOCAL_HEADER_LIBRARIES := \ LOCAL_HEADER_LIBRARIES := \
libstagefright_foundation_headers \ libstagefright_foundation_headers \
# endif $(WV_UNITTESTS_BUILD_TARGET)
endif
LOCAL_MODULE := libwvdrmengine_hal_test LOCAL_MODULE := libwvdrmengine_hal_test
LOCAL_LICENSE_KINDS := legacy_by_exception_only LOCAL_LICENSE_KINDS := legacy_by_exception_only

View File

@@ -1,38 +0,0 @@
//
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
#include "gtest/gtest.h"
#include "WVCreatePluginFactories.h"
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_4 {
namespace widevine {
using ::android::sp;
using namespace android;
TEST(CreatePluginFactoriesTest, CreatesDrmFactory) {
sp<IDrmFactory> factory(createDrmFactory());
EXPECT_NE((IDrmFactory*)NULL, factory.get()) <<
"createDrmFactory() returned null";
}
TEST(CreatePluginFactoriesTest, CreatesCryptoFactory) {
sp<ICryptoFactory> factory(createCryptoFactory());
EXPECT_NE((ICryptoFactory*)NULL, factory.get()) <<
"createCryptoFactory() returned null";
}
} // namespace widevine
} // namespace V1_4
} // namespace drm
} // namespace hardware
} // namespace wvdrm

View File

@@ -1,54 +0,0 @@
/*
* Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
* source code may only be used and distributed under the Widevine License
* Agreement.
*/
#include "gtest/gtest.h"
#include "WVCryptoFactory.h"
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_4 {
namespace widevine {
using ::android::sp;
const uint8_t kWidevineUUID[16] = {
0xED,0xEF,0x8B,0xA9,0x79,0xD6,0x4A,0xCE,
0xA3,0xC8,0x27,0xDC,0xD5,0x1D,0x21,0xED
};
const uint8_t kOldNetflixWidevineUUID[16] = {
0x29,0x70,0x1F,0xE4,0x3C,0xC7,0x4A,0x34,
0x8C,0x5B,0xAE,0x90,0xC7,0x43,0x9A,0x47
};
const uint8_t kUnknownUUID[16] = {
0x6A,0x7F,0xAA,0xB0,0x83,0xC7,0x9E,0x20,
0x08,0xBC,0xEF,0x32,0x34,0x1A,0x9A,0x26
};
TEST(WVCryptoFactoryTest, SupportsSupportedCryptoSchemes) {
sp<WVCryptoFactory> factory(new WVCryptoFactory());
EXPECT_TRUE(factory->isCryptoSchemeSupported(kWidevineUUID)) <<
"WVPluginFactory does not support Widevine's UUID";
EXPECT_TRUE(factory->isCryptoSchemeSupported(kOldNetflixWidevineUUID)) <<
"WVPluginFactory does not support the old Netflix Widevine UUID";
}
TEST(WVCryptoFactoryTest, DoesNotSupportUnsupportedCryptoSchemes) {
sp<WVCryptoFactory> factory(new WVCryptoFactory());
EXPECT_FALSE(factory->isCryptoSchemeSupported(kUnknownUUID)) <<
"WVPluginFactory incorrectly claims to support an unknown UUID";
}
} // namespace widevine
} // namespace V1_4
} // namespace drm
} // namespace hardware
} // namespace wvdrm

View File

@@ -1,150 +0,0 @@
/*
* Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
* source code may only be used and distributed under the Widevine License
* Agreement.
*/
#include "android-base/properties.h"
#include "cutils/properties.h"
#include "gtest/gtest.h"
#include "HidlTypes.h"
#include "WVDrmFactory.h"
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_4 {
namespace widevine {
using namespace android;
const uint8_t kWidevineUUID[16] = {
0xED,0xEF,0x8B,0xA9,0x79,0xD6,0x4A,0xCE,
0xA3,0xC8,0x27,0xDC,0xD5,0x1D,0x21,0xED
};
const uint8_t kOldNetflixWidevineUUID[16] = {
0x29,0x70,0x1F,0xE4,0x3C,0xC7,0x4A,0x34,
0x8C,0x5B,0xAE,0x90,0xC7,0x43,0x9A,0x47
};
const uint8_t kUnknownUUID[16] = {
0x6A,0x7F,0xAA,0xB0,0x83,0xC7,0x9E,0x20,
0x08,0xBC,0xEF,0x32,0x34,0x1A,0x9A,0x26
};
class WVDrmFactoryTestPeer : public WVDrmFactory {
public:
using WVDrmFactory::areSpoidsEnabled;
using WVDrmFactory::isBlankAppPackageNameAllowed;
};
TEST(WVDrmFactoryTest, SupportsSupportedCryptoSchemes) {
WVDrmFactory factory;
EXPECT_TRUE(factory.isCryptoSchemeSupported(kWidevineUUID)) <<
"WVPluginFactory does not support Widevine's UUID";
EXPECT_TRUE(factory.isCryptoSchemeSupported(kOldNetflixWidevineUUID)) <<
"WVPluginFactory does not support the old Netflix Widevine UUID";
}
TEST(WVDrmFactoryTest, DoesNotSupportUnsupportedCryptoSchemes) {
WVDrmFactory factory;
EXPECT_FALSE(factory.isCryptoSchemeSupported(kUnknownUUID)) <<
"WVPluginFactory incorrectly claims to support an unknown UUID";
}
TEST(WVDrmFactoryTest, SupportsSupportedContainerFormats) {
WVDrmFactory factory;
EXPECT_TRUE(factory.isContentTypeSupported(hidl_string("video/mp4"))) <<
"WVPluginFactory does not support ISO-BMFF video";
EXPECT_TRUE(factory.isContentTypeSupported(hidl_string("audio/mp4"))) <<
"WVPluginFactory does not support ISO-BMFF audio";
EXPECT_TRUE(factory.isContentTypeSupported(hidl_string("video/webm"))) <<
"WVPluginFactory does not support WebM video";
EXPECT_TRUE(factory.isContentTypeSupported(hidl_string("audio/webm"))) <<
"WVPluginFactory does not support WebM audio";
}
TEST(WVDrmFactoryTest, DoesNotSupportUnsupportedContainerFormats) {
WVDrmFactory factory;
// Taken from Encoding.com's list of the most common internet video MIME-types
EXPECT_FALSE(factory.isContentTypeSupported(hidl_string("video/x-matroska"))) <<
"WVPluginFactory incorrectly claims to support Matroska";
EXPECT_FALSE(factory.isContentTypeSupported(hidl_string("video/x-flv"))) <<
"WVPluginFactory incorrectly claims to support Flash Video";
EXPECT_FALSE(factory.isContentTypeSupported(hidl_string("application/x-mpegURL"))) <<
"WVPluginFactory incorrectly claims to support m3u8 Indexes";
EXPECT_FALSE(factory.isContentTypeSupported(hidl_string("video/MP2T"))) <<
"WVPluginFactory incorrectly claims to support MPEG-2 TS";
EXPECT_FALSE(factory.isContentTypeSupported(hidl_string("video/3gpp"))) <<
"WVPluginFactory incorrectly claims to support 3GP Mobile";
EXPECT_FALSE(factory.isContentTypeSupported(hidl_string("video/quicktime"))) <<
"WVPluginFactory incorrectly claims to support Quicktime";
EXPECT_FALSE(factory.isContentTypeSupported(hidl_string("video/x-msvideo"))) <<
"WVPluginFactory incorrectly claims to support AVI";
EXPECT_FALSE(factory.isContentTypeSupported(hidl_string("video/x-ms-wmv"))) <<
"WVPluginFactory incorrectly claims to support WMV";
}
TEST(WVDrmFactoryTest, SupportsSupportedCryptoSchemeWithLevel) {
WVDrmFactory factory;
EXPECT_TRUE(factory.isCryptoSchemeSupported_1_2(kWidevineUUID, hidl_string("video/mp4"),
android::hardware::drm::V1_1::SecurityLevel::SW_SECURE_CRYPTO)) <<
"WVPluginFactory does not support Widevine's UUID for video/mp4 and SW_SECURE_CRYPTO";
}
TEST(WVDrmFactoryTest, CalculatesSpoidUseCorrectly) {
WVDrmFactoryTestPeer factory;
int32_t firstApiLevel =
android::base::GetIntProperty<int32_t>("ro.product.first_api_level", 0);
if (firstApiLevel == 0) {
// First API Level is 0 on factory ROMs, but we can assume the current SDK
// version is the first if it's a factory ROM.
firstApiLevel =
android::base::GetIntProperty<int32_t>("ro.build.version.sdk", 0);
}
bool shouldUseSpoids = (firstApiLevel >= 26); // Android O
EXPECT_EQ(shouldUseSpoids, factory.areSpoidsEnabled()) <<
"WVDrmFactory calculated a different SPOID state than expected.";
}
TEST(WVDrmFactoryTest, CalculatesBlankAppPackageNamePermissibilityCorrectly) {
WVDrmFactoryTestPeer factory;
int32_t firstApiLevel =
android::base::GetIntProperty<int32_t>("ro.product.first_api_level", 0);
if (firstApiLevel == 0) {
// First API Level is 0 on factory ROMs, but we can assume the current SDK
// version is the first if it's a factory ROM.
firstApiLevel =
android::base::GetIntProperty<int32_t>("ro.build.version.sdk", 0);
}
bool shouldAllow = (firstApiLevel < 29); // Android Q
EXPECT_EQ(shouldAllow, factory.isBlankAppPackageNameAllowed()) <<
"WVDrmFactory calculated a different Blank App Package Name state than expected.";
}
} // namespace widevine
} // namespace V1_4
} // namespace drm
} // namespace hardware
} // namespace wvdrm

View File

@@ -1,38 +0,0 @@
//
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
#include "gtest/gtest.h"
#include "WVCreatePluginFactories.h"
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_4 {
namespace widevine {
using ::android::sp;
using namespace android;
TEST(CreatePluginFactoriesTest, CreatesDrmFactory) {
sp<IDrmFactory> factory(createDrmFactory());
EXPECT_NE((IDrmFactory*)NULL, factory.get()) <<
"createDrmFactory() returned null";
}
TEST(CreatePluginFactoriesTest, CreatesCryptoFactory) {
sp<ICryptoFactory> factory(createCryptoFactory());
EXPECT_NE((ICryptoFactory*)NULL, factory.get()) <<
"createCryptoFactory() returned null";
}
} // namespace widevine
} // namespace V1_4
} // namespace drm
} // namespace hardware
} // namespace wvdrm

View File

@@ -1,54 +0,0 @@
/*
* Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
* source code may only be used and distributed under the Widevine License
* Agreement.
*/
#include "gtest/gtest.h"
#include "WVCryptoFactory.h"
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_4 {
namespace widevine {
using ::android::sp;
const uint8_t kWidevineUUID[16] = {
0xED,0xEF,0x8B,0xA9,0x79,0xD6,0x4A,0xCE,
0xA3,0xC8,0x27,0xDC,0xD5,0x1D,0x21,0xED
};
const uint8_t kOldNetflixWidevineUUID[16] = {
0x29,0x70,0x1F,0xE4,0x3C,0xC7,0x4A,0x34,
0x8C,0x5B,0xAE,0x90,0xC7,0x43,0x9A,0x47
};
const uint8_t kUnknownUUID[16] = {
0x6A,0x7F,0xAA,0xB0,0x83,0xC7,0x9E,0x20,
0x08,0xBC,0xEF,0x32,0x34,0x1A,0x9A,0x26
};
TEST(WVCryptoFactoryTest, SupportsSupportedCryptoSchemes) {
sp<WVCryptoFactory> factory(new WVCryptoFactory());
EXPECT_TRUE(factory->isCryptoSchemeSupported(kWidevineUUID)) <<
"WVPluginFactory does not support Widevine's UUID";
EXPECT_TRUE(factory->isCryptoSchemeSupported(kOldNetflixWidevineUUID)) <<
"WVPluginFactory does not support the old Netflix Widevine UUID";
}
TEST(WVCryptoFactoryTest, DoesNotSupportUnsupportedCryptoSchemes) {
sp<WVCryptoFactory> factory(new WVCryptoFactory());
EXPECT_FALSE(factory->isCryptoSchemeSupported(kUnknownUUID)) <<
"WVPluginFactory incorrectly claims to support an unknown UUID";
}
} // namespace widevine
} // namespace V1_4
} // namespace drm
} // namespace hardware
} // namespace wvdrm

View File

@@ -1,150 +0,0 @@
/*
* Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
* source code may only be used and distributed under the Widevine License
* Agreement.
*/
#include "android-base/properties.h"
#include "cutils/properties.h"
#include "gtest/gtest.h"
#include "HidlTypes.h"
#include "WVDrmFactory.h"
namespace wvdrm {
namespace hardware {
namespace drm {
namespace V1_4 {
namespace widevine {
using namespace android;
const uint8_t kWidevineUUID[16] = {
0xED,0xEF,0x8B,0xA9,0x79,0xD6,0x4A,0xCE,
0xA3,0xC8,0x27,0xDC,0xD5,0x1D,0x21,0xED
};
const uint8_t kOldNetflixWidevineUUID[16] = {
0x29,0x70,0x1F,0xE4,0x3C,0xC7,0x4A,0x34,
0x8C,0x5B,0xAE,0x90,0xC7,0x43,0x9A,0x47
};
const uint8_t kUnknownUUID[16] = {
0x6A,0x7F,0xAA,0xB0,0x83,0xC7,0x9E,0x20,
0x08,0xBC,0xEF,0x32,0x34,0x1A,0x9A,0x26
};
class WVDrmFactoryTestPeer : public WVDrmFactory {
public:
using WVDrmFactory::areSpoidsEnabled;
using WVDrmFactory::isBlankAppPackageNameAllowed;
};
TEST(WVDrmFactoryTest, SupportsSupportedCryptoSchemes) {
WVDrmFactory factory;
EXPECT_TRUE(factory.isCryptoSchemeSupported(kWidevineUUID)) <<
"WVPluginFactory does not support Widevine's UUID";
EXPECT_TRUE(factory.isCryptoSchemeSupported(kOldNetflixWidevineUUID)) <<
"WVPluginFactory does not support the old Netflix Widevine UUID";
}
TEST(WVDrmFactoryTest, DoesNotSupportUnsupportedCryptoSchemes) {
WVDrmFactory factory;
EXPECT_FALSE(factory.isCryptoSchemeSupported(kUnknownUUID)) <<
"WVPluginFactory incorrectly claims to support an unknown UUID";
}
TEST(WVDrmFactoryTest, SupportsSupportedContainerFormats) {
WVDrmFactory factory;
EXPECT_TRUE(factory.isContentTypeSupported(hidl_string("video/mp4"))) <<
"WVPluginFactory does not support ISO-BMFF video";
EXPECT_TRUE(factory.isContentTypeSupported(hidl_string("audio/mp4"))) <<
"WVPluginFactory does not support ISO-BMFF audio";
EXPECT_TRUE(factory.isContentTypeSupported(hidl_string("video/webm"))) <<
"WVPluginFactory does not support WebM video";
EXPECT_TRUE(factory.isContentTypeSupported(hidl_string("audio/webm"))) <<
"WVPluginFactory does not support WebM audio";
}
TEST(WVDrmFactoryTest, DoesNotSupportUnsupportedContainerFormats) {
WVDrmFactory factory;
// Taken from Encoding.com's list of the most common internet video MIME-types
EXPECT_FALSE(factory.isContentTypeSupported(hidl_string("video/x-matroska"))) <<
"WVPluginFactory incorrectly claims to support Matroska";
EXPECT_FALSE(factory.isContentTypeSupported(hidl_string("video/x-flv"))) <<
"WVPluginFactory incorrectly claims to support Flash Video";
EXPECT_FALSE(factory.isContentTypeSupported(hidl_string("application/x-mpegURL"))) <<
"WVPluginFactory incorrectly claims to support m3u8 Indexes";
EXPECT_FALSE(factory.isContentTypeSupported(hidl_string("video/MP2T"))) <<
"WVPluginFactory incorrectly claims to support MPEG-2 TS";
EXPECT_FALSE(factory.isContentTypeSupported(hidl_string("video/3gpp"))) <<
"WVPluginFactory incorrectly claims to support 3GP Mobile";
EXPECT_FALSE(factory.isContentTypeSupported(hidl_string("video/quicktime"))) <<
"WVPluginFactory incorrectly claims to support Quicktime";
EXPECT_FALSE(factory.isContentTypeSupported(hidl_string("video/x-msvideo"))) <<
"WVPluginFactory incorrectly claims to support AVI";
EXPECT_FALSE(factory.isContentTypeSupported(hidl_string("video/x-ms-wmv"))) <<
"WVPluginFactory incorrectly claims to support WMV";
}
TEST(WVDrmFactoryTest, SupportsSupportedCryptoSchemeWithLevel) {
WVDrmFactory factory;
EXPECT_TRUE(factory.isCryptoSchemeSupported_1_2(kWidevineUUID, hidl_string("video/mp4"),
android::hardware::drm::V1_1::SecurityLevel::SW_SECURE_CRYPTO)) <<
"WVPluginFactory does not support Widevine's UUID for video/mp4 and SW_SECURE_CRYPTO";
}
TEST(WVDrmFactoryTest, CalculatesSpoidUseCorrectly) {
WVDrmFactoryTestPeer factory;
int32_t firstApiLevel =
android::base::GetIntProperty<int32_t>("ro.product.first_api_level", 0);
if (firstApiLevel == 0) {
// First API Level is 0 on factory ROMs, but we can assume the current SDK
// version is the first if it's a factory ROM.
firstApiLevel =
android::base::GetIntProperty<int32_t>("ro.build.version.sdk", 0);
}
bool shouldUseSpoids = (firstApiLevel >= 26); // Android O
EXPECT_EQ(shouldUseSpoids, factory.areSpoidsEnabled()) <<
"WVDrmFactory calculated a different SPOID state than expected.";
}
TEST(WVDrmFactoryTest, CalculatesBlankAppPackageNamePermissibilityCorrectly) {
WVDrmFactoryTestPeer factory;
int32_t firstApiLevel =
android::base::GetIntProperty<int32_t>("ro.product.first_api_level", 0);
if (firstApiLevel == 0) {
// First API Level is 0 on factory ROMs, but we can assume the current SDK
// version is the first if it's a factory ROM.
firstApiLevel =
android::base::GetIntProperty<int32_t>("ro.build.version.sdk", 0);
}
bool shouldAllow = (firstApiLevel < 29); // Android Q
EXPECT_EQ(shouldAllow, factory.isBlankAppPackageNameAllowed()) <<
"WVDrmFactory calculated a different Blank App Package Name state than expected.";
}
} // namespace widevine
} // namespace V1_4
} // namespace drm
} // namespace hardware
} // namespace wvdrm

View File

@@ -45,7 +45,7 @@ cc_binary_host {
"vendor/widevine/libwvdrmengine/cdm/core/include", "vendor/widevine/libwvdrmengine/cdm/core/include",
"vendor/widevine/libwvdrmengine/cdm/core/test", "vendor/widevine/libwvdrmengine/cdm/core/test",
"vendor/widevine/libwvdrmengine/cdm/metrics/include", "vendor/widevine/libwvdrmengine/cdm/metrics/include",
"vendor/widevine/libwvdrmengine/include_hidl", "vendor/widevine/libwvdrmengine/include",
"vendor/widevine/libwvdrmengine/oemcrypto/include", "vendor/widevine/libwvdrmengine/oemcrypto/include",
"vendor/widevine/libwvdrmengine/tools/metrics_dump/include", "vendor/widevine/libwvdrmengine/tools/metrics_dump/include",
], ],

View File

@@ -38,7 +38,6 @@ cc_library_shared {
"vendor/widevine/libwvdrmengine/cdm/core/include", "vendor/widevine/libwvdrmengine/cdm/core/include",
"vendor/widevine/libwvdrmengine/cdm/core/test", "vendor/widevine/libwvdrmengine/cdm/core/test",
"vendor/widevine/libwvdrmengine/cdm/util/include", "vendor/widevine/libwvdrmengine/cdm/util/include",
"system/libhidl/base/include",
"system/libbase/include", "system/libbase/include",
"system/libvintf/include", "system/libvintf/include",
], ],