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_LOCATOR_H 17 #define CALL_EARTHQUAKE_ALARM_LOCATOR_H 18 19 #include <iostream> 20 #include <memory> 21 #include <map> 22 23 #include "request_config.h" 24 #include "location.h" 25 #include "locator.h" 26 #include "i_locator_callback.h" 27 #include "locator_impl.h" 28 #include "location_log.h" 29 #include "iremote_stub.h" 30 #include "call_earthquake_alarm_subscriber.h" 31 #include "ability_connect_callback_interface.h" 32 #include "telephony_permission.h" 33 #include "os_account_manager.h" 34 #include "telephony_log_wrapper.h" 35 #include "call_connect_ability.h" 36 #include "ability_manager_client.h" 37 #include "call_ability_connect_callback.h" 38 #include "call_number_utils.h" 39 #include "int_wrapper.h" 40 #include "string_wrapper.h" 41 #include "call_ability_report_proxy.h" 42 #include "call_object_manager.h" 43 #include "data_ability_observer_stub.h" 44 #include "call_base.h" 45 46 namespace OHOS { 47 namespace Telephony { 48 49 class OOBESwitchObserver : public AAFwk::DataAbilityObserverStub { 50 public: OOBESwitchObserver(std::string key)51 OOBESwitchObserver(std::string key) : mKey(key) {}; 52 virtual ~OOBESwitchObserver() = default; 53 void OnChange() override; 54 static std::map<std::string, bool> keyStatus; 55 56 private: 57 std::string mKey = ""; 58 std::string mValue = ""; 59 static std::mutex mutex_; 60 }; 61 62 class MyLocationEngine { 63 public: 64 MyLocationEngine(); 65 virtual ~MyLocationEngine(); 66 void OnInit(); 67 void SetValue(); 68 void RegisterLocationChange(); 69 void UnregisterLocationChange(); 70 void RegisterSwitchCallback(); 71 void UnRegisterSwitchCallback(); 72 void LocationSwitchChange(); 73 static void OOBEComplete(); 74 static void BootComplete(bool switchState); 75 static bool IsSwitchOn(std::string key, std::string& value); 76 static std::shared_ptr<MyLocationEngine> GetInstance(); 77 static void StartEccService(sptr<CallBase> call, const CallDetailInfo &info); 78 static void StopEccService(int32_t callId); 79 static void ConnectAbility(std::string value, sptr<AAFwk::IAbilityConnection>& callback, AAFwk::Want& want); 80 private: 81 class MyLocationCallBack : public IRemoteStub<Location::ILocatorCallback> { 82 public: 83 MyLocationCallBack(); 84 virtual void OnLocationReport(const std::unique_ptr<Location::Location>& location) override; 85 virtual void OnLocatingStatusChange(const int status) override; 86 virtual void OnErrorReport(const int errorCode) override; 87 int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, 88 MessageOption &option) override; 89 }; 90 //class MyLoctionCallBack 91 92 class MySwitchCallback : public IRemoteStub<Location::ISwitchCallback> { 93 public: 94 explicit MySwitchCallback(std::shared_ptr<MyLocationEngine> locationUpdate); 95 virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, 96 MessageOption &option) override; 97 void OnSwitchChange(const int state) override; 98 private: 99 std::shared_ptr<MyLocationEngine> locationUpdate_ = nullptr; 100 }; 101 private: 102 std::unique_ptr<Location::RequestConfig> requestConfig = nullptr; 103 std::shared_ptr<Location::LocatorImpl> locatorImpl = nullptr; 104 sptr<MyLocationCallBack> locatorCallback_ = nullptr; 105 sptr<MySwitchCallback> switchCallback_ = nullptr; 106 bool locationEnabled_ = false; 107 static std::shared_ptr<MyLocationEngine> mylocator; 108 static const int DISTANCE_INTERVAL; 109 static const int TIMER_INTERVAL; 110 static const std::string EMERGENCY_DEVICE_ID; 111 static const std::string EMERGENCY_BUNDLE_NAME; 112 static const std::string EMERGENCY_ABILITY_NAME; 113 static const std::string EMERGENCY_ABILITY_NAME_ECC; 114 static const std::string PARAMETERS_VALUE; 115 static const char* PARAMETERS_KEY; 116 static const char* PARAMETERS_KEY_PHONE_NUMBER; 117 static const char* PARAMETERS_KEY_SLOTID; 118 static const std::string ALARM_SWITCH_ON; 119 static const std::string ALARM_SWITCH_OFF; 120 121 public: 122 static const std::string INITIAL_FIRST_VALUE; 123 static const std::string PARAMETERS_VALUE_ECC; 124 static const std::string PARAMETERS_VALUE_OOBE; 125 static std::map<std::string, sptr<AAFwk::IDataAbilityObserver>> settingsCallbacks; 126 }; 127 //class MyLocationCallBack 128 129 class EmergencyCallConnectCallback : public IRemoteStub<AAFwk::IAbilityConnection> { 130 public: 131 EmergencyCallConnectCallback() = default; 132 ~EmergencyCallConnectCallback() = default; 133 void OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, 134 int resultCode); 135 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode); 136 static sptr<AAFwk::IAbilityConnection> connectCallback_; 137 static sptr<AAFwk::IAbilityConnection> connectCallbackEcc; 138 static bool isStartEccService; 139 static std::mutex mutex_; 140 static int32_t nowCallId; 141 }; 142 143 } // namespace Telephony 144 } // namespace OHOS 145 #endif // CALL_MANAGER_SERVICE_LOCATOR_H