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_MEDIAKEYSESSIONSERVICE_H 17 #define OHOS_HDI_DRM_V1_0_MEDIAKEYSESSIONSERVICE_H 18 19 #include "v1_0/imedia_key_session.h" 20 #include "v1_0/media_decrypt_module_service.h" 21 #include "v1_0/media_key_session_callback_service.h" 22 #include "v1_0/media_key_system_types.h" 23 #include "media_key_session_callback_service.h" 24 #include "session.h" 25 #include <mutex> 26 #include <map> 27 #include <sys/stat.h> 28 #include <sys/types.h> 29 30 namespace OHOS { 31 namespace HDI { 32 namespace Drm { 33 namespace V1_0 { 34 class KeySessionServiceCallback; 35 class MediaKeySessionService : public OHOS::HDI::Drm::V1_0::IMediaKeySession { 36 public: 37 MediaKeySessionService(); 38 MediaKeySessionService(ContentProtectionLevel level); 39 virtual ~MediaKeySessionService() = default; 40 41 int32_t GenerateMediaKeyRequest(const MediaKeyRequestInfo &mediaKeyRequestInfo, 42 MediaKeyRequest &mediaKeyRequest) override; 43 44 int32_t ProcessMediaKeyResponse(const std::vector<uint8_t> &mediaKeyResponse, 45 std::vector<uint8_t> &mediaKeyId) override; 46 47 int32_t CheckMediaKeyStatus(std::map<std::string, std::string> &mediaKeyStatus) override; 48 49 int32_t ClearMediaKeys() override; 50 51 int32_t GetOfflineReleaseRequest(const std::vector<uint8_t> &mediaKeyId, 52 std::vector<uint8_t> &releaseRequest) override; 53 54 int32_t ProcessOfflineReleaseResponse(const std::vector<uint8_t> &mediaKeyId, 55 const std::vector<uint8_t> &response) override; 56 57 int32_t RestoreOfflineMediaKeys(const std::vector<uint8_t> &mediaKeyId) override; 58 59 int32_t GetContentProtectionLevel(ContentProtectionLevel &level) override; 60 61 int32_t RequiresSecureDecoderModule(const std::string &mimeType, bool &required) override; 62 63 int32_t SetCallback(const sptr<OHOS::HDI::Drm::V1_0::IMediaKeySessionCallback> &sessionCallback) override; 64 65 int32_t GetMediaDecryptModule(sptr<OHOS::HDI::Drm::V1_0::IMediaDecryptModule> &decryptModule) override; 66 67 int32_t Destroy() override; 68 69 int32_t Init(); 70 int32_t GetDecryptNumber(); 71 int32_t GetErrorDecryptNumber(); 72 int32_t SetKeySessionServiceCallback(sptr<KeySessionServiceCallback> callback); 73 sptr<Session> session_; 74 75 private: 76 int32_t GetOfflineKeyFromFile(); 77 int32_t SetOfflineKeyToFile(); 78 ContentProtectionLevel level_; 79 sptr<OHOS::HDI::Drm::V1_0::MediaDecryptModuleService> decryptModule_; 80 sptr<KeySessionServiceCallback> sessionCallback_; 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 OHOS::sptr<MediaKeySessionCallbackService> vdiCallbackObj; 86 }; 87 class KeySessionServiceCallback : public virtual RefBase { 88 public: 89 KeySessionServiceCallback() = default; 90 virtual ~KeySessionServiceCallback() = default; 91 virtual int32_t CloseKeySessionService(sptr<MediaKeySessionService> mediaKeySession) = 0; 92 }; 93 } // V1_0 94 } // Drm 95 } // HDI 96 } // OHOS 97 98 #endif // OHOS_HDI_DRM_V1_0_MEDIAKEYSESSIONSERVICE_H