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 = 0;
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
UpdateSaAbilityV9()460 LocationErrCode LocatorProxy::UpdateSaAbilityV9()
461 {
462 LocationErrCode errorCode = SendSimpleMsgV9(static_cast<int>(LocatorInterfaceCode::UPDATE_SA_ABILITY));
463 LBSLOGD(LOCATOR_STANDARD, "Proxy::UpdateSaAbility Transact ErrCodes = %{public}d", errorCode);
464 return errorCode;
465 }
466
SendMsgWithDataReplyV9(const int msgId,MessageParcel & data,MessageParcel & reply)467 LocationErrCode LocatorProxy::SendMsgWithDataReplyV9(const int msgId, MessageParcel& data, MessageParcel& reply)
468 {
469 MessageOption option;
470 sptr<IRemoteObject> remote = Remote();
471 if (remote == nullptr) {
472 LBSLOGE(LOCATOR_STANDARD, "SendMsgWithDataReply remote is null");
473 return ERRCODE_SERVICE_UNAVAILABLE;
474 }
475 int error = remote->SendRequest(msgId, data, reply, option);
476 if (error != NO_ERROR) {
477 LBSLOGE(LOCATOR_STANDARD, "msgid = %{public}d, send request error: %{public}d", msgId, error);
478 return ERRCODE_SERVICE_UNAVAILABLE;
479 }
480 LBSLOGD(LOCATOR_STANDARD, "Proxy::SendMsgWithDataReply result from server.");
481 return LocationErrCode(reply.ReadInt32());
482 }
483
SendMsgWithReplyV9(const int msgId,MessageParcel & reply)484 LocationErrCode LocatorProxy::SendMsgWithReplyV9(const int msgId, MessageParcel& reply)
485 {
486 MessageParcel data;
487 if (!data.WriteInterfaceToken(GetDescriptor())) {
488 LBSLOGE(LOCATOR_STANDARD, "SendMsgWithReply WriteInterfaceToken failed");
489 return ERRCODE_SERVICE_UNAVAILABLE;
490 }
491 return SendMsgWithDataReplyV9(msgId, data, reply);
492 }
493
SendSimpleMsgV9(const int msgId)494 LocationErrCode LocatorProxy::SendSimpleMsgV9(const int msgId)
495 {
496 MessageParcel reply;
497 return SendMsgWithReplyV9(msgId, reply);
498 }
499
SendRegisterMsgToRemoteV9(const int msgId,const sptr<IRemoteObject> & callback)500 LocationErrCode LocatorProxy::SendRegisterMsgToRemoteV9(const int msgId, const sptr<IRemoteObject>& callback)
501 {
502 MessageParcel data;
503 if (!data.WriteInterfaceToken(GetDescriptor())) {
504 LBSLOGE(LOCATOR_STANDARD, "SendRegisterMsgToRemote WriteInterfaceToken failed");
505 return ERRCODE_SERVICE_UNAVAILABLE;
506 }
507 if (callback == nullptr) {
508 LBSLOGE(LOCATOR_STANDARD, "SendRegisterMsgToRemote callback is nullptr");
509 return ERRCODE_INVALID_PARAM;
510 }
511 data.WriteObject<IRemoteObject>(callback);
512 MessageParcel reply;
513 MessageOption option;
514 sptr<IRemoteObject> remote = Remote();
515 if (remote == nullptr) {
516 LBSLOGE(LOCATOR_STANDARD, "SendRegisterMsgToRemote remote is null");
517 return ERRCODE_SERVICE_UNAVAILABLE;
518 }
519 int error = remote->SendRequest(msgId, data, reply, option);
520 if (error != NO_ERROR) {
521 LBSLOGE(LOCATOR_STANDARD, "msgid = %{public}d, send request error: %{public}d", msgId, error);
522 return ERRCODE_SERVICE_UNAVAILABLE;
523 }
524 return LocationErrCode(reply.ReadInt32());
525 }
526
RegisterSwitchCallbackV9(const sptr<IRemoteObject> & callback)527 LocationErrCode LocatorProxy::RegisterSwitchCallbackV9(const sptr<IRemoteObject>& callback)
528 {
529 LocationErrCode errorCode =
530 SendRegisterMsgToRemoteV9(static_cast<int>(LocatorInterfaceCode::REG_SWITCH_CALLBACK), callback);
531 LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterSwitchCallback Transact ErrCodes = %{public}d", errorCode);
532 return errorCode;
533 }
534
UnregisterSwitchCallbackV9(const sptr<IRemoteObject> & callback)535 LocationErrCode LocatorProxy::UnregisterSwitchCallbackV9(const sptr<IRemoteObject>& callback)
536 {
537 LocationErrCode errorCode =
538 SendRegisterMsgToRemoteV9(static_cast<int>(LocatorInterfaceCode::UNREG_SWITCH_CALLBACK), callback);
539 LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterSwitchCallback Transact ErrCodes = %{public}d", errorCode);
540 return errorCode;
541 }
542
RegisterGnssStatusCallbackV9(const sptr<IRemoteObject> & callback)543 LocationErrCode LocatorProxy::RegisterGnssStatusCallbackV9(const sptr<IRemoteObject>& callback)
544 {
545 LocationErrCode errorCode =
546 SendRegisterMsgToRemoteV9(static_cast<int>(LocatorInterfaceCode::REG_GNSS_STATUS_CALLBACK), callback);
547 LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterGnssStatusCallback Transact ErrCodes = %{public}d", errorCode);
548 return errorCode;
549 }
550
UnregisterGnssStatusCallbackV9(const sptr<IRemoteObject> & callback)551 LocationErrCode LocatorProxy::UnregisterGnssStatusCallbackV9(const sptr<IRemoteObject>& callback)
552 {
553 LocationErrCode errorCode =
554 SendRegisterMsgToRemoteV9(static_cast<int>(LocatorInterfaceCode::UNREG_GNSS_STATUS_CALLBACK), callback);
555 LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterGnssStatusCallback Transact ErrCodes = %{public}d", errorCode);
556 return errorCode;
557 }
558
RegisterNmeaMessageCallbackV9(const sptr<IRemoteObject> & callback)559 LocationErrCode LocatorProxy::RegisterNmeaMessageCallbackV9(const sptr<IRemoteObject>& callback)
560 {
561 MessageParcel data;
562 MessageParcel reply;
563 if (!data.WriteInterfaceToken(GetDescriptor())) {
564 LBSLOGE(LOCATOR_STANDARD, "WriteInterfaceToken failed");
565 return ERRCODE_SERVICE_UNAVAILABLE;
566 }
567 if (callback == nullptr) {
568 LBSLOGE(LOCATOR_STANDARD, "callback is nullptr");
569 return ERRCODE_INVALID_PARAM;
570 }
571 data.WriteObject<IRemoteObject>(callback);
572 LocationErrCode errorCode =
573 SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::REG_NMEA_CALLBACK_V9), data, reply);
574 LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterNmeaMessageCallbackV9 Transact ErrCodes = %{public}d", errorCode);
575 return errorCode;
576 }
577
UnregisterNmeaMessageCallbackV9(const sptr<IRemoteObject> & callback)578 LocationErrCode LocatorProxy::UnregisterNmeaMessageCallbackV9(const sptr<IRemoteObject>& callback)
579 {
580 MessageParcel data;
581 MessageParcel reply;
582 if (!data.WriteInterfaceToken(GetDescriptor())) {
583 LBSLOGE(LOCATOR_STANDARD, "WriteInterfaceToken failed");
584 return ERRCODE_SERVICE_UNAVAILABLE;
585 }
586 if (callback == nullptr) {
587 LBSLOGE(LOCATOR_STANDARD, "callback is nullptr");
588 return ERRCODE_INVALID_PARAM;
589 }
590 data.WriteObject<IRemoteObject>(callback);
591 LocationErrCode errorCode =
592 SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::UNREG_NMEA_CALLBACK_V9), data, reply);
593 LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterNmeaMessageCallbackV9 Transact ErrCodes = %{public}d", errorCode);
594 return errorCode;
595 }
596
StartLocatingV9(std::unique_ptr<RequestConfig> & requestConfig,sptr<ILocatorCallback> & callback)597 LocationErrCode LocatorProxy::StartLocatingV9(std::unique_ptr<RequestConfig>& requestConfig,
598 sptr<ILocatorCallback>& callback)
599 {
600 MessageParcel data;
601 if (!data.WriteInterfaceToken(GetDescriptor())) {
602 return ERRCODE_SERVICE_UNAVAILABLE;
603 }
604 if (requestConfig != nullptr) {
605 requestConfig->Marshalling(data);
606 }
607 if (callback != nullptr) {
608 data.WriteObject<IRemoteObject>(callback->AsObject());
609 }
610 MessageParcel reply;
611 LocationErrCode errorCode =
612 SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::START_LOCATING), data, reply);
613 LBSLOGD(LOCATOR_STANDARD, "Proxy::StartLocating Transact ErrCodes = %{public}d", errorCode);
614 return errorCode;
615 }
616
StopLocatingV9(sptr<ILocatorCallback> & callback)617 LocationErrCode LocatorProxy::StopLocatingV9(sptr<ILocatorCallback>& callback)
618 {
619 if (callback == nullptr) {
620 LBSLOGE(LOCATOR_STANDARD, "StopLocating callback is nullptr");
621 return ERRCODE_SERVICE_UNAVAILABLE;
622 }
623 LocationErrCode errorCode =
624 SendRegisterMsgToRemoteV9(static_cast<int>(LocatorInterfaceCode::STOP_LOCATING), callback->AsObject());
625 LBSLOGD(LOCATOR_STANDARD, "Proxy::StopLocatingV9 Transact ErrCodes = %{public}d", errorCode);
626 return errorCode;
627 }
628
GetCacheLocationV9(std::unique_ptr<Location> & loc)629 LocationErrCode LocatorProxy::GetCacheLocationV9(std::unique_ptr<Location> &loc)
630 {
631 MessageParcel reply;
632 LocationErrCode errorCode =
633 SendMsgWithReplyV9(static_cast<int>(LocatorInterfaceCode::GET_CACHE_LOCATION), reply);
634 if (errorCode == ERRCODE_SUCCESS) {
635 loc = Location::Unmarshalling(reply);
636 } else {
637 loc = nullptr;
638 }
639 LBSLOGD(LOCATOR_STANDARD, "Proxy::GetCacheLocation Transact ErrCodes = %{public}d", errorCode);
640 return errorCode;
641 }
642
IsGeoConvertAvailableV9(bool & isAvailable)643 LocationErrCode LocatorProxy::IsGeoConvertAvailableV9(bool &isAvailable)
644 {
645 MessageParcel reply;
646 LocationErrCode errorCode =
647 SendMsgWithReplyV9(static_cast<int>(LocatorInterfaceCode::GEO_IS_AVAILABLE), reply);
648 if (errorCode == ERRCODE_SUCCESS) {
649 isAvailable = reply.ReadBool();
650 } else {
651 isAvailable = false;
652 }
653 LBSLOGD(LOCATOR_STANDARD, "Proxy::IsGeoConvertAvailable Transact ErrCodes = %{public}d", errorCode);
654 return errorCode;
655 }
656
GetAddressByCoordinateV9(MessageParcel & data,std::list<std::shared_ptr<GeoAddress>> & replyList)657 LocationErrCode LocatorProxy::GetAddressByCoordinateV9(MessageParcel &data,
658 std::list<std::shared_ptr<GeoAddress>>& replyList)
659 {
660 MessageParcel reply;
661 LocationErrCode errorCode =
662 SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::GET_FROM_COORDINATE), data, reply);
663 if (errorCode == ERRCODE_SUCCESS) {
664 int resultSize = reply.ReadInt32();
665 if (resultSize > GeoAddress::MAX_RESULT) {
666 resultSize = GeoAddress::MAX_RESULT;
667 }
668 for (int i = 0; i < resultSize; i++) {
669 replyList.push_back(GeoAddress::Unmarshalling(reply));
670 }
671 }
672 LBSLOGD(LOCATOR_STANDARD, "Proxy::GetAddressByCoordinate Transact ErrCodes = %{public}d", errorCode);
673 return errorCode;
674 }
675
GetAddressByLocationNameV9(MessageParcel & data,std::list<std::shared_ptr<GeoAddress>> & replyList)676 LocationErrCode LocatorProxy::GetAddressByLocationNameV9(MessageParcel &data,
677 std::list<std::shared_ptr<GeoAddress>>& replyList)
678 {
679 MessageParcel reply;
680 LocationErrCode errorCode =
681 SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::GET_FROM_LOCATION_NAME), data, reply);
682 if (errorCode == ERRCODE_SUCCESS) {
683 int resultSize = reply.ReadInt32();
684 if (resultSize > GeoAddress::MAX_RESULT) {
685 resultSize = GeoAddress::MAX_RESULT;
686 }
687 for (int i = 0; i < resultSize; i++) {
688 replyList.push_back(GeoAddress::Unmarshalling(reply));
689 }
690 }
691 LBSLOGD(LOCATOR_STANDARD, "Proxy::GetAddressByLocationName Transact ErrCodes = %{public}d", errorCode);
692 return errorCode;
693 }
694
IsLocationPrivacyConfirmedV9(const int type,bool & isConfirmed)695 LocationErrCode LocatorProxy::IsLocationPrivacyConfirmedV9(const int type, bool &isConfirmed)
696 {
697 MessageParcel data;
698 MessageParcel reply;
699 if (!data.WriteInterfaceToken(GetDescriptor())) {
700 return ERRCODE_SERVICE_UNAVAILABLE;
701 }
702 data.WriteInt32(type);
703 LocationErrCode errorCode =
704 SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::IS_PRIVACY_COMFIRMED), data, reply);
705 LBSLOGD(LOCATOR_STANDARD, "Proxy::IsLocationPrivacyConfirmed Transact ErrCodes = %{public}d", errorCode);
706 if (errorCode == ERRCODE_SUCCESS) {
707 isConfirmed = reply.ReadBool();
708 } else {
709 isConfirmed = false;
710 }
711 LBSLOGD(LOCATOR_STANDARD, "Proxy::IsLocationPrivacyConfirmed return %{public}d", isConfirmed);
712 return errorCode;
713 }
714
SetLocationPrivacyConfirmStatusV9(const int type,bool isConfirmed)715 LocationErrCode LocatorProxy::SetLocationPrivacyConfirmStatusV9(const int type, bool isConfirmed)
716 {
717 MessageParcel data;
718 MessageParcel reply;
719 if (!data.WriteInterfaceToken(GetDescriptor())) {
720 LBSLOGE(LOCATOR_STANDARD, "SetLocationPrivacyConfirmStatus, WriteInterfaceToken failed.");
721 return ERRCODE_SERVICE_UNAVAILABLE;
722 }
723 data.WriteInt32(type);
724 data.WriteBool(isConfirmed);
725 LocationErrCode errorCode =
726 SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::SET_PRIVACY_COMFIRM_STATUS), data, reply);
727 LBSLOGD(LOCATOR_STANDARD, "Proxy::SetLocationPrivacyConfirmStatus Transact ErrCodes = %{public}d", errorCode);
728 return errorCode;
729 }
730
RegisterCachedLocationCallbackV9(std::unique_ptr<CachedGnssLocationsRequest> & request,sptr<ICachedLocationsCallback> & callback,std::string bundleName)731 LocationErrCode LocatorProxy::RegisterCachedLocationCallbackV9(std::unique_ptr<CachedGnssLocationsRequest>& request,
732 sptr<ICachedLocationsCallback>& callback, std::string bundleName)
733 {
734 MessageParcel data;
735 if (!data.WriteInterfaceToken(GetDescriptor())) {
736 return ERRCODE_SERVICE_UNAVAILABLE;
737 }
738 if (request != nullptr) {
739 data.WriteInt32(request->reportingPeriodSec);
740 data.WriteBool(request->wakeUpCacheQueueFull);
741 }
742 if (callback != nullptr) {
743 data.WriteRemoteObject(callback->AsObject());
744 }
745 data.WriteString16(Str8ToStr16(bundleName));
746 MessageParcel reply;
747 LocationErrCode errorCode =
748 SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::REG_CACHED_CALLBACK), data, reply);
749 LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterCachedLocationCallback Transact ErrCodes = %{public}d", errorCode);
750 return errorCode;
751 }
752
UnregisterCachedLocationCallbackV9(sptr<ICachedLocationsCallback> & callback)753 LocationErrCode LocatorProxy::UnregisterCachedLocationCallbackV9(sptr<ICachedLocationsCallback>& callback)
754 {
755 LocationErrCode errorCode =
756 SendRegisterMsgToRemoteV9(static_cast<int>(LocatorInterfaceCode::UNREG_CACHED_CALLBACK), callback->AsObject());
757 LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterCachedLocationCallback Transact ErrCodes = %{public}d", errorCode);
758 return errorCode;
759 }
760
GetCachedGnssLocationsSizeV9(int & size)761 LocationErrCode LocatorProxy::GetCachedGnssLocationsSizeV9(int &size)
762 {
763 MessageParcel reply;
764 LocationErrCode errorCode =
765 SendMsgWithReplyV9(static_cast<int>(LocatorInterfaceCode::GET_CACHED_LOCATION_SIZE), reply);
766 LBSLOGD(LOCATOR_STANDARD, "Proxy::GetCachedGnssLocationsSize Transact ErrCode = %{public}d", errorCode);
767 if (errorCode == ERRCODE_SUCCESS) {
768 size = reply.ReadInt32();
769 } else {
770 size = 0;
771 }
772 LBSLOGD(LOCATOR_STANDARD, "Proxy::GetCachedGnssLocationsSize return %{public}d", size);
773 return errorCode;
774 }
775
FlushCachedGnssLocationsV9()776 LocationErrCode LocatorProxy::FlushCachedGnssLocationsV9()
777 {
778 LocationErrCode errorCode = SendSimpleMsgV9(static_cast<int>(LocatorInterfaceCode::FLUSH_CACHED_LOCATIONS));
779 LBSLOGD(LOCATOR_STANDARD, "Proxy::FlushCachedGnssLocations Transact ErrCodes = %{public}d", errorCode);
780 return errorCode;
781 }
782
SendCommandV9(std::unique_ptr<LocationCommand> & commands)783 LocationErrCode LocatorProxy::SendCommandV9(std::unique_ptr<LocationCommand>& commands)
784 {
785 if (commands == nullptr) {
786 return ERRCODE_INVALID_PARAM;
787 }
788 MessageParcel data;
789 MessageParcel reply;
790 if (!data.WriteInterfaceToken(GetDescriptor())) {
791 return ERRCODE_SERVICE_UNAVAILABLE;
792 }
793 data.WriteInt32(commands->scenario);
794 data.WriteString16(Str8ToStr16(commands->command));
795 LocationErrCode errorCode =
796 SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::SEND_COMMAND), data, reply);
797 LBSLOGD(LOCATOR_STANDARD, "Proxy::SendCommand Transact ErrCodes = %{public}d", errorCode);
798 return errorCode;
799 }
800
AddFenceV9(std::shared_ptr<GeofenceRequest> & request)801 LocationErrCode LocatorProxy::AddFenceV9(std::shared_ptr<GeofenceRequest>& request)
802 {
803 return HandleGnssfenceRequest(LocatorInterfaceCode::ADD_FENCE, request);
804 }
805
RemoveFenceV9(std::shared_ptr<GeofenceRequest> & request)806 LocationErrCode LocatorProxy::RemoveFenceV9(std::shared_ptr<GeofenceRequest>& request)
807 {
808 return HandleGnssfenceRequest(LocatorInterfaceCode::REMOVE_FENCE, request);
809 }
810
HandleGnssfenceRequest(LocatorInterfaceCode code,std::shared_ptr<GeofenceRequest> & request)811 LocationErrCode LocatorProxy::HandleGnssfenceRequest(
812 LocatorInterfaceCode code, std::shared_ptr<GeofenceRequest>& request)
813 {
814 if (request == nullptr) {
815 return ERRCODE_INVALID_PARAM;
816 }
817 MessageParcel data;
818 MessageParcel reply;
819 if (!data.WriteInterfaceToken(GetDescriptor())) {
820 LBSLOGE(LOCATOR_STANDARD, "%{public}s WriteInterfaceToken failed", __func__);
821 return ERRCODE_SERVICE_UNAVAILABLE;
822 }
823 request->Marshalling(data);
824 LocationErrCode errorCode = SendMsgWithDataReplyV9(static_cast<int>(code), data, reply);
825 LBSLOGD(LOCATOR_STANDARD, "Transact ErrCodes = %{public}d", errorCode);
826 return errorCode;
827 }
828
AddGnssGeofence(std::shared_ptr<GeofenceRequest> & request)829 LocationErrCode LocatorProxy::AddGnssGeofence(std::shared_ptr<GeofenceRequest>& request)
830 {
831 return HandleGnssfenceRequest(LocatorInterfaceCode::ADD_GNSS_GEOFENCE, request);
832 }
833
RemoveGnssGeofence(std::shared_ptr<GeofenceRequest> & request)834 LocationErrCode LocatorProxy::RemoveGnssGeofence(std::shared_ptr<GeofenceRequest>& request)
835 {
836 if (request == nullptr) {
837 return ERRCODE_INVALID_PARAM;
838 }
839 MessageParcel data;
840 MessageParcel reply;
841 if (!data.WriteInterfaceToken(GetDescriptor())) {
842 return ERRCODE_SERVICE_UNAVAILABLE;
843 }
844 data.WriteInt32(request->GetFenceId());
845 LocationErrCode errorCode = SendMsgWithDataReplyV9(
846 static_cast<int>(LocatorInterfaceCode::REMOVE_GNSS_GEOFENCE), data, reply);
847 LBSLOGD(LOCATOR_STANDARD, "Transact ErrCodes = %{public}d", errorCode);
848 return errorCode;
849 }
850
EnableLocationMockV9()851 LocationErrCode LocatorProxy::EnableLocationMockV9()
852 {
853 MessageParcel data;
854 MessageParcel reply;
855 if (!data.WriteInterfaceToken(GetDescriptor())) {
856 return ERRCODE_SERVICE_UNAVAILABLE;
857 }
858 LocationErrCode errorCode =
859 SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::ENABLE_LOCATION_MOCK), data, reply);
860 LBSLOGD(LOCATOR_STANDARD, "Proxy::EnableLocationMock Transact ErrCodes = %{public}d", errorCode);
861 return errorCode;
862 }
863
DisableLocationMockV9()864 LocationErrCode LocatorProxy::DisableLocationMockV9()
865 {
866 MessageParcel data;
867 MessageParcel reply;
868 if (!data.WriteInterfaceToken(GetDescriptor())) {
869 return ERRCODE_SERVICE_UNAVAILABLE;
870 }
871 LocationErrCode errorCode =
872 SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::DISABLE_LOCATION_MOCK), data, reply);
873 LBSLOGD(LOCATOR_STANDARD, "Proxy::DisableLocationMock Transact ErrCodes = %{public}d", errorCode);
874 return errorCode;
875 }
876
SetMockedLocationsV9(const int timeInterval,const std::vector<std::shared_ptr<Location>> & location)877 LocationErrCode LocatorProxy::SetMockedLocationsV9(
878 const int timeInterval, const std::vector<std::shared_ptr<Location>> &location)
879 {
880 MessageParcel data;
881 MessageParcel reply;
882 if (!data.WriteInterfaceToken(GetDescriptor())) {
883 return ERRCODE_SERVICE_UNAVAILABLE;
884 }
885 data.WriteInt32(timeInterval);
886 int locationSize = static_cast<int>(location.size());
887 data.WriteInt32(locationSize);
888 for (int i = 0; i < locationSize; i++) {
889 location.at(i)->Marshalling(data);
890 }
891 LocationErrCode errorCode =
892 SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::SET_MOCKED_LOCATIONS), data, reply);
893 LBSLOGD(LOCATOR_STANDARD, "Proxy::SetMockedLocations Transact ErrCodes = %{public}d", errorCode);
894 return errorCode;
895 }
896
EnableReverseGeocodingMockV9()897 LocationErrCode LocatorProxy::EnableReverseGeocodingMockV9()
898 {
899 MessageParcel reply;
900 LocationErrCode errorCode =
901 SendMsgWithReplyV9(static_cast<int>(LocatorInterfaceCode::ENABLE_REVERSE_GEOCODE_MOCK), reply);
902 LBSLOGD(LOCATOR_STANDARD, "Proxy::EnableReverseGeocodingMock Transact ErrCodes = %{public}d", errorCode);
903 return errorCode;
904 }
905
DisableReverseGeocodingMockV9()906 LocationErrCode LocatorProxy::DisableReverseGeocodingMockV9()
907 {
908 MessageParcel reply;
909 LocationErrCode errorCode =
910 SendMsgWithReplyV9(static_cast<int>(LocatorInterfaceCode::DISABLE_REVERSE_GEOCODE_MOCK), reply);
911 LBSLOGD(LOCATOR_STANDARD, "Proxy::DisableReverseGeocodingMock Transact ErrCodes = %{public}d", errorCode);
912 return errorCode;
913 }
914
SetReverseGeocodingMockInfoV9(std::vector<std::shared_ptr<GeocodingMockInfo>> & mockInfo)915 LocationErrCode LocatorProxy::SetReverseGeocodingMockInfoV9(std::vector<std::shared_ptr<GeocodingMockInfo>>& mockInfo)
916 {
917 MessageParcel data;
918 MessageParcel reply;
919 if (!data.WriteInterfaceToken(GetDescriptor())) {
920 return ERRCODE_SERVICE_UNAVAILABLE;
921 }
922 data.WriteInt32(mockInfo.size());
923 for (size_t i = 0; i < mockInfo.size(); i++) {
924 mockInfo[i]->Marshalling(data);
925 }
926 LocationErrCode errorCode =
927 SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::SET_REVERSE_GEOCODE_MOCKINFO), data, reply);
928 LBSLOGD(LOCATOR_STANDARD, "Proxy::SetReverseGeocodingMockInfo Transact ErrCodes = %{public}d", errorCode);
929 return errorCode;
930 }
931
ProxyForFreeze(std::set<int> pidList,bool isProxy)932 LocationErrCode LocatorProxy::ProxyForFreeze(std::set<int> pidList, bool isProxy)
933 {
934 MessageParcel data;
935 MessageParcel reply;
936 if (!data.WriteInterfaceToken(GetDescriptor())) {
937 return ERRCODE_SERVICE_UNAVAILABLE;
938 }
939
940 data.WriteInt32(pidList.size());
941 for (auto it = pidList.begin(); it != pidList.end(); it++) {
942 data.WriteInt32(*it);
943 }
944 data.WriteBool(isProxy);
945 LocationErrCode errorCode =
946 SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::PROXY_PID_FOR_FREEZE), data, reply);
947 LBSLOGD(LOCATOR_STANDARD, "Proxy::ProxyForFreeze Transact ErrCodes = %{public}d", errorCode);
948 return errorCode;
949 }
950
ResetAllProxy()951 LocationErrCode LocatorProxy::ResetAllProxy()
952 {
953 MessageParcel reply;
954 LocationErrCode errorCode = SendMsgWithReplyV9(static_cast<int>(LocatorInterfaceCode::RESET_ALL_PROXY), reply);
955 LBSLOGD(LOCATOR_STANDARD, "Proxy::ResetAllProxy Transact ErrCodes = %{public}d", errorCode);
956 return errorCode;
957 }
958
RegisterLocatingRequiredDataCallback(std::unique_ptr<LocatingRequiredDataConfig> & dataConfig,sptr<ILocatingRequiredDataCallback> & callback)959 LocationErrCode LocatorProxy::RegisterLocatingRequiredDataCallback(
960 std::unique_ptr<LocatingRequiredDataConfig>& dataConfig, sptr<ILocatingRequiredDataCallback>& callback)
961 {
962 MessageParcel data;
963 if (!data.WriteInterfaceToken(GetDescriptor())) {
964 return ERRCODE_SERVICE_UNAVAILABLE;
965 }
966 if (dataConfig != nullptr) {
967 dataConfig->Marshalling(data);
968 }
969 if (callback != nullptr) {
970 data.WriteObject<IRemoteObject>(callback->AsObject());
971 }
972 MessageParcel reply;
973 LocationErrCode errorCode =
974 SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::REG_LOCATING_REQUIRED_DATA_CALLBACK),
975 data, reply);
976 LBSLOGD(LOCATOR_STANDARD, "Proxy::%{public}s Transact ErrCodes = %{public}d", __func__, errorCode);
977 return errorCode;
978 }
979
UnRegisterLocatingRequiredDataCallback(sptr<ILocatingRequiredDataCallback> & callback)980 LocationErrCode LocatorProxy::UnRegisterLocatingRequiredDataCallback(sptr<ILocatingRequiredDataCallback>& callback)
981 {
982 LocationErrCode errorCode =
983 SendRegisterMsgToRemoteV9(static_cast<int>(LocatorInterfaceCode::UNREG_LOCATING_REQUIRED_DATA_CALLBACK),
984 callback->AsObject());
985 LBSLOGD(LOCATOR_STANDARD, "Proxy::%{public}s Transact ErrCodes = %{public}d", __func__, errorCode);
986 return errorCode;
987 }
988
SubscribeLocationError(sptr<ILocatorCallback> & callback)989 LocationErrCode LocatorProxy::SubscribeLocationError(sptr<ILocatorCallback>& callback)
990 {
991 MessageParcel data;
992 if (!data.WriteInterfaceToken(GetDescriptor())) {
993 return ERRCODE_SERVICE_UNAVAILABLE;
994 }
995 if (callback != nullptr) {
996 data.WriteObject<IRemoteObject>(callback->AsObject());
997 }
998 MessageParcel reply;
999 LocationErrCode errorCode =
1000 SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::REG_LOCATION_ERROR), data, reply);
1001 LBSLOGD(LOCATOR_STANDARD, "Proxy::StartLocating Transact ErrCodes = %{public}d", errorCode);
1002 return errorCode;
1003 }
1004
UnSubscribeLocationError(sptr<ILocatorCallback> & callback)1005 LocationErrCode LocatorProxy::UnSubscribeLocationError(sptr<ILocatorCallback>& callback)
1006 {
1007 if (callback == nullptr) {
1008 LBSLOGE(LOCATOR_STANDARD, "StopLocating callback is nullptr");
1009 return ERRCODE_SERVICE_UNAVAILABLE;
1010 }
1011 LocationErrCode errorCode =
1012 SendRegisterMsgToRemoteV9(static_cast<int>(LocatorInterfaceCode::UNREG_LOCATION_ERROR), callback->AsObject());
1013 LBSLOGD(LOCATOR_STANDARD, "Proxy::StopLocatingV9 Transact ErrCodes = %{public}d", errorCode);
1014 return errorCode;
1015 }
1016
GetGeofenceSupportedCoordTypes(std::vector<CoordinateSystemType> & coordinateSystemTypes)1017 LocationErrCode LocatorProxy::GetGeofenceSupportedCoordTypes(
1018 std::vector<CoordinateSystemType>& coordinateSystemTypes)
1019 {
1020 MessageParcel data;
1021 if (!data.WriteInterfaceToken(GetDescriptor())) {
1022 return ERRCODE_SERVICE_UNAVAILABLE;
1023 }
1024 MessageParcel reply;
1025 LocationErrCode errorCode = SendMsgWithDataReplyV9(
1026 static_cast<int>(LocatorInterfaceCode::GET_GEOFENCE_SUPPORT_COORDINATE_SYSTEM_TYPE), data, reply);
1027 LBSLOGD(LOCATOR_STANDARD, "Proxy::%{public}s Transact ErrCodes = %{public}d", __func__, errorCode);
1028 int size = reply.ReadInt32();
1029 size = size > COORDINATE_SYSTEM_TYPE_SIZE ? COORDINATE_SYSTEM_TYPE_SIZE : size;
1030 for (int i = 0; i < size; i++) {
1031 int coordinateSystemType = reply.ReadInt32();
1032 coordinateSystemTypes.push_back(static_cast<CoordinateSystemType>(coordinateSystemType));
1033 }
1034 return errorCode;
1035 }
1036 } // namespace Location
1037 } // namespace OHOS
1038