diff --git a/frameworks/js/napi/include/location_napi_adapter.h b/frameworks/js/napi/include/location_napi_adapter.h index 6a52898a1d7a652eb99bcdabdfd883815080b4dd..30fc58c370b29b5fce9ffe400579c9bf17490181 100644 --- a/frameworks/js/napi/include/location_napi_adapter.h +++ b/frameworks/js/napi/include/location_napi_adapter.h @@ -50,11 +50,14 @@ napi_value HandleGetCachedLocation(napi_env env); LocationErrCode CheckLocationSwitchState(); napi_value GetLocatingRequiredData(napi_env env, napi_callback_info info); napi_value AddGnssGeofence(napi_env env, napi_callback_info info); -GnssGeofenceAsyncContext* CreateGnssGeofenceAsyncContextForAdd(const napi_env& env, +GnssGeofenceAsyncContext* CreateAsyncContextForAddGnssGeofence(const napi_env& env, std::shared_ptr& request, sptr callback); napi_value RemoveGnssGeofence(napi_env env, napi_callback_info info); -GnssGeofenceAsyncContext* CreateGnssGeofenceAsyncContextForRemove(const napi_env& env, int fenceId); +GnssGeofenceAsyncContext* CreateAsyncContextForRemoveGnssGeofence(const napi_env& env, int fenceId); napi_value GetGeofenceSupportedCoordTypes(napi_env env, napi_callback_info info); +void AddCallbackToGnssGeofenceCallbackHostMap(int fenceId, sptr callbackHost); +void RemoveCallbackToGnssGeofenceCallbackHostMap(int fenceId); +sptr FindCallbackInGnssGeofenceCallbackHostMap(int fenceId); #endif } // namespace Location } // namespace OHOS diff --git a/frameworks/js/napi/source/location_napi_adapter.cpp b/frameworks/js/napi/source/location_napi_adapter.cpp index 9bf57af6e9e342b0530539645d1c1b6fee9191c1..876cc75ddbe8ee06396d19cfcadd37bbeea77349 100644 --- a/frameworks/js/napi/source/location_napi_adapter.cpp +++ b/frameworks/js/napi/source/location_napi_adapter.cpp @@ -22,6 +22,7 @@ namespace OHOS { namespace Location { auto g_locatorClient = Locator::GetInstance(); std::map> g_gnssGeofenceCallbackHostMap; +std::mutex g_gnssGeofenceCallbackHostMutex; napi_value GetLastLocation(napi_env env, napi_callback_info info) { @@ -1061,7 +1062,7 @@ napi_value AddGnssGeofence(napi_env env, napi_callback_info info) JsObjToGeofenceTransitionCallback(env, argv[0], locationGnssGeofenceCallbackHost); auto callbackPtr = sptr(locationGnssGeofenceCallbackHost); gnssGeofenceRequest->SetGeofenceTransitionCallback(callbackPtr->AsObject()); - auto asyncContext = CreateGnssGeofenceAsyncContextForAdd( + auto asyncContext = CreateAsyncContextForAddGnssGeofence( env, gnssGeofenceRequest, locationGnssGeofenceCallbackHost); if (asyncContext == nullptr) { HandleSyncErrCode(env, ERRCODE_INVALID_PARAM); @@ -1070,7 +1071,7 @@ napi_value AddGnssGeofence(napi_env env, napi_callback_info info) return DoAsyncWork(env, asyncContext, argc, argv, 1); } -GnssGeofenceAsyncContext* CreateGnssGeofenceAsyncContextForAdd(const napi_env& env, +GnssGeofenceAsyncContext* CreateAsyncContextForAddGnssGeofence(const napi_env& env, std::shared_ptr& request, sptr callback) { auto asyncContext = new (std::nothrow) GnssGeofenceAsyncContext(env); @@ -1097,7 +1098,7 @@ GnssGeofenceAsyncContext* CreateGnssGeofenceAsyncContextForAdd(const napi_env& e context->errCode = ERRCODE_SERVICE_UNAVAILABLE; } callbackHost->SetCount(1); - g_gnssGeofenceCallbackHostMap.insert(std::make_pair(callbackHost->GetFenceId(), callbackHost)); + AddCallbackToGnssGeofenceCallbackHostMap(gnssGeofenceRequest->GetFenceId(), callbackHost); } }; asyncContext->completeFunc = [&](void* data) -> void { @@ -1106,14 +1107,13 @@ GnssGeofenceAsyncContext* CreateGnssGeofenceAsyncContextForAdd(const napi_env& e } auto context = static_cast(data); auto callbackHost = context->callbackHost_; - if (callbackHost != nullptr && + if (callbackHost != nullptr && context->errCode == ERRCODE_SUCCESS && callbackHost->GetGeofenceOperationType() == GnssGeofenceOperateType::GNSS_GEOFENCE_OPT_TYPE_ADD) { LocationErrCode errCode = callbackHost->DealGeofenceOperationResult(); if (errCode == ERRCODE_SUCCESS) { int fenceId = callbackHost->GetFenceId(); napi_create_object(context->env, &context->result[PARAM1]); napi_create_int64(context->env, fenceId, &context->result[PARAM1]); - callbackHost->ClearFenceId(); } else { context->errCode = errCode; } @@ -1143,28 +1143,21 @@ napi_value RemoveGnssGeofence(napi_env env, napi_callback_info info) return UndefinedNapiValue(env); } NAPI_CALL(env, napi_get_value_int32(env, argv[0], &fenceId)); - auto asyncContext = CreateGnssGeofenceAsyncContextForRemove(env, fenceId); + auto asyncContext = CreateAsyncContextForRemoveGnssGeofence(env, fenceId); if (asyncContext == nullptr) { HandleSyncErrCode(env, ERRCODE_INVALID_PARAM); return UndefinedNapiValue(env); } - auto iterForDelete = g_gnssGeofenceCallbackHostMap.find(fenceId); - if (iterForDelete != g_gnssGeofenceCallbackHostMap.end()) { - g_gnssGeofenceCallbackHostMap.erase(iterForDelete); - } size_t objectArgsNum = 1; return DoAsyncWork(env, asyncContext, argc, argv, objectArgsNum); } -GnssGeofenceAsyncContext* CreateGnssGeofenceAsyncContextForRemove(const napi_env& env, int fenceId) +GnssGeofenceAsyncContext* CreateAsyncContextForRemoveGnssGeofence(const napi_env& env, int fenceId) { auto asyncContext = new (std::nothrow) GnssGeofenceAsyncContext(env); NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null."); asyncContext->fenceId_ = fenceId; - auto iter = g_gnssGeofenceCallbackHostMap.find(fenceId); - if (iter != g_gnssGeofenceCallbackHostMap.end()) { - asyncContext->callbackHost_ = iter->second; - } + asyncContext->callbackHost_ = FindCallbackInGnssGeofenceCallbackHostMap(fenceId); NAPI_CALL(env, napi_create_string_latin1(env, "removeGnssGeofence", NAPI_AUTO_LENGTH, &asyncContext->resourceName)); @@ -1191,7 +1184,7 @@ GnssGeofenceAsyncContext* CreateGnssGeofenceAsyncContextForRemove(const napi_env asyncContext->completeFunc = [&](void* data) -> void { auto context = static_cast(data); auto callbackHost = context->callbackHost_; - if (callbackHost != nullptr && + if (callbackHost != nullptr && context->errCode == ERRCODE_SUCCESS && callbackHost->GetGeofenceOperationType() == GnssGeofenceOperateType::GNSS_GEOFENCE_OPT_TYPE_DELETE) { LocationErrCode errCode = callbackHost->DealGeofenceOperationResult(); @@ -1204,6 +1197,7 @@ GnssGeofenceAsyncContext* CreateGnssGeofenceAsyncContextForRemove(const napi_env } else { context->errCode = ERRCODE_GEOFENCE_INCORRECT_ID; } + RemoveCallbackToGnssGeofenceCallbackHostMap(context->fenceId_); LBSLOGD(LOCATOR_STANDARD, "Push RemoveGnssGeofence result to client"); }; return asyncContext; @@ -1236,6 +1230,31 @@ napi_value GetGeofenceSupportedCoordTypes(napi_env env, napi_callback_info info) } return res; } + +void AddCallbackToGnssGeofenceCallbackHostMap(int fenceId, sptr callbackHost) +{ + std::unique_lock lock(g_gnssGeofenceCallbackHostMutex); + g_gnssGeofenceCallbackHostMap.insert(std::make_pair(fenceId, callbackHost)); +} + +void RemoveCallbackToGnssGeofenceCallbackHostMap(int fenceId) +{ + std::unique_lock lock(g_gnssGeofenceCallbackHostMutex); + auto iterForDelete = g_gnssGeofenceCallbackHostMap.find(fenceId); + if (iterForDelete != g_gnssGeofenceCallbackHostMap.end()) { + g_gnssGeofenceCallbackHostMap.erase(iterForDelete); + } +} + +sptr FindCallbackInGnssGeofenceCallbackHostMap(int fenceId) +{ + std::unique_lock lock(g_gnssGeofenceCallbackHostMutex); + auto iter = g_gnssGeofenceCallbackHostMap.find(fenceId); + if (iter != g_gnssGeofenceCallbackHostMap.end()) { + return iter->second; + } + return nullptr; +} #endif } // namespace Location } // namespace OHOS diff --git a/frameworks/location_common/common/source/geofence_request.cpp b/frameworks/location_common/common/source/geofence_request.cpp index e62c0c8fe086a656557e9adbee05e84371215e11..075be1ad518957095d7c0d15da1f61b571094463 100644 --- a/frameworks/location_common/common/source/geofence_request.cpp +++ b/frameworks/location_common/common/source/geofence_request.cpp @@ -20,17 +20,19 @@ #include "notification_request.h" #endif #include "iremote_object.h" +#include "want_agent.h" namespace OHOS { namespace Location { void GeofenceRequest::ReadFromParcel(Parcel& data) { std::unique_lock lock(geofenceRequestMutex_); - geofence_->latitude = data.ReadDouble(); - geofence_->longitude = data.ReadDouble(); - geofence_->radius = data.ReadDouble(); - geofence_->expiration = data.ReadDouble(); - geofence_->coordinateSystemType = static_cast(data.ReadInt32()); + scenario_ = data.ReadInt32(); + geofence_.latitude = data.ReadDouble(); + geofence_.longitude = data.ReadDouble(); + geofence_.radius = data.ReadDouble(); + geofence_.expiration = data.ReadDouble(); + geofence_.coordinateSystemType = static_cast(data.ReadInt32()); int monitorGeofenceTransitionSize = data.ReadInt32(); if (monitorGeofenceTransitionSize > MAX_TRANSITION_SIZE) { LBSLOGE(LOCATOR, "fence transition list size should not be greater than 3"); @@ -47,21 +49,30 @@ void GeofenceRequest::ReadFromParcel(Parcel& data) } for (int i = 0; i < requestSize; i++) { auto request = Notification::NotificationRequest::Unmarshalling(data); - notificationRequestList_.push_back(std::make_shared(*request)); + if (request != nullptr) { + notificationRequestList_.push_back(*request); + delete request; + } } #endif callback_ = data.ReadObject(); bundleName_ = data.ReadString(); + auto wantAgent = data.ReadParcelable(); + if (wantAgent != nullptr) { + wantAgent_ = *(wantAgent); + delete wantAgent; + } } bool GeofenceRequest::Marshalling(Parcel& parcel) const { std::unique_lock lock(geofenceRequestMutex_); - parcel.WriteDouble(geofence_->latitude); - parcel.WriteDouble(geofence_->longitude); - parcel.WriteDouble(geofence_->radius); - parcel.WriteDouble(geofence_->expiration); - parcel.WriteInt32(static_cast(geofence_->coordinateSystemType)); + parcel.WriteInt32(scenario_); + parcel.WriteDouble(geofence_.latitude); + parcel.WriteDouble(geofence_.longitude); + parcel.WriteDouble(geofence_.radius); + parcel.WriteDouble(geofence_.expiration); + parcel.WriteInt32(static_cast(geofence_.coordinateSystemType)); if (transitionStatusList_.size() > MAX_TRANSITION_SIZE) { LBSLOGE(LOCATOR, "fence transition list size should not be greater than 3"); return false; @@ -77,11 +88,12 @@ bool GeofenceRequest::Marshalling(Parcel& parcel) const } parcel.WriteInt32(notificationRequestList_.size()); for (int i = 0; i < notificationRequestList_.size(); i++) { - notificationRequestList_[i]->Marshalling(parcel); + notificationRequestList_[i].Marshalling(parcel); } #endif parcel.WriteRemoteObject(callback_); parcel.WriteString(bundleName_); + parcel.WriteParcelable(&wantAgent_); return true; } diff --git a/frameworks/native/source/location_gnss_geofence_callback_host.cpp b/frameworks/native/source/location_gnss_geofence_callback_host.cpp index b183cde6980ddff32d5caedc048e692f3eb988a7..02c1c391acc22a6d1d4d88a68a5bcbd157e70d5b 100644 --- a/frameworks/native/source/location_gnss_geofence_callback_host.cpp +++ b/frameworks/native/source/location_gnss_geofence_callback_host.cpp @@ -61,16 +61,18 @@ int LocationGnssGeofenceCallbackHost::OnRemoteRequest( } switch (code) { case RECEIVE_TRANSITION_STATUS_EVENT: { - Send(code, data); + GeofenceTransition transition; + transition.fenceId = data.ReadInt32(); + transition.event = + static_cast(data.ReadInt32()); + OnTransitionStatusChange(transition); break; } case REPORT_OPERATION_RESULT_EVENT: { int fenceId = data.ReadInt32(); int type = data.ReadInt32(); int result = data.ReadInt32(); - SetFenceId(fenceId); - SetGeofenceOperationType(static_cast(type)); - SetGeofenceOperationResult(static_cast(result)); + OnReportOperationResult(fenceId, type, result); CountDown(); break; } @@ -82,7 +84,8 @@ int LocationGnssGeofenceCallbackHost::OnRemoteRequest( return 0; } -void LocationGnssGeofenceCallbackHost::Send(int code, MessageParcel& data) +void LocationGnssGeofenceCallbackHost::OnTransitionStatusChange( + GeofenceTransition transition) { std::unique_lock guard(mutex_); uv_loop_s *loop = nullptr; @@ -103,13 +106,24 @@ void LocationGnssGeofenceCallbackHost::Send(int code, MessageParcel& data) } context->env = env_; context->callback[SUCCESS_CALLBACK] = handlerCb_; - if (code == static_cast(RECEIVE_TRANSITION_STATUS_EVENT)) { - context->transition_.fenceId = data.ReadInt32(); - context->transition_.event = - static_cast(data.ReadInt32()); - context->code_ = code; - work->data = context; - UvQueueWork(loop, work); + context->transition_ = transition; + work->data = context; + UvQueueWork(loop, work); +} + +void LocationGnssGeofenceCallbackHost::OnReportOperationResult(int fenceId, int type, int result) +{ + int addValue = static_cast(GnssGeofenceOperateType::GNSS_GEOFENCE_OPT_TYPE_ADD); + if ((type != addValue && fenceId == GetFenceId()) || + (type == addValue)) { + GnssGeofenceOperateResult optResult = static_cast(result); + GnssGeofenceOperateType optType = static_cast(type); + if (result == GnssGeofenceOperateResult::GNSS_GEOFENCE_OPERATION_SUCCESS && + optType == GnssGeofenceOperateType::GNSS_GEOFENCE_OPT_TYPE_ADD) { + SetFenceId(fenceId); + } + SetGeofenceOperationType(optType); + SetGeofenceOperationResult(optResult); } } @@ -144,11 +158,9 @@ void LocationGnssGeofenceCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* w napi_value jsEvent[PARAM2]; CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_create_object(context->env, &jsEvent[PARAM1]), scope, context, work); - if (context->code_ == RECEIVE_TRANSITION_STATUS_EVENT) { - CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_get_undefined(context->env, &jsEvent[PARAM0]), - scope, context, work); - GeofenceTransitionToJs(context->env, context->transition_, jsEvent[PARAM1]); - } + CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_get_undefined(context->env, &jsEvent[PARAM0]), + scope, context, work); + GeofenceTransitionToJs(context->env, context->transition_, jsEvent[PARAM1]); if (context->callback[SUCCESS_CALLBACK] != nullptr) { napi_value undefine; napi_value handler = nullptr; diff --git a/frameworks/native/source/locator_impl.cpp b/frameworks/native/source/locator_impl.cpp index d5363e3b9dc12d308bb9f4eabb1f3c29d196d57f..02206afa2b202bbc61bf87758629f68dcb01aecc 100644 --- a/frameworks/native/source/locator_impl.cpp +++ b/frameworks/native/source/locator_impl.cpp @@ -1020,7 +1020,7 @@ LocationErrCode LocatorImpl::RemoveGnssGeofence(std::shared_ptr if (!LocationSaLoadManager::InitLocationSa(LOCATION_LOCATOR_SA_ID)) { return ERRCODE_SERVICE_UNAVAILABLE; } - LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::AddGnssGeofence()"); + LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::RemoveGnssGeofence()"); sptr proxy = GetProxy(); if (proxy == nullptr) { LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__); diff --git a/frameworks/native/source/locator_proxy.cpp b/frameworks/native/source/locator_proxy.cpp index 8886280acace24329c6eb454231e297d3e0a4ce6..b11892c7830cace01c64b258a6b97b58297f30ac 100644 --- a/frameworks/native/source/locator_proxy.cpp +++ b/frameworks/native/source/locator_proxy.cpp @@ -820,15 +820,7 @@ LocationErrCode LocatorProxy::HandleGnssfenceRequest( LBSLOGE(LOCATOR_STANDARD, "%{public}s WriteInterfaceToken failed", __func__); return ERRCODE_SERVICE_UNAVAILABLE; } - data.WriteInt32(request->GetScenario()); - auto geofence = request->GetGeofence(); - data.WriteDouble(geofence->latitude); - data.WriteDouble(geofence->longitude); - data.WriteDouble(geofence->radius); - data.WriteDouble(geofence->expiration); - data.WriteInt32(static_cast(geofence->coordinateSystemType)); - auto wantAgent = request->GetWantAgent(); - data.WriteParcelable(&wantAgent); + request->Marshalling(data); LocationErrCode errorCode = SendMsgWithDataReplyV9(static_cast(code), data, reply); LBSLOGD(LOCATOR_STANDARD, "Transact ErrCodes = %{public}d", errorCode); return errorCode; @@ -836,25 +828,10 @@ LocationErrCode LocatorProxy::HandleGnssfenceRequest( LocationErrCode LocatorProxy::AddGnssGeofence(std::shared_ptr& request) { - if (request == nullptr) { - LBSLOGE(LOCATOR_STANDARD, "request is nullptr"); - return ERRCODE_INVALID_PARAM; - } - MessageParcel data; - MessageParcel reply; - if (!data.WriteInterfaceToken(GetDescriptor())) { - LBSLOGE(LOCATOR_STANDARD, "can not write descriptor"); - return ERRCODE_SERVICE_UNAVAILABLE; - } - request->Marshalling(data); - LocationErrCode errorCode = SendMsgWithDataReplyV9( - static_cast(LocatorInterfaceCode::ADD_GNSS_GEOFENCE), data, reply); - LBSLOGD(LOCATOR_STANDARD, "Transact ErrCodes = %{public}d", errorCode); - return errorCode; + return HandleGnssfenceRequest(LocatorInterfaceCode::ADD_GNSS_GEOFENCE, request); } -LocationErrCode LocatorProxy::RemoveGnssGeofence( - std::shared_ptr& request) +LocationErrCode LocatorProxy::RemoveGnssGeofence(std::shared_ptr& request) { if (request == nullptr) { return ERRCODE_INVALID_PARAM; @@ -1046,7 +1023,7 @@ LocationErrCode LocatorProxy::GetGeofenceSupportedCoordTypes( } MessageParcel reply; LocationErrCode errorCode = SendMsgWithDataReplyV9( - static_cast(LocatorInterfaceCode::QUERY_SUPPORT_COORDINATE_SYSTEM_TYPE), data, reply); + static_cast(LocatorInterfaceCode::GET_GEOFENCE_SUPPORT_COORDINATE_SYSTEM_TYPE), data, reply); LBSLOGD(LOCATOR_STANDARD, "Proxy::%{public}s Transact ErrCodes = %{public}d", __func__, errorCode); int size = reply.ReadInt32(); size = size > COORDINATE_SYSTEM_TYPE_SIZE ? COORDINATE_SYSTEM_TYPE_SIZE : size; diff --git a/frameworks/native/source/napi_util.cpp b/frameworks/native/source/napi_util.cpp index cc9df3075a9749d1bc7dc9ce4b0328cb4b595306..ede3abab3afaff8afd33f0e5886c3ba0d42663cd 100644 --- a/frameworks/native/source/napi_util.cpp +++ b/frameworks/native/source/napi_util.cpp @@ -277,23 +277,23 @@ void JsObjToGeoFenceRequest(const napi_env& env, const napi_value& object, LBSLOGE(LOCATOR_STANDARD, "parse geofence failed"); return; } - std::shared_ptr geofence = std::make_shared(); + GeoFence geofence; if (JsObjectToDouble(env, geofenceValue, "latitude", doubleValue) == SUCCESS) { - geofence->latitude = doubleValue; + geofence.latitude = doubleValue; } if (JsObjectToDouble(env, geofenceValue, "longitude", doubleValue) == SUCCESS) { - geofence->longitude = doubleValue; + geofence.longitude = doubleValue; } if (JsObjectToInt(env, geofenceValue, "coordinateSystemType", value) == SUCCESS) { - geofence->coordinateSystemType = static_cast(value); + geofence.coordinateSystemType = static_cast(value); } else { - geofence->coordinateSystemType = CoordinateSystemType::WGS84; + geofence.coordinateSystemType = CoordinateSystemType::WGS84; } if (JsObjectToDouble(env, geofenceValue, "radius", doubleValue) == SUCCESS) { - geofence->radius = doubleValue; + geofence.radius = doubleValue; } if (JsObjectToDouble(env, geofenceValue, "expiration", doubleValue) == SUCCESS) { - geofence->expiration = doubleValue; + geofence.expiration = doubleValue; } request->SetGeofence(geofence); } @@ -484,7 +484,7 @@ bool GenGnssGeofenceRequest( JsObjToGeofenceTransitionEventList(env, value, geofenceTransitionStatusList); geofenceRequest->SetGeofenceTransitionEventList(geofenceTransitionStatusList); #ifdef NOTIFICATION_ENABLE - std::vector> notificationRequestList; + std::vector notificationRequestList; JsObjToNotificationRequestList(env, value, notificationRequestList); geofenceRequest->SetNotificationRequestList(notificationRequestList); #endif @@ -530,14 +530,14 @@ napi_value GetArrayProperty(const napi_env& env, const napi_value& object, std:: #ifdef NOTIFICATION_ENABLE void JsObjToNotificationRequestList(const napi_env& env, const napi_value& object, - std::vector>& notificationRequestList) + std::vector& notificationRequestList) { napi_value notificationRequest = GetArrayProperty(env, object, "notifications"); GetNotificationRequestArray(env, notificationRequest, notificationRequestList); } void GetNotificationRequestArray(const napi_env& env, const napi_value& notificationRequestValue, - std::vector>& notificationRequestList) + std::vector& notificationRequestList) { napi_valuetype valueType; NAPI_CALL_RETURN_VOID(env, napi_typeof(env, notificationRequestValue, &valueType)); @@ -562,9 +562,7 @@ void GetNotificationRequestArray(const napi_env& env, const napi_value& notifica } NotificationRequest notificationRequest; GenNotificationRequest(env, elementValue, notificationRequest); - std::shared_ptr request = - std::make_shared(notificationRequest); - notificationRequestList.push_back(request); + notificationRequestList.push_back(notificationRequest); } } diff --git a/interfaces/inner_api/include/geofence_request.h b/interfaces/inner_api/include/geofence_request.h index d21dfd3368c65acaa035c504c5491e224b72e7ad..53c832250e8759154338c9ef1f0ac1f769c6fd5e 100644 --- a/interfaces/inner_api/include/geofence_request.h +++ b/interfaces/inner_api/include/geofence_request.h @@ -38,7 +38,6 @@ public: GeofenceRequest() { callback_ = nullptr; - geofence_ = std::make_shared(); scenario_ = -1; fenceId_ = -1; } @@ -57,12 +56,12 @@ public: ~GeofenceRequest() {} - inline std::shared_ptr GetGeofence() + inline GeoFence GetGeofence() { return geofence_; } - inline void SetGeofence(std::shared_ptr geofence) + inline void SetGeofence(GeoFence geofence) { geofence_ = geofence; } @@ -107,19 +106,19 @@ public: } } - inline std::vector> GetNotificationRequestList() + inline std::vector GetNotificationRequestList() { std::unique_lock lock(geofenceRequestMutex_); return notificationRequestList_; } - inline void SetNotificationRequest(std::shared_ptr request) + inline void SetNotificationRequest(Notification::NotificationRequest request) { std::unique_lock lock(geofenceRequestMutex_); notificationRequestList_.push_back(request); } - inline void SetNotificationRequestList(std::vector> requestList) + inline void SetNotificationRequestList(std::vector requestList) { std::unique_lock lock(geofenceRequestMutex_); for (auto it = requestList.begin(); it != requestList.end(); ++it) { @@ -162,9 +161,9 @@ public: static std::shared_ptr Unmarshalling(Parcel& parcel); private: std::vector transitionStatusList_; - std::vector> notificationRequestList_; + std::vector notificationRequestList_; sptr callback_ = nullptr; - std::shared_ptr geofence_ = nullptr; + GeoFence geofence_; int scenario_; int fenceId_; AbilityRuntime::WantAgent::WantAgent wantAgent_; diff --git a/interfaces/inner_api/include/i_gnss_geofence_callback.h b/interfaces/inner_api/include/i_gnss_geofence_callback.h index bbb42e9d1d0b9e7dc566d3e72921f92dfaca0ced..c8bee7aefa9eb307bff73911b39d102dfb468d1a 100644 --- a/interfaces/inner_api/include/i_gnss_geofence_callback.h +++ b/interfaces/inner_api/include/i_gnss_geofence_callback.h @@ -18,7 +18,7 @@ #include "iremote_broker.h" -#include "constant_definition.h" +#include "geofence_definition.h" namespace OHOS { namespace Location { @@ -29,6 +29,8 @@ public: RECEIVE_TRANSITION_STATUS_EVENT }; DECLARE_INTERFACE_DESCRIPTOR(u"location.IGnssGeofenceCallback"); + virtual void OnTransitionStatusChange(GeofenceTransition transition) = 0; + virtual void OnReportOperationResult(int fenceId, int type, int result) = 0; }; } // namespace Location } // namespace OHOS diff --git a/interfaces/inner_api/include/location_gnss_geofence_callback_host.h b/interfaces/inner_api/include/location_gnss_geofence_callback_host.h index 54a5fd309ab9af63625f5164dc1fe220c79a905f..aa18287dd65f21de8af95cda0295169a03174c07 100644 --- a/interfaces/inner_api/include/location_gnss_geofence_callback_host.h +++ b/interfaces/inner_api/include/location_gnss_geofence_callback_host.h @@ -47,6 +47,8 @@ public: void SetGeofenceOperationType(GnssGeofenceOperateType type); GnssGeofenceOperateResult GetGeofenceOperationResult(); void SetGeofenceOperationResult(GnssGeofenceOperateResult result); + void OnTransitionStatusChange(GeofenceTransition transition) override; + void OnReportOperationResult(int fenceId, int type, int result) override; inline napi_env GetEnv() const { @@ -79,7 +81,6 @@ public: } private: - void Send(int code, MessageParcel& data); void UvQueueWork(uv_loop_s* loop, uv_work_t* work); void InitLatch(); diff --git a/interfaces/inner_api/include/locationhub_ipc_interface_code.h b/interfaces/inner_api/include/locationhub_ipc_interface_code.h index 64311c79ceefcb0e5e99076a333a67bc5cd036d7..e427b710c2278ae654bcec0026f41274f8f8d4e3 100644 --- a/interfaces/inner_api/include/locationhub_ipc_interface_code.h +++ b/interfaces/inner_api/include/locationhub_ipc_interface_code.h @@ -66,7 +66,7 @@ enum class LocatorInterfaceCode { UNREG_LOCATING_REQUIRED_DATA_CALLBACK = 44, ADD_GNSS_GEOFENCE = 45, REMOVE_GNSS_GEOFENCE = 46, - QUERY_SUPPORT_COORDINATE_SYSTEM_TYPE = 47, + GET_GEOFENCE_SUPPORT_COORDINATE_SYSTEM_TYPE = 47, REG_LOCATION_ERROR = 48, UNREG_LOCATION_ERROR = 49, REPORT_LOCATION_ERROR = 50 @@ -110,7 +110,7 @@ enum class GnssInterfaceCode { DISABLE_REV_GEOCODE_MOCK = 26, ADD_GNSS_GEOFENCE = 27, REMOVE_GNSS_GEOFENCE = 28, - QUERY_SUPPORT_COORDINATE_SYSTEM_TYPE = 29, + GET_GEOFENCE_SUPPORT_COORDINATE_SYSTEM_TYPE = 29, }; enum class NetworkInterfaceCode { diff --git a/interfaces/inner_api/include/napi_util.h b/interfaces/inner_api/include/napi_util.h index 341d463311f95e32a8598ab88762ef7d24ad788b..9a4e7706c9fe02777aafec0cf29356ccce66dcca 100644 --- a/interfaces/inner_api/include/napi_util.h +++ b/interfaces/inner_api/include/napi_util.h @@ -99,9 +99,9 @@ bool GenGnssGeofenceRequest( napi_value GetArrayProperty(const napi_env& env, const napi_value& object, std::string propertyName); #ifdef NOTIFICATION_ENABLE void JsObjToNotificationRequestList(const napi_env& env, const napi_value& object, - std::vector>& notificationRequestList); + std::vector& notificationRequestList); void GetNotificationRequestArray(const napi_env& env, const napi_value& notificationRequest, - std::vector>& notificationRequestList); + std::vector& notificationRequestList); #endif void JsObjToGeofenceTransitionEventList(const napi_env& env, const napi_value& object, std::vector& geofenceTransitionStatusList); diff --git a/services/location_gnss/gnss/BUILD.gn b/services/location_gnss/gnss/BUILD.gn index 99897ec11932705556653765e8b891abf4e9748e..a4ab8242790411aaa62a467b13d8bc4dd4ea7564 100644 --- a/services/location_gnss/gnss/BUILD.gn +++ b/services/location_gnss/gnss/BUILD.gn @@ -24,7 +24,6 @@ if (location_feature_with_gnss) { "$LOCATION_GNSS_ROOT/source/gnss_ability_skeleton.cpp", "$LOCATION_GNSS_ROOT/source/gnss_common_event_subscriber.cpp", "$LOCATION_GNSS_ROOT/source/gnss_event_callback.cpp", - "$LOCATION_GNSS_ROOT/source/location_gnss_geofence_callback_proxy.cpp", "$LOCATION_GNSS_ROOT/source/string_utils.cpp", "$LOCATION_GNSS_ROOT/source/ui_extension_ability_connection.cpp", "$LOCATION_LOCATOR_ROOT/source/location_config_manager.cpp", diff --git a/services/location_gnss/gnss/include/gnss_ability.h b/services/location_gnss/gnss/include/gnss_ability.h index abb5dfbe3cb3c25d4da1102034299c103a3af8ca..358e482705c6a3b5afdac3fb265b29b5118ed159 100644 --- a/services/location_gnss/gnss/include/gnss_ability.h +++ b/services/location_gnss/gnss/include/gnss_ability.h @@ -82,7 +82,9 @@ using HDI::Location::Geofence::V2_0::GeofenceInfo; typedef struct { std::shared_ptr request; +#ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE sptr callback; +#endif int requestCode; int retCode; std::vector coordinateSystemTypes; @@ -181,10 +183,11 @@ public: const sptr& callback); bool UnregisterGnssGeofenceCallback(int fenceId); std::shared_ptr GetGeofenceRequestByFenceId(int fenceId); - sptr GetGnssGeofenceCallbackByFenceId(int fenceId); +#ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE void ReportGeofenceEvent(int fenceId, GeofenceEvent event); void ReportGeofenceOperationResult( int fenceId, GeofenceOperateType type, GeofenceOperateResult result); +#endif bool RemoveGnssGeofenceRequestByCallback(sptr callbackObj); LocationErrCode QuerySupportCoordinateSystemType( std::vector& coordinateSystemTypes) override; diff --git a/services/location_gnss/gnss/source/gnss_ability.cpp b/services/location_gnss/gnss/source/gnss_ability.cpp index 4388a70c4b2c9822d0a4f87d44b983465194cce6..1abe521a8bbcbce07e56dace96f63e5fe79a573b 100644 --- a/services/location_gnss/gnss/source/gnss_ability.cpp +++ b/services/location_gnss/gnss/source/gnss_ability.cpp @@ -43,7 +43,6 @@ #include "location_data_rdb_manager.h" #include "hook_utils.h" -#include "location_gnss_geofence_callback_proxy.h" #include "geofence_definition.h" namespace OHOS { @@ -485,28 +484,24 @@ LocationErrCode GnssAbility::SetPositionMode() LocationErrCode GnssAbility::AddFence(std::shared_ptr& request) { - auto geofence = request->GetGeofence(); - if (geofence == nullptr) { - LBSLOGE(GNSS, "geofence is nullptr"); - return ERRCODE_INVALID_PARAM; - } int fenceId = GenerateFenceId(); request->SetFenceId(fenceId); #ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE + auto geofence = request->GetGeofence(); if (geofenceInterface_ == nullptr) { LBSLOGE(GNSS, "geofenceInterface_ is nullptr"); return ERRCODE_SERVICE_UNAVAILABLE; } GeofenceInfo fenceInfo; fenceInfo.fenceIndex = fenceId; - fenceInfo.latitude = geofence->latitude; - fenceInfo.longitude = geofence->longitude; - fenceInfo.radius = geofence->radius; + fenceInfo.latitude = geofence.latitude; + fenceInfo.longitude = geofence.longitude; + fenceInfo.radius = geofence.radius; int monitorEvent = static_cast(GeofenceTransitionEvent::GEOFENCE_TRANSITION_EVENT_ENTER) | static_cast(GeofenceTransitionEvent::GEOFENCE_TRANSITION_EVENT_EXIT); int32_t ret = geofenceInterface_->AddGnssGeofence(fenceInfo, static_cast(monitorEvent)); -#endif LBSLOGD(GNSS, "Successfully AddFence!, %{public}d", ret); +#endif if (ExecuteFenceProcess(GnssInterfaceCode::ADD_FENCE_INFO, request)) { return ERRCODE_SUCCESS; } @@ -521,8 +516,8 @@ LocationErrCode GnssAbility::RemoveFence(std::shared_ptr& reque return ERRCODE_SERVICE_UNAVAILABLE; } int32_t ret = geofenceInterface_->DeleteGnssGeofence(request->GetFenceId()); -#endif LBSLOGD(GNSS, "Successfully RemoveFence!, %{public}d", ret); +#endif if (ExecuteFenceProcess(GnssInterfaceCode::REMOVE_FENCE_INFO, request)) { return ERRCODE_SUCCESS; } @@ -543,23 +538,19 @@ int32_t GnssAbility::GenerateFenceId() LocationErrCode GnssAbility::AddGnssGeofence(std::shared_ptr& request) { - auto geofence = request->GetGeofence(); - if (geofence == nullptr) { - LBSLOGE(GNSS, "geofence is nullptr"); - return ERRCODE_INVALID_PARAM; - } int fenceId = GenerateFenceId(); request->SetFenceId(fenceId); #ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE + auto geofence = request->GetGeofence(); if (geofenceInterface_ == nullptr) { LBSLOGE(GNSS, "geofenceInterface_ is nullptr"); return ERRCODE_SERVICE_UNAVAILABLE; } GeofenceInfo fenceInfo; fenceInfo.fenceIndex = fenceId; - fenceInfo.latitude = geofence->latitude; - fenceInfo.longitude = geofence->longitude; - fenceInfo.radius = geofence->radius; + fenceInfo.latitude = geofence.latitude; + fenceInfo.longitude = geofence.longitude; + fenceInfo.radius = geofence.radius; auto transitionList = request->GetGeofenceTransitionEventList(); int monitorEvent = 0; for (int i = 0; i < transitionList.size(); i++) { @@ -623,6 +614,7 @@ bool GnssAbility::UnregisterGnssGeofenceCallback(int fenceId) auto fenceIdInMap = requestInMap->GetFenceId(); if (fenceId == fenceIdInMap) { iter = gnssGeofenceRequestMap_.erase(iter); + break; } else { iter++; } @@ -667,6 +659,7 @@ bool GnssAbility::RemoveGnssGeofenceRequestByCallback(sptr callba return true; } +#ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE void GnssAbility::ReportGeofenceOperationResult( int fenceId, GeofenceOperateType type, GeofenceOperateResult result) { @@ -676,19 +669,21 @@ void GnssAbility::ReportGeofenceOperationResult( LBSLOGE(GNSS, "request is nullptr"); return; } - auto callback = GetGnssGeofenceCallbackByFenceId(fenceId); + auto callback = geofenceRequest->GetGeofenceTransitionCallback(); if (callback == nullptr) { LBSLOGE(GNSS, "callback is nullptr"); return; } - auto gnssGeofenceCallback = std::make_unique(callback); + sptr gnssGeofenceCallback = iface_cast(callback); gnssGeofenceCallback->OnReportOperationResult( fenceId, static_cast(type), static_cast(result)); if (type == GeofenceOperateType::TYPE_DELETE) { UnregisterGnssGeofenceCallback(fenceId); } } +#endif +#ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE void GnssAbility::ReportGeofenceEvent(int fenceIndex, GeofenceEvent event) { std::unique_lock lock(gnssGeofenceRequestMapMutex_); @@ -702,7 +697,7 @@ void GnssAbility::ReportGeofenceEvent(int fenceIndex, GeofenceEvent event) LBSLOGE(GNSS, "callback is nullptr"); return; } - auto gnssGeofenceCallback = std::make_unique(callback); + sptr gnssGeofenceCallback = iface_cast(callback); auto transitionStatusList = request->GetGeofenceTransitionEventList(); #ifdef NOTIFICATION_ENABLE auto notificationRequestList = request->GetNotificationRequestList(); @@ -718,16 +713,16 @@ void GnssAbility::ReportGeofenceEvent(int fenceIndex, GeofenceEvent event) gnssGeofenceCallback->OnTransitionStatusChange(geofenceTransition); #ifdef NOTIFICATION_ENABLE auto notificationRequest = notificationRequestList[i]; - if (notificationRequest != nullptr && - transitionStatusList.size() == notificationRequestList.size()) { - notificationRequest->SetCreatorUid(IPCSkeleton::GetCallingUid()); - Notification::NotificationHelper::PublishNotification(*notificationRequest); + if (transitionStatusList.size() == notificationRequestList.size()) { + notificationRequest.SetCreatorUid(IPCSkeleton::GetCallingUid()); + Notification::NotificationHelper::PublishNotification(notificationRequest); } else { LBSLOGE(GNSS, "transitionStatusList size does not equals to notificationRequestList size"); } #endif } } +#endif std::shared_ptr GnssAbility::GetGeofenceRequestByFenceId(int fenceId) { @@ -740,18 +735,6 @@ std::shared_ptr GnssAbility::GetGeofenceRequestByFenceId(int fe return nullptr; } -sptr GnssAbility::GetGnssGeofenceCallbackByFenceId(int fenceId) -{ - for (auto iter = gnssGeofenceRequestMap_.begin(); iter != gnssGeofenceRequestMap_.end(); iter++) { - auto request = iter->first; - auto callback = iter->second; - if (request->GetFenceId() == fenceId) { - return callback; - } - } - return nullptr; -} - bool GnssAbility::ExecuteFenceProcess( GnssInterfaceCode code, std::shared_ptr& request) { @@ -949,7 +932,7 @@ bool GnssAbility::ConnectHdi() #ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE geofenceInterface_ = IGeofenceInterface::Get(); if (geofenceInterface_ != nullptr) { - geofenceCallback_ = new (std::nothrow) GeofenceEventCallback(); + geofenceCallback_ = sptr(new (std::nothrow) GeofenceEventCallback); SetGeofenceCallback(); } #endif @@ -1163,7 +1146,7 @@ LocationErrCode GnssAbility::QuerySupportCoordinateSystemType( supportedTypes.push_back(CoordinateSystemType::WGS84); FenceStruct fenceStruct; fenceStruct.requestCode = - static_cast(GnssInterfaceCode::QUERY_SUPPORT_COORDINATE_SYSTEM_TYPE); + static_cast(GnssInterfaceCode::GET_GEOFENCE_SUPPORT_COORDINATE_SYSTEM_TYPE); fenceStruct.coordinateSystemTypes = supportedTypes; HookUtils::ExecuteHook( LocationProcessStage::FENCE_REQUEST_PROCESS, (void *)&fenceStruct, nullptr); diff --git a/services/location_gnss/gnss/source/gnss_ability_skeleton.cpp b/services/location_gnss/gnss/source/gnss_ability_skeleton.cpp index 22784d5f99c2673d7adf8d2133cc8a5f97f2abb6..4ee96c5381e4cfd3eaa55a62f46d8cbbc541320d 100644 --- a/services/location_gnss/gnss/source/gnss_ability_skeleton.cpp +++ b/services/location_gnss/gnss/source/gnss_ability_skeleton.cpp @@ -70,7 +70,7 @@ void GnssAbilityStub::InitGnssMsgHandleMap() &GnssAbilityStub::AddGnssGeofenceInner; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::REMOVE_GNSS_GEOFENCE)] = &GnssAbilityStub::RemoveGnssGeofenceInner; - GnssMsgHandleMap_[static_cast(GnssInterfaceCode::QUERY_SUPPORT_COORDINATE_SYSTEM_TYPE)] = + GnssMsgHandleMap_[static_cast(GnssInterfaceCode::GET_GEOFENCE_SUPPORT_COORDINATE_SYSTEM_TYPE)] = &GnssAbilityStub::QuerySupportCoordinateSystemTypeInner; } @@ -236,17 +236,7 @@ int GnssAbilityStub::AddFenceInner(MessageParcel &data, MessageParcel &reply, Ap if (!PermissionManager::CheckCallingPermission(identity.GetUid(), identity.GetPid(), reply)) { return ERRCODE_PERMISSION_DENIED; } - std::shared_ptr geofence = std::make_shared(); - std::shared_ptr request = std::make_shared(); - request->SetScenario(data.ReadInt32()); - geofence->latitude = data.ReadDouble(); - geofence->longitude = data.ReadDouble(); - geofence->radius = data.ReadDouble(); - geofence->expiration = data.ReadDouble(); - geofence->coordinateSystemType = static_cast(data.ReadInt32()); - request->SetGeofence(geofence); - auto agent = data.ReadParcelable(); - request->SetWantAgent(*agent); + auto request = GeofenceRequest::Unmarshalling(data); reply.WriteInt32(AddFence(request)); return ERRCODE_SUCCESS; } @@ -256,17 +246,7 @@ int GnssAbilityStub::RemoveFenceInner(MessageParcel &data, MessageParcel &reply, if (!PermissionManager::CheckCallingPermission(identity.GetUid(), identity.GetPid(), reply)) { return ERRCODE_PERMISSION_DENIED; } - std::shared_ptr geofence = std::make_shared(); - std::shared_ptr request = std::make_shared(); - request->SetScenario(data.ReadInt32()); - geofence->latitude = data.ReadDouble(); - geofence->longitude = data.ReadDouble(); - geofence->radius = data.ReadDouble(); - geofence->expiration = data.ReadDouble(); - geofence->coordinateSystemType = static_cast(data.ReadInt32()); - request->SetGeofence(geofence); - auto agent = data.ReadParcelable(); - request->SetWantAgent(*agent); + auto request = GeofenceRequest::Unmarshalling(data); reply.WriteInt32(RemoveFence(request)); return ERRCODE_SUCCESS; } diff --git a/services/location_gnss/gnss/include/location_gnss_geofence_callback_proxy.h b/services/location_locator/callback/include/location_gnss_geofence_callback_proxy.h similarity index 100% rename from services/location_gnss/gnss/include/location_gnss_geofence_callback_proxy.h rename to services/location_locator/callback/include/location_gnss_geofence_callback_proxy.h diff --git a/services/location_gnss/gnss/source/location_gnss_geofence_callback_proxy.cpp b/services/location_locator/callback/source/location_gnss_geofence_callback_proxy.cpp similarity index 100% rename from services/location_gnss/gnss/source/location_gnss_geofence_callback_proxy.cpp rename to services/location_locator/callback/source/location_gnss_geofence_callback_proxy.cpp diff --git a/services/location_locator/locator/BUILD.gn b/services/location_locator/locator/BUILD.gn index 4a315e4268055f98704886e908379deb19aac6f0..3cbe422bb666344bb8a292baa9f77fc5b7068a47 100644 --- a/services/location_locator/locator/BUILD.gn +++ b/services/location_locator/locator/BUILD.gn @@ -26,6 +26,7 @@ ohos_shared_library("lbsservice_locator") { "$SUBSYSTEM_DIR/location_locator/callback/source/country_code_callback_proxy.cpp", "$SUBSYSTEM_DIR/location_locator/callback/source/gnss_status_callback_proxy.cpp", "$SUBSYSTEM_DIR/location_locator/callback/source/locating_required_data_callback_proxy.cpp", + "$SUBSYSTEM_DIR/location_locator/callback/source/location_gnss_geofence_callback_proxy.cpp", "$SUBSYSTEM_DIR/location_locator/callback/source/locator_callback_proxy.cpp", "$SUBSYSTEM_DIR/location_locator/callback/source/nmea_message_callback_proxy.cpp", "$SUBSYSTEM_DIR/location_locator/locator/source/fusion_controller.cpp", diff --git a/services/location_locator/locator/source/gnss_ability_proxy.cpp b/services/location_locator/locator/source/gnss_ability_proxy.cpp index 197b1d49522000b9babcd52905ea451213f85e33..b092bccfe304d538a7d41953a277fff52d8ea9a9 100644 --- a/services/location_locator/locator/source/gnss_ability_proxy.cpp +++ b/services/location_locator/locator/source/gnss_ability_proxy.cpp @@ -266,15 +266,7 @@ LocationErrCode GnssAbilityProxy::AddFence(std::shared_ptr& req LBSLOGE(GNSS, "write interfaceToken fail!"); return ERRCODE_SERVICE_UNAVAILABLE; } - data.WriteInt32(request->GetScenario()); - auto geofence = request->GetGeofence(); - data.WriteDouble(geofence->latitude); - data.WriteDouble(geofence->longitude); - data.WriteDouble(geofence->radius); - data.WriteDouble(geofence->expiration); - data.WriteInt32(static_cast(geofence->coordinateSystemType)); - auto wantAgent = request->GetWantAgent(); - data.WriteParcelable(&wantAgent); + request->Marshalling(data); sptr remote = Remote(); if (remote == nullptr) { LBSLOGE(GNSS, "AddFence remote is null"); @@ -295,15 +287,7 @@ LocationErrCode GnssAbilityProxy::RemoveFence(std::shared_ptr& LBSLOGE(GNSS, "write interfaceToken fail!"); return ERRCODE_SERVICE_UNAVAILABLE; } - data.WriteInt32(request->GetScenario()); - auto geofence = request->GetGeofence(); - data.WriteDouble(geofence->latitude); - data.WriteDouble(geofence->longitude); - data.WriteDouble(geofence->radius); - data.WriteDouble(geofence->expiration); - data.WriteInt32(static_cast(geofence->coordinateSystemType)); - auto wantAgent = request->GetWantAgent(); - data.WriteParcelable(&wantAgent); + request->Marshalling(data); sptr remote = Remote(); if (remote == nullptr) { LBSLOGE(GNSS, "RemoveFence remote is null"); @@ -443,8 +427,8 @@ LocationErrCode GnssAbilityProxy::QuerySupportCoordinateSystemType( LBSLOGE(GNSS, "write interfaceToken fail!"); return ERRCODE_SERVICE_UNAVAILABLE; } - int error = - remote->SendRequest(static_cast(GnssInterfaceCode::DISABLE_LOCATION_MOCK), data, reply, option); + int error = remote->SendRequest( + static_cast(GnssInterfaceCode::GET_GEOFENCE_SUPPORT_COORDINATE_SYSTEM_TYPE), data, reply, option); LBSLOGD(GNSS, "%{public}s Transact Error = %{public}d", __func__, error); return LocationErrCode(reply.ReadInt32()); } diff --git a/services/location_locator/locator/source/locator_ability.cpp b/services/location_locator/locator/source/locator_ability.cpp index f99fcb0717d91d529a981c0e75aa6755c000dfa8..70debbffb32fe252e8d6cde5dcafe65f46403579 100644 --- a/services/location_locator/locator/source/locator_ability.cpp +++ b/services/location_locator/locator/source/locator_ability.cpp @@ -603,15 +603,7 @@ LocationErrCode LocatorAbility::AddFence(std::shared_ptr& reque if (!dataToStub.WriteInterfaceToken(GnssAbilityProxy::GetDescriptor())) { return ERRCODE_SERVICE_UNAVAILABLE; } - dataToStub.WriteInt32(request->GetScenario()); - auto geofence = request->GetGeofence(); - dataToStub.WriteDouble(geofence->latitude); - dataToStub.WriteDouble(geofence->longitude); - dataToStub.WriteDouble(geofence->radius); - dataToStub.WriteDouble(geofence->expiration); - dataToStub.WriteInt32(static_cast(geofence->coordinateSystemType)); - auto wantAgent = request->GetWantAgent(); - dataToStub.WriteParcelable(&wantAgent); + request->Marshalling(dataToStub); return SendGnssRequest( static_cast(GnssInterfaceCode::ADD_FENCE_INFO), dataToStub, replyToStub); } @@ -625,15 +617,7 @@ LocationErrCode LocatorAbility::RemoveFence(std::shared_ptr& re if (!dataToStub.WriteInterfaceToken(GnssAbilityProxy::GetDescriptor())) { return ERRCODE_SERVICE_UNAVAILABLE; } - dataToStub.WriteInt32(request->GetScenario()); - auto geofence = request->GetGeofence(); - dataToStub.WriteDouble(geofence->latitude); - dataToStub.WriteDouble(geofence->longitude); - dataToStub.WriteDouble(geofence->radius); - dataToStub.WriteDouble(geofence->expiration); - dataToStub.WriteInt32(static_cast(geofence->coordinateSystemType)); - auto wantAgent = request->GetWantAgent(); - dataToStub.WriteParcelable(&wantAgent); + request->Marshalling(dataToStub); return SendGnssRequest( static_cast(GnssInterfaceCode::REMOVE_FENCE_INFO), dataToStub, replyToStub); } @@ -1344,7 +1328,7 @@ LocationErrCode LocatorAbility::QuerySupportCoordinateSystemType( return ERRCODE_SERVICE_UNAVAILABLE; } auto errCode = SendGnssRequest( - static_cast(GnssInterfaceCode::QUERY_SUPPORT_COORDINATE_SYSTEM_TYPE), + static_cast(GnssInterfaceCode::GET_GEOFENCE_SUPPORT_COORDINATE_SYSTEM_TYPE), dataToStub, replyToStub); if (errCode == ERRCODE_SUCCESS) { int size = replyToStub.ReadInt32(); diff --git a/services/location_locator/locator/source/locator_skeleton.cpp b/services/location_locator/locator/source/locator_skeleton.cpp index fb9b27a5acd84413817589aa949828ae9af5d7e3..897214fdbd47dca9d748b3e9d6a9019a9155d0ba 100644 --- a/services/location_locator/locator/source/locator_skeleton.cpp +++ b/services/location_locator/locator/source/locator_skeleton.cpp @@ -113,7 +113,7 @@ void LocatorAbilityStub::ConstructGnssHandleMap() &LocatorAbilityStub::PreUnregisterNmeaMessageCallbackV9; locatorHandleMap_[LocatorInterfaceCode::ADD_GNSS_GEOFENCE] = &LocatorAbilityStub::PreAddGnssGeofence; locatorHandleMap_[LocatorInterfaceCode::REMOVE_GNSS_GEOFENCE] = &LocatorAbilityStub::PreRemoveGnssGeofence; - locatorHandleMap_[LocatorInterfaceCode::QUERY_SUPPORT_COORDINATE_SYSTEM_TYPE] = + locatorHandleMap_[LocatorInterfaceCode::GET_GEOFENCE_SUPPORT_COORDINATE_SYSTEM_TYPE] = &LocatorAbilityStub::PreQuerySupportCoordinateSystemType; #endif } @@ -654,17 +654,7 @@ int LocatorAbilityStub::DoProcessFenceRequest( reply.WriteInt32(ERRCODE_SERVICE_UNAVAILABLE); return ERRCODE_SERVICE_UNAVAILABLE; } - std::shared_ptr geofence = std::make_shared(); - std::shared_ptr request = std::make_shared(); - request->SetScenario(data.ReadInt32()); - geofence->latitude = data.ReadDouble(); - geofence->longitude = data.ReadDouble(); - geofence->radius = data.ReadDouble(); - geofence->expiration = data.ReadDouble(); - geofence->coordinateSystemType = static_cast(data.ReadInt32()); - request->SetGeofence(geofence); - auto wantAgent = data.ReadParcelable(); - request->SetWantAgent(*wantAgent); + auto request = GeofenceRequest::Unmarshalling(data); if (code == LocatorInterfaceCode::ADD_FENCE) { reply.WriteInt32(locatorAbility->AddFence(request)); } else if (code == LocatorInterfaceCode::REMOVE_FENCE) { diff --git a/test/location_gnss/source/gnss_ability_test.cpp b/test/location_gnss/source/gnss_ability_test.cpp index c429596308f03f60863810daff5dc8b5644cc878..b94f94cea7ab696f7cf594ed4dd184f74970a746 100644 --- a/test/location_gnss/source/gnss_ability_test.cpp +++ b/test/location_gnss/source/gnss_ability_test.cpp @@ -514,11 +514,11 @@ HWTEST_F(GnssAbilityTest, AddFence001, TestSize.Level1) /* * @tc.steps: step1. build geo fence request */ - std::shared_ptr geofence = std::make_shared(); - geofence->latitude = 35.1; - geofence->longitude = 40.2; - geofence->radius = 2.2; - geofence->expiration = 12.2; + GeoFence geofence; + geofence.latitude = 35.1; + geofence.longitude = 40.2; + geofence.radius = 2.2; + geofence.expiration = 12.2; std::shared_ptr request = std::make_shared(); request->SetGeofence(geofence); @@ -543,11 +543,11 @@ HWTEST_F(GnssAbilityTest, RemoveFence001, TestSize.Level1) /* * @tc.steps: step1. build geo fence request */ - std::shared_ptr geofence = std::make_shared(); - geofence->latitude = 35.1; - geofence->longitude = 40.2; - geofence->radius = 2.2; - geofence->expiration = 12.2; + GeoFence geofence; + geofence.latitude = 35.1; + geofence.longitude = 40.2; + geofence.radius = 2.2; + geofence.expiration = 12.2; std::shared_ptr request = std::make_shared(); request->SetGeofence(geofence); diff --git a/test/location_locator/source/location_without_permission_test.cpp b/test/location_locator/source/location_without_permission_test.cpp index 340cae78d83a3e914b2c5cb82458d78c8916462b..fe562a218037223985bc05161dd839900b5513d0 100644 --- a/test/location_locator/source/location_without_permission_test.cpp +++ b/test/location_locator/source/location_without_permission_test.cpp @@ -276,11 +276,11 @@ HWTEST_F(LocationWithoutPermissionTest, LocatorWithoutLocationPermissionV9003, T bool state = false; EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl->IsLocationEnabledV9(state)); #ifdef FEATURE_GNSS_SUPPORT - std::shared_ptr geofence = std::make_shared(); - geofence->latitude = 35.1; - geofence->longitude = 40.2; - geofence->radius = 2.2; - geofence->expiration = 12.2; + GeoFence geofence; + geofence.latitude = 35.1; + geofence.longitude = 40.2; + geofence.radius = 2.2; + geofence.expiration = 12.2; std::shared_ptr fenceRequest = std::make_shared(); fenceRequest->SetGeofence(geofence); if (state) { diff --git a/test/location_locator/source/locator_impl_test.cpp b/test/location_locator/source/locator_impl_test.cpp index 2ab14b9131f6826796dd1117afac672f718fb1d0..ebb750e82f30d8df7ac760b330f47de37596f373 100644 --- a/test/location_locator/source/locator_impl_test.cpp +++ b/test/location_locator/source/locator_impl_test.cpp @@ -305,11 +305,11 @@ HWTEST_F(LocatorImplTest, locatorImplRequestFenceV9, TestSize.Level1) GTEST_LOG_(INFO) << "LocatorImplTest, locatorImplRequestFenceV9, TestSize.Level1"; LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplRequestFenceV9 begin"); - std::shared_ptr geofence = std::make_shared(); - geofence->latitude = 35.1; - geofence->longitude = 40.2; - geofence->radius = 2.2; - geofence->expiration = 12.2; + GeoFence geofence; + geofence.latitude = 35.1; + geofence.longitude = 40.2; + geofence.radius = 2.2; + geofence.expiration = 12.2; std::shared_ptr fenceRequest = std::make_shared(); fenceRequest->SetGeofence(geofence); EXPECT_EQ(ERRCODE_NOT_SUPPORTED, locatorImpl_->AddFenceV9(fenceRequest)); diff --git a/test/location_locator/source/locator_service_test.cpp b/test/location_locator/source/locator_service_test.cpp index 0be5682ceb1f2607ce6dace4d293ad0f2c93d304..2cc712b782328cb6dcb6fc05bc86576771b90343 100644 --- a/test/location_locator/source/locator_service_test.cpp +++ b/test/location_locator/source/locator_service_test.cpp @@ -1661,11 +1661,11 @@ HWTEST_F(LocatorServiceTest, locatorServiceFence001, TestSize.Level1) LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceFence001 begin"); auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); - std::shared_ptr geofence = std::make_shared(); - geofence->latitude = 35.1; - geofence->longitude = 40.2; - geofence->radius = 2.2; - geofence->expiration = 12.2; + GeoFence geofence; + geofence.latitude = 35.1; + geofence.longitude = 40.2; + geofence.radius = 2.2; + geofence.expiration = 12.2; std::shared_ptr fenceRequest = std::make_shared(); fenceRequest->SetGeofence(geofence); // uid pid not match locationhub process