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