• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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_HDI_DRM_V1_0_MEDIAKEYSYSTEMSERVICE_H
17 #define OHOS_HDI_DRM_V1_0_MEDIAKEYSYSTEMSERVICE_H
18 
19 #include "v1_0/imedia_key_system.h"
20 #include "v1_0/media_key_session_service.h"
21 #include "media_key_system_callback_service.h"
22 
23 namespace OHOS {
24 namespace HDI {
25 namespace Drm {
26 namespace V1_0 {
27 class MediaKeySystemServiceCallback;
28 class MediaKeySystemService : public OHOS::HDI::Drm::V1_0::IMediaKeySystem, public KeySessionServiceCallback {
29 public:
30     MediaKeySystemService() = default;
31     virtual ~MediaKeySystemService();
32 
33     int32_t GetConfigurationString(const std::string &name, std::string &value) override;
34 
35     int32_t SetConfigurationString(const std::string &name, const std::string &value) override;
36 
37     int32_t GetConfigurationByteArray(const std::string &name, std::vector<uint8_t> &value) override;
38 
39     int32_t SetConfigurationByteArray(const std::string &name, const std::vector<uint8_t> &value) override;
40 
41     int32_t GetStatistics(std::map<std::string, std::string> &statistics) override;
42 
43     int32_t GetMaxContentProtectionLevel(ContentProtectionLevel &level) override;
44 
45     int32_t GenerateKeySystemRequest(std::string &defaultUrl, std::vector<uint8_t> &request) override;
46 
47     int32_t ProcessKeySystemResponse(const std::vector<uint8_t> &response) override;
48 
49     int32_t GetOemCertificateStatus(CertificateStatus &status) override;
50 
51     int32_t SetCallback(const sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystemCallback> &systemCallback) override;
52 
53     int32_t CreateMediaKeySession(ContentProtectionLevel level,
54         sptr<OHOS::HDI::Drm::V1_0::IMediaKeySession> &keySession) override;
55 
56     int32_t GetOfflineMediaKeyIds(std::vector<std::vector<uint8_t>> &mediaKeyIds) override;
57 
58     int32_t GetOfflineMediaKeyStatus(const std::vector<uint8_t> &mediaKeyId,
59         OfflineMediaKeyStatus &mediaKeyStatus) override;
60 
61     int32_t ClearOfflineMediaKeys(const std::vector<uint8_t> &mediaKeyId) override;
62 
63     int32_t GetOemCertificate(sptr<OHOS::HDI::Drm::V1_0::IOemCertificate> &oemCert) override;
64 
65     int32_t Destroy() override;
66 
67     int32_t SetKeySystemServiceCallback(sptr<MediaKeySystemServiceCallback> callback);
68     int32_t CloseKeySessionService(sptr<MediaKeySessionService> mediaKeySession) override;
69 
70 private:
71     int32_t GetOfflineKeyFromFile();
72     int32_t SetOfflineKeyToFile();
73     std::map<std::string, std::vector<uint8_t>> configuration_;
74     std::map<std::string, std::string> configurationString_;
75     std::map<sptr<MediaKeySessionService>, bool> mediaKeySessionMap_;
76     std::mutex mediaKeySessionMutex_;
77     sptr<MediaKeySystemServiceCallback> systemCallback_;
78     std::mutex offlineKeyMutex_;
79     std::map<std::string, std::string> offlineKeyIdAndKeyValueBase64_;
80     const char *offlineKeyFileName = "/data/local/traces/offline_key.txt";
81     const int keyIdMaxLength = 255;
82     const std::string currentSessionNumName = "currentSessionNum";
83     const std::string versionName = "version";
84     const std::string decryptNumberName = "decryptNumber";
85     const std::string errorDecryptNumberName = "errorDecryptNumber";
86     OHOS::sptr<MediaKeySystemCallbackService> vdiCallbackObj;
87 };
88 class MediaKeySystemServiceCallback : public virtual RefBase {
89 public:
90     MediaKeySystemServiceCallback() = default;
91     virtual ~MediaKeySystemServiceCallback() = default;
92     virtual int32_t CloseMediaKeySystemService(sptr<MediaKeySystemService> mediaKeySystem) = 0;
93 };
94 } // V1_0
95 } // Drm
96 } // HDI
97 } // OHOS
98 
99 #endif // OHOS_HDI_DRM_V1_0_MEDIAKEYSYSTEMSERVICE_H