• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef LOCATOR_IMPL_H
16 #define LOCATOR_IMPL_H
17 
18 #include <vector>
19 
20 #include "iremote_object.h"
21 
22 #include "constant_definition.h"
23 #include "country_code.h"
24 #include "country_code_manager.h"
25 #include "geo_address.h"
26 #include "geocoding_mock_info.h"
27 #include "i_cached_locations_callback.h"
28 #include "locator_proxy.h"
29 #include "i_locating_required_data_callback.h"
30 #include "locating_required_data_config.h"
31 #include "location_data_manager.h"
32 #include "request_config.h"
33 #include "system_ability_status_change_stub.h"
34 #include "locationhub_ipc_interface_code.h"
35 #include "ibluetooth_scan_result_callback.h"
36 #include "ilocator_service.h"
37 #include "beacon_fence_request.h"
38 #include "beacon_fence.h"
39 
40 namespace OHOS {
41 namespace Location {
42 class ICallbackResumeManager {
43 public:
44     virtual ~ICallbackResumeManager() = default;
45     virtual void ResumeCallback() = 0;
46 };
47 
48 class LocatorSystemAbilityListener : public SystemAbilityStatusChangeStub {
49 public:
50     void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
51     void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
52 private:
53     bool needResume_ = false;
54     std::mutex mutex_;
55 };
56 
57 class LocatorImpl {
58 public:
59     static std::shared_ptr<LocatorImpl> GetInstance();
60     explicit LocatorImpl();
61     ~LocatorImpl();
62 
63     /**
64      * @brief Obtain current location switch status.
65      *
66      * @return Returns true if the location switch on, returns false otherwise.
67      */
68     bool IsLocationEnabled();
69     void ShowNotification();
70     void RequestPermission();
71     void RequestEnableLocation();
72 
73     /**
74      * @brief Enable location switch.
75      *
76      * @param enable Status of the location switch to be set.
77      */
78     void EnableAbility(bool enable);
79 
80     /**
81      * @brief Subscribe location changed.
82      *
83      * @param requestConfig Indicates the location request parameters.
84      * @param callback Indicates the callback for reporting the location result.
85      */
86     void StartLocating(std::unique_ptr<RequestConfig>& requestConfig,
87         sptr<ILocatorCallback>& callback);
88 
89     /**
90      * @brief Unsubscribe location changed.
91      *
92      * @param callback Indicates the callback for reporting the location result.
93      */
94     void StopLocating(sptr<ILocatorCallback>& callback);
95 
96     /**
97      * @brief Obtain last known location.
98      *
99      * @return The last known location information.
100      */
101     std::unique_ptr<Location> GetCachedLocation();
102 
103     /**
104      * @brief Subscribe location switch changed.
105      *
106      * @param callback Indicates the callback for reporting the location switch status.
107      * @param uid Indicates the calling uid
108      * @return Return whether the registration is successful.
109      */
110     bool RegisterSwitchCallback(const sptr<IRemoteObject>& callback, pid_t uid);
111 
112     /**
113      * @brief Unsubscribe location switch changed.
114      *
115      * @param callback Indicates the callback for reporting the location switch status.
116      * @return Return whether the deregistration is successful.
117      */
118     bool UnregisterSwitchCallback(const sptr<IRemoteObject>& callback);
119 
120     /**
121      * @brief Subscribe satellite status changed.
122      *
123      * @param callback Indicates the callback for reporting the satellite status.
124      * @param uid Indicates the calling uid
125      * @return Return whether the registration is successful.
126      */
127     bool RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid);
128 
129     /**
130      * @brief Unsubscribe satellite status changed.
131      *
132      * @param callback Indicates the callback for reporting the satellite status.
133      * @return Return whether the deregistration is successful.
134      */
135     bool UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback);
136 
137     /**
138      * @brief Subscribe nmea message changed.
139      *
140      * @param callback Indicates the callback for reporting the nmea message.
141      * @param uid Indicates the calling uid
142      * @return Return whether the registration is successful.
143      */
144     bool RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid);
145 
146     /**
147      * @brief Unsubscribe nmea message changed.
148      *
149      * @param callback Indicates the callback for reporting the nmea message.
150      * @return Return whether the deregistration is successful.
151      */
152     bool UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback);
153 
154     /**
155      * @brief Registering the callback function for listening to country code changes.
156      *
157      * @param callback Indicates the callback for reporting country code changes.
158      * @param uid Indicates the calling uid
159      * @return Return whether the registration is successful.
160      */
161     bool RegisterCountryCodeCallback(const sptr<IRemoteObject>& callback, pid_t uid);
162 
163     /**
164      * @brief Unregistering the callback function for listening to country code changes.
165      *
166      * @param callback Indicates the callback for reporting country code changes.
167      * @return Return whether the deregistration is successful.
168      */
169     bool UnregisterCountryCodeCallback(const sptr<IRemoteObject>& callback);
170 
171     /**
172      * @brief Subscribe to cache GNSS locations update messages.
173      *
174      * @param request Indicates the cached GNSS locations request parameters.
175      * @param callback Indicates the callback for reporting the cached GNSS locations.
176      * @return Return whether the registration is successful.
177      */
178     void RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLocationsRequest>& request,
179         sptr<ICachedLocationsCallback>& callback);
180 
181     /**
182      * @brief Unsubscribe to cache GNSS locations update messages.
183      *
184      * @param callback Indicates the callback for reporting the cached gnss locations.
185      * @return Return whether the deregistration is successful.
186      */
187     void UnregisterCachedLocationCallback(sptr<ICachedLocationsCallback>& callback);
188 
189     /**
190      * @brief Obtain geocoding service status.
191      *
192      * @return Returns true if geocoding service is available, returns false otherwise.
193      */
194     bool IsGeoServiceAvailable();
195 
196     /**
197      * @brief Obtain address info from location.
198      *
199      * @param data Indicates the reverse geocode query parameters.
200      * @param replyList Indicates the result of the address info.
201      */
202     void GetAddressByCoordinate(MessageParcel &data, std::list<std::shared_ptr<GeoAddress>>& replyList);
203 
204     /**
205      * @brief Obtain latitude and longitude info from location address.
206      *
207      * @param data Indicates the geocode query parameters.
208      * @param replyList Indicates the result of the address info.
209      */
210     void GetAddressByLocationName(MessageParcel &data, std::list<std::shared_ptr<GeoAddress>>& replyList);
211 
212     /**
213      * @brief Querying location privacy protocol confirmation status.
214      *
215      * @param type Indicates location privacy protocol type.
216      * @return Returns true if the location privacy protocol has been confirmed, returns false otherwise.
217      */
218     bool IsLocationPrivacyConfirmed(const int type);
219 
220     /**
221      * @brief Set location privacy protocol confirmation status.
222      *
223      * @param type Indicates location privacy protocol type.
224      * @param isConfirmed Indicates whether the location privacy protocol should be confirmed.
225      * @return Returns 1 if the location privacy protocol has been set, returns 0 otherwise.
226      */
227     int SetLocationPrivacyConfirmStatus(const int type, bool isConfirmed);
228 
229     /**
230      * @brief Obtain the number of cached GNSS locations.
231      *
232      * @return Returns the result of the cached GNSS locations size.
233      */
234     int GetCachedGnssLocationsSize();
235 
236     /**
237      * @brief All prepared GNSS locations are returned to the application through the callback function,
238      * and the bottom-layer buffer is cleared.
239      *
240      * @return Returns 1 if the cached gnss location has been flushed, returns 0 otherwise.
241      */
242     int FlushCachedGnssLocations();
243 
244     /**
245      * @brief Send extended commands to location subsystem.
246      *
247      * @param commands Indicates the extended command message body.
248      * @return Returns true if the command has been sent successfully, returns false otherwise.
249      */
250     bool SendCommand(std::unique_ptr<LocationCommand>& commands);
251 
252     /**
253      * @brief Obtain the current country code.
254      *
255      * @return Returns the result of the country code.
256      */
257     std::shared_ptr<CountryCode> GetIsoCountryCode();
258 
259     /**
260      * @brief Enable the geographical location simulation function.
261      *
262      * @return Returns true if the mock location function has been enabled successfully, returns false otherwise.
263      */
264     bool EnableLocationMock();
265 
266     /**
267      * @brief Disable the geographical location simulation function.
268      *
269      * @return Returns true if the mock location function has been disabled successfully, returns false otherwise.
270      */
271     bool DisableLocationMock();
272 
273     /**
274      * @brief Set the configuration parameters for location simulation.
275      *
276      * @param timeInterval Indicates how often the simulated location is reported.
277      * @param location Indicates the simulated location to be reported.
278      * @return Returns true if the mock location config has been set successfully, returns false otherwise.
279      */
280     bool SetMockedLocations(
281         const int timeInterval, const std::vector<std::shared_ptr<Location>> &location);
282 
283     /**
284      * @brief Enable the reverse geocoding simulation function.
285      *
286      * @return Returns true if the mock reverse geocoding function has been enabled successfully,
287      * returns false otherwise.
288      */
289     bool EnableReverseGeocodingMock();
290 
291     /**
292      * @brief Disable the reverse geocoding simulation function.
293      *
294      * @return Returns true if the mock reverse geocoding function has been disabled successfully,
295      * returns false otherwise.
296      */
297     bool DisableReverseGeocodingMock();
298 
299     /**
300      * @brief Set the configuration parameters for simulating reverse geocoding.
301      *
302      * @param mockInfo Indicates the set of locations and place names to be simulated.
303      * @return Returns true if the mock reverse geocoding config has been set successfully, returns false otherwise.
304      */
305     bool SetReverseGeocodingMockInfo(std::vector<std::shared_ptr<GeocodingMockInfo>>& mockInfo);
306 
307     /**
308      * @brief Obtain current location switch status.
309      *
310      * @param isEnabled Indicates if the location switch on.
311      * @return Returns ERRCODE_SUCCESS if obtain current location switch status succeed.
312      */
313     LocationErrCode IsLocationEnabledV9(bool &isEnabled);
314 
315     /**
316      * @brief Obtain current location switch status.
317      *
318      * @param isEnabled Indicates if the location switch on.
319      * @return Returns ERRCODE_SUCCESS if obtain current location switch status succeed.
320      */
321     LocationErrCode IsLocationEnabledForUser(bool &isEnabled, int32_t userId);
322 
323     /**
324      * @brief Enable location switch.
325      *
326      * @param enable Status of the location switch to be set.
327      * @return Returns ERRCODE_SUCCESS if enable location switch succeed.
328      */
329     LocationErrCode EnableAbilityV9(bool enable);
330 
331     /**
332      * @brief Enable location switch.
333      *
334      * @param enable Status of the location switch to be set.
335      * @param userId userId of the user.
336      * @return Returns ERRCODE_SUCCESS if enable location switch succeed.
337      */
338     LocationErrCode EnableAbilityForUser(bool enable, int32_t userId);
339 
340     /**
341      * @brief Subscribe location changed.
342      *
343      * @param requestConfig Indicates the location request parameters.
344      * @param callback Indicates the callback for reporting the location result.
345      * @return Returns ERRCODE_SUCCESS if subscribe location changed succeed.
346      */
347     LocationErrCode StartLocatingV9(std::unique_ptr<RequestConfig>& requestConfig,
348         sptr<ILocatorCallback>& callback);
349 
350     /**
351      * @brief Unsubscribe location changed.
352      *
353      * @param callback Indicates the callback for reporting the location result.
354      * @return Returns ERRCODE_SUCCESS if Unsubscribe location changed succeed.
355      */
356     LocationErrCode StopLocatingV9(sptr<ILocatorCallback>& callback);
357 
358     /**
359      * @brief Obtain last known location.
360      *
361      * @param loc Indicates the last known location information.
362      * @return Returns ERRCODE_SUCCESS if obtain last known location succeed.
363      */
364     LocationErrCode GetCachedLocationV9(std::unique_ptr<Location> &loc);
365 
366     /**
367      * @brief Subscribe location switch changed.
368      *
369      * @param callback Indicates the callback for reporting the location switch status.
370      * @return Return ERRCODE_SUCCESS if the registration is successful.
371      */
372     LocationErrCode RegisterSwitchCallbackV9(const sptr<IRemoteObject>& callback);
373 
374     /**
375      * @brief Unsubscribe location switch changed.
376      *
377      * @param callback Indicates the callback for reporting the location switch status.
378      * @return Return ERRCODE_SUCCESS if the deregistration is successful.
379      */
380     LocationErrCode UnregisterSwitchCallbackV9(const sptr<IRemoteObject>& callback);
381 
382     /**
383      * @brief Subscribe satellite status changed.
384      *
385      * @param callback Indicates the callback for reporting the satellite status.
386      * @return Return ERRCODE_SUCCESS if the registration is successful.
387      */
388     LocationErrCode RegisterGnssStatusCallbackV9(const sptr<IRemoteObject>& callback);
389 
390     /**
391      * @brief Unsubscribe satellite status changed.
392      *
393      * @param callback Indicates the callback for reporting the satellite status.
394      * @return Return ERRCODE_SUCCESS if the deregistration is successful.
395      */
396     LocationErrCode UnregisterGnssStatusCallbackV9(const sptr<IRemoteObject>& callback);
397 
398     /**
399      * @brief Subscribe nmea message changed.
400      *
401      * @param callback Indicates the callback for reporting the nmea message.
402      * @return Return ERRCODE_SUCCESS if the registration is successful.
403      */
404     LocationErrCode RegisterNmeaMessageCallbackV9(const sptr<IRemoteObject>& callback);
405 
406     /**
407      * @brief Unsubscribe nmea message changed.
408      *
409      * @param callback Indicates the callback for reporting the nmea message.
410      * @return Return ERRCODE_SUCCESS if the deregistration is successful.
411      */
412     LocationErrCode UnregisterNmeaMessageCallbackV9(const sptr<IRemoteObject>& callback);
413 
414     /**
415      * @brief Registering the callback function for listening to country code changes.
416      *
417      * @param callback Indicates the callback for reporting country code changes.
418      * @return Return ERRCODE_SUCCESS if the registration is successful.
419      */
420     LocationErrCode RegisterCountryCodeCallbackV9(const sptr<IRemoteObject>& callback);
421 
422     /**
423      * @brief Unregistering the callback function for listening to country code changes.
424      *
425      * @param callback Indicates the callback for reporting country code changes.
426      * @return Return ERRCODE_SUCCESS if the deregistration is successful.
427      */
428     LocationErrCode UnregisterCountryCodeCallbackV9(const sptr<IRemoteObject>& callback);
429 
430     /**
431      * @brief Subscribe to cache GNSS locations update messages.
432      *
433      * @param request Indicates the cached GNSS locations request parameters.
434      * @param callback Indicates the callback for reporting the cached GNSS locations.
435      * @return Return ERRCODE_SUCCESS if the registration is successful.
436      */
437     LocationErrCode RegisterCachedLocationCallbackV9(std::unique_ptr<CachedGnssLocationsRequest>& request,
438         sptr<ICachedLocationsCallback>& callback);
439 
440     /**
441      * @brief Unsubscribe to cache GNSS locations update messages.
442      *
443      * @param callback Indicates the callback for reporting the cached gnss locations.
444      * @return Return ERRCODE_SUCCESS if the deregistration is successful.
445      */
446     LocationErrCode UnregisterCachedLocationCallbackV9(sptr<ICachedLocationsCallback>& callback);
447 
448     /**
449      * @brief Obtain geocoding service status.
450      *
451      * @param isAvailable Indicates if geocoding service is available
452      * @return Return ERRCODE_SUCCESS if obtain geocoding service status is successful.
453      */
454     LocationErrCode IsGeoServiceAvailableV9(bool &isAvailable);
455 
456     /**
457      * @brief Obtain address info from location.
458      *
459      * @param data Indicates the reverse geocode query parameters.
460      * @param replyList Indicates the result of the address info.
461      * @return Return ERRCODE_SUCCESS if obtain address info from location is successful.
462      */
463     LocationErrCode GetAddressByCoordinateV9(MessageParcel &data,
464         std::list<std::shared_ptr<GeoAddress>>& replyList);
465 
466     /**
467      * @brief Obtain latitude and longitude info from location address.
468      *
469      * @param data Indicates the geocode query parameters.
470      * @param replyList Indicates the result of the address info.
471      * @return Return ERRCODE_SUCCESS if obtain latitude and longitude info from location address is successful.
472      */
473     LocationErrCode GetAddressByLocationNameV9(MessageParcel &data,
474         std::list<std::shared_ptr<GeoAddress>>& replyList);
475 
476     /**
477      * @brief Querying location privacy protocol confirmation status.
478      *
479      * @param type Indicates location privacy protocol type.
480      * @param isConfirmed Indicates if the location privacy protocol has been confirmed
481      * @return Return ERRCODE_SUCCESS if querying location privacy protocol confirmation status is successful.
482      */
483     LocationErrCode IsLocationPrivacyConfirmedV9(const int type, bool &isConfirmed);
484 
485     /**
486      * @brief Set location privacy protocol confirmation status.
487      *
488      * @param type Indicates location privacy protocol type.
489      * @param isConfirmed Indicates whether the location privacy protocol should be confirmed.
490      * @return Return ERRCODE_SUCCESS if set location privacy protocol confirmation status is successful.
491      */
492     LocationErrCode SetLocationPrivacyConfirmStatusV9(const int type, bool isConfirmed);
493 
494     /**
495      * @brief Obtain the number of cached GNSS locations.
496      *
497      * @param size Indicates the cached GNSS locations size
498      * @return Return ERRCODE_SUCCESS if obtain the number of cached GNSS locations is successful.
499      */
500     LocationErrCode GetCachedGnssLocationsSizeV9(int &size);
501 
502     /**
503      * @brief All prepared GNSS locations are returned to the application through the callback function,
504      * and the bottom-layer buffer is cleared.
505      *
506      * @return Return ERRCODE_SUCCESS if flush cached gnss locations is successful.
507      */
508     LocationErrCode FlushCachedGnssLocationsV9();
509 
510     /**
511      * @brief Send extended commands to location subsystem.
512      *
513      * @param commands Indicates the extended command message body.
514      * @return Returns ERRCODE_SUCCESS if the command has been sent successfully.
515      */
516     LocationErrCode SendCommandV9(std::unique_ptr<LocationCommand>& commands);
517 
518     /**
519      * @brief Obtain the current country code.
520      *
521      * @param countryCode the result of the country code
522      * @return Returns ERRCODE_SUCCESS if obtain the current country code successfully.
523      */
524     LocationErrCode GetIsoCountryCodeV9(std::shared_ptr<CountryCode>& countryCode);
525 
526     /**
527      * @brief Enable the geographical location simulation function.
528      *
529      * @return Returns ERRCODE_SUCCESS if the mock location function has been enabled successfully.
530      */
531     LocationErrCode EnableLocationMockV9();
532 
533     /**
534      * @brief Disable the geographical location simulation function.
535      *
536      * @return Returns ERRCODE_SUCCESS if the mock location function has been disabled successfully.
537      */
538     LocationErrCode DisableLocationMockV9();
539 
540     /**
541      * @brief Set the configuration parameters for location simulation.
542      *
543      * @param timeInterval Indicates how often the simulated location is reported.
544      * @param location Indicates the simulated location to be reported.
545      * @return Returns ERRCODE_SUCCESS if the mock location config has been set successfully.
546      */
547     LocationErrCode SetMockedLocationsV9(
548         const int timeInterval, const std::vector<std::shared_ptr<Location>> &location);
549 
550     /**
551      * @brief Enable the reverse geocoding simulation function.
552      *
553      * @return Returns ERRCODE_SUCCESS if the mock reverse geocoding function has been enabled successfully.
554      */
555     LocationErrCode EnableReverseGeocodingMockV9();
556 
557     /**
558      * @brief Disable the reverse geocoding simulation function.
559      *
560      * @return Returns ERRCODE_SUCCESS if the mock reverse geocoding function has been disabled successfully.
561      */
562     LocationErrCode DisableReverseGeocodingMockV9();
563 
564     /**
565      * @brief Set the configuration parameters for simulating reverse geocoding.
566      *
567      * @param mockInfo Indicates the set of locations and place names to be simulated.
568      * @return Returns ERRCODE_SUCCESS if the mock reverse geocoding config has been set successfully.
569      */
570     LocationErrCode SetReverseGeocodingMockInfoV9(std::vector<std::shared_ptr<GeocodingMockInfo>>& mockInfo);
571 
572     /**
573      * @brief Used to freeze locating process with specified uid.
574      *
575      * @param pidList Indicates the calling pid.
576      * @param isProxy Indicates if the locating process should be freezed.
577      * @return Returns ERRCODE_SUCCESS if the process has been frozen successfully.
578      */
579     LocationErrCode ProxyForFreeze(std::set<int> pidList, bool isProxy);
580 
581     /**
582      * @brief Used to reset the frozen status of all location processes.
583      *
584      * @return Returns ERRCODE_SUCCESS if the frozen status of process has been reset successfully.
585      */
586     LocationErrCode ResetAllProxy();
587 
588     /**
589      * @brief Subscribe to changes in WiFi/BT scanning information.
590      *
591      * @param dataConfig Indicates the locating required data configuration parameters.
592      * @param callback Indicates the callback for reporting WiFi/BT scan info.
593      * @return Returns ERRCODE_SUCCESS if subscribe to changes in WiFi/BT scanning information successfully.
594      */
595     LocationErrCode RegisterLocatingRequiredDataCallback(std::unique_ptr<LocatingRequiredDataConfig>& dataConfig,
596         sptr<ILocatingRequiredDataCallback>& callback);
597 
598     /**
599      * @brief Unsubscribe to changes in WiFi/BT scanning information.
600      *
601      * @param callback Indicates the callback for reporting WiFi/BT scan info.
602      * @return Returns ERRCODE_SUCCESS if Unsubscribe to changes in WiFi/BT scanning information successfully.
603      */
604     LocationErrCode UnRegisterLocatingRequiredDataCallback(sptr<ILocatingRequiredDataCallback>& callback);
605 
606     /**
607      * @brief Subscribe location error changed.
608      *
609      * @param callback Indicates the callback for reporting the location error result.
610      * @return Returns ERRCODE_SUCCESS if subscribe error changed succeed.
611      */
612     LocationErrCode SubscribeLocationError(sptr<ILocatorCallback>& callback);
613 
614     /**
615      * @brief Subscribe bluetooth scan result change.
616      *
617      * @param callback Indicates the callback for reporting the location error result.
618      * @return Returns ERRCODE_SUCCESS if subscribe error changed succeed.
619      */
620     LocationErrCode SubscribeBluetoothScanResultChange(sptr<IBluetoothScanResultCallback>& callback);
621 
622     /**
623      * @brief Unsubscribe bluetooth scan result change.
624      *
625      * @param callback Indicates the callback for reporting the bluetooth scan result.
626      * @return Returns ERRCODE_SUCCESS if subscribe error changed succeed.
627      */
628     LocationErrCode UnSubscribeBluetoothScanResultChange(sptr<IBluetoothScanResultCallback>& callback);
629 
630     /**
631      * @brief Unsubscribe location errorcode changed.
632      *
633      * @param callback Indicates the callback for reporting the location error result.
634      * @return Returns ERRCODE_SUCCESS if Unsubscribe error changed succeed.
635      */
636     LocationErrCode UnSubscribeLocationError(sptr<ILocatorCallback>& callback);
637 
638     /**
639      * @brief Obtain last known location.
640      *
641      * @param loc Indicates the last known location information.
642      * @return Returns ERRCODE_SUCCESS if obtain last known location succeed.
643      */
644     LocationErrCode GetCurrentWifiBssidForLocating(std::string& bssid);
645 
646     /**
647      * @brief Gets the distance between two positions.
648      *
649      * @param loc location 1.
650      * @param loc location 2.
651      * @param loc distance.
652      * @return Returns ERRCODE_SUCCESS if obtain last known location succeed.
653      */
654     LocationErrCode GetDistanceBetweenLocations(const Location& location1,
655         const Location& location2, double& distance);
656 
657     /**
658      * Obtaining the location switch status of a specified user.
659      *
660      * @param userId - Indicates the ID of a specified user.
661      * @returns Returns {@code true} if the location switch on, returns {@code false} otherwise.
662      */
663     LocationErrCode SetLocationSwitchIgnored(bool enable);
664 
665     /**
666      * Check whether the POI service is supported.
667      *
668      * @returns { boolean } Returns {@code true} if POI service is available, returns {@code false} otherwise.
669      */
670     bool IsPoiServiceSupported();
671 
672     /**
673      * add beacon fence.
674      *
675      * @param beaconFenceRequest - beacon fence request parameters.
676      * @return Returns ERRCODE_SUCCESS if add beacon fence succeed.
677      */
678     LocationErrCode AddBeaconFence(const std::shared_ptr<BeaconFenceRequest>& beaconFenceRequest);
679 
680     /**
681      * remove beacon fence.
682      *
683      * @param beaconFence - beacon fence parameters.
684      * @return Returns ERRCODE_SUCCESS if remove beacon fence succeed.
685      */
686     LocationErrCode RemoveBeaconFence(const std::shared_ptr<BeaconFence>& beaconFence);
687 
688     /**
689      * Check whether the beacon fence is supported.
690      *
691      * @return { boolean } Returns {@code true} if beacon fence is supported, returns {@code false} otherwise.
692      */
693     bool IsBeaconFenceSupported();
694 
695     void ResetLocatorProxy(const wptr<IRemoteObject> &remote);
696     sptr<ILocatorService> GetProxy();
697     bool IsLocationCallbackRegistered(const sptr<ILocatorCallback>& callback);
698     bool IsSatelliteStatusChangeCallbackRegistered(const sptr<IRemoteObject>& callback);
699     bool IsNmeaCallbackRegistered(const sptr<IRemoteObject>& callback);
700     bool HasGnssNetworkRequest();
701     void AddLocationCallBack(std::unique_ptr<RequestConfig>& requestConfig, sptr<ILocatorCallback>& callback);
702     void RemoveLocationCallBack(sptr<ILocatorCallback>& callback);
703     void AddSatelliteStatusChangeCallBack(const sptr<IRemoteObject>& callback);
704     void RemoveSatelliteStatusChangeCallBack(const sptr<IRemoteObject>& callback);
705     void AddNmeaCallBack(const sptr<IRemoteObject>& callback);
706     void RemoveNmeaCallBack(const sptr<IRemoteObject>& callback);
707     void SetIsServerExist(bool isServerExist);
708 
709 private:
710     LocationErrCode CheckEdmPolicy(bool enable);
711 
712 private:
713     class LocatorDeathRecipient : public IRemoteObject::DeathRecipient {
714     public:
LocatorDeathRecipient(LocatorImpl & impl)715         explicit LocatorDeathRecipient(LocatorImpl &impl) : impl_(impl) {}
716         ~LocatorDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)717         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
718         {
719             impl_.ResetLocatorProxy(remote);
720         }
721     private:
722         LocatorImpl &impl_;
723     };
724 
725 private:
726     bool IsCallbackResuming();
727     void UpdateCallbackResumingState(bool state);
728 
729     sptr<ILocatorService> client_ { nullptr };
730     sptr<IRemoteObject::DeathRecipient> recipient_ { nullptr };
731     LocationDataManager* locationDataManager_ { nullptr };
732     bool isServerExist_ = false;
733     bool isCallbackResuming_ = false;
734     std::mutex mutex_;
735     std::mutex resumeMutex_;
736     static std::mutex locatorMutex_;
737     static std::shared_ptr<LocatorImpl> instance_;
738     sptr<ISystemAbilityStatusChange> saStatusListener_ =
739         sptr<LocatorSystemAbilityListener>(new LocatorSystemAbilityListener());
740 };
741 
742 class CallbackResumeManager : public ICallbackResumeManager {
743 public:
744     CallbackResumeManager() = default;
745     ~CallbackResumeManager() = default;
746     void ResumeCallback() override;
747 private:
748     void InitResumeCallbackFuncMap();
749     void ResumeGnssStatusCallback();
750     void ResumeNmeaMessageCallback();
751     void ResumeLocating();
752 };
753 }  // namespace Location
754 }  // namespace OHOS
755 #endif // LOCATOR_IMPL_H
756