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_FACTORY_SERVICE_H 17 #define OHOS_DRM_MEDIA_KEY_SYSTEM_FACTORY_SERVICE_H 18 19 #include <iostream> 20 #include <memory> 21 #include <mutex> 22 #include <string> 23 #include <vector> 24 #include <set> 25 #include <map> 26 #include <unordered_set> 27 #include <refbase.h> 28 #include "iremote_stub.h" 29 #include "system_ability.h" 30 #include "drm_host_manager.h" 31 #include "drm_log.h" 32 #include "media_key_system_factory_service_stub.h" 33 #include "mediakeysystem_service.h" 34 #include "idrm_listener.h" 35 #include "drm_death_recipient.h" 36 37 #include "v1_0/media_key_system_factory_proxy.h" 38 #include "v1_0/media_key_system_proxy.h" 39 40 namespace OHOS { 41 namespace DrmStandard { 42 using namespace OHOS::HDI::Drm::V1_0; 43 using namespace OHOS::HDI; 44 class MediaKeySystemFactoryService : public SystemAbility, 45 public MediaKeySystemFactoryServiceStub, 46 public DrmHostManager::StatusCallback, 47 public IMediaKeySystemServiceOperatorsCallback { 48 DECLARE_SYSTEM_ABILITY(MediaKeySystemFactoryService); 49 50 public: 51 DISALLOW_COPY_AND_MOVE(MediaKeySystemFactoryService); 52 explicit MediaKeySystemFactoryService(int32_t systemAbilityId, bool runOnCreate = true); 53 ~MediaKeySystemFactoryService() override; 54 void OnDump() override; 55 void OnStart() override; 56 void OnStop() override; 57 int32_t OnIdle(const SystemAbilityOnDemandReason& idleReason) override; 58 int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override; 59 int32_t IsMediaKeySystemSupported(const std::string &name, bool &isSupported) override; 60 int32_t IsMediaKeySystemSupported(const std::string &name, const std::string &mimeType, 61 bool &isSupported) override; 62 int32_t IsMediaKeySystemSupported(const std::string &name, const std::string &mimeType, int32_t securityLevel, 63 bool &isSupported) override; 64 int32_t CreateMediaKeySystem(const std::string &name, sptr<IMediaKeySystemService> &mediaKeySystemProxy) override; 65 int32_t CloseMediaKeySystemService(sptr<MediaKeySystemService> mediaKeySystemService) override; 66 int32_t GetMediaKeySystems(std::map<std::string, std::string> &mediaKeySystemNames) override; 67 int32_t GetMediaKeySystemUuid(const std::string &name, std::string &uuid) override; 68 void OnDrmPluginDied(std::string &name) override; 69 int32_t SetListenerObject(const sptr<IRemoteObject>& object) override; 70 71 private: 72 void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 73 void InitStatisticsInfo(const sptr<IMediaKeySystem> &hdiMediaKeySystem, 74 std::string pluginName, StatisticsInfo &statisticsInfo); 75 int32_t WriteDumpInfo(int32_t fd, std::string &dumpString); 76 std::recursive_mutex mutex_; 77 sptr<DrmHostManager> drmHostManager_; 78 std::map<int32_t, std::set<sptr<MediaKeySystemService>>> mediaKeySystemForPid_; 79 std::map<std::string, int32_t> currentMediaKeySystemNum_; 80 std::recursive_mutex factoryServiceMutex_; 81 void DistroyForClientDied(pid_t pid); 82 void MediaKeySystemFactoryClientDied(pid_t pid); 83 bool IsListenerObjectSet(); 84 int32_t CancelAbilityIdle(); 85 std::map<pid_t, sptr<DrmDeathRecipient>> deathRecipientMap_; 86 std::map<pid_t, sptr<IDrmListener>> clientListenerMap_; 87 }; 88 } // DrmStandard 89 } // OHOS 90 91 #endif // OHOS_DRM_MEDIA_KEY_SYSTEM_FACTORY_SERVICE_H