1 /* 2 * Copyright (C) 2022 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 GEO_CONVERT_SERVICE_H 17 #define GEO_CONVERT_SERVICE_H 18 #ifdef FEATURE_GEOCODE_SUPPORT 19 20 #include <mutex> 21 #include <singleton.h> 22 #include <string> 23 #include <vector> 24 25 #include "if_system_ability_manager.h" 26 #include "iremote_object.h" 27 #include "message_parcel.h" 28 #include "message_option.h" 29 #include "system_ability.h" 30 31 #include "common_utils.h" 32 #include "constant_definition.h" 33 #include "geo_coding_mock_info.h" 34 #include "geo_convert_callback_host.h" 35 #include "geo_convert_skeleton.h" 36 37 namespace OHOS { 38 namespace Location { 39 class GeoConvertService : public SystemAbility, public GeoConvertServiceStub, DelayedSingleton<GeoConvertService> { 40 DECLEAR_SYSTEM_ABILITY(GeoConvertService); 41 42 public: 43 DISALLOW_COPY_AND_MOVE(GeoConvertService); 44 GeoConvertService(); 45 ~GeoConvertService() override; 46 void OnStart() override; 47 void OnStop() override; QueryServiceState()48 ServiceRunningState QueryServiceState() const 49 { 50 return state_; 51 } 52 int IsGeoConvertAvailable(MessageParcel &reply) override; 53 int GetAddressByCoordinate(MessageParcel &data, MessageParcel &reply) override; 54 int GetAddressByLocationName(MessageParcel &data, MessageParcel &reply) override; 55 bool EnableReverseGeocodingMock() override; 56 bool DisableReverseGeocodingMock() override; 57 LocationErrCode SetReverseGeocodingMockInfo(std::vector<std::shared_ptr<GeocodingMockInfo>>& mockInfo) override; 58 int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override; 59 void UnloadGeoConvertSystemAbility() override; 60 61 bool ConnectService(); 62 bool ReConnectService(); 63 void NotifyConnected(const sptr<IRemoteObject>& remoteObject); 64 void NotifyDisConnected(); 65 private: 66 bool Init(); 67 static void SaDumpInfo(std::string& result); 68 int RemoteToService(uint32_t code, MessageParcel &data, MessageParcel &rep); 69 void ReportAddressMock(MessageParcel &data, MessageParcel &reply); 70 bool CheckIfGeoConvertConnecting(); 71 bool WriteInfoToParcel(MessageParcel &data, MessageParcel &dataParcel, bool flag); 72 bool WriteResultToParcel(const std::list<std::shared_ptr<GeoAddress>> result, MessageParcel &reply, bool flag); 73 bool GetService(); 74 bool IsConnect(); 75 76 bool mockEnabled_ = false; 77 bool registerToService_ = false; 78 ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START; 79 std::vector<std::shared_ptr<GeocodingMockInfo>> mockInfo_; 80 std::mutex mockInfoMutex_; 81 82 std::mutex mutex_; 83 sptr<IRemoteObject> serviceProxy_ = nullptr; 84 std::condition_variable connectCondition_; 85 }; 86 } // namespace OHOS 87 } // namespace Location 88 #endif // FEATURE_GEOCODE_SUPPORT 89 #endif // GEO_CONVERT_SERVICE_H 90