• 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 #ifndef OHOS_DRM_MEDIA_KEY_SYSTEM_SERVICE_H
17 #define OHOS_DRM_MEDIA_KEY_SYSTEM_SERVICE_H
18 
19 #include <iostream>
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 #include <vector>
24 #include <set>
25 #include <unordered_set>
26 #include <refbase.h>
27 #include "media_key_system_service_stub.h"
28 #include "key_session_service.h"
29 #include "drm_dfx_utils.h"
30 #include "drm_host_manager.h"
31 #include "drm_log.h"
32 #include "iremote_stub.h"
33 #include "system_ability.h"
34 
35 #include "v1_0/media_key_session_proxy.h"
36 #include "v1_0/media_key_system_proxy.h"
37 
38 namespace OHOS {
39 namespace DrmStandard {
40 using namespace OHOS::HDI::Drm::V1_0;
41 using namespace OHOS::HDI;
42 class IMediaKeySystemServiceOperatorsCallback;
43 class MediaKeySystemService : public MediaKeySystemServiceStub,
44     public DrmHostManager::StatusCallback,
45     public IMediaKeySessionServiceOperatorsCallback,
46     public IMediaKeySystemCallback {
47 public:
48     explicit MediaKeySystemService(sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystem> hdiKeySystem);
49     explicit MediaKeySystemService(sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystem> hdiKeySystem,
50         StatisticsInfo statisticsInfo);
51     ~MediaKeySystemService() override;
52     int32_t Release() override;
53     int32_t SetMediaKeySystemServiceOperatorsCallback(wptr<IMediaKeySystemServiceOperatorsCallback> callback);
54     int32_t CloseMediaKeySystemServiceByCallback();
55     int32_t SetConfigurationString(const std::string &configName, const std::string &value) override;
56     int32_t GetConfigurationString(const std::string &configName, std::string &value) override;
57     int32_t SetConfigurationByteArray(const std::string &configName, const std::vector<uint8_t> &value) override;
58     int32_t GetConfigurationByteArray(const std::string &configName, std::vector<uint8_t> &value) override;
59     int32_t GetMaxContentProtectionLevel(ContentProtectionLevel &securityLevel) override;
60     int32_t CreateMediaKeySession(ContentProtectionLevel securityLevel,
61         sptr<IMediaKeySessionService> &keySessionProxy) override;
62     int32_t GenerateKeySystemRequest(std::vector<uint8_t> &request, std::string &defaultUrl) override;
63     int32_t ProcessKeySystemResponse(const std::vector<uint8_t> &response) override;
64     int32_t GetCertificateStatus(CertificateStatus &certStatus) override;
65 
66     int32_t GetOfflineMediaKeyIds(std::vector<std::vector<uint8_t>> &licenseIds) override;
67     int32_t GetOfflineMediaKeyStatus(const std::vector<uint8_t> &licenseId,
68         OfflineMediaKeyStatus &status) override;
69     int32_t ClearOfflineMediaKeys(const std::vector<uint8_t> &licenseId) override;
70 
71     int32_t CloseMediaKeySessionService(sptr<MediaKeySessionService> sessionService) override;
72     int32_t GetStatistics(std::vector<MetircKeyValue> &metrics) override;
73     int32_t SetCallback(const sptr<IMediaKeySystemServiceCallback> &callback) override;
74     std::string GetPluginName();
75     sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystem> getMediaKeySystem();
76     int32_t SetBundleName();
77     int32_t SetApiTargetVersion();
78 
79     // for hdi callback
80     int32_t SendEvent(OHOS::HDI::Drm::V1_0::EventType eventType, int32_t extra,
81         const std::vector<uint8_t> &data) override;
82     std::string GetSessionsDumpInfo();
83 
84 private:
85     void OnDrmPluginDied(std::string &name) override;
86     std::recursive_mutex mutex_;
87     std::recursive_mutex callbackMutex_;
88     sptr<IMediaKeySystemServiceCallback> callback_;
89     wptr<IMediaKeySystemServiceOperatorsCallback> keySystemOperatoersCallback_;
90     std::mutex sessionsSetMutex_;
91     std::set<sptr<MediaKeySessionService>> sessionsSet_;
92     sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystem> hdiKeySystem_;
93     StatisticsInfo statisticsInfo_;
94     std::string generationResult_;
95     uint32_t generationDuration_ = 0;
96     uint32_t currentKeySessionNumber = 0;
97 };
98 
99 class IMediaKeySystemServiceOperatorsCallback : public virtual RefBase {
100 public:
101     IMediaKeySystemServiceOperatorsCallback() = default;
102     virtual ~IMediaKeySystemServiceOperatorsCallback() = default;
103     virtual int32_t CloseMediaKeySystemService(sptr<MediaKeySystemService> mediaKeySystemService) = 0;
104 };
105 } // DrmStandard
106 } // OHOS
107 
108 #endif // OHOS_DRM_MEDIA_KEY_SYSTEM_SERVICE_H