• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <securec.h>
17 #include <unistd.h>
18 #include <unordered_set>
19 #include "system_ability_definition.h"
20 #include "mem_mgr_client.h"
21 #include "mem_mgr_proxy.h"
22 #include "ipc_skeleton.h"
23 #include "drm_dfx_utils.h"
24 #include "drm_log.h"
25 #include "drm_dfx.h"
26 #include "drm_error_code.h"
27 #include "dump_usage.h"
28 #include "hitrace/tracechain.h"
29 #include "mediakeysystem_service.h"
30 #include "mediakeysystemfactory_service.h"
31 
32 namespace OHOS {
33 namespace DrmStandard {
34 using namespace OHOS::HiviewDFX;
35 namespace {
36 constexpr uint32_t MAX_LISTNER_NUM = 64;
37 }
38 const std::string SPLIT_LINE =
39     "----------------------------------------------------------------------------------------\n";
40 
REGISTER_SYSTEM_ABILITY_BY_ID(MediaKeySystemFactoryService,MEDIA_KEY_SYSTEM_SERVICE_ID,true)41 REGISTER_SYSTEM_ABILITY_BY_ID(MediaKeySystemFactoryService, MEDIA_KEY_SYSTEM_SERVICE_ID, true)
42 
43 
44 void MediaKeySystemFactoryService::OnDrmPluginDied(std::string &name)
45 {
46     DRM_INFO_LOG("OnDrmPluginDied enter.");
47     std::lock_guard<std::recursive_mutex> lock(mutex_);
48     for (auto pidIt = mediaKeySystemForPid_.begin(); pidIt != mediaKeySystemForPid_.end();) {
49         std::set<sptr<MediaKeySystemService>> mediaKeySystemServiceSet = pidIt->second;
50         for (auto keySystem = mediaKeySystemServiceSet.begin(); keySystem != mediaKeySystemServiceSet.end();) {
51             std::string pluginName = (*keySystem)->GetPluginName();
52             if (name == pluginName) {
53                 CloseMediaKeySystemService(*keySystem);
54                 mediaKeySystemServiceSet.erase(keySystem++);
55             } else {
56                 ++keySystem;
57             }
58         }
59         if (mediaKeySystemServiceSet.empty()) {
60             pidIt = mediaKeySystemForPid_.erase(pidIt);
61         } else {
62             pidIt++;
63         }
64     }
65     currentMediaKeySystemNum_.erase(name);
66 }
67 
MediaKeySystemFactoryService(int32_t systemAbilityId,bool runOnCreate)68 MediaKeySystemFactoryService::MediaKeySystemFactoryService(int32_t systemAbilityId, bool runOnCreate)
69     : SystemAbility(systemAbilityId, runOnCreate)
70 {
71     DRM_INFO_LOG("MediaKeySystemFactoryService enter.");
72     deathRecipientMap_.clear();
73     drmHostManager_ = new (std::nothrow) DrmHostManager(this);
74     if (drmHostManager_ == nullptr) {
75         DRM_ERR_LOG("create drmHostManager_ failed.");
76         return;
77     }
78 }
79 
~MediaKeySystemFactoryService()80 MediaKeySystemFactoryService::~MediaKeySystemFactoryService()
81 {
82     DRM_INFO_LOG("~MediaKeySystemFactoryService enter.");
83 }
84 
OnStart()85 void MediaKeySystemFactoryService::OnStart()
86 {
87     DRM_INFO_LOG("OnStart enter.");
88     std::lock_guard<std::recursive_mutex> lock(mutex_);
89     DRM_CHECK_AND_RETURN_LOG(drmHostManager_ != nullptr && drmHostManager_->Init() == DRM_INNER_ERR_OK,
90         "OnStart failed to init drm host manager.");
91     bool res = Publish(this);
92     DRM_DEBUG_LOG("MediaKeySystemFactoryService OnStart res=%{public}d", res);
93     AddSystemAbilityListener(MEMORY_MANAGER_SA_ID);
94     ReportServiceBehaviorEvent("DRM_SERVICE", "start");
95 }
96 
OnDump()97 void MediaKeySystemFactoryService::OnDump()
98 {
99 }
100 
OnStop()101 void MediaKeySystemFactoryService::OnStop()
102 {
103     DRM_INFO_LOG("OnStop enter.");
104     std::lock_guard<std::recursive_mutex> lock(mutex_);
105 
106     if (drmHostManager_) {
107         drmHostManager_->DeInit();
108         drmHostManager_ = nullptr;
109     }
110 
111     int pid = getpid();
112     /* 3012 is the saId of drm_service */
113     Memory::MemMgrClient::GetInstance().NotifyProcessStatus(pid, 1, 0, 3012);
114     OHOS::HiviewDFX::DumpUsage dumpUse;
115     ReportServiceBehaviorEvent("DRM_SERVICE", "end");
116 }
117 
OnIdle(const SystemAbilityOnDemandReason & idleReason)118 int32_t MediaKeySystemFactoryService::OnIdle(const SystemAbilityOnDemandReason& idleReason)
119 {
120     (void)idleReason;
121     DRM_INFO_LOG("OnIdle enter.");
122     std::lock_guard<std::recursive_mutex> lock(mutex_);
123     if (!mediaKeySystemForPid_.empty()) {
124         return -1; // -1:reject unload
125     }
126     return 0;
127 }
128 
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)129 void MediaKeySystemFactoryService::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId)
130 {
131     DRM_INFO_LOG("OnAddSystemAbility enter.");
132     if (systemAbilityId == MEMORY_MANAGER_SA_ID) {
133         int32_t pid = getpid();
134         /* 3012 is the said of drm service */
135         Memory::MemMgrClient::GetInstance().NotifyProcessStatus(pid, 1, 1, 3012);
136     }
137 }
138 
Dump(int32_t fd,const std::vector<std::u16string> & args)139 int32_t MediaKeySystemFactoryService::Dump(int32_t fd, const std::vector<std::u16string>& args)
140 {
141     DRM_CHECK_AND_RETURN_RET_LOG(fd > 0, OHOS::INVALID_OPERATION, "Failed to check fd.");
142     std::string dumpString;
143 
144     auto ret = WriteDumpInfo(fd, dumpString);
145     DRM_CHECK_AND_RETURN_RET_LOG(ret == NO_ERROR,
146         OHOS::INVALID_OPERATION, "Failed to write framework information");
147     return OHOS::NO_ERROR;
148 }
149 
DistroyForClientDied(pid_t pid)150 void MediaKeySystemFactoryService::DistroyForClientDied(pid_t pid)
151 {
152     // destroy all system objects for this pid
153     DRM_INFO_LOG("DistroyForClientDied pid: %{public}d.", pid);
154     std::lock_guard<std::recursive_mutex> lock(mutex_);
155     DRM_CHECK_AND_RETURN_LOG(mediaKeySystemForPid_.find(pid) != mediaKeySystemForPid_.end(), "pid not found");
156     for (auto it = mediaKeySystemForPid_[pid].begin(); it != mediaKeySystemForPid_[pid].end();) {
157         if ((*it) != nullptr) {
158             // decrease the total count in drm host manager.
159             sptr<IMediaKeySystem> hdiMediaKeySystem = (*it)->getMediaKeySystem();
160             (*it)->CloseMediaKeySystemServiceByCallback();
161             if (hdiMediaKeySystem != nullptr) {
162                 drmHostManager_->ReleaseMediaKeySystem(hdiMediaKeySystem);
163             }
164             if (currentMediaKeySystemNum_.find((*it)->GetPluginName()) != currentMediaKeySystemNum_.end()) {
165                 currentMediaKeySystemNum_[(*it)->GetPluginName()]--;
166             }
167         }
168         it = mediaKeySystemForPid_[pid].erase(it);
169     }
170     mediaKeySystemForPid_[pid].clear();
171     mediaKeySystemForPid_.erase(pid);
172 }
173 
MediaKeySystemFactoryClientDied(pid_t pid)174 void MediaKeySystemFactoryService::MediaKeySystemFactoryClientDied(pid_t pid)
175 {
176     DRM_ERR_LOG("MediaKeySystemFactory client has died, pid:%{public}d", pid);
177     std::lock_guard<std::recursive_mutex> lock(factoryServiceMutex_);
178     if (clientListenerMap_.find(pid) != clientListenerMap_.end()) {
179         if (clientListenerMap_[pid] != nullptr && clientListenerMap_[pid]->AsObject() != nullptr &&
180             deathRecipientMap_.find(pid) != deathRecipientMap_.end() && deathRecipientMap_[pid] != nullptr) {
181             (void)clientListenerMap_[pid]->AsObject()->RemoveDeathRecipient(deathRecipientMap_[pid]);
182         }
183         deathRecipientMap_.erase(pid);
184         clientListenerMap_.erase(pid);
185     }
186     DistroyForClientDied(pid);
187 }
188 
SetListenerObject(const sptr<IRemoteObject> & object)189 int32_t MediaKeySystemFactoryService::SetListenerObject(const sptr<IRemoteObject> &object)
190 {
191     pid_t pid = IPCSkeleton::GetCallingPid();
192     std::lock_guard<std::recursive_mutex> lock(factoryServiceMutex_);
193     if (clientListenerMap_.find(pid) != clientListenerMap_.end()) {
194         if (clientListenerMap_[pid] != nullptr && clientListenerMap_[pid]->AsObject() != nullptr &&
195             deathRecipientMap_.find(pid) != deathRecipientMap_.end() && deathRecipientMap_[pid] != nullptr) {
196             (void)clientListenerMap_[pid]->AsObject()->RemoveDeathRecipient(deathRecipientMap_[pid]);
197         }
198         deathRecipientMap_.erase(pid);
199         clientListenerMap_.erase(pid);
200     }
201     DRM_CHECK_AND_RETURN_RET_LOG(clientListenerMap_.size() < MAX_LISTNER_NUM,
202         DRM_INNER_ERR_OPERATION_NOT_PERMITTED, "the number of listeners exceeds MAX_LISTNER_NUM: 64");
203     DRM_CHECK_AND_RETURN_RET_LOG(object != nullptr, DRM_INNER_ERR_MEMORY_ERROR, "set listener object is nullptr");
204     sptr<IDrmListener> clientListener = iface_cast<IDrmListener>(object);
205     DRM_CHECK_AND_RETURN_RET_LOG(
206         clientListener != nullptr, DRM_INNER_ERR_MEMORY_ERROR, "failed to convert IDrmListener");
207     sptr<DrmDeathRecipient> deathRecipient = new (std::nothrow) DrmDeathRecipient(pid);
208     DRM_CHECK_AND_RETURN_RET_LOG(deathRecipient != nullptr, DRM_INNER_ERR_MEMORY_ERROR,
209         "failed to new DrmDeathRecipient");
210     deathRecipient->SetNotifyCb([this] (pid_t pid) {
211         this->MediaKeySystemFactoryClientDied(pid);
212     });
213     if (clientListener->AsObject() != nullptr) {
214         (void)clientListener->AsObject()->AddDeathRecipient(deathRecipient);
215     }
216     DRM_DEBUG_LOG("MediaKeySystem client pid:%{public}d", pid);
217     deathRecipientMap_[pid] = deathRecipient;
218     clientListenerMap_[pid] = clientListener;
219     return DRM_INNER_ERR_OK;
220 }
221 
IsListenerObjectSet()222 bool MediaKeySystemFactoryService::IsListenerObjectSet()
223 {
224     std::lock_guard<std::recursive_mutex> lock(factoryServiceMutex_);
225     pid_t pid = IPCSkeleton::GetCallingPid();
226     bool ret = false;
227     if (clientListenerMap_.find(pid) != clientListenerMap_.end()) {
228         ret = true;
229     }
230     return ret;
231 }
232 
CancelAbilityIdle()233 int32_t MediaKeySystemFactoryService::CancelAbilityIdle()
234 {
235     if (GetAbilityState() == SystemAbilityState::IDLE) {
236         bool result = CancelIdle();
237         DRM_CHECK_AND_RETURN_RET_LOG(result, DRM_INNER_ERR_SERVICE_DIED, "CancelIdle failed");
238     }
239     return DRM_INNER_ERR_OK;
240 }
241 
CreateMediaKeySystem(const std::string & name,sptr<IMediaKeySystemService> & mediaKeySystemProxy)242 int32_t MediaKeySystemFactoryService::CreateMediaKeySystem(const std::string &name,
243     sptr<IMediaKeySystemService> &mediaKeySystemProxy)
244 {
245     DRM_INFO_LOG("CreateMediaKeySystem enter.");
246     bool res = IsListenerObjectSet();
247     DRM_CHECK_AND_RETURN_RET_LOG(res, DRM_INNER_ERR_OPERATION_NOT_PERMITTED, "Not Set Listener.");
248     std::lock_guard<std::recursive_mutex> lock(mutex_);
249     DRM_CHECK_AND_RETURN_RET_LOG(
250         CancelAbilityIdle() == DRM_INNER_ERR_OK, DRM_INNER_ERR_SERVICE_DIED, "Cancel Idle failed");
251     sptr<MediaKeySystemService> mediaKeySystemService = nullptr;
252     sptr<IMediaKeySystem> hdiMediaKeySystem = nullptr;
253     if (currentMediaKeySystemNum_[name] >= KEY_SYSTEM_INSTANCES_MAX_NUMBER) {
254         DRM_ERR_LOG("The number of MediaKeySystem is greater than 64");
255         return DRM_INNER_ERR_MAX_SYSTEM_NUM_REACHED;
256     }
257     std::string systemName = name;
258     int32_t ret = drmHostManager_->CreateMediaKeySystem(systemName, hdiMediaKeySystem);
259     if (hdiMediaKeySystem == nullptr || ret != DRM_INNER_ERR_OK) {
260         DRM_ERR_LOG("drmHostManager_ return hdiMediaKeySystem nullptr.");
261         ReportFaultEvent(7, "CreateMediaKeySystem failed", ""); // 7:SERVICE ERR
262         return DRM_INNER_ERR_INVALID_MEDIA_KEY_SYSTEM;
263     }
264 
265     StatisticsInfo statisticsInfo;
266     InitStatisticsInfo(hdiMediaKeySystem, name, statisticsInfo);
267     mediaKeySystemService = new(std::nothrow) MediaKeySystemService(hdiMediaKeySystem, statisticsInfo);
268     if (mediaKeySystemService == nullptr) {
269         DRM_ERR_LOG("CreateMediaKeySystem allocation failed.");
270         ReportFaultEvent(1, "CreateMediaKeySystem failed", ""); // 1:ALLOC ERR
271         return DRM_INNER_ERR_NO_MEMORY;
272     }
273     mediaKeySystemService->SetMediaKeySystemServiceOperatorsCallback(this);
274     (void)mediaKeySystemService->SetBundleName();
275     (void)mediaKeySystemService->SetApiTargetVersion();
276 
277     int32_t pid = IPCSkeleton::GetCallingPid();
278     DRM_DEBUG_LOG("CreateMediaKeySystem GetCallingPID: %{public}d.", pid);
279     mediaKeySystemForPid_[pid].insert(mediaKeySystemService);
280     DRM_DEBUG_LOG("0x%{public}06" PRIXPTR "  Current mediaKeySystemService",
281         FAKE_POINTER(mediaKeySystemService.GetRefPtr()));
282     mediaKeySystemProxy = mediaKeySystemService;
283     if (currentMediaKeySystemNum_.find(name) != currentMediaKeySystemNum_.end()) {
284         currentMediaKeySystemNum_[name]++;
285     } else {
286         currentMediaKeySystemNum_[name] = 1;
287     }
288     return ret;
289 }
290 
CloseMediaKeySystemService(sptr<MediaKeySystemService> mediaKeySystemService)291 int32_t MediaKeySystemFactoryService::CloseMediaKeySystemService(sptr<MediaKeySystemService> mediaKeySystemService)
292 {
293     std::lock_guard<std::recursive_mutex> lock(mutex_);
294     DRM_INFO_LOG("CloseMediaKeySystemService enter.");
295     int32_t currentPid = IPCSkeleton::GetCallingPid();
296     DRM_DEBUG_LOG("MediaKeySystemFactoryService GetCallingPID: %{public}d", currentPid);
297     sptr<IMediaKeySystem> hdiMediaKeySystem = mediaKeySystemService->getMediaKeySystem();
298 
299     for (auto &pidSystemsSet : mediaKeySystemForPid_) {
300         if (pidSystemsSet.second.find(mediaKeySystemService) != pidSystemsSet.second.end()) {
301             mediaKeySystemService->CloseMediaKeySystemServiceByCallback();
302             pidSystemsSet.second.erase(mediaKeySystemService);
303             break;
304         }
305     }
306     std::string pluginName = mediaKeySystemService->GetPluginName();
307     if (currentMediaKeySystemNum_.find(pluginName) != currentMediaKeySystemNum_.end() &&
308         currentMediaKeySystemNum_[pluginName] > 0) {
309         currentMediaKeySystemNum_[pluginName]--;
310     }
311     if (hdiMediaKeySystem != NULL) {
312         drmHostManager_->ReleaseMediaKeySystem(hdiMediaKeySystem);
313     }
314     mediaKeySystemService = nullptr;
315     return DRM_INNER_ERR_OK;
316 }
317 
IsMediaKeySystemSupported(const std::string & name,bool & isSupported)318 int32_t MediaKeySystemFactoryService::IsMediaKeySystemSupported(const std::string &name, bool &isSupported)
319 {
320     DRM_INFO_LOG("IsMediaKeySystemSupported one parameters enter.");
321     std::lock_guard<std::recursive_mutex> lock(mutex_);
322     bool isSystemSupported = false;
323     DRM_CHECK_AND_RETURN_RET_LOG(
324         CancelAbilityIdle() == DRM_INNER_ERR_OK, DRM_INNER_ERR_SERVICE_DIED, "Cancel Idle failed");
325     std::string systemName = name;
326     int32_t ret = drmHostManager_->IsMediaKeySystemSupported(systemName, &isSystemSupported);
327     if (ret != DRM_INNER_ERR_OK) {
328         DRM_ERR_LOG("IsMediaKeySystemSupported failed.");
329         return ret;
330     }
331     isSupported = isSystemSupported;
332     return ret;
333 }
334 
IsMediaKeySystemSupported(const std::string & name,const std::string & mimeType,bool & isSupported)335 int32_t MediaKeySystemFactoryService::IsMediaKeySystemSupported(const std::string &name, const std::string &mimeType,
336     bool &isSupported)
337 {
338     DRM_INFO_LOG("IsMediaKeySystemSupported two parameters enter.");
339     std::lock_guard<std::recursive_mutex> lock(mutex_);
340     bool isSystemSupported = false;
341     DRM_CHECK_AND_RETURN_RET_LOG(
342         CancelAbilityIdle() == DRM_INNER_ERR_OK, DRM_INNER_ERR_SERVICE_DIED, "Cancel Idle failed");
343     std::string systemName = name;
344     std::string systemMimeType = mimeType;
345     int32_t ret = drmHostManager_->IsMediaKeySystemSupported(systemName, systemMimeType, &isSystemSupported);
346     if (ret != DRM_INNER_ERR_OK) {
347         DRM_ERR_LOG("IsMediaKeySystemSupported failed.");
348         return ret;
349     }
350     isSupported = isSystemSupported;
351     return ret;
352 }
353 
IsMediaKeySystemSupported(const std::string & name,const std::string & mimeType,int32_t securityLevel,bool & isSupported)354 int32_t MediaKeySystemFactoryService::IsMediaKeySystemSupported(const std::string &name, const std::string &mimeType,
355     int32_t securityLevel, bool &isSupported)
356 {
357     DRM_INFO_LOG("IsMediaKeySystemSupported three parameters enter.");
358     std::lock_guard<std::recursive_mutex> lock(mutex_);
359     bool isSystemSupported = false;
360     DRM_CHECK_AND_RETURN_RET_LOG(
361         CancelAbilityIdle() == DRM_INNER_ERR_OK, DRM_INNER_ERR_SERVICE_DIED, "Cancel Idle failed");
362     std::string systemName = name;
363     std::string systemMimeType = mimeType;
364     int32_t ret = drmHostManager_->IsMediaKeySystemSupported(systemName,
365         systemMimeType, securityLevel, &isSystemSupported);
366     if (ret != DRM_INNER_ERR_OK) {
367         DRM_ERR_LOG("IsMediaKeySystemSupported failed.");
368         return ret;
369     }
370     isSupported = isSystemSupported;
371     return ret;
372 }
373 
GetMediaKeySystems(std::map<std::string,std::string> & mediaKeySystemNames)374 int32_t MediaKeySystemFactoryService::GetMediaKeySystems(std::map<std::string, std::string> &mediaKeySystemNames)
375 {
376     DRM_INFO_LOG("GetMediaKeySystems enter.");
377     std::lock_guard<std::recursive_mutex> lock(mutex_);
378     DRM_CHECK_AND_RETURN_RET_LOG(
379         CancelAbilityIdle() == DRM_INNER_ERR_OK, DRM_INNER_ERR_SERVICE_DIED, "Cancel Idle failed");
380     int32_t ret = drmHostManager_->GetMediaKeySystems(mediaKeySystemNames);
381     DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_INNER_ERR_OK, ret, "GetMediaKeySystems failed.");
382     return ret;
383 }
384 
GetMediaKeySystemUuid(const std::string & name,std::string & uuid)385 int32_t MediaKeySystemFactoryService::GetMediaKeySystemUuid(const std::string &name, std::string &uuid)
386 {
387     DRM_INFO_LOG("GetMediaKeySystemUuid enter.");
388     std::lock_guard<std::recursive_mutex> lock(mutex_);
389     DRM_CHECK_AND_RETURN_RET_LOG(
390         CancelAbilityIdle() == DRM_INNER_ERR_OK, DRM_INNER_ERR_SERVICE_DIED, "Cancel Idle failed");
391     std::string systemName = name;
392     int32_t ret = drmHostManager_->GetMediaKeySystemUuid(systemName, uuid);
393     DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_INNER_ERR_OK, ret, "GetMediaKeySystemUuid failed.");
394     return ret;
395 }
396 
InitStatisticsInfo(const sptr<IMediaKeySystem> & hdiMediaKeySystem,std::string pluginName,StatisticsInfo & statisticsInfo)397 void MediaKeySystemFactoryService::InitStatisticsInfo(const sptr<IMediaKeySystem> &hdiMediaKeySystem,
398     std::string pluginName, StatisticsInfo &statisticsInfo)
399 {
400     DRM_INFO_LOG("InitStatisticsInfo enter.");
401     std::lock_guard<std::recursive_mutex> lock(mutex_);
402     statisticsInfo.pluginName = pluginName;
403     if (drmHostManager_ != nullptr) {
404         std::map<std::string, std::string> pluginNameUuidMap;
405         drmHostManager_->GetMediaKeySystems(pluginNameUuidMap);
406         if (pluginNameUuidMap.find(pluginName) != pluginNameUuidMap.end()) {
407             statisticsInfo.pluginUuid = pluginNameUuidMap[pluginName];
408         }
409     }
410     statisticsInfo.bundleName = GetClientBundleName(IPCSkeleton::GetCallingUid());
411     if (hdiMediaKeySystem != nullptr) {
412         (void)hdiMediaKeySystem->GetConfigurationString("vendor", statisticsInfo.vendorName);
413         (void)hdiMediaKeySystem->GetConfigurationString("version", statisticsInfo.versionName);
414     }
415     statisticsInfo.targetVersion = GetClientBundleInfoTargetVersion(statisticsInfo.bundleName,
416         IPCSkeleton::GetCallingUid());
417     DRM_INFO_LOG("uid: %{public}d, appName: %{public}s, targetVersion: %{public}u.",
418         IPCSkeleton::GetCallingUid(), statisticsInfo.bundleName.c_str(), statisticsInfo.targetVersion);
419     DRM_INFO_LOG("pluginName: %{public}s, pluginUUID: %{public}s",
420         statisticsInfo.pluginName.c_str(), statisticsInfo.pluginUuid.c_str());
421     DRM_INFO_LOG("vendorName: %{public}s, versionName: %{public}s",
422         statisticsInfo.vendorName.c_str(), statisticsInfo.versionName.c_str());
423 }
424 
WriteDumpInfo(int32_t fd,std::string & dumpString)425 int32_t MediaKeySystemFactoryService::WriteDumpInfo(int32_t fd, std::string &dumpString)
426 {
427     OHOS::HiviewDFX::DumpUsage dumpUse;
428     std::lock_guard<std::recursive_mutex> lock(mutex_);
429     dumpString += "MediaKeySystem MemoryUsage: " + std::to_string(dumpUse.GetPss(getpid())) + "\n";
430     std::map<std::string, std::string> mediaKeySystemInfo;
431     drmHostManager_->GetMediaKeySystems(mediaKeySystemInfo);
432     for (auto &iter : mediaKeySystemInfo) {
433         dumpString += SPLIT_LINE;
434         std::string tmpStr = "Plugin Name: " + iter.first + "\n" +
435                              "Plugin UUID: " + iter.second + "\n" +
436                              "Total MediaKeySystem Num: ";
437         int32_t systemNum = 0;
438         if (currentMediaKeySystemNum_.find(iter.first) != currentMediaKeySystemNum_.end()) {
439             systemNum = currentMediaKeySystemNum_[iter.first];
440         }
441         tmpStr += std::to_string(systemNum) + "\n";
442         dumpString += tmpStr;
443     }
444     uint32_t systemNum = 0;
445     for (auto &pidIter : mediaKeySystemForPid_) {
446         dumpString += SPLIT_LINE;
447         systemNum++;
448         dumpString += "#### MediaKeySystem " + std::to_string(systemNum) + " ####\n";
449         dumpString += "PID: " + std::to_string(pidIter.first) + "\n";
450         for (auto &system : pidIter.second) {
451             dumpString += "-------------------------------\n";
452             CertificateStatus certStatus = CertificateStatus::CERT_STATUS_UNAVAILABLE;
453             system->GetCertificateStatus(certStatus);
454             dumpString += "Plugin Name: " + system->GetPluginName() + "\n";
455             dumpString += "Certificate Status: " + std::to_string(static_cast<int32_t>(certStatus)) + "\n";
456             dumpString += system->GetSessionsDumpInfo();
457         }
458     }
459     dumpString += SPLIT_LINE;
460     DRM_CHECK_AND_RETURN_RET_LOG(fd != -1, OHOS::NO_ERROR, "%{public}s", dumpString.c_str());
461     ssize_t writeLen = write(fd, dumpString.c_str(), dumpString.size());
462     DRM_CHECK_AND_RETURN_RET_LOG(writeLen != -1, OHOS::NO_ERROR, "Dump write error!");
463     return OHOS::NO_ERROR;
464 }
465 
466 } // DrmStandard
467 } // OHOS
468