• 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_SYSTEMP_IMPL_H
17 #define OHOS_DRM_MEDIA_KEY_SYSTEMP_IMPL_H
18 
19 #include "ipc_skeleton.h"
20 #include "nocopyable.h"
21 #include "drm_log.h"
22 #include "drm_death_recipient.h"
23 #include "key_session_impl.h"
24 #include "drm_listener_stub.h"
25 #include "i_mediakeysystem_service.h"
26 #include "mediakeysystem_service_callback_stub.h"
27 
28 namespace OHOS {
29 namespace DrmStandard {
30 namespace MediaKeySystemEvent {
31 const std::string EVENT_STR_PROVISION_REQUIRED = "keySystemRequired";
32 }
33 class MediaKeySystemImplCallback : public RefBase {
34 public:
35     MediaKeySystemImplCallback() = default;
36     virtual ~MediaKeySystemImplCallback() = default;
37     virtual void SendEvent(const std::string &event, int32_t extra, const std::vector<uint8_t> &data) = 0;
38 };
39 
40 class MediaKeySystemImpl : public RefBase {
41 public:
42     explicit MediaKeySystemImpl(sptr<IMediaKeySystemService> &mediaKeysystem);
43     ~MediaKeySystemImpl();
44 
45     int32_t SetConfigurationString(std::string &configName, std::string &value);
46     int32_t GetConfigurationString(std::string &configName, std::string &value);
47     int32_t SetConfigurationByteArray(std::string &configName, std::vector<uint8_t> &value);
48     int32_t GetConfigurationByteArray(std::string &configName, std::vector<uint8_t> &value);
49     int32_t CreateMediaKeySession(IMediaKeySessionService::ContentProtectionLevel securityLevel,
50         sptr<MediaKeySessionImpl> *keySessionImpl);
51     int32_t GetStatistics(std::vector<IMediaKeySystemService::MetircKeyValue> &metrics);
52     int32_t GetMaxContentProtectionLevel(IMediaKeySessionService::ContentProtectionLevel *securityLevel);
53 
54     int32_t GenerateKeySystemRequest(std::vector<uint8_t> &request, std::string &defaultUrl);
55     int32_t ProcessKeySystemResponse(const std::vector<uint8_t> &response);
56 
57     int32_t GetOfflineMediaKeyIds(std::vector<std::vector<uint8_t>> &licenseIds);
58     int32_t GetOfflineMediaKeyStatus(std::vector<uint8_t> &licenseId,
59         IMediaKeySessionService::OfflineMediaKeyStatus &status);
60     int32_t ClearOfflineMediaKeys(std::vector<uint8_t> &licenseId);
61 
62     int32_t GetCertificateStatus(IMediaKeySystemService::CertificateStatus *certStatus);
63     sptr<MediaKeySystemImplCallback> GetApplicationCallback();
64     int32_t SetCallback(const sptr<MediaKeySystemImplCallback> &callback);
65     int32_t Release();
66 
67 private:
68     void MediaKeySystemServerDied(pid_t pid);
69     std::recursive_mutex mutex_;
70     sptr<IMediaKeySystemService> serviceProxy_;
71     sptr<MediaKeySystemImplCallback> mediaKeySystemApplicationCallback_;
72     sptr<IMediaKeySystemServiceCallback> serviceCallback_;
73     sptr<DrmDeathRecipient> deathRecipient_ = nullptr;
74 };
75 
76 class MediaKeySystemCallback : public MediaKeySystemServiceCallbackStub {
77 public:
MediaKeySystemCallback()78     MediaKeySystemCallback() : systemImpl_(nullptr)
79     {
80         InitEventMap();
81     };
MediaKeySystemCallback(MediaKeySystemImpl * systemImpl)82     explicit MediaKeySystemCallback(MediaKeySystemImpl *systemImpl) : systemImpl_(systemImpl)
83     {
84         InitEventMap();
85     };
86     ~MediaKeySystemCallback();
87     void InitEventMap();
88     std::string GetEventName(DrmEventType event);
89     int32_t SendEvent(DrmEventType event, int32_t extra, const std::vector<uint8_t> &data) override;
90 
91 private:
92     std::recursive_mutex mutex_;
93     MediaKeySystemImpl *systemImpl_;
94     std::unordered_map<int32_t, std::string> eventMap_;
95 };
96 } // DrmStandard
97 } // OHOS
98 #endif // OHOS_DRM_MEDIA_KEY_SYSTEMP_IMPL_H
99