• 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 
16 #include "locator_impl.h"
17 #include "if_system_ability_manager.h"
18 #include "ipc_skeleton.h"
19 #include "iservice_registry.h"
20 #include "system_ability_definition.h"
21 #include "common_utils.h"
22 #include "country_code.h"
23 
24 #include "geo_convert_callback_host.h"
25 #include "location_data_rdb_observer.h"
26 #include "location_data_rdb_helper.h"
27 #include "location_data_rdb_manager.h"
28 #include "location_log.h"
29 #include "location_sa_load_manager.h"
30 #include "locator.h"
31 #include "permission_manager.h"
32 #include "geocode_convert_address_request.h"
33 #include "geocode_convert_location_request.h"
34 
35 namespace OHOS {
36 namespace Location {
37 constexpr uint32_t WAIT_MS = 1000;
38 std::shared_ptr<LocatorImpl> LocatorImpl::instance_ = nullptr;
39 std::mutex LocatorImpl::locatorMutex_;
40 auto g_locatorImpl = Locator::GetInstance();
41 std::mutex g_locationCallbackMapMutex;
42 std::mutex g_gnssStatusInfoCallbacksMutex;
43 std::mutex g_nmeaCallbacksMutex;
44 std::shared_ptr<CallbackResumeManager> g_callbackResumer = std::make_shared<CallbackResumeManager>();
45 using CallbackResumeHandle = std::function<void()>;
46 std::map<sptr<ILocatorCallback>, RequestConfig> g_locationCallbackMap;
47 std::set<sptr<IRemoteObject>> g_gnssStatusInfoCallbacks;
48 std::set<sptr<IRemoteObject>> g_nmeaCallbacks;
49 
GetInstance()50 std::shared_ptr<LocatorImpl> LocatorImpl::GetInstance()
51 {
52     if (instance_ == nullptr) {
53         std::unique_lock<std::mutex> lock(locatorMutex_);
54         if (instance_ == nullptr) {
55             std::shared_ptr<LocatorImpl> locator = std::make_shared<LocatorImpl>();
56             instance_ = locator;
57         }
58     }
59     return instance_;
60 }
61 
LocatorImpl()62 LocatorImpl::LocatorImpl()
63 {
64     locationDataManager_ = LocationDataManager::GetInstance();
65 }
66 
~LocatorImpl()67 LocatorImpl::~LocatorImpl()
68 {
69 }
70 
IsLocationEnabled()71 bool LocatorImpl::IsLocationEnabled()
72 {
73     LBSLOGD(LOCATION_NAPI, "IsLocationEnabled");
74     int32_t state = DEFAULT_SWITCH_STATE;
75     state = LocationDataRdbManager::GetSwitchStateFromSysparaForCurrentUser();
76     if (state == DISABLED || state == ENABLED) {
77         return (state == ENABLED);
78     }
79     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
80         return false;
81     }
82     sptr<ILocatorService> proxy = GetProxy();
83     if (proxy == nullptr) {
84         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
85         return false;
86     }
87     proxy->GetSwitchState(state);
88     return (state == ENABLED);
89 }
90 
ShowNotification()91 void LocatorImpl::ShowNotification()
92 {
93     LBSLOGI(LOCATION_NAPI, "ShowNotification");
94 }
95 
RequestPermission()96 void LocatorImpl::RequestPermission()
97 {
98     LBSLOGI(LOCATION_NAPI, "permission need to be granted");
99 }
100 
RequestEnableLocation()101 void LocatorImpl::RequestEnableLocation()
102 {
103     LBSLOGI(LOCATION_NAPI, "RequestEnableLocation");
104 }
105 
EnableAbility(bool enable)106 void LocatorImpl::EnableAbility(bool enable)
107 {
108     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
109         return;
110     }
111     LocationErrCode errorCode = CheckEdmPolicy(enable);
112     if (errorCode != ERRCODE_SUCCESS) {
113         return;
114     }
115     sptr<ILocatorService> proxy = GetProxy();
116     if (proxy == nullptr) {
117         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
118         return;
119     }
120     ErrCode errCode = proxy->EnableAbility(enable);
121     if (errCode != ERRCODE_SUCCESS) {
122         LBSLOGE(LOCATOR_STANDARD, "%{public}s failed. %{public}d", __func__, errCode);
123     }
124 }
125 
StartLocating(std::unique_ptr<RequestConfig> & requestConfig,sptr<ILocatorCallback> & callback)126 void LocatorImpl::StartLocating(std::unique_ptr<RequestConfig>& requestConfig,
127     sptr<ILocatorCallback>& callback)
128 {
129     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
130         return;
131     }
132     sptr<ILocatorService> proxy = GetProxy();
133     if (proxy == nullptr) {
134         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
135         return;
136     }
137     if (IsLocationCallbackRegistered(callback)) {
138         LBSLOGE(LOCATOR_STANDARD, "%{public}s locatorCallback has registered", __func__);
139         return;
140     }
141     AddLocationCallBack(requestConfig, callback);
142     int errCode = proxy->StartLocating(*requestConfig, callback);
143     if (errCode != ERRCODE_SUCCESS) {
144         RemoveLocationCallBack(callback);
145     }
146 }
147 
StopLocating(sptr<ILocatorCallback> & callback)148 void LocatorImpl::StopLocating(sptr<ILocatorCallback>& callback)
149 {
150     if (callback == nullptr) {
151         LBSLOGE(LOCATOR_STANDARD, "%{public}s callback is nullptr", __func__);
152         return;
153     }
154     RemoveLocationCallBack(callback);
155     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
156         return;
157     }
158     sptr<ILocatorService> proxy = GetProxy();
159     if (proxy == nullptr) {
160         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
161         return;
162     }
163     proxy->StopLocating(callback);
164 }
165 
GetCachedLocation()166 std::unique_ptr<Location> LocatorImpl::GetCachedLocation()
167 {
168     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
169         return nullptr;
170     }
171     sptr<ILocatorService> proxy = GetProxy();
172     if (proxy == nullptr) {
173         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
174         return nullptr;
175     }
176     std::unique_ptr<Location> location = std::make_unique<Location>();
177     ErrCode errorCodeValue = proxy->GetCacheLocation(*location);
178     if (errorCodeValue != ERRCODE_SUCCESS) {
179         LBSLOGE(LOCATOR_STANDARD, "cause some exception happened in lower service.");
180         location = nullptr;
181     }
182     return location;
183 }
184 
RegisterSwitchCallback(const sptr<IRemoteObject> & callback,pid_t uid)185 bool LocatorImpl::RegisterSwitchCallback(const sptr<IRemoteObject>& callback, pid_t uid)
186 {
187     if (locationDataManager_ == nullptr) {
188         return false;
189     }
190     AppIdentity appIdentity;
191     appIdentity.SetTokenId(IPCSkeleton::GetCallingTokenID());
192     appIdentity.SetUid(IPCSkeleton::GetCallingUid());
193     return locationDataManager_->RegisterSwitchCallback(callback, appIdentity) == ERRCODE_SUCCESS;
194 }
195 
UnregisterSwitchCallback(const sptr<IRemoteObject> & callback)196 bool LocatorImpl::UnregisterSwitchCallback(const sptr<IRemoteObject>& callback)
197 {
198     if (locationDataManager_ == nullptr) {
199         return false;
200     }
201     return locationDataManager_->UnregisterSwitchCallback(callback) == ERRCODE_SUCCESS;
202 }
203 
RegisterGnssStatusCallback(const sptr<IRemoteObject> & callback,pid_t uid)204 bool LocatorImpl::RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid)
205 {
206     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
207         return false;
208     }
209     sptr<ILocatorService> proxy = GetProxy();
210     if (proxy == nullptr) {
211         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
212         return false;
213     }
214     if (IsSatelliteStatusChangeCallbackRegistered(callback)) {
215         LBSLOGE(LOCATOR_STANDARD, "%{public}s callback has registered.", __func__);
216         return false;
217     }
218     AddSatelliteStatusChangeCallBack(callback);
219     proxy->RegisterGnssStatusCallback(callback);
220     return true;
221 }
222 
UnregisterGnssStatusCallback(const sptr<IRemoteObject> & callback)223 bool LocatorImpl::UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback)
224 {
225     if (callback == nullptr) {
226         LBSLOGE(LOCATOR_STANDARD, "%{public}s callback is nullptr", __func__);
227         return false;
228     }
229     RemoveSatelliteStatusChangeCallBack(callback);
230     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
231         return false;
232     }
233     sptr<ILocatorService> proxy = GetProxy();
234     if (proxy == nullptr) {
235         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
236         return false;
237     }
238     proxy->UnregisterGnssStatusCallback(callback);
239     return true;
240 }
241 
RegisterNmeaMessageCallback(const sptr<IRemoteObject> & callback,pid_t uid)242 bool LocatorImpl::RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid)
243 {
244     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
245         return false;
246     }
247     sptr<ILocatorService> proxy = GetProxy();
248     if (proxy == nullptr) {
249         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
250         return false;
251     }
252     if (IsNmeaCallbackRegistered(callback)) {
253         LBSLOGE(LOCATOR_STANDARD, "%{public}s callback has registered.", __func__);
254         return false;
255     }
256     AddNmeaCallBack(callback);
257     proxy->RegisterNmeaMessageCallback(callback);
258     return true;
259 }
260 
UnregisterNmeaMessageCallback(const sptr<IRemoteObject> & callback)261 bool LocatorImpl::UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback)
262 {
263     if (callback == nullptr) {
264         LBSLOGE(LOCATOR_STANDARD, "%{public}s callback is nullptr", __func__);
265         return false;
266     }
267     RemoveNmeaCallBack(callback);
268     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
269         return false;
270     }
271     sptr<ILocatorService> proxy = GetProxy();
272     if (proxy == nullptr) {
273         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
274         return false;
275     }
276     proxy->UnregisterNmeaMessageCallback(callback);
277     return true;
278 }
279 
RegisterCountryCodeCallback(const sptr<IRemoteObject> & callback,pid_t uid)280 bool LocatorImpl::RegisterCountryCodeCallback(const sptr<IRemoteObject>& callback, pid_t uid)
281 {
282     auto countryCodeManager = CountryCodeManager::GetInstance();
283     if (countryCodeManager == nullptr) {
284         LBSLOGE(LOCATOR, "%{public}s countryCodeManager is nullptr", __func__);
285         return false;
286     }
287     AppIdentity identity;
288     identity.SetPid(IPCSkeleton::GetCallingPid());
289     identity.SetUid(IPCSkeleton::GetCallingUid());
290     identity.SetTokenId(IPCSkeleton::GetCallingTokenID());
291     identity.SetTokenIdEx(IPCSkeleton::GetCallingFullTokenID());
292     identity.SetFirstTokenId(IPCSkeleton::GetFirstTokenID());
293     std::string bundleName = "";
294     if (!CommonUtils::GetBundleNameByUid(identity.GetUid(), bundleName)) {
295         LBSLOGD(LOCATOR, "Fail to Get bundle name: uid = %{public}d.", identity.GetUid());
296     }
297     identity.SetBundleName(bundleName);
298     countryCodeManager->RegisterCountryCodeCallback(callback, identity);
299     return true;
300 }
301 
UnregisterCountryCodeCallback(const sptr<IRemoteObject> & callback)302 bool LocatorImpl::UnregisterCountryCodeCallback(const sptr<IRemoteObject>& callback)
303 {
304     auto countryCodeManager = CountryCodeManager::GetInstance();
305     if (countryCodeManager == nullptr) {
306         LBSLOGE(LOCATOR, "%{public}s countryCodeManager is nullptr", __func__);
307         return false;
308     }
309     countryCodeManager->UnregisterCountryCodeCallback(callback);
310     return true;
311 }
312 
RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLocationsRequest> & request,sptr<ICachedLocationsCallback> & callback)313 void LocatorImpl::RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLocationsRequest>& request,
314     sptr<ICachedLocationsCallback>& callback)
315 {
316     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
317         return;
318     }
319     sptr<ILocatorService> proxy = GetProxy();
320     if (proxy == nullptr) {
321         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
322         return;
323     }
324     proxy->RegisterCachedLocationCallback(request->reportingPeriodSec,
325         request->wakeUpCacheQueueFull, callback, "location.ILocatorService");
326 }
327 
UnregisterCachedLocationCallback(sptr<ICachedLocationsCallback> & callback)328 void LocatorImpl::UnregisterCachedLocationCallback(sptr<ICachedLocationsCallback>& callback)
329 {
330     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
331         return;
332     }
333     sptr<ILocatorService> proxy = GetProxy();
334     if (proxy == nullptr) {
335         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
336         return;
337     }
338     if (callback == nullptr) {
339         return;
340     }
341     proxy->UnregisterCachedLocationCallback(callback);
342 }
343 
IsGeoServiceAvailable()344 bool LocatorImpl::IsGeoServiceAvailable()
345 {
346     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
347         return false;
348     }
349     bool res = false;
350     sptr<ILocatorService> proxy = GetProxy();
351     if (proxy == nullptr) {
352         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
353         return false;
354     }
355     proxy->IsGeoConvertAvailable(res);
356     return res;
357 }
358 
GetAddressByCoordinate(MessageParcel & data,std::list<std::shared_ptr<GeoAddress>> & replyList)359 void LocatorImpl::GetAddressByCoordinate(MessageParcel &data, std::list<std::shared_ptr<GeoAddress>>& replyList)
360 {
361     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
362         return;
363     }
364     sptr<ILocatorService> proxy = GetProxy();
365     if (proxy == nullptr) {
366         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
367         return;
368     }
369     sptr<GeoConvertCallbackHost> callback = new (std::nothrow) GeoConvertCallbackHost();
370     if (callback == nullptr) {
371         LBSLOGE(LOCATOR_STANDARD, "can not get valid callback.");
372         return;
373     }
374     data.ReadInterfaceToken();
375     std::unique_ptr<GeocodeConvertLocationRequest> request =
376         GeocodeConvertLocationRequest::UnmarshallingMessageParcel(data);
377     proxy->GetAddressByCoordinate(callback->AsObject(), *request);
378     replyList = callback->GetResult();
379     uint32_t tokenId = IPCSkeleton::GetCallingTokenID();
380     uint64_t tokenIdEx = IPCSkeleton::GetCallingFullTokenID();
381     bool flag = false;
382     if (PermissionManager::CheckSystemPermission(tokenId, tokenIdEx)) {
383         flag = true;
384     }
385     for (auto iter = replyList.begin(); iter != replyList.end(); ++iter) {
386         auto geoAddress = *iter;
387         geoAddress->SetIsSystemApp(flag);
388     }
389 }
390 
GetAddressByLocationName(MessageParcel & data,std::list<std::shared_ptr<GeoAddress>> & replyList)391 void LocatorImpl::GetAddressByLocationName(MessageParcel &data, std::list<std::shared_ptr<GeoAddress>>& replyList)
392 {
393     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
394         return;
395     }
396     sptr<ILocatorService> proxy = GetProxy();
397     if (proxy == nullptr) {
398         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
399         return;
400     }
401     sptr<GeoConvertCallbackHost> callback = new (std::nothrow) GeoConvertCallbackHost();
402     if (callback == nullptr) {
403         LBSLOGE(LOCATOR_STANDARD, "can not get valid callback.");
404         return;
405     }
406     data.ReadInterfaceToken();
407     std::unique_ptr<GeocodeConvertAddressRequest> request =
408         GeocodeConvertAddressRequest::UnmarshallingMessageParcel(data);
409     proxy->GetAddressByLocationName(callback->AsObject(), *request);
410     replyList = callback->GetResult();
411     uint32_t tokenId = IPCSkeleton::GetCallingTokenID();
412     uint64_t tokenIdEx = IPCSkeleton::GetCallingFullTokenID();
413     bool flag = false;
414     if (PermissionManager::CheckSystemPermission(tokenId, tokenIdEx)) {
415         flag = true;
416     }
417     for (auto iter = replyList.begin(); iter != replyList.end(); ++iter) {
418         auto geoAddress = *iter;
419         geoAddress->SetIsSystemApp(flag);
420     }
421 }
422 
IsLocationPrivacyConfirmed(const int type)423 bool LocatorImpl::IsLocationPrivacyConfirmed(const int type)
424 {
425     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
426         return false;
427     }
428     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::IsLocationPrivacyConfirmed()");
429     sptr<ILocatorService> proxy = GetProxy();
430     if (proxy == nullptr) {
431         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
432         return false;
433     }
434     bool flag = false;
435     proxy->IsLocationPrivacyConfirmed(type, flag);
436     return flag;
437 }
438 
SetLocationPrivacyConfirmStatus(const int type,bool isConfirmed)439 int LocatorImpl::SetLocationPrivacyConfirmStatus(const int type, bool isConfirmed)
440 {
441     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
442         return false;
443     }
444     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::SetLocationPrivacyConfirmStatus()");
445     sptr<ILocatorService> proxy = GetProxy();
446     if (proxy == nullptr) {
447         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
448         return false;
449     }
450     ErrCode errorCodeValue = proxy->SetLocationPrivacyConfirmStatus(type, isConfirmed);
451     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
452     return locationErrCode;
453 }
454 
GetCachedGnssLocationsSize()455 int LocatorImpl::GetCachedGnssLocationsSize()
456 {
457     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
458         return -1;
459     }
460     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::GetCachedGnssLocationsSize()");
461     sptr<ILocatorService> proxy = GetProxy();
462     if (proxy == nullptr) {
463         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
464         return false;
465     }
466     int size = 0;
467     proxy->GetCachedGnssLocationsSize(size);
468     return size;
469 }
470 
FlushCachedGnssLocations()471 int LocatorImpl::FlushCachedGnssLocations()
472 {
473     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
474         return -1;
475     }
476     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::FlushCachedGnssLocations()");
477     sptr<ILocatorService> proxy = GetProxy();
478     if (proxy == nullptr) {
479         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
480         return false;
481     }
482     ErrCode errorCodeValue = proxy->FlushCachedGnssLocations();
483     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
484     return locationErrCode;
485 }
486 
SendCommand(std::unique_ptr<LocationCommand> & commands)487 bool LocatorImpl::SendCommand(std::unique_ptr<LocationCommand>& commands)
488 {
489     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
490         return false;
491     }
492     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::SendCommand()");
493     sptr<ILocatorService> proxy = GetProxy();
494     if (proxy == nullptr) {
495         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
496         return false;
497     }
498     proxy->SendCommand(commands->scenario, commands->command);
499     return true;
500 }
501 
GetIsoCountryCode()502 std::shared_ptr<CountryCode> LocatorImpl::GetIsoCountryCode()
503 {
504     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::GetIsoCountryCode()");
505     auto countryCodeManager = CountryCodeManager::GetInstance();
506     if (countryCodeManager == nullptr) {
507         LBSLOGE(LOCATOR, "%{public}s countryCodeManager is nullptr", __func__);
508         return nullptr;
509     }
510     return countryCodeManager->GetIsoCountryCode();
511 }
512 
EnableLocationMock()513 bool LocatorImpl::EnableLocationMock()
514 {
515     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
516         return false;
517     }
518     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::EnableLocationMock()");
519     sptr<ILocatorService> proxy = GetProxy();
520     if (proxy == nullptr) {
521         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
522         return false;
523     }
524     ErrCode res = proxy->EnableLocationMock();
525     if (res != ERR_OK) {
526         return false;
527     }
528     return true;
529 }
530 
DisableLocationMock()531 bool LocatorImpl::DisableLocationMock()
532 {
533     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
534         return false;
535     }
536     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::DisableLocationMock()");
537     sptr<ILocatorService> proxy = GetProxy();
538     if (proxy == nullptr) {
539         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
540         return false;
541     }
542     ErrCode res = proxy->DisableLocationMock();
543     if (res != ERR_OK) {
544         return false;
545     }
546     return true;
547 }
548 
SetMockedLocations(const int timeInterval,const std::vector<std::shared_ptr<Location>> & location)549 bool LocatorImpl::SetMockedLocations(
550     const int timeInterval, const std::vector<std::shared_ptr<Location>> &location)
551 {
552     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
553         return false;
554     }
555     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::SetMockedLocations()");
556     sptr<ILocatorService> proxy = GetProxy();
557     if (proxy == nullptr) {
558         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
559         return false;
560     }
561     std::vector<Location> locationVector;
562     for (const auto& it : location) {
563         locationVector.push_back(*it);
564     }
565     ErrCode errorCodeValue = proxy->SetMockedLocations(timeInterval, locationVector);
566     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
567     if (locationErrCode != ERRCODE_SUCCESS) {
568         return false;
569     }
570     return true;
571 }
572 
EnableReverseGeocodingMock()573 bool LocatorImpl::EnableReverseGeocodingMock()
574 {
575     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
576         return false;
577     }
578     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::EnableReverseGeocodingMock()");
579     sptr<ILocatorService> proxy = GetProxy();
580     if (proxy == nullptr) {
581         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
582         return false;
583     }
584     ErrCode res = proxy->EnableReverseGeocodingMock();
585     if (res != ERR_OK) {
586         return false;
587     }
588     return true;
589 }
590 
DisableReverseGeocodingMock()591 bool LocatorImpl::DisableReverseGeocodingMock()
592 {
593     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
594         return false;
595     }
596     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::DisableReverseGeocodingMock()");
597     sptr<ILocatorService> proxy = GetProxy();
598     if (proxy == nullptr) {
599         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
600         return false;
601     }
602     ErrCode res = proxy->DisableReverseGeocodingMock();
603     if (res != ERR_OK) {
604         return false;
605     }
606     return true;
607 }
608 
SetReverseGeocodingMockInfo(std::vector<std::shared_ptr<GeocodingMockInfo>> & mockInfo)609 bool LocatorImpl::SetReverseGeocodingMockInfo(std::vector<std::shared_ptr<GeocodingMockInfo>>& mockInfo)
610 {
611     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
612         return false;
613     }
614     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::SetReverseGeocodingMockInfo()");
615     sptr<ILocatorService> proxy = GetProxy();
616     if (proxy == nullptr) {
617         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
618         return false;
619     }
620     std::vector<GeocodingMockInfo> mockInfoVector;
621     for (const auto& it : mockInfo) {
622         mockInfoVector.push_back(*it);
623     }
624     ErrCode errorCodeValue = proxy->SetReverseGeocodingMockInfo(mockInfoVector);
625     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
626     if (locationErrCode != ERRCODE_SUCCESS) {
627         return false;
628     }
629     return true;
630 }
631 
IsLocationEnabledV9(bool & isEnabled)632 LocationErrCode LocatorImpl::IsLocationEnabledV9(bool &isEnabled)
633 {
634     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::IsLocationEnabledV9()");
635     int32_t state = DEFAULT_SWITCH_STATE;
636     state = LocationDataRdbManager::GetSwitchStateFromSysparaForCurrentUser();
637     if (state == DISABLED || state == ENABLED) {
638         isEnabled = (state == ENABLED);
639         return ERRCODE_SUCCESS;
640     }
641     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
642         return ERRCODE_SERVICE_UNAVAILABLE;
643     }
644     sptr<ILocatorService> proxy = GetProxy();
645     if (proxy == nullptr) {
646         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
647         return ERRCODE_SERVICE_UNAVAILABLE;
648     }
649     proxy->GetSwitchState(state);
650     isEnabled = (state == ENABLED);
651     return ERRCODE_SUCCESS;
652 }
653 
IsLocationEnabledForUser(bool & isEnabled,int32_t userId)654 LocationErrCode LocatorImpl::IsLocationEnabledForUser(bool &isEnabled, int32_t userId)
655 {
656     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::IsLocationEnabledV9()");
657     int32_t state = DEFAULT_SWITCH_STATE;
658     state = LocationDataRdbManager::GetSwitchStateFromSysparaForUser(userId);
659     if (state == DISABLED || state == ENABLED) {
660         isEnabled = (state == ENABLED);
661         return ERRCODE_SUCCESS;
662     }
663     auto ret = LocationDataRdbManager::GetSwitchStateFromDbForUser(state, userId);
664     if (ret != ERRCODE_SUCCESS) {
665         return ERRCODE_SERVICE_UNAVAILABLE;
666     }
667     isEnabled = (state == ENABLED);
668     return ERRCODE_SUCCESS;
669 }
670 
CheckEdmPolicy(bool enable)671 LocationErrCode LocatorImpl::CheckEdmPolicy(bool enable)
672 {
673     std::string policy = "";
674     bool res = CommonUtils::GetEdmPolicy(policy);
675     if (!res || policy.empty()) {
676         LBSLOGE(LOCATOR_STANDARD, "get edm policy failed!");
677         return ERRCODE_SUCCESS;
678     }
679     if (policy == "force_open" && enable == false) {
680         LBSLOGE(LOCATOR_STANDARD, "disable location switch is not allowed");
681         return ERRCODE_EDM_POLICY_ABANDON;
682     } else if (policy == "disallow" && enable == true) {
683         LBSLOGE(LOCATOR_STANDARD, "enable location switch is not allowed");
684         return ERRCODE_EDM_POLICY_ABANDON;
685     }
686     return ERRCODE_SUCCESS;
687 }
688 
689 
EnableAbilityV9(bool enable)690 LocationErrCode LocatorImpl::EnableAbilityV9(bool enable)
691 {
692     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
693         return ERRCODE_SERVICE_UNAVAILABLE;
694     }
695     LocationErrCode errorCode = CheckEdmPolicy(enable);
696     if (errorCode != ERRCODE_SUCCESS) {
697         return errorCode;
698     }
699     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::EnableAbilityV9()");
700     sptr<ILocatorService> proxy = GetProxy();
701     if (proxy == nullptr) {
702         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
703         return ERRCODE_SERVICE_UNAVAILABLE;
704     }
705     ErrCode errorCodeValue = proxy->EnableAbility(enable);
706     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
707     return locationErrCode;
708 }
709 
EnableAbilityForUser(bool enable,int32_t userId)710 LocationErrCode LocatorImpl::EnableAbilityForUser(bool enable, int32_t userId)
711 {
712     if (!LocationSaLoadManager::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
713         return ERRCODE_SERVICE_UNAVAILABLE;
714     }
715     LocationErrCode errorCode = CheckEdmPolicy(enable);
716     if (errorCode != ERRCODE_SUCCESS) {
717         return errorCode;
718     }
719     sptr<ILocatorService> proxy = GetProxy();
720     if (proxy == nullptr) {
721         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
722         return ERRCODE_SERVICE_UNAVAILABLE;
723     }
724     ErrCode errorCodeValue = proxy->EnableAbilityForUser(enable, userId);
725     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
726     return locationErrCode;
727 }
728 
StartLocatingV9(std::unique_ptr<RequestConfig> & requestConfig,sptr<ILocatorCallback> & callback)729 LocationErrCode LocatorImpl::StartLocatingV9(std::unique_ptr<RequestConfig>& requestConfig,
730     sptr<ILocatorCallback>& callback)
731 {
732     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
733         return ERRCODE_SERVICE_UNAVAILABLE;
734     }
735     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::StartLocatingV9()");
736     sptr<ILocatorService> proxy = GetProxy();
737     if (proxy == nullptr) {
738         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
739         return ERRCODE_SERVICE_UNAVAILABLE;
740     }
741     if (IsLocationCallbackRegistered(callback)) {
742         LBSLOGE(LOCATOR_STANDARD, "%{public}s locatorCallback has registered", __func__);
743         return ERRCODE_SERVICE_UNAVAILABLE;
744     }
745     AddLocationCallBack(requestConfig, callback);
746     ErrCode errorCodeValue = proxy->StartLocating(*requestConfig, callback);
747     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
748     if (locationErrCode != ERRCODE_SUCCESS) {
749         RemoveLocationCallBack(callback);
750     }
751     return locationErrCode;
752 }
753 
StopLocatingV9(sptr<ILocatorCallback> & callback)754 LocationErrCode LocatorImpl::StopLocatingV9(sptr<ILocatorCallback>& callback)
755 {
756     if (callback == nullptr) {
757         LBSLOGE(LOCATOR_STANDARD, "%{public}s callback is nullptr", __func__);
758         return ERRCODE_INVALID_PARAM;
759     }
760     RemoveLocationCallBack(callback);
761     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
762         return ERRCODE_SERVICE_UNAVAILABLE;
763     }
764     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::StopLocatingV9()");
765     sptr<ILocatorService> proxy = GetProxy();
766     if (proxy == nullptr) {
767         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
768         return ERRCODE_SERVICE_UNAVAILABLE;
769     }
770     ErrCode errorCodeValue = proxy->StopLocating(callback);
771     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
772     return locationErrCode;
773 }
774 
GetCachedLocationV9(std::unique_ptr<Location> & loc)775 LocationErrCode LocatorImpl::GetCachedLocationV9(std::unique_ptr<Location> &loc)
776 {
777     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
778         return ERRCODE_SERVICE_UNAVAILABLE;
779     }
780     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::GetCachedLocationV9()");
781     sptr<ILocatorService> proxy = GetProxy();
782     if (proxy == nullptr) {
783         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
784         return ERRCODE_SERVICE_UNAVAILABLE;
785     }
786     if (loc == nullptr) {
787         loc = std::make_unique<Location>();
788     }
789     ErrCode errorCodeValue = proxy->GetCacheLocation(*loc);
790     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
791     if (locationErrCode != ERRCODE_SUCCESS) {
792         loc = nullptr;
793     }
794     return locationErrCode;
795 }
796 
RegisterSwitchCallbackV9(const sptr<IRemoteObject> & callback)797 LocationErrCode LocatorImpl::RegisterSwitchCallbackV9(const sptr<IRemoteObject>& callback)
798 {
799     if (locationDataManager_ == nullptr) {
800         return ERRCODE_SERVICE_UNAVAILABLE;
801     }
802     AppIdentity appIdentity;
803     appIdentity.SetTokenId(IPCSkeleton::GetCallingTokenID());
804     appIdentity.SetUid(IPCSkeleton::GetCallingUid());
805     return locationDataManager_->
806         RegisterSwitchCallback(callback, appIdentity);
807 }
808 
UnregisterSwitchCallbackV9(const sptr<IRemoteObject> & callback)809 LocationErrCode LocatorImpl::UnregisterSwitchCallbackV9(const sptr<IRemoteObject>& callback)
810 {
811     if (locationDataManager_ == nullptr) {
812         return ERRCODE_SERVICE_UNAVAILABLE;
813     }
814     return locationDataManager_->UnregisterSwitchCallback(callback);
815 }
816 
RegisterGnssStatusCallbackV9(const sptr<IRemoteObject> & callback)817 LocationErrCode LocatorImpl::RegisterGnssStatusCallbackV9(const sptr<IRemoteObject>& callback)
818 {
819     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
820         return ERRCODE_SERVICE_UNAVAILABLE;
821     }
822     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::RegisterGnssStatusCallbackV9()");
823     sptr<ILocatorService> proxy = GetProxy();
824     if (proxy == nullptr) {
825         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
826         return ERRCODE_SERVICE_UNAVAILABLE;
827     }
828     if (IsSatelliteStatusChangeCallbackRegistered(callback)) {
829         LBSLOGE(LOCATOR_STANDARD, "%{public}s callback has registered.", __func__);
830         return ERRCODE_SERVICE_UNAVAILABLE;
831     }
832     AddSatelliteStatusChangeCallBack(callback);
833     ErrCode errorCodeValue = proxy->RegisterGnssStatusCallback(callback);
834     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
835     if (locationErrCode != ERRCODE_SUCCESS) {
836         RemoveSatelliteStatusChangeCallBack(callback);
837     }
838     return locationErrCode;
839 }
840 
UnregisterGnssStatusCallbackV9(const sptr<IRemoteObject> & callback)841 LocationErrCode LocatorImpl::UnregisterGnssStatusCallbackV9(const sptr<IRemoteObject>& callback)
842 {
843     if (callback == nullptr) {
844         LBSLOGE(LOCATOR_STANDARD, "%{public}s callback is nullptr", __func__);
845         return ERRCODE_INVALID_PARAM;
846     }
847     RemoveSatelliteStatusChangeCallBack(callback);
848     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
849         return ERRCODE_SERVICE_UNAVAILABLE;
850     }
851     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::UnregisterGnssStatusCallbackV9()");
852     sptr<ILocatorService> proxy = GetProxy();
853     if (proxy == nullptr) {
854         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
855         return ERRCODE_SERVICE_UNAVAILABLE;
856     }
857     ErrCode errorCodeValue = proxy->UnregisterGnssStatusCallback(callback);
858     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
859     return locationErrCode;
860 }
861 
RegisterNmeaMessageCallbackV9(const sptr<IRemoteObject> & callback)862 LocationErrCode LocatorImpl::RegisterNmeaMessageCallbackV9(const sptr<IRemoteObject>& callback)
863 {
864     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
865         return ERRCODE_SERVICE_UNAVAILABLE;
866     }
867     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::RegisterNmeaMessageCallbackV9()");
868     sptr<ILocatorService> proxy = GetProxy();
869     if (proxy == nullptr) {
870         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
871         return ERRCODE_SERVICE_UNAVAILABLE;
872     }
873     if (IsNmeaCallbackRegistered(callback)) {
874         LBSLOGE(LOCATOR_STANDARD, "%{public}s callback has registered.", __func__);
875         return ERRCODE_SERVICE_UNAVAILABLE;
876     }
877     AddNmeaCallBack(callback);
878     ErrCode errorCodeValue = proxy->RegisterNmeaMessageCallback(callback);
879     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
880     if (locationErrCode != ERRCODE_SUCCESS) {
881         RemoveNmeaCallBack(callback);
882     }
883     return locationErrCode;
884 }
885 
UnregisterNmeaMessageCallbackV9(const sptr<IRemoteObject> & callback)886 LocationErrCode LocatorImpl::UnregisterNmeaMessageCallbackV9(const sptr<IRemoteObject>& callback)
887 {
888     if (callback == nullptr) {
889         LBSLOGE(LOCATOR_STANDARD, "%{public}s callback is nullptr", __func__);
890         return ERRCODE_INVALID_PARAM;
891     }
892     RemoveNmeaCallBack(callback);
893     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
894         return ERRCODE_SERVICE_UNAVAILABLE;
895     }
896     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::UnregisterNmeaMessageCallbackV9()");
897     sptr<ILocatorService> proxy = GetProxy();
898     if (proxy == nullptr) {
899         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
900         return ERRCODE_SERVICE_UNAVAILABLE;
901     }
902     ErrCode errorCodeValue = proxy->UnregisterNmeaMessageCallback(callback);
903     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
904     return locationErrCode;
905 }
906 
RegisterCountryCodeCallbackV9(const sptr<IRemoteObject> & callback)907 LocationErrCode LocatorImpl::RegisterCountryCodeCallbackV9(const sptr<IRemoteObject>& callback)
908 {
909     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::RegisterCountryCodeCallbackV9()");
910     auto countryCodeManager = CountryCodeManager::GetInstance();
911     if (countryCodeManager == nullptr) {
912         LBSLOGE(LOCATOR, "%{public}s countryCodeManager is nullptr", __func__);
913         return ERRCODE_SERVICE_UNAVAILABLE;
914     }
915     AppIdentity identity;
916     identity.SetPid(IPCSkeleton::GetCallingPid());
917     identity.SetUid(IPCSkeleton::GetCallingUid());
918     identity.SetTokenId(IPCSkeleton::GetCallingTokenID());
919     identity.SetTokenIdEx(IPCSkeleton::GetCallingFullTokenID());
920     identity.SetFirstTokenId(IPCSkeleton::GetFirstTokenID());
921     std::string bundleName = "";
922     if (!CommonUtils::GetBundleNameByUid(identity.GetUid(), bundleName)) {
923         LBSLOGD(LOCATOR, "Fail to Get bundle name: uid = %{public}d.", identity.GetUid());
924     }
925     identity.SetBundleName(bundleName);
926     countryCodeManager->RegisterCountryCodeCallback(callback, identity);
927     return ERRCODE_SUCCESS;
928 }
929 
UnregisterCountryCodeCallbackV9(const sptr<IRemoteObject> & callback)930 LocationErrCode LocatorImpl::UnregisterCountryCodeCallbackV9(const sptr<IRemoteObject>& callback)
931 {
932     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::UnregisterCountryCodeCallbackV9()");
933     auto countryCodeManager = CountryCodeManager::GetInstance();
934     if (countryCodeManager == nullptr) {
935         LBSLOGE(LOCATOR, "%{public}s countryCodeManager is nullptr", __func__);
936         return ERRCODE_SERVICE_UNAVAILABLE;
937     }
938     countryCodeManager->UnregisterCountryCodeCallback(callback);
939     return ERRCODE_SUCCESS;
940 }
941 
RegisterCachedLocationCallbackV9(std::unique_ptr<CachedGnssLocationsRequest> & request,sptr<ICachedLocationsCallback> & callback)942 LocationErrCode LocatorImpl::RegisterCachedLocationCallbackV9(std::unique_ptr<CachedGnssLocationsRequest>& request,
943     sptr<ICachedLocationsCallback>& callback)
944 {
945     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
946         return ERRCODE_SERVICE_UNAVAILABLE;
947     }
948     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::RegisterCachedLocationCallbackV9()");
949     sptr<ILocatorService> proxy = GetProxy();
950     if (proxy == nullptr) {
951         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
952         return ERRCODE_SERVICE_UNAVAILABLE;
953     }
954     ErrCode errorCodeValue = proxy->RegisterCachedLocationCallback(request->reportingPeriodSec,
955         request->wakeUpCacheQueueFull, callback, "location.ILocatorService");
956     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
957     return locationErrCode;
958 }
959 
UnregisterCachedLocationCallbackV9(sptr<ICachedLocationsCallback> & callback)960 LocationErrCode LocatorImpl::UnregisterCachedLocationCallbackV9(sptr<ICachedLocationsCallback>& callback)
961 {
962     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
963         return ERRCODE_SERVICE_UNAVAILABLE;
964     }
965     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::UnregisterCachedLocationCallbackV9()");
966     sptr<ILocatorService> proxy = GetProxy();
967     if (proxy == nullptr) {
968         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
969         return ERRCODE_SERVICE_UNAVAILABLE;
970     }
971     if (callback == nullptr) {
972         LBSLOGE(LOCATOR_STANDARD, "SendRegisterMsgToRemote callback is nullptr");
973         return ERRCODE_INVALID_PARAM;
974     }
975     ErrCode errorCodeValue = proxy->UnregisterCachedLocationCallback(callback);
976     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
977     return locationErrCode;
978 }
979 
IsGeoServiceAvailableV9(bool & isAvailable)980 LocationErrCode LocatorImpl::IsGeoServiceAvailableV9(bool &isAvailable)
981 {
982     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
983         return ERRCODE_SERVICE_UNAVAILABLE;
984     }
985     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::IsGeoServiceAvailableV9()");
986     sptr<ILocatorService> proxy = GetProxy();
987     if (proxy == nullptr) {
988         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
989         return ERRCODE_SERVICE_UNAVAILABLE;
990     }
991     ErrCode errorCodeValue = proxy->IsGeoConvertAvailable(isAvailable);
992     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
993     return locationErrCode;
994 }
995 
GetAddressByCoordinateV9(MessageParcel & data,std::list<std::shared_ptr<GeoAddress>> & replyList)996 LocationErrCode LocatorImpl::GetAddressByCoordinateV9(MessageParcel &data,
997     std::list<std::shared_ptr<GeoAddress>>& replyList)
998 {
999     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1000         return ERRCODE_SERVICE_UNAVAILABLE;
1001     }
1002     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::GetAddressByCoordinateV9()");
1003     sptr<ILocatorService> proxy = GetProxy();
1004     if (proxy == nullptr) {
1005         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1006         return ERRCODE_SERVICE_UNAVAILABLE;
1007     }
1008     sptr<GeoConvertCallbackHost> callback = new (std::nothrow) GeoConvertCallbackHost();
1009     if (callback == nullptr) {
1010         LBSLOGE(LOCATOR_STANDARD, "can not get valid callback.");
1011         return ERRCODE_REVERSE_GEOCODING_FAIL;
1012     }
1013     data.ReadInterfaceToken();
1014     std::unique_ptr<GeocodeConvertLocationRequest> request =
1015         GeocodeConvertLocationRequest::UnmarshallingMessageParcel(data);
1016     ErrCode errorCodeValue = proxy->GetAddressByCoordinate(callback->AsObject(), *request);
1017     replyList = callback->GetResult();
1018     if (replyList.size() == 0) {
1019         return ERRCODE_REVERSE_GEOCODING_FAIL;
1020     }
1021     uint32_t tokenId = IPCSkeleton::GetCallingTokenID();
1022     uint64_t tokenIdEx = IPCSkeleton::GetCallingFullTokenID();
1023     bool flag = false;
1024     if (PermissionManager::CheckSystemPermission(tokenId, tokenIdEx)) {
1025         flag = true;
1026     }
1027     for (auto iter = replyList.begin(); iter != replyList.end(); ++iter) {
1028         auto geoAddress = *iter;
1029         geoAddress->SetIsSystemApp(flag);
1030     }
1031     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1032     return locationErrCode;
1033 }
1034 
GetAddressByLocationNameV9(MessageParcel & data,std::list<std::shared_ptr<GeoAddress>> & replyList)1035 LocationErrCode LocatorImpl::GetAddressByLocationNameV9(MessageParcel &data,
1036     std::list<std::shared_ptr<GeoAddress>>& replyList)
1037 {
1038     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1039         return ERRCODE_SERVICE_UNAVAILABLE;
1040     }
1041     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::GetAddressByLocationNameV9()");
1042     sptr<ILocatorService> proxy = GetProxy();
1043     if (proxy == nullptr) {
1044         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1045         return ERRCODE_SERVICE_UNAVAILABLE;
1046     }
1047     sptr<GeoConvertCallbackHost> callback = new (std::nothrow) GeoConvertCallbackHost();
1048     if (callback == nullptr) {
1049         LBSLOGE(LOCATOR_STANDARD, "can not get valid callback.");
1050         return ERRCODE_GEOCODING_FAIL;
1051     }
1052     data.ReadInterfaceToken();
1053     std::unique_ptr<GeocodeConvertAddressRequest> request =
1054         GeocodeConvertAddressRequest::UnmarshallingMessageParcel(data);
1055     ErrCode errorCodeValue = proxy->GetAddressByLocationName(callback->AsObject(), *request);
1056     replyList = callback->GetResult();
1057     if (replyList.size() == 0) {
1058         return ERRCODE_GEOCODING_FAIL;
1059     }
1060     uint32_t tokenId = IPCSkeleton::GetCallingTokenID();
1061     uint64_t tokenIdEx = IPCSkeleton::GetCallingFullTokenID();
1062     bool flag = false;
1063     if (PermissionManager::CheckSystemPermission(tokenId, tokenIdEx)) {
1064         flag = true;
1065     }
1066     for (auto iter = replyList.begin(); iter != replyList.end(); ++iter) {
1067         auto geoAddress = *iter;
1068         geoAddress->SetIsSystemApp(flag);
1069     }
1070     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1071     return locationErrCode;
1072 }
1073 
IsLocationPrivacyConfirmedV9(const int type,bool & isConfirmed)1074 LocationErrCode LocatorImpl::IsLocationPrivacyConfirmedV9(const int type, bool &isConfirmed)
1075 {
1076     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1077         return ERRCODE_SERVICE_UNAVAILABLE;
1078     }
1079     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::IsLocationPrivacyConfirmedV9()");
1080     sptr<ILocatorService> proxy = GetProxy();
1081     if (proxy == nullptr) {
1082         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1083         return ERRCODE_SERVICE_UNAVAILABLE;
1084     }
1085     ErrCode errorCodeValue = proxy->IsLocationPrivacyConfirmed(type, isConfirmed);
1086     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1087     return locationErrCode;
1088 }
1089 
SetLocationPrivacyConfirmStatusV9(const int type,bool isConfirmed)1090 LocationErrCode LocatorImpl::SetLocationPrivacyConfirmStatusV9(const int type, bool isConfirmed)
1091 {
1092     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1093         return ERRCODE_SERVICE_UNAVAILABLE;
1094     }
1095     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::SetLocationPrivacyConfirmStatusV9()");
1096     sptr<ILocatorService> proxy = GetProxy();
1097     if (proxy == nullptr) {
1098         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1099         return ERRCODE_SERVICE_UNAVAILABLE;
1100     }
1101     ErrCode errorCodeValue = proxy->SetLocationPrivacyConfirmStatus(type, isConfirmed);
1102     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1103     return locationErrCode;
1104 }
1105 
GetCachedGnssLocationsSizeV9(int & size)1106 LocationErrCode LocatorImpl::GetCachedGnssLocationsSizeV9(int &size)
1107 {
1108     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1109         return ERRCODE_SERVICE_UNAVAILABLE;
1110     }
1111     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::GetCachedGnssLocationsSizeV9()");
1112     sptr<ILocatorService> proxy = GetProxy();
1113     if (proxy == nullptr) {
1114         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1115         return ERRCODE_SERVICE_UNAVAILABLE;
1116     }
1117     ErrCode errorCodeValue = proxy->GetCachedGnssLocationsSize(size);
1118     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1119     if (locationErrCode != ERRCODE_SUCCESS) {
1120         size = 0;
1121     }
1122     return locationErrCode;
1123 }
1124 
FlushCachedGnssLocationsV9()1125 LocationErrCode LocatorImpl::FlushCachedGnssLocationsV9()
1126 {
1127     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1128         return ERRCODE_SERVICE_UNAVAILABLE;
1129     }
1130     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::FlushCachedGnssLocationsV9()");
1131     sptr<ILocatorService> proxy = GetProxy();
1132     if (proxy == nullptr) {
1133         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1134         return ERRCODE_SERVICE_UNAVAILABLE;
1135     }
1136     ErrCode errorCodeValue = proxy->FlushCachedGnssLocations();
1137     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1138     return locationErrCode;
1139 }
1140 
SendCommandV9(std::unique_ptr<LocationCommand> & commands)1141 LocationErrCode LocatorImpl::SendCommandV9(std::unique_ptr<LocationCommand>& commands)
1142 {
1143     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1144         return ERRCODE_SERVICE_UNAVAILABLE;
1145     }
1146     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::SendCommandV9()");
1147     sptr<ILocatorService> proxy = GetProxy();
1148     if (proxy == nullptr) {
1149         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1150         return ERRCODE_SERVICE_UNAVAILABLE;
1151     }
1152     if (commands == nullptr) {
1153         return ERRCODE_INVALID_PARAM;
1154     }
1155     ErrCode errorCodeValue = proxy->SendCommand(commands->scenario, commands->command);
1156     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1157     return locationErrCode;
1158 }
1159 
GetIsoCountryCodeV9(std::shared_ptr<CountryCode> & countryCode)1160 LocationErrCode LocatorImpl::GetIsoCountryCodeV9(std::shared_ptr<CountryCode>& countryCode)
1161 {
1162     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::GetIsoCountryCodeV9()");
1163     auto countryCodeManager = CountryCodeManager::GetInstance();
1164     if (countryCodeManager == nullptr) {
1165         LBSLOGE(LOCATOR, "%{public}s countryCodeManager is nullptr", __func__);
1166         return ERRCODE_SERVICE_UNAVAILABLE;
1167     }
1168     countryCode = countryCodeManager->GetIsoCountryCode();
1169     return ERRCODE_SUCCESS;
1170 }
1171 
EnableLocationMockV9()1172 LocationErrCode LocatorImpl::EnableLocationMockV9()
1173 {
1174     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1175         return ERRCODE_SERVICE_UNAVAILABLE;
1176     }
1177     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::EnableLocationMockV9()");
1178     sptr<ILocatorService> proxy = GetProxy();
1179     if (proxy == nullptr) {
1180         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1181         return ERRCODE_SERVICE_UNAVAILABLE;
1182     }
1183     ErrCode errorCodeValue = proxy->EnableLocationMock();
1184     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1185     return locationErrCode;
1186 }
1187 
DisableLocationMockV9()1188 LocationErrCode LocatorImpl::DisableLocationMockV9()
1189 {
1190     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1191         return ERRCODE_SERVICE_UNAVAILABLE;
1192     }
1193     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::DisableLocationMockV9()");
1194     sptr<ILocatorService> proxy = GetProxy();
1195     if (proxy == nullptr) {
1196         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1197         return ERRCODE_SERVICE_UNAVAILABLE;
1198     }
1199     ErrCode errorCodeValue = proxy->DisableLocationMock();
1200     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1201     return locationErrCode;
1202 }
1203 
SetMockedLocationsV9(const int timeInterval,const std::vector<std::shared_ptr<Location>> & location)1204 LocationErrCode LocatorImpl::SetMockedLocationsV9(
1205     const int timeInterval, const std::vector<std::shared_ptr<Location>> &location)
1206 {
1207     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1208         return ERRCODE_SERVICE_UNAVAILABLE;
1209     }
1210     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::SetMockedLocationsV9()");
1211     sptr<ILocatorService> proxy = GetProxy();
1212     if (proxy == nullptr) {
1213         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1214         return ERRCODE_SERVICE_UNAVAILABLE;
1215     }
1216     std::vector<Location> locationVector;
1217     for (const auto& it : location) {
1218         locationVector.push_back(*it);
1219     }
1220     ErrCode errorCodeValue = proxy->SetMockedLocations(timeInterval, locationVector);
1221     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1222     return locationErrCode;
1223 }
1224 
EnableReverseGeocodingMockV9()1225 LocationErrCode LocatorImpl::EnableReverseGeocodingMockV9()
1226 {
1227     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1228         return ERRCODE_SERVICE_UNAVAILABLE;
1229     }
1230     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::EnableReverseGeocodingMockV9()");
1231     sptr<ILocatorService> proxy = GetProxy();
1232     if (proxy == nullptr) {
1233         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1234         return ERRCODE_SERVICE_UNAVAILABLE;
1235     }
1236     ErrCode errorCodeValue = proxy->EnableReverseGeocodingMock();
1237     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1238     return locationErrCode;
1239 }
1240 
DisableReverseGeocodingMockV9()1241 LocationErrCode LocatorImpl::DisableReverseGeocodingMockV9()
1242 {
1243     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1244         return ERRCODE_SERVICE_UNAVAILABLE;
1245     }
1246     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::DisableReverseGeocodingMockV9()");
1247     sptr<ILocatorService> proxy = GetProxy();
1248     if (proxy == nullptr) {
1249         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1250         return ERRCODE_SERVICE_UNAVAILABLE;
1251     }
1252     ErrCode errorCodeValue = proxy->DisableReverseGeocodingMock();
1253     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1254     return locationErrCode;
1255 }
1256 
SetReverseGeocodingMockInfoV9(std::vector<std::shared_ptr<GeocodingMockInfo>> & mockInfo)1257 LocationErrCode LocatorImpl::SetReverseGeocodingMockInfoV9(std::vector<std::shared_ptr<GeocodingMockInfo>>& mockInfo)
1258 {
1259     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1260         return ERRCODE_SERVICE_UNAVAILABLE;
1261     }
1262     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::SetReverseGeocodingMockInfoV9()");
1263     sptr<ILocatorService> proxy = GetProxy();
1264     if (proxy == nullptr) {
1265         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1266         return ERRCODE_SERVICE_UNAVAILABLE;
1267     }
1268     std::vector<GeocodingMockInfo> geocodingMockInfoVector;
1269     for (const auto& it : mockInfo) {
1270         geocodingMockInfoVector.push_back(*it);
1271     }
1272     ErrCode errorCodeValue = proxy->SetReverseGeocodingMockInfo(geocodingMockInfoVector);
1273     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1274     return locationErrCode;
1275 }
1276 
ProxyForFreeze(std::set<int> pidList,bool isProxy)1277 LocationErrCode LocatorImpl::ProxyForFreeze(std::set<int> pidList, bool isProxy)
1278 {
1279     if (!LocationSaLoadManager::CheckIfSystemAbilityAvailable(LOCATION_LOCATOR_SA_ID)) {
1280         LBSLOGI(LOCATOR_STANDARD, "%{public}s locator sa is not available.", __func__);
1281         isServerExist_ = false;
1282         return ERRCODE_SUCCESS;
1283     }
1284     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1285         LBSLOGE(LOCATOR_STANDARD, "%{public}s init locator sa failed", __func__);
1286         isServerExist_ = false;
1287         return ERRCODE_SERVICE_UNAVAILABLE;
1288     }
1289     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::ProxyForFreeze()");
1290     sptr<ILocatorService> proxy = GetProxy();
1291     if (proxy == nullptr) {
1292         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1293         return ERRCODE_SERVICE_UNAVAILABLE;
1294     }
1295     std::vector<int> dataVector(pidList.begin(), pidList.end());
1296     ErrCode errorCodeValue = proxy->ProxyForFreeze(dataVector, isProxy);
1297     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1298     return locationErrCode;
1299 }
1300 
ResetAllProxy()1301 LocationErrCode LocatorImpl::ResetAllProxy()
1302 {
1303     if (!LocationSaLoadManager::CheckIfSystemAbilityAvailable(LOCATION_LOCATOR_SA_ID)) {
1304         LBSLOGI(LOCATOR_STANDARD, "%{public}s, no need reset proxy", __func__);
1305         isServerExist_ = false;
1306         return ERRCODE_SUCCESS;
1307     }
1308     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1309         isServerExist_ = false;
1310         return ERRCODE_SERVICE_UNAVAILABLE;
1311     }
1312     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::ResetAllProxy()");
1313     sptr<ILocatorService> proxy = GetProxy();
1314     if (proxy == nullptr) {
1315         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1316         return ERRCODE_SERVICE_UNAVAILABLE;
1317     }
1318     ErrCode errorCodeValue = proxy->ResetAllProxy();
1319     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1320     return locationErrCode;
1321 }
1322 
RegisterLocatingRequiredDataCallback(std::unique_ptr<LocatingRequiredDataConfig> & dataConfig,sptr<ILocatingRequiredDataCallback> & callback)1323 LocationErrCode LocatorImpl::RegisterLocatingRequiredDataCallback(
1324     std::unique_ptr<LocatingRequiredDataConfig>& dataConfig, sptr<ILocatingRequiredDataCallback>& callback)
1325 {
1326     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1327         return ERRCODE_SERVICE_UNAVAILABLE;
1328     }
1329     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::%{public}s", __func__);
1330     sptr<ILocatorService> proxy = GetProxy();
1331     if (proxy == nullptr) {
1332         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1333         return ERRCODE_SERVICE_UNAVAILABLE;
1334     }
1335     ErrCode errorCodeValue = proxy->RegisterLocatingRequiredDataCallback(*dataConfig, callback);
1336     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1337     return locationErrCode;
1338 }
1339 
UnRegisterLocatingRequiredDataCallback(sptr<ILocatingRequiredDataCallback> & callback)1340 LocationErrCode LocatorImpl::UnRegisterLocatingRequiredDataCallback(sptr<ILocatingRequiredDataCallback>& callback)
1341 {
1342     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1343         return ERRCODE_SERVICE_UNAVAILABLE;
1344     }
1345     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::%{public}s", __func__);
1346     sptr<ILocatorService> proxy = GetProxy();
1347     if (proxy == nullptr) {
1348         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1349         return ERRCODE_SERVICE_UNAVAILABLE;
1350     }
1351     if (callback == nullptr) {
1352         LBSLOGE(LOCATOR_STANDARD, "SendRegisterMsgToRemote callback is nullptr");
1353         return ERRCODE_INVALID_PARAM;
1354     }
1355     ErrCode errorCodeValue = proxy->UnRegisterLocatingRequiredDataCallback(callback);
1356     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1357     return locationErrCode;
1358 }
1359 
SubscribeBluetoothScanResultChange(sptr<IBluetoothScanResultCallback> & callback)1360 LocationErrCode LocatorImpl::SubscribeBluetoothScanResultChange(sptr<IBluetoothScanResultCallback>& callback)
1361 {
1362     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1363         return ERRCODE_SERVICE_UNAVAILABLE;
1364     }
1365     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::SubscribeBluetoothScanResultChange()");
1366     sptr<ILocatorService> proxy = GetProxy();
1367     if (proxy == nullptr) {
1368         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1369         return ERRCODE_SERVICE_UNAVAILABLE;
1370     }
1371     if (callback == nullptr) {
1372         LBSLOGE(LOCATOR_STANDARD, "SendRegisterMsgToRemote callback is nullptr");
1373         return ERRCODE_SERVICE_UNAVAILABLE;
1374     }
1375     ErrCode errorCodeValue = proxy->SubscribeBluetoothScanResultChange(callback);
1376     if (errorCodeValue != ERRCODE_SUCCESS) {
1377         LBSLOGE(LOCATOR_STANDARD, "SubscribeBluetoothScanResultChange failed.");
1378     }
1379     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1380     return locationErrCode;
1381 }
1382 
UnSubscribeBluetoothScanResultChange(sptr<IBluetoothScanResultCallback> & callback)1383 LocationErrCode LocatorImpl::UnSubscribeBluetoothScanResultChange(sptr<IBluetoothScanResultCallback>& callback)
1384 {
1385     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1386         return ERRCODE_SERVICE_UNAVAILABLE;
1387     }
1388     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::UnSubscribeBluetoothScanResultChange()");
1389     sptr<ILocatorService> proxy = GetProxy();
1390     if (proxy == nullptr) {
1391         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1392         return ERRCODE_SERVICE_UNAVAILABLE;
1393     }
1394     if (callback == nullptr) {
1395         LBSLOGE(LOCATOR_STANDARD, "SendRegisterMsgToRemote callback is nullptr");
1396         return ERRCODE_SERVICE_UNAVAILABLE;
1397     }
1398     ErrCode errorCodeValue = proxy->UnSubscribeBluetoothScanResultChange(callback);
1399     if (errorCodeValue != ERRCODE_SUCCESS) {
1400         LBSLOGE(LOCATOR_STANDARD, "UnSubscribeBluetoothScanResultChange failed.");
1401     }
1402     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1403     return locationErrCode;
1404 }
1405 
SubscribeLocationError(sptr<ILocatorCallback> & callback)1406 LocationErrCode LocatorImpl::SubscribeLocationError(sptr<ILocatorCallback>& callback)
1407 {
1408     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1409         return ERRCODE_SERVICE_UNAVAILABLE;
1410     }
1411     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::StartLocatingV9()");
1412     sptr<ILocatorService> proxy = GetProxy();
1413     if (proxy == nullptr) {
1414         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1415         return ERRCODE_SERVICE_UNAVAILABLE;
1416     }
1417     ErrCode errorCodeValue = proxy->SubscribeLocationError(callback);
1418     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1419     if (locationErrCode != ERRCODE_SUCCESS) {
1420         LBSLOGE(LOCATOR_STANDARD, "SubscribeLocationError failed.");
1421     }
1422     return locationErrCode;
1423 }
1424 
UnSubscribeLocationError(sptr<ILocatorCallback> & callback)1425 LocationErrCode LocatorImpl::UnSubscribeLocationError(sptr<ILocatorCallback>& callback)
1426 {
1427     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1428         return ERRCODE_SERVICE_UNAVAILABLE;
1429     }
1430     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::StopLocatingV9()");
1431     sptr<ILocatorService> proxy = GetProxy();
1432     if (proxy == nullptr) {
1433         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1434         return ERRCODE_SERVICE_UNAVAILABLE;
1435     }
1436     if (callback == nullptr) {
1437         LBSLOGE(LOCATOR_STANDARD, "StopLocating callback is nullptr");
1438         return ERRCODE_SERVICE_UNAVAILABLE;
1439     }
1440     ErrCode errorCodeValue = proxy->UnSubscribeLocationError(callback);
1441     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1442     if (locationErrCode != ERRCODE_SUCCESS) {
1443         LBSLOGE(LOCATOR_STANDARD, "UnSubscribeLocationError failed.");
1444     }
1445     return locationErrCode;
1446 }
1447 
GetCurrentWifiBssidForLocating(std::string & bssid)1448 LocationErrCode LocatorImpl::GetCurrentWifiBssidForLocating(std::string& bssid)
1449 {
1450     LBSLOGI(LOCATOR_STANDARD, "LocatorImpl::GetCurrentWifiBssidForLocating() enter");
1451     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1452         return ERRCODE_SERVICE_UNAVAILABLE;
1453     }
1454     sptr<ILocatorService> proxy = GetProxy();
1455     if (proxy == nullptr) {
1456         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1457         return ERRCODE_SERVICE_UNAVAILABLE;
1458     }
1459     ErrCode errorCodeValue = proxy->GetCurrentWifiBssidForLocating(bssid);
1460     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1461     return locationErrCode;
1462 }
1463 
IsPoiServiceSupported()1464 bool LocatorImpl::IsPoiServiceSupported()
1465 {
1466     LBSLOGI(LOCATOR_STANDARD, "LocatorImpl::IsPoiServiceSupported() enter");
1467     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1468         return false;
1469     }
1470     sptr<ILocatorService> proxy = GetProxy();
1471     if (proxy == nullptr) {
1472         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1473         return false;
1474     }
1475     bool poiServiceSupportState = false;
1476     proxy->IsPoiServiceSupported(poiServiceSupportState);
1477     return poiServiceSupportState;
1478 }
1479 
GetDistanceBetweenLocations(const Location & location1,const Location & location2,double & distance)1480 LocationErrCode LocatorImpl::GetDistanceBetweenLocations(const Location& location1,
1481     const Location& location2, double& distance)
1482 {
1483     LBSLOGI(LOCATOR_STANDARD, "LocatorImpl::GetDistanceBetweenLocations() enter");
1484     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1485         return ERRCODE_SERVICE_UNAVAILABLE;
1486     }
1487     sptr<ILocatorService> proxy = GetProxy();
1488     if (proxy == nullptr) {
1489         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1490         return ERRCODE_SERVICE_UNAVAILABLE;
1491     }
1492     distance = location1.GetDistanceBetweenLocations(location1.GetLatitude(), location1.GetLongitude(),
1493         location2.GetLatitude(), location2.GetLongitude());
1494     return ERRCODE_SUCCESS;
1495 }
1496 
ResetLocatorProxy(const wptr<IRemoteObject> & remote)1497 void LocatorImpl::ResetLocatorProxy(const wptr<IRemoteObject> &remote)
1498 {
1499     if (remote == nullptr) {
1500         LBSLOGE(LOCATOR_STANDARD, "%{public}s: remote is nullptr.", __func__);
1501         return;
1502     }
1503     if (client_ == nullptr || !isServerExist_) {
1504         LBSLOGE(LOCATOR_STANDARD, "%{public}s: proxy is nullptr.", __func__);
1505         return;
1506     }
1507     if (remote.promote() != nullptr) {
1508         remote.promote()->RemoveDeathRecipient(recipient_);
1509     }
1510     isServerExist_ = false;
1511     if (g_callbackResumer != nullptr && !IsCallbackResuming()) {
1512         // only the first request will be handled
1513         UpdateCallbackResumingState(true);
1514         // wait for remote died finished
1515         std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_MS));
1516         if (HasGnssNetworkRequest() && SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1517             g_callbackResumer->ResumeCallback();
1518         }
1519         UpdateCallbackResumingState(false);
1520     }
1521 }
1522 
GetProxy()1523 sptr<ILocatorService> LocatorImpl::GetProxy()
1524 {
1525     std::unique_lock<std::mutex> lock(mutex_);
1526     if (client_ != nullptr && isServerExist_) {
1527         return client_;
1528     }
1529 
1530     sptr<ISystemAbilityManager> sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
1531     if (sam == nullptr) {
1532         LBSLOGE(LOCATOR_STANDARD, "%{public}s: get samgr failed.", __func__);
1533         return nullptr;
1534     }
1535     sptr<IRemoteObject> obj = sam->CheckSystemAbility(LOCATION_LOCATOR_SA_ID);
1536     if (obj == nullptr) {
1537         LBSLOGE(LOCATOR_STANDARD, "%{public}s: get remote service failed.", __func__);
1538         return nullptr;
1539     }
1540     client_ = iface_cast<ILocatorService>(obj);
1541     if (!client_ || !client_->AsObject()) {
1542         LBSLOGE(LOCATOR_STANDARD, "%{public}s: get locator service failed.", __func__);
1543         return nullptr;
1544     }
1545     LBSLOGI(LOCATOR_STANDARD, "%{public}s: create locator proxy", __func__);
1546     recipient_ = sptr<LocatorDeathRecipient>(new (std::nothrow) LocatorDeathRecipient(*this));
1547     if ((obj->IsProxyObject()) && (!obj->AddDeathRecipient(recipient_))) {
1548         LBSLOGE(LOCATOR_STANDARD, "%{public}s: deathRecipient add failed.", __func__);
1549         return nullptr;
1550     }
1551     isServerExist_ = true;
1552     if (saStatusListener_ == nullptr) {
1553         saStatusListener_ = sptr<LocatorSystemAbilityListener>(new LocatorSystemAbilityListener());
1554     }
1555     int32_t result = sam->SubscribeSystemAbility(static_cast<int32_t>(LOCATION_LOCATOR_SA_ID), saStatusListener_);
1556     if (result != ERR_OK) {
1557         LBSLOGE(LOCATOR, "%{public}s SubcribeSystemAbility result is %{public}d!", __func__, result);
1558     }
1559     return client_;
1560 }
1561 
UpdateCallbackResumingState(bool state)1562 void LocatorImpl::UpdateCallbackResumingState(bool state)
1563 {
1564     std::unique_lock<std::mutex> lock(resumeMutex_);
1565     isCallbackResuming_ = state;
1566 }
1567 
IsCallbackResuming()1568 bool LocatorImpl::IsCallbackResuming()
1569 {
1570     std::unique_lock<std::mutex> lock(resumeMutex_);
1571     return isCallbackResuming_;
1572 }
1573 
IsLocationCallbackRegistered(const sptr<ILocatorCallback> & callback)1574 bool LocatorImpl::IsLocationCallbackRegistered(const sptr<ILocatorCallback>& callback)
1575 {
1576     if (callback == nullptr) {
1577         return true;
1578     }
1579     std::unique_lock<std::mutex> lock(g_locationCallbackMapMutex);
1580     for (auto iter = g_locationCallbackMap.begin(); iter != g_locationCallbackMap.end(); iter++) {
1581         auto locatorCallback = iter->first;
1582         if (locatorCallback == nullptr) {
1583             continue;
1584         }
1585         if (locatorCallback == callback) {
1586             return true;
1587         }
1588     }
1589     return false;
1590 }
1591 
IsSatelliteStatusChangeCallbackRegistered(const sptr<IRemoteObject> & callback)1592 bool LocatorImpl::IsSatelliteStatusChangeCallbackRegistered(const sptr<IRemoteObject>& callback)
1593 {
1594     if (callback == nullptr) {
1595         return true;
1596     }
1597     std::unique_lock<std::mutex> lock(g_gnssStatusInfoCallbacksMutex);
1598     for (auto gnssStatusCallback : g_gnssStatusInfoCallbacks) {
1599         if (gnssStatusCallback == callback) {
1600             return true;
1601         }
1602     }
1603     return false;
1604 }
1605 
IsNmeaCallbackRegistered(const sptr<IRemoteObject> & callback)1606 bool LocatorImpl::IsNmeaCallbackRegistered(const sptr<IRemoteObject>& callback)
1607 {
1608     if (callback == nullptr) {
1609         return true;
1610     }
1611     std::unique_lock<std::mutex> lock(g_nmeaCallbacksMutex);
1612     for (auto nmeaCallback : g_nmeaCallbacks) {
1613         if (nmeaCallback == callback) {
1614             return true;
1615         }
1616     }
1617     return false;
1618 }
1619 
AddLocationCallBack(std::unique_ptr<RequestConfig> & requestConfig,sptr<ILocatorCallback> & callback)1620 void LocatorImpl::AddLocationCallBack(std::unique_ptr<RequestConfig>& requestConfig,
1621     sptr<ILocatorCallback>& callback)
1622 {
1623     std::unique_lock<std::mutex> lock(g_locationCallbackMapMutex);
1624     g_locationCallbackMap.insert(std::make_pair(callback, *requestConfig));
1625 }
1626 
RemoveLocationCallBack(sptr<ILocatorCallback> & callback)1627 void LocatorImpl::RemoveLocationCallBack(sptr<ILocatorCallback>& callback)
1628 {
1629     std::unique_lock<std::mutex> lock(g_locationCallbackMapMutex);
1630     auto iter = g_locationCallbackMap.find(callback);
1631     if (iter != g_locationCallbackMap.end()) {
1632         g_locationCallbackMap.erase(iter);
1633     }
1634 }
1635 
AddSatelliteStatusChangeCallBack(const sptr<IRemoteObject> & callback)1636 void LocatorImpl::AddSatelliteStatusChangeCallBack(const sptr<IRemoteObject>& callback)
1637 {
1638     std::unique_lock<std::mutex> lock(g_gnssStatusInfoCallbacksMutex);
1639     g_gnssStatusInfoCallbacks.insert(callback);
1640 }
1641 
RemoveSatelliteStatusChangeCallBack(const sptr<IRemoteObject> & callback)1642 void LocatorImpl::RemoveSatelliteStatusChangeCallBack(const sptr<IRemoteObject>& callback)
1643 {
1644     std::unique_lock<std::mutex> lock(g_gnssStatusInfoCallbacksMutex);
1645     for (auto iter = g_gnssStatusInfoCallbacks.begin(); iter != g_gnssStatusInfoCallbacks.end(); iter++) {
1646         if (callback == *iter) {
1647             g_gnssStatusInfoCallbacks.erase(callback);
1648             break;
1649         }
1650     }
1651 }
1652 
AddNmeaCallBack(const sptr<IRemoteObject> & callback)1653 void LocatorImpl::AddNmeaCallBack(const sptr<IRemoteObject>& callback)
1654 {
1655     std::unique_lock<std::mutex> lock(g_nmeaCallbacksMutex);
1656     g_nmeaCallbacks.insert(callback);
1657 }
1658 
RemoveNmeaCallBack(const sptr<IRemoteObject> & callback)1659 void LocatorImpl::RemoveNmeaCallBack(const sptr<IRemoteObject>& callback)
1660 {
1661     std::unique_lock<std::mutex> lock(g_nmeaCallbacksMutex);
1662     for (auto iter = g_nmeaCallbacks.begin(); iter != g_nmeaCallbacks.end(); iter++) {
1663         if (callback == *iter) {
1664             g_nmeaCallbacks.erase(callback);
1665             break;
1666         }
1667     }
1668 }
1669 
HasGnssNetworkRequest()1670 bool LocatorImpl::HasGnssNetworkRequest()
1671 {
1672     bool ret = false;
1673     std::unique_lock<std::mutex> lock(g_locationCallbackMapMutex);
1674     for (auto iter = g_locationCallbackMap.begin(); iter != g_locationCallbackMap.end(); iter++) {
1675         auto locatorCallback = iter->first;
1676         if (locatorCallback == nullptr || iter->first == nullptr) {
1677             continue;
1678         }
1679         auto requestConfig = std::make_unique<RequestConfig>();
1680         requestConfig->Set(iter->second);
1681         if (requestConfig->GetScenario() != SCENE_NO_POWER &&
1682             (requestConfig->GetScenario() != SCENE_UNSET ||
1683             requestConfig->GetPriority() != PRIORITY_UNSET)) {
1684             ret = true;
1685             break;
1686         }
1687     }
1688     return ret;
1689 }
1690 
SetIsServerExist(bool isServerExist)1691 void LocatorImpl::SetIsServerExist(bool isServerExist)
1692 {
1693     isServerExist_ = isServerExist;
1694 }
1695 
SetLocationSwitchIgnored(bool enable)1696 LocationErrCode LocatorImpl::SetLocationSwitchIgnored(bool enable)
1697 {
1698     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1699         return ERRCODE_SERVICE_UNAVAILABLE;
1700     }
1701     LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::SetLocationSwitchIgnored()");
1702     sptr<ILocatorService> proxy = GetProxy();
1703     if (proxy == nullptr) {
1704         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1705         return ERRCODE_SERVICE_UNAVAILABLE;
1706     }
1707     ErrCode errorCodeValue = proxy->SetLocationSwitchIgnored(enable);
1708     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1709     return locationErrCode;
1710 }
1711 
AddBeaconFence(const std::shared_ptr<BeaconFenceRequest> & beaconFenceRequest)1712 LocationErrCode LocatorImpl::AddBeaconFence(const std::shared_ptr<BeaconFenceRequest>& beaconFenceRequest)
1713 {
1714     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1715         return ERRCODE_SERVICE_UNAVAILABLE;
1716     }
1717     LBSLOGI(LOCATOR_STANDARD, "LocatorImpl::AddBeaconFence()");
1718 #ifdef BLUETOOTH_ENABLE
1719     sptr<ILocatorService> proxy = GetProxy();
1720     if (proxy == nullptr) {
1721         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1722         return ERRCODE_SERVICE_UNAVAILABLE;
1723     }
1724     if (beaconFenceRequest == nullptr) {
1725         LBSLOGE(LOCATOR_STANDARD, "%{public}s beaconFenceRequest is nullptr.", __func__);
1726         return ERRCODE_SERVICE_UNAVAILABLE;
1727     }
1728     ErrCode errorCodeValue = proxy->AddBeaconFence(*beaconFenceRequest);
1729     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1730     return locationErrCode;
1731 #else
1732     return LOCATION_ERRCODE_NOT_SUPPORTED;
1733 #endif
1734 }
1735 
RemoveBeaconFence(const std::shared_ptr<BeaconFence> & beaconFence)1736 LocationErrCode LocatorImpl::RemoveBeaconFence(const std::shared_ptr<BeaconFence>& beaconFence)
1737 {
1738     if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
1739         return ERRCODE_SERVICE_UNAVAILABLE;
1740     }
1741     LBSLOGI(LOCATOR_STANDARD, "LocatorImpl::RemoveBeaconFence()");
1742 #ifdef BLUETOOTH_ENABLE
1743     sptr<ILocatorService> proxy = GetProxy();
1744     if (proxy == nullptr) {
1745         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1746         return ERRCODE_SERVICE_UNAVAILABLE;
1747     }
1748     if (beaconFence == nullptr) {
1749         LBSLOGE(LOCATOR_STANDARD, "%{public}s beaconFenceRequest is nullptr.", __func__);
1750         return ERRCODE_SERVICE_UNAVAILABLE;
1751     }
1752     ErrCode errorCodeValue = proxy->RemoveBeaconFence(*beaconFence);
1753     LocationErrCode locationErrCode = CommonUtils::ErrCodeToLocationErrCode(errorCodeValue);
1754     return locationErrCode;
1755 #else
1756     return LOCATION_ERRCODE_NOT_SUPPORTED;
1757 #endif
1758 }
1759 
IsBeaconFenceSupported()1760 bool LocatorImpl::IsBeaconFenceSupported()
1761 {
1762     LBSLOGI(LOCATOR_STANDARD, "LocatorImpl::IsBeaconFenceSupported() enter");
1763 #ifdef BLUETOOTH_ENABLE
1764     return true;
1765 #else
1766     return false;
1767 #endif
1768 }
1769 
ResumeCallback()1770 void CallbackResumeManager::ResumeCallback()
1771 {
1772     ResumeGnssStatusCallback();
1773     ResumeNmeaMessageCallback();
1774     ResumeLocating();
1775 }
1776 
ResumeGnssStatusCallback()1777 void CallbackResumeManager::ResumeGnssStatusCallback()
1778 {
1779     sptr<ILocatorService> proxy = g_locatorImpl->GetProxy();
1780     if (proxy == nullptr) {
1781         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1782         return ;
1783     }
1784     std::unique_lock<std::mutex> lock(g_gnssStatusInfoCallbacksMutex);
1785     for (auto gnssStatusCallback : g_gnssStatusInfoCallbacks) {
1786         if (gnssStatusCallback == nullptr) {
1787             continue;
1788         }
1789         proxy->RegisterGnssStatusCallback(gnssStatusCallback);
1790     }
1791 }
1792 
ResumeNmeaMessageCallback()1793 void CallbackResumeManager::ResumeNmeaMessageCallback()
1794 {
1795     sptr<ILocatorService> proxy = g_locatorImpl->GetProxy();
1796     if (proxy == nullptr) {
1797         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1798         return;
1799     }
1800     std::unique_lock<std::mutex> lock(g_nmeaCallbacksMutex);
1801     for (auto nmeaCallback : g_nmeaCallbacks) {
1802         if (nmeaCallback == nullptr) {
1803             continue;
1804         }
1805         proxy->RegisterNmeaMessageCallback(nmeaCallback);
1806     }
1807 }
1808 
ResumeLocating()1809 void CallbackResumeManager::ResumeLocating()
1810 {
1811     sptr<ILocatorService> proxy = g_locatorImpl->GetProxy();
1812     if (proxy == nullptr) {
1813         LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
1814         return;
1815     }
1816     std::unique_lock<std::mutex> lock(g_locationCallbackMapMutex);
1817     for (auto iter = g_locationCallbackMap.begin(); iter != g_locationCallbackMap.end(); iter++) {
1818         auto locatorCallback = iter->first;
1819         if (locatorCallback == nullptr || iter->first == nullptr) {
1820             continue;
1821         }
1822         auto requestConfig = std::make_unique<RequestConfig>();
1823         requestConfig->Set(iter->second);
1824         LBSLOGW(LOCATOR_STANDARD, "ResumeLocating requestConfig = %{public}s", requestConfig->ToString().c_str());
1825         proxy->StartLocating(*requestConfig, locatorCallback);
1826     }
1827 }
1828 
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)1829 void LocatorSystemAbilityListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
1830 {
1831     LBSLOGD(LOCATOR_STANDARD, "%{public}s enter", __func__);
1832     std::unique_lock<std::mutex> lock(mutex_);
1833     if (needResume_) {
1834         if (g_callbackResumer != nullptr && !g_locatorImpl->HasGnssNetworkRequest()) {
1835             g_callbackResumer->ResumeCallback();
1836         }
1837         needResume_ = false;
1838     }
1839 }
1840 
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)1841 void LocatorSystemAbilityListener::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
1842 {
1843     LBSLOGD(LOCATOR_STANDARD, "%{public}s enter", __func__);
1844     auto locatorImpl = LocatorImpl::GetInstance();
1845     if (locatorImpl != nullptr) {
1846         locatorImpl->SetIsServerExist(false);
1847     }
1848     std::unique_lock<std::mutex> lock(mutex_);
1849     needResume_ = true;
1850 }
1851 }  // namespace Location
1852 }  // namespace OHOS
1853