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 CALL_EARTHQUAKE_ALARM_SUBSCRIBER_H 17 #define CALL_EARTHQUAKE_ALARM_SUBSCRIBER_H 18 19 #include <mutex> 20 #include <unordered_map> 21 #include <memory> 22 23 #include "common_event_manager.h" 24 #include "common_event_subscribe_info.h" 25 #include "common_event_subscriber.h" 26 #include "common_event_support.h" 27 #include "matching_skills.h" 28 #include "system_ability_definition.h" 29 #include "uri.h" 30 #include "iservice_registry.h" 31 #include "telephony_errors.h" 32 #include "want.h" 33 #include "datashare_helper.h" 34 #include "datashare_predicates.h" 35 #include "rdb_errno.h" 36 #include "singleton.h" 37 #include "system_ability_status_change_stub.h" 38 #include "call_earthquake_alarm_locator.h" 39 #include "call_manager_inner_type.h" 40 #include "os_account_manager_wrapper.h" 41 #include "securec.h" 42 43 namespace OHOS { 44 namespace Telephony { 45 class LocationSubscriber : public EventFwk::CommonEventSubscriber { 46 public: 47 LocationSubscriber() = default; 48 explicit LocationSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo); 49 virtual ~LocationSubscriber() = default; 50 virtual void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override; 51 static bool Subscriber(void); 52 public: 53 static const std::string SWITCH_STATE_CHANGE_EVENTS; 54 static const std::string SWITCH_STATE_START; 55 static const std::string SWITCH_STATE_STOP; 56 static const std::string SWITCH_STATE; 57 static std::shared_ptr<LocationSubscriber> subscriber_; 58 static const std::string SWITCH_STATE_KEY; 59 }; 60 61 class DataShareSwitchState { 62 public: 63 DataShareSwitchState(); 64 int32_t QueryData(Uri& uri, const std::string& key, std::string& values); 65 bool RegisterListenSettingsKey(std::string key, bool isReg, sptr<AAFwk::IDataAbilityObserver> callback); 66 67 public: 68 static const int TELEPHONY_SUCCESS; 69 static const int INVALID_VALUE; 70 const std::string DEFAULT_URI = 71 "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key="; 72 private: 73 std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper(int systemAbilityId); 74 std::shared_ptr<DataShare::DataShareHelper> datashareHelper_ = nullptr; 75 }; 76 77 class LocationSystemAbilityListener : public SystemAbilityStatusChangeStub { 78 public: 79 LocationSystemAbilityListener() = default; 80 ~LocationSystemAbilityListener() = default; 81 void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 82 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 83 static bool SystemAbilitySubscriber(); 84 static bool GetSystemAbility(int32_t systemAbilityId); 85 86 private: 87 std::mutex mutex_; 88 bool startService = false; 89 static sptr<ISystemAbilityStatusChange> statusChangeListener_; 90 static std::map<int32_t, bool> systemAbilityStatus; 91 }; 92 } // namespace Telephony 93 } // namespace OHOS 94 #endif // CALL_MANAGER_SERVICE_SUBSCRIBER_H