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