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_ABILITY_RUNTIME_DMS_SA_CLIENT_H 17 #define OHOS_ABILITY_RUNTIME_DMS_SA_CLIENT_H 18 19 #include <mutex> 20 21 #include "ability_manager_client.h" 22 #include "if_system_ability_manager.h" 23 #include "iservice_registry.h" 24 #include "sam_log.h" 25 #include "system_ability_status_change_stub.h" 26 #include "system_ability_definition.h" 27 28 namespace OHOS { 29 namespace AAFwk { 30 class DmsSaClient : public SystemAbilityStatusChangeStub { 31 public: 32 static DmsSaClient &GetInstance(); 33 bool SubscribeDmsSA(); 34 int32_t AddListener(const std::string& type, const sptr<IRemoteOnListener>& listener); 35 int32_t DelListener(const std::string& type, const sptr<IRemoteOnListener>& listener); 36 void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 37 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 38 private: DmsSaClient()39 DmsSaClient() {}; ~DmsSaClient()40 ~DmsSaClient() {}; 41 bool hasSubscribeDmsSA_ = false; 42 OHOS::sptr<ISystemAbilityManager> saMgrProxy_; 43 std::map<std::string, sptr<IRemoteOnListener>> listeners_; 44 std::mutex eventMutex_; 45 }; 46 } // namespace AAFwk 47 } // namespace OHOS 48 #endif 49