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