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