• 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_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     void GetDecryptTimeAsString(std::vector<std::vector<double>> &topThreeTimes,
70         std::string &decryptTimes);
71 
72 private:
73     int32_t GetOfflineKeyFromFile();
74     int32_t SetOfflineKeyToFile();
75     static void GetDecryptMaxTimes(double time, std::vector<double> &topThreeTimes);
76     std::map<std::string, std::vector<uint8_t>> configuration_;
77     std::map<std::string, std::string> configurationString_;
78     std::map<sptr<MediaKeySessionService>, bool> mediaKeySessionMap_;
79     std::mutex mediaKeySessionMutex_;
80     sptr<MediaKeySystemServiceCallback> systemCallback_;
81     std::mutex offlineKeyMutex_;
82     std::map<std::string, std::string> offlineKeyIdAndKeyValueBase64_;
83     const char* offlineKeyFileName = "/data/local/traces/offline_key.txt";
84     const int keyIdMaxLength = 255;
85     const std::string currentSessionNumName = "currentSessionNum";
86     const std::string versionName = "version";
87     const std::string decryptNumberName = "decryptNumber";
88     const std::string errorDecryptNumberName = "errorDecryptNumber";
89     const std::string decryptTime = "decryptTimes";
90     OHOS::sptr<MediaKeySystemCallbackService> vdiCallbackObj;
91 };
92 class MediaKeySystemServiceCallback : public virtual RefBase {
93 public:
94     MediaKeySystemServiceCallback() = default;
95     virtual ~MediaKeySystemServiceCallback() = default;
96     virtual int32_t CloseMediaKeySystemService(sptr<MediaKeySystemService> mediaKeySystem) = 0;
97 };
98 } // V1_0
99 } // Drm
100 } // HDI
101 } // OHOS
102 
103 #endif // OHOS_HDI_DRM_V1_0_MEDIAKEYSYSTEMSERVICE_H