15c735df2Sopenharmony_ci/* 25c735df2Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 35c735df2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 45c735df2Sopenharmony_ci * you may not use this file except in compliance with the License. 55c735df2Sopenharmony_ci * You may obtain a copy of the License at 65c735df2Sopenharmony_ci * 75c735df2Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 85c735df2Sopenharmony_ci * 95c735df2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 105c735df2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 115c735df2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125c735df2Sopenharmony_ci * See the License for the specific language governing permissions and 135c735df2Sopenharmony_ci * limitations under the License. 145c735df2Sopenharmony_ci */ 155c735df2Sopenharmony_ci#ifndef LOCATOR_IMPL_H 165c735df2Sopenharmony_ci#define LOCATOR_IMPL_H 175c735df2Sopenharmony_ci 185c735df2Sopenharmony_ci#include <vector> 195c735df2Sopenharmony_ci 205c735df2Sopenharmony_ci#include "iremote_object.h" 215c735df2Sopenharmony_ci 225c735df2Sopenharmony_ci#include "constant_definition.h" 235c735df2Sopenharmony_ci#include "country_code.h" 245c735df2Sopenharmony_ci#include "country_code_manager.h" 255c735df2Sopenharmony_ci#include "geo_address.h" 265c735df2Sopenharmony_ci#include "geo_coding_mock_info.h" 275c735df2Sopenharmony_ci#include "i_cached_locations_callback.h" 285c735df2Sopenharmony_ci#include "locator_proxy.h" 295c735df2Sopenharmony_ci#include "i_locating_required_data_callback.h" 305c735df2Sopenharmony_ci#include "locating_required_data_config.h" 315c735df2Sopenharmony_ci#include "location_data_manager.h" 325c735df2Sopenharmony_ci#include "system_ability_status_change_stub.h" 335c735df2Sopenharmony_ci#include "locationhub_ipc_interface_code.h" 345c735df2Sopenharmony_ci 355c735df2Sopenharmony_cinamespace OHOS { 365c735df2Sopenharmony_cinamespace Location { 375c735df2Sopenharmony_ciclass ICallbackResumeManager { 385c735df2Sopenharmony_cipublic: 395c735df2Sopenharmony_ci virtual ~ICallbackResumeManager() = default; 405c735df2Sopenharmony_ci virtual void ResumeCallback() = 0; 415c735df2Sopenharmony_ci}; 425c735df2Sopenharmony_ci 435c735df2Sopenharmony_ciclass LocatorSystemAbilityListener : public SystemAbilityStatusChangeStub { 445c735df2Sopenharmony_cipublic: 455c735df2Sopenharmony_ci void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 465c735df2Sopenharmony_ci void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 475c735df2Sopenharmony_ciprivate: 485c735df2Sopenharmony_ci bool needResume_ = false; 495c735df2Sopenharmony_ci std::mutex mutex_; 505c735df2Sopenharmony_ci}; 515c735df2Sopenharmony_ci 525c735df2Sopenharmony_ciclass LocatorImpl { 535c735df2Sopenharmony_cipublic: 545c735df2Sopenharmony_ci static std::shared_ptr<LocatorImpl> GetInstance(); 555c735df2Sopenharmony_ci explicit LocatorImpl(); 565c735df2Sopenharmony_ci ~LocatorImpl(); 575c735df2Sopenharmony_ci 585c735df2Sopenharmony_ci /** 595c735df2Sopenharmony_ci * @brief Obtain current location switch status. 605c735df2Sopenharmony_ci * 615c735df2Sopenharmony_ci * @return Returns true if the location switch on, returns false otherwise. 625c735df2Sopenharmony_ci */ 635c735df2Sopenharmony_ci bool IsLocationEnabled(); 645c735df2Sopenharmony_ci void ShowNotification(); 655c735df2Sopenharmony_ci void RequestPermission(); 665c735df2Sopenharmony_ci void RequestEnableLocation(); 675c735df2Sopenharmony_ci 685c735df2Sopenharmony_ci /** 695c735df2Sopenharmony_ci * @brief Enable location switch. 705c735df2Sopenharmony_ci * 715c735df2Sopenharmony_ci * @param enable Status of the location switch to be set. 725c735df2Sopenharmony_ci */ 735c735df2Sopenharmony_ci void EnableAbility(bool enable); 745c735df2Sopenharmony_ci 755c735df2Sopenharmony_ci /** 765c735df2Sopenharmony_ci * @brief Subscribe location changed. 775c735df2Sopenharmony_ci * 785c735df2Sopenharmony_ci * @param requestConfig Indicates the location request parameters. 795c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the location result. 805c735df2Sopenharmony_ci */ 815c735df2Sopenharmony_ci void StartLocating(std::unique_ptr<RequestConfig>& requestConfig, 825c735df2Sopenharmony_ci sptr<ILocatorCallback>& callback); 835c735df2Sopenharmony_ci 845c735df2Sopenharmony_ci /** 855c735df2Sopenharmony_ci * @brief Unsubscribe location changed. 865c735df2Sopenharmony_ci * 875c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the location result. 885c735df2Sopenharmony_ci */ 895c735df2Sopenharmony_ci void StopLocating(sptr<ILocatorCallback>& callback); 905c735df2Sopenharmony_ci 915c735df2Sopenharmony_ci /** 925c735df2Sopenharmony_ci * @brief Obtain last known location. 935c735df2Sopenharmony_ci * 945c735df2Sopenharmony_ci * @return The last known location information. 955c735df2Sopenharmony_ci */ 965c735df2Sopenharmony_ci std::unique_ptr<Location> GetCachedLocation(); 975c735df2Sopenharmony_ci 985c735df2Sopenharmony_ci /** 995c735df2Sopenharmony_ci * @brief Subscribe location switch changed. 1005c735df2Sopenharmony_ci * 1015c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the location switch status. 1025c735df2Sopenharmony_ci * @param uid Indicates the calling uid 1035c735df2Sopenharmony_ci * @return Return whether the registration is successful. 1045c735df2Sopenharmony_ci */ 1055c735df2Sopenharmony_ci bool RegisterSwitchCallback(const sptr<IRemoteObject>& callback, pid_t uid); 1065c735df2Sopenharmony_ci 1075c735df2Sopenharmony_ci /** 1085c735df2Sopenharmony_ci * @brief Unsubscribe location switch changed. 1095c735df2Sopenharmony_ci * 1105c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the location switch status. 1115c735df2Sopenharmony_ci * @return Return whether the deregistration is successful. 1125c735df2Sopenharmony_ci */ 1135c735df2Sopenharmony_ci bool UnregisterSwitchCallback(const sptr<IRemoteObject>& callback); 1145c735df2Sopenharmony_ci 1155c735df2Sopenharmony_ci /** 1165c735df2Sopenharmony_ci * @brief Subscribe satellite status changed. 1175c735df2Sopenharmony_ci * 1185c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the satellite status. 1195c735df2Sopenharmony_ci * @param uid Indicates the calling uid 1205c735df2Sopenharmony_ci * @return Return whether the registration is successful. 1215c735df2Sopenharmony_ci */ 1225c735df2Sopenharmony_ci bool RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid); 1235c735df2Sopenharmony_ci 1245c735df2Sopenharmony_ci /** 1255c735df2Sopenharmony_ci * @brief Unsubscribe satellite status changed. 1265c735df2Sopenharmony_ci * 1275c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the satellite status. 1285c735df2Sopenharmony_ci * @return Return whether the deregistration is successful. 1295c735df2Sopenharmony_ci */ 1305c735df2Sopenharmony_ci bool UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback); 1315c735df2Sopenharmony_ci 1325c735df2Sopenharmony_ci /** 1335c735df2Sopenharmony_ci * @brief Subscribe nmea message changed. 1345c735df2Sopenharmony_ci * 1355c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the nmea message. 1365c735df2Sopenharmony_ci * @param uid Indicates the calling uid 1375c735df2Sopenharmony_ci * @return Return whether the registration is successful. 1385c735df2Sopenharmony_ci */ 1395c735df2Sopenharmony_ci bool RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid); 1405c735df2Sopenharmony_ci 1415c735df2Sopenharmony_ci /** 1425c735df2Sopenharmony_ci * @brief Unsubscribe nmea message changed. 1435c735df2Sopenharmony_ci * 1445c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the nmea message. 1455c735df2Sopenharmony_ci * @return Return whether the deregistration is successful. 1465c735df2Sopenharmony_ci */ 1475c735df2Sopenharmony_ci bool UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback); 1485c735df2Sopenharmony_ci 1495c735df2Sopenharmony_ci /** 1505c735df2Sopenharmony_ci * @brief Registering the callback function for listening to country code changes. 1515c735df2Sopenharmony_ci * 1525c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting country code changes. 1535c735df2Sopenharmony_ci * @param uid Indicates the calling uid 1545c735df2Sopenharmony_ci * @return Return whether the registration is successful. 1555c735df2Sopenharmony_ci */ 1565c735df2Sopenharmony_ci bool RegisterCountryCodeCallback(const sptr<IRemoteObject>& callback, pid_t uid); 1575c735df2Sopenharmony_ci 1585c735df2Sopenharmony_ci /** 1595c735df2Sopenharmony_ci * @brief Unregistering the callback function for listening to country code changes. 1605c735df2Sopenharmony_ci * 1615c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting country code changes. 1625c735df2Sopenharmony_ci * @return Return whether the deregistration is successful. 1635c735df2Sopenharmony_ci */ 1645c735df2Sopenharmony_ci bool UnregisterCountryCodeCallback(const sptr<IRemoteObject>& callback); 1655c735df2Sopenharmony_ci 1665c735df2Sopenharmony_ci /** 1675c735df2Sopenharmony_ci * @brief Subscribe to cache GNSS locations update messages. 1685c735df2Sopenharmony_ci * 1695c735df2Sopenharmony_ci * @param request Indicates the cached GNSS locations request parameters. 1705c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the cached GNSS locations. 1715c735df2Sopenharmony_ci * @return Return whether the registration is successful. 1725c735df2Sopenharmony_ci */ 1735c735df2Sopenharmony_ci void RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLocationsRequest>& request, 1745c735df2Sopenharmony_ci sptr<ICachedLocationsCallback>& callback); 1755c735df2Sopenharmony_ci 1765c735df2Sopenharmony_ci /** 1775c735df2Sopenharmony_ci * @brief Unsubscribe to cache GNSS locations update messages. 1785c735df2Sopenharmony_ci * 1795c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the cached gnss locations. 1805c735df2Sopenharmony_ci * @return Return whether the deregistration is successful. 1815c735df2Sopenharmony_ci */ 1825c735df2Sopenharmony_ci void UnregisterCachedLocationCallback(sptr<ICachedLocationsCallback>& callback); 1835c735df2Sopenharmony_ci 1845c735df2Sopenharmony_ci /** 1855c735df2Sopenharmony_ci * @brief Obtain geocoding service status. 1865c735df2Sopenharmony_ci * 1875c735df2Sopenharmony_ci * @return Returns true if geocoding service is available, returns false otherwise. 1885c735df2Sopenharmony_ci */ 1895c735df2Sopenharmony_ci bool IsGeoServiceAvailable(); 1905c735df2Sopenharmony_ci 1915c735df2Sopenharmony_ci /** 1925c735df2Sopenharmony_ci * @brief Obtain address info from location. 1935c735df2Sopenharmony_ci * 1945c735df2Sopenharmony_ci * @param data Indicates the reverse geocode query parameters. 1955c735df2Sopenharmony_ci * @param replyList Indicates the result of the address info. 1965c735df2Sopenharmony_ci */ 1975c735df2Sopenharmony_ci void GetAddressByCoordinate(MessageParcel &data, std::list<std::shared_ptr<GeoAddress>>& replyList); 1985c735df2Sopenharmony_ci 1995c735df2Sopenharmony_ci /** 2005c735df2Sopenharmony_ci * @brief Obtain latitude and longitude info from location address. 2015c735df2Sopenharmony_ci * 2025c735df2Sopenharmony_ci * @param data Indicates the geocode query parameters. 2035c735df2Sopenharmony_ci * @param replyList Indicates the result of the address info. 2045c735df2Sopenharmony_ci */ 2055c735df2Sopenharmony_ci void GetAddressByLocationName(MessageParcel &data, std::list<std::shared_ptr<GeoAddress>>& replyList); 2065c735df2Sopenharmony_ci 2075c735df2Sopenharmony_ci /** 2085c735df2Sopenharmony_ci * @brief Querying location privacy protocol confirmation status. 2095c735df2Sopenharmony_ci * 2105c735df2Sopenharmony_ci * @param type Indicates location privacy protocol type. 2115c735df2Sopenharmony_ci * @return Returns true if the location privacy protocol has been confirmed, returns false otherwise. 2125c735df2Sopenharmony_ci */ 2135c735df2Sopenharmony_ci bool IsLocationPrivacyConfirmed(const int type); 2145c735df2Sopenharmony_ci 2155c735df2Sopenharmony_ci /** 2165c735df2Sopenharmony_ci * @brief Set location privacy protocol confirmation status. 2175c735df2Sopenharmony_ci * 2185c735df2Sopenharmony_ci * @param type Indicates location privacy protocol type. 2195c735df2Sopenharmony_ci * @param isConfirmed Indicates whether the location privacy protocol should be confirmed. 2205c735df2Sopenharmony_ci * @return Returns 1 if the location privacy protocol has been set, returns 0 otherwise. 2215c735df2Sopenharmony_ci */ 2225c735df2Sopenharmony_ci int SetLocationPrivacyConfirmStatus(const int type, bool isConfirmed); 2235c735df2Sopenharmony_ci 2245c735df2Sopenharmony_ci /** 2255c735df2Sopenharmony_ci * @brief Obtain the number of cached GNSS locations. 2265c735df2Sopenharmony_ci * 2275c735df2Sopenharmony_ci * @return Returns the result of the cached GNSS locations size. 2285c735df2Sopenharmony_ci */ 2295c735df2Sopenharmony_ci int GetCachedGnssLocationsSize(); 2305c735df2Sopenharmony_ci 2315c735df2Sopenharmony_ci /** 2325c735df2Sopenharmony_ci * @brief All prepared GNSS locations are returned to the application through the callback function, 2335c735df2Sopenharmony_ci * and the bottom-layer buffer is cleared. 2345c735df2Sopenharmony_ci * 2355c735df2Sopenharmony_ci * @return Returns 1 if the cached gnss location has been flushed, returns 0 otherwise. 2365c735df2Sopenharmony_ci */ 2375c735df2Sopenharmony_ci int FlushCachedGnssLocations(); 2385c735df2Sopenharmony_ci 2395c735df2Sopenharmony_ci /** 2405c735df2Sopenharmony_ci * @brief Send extended commands to location subsystem. 2415c735df2Sopenharmony_ci * 2425c735df2Sopenharmony_ci * @param commands Indicates the extended command message body. 2435c735df2Sopenharmony_ci * @return Returns true if the command has been sent successfully, returns false otherwise. 2445c735df2Sopenharmony_ci */ 2455c735df2Sopenharmony_ci bool SendCommand(std::unique_ptr<LocationCommand>& commands); 2465c735df2Sopenharmony_ci 2475c735df2Sopenharmony_ci /** 2485c735df2Sopenharmony_ci * @brief Obtain the current country code. 2495c735df2Sopenharmony_ci * 2505c735df2Sopenharmony_ci * @return Returns the result of the country code. 2515c735df2Sopenharmony_ci */ 2525c735df2Sopenharmony_ci std::shared_ptr<CountryCode> GetIsoCountryCode(); 2535c735df2Sopenharmony_ci 2545c735df2Sopenharmony_ci /** 2555c735df2Sopenharmony_ci * @brief Enable the geographical location simulation function. 2565c735df2Sopenharmony_ci * 2575c735df2Sopenharmony_ci * @return Returns true if the mock location function has been enabled successfully, returns false otherwise. 2585c735df2Sopenharmony_ci */ 2595c735df2Sopenharmony_ci bool EnableLocationMock(); 2605c735df2Sopenharmony_ci 2615c735df2Sopenharmony_ci /** 2625c735df2Sopenharmony_ci * @brief Disable the geographical location simulation function. 2635c735df2Sopenharmony_ci * 2645c735df2Sopenharmony_ci * @return Returns true if the mock location function has been disabled successfully, returns false otherwise. 2655c735df2Sopenharmony_ci */ 2665c735df2Sopenharmony_ci bool DisableLocationMock(); 2675c735df2Sopenharmony_ci 2685c735df2Sopenharmony_ci /** 2695c735df2Sopenharmony_ci * @brief Set the configuration parameters for location simulation. 2705c735df2Sopenharmony_ci * 2715c735df2Sopenharmony_ci * @param timeInterval Indicates how often the simulated location is reported. 2725c735df2Sopenharmony_ci * @param location Indicates the simulated location to be reported. 2735c735df2Sopenharmony_ci * @return Returns true if the mock location config has been set successfully, returns false otherwise. 2745c735df2Sopenharmony_ci */ 2755c735df2Sopenharmony_ci bool SetMockedLocations( 2765c735df2Sopenharmony_ci const int timeInterval, const std::vector<std::shared_ptr<Location>> &location); 2775c735df2Sopenharmony_ci 2785c735df2Sopenharmony_ci /** 2795c735df2Sopenharmony_ci * @brief Enable the reverse geocoding simulation function. 2805c735df2Sopenharmony_ci * 2815c735df2Sopenharmony_ci * @return Returns true if the mock reverse geocoding function has been enabled successfully, 2825c735df2Sopenharmony_ci * returns false otherwise. 2835c735df2Sopenharmony_ci */ 2845c735df2Sopenharmony_ci bool EnableReverseGeocodingMock(); 2855c735df2Sopenharmony_ci 2865c735df2Sopenharmony_ci /** 2875c735df2Sopenharmony_ci * @brief Disable the reverse geocoding simulation function. 2885c735df2Sopenharmony_ci * 2895c735df2Sopenharmony_ci * @return Returns true if the mock reverse geocoding function has been disabled successfully, 2905c735df2Sopenharmony_ci * returns false otherwise. 2915c735df2Sopenharmony_ci */ 2925c735df2Sopenharmony_ci bool DisableReverseGeocodingMock(); 2935c735df2Sopenharmony_ci 2945c735df2Sopenharmony_ci /** 2955c735df2Sopenharmony_ci * @brief Set the configuration parameters for simulating reverse geocoding. 2965c735df2Sopenharmony_ci * 2975c735df2Sopenharmony_ci * @param mockInfo Indicates the set of locations and place names to be simulated. 2985c735df2Sopenharmony_ci * @return Returns true if the mock reverse geocoding config has been set successfully, returns false otherwise. 2995c735df2Sopenharmony_ci */ 3005c735df2Sopenharmony_ci bool SetReverseGeocodingMockInfo(std::vector<std::shared_ptr<GeocodingMockInfo>>& mockInfo); 3015c735df2Sopenharmony_ci 3025c735df2Sopenharmony_ci /** 3035c735df2Sopenharmony_ci * @brief Obtain current location switch status. 3045c735df2Sopenharmony_ci * 3055c735df2Sopenharmony_ci * @param isEnabled Indicates if the location switch on. 3065c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if obtain current location switch status succeed. 3075c735df2Sopenharmony_ci */ 3085c735df2Sopenharmony_ci LocationErrCode IsLocationEnabledV9(bool &isEnabled); 3095c735df2Sopenharmony_ci 3105c735df2Sopenharmony_ci /** 3115c735df2Sopenharmony_ci * @brief Obtain current location switch status. 3125c735df2Sopenharmony_ci * 3135c735df2Sopenharmony_ci * @param isEnabled Indicates if the location switch on. 3145c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if obtain current location switch status succeed. 3155c735df2Sopenharmony_ci */ 3165c735df2Sopenharmony_ci LocationErrCode IsLocationEnabledForUser(bool &isEnabled, int32_t userId); 3175c735df2Sopenharmony_ci 3185c735df2Sopenharmony_ci /** 3195c735df2Sopenharmony_ci * @brief Enable location switch. 3205c735df2Sopenharmony_ci * 3215c735df2Sopenharmony_ci * @param enable Status of the location switch to be set. 3225c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if enable location switch succeed. 3235c735df2Sopenharmony_ci */ 3245c735df2Sopenharmony_ci LocationErrCode EnableAbilityV9(bool enable); 3255c735df2Sopenharmony_ci 3265c735df2Sopenharmony_ci /** 3275c735df2Sopenharmony_ci * @brief Enable location switch. 3285c735df2Sopenharmony_ci * 3295c735df2Sopenharmony_ci * @param enable Status of the location switch to be set. 3305c735df2Sopenharmony_ci * @param userId userId of the user. 3315c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if enable location switch succeed. 3325c735df2Sopenharmony_ci */ 3335c735df2Sopenharmony_ci LocationErrCode EnableAbilityForUser(bool enable, int32_t userId); 3345c735df2Sopenharmony_ci 3355c735df2Sopenharmony_ci /** 3365c735df2Sopenharmony_ci * @brief Subscribe location changed. 3375c735df2Sopenharmony_ci * 3385c735df2Sopenharmony_ci * @param requestConfig Indicates the location request parameters. 3395c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the location result. 3405c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if subscribe location changed succeed. 3415c735df2Sopenharmony_ci */ 3425c735df2Sopenharmony_ci LocationErrCode StartLocatingV9(std::unique_ptr<RequestConfig>& requestConfig, 3435c735df2Sopenharmony_ci sptr<ILocatorCallback>& callback); 3445c735df2Sopenharmony_ci 3455c735df2Sopenharmony_ci /** 3465c735df2Sopenharmony_ci * @brief Unsubscribe location changed. 3475c735df2Sopenharmony_ci * 3485c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the location result. 3495c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if Unsubscribe location changed succeed. 3505c735df2Sopenharmony_ci */ 3515c735df2Sopenharmony_ci LocationErrCode StopLocatingV9(sptr<ILocatorCallback>& callback); 3525c735df2Sopenharmony_ci 3535c735df2Sopenharmony_ci /** 3545c735df2Sopenharmony_ci * @brief Obtain last known location. 3555c735df2Sopenharmony_ci * 3565c735df2Sopenharmony_ci * @param loc Indicates the last known location information. 3575c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if obtain last known location succeed. 3585c735df2Sopenharmony_ci */ 3595c735df2Sopenharmony_ci LocationErrCode GetCachedLocationV9(std::unique_ptr<Location> &loc); 3605c735df2Sopenharmony_ci 3615c735df2Sopenharmony_ci /** 3625c735df2Sopenharmony_ci * @brief Subscribe location switch changed. 3635c735df2Sopenharmony_ci * 3645c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the location switch status. 3655c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if the registration is successful. 3665c735df2Sopenharmony_ci */ 3675c735df2Sopenharmony_ci LocationErrCode RegisterSwitchCallbackV9(const sptr<IRemoteObject>& callback); 3685c735df2Sopenharmony_ci 3695c735df2Sopenharmony_ci /** 3705c735df2Sopenharmony_ci * @brief Unsubscribe location switch changed. 3715c735df2Sopenharmony_ci * 3725c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the location switch status. 3735c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if the deregistration is successful. 3745c735df2Sopenharmony_ci */ 3755c735df2Sopenharmony_ci LocationErrCode UnregisterSwitchCallbackV9(const sptr<IRemoteObject>& callback); 3765c735df2Sopenharmony_ci 3775c735df2Sopenharmony_ci /** 3785c735df2Sopenharmony_ci * @brief Subscribe satellite status changed. 3795c735df2Sopenharmony_ci * 3805c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the satellite status. 3815c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if the registration is successful. 3825c735df2Sopenharmony_ci */ 3835c735df2Sopenharmony_ci LocationErrCode RegisterGnssStatusCallbackV9(const sptr<IRemoteObject>& callback); 3845c735df2Sopenharmony_ci 3855c735df2Sopenharmony_ci /** 3865c735df2Sopenharmony_ci * @brief Unsubscribe satellite status changed. 3875c735df2Sopenharmony_ci * 3885c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the satellite status. 3895c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if the deregistration is successful. 3905c735df2Sopenharmony_ci */ 3915c735df2Sopenharmony_ci LocationErrCode UnregisterGnssStatusCallbackV9(const sptr<IRemoteObject>& callback); 3925c735df2Sopenharmony_ci 3935c735df2Sopenharmony_ci /** 3945c735df2Sopenharmony_ci * @brief Subscribe nmea message changed. 3955c735df2Sopenharmony_ci * 3965c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the nmea message. 3975c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if the registration is successful. 3985c735df2Sopenharmony_ci */ 3995c735df2Sopenharmony_ci LocationErrCode RegisterNmeaMessageCallbackV9(const sptr<IRemoteObject>& callback); 4005c735df2Sopenharmony_ci 4015c735df2Sopenharmony_ci /** 4025c735df2Sopenharmony_ci * @brief Unsubscribe nmea message changed. 4035c735df2Sopenharmony_ci * 4045c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the nmea message. 4055c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if the deregistration is successful. 4065c735df2Sopenharmony_ci */ 4075c735df2Sopenharmony_ci LocationErrCode UnregisterNmeaMessageCallbackV9(const sptr<IRemoteObject>& callback); 4085c735df2Sopenharmony_ci 4095c735df2Sopenharmony_ci /** 4105c735df2Sopenharmony_ci * @brief Registering the callback function for listening to country code changes. 4115c735df2Sopenharmony_ci * 4125c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting country code changes. 4135c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if the registration is successful. 4145c735df2Sopenharmony_ci */ 4155c735df2Sopenharmony_ci LocationErrCode RegisterCountryCodeCallbackV9(const sptr<IRemoteObject>& callback); 4165c735df2Sopenharmony_ci 4175c735df2Sopenharmony_ci /** 4185c735df2Sopenharmony_ci * @brief Unregistering the callback function for listening to country code changes. 4195c735df2Sopenharmony_ci * 4205c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting country code changes. 4215c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if the deregistration is successful. 4225c735df2Sopenharmony_ci */ 4235c735df2Sopenharmony_ci LocationErrCode UnregisterCountryCodeCallbackV9(const sptr<IRemoteObject>& callback); 4245c735df2Sopenharmony_ci 4255c735df2Sopenharmony_ci /** 4265c735df2Sopenharmony_ci * @brief Subscribe to cache GNSS locations update messages. 4275c735df2Sopenharmony_ci * 4285c735df2Sopenharmony_ci * @param request Indicates the cached GNSS locations request parameters. 4295c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the cached GNSS locations. 4305c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if the registration is successful. 4315c735df2Sopenharmony_ci */ 4325c735df2Sopenharmony_ci LocationErrCode RegisterCachedLocationCallbackV9(std::unique_ptr<CachedGnssLocationsRequest>& request, 4335c735df2Sopenharmony_ci sptr<ICachedLocationsCallback>& callback); 4345c735df2Sopenharmony_ci 4355c735df2Sopenharmony_ci /** 4365c735df2Sopenharmony_ci * @brief Unsubscribe to cache GNSS locations update messages. 4375c735df2Sopenharmony_ci * 4385c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the cached gnss locations. 4395c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if the deregistration is successful. 4405c735df2Sopenharmony_ci */ 4415c735df2Sopenharmony_ci LocationErrCode UnregisterCachedLocationCallbackV9(sptr<ICachedLocationsCallback>& callback); 4425c735df2Sopenharmony_ci 4435c735df2Sopenharmony_ci /** 4445c735df2Sopenharmony_ci * @brief Obtain geocoding service status. 4455c735df2Sopenharmony_ci * 4465c735df2Sopenharmony_ci * @param isAvailable Indicates if geocoding service is available 4475c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if obtain geocoding service status is successful. 4485c735df2Sopenharmony_ci */ 4495c735df2Sopenharmony_ci LocationErrCode IsGeoServiceAvailableV9(bool &isAvailable); 4505c735df2Sopenharmony_ci 4515c735df2Sopenharmony_ci /** 4525c735df2Sopenharmony_ci * @brief Obtain address info from location. 4535c735df2Sopenharmony_ci * 4545c735df2Sopenharmony_ci * @param data Indicates the reverse geocode query parameters. 4555c735df2Sopenharmony_ci * @param replyList Indicates the result of the address info. 4565c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if obtain address info from location is successful. 4575c735df2Sopenharmony_ci */ 4585c735df2Sopenharmony_ci LocationErrCode GetAddressByCoordinateV9(MessageParcel &data, 4595c735df2Sopenharmony_ci std::list<std::shared_ptr<GeoAddress>>& replyList); 4605c735df2Sopenharmony_ci 4615c735df2Sopenharmony_ci /** 4625c735df2Sopenharmony_ci * @brief Obtain latitude and longitude info from location address. 4635c735df2Sopenharmony_ci * 4645c735df2Sopenharmony_ci * @param data Indicates the geocode query parameters. 4655c735df2Sopenharmony_ci * @param replyList Indicates the result of the address info. 4665c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if obtain latitude and longitude info from location address is successful. 4675c735df2Sopenharmony_ci */ 4685c735df2Sopenharmony_ci LocationErrCode GetAddressByLocationNameV9(MessageParcel &data, 4695c735df2Sopenharmony_ci std::list<std::shared_ptr<GeoAddress>>& replyList); 4705c735df2Sopenharmony_ci 4715c735df2Sopenharmony_ci /** 4725c735df2Sopenharmony_ci * @brief Querying location privacy protocol confirmation status. 4735c735df2Sopenharmony_ci * 4745c735df2Sopenharmony_ci * @param type Indicates location privacy protocol type. 4755c735df2Sopenharmony_ci * @param isConfirmed Indicates if the location privacy protocol has been confirmed 4765c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if querying location privacy protocol confirmation status is successful. 4775c735df2Sopenharmony_ci */ 4785c735df2Sopenharmony_ci LocationErrCode IsLocationPrivacyConfirmedV9(const int type, bool &isConfirmed); 4795c735df2Sopenharmony_ci 4805c735df2Sopenharmony_ci /** 4815c735df2Sopenharmony_ci * @brief Set location privacy protocol confirmation status. 4825c735df2Sopenharmony_ci * 4835c735df2Sopenharmony_ci * @param type Indicates location privacy protocol type. 4845c735df2Sopenharmony_ci * @param isConfirmed Indicates whether the location privacy protocol should be confirmed. 4855c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if set location privacy protocol confirmation status is successful. 4865c735df2Sopenharmony_ci */ 4875c735df2Sopenharmony_ci LocationErrCode SetLocationPrivacyConfirmStatusV9(const int type, bool isConfirmed); 4885c735df2Sopenharmony_ci 4895c735df2Sopenharmony_ci /** 4905c735df2Sopenharmony_ci * @brief Obtain the number of cached GNSS locations. 4915c735df2Sopenharmony_ci * 4925c735df2Sopenharmony_ci * @param size Indicates the cached GNSS locations size 4935c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if obtain the number of cached GNSS locations is successful. 4945c735df2Sopenharmony_ci */ 4955c735df2Sopenharmony_ci LocationErrCode GetCachedGnssLocationsSizeV9(int &size); 4965c735df2Sopenharmony_ci 4975c735df2Sopenharmony_ci /** 4985c735df2Sopenharmony_ci * @brief All prepared GNSS locations are returned to the application through the callback function, 4995c735df2Sopenharmony_ci * and the bottom-layer buffer is cleared. 5005c735df2Sopenharmony_ci * 5015c735df2Sopenharmony_ci * @return Return ERRCODE_SUCCESS if flush cached gnss locations is successful. 5025c735df2Sopenharmony_ci */ 5035c735df2Sopenharmony_ci LocationErrCode FlushCachedGnssLocationsV9(); 5045c735df2Sopenharmony_ci 5055c735df2Sopenharmony_ci /** 5065c735df2Sopenharmony_ci * @brief Send extended commands to location subsystem. 5075c735df2Sopenharmony_ci * 5085c735df2Sopenharmony_ci * @param commands Indicates the extended command message body. 5095c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if the command has been sent successfully. 5105c735df2Sopenharmony_ci */ 5115c735df2Sopenharmony_ci LocationErrCode SendCommandV9(std::unique_ptr<LocationCommand>& commands); 5125c735df2Sopenharmony_ci 5135c735df2Sopenharmony_ci /** 5145c735df2Sopenharmony_ci * @brief Obtain the current country code. 5155c735df2Sopenharmony_ci * 5165c735df2Sopenharmony_ci * @param countryCode the result of the country code 5175c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if obtain the current country code successfully. 5185c735df2Sopenharmony_ci */ 5195c735df2Sopenharmony_ci LocationErrCode GetIsoCountryCodeV9(std::shared_ptr<CountryCode>& countryCode); 5205c735df2Sopenharmony_ci 5215c735df2Sopenharmony_ci /** 5225c735df2Sopenharmony_ci * @brief Enable the geographical location simulation function. 5235c735df2Sopenharmony_ci * 5245c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if the mock location function has been enabled successfully. 5255c735df2Sopenharmony_ci */ 5265c735df2Sopenharmony_ci LocationErrCode EnableLocationMockV9(); 5275c735df2Sopenharmony_ci 5285c735df2Sopenharmony_ci /** 5295c735df2Sopenharmony_ci * @brief Disable the geographical location simulation function. 5305c735df2Sopenharmony_ci * 5315c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if the mock location function has been disabled successfully. 5325c735df2Sopenharmony_ci */ 5335c735df2Sopenharmony_ci LocationErrCode DisableLocationMockV9(); 5345c735df2Sopenharmony_ci 5355c735df2Sopenharmony_ci /** 5365c735df2Sopenharmony_ci * @brief Set the configuration parameters for location simulation. 5375c735df2Sopenharmony_ci * 5385c735df2Sopenharmony_ci * @param timeInterval Indicates how often the simulated location is reported. 5395c735df2Sopenharmony_ci * @param location Indicates the simulated location to be reported. 5405c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if the mock location config has been set successfully. 5415c735df2Sopenharmony_ci */ 5425c735df2Sopenharmony_ci LocationErrCode SetMockedLocationsV9( 5435c735df2Sopenharmony_ci const int timeInterval, const std::vector<std::shared_ptr<Location>> &location); 5445c735df2Sopenharmony_ci 5455c735df2Sopenharmony_ci /** 5465c735df2Sopenharmony_ci * @brief Enable the reverse geocoding simulation function. 5475c735df2Sopenharmony_ci * 5485c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if the mock reverse geocoding function has been enabled successfully. 5495c735df2Sopenharmony_ci */ 5505c735df2Sopenharmony_ci LocationErrCode EnableReverseGeocodingMockV9(); 5515c735df2Sopenharmony_ci 5525c735df2Sopenharmony_ci /** 5535c735df2Sopenharmony_ci * @brief Disable the reverse geocoding simulation function. 5545c735df2Sopenharmony_ci * 5555c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if the mock reverse geocoding function has been disabled successfully. 5565c735df2Sopenharmony_ci */ 5575c735df2Sopenharmony_ci LocationErrCode DisableReverseGeocodingMockV9(); 5585c735df2Sopenharmony_ci 5595c735df2Sopenharmony_ci /** 5605c735df2Sopenharmony_ci * @brief Set the configuration parameters for simulating reverse geocoding. 5615c735df2Sopenharmony_ci * 5625c735df2Sopenharmony_ci * @param mockInfo Indicates the set of locations and place names to be simulated. 5635c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if the mock reverse geocoding config has been set successfully. 5645c735df2Sopenharmony_ci */ 5655c735df2Sopenharmony_ci LocationErrCode SetReverseGeocodingMockInfoV9(std::vector<std::shared_ptr<GeocodingMockInfo>>& mockInfo); 5665c735df2Sopenharmony_ci 5675c735df2Sopenharmony_ci /** 5685c735df2Sopenharmony_ci * @brief Used to freeze locating process with specified uid. 5695c735df2Sopenharmony_ci * 5705c735df2Sopenharmony_ci * @param pidList Indicates the calling pid. 5715c735df2Sopenharmony_ci * @param isProxy Indicates if the locating process should be freezed. 5725c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if the process has been frozen successfully. 5735c735df2Sopenharmony_ci */ 5745c735df2Sopenharmony_ci LocationErrCode ProxyForFreeze(std::set<int> pidList, bool isProxy); 5755c735df2Sopenharmony_ci 5765c735df2Sopenharmony_ci /** 5775c735df2Sopenharmony_ci * @brief Used to reset the frozen status of all location processes. 5785c735df2Sopenharmony_ci * 5795c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if the frozen status of process has been reset successfully. 5805c735df2Sopenharmony_ci */ 5815c735df2Sopenharmony_ci LocationErrCode ResetAllProxy(); 5825c735df2Sopenharmony_ci 5835c735df2Sopenharmony_ci /** 5845c735df2Sopenharmony_ci * @brief Subscribe to changes in WiFi/BT scanning information. 5855c735df2Sopenharmony_ci * 5865c735df2Sopenharmony_ci * @param dataConfig Indicates the locating required data configuration parameters. 5875c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting WiFi/BT scan info. 5885c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if subscribe to changes in WiFi/BT scanning information successfully. 5895c735df2Sopenharmony_ci */ 5905c735df2Sopenharmony_ci LocationErrCode RegisterLocatingRequiredDataCallback(std::unique_ptr<LocatingRequiredDataConfig>& dataConfig, 5915c735df2Sopenharmony_ci sptr<ILocatingRequiredDataCallback>& callback); 5925c735df2Sopenharmony_ci 5935c735df2Sopenharmony_ci /** 5945c735df2Sopenharmony_ci * @brief Unsubscribe to changes in WiFi/BT scanning information. 5955c735df2Sopenharmony_ci * 5965c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting WiFi/BT scan info. 5975c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if Unsubscribe to changes in WiFi/BT scanning information successfully. 5985c735df2Sopenharmony_ci */ 5995c735df2Sopenharmony_ci LocationErrCode UnRegisterLocatingRequiredDataCallback(sptr<ILocatingRequiredDataCallback>& callback); 6005c735df2Sopenharmony_ci 6015c735df2Sopenharmony_ci /** 6025c735df2Sopenharmony_ci * @brief Subscribe location error changed. 6035c735df2Sopenharmony_ci * 6045c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the location error result. 6055c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if subscribe error changed succeed. 6065c735df2Sopenharmony_ci */ 6075c735df2Sopenharmony_ci LocationErrCode SubscribeLocationError(sptr<ILocatorCallback>& callback); 6085c735df2Sopenharmony_ci 6095c735df2Sopenharmony_ci /** 6105c735df2Sopenharmony_ci * @brief Unsubscribe location errorcode changed. 6115c735df2Sopenharmony_ci * 6125c735df2Sopenharmony_ci * @param callback Indicates the callback for reporting the location error result. 6135c735df2Sopenharmony_ci * @return Returns ERRCODE_SUCCESS if Unsubscribe error changed succeed. 6145c735df2Sopenharmony_ci */ 6155c735df2Sopenharmony_ci LocationErrCode UnSubscribeLocationError(sptr<ILocatorCallback>& callback); 6165c735df2Sopenharmony_ci void ResetLocatorProxy(const wptr<IRemoteObject> &remote); 6175c735df2Sopenharmony_ci sptr<LocatorProxy> GetProxy(); 6185c735df2Sopenharmony_ci bool IsLocationCallbackRegistered(const sptr<ILocatorCallback>& callback); 6195c735df2Sopenharmony_ci bool IsSatelliteStatusChangeCallbackRegistered(const sptr<IRemoteObject>& callback); 6205c735df2Sopenharmony_ci bool IsNmeaCallbackRegistered(const sptr<IRemoteObject>& callback); 6215c735df2Sopenharmony_ci bool HasGnssNetworkRequest(); 6225c735df2Sopenharmony_ci void AddLocationCallBack(std::unique_ptr<RequestConfig>& requestConfig, sptr<ILocatorCallback>& callback); 6235c735df2Sopenharmony_ci void RemoveLocationCallBack(sptr<ILocatorCallback>& callback); 6245c735df2Sopenharmony_ci void AddSatelliteStatusChangeCallBack(const sptr<IRemoteObject>& callback); 6255c735df2Sopenharmony_ci void RemoveSatelliteStatusChangeCallBack(const sptr<IRemoteObject>& callback); 6265c735df2Sopenharmony_ci void AddNmeaCallBack(const sptr<IRemoteObject>& callback); 6275c735df2Sopenharmony_ci void RemoveNmeaCallBack(const sptr<IRemoteObject>& callback); 6285c735df2Sopenharmony_ci void SetIsServerExist(bool isServerExist); 6295c735df2Sopenharmony_ci 6305c735df2Sopenharmony_ciprivate: 6315c735df2Sopenharmony_ci LocationErrCode CheckEdmPolicy(bool enable); 6325c735df2Sopenharmony_ci 6335c735df2Sopenharmony_ciprivate: 6345c735df2Sopenharmony_ci class LocatorDeathRecipient : public IRemoteObject::DeathRecipient { 6355c735df2Sopenharmony_ci public: 6365c735df2Sopenharmony_ci explicit LocatorDeathRecipient(LocatorImpl &impl) : impl_(impl) {} 6375c735df2Sopenharmony_ci ~LocatorDeathRecipient() override = default; 6385c735df2Sopenharmony_ci void OnRemoteDied(const wptr<IRemoteObject> &remote) override 6395c735df2Sopenharmony_ci { 6405c735df2Sopenharmony_ci impl_.ResetLocatorProxy(remote); 6415c735df2Sopenharmony_ci } 6425c735df2Sopenharmony_ci private: 6435c735df2Sopenharmony_ci LocatorImpl &impl_; 6445c735df2Sopenharmony_ci }; 6455c735df2Sopenharmony_ci 6465c735df2Sopenharmony_ciprivate: 6475c735df2Sopenharmony_ci bool IsCallbackResuming(); 6485c735df2Sopenharmony_ci void UpdateCallbackResumingState(bool state); 6495c735df2Sopenharmony_ci 6505c735df2Sopenharmony_ci sptr<LocatorProxy> client_ { nullptr }; 6515c735df2Sopenharmony_ci sptr<IRemoteObject::DeathRecipient> recipient_ { nullptr }; 6525c735df2Sopenharmony_ci LocationDataManager* locationDataManager_ { nullptr }; 6535c735df2Sopenharmony_ci bool isServerExist_ = false; 6545c735df2Sopenharmony_ci bool isCallbackResuming_ = false; 6555c735df2Sopenharmony_ci std::mutex mutex_; 6565c735df2Sopenharmony_ci std::mutex resumeMutex_; 6575c735df2Sopenharmony_ci static std::mutex locatorMutex_; 6585c735df2Sopenharmony_ci static std::shared_ptr<LocatorImpl> instance_; 6595c735df2Sopenharmony_ci sptr<ISystemAbilityStatusChange> saStatusListener_ = 6605c735df2Sopenharmony_ci sptr<LocatorSystemAbilityListener>(new LocatorSystemAbilityListener()); 6615c735df2Sopenharmony_ci}; 6625c735df2Sopenharmony_ci 6635c735df2Sopenharmony_ciclass CallbackResumeManager : public ICallbackResumeManager { 6645c735df2Sopenharmony_cipublic: 6655c735df2Sopenharmony_ci CallbackResumeManager() = default; 6665c735df2Sopenharmony_ci ~CallbackResumeManager() = default; 6675c735df2Sopenharmony_ci void ResumeCallback() override; 6685c735df2Sopenharmony_ciprivate: 6695c735df2Sopenharmony_ci void InitResumeCallbackFuncMap(); 6705c735df2Sopenharmony_ci void ResumeGnssStatusCallback(); 6715c735df2Sopenharmony_ci void ResumeNmeaMessageCallback(); 6725c735df2Sopenharmony_ci void ResumeLocating(); 6735c735df2Sopenharmony_ci}; 6745c735df2Sopenharmony_ci} // namespace Location 6755c735df2Sopenharmony_ci} // namespace OHOS 6765c735df2Sopenharmony_ci#endif // LOCATOR_IMPL_H 677