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 <unordered_set>
17 #include <securec.h>
18 #include "system_ability_definition.h"
19 #include "ipc_skeleton.h"
20 #include "iservice_registry.h"
21 #include "drm_dfx_utils.h"
22 #include "drm_host_manager.h"
23 #include "drm_log.h"
24 #include "drm_trace.h"
25 #include "drm_error_code.h"
26 #include "key_session_service.h"
27 #include "mediakeysystem_service.h"
28 #include "hitrace/tracechain.h"
29
30 namespace OHOS {
31 namespace DrmStandard {
32 using namespace OHOS::HiviewDFX;
MediaKeySystemService(sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystem> hdiKeySystem)33 MediaKeySystemService::MediaKeySystemService(sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystem> hdiKeySystem)
34 {
35 DRM_INFO_LOG("MediaKeySystemService 0x%{public}06" PRIXPTR " Instances create.", FAKE_POINTER(this));
36 keySystemOperatoersCallback_ = nullptr;
37 hdiKeySystem_ = hdiKeySystem;
38 }
39
MediaKeySystemService(sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystem> hdiKeySystem, StatisticsInfo statisticsInfo)40 MediaKeySystemService::MediaKeySystemService(sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystem> hdiKeySystem,
41 StatisticsInfo statisticsInfo)
42 {
43 DRM_INFO_LOG("MediaKeySystemService 0x%{public}06" PRIXPTR " Instances create.", FAKE_POINTER(this));
44 keySystemOperatoersCallback_ = nullptr;
45 hdiKeySystem_ = hdiKeySystem;
46 statisticsInfo_ = statisticsInfo;
47 }
48
~MediaKeySystemService()49 MediaKeySystemService::~MediaKeySystemService()
50 {
51 DRM_INFO_LOG("~MediaKeySystemService 0x%{public}06" PRIXPTR " Instances destroy.", FAKE_POINTER(this));
52 std::lock_guard<std::recursive_mutex> lock(mutex_);
53 keySystemOperatoersCallback_ = nullptr;
54 if (hdiKeySystem_ != nullptr) {
55 DRM_ERR_LOG("hdiKeySystem != nullptr");
56 }
57 }
58
OnDrmPluginDied(std::string &name)59 void MediaKeySystemService::OnDrmPluginDied(std::string &name)
60 {}
61
CloseMediaKeySystemServiceByCallback()62 int32_t MediaKeySystemService::CloseMediaKeySystemServiceByCallback()
63 {
64 DRM_INFO_LOG("CloseMediaKeySystemServiceByCallback enter.");
65 int32_t currentPid = IPCSkeleton::GetCallingPid();
66 DRM_DEBUG_LOG("MediaKeySystemService GetCallingPID: %{public}d", currentPid);
67 {
68 std::lock_guard<std::mutex> lock(sessionsSetMutex_);
69 for (auto it = sessionsSet_.begin(); it != sessionsSet_.end();) {
70 if ((*it) != nullptr) {
71 (*it)->CloseMediaKeySessionServiceByCallback();
72 }
73 it = sessionsSet_.erase(it);
74 }
75 sessionsSet_.clear();
76 }
77 std::lock_guard<std::recursive_mutex> lock(mutex_);
78 // release itself
79 if (hdiKeySystem_ != nullptr) {
80 DRM_ERR_LOG("hdiKeySystem_ CloseHdiMediaKeySession");
81 hdiKeySystem_->Destroy();
82 hdiKeySystem_ = nullptr;
83 }
84 keySystemOperatoersCallback_ = nullptr;
85 return DRM_OK;
86 }
87
Release()88 int32_t MediaKeySystemService::Release()
89 {
90 DRM_INFO_LOG("Release enter.");
91 int32_t currentPid = IPCSkeleton::GetCallingPid();
92 DRM_DEBUG_LOG("MediaKeySystemService GetCallingPID: %{public}d", currentPid);
93 std::lock_guard<std::recursive_mutex> lock(mutex_);
94 if (keySystemOperatoersCallback_ != nullptr) {
95 keySystemOperatoersCallback_->CloseMediaKeySystemService(this);
96 }
97 return DRM_OK;
98 }
99
SetMediaKeySystemServiceOperatorsCallback( wptr<IMediaKeySystemServiceOperatorsCallback> callback)100 int32_t MediaKeySystemService::SetMediaKeySystemServiceOperatorsCallback(
101 wptr<IMediaKeySystemServiceOperatorsCallback> callback)
102 {
103 std::lock_guard<std::recursive_mutex> lock(mutex_);
104 if (callback.promote() == nullptr) {
105 DRM_ERR_LOG("SetMediaKeySystemServiceOperatorsCallback callback is null");
106 return DRM_INVALID_ARG;
107 }
108 keySystemOperatoersCallback_ = callback;
109 return DRM_OK;
110 }
111
GenerateKeySystemRequest(std::vector<uint8_t> &request, std::string &defaultUrl)112 int32_t MediaKeySystemService::GenerateKeySystemRequest(std::vector<uint8_t> &request, std::string &defaultUrl)
113 {
114 DrmTrace trace("MediaKeySystemService::GenerateKeySystemRequest");
115 DRM_INFO_LOG("GenerateKeySystemRequest enter.");
116 int32_t ret = DRM_OK;
117 std::lock_guard<std::recursive_mutex> lock(mutex_);
118 DRM_CHECK_AND_RETURN_RET_LOG(hdiKeySystem_ != nullptr, DRM_SERVICE_FATAL_ERROR,
119 "hdiKeySystem_ is nullptr!");
120 auto timeBefore = std::chrono::system_clock::now();
121 ret = hdiKeySystem_->GenerateKeySystemRequest(defaultUrl, request);
122 generationDuration_ = CalculateTimeDiff(timeBefore, std::chrono::system_clock::now());
123 if (ret != DRM_OK) {
124 DRM_ERR_LOG("GenerateKeySystemRequest failed.");
125 ReportFaultEvent(ret, "GenerateKeySystemRequest failed", "");
126 generationResult_ = "failed";
127 return ret;
128 }
129 generationResult_ = "success";
130 return ret;
131 }
132
ProcessKeySystemResponse(const std::vector<uint8_t> &response)133 int32_t MediaKeySystemService::ProcessKeySystemResponse(const std::vector<uint8_t> &response)
134 {
135 DrmTrace trace("MediaKeySystemService::ProcessKeySystemResponse");
136 DRM_INFO_LOG("ProcessKeySystemResponse enter.");
137 int32_t ret = DRM_OK;
138 std::lock_guard<std::recursive_mutex> lock(mutex_);
139 DRM_CHECK_AND_RETURN_RET_LOG(hdiKeySystem_ != nullptr, DRM_SERVICE_FATAL_ERROR,
140 "hdiKeySystem_ is nullptr!");
141 auto timeBefore = std::chrono::system_clock::now();
142 ret = hdiKeySystem_->ProcessKeySystemResponse(response);
143 uint32_t processDuration = CalculateTimeDiff(timeBefore, std::chrono::system_clock::now());
144 if (ret != DRM_OK) {
145 DRM_ERR_LOG("ProcessKeySystemResponse failed.");
146 std::string responseString = std::string(reinterpret_cast<const char*>(response.data()), response.size());
147 ReportFaultEvent(ret, "ProcessKeySystemResponse failed", responseString);
148 return ret;
149 }
150 struct DownLoadInfo downLoadInfo = InitDownLoadInfo(generationDuration_, generationResult_, processDuration,
151 "success");
152 ReportCertificateBehaviorEvent(statisticsInfo_, downLoadInfo, 0, 0, "");
153 return ret;
154 }
155
SetConfigurationString(std::string &configName, std::string &value)156 int32_t MediaKeySystemService::SetConfigurationString(std::string &configName, std::string &value)
157 {
158 DRM_INFO_LOG("SetConfiguration enter, configName:%{public}s, value:%{public}s.",
159 configName.c_str(), value.c_str());
160 DRM_CHECK_AND_RETURN_RET_LOG(configName != "bundleName", DRM_INVALID_ARG,
161 "configuration name is not support");
162 int32_t ret = DRM_OK;
163 std::lock_guard<std::recursive_mutex> lock(mutex_);
164 DRM_CHECK_AND_RETURN_RET_LOG(hdiKeySystem_ != nullptr, DRM_SERVICE_FATAL_ERROR,
165 "hdiKeySystem_ is nullptr!");
166 ret = hdiKeySystem_->SetConfigurationString(configName, value);
167 if (ret != DRM_OK) {
168 DRM_ERR_LOG("SetConfiguration failed.");
169 return ret;
170 }
171 return ret;
172 }
173
GetConfigurationString(std::string &configName, std::string &value)174 int32_t MediaKeySystemService::GetConfigurationString(std::string &configName, std::string &value)
175 {
176 DRM_INFO_LOG("GetConfiguration enter, configName:%{public}s.", configName.c_str());
177 DRM_CHECK_AND_RETURN_RET_LOG(configName != "bundleName", DRM_INVALID_ARG,
178 "configuration name is not support");
179 int32_t ret = DRM_OK;
180 std::lock_guard<std::recursive_mutex> lock(mutex_);
181 DRM_CHECK_AND_RETURN_RET_LOG(hdiKeySystem_ != nullptr, DRM_SERVICE_FATAL_ERROR,
182 "hdiKeySystem_ is nullptr!");
183
184 ret = hdiKeySystem_->GetConfigurationString(configName, value);
185 if (ret != DRM_OK) {
186 DRM_ERR_LOG("GetConfiguration failed.");
187 return ret;
188 }
189 return ret;
190 }
191
SetConfigurationByteArray(std::string &configName, std::vector<uint8_t> &value)192 int32_t MediaKeySystemService::SetConfigurationByteArray(std::string &configName, std::vector<uint8_t> &value)
193 {
194 DRM_INFO_LOG("SetConfiguration enter, configName:%{public}s.", configName.c_str());
195 DRM_CHECK_AND_RETURN_RET_LOG(configName != "bundleName", DRM_INVALID_ARG,
196 "configuration name is not support");
197 int32_t ret = DRM_OK;
198 std::lock_guard<std::recursive_mutex> lock(mutex_);
199 DRM_CHECK_AND_RETURN_RET_LOG(hdiKeySystem_ != nullptr, DRM_SERVICE_FATAL_ERROR,
200 "hdiKeySystem_ is nullptr!");
201 std::vector<uint8_t> valueVec;
202 valueVec.assign(value.begin(), value.end());
203 ret = hdiKeySystem_->SetConfigurationByteArray(configName, valueVec);
204 if (ret != DRM_OK) {
205 DRM_ERR_LOG("SetConfiguration failed.");
206 return ret;
207 }
208 return ret;
209 }
210
GetConfigurationByteArray(std::string &configName, std::vector<uint8_t> &value)211 int32_t MediaKeySystemService::GetConfigurationByteArray(std::string &configName, std::vector<uint8_t> &value)
212 {
213 DRM_INFO_LOG("GetConfiguration enter, configName:%{public}s.", configName.c_str());
214 DRM_CHECK_AND_RETURN_RET_LOG(configName != "bundleName", DRM_INVALID_ARG,
215 "configuration name is not support");
216 int32_t ret = DRM_OK;
217 std::lock_guard<std::recursive_mutex> lock(mutex_);
218 DRM_CHECK_AND_RETURN_RET_LOG(hdiKeySystem_ != nullptr, DRM_SERVICE_FATAL_ERROR,
219 "hdiKeySystem_ is nullptr!");
220 std::vector<uint8_t> valueVec;
221 ret = hdiKeySystem_->GetConfigurationByteArray(configName, valueVec);
222 if (ret != DRM_OK) {
223 DRM_ERR_LOG("GetConfiguration failed.");
224 return ret;
225 }
226 value.assign(valueVec.begin(), valueVec.end());
227 return ret;
228 }
229
CreateMediaKeySession(IMediaKeySessionService::ContentProtectionLevel securityLevel, sptr<IMediaKeySessionService> &keySessionProxy)230 int32_t MediaKeySystemService::CreateMediaKeySession(IMediaKeySessionService::ContentProtectionLevel securityLevel,
231 sptr<IMediaKeySessionService> &keySessionProxy)
232 {
233 DrmTrace trace("MediaKeySystemService::CreateMediaKeySession");
234 DRM_INFO_LOG("CreateMediaKeySession enter, securityLevel:%{public}d.", securityLevel);
235 int32_t ret = DRM_OK;
236 std::lock_guard<std::recursive_mutex> lock(mutex_);
237 DRM_CHECK_AND_RETURN_RET_LOG(hdiKeySystem_ != nullptr, DRM_SERVICE_FATAL_ERROR,
238 "hdiKeySystem_ is nullptr!");
239 sptr<MediaKeySessionService> keySessionService = nullptr;
240 sptr<OHOS::HDI::Drm::V1_0::IMediaKeySession> hdiMediaKeySession = nullptr;
241 if (currentKeySessionNumber >= KEY_SESSION_MAX_NUMBER) {
242 DRM_ERR_LOG("The number of MediaKeySession is greater than 64");
243 return DRM_MAX_SESSION_NUM_REACHED;
244 }
245 ret = hdiKeySystem_->CreateMediaKeySession((OHOS::HDI::Drm::V1_0::ContentProtectionLevel)securityLevel,
246 hdiMediaKeySession);
247 if (hdiMediaKeySession == nullptr) {
248 DRM_ERR_LOG("hdiKeySystem_ CreateMediaKeySession failed.");
249 ReportFaultEvent(DRM_SERVICE_ERROR, "CreateMediaKeySession failed", "");
250 return DRM_SERVICE_ERROR;
251 }
252 keySessionService = new (std::nothrow) MediaKeySessionService(hdiMediaKeySession, statisticsInfo_);
253 if (keySessionService == nullptr) {
254 DRM_ERR_LOG("CreateMediaKeySession allocation failed.");
255 ReportFaultEvent(DRM_ALLOC_ERROR, "CreateMediaKeySession failed", "");
256 return DRM_ALLOC_ERROR;
257 }
258 keySessionService->SetMediaKeySessionServiceOperatorsCallback(this);
259
260 int32_t pid = IPCSkeleton::GetCallingPid();
261 DRM_DEBUG_LOG("MediaKeySystemService CreateMediaKeySession GetCallingPID: %{public}d", pid);
262 {
263 std::lock_guard<std::mutex> lock(sessionsSetMutex_);
264 sessionsSet_.insert(keySessionService);
265 }
266
267 DRM_DEBUG_LOG("0x%{public}06" PRIXPTR " is Current keySessionService", FAKE_POINTER(keySessionService.GetRefPtr()));
268 keySessionProxy = keySessionService;
269 currentKeySessionNumber++;
270 return ret;
271 }
272
SetBundleName()273 int32_t MediaKeySystemService::SetBundleName()
274 {
275 DRM_INFO_LOG("SetBundleName");
276 int32_t ret = DRM_OK;
277 std::lock_guard<std::recursive_mutex> lock(mutex_);
278 DRM_CHECK_AND_RETURN_RET_LOG(hdiKeySystem_ != nullptr, DRM_SERVICE_FATAL_ERROR,
279 "hdiKeySystem_ is nullptr!");
280 DRM_CHECK_AND_RETURN_RET_LOG(!statisticsInfo_.bundleName.empty(), DRM_UNKNOWN_ERROR,
281 "bundle name is empty!");
282 ret = hdiKeySystem_->SetConfigurationString("bundleName", statisticsInfo_.bundleName);
283 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "SetBundleName failed.");
284 return ret;
285 }
286
CloseMediaKeySessionService(sptr<MediaKeySessionService> sessionService)287 int32_t MediaKeySystemService::CloseMediaKeySessionService(sptr<MediaKeySessionService> sessionService)
288 {
289 DRM_INFO_LOG("CloseMediaKeySessionService enter.");
290 int32_t ret = DRM_OK;
291 int32_t currentPid = IPCSkeleton::GetCallingPid();
292 DRM_DEBUG_LOG("MediaKeySystemService GetCallingPID: %{public}d", currentPid);
293 std::lock_guard<std::recursive_mutex> lock(mutex_);
294
295 if (sessionService != nullptr) {
296 DRM_INFO_LOG("MediaKeySystemService call CloseMediaKeySessionServiceByCallback ");
297 ret = sessionService->CloseMediaKeySessionServiceByCallback();
298 }
299 {
300 std::lock_guard<std::mutex> lock(sessionsSetMutex_);
301 sessionsSet_.erase(sessionService);
302 if (currentKeySessionNumber > 0) {
303 currentKeySessionNumber--;
304 }
305 }
306 sessionService = nullptr;
307 return ret;
308 }
309
GetStatistics(std::vector<IMediaKeySystemService::MetircKeyValue> &metrics)310 int32_t MediaKeySystemService::GetStatistics(std::vector<IMediaKeySystemService::MetircKeyValue> &metrics)
311 {
312 DRM_INFO_LOG("GetStatistics enter");
313 int32_t ret = DRM_OK;
314 std::lock_guard<std::recursive_mutex> lock(mutex_);
315 DRM_CHECK_AND_RETURN_RET_LOG(hdiKeySystem_ != nullptr, DRM_SERVICE_FATAL_ERROR,
316 "hdiKeySystem_ is nullptr!");
317 std::map<std::string, std::string> tmpStatistics;
318 ret = hdiKeySystem_->GetStatistics(tmpStatistics);
319 if (ret != DRM_OK) {
320 DRM_ERR_LOG("GetStatistics failed.");
321 return ret;
322 }
323 for (auto it = tmpStatistics.begin(); it != tmpStatistics.end(); it++) {
324 IMediaKeySystemService::MetircKeyValue keyValue;
325 keyValue.name = it->first;
326 keyValue.value = it->second;
327 metrics.push_back(keyValue);
328 }
329 if (metrics.size() == 0) {
330 DRM_ERR_LOG("GetStatistics failed.");
331 return DRM_ERROR;
332 }
333 return ret;
334 }
335
GetMaxContentProtectionLevel( IMediaKeySessionService::ContentProtectionLevel *securityLevel)336 int32_t MediaKeySystemService::GetMaxContentProtectionLevel(
337 IMediaKeySessionService::ContentProtectionLevel *securityLevel)
338 {
339 DRM_INFO_LOG("GetMaxContentProtectionLevel enter.");
340 int32_t ret = DRM_OK;
341 OHOS::HDI::Drm::V1_0::ContentProtectionLevel level;
342 std::lock_guard<std::recursive_mutex> lock(mutex_);
343 DRM_CHECK_AND_RETURN_RET_LOG(hdiKeySystem_ != nullptr, DRM_SERVICE_FATAL_ERROR,
344 "hdiKeySystem_ is nullptr!");
345
346 ret = hdiKeySystem_->GetMaxContentProtectionLevel(level);
347 if (ret != DRM_OK) {
348 DRM_ERR_LOG("GetMaxContentProtectionLevel failed.");
349 return ret;
350 }
351 *securityLevel = (IMediaKeySessionService::ContentProtectionLevel)level;
352 return ret;
353 }
354
GetCertificateStatus(IMediaKeySystemService::CertificateStatus *certStatus)355 int32_t MediaKeySystemService::GetCertificateStatus(IMediaKeySystemService::CertificateStatus *certStatus)
356 {
357 DRM_INFO_LOG("GetCertificateStatus enter.");
358 int32_t ret = DRM_OK;
359 std::lock_guard<std::recursive_mutex> lock(mutex_);
360 DRM_CHECK_AND_RETURN_RET_LOG(hdiKeySystem_ != nullptr, DRM_SERVICE_FATAL_ERROR,
361 "hdiKeySystem_ is nullptr!");
362
363 OHOS::HDI::Drm::V1_0::CertificateStatus tmpStatus;
364 ret = hdiKeySystem_->GetOemCertificateStatus(tmpStatus);
365 if (ret != DRM_OK) {
366 DRM_ERR_LOG("GetCertificateStatus failed.");
367 return ret;
368 }
369 *certStatus = (IMediaKeySystemService::CertificateStatus)tmpStatus;
370
371 return ret;
372 }
373
GetOfflineMediaKeyIds(std::vector<std::vector<uint8_t>> &licenseIds)374 int32_t MediaKeySystemService::GetOfflineMediaKeyIds(std::vector<std::vector<uint8_t>> &licenseIds)
375 {
376 DRM_INFO_LOG("GetOfflineMediaKeyIds enter.");
377 int32_t ret = DRM_OK;
378 std::lock_guard<std::recursive_mutex> lock(mutex_);
379 DRM_CHECK_AND_RETURN_RET_LOG(hdiKeySystem_ != nullptr, DRM_SERVICE_FATAL_ERROR,
380 "hdiKeySystem_ is nullptr!");
381
382 ret = hdiKeySystem_->GetOfflineMediaKeyIds(licenseIds);
383 if (ret != DRM_OK) {
384 DRM_ERR_LOG("GetOfflineMediaKeyIds failed.");
385 return ret;
386 }
387
388 return ret;
389 }
390
GetOfflineMediaKeyStatus(std::vector<uint8_t> &licenseId, IMediaKeySessionService::OfflineMediaKeyStatus &status)391 int32_t MediaKeySystemService::GetOfflineMediaKeyStatus(std::vector<uint8_t> &licenseId,
392 IMediaKeySessionService::OfflineMediaKeyStatus &status)
393 {
394 DRM_INFO_LOG("GetOfflineMediaKeyStatus enter.");
395 int32_t ret = DRM_OK;
396 std::lock_guard<std::recursive_mutex> lock(mutex_);
397 DRM_CHECK_AND_RETURN_RET_LOG(hdiKeySystem_ != nullptr, DRM_SERVICE_FATAL_ERROR,
398 "hdiKeySystem_ is nullptr!");
399
400 OHOS::HDI::Drm::V1_0::OfflineMediaKeyStatus offlineMediaKeyStatus;
401 ret = hdiKeySystem_->GetOfflineMediaKeyStatus(licenseId, offlineMediaKeyStatus);
402 if (ret != DRM_OK) {
403 DRM_ERR_LOG("GetOfflineMediaKeyStatus failed.");
404 return ret;
405 }
406 status = (IMediaKeySessionService::OfflineMediaKeyStatus)offlineMediaKeyStatus;
407
408 return ret;
409 }
410
ClearOfflineMediaKeys(std::vector<uint8_t> &licenseId)411 int32_t MediaKeySystemService::ClearOfflineMediaKeys(std::vector<uint8_t> &licenseId)
412 {
413 DRM_INFO_LOG("ClearOfflineMediaKeys enter.");
414 int32_t ret = DRM_OK;
415 std::lock_guard<std::recursive_mutex> lock(mutex_);
416 DRM_CHECK_AND_RETURN_RET_LOG(hdiKeySystem_ != nullptr, DRM_SERVICE_FATAL_ERROR,
417 "hdiKeySystem_ is nullptr!");
418
419 ret = hdiKeySystem_->ClearOfflineMediaKeys(licenseId);
420 if (ret != DRM_OK) {
421 DRM_ERR_LOG("ClearOfflineMediaKeys failed.");
422 return ret;
423 }
424
425 return ret;
426 }
427
SetCallback(sptr<IMediaKeySystemServiceCallback> &callback)428 int32_t MediaKeySystemService::SetCallback(sptr<IMediaKeySystemServiceCallback> &callback)
429 {
430 DRM_INFO_LOG("SetCallback enter");
431 int32_t ret = DRM_ERROR;
432 std::lock_guard<std::recursive_mutex> lock(mutex_);
433 DRM_CHECK_AND_RETURN_RET_LOG(hdiKeySystem_ != nullptr, DRM_SERVICE_FATAL_ERROR,
434 "hdiKeySystem_ is nullptr!");
435 if (callback == nullptr) {
436 DRM_ERR_LOG("SetCallback callback is nullptr.");
437 return ret;
438 }
439 callback_ = callback;
440
441 if (hdiKeySystem_ != nullptr) {
442 return hdiKeySystem_->SetCallback(this);
443 }
444 DRM_ERR_LOG("SetCallback hdiKeySystem_ is nullptr.");
445 return ret;
446 }
447
SendEvent(OHOS::HDI::Drm::V1_0::EventType eventType, int32_t extra, const std::vector<uint8_t> &data)448 int32_t MediaKeySystemService::SendEvent(OHOS::HDI::Drm::V1_0::EventType eventType, int32_t extra,
449 const std::vector<uint8_t> &data)
450 {
451 DRM_INFO_LOG("SendEvent enter.");
452 DrmEventType event = static_cast<DrmEventType>(eventType);
453 std::lock_guard<std::recursive_mutex> lock(mutex_);
454 if (callback_ != nullptr) {
455 return callback_->SendEvent(event, extra, data);
456 }
457 DRM_INFO_LOG("SendEvent failed because callback is nullptr");
458 return DRM_OPERATION_NOT_ALLOWED;
459 }
460
GetPluginName()461 std::string MediaKeySystemService::GetPluginName()
462 {
463 std::lock_guard<std::recursive_mutex> lock(mutex_);
464 return statisticsInfo_.pluginName;
465 }
466
GetSessionsDumpInfo()467 std::string MediaKeySystemService::GetSessionsDumpInfo()
468 {
469 DRM_INFO_LOG("GetSessionsDumpInfo enter");
470 std::string dumpInfo;
471 std::lock_guard<std::mutex> lock(sessionsSetMutex_);
472 dumpInfo += "Total MediaKeySession Num: " + std::to_string(sessionsSet_.size()) + "\n";
473 uint32_t sessionNum = 0;
474 for (auto &session : sessionsSet_) {
475 sessionNum++;
476 dumpInfo += "#### MediaKeySession " + std::to_string(sessionNum) + " ####\n";
477 if (session != nullptr) {
478 dumpInfo += session->GetDecryptModuleDumpInfo();
479 }
480 }
481 return dumpInfo;
482 }
483
getMediaKeySystem()484 sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystem> MediaKeySystemService::getMediaKeySystem()
485 {
486 std::lock_guard<std::recursive_mutex> lock(mutex_);
487 return hdiKeySystem_;
488 }
489
490 } // DrmStandard
491 } // OHOS
492