diff --git a/bundle.json b/bundle.json index bc2e8d8c..01820279 100644 --- a/bundle.json +++ b/bundle.json @@ -31,13 +31,11 @@ "c_utils", "hilog", "hidumper", - "access_token", "hicollie", "hdf_core", "eventhandler", "bundle_framework", "drivers_interface_drm", - "media_foundation", "memmgr", "hiappevent", "json" diff --git a/frameworks/native/test/fuzztest/drmservice_fuzzer/BUILD.gn b/frameworks/native/test/fuzztest/drmservice_fuzzer/BUILD.gn index 1422c4a9..415136e8 100644 --- a/frameworks/native/test/fuzztest/drmservice_fuzzer/BUILD.gn +++ b/frameworks/native/test/fuzztest/drmservice_fuzzer/BUILD.gn @@ -76,11 +76,9 @@ ohos_fuzztest("drmserviceFuzzTest") { "hidumper:lib_dump_usage", "hilog:libhilog", "hisysevent:libhisysevent", - "hitrace:hitrace_meter", "hitrace:libhitracechain", "ipc:ipc_core", "ipc:ipc_single", - "media_foundation:media_foundation", "memmgr:memmgrclient", "napi:ace_napi", "safwk:system_ability_fwk", diff --git a/frameworks/native/test/fuzztest/mediakeydecryptndk_fuzzer/BUILD.gn b/frameworks/native/test/fuzztest/mediakeydecryptndk_fuzzer/BUILD.gn index 3259bdb7..08c3a817 100644 --- a/frameworks/native/test/fuzztest/mediakeydecryptndk_fuzzer/BUILD.gn +++ b/frameworks/native/test/fuzztest/mediakeydecryptndk_fuzzer/BUILD.gn @@ -69,7 +69,6 @@ ohos_fuzztest("mediakeydecryptndkFuzzTest") { external_deps = [ "c_utils:utils", "hilog:libhilog", - "hitrace:hitrace_meter", "ipc:ipc_core", ] subsystem_name = "multimedia" diff --git a/frameworks/native/test/fuzztest/mediakeysessionndk_fuzzer/BUILD.gn b/frameworks/native/test/fuzztest/mediakeysessionndk_fuzzer/BUILD.gn index b8fd9682..a0eaab49 100644 --- a/frameworks/native/test/fuzztest/mediakeysessionndk_fuzzer/BUILD.gn +++ b/frameworks/native/test/fuzztest/mediakeysessionndk_fuzzer/BUILD.gn @@ -70,7 +70,6 @@ ohos_fuzztest("mediakeysessionndkFuzzTest") { external_deps = [ "c_utils:utils", "hilog:libhilog", - "hitrace:hitrace_meter", "ipc:ipc_core", ] subsystem_name = "multimedia" diff --git a/frameworks/native/test/fuzztest/mediakeysystemndk_fuzzer/BUILD.gn b/frameworks/native/test/fuzztest/mediakeysystemndk_fuzzer/BUILD.gn index 0e765beb..add87e5c 100644 --- a/frameworks/native/test/fuzztest/mediakeysystemndk_fuzzer/BUILD.gn +++ b/frameworks/native/test/fuzztest/mediakeysystemndk_fuzzer/BUILD.gn @@ -69,7 +69,6 @@ ohos_fuzztest("mediakeysystemndkFuzzTest") { external_deps = [ "c_utils:utils", "hilog:libhilog", - "hitrace:hitrace_meter", "ipc:ipc_core", ] subsystem_name = "multimedia" diff --git a/frameworks/native/test/fuzztest/mediakeysystemndkfactory_fuzzer/BUILD.gn b/frameworks/native/test/fuzztest/mediakeysystemndkfactory_fuzzer/BUILD.gn index 67a25fcc..79d348a0 100644 --- a/frameworks/native/test/fuzztest/mediakeysystemndkfactory_fuzzer/BUILD.gn +++ b/frameworks/native/test/fuzztest/mediakeysystemndkfactory_fuzzer/BUILD.gn @@ -68,7 +68,6 @@ ohos_fuzztest("mediakeysystemndkfactoryFuzzTest") { external_deps = [ "c_utils:utils", "hilog:libhilog", - "hitrace:hitrace_meter", "ipc:ipc_core", ] subsystem_name = "multimedia" diff --git a/frameworks/native/test/unittest/BUILD.gn b/frameworks/native/test/unittest/BUILD.gn index c1e6d107..f5bdb673 100644 --- a/frameworks/native/test/unittest/BUILD.gn +++ b/frameworks/native/test/unittest/BUILD.gn @@ -71,10 +71,8 @@ ohos_unittest("drm_framework_capi_unittest_v1_0") { "hidumper:lib_dump_usage", "hilog:libhilog", "hisysevent:libhisysevent", - "hitrace:hitrace_meter", "hitrace:libhitracechain", "ipc:ipc_core", - "media_foundation:media_foundation", ] subsystem_name = "multimedia" part_name = "drm_framework" diff --git a/frameworks/native/test/unittest/src/drm_framework_dfx_unittest.cpp b/frameworks/native/test/unittest/src/drm_framework_dfx_unittest.cpp index 5d3396cd..a4dd2922 100644 --- a/frameworks/native/test/unittest/src/drm_framework_dfx_unittest.cpp +++ b/frameworks/native/test/unittest/src/drm_framework_dfx_unittest.cpp @@ -22,7 +22,6 @@ #include "native_drm_common.h" #include "native_drm_err.h" #include "gmock/gmock.h" -#include "meta/meta.h" #include "native_drm_base.h" #include "native_drm_object.h" #include "native_mediakeysession.h" @@ -164,30 +163,5 @@ HWTEST_F(DrmFrameworkUnitTest, Drm_unittest_ReportCertificateBehaviorEvent, Test serverResult); } -HWTEST_F(DrmFrameworkUnitTest, Drm_unittest_HiSysWriteStatistic, TestSize.Level0) -{ - int32_t errNo = DRM_ERR_UNKNOWN; - int32_t uid = 324442; - int32_t instanceId = 324442; - errNo = DrmEvent::GetInstance().CreateMediaInfo(uid, instanceId); - EXPECT_EQ(errNo, DRM_ERR_OK); - std::shared_ptr meta = std::make_shared(); - meta->SetData(Media::Tag::DRM_ERROR_MESG, "errMessage"); - errNo = DrmEvent::GetInstance().AppendMediaInfo(meta, instanceId); - EXPECT_EQ(errNo, DRM_ERR_OK); - errNo = DrmEvent::GetInstance().ReportMediaInfo(instanceId); - EXPECT_EQ(errNo, DRM_ERR_OK); -} - -HWTEST_F(DrmFrameworkUnitTest, Drm_unittest_HiSysWriteStatisticAbNormal, TestSize.Level0) -{ - int32_t errNo = DRM_ERR_UNKNOWN; - int32_t uid = 324442; - int32_t instanceId = 324442; - DrmEvent::GetInstance().CreateMediaInfo(uid, instanceId); - std::shared_ptr meta = std::make_shared(); - errNo = DrmEvent::GetInstance().AppendMediaInfo(meta, instanceId); - EXPECT_NE(errNo, DRM_ERR_OK); -} } // DrmStandard } // OHOS diff --git a/interfaces/kits/js/drm_napi/BUILD.gn b/interfaces/kits/js/drm_napi/BUILD.gn index ddde7f41..ca0dff15 100644 --- a/interfaces/kits/js/drm_napi/BUILD.gn +++ b/interfaces/kits/js/drm_napi/BUILD.gn @@ -59,12 +59,10 @@ ohos_shared_library("drm_napi") { external_deps = [ "ability_runtime:abilitykit_native", "ability_runtime:napi_base_context", - "access_token:libtokenid_sdk", "c_utils:utils", "hiappevent:hiappevent_innerapi", "hilog:libhilog", "hisysevent:libhisysevent", - "hitrace:hitrace_meter", "hitrace:libhitracechain", "ipc:ipc_core", "napi:ace_napi", diff --git a/services/drm_service/BUILD.gn b/services/drm_service/BUILD.gn index db77faed..b610f87f 100644 --- a/services/drm_service/BUILD.gn +++ b/services/drm_service/BUILD.gn @@ -51,8 +51,6 @@ ohos_shared_library("drm_service") { "ability_base:want", "ability_runtime:abilitykit_native", "ability_runtime:napi_base_context", - "access_token:libaccesstoken_sdk", - "access_token:libprivacy_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", @@ -69,7 +67,6 @@ ohos_shared_library("drm_service") { "hitrace:libhitracechain", "ipc:ipc_core", "ipc:ipc_single", - "media_foundation:media_foundation", "memmgr:memmgrclient", "napi:ace_napi", "safwk:system_ability_fwk", diff --git a/services/drm_service/server/include/media_decrypt_module_service.h b/services/drm_service/server/include/media_decrypt_module_service.h index 396a7820..7dd43177 100644 --- a/services/drm_service/server/include/media_decrypt_module_service.h +++ b/services/drm_service/server/include/media_decrypt_module_service.h @@ -16,10 +16,11 @@ #define OHOS_DRM_MEDIADECRYPTMODULESERVICE_H #include -#include #include #include "drm_host_manager.h" #include "drm_log.h" +#include "drm_dfx.h" +#include "drm_dfx_utils.h" #include "media_decrypt_module_service_stub.h" #include "v1_0/media_decrypt_module_proxy.h" @@ -27,21 +28,12 @@ namespace OHOS { namespace DrmStandard { using namespace OHOS::HDI::Drm::V1_0; using namespace OHOS::HDI; -struct DecryptStatistics { - uint32_t decryptTimes = 0; - uint64_t decryptSumSize = 0; - uint64_t decryptSumDuration = 0; - uint32_t decryptMaxSize = 0; - uint32_t decryptMaxDuration = 0; - uint64_t errorDecryptTimes = 0; - int32_t errCode = 0; - std::string errMessage = "no error"; - std::priority_queue, std::greater> topThree; -}; class MediaDecryptModuleService : public MediaDecryptModuleServiceStub { public: MediaDecryptModuleService(sptr hdiMediaDecryptModule); + MediaDecryptModuleService(sptr hdiMediaDecryptModule, + StatisticsInfo statisticsInfo); ~MediaDecryptModuleService(); int32_t Release() override; int32_t DecryptMediaData(bool secureDecodrtState, IMediaDecryptModuleService::CryptInfo &cryptInfo, @@ -56,11 +48,12 @@ private: uint32_t bufLen); void UpdateDecryptionStatistics(int32_t decryptionResult, uint32_t bufLen, uint32_t curDuration); const std::string GetTopThreeDecryptionDurations(); - void ReportDecryptionStatisticEvent(); + std::mutex moduleLock_; sptr hdiMediaDecryptModule_; + StatisticsInfo statisticsInfo_; std::mutex statisticsMutex_; - DecryptStatistics decryptStatistics_; + DecryptionStatistics decryptStatistics_; uint64_t instanceId_; }; } // DrmStandard diff --git a/services/drm_service/server/src/key_session_service.cpp b/services/drm_service/server/src/key_session_service.cpp index 5e6b78bf..dc1eacd1 100644 --- a/services/drm_service/server/src/key_session_service.cpp +++ b/services/drm_service/server/src/key_session_service.cpp @@ -105,9 +105,6 @@ int32_t MediaKeySessionService::GenerateMediaKeyRequest( { DrmTrace trace("MediaKeySessionService::GenerateMediaKeyRequest"); DRM_INFO_LOG("MediaKeySessionService::GenerateMediaKeyRequest enter."); - DRM_DEBUG_LOG("pluginName:%{public}s, pluginUuid:%{public}s\nbundleName:%{public}s,\nvendor:%{public}s,\n" - "version:%{public}s,\n", statisticsInfo_.pluginName.c_str(), statisticsInfo_.pluginUuid.c_str(), - statisticsInfo_.bundleName.c_str(), statisticsInfo_.vendorName.c_str(), statisticsInfo_.versionName.c_str()); int32_t ret = DRM_OK; OHOS::HDI::Drm::V1_0::MediaKeyRequestInfo hdiMediaKeyRequestInfo; @@ -148,9 +145,6 @@ int32_t MediaKeySessionService::ProcessMediaKeyResponse(std::vector &li { DrmTrace trace("MediaKeySessionService::ProcessMediaKeyResponse"); DRM_INFO_LOG("MediaKeySessionService::ProcessMediaKeyResponse enter."); - DRM_DEBUG_LOG("pluginName:%{public}s, pluginUuid:%{public}s\nbundleName:%{public}s,\nvendor:%{public}s,\n" - "version:%{public}s,\n", statisticsInfo_.pluginName.c_str(), statisticsInfo_.pluginUuid.c_str(), - statisticsInfo_.bundleName.c_str(), statisticsInfo_.vendorName.c_str(), statisticsInfo_.versionName.c_str()); int32_t ret = DRM_OK; auto timeBefore = std::chrono::system_clock::now(); ret = hdiMediaKeySession_->ProcessMediaKeyResponse(licenseResponse, licenseId); @@ -228,9 +222,6 @@ int32_t MediaKeySessionService::CheckMediaKeyStatus(std::map &licenseId) { DRM_INFO_LOG("MediaKeySessionService::RestoreOfflineMediaKeys enter."); - DRM_DEBUG_LOG("pluginName:%{public}s, pluginUuid:%{public}s\nbundleName:%{public}s,\nvendor:%{public}s,\n" - "version:%{public}s,\n", statisticsInfo_.pluginName.c_str(), statisticsInfo_.pluginUuid.c_str(), - statisticsInfo_.bundleName.c_str(), statisticsInfo_.vendorName.c_str(), statisticsInfo_.versionName.c_str()); int32_t ret = DRM_OK; ret = hdiMediaKeySession_->RestoreOfflineMediaKeys(licenseId); if (ret != DRM_OK) { @@ -293,7 +284,7 @@ int32_t MediaKeySessionService::GetMediaDecryptModule(sptr #include #include +#include #include "ashmem.h" #include "system_ability_definition.h" #include "mem_mgr_client.h" #include "mem_mgr_proxy.h" -#include "drm_dfx.h" #include "drm_trace.h" #include "drm_dfx_utils.h" #include "drm_error_code.h" #include "hitrace/tracechain.h" #include "ipc_skeleton.h" #include "media_decrypt_module_service.h" -#include "meta/meta.h" namespace OHOS { namespace DrmStandard { @@ -42,9 +41,16 @@ MediaDecryptModuleService::MediaDecryptModuleService( { DRM_INFO_LOG("MediaDecryptModuleService 0x%{public}06" PRIXPTR " Instances create.", FAKE_POINTER(this)); hdiMediaDecryptModule_ = hdiMediaDecryptModule; - int32_t uid = IPCSkeleton::GetCallingUid(); +} + +MediaDecryptModuleService::MediaDecryptModuleService( + sptr hdiMediaDecryptModule, + StatisticsInfo statisticsInfo) +{ + DRM_INFO_LOG("MediaDecryptModuleService 0x%{public}06" PRIXPTR " Instances create.", FAKE_POINTER(this)); + hdiMediaDecryptModule_ = hdiMediaDecryptModule; + statisticsInfo_ = statisticsInfo; instanceId_ = HiTraceChain::GetId().GetChainId(); - DrmEvent::GetInstance().CreateMediaInfo(uid, instanceId_); } MediaDecryptModuleService::~MediaDecryptModuleService() @@ -54,7 +60,7 @@ MediaDecryptModuleService::~MediaDecryptModuleService() if (hdiMediaDecryptModule_ != nullptr) { Release(); } - ReportDecryptionStatisticEvent(); + ReportDecryptionStatisticsEvent(instanceId_, statisticsInfo_.bundleName, decryptStatistics_); DRM_INFO_LOG("MediaDecryptModuleService::~MediaDecryptModuleService exit."); } @@ -141,29 +147,6 @@ void MediaDecryptModuleService::SetDrmBufferInfo(OHOS::HDI::Drm::V1_0::DrmBuffer drmDstBuffer->sharedMemType = dstBuffer.sharedMemType; } -void MediaDecryptModuleService::ReportDecryptionStatisticEvent() -{ - std::shared_ptr meta = std::make_shared(); - meta->SetData(Media::Tag::DRM_APP_NAME, GetClientBundleName(IPCSkeleton::GetCallingUid())); - meta->SetData(Media::Tag::DRM_INSTANCE_ID, std::to_string(instanceId_)); - meta->SetData(Media::Tag::DRM_ERROR_CODE, decryptStatistics_.errCode); - meta->SetData(Media::Tag::DRM_ERROR_MESG, decryptStatistics_.errMessage); - meta->SetData(Media::Tag::DRM_DECRYPT_TIMES, decryptStatistics_.decryptTimes); - if (decryptStatistics_.decryptTimes != 0) { - meta->SetData(Media::Tag::DRM_DECRYPT_AVG_SIZE, - static_cast(decryptStatistics_.decryptSumSize / decryptStatistics_.decryptTimes)); - meta->SetData(Media::Tag::DRM_DECRYPT_AVG_DURATION, - static_cast(decryptStatistics_.decryptSumDuration / decryptStatistics_.decryptTimes)); - } else { - meta->SetData(Media::Tag::DRM_DECRYPT_AVG_SIZE, 0); - meta->SetData(Media::Tag::DRM_DECRYPT_AVG_DURATION, 0); - } - meta->SetData(Media::Tag::DRM_DECRYPT_MAX_SIZE, decryptStatistics_.decryptMaxSize); - meta->SetData(Media::Tag::DRM_DECRYPT_MAX_DURATION, decryptStatistics_.decryptMaxDuration); - DrmEvent::GetInstance().AppendMediaInfo(meta, instanceId_); - DrmEvent::GetInstance().ReportMediaInfo(instanceId_); -} - void MediaDecryptModuleService::UpdateDecryptionStatistics(int32_t decryptionResult, uint32_t bufLen, uint32_t curDuration) { @@ -173,9 +156,9 @@ void MediaDecryptModuleService::UpdateDecryptionStatistics(int32_t decryptionRes decryptStatistics_.topThree.pop(); } - if (decryptStatistics_.decryptMaxSize < bufLen) { - decryptStatistics_.decryptMaxSize = bufLen; - } + decryptStatistics_.decryptMaxSize = std::max(decryptStatistics_.decryptMaxSize, bufLen); + decryptStatistics_.decryptMaxDuration = std::max(decryptStatistics_.decryptMaxDuration, curDuration); + if (decryptionResult != DRM_OK) { decryptStatistics_.errorDecryptTimes++; } diff --git a/services/drm_service/server/src/mediakeysystem_service.cpp b/services/drm_service/server/src/mediakeysystem_service.cpp index afb6eeab..c384fea7 100644 --- a/services/drm_service/server/src/mediakeysystem_service.cpp +++ b/services/drm_service/server/src/mediakeysystem_service.cpp @@ -18,7 +18,6 @@ #include "system_ability_definition.h" #include "ipc_skeleton.h" #include "iservice_registry.h" -#include "access_token.h" #include "drm_dfx_utils.h" #include "drm_host_manager.h" #include "drm_log.h" @@ -87,9 +86,6 @@ int32_t MediaKeySystemService::CloseMediaKeySystemServiceByCallback() int32_t MediaKeySystemService::Release() { DRM_INFO_LOG("MediaKeySystemService::Release enter."); - DRM_DEBUG_LOG("pluginName:%{public}s, pluginUuid:%{public}s\nbundleName:%{public}s,\nvendor:%{public}s,\n" - "version:%{public}s,\n", statisticsInfo_.pluginName.c_str(), statisticsInfo_.pluginUuid.c_str(), - statisticsInfo_.bundleName.c_str(), statisticsInfo_.vendorName.c_str(), statisticsInfo_.versionName.c_str()); int32_t currentPid = IPCSkeleton::GetCallingPid(); DRM_DEBUG_LOG("MediaKeySystemService GetCallingPID: %{public}d", currentPid); if (keySystemOperatoersCallback_ != nullptr) { @@ -114,9 +110,6 @@ int32_t MediaKeySystemService::GenerateKeySystemRequest(std::vector &re { DrmTrace trace("MediaKeySystemService::GenerateKeySystemRequest"); DRM_INFO_LOG("MediaKeySystemService::GenerateKeySystemRequest enter."); - DRM_DEBUG_LOG("pluginName:%{public}s, pluginUuid:%{public}s\nbundleName:%{public}s,\nvendor:%{public}s,\n" - "version:%{public}s,\n", statisticsInfo_.pluginName.c_str(), statisticsInfo_.pluginUuid.c_str(), - statisticsInfo_.bundleName.c_str(), statisticsInfo_.vendorName.c_str(), statisticsInfo_.versionName.c_str()); int32_t ret = DRM_OK; auto timeBefore = std::chrono::system_clock::now(); ret = hdiKeySystem_->GenerateKeySystemRequest(defaultUrl, request); @@ -139,9 +132,6 @@ int32_t MediaKeySystemService::ProcessKeySystemResponse(const std::vectorProcessKeySystemResponse(response); @@ -225,9 +215,6 @@ int32_t MediaKeySystemService::CreateMediaKeySession(IMediaKeySessionService::Co { DrmTrace trace("MediaKeySystemService::CreateMediaKeySession"); DRM_INFO_LOG("MediaKeySystemService::CreateMediaKeySession enter, securityLevel:%{public}d.", securityLevel); - DRM_DEBUG_LOG("pluginName:%{public}s, pluginUuid:%{public}s\nbundleName:%{public}s,\nvendor:%{public}s,\n" - "version:%{public}s,\n", statisticsInfo_.pluginName.c_str(), statisticsInfo_.pluginUuid.c_str(), - statisticsInfo_.bundleName.c_str(), statisticsInfo_.vendorName.c_str(), statisticsInfo_.versionName.c_str()); int32_t ret = DRM_OK; std::lock_guard lock(mutex_); sptr keySessionService = nullptr; diff --git a/services/drm_service/server/src/mediakeysystemfactory_service.cpp b/services/drm_service/server/src/mediakeysystemfactory_service.cpp index 3cdd359b..b93e083d 100644 --- a/services/drm_service/server/src/mediakeysystemfactory_service.cpp +++ b/services/drm_service/server/src/mediakeysystemfactory_service.cpp @@ -20,7 +20,6 @@ #include "mem_mgr_client.h" #include "mem_mgr_proxy.h" #include "ipc_skeleton.h" -#include "access_token.h" #include "iservice_registry.h" #include "drm_dfx_utils.h" #include "drm_log.h" @@ -128,10 +127,10 @@ void MediaKeySystemFactoryService::DistroyForClientDied(pid_t pid) DRM_DEBUG_LOG("MediaKeySystemFactoryService ReleaseMediaKeySystem."); drmHostManager_->ReleaseMediaKeySystem(hdiMediaKeySystem); } - } - // decrease in dfx. - if (CurrentMediaKeySystemNum_.find((*it)->GetPluginName()) != CurrentMediaKeySystemNum_.end()) { - CurrentMediaKeySystemNum_[(*it)->GetPluginName()]--; + // decrease in dfx. + if (CurrentMediaKeySystemNum_.find((*it)->GetPluginName()) != CurrentMediaKeySystemNum_.end()) { + CurrentMediaKeySystemNum_[(*it)->GetPluginName()]--; + } } it = mediaKeySystemForPid_[pid].erase(it); } @@ -283,8 +282,11 @@ void MediaKeySystemFactoryService::InitStatisticsInfo(const sptrGetConfigurationString("vendor", statisticsInfo.vendorName); (void)hdiMediaKeySystem->GetConfigurationString("version", statisticsInfo.versionName); } - DRM_INFO_LOG("InitStatisticsInfo %{public}s %{public}s %{public}s %{public}s %{public}s.", - statisticsInfo.pluginName.c_str(), statisticsInfo.pluginUuid.c_str(), statisticsInfo.bundleName.c_str(), + DRM_INFO_LOG("InitStatisticsInfo uid: %{public}d, appName: %{public}s.", + IPCSkeleton::GetCallingUid(), statisticsInfo.bundleName.c_str()); + DRM_INFO_LOG("InitStatisticsInfo pluginName: %{public}s, pluginUUID: %{public}s", + statisticsInfo.pluginName.c_str(), statisticsInfo.pluginUuid.c_str()); + DRM_INFO_LOG("InitStatisticsInfo vendorName: %{public}s, versionName: %{public}s", statisticsInfo.vendorName.c_str(), statisticsInfo.versionName.c_str()); } diff --git a/services/utils/drm_dfx.cpp b/services/utils/drm_dfx.cpp index 02afc126..b08fb60f 100644 --- a/services/utils/drm_dfx.cpp +++ b/services/utils/drm_dfx.cpp @@ -23,24 +23,13 @@ #include "securec.h" #include "ipc_skeleton.h" #include "hitrace/tracechain.h" -#include "meta/any.h" #include -namespace { - constexpr int64_t HOURS_BETWEEN_REPORTS = 4; - constexpr int64_t MAX_MAP_SIZE = 100; - std::mutex collectMut_; - std::mutex reportMut_; - std::chrono::system_clock::time_point currentTime_ = std::chrono::system_clock::now(); - std::map idMap_; - std::map>>> mediaInfoMap_; - std::map>>> reportMediaInfoMap_; - bool g_reachMaxMapSize {false}; -} namespace OHOS { namespace DrmStandard { using namespace OHOS::HiviewDFX; using json = nlohmann::json; +constexpr uint32_t MIN_DECRYPTION_TIMES = 1000; DrmEvent& DrmEvent::GetInstance() { @@ -48,204 +37,6 @@ DrmEvent& DrmEvent::GetInstance() return instance; } -void DrmEvent::DrmStatisicsEventWrite(OHOS::HiviewDFX::HiSysEvent::EventType type, - const std::map>>>& infoMap) -{ - DRM_INFO_LOG("DrmEvent::DrmStatisicsEventWrite."); - if (infoMap.empty()) { - DRM_INFO_LOG("DrmEvent infoMap is empty."); - return; - } - std::vector infoArr; - for (const auto& kv : infoMap) { - json jsonArray; - json eventInfoJson; - json drmEvents; - for (const auto& listPair : kv.second) { - json metaInfoJson; - ParseOneEvent(listPair, metaInfoJson); - drmEvents.push_back(metaInfoJson); - } - eventInfoJson["appName"] = GetClientBundleName(kv.first); - eventInfoJson["drmStatistics"] = drmEvents; - jsonArray.push_back(eventInfoJson); - infoArr.push_back(jsonArray.dump()); - } - StatisicsHiSysEventWrite(type, infoArr); -} - -void DrmEvent::ParseOneEvent(const std::pair> &listPair, - json& metaInfoJson) -{ - for (auto it = listPair.second->begin(); it != listPair.second->end(); ++it) { - Media::Any valueType = OHOS::Media::GetDefaultAnyValue(it->first); - if (Media::Any::IsSameTypeWith(valueType)) { - int32_t intVal; - if (listPair.second->GetData(it->first, intVal)) { - metaInfoJson[it->first] = std::to_string(intVal); - } - } else if (Media::Any::IsSameTypeWith(valueType)) { - uint32_t uintVal; - if (listPair.second->GetData(it->first, uintVal)) { - metaInfoJson[it->first] = std::to_string(uintVal); - } - } else if (Media::Any::IsSameTypeWith(valueType)) { - metaInfoJson[it->first] = Media::AnyCast(it->second); - } else if (Media::Any::IsSameTypeWith(valueType)) { - int8_t intVal; - if (listPair.second->GetData(it->first, intVal)) { - metaInfoJson[it->first] = std::to_string(intVal); - } - } else if (Media::Any::IsSameTypeWith(valueType)) { - bool isTrue; - if (listPair.second->GetData(it->first, isTrue)) { - metaInfoJson[it->first] = isTrue ? "true" : "false"; - } - } else { - DRM_INFO_LOG("not found type matched with it->first: %{public}s.", it->first.c_str()); - } - } -} - -void DrmEvent::StatisicsHiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::EventType type, - const std::vector& infoArr) -{ - DRM_INFO_LOG("DrmEvent::StatisicsHiSysEventWrite."); - std::string eventName = "DRM_STATISTICS"; - HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA, eventName, type, - "EVENTS", infoArr); -} - -int32_t DrmEvent::AppendMediaInfo(const std::shared_ptr& meta, uint64_t instanceId) -{ - DRM_INFO_LOG("AppendMediaInfo."); - if (meta == nullptr || meta->Empty()) { - DRM_INFO_LOG("Insert meta is empty."); - return DRM_ERR_INVALID_STATE; - } - - std::lock_guard lock(collectMut_); - auto idMapIt = idMap_.find(instanceId); - if (idMapIt == idMap_.end()) { - DRM_INFO_LOG("Not found instanceId."); - return DRM_ERR_INVALID_VAL; - } - int32_t uid = idMapIt->second; - auto it = mediaInfoMap_.find(uid); - if (it == mediaInfoMap_.end()) { - DRM_INFO_LOG("Not found uid."); - return DRM_ERR_INVALID_STATE; - } - auto& instanceList = it->second; - for (const auto& instancePair : instanceList) { - if (instancePair.first == instanceId) { - auto arg = meta->begin(); - while (arg != meta->end()) { - instancePair.second->SetData(arg->first, arg->second); - ++arg; - } - break; - } - } - return DRM_ERR_OK; -} - -int32_t DrmEvent::CreateMediaInfo(int32_t uid, uint64_t instanceId) -{ - DRM_INFO_LOG("CreateMediaInfo."); - std::lock_guard lock(collectMut_); - DRM_INFO_LOG("CreateMediaInfo uid is: %{public}" PRId32 " instanceId is: %{public}." PRIu64, uid, instanceId); - auto instanceIdMap = idMap_.find(instanceId); - if (instanceIdMap != idMap_.end()) { - DRM_INFO_LOG("instanceId already exists."); - return DRM_ERR_INVALID_VAL; - } else { - idMap_[instanceId] = uid; - } - - std::shared_ptr meta = std::make_shared(); - std::pair> metaAppIdPair(instanceId, meta); - auto it = mediaInfoMap_.find(uid); - if (it != mediaInfoMap_.end()) { - it->second.push_back(metaAppIdPair); - } else { - mediaInfoMap_[uid].push_back(metaAppIdPair); - } - return DRM_ERR_OK; -} - -int32_t DrmEvent::ReportMediaInfo(uint64_t instanceId) -{ - auto currentTime = std::chrono::system_clock::now(); - auto diff = currentTime - currentTime_; - auto hour = std::chrono::duration_cast(diff).count(); - CollectReportMediaInfo(instanceId); - std::lock_guard lock(reportMut_); - if (g_reachMaxMapSize) { - DRM_INFO_LOG("Event data size exceeds 100, report the event"); - g_reachMaxMapSize = false; - return StatisticsEventReport(); - } - if (hour >= HOURS_BETWEEN_REPORTS) { - DRM_INFO_LOG("Over 4 hours, report the event."); - return StatisticsEventReport(); - } - return DRM_ERR_OK; -} - -void DrmEvent::CollectReportMediaInfo(uint64_t instanceId) -{ - int32_t uid; - std::pair> metaAppIdPair; - { - std::lock_guard lock(collectMut_); - DRM_INFO_LOG("CollectReportMediaInfo."); - auto idMapIt = idMap_.find(instanceId); - if (idMapIt == idMap_.end()) { - DRM_INFO_LOG("Not found instanceId in idMap, instanceId is : %{public}." PRIu64, instanceId); - return; - } - uid = idMapIt->second; - idMap_.erase(idMapIt); - auto uidToMediaInfo = mediaInfoMap_.find(uid); - if (uidToMediaInfo == mediaInfoMap_.end()) { - return; - } - auto& instanceList = uidToMediaInfo->second; - for (const auto& instancePair : instanceList) { - if (instancePair.first == instanceId) { - metaAppIdPair = instancePair; - instanceList.remove(instancePair); - break; - } - } - } - - std::lock_guard lock(reportMut_); - auto reportUidToMediaInfo = reportMediaInfoMap_.find(uid); - if (reportUidToMediaInfo != reportMediaInfoMap_.end()) { - reportUidToMediaInfo->second.push_back(metaAppIdPair); - } else { - reportMediaInfoMap_[uid].push_back(metaAppIdPair); - } - g_reachMaxMapSize = (reportMediaInfoMap_.size() >= MAX_MAP_SIZE); -} - -int32_t DrmEvent::StatisticsEventReport() -{ - DRM_INFO_LOG("StatisticsEventReport."); - if (reportMediaInfoMap_.empty()) { - DRM_INFO_LOG("reportMediaInfoMap_ is empty, can't report."); - return DRM_ERR_INVALID_STATE; - } - - DrmStatisicsEventWrite(OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, reportMediaInfoMap_); - auto currentTime = std::chrono::system_clock::now(); - currentTime_ = currentTime; - reportMediaInfoMap_.clear(); - return DRM_ERR_OK; -} - void DrmEvent::WriteServiceEvent(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, DrmServiveInfo &info) { @@ -454,5 +245,37 @@ DownLoadInfo InitDownLoadInfo(uint32_t generationDuration, std::string generatio }; return downLoadInfo; } + +void ReportDecryptionStatisticsEvent(uint64_t instanceId, std::string appName, + DecryptionStatistics &statistics) +{ + DRM_INFO_LOG("ReportDecryptionStatisticsEvent."); + + int32_t res = DRM_ERR_OK; + if (statistics.decryptTimes < MIN_DECRYPTION_TIMES) { + return; + } + uint32_t avgSize = statistics.decryptSumSize / statistics.decryptTimes; + uint32_t avgDuration = statistics.decryptSumDuration / statistics.decryptTimes; + + res = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA, + "DRM_STATISTICS", + HiviewDFX::HiSysEvent::EventType::STATISTIC, + "APP_NAME", appName, + "INSTANCE_ID", instanceId, + "ERROR_CODE", statistics.errCode, + "ERROR_MESG", statistics.errMessage, + "DECRYPT_TIMES", statistics.decryptTimes, + "DECRYPT_AVG_SIZE", avgSize, + "DECRYPT_AVG_DURATION", avgDuration, + "DECRYPT_MAX_SIZE", statistics.decryptMaxSize, + "DECRYPT_MAX_DURATION", statistics.decryptMaxDuration); + if (res != DRM_ERR_OK) { + DRM_ERR_LOG("DRM_STATISTICS Event Write failed, res = %d", res); + } else { + DRM_INFO_LOG("DRM_STATISTICS Event Write success"); + } + DRM_INFO_LOG("ReportDecryptionStatisticsEvent done!"); +} } // namespace DrmStandard } // namespace OHOS \ No newline at end of file diff --git a/services/utils/include/drm_dfx.h b/services/utils/include/drm_dfx.h index ba2b5a47..442d572e 100644 --- a/services/utils/include/drm_dfx.h +++ b/services/utils/include/drm_dfx.h @@ -18,11 +18,11 @@ #include #include +#include #include #include "drm_dfx_utils.h" #include "nocopyable.h" #include "nlohmann/json.hpp" -#include "meta/meta.h" #include "hisysevent.h" #include "hitrace/tracechain.h" #include @@ -98,21 +98,21 @@ struct DownLoadInfo { std::string processResult; }; +struct DecryptionStatistics { + uint32_t decryptTimes = 0; + uint64_t decryptSumSize = 0; + uint64_t decryptSumDuration = 0; + uint32_t decryptMaxSize = 0; + uint32_t decryptMaxDuration = 0; + uint64_t errorDecryptTimes = 0; + int32_t errCode = 0; + std::string errMessage = "no error"; + std::priority_queue, std::greater> topThree; +}; + class DrmEvent { public: static DrmEvent& GetInstance(); - - void DrmStatisicsEventWrite(OHOS::HiviewDFX::HiSysEvent::EventType type, - const std::map>>>& infoMap); - void StatisicsHiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::EventType type, - const std::vector& infoArr); - void ParseOneEvent(const std::pair> &listPair, - nlohmann::json& metaInfoJson); - void CollectReportMediaInfo(uint64_t instanceId); - int32_t AppendMediaInfo(const std::shared_ptr& meta, uint64_t instanceId); - int32_t CreateMediaInfo(int32_t uid, uint64_t instanceId); - int32_t ReportMediaInfo(uint64_t instanceId); - int32_t StatisticsEventReport(); void WriteServiceEvent(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, DrmServiveInfo &info); void WriteLicenseEvent(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, DrmLicenseInfo &info); void WriteCertificateEvent(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, @@ -133,6 +133,8 @@ __attribute__((visibility("default"))) void ReportDecryptionFaultEvent(int32_t e std::string decryptAlgo, std::string decryptKeyid, std::string decryptIv); __attribute__((visibility("default"))) DownLoadInfo InitDownLoadInfo(uint32_t generationDuration, std::string generationResult, uint32_t processDuration, std::string processResult); +__attribute__((visibility("default"))) void ReportDecryptionStatisticsEvent(uint64_t instanceId, std::string appName, + DecryptionStatistics &statistics); } // namespace DrmStandard } // namespace OHOS #endif // DRM_DFX_H \ No newline at end of file diff --git a/services/utils/include/drm_dfx_utils.h b/services/utils/include/drm_dfx_utils.h index 8911b00f..b93f48c5 100644 --- a/services/utils/include/drm_dfx_utils.h +++ b/services/utils/include/drm_dfx_utils.h @@ -32,8 +32,6 @@ namespace DrmStandard { uint32_t __attribute__((visibility("default"))) CalculateTimeDiff(std::chrono::system_clock::time_point timeBefore, std::chrono::system_clock::time_point timeAfter); const int minimumDigit = 2; - const std::string version = "version"; - const std::string vendor = "vendor"; } // namespace DrmStandard } // namespace OHOS