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 "request_config.h" 21 #include "location.h" 22 #include "locator.h" 23 #include "i_locator_callback.h" 24 #include "locator_impl.h" 25 #include "location_log.h" 26 #include "iremote_stub.h" 27 #include <memory> 28 #include "call_earthquake_alarm_subscriber.h" 29 #include "ability_connect_callback_interface.h" 30 #include "telephony_permission.h" 31 #include "os_account_manager.h" 32 #include "telephony_log_wrapper.h" 33 #include "call_connect_ability.h" 34 #include "ability_manager_client.h" 35 #include "call_ability_connect_callback.h" 36 #include "call_number_utils.h" 37 #include "int_wrapper.h" 38 #include "string_wrapper.h" 39 #include "call_ability_report_proxy.h" 40 #include "call_object_manager.h" 41 42 namespace OHOS { 43 namespace Telephony { 44 class MyLocationEngine { 45 public: 46 MyLocationEngine(); 47 virtual ~MyLocationEngine(); 48 void OnInit(); 49 void SetValue(); 50 void RegisterLocationChange(); 51 void UnregisterLocationChange(); 52 void RegisterSwitchCallback(); 53 void UnRegisterSwitchCallback(); 54 void LocationSwitchChange(); 55 static void BootComplete(); 56 static bool IsSwitchOn(); 57 static std::shared_ptr<MyLocationEngine> GetInstance(); 58 static void ConnectAbility(); 59 static OHOS::Uri uri_q; 60 private: 61 class MyLocationCallBack : public IRemoteStub<Location::ILocatorCallback> { 62 public: 63 MyLocationCallBack(); 64 virtual void OnLocationReport(const std::unique_ptr<Location::Location>& location) override; 65 virtual void OnLocatingStatusChange(const int status) override; 66 virtual void OnErrorReport(const int errorCode) override; 67 int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, 68 MessageOption &option) override; 69 }; 70 //class MyLoctionCallBack 71 72 class MySwitchCallback : public IRemoteStub<Location::ISwitchCallback> { 73 public: 74 explicit MySwitchCallback(std::shared_ptr<MyLocationEngine> locationUpdate); 75 virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, 76 MessageOption &option) override; 77 void OnSwitchChange(const int state) override; 78 private: 79 std::shared_ptr<MyLocationEngine> locationUpdate_ = nullptr; 80 }; 81 private: 82 std::unique_ptr<Location::RequestConfig> requestConfig = nullptr; 83 std::shared_ptr<Location::LocatorImpl> locatorImpl = nullptr; 84 sptr<MyLocationCallBack> locatorCallback_ = nullptr; 85 sptr<MySwitchCallback> switchCallback_ = nullptr; 86 bool locationEnabled_ = false; 87 static std::shared_ptr<MyLocationEngine> mylocator; 88 static const int DISTANCE_INTERVAL; 89 static const int TIMER_INTERVAL; 90 static const std::string EMERGENCY_DEVICE_ID; 91 static const std::string EMERGENCY_BUNDLE_NAME; 92 static const std::string EMERGENCY_ABILITY_NAME; 93 static const std::string PARAMETERS_VALUE; 94 static const char* PARAMETERS_KEY; 95 static const std::string ALARM_SWITCH_ON; 96 static const std::string ALARM_SWITCH_OFF; 97 static std::string INITIAL_FIRST_VALUE; 98 }; 99 //class MyLocationCallBack 100 101 class EmergencyCallConnectCallback : public IRemoteStub<AAFwk::IAbilityConnection> { 102 public: 103 EmergencyCallConnectCallback() = default; 104 ~EmergencyCallConnectCallback() = default; 105 void OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, 106 int resultCode); 107 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode); 108 static sptr<AAFwk::IAbilityConnection> connectCallback_; 109 static const int CONNECT_SUCCESS; 110 }; 111 } // namespace Telephony 112 } // namespace OHOS 113 #endif // CALL_MANAGER_SERVICE_LOCATOR_H