fix cannot get bundle name

Signed-off-by: caochuan <caochuan@huawei.com>
This commit is contained in:
caochuan
2024-05-31 13:59:36 +08:00
9 changed files with 64 additions and 37 deletions
@@ -55,7 +55,7 @@ struct Message {
Message(Type t, std::string pluginName, ExtraInfo info) : type(t), name(pluginName), extraInfo(info) {}
};
#define OEM_CERTIFICATE_PATH "/system/lib64/oem_certificate_service"
#define OEM_CERTIFICATE_PATH "/system/lib64/oem_certificate_service/"
#define PLUGIN_LAZYLOAD_CONFIG_PATH "/etc/drm/drm_plugin_lazyloding.cfg"
typedef void (*MediaKeySystemCallBack)(std::string &, ExtraInfo);
@@ -76,7 +76,7 @@ private:
StatisticsInfo statisticsInfo_;
std::string generationResult_;
std::string mediaKeyType_;
uint32_t generationDuration_;
uint32_t generationDuration_ = 0;
};
class IMediaKeySessionServiceOperatorsCallback : public virtual RefBase {
@@ -88,7 +88,7 @@ private:
sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystem> hdiKeySystem_;
StatisticsInfo statisticsInfo_;
std::string generationResult_;
uint32_t generationDuration_;
uint32_t generationDuration_ = 0;
};
class IMediaKeySystemServiceOperatorsCallback : public virtual RefBase {
@@ -311,9 +311,18 @@ int32_t DrmHostManager::GetSevices(std::string &name, bool *isSurpported)
std::vector<std::string> serviceName;
/* The plugin service corresponding to name has been started, no need to reload, just mark the count. */
if (drmHostServieProxyMap[name] != nullptr) {
pluginCountMap[name]++;
DRM_DEBUG_LOG("DrmHostManager::GetSevices, the plugin service has been pulled up.");
return DRM_OK;
ret = drmHostServieProxyMap[name]->IsMediaKeySystemSupported(name, "", SECURE_UNKNOWN, *isSurpported);
if (ret == DRM_OK) {
pluginCountMap[name]++;
DRM_DEBUG_LOG("DrmHostManager::GetSevices, the plugin service has been pulled up.");
return DRM_OK;
}
}
auto servmgr = IServiceManager::Get();
ret = servmgr->ListServiceByInterfaceDesc(serviceName, "ohos.hdi.drm.v1_0.IMediaKeySystemFactory");
if (ret != DRM_OK) {
DRM_ERR_LOG("ListServiceByInterfaceDesc faild, return Code:%{public}d", ret);
return ret;
}
/*
* If the plugin is configured with lazy loading, read the service name from the configuration file.
@@ -322,23 +331,19 @@ int32_t DrmHostManager::GetSevices(std::string &name, bool *isSurpported)
*/
loadPluginInfo(PLUGIN_LAZYLOAD_CONFIG_PATH);
if (lazyLoadPluginInfoMap.count(name) > 0) {
sptr<IDeviceManager> deviceMgr = IDeviceManager::Get();
if (deviceMgr == nullptr) {
DRM_ERR_LOG("DrmHostManager:GetSevices deviceMgr == nullptr");
return DRM_SERVICE_ERROR;
}
ret = deviceMgr->LoadDevice(lazyLoadPluginInfoMap[name]);
if (ret != DRM_OK) {
DRM_ERR_LOG("DrmHostManager LoadDevice return Code:%{public}d", ret);
return DRM_HOST_ERROR;
}
serviceName.push_back(lazyLoadPluginInfoMap[name]);
} else {
auto servmgr = IServiceManager::Get();
ret = servmgr->ListServiceByInterfaceDesc(serviceName, "ohos.hdi.drm.v1_0.IMediaKeySystemFactory");
if (ret != DRM_OK) {
DRM_ERR_LOG("ListServiceByInterfaceDesc faild, return Code:%{public}d", ret);
return ret;
auto it = std::find(serviceName.begin(), serviceName.end(), lazyLoadPluginInfoMap[name]);
if (it == serviceName.end()) {
sptr<IDeviceManager> deviceMgr = IDeviceManager::Get();
if (deviceMgr == nullptr) {
DRM_ERR_LOG("DrmHostManager:GetSevices deviceMgr == nullptr");
return DRM_SERVICE_ERROR;
}
ret = deviceMgr->LoadDevice(lazyLoadPluginInfoMap[name]);
if (ret != DRM_OK) {
DRM_ERR_LOG("DrmHostManager LoadDevice return Code:%{public}d", ret);
return DRM_HOST_ERROR;
}
serviceName.push_back(lazyLoadPluginInfoMap[name]);
}
}
for (auto hdiServiceName : serviceName) {
@@ -377,7 +382,6 @@ int32_t DrmHostManager::IsMediaKeySystemSupported(std::string &name, bool *isSur
ReleaseSevices(name);
return DRM_SERVICE_ERROR;
}
*isSurpported = true;
drmHostServieProxyMap[name] = nullptr;
ReleaseSevices(name);
DRM_INFO_LOG("DrmHostManager::IsMediaKeySystemSupported one parameters exit, isSurpported:%{public}d.",
@@ -461,7 +465,7 @@ int32_t DrmHostManager::CreateMediaKeySystem(std::string &name, sptr<IMediaKeySy
std::unique_lock<std::shared_mutex> lock(lazyLoadPluginInfoMapMtx);
int32_t ret = GetSevices(name, &isSurpported);
if (ret != DRM_OK || drmHostServieProxyMap[name] == nullptr) {
DRM_INFO_LOG("DrmHostManager::CreateMediaKeySystem faild.");
DRM_ERR_LOG("DrmHostManager::CreateMediaKeySystem faild.");
return ret;
}
drmHostDeathRecipient_ = new DrmHostDeathRecipient();
@@ -522,6 +526,12 @@ int32_t DrmHostManager::GetMediaKeySystems(std::map<std::string, std::string> &m
std::vector<std::string> lazyLoadServiceNames;
std::vector<std::string> pluginServiceNames;
std::unique_lock<std::shared_mutex> lock(lazyLoadPluginInfoMapMtx);
auto servmgr = IServiceManager::Get();
ret = servmgr->ListServiceByInterfaceDesc(pluginServiceNames, "ohos.hdi.drm.v1_0.IMediaKeySystemFactory");
if (ret != DRM_OK) {
DRM_ERR_LOG("ListServiceByInterfaceDesc faild, return Code:%{public}d", ret);
return ret;
}
/*
* If the plugin is configured with lazy loading, read the service name from the configuration file.
* If lazy loading is not configured, traverse the service bound by the interface descriptor, and obtain
@@ -531,14 +541,13 @@ int32_t DrmHostManager::GetMediaKeySystems(std::map<std::string, std::string> &m
sptr<IDeviceManager> deviceMgr = IDeviceManager::Get();
if (deviceMgr == nullptr) {
DRM_ERR_LOG("DrmHostManager:GetSevices deviceMgr == nullptr");
return DRM_SERVICE_ERROR;
}
for (auto pluginInfoIt = lazyLoadPluginInfoMap.begin(); pluginInfoIt != lazyLoadPluginInfoMap.end();
pluginInfoIt++) {
ret = deviceMgr->LoadDevice(pluginInfoIt->second);
if (ret != DRM_OK) {
DRM_ERR_LOG("DrmHostManager LoadDevice return Code:%{public}d", ret);
return DRM_HOST_ERROR;
continue;
}
lazyLoadServiceNames.push_back(pluginInfoIt->second);
if (pluginCountMap.empty()) {
@@ -547,12 +556,6 @@ int32_t DrmHostManager::GetMediaKeySystems(std::map<std::string, std::string> &m
pluginCountMap[pluginInfoIt->first]++;
}
}
auto servmgr = IServiceManager::Get();
ret = servmgr->ListServiceByInterfaceDesc(pluginServiceNames, "ohos.hdi.drm.v1_0.IMediaKeySystemFactory");
if (ret != DRM_OK) {
DRM_ERR_LOG("ListServiceByInterfaceDesc faild, return Code:%{public}d", ret);
return ret;
}
for (uint32_t i = 0; i < lazyLoadServiceNames.size(); i++) {
bool found = false;
for (uint32_t j = 0; i < pluginServiceNames.size(); j++) {
@@ -97,10 +97,8 @@ int32_t MediaDecryptModuleService::DecryptMediaData(bool secureDecodrtState,
(void)::close(srcBuffer.fd);
(void)::close(dstBuffer.fd);
DRM_ERR_LOG("MediaDecryptModuleService::DecryptMediaData failed.");
std::string decryptKeyId;
decryptKeyId.assign(cryptInfoTmp.keyId.begin(), cryptInfoTmp.keyId.end());
std::string decryptKeyIv;
decryptKeyIv.assign(cryptInfoTmp.iv.begin(), cryptInfoTmp.iv.end());
std::string decryptKeyId = CastToHexString(cryptInfoTmp.keyId);
std::string decryptKeyIv = CastToHexString(cryptInfoTmp.iv);
ReportDecryptionFaultEvent(ret, "DecryptMediaData failed",
std::to_string(static_cast<int32_t>(cryptInfoTmp.type)), decryptKeyId, decryptKeyIv);
return ret;
+6
View File
@@ -254,6 +254,7 @@ void DrmEvent::WriteServiceEvent(std::string eventName, OHOS::HiviewDFX::HiSysEv
int32_t res = DRM_ERR_OK;
res = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA, eventName, type,
"MODULE", info.module,
"TIME", info.currentTime,
"SERVICE_NAME", info.serviceName,
"ACTION", info.action,
"MEMORY", info.memoryUsage);
@@ -270,6 +271,7 @@ void DrmEvent::WriteLicenseEvent(std::string eventName, OHOS::HiviewDFX::HiSysEv
int32_t res = DRM_ERR_OK;
res = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA, eventName, type,
"MODULE", info.module,
"TIME", info.currentTime,
"APP_NAME", info.appName,
"INSTANCE_ID", info.instanceId,
"DRM_NAME", info.drmName,
@@ -293,6 +295,7 @@ void DrmEvent::WriteCertificateEvent(std::string eventName, OHOS::HiviewDFX::HiS
int32_t res = DRM_ERR_OK;
res = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA, eventName, type,
"MODULE", info.module,
"TIME", info.currentTime,
"APP_NAME", info.appName,
"INSTANCE_ID", info.instanceId,
"DRM_NAME", info.drmName,
@@ -357,6 +360,7 @@ void ReportServiceBehaviorEvent(std::string serviceName, std::string action)
uint32_t memoryUsage = dumpUse.GetPss(getpid());
struct DrmServiveInfo drmServiveInfo = {
"DRM_SERVICE",
0,
serviceName,
action,
memoryUsage,
@@ -370,6 +374,7 @@ void ReportLicenseBehaviorEvent(StatisticsInfo statisticsInfo, std::string licen
DrmEvent event;
struct DrmLicenseInfo drmLicenseInfo = {
"DRM_SERVICE",
0,
GetClientBundleName(IPCSkeleton::GetCallingUid()),
std::to_string(HiTraceChain::GetId().GetChainId()),
statisticsInfo.pluginName,
@@ -392,6 +397,7 @@ void ReportCertificateBehaviorEvent(StatisticsInfo statisticsInfo, uint32_t gene
DrmEvent event;
struct DrmCertificateInfo DrmCertificateInfo = {
"DRM_SERVICE",
0,
GetClientBundleName(IPCSkeleton::GetCallingUid()),
std::to_string(HiTraceChain::GetId().GetChainId()),
statisticsInfo.pluginName,
+14
View File
@@ -13,6 +13,9 @@
* limitations under the License.
*/
#include <cstdint>
#include <iomanip>
#include <sstream>
#include "drm_dfx_utils.h"
#include "drm_log.h"
#include "iservice_registry.h"
@@ -54,6 +57,17 @@ std::string __attribute__((visibility("default"))) GetClientBundleName(int32_t u
return bundleName;
}
std::string __attribute__((visibility("default"))) CastToHexString(std::vector<uint8_t> binaryData)
{
std::string hexString;
for (uint8_t binary : binaryData) {
std::stringstream stream;
stream << std::hex << std::setw(minimumDigit) << std::setfill('0') << static_cast<int>(binary);
hexString += stream.str();
}
return hexString;
}
uint32_t __attribute__((visibility("default"))) CalculateTimeDiff(std::chrono::system_clock::time_point timeBefore,
std::chrono::system_clock::time_point timeAfter)
{
+3
View File
@@ -37,6 +37,7 @@ using namespace OHOS::HiviewDFX;
#ifdef ENABLE_DRM_SYSEVENT_CONTROL
struct DrmServiveInfo {
std::string module;
uint32_t currentTime;
std::string serviceName;
std::string action;
uint32_t memoryUsage;
@@ -44,6 +45,7 @@ struct DrmServiveInfo {
struct DrmLicenseInfo {
std::string module;
uint32_t currentTime;
std::string appName;
std::string instanceId;
std::string drmName;
@@ -58,6 +60,7 @@ struct DrmLicenseInfo {
struct DrmCertificateInfo {
std::string module;
uint32_t currentTime;
std::string appName;
std::string instanceId;
std::string drmName;
+3
View File
@@ -16,6 +16,7 @@
#ifndef DRM_DFX_UTILS_H
#define DRM_DFX_UTILS_H
#include <string>
#include <vector>
namespace OHOS {
namespace DrmStandard {
@@ -27,8 +28,10 @@ namespace DrmStandard {
std::string bundleName;
};
std::string __attribute__((visibility("default"))) GetClientBundleName(int32_t uid);
std::string __attribute__((visibility("default"))) CastToHexString(std::vector<uint8_t> binaryData);
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 currentSessionNum = "currentSessionNum";
const std::string version = "version";
const std::string errorDecryptNumber = "errorDecryptNumber";