• 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_proxy.h"
17 
18 #include "ipc_types.h"
19 #include "iremote_object.h"
20 #include "iremote_proxy.h"
21 #include "message_option.h"
22 #include "message_parcel.h"
23 #include "refbase.h"
24 #include "string_ex.h"
25 
26 #include "common_utils.h"
27 #include "constant_definition.h"
28 #include "country_code.h"
29 #include "geo_coding_mock_info.h"
30 #include "i_cached_locations_callback.h"
31 #include "i_locator.h"
32 #include "i_locator_callback.h"
33 #include "location.h"
34 #include "location_log.h"
35 #include "request_config.h"
36 
37 namespace OHOS {
38 namespace Location {
LocatorProxy(const sptr<IRemoteObject> & impl)39 LocatorProxy::LocatorProxy(const sptr<IRemoteObject> &impl)
40     : IRemoteProxy<ILocator>(impl)
41 {
42 }
43 
GetSwitchState()44 int LocatorProxy::GetSwitchState()
45 {
46     MessageParcel reply;
47     int error = SendMsgWithReply(GET_SWITCH_STATE, reply);
48     LBSLOGD(LOCATOR_STANDARD, "Proxy::GetSwitchState Transact ErrCode = %{public}d", error);
49     int state = 0;
50     if (error == NO_ERROR && reply.ReadInt32() == ERRCODE_SUCCESS) {
51         state = reply.ReadInt32();
52     }
53     LBSLOGD(LOCATOR_STANDARD, "Proxy::GetSwitchState return  %{public}d", state);
54     return state;
55 }
56 
EnableAbility(bool isEnabled)57 void LocatorProxy::EnableAbility(bool isEnabled)
58 {
59     MessageParcel data;
60     MessageParcel reply;
61     if (!data.WriteInterfaceToken(GetDescriptor())) {
62         return;
63     }
64     data.WriteBool(isEnabled);
65     int error = SendMsgWithDataReply(ENABLE_ABILITY, data, reply);
66     LBSLOGD(LOCATOR_STANDARD, "Proxy::EnableAbility Transact ErrCodes = %{public}d", error);
67 }
68 
UpdateSaAbility()69 void LocatorProxy::UpdateSaAbility()
70 {
71     int state = SendSimpleMsg(UPDATE_SA_ABILITY);
72     LBSLOGD(LOCATOR_STANDARD, "Proxy::UpdateSaAbility return  %{public}d", state);
73 }
74 
SendMsgWithDataReply(const int msgId,MessageParcel & data,MessageParcel & reply)75 int LocatorProxy::SendMsgWithDataReply(const int msgId, MessageParcel& data, MessageParcel& reply)
76 {
77     int error;
78     MessageOption option;
79     sptr<IRemoteObject> remote = Remote();
80     if (remote == nullptr) {
81         LBSLOGE(LOCATOR_STANDARD, "SendMsgWithDataReply remote is null");
82         reply.WriteInt32(REPLY_CODE_EXCEPTION);
83         return REPLY_CODE_EXCEPTION;
84     }
85     error = remote->SendRequest(msgId, data, reply, option);
86     LBSLOGD(LOCATOR_STANDARD, "Proxy::SendMsgWithDataReply result from server.");
87     return error;
88 }
89 
SendMsgWithReply(const int msgId,MessageParcel & reply)90 int LocatorProxy::SendMsgWithReply(const int msgId, MessageParcel& reply)
91 {
92     MessageParcel data;
93     if (!data.WriteInterfaceToken(GetDescriptor())) {
94         LBSLOGE(LOCATOR_STANDARD, "SendMsgWithReply WriteInterfaceToken failed");
95         reply.WriteInt32(REPLY_CODE_EXCEPTION);
96         return REPLY_CODE_EXCEPTION;
97     }
98     return SendMsgWithDataReply(msgId, data, reply);
99 }
100 
SendSimpleMsg(const int msgId)101 int LocatorProxy::SendSimpleMsg(const int msgId)
102 {
103     MessageParcel reply;
104     return SendMsgWithReply(msgId, reply);
105 }
106 
SendRegisterMsgToRemote(const int msgId,const sptr<IRemoteObject> & callback,pid_t uid)107 int LocatorProxy::SendRegisterMsgToRemote(const int msgId, const sptr<IRemoteObject>& callback, pid_t uid)
108 {
109     MessageParcel data;
110     if (!data.WriteInterfaceToken(GetDescriptor())) {
111         LBSLOGE(LOCATOR_STANDARD, "SendRegisterMsgToRemote WriteInterfaceToken failed");
112         return REPLY_CODE_EXCEPTION;
113     }
114     if (callback == nullptr) {
115         LBSLOGE(LOCATOR_STANDARD, "SendRegisterMsgToRemote callback is nullptr");
116         return REPLY_CODE_EXCEPTION;
117     }
118     data.WriteObject<IRemoteObject>(callback);
119     MessageParcel reply;
120     MessageOption option;
121     sptr<IRemoteObject> remote = Remote();
122     if (remote == nullptr) {
123         LBSLOGE(LOCATOR_STANDARD, "SendRegisterMsgToRemote remote is null");
124         return REPLY_CODE_EXCEPTION;
125     }
126     return remote->SendRequest(msgId, data, reply, option);
127 }
128 
RegisterSwitchCallback(const sptr<IRemoteObject> & callback,pid_t uid)129 void LocatorProxy::RegisterSwitchCallback(const sptr<IRemoteObject>& callback, pid_t uid)
130 {
131     int error = SendRegisterMsgToRemote(REG_SWITCH_CALLBACK, callback, uid);
132     LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterSwitchCallback Transact ErrCodes = %{public}d", error);
133 }
134 
UnregisterSwitchCallback(const sptr<IRemoteObject> & callback)135 void LocatorProxy::UnregisterSwitchCallback(const sptr<IRemoteObject>& callback)
136 {
137     int error = SendRegisterMsgToRemote(UNREG_SWITCH_CALLBACK, callback, 0);
138     LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterSwitchCallback Transact ErrCodes = %{public}d", error);
139 }
140 
RegisterGnssStatusCallback(const sptr<IRemoteObject> & callback,pid_t uid)141 void LocatorProxy::RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid)
142 {
143     int error = SendRegisterMsgToRemote(REG_GNSS_STATUS_CALLBACK, callback, uid);
144     LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterGnssStatusCallback Transact ErrCodes = %{public}d", error);
145 }
146 
UnregisterGnssStatusCallback(const sptr<IRemoteObject> & callback)147 void LocatorProxy::UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback)
148 {
149     int error = SendRegisterMsgToRemote(UNREG_GNSS_STATUS_CALLBACK, callback, 0);
150     LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterGnssStatusCallback Transact ErrCodes = %{public}d", error);
151 }
152 
RegisterNmeaMessageCallback(const sptr<IRemoteObject> & callback,pid_t uid)153 void LocatorProxy::RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid)
154 {
155     int error = SendRegisterMsgToRemote(REG_NMEA_CALLBACK, callback, uid);
156     LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterNmeaMessageCallback Transact ErrCodes = %{public}d", error);
157 }
158 
UnregisterNmeaMessageCallback(const sptr<IRemoteObject> & callback)159 void LocatorProxy::UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback)
160 {
161     int error = SendRegisterMsgToRemote(UNREG_NMEA_CALLBACK, callback, 0);
162     LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterNmeaMessageCallback Transact ErrCodes = %{public}d", error);
163 }
164 
RegisterCountryCodeCallback(const sptr<IRemoteObject> & callback,pid_t uid)165 void LocatorProxy::RegisterCountryCodeCallback(const sptr<IRemoteObject> &callback, pid_t uid)
166 {
167     int error = SendRegisterMsgToRemote(REG_COUNTRY_CODE_CALLBACK, callback, uid);
168     LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterCountryCodeCallback Transact ErrCodes = %{public}d", error);
169 }
170 
UnregisterCountryCodeCallback(const sptr<IRemoteObject> & callback)171 void LocatorProxy::UnregisterCountryCodeCallback(const sptr<IRemoteObject> &callback)
172 {
173     int error = SendRegisterMsgToRemote(UNREG_COUNTRY_CODE_CALLBACK, callback, 0);
174     LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterCountryCodeCallback Transact ErrCodes = %{public}d", error);
175 }
176 
StartLocating(std::unique_ptr<RequestConfig> & requestConfig,sptr<ILocatorCallback> & callback,std::string bundleName,pid_t pid,pid_t uid)177 int LocatorProxy::StartLocating(std::unique_ptr<RequestConfig>& requestConfig,
178     sptr<ILocatorCallback>& callback, std::string bundleName, pid_t pid, pid_t uid)
179 {
180     LBSLOGD(LOCATOR_STANDARD, "uid is: %{public}d, pid is: %{public}d", uid, pid);
181     MessageParcel data;
182     if (!data.WriteInterfaceToken(GetDescriptor())) {
183         return REPLY_CODE_EXCEPTION;
184     }
185     if (requestConfig != nullptr) {
186         requestConfig->Marshalling(data);
187     }
188     if (callback != nullptr) {
189         data.WriteObject<IRemoteObject>(callback->AsObject());
190     }
191     data.WriteString16(Str8ToStr16(bundleName));
192     MessageParcel reply;
193     int error = SendMsgWithDataReply(START_LOCATING, data, reply);
194     LBSLOGD(LOCATOR_STANDARD, "Proxy::StartLocating Transact ErrCodes = %{public}d", error);
195     return error;
196 }
197 
StopLocating(sptr<ILocatorCallback> & callback)198 int LocatorProxy::StopLocating(sptr<ILocatorCallback>& callback)
199 {
200     if (callback == nullptr) {
201         LBSLOGE(LOCATOR_STANDARD, "StopLocating callback is nullptr");
202         return REPLY_CODE_EXCEPTION;
203     }
204     int error = SendRegisterMsgToRemote(STOP_LOCATING, callback->AsObject(), 0);
205     LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterCountryCodeCallback Transact ErrCodes = %{public}d", error);
206     return error;
207 }
208 
GetCacheLocation(MessageParcel & reply)209 int LocatorProxy::GetCacheLocation(MessageParcel &reply)
210 {
211     int error = SendMsgWithReply(GET_CACHE_LOCATION, reply);
212     LBSLOGD(LOCATOR_STANDARD, "Proxy::GetCacheLocation Transact ErrCodes = %{public}d", error);
213     return error;
214 }
215 
IsGeoConvertAvailable(MessageParcel & reply)216 int LocatorProxy::IsGeoConvertAvailable(MessageParcel &reply)
217 {
218     return SendMsgWithReply(GEO_IS_AVAILABLE, reply);
219 }
220 
GetAddressByCoordinate(MessageParcel & data,MessageParcel & reply)221 int LocatorProxy::GetAddressByCoordinate(MessageParcel &data, MessageParcel &reply)
222 {
223     return SendMsgWithDataReply(GET_FROM_COORDINATE, data, reply);
224 }
225 
GetAddressByLocationName(MessageParcel & data,MessageParcel & reply)226 int LocatorProxy::GetAddressByLocationName(MessageParcel &data, MessageParcel &reply)
227 {
228     return SendMsgWithDataReply(GET_FROM_LOCATION_NAME, data, reply);
229 }
230 
IsLocationPrivacyConfirmed(const int type)231 bool LocatorProxy::IsLocationPrivacyConfirmed(const int type)
232 {
233     MessageParcel data;
234     MessageParcel reply;
235     if (!data.WriteInterfaceToken(GetDescriptor())) {
236         return REPLY_CODE_EXCEPTION;
237     }
238     data.WriteInt32(type);
239     int error = SendMsgWithDataReply(IS_PRIVACY_COMFIRMED, data, reply);
240     LBSLOGD(LOCATOR_STANDARD, "Proxy::IsLocationPrivacyConfirmed Transact ErrCode = %{public}d", error);
241     bool state = false;
242     if (error == NO_ERROR && reply.ReadInt32() == ERRCODE_SUCCESS) {
243         state = reply.ReadBool();
244     }
245     LBSLOGD(LOCATOR_STANDARD, "Proxy::IsLocationPrivacyConfirmed return  %{public}d", state ? 1 : 0);
246     return state;
247 }
248 
SetLocationPrivacyConfirmStatus(const int type,bool isConfirmed)249 int LocatorProxy::SetLocationPrivacyConfirmStatus(const int type, bool isConfirmed)
250 {
251     MessageParcel data;
252     MessageParcel reply;
253     if (!data.WriteInterfaceToken(GetDescriptor())) {
254         LBSLOGE(LOCATOR_STANDARD, "SetLocationPrivacyConfirmStatus, WriteInterfaceToken failed.");
255         return REPLY_CODE_EXCEPTION;
256     }
257     data.WriteInt32(type);
258     data.WriteBool(isConfirmed);
259     SendMsgWithDataReply(SET_PRIVACY_COMFIRM_STATUS, data, reply);
260     int error = reply.ReadInt32();
261     LBSLOGD(LOCATOR_STANDARD, "Proxy::SetLocationPrivacyConfirmStatus Transact ErrCodes = %{public}d", error);
262     return error;
263 }
264 
RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLocationsRequest> & request,sptr<ICachedLocationsCallback> & callback,std::string bundleName)265 int LocatorProxy::RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLocationsRequest>& request,
266     sptr<ICachedLocationsCallback>& callback, std::string bundleName)
267 {
268     MessageParcel data;
269     if (!data.WriteInterfaceToken(GetDescriptor())) {
270         return REPLY_CODE_EXCEPTION;
271     }
272     if (request != nullptr) {
273         data.WriteInt32(request->reportingPeriodSec);
274         data.WriteBool(request->wakeUpCacheQueueFull);
275     }
276     if (callback != nullptr) {
277         data.WriteRemoteObject(callback->AsObject());
278     }
279     data.WriteString16(Str8ToStr16(bundleName));
280     MessageParcel reply;
281     int error = SendMsgWithDataReply(REG_CACHED_CALLBACK, data, reply);
282     LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterCachedLocationCallback Transact ErrCodes = %{public}d", error);
283     return error;
284 }
285 
UnregisterCachedLocationCallback(sptr<ICachedLocationsCallback> & callback)286 int LocatorProxy::UnregisterCachedLocationCallback(sptr<ICachedLocationsCallback>& callback)
287 {
288     int error = SendRegisterMsgToRemote(UNREG_CACHED_CALLBACK, callback->AsObject(), 0);
289     LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterCachedLocationCallback Transact ErrCodes = %{public}d", error);
290     return error;
291 }
292 
GetCachedGnssLocationsSize()293 int LocatorProxy::GetCachedGnssLocationsSize()
294 {
295     MessageParcel reply;
296     int error = SendMsgWithReply(GET_CACHED_LOCATION_SIZE, reply);
297     LBSLOGD(LOCATOR_STANDARD, "Proxy::GetCachedGnssLocationsSize Transact ErrCode = %{public}d", error);
298     int size = 0;
299     if (error == NO_ERROR && reply.ReadInt32() == ERRCODE_SUCCESS) {
300         size = reply.ReadInt32();
301     }
302     LBSLOGD(LOCATOR_STANDARD, "Proxy::GetCachedGnssLocationsSize return  %{public}d", size);
303     return size;
304 }
305 
FlushCachedGnssLocations()306 int LocatorProxy::FlushCachedGnssLocations()
307 {
308     MessageParcel reply;
309     int error = SendMsgWithReply(FLUSH_CACHED_LOCATIONS, reply);
310     LBSLOGD(LOCATOR_STANDARD, "Proxy::FlushCachedGnssLocations Transact ErrCodes = %{public}d", error);
311     if (error == NO_ERROR) {
312         return reply.ReadInt32();
313     }
314     return REPLY_CODE_EXCEPTION;
315 }
316 
SendCommand(std::unique_ptr<LocationCommand> & commands)317 void LocatorProxy::SendCommand(std::unique_ptr<LocationCommand>& commands)
318 {
319     MessageParcel data;
320     MessageParcel reply;
321     if (!data.WriteInterfaceToken(GetDescriptor())) {
322         return;
323     }
324     data.WriteInt32(commands->scenario);
325     data.WriteString16(Str8ToStr16(commands->command));
326     int error = SendMsgWithDataReply(SEND_COMMAND, data, reply);
327     LBSLOGD(LOCATOR_STANDARD, "Proxy::SendCommand Transact ErrCodes = %{public}d", error);
328 }
329 
AddFence(std::unique_ptr<GeofenceRequest> & request)330 void LocatorProxy::AddFence(std::unique_ptr<GeofenceRequest>& request)
331 {
332     MessageParcel data;
333     MessageParcel reply;
334     if (!data.WriteInterfaceToken(GetDescriptor())) {
335         return;
336     }
337     data.WriteInt32(request->scenario);
338     data.WriteDouble(request->geofence.latitude);
339     data.WriteDouble(request->geofence.longitude);
340     data.WriteDouble(request->geofence.radius);
341     data.WriteDouble(request->geofence.expiration);
342     int error = SendMsgWithDataReply(ADD_FENCE, data, reply);
343     LBSLOGD(LOCATOR_STANDARD, "Proxy::AddFence Transact ErrCodes = %{public}d", error);
344 }
345 
RemoveFence(std::unique_ptr<GeofenceRequest> & request)346 void LocatorProxy::RemoveFence(std::unique_ptr<GeofenceRequest>& request)
347 {
348     MessageParcel data;
349     MessageParcel reply;
350     if (!data.WriteInterfaceToken(GetDescriptor())) {
351         return;
352     }
353     data.WriteInt32(request->scenario);
354     data.WriteDouble(request->geofence.latitude);
355     data.WriteDouble(request->geofence.longitude);
356     data.WriteDouble(request->geofence.radius);
357     data.WriteDouble(request->geofence.expiration);
358     int error = SendMsgWithDataReply(REMOVE_FENCE, data, reply);
359     LBSLOGD(LOCATOR_STANDARD, "Proxy::RemoveFence Transact ErrCodes = %{public}d", error);
360 }
361 
GetIsoCountryCode()362 std::shared_ptr<CountryCode> LocatorProxy::GetIsoCountryCode()
363 {
364     MessageParcel reply;
365     int error = SendMsgWithReply(GET_ISO_COUNTRY_CODE, reply);
366     LBSLOGD(LOCATOR_STANDARD, "Proxy::GetIsoCountryCode Transact ErrCodes = %{public}d", error);
367     if (error == NO_ERROR && reply.ReadInt32() == ERRCODE_SUCCESS) {
368         std::string country = Str16ToStr8(reply.ReadString16());
369         int countryType = reply.ReadInt32();
370         auto countryCode = std::make_shared<CountryCode>();
371         countryCode->SetCountryCodeStr(country);
372         countryCode->SetCountryCodeType(countryType);
373         return countryCode;
374     } else {
375         return nullptr;
376     }
377 }
378 
EnableLocationMock()379 bool LocatorProxy::EnableLocationMock()
380 {
381     MessageParcel data;
382     MessageParcel reply;
383     if (!data.WriteInterfaceToken(GetDescriptor())) {
384         return false;
385     }
386     int error = SendMsgWithDataReply(ENABLE_LOCATION_MOCK, data, reply);
387     LBSLOGD(LOCATOR_STANDARD, "Proxy::EnableLocationMock Transact ErrCodes = %{public}d", error);
388     bool state = false;
389     if (error == NO_ERROR && reply.ReadInt32() == ERRCODE_SUCCESS) {
390         state = true;
391     }
392     return state;
393 }
394 
DisableLocationMock()395 bool LocatorProxy::DisableLocationMock()
396 {
397     MessageParcel data;
398     MessageParcel reply;
399     if (!data.WriteInterfaceToken(GetDescriptor())) {
400         return false;
401     }
402     int error = SendMsgWithDataReply(DISABLE_LOCATION_MOCK, data, reply);
403     LBSLOGD(LOCATOR_STANDARD, "Proxy::DisableLocationMock Transact ErrCodes = %{public}d", error);
404     bool state = false;
405     if (error == NO_ERROR && reply.ReadInt32() == ERRCODE_SUCCESS) {
406         state = true;
407     }
408     return state;
409 }
410 
SetMockedLocations(const int timeInterval,const std::vector<std::shared_ptr<Location>> & location)411 bool LocatorProxy::SetMockedLocations(
412     const int timeInterval, const std::vector<std::shared_ptr<Location>> &location)
413 {
414     MessageParcel data;
415     MessageParcel reply;
416     if (!data.WriteInterfaceToken(GetDescriptor())) {
417         return false;
418     }
419     data.WriteInt32(timeInterval);
420     int locationSize = static_cast<int>(location.size());
421     data.WriteInt32(locationSize);
422     for (int i = 0; i < locationSize; i++) {
423         location.at(i)->Marshalling(data);
424     }
425     int error = SendMsgWithDataReply(SET_MOCKED_LOCATIONS, data, reply);
426     LBSLOGD(LOCATOR_STANDARD, "Proxy::SetMockedLocations Transact ErrCodes = %{public}d", error);
427     bool state = false;
428     if (error == NO_ERROR && reply.ReadInt32() == ERRCODE_SUCCESS) {
429         state = true;
430     }
431     return state;
432 }
433 
EnableReverseGeocodingMock()434 bool LocatorProxy::EnableReverseGeocodingMock()
435 {
436     bool state = false;
437     MessageParcel reply;
438     int error = SendMsgWithReply(ENABLE_REVERSE_GEOCODE_MOCK, reply);
439     LBSLOGD(LOCATOR_STANDARD, "Proxy::EnableReverseGeocodingMock Transact ErrCodes = %{public}d", error);
440     if (error == NO_ERROR && reply.ReadInt32() == ERRCODE_SUCCESS) {
441         state = true;
442     }
443     return state;
444 }
445 
DisableReverseGeocodingMock()446 bool LocatorProxy::DisableReverseGeocodingMock()
447 {
448     bool state = false;
449     MessageParcel reply;
450     int error = SendMsgWithReply(DISABLE_REVERSE_GEOCODE_MOCK, reply);
451     LBSLOGD(LOCATOR_STANDARD, "Proxy::DisableReverseGeocodingMock Transact ErrCodes = %{public}d", error);
452     if (error == NO_ERROR && reply.ReadInt32() == ERRCODE_SUCCESS) {
453         state = true;
454     }
455     return state;
456 }
457 
SetReverseGeocodingMockInfo(std::vector<std::shared_ptr<GeocodingMockInfo>> & mockInfo)458 bool LocatorProxy::SetReverseGeocodingMockInfo(std::vector<std::shared_ptr<GeocodingMockInfo>>& mockInfo)
459 {
460     bool state = false;
461     MessageParcel data;
462     MessageParcel reply;
463     if (!data.WriteInterfaceToken(GetDescriptor())) {
464         return false;
465     }
466     data.WriteInt32(mockInfo.size());
467     for (size_t i = 0; i < mockInfo.size(); i++) {
468         mockInfo[i]->Marshalling(data);
469     }
470     int error = SendMsgWithDataReply(SET_REVERSE_GEOCODE_MOCKINFO, data, reply);
471     LBSLOGD(LOCATOR_STANDARD, "Proxy::SetReverseGeocodingMockInfo Transact ErrCodes = %{public}d", error);
472     if (error == NO_ERROR && reply.ReadInt32() == ERRCODE_SUCCESS) {
473         state = true;
474     }
475     return state;
476 }
477 
ProxyUidForFreeze(int32_t uid,bool isProxy)478 bool LocatorProxy::ProxyUidForFreeze(int32_t uid, bool isProxy)
479 {
480     bool state = false;
481     MessageParcel data;
482     MessageParcel reply;
483     if (!data.WriteInterfaceToken(GetDescriptor())) {
484         return false;
485     }
486 
487     if (!data.WriteInt32(uid) || !data.WriteBool(isProxy)) {
488         LBSLOGE(LOCATOR_STANDARD, "[ProxyUid] fail: write data failed");
489         return false;
490     }
491     int error = SendMsgWithDataReply(PROXY_UID_FOR_FREEZE, data, reply);
492     LBSLOGD(LOCATOR_STANDARD, "Proxy::ProxyUid Transact ErrCodes = %{public}d", error);
493     if (error == NO_ERROR && reply.ReadInt32() == ERRCODE_SUCCESS) {
494         state = true;
495     }
496     return state;
497 }
498 
ResetAllProxy()499 bool LocatorProxy::ResetAllProxy()
500 {
501     bool state = false;
502     MessageParcel reply;
503     int error = SendMsgWithReply(RESET_ALL_PROXY, reply);
504     LBSLOGD(LOCATOR_STANDARD, "Proxy::ResetAllProxy Transact ErrCodes = %{public}d", error);
505     if (error == NO_ERROR && reply.ReadInt32() == ERRCODE_SUCCESS) {
506         state = true;
507     }
508     return state;
509 }
510 
GetSwitchStateV9(bool & isEnabled)511 LocationErrCode LocatorProxy::GetSwitchStateV9(bool &isEnabled)
512 {
513     MessageParcel reply;
514     LocationErrCode errorCode = SendMsgWithReplyV9(GET_SWITCH_STATE, reply);
515     LBSLOGD(LOCATOR_STANDARD, "Proxy::GetSwitchState Transact ErrCode = %{public}d", errorCode);
516     int state = DISABLED;
517     if (errorCode == ERRCODE_SUCCESS) {
518         state = reply.ReadInt32();
519     }
520     isEnabled = (state == ENABLED);
521     LBSLOGD(LOCATOR_STANDARD, "Proxy::GetSwitchState return %{public}d", isEnabled);
522     return errorCode;
523 }
524 
EnableAbilityV9(bool isEnabled)525 LocationErrCode LocatorProxy::EnableAbilityV9(bool isEnabled)
526 {
527     MessageParcel data;
528     MessageParcel reply;
529     if (!data.WriteInterfaceToken(GetDescriptor())) {
530         return ERRCODE_SERVICE_UNAVAILABLE;
531     }
532     data.WriteBool(isEnabled);
533     LocationErrCode errorCode = SendMsgWithDataReplyV9(ENABLE_ABILITY, data, reply);
534     LBSLOGD(LOCATOR_STANDARD, "Proxy::EnableAbility Transact ErrCodes = %{public}d", errorCode);
535     return errorCode;
536 }
537 
UpdateSaAbilityV9()538 LocationErrCode LocatorProxy::UpdateSaAbilityV9()
539 {
540     LocationErrCode errorCode = SendSimpleMsgV9(UPDATE_SA_ABILITY);
541     LBSLOGD(LOCATOR_STANDARD, "Proxy::UpdateSaAbility Transact ErrCodes = %{public}d", errorCode);
542     return errorCode;
543 }
544 
SendMsgWithDataReplyV9(const int msgId,MessageParcel & data,MessageParcel & reply)545 LocationErrCode LocatorProxy::SendMsgWithDataReplyV9(const int msgId, MessageParcel& data, MessageParcel& reply)
546 {
547     MessageOption option;
548     sptr<IRemoteObject> remote = Remote();
549     if (remote == nullptr) {
550         LBSLOGE(LOCATOR_STANDARD, "SendMsgWithDataReply remote is null");
551         return ERRCODE_SERVICE_UNAVAILABLE;
552     }
553     int error = remote->SendRequest(msgId, data, reply, option);
554     if (error != NO_ERROR) {
555         LBSLOGE(LOCATOR_STANDARD, "msgid = %{public}d, send request error: %{public}d", msgId, error);
556         return ERRCODE_SERVICE_UNAVAILABLE;
557     }
558     LBSLOGD(LOCATOR_STANDARD, "Proxy::SendMsgWithDataReply result from server.");
559     return LocationErrCode(reply.ReadInt32());
560 }
561 
SendMsgWithReplyV9(const int msgId,MessageParcel & reply)562 LocationErrCode LocatorProxy::SendMsgWithReplyV9(const int msgId, MessageParcel& reply)
563 {
564     MessageParcel data;
565     if (!data.WriteInterfaceToken(GetDescriptor())) {
566         LBSLOGE(LOCATOR_STANDARD, "SendMsgWithReply WriteInterfaceToken failed");
567         return ERRCODE_SERVICE_UNAVAILABLE;
568     }
569     return SendMsgWithDataReplyV9(msgId, data, reply);
570 }
571 
SendSimpleMsgV9(const int msgId)572 LocationErrCode LocatorProxy::SendSimpleMsgV9(const int msgId)
573 {
574     MessageParcel reply;
575     return SendMsgWithReplyV9(msgId, reply);
576 }
577 
SendRegisterMsgToRemoteV9(const int msgId,const sptr<IRemoteObject> & callback)578 LocationErrCode LocatorProxy::SendRegisterMsgToRemoteV9(const int msgId, const sptr<IRemoteObject>& callback)
579 {
580     MessageParcel data;
581     if (!data.WriteInterfaceToken(GetDescriptor())) {
582         LBSLOGE(LOCATOR_STANDARD, "SendRegisterMsgToRemote WriteInterfaceToken failed");
583         return ERRCODE_SERVICE_UNAVAILABLE;
584     }
585     if (callback == nullptr) {
586         LBSLOGE(LOCATOR_STANDARD, "SendRegisterMsgToRemote callback is nullptr");
587         return ERRCODE_INVALID_PARAM;
588     }
589     data.WriteObject<IRemoteObject>(callback);
590     MessageParcel reply;
591     MessageOption option;
592     sptr<IRemoteObject> remote = Remote();
593     if (remote == nullptr) {
594         LBSLOGE(LOCATOR_STANDARD, "SendRegisterMsgToRemote remote is null");
595         return ERRCODE_SERVICE_UNAVAILABLE;
596     }
597     int error = remote->SendRequest(msgId, data, reply, option);
598     if (error != NO_ERROR) {
599         LBSLOGE(LOCATOR_STANDARD, "msgid = %{public}d, send request error: %{public}d", msgId, error);
600         return ERRCODE_SERVICE_UNAVAILABLE;
601     }
602     return LocationErrCode(reply.ReadInt32());
603 }
604 
RegisterSwitchCallbackV9(const sptr<IRemoteObject> & callback)605 LocationErrCode LocatorProxy::RegisterSwitchCallbackV9(const sptr<IRemoteObject>& callback)
606 {
607     LocationErrCode errorCode = SendRegisterMsgToRemoteV9(REG_SWITCH_CALLBACK, callback);
608     LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterSwitchCallback Transact ErrCodes = %{public}d", errorCode);
609     return errorCode;
610 }
611 
UnregisterSwitchCallbackV9(const sptr<IRemoteObject> & callback)612 LocationErrCode LocatorProxy::UnregisterSwitchCallbackV9(const sptr<IRemoteObject>& callback)
613 {
614     LocationErrCode errorCode = SendRegisterMsgToRemoteV9(UNREG_SWITCH_CALLBACK, callback);
615     LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterSwitchCallback Transact ErrCodes = %{public}d", errorCode);
616     return errorCode;
617 }
618 
RegisterGnssStatusCallbackV9(const sptr<IRemoteObject> & callback)619 LocationErrCode LocatorProxy::RegisterGnssStatusCallbackV9(const sptr<IRemoteObject>& callback)
620 {
621     LocationErrCode errorCode = SendRegisterMsgToRemoteV9(REG_GNSS_STATUS_CALLBACK, callback);
622     LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterGnssStatusCallback Transact ErrCodes = %{public}d", errorCode);
623     return errorCode;
624 }
625 
UnregisterGnssStatusCallbackV9(const sptr<IRemoteObject> & callback)626 LocationErrCode LocatorProxy::UnregisterGnssStatusCallbackV9(const sptr<IRemoteObject>& callback)
627 {
628     LocationErrCode errorCode = SendRegisterMsgToRemoteV9(UNREG_GNSS_STATUS_CALLBACK, callback);
629     LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterGnssStatusCallback Transact ErrCodes = %{public}d", errorCode);
630     return errorCode;
631 }
632 
RegisterNmeaMessageCallbackV9(const sptr<IRemoteObject> & callback)633 LocationErrCode LocatorProxy::RegisterNmeaMessageCallbackV9(const sptr<IRemoteObject>& callback)
634 {
635     MessageParcel data;
636     MessageParcel reply;
637     if (!data.WriteInterfaceToken(GetDescriptor())) {
638         LBSLOGE(LOCATOR_STANDARD, "WriteInterfaceToken failed");
639         return ERRCODE_SERVICE_UNAVAILABLE;
640     }
641     if (callback == nullptr) {
642         LBSLOGE(LOCATOR_STANDARD, "callback is nullptr");
643         return ERRCODE_INVALID_PARAM;
644     }
645     data.WriteObject<IRemoteObject>(callback);
646     LocationErrCode errorCode = SendMsgWithDataReplyV9(REG_NMEA_CALLBACK_v9, data, reply);
647     LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterNmeaMessageCallbackV9 Transact ErrCodes = %{public}d", errorCode);
648     return errorCode;
649 }
650 
UnregisterNmeaMessageCallbackV9(const sptr<IRemoteObject> & callback)651 LocationErrCode LocatorProxy::UnregisterNmeaMessageCallbackV9(const sptr<IRemoteObject>& callback)
652 {
653     MessageParcel data;
654     MessageParcel reply;
655     if (!data.WriteInterfaceToken(GetDescriptor())) {
656         LBSLOGE(LOCATOR_STANDARD, "WriteInterfaceToken failed");
657         return ERRCODE_SERVICE_UNAVAILABLE;
658     }
659     if (callback == nullptr) {
660         LBSLOGE(LOCATOR_STANDARD, "callback is nullptr");
661         return ERRCODE_INVALID_PARAM;
662     }
663     data.WriteObject<IRemoteObject>(callback);
664     LocationErrCode errorCode = SendMsgWithDataReplyV9(UNREG_NMEA_CALLBACK_v9, data, reply);
665     LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterNmeaMessageCallbackV9 Transact ErrCodes = %{public}d", errorCode);
666     return errorCode;
667 }
668 
RegisterCountryCodeCallbackV9(const sptr<IRemoteObject> & callback)669 LocationErrCode LocatorProxy::RegisterCountryCodeCallbackV9(const sptr<IRemoteObject> &callback)
670 {
671     LocationErrCode errorCode = SendRegisterMsgToRemoteV9(REG_COUNTRY_CODE_CALLBACK, callback);
672     LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterCountryCodeCallback Transact ErrCodes = %{public}d", errorCode);
673     return errorCode;
674 }
675 
UnregisterCountryCodeCallbackV9(const sptr<IRemoteObject> & callback)676 LocationErrCode LocatorProxy::UnregisterCountryCodeCallbackV9(const sptr<IRemoteObject> &callback)
677 {
678     LocationErrCode errorCode = SendRegisterMsgToRemoteV9(UNREG_COUNTRY_CODE_CALLBACK, callback);
679     LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterCountryCodeCallback Transact ErrCodes = %{public}d", errorCode);
680     return errorCode;
681 }
682 
StartLocatingV9(std::unique_ptr<RequestConfig> & requestConfig,sptr<ILocatorCallback> & callback)683 LocationErrCode LocatorProxy::StartLocatingV9(std::unique_ptr<RequestConfig>& requestConfig,
684     sptr<ILocatorCallback>& callback)
685 {
686     MessageParcel data;
687     if (!data.WriteInterfaceToken(GetDescriptor())) {
688         return ERRCODE_SERVICE_UNAVAILABLE;
689     }
690     if (requestConfig != nullptr) {
691         requestConfig->Marshalling(data);
692     }
693     if (callback != nullptr) {
694         data.WriteObject<IRemoteObject>(callback->AsObject());
695     }
696     MessageParcel reply;
697     LocationErrCode errorCode = SendMsgWithDataReplyV9(START_LOCATING, data, reply);
698     LBSLOGD(LOCATOR_STANDARD, "Proxy::StartLocating Transact ErrCodes = %{public}d", errorCode);
699     return errorCode;
700 }
701 
StopLocatingV9(sptr<ILocatorCallback> & callback)702 LocationErrCode LocatorProxy::StopLocatingV9(sptr<ILocatorCallback>& callback)
703 {
704     if (callback == nullptr) {
705         LBSLOGE(LOCATOR_STANDARD, "StopLocating callback is nullptr");
706         return ERRCODE_SERVICE_UNAVAILABLE;
707     }
708     LocationErrCode errorCode = SendRegisterMsgToRemoteV9(STOP_LOCATING, callback->AsObject());
709     LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterCountryCodeCallback Transact ErrCodes = %{public}d", errorCode);
710     return errorCode;
711 }
712 
GetCacheLocationV9(std::unique_ptr<Location> & loc)713 LocationErrCode LocatorProxy::GetCacheLocationV9(std::unique_ptr<Location> &loc)
714 {
715     MessageParcel reply;
716     LocationErrCode errorCode = SendMsgWithReplyV9(GET_CACHE_LOCATION, reply);
717     if (errorCode == ERRCODE_SUCCESS) {
718         loc = Location::Unmarshalling(reply);
719     } else {
720         loc = nullptr;
721     }
722     LBSLOGD(LOCATOR_STANDARD, "Proxy::GetCacheLocation Transact ErrCodes = %{public}d", errorCode);
723     return errorCode;
724 }
725 
IsGeoConvertAvailableV9(bool & isAvailable)726 LocationErrCode LocatorProxy::IsGeoConvertAvailableV9(bool &isAvailable)
727 {
728     MessageParcel reply;
729     LocationErrCode errorCode = SendMsgWithReplyV9(GEO_IS_AVAILABLE, reply);
730     if (errorCode == ERRCODE_SUCCESS) {
731         isAvailable = reply.ReadBool();
732     } else {
733         isAvailable = false;
734     }
735     LBSLOGD(LOCATOR_STANDARD, "Proxy::IsGeoConvertAvailable Transact ErrCodes = %{public}d", errorCode);
736     return errorCode;
737 }
738 
GetAddressByCoordinateV9(MessageParcel & data,std::list<std::shared_ptr<GeoAddress>> & replyList)739 LocationErrCode LocatorProxy::GetAddressByCoordinateV9(MessageParcel &data,
740     std::list<std::shared_ptr<GeoAddress>>& replyList)
741 {
742     MessageParcel reply;
743     LocationErrCode errorCode = SendMsgWithDataReplyV9(GET_FROM_COORDINATE, data, reply);
744     if (errorCode == ERRCODE_SUCCESS) {
745         int resultSize = reply.ReadInt32();
746         if (resultSize > GeoAddress::MAX_RESULT) {
747             resultSize = GeoAddress::MAX_RESULT;
748         }
749         for (int i = 0; i < resultSize; i++) {
750             replyList.push_back(GeoAddress::Unmarshalling(reply));
751         }
752     }
753     LBSLOGD(LOCATOR_STANDARD, "Proxy::GetAddressByCoordinate Transact ErrCodes = %{public}d", errorCode);
754     return errorCode;
755 }
756 
GetAddressByLocationNameV9(MessageParcel & data,std::list<std::shared_ptr<GeoAddress>> & replyList)757 LocationErrCode LocatorProxy::GetAddressByLocationNameV9(MessageParcel &data,
758     std::list<std::shared_ptr<GeoAddress>>& replyList)
759 {
760     MessageParcel reply;
761     LocationErrCode errorCode = SendMsgWithDataReplyV9(GET_FROM_LOCATION_NAME, data, reply);
762     if (errorCode == ERRCODE_SUCCESS) {
763         int resultSize = reply.ReadInt32();
764         if (resultSize > GeoAddress::MAX_RESULT) {
765             resultSize = GeoAddress::MAX_RESULT;
766         }
767         for (int i = 0; i < resultSize; i++) {
768             replyList.push_back(GeoAddress::Unmarshalling(reply));
769         }
770     }
771     LBSLOGD(LOCATOR_STANDARD, "Proxy::GetAddressByLocationName Transact ErrCodes = %{public}d", errorCode);
772     return errorCode;
773 }
774 
IsLocationPrivacyConfirmedV9(const int type,bool & isConfirmed)775 LocationErrCode LocatorProxy::IsLocationPrivacyConfirmedV9(const int type, bool &isConfirmed)
776 {
777     MessageParcel data;
778     MessageParcel reply;
779     if (!data.WriteInterfaceToken(GetDescriptor())) {
780         return ERRCODE_SERVICE_UNAVAILABLE;
781     }
782     data.WriteInt32(type);
783     LocationErrCode errorCode = SendMsgWithDataReplyV9(IS_PRIVACY_COMFIRMED, data, reply);
784     LBSLOGD(LOCATOR_STANDARD, "Proxy::IsLocationPrivacyConfirmed Transact ErrCodes = %{public}d", errorCode);
785     if (errorCode == ERRCODE_SUCCESS) {
786         isConfirmed = reply.ReadBool();
787     } else {
788         isConfirmed = false;
789     }
790     LBSLOGD(LOCATOR_STANDARD, "Proxy::IsLocationPrivacyConfirmed return  %{public}d", isConfirmed);
791     return errorCode;
792 }
793 
SetLocationPrivacyConfirmStatusV9(const int type,bool isConfirmed)794 LocationErrCode LocatorProxy::SetLocationPrivacyConfirmStatusV9(const int type, bool isConfirmed)
795 {
796     MessageParcel data;
797     MessageParcel reply;
798     if (!data.WriteInterfaceToken(GetDescriptor())) {
799         LBSLOGE(LOCATOR_STANDARD, "SetLocationPrivacyConfirmStatus, WriteInterfaceToken failed.");
800         return ERRCODE_SERVICE_UNAVAILABLE;
801     }
802     data.WriteInt32(type);
803     data.WriteBool(isConfirmed);
804     LocationErrCode errorCode = SendMsgWithDataReplyV9(SET_PRIVACY_COMFIRM_STATUS, data, reply);
805     LBSLOGD(LOCATOR_STANDARD, "Proxy::SetLocationPrivacyConfirmStatus Transact ErrCodes = %{public}d", errorCode);
806     return errorCode;
807 }
808 
RegisterCachedLocationCallbackV9(std::unique_ptr<CachedGnssLocationsRequest> & request,sptr<ICachedLocationsCallback> & callback,std::string bundleName)809 LocationErrCode LocatorProxy::RegisterCachedLocationCallbackV9(std::unique_ptr<CachedGnssLocationsRequest>& request,
810     sptr<ICachedLocationsCallback>& callback, std::string bundleName)
811 {
812     MessageParcel data;
813     if (!data.WriteInterfaceToken(GetDescriptor())) {
814         return ERRCODE_SERVICE_UNAVAILABLE;
815     }
816     if (request != nullptr) {
817         data.WriteInt32(request->reportingPeriodSec);
818         data.WriteBool(request->wakeUpCacheQueueFull);
819     }
820     if (callback != nullptr) {
821         data.WriteRemoteObject(callback->AsObject());
822     }
823     data.WriteString16(Str8ToStr16(bundleName));
824     MessageParcel reply;
825     LocationErrCode errorCode = SendMsgWithDataReplyV9(REG_CACHED_CALLBACK, data, reply);
826     LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterCachedLocationCallback Transact ErrCodes = %{public}d", errorCode);
827     return errorCode;
828 }
829 
UnregisterCachedLocationCallbackV9(sptr<ICachedLocationsCallback> & callback)830 LocationErrCode LocatorProxy::UnregisterCachedLocationCallbackV9(sptr<ICachedLocationsCallback>& callback)
831 {
832     LocationErrCode errorCode = SendRegisterMsgToRemoteV9(UNREG_CACHED_CALLBACK, callback->AsObject());
833     LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterCachedLocationCallback Transact ErrCodes = %{public}d", errorCode);
834     return errorCode;
835 }
836 
GetCachedGnssLocationsSizeV9(int & size)837 LocationErrCode LocatorProxy::GetCachedGnssLocationsSizeV9(int &size)
838 {
839     MessageParcel reply;
840     LocationErrCode errorCode = SendMsgWithReplyV9(GET_CACHED_LOCATION_SIZE, reply);
841     LBSLOGD(LOCATOR_STANDARD, "Proxy::GetCachedGnssLocationsSize Transact ErrCode = %{public}d", errorCode);
842     if (errorCode == ERRCODE_SUCCESS) {
843         size = reply.ReadInt32();
844     } else {
845         size = 0;
846     }
847     LBSLOGD(LOCATOR_STANDARD, "Proxy::GetCachedGnssLocationsSize return  %{public}d", size);
848     return errorCode;
849 }
850 
FlushCachedGnssLocationsV9()851 LocationErrCode LocatorProxy::FlushCachedGnssLocationsV9()
852 {
853     LocationErrCode errorCode = SendSimpleMsgV9(FLUSH_CACHED_LOCATIONS);
854     LBSLOGD(LOCATOR_STANDARD, "Proxy::FlushCachedGnssLocations Transact ErrCodes = %{public}d", errorCode);
855     return errorCode;
856 }
857 
SendCommandV9(std::unique_ptr<LocationCommand> & commands)858 LocationErrCode LocatorProxy::SendCommandV9(std::unique_ptr<LocationCommand>& commands)
859 {
860     if (commands == nullptr) {
861         return ERRCODE_INVALID_PARAM;
862     }
863     MessageParcel data;
864     MessageParcel reply;
865     if (!data.WriteInterfaceToken(GetDescriptor())) {
866         return ERRCODE_SERVICE_UNAVAILABLE;
867     }
868     data.WriteInt32(commands->scenario);
869     data.WriteString16(Str8ToStr16(commands->command));
870     LocationErrCode errorCode = SendMsgWithDataReplyV9(SEND_COMMAND, data, reply);
871     LBSLOGD(LOCATOR_STANDARD, "Proxy::SendCommand Transact ErrCodes = %{public}d", errorCode);
872     return errorCode;
873 }
874 
AddFenceV9(std::unique_ptr<GeofenceRequest> & request)875 LocationErrCode LocatorProxy::AddFenceV9(std::unique_ptr<GeofenceRequest>& request)
876 {
877     if (request == nullptr) {
878         return ERRCODE_INVALID_PARAM;
879     }
880     MessageParcel data;
881     MessageParcel reply;
882     if (!data.WriteInterfaceToken(GetDescriptor())) {
883         return ERRCODE_SERVICE_UNAVAILABLE;
884     }
885     data.WriteInt32(request->scenario);
886     data.WriteDouble(request->geofence.latitude);
887     data.WriteDouble(request->geofence.longitude);
888     data.WriteDouble(request->geofence.radius);
889     data.WriteDouble(request->geofence.expiration);
890     LocationErrCode errorCode = SendMsgWithDataReplyV9(ADD_FENCE, data, reply);
891     LBSLOGD(LOCATOR_STANDARD, "Proxy::AddFence Transact ErrCodes = %{public}d", errorCode);
892     return errorCode;
893 }
894 
RemoveFenceV9(std::unique_ptr<GeofenceRequest> & request)895 LocationErrCode LocatorProxy::RemoveFenceV9(std::unique_ptr<GeofenceRequest>& request)
896 {
897     if (request == nullptr) {
898         return ERRCODE_INVALID_PARAM;
899     }
900     MessageParcel data;
901     MessageParcel reply;
902     if (!data.WriteInterfaceToken(GetDescriptor())) {
903         return ERRCODE_SERVICE_UNAVAILABLE;
904     }
905     data.WriteInt32(request->scenario);
906     data.WriteDouble(request->geofence.latitude);
907     data.WriteDouble(request->geofence.longitude);
908     data.WriteDouble(request->geofence.radius);
909     data.WriteDouble(request->geofence.expiration);
910     LocationErrCode errorCode = SendMsgWithDataReplyV9(REMOVE_FENCE, data, reply);
911     LBSLOGD(LOCATOR_STANDARD, "Proxy::RemoveFence Transact ErrCodes = %{public}d", errorCode);
912     return errorCode;
913 }
914 
GetIsoCountryCodeV9(std::shared_ptr<CountryCode> & countryCode)915 LocationErrCode LocatorProxy::GetIsoCountryCodeV9(std::shared_ptr<CountryCode>& countryCode)
916 {
917     if (countryCode == nullptr) {
918         return ERRCODE_INVALID_PARAM;
919     }
920     MessageParcel reply;
921     LocationErrCode errorCode = SendMsgWithReplyV9(GET_ISO_COUNTRY_CODE, reply);
922     LBSLOGD(LOCATOR_STANDARD, "Proxy::GetIsoCountryCode Transact ErrCodes = %{public}d", errorCode);
923     if (errorCode == ERRCODE_SUCCESS) {
924         std::string country = Str16ToStr8(reply.ReadString16());
925         int countryType = reply.ReadInt32();
926         countryCode->SetCountryCodeStr(country);
927         countryCode->SetCountryCodeType(countryType);
928     }
929     return errorCode;
930 }
931 
EnableLocationMockV9()932 LocationErrCode LocatorProxy::EnableLocationMockV9()
933 {
934     MessageParcel data;
935     MessageParcel reply;
936     if (!data.WriteInterfaceToken(GetDescriptor())) {
937         return ERRCODE_SERVICE_UNAVAILABLE;
938     }
939     LocationErrCode errorCode = SendMsgWithDataReplyV9(ENABLE_LOCATION_MOCK, data, reply);
940     LBSLOGD(LOCATOR_STANDARD, "Proxy::EnableLocationMock Transact ErrCodes = %{public}d", errorCode);
941     return errorCode;
942 }
943 
DisableLocationMockV9()944 LocationErrCode LocatorProxy::DisableLocationMockV9()
945 {
946     MessageParcel data;
947     MessageParcel reply;
948     if (!data.WriteInterfaceToken(GetDescriptor())) {
949         return ERRCODE_SERVICE_UNAVAILABLE;
950     }
951     LocationErrCode errorCode = SendMsgWithDataReplyV9(DISABLE_LOCATION_MOCK, data, reply);
952     LBSLOGD(LOCATOR_STANDARD, "Proxy::DisableLocationMock Transact ErrCodes = %{public}d", errorCode);
953     return errorCode;
954 }
955 
SetMockedLocationsV9(const int timeInterval,const std::vector<std::shared_ptr<Location>> & location)956 LocationErrCode LocatorProxy::SetMockedLocationsV9(
957     const int timeInterval, const std::vector<std::shared_ptr<Location>> &location)
958 {
959     MessageParcel data;
960     MessageParcel reply;
961     if (!data.WriteInterfaceToken(GetDescriptor())) {
962         return ERRCODE_SERVICE_UNAVAILABLE;
963     }
964     data.WriteInt32(timeInterval);
965     int locationSize = static_cast<int>(location.size());
966     data.WriteInt32(locationSize);
967     for (int i = 0; i < locationSize; i++) {
968         location.at(i)->Marshalling(data);
969     }
970     LocationErrCode errorCode = SendMsgWithDataReplyV9(SET_MOCKED_LOCATIONS, data, reply);
971     LBSLOGD(LOCATOR_STANDARD, "Proxy::SetMockedLocations Transact ErrCodes = %{public}d", errorCode);
972     return errorCode;
973 }
974 
EnableReverseGeocodingMockV9()975 LocationErrCode LocatorProxy::EnableReverseGeocodingMockV9()
976 {
977     MessageParcel reply;
978     LocationErrCode errorCode = SendMsgWithReplyV9(ENABLE_REVERSE_GEOCODE_MOCK, reply);
979     LBSLOGD(LOCATOR_STANDARD, "Proxy::EnableReverseGeocodingMock Transact ErrCodes = %{public}d", errorCode);
980     return errorCode;
981 }
982 
DisableReverseGeocodingMockV9()983 LocationErrCode LocatorProxy::DisableReverseGeocodingMockV9()
984 {
985     MessageParcel reply;
986     LocationErrCode errorCode = SendMsgWithReplyV9(DISABLE_REVERSE_GEOCODE_MOCK, reply);
987     LBSLOGD(LOCATOR_STANDARD, "Proxy::DisableReverseGeocodingMock Transact ErrCodes = %{public}d", errorCode);
988     return errorCode;
989 }
990 
SetReverseGeocodingMockInfoV9(std::vector<std::shared_ptr<GeocodingMockInfo>> & mockInfo)991 LocationErrCode LocatorProxy::SetReverseGeocodingMockInfoV9(std::vector<std::shared_ptr<GeocodingMockInfo>>& mockInfo)
992 {
993     MessageParcel data;
994     MessageParcel reply;
995     if (!data.WriteInterfaceToken(GetDescriptor())) {
996         return ERRCODE_SERVICE_UNAVAILABLE;
997     }
998     data.WriteInt32(mockInfo.size());
999     for (size_t i = 0; i < mockInfo.size(); i++) {
1000         mockInfo[i]->Marshalling(data);
1001     }
1002     LocationErrCode errorCode = SendMsgWithDataReplyV9(SET_REVERSE_GEOCODE_MOCKINFO, data, reply);
1003     LBSLOGD(LOCATOR_STANDARD, "Proxy::SetReverseGeocodingMockInfo Transact ErrCodes = %{public}d", errorCode);
1004     return errorCode;
1005 }
1006 
ProxyUidForFreezeV9(int32_t uid,bool isProxy)1007 LocationErrCode LocatorProxy::ProxyUidForFreezeV9(int32_t uid, bool isProxy)
1008 {
1009     MessageParcel data;
1010     MessageParcel reply;
1011     if (!data.WriteInterfaceToken(GetDescriptor())) {
1012         return ERRCODE_SERVICE_UNAVAILABLE;
1013     }
1014 
1015     if (!data.WriteInt32(uid) || !data.WriteBool(isProxy)) {
1016         LBSLOGE(LOCATOR_STANDARD, "[ProxyUid] fail: write data failed");
1017         return ERRCODE_INVALID_PARAM;
1018     }
1019     LocationErrCode errorCode = SendMsgWithDataReplyV9(PROXY_UID_FOR_FREEZE, data, reply);
1020     LBSLOGD(LOCATOR_STANDARD, "Proxy::ProxyUid Transact ErrCodes = %{public}d", errorCode);
1021     return errorCode;
1022 }
1023 
ResetAllProxyV9()1024 LocationErrCode LocatorProxy::ResetAllProxyV9()
1025 {
1026     MessageParcel reply;
1027     LocationErrCode errorCode = SendMsgWithReplyV9(RESET_ALL_PROXY, reply);
1028     LBSLOGD(LOCATOR_STANDARD, "Proxy::ResetAllProxy Transact ErrCodes = %{public}d", errorCode);
1029     return errorCode;
1030 }
1031 } // namespace Location
1032 } // namespace OHOS
1033