diff --git a/bundle.json b/bundle.json index 24b125bb..8287c1b6 100644 --- a/bundle.json +++ b/bundle.json @@ -54,6 +54,7 @@ "drivers_interface_location_gnss", "drivers_interface_location_geofence", "eventhandler", + "ffrt", "form_fwk", "hdf_core", "hisysevent", @@ -76,14 +77,13 @@ "movement", "device_standby", "time_service" - ], - "third_party": [ - "libuv" ] }, "build": { "group_type": { - "base_group": [], + "base_group": [ + "//base/location/services/utils:lbsresources" + ], "fwk_group": [ "//base/location/frameworks/native/locator_sdk:locator_sdk", "//base/location/frameworks/js/napi:geolocation", @@ -137,6 +137,7 @@ "test": [ "//base/location/test/location_common:unittest", "//base/location/test/location_geocode:unittest", + "//base/location/test/location_geofence:unittest", "//base/location/test/location_gnss:unittest", "//base/location/test/location_locator:unittest", "//base/location/test/location_network:unittest", diff --git a/config.gni b/config.gni index 2c97e33a..0e2d5d78 100644 --- a/config.gni +++ b/config.gni @@ -26,7 +26,6 @@ SAMGR_ROOT_DIR = "//foundation/systemabilitymgr" SECURITY_ROOT_DIR = "//base/security" START_UP_ROOT_DIR = "//base/startup" GOOGLE_TEST_DIR = "//third_party/googletest" -LIB_UV_DIR = "//third_party/libuv" DFX_HILOG_DIR = "//base/hiviewdfx/hilog" ABILITY_RUNTIME = "//foundation/ability/ability_runtime" LOCATION_NATIVE_DIR = "$LOCATION_ROOT_DIR/frameworks/native" diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index e2581a5a..9fd4203b 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022 Huawei Device Co., Ltd. +# Copyright (C) 2022-2024 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -14,6 +14,44 @@ import("//base/location/config.gni") import("//build/ohos.gni") +local_base_sources = [ + "$LOCATION_ROOT_DIR/frameworks/js/napi/source/cached_locations_callback_napi.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/source/country_code_callback_napi.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/source/geofence_napi.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/source/gnss_status_callback_napi.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/source/locating_required_data_callback_napi.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_error_callback_napi.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_gnss_geofence_callback_napi.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_adapter.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_entry.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_errcode.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_event.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_system.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_switch_callback_napi.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/source/locator_callback_napi.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/source/napi_util.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/source/nmea_message_callback_napi.cpp", +] + +if (notification_distributed_notification_service_enable) { + local_notification_sources = [ + "$LOCATION_ROOT_DIR/frameworks/js/napi/notification/src/notification_napi.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/notification/src/notification_napi_convert_content.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/notification/src/notification_napi_convert_liveview.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/notification/src/notification_napi_convert_notification.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/notification/src/notification_napi_convert_request.cpp", + "$LOCATION_ROOT_DIR/frameworks/js/napi/notification/src/notification_napi_utils.cpp", + ] + + notification_external_deps = [ + "ability_base:want", + "ability_runtime:napi_common", + "distributed_notification_service:ans_innerkits", + "image_framework:image", + "relational_store:native_rdb", + ] +} + ohos_shared_library("geolocation") { sanitize = { cfi = true @@ -24,15 +62,11 @@ ohos_shared_library("geolocation") { install_enable = true include_dirs = [ "$LOCATION_ROOT_DIR/frameworks/js/napi/include", + "$LOCATION_ROOT_DIR/frameworks/js/napi/notification/include", "$LOCATION_ROOT_DIR/interfaces/inner_api/include", ] - sources = [ - "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_adapter.cpp", - "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_entry.cpp", - "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_event.cpp", - "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_system.cpp", - ] + sources = local_base_sources deps = [ "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", @@ -41,20 +75,24 @@ ohos_shared_library("geolocation") { ] external_deps = [ - "c_utils:utils", "hilog:libhilog", "ipc:ipc_single", "napi:ace_napi", ] defines = [] + + if (notification_distributed_notification_service_enable) { + sources += local_notification_sources + external_deps += notification_external_deps + defines += [ "NOTIFICATION_ENABLE" ] + } + if (location_feature_with_jsstack) { defines += [ "SUPPORT_JSSTACK" ] external_deps += [ "hiview:libxpower_event_js" ] } - if (notification_distributed_notification_service_enable) { - defines += [ "NOTIFICATION_ENABLE" ] - } + relative_install_dir = "module" part_name = "location" subsystem_name = "location" @@ -70,14 +108,10 @@ ohos_static_library("geolocation_static") { include_dirs = [ "$LOCATION_ROOT_DIR/frameworks/js/napi/include", "$LOCATION_ROOT_DIR/interfaces/inner_api/include", + "$LOCATION_ROOT_DIR/frameworks/js/napi/notification/include", ] - sources = [ - "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_adapter.cpp", - "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_entry.cpp", - "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_event.cpp", - "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_system.cpp", - ] + sources = local_base_sources deps = [ "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", @@ -86,13 +120,16 @@ ohos_static_library("geolocation_static") { ] external_deps = [ - "c_utils:utils", "hilog:libhilog", "ipc:ipc_single", "napi:ace_napi", ] + defines = [] + if (notification_distributed_notification_service_enable) { + sources += local_notification_sources + external_deps += notification_external_deps defines += [ "NOTIFICATION_ENABLE" ] } part_name = "location" @@ -110,15 +147,10 @@ ohos_shared_library("geolocationmanager") { include_dirs = [ "$LOCATION_ROOT_DIR/frameworks/js/napi/include", "$LOCATION_ROOT_DIR/interfaces/inner_api/include", + "$LOCATION_ROOT_DIR/frameworks/js/napi/notification/include", ] - sources = [ - "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_adapter.cpp", - "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_entry.cpp", - "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_errcode.cpp", - "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_event.cpp", - "$LOCATION_ROOT_DIR/frameworks/js/napi/source/location_napi_system.cpp", - ] + sources = local_base_sources deps = [ "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", @@ -129,19 +161,21 @@ ohos_shared_library("geolocationmanager") { defines = [ "ENABLE_NAPI_MANAGER" ] external_deps = [ - "c_utils:utils", "hilog:libhilog", "ipc:ipc_single", "napi:ace_napi", ] + if (notification_distributed_notification_service_enable) { + sources += local_notification_sources + external_deps += notification_external_deps + defines += [ "NOTIFICATION_ENABLE" ] + } + if (location_feature_with_jsstack) { defines += [ "SUPPORT_JSSTACK" ] external_deps += [ "hiview:libxpower_event_js" ] } - if (notification_distributed_notification_service_enable) { - defines += [ "NOTIFICATION_ENABLE" ] - } relative_install_dir = "module" part_name = "location" subsystem_name = "location" diff --git a/interfaces/inner_api/include/cached_locations_callback_host.h b/frameworks/js/napi/include/cached_locations_callback_napi.h similarity index 71% rename from interfaces/inner_api/include/cached_locations_callback_host.h rename to frameworks/js/napi/include/cached_locations_callback_napi.h index e2ac9d7f..1bcfc547 100644 --- a/interfaces/inner_api/include/cached_locations_callback_host.h +++ b/frameworks/js/napi/include/cached_locations_callback_napi.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef CACHED_LOCATIONS_CALLBACK_HOST_H -#define CACHED_LOCATIONS_CALLBACK_HOST_H +#ifndef CACHED_LOCATIONS_CALLBACK_NAPI_H +#define CACHED_LOCATIONS_CALLBACK_NAPI_H #include @@ -30,10 +30,10 @@ namespace OHOS { namespace Location { -class CachedLocationsCallbackHost : public IRemoteStub { +class CachedLocationsCallbackNapi : public IRemoteStub { public: - CachedLocationsCallbackHost(); - virtual ~CachedLocationsCallbackHost(); + CachedLocationsCallbackNapi(); + virtual ~CachedLocationsCallbackNapi(); virtual int OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; bool IsRemoteDied(); @@ -42,6 +42,20 @@ public: void DeleteHandler(); void UvQueueWork(uv_loop_s* loop, uv_work_t* work); + template + bool InitContext(T* context) + { + if (context == nullptr) { + LBSLOGE(CACHED_LOCATIONS_CALLBACK, "context == nullptr."); + return false; + } + context->env = env_; + callbackValid_ = handlerCb_ == nullptr ? false : true; + context->callbackValid = &callbackValid_; + context->callback[SUCCESS_CALLBACK] = handlerCb_; + return true; + } + inline napi_env GetEnv() const { return env_; @@ -77,7 +91,8 @@ private: napi_ref handlerCb_; bool remoteDied_; std::mutex mutex_; + bool callbackValid_; }; } // namespace Location } // namespace OHOS -#endif // CACHED_LOCATIONS_CALLBACK_HOST_H +#endif // CACHED_LOCATIONS_CALLBACK_NAPI_H diff --git a/frameworks/js/napi/include/callback_manager.h b/frameworks/js/napi/include/callback_manager.h index f776ccba..398ad4d3 100644 --- a/frameworks/js/napi/include/callback_manager.h +++ b/frameworks/js/napi/include/callback_manager.h @@ -18,6 +18,7 @@ #include #include "location_napi_errcode.h" + namespace OHOS { namespace Location { template diff --git a/frameworks/js/napi/include/country_code_callback_napi.h b/frameworks/js/napi/include/country_code_callback_napi.h new file mode 100644 index 00000000..7f37db6e --- /dev/null +++ b/frameworks/js/napi/include/country_code_callback_napi.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef COUNTRY_CODE_CALLBACK_NAPI_H +#define COUNTRY_CODE_CALLBACK_NAPI_H + +#include "i_country_code_callback.h" +#include "iremote_stub.h" +#include "napi/native_api.h" +#include "uv.h" +#include "country_code.h" +#include "location_log.h" + +namespace OHOS { +namespace Location { +class CountryCodeCallbackNapi : public IRemoteStub { +public: + CountryCodeCallbackNapi(); + virtual ~CountryCodeCallbackNapi(); + virtual int OnRemoteRequest(uint32_t code, + MessageParcel& data, MessageParcel& reply, MessageOption& option) override; + void OnCountryCodeChange(const std::shared_ptr& country) override; + bool Send(const std::shared_ptr& country); + void SetEnv(napi_env env); + void SetCallback(napi_ref cb); + void DeleteHandler(); + void UvQueueWork(uv_loop_s* loop, uv_work_t* work); + + template + bool InitContext(T* context) + { + if (context == nullptr) { + LBSLOGE(COUNTRY_CODE_CALLBACK, "context == nullptr."); + return false; + } + context->env = env_; + callbackValid_ = handlerCb_ == nullptr ? false : true; + context->callbackValid = &callbackValid_; + context->callback[SUCCESS_CALLBACK] = handlerCb_; + return true; + } +private: + napi_env env_; + napi_ref handlerCb_; + std::mutex mutex_; + bool callbackValid_; +}; +} // namespace Location +} // namespace OHOS +#endif // COUNTRY_CODE_CALLBACK_NAPI_H diff --git a/interfaces/inner_api/include/gnss_status_callback_host.h b/frameworks/js/napi/include/gnss_status_callback_napi.h similarity index 71% rename from interfaces/inner_api/include/gnss_status_callback_host.h rename to frameworks/js/napi/include/gnss_status_callback_napi.h index 03e135e2..dc3417d3 100644 --- a/interfaces/inner_api/include/gnss_status_callback_host.h +++ b/frameworks/js/napi/include/gnss_status_callback_napi.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef GNSS_STATUS_CALLBACK_HOST_H -#define GNSS_STATUS_CALLBACK_HOST_H +#ifndef GNSS_STATUS_CALLBACK_NAPI_H +#define GNSS_STATUS_CALLBACK_NAPI_H #include "iremote_stub.h" #include "message_option.h" @@ -28,10 +28,10 @@ namespace OHOS { namespace Location { -class GnssStatusCallbackHost : public IRemoteStub { +class GnssStatusCallbackNapi : public IRemoteStub { public: - GnssStatusCallbackHost(); - virtual ~GnssStatusCallbackHost(); + GnssStatusCallbackNapi(); + virtual ~GnssStatusCallbackNapi(); virtual int OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; bool IsRemoteDied(); @@ -40,6 +40,20 @@ public: void DeleteHandler(); void UvQueueWork(uv_loop_s* loop, uv_work_t* work); + template + bool InitContext(T* context) + { + if (context == nullptr) { + LBSLOGE(GNSS_STATUS_CALLBACK, "context == nullptr."); + return false; + } + context->env = env_; + callbackValid_ = handlerCb_ == nullptr ? false : true; + context->callbackValid = &callbackValid_; + context->callback[SUCCESS_CALLBACK] = handlerCb_; + return true; + } + inline napi_env GetEnv() const { return env_; @@ -75,7 +89,8 @@ private: napi_ref handlerCb_; bool remoteDied_; std::mutex mutex_; + bool callbackValid_; }; } // namespace Location } // namespace OHOS -#endif // GNSS_STATUS_CALLBACK_HOST_H +#endif // GNSS_STATUS_CALLBACK_NAPI_H diff --git a/interfaces/inner_api/include/locating_required_data_callback_host.h b/frameworks/js/napi/include/locating_required_data_callback_napi.h similarity index 77% rename from interfaces/inner_api/include/locating_required_data_callback_host.h rename to frameworks/js/napi/include/locating_required_data_callback_napi.h index a2e74293..b00b28d7 100644 --- a/interfaces/inner_api/include/locating_required_data_callback_host.h +++ b/frameworks/js/napi/include/locating_required_data_callback_napi.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Huawei Device Co., Ltd. + * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef LOCATING_REQUIRED_DATA_CALLBACK_HOST_H -#define LOCATING_REQUIRED_DATA_CALLBACK_HOST_H +#ifndef LOCATING_REQUIRED_DATA_CALLBACK_NAPI_H +#define LOCATING_REQUIRED_DATA_CALLBACK_NAPI_H #include "i_locating_required_data_callback.h" #include "iremote_stub.h" @@ -26,10 +26,10 @@ namespace OHOS { namespace Location { -class LocatingRequiredDataCallbackHost : public IRemoteStub { +class LocatingRequiredDataCallbackNapi : public IRemoteStub { public: - LocatingRequiredDataCallbackHost(); - virtual ~LocatingRequiredDataCallbackHost(); + LocatingRequiredDataCallbackNapi(); + virtual ~LocatingRequiredDataCallbackNapi(); virtual int OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; bool IsRemoteDied(); @@ -46,6 +46,20 @@ public: void ClearSingleResult(); void SetSingleResult( std::vector> singleResult); + + template + bool InitContext(T* context) + { + if (context == nullptr) { + LBSLOGE(LOCATING_DATA_CALLBACK, "context == nullptr."); + return false; + } + context->env = env_; + callbackValid_ = handlerCb_ == nullptr ? false : true; + context->callbackValid = &callbackValid_; + context->callback[SUCCESS_CALLBACK] = handlerCb_; + return true; + } inline napi_env GetEnv() const { @@ -93,6 +107,7 @@ public: fixNumber_ = fixNumber; } private: + bool callbackValid_; int fixNumber_; napi_env env_; napi_ref handlerCb_; @@ -104,4 +119,4 @@ private: }; } // namespace Location } // namespace OHOS -#endif // LOCATING_REQUIRED_DATA_CALLBACK_HOST_H +#endif // LOCATING_REQUIRED_DATA_CALLBACK_NAPI_H diff --git a/interfaces/inner_api/include/location_error_callback_host.h b/frameworks/js/napi/include/location_error_callback_napi.h similarity index 71% rename from interfaces/inner_api/include/location_error_callback_host.h rename to frameworks/js/napi/include/location_error_callback_napi.h index 0ac52010..ed3320b8 100644 --- a/interfaces/inner_api/include/location_error_callback_host.h +++ b/frameworks/js/napi/include/location_error_callback_napi.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef LOCATION_ERROR_CALLBACK_HOST_H -#define LOCATION_ERROR_CALLBACK_HOST_H +#ifndef LOCATION_ERROR_CALLBACK_NAPI_H +#define LOCATION_ERROR_CALLBACK_NAPI_H #include "iremote_stub.h" #include "napi/native_api.h" #include "uv.h" @@ -26,10 +26,10 @@ namespace OHOS { namespace Location { -class LocationErrorCallbackHost : public IRemoteStub { +class LocationErrorCallbackNapi : public IRemoteStub { public: - LocationErrorCallbackHost(); - virtual ~LocationErrorCallbackHost(); + LocationErrorCallbackNapi(); + virtual ~LocationErrorCallbackNapi(); virtual int OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; void OnLocationReport(const std::unique_ptr& location) override; @@ -40,6 +40,20 @@ public: void DeleteHandler(); void UvQueueWork(uv_loop_s* loop, uv_work_t* work); + template + bool InitContext(T* context) + { + if (context == nullptr) { + LBSLOGE(LOCATION_ERR_CALLBACK, "context == nullptr."); + return false; + } + context->env = env_; + callbackValid_ = handlerCb_ == nullptr ? false : true; + context->callbackValid = &callbackValid_; + context->callback[SUCCESS_CALLBACK] = handlerCb_; + return true; + } + inline napi_env GetEnv() const { return env_; @@ -64,7 +78,8 @@ private: napi_env env_; napi_ref handlerCb_; std::mutex mutex_; + bool callbackValid_; }; } // namespace Location } // namespace OHOS -#endif // LOCATION_SWITCH_CALLBACK_HOST_H +#endif // LOCATION_ERROR_CALLBACK_NAPI_H diff --git a/frameworks/js/napi/include/location_napi_adapter.h b/frameworks/js/napi/include/location_napi_adapter.h index 3faa6efe..d95e07a5 100644 --- a/frameworks/js/napi/include/location_napi_adapter.h +++ b/frameworks/js/napi/include/location_napi_adapter.h @@ -21,7 +21,7 @@ #include "napi_util.h" #include "geofence_request.h" #include "constant_definition.h" -#include "location_gnss_geofence_callback_host.h" +#include "location_gnss_geofence_callback_napi.h" #include "geofence_async_context.h" namespace OHOS { @@ -52,13 +52,13 @@ LocationErrCode CheckLocationSwitchState(); napi_value GetLocatingRequiredData(napi_env env, napi_callback_info info); napi_value AddGnssGeofence(napi_env env, napi_callback_info info); GnssGeofenceAsyncContext* CreateAsyncContextForAddGnssGeofence(const napi_env& env, - std::shared_ptr& request, sptr callback); + std::shared_ptr& request, sptr callback); napi_value RemoveGnssGeofence(napi_env env, napi_callback_info info); 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 AddCallbackToGnssGeofenceCallbackHostMap(int fenceId, sptr callbackHost); void RemoveCallbackToGnssGeofenceCallbackHostMap(int fenceId); -sptr FindCallbackInGnssGeofenceCallbackHostMap(int fenceId); +sptr FindCallbackInGnssGeofenceCallbackHostMap(int fenceId); #endif } // namespace Location } // namespace OHOS diff --git a/frameworks/js/napi/include/location_napi_event.h b/frameworks/js/napi/include/location_napi_event.h index f36e55c1..cc9e00ae 100644 --- a/frameworks/js/napi/include/location_napi_event.h +++ b/frameworks/js/napi/include/location_napi_event.h @@ -16,15 +16,15 @@ #ifndef LOCATION_NAPI_EVENT_H #define LOCATION_NAPI_EVENT_H -#include "cached_locations_callback_host.h" -#include "gnss_status_callback_host.h" -#include "locating_required_data_callback_host.h" -#include "location_switch_callback_host.h" +#include "cached_locations_callback_napi.h" +#include "gnss_status_callback_napi.h" +#include "locating_required_data_callback_napi.h" +#include "location_switch_callback_napi.h" #include "locator.h" -#include "locator_callback_host.h" -#include "nmea_message_callback_host.h" +#include "locator_callback_napi.h" +#include "nmea_message_callback_napi.h" #include "request_config.h" -#include "location_error_callback_host.h" +#include "location_error_callback_napi.h" namespace OHOS { namespace Location { @@ -61,22 +61,22 @@ bool OffLocationErrorCallback(const napi_env& env, const napi_value& handler); #endif void SubscribeLocationServiceState(const napi_env& env, - const napi_ref& handlerRef, sptr& switchCallbackHost); + const napi_ref& handlerRef, sptr& switchCallbackHost); void SubscribeGnssStatus(const napi_env& env, const napi_ref& handlerRef, - sptr& gnssStatusCallbackHost); + sptr& gnssStatusCallbackHost); void SubscribeNmeaMessage(const napi_env& env, const napi_ref& handlerRef, - sptr& nmeaMessageCallbackHost); + sptr& nmeaMessageCallbackHost); void SubscribeLocationChange(const napi_env& env, const napi_value& object, - const napi_ref& handlerRef, sptr& locatorCallbackHost); + const napi_ref& handlerRef, sptr& locatorCallbackHost); void SubscribeCacheLocationChange(const napi_env& env, const napi_value& object, - const napi_ref& handlerRef, sptr& cachedCallbackHost); + const napi_ref& handlerRef, sptr& cachedCallbackHost); void SubscribeFenceStatusChange(const napi_env& env, const napi_value& object, const napi_value& handler); void UnSubscribeLocationChange(sptr& callback); void UnSubscribeFenceStatusChange(const napi_env& env, const napi_value& object, const napi_value& handler); void UnSubscribeCacheLocationChange(sptr& callback); -void UnSubscribeLocationServiceState(sptr& switchCallbackHost); -void UnSubscribeGnssStatus(sptr& gnssStatusCallbackHost); -void UnSubscribeNmeaMessage(sptr& nmeaMessageCallbackHost); +void UnSubscribeLocationServiceState(sptr& switchCallbackHost); +void UnSubscribeGnssStatus(sptr& gnssStatusCallbackHost); +void UnSubscribeNmeaMessage(sptr& nmeaMessageCallbackHost); bool IsCallbackEquals(const napi_env& env, const napi_value& handler, const napi_ref& savedCallback); void GenRequestConfig(const napi_env& env, const napi_value* argv, const size_t& objectArgsNum, std::unique_ptr& requestConfig); @@ -89,28 +89,28 @@ int GetCurrentLocationType(std::unique_ptr& config); #ifdef ENABLE_NAPI_MANAGER LocationErrCode SubscribeLocationServiceStateV9(const napi_env& env, - const napi_ref& handlerRef, sptr& switchCallbackHost); + const napi_ref& handlerRef, sptr& switchCallbackHost); LocationErrCode SubscribeGnssStatusV9(const napi_env& env, const napi_ref& handlerRef, - sptr& gnssStatusCallbackHost); + sptr& gnssStatusCallbackHost); LocationErrCode SubscribeNmeaMessageV9(const napi_env& env, const napi_ref& handlerRef, - sptr& nmeaMessageCallbackHost); + sptr& nmeaMessageCallbackHost); LocationErrCode SubscribeLocationChangeV9(const napi_env& env, const napi_value& object, - const napi_ref& handlerRef, sptr& locatorCallbackHost); + const napi_ref& handlerRef, sptr& locatorCallbackHost); LocationErrCode SubscribeCacheLocationChangeV9(const napi_env& env, const napi_value& object, - const napi_ref& handlerRef, sptr& cachedCallbackHost); + const napi_ref& handlerRef, sptr& cachedCallbackHost); LocationErrCode SubscribeFenceStatusChangeV9(const napi_env& env, const napi_value& object, const napi_value& handler); LocationErrCode SubscribeLocatingRequiredDataChange(const napi_env& env, const napi_value& object, - const napi_ref& handlerRef, sptr& locatingCallbackHost); + const napi_ref& handlerRef, sptr& locatingCallbackHost); LocationErrCode SubscribeLocationError(const napi_env& env, - const napi_ref& handlerRef, sptr& locationErrorCallbackHost); + const napi_ref& handlerRef, sptr& locationErrorCallbackHost); LocationErrCode UnSubscribeLocationChangeV9(sptr& callback); LocationErrCode UnSubscribeFenceStatusChangeV9(const napi_env& env, const napi_value& object, const napi_value& handler); LocationErrCode UnSubscribeCacheLocationChangeV9(sptr& callback); -LocationErrCode UnSubscribeLocationServiceStateV9(sptr& switchCallbackHost); -LocationErrCode UnSubscribeGnssStatusV9(sptr& gnssStatusCallbackHost); -LocationErrCode UnSubscribeNmeaMessageV9(sptr& nmeaMessageCallbackHost); -LocationErrCode UnSubscribeLocatingRequiredDataChange(sptr& callbackHost); +LocationErrCode UnSubscribeLocationServiceStateV9(sptr& switchCallbackHost); +LocationErrCode UnSubscribeGnssStatusV9(sptr& gnssStatusCallbackHost); +LocationErrCode UnSubscribeNmeaMessageV9(sptr& nmeaMessageCallbackHost); +LocationErrCode UnSubscribeLocatingRequiredDataChange(sptr& callbackHost); LocationErrCode UnSubscribeLocationError(sptr& callback); napi_value RequestLocationOnceV9(const napi_env& env, const size_t argc, const napi_value* argv); LocationErrCode CheckLocationSwitchEnable(); diff --git a/interfaces/inner_api/include/location_switch_callback_host.h b/frameworks/js/napi/include/location_switch_callback_napi.h similarity index 70% rename from interfaces/inner_api/include/location_switch_callback_host.h rename to frameworks/js/napi/include/location_switch_callback_napi.h index 2e993461..80ee9d30 100644 --- a/interfaces/inner_api/include/location_switch_callback_host.h +++ b/frameworks/js/napi/include/location_switch_callback_napi.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef LOCATION_SWITCH_CALLBACK_HOST_H -#define LOCATION_SWITCH_CALLBACK_HOST_H +#ifndef LOCATION_SWITCH_CALLBACK_NAPI_H +#define LOCATION_SWITCH_CALLBACK_NAPI_H #include "i_switch_callback.h" #include "iremote_stub.h" @@ -26,10 +26,10 @@ namespace OHOS { namespace Location { -class LocationSwitchCallbackHost : public IRemoteStub { +class LocationSwitchCallbackNapi : public IRemoteStub { public: - LocationSwitchCallbackHost(); - virtual ~LocationSwitchCallbackHost(); + LocationSwitchCallbackNapi(); + virtual ~LocationSwitchCallbackNapi(); virtual int OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; bool IsRemoteDied(); @@ -39,6 +39,20 @@ public: void DeleteHandler(); void UvQueueWork(uv_loop_s* loop, uv_work_t* work); + template + bool InitContext(T* context) + { + if (context == nullptr) { + LBSLOGE(SWITCH_CALLBACK, "context == nullptr."); + return false; + } + context->env = env_; + callbackValid_ = handlerCb_ == nullptr ? false : true; + context->callbackValid = &callbackValid_; + context->callback[SUCCESS_CALLBACK] = handlerCb_; + return true; + } + inline napi_env GetEnv() const { return env_; @@ -74,7 +88,8 @@ private: napi_ref handlerCb_; bool remoteDied_; std::mutex mutex_; + bool callbackValid_; }; } // namespace Location } // namespace OHOS -#endif // LOCATION_SWITCH_CALLBACK_HOST_H +#endif // LOCATION_SWITCH_CALLBACK_NAPI_H diff --git a/interfaces/inner_api/include/locator_callback_host.h b/frameworks/js/napi/include/locator_callback_napi.h similarity index 88% rename from interfaces/inner_api/include/locator_callback_host.h rename to frameworks/js/napi/include/locator_callback_napi.h index 0b1001c5..ca9c02c2 100644 --- a/interfaces/inner_api/include/locator_callback_host.h +++ b/frameworks/js/napi/include/locator_callback_napi.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef LOCATOR_CALLBACK_HOST_H -#define LOCATOR_CALLBACK_HOST_H +#ifndef LOCATOR_CALLBACK_NAPI_H +#define LOCATOR_CALLBACK_NAPI_H #include "iremote_stub.h" #include "napi/native_api.h" @@ -27,10 +27,10 @@ namespace OHOS { namespace Location { -class LocatorCallbackHost : public IRemoteStub { +class LocatorCallbackNapi : public IRemoteStub { public: - LocatorCallbackHost(); - virtual ~LocatorCallbackHost(); + LocatorCallbackNapi(); + virtual ~LocatorCallbackNapi(); virtual int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; void DoSendWork(uv_loop_s *&loop, uv_work_t *&work); @@ -61,13 +61,14 @@ public: return false; } context->env = env_; + callbackValid_ = handlerCb_ == nullptr ? false : true; + context->callbackValid = &callbackValid_; if (IsSystemGeoLocationApi()) { context->callback[SUCCESS_CALLBACK] = successHandlerCb_; context->callback[FAIL_CALLBACK] = failHandlerCb_; context->callback[COMPLETE_CALLBACK] = completeHandlerCb_; } else { context->callback[SUCCESS_CALLBACK] = handlerCb_; - context->deferred = deferred_; } return true; } @@ -132,16 +133,6 @@ public: fixNumber_ = fixNumber; } - inline napi_deferred GetDeferred() const - { - return deferred_; - } - - inline void SetDeferred(const napi_deferred& deferred) - { - deferred_ = deferred; - } - inline void SetLocationPriority(const int locationPriority) { locationPriority_ = locationPriority; @@ -168,13 +159,13 @@ private: napi_ref failHandlerCb_; napi_ref completeHandlerCb_; int fixNumber_; - napi_deferred deferred_; std::mutex mutex_; CountDownLatch* latch_; std::shared_ptr singleLocation_; int locationPriority_; bool inHdArea_; + bool callbackValid_; }; } // namespace Location } // namespace OHOS -#endif // LOCATOR_CALLBACK_HOST_H +#endif // LOCATOR_CALLBACK_NAPI_H diff --git a/interfaces/inner_api/include/napi_util.h b/frameworks/js/napi/include/napi_util.h similarity index 100% rename from interfaces/inner_api/include/napi_util.h rename to frameworks/js/napi/include/napi_util.h diff --git a/interfaces/inner_api/include/nmea_message_callback_host.h b/frameworks/js/napi/include/nmea_message_callback_napi.h similarity index 71% rename from interfaces/inner_api/include/nmea_message_callback_host.h rename to frameworks/js/napi/include/nmea_message_callback_napi.h index e724db0a..07775658 100644 --- a/interfaces/inner_api/include/nmea_message_callback_host.h +++ b/frameworks/js/napi/include/nmea_message_callback_napi.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef NMEA_MESSAGE_CALLBACK_HOST_H -#define NMEA_MESSAGE_CALLBACK_HOST_H +#ifndef NMEA_MESSAGE_CALLBACK_NAPI_H +#define NMEA_MESSAGE_CALLBACK_NAPI_H #include @@ -29,10 +29,10 @@ namespace OHOS { namespace Location { -class NmeaMessageCallbackHost : public IRemoteStub { +class NmeaMessageCallbackNapi : public IRemoteStub { public: - NmeaMessageCallbackHost(); - virtual ~NmeaMessageCallbackHost(); + NmeaMessageCallbackNapi(); + virtual ~NmeaMessageCallbackNapi(); virtual int OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; bool IsRemoteDied(); @@ -42,6 +42,20 @@ public: void DeleteHandler(); void UvQueueWork(uv_loop_s* loop, uv_work_t* work); + template + bool InitContext(T* context) + { + if (context == nullptr) { + LBSLOGE(NMEA_MESSAGE_CALLBACK, "context == nullptr."); + return false; + } + context->env = env_; + callbackValid_ = handlerCb_ == nullptr ? false : true; + context->callbackValid = &callbackValid_; + context->callback[SUCCESS_CALLBACK] = handlerCb_; + return true; + } + inline napi_env GetEnv() const { return env_; @@ -77,7 +91,8 @@ private: napi_ref handlerCb_; bool remoteDied_; std::mutex mutex_; + bool callbackValid_; }; } // namespace Location } // namespace OHOS -#endif // NMEA_MESSAGE_CALLBACK_HOST_H +#endif // NMEA_MESSAGE_CALLBACK_NAPI_H diff --git a/interfaces/inner_api/include/geofence_napi.h b/frameworks/js/napi/notification/include/geofence_napi.h similarity index 97% rename from interfaces/inner_api/include/geofence_napi.h rename to frameworks/js/napi/notification/include/geofence_napi.h index 7c98beb9..7cddd928 100644 --- a/interfaces/inner_api/include/geofence_napi.h +++ b/frameworks/js/napi/notification/include/geofence_napi.h @@ -51,7 +51,7 @@ void GenNotificationRequest(const napi_env& env, const napi_value& elementValue, void GeofenceTransitionToJs(const napi_env& env, const GeofenceTransition geofenceTransition, napi_value& result); void JsObjToGeofenceTransitionCallback(const napi_env& env, const napi_value& object, - sptr callbackHost); + sptr callbackHost); } // namespace Location } // namespace OHOS #endif // GEOFENCE_NAPI_H diff --git a/frameworks/native/notification/include/notification_napi.h b/frameworks/js/napi/notification/include/notification_napi.h similarity index 100% rename from frameworks/native/notification/include/notification_napi.h rename to frameworks/js/napi/notification/include/notification_napi.h diff --git a/frameworks/native/notification/src/notification_napi.cpp b/frameworks/js/napi/notification/src/notification_napi.cpp similarity index 100% rename from frameworks/native/notification/src/notification_napi.cpp rename to frameworks/js/napi/notification/src/notification_napi.cpp diff --git a/frameworks/native/notification/src/notification_napi_convert_content.cpp b/frameworks/js/napi/notification/src/notification_napi_convert_content.cpp similarity index 100% rename from frameworks/native/notification/src/notification_napi_convert_content.cpp rename to frameworks/js/napi/notification/src/notification_napi_convert_content.cpp diff --git a/frameworks/native/notification/src/notification_napi_convert_liveview.cpp b/frameworks/js/napi/notification/src/notification_napi_convert_liveview.cpp similarity index 100% rename from frameworks/native/notification/src/notification_napi_convert_liveview.cpp rename to frameworks/js/napi/notification/src/notification_napi_convert_liveview.cpp diff --git a/frameworks/native/notification/src/notification_napi_convert_notification.cpp b/frameworks/js/napi/notification/src/notification_napi_convert_notification.cpp similarity index 100% rename from frameworks/native/notification/src/notification_napi_convert_notification.cpp rename to frameworks/js/napi/notification/src/notification_napi_convert_notification.cpp diff --git a/frameworks/native/notification/src/notification_napi_convert_request.cpp b/frameworks/js/napi/notification/src/notification_napi_convert_request.cpp similarity index 100% rename from frameworks/native/notification/src/notification_napi_convert_request.cpp rename to frameworks/js/napi/notification/src/notification_napi_convert_request.cpp diff --git a/frameworks/native/notification/src/notification_napi_utils.cpp b/frameworks/js/napi/notification/src/notification_napi_utils.cpp similarity index 100% rename from frameworks/native/notification/src/notification_napi_utils.cpp rename to frameworks/js/napi/notification/src/notification_napi_utils.cpp diff --git a/frameworks/native/locator_sdk/source/cached_locations_callback_host.cpp b/frameworks/js/napi/source/cached_locations_callback_napi.cpp similarity index 79% rename from frameworks/native/locator_sdk/source/cached_locations_callback_host.cpp rename to frameworks/js/napi/source/cached_locations_callback_napi.cpp index eedbf6c4..a2bf146b 100644 --- a/frameworks/native/locator_sdk/source/cached_locations_callback_host.cpp +++ b/frameworks/js/napi/source/cached_locations_callback_napi.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #include "ipc_skeleton.h" #include "napi/native_common.h" @@ -23,21 +23,22 @@ namespace OHOS { namespace Location { -CachedLocationsCallbackHost::CachedLocationsCallbackHost() +CachedLocationsCallbackNapi::CachedLocationsCallbackNapi() { env_ = nullptr; handlerCb_ = nullptr; remoteDied_ = false; + callbackValid_ = false; } -CachedLocationsCallbackHost::~CachedLocationsCallbackHost() +CachedLocationsCallbackNapi::~CachedLocationsCallbackNapi() { } -int CachedLocationsCallbackHost::OnRemoteRequest( +int CachedLocationsCallbackNapi::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { - LBSLOGD(CACHED_LOCATIONS_CALLBACK, "CachedLocationsCallbackHost::OnRemoteRequest!"); + LBSLOGD(CACHED_LOCATIONS_CALLBACK, "CachedLocationsCallbackNapi::OnRemoteRequest!"); if (data.ReadInterfaceToken() != GetDescriptor()) { LBSLOGE(CACHED_LOCATIONS_CALLBACK, "invalid token."); return -1; @@ -67,12 +68,12 @@ int CachedLocationsCallbackHost::OnRemoteRequest( return 0; } -bool CachedLocationsCallbackHost::IsRemoteDied() +bool CachedLocationsCallbackNapi::IsRemoteDied() { return remoteDied_; } -bool CachedLocationsCallbackHost::Send(std::vector>& locations) +bool CachedLocationsCallbackNapi::Send(std::vector>& locations) { std::unique_lock guard(mutex_); uv_loop_s *loop = nullptr; @@ -81,6 +82,10 @@ bool CachedLocationsCallbackHost::Send(std::vector>& l LBSLOGE(CACHED_LOCATIONS_CALLBACK, "loop == nullptr."); return false; } + if (handlerCb_ == nullptr) { + LBSLOGE(CACHED_LOCATIONS_CALLBACK, "handler is nullptr."); + return false; + } uv_work_t *work = new (std::nothrow) uv_work_t; if (work == nullptr) { LBSLOGE(CACHED_LOCATIONS_CALLBACK, "work == nullptr."); @@ -92,8 +97,10 @@ bool CachedLocationsCallbackHost::Send(std::vector>& l delete work; return false; } - context->env = env_; - context->callback[SUCCESS_CALLBACK] = handlerCb_; + if (!InitContext(context)) { + LBSLOGE(CACHED_LOCATIONS_CALLBACK, "InitContext fail"); + return false; + } for (std::unique_ptr& location : locations) { context->locationList.emplace_back(std::move(location)); } @@ -102,7 +109,7 @@ bool CachedLocationsCallbackHost::Send(std::vector>& l return true; } -void CachedLocationsCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) +void CachedLocationsCallbackNapi::UvQueueWork(uv_loop_s* loop, uv_work_t* work) { uv_queue_work( loop, @@ -116,7 +123,7 @@ void CachedLocationsCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) return; } context = static_cast(work->data); - if (context == nullptr || context->env == nullptr) { + if (context == nullptr || context->env == nullptr || context->callbackValid == nullptr) { LBSLOGE(CACHED_LOCATIONS_CALLBACK, "context is nullptr"); delete work; return; @@ -132,7 +139,7 @@ void CachedLocationsCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_create_object(context->env, &jsEvent), scope, context, work); LocationsToJs(context->env, context->locationList, jsEvent); - if (context->callback[0] != nullptr) { + if (context->callback[0] != nullptr && *(context->callbackValid)) { napi_value undefine; napi_value handler = nullptr; CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_get_undefined(context->env, &undefine), @@ -150,27 +157,21 @@ void CachedLocationsCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) }); } -void CachedLocationsCallbackHost::OnCacheLocationsReport(const std::vector>& locations) +void CachedLocationsCallbackNapi::OnCacheLocationsReport(const std::vector>& locations) { - LBSLOGD(CACHED_LOCATIONS_CALLBACK, "CachedLocationsCallbackHost::OnCacheLocationsReport"); + LBSLOGD(CACHED_LOCATIONS_CALLBACK, "CachedLocationsCallbackNapi::OnCacheLocationsReport"); } -void CachedLocationsCallbackHost::DeleteHandler() +void CachedLocationsCallbackNapi::DeleteHandler() { std::unique_lock guard(mutex_); if (handlerCb_ == nullptr || env_ == nullptr) { LBSLOGE(CACHED_LOCATIONS_CALLBACK, "handler or env is nullptr."); return; } - auto context = new (std::nothrow) AsyncContext(env_); - if (context == nullptr) { - LBSLOGE(CACHED_LOCATIONS_CALLBACK, "context == nullptr."); - return; - } - context->env = env_; - context->callback[SUCCESS_CALLBACK] = handlerCb_; - DeleteQueueWork(context); + NAPI_CALL_RETURN_VOID(env_, napi_delete_reference(env_, handlerCb_)); handlerCb_ = nullptr; + callbackValid_ = false; } } // namespace Location } // namespace OHOS diff --git a/frameworks/js/napi/source/country_code_callback_napi.cpp b/frameworks/js/napi/source/country_code_callback_napi.cpp new file mode 100644 index 00000000..dd0c6325 --- /dev/null +++ b/frameworks/js/napi/source/country_code_callback_napi.cpp @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "country_code_callback_napi.h" + +#include "common_utils.h" +#include "ipc_skeleton.h" +#include "location_log.h" +#include "napi/native_api.h" +#include "country_code.h" +#include "napi_util.h" + +namespace OHOS { +namespace Location { +CountryCodeCallbackNapi::CountryCodeCallbackNapi() +{ + env_ = nullptr; + handlerCb_ = nullptr; + callbackValid_ = false; +} + +CountryCodeCallbackNapi::~CountryCodeCallbackNapi() +{ +} + +int CountryCodeCallbackNapi::OnRemoteRequest( + uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) +{ + LBSLOGD(COUNTRY_CODE_CALLBACK, "CountryCodeCallbackNapi::OnRemoteRequest!"); + if (data.ReadInterfaceToken() != GetDescriptor()) { + LBSLOGE(COUNTRY_CODE_CALLBACK, "invalid token."); + return -1; + } + + switch (code) { + case COUNTRY_CODE_CHANGE_EVENT: { + auto countryCodePtr = CountryCode::Unmarshalling(data); + OnCountryCodeChange(countryCodePtr); + break; + } + default: { + IPCObjectStub::OnRemoteRequest(code, data, reply, option); + break; + } + } + return 0; +} + +bool CountryCodeCallbackNapi::Send(const std::shared_ptr& country) +{ + std::unique_lock guard(mutex_); + uv_loop_s *loop = nullptr; + if (env_ == nullptr) { + LBSLOGE(COUNTRY_CODE_CALLBACK, "env_ == nullptr."); + return false; + } + if (handlerCb_ == nullptr) { + LBSLOGE(COUNTRY_CODE_CALLBACK, "handler is nullptr."); + return false; + } + if (country == nullptr) { + LBSLOGE(COUNTRY_CODE_CALLBACK, "country == nullptr."); + return false; + } + NAPI_CALL_BASE(env_, napi_get_uv_event_loop(env_, &loop), false); + if (loop == nullptr) { + LBSLOGE(COUNTRY_CODE_CALLBACK, "loop == nullptr."); + return false; + } + uv_work_t *work = new (std::nothrow) uv_work_t; + if (work == nullptr) { + LBSLOGE(COUNTRY_CODE_CALLBACK, "work == nullptr."); + return false; + } + auto context = new (std::nothrow) CountryCodeContext(env_); + if (context == nullptr) { + LBSLOGE(COUNTRY_CODE_CALLBACK, "context == nullptr."); + delete work; + return false; + } + if (!InitContext(context)) { + LBSLOGE(COUNTRY_CODE_CALLBACK, "InitContext fail"); + return false; + } + context->country = country; + work->data = context; + UvQueueWork(loop, work); + return true; +} + +void CountryCodeCallbackNapi::UvQueueWork(uv_loop_s* loop, uv_work_t* work) +{ + uv_queue_work( + loop, + work, + [](uv_work_t *work) {}, + [](uv_work_t *work, int status) { + CountryCodeContext *context = nullptr; + napi_handle_scope scope = nullptr; + if (work == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "work is nullptr!"); + return; + } + context = static_cast(work->data); + if (context == nullptr || context->env == nullptr || context->callbackValid == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "context is nullptr!"); + delete work; + return; + } + NAPI_CALL_RETURN_VOID(context->env, napi_open_handle_scope(context->env, &scope)); + if (scope == nullptr) { + LBSLOGE(COUNTRY_CODE_CALLBACK, "scope is nullptr"); + delete context; + delete work; + return; + } + napi_value jsEvent; + CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_create_object(context->env, &jsEvent), + scope, context, work); + if (context->country) { + CountryCodeToJs(context->env, context->country, jsEvent); + } else { + LBSLOGE(LOCATOR_STANDARD, "country is nullptr!"); + } + if (context->callback[0] != nullptr && *(context->callbackValid)) { + napi_value undefine; + napi_value handler = nullptr; + CHK_NAPI_ERR_CLOSE_SCOPE(context->env, + napi_get_undefined(context->env, &undefine), scope, context, work); + CHK_NAPI_ERR_CLOSE_SCOPE(context->env, + napi_get_reference_value(context->env, context->callback[SUCCESS_CALLBACK], &handler), + scope, context, work); + if (napi_call_function(context->env, nullptr, handler, 1, &jsEvent, &undefine) != napi_ok) { + LBSLOGE(COUNTRY_CODE_CALLBACK, "Report event failed"); + } + } + NAPI_CALL_RETURN_VOID(context->env, napi_close_handle_scope(context->env, scope)); + delete context; + delete work; + }); +} + +void CountryCodeCallbackNapi::OnCountryCodeChange(const std::shared_ptr& country) +{ + LBSLOGD(COUNTRY_CODE_CALLBACK, "CountryCodeCallbackNapi::OnCountryCodeChange"); + Send(country); +} + +void CountryCodeCallbackNapi::SetEnv(napi_env env) +{ + std::unique_lock guard(mutex_); + env_ = env; +} + +void CountryCodeCallbackNapi::SetCallback(napi_ref cb) +{ + std::unique_lock guard(mutex_); + handlerCb_ = cb; +} + +void CountryCodeCallbackNapi::DeleteHandler() +{ + std::unique_lock guard(mutex_); + if (handlerCb_ == nullptr || env_ == nullptr) { + LBSLOGE(COUNTRY_CODE_CALLBACK, "handler or env is nullptr."); + return; + } + NAPI_CALL_RETURN_VOID(env_, napi_delete_reference(env_, handlerCb_)); + handlerCb_ = nullptr; + callbackValid_ = false; +} +} // namespace Location +} // namespace OHOS diff --git a/frameworks/native/geofence_sdk/source/geofence_napi.cpp b/frameworks/js/napi/source/geofence_napi.cpp similarity index 99% rename from frameworks/native/geofence_sdk/source/geofence_napi.cpp rename to frameworks/js/napi/source/geofence_napi.cpp index 74f9ab0d..3ba6cf5f 100644 --- a/frameworks/native/geofence_sdk/source/geofence_napi.cpp +++ b/frameworks/js/napi/source/geofence_napi.cpp @@ -65,7 +65,7 @@ bool GenGnssGeofenceRequest( } void JsObjToGeofenceTransitionCallback(const napi_env& env, const napi_value& object, - sptr callbackHost) + sptr callbackHost) { napi_ref handlerRef = nullptr; napi_value callbackNapiValue = nullptr; diff --git a/frameworks/native/locator_sdk/source/gnss_status_callback_host.cpp b/frameworks/js/napi/source/gnss_status_callback_napi.cpp similarity index 80% rename from frameworks/native/locator_sdk/source/gnss_status_callback_host.cpp rename to frameworks/js/napi/source/gnss_status_callback_napi.cpp index 0bf97fea..bdd36943 100644 --- a/frameworks/native/locator_sdk/source/gnss_status_callback_host.cpp +++ b/frameworks/js/napi/source/gnss_status_callback_napi.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #include "napi/native_common.h" @@ -25,21 +25,22 @@ namespace OHOS { namespace Location { -GnssStatusCallbackHost::GnssStatusCallbackHost() +GnssStatusCallbackNapi::GnssStatusCallbackNapi() { env_ = nullptr; handlerCb_ = nullptr; remoteDied_ = false; + callbackValid_ = false; } -GnssStatusCallbackHost::~GnssStatusCallbackHost() +GnssStatusCallbackNapi::~GnssStatusCallbackNapi() { } -int GnssStatusCallbackHost::OnRemoteRequest( +int GnssStatusCallbackNapi::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { - LBSLOGD(GNSS_STATUS_CALLBACK, "GnssStatusCallbackHost::OnRemoteRequest!"); + LBSLOGD(GNSS_STATUS_CALLBACK, "GnssStatusCallbackNapi::OnRemoteRequest!"); if (data.ReadInterfaceToken() != GetDescriptor()) { LBSLOGE(GNSS_STATUS_CALLBACK, "invalid token."); return -1; @@ -63,12 +64,12 @@ int GnssStatusCallbackHost::OnRemoteRequest( return 0; } -bool GnssStatusCallbackHost::IsRemoteDied() +bool GnssStatusCallbackNapi::IsRemoteDied() { return remoteDied_; } -bool GnssStatusCallbackHost::Send(std::unique_ptr& statusInfo) +bool GnssStatusCallbackNapi::Send(std::unique_ptr& statusInfo) { std::unique_lock guard(mutex_); uv_loop_s *loop = nullptr; @@ -77,6 +78,10 @@ bool GnssStatusCallbackHost::Send(std::unique_ptr& statusInfo) LBSLOGE(GNSS_STATUS_CALLBACK, "loop == nullptr."); return false; } + if (handlerCb_ == nullptr) { + LBSLOGE(GNSS_STATUS_CALLBACK, "handler is nullptr."); + return false; + } uv_work_t *work = new (std::nothrow) uv_work_t; if (work == nullptr) { LBSLOGE(GNSS_STATUS_CALLBACK, "work == nullptr."); @@ -88,15 +93,17 @@ bool GnssStatusCallbackHost::Send(std::unique_ptr& statusInfo) delete work; return false; } - context->env = env_; - context->callback[SUCCESS_CALLBACK] = handlerCb_; + if (!InitContext(context)) { + LBSLOGE(GNSS_STATUS_CALLBACK, "InitContext fail"); + return false; + } context->statusInfo = std::move(statusInfo); work->data = context; UvQueueWork(loop, work); return true; } -void GnssStatusCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) +void GnssStatusCallbackNapi::UvQueueWork(uv_loop_s* loop, uv_work_t* work) { uv_queue_work( loop, @@ -110,7 +117,7 @@ void GnssStatusCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) return; } context = static_cast(work->data); - if (context == nullptr || context->env == nullptr) { + if (context == nullptr || context->env == nullptr || context->callbackValid == nullptr) { LBSLOGE(LOCATOR_CALLBACK, "context is nullptr!"); delete work; return; @@ -128,7 +135,7 @@ void GnssStatusCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) scope, context, work); SatelliteStatusToJs(context->env, context->statusInfo, jsEvent); } - if (context->callback[0] != nullptr) { + if (context->callback[0] != nullptr && *(context->callbackValid)) { napi_value undefine; napi_value handler = nullptr; CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_get_undefined(context->env, &undefine), @@ -146,27 +153,21 @@ void GnssStatusCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) }); } -void GnssStatusCallbackHost::OnStatusChange(const std::unique_ptr& statusInfo) +void GnssStatusCallbackNapi::OnStatusChange(const std::unique_ptr& statusInfo) { - LBSLOGD(GNSS_STATUS_CALLBACK, "GnssStatusCallbackHost::OnStatusChange"); + LBSLOGD(GNSS_STATUS_CALLBACK, "GnssStatusCallbackNapi::OnStatusChange"); } -void GnssStatusCallbackHost::DeleteHandler() +void GnssStatusCallbackNapi::DeleteHandler() { std::unique_lock guard(mutex_); if (handlerCb_ == nullptr || env_ == nullptr) { LBSLOGE(GNSS_STATUS_CALLBACK, "handler or env is nullptr."); return; } - auto context = new (std::nothrow) AsyncContext(env_); - if (context == nullptr) { - LBSLOGE(GNSS_STATUS_CALLBACK, "context == nullptr."); - return; - } - context->env = env_; - context->callback[SUCCESS_CALLBACK] = handlerCb_; - DeleteQueueWork(context); + NAPI_CALL_RETURN_VOID(env_, napi_delete_reference(env_, handlerCb_)); handlerCb_ = nullptr; + callbackValid_ = false; } } // namespace Location } // namespace OHOS diff --git a/frameworks/native/locator_sdk/source/locating_required_data_callback_host.cpp b/frameworks/js/napi/source/locating_required_data_callback_napi.cpp similarity index 79% rename from frameworks/native/locator_sdk/source/locating_required_data_callback_host.cpp rename to frameworks/js/napi/source/locating_required_data_callback_napi.cpp index fb8fe27e..f19692ea 100644 --- a/frameworks/native/locator_sdk/source/locating_required_data_callback_host.cpp +++ b/frameworks/js/napi/source/locating_required_data_callback_napi.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Huawei Device Co., Ltd. + * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "locating_required_data_callback_host.h" +#include "locating_required_data_callback_napi.h" #include "ipc_skeleton.h" #include "napi/native_common.h" @@ -23,16 +23,17 @@ namespace OHOS { namespace Location { -LocatingRequiredDataCallbackHost::LocatingRequiredDataCallbackHost() +LocatingRequiredDataCallbackNapi::LocatingRequiredDataCallbackNapi() { env_ = nullptr; handlerCb_ = nullptr; remoteDied_ = false; fixNumber_ = 0; InitLatch(); + callbackValid_ = false; } -LocatingRequiredDataCallbackHost::~LocatingRequiredDataCallbackHost() +LocatingRequiredDataCallbackNapi::~LocatingRequiredDataCallbackNapi() { if (latch_ != nullptr) { delete latch_; @@ -40,16 +41,16 @@ LocatingRequiredDataCallbackHost::~LocatingRequiredDataCallbackHost() } } -void LocatingRequiredDataCallbackHost::InitLatch() +void LocatingRequiredDataCallbackNapi::InitLatch() { latch_ = new CountDownLatch(); latch_->SetCount(1); } -int LocatingRequiredDataCallbackHost::OnRemoteRequest( +int LocatingRequiredDataCallbackNapi::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { - LBSLOGD(LOCATING_DATA_CALLBACK, "LocatingRequiredDataCallbackHost::OnRemoteRequest!"); + LBSLOGD(LOCATING_DATA_CALLBACK, "LocatingRequiredDataCallbackNapi::OnRemoteRequest!"); if (data.ReadInterfaceToken() != GetDescriptor()) { LBSLOGE(LOCATING_DATA_CALLBACK, "invalid token."); return -1; @@ -84,12 +85,12 @@ int LocatingRequiredDataCallbackHost::OnRemoteRequest( return 0; } -bool LocatingRequiredDataCallbackHost::IsRemoteDied() +bool LocatingRequiredDataCallbackNapi::IsRemoteDied() { return remoteDied_; } -bool LocatingRequiredDataCallbackHost::Send(const std::vector>& data) +bool LocatingRequiredDataCallbackNapi::Send(const std::vector>& data) { if (IsSingleLocationRequest()) { return false; @@ -101,6 +102,10 @@ bool LocatingRequiredDataCallbackHost::Send(const std::vectorenv = env_; - context->callback[SUCCESS_CALLBACK] = handlerCb_; + if (!InitContext(context)) { + LBSLOGE(LOCATING_DATA_CALLBACK, "InitContext fail"); + return false; + } context->locatingRequiredDataList_ = data; work->data = context; UvQueueWork(loop, work); return true; } -void LocatingRequiredDataCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) +void LocatingRequiredDataCallbackNapi::UvQueueWork(uv_loop_s* loop, uv_work_t* work) { uv_queue_work( loop, @@ -134,7 +141,7 @@ void LocatingRequiredDataCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* w return; } context = static_cast(work->data); - if (context == nullptr || context->env == nullptr) { + if (context == nullptr || context->env == nullptr || context->callbackValid == nullptr) { LBSLOGE(LOCATING_DATA_CALLBACK, "context is nullptr"); delete work; return; @@ -151,7 +158,7 @@ void LocatingRequiredDataCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* w napi_create_array_with_length(context->env, context->locatingRequiredDataList_.size(), &jsEvent), scope, context, work); LocatingRequiredDataToJsObj(context->env, context->locatingRequiredDataList_, jsEvent); - if (context->callback[0] != nullptr) { + if (context->callback[0] != nullptr && *(context->callbackValid)) { napi_value undefine; napi_value handler = nullptr; CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_get_undefined(context->env, &undefine), @@ -169,51 +176,45 @@ void LocatingRequiredDataCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* w }); } -void LocatingRequiredDataCallbackHost::OnLocatingDataChange( +void LocatingRequiredDataCallbackNapi::OnLocatingDataChange( const std::vector>& data) { - LBSLOGD(LOCATING_DATA_CALLBACK, "LocatingRequiredDataCallbackHost::OnLocatingDataChange"); + LBSLOGD(LOCATING_DATA_CALLBACK, "LocatingRequiredDataCallbackNapi::OnLocatingDataChange"); Send(data); } -void LocatingRequiredDataCallbackHost::DeleteHandler() +void LocatingRequiredDataCallbackNapi::DeleteHandler() { std::unique_lock guard(mutex_); if (handlerCb_ == nullptr || env_ == nullptr) { LBSLOGE(LOCATING_DATA_CALLBACK, "handler or env is nullptr."); return; } - auto context = new (std::nothrow) AsyncContext(env_); - if (context == nullptr) { - LBSLOGE(LOCATING_DATA_CALLBACK, "context == nullptr."); - return; - } - context->env = env_; - context->callback[SUCCESS_CALLBACK] = handlerCb_; - DeleteQueueWork(context); + NAPI_CALL_RETURN_VOID(env_, napi_delete_reference(env_, handlerCb_)); handlerCb_ = nullptr; + callbackValid_ = false; } -bool LocatingRequiredDataCallbackHost::IsSingleLocationRequest() +bool LocatingRequiredDataCallbackNapi::IsSingleLocationRequest() { return (fixNumber_ == 1); } -void LocatingRequiredDataCallbackHost::CountDown() +void LocatingRequiredDataCallbackNapi::CountDown() { if (IsSingleLocationRequest() && latch_ != nullptr) { latch_->CountDown(); } } -void LocatingRequiredDataCallbackHost::Wait(int time) +void LocatingRequiredDataCallbackNapi::Wait(int time) { if (IsSingleLocationRequest() && latch_ != nullptr) { latch_->Wait(time); } } -int LocatingRequiredDataCallbackHost::GetCount() +int LocatingRequiredDataCallbackNapi::GetCount() { if (IsSingleLocationRequest() && latch_ != nullptr) { return latch_->GetCount(); @@ -221,20 +222,20 @@ int LocatingRequiredDataCallbackHost::GetCount() return 0; } -void LocatingRequiredDataCallbackHost::SetCount(int count) +void LocatingRequiredDataCallbackNapi::SetCount(int count) { if (IsSingleLocationRequest() && latch_ != nullptr) { return latch_->SetCount(count); } } -void LocatingRequiredDataCallbackHost::ClearSingleResult() +void LocatingRequiredDataCallbackNapi::ClearSingleResult() { std::unique_lock guard(singleResultMutex_); singleResult_.clear(); } -void LocatingRequiredDataCallbackHost::SetSingleResult( +void LocatingRequiredDataCallbackNapi::SetSingleResult( std::vector> singleResult) { std::unique_lock guard(singleResultMutex_); diff --git a/frameworks/native/locator_sdk/source/location_error_callback_host.cpp b/frameworks/js/napi/source/location_error_callback_napi.cpp similarity index 65% rename from frameworks/native/locator_sdk/source/location_error_callback_host.cpp rename to frameworks/js/napi/source/location_error_callback_napi.cpp index 55eaca94..0b81b6a5 100644 --- a/frameworks/native/locator_sdk/source/location_error_callback_host.cpp +++ b/frameworks/js/napi/source/location_error_callback_napi.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "location_error_callback_host.h" +#include "location_error_callback_napi.h" #include "common_utils.h" #include "ipc_skeleton.h" #include "location_log.h" @@ -23,22 +23,23 @@ namespace OHOS { namespace Location { -LocationErrorCallbackHost::LocationErrorCallbackHost() +LocationErrorCallbackNapi::LocationErrorCallbackNapi() { env_ = nullptr; handlerCb_ = nullptr; + callbackValid_ = false; } -LocationErrorCallbackHost::~LocationErrorCallbackHost() +LocationErrorCallbackNapi::~LocationErrorCallbackNapi() { } -int LocationErrorCallbackHost::OnRemoteRequest( +int LocationErrorCallbackNapi::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { - LBSLOGI(LOCATOR_CALLBACK, "LocatorCallbackHost::OnRemoteRequest! code = %{public}d", code); + LBSLOGI(LOCATION_ERR_CALLBACK, "LocatorCallbackHost::OnRemoteRequest! code = %{public}d", code); if (data.ReadInterfaceToken() != GetDescriptor()) { - LBSLOGE(LOCATOR_CALLBACK, "invalid token."); + LBSLOGE(LOCATION_ERR_CALLBACK, "invalid token."); return -1; } @@ -55,36 +56,42 @@ int LocationErrorCallbackHost::OnRemoteRequest( return 0; } -bool LocationErrorCallbackHost::Send(int32_t errorCode) +bool LocationErrorCallbackNapi::Send(int32_t errorCode) { - LBSLOGI(LOCATOR_CALLBACK, "LocatorCallbackHost::OnRemoteRequest! errorCode = %{public}d", errorCode); + LBSLOGI(LOCATION_ERR_CALLBACK, "LocatorCallbackNapi::OnRemoteRequest! errorCode = %{public}d", errorCode); std::unique_lock guard(mutex_); uv_loop_s *loop = nullptr; NAPI_CALL_BASE(env_, napi_get_uv_event_loop(env_, &loop), false); if (loop == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "loop == nullptr."); + LBSLOGE(LOCATION_ERR_CALLBACK, "loop == nullptr."); + return false; + } + if (handlerCb_ == nullptr) { + LBSLOGE(LOCATION_ERR_CALLBACK, "handler is nullptr."); return false; } uv_work_t *work = new (std::nothrow) uv_work_t; if (work == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "work == nullptr."); + LBSLOGE(LOCATION_ERR_CALLBACK, "work == nullptr."); return false; } LocationErrorAsyncContext *context = new (std::nothrow) LocationErrorAsyncContext(env_); if (context == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "context == nullptr."); + LBSLOGE(LOCATION_ERR_CALLBACK, "context == nullptr."); delete work; return false; } - context->env = env_; - context->callback[SUCCESS_CALLBACK] = handlerCb_; + if (!InitContext(context)) { + LBSLOGE(LOCATION_ERR_CALLBACK, "InitContext fail"); + return false; + } context->errCode = errorCode; work->data = context; UvQueueWork(loop, work); return true; } -void LocationErrorCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) +void LocationErrorCallbackNapi::UvQueueWork(uv_loop_s* loop, uv_work_t* work) { uv_queue_work( loop, @@ -94,12 +101,12 @@ void LocationErrorCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) LocationErrorAsyncContext *context = nullptr; napi_handle_scope scope = nullptr; if (work == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "work is nullptr!"); + LBSLOGE(LOCATION_ERR_CALLBACK, "work is nullptr!"); return; } context = static_cast(work->data); - if (context == nullptr || context->env == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "context is nullptr!"); + if (context == nullptr || context->env == nullptr || context->callbackValid == nullptr) { + LBSLOGE(LOCATION_ERR_CALLBACK, "context is nullptr!"); delete work; return; } @@ -108,12 +115,12 @@ void LocationErrorCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_create_int32(context->env, context->errCode, &jsEvent), scope, context, work); if (scope == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "scope is nullptr"); + LBSLOGE(LOCATION_ERR_CALLBACK, "scope is nullptr"); delete context; delete work; return; } - if (context->callback[0] != nullptr) { + if (context->callback[0] != nullptr && *(context->callbackValid)) { napi_value undefine; napi_value handler = nullptr; CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_get_undefined(context->env, &undefine), @@ -122,7 +129,7 @@ void LocationErrorCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) napi_get_reference_value(context->env, context->callback[0], &handler), scope, context, work); if (napi_call_function(context->env, nullptr, handler, 1, &jsEvent, &undefine) != napi_ok) { - LBSLOGE(LOCATOR_CALLBACK, "Report event failed"); + LBSLOGE(LOCATION_ERR_CALLBACK, "Report event failed"); } } NAPI_CALL_RETURN_VOID(context->env, napi_close_handle_scope(context->env, scope)); @@ -131,36 +138,30 @@ void LocationErrorCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) }); } -void LocationErrorCallbackHost::OnLocationReport(const std::unique_ptr& location) +void LocationErrorCallbackNapi::OnLocationReport(const std::unique_ptr& location) { } -void LocationErrorCallbackHost::OnLocatingStatusChange(const int status) +void LocationErrorCallbackNapi::OnLocatingStatusChange(const int status) { } -void LocationErrorCallbackHost::OnErrorReport(const int errorCode) +void LocationErrorCallbackNapi::OnErrorReport(const int errorCode) { - LBSLOGI(LOCATOR_CALLBACK, "LocatorCallbackHost::OnRemoteRequest! errorCode = %{public}d", errorCode); + LBSLOGI(LOCATION_ERR_CALLBACK, "LocatorCallbackNapi::OnRemoteRequest! errorCode = %{public}d", errorCode); Send(errorCode); } -void LocationErrorCallbackHost::DeleteHandler() +void LocationErrorCallbackNapi::DeleteHandler() { std::unique_lock guard(mutex_); if (handlerCb_ == nullptr || env_ == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "handler or env is nullptr."); + LBSLOGE(LOCATION_ERR_CALLBACK, "handler or env is nullptr."); return; } - auto context = new (std::nothrow) AsyncContext(env_); - if (context == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "context == nullptr."); - return; - } - context->env = env_; - context->callback[SUCCESS_CALLBACK] = handlerCb_; - DeleteQueueWork(context); + NAPI_CALL_RETURN_VOID(env_, napi_delete_reference(env_, handlerCb_)); handlerCb_ = nullptr; + callbackValid_ = false; } } // namespace Location } // namespace OHOS diff --git a/frameworks/native/geofence_sdk/source/location_gnss_geofence_callback_host.cpp b/frameworks/js/napi/source/location_gnss_geofence_callback_napi.cpp similarity index 82% rename from frameworks/native/geofence_sdk/source/location_gnss_geofence_callback_host.cpp rename to frameworks/js/napi/source/location_gnss_geofence_callback_napi.cpp index 83e8443d..cb9a02d0 100644 --- a/frameworks/native/geofence_sdk/source/location_gnss_geofence_callback_host.cpp +++ b/frameworks/js/napi/source/location_gnss_geofence_callback_napi.cpp @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "location_gnss_geofence_callback_host.h" +#include "location_gnss_geofence_callback_napi.h" #include "ipc_skeleton.h" #include "napi/native_common.h" @@ -26,7 +26,7 @@ namespace OHOS { namespace Location { -LocationGnssGeofenceCallbackHost::LocationGnssGeofenceCallbackHost() +LocationGnssGeofenceCallbackNapi::LocationGnssGeofenceCallbackNapi() { env_ = nullptr; handlerCb_ = nullptr; @@ -34,10 +34,11 @@ LocationGnssGeofenceCallbackHost::LocationGnssGeofenceCallbackHost() fenceId_ = -1; type_ = GNSS_GEOFENCE_OPT_TYPE_ADD; result_ = GNSS_GEOFENCE_OPERATION_SUCCESS; + callbackValid_ = false; InitLatch(); } -LocationGnssGeofenceCallbackHost::~LocationGnssGeofenceCallbackHost() +LocationGnssGeofenceCallbackNapi::~LocationGnssGeofenceCallbackNapi() { if (latch_ != nullptr) { delete latch_; @@ -45,13 +46,13 @@ LocationGnssGeofenceCallbackHost::~LocationGnssGeofenceCallbackHost() } } -void LocationGnssGeofenceCallbackHost::InitLatch() +void LocationGnssGeofenceCallbackNapi::InitLatch() { latch_ = new CountDownLatch(); latch_->SetCount(1); } -int LocationGnssGeofenceCallbackHost::OnRemoteRequest( +int LocationGnssGeofenceCallbackNapi::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { LBSLOGD(LOCATION_GNSS_GEOFENCE_CALLBACK, "OnRemoteRequest enter"); @@ -88,7 +89,7 @@ int LocationGnssGeofenceCallbackHost::OnRemoteRequest( return 0; } -void LocationGnssGeofenceCallbackHost::OnTransitionStatusChange( +void LocationGnssGeofenceCallbackNapi::OnTransitionStatusChange( GeofenceTransition transition) { std::unique_lock guard(mutex_); @@ -98,6 +99,10 @@ void LocationGnssGeofenceCallbackHost::OnTransitionStatusChange( LBSLOGE(LOCATION_GNSS_GEOFENCE_CALLBACK, "loop == nullptr."); return; } + if (handlerCb_ == nullptr) { + LBSLOGE(LOCATION_GNSS_GEOFENCE_CALLBACK, "handler is nullptr."); + return; + } uv_work_t *work = new (std::nothrow) uv_work_t; if (work == nullptr) { LBSLOGE(LOCATION_GNSS_GEOFENCE_CALLBACK, "work == nullptr."); @@ -109,14 +114,16 @@ void LocationGnssGeofenceCallbackHost::OnTransitionStatusChange( delete work; return; } - context->env = env_; - context->callback[SUCCESS_CALLBACK] = handlerCb_; + if (!InitContext(context)) { + LBSLOGE(LOCATION_GNSS_GEOFENCE_CALLBACK, "InitContext fail"); + return; + } context->transition_ = transition; work->data = context; UvQueueWork(loop, work); } -void LocationGnssGeofenceCallbackHost::OnReportOperationResult(int fenceId, int type, int result) +void LocationGnssGeofenceCallbackNapi::OnReportOperationResult(int fenceId, int type, int result) { int addValue = static_cast(GnssGeofenceOperateType::GNSS_GEOFENCE_OPT_TYPE_ADD); if ((type != addValue && fenceId == GetFenceId()) || @@ -132,12 +139,12 @@ void LocationGnssGeofenceCallbackHost::OnReportOperationResult(int fenceId, int } } -bool LocationGnssGeofenceCallbackHost::IsRemoteDied() +bool LocationGnssGeofenceCallbackNapi::IsRemoteDied() { return remoteDied_; } -void LocationGnssGeofenceCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) +void LocationGnssGeofenceCallbackNapi::UvQueueWork(uv_loop_s* loop, uv_work_t* work) { uv_queue_work( loop, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { @@ -148,7 +155,7 @@ void LocationGnssGeofenceCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* w return; } context = static_cast(work->data); - if (context == nullptr || context->env == nullptr) { + if (context == nullptr || context->env == nullptr || context->callbackValid == nullptr) { LBSLOGE(LOCATION_GNSS_GEOFENCE_CALLBACK, "context is nullptr"); delete work; return; @@ -166,7 +173,7 @@ void LocationGnssGeofenceCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* w 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) { + if (context->callback[SUCCESS_CALLBACK] != nullptr && *(context->callbackValid)) { napi_value undefine; napi_value handler = nullptr; CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_get_undefined(context->env, &undefine), @@ -185,39 +192,33 @@ void LocationGnssGeofenceCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* w }); } -void LocationGnssGeofenceCallbackHost::DeleteHandler() +void LocationGnssGeofenceCallbackNapi::DeleteHandler() { std::unique_lock guard(mutex_); if (handlerCb_ == nullptr || env_ == nullptr) { LBSLOGE(LOCATION_GNSS_GEOFENCE_CALLBACK, "handler or env is nullptr."); return; } - auto context = new (std::nothrow) AsyncContext(env_); - if (context == nullptr) { - LBSLOGE(LOCATION_GNSS_GEOFENCE_CALLBACK, "context == nullptr."); - return; - } - context->env = env_; - context->callback[SUCCESS_CALLBACK] = handlerCb_; - DeleteQueueWork(context); + NAPI_CALL_RETURN_VOID(env_, napi_delete_reference(env_, handlerCb_)); handlerCb_ = nullptr; + callbackValid_ = false; } -void LocationGnssGeofenceCallbackHost::CountDown() +void LocationGnssGeofenceCallbackNapi::CountDown() { if (latch_ != nullptr) { latch_->CountDown(); } } -void LocationGnssGeofenceCallbackHost::Wait(int time) +void LocationGnssGeofenceCallbackNapi::Wait(int time) { if (latch_ != nullptr) { latch_->Wait(time); } } -int LocationGnssGeofenceCallbackHost::GetCount() +int LocationGnssGeofenceCallbackNapi::GetCount() { if (latch_ != nullptr) { return latch_->GetCount(); @@ -225,56 +226,56 @@ int LocationGnssGeofenceCallbackHost::GetCount() return 0; } -void LocationGnssGeofenceCallbackHost::SetCount(int count) +void LocationGnssGeofenceCallbackNapi::SetCount(int count) { if (latch_ != nullptr) { return latch_->SetCount(count); } } -void LocationGnssGeofenceCallbackHost::ClearFenceId() +void LocationGnssGeofenceCallbackNapi::ClearFenceId() { std::unique_lock guard(operationResultMutex_); fenceId_ = -1; } -int LocationGnssGeofenceCallbackHost::GetFenceId() +int LocationGnssGeofenceCallbackNapi::GetFenceId() { std::unique_lock guard(operationResultMutex_); return fenceId_; } -void LocationGnssGeofenceCallbackHost::SetFenceId(int fenceId) +void LocationGnssGeofenceCallbackNapi::SetFenceId(int fenceId) { std::unique_lock guard(operationResultMutex_); fenceId_ = fenceId; } -GnssGeofenceOperateType LocationGnssGeofenceCallbackHost::GetGeofenceOperationType() +GnssGeofenceOperateType LocationGnssGeofenceCallbackNapi::GetGeofenceOperationType() { std::unique_lock guard(operationResultMutex_); return type_; } -void LocationGnssGeofenceCallbackHost::SetGeofenceOperationType(GnssGeofenceOperateType type) +void LocationGnssGeofenceCallbackNapi::SetGeofenceOperationType(GnssGeofenceOperateType type) { std::unique_lock guard(operationResultMutex_); type_ = type; } -GnssGeofenceOperateResult LocationGnssGeofenceCallbackHost::GetGeofenceOperationResult() +GnssGeofenceOperateResult LocationGnssGeofenceCallbackNapi::GetGeofenceOperationResult() { std::unique_lock guard(operationResultMutex_); return result_; } -void LocationGnssGeofenceCallbackHost::SetGeofenceOperationResult(GnssGeofenceOperateResult result) +void LocationGnssGeofenceCallbackNapi::SetGeofenceOperationResult(GnssGeofenceOperateResult result) { std::unique_lock guard(operationResultMutex_); result_ = result; } -LocationErrCode LocationGnssGeofenceCallbackHost::DealGeofenceOperationResult() +LocationErrCode LocationGnssGeofenceCallbackNapi::DealGeofenceOperationResult() { std::unique_lock guard(operationResultMutex_); LocationErrCode errCode = ERRCODE_SUCCESS; diff --git a/frameworks/js/napi/source/location_napi_adapter.cpp b/frameworks/js/napi/source/location_napi_adapter.cpp index 9dd2aabb..eb8bd677 100644 --- a/frameworks/js/napi/source/location_napi_adapter.cpp +++ b/frameworks/js/napi/source/location_napi_adapter.cpp @@ -25,7 +25,7 @@ namespace OHOS { namespace Location { auto g_locatorClient = Locator::GetInstance(); auto g_geofenceClient = GeofenceManager::GetInstance(); -std::map> g_gnssGeofenceCallbackHostMap; +std::map> g_gnssGeofenceCallbackHostMap; std::mutex g_gnssGeofenceCallbackHostMutex; napi_value GetLastLocation(napi_env env, napi_callback_info info) @@ -942,10 +942,10 @@ LocationErrCode CheckLocationSwitchState() return ERRCODE_SUCCESS; } -sptr CreateSingleCallbackHost() +sptr CreateSingleCallbackHost() { auto callbackHost = - sptr(new (std::nothrow) LocatingRequiredDataCallbackHost()); + sptr(new (std::nothrow) LocatingRequiredDataCallbackNapi()); if (callbackHost) { callbackHost->SetFixNumber(1); } @@ -953,7 +953,7 @@ sptr CreateSingleCallbackHost() } SingleScanAsyncContext* CreateSingleScanAsyncContext(const napi_env& env, - std::unique_ptr& config, sptr callback) + std::unique_ptr& config, sptr callback) { auto asyncContext = new (std::nothrow) SingleScanAsyncContext(env); NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null."); @@ -1048,7 +1048,7 @@ napi_value GetLocatingRequiredData(napi_env env, napi_callback_info info) napi_value AddGnssGeofence(napi_env env, napi_callback_info info) { - LBSLOGD(LOCATOR_STANDARD, "%{public}s called.", __func__); + LBSLOGI(LOCATOR_STANDARD, "%{public}s called.", __func__); size_t argc = MAXIMUM_JS_PARAMS; napi_value argv[MAXIMUM_JS_PARAMS]; napi_value thisVar = nullptr; @@ -1066,7 +1066,7 @@ napi_value AddGnssGeofence(napi_env env, napi_callback_info info) return UndefinedNapiValue(env); } auto locationGnssGeofenceCallbackHost = - sptr(new (std::nothrow) LocationGnssGeofenceCallbackHost()); + sptr(new (std::nothrow) LocationGnssGeofenceCallbackNapi()); JsObjToGeofenceTransitionCallback(env, argv[0], locationGnssGeofenceCallbackHost); auto callbackPtr = sptr(locationGnssGeofenceCallbackHost); gnssGeofenceRequest->SetGeofenceTransitionCallback(callbackPtr->AsObject()); @@ -1080,7 +1080,7 @@ napi_value AddGnssGeofence(napi_env env, napi_callback_info info) } GnssGeofenceAsyncContext* CreateAsyncContextForAddGnssGeofence(const napi_env& env, - std::shared_ptr& request, sptr callback) + std::shared_ptr& request, sptr callback) { auto asyncContext = new (std::nothrow) GnssGeofenceAsyncContext(env); NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null."); @@ -1094,8 +1094,7 @@ GnssGeofenceAsyncContext* CreateAsyncContextForAddGnssGeofence(const napi_env& e auto context = static_cast(data); auto callbackHost = context->callbackHost_; auto gnssGeofenceRequest = context->request_; - if (callbackHost != nullptr || gnssGeofenceRequest != nullptr) { - auto callbackPtr = sptr(callbackHost); + if (callbackHost != nullptr && gnssGeofenceRequest != nullptr) { auto errCode = g_geofenceClient->AddGnssGeofence(gnssGeofenceRequest); if (errCode != ERRCODE_SUCCESS) { context->errCode = errCode; @@ -1132,7 +1131,7 @@ GnssGeofenceAsyncContext* CreateAsyncContextForAddGnssGeofence(const napi_env& e napi_value RemoveGnssGeofence(napi_env env, napi_callback_info info) { - LBSLOGD(LOCATOR_STANDARD, "%{public}s called.", __func__); + LBSLOGI(LOCATOR_STANDARD, "%{public}s called.", __func__); size_t argc = MAXIMUM_JS_PARAMS; napi_value argv[MAXIMUM_JS_PARAMS]; napi_value thisVar = nullptr; @@ -1237,7 +1236,7 @@ napi_value GetGeofenceSupportedCoordTypes(napi_env env, napi_callback_info info) return res; } -void AddCallbackToGnssGeofenceCallbackHostMap(int fenceId, sptr callbackHost) +void AddCallbackToGnssGeofenceCallbackHostMap(int fenceId, sptr callbackHost) { std::unique_lock lock(g_gnssGeofenceCallbackHostMutex); g_gnssGeofenceCallbackHostMap.insert(std::make_pair(fenceId, callbackHost)); @@ -1252,7 +1251,7 @@ void RemoveCallbackToGnssGeofenceCallbackHostMap(int fenceId) } } -sptr FindCallbackInGnssGeofenceCallbackHostMap(int fenceId) +sptr FindCallbackInGnssGeofenceCallbackHostMap(int fenceId) { std::unique_lock lock(g_gnssGeofenceCallbackHostMutex); auto iter = g_gnssGeofenceCallbackHostMap.find(fenceId); diff --git a/frameworks/js/napi/source/location_napi_entry.cpp b/frameworks/js/napi/source/location_napi_entry.cpp index 46ddaea3..526eb66a 100644 --- a/frameworks/js/napi/source/location_napi_entry.cpp +++ b/frameworks/js/napi/source/location_napi_entry.cpp @@ -191,6 +191,33 @@ napi_value LocatingRequiredDataTypeConstructor(napi_env env) return locatingPriority; } +napi_value LocationSourceTypeConstructor(napi_env env) +{ + napi_value locationSourceType = nullptr; + NAPI_CALL(env, napi_create_object(env, &locationSourceType)); + SetEnumPropertyByInteger(env, locationSourceType, LocationSourceType::GNSS_TYPE, "GNSS"); + SetEnumPropertyByInteger(env, locationSourceType, LocationSourceType::NETWORK_TYPE, "NETWORK"); + SetEnumPropertyByInteger(env, locationSourceType, LocationSourceType::INDOOR_TYPE, "INDOOR"); + SetEnumPropertyByInteger(env, locationSourceType, LocationSourceType::RTK_TYPE, "RTK"); + return locationSourceType; +} + +napi_value LocationErrorConstructor(napi_env env) +{ + napi_value locationError = nullptr; + NAPI_CALL(env, napi_create_object(env, &locationError)); + SetEnumPropertyByInteger(env, locationError, LocationErr::LOCATING_FAILED_DEFAULT, "LOCATING_FAILED_DEFAULT"); + SetEnumPropertyByInteger(env, locationError, + LocationErr::LOCATING_FAILED_LOCATION_PERMISSION_DENIED, "LOCATING_FAILED_LOCATION_PERMISSION_DENIED"); + SetEnumPropertyByInteger(env, locationError, + LocationErr::LOCATING_FAILED_BACKGROUND_PERMISSION_DENIED, "LOCATING_FAILED_BACKGROUND_PERMISSION_DENIED"); + SetEnumPropertyByInteger(env, locationError, + LocationErr::LOCATING_FAILED_LOCATION_SWITCH_OFF, "LOCATING_FAILED_LOCATION_SWITCH_OFF"); + SetEnumPropertyByInteger(env, locationError, + LocationErr::LOCATING_FAILED_INTERNET_ACCESS_FAILURE, "LOCATING_FAILED_INTERNET_ACCESS_FAILURE"); + return locationError; +} + #ifndef ENABLE_NAPI_MANAGER /* * Module initialization function @@ -291,6 +318,8 @@ static napi_value InitManager(napi_env env, napi_value exports) DECLARE_NAPI_PROPERTY("UserActivityScenario", UserActivityScenarioTypeConstructor(env)), DECLARE_NAPI_PROPERTY("LocatingPriority", LocatingPriorityTypeConstructor(env)), DECLARE_NAPI_PROPERTY("PowerConsumptionScenario", PowerConsumptionScenarioTypeConstructor(env)), + DECLARE_NAPI_PROPERTY("LocationSourceType", LocationSourceTypeConstructor(env)), + DECLARE_NAPI_PROPERTY("LocationError", LocationErrorConstructor(env)), }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc)); diff --git a/frameworks/js/napi/source/location_napi_event.cpp b/frameworks/js/napi/source/location_napi_event.cpp index c1eee428..80be5ef4 100644 --- a/frameworks/js/napi/source/location_napi_event.cpp +++ b/frameworks/js/napi/source/location_napi_event.cpp @@ -18,7 +18,7 @@ #include "common_utils.h" #include "location_log.h" #include "location_napi_errcode.h" -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "locator.h" #include "geofence_sdk.h" #include "geofence_napi.h" @@ -30,14 +30,14 @@ namespace OHOS { namespace Location { -CallbackManager g_switchCallbacks; -CallbackManager g_locationCallbacks; -CallbackManager g_gnssStatusInfoCallbacks; -CallbackManager g_nmeaCallbacks; -CallbackManager g_cachedLocationCallbacks; -CallbackManager g_countryCodeCallbacks; -CallbackManager g_locatingRequiredDataCallbacks; -CallbackManager g_locationErrorCallbackHosts; +CallbackManager g_switchCallbacks; +CallbackManager g_locationCallbacks; +CallbackManager g_gnssStatusInfoCallbacks; +CallbackManager g_nmeaCallbacks; +CallbackManager g_cachedLocationCallbacks; +CallbackManager g_countryCodeCallbacks; +CallbackManager g_locatingRequiredDataCallbacks; +CallbackManager g_locationErrorCallbackHosts; std::unique_ptr g_cachedRequest = std::make_unique(); auto g_locatorProxy = Locator::GetInstance(); @@ -115,7 +115,7 @@ void InitOffFuncMap() } void SubscribeLocationServiceState(const napi_env& env, - const napi_ref& handlerRef, sptr& switchCallbackHost) + const napi_ref& handlerRef, sptr& switchCallbackHost) { switchCallbackHost->SetEnv(env); switchCallbackHost->SetHandleCb(handlerRef); @@ -124,7 +124,7 @@ void SubscribeLocationServiceState(const napi_env& env, #ifdef ENABLE_NAPI_MANAGER LocationErrCode SubscribeLocationServiceStateV9(const napi_env& env, - const napi_ref& handlerRef, sptr& switchCallbackHost) + const napi_ref& handlerRef, sptr& switchCallbackHost) { switchCallbackHost->SetEnv(env); switchCallbackHost->SetHandleCb(handlerRef); @@ -133,7 +133,7 @@ LocationErrCode SubscribeLocationServiceStateV9(const napi_env& env, #endif void SubscribeGnssStatus(const napi_env& env, const napi_ref& handlerRef, - sptr& gnssStatusCallbackHost) + sptr& gnssStatusCallbackHost) { gnssStatusCallbackHost->SetEnv(env); gnssStatusCallbackHost->SetHandleCb(handlerRef); @@ -142,7 +142,7 @@ void SubscribeGnssStatus(const napi_env& env, const napi_ref& handlerRef, #ifdef ENABLE_NAPI_MANAGER LocationErrCode SubscribeGnssStatusV9(const napi_env& env, const napi_ref& handlerRef, - sptr& gnssStatusCallbackHost) + sptr& gnssStatusCallbackHost) { LocationErrCode errorCode = CheckLocationSwitchEnable(); if (errorCode != ERRCODE_SUCCESS) { @@ -155,7 +155,7 @@ LocationErrCode SubscribeGnssStatusV9(const napi_env& env, const napi_ref& handl #endif void SubscribeNmeaMessage(const napi_env& env, const napi_ref& handlerRef, - sptr& nmeaMessageCallbackHost) + sptr& nmeaMessageCallbackHost) { nmeaMessageCallbackHost->SetEnv(env); nmeaMessageCallbackHost->SetHandleCb(handlerRef); @@ -164,7 +164,7 @@ void SubscribeNmeaMessage(const napi_env& env, const napi_ref& handlerRef, #ifdef ENABLE_NAPI_MANAGER LocationErrCode SubscribeNmeaMessageV9(const napi_env& env, const napi_ref& handlerRef, - sptr& nmeaMessageCallbackHost) + sptr& nmeaMessageCallbackHost) { LocationErrCode errorCode = CheckLocationSwitchEnable(); if (errorCode != ERRCODE_SUCCESS) { @@ -176,42 +176,42 @@ LocationErrCode SubscribeNmeaMessageV9(const napi_env& env, const napi_ref& hand } #endif -void UnSubscribeLocationServiceState(sptr& switchCallbackHost) +void UnSubscribeLocationServiceState(sptr& switchCallbackHost) { LBSLOGD(LOCATION_NAPI, "UnSubscribeLocationServiceState"); g_locatorProxy->UnregisterSwitchCallback(switchCallbackHost->AsObject()); } #ifdef ENABLE_NAPI_MANAGER -LocationErrCode UnSubscribeLocationServiceStateV9(sptr& switchCallbackHost) +LocationErrCode UnSubscribeLocationServiceStateV9(sptr& switchCallbackHost) { LBSLOGD(LOCATION_NAPI, "UnSubscribeLocationServiceStateV9"); return g_locatorProxy->UnregisterSwitchCallbackV9(switchCallbackHost->AsObject()); } #endif -void UnSubscribeGnssStatus(sptr& gnssStatusCallbackHost) +void UnSubscribeGnssStatus(sptr& gnssStatusCallbackHost) { LBSLOGD(LOCATION_NAPI, "UnSubscribeGnssStatus"); g_locatorProxy->UnregisterGnssStatusCallback(gnssStatusCallbackHost->AsObject()); } #ifdef ENABLE_NAPI_MANAGER -LocationErrCode UnSubscribeGnssStatusV9(sptr& gnssStatusCallbackHost) +LocationErrCode UnSubscribeGnssStatusV9(sptr& gnssStatusCallbackHost) { LBSLOGD(LOCATION_NAPI, "UnSubscribeGnssStatusV9"); return g_locatorProxy->UnregisterGnssStatusCallbackV9(gnssStatusCallbackHost->AsObject()); } #endif -void UnSubscribeNmeaMessage(sptr& nmeaMessageCallbackHost) +void UnSubscribeNmeaMessage(sptr& nmeaMessageCallbackHost) { LBSLOGD(LOCATION_NAPI, "UnSubscribeNmeaMessage"); g_locatorProxy->UnregisterNmeaMessageCallback(nmeaMessageCallbackHost->AsObject()); } #ifdef ENABLE_NAPI_MANAGER -LocationErrCode UnSubscribeNmeaMessageV9(sptr& nmeaMessageCallbackHost) +LocationErrCode UnSubscribeNmeaMessageV9(sptr& nmeaMessageCallbackHost) { LBSLOGD(LOCATION_NAPI, "UnSubscribeNmeaMessageV9"); return g_locatorProxy->UnregisterNmeaMessageCallbackV9(nmeaMessageCallbackHost->AsObject()); @@ -219,7 +219,7 @@ LocationErrCode UnSubscribeNmeaMessageV9(sptr& nmeaMess #endif void SubscribeLocationChange(const napi_env& env, const napi_value& object, - const napi_ref& handlerRef, sptr& locatorCallbackHost) + const napi_ref& handlerRef, sptr& locatorCallbackHost) { auto locatorCallback = sptr(locatorCallbackHost); locatorCallbackHost->SetFixNumber(0); @@ -232,7 +232,7 @@ void SubscribeLocationChange(const napi_env& env, const napi_value& object, #ifdef ENABLE_NAPI_MANAGER LocationErrCode SubscribeLocationChangeV9(const napi_env& env, const napi_value& object, - const napi_ref& handlerRef, sptr& locatorCallbackHost) + const napi_ref& handlerRef, sptr& locatorCallbackHost) { LocationErrCode errorCode = CheckLocationSwitchEnable(); if (errorCode != ERRCODE_SUCCESS) { @@ -252,7 +252,7 @@ LocationErrCode SubscribeLocationChangeV9(const napi_env& env, const napi_value& #endif void SubscribeCountryCodeChange(const napi_env& env, - const napi_ref& handlerRef, sptr& callbackHost) + const napi_ref& handlerRef, sptr& callbackHost) { auto callbackPtr = sptr(callbackHost); callbackHost->SetEnv(env); @@ -262,7 +262,7 @@ void SubscribeCountryCodeChange(const napi_env& env, #ifdef ENABLE_NAPI_MANAGER LocationErrCode SubscribeCountryCodeChangeV9(const napi_env& env, - const napi_ref& handlerRef, sptr& callbackHost) + const napi_ref& handlerRef, sptr& callbackHost) { auto callbackPtr = sptr(callbackHost); callbackHost->SetEnv(env); @@ -273,7 +273,7 @@ LocationErrCode SubscribeCountryCodeChangeV9(const napi_env& env, #ifdef ENABLE_NAPI_MANAGER LocationErrCode SubscribeLocatingRequiredDataChange(const napi_env& env, const napi_value& object, - const napi_ref& handlerRef, sptr& locatingCallbackHost) + const napi_ref& handlerRef, sptr& locatingCallbackHost) { auto callbackPtr = sptr(locatingCallbackHost); locatingCallbackHost->SetEnv(env); @@ -284,7 +284,7 @@ LocationErrCode SubscribeLocatingRequiredDataChange(const napi_env& env, const n } LocationErrCode SubscribeLocationError(const napi_env& env, - const napi_ref& handlerRef, sptr& locationErrorCallbackHost) + const napi_ref& handlerRef, sptr& locationErrorCallbackHost) { locationErrorCallbackHost->SetEnv(env); locationErrorCallbackHost->SetHandleCb(handlerRef); @@ -293,14 +293,14 @@ LocationErrCode SubscribeLocationError(const napi_env& env, } #endif -void UnsubscribeCountryCodeChange(sptr& callbackHost) +void UnsubscribeCountryCodeChange(sptr& callbackHost) { LBSLOGD(LOCATION_NAPI, "UnsubscribeCountryCodeChange"); g_locatorProxy->UnregisterCountryCodeCallback(callbackHost->AsObject()); } #ifdef ENABLE_NAPI_MANAGER -LocationErrCode UnsubscribeCountryCodeChangeV9(sptr& callbackHost) +LocationErrCode UnsubscribeCountryCodeChangeV9(sptr& callbackHost) { LBSLOGD(LOCATION_NAPI, "UnsubscribeCountryCodeChangeV9"); return g_locatorProxy->UnregisterCountryCodeCallbackV9(callbackHost->AsObject()); @@ -308,7 +308,7 @@ LocationErrCode UnsubscribeCountryCodeChangeV9(sptr& ca #endif void SubscribeCacheLocationChange(const napi_env& env, const napi_value& object, - const napi_ref& handlerRef, sptr& cachedCallbackHost) + const napi_ref& handlerRef, sptr& cachedCallbackHost) { auto cachedCallback = sptr(cachedCallbackHost); cachedCallbackHost->SetEnv(env); @@ -319,7 +319,7 @@ void SubscribeCacheLocationChange(const napi_env& env, const napi_value& object, #ifdef ENABLE_NAPI_MANAGER LocationErrCode SubscribeCacheLocationChangeV9(const napi_env& env, const napi_value& object, - const napi_ref& handlerRef, sptr& cachedCallbackHost) + const napi_ref& handlerRef, sptr& cachedCallbackHost) { LocationErrCode errorCode = CheckLocationSwitchEnable(); if (errorCode != ERRCODE_SUCCESS) { @@ -400,7 +400,7 @@ LocationErrCode UnSubscribeFenceStatusChangeV9(const napi_env& env, const napi_v #endif #ifdef ENABLE_NAPI_MANAGER -LocationErrCode UnSubscribeLocatingRequiredDataChange(sptr& callbackHost) +LocationErrCode UnSubscribeLocatingRequiredDataChange(sptr& callbackHost) { LBSLOGD(LOCATION_NAPI, "%{public}s start", __func__); auto callbackPtr = sptr(callbackHost); @@ -464,7 +464,7 @@ void GenerateCompleteContext(SingleLocationAsyncContext* context) } SingleLocationAsyncContext* CreateSingleLocationAsyncContext(const napi_env& env, - std::unique_ptr& config, sptr callback) + std::unique_ptr& config, sptr callback) { auto asyncContext = new (std::nothrow) SingleLocationAsyncContext(env); NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null."); @@ -527,10 +527,10 @@ std::unique_ptr CreateRequestConfig(const napi_env& env, return requestConfig; } -sptr CreateSingleLocationCallbackHost() +sptr CreateSingleLocationCallbackHost() { auto callbackHost = - sptr(new (std::nothrow) LocatorCallbackHost()); + sptr(new (std::nothrow) LocatorCallbackNapi()); if (callbackHost) { callbackHost->SetFixNumber(1); } @@ -651,7 +651,7 @@ bool OnLocationServiceStateCallback(const napi_env& env, const size_t argc, cons return false; } auto switchCallbackHost = - sptr(new (std::nothrow) LocationSwitchCallbackHost()); + sptr(new (std::nothrow) LocationSwitchCallbackNapi()); if (switchCallbackHost != nullptr) { napi_ref handlerRef = nullptr; NAPI_CALL_BASE(env, napi_create_reference(env, argv[PARAM1], 1, &handlerRef), false); @@ -699,7 +699,7 @@ bool OnCachedGnssLocationsReportingCallback(const napi_env& env, const size_t ar return false; } auto cachedCallbackHost = - sptr(new (std::nothrow) CachedLocationsCallbackHost()); + sptr(new (std::nothrow) CachedLocationsCallbackNapi()); if (cachedCallbackHost != nullptr) { napi_ref handlerRef = nullptr; NAPI_CALL_BASE(env, napi_create_reference(env, argv[PARAM2], PARAM1, &handlerRef), false); @@ -738,7 +738,7 @@ bool OnGnssStatusChangeCallback(const napi_env& env, const size_t argc, const na return false; } auto gnssCallbackHost = - sptr(new (std::nothrow) GnssStatusCallbackHost()); + sptr(new (std::nothrow) GnssStatusCallbackNapi()); if (gnssCallbackHost != nullptr) { napi_ref handlerRef = nullptr; NAPI_CALL_BASE(env, napi_create_reference(env, argv[PARAM1], PARAM1, &handlerRef), false); @@ -787,7 +787,7 @@ bool OnLocationChangeCallback(const napi_env& env, const size_t argc, const napi return false; } auto locatorCallbackHost = - sptr(new (std::nothrow) LocatorCallbackHost()); + sptr(new (std::nothrow) LocatorCallbackNapi()); if (locatorCallbackHost != nullptr) { napi_ref handlerRef = nullptr; NAPI_CALL_BASE(env, napi_create_reference(env, argv[PARAM2], 1, &handlerRef), false); @@ -827,7 +827,7 @@ bool OnNmeaMessageChangeCallback(const napi_env& env, const size_t argc, const n return false; } auto nmeaCallbackHost = - sptr(new (std::nothrow) NmeaMessageCallbackHost()); + sptr(new (std::nothrow) NmeaMessageCallbackNapi()); if (nmeaCallbackHost != nullptr) { napi_ref handlerRef = nullptr; NAPI_CALL_BASE(env, napi_create_reference(env, argv[PARAM1], PARAM1, &handlerRef), false); @@ -866,7 +866,7 @@ bool OnCountryCodeChangeCallback(const napi_env& env, const size_t argc, const n return false; } auto callbackHost = - sptr(new (std::nothrow) CountryCodeCallbackHost()); + sptr(new (std::nothrow) CountryCodeCallbackNapi()); if (callbackHost) { napi_ref handlerRef = nullptr; NAPI_CALL_BASE(env, napi_create_reference(env, argv[PARAM1], 1, &handlerRef), false); @@ -927,7 +927,7 @@ bool OnLocatingRequiredDataChangeCallback(const napi_env& env, const size_t argc return false; } auto locatingCallbackHost = - sptr(new (std::nothrow) LocatingRequiredDataCallbackHost()); + sptr(new (std::nothrow) LocatingRequiredDataCallbackNapi()); if (locatingCallbackHost != nullptr) { napi_ref handlerRef = nullptr; NAPI_CALL_BASE(env, napi_create_reference(env, argv[PARAM2], 1, &handlerRef), false); @@ -980,7 +980,7 @@ napi_value On(napi_env env, napi_callback_info cbinfo) bool OffAllLocationServiceStateCallback(const napi_env& env) { - std::map>> callbackMap = + std::map>> callbackMap = g_switchCallbacks.GetCallbackMap(); auto iter = callbackMap.find(env); if (iter == callbackMap.end()) { @@ -1009,7 +1009,7 @@ bool OffAllLocationServiceStateCallback(const napi_env& env) bool OffAllLocationChangeCallback(const napi_env& env) { - std::map>> callbackMap = + std::map>> callbackMap = g_locationCallbacks.GetCallbackMap(); auto iter = callbackMap.find(env); if (iter == callbackMap.end()) { @@ -1039,7 +1039,7 @@ bool OffAllLocationChangeCallback(const napi_env& env) bool OffAllGnssStatusChangeCallback(const napi_env& env) { - std::map>> callbackMap = + std::map>> callbackMap = g_gnssStatusInfoCallbacks.GetCallbackMap(); auto iter = callbackMap.find(env); if (iter == callbackMap.end()) { @@ -1068,7 +1068,7 @@ bool OffAllGnssStatusChangeCallback(const napi_env& env) bool OffAllNmeaMessageChangeCallback(const napi_env& env) { - std::map>> callbackMap = + std::map>> callbackMap = g_nmeaCallbacks.GetCallbackMap(); auto iter = callbackMap.find(env); if (iter == callbackMap.end()) { @@ -1097,7 +1097,7 @@ bool OffAllNmeaMessageChangeCallback(const napi_env& env) bool OffAllCachedGnssLocationsReportingCallback(const napi_env& env) { - std::map>> callbackMap = + std::map>> callbackMap = g_cachedLocationCallbacks.GetCallbackMap(); auto iter = callbackMap.find(env); if (iter == callbackMap.end()) { @@ -1130,7 +1130,7 @@ bool OffAllCachedGnssLocationsReportingCallback(const napi_env& env) bool OffAllCountryCodeChangeCallback(const napi_env& env) { - std::map>> callbackMap = + std::map>> callbackMap = g_countryCodeCallbacks.GetCallbackMap(); auto iter = callbackMap.find(env); if (iter == callbackMap.end()) { @@ -1160,7 +1160,7 @@ bool OffAllCountryCodeChangeCallback(const napi_env& env) #ifdef ENABLE_NAPI_MANAGER bool OffAllLocatingRequiredDataChangeCallback(const napi_env& env) { - std::map>> callbackMap = + std::map>> callbackMap = g_locatingRequiredDataCallbacks.GetCallbackMap(); auto iter = callbackMap.find(env); if (iter == callbackMap.end()) { @@ -1539,7 +1539,7 @@ bool OnLocationErrorCallback(const napi_env& env, const size_t argc, const napi_ return false; } auto locationErrorCallbackHost = - sptr(new (std::nothrow) LocationErrorCallbackHost()); + sptr(new (std::nothrow) LocationErrorCallbackNapi()); if (locationErrorCallbackHost != nullptr) { napi_ref handlerRef = nullptr; NAPI_CALL_BASE(env, napi_create_reference(env, argv[PARAM1], 1, &handlerRef), false); diff --git a/frameworks/js/napi/source/location_napi_system.cpp b/frameworks/js/napi/source/location_napi_system.cpp index 5a237e63..c9f075f0 100644 --- a/frameworks/js/napi/source/location_napi_system.cpp +++ b/frameworks/js/napi/source/location_napi_system.cpp @@ -15,17 +15,17 @@ #include "location_napi_system.h" -#include "locator_callback_host.h" +#include "locator_callback_napi.h" #include "location_log.h" #include "locator.h" #include "napi_util.h" namespace OHOS { namespace Location { -sptr g_systemSingleLocatorCallbackHost = - sptr(new (std::nothrow)LocatorCallbackHost()); -sptr g_systemSubcribeCallbackHost = - sptr(new (std::nothrow)LocatorCallbackHost()); +sptr g_systemSingleLocatorCallbackHost = + sptr(new (std::nothrow)LocatorCallbackNapi()); +sptr g_systemSubcribeCallbackHost = + sptr(new (std::nothrow)LocatorCallbackNapi()); auto g_locatorImpl = Locator::GetInstance(); napi_value GetLocationOnce(const napi_env& env, @@ -188,7 +188,7 @@ void SubscribeSystemLocationChange(napi_env env, napi_ref& successHandlerRef, napi_ref& failHandlerRef, int fixNumber, - sptr& locatorCallbackHost) + sptr& locatorCallbackHost) { auto locatorCallback = sptr(locatorCallbackHost); if (locatorCallbackHost->GetSuccHandleCb() != nullptr || diff --git a/frameworks/js/napi/source/location_switch_callback_napi.cpp b/frameworks/js/napi/source/location_switch_callback_napi.cpp new file mode 100644 index 00000000..9d564969 --- /dev/null +++ b/frameworks/js/napi/source/location_switch_callback_napi.cpp @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "location_switch_callback_napi.h" +#include "common_utils.h" +#include "ipc_skeleton.h" +#include "location_log.h" + +namespace OHOS { +namespace Location { +LocationSwitchCallbackNapi::LocationSwitchCallbackNapi() +{ + env_ = nullptr; + handlerCb_ = nullptr; + remoteDied_ = false; + callbackValid_ = false; +} + +LocationSwitchCallbackNapi::~LocationSwitchCallbackNapi() +{ +} + +int LocationSwitchCallbackNapi::OnRemoteRequest( + uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) +{ + LBSLOGD(SWITCH_CALLBACK, "LocatorCallbackNapi::OnRemoteRequest!"); + if (data.ReadInterfaceToken() != GetDescriptor()) { + LBSLOGE(SWITCH_CALLBACK, "invalid token."); + return -1; + } + if (remoteDied_) { + LBSLOGD(SWITCH_CALLBACK, "Failed to `%{public}s`,Remote service is died!", __func__); + return -1; + } + + switch (code) { + case RECEIVE_SWITCH_STATE_EVENT: { + OnSwitchChange(data.ReadInt32()); + break; + } + default: { + IPCObjectStub::OnRemoteRequest(code, data, reply, option); + break; + } + } + return 0; +} + +bool LocationSwitchCallbackNapi::IsRemoteDied() +{ + return remoteDied_; +} + +napi_value LocationSwitchCallbackNapi::PackResult(bool switchState) +{ + napi_value result; + NAPI_CALL(env_, napi_get_boolean(env_, switchState, &result)); + return result; +} + +bool LocationSwitchCallbackNapi::Send(int switchState) +{ + std::unique_lock guard(mutex_); + uv_loop_s *loop = nullptr; + NAPI_CALL_BASE(env_, napi_get_uv_event_loop(env_, &loop), false); + if (loop == nullptr) { + LBSLOGE(SWITCH_CALLBACK, "loop == nullptr."); + return false; + } + if (handlerCb_ == nullptr) { + LBSLOGE(SWITCH_CALLBACK, "handler is nullptr."); + return false; + } + uv_work_t *work = new (std::nothrow) uv_work_t; + if (work == nullptr) { + LBSLOGE(SWITCH_CALLBACK, "work == nullptr."); + return false; + } + SwitchAsyncContext *context = new (std::nothrow) SwitchAsyncContext(env_); + if (context == nullptr) { + LBSLOGE(SWITCH_CALLBACK, "context == nullptr."); + delete work; + return false; + } + if (!InitContext(context)) { + LBSLOGE(LOCATOR_CALLBACK, "InitContext fail"); + return false; + } + context->enable = (switchState == 1 ? true : false); + work->data = context; + UvQueueWork(loop, work); + return true; +} + +void LocationSwitchCallbackNapi::UvQueueWork(uv_loop_s* loop, uv_work_t* work) +{ + uv_queue_work( + loop, + work, + [](uv_work_t *work) {}, + [](uv_work_t *work, int status) { + SwitchAsyncContext *context = nullptr; + napi_handle_scope scope = nullptr; + if (work == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "work is nullptr!"); + return; + } + context = static_cast(work->data); + if (context == nullptr || context->env == nullptr || context->callbackValid == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "context is nullptr!"); + delete work; + return; + } + NAPI_CALL_RETURN_VOID(context->env, napi_open_handle_scope(context->env, &scope)); + napi_value jsEvent; + CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_get_boolean(context->env, context->enable, &jsEvent), + scope, context, work); + if (scope == nullptr) { + LBSLOGE(SWITCH_CALLBACK, "scope is nullptr"); + delete context; + delete work; + return; + } + if (context->callback[0] != nullptr && *(context->callbackValid)) { + napi_value undefine; + napi_value handler = nullptr; + CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_get_undefined(context->env, &undefine), + scope, context, work); + CHK_NAPI_ERR_CLOSE_SCOPE(context->env, + napi_get_reference_value(context->env, context->callback[0], &handler), scope, context, work); + if (napi_call_function(context->env, nullptr, handler, 1, + &jsEvent, &undefine) != napi_ok) { + LBSLOGE(SWITCH_CALLBACK, "Report event failed"); + } + } + NAPI_CALL_RETURN_VOID(context->env, napi_close_handle_scope(context->env, scope)); + delete context; + delete work; + }); +} + +void LocationSwitchCallbackNapi::OnSwitchChange(int switchState) +{ + LBSLOGD(SWITCH_CALLBACK, "LocatorCallbackNapi::OnSwitchChange"); + Send(switchState); +} + +void LocationSwitchCallbackNapi::DeleteHandler() +{ + std::unique_lock guard(mutex_); + if (handlerCb_ == nullptr || env_ == nullptr) { + LBSLOGE(SWITCH_CALLBACK, "handler or env is nullptr."); + return; + } + NAPI_CALL_RETURN_VOID(env_, napi_delete_reference(env_, handlerCb_)); + handlerCb_ = nullptr; + callbackValid_ = false; +} +} // namespace Location +} // namespace OHOS diff --git a/frameworks/js/napi/source/locator_callback_napi.cpp b/frameworks/js/napi/source/locator_callback_napi.cpp new file mode 100644 index 00000000..6dc7c010 --- /dev/null +++ b/frameworks/js/napi/source/locator_callback_napi.cpp @@ -0,0 +1,388 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "locator_callback_napi.h" + +#include "ipc_object_stub.h" +#include "ipc_skeleton.h" +#include "js_native_api.h" +#include "message_option.h" +#include "message_parcel.h" +#include "napi/native_common.h" +#include "uv.h" + +#include "common_utils.h" +#include "constant_definition.h" +#include "i_locator_callback.h" +#include "location.h" +#include "location_async_context.h" +#include "location_log.h" +#include "napi_util.h" + +namespace OHOS { +namespace Location { +LocatorCallbackNapi::LocatorCallbackNapi() +{ + env_ = nullptr; + handlerCb_ = nullptr; + successHandlerCb_ = nullptr; + failHandlerCb_ = nullptr; + completeHandlerCb_ = nullptr; + fixNumber_ = 0; + inHdArea_ = true; + singleLocation_ = nullptr; + callbackValid_ = false; + InitLatch(); +} + +void LocatorCallbackNapi::InitLatch() +{ + latch_ = new CountDownLatch(); + latch_->SetCount(1); +} + +LocatorCallbackNapi::~LocatorCallbackNapi() +{ + delete latch_; +} + +int LocatorCallbackNapi::OnRemoteRequest(uint32_t code, + MessageParcel& data, MessageParcel& reply, MessageOption& option) +{ + if (data.ReadInterfaceToken() != GetDescriptor()) { + LBSLOGE(LOCATOR_CALLBACK, "invalid token."); + return -1; + } + + switch (code) { + case RECEIVE_LOCATION_INFO_EVENT: { + std::unique_ptr location = Location::Unmarshalling(data); + OnLocationReport(location); + if (location->GetLocationSourceType() == LocationSourceType::NETWORK_TYPE && + location->GetAdditionsMap()["inHdArea"] != "") { + inHdArea_ = (location->GetAdditionsMap()["inHdArea"] == "true"); + } + if (NeedSetSingleLocation(location)) { + SetSingleLocation(location); + } + if (IfReportAccuracyLocation()) { + CountDown(); + } + break; + } + case RECEIVE_LOCATION_STATUS_EVENT: { + int status = data.ReadInt32(); + OnLocatingStatusChange(status); + break; + } + case RECEIVE_ERROR_INFO_EVENT: { + int errorCode = data.ReadInt32(); + LBSLOGI(LOCATOR_STANDARD, "CallbackSutb receive ERROR_EVENT. errorCode:%{public}d", errorCode); + if (errorCode == LOCATING_FAILED_INTERNET_ACCESS_FAILURE) { + inHdArea_ = false; + if (GetSingleLocation() != nullptr) { + CountDown(); + } + } else { + OnErrorReport(errorCode); + } + break; + } + default: { + IPCObjectStub::OnRemoteRequest(code, data, reply, option); + break; + } + } + return 0; +} + +void LocatorCallbackNapi::DoSendWork(uv_loop_s*& loop, uv_work_t*& work) +{ + uv_queue_work(loop, work, [](uv_work_t* work) {}, [](uv_work_t* work, int status) { + if (work == nullptr) { + return; + } + napi_handle_scope scope = nullptr; + auto context = static_cast(work->data); + if (context == nullptr) { + delete work; + return; + } + if (context->env == nullptr || context->loc == nullptr || context->callbackValid == nullptr) { + delete context; + delete work; + return; + } + napi_open_handle_scope(context->env, &scope); + if (scope == nullptr) { + DELETE_SCOPE_CONTEXT_WORK(context->env, scope, context, work); + return; + } + napi_value jsEvent = nullptr; + CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_create_object(context->env, &jsEvent), scope, context, work); + if (context->callback[1]) { + SystemLocationToJs(context->env, context->loc, jsEvent); + } else { + LocationToJs(context->env, context->loc, jsEvent); + } + if (context->callback[0] != nullptr && *(context->callbackValid)) { + napi_value undefine = nullptr; + napi_value handler = nullptr; + CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_get_undefined(context->env, &undefine), + scope, context, work); + CHK_NAPI_ERR_CLOSE_SCOPE(context->env, + napi_get_reference_value(context->env, context->callback[0], &handler), scope, context, work); + if (napi_call_function(context->env, nullptr, handler, 1, &jsEvent, &undefine) != napi_ok) { + LBSLOGE(LOCATOR_CALLBACK, "Report location failed"); + } + } + DELETE_SCOPE_CONTEXT_WORK(context->env, scope, context, work); + }); +} + +void LocatorCallbackNapi::DoSendErrorCode(uv_loop_s *&loop, uv_work_t *&work) +{ + uv_queue_work(loop, work, [](uv_work_t *work) {}, + [](uv_work_t *work, int status) { + AsyncContext *context = nullptr; + napi_handle_scope scope = nullptr; + if (work == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "work is nullptr"); + return; + } + context = static_cast(work->data); + if (context == nullptr || context->env == nullptr || context->callbackValid == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "context is nullptr"); + delete work; + return; + } + NAPI_CALL_RETURN_VOID(context->env, napi_open_handle_scope(context->env, &scope)); + if (scope == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "scope is nullptr"); + delete context; + delete work; + return; + } + if (context->callback[FAIL_CALLBACK] != nullptr && *(context->callbackValid)) { + napi_value undefine; + napi_value handler = nullptr; + CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_get_undefined(context->env, &undefine), + scope, context, work); + CHK_NAPI_ERR_CLOSE_SCOPE(context->env, + napi_get_reference_value(context->env, context->callback[FAIL_CALLBACK], &handler), + scope, context, work); + std::string msg = GetErrorMsgByCode(context->errCode); + CreateFailCallBackParams(*context, msg, context->errCode); + if (napi_call_function(context->env, nullptr, handler, RESULT_SIZE, + context->result, &undefine) != napi_ok) { + LBSLOGE(LOCATOR_CALLBACK, "Report system error failed"); + } + } + NAPI_CALL_RETURN_VOID(context->env, napi_close_handle_scope(context->env, scope)); + delete context; + delete work; + }); +} + +bool LocatorCallbackNapi::SendErrorCode(const int& errorCode) +{ + std::unique_lock guard(mutex_); + if (!IsSystemGeoLocationApi() && !IsSingleLocationRequest()) { + LBSLOGE(LOCATOR_CALLBACK, "this is Callback type,cant send error msg."); + return false; + } + if (env_ == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "env_ is nullptr."); + return false; + } + if (handlerCb_ == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "handler is nullptr."); + return false; + } + uv_loop_s *loop = nullptr; + NAPI_CALL_BASE(env_, napi_get_uv_event_loop(env_, &loop), false); + if (loop == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "loop == nullptr."); + return false; + } + uv_work_t *work = new (std::nothrow) uv_work_t; + if (work == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "work == nullptr."); + return false; + } + AsyncContext *context = new (std::nothrow) AsyncContext(env_); + if (context == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "context == nullptr."); + delete work; + return false; + } + if (!InitContext(context)) { + LBSLOGE(LOCATOR_CALLBACK, "InitContext fail"); + } + context->errCode = errorCode; + work->data = context; + DoSendErrorCode(loop, work); + return true; +} + +void LocatorCallbackNapi::OnLocationReport(const std::unique_ptr& location) +{ + std::unique_lock guard(mutex_); + uv_loop_s *loop = nullptr; + if (env_ == nullptr) { + LBSLOGD(LOCATOR_CALLBACK, "env_ is nullptr."); + return; + } + if (handlerCb_ == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "handler is nullptr."); + return; + } + NAPI_CALL_RETURN_VOID(env_, napi_get_uv_event_loop(env_, &loop)); + if (loop == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "loop == nullptr."); + return; + } + uv_work_t *work = new (std::nothrow) uv_work_t; + if (work == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "work == nullptr."); + return; + } + auto context = new (std::nothrow) LocationAsyncContext(env_); + if (context == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "context == nullptr."); + delete work; + return; + } + if (!InitContext(context)) { + LBSLOGE(LOCATOR_CALLBACK, "InitContext fail"); + } + context->loc = std::make_unique(*location); + work->data = context; + DoSendWork(loop, work); +} + +void LocatorCallbackNapi::OnLocatingStatusChange(const int status) +{ +} + +void LocatorCallbackNapi::OnErrorReport(const int errorCode) +{ + SendErrorCode(errorCode); +} + +void LocatorCallbackNapi::DeleteAllCallbacks() +{ + DeleteHandler(); +} + +void LocatorCallbackNapi::DeleteHandler() +{ + LBSLOGD(LOCATOR_CALLBACK, "before DeleteHandler"); + std::unique_lock guard(mutex_); + if (env_ == nullptr) { + LBSLOGE(LOCATOR_CALLBACK, "env is nullptr."); + return; + } + if (IsSystemGeoLocationApi()) { + if (successHandlerCb_ != nullptr) { + NAPI_CALL_RETURN_VOID(env_, napi_delete_reference(env_, successHandlerCb_)); + successHandlerCb_ = nullptr; + } + if (failHandlerCb_ != nullptr) { + NAPI_CALL_RETURN_VOID(env_, napi_delete_reference(env_, failHandlerCb_)); + failHandlerCb_ = nullptr; + } + if (completeHandlerCb_ != nullptr) { + NAPI_CALL_RETURN_VOID(env_, napi_delete_reference(env_, completeHandlerCb_)); + completeHandlerCb_ = nullptr; + } + } else { + if (handlerCb_ != nullptr) { + NAPI_CALL_RETURN_VOID(env_, napi_delete_reference(env_, handlerCb_)); + handlerCb_ = nullptr; + } + } + callbackValid_ = false; +} + +bool LocatorCallbackNapi::IsSystemGeoLocationApi() +{ + return (successHandlerCb_ != nullptr) ? true : false; +} + +bool LocatorCallbackNapi::IsSingleLocationRequest() +{ + return (fixNumber_ == 1); +} + +void LocatorCallbackNapi::CountDown() +{ + if (IsSingleLocationRequest() && latch_ != nullptr) { + latch_->CountDown(); + } +} + +void LocatorCallbackNapi::Wait(int time) +{ + if (IsSingleLocationRequest() && latch_ != nullptr) { + latch_->Wait(time); + } +} + +int LocatorCallbackNapi::GetCount() +{ + if (IsSingleLocationRequest() && latch_ != nullptr) { + return latch_->GetCount(); + } + return 0; +} + +void LocatorCallbackNapi::SetCount(int count) +{ + if (IsSingleLocationRequest() && latch_ != nullptr) { + return latch_->SetCount(count); + } +} + +bool LocatorCallbackNapi::NeedSetSingleLocation(const std::unique_ptr& location) +{ + if (locationPriority_ == LOCATION_PRIORITY_ACCURACY && + singleLocation_ != nullptr && + location->GetLocationSourceType() == LocationSourceType::NETWORK_TYPE) { + return false; + } else { + return true; + } +} + +bool LocatorCallbackNapi::IfReportAccuracyLocation() +{ + if (locationPriority_ == LOCATION_PRIORITY_ACCURACY && + (((singleLocation_->GetLocationSourceType() == LocationSourceType::GNSS_TYPE || + singleLocation_->GetLocationSourceType() == LocationSourceType::RTK_TYPE) && inHdArea_) || + singleLocation_->GetLocationSourceType() == LocationSourceType::NETWORK_TYPE)) { + return false; + } else { + return true; + } +} + +void LocatorCallbackNapi::SetSingleLocation(const std::unique_ptr& location) +{ + std::unique_lock guard(mutex_); + singleLocation_ = std::make_shared(*location); +} +} // namespace Location +} // namespace OHOS diff --git a/frameworks/native/locator_sdk/source/napi_util.cpp b/frameworks/js/napi/source/napi_util.cpp similarity index 99% rename from frameworks/native/locator_sdk/source/napi_util.cpp rename to frameworks/js/napi/source/napi_util.cpp index ad77fc7c..98eea5d1 100644 --- a/frameworks/native/locator_sdk/source/napi_util.cpp +++ b/frameworks/js/napi/source/napi_util.cpp @@ -1037,7 +1037,7 @@ void DeleteCallbackHandler(uv_loop_s *&loop, uv_work_t *&work) return; } context = static_cast(work->data); - if (context == nullptr || context->env == nullptr) { + if (context == nullptr || context->env == nullptr || context->callbackValid == nullptr) { LBSLOGE(LOCATOR_CALLBACK, "context is nullptr"); delete work; return; @@ -1049,6 +1049,13 @@ void DeleteCallbackHandler(uv_loop_s *&loop, uv_work_t *&work) delete work; return; } + if (*(context->callbackValid) == false) { + LBSLOGE(LOCATOR_CALLBACK, "callbackValid is false"); + NAPI_CALL_RETURN_VOID(context->env, napi_close_handle_scope(context->env, scope)); + delete context; + delete work; + return; + } if (context->callback[SUCCESS_CALLBACK] != nullptr) { CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_delete_reference(context->env, context->callback[SUCCESS_CALLBACK]), @@ -1064,6 +1071,7 @@ void DeleteCallbackHandler(uv_loop_s *&loop, uv_work_t *&work) napi_delete_reference(context->env, context->callback[COMPLETE_CALLBACK]), scope, context, work); } + *(context->callbackValid) = false; NAPI_CALL_RETURN_VOID(context->env, napi_close_handle_scope(context->env, scope)); delete context; delete work; diff --git a/frameworks/native/locator_sdk/source/nmea_message_callback_host.cpp b/frameworks/js/napi/source/nmea_message_callback_napi.cpp similarity index 79% rename from frameworks/native/locator_sdk/source/nmea_message_callback_host.cpp rename to frameworks/js/napi/source/nmea_message_callback_napi.cpp index 9f653eb0..35a5e793 100644 --- a/frameworks/native/locator_sdk/source/nmea_message_callback_host.cpp +++ b/frameworks/js/napi/source/nmea_message_callback_napi.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #include "common_utils.h" #include "ipc_skeleton.h" @@ -24,21 +24,22 @@ namespace OHOS { namespace Location { -NmeaMessageCallbackHost::NmeaMessageCallbackHost() +NmeaMessageCallbackNapi::NmeaMessageCallbackNapi() { env_ = nullptr; handlerCb_ = nullptr; remoteDied_ = false; + callbackValid_ = false; } -NmeaMessageCallbackHost::~NmeaMessageCallbackHost() +NmeaMessageCallbackNapi::~NmeaMessageCallbackNapi() { } -int NmeaMessageCallbackHost::OnRemoteRequest( +int NmeaMessageCallbackNapi::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { - LBSLOGD(NMEA_MESSAGE_CALLBACK, "NmeaMessageCallbackHost::OnRemoteRequest!"); + LBSLOGD(NMEA_MESSAGE_CALLBACK, "NmeaMessageCallbackNapi::OnRemoteRequest!"); if (data.ReadInterfaceToken() != GetDescriptor()) { LBSLOGE(NMEA_MESSAGE_CALLBACK, "invalid token."); return -1; @@ -63,19 +64,19 @@ int NmeaMessageCallbackHost::OnRemoteRequest( return 0; } -bool NmeaMessageCallbackHost::IsRemoteDied() +bool NmeaMessageCallbackNapi::IsRemoteDied() { return remoteDied_; } -napi_value NmeaMessageCallbackHost::PackResult(const std::string msg) +napi_value NmeaMessageCallbackNapi::PackResult(const std::string msg) { napi_value result; NAPI_CALL(env_, napi_create_string_utf8(env_, msg.c_str(), NAPI_AUTO_LENGTH, &result)); return result; } -bool NmeaMessageCallbackHost::Send(const std::string msg) +bool NmeaMessageCallbackNapi::Send(const std::string msg) { std::unique_lock guard(mutex_); uv_loop_s *loop = nullptr; @@ -84,6 +85,10 @@ bool NmeaMessageCallbackHost::Send(const std::string msg) LBSLOGE(NMEA_MESSAGE_CALLBACK, "loop == nullptr."); return false; } + if (handlerCb_ == nullptr) { + LBSLOGE(NMEA_MESSAGE_CALLBACK, "handler is nullptr."); + return false; + } uv_work_t *work = new (std::nothrow) uv_work_t; if (work == nullptr) { LBSLOGE(NMEA_MESSAGE_CALLBACK, "work == nullptr."); @@ -95,8 +100,10 @@ bool NmeaMessageCallbackHost::Send(const std::string msg) delete work; return false; } - context->env = env_; - context->callback[SUCCESS_CALLBACK] = handlerCb_; + if (!InitContext(context)) { + LBSLOGE(NMEA_MESSAGE_CALLBACK, "InitContext fail"); + return false; + } context->msg = msg; work->data = context; UvQueueWork(loop, work); @@ -104,7 +111,7 @@ bool NmeaMessageCallbackHost::Send(const std::string msg) } -void NmeaMessageCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) +void NmeaMessageCallbackNapi::UvQueueWork(uv_loop_s* loop, uv_work_t* work) { uv_queue_work( loop, @@ -118,7 +125,7 @@ void NmeaMessageCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) return; } context = static_cast(work->data); - if (context == nullptr || context->env == nullptr) { + if (context == nullptr || context->env == nullptr || context->callbackValid == nullptr) { LBSLOGE(LOCATOR_CALLBACK, "context is nullptr!"); delete work; return; @@ -134,7 +141,7 @@ void NmeaMessageCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_create_string_utf8(context->env, context->msg.c_str(), NAPI_AUTO_LENGTH, &jsEvent), scope, context, work); - if (context->callback[0] != nullptr) { + if (context->callback[0] != nullptr && *(context->callbackValid)) { napi_value undefine; napi_value handler = nullptr; CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_get_undefined(context->env, &undefine), @@ -153,28 +160,22 @@ void NmeaMessageCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) }); } -void NmeaMessageCallbackHost::OnMessageChange(int64_t timestamp, const std::string msg) +void NmeaMessageCallbackNapi::OnMessageChange(int64_t timestamp, const std::string msg) { - LBSLOGD(NMEA_MESSAGE_CALLBACK, "NmeaMessageCallbackHost::OnMessageChange"); + LBSLOGD(NMEA_MESSAGE_CALLBACK, "NmeaMessageCallbackNapi::OnMessageChange"); Send(msg); } -void NmeaMessageCallbackHost::DeleteHandler() +void NmeaMessageCallbackNapi::DeleteHandler() { std::unique_lock guard(mutex_); if (handlerCb_ == nullptr || env_ == nullptr) { LBSLOGE(NMEA_MESSAGE_CALLBACK, "handler or env is nullptr."); return; } - auto context = new (std::nothrow) AsyncContext(env_); - if (context == nullptr) { - LBSLOGE(NMEA_MESSAGE_CALLBACK, "context == nullptr."); - return; - } - context->env = env_; - context->callback[SUCCESS_CALLBACK] = handlerCb_; - DeleteQueueWork(context); + NAPI_CALL_RETURN_VOID(env_, napi_delete_reference(env_, handlerCb_)); handlerCb_ = nullptr; + callbackValid_ = false; } } // namespace Location } // namespace OHOS diff --git a/frameworks/location_common/common/BUILD.gn b/frameworks/location_common/common/BUILD.gn index 2f17ded1..ae7e061d 100644 --- a/frameworks/location_common/common/BUILD.gn +++ b/frameworks/location_common/common/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022 Huawei Device Co., Ltd. +# Copyright (C) 2022-2024 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -19,6 +19,25 @@ config("location_common_config") { include_dirs = [ "$LOCATION_ROOT_DIR/interfaces/inner_api/include" ] } +local_base_sources = [ + "$LOCATION_COMMON_DIR/source/app_identity.cpp", + "$LOCATION_COMMON_DIR/source/common_hisysevent.cpp", + "$LOCATION_COMMON_DIR/source/common_utils.cpp", + "$LOCATION_COMMON_DIR/source/geo_address.cpp", + "$LOCATION_COMMON_DIR/source/geo_coding_mock_info.cpp", + "$LOCATION_COMMON_DIR/source/hook_utils.cpp", + "$LOCATION_COMMON_DIR/source/location.cpp", + "$LOCATION_COMMON_DIR/source/location_data_rdb_helper.cpp", + "$LOCATION_COMMON_DIR/source/location_data_rdb_manager.cpp", + "$LOCATION_COMMON_DIR/source/location_dumper.cpp", + "$LOCATION_COMMON_DIR/source/location_sa_load_manager.cpp", + "$LOCATION_COMMON_DIR/source/permission_manager.cpp", + "$LOCATION_COMMON_DIR/source/request.cpp", + "$LOCATION_COMMON_DIR/source/request_config.cpp", + "$LOCATION_COMMON_DIR/source/satellite_status.cpp", + "$LOCATION_COMMON_DIR/source/ui_extension_ability_connection.cpp", +] + ohos_shared_library("lbsservice_common") { public_configs = [ ":location_common_config" ] @@ -29,24 +48,7 @@ ohos_shared_library("lbsservice_common") { } branch_protector_ret = "pac_ret" - sources = [ - "$LOCATION_COMMON_DIR/source/app_identity.cpp", - "$LOCATION_COMMON_DIR/source/common_hisysevent.cpp", - "$LOCATION_COMMON_DIR/source/common_utils.cpp", - "$LOCATION_COMMON_DIR/source/geo_address.cpp", - "$LOCATION_COMMON_DIR/source/geo_coding_mock_info.cpp", - "$LOCATION_COMMON_DIR/source/hook_utils.cpp", - "$LOCATION_COMMON_DIR/source/location.cpp", - "$LOCATION_COMMON_DIR/source/location_data_rdb_helper.cpp", - "$LOCATION_COMMON_DIR/source/location_data_rdb_manager.cpp", - "$LOCATION_COMMON_DIR/source/location_dumper.cpp", - "$LOCATION_COMMON_DIR/source/location_sa_load_manager.cpp", - "$LOCATION_COMMON_DIR/source/permission_manager.cpp", - "$LOCATION_COMMON_DIR/source/request.cpp", - "$LOCATION_COMMON_DIR/source/request_config.cpp", - "$LOCATION_COMMON_DIR/source/satellite_status.cpp", - "$LOCATION_COMMON_DIR/source/ui_extension_ability_connection.cpp", - ] + sources = local_base_sources deps = [] @@ -69,15 +71,69 @@ ohos_shared_library("lbsservice_common") { ] defines = [] - if (notification_distributed_notification_service_enable) { - defines += [ "NOTIFICATION_ENABLE" ] - } if (is_emulator) { defines += [ "EMULATOR_ENABLED" ] } + ldflags = [ + "-Wl,--as-needed", + "-Wl,--gc-sections", + ] + + cflags_cc = [ + "-ffunction-sections", + "-fdata-sections", + "-flto=thin", + "-Os", + ] + + # Used to control the export of dynamic library symbols. + version_script = "liblbsservice_common_version_script.txt" + innerapi_tags = [ "platformsdk" ] part_name = "location" subsystem_name = "location" } + +ohos_static_library("lbsservice_common_static") { + public_configs = [ ":location_common_config" ] + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + sources = local_base_sources + + deps = [] + + public_external_deps = [ + "ability_base:zuri", + "ability_runtime:extension_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "data_share:datashare_consumer", + "hilog:libhilog", + "hisysevent:libhisysevent", + "init:libbegetutil", + "ipc:ipc_single", + "os_account:os_account_innerkits", + "samgr:samgr_proxy", + ] + + defines = [] + + if (is_emulator) { + defines += [ "EMULATOR_ENABLED" ] + } + + part_name = "location" + subsystem_name = "location" +} diff --git a/frameworks/location_common/common/liblbsservice_common_version_script.txt b/frameworks/location_common/common/liblbsservice_common_version_script.txt new file mode 100644 index 00000000..ad489b28 --- /dev/null +++ b/frameworks/location_common/common/liblbsservice_common_version_script.txt @@ -0,0 +1,27 @@ +{ + global: + "*RequestConfig*"; + "*LocationSaLoadManager*"; + "*Unmarshalling*"; + "*GetLabel*"; + "*GetCapability*"; + "*Request*"; + "*SetLocationWorkingState*"; + "*LocationDumper*"; + "*CommonUtils*"; + "*GeocodingMockInfo*"; + "*PermissionManager*"; + "*AppIdentity*"; + "*QuerySwitchState*"; + "*WriteLocationInnerEvent*"; + "*Location*Location*"; + "*Location*CountDownLatch*"; + "*Location*GeoAddress*"; + "*Location*UIExtensionAbilityConnection*"; + "*Location*WriteGnssStateEvent*"; + "*Location*SatelliteStatus*"; + "*Location*WriteAppLocatingStateEvent*"; + "*ExecuteHookWhenAddWorkRecord*"; + local: + *; +}; \ No newline at end of file diff --git a/frameworks/location_common/common/source/common_hisysevent.cpp b/frameworks/location_common/common/source/common_hisysevent.cpp index cf83f53b..116e536a 100644 --- a/frameworks/location_common/common/source/common_hisysevent.cpp +++ b/frameworks/location_common/common/source/common_hisysevent.cpp @@ -64,13 +64,11 @@ void WriteLocationInnerEvent(const int event, std::initializer_list } flag = !flag; } - WriteEvent("LBS_CHR_INNER_EVENT", "EVENT", event, "NAMES", names, "VALUES", values); HookUtils::ExecuteHookWhenReportInnerInfo(event, names, values); } void WriteLocationInnerEvent(const int event, std::vector names, std::vector& values) { - WriteEvent("LBS_CHR_INNER_EVENT", "EVENT", event, "NAMES", names, "VALUES", values); HookUtils::ExecuteHookWhenReportInnerInfo(event, names, values); } } // namespace Location diff --git a/frameworks/location_common/common/source/common_utils.cpp b/frameworks/location_common/common/source/common_utils.cpp index 6610c438..b5e68b55 100644 --- a/frameworks/location_common/common/source/common_utils.cpp +++ b/frameworks/location_common/common/source/common_utils.cpp @@ -407,12 +407,13 @@ bool CommonUtils::CheckAppForUser(int32_t uid) { int currentUserId = 0; int userId = 0; - if (!GetCurrentUserId(currentUserId)) { - currentUserId = 100; + bool ret = GetCurrentUserId(currentUserId); + if (!ret) { + return true; } auto result = AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); if (result != ERR_OK) { - return false; + return true; } if (userId != currentUserId) { return false; diff --git a/frameworks/location_common/common/source/location_data_rdb_helper.cpp b/frameworks/location_common/common/source/location_data_rdb_helper.cpp index d40187b7..8d38bac9 100644 --- a/frameworks/location_common/common/source/location_data_rdb_helper.cpp +++ b/frameworks/location_common/common/source/location_data_rdb_helper.cpp @@ -29,6 +29,9 @@ namespace OHOS { namespace Location { +constexpr const char* LOCATION_DATA_COLUMN_KEYWORD = "KEYWORD"; +constexpr const char* LOCATION_DATA_COLUMN_VALUE = "VALUE"; + LocationDataRdbHelper* LocationDataRdbHelper::GetInstance() { static LocationDataRdbHelper data; diff --git a/frameworks/location_common/common/source/location_data_rdb_manager.cpp b/frameworks/location_common/common/source/location_data_rdb_manager.cpp index b3228870..fcc91d2a 100644 --- a/frameworks/location_common/common/source/location_data_rdb_manager.cpp +++ b/frameworks/location_common/common/source/location_data_rdb_manager.cpp @@ -26,6 +26,8 @@ const int UNKNOW_ERROR = -1; const int MAX_SIZE = 100; const char* LOCATION_SWITCH_MODE = "persist.location.switch_mode"; std::mutex LocationDataRdbManager::mutex_; +const std::string LOCATION_ENHANCE_STATUS = "location_enhance_status"; + std::string LocationDataRdbManager::GetLocationDataUri(std::string key) { int userId = 0; diff --git a/frameworks/location_common/common/source/request.cpp b/frameworks/location_common/common/source/request.cpp index 3f862c08..74193140 100644 --- a/frameworks/location_common/common/source/request.cpp +++ b/frameworks/location_common/common/source/request.cpp @@ -351,5 +351,14 @@ sptr Request::GetLocationErrorCallBack() return locationErrorcallBack_; } +void Request::SetLocatorCallbackRecipient(const sptr& recipient) +{ + locatorCallbackRecipient_ = recipient; +} + +sptr Request::GetLocatorCallbackRecipient() +{ + return locatorCallbackRecipient_; +} } // namespace Location } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/geofence_sdk/BUILD.gn b/frameworks/native/geofence_sdk/BUILD.gn index 3f2d97db..f484f32d 100644 --- a/frameworks/native/geofence_sdk/BUILD.gn +++ b/frameworks/native/geofence_sdk/BUILD.gn @@ -19,9 +19,15 @@ config("geofence_sdk_config") { include_dirs = [ "$LOCATION_ROOT_DIR/interfaces/inner_api/include", "$LOCATION_ROOT_DIR/frameworks/native/notification/include", + "$LOCATION_ROOT_DIR/frameworks/js/napi/include", ] } +local_base_sources = [ + "$LOCATION_NATIVE_DIR/geofence_sdk/source/geofence_request.cpp", + "$LOCATION_NATIVE_DIR/geofence_sdk/source/geofence_sdk.cpp", +] + ohos_shared_library("geofence_sdk") { install_enable = true @@ -34,45 +40,76 @@ ohos_shared_library("geofence_sdk") { } branch_protector_ret = "pac_ret" - sources = [ - "$LOCATION_COMMON_DIR/source/geofence_request.cpp", - "$LOCATION_NATIVE_DIR/geofence_sdk/source/geofence_napi.cpp", - "$LOCATION_NATIVE_DIR/geofence_sdk/source/geofence_sdk.cpp", - "$LOCATION_NATIVE_DIR/geofence_sdk/source/location_gnss_geofence_callback_host.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/locator_proxy.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/napi_util.cpp", - ] + sources = local_base_sources + deps = [ "$LOCATION_COMMON_DIR:lbsservice_common" ] + public_external_deps = [ - "ability_base:zuri", - "ability_runtime:napi_common", - "ability_runtime:wantagent_innerkits", - "access_token:libaccesstoken_sdk", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "data_share:datashare_consumer", "hilog:libhilog", - "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_single", - "napi:ace_napi", - "os_account:os_account_innerkits", "samgr:samgr_proxy", ] + defines = [] + + if (notification_distributed_notification_service_enable) { + public_external_deps += [ "distributed_notification_service:ans_innerkits" ] + defines += [ "NOTIFICATION_ENABLE" ] + } + + if (is_emulator) { + defines += [ "EMULATOR_ENABLED" ] + } + + cflags_cc = [ + "-std=c++17", + "-fno-rtti", + "-ffunction-sections", + "-fdata-sections", + "-Os", + ] + + ldflags = [ + "-fPIC", + "-Wl,-E", + "-Wl,--as-needed", + "-Wl,--gc-sections", + ] + + # Used to control the export of dynamic library symbols. + version_script = "libgeofence_sdk_version_script.txt" + + innerapi_tags = [ "platformsdk" ] + part_name = "location" + subsystem_name = "location" +} + +ohos_static_library("geofence_sdk_static") { + public_configs = [ ":geofence_sdk_config" ] + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + sources = local_base_sources + + deps = [ "$LOCATION_COMMON_DIR:lbsservice_common" ] + + public_external_deps = [ + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_single", + "samgr:samgr_proxy", + ] + + defines = [] + if (notification_distributed_notification_service_enable) { - sources += [ "$LOCATION_NATIVE_DIR/notification/src/notification_napi.cpp" ] - sources += [ "$LOCATION_NATIVE_DIR/notification/src/notification_napi_convert_content.cpp" ] - sources += [ "$LOCATION_NATIVE_DIR/notification/src/notification_napi_convert_liveview.cpp" ] - sources += [ "$LOCATION_NATIVE_DIR/notification/src/notification_napi_convert_notification.cpp" ] - sources += [ "$LOCATION_NATIVE_DIR/notification/src/notification_napi_convert_request.cpp" ] - sources += - [ "$LOCATION_NATIVE_DIR/notification/src/notification_napi_utils.cpp" ] public_external_deps += [ "distributed_notification_service:ans_innerkits" ] - public_external_deps += [ "ability_base:want" ] - public_external_deps += [ "image_framework:image" ] - public_external_deps += [ "relational_store:native_rdb" ] defines += [ "NOTIFICATION_ENABLE" ] } @@ -90,7 +127,6 @@ ohos_shared_library("geofence_sdk") { "-Wl,-E", ] - innerapi_tags = [ "platformsdk" ] part_name = "location" subsystem_name = "location" } diff --git a/frameworks/native/geofence_sdk/libgeofence_sdk_version_script.txt b/frameworks/native/geofence_sdk/libgeofence_sdk_version_script.txt new file mode 100644 index 00000000..d2e2821f --- /dev/null +++ b/frameworks/native/geofence_sdk/libgeofence_sdk_version_script.txt @@ -0,0 +1,36 @@ +{ + global: + "*GeofenceManager*GetInstance*"; + "*GeofenceManager*AddFenceV9*"; + "*GeofenceManager*RemoveFenceV9*"; + "*DoAsyncWork*"; + "*LocationToJs*"; + "*JsObjToReverseGeoCodeRequest*"; + "*GeoAddressesToJsObj*"; + "*JsObjToGeoCodeRequest*"; + "*JsObjToCommand*"; + "*SetEnumPropertyByInteger*"; + "*CheckIfParamIsFunctionType*"; + "*JsObjToLocationRequest*"; + "*JsObjToGeoFenceRequest*"; + "*GeofenceRequest*"; + "*JsObjToCachedLocationRequest*"; + "*JsObjToCurrentLocationRequest*"; + "*UndefinedNapiValue*"; + "*CountryCodeToJs*"; + "*JsObjectToInt*"; + "*GetLocationArray*"; + "*JsObjToRevGeocodeMock*"; + "*LocatingRequiredDataToJsObj*"; + "*CheckIfParamIsObjectType*"; + "*JsObjToLocatingRequiredDataConfig*"; + "*ParseGnssGeofenceRequest*"; + "*LocationGnssGeofenceCallbackNapi*"; + "*Unmarshalling*"; + "*GetErrorMsgByCode*"; + "*GeofenceManager*GetGeofenceSupportedCoordTypes*"; + "*GeofenceSdk*"; + "*LocatorProxy*"; + local: + *; +}; \ No newline at end of file diff --git a/frameworks/location_common/common/source/geofence_request.cpp b/frameworks/native/geofence_sdk/source/geofence_request.cpp similarity index 53% rename from frameworks/location_common/common/source/geofence_request.cpp rename to frameworks/native/geofence_sdk/source/geofence_request.cpp index 2e0675d9..dfd97268 100644 --- a/frameworks/location_common/common/source/geofence_request.cpp +++ b/frameworks/native/geofence_sdk/source/geofence_request.cpp @@ -24,6 +24,131 @@ namespace OHOS { namespace Location { +GeofenceRequest::GeofenceRequest() +{ + callback_ = nullptr; + scenario_ = -1; + fenceId_ = -1; +} + +GeofenceRequest::GeofenceRequest(GeofenceRequest& geofenceRequest) +{ + this->SetGeofence(geofenceRequest.GetGeofence()); + this->SetScenario(geofenceRequest.GetScenario()); + this->SetWantAgent(geofenceRequest.GetWantAgent()); + this->SetGeofenceTransitionEventList(geofenceRequest.GetGeofenceTransitionEventList()); +#ifdef NOTIFICATION_ENABLE + this->SetNotificationRequestList(geofenceRequest.GetNotificationRequestList()); +#endif + this->SetGeofenceTransitionCallback(geofenceRequest.GetGeofenceTransitionCallback()); + this->SetFenceId(geofenceRequest.GetFenceId()); + this->SetBundleName(geofenceRequest.GetBundleName()); +} + +GeofenceRequest::~GeofenceRequest() {} + +GeoFence GeofenceRequest::GetGeofence() +{ + return geofence_; +} + +void GeofenceRequest::SetGeofence(GeoFence geofence) +{ + geofence_ = geofence; +} + +int GeofenceRequest::GetScenario() +{ + return scenario_; +} + +void GeofenceRequest::SetScenario(int scenario) +{ + scenario_ = scenario; +} + +void GeofenceRequest::SetWantAgent(const AbilityRuntime::WantAgent::WantAgent wantAgent) +{ + wantAgent_ = wantAgent; +} + +AbilityRuntime::WantAgent::WantAgent GeofenceRequest::GetWantAgent() +{ + return wantAgent_; +} + +std::vector GeofenceRequest::GetGeofenceTransitionEventList() +{ + std::unique_lock lock(geofenceRequestMutex_); + return transitionStatusList_; +} + +void GeofenceRequest::SetGeofenceTransitionEvent(GeofenceTransitionEvent status) +{ + std::unique_lock lock(geofenceRequestMutex_); + transitionStatusList_.push_back(status); +} + +void GeofenceRequest::SetGeofenceTransitionEventList(std::vector statusList) +{ + std::unique_lock lock(geofenceRequestMutex_); + for (auto it = statusList.begin(); it != statusList.end(); ++it) { + transitionStatusList_.push_back(*it); + } +} + +#ifdef NOTIFICATION_ENABLE +std::vector GeofenceRequest::GetNotificationRequestList() +{ + std::unique_lock lock(geofenceRequestMutex_); + return notificationRequestList_; +} + +void GeofenceRequest::SetNotificationRequest(OHOS::Notification::NotificationRequest request) +{ + std::unique_lock lock(geofenceRequestMutex_); + notificationRequestList_.push_back(request); +} + +void GeofenceRequest::SetNotificationRequestList(std::vector requestList) +{ + std::unique_lock lock(geofenceRequestMutex_); + for (auto it = requestList.begin(); it != requestList.end(); ++it) { + notificationRequestList_.push_back(*it); + } +} +#endif + +void GeofenceRequest::SetGeofenceTransitionCallback(const sptr& callback) +{ + callback_ = callback; +} + +sptr GeofenceRequest::GetGeofenceTransitionCallback() +{ + return callback_; +} + +int GeofenceRequest::GetFenceId() +{ + return fenceId_; +} + +void GeofenceRequest::SetFenceId(int fenceId) +{ + fenceId_ = fenceId; +} + +std::string GeofenceRequest::GetBundleName() +{ + return bundleName_; +} + +void GeofenceRequest::SetBundleName(std::string bundleName) +{ + bundleName_ = bundleName; +} + void GeofenceRequest::ReadFromParcel(Parcel& data) { std::unique_lock lock(geofenceRequestMutex_); diff --git a/frameworks/native/geofence_sdk/source/geofence_sdk.cpp b/frameworks/native/geofence_sdk/source/geofence_sdk.cpp index 942e604f..2d56c9eb 100644 --- a/frameworks/native/geofence_sdk/source/geofence_sdk.cpp +++ b/frameworks/native/geofence_sdk/source/geofence_sdk.cpp @@ -35,10 +35,27 @@ GeofenceManager::GeofenceManager() GeofenceManager::~GeofenceManager() {} +void GeofenceManager::ResetGeofenceSdkProxy(const wptr &remote) +{ + if (remote == nullptr) { + LBSLOGE(GEOFENCE_SDK, "%{public}s: remote is nullptr.", __func__); + return; + } + if (client_ == nullptr || !isServerExist_) { + LBSLOGE(GEOFENCE_SDK, "%{public}s: proxy is nullptr.", __func__); + return; + } + if (remote.promote() != nullptr) { + remote.promote()->RemoveDeathRecipient(recipient_); + } + isServerExist_ = false; + LBSLOGI(GEOFENCE_SDK, "%{public}s: finish.", __func__); +} + sptr GeofenceManager::GetProxy() { std::unique_lock lock(mutex_); - if (client_ != nullptr) { + if (client_ != nullptr && isServerExist_) { return client_; } @@ -52,6 +69,12 @@ sptr GeofenceManager::GetProxy() LBSLOGE(GEOFENCE_SDK, "%{public}s: get remote service failed.", __func__); return nullptr; } + recipient_ = sptr(new (std::nothrow) GeofenceManagerDeathRecipient(*this)); + if ((obj->IsProxyObject()) && (!obj->AddDeathRecipient(recipient_))) { + LBSLOGE(GEOFENCE_SDK, "%{public}s: deathRecipient add failed.", __func__); + return nullptr; + } + isServerExist_ = true; client_ = sptr(new (std::nothrow) GeofenceSdk(obj)); return client_; } @@ -91,7 +114,6 @@ LocationErrCode GeofenceManager::AddGnssGeofence(std::shared_ptr proxy = GetProxy(); if (proxy == nullptr) { LBSLOGE(GEOFENCE_SDK, "%{public}s get proxy failed.", __func__); @@ -160,7 +182,7 @@ LocationErrCode GeofenceSdk::HandleGnssfenceRequest( } request->Marshalling(data); LocationErrCode errorCode = SendMsgWithDataReplyV9(static_cast(code), data, reply); - LBSLOGD(GEOFENCE_SDK, "Transact ErrCodes = %{public}d", errorCode); + LBSLOGI(GEOFENCE_SDK, "Transact ErrCodes = %{public}d", errorCode); return errorCode; } @@ -182,7 +204,7 @@ LocationErrCode GeofenceSdk::RemoveGnssGeofence(std::shared_ptr data.WriteInt32(request->GetFenceId()); LocationErrCode errorCode = SendMsgWithDataReplyV9( static_cast(LocatorInterfaceCode::REMOVE_GNSS_GEOFENCE), data, reply); - LBSLOGD(GEOFENCE_SDK, "Transact ErrCodes = %{public}d", errorCode); + LBSLOGI(GEOFENCE_SDK, "Transact ErrCodes = %{public}d", errorCode); return errorCode; } @@ -214,12 +236,12 @@ LocationErrCode GeofenceSdk::SendMsgWithDataReplyV9(const int msgId, MessageParc LBSLOGE(GEOFENCE_SDK, "SendMsgWithDataReply remote is null"); return ERRCODE_SERVICE_UNAVAILABLE; } + LBSLOGI(GEOFENCE_SDK, "%{public}s: %{public}d", __func__, msgId); int error = remote->SendRequest(msgId, data, reply, option); if (error != NO_ERROR) { LBSLOGE(GEOFENCE_SDK, "msgid = %{public}d, send request error: %{public}d", msgId, error); return ERRCODE_SERVICE_UNAVAILABLE; } - LBSLOGD(GEOFENCE_SDK, "Proxy::SendMsgWithDataReply result from server."); return LocationErrCode(reply.ReadInt32()); } } diff --git a/frameworks/native/locator_agent/BUILD.gn b/frameworks/native/locator_agent/BUILD.gn index a0a6d457..411e5cd8 100644 --- a/frameworks/native/locator_agent/BUILD.gn +++ b/frameworks/native/locator_agent/BUILD.gn @@ -38,17 +38,27 @@ ohos_shared_library("locator_agent") { cfi_cross_dso = true debug = false } + branch_protector_ret = "pac_ret" deps = [ "$LOCATION_COMMON_DIR:lbsservice_common" ] external_deps = [ - "c_utils:utils", "hilog:libhilog", "ipc:ipc_single", "samgr:samgr_proxy", ] + ldflags = [ + "-Wl,--as-needed", + "-Wl,--gc-sections", + ] + + cflags_cc = [ + "-ffunction-sections", + "-fdata-sections", + ] + defines = [] if (is_emulator) { defines += [ "EMULATOR_ENABLED" ] diff --git a/frameworks/native/locator_sdk/BUILD.gn b/frameworks/native/locator_sdk/BUILD.gn index 43f79231..f8dfbbd5 100644 --- a/frameworks/native/locator_sdk/BUILD.gn +++ b/frameworks/native/locator_sdk/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022 Huawei Device Co., Ltd. +# Copyright (C) 2022-2024 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -21,9 +21,26 @@ config("locator_sdk_config") { include_dirs = [ "$LOCATION_ROOT_DIR/interfaces/inner_api/include", "$LOCATION_ROOT_DIR/frameworks/js/napi/include", + "$LOCATION_ROOT_DIR/services/utils/lbsutils/include", + "$LOCATION_ROOT_DIR/services/utils/inner_api", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk/include", ] } +local_base_sources = [ + "$LOCATION_NATIVE_DIR/locator_sdk/source/country_code_callback_host.cpp", + "$LOCATION_NATIVE_DIR/locator_sdk/source/country_code_manager.cpp", + "$LOCATION_NATIVE_DIR/locator_sdk/source/location_data_manager.cpp", + "$LOCATION_NATIVE_DIR/locator_sdk/source/location_data_rdb_observer.cpp", + "$LOCATION_NATIVE_DIR/locator_sdk/source/location_switch_callback_host.cpp", + "$LOCATION_NATIVE_DIR/locator_sdk/source/locator.cpp", + "$LOCATION_NATIVE_DIR/locator_sdk/source/locator_callback_host.cpp", + "$LOCATION_NATIVE_DIR/locator_sdk/source/locator_impl.cpp", + "$LOCATION_NATIVE_DIR/locator_sdk/source/locator_proxy.cpp", + "$LOCATION_NATIVE_DIR/locator_sdk/source/switch_callback_proxy.cpp", + "$LOCATION_ROOT_DIR/services/utils/lbsutils/source/lbs_res_loader.cpp", +] + ohos_shared_library("locator_sdk") { install_enable = true @@ -34,48 +51,93 @@ ohos_shared_library("locator_sdk") { cfi_cross_dso = true debug = false } + branch_protector_ret = "pac_ret" - sources = [ - "$LOCATION_NATIVE_DIR/locator_sdk/source/cached_locations_callback_host.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/country_code_callback_host.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/country_code_manager.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/gnss_status_callback_host.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/locating_required_data_callback_host.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/location_data_manager.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/location_data_rdb_observer.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/location_error_callback_host.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/location_switch_callback_host.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/locator.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/locator_callback_host.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/locator_impl.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/locator_proxy.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/napi_util.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/nmea_message_callback_host.cpp", - "$LOCATION_NATIVE_DIR/locator_sdk/source/switch_callback_proxy.cpp", - ] + sources = local_base_sources + + deps = [ "$LOCATION_COMMON_DIR:lbsservice_common" ] + + public_external_deps = [ + "ability_runtime:dataobs_manager", + "data_share:datashare_consumer", + "hilog:libhilog", + "init:libbeget_proxy", + "ipc:ipc_single", + "samgr:samgr_proxy", + ] + + defines = [] + + if (i18n_enable) { + defines += [ "I18N_ENABLE" ] + } + + if (telephony_core_service_enable) { + public_external_deps += [ "core_service:tel_core_service_api" ] + defines += [ "TEL_CORE_SERVICE_ENABLE" ] + } + + if (telephony_cellular_data_enable) { + public_external_deps += [ "cellular_data:tel_cellular_data_api" ] + defines += [ "TEL_CELLULAR_DATA_ENABLE" ] + } + + if (is_emulator) { + defines += [ "EMULATOR_ENABLED" ] + } + + cflags_cc = [ + "-std=c++17", + "-fno-rtti", + "-ffunction-sections", + "-fdata-sections", + "-flto=thin", + "-Os", + ] + + ldflags = [ + "-fPIC", + "-Wl,-E", + "-Wl,--as-needed", + "-Wl,--gc-sections", + ] + + # Used to control the export of dynamic library symbols. + version_script = "liblocator_sdk_version_script.txt" + + innerapi_tags = [ "platformsdk" ] + part_name = "location" + subsystem_name = "location" +} + +ohos_static_library("locator_sdk_static") { + public_configs = [ ":locator_sdk_config" ] + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + branch_protector_ret = "pac_ret" + + sources = local_base_sources deps = [ "$LOCATION_COMMON_DIR:lbsservice_common" ] public_external_deps = [ - "ability_base:zuri", "ability_runtime:dataobs_manager", - "ability_runtime:wantagent_innerkits", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", "data_share:datashare_consumer", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_single", - "libuv:uv", - "napi:ace_napi", "samgr:samgr_proxy", ] defines = [] if (i18n_enable) { - public_external_deps += [ "i18n:intl_util" ] defines += [ "I18N_ENABLE" ] } @@ -103,7 +165,6 @@ ohos_shared_library("locator_sdk") { "-Wl,-E", ] - innerapi_tags = [ "platformsdk" ] part_name = "location" subsystem_name = "location" } diff --git a/interfaces/inner_api/include/country_code_callback_host.h b/frameworks/native/locator_sdk/include/country_code_callback_host.h similarity index 72% rename from interfaces/inner_api/include/country_code_callback_host.h rename to frameworks/native/locator_sdk/include/country_code_callback_host.h index 736a4521..1ea69da5 100644 --- a/interfaces/inner_api/include/country_code_callback_host.h +++ b/frameworks/native/locator_sdk/include/country_code_callback_host.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -18,28 +18,15 @@ #include "i_country_code_callback.h" #include "iremote_stub.h" -#include "napi/native_api.h" -#include "uv.h" #include "country_code.h" namespace OHOS { namespace Location { class CountryCodeCallbackHost : public IRemoteStub { public: - CountryCodeCallbackHost(); - virtual ~CountryCodeCallbackHost(); virtual int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; void OnCountryCodeChange(const std::shared_ptr& country) override; - bool Send(const std::shared_ptr& country); - void SetEnv(napi_env env); - void SetCallback(napi_ref cb); - void DeleteHandler(); - void UvQueueWork(uv_loop_s* loop, uv_work_t* work); -private: - napi_env env_; - napi_ref handlerCb_; - std::mutex mutex_; }; } // namespace Location } // namespace OHOS diff --git a/frameworks/native/locator_sdk/include/location_switch_callback_host.h b/frameworks/native/locator_sdk/include/location_switch_callback_host.h new file mode 100644 index 00000000..eab887ee --- /dev/null +++ b/frameworks/native/locator_sdk/include/location_switch_callback_host.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LOCATION_SWITCH_CALLBACK_HOST_H +#define LOCATION_SWITCH_CALLBACK_HOST_H + +#include "i_switch_callback.h" + +#include "iremote_stub.h" + +namespace OHOS { +namespace Location { +class LocationSwitchCallbackHost : public IRemoteStub { +public: + virtual int OnRemoteRequest( + uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; + void OnSwitchChange(int switchState) override; +}; +} // namespace Location +} // namespace OHOS +#endif // LOCATION_SWITCH_CALLBACK_HOST_H diff --git a/frameworks/native/locator_sdk/include/locator_callback_host.h b/frameworks/native/locator_sdk/include/locator_callback_host.h new file mode 100644 index 00000000..902300cf --- /dev/null +++ b/frameworks/native/locator_sdk/include/locator_callback_host.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LOCATOR_CALLBACK_HOST_H +#define LOCATOR_CALLBACK_HOST_H + +#include "iremote_stub.h" +#include "i_locator_callback.h" + +namespace OHOS { +namespace Location { +class LocatorCallbackHost : public IRemoteStub { +public: + virtual int OnRemoteRequest(uint32_t code, + MessageParcel& data, MessageParcel& reply, MessageOption& option) override; + void OnLocationReport(const std::unique_ptr& location) override; + void OnLocatingStatusChange(const int status) override; + void OnErrorReport(const int errorCode) override; +}; +} // namespace Location +} // namespace OHOS +#endif // LOCATOR_CALLBACK_HOST_H diff --git a/frameworks/native/locator_sdk/liblocator_sdk_version_script.txt b/frameworks/native/locator_sdk/liblocator_sdk_version_script.txt new file mode 100644 index 00000000..b7281a67 --- /dev/null +++ b/frameworks/native/locator_sdk/liblocator_sdk_version_script.txt @@ -0,0 +1,11 @@ +{ + global: + "*LocatorImpl*"; + "*GetInstance*"; + "*LocatorProxy*"; + "*LocationSwitchCallbackHost*"; + "*LocatorCallbackHost*"; + "*CountryCodeCallbackHost*"; + local: + *; +}; \ No newline at end of file diff --git a/frameworks/native/locator_sdk/source/country_code_callback_host.cpp b/frameworks/native/locator_sdk/source/country_code_callback_host.cpp index 26f2aace..8bdca176 100644 --- a/frameworks/native/locator_sdk/source/country_code_callback_host.cpp +++ b/frameworks/native/locator_sdk/source/country_code_callback_host.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,25 +14,10 @@ */ #include "country_code_callback_host.h" -#include "common_utils.h" -#include "ipc_skeleton.h" #include "location_log.h" -#include "napi/native_api.h" -#include "country_code.h" -#include "napi_util.h" namespace OHOS { namespace Location { -CountryCodeCallbackHost::CountryCodeCallbackHost() -{ - env_ = nullptr; - handlerCb_ = nullptr; -} - -CountryCodeCallbackHost::~CountryCodeCallbackHost() -{ -} - int CountryCodeCallbackHost::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { @@ -56,128 +41,8 @@ int CountryCodeCallbackHost::OnRemoteRequest( return 0; } -bool CountryCodeCallbackHost::Send(const std::shared_ptr& country) -{ - std::unique_lock guard(mutex_); - uv_loop_s *loop = nullptr; - if (env_ == nullptr) { - LBSLOGE(COUNTRY_CODE_CALLBACK, "env_ == nullptr."); - return false; - } - if (country == nullptr) { - LBSLOGE(COUNTRY_CODE_CALLBACK, "country == nullptr."); - return false; - } - NAPI_CALL_BASE(env_, napi_get_uv_event_loop(env_, &loop), false); - if (loop == nullptr) { - LBSLOGE(COUNTRY_CODE_CALLBACK, "loop == nullptr."); - return false; - } - uv_work_t *work = new (std::nothrow) uv_work_t; - if (work == nullptr) { - LBSLOGE(COUNTRY_CODE_CALLBACK, "work == nullptr."); - return false; - } - auto context = new (std::nothrow) CountryCodeContext(env_); - if (context == nullptr) { - LBSLOGE(COUNTRY_CODE_CALLBACK, "context == nullptr."); - delete work; - return false; - } - context->env = env_; - context->callback[SUCCESS_CALLBACK] = handlerCb_; - context->country = country; - work->data = context; - UvQueueWork(loop, work); - return true; -} - -void CountryCodeCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) -{ - uv_queue_work( - loop, - work, - [](uv_work_t *work) {}, - [](uv_work_t *work, int status) { - CountryCodeContext *context = nullptr; - napi_handle_scope scope = nullptr; - if (work == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "work is nullptr!"); - return; - } - context = static_cast(work->data); - if (context == nullptr || context->env == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "context is nullptr!"); - delete work; - return; - } - NAPI_CALL_RETURN_VOID(context->env, napi_open_handle_scope(context->env, &scope)); - if (scope == nullptr) { - LBSLOGE(COUNTRY_CODE_CALLBACK, "scope is nullptr"); - delete context; - delete work; - return; - } - napi_value jsEvent; - CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_create_object(context->env, &jsEvent), - scope, context, work); - if (context->country) { - CountryCodeToJs(context->env, context->country, jsEvent); - } else { - LBSLOGE(LOCATOR_STANDARD, "country is nullptr!"); - } - if (context->callback[0] != nullptr) { - napi_value undefine; - napi_value handler = nullptr; - CHK_NAPI_ERR_CLOSE_SCOPE(context->env, - napi_get_undefined(context->env, &undefine), scope, context, work); - CHK_NAPI_ERR_CLOSE_SCOPE(context->env, - napi_get_reference_value(context->env, context->callback[SUCCESS_CALLBACK], &handler), - scope, context, work); - if (napi_call_function(context->env, nullptr, handler, 1, &jsEvent, &undefine) != napi_ok) { - LBSLOGE(COUNTRY_CODE_CALLBACK, "Report event failed"); - } - } - NAPI_CALL_RETURN_VOID(context->env, napi_close_handle_scope(context->env, scope)); - delete context; - delete work; - }); -} - void CountryCodeCallbackHost::OnCountryCodeChange(const std::shared_ptr& country) { - LBSLOGD(COUNTRY_CODE_CALLBACK, "CountryCodeCallbackHost::OnCountryCodeChange"); - Send(country); -} - -void CountryCodeCallbackHost::SetEnv(napi_env env) -{ - std::unique_lock guard(mutex_); - env_ = env; -} - -void CountryCodeCallbackHost::SetCallback(napi_ref cb) -{ - std::unique_lock guard(mutex_); - handlerCb_ = cb; -} - -void CountryCodeCallbackHost::DeleteHandler() -{ - std::unique_lock guard(mutex_); - if (handlerCb_ == nullptr || env_ == nullptr) { - LBSLOGE(COUNTRY_CODE_CALLBACK, "handler or env is nullptr."); - return; - } - auto context = new (std::nothrow) AsyncContext(env_); - if (context == nullptr) { - LBSLOGE(COUNTRY_CODE_CALLBACK, "context == nullptr."); - return; - } - context->env = env_; - context->callback[SUCCESS_CALLBACK] = handlerCb_; - DeleteQueueWork(context); - handlerCb_ = nullptr; } } // namespace Location } // namespace OHOS diff --git a/frameworks/native/locator_sdk/source/country_code_manager.cpp b/frameworks/native/locator_sdk/source/country_code_manager.cpp index 0b157be6..03d3a065 100644 --- a/frameworks/native/locator_sdk/source/country_code_manager.cpp +++ b/frameworks/native/locator_sdk/source/country_code_manager.cpp @@ -19,11 +19,7 @@ #ifdef TEL_CORE_SERVICE_ENABLE #include "core_service_client.h" #endif -#ifdef I18N_ENABLE -#include "locale_config.h" -#endif #include "parameter.h" - #include "common_event_manager.h" #include "common_event_support.h" #include "common_utils.h" @@ -31,6 +27,7 @@ #include "country_code.h" #include "location_log.h" #include "locator_impl.h" +#include "lbs_res_loader.h" namespace OHOS { namespace Location { @@ -44,7 +41,6 @@ CountryCodeManager::CountryCodeManager() { lastCountryByLocation_ = std::make_shared(); lastCountry_ = std::make_shared(); - countryCodeCallback_ = std::make_unique>>(); simSubscriber_ = nullptr; networkSubscriber_ = nullptr; SubscribeLocaleConfigEvent(); @@ -57,13 +53,12 @@ CountryCodeManager::~CountryCodeManager() void CountryCodeManager::NotifyAllListener() { std::unique_lock lock(countryCodeCallbackMutex_); - if (lastCountry_ == nullptr || countryCodeCallback_ == nullptr) { + if (lastCountry_ == nullptr) { LBSLOGE(COUNTRY_CODE, "NotifyAllListener cancel, para is invalid"); return; } auto country = std::make_shared(*lastCountry_); - for (auto iter = countryCodeCallback_->begin(); iter != countryCodeCallback_->end(); iter++) { - sptr callback = (iter->second); + for (auto callback : countryCodeCallbacks_) { if (callback) { callback->OnCountryCodeChange(country); } @@ -74,7 +69,7 @@ void CountryCodeManager::RegisterCountryCodeCallback(const sptr& { std::unique_lock lock(countryCodeCallbackMutex_, std::defer_lock); lock.lock(); - if (callback == nullptr || countryCodeCallback_ == nullptr) { + if (callback == nullptr) { LBSLOGE(COUNTRY_CODE, "callback is invalid"); lock.unlock(); return; @@ -86,11 +81,10 @@ void CountryCodeManager::RegisterCountryCodeCallback(const sptr& lock.unlock(); return; } - countryCodeCallback_->erase(uid); - countryCodeCallback_->insert(std::make_pair(uid, countryCodeCallback)); - LBSLOGD(COUNTRY_CODE, "after uid:%{public}d register, countryCodeCallback_ size:%{public}s", - uid, std::to_string(countryCodeCallback_->size()).c_str()); - if (countryCodeCallback_->size() != 1) { + countryCodeCallbacks_.push_back(countryCodeCallback); + LBSLOGD(COUNTRY_CODE, "after uid:%{public}d register, countryCodeCallbacks_ size:%{public}s", + uid, std::to_string(countryCodeCallbacks_.size()).c_str()); + if (countryCodeCallbacks_.size() != 1) { lock.unlock(); return; } @@ -103,7 +97,7 @@ void CountryCodeManager::UnregisterCountryCodeCallback(const sptr { std::unique_lock lock(countryCodeCallbackMutex_, std::defer_lock); lock.lock(); - if (callback == nullptr || countryCodeCallback_ == nullptr) { + if (callback == nullptr) { LBSLOGE(COUNTRY_CODE, "unregister an invalid callback"); lock.unlock(); return; @@ -114,19 +108,27 @@ void CountryCodeManager::UnregisterCountryCodeCallback(const sptr lock.unlock(); return; } - - pid_t uid = -1; - for (auto iter = countryCodeCallback_->begin(); iter != countryCodeCallback_->end(); iter++) { - sptr remoteObject = (iter->second)->AsObject(); + size_t i = 0; + for (; i < countryCodeCallbacks_.size(); i++) { + if (countryCodeCallbacks_[i] == nullptr) { + continue; + } + sptr remoteObject = countryCodeCallbacks_[i]->AsObject(); if (remoteObject == callback) { - uid = iter->first; break; } } - countryCodeCallback_->erase(uid); - LBSLOGD(COUNTRY_CODE, "after uid:%{public}d unregister, countryCodeCallback_ size:%{public}s", - uid, std::to_string(countryCodeCallback_->size()).c_str()); - if (countryCodeCallback_->size() != 0) { + if (i >= countryCodeCallbacks_.size()) { + LBSLOGD(GNSS, "countryCode callback is not in vector"); + lock.unlock(); + return; + } + if (countryCodeCallbacks_.size() > 0) { + countryCodeCallbacks_.erase(countryCodeCallbacks_.begin() + i); + } + LBSLOGD(COUNTRY_CODE, "after unregister, countryCodeCallbacks_ size:%{public}s", + std::to_string(countryCodeCallbacks_.size()).c_str()); + if (countryCodeCallbacks_.size() != 0) { lock.unlock(); return; } @@ -138,7 +140,7 @@ void CountryCodeManager::UnregisterCountryCodeCallback(const sptr bool CountryCodeManager::IsCountryCodeRegistered() { std::unique_lock lock(countryCodeCallbackMutex_); - return countryCodeCallback_->size() != 0; + return countryCodeCallbacks_.size() != 0; } std::string CountryCodeManager::GetCountryCodeByLastLocation() @@ -257,7 +259,8 @@ std::shared_ptr CountryCodeManager::GetIsoCountryCode() #endif #ifdef I18N_ENABLE if (countryCodeStr8.empty()) { - countryCodeStr8 = Global::I18n::LocaleConfig::GetSystemRegion(); + LbsResLoader resLoader; + countryCodeStr8 = resLoader.GetSystemRegion(); type = COUNTRY_CODE_FROM_LOCALE; } #endif @@ -276,16 +279,16 @@ std::shared_ptr CountryCodeManager::GetIsoCountryCode() bool CountryCodeManager::SubscribeSimEvent() { LBSLOGD(COUNTRY_CODE, "SubscribeSimEvent"); - OHOS::EventFwk::MatchingSkills matchingSkills; - matchingSkills.AddEvent(SIM_STATE_CHANGE_ACTION); - OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_STATE_CHANGED); + EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); std::unique_lock lock(simSubscriberMutex_, std::defer_lock); lock.lock(); if (simSubscriber_ == nullptr) { simSubscriber_ = std::make_shared(subscriberInfo); } lock.unlock(); - bool result = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(simSubscriber_); + bool result = EventFwk::CommonEventManager::SubscribeCommonEvent(simSubscriber_); if (!result) { LBSLOGE(COUNTRY_CODE, "SubscribeSimEvent failed."); } @@ -295,16 +298,16 @@ bool CountryCodeManager::SubscribeSimEvent() bool CountryCodeManager::SubscribeNetworkStatusEvent() { LBSLOGD(COUNTRY_CODE, "SubscribeNetworkStatusEvent"); - OHOS::EventFwk::MatchingSkills matchingSkills; - matchingSkills.AddEvent(SEARCH_NET_WORK_STATE_CHANGE_ACTION); - OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_NETWORK_STATE_CHANGED); + EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); std::unique_lock lock(networkSubscriberMutex_, std::defer_lock); lock.lock(); if (networkSubscriber_ == nullptr) { networkSubscriber_ = std::make_shared(subscriberInfo); } lock.unlock(); - bool result = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(networkSubscriber_); + bool result = EventFwk::CommonEventManager::SubscribeCommonEvent(networkSubscriber_); if (!result) { LBSLOGE(COUNTRY_CODE, "SubscribeNetworkStatusEvent failed."); } @@ -323,7 +326,7 @@ bool CountryCodeManager::SubscribeLocaleConfigEvent() manager->GetIsoCountryCode(); }; - int ret = WatchParameter(LOCALE_KEY.c_str(), eventCallback, nullptr); + int ret = WatchParameter(LOCALE_KEY, eventCallback, nullptr); if (ret != SUCCESS) { LBSLOGD(COUNTRY_CODE, "WatchParameter fail"); return false; @@ -419,7 +422,7 @@ void CountryCodeManager::ReSubscribeEvent() { std::unique_lock lock(countryCodeCallbackMutex_, std::defer_lock); lock.lock(); - if (countryCodeCallback_->size() <= 0) { + if (countryCodeCallbacks_.size() <= 0) { LBSLOGD(COUNTRY_CODE, "no valid callback registed, no need to subscribe"); lock.unlock(); return; @@ -433,7 +436,7 @@ void CountryCodeManager::ReUnsubscribeEvent() { std::unique_lock lock(countryCodeCallbackMutex_, std::defer_lock); lock.lock(); - if (countryCodeCallback_->size() <= 0) { + if (countryCodeCallbacks_.size() <= 0) { LBSLOGE(COUNTRY_CODE, "no valid callback registed, no need to unsubscribe"); lock.unlock(); return; diff --git a/frameworks/native/locator_sdk/source/location_data_manager.cpp b/frameworks/native/locator_sdk/source/location_data_manager.cpp index 1a94d6b7..6a9e1ce9 100644 --- a/frameworks/native/locator_sdk/source/location_data_manager.cpp +++ b/frameworks/native/locator_sdk/source/location_data_manager.cpp @@ -38,7 +38,6 @@ LocationDataManager* LocationDataManager::GetInstance() LocationDataManager::LocationDataManager() { - switchCallbacks_ = std::make_unique>>(); sptr sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (sam == nullptr) { LBSLOGE(LOCATOR_STANDARD, "%{public}s: get samgr failed.", __func__); @@ -59,15 +58,10 @@ LocationDataManager::~LocationDataManager() LocationErrCode LocationDataManager::ReportSwitchState(bool isEnabled) { - if (switchCallbacks_ == nullptr) { - LBSLOGE(LOCATOR, "switchCallbacks_ is nullptr"); - return ERRCODE_INVALID_PARAM; - } int state = isEnabled ? ENABLED : DISABLED; - std::unique_lock lock(mutex_); - for (auto iter = switchCallbacks_->begin(); iter != switchCallbacks_->end(); iter++) { - sptr remoteObject = (iter->second)->AsObject(); + for (auto switchCallback : switchCallbacks_) { + sptr remoteObject = switchCallback->AsObject(); auto callback = std::make_unique(remoteObject); callback->OnSwitchChange(state); } @@ -76,7 +70,7 @@ LocationErrCode LocationDataManager::ReportSwitchState(bool isEnabled) LocationErrCode LocationDataManager::RegisterSwitchCallback(const sptr& callback, pid_t uid) { - if (callback == nullptr || switchCallbacks_ == nullptr) { + if (callback == nullptr) { LBSLOGE(LOCATOR, "register an invalid switch callback"); return ERRCODE_INVALID_PARAM; } @@ -86,16 +80,15 @@ LocationErrCode LocationDataManager::RegisterSwitchCallback(const sptr lock(mutex_); - switchCallbacks_->erase(uid); - switchCallbacks_->insert(std::make_pair(uid, switchCallback)); + switchCallbacks_.push_back(switchCallback); LBSLOGD(LOCATOR, "after uid:%{public}d register, switch callback size:%{public}s", - uid, std::to_string(switchCallbacks_->size()).c_str()); + uid, std::to_string(switchCallbacks_.size()).c_str()); return ERRCODE_SUCCESS; } LocationErrCode LocationDataManager::UnregisterSwitchCallback(const sptr& callback) { - if (callback == nullptr || switchCallbacks_ == nullptr) { + if (callback == nullptr) { LBSLOGE(LOCATOR, "unregister an invalid switch callback"); return ERRCODE_INVALID_PARAM; } @@ -105,18 +98,26 @@ LocationErrCode LocationDataManager::UnregisterSwitchCallback(const sptr lock(mutex_); - for (auto iter = switchCallbacks_->begin(); iter != switchCallbacks_->end(); iter++) { - sptr remoteObject = (iter->second)->AsObject(); + size_t i = 0; + for (; i < switchCallbacks_.size(); i++) { + if (switchCallbacks_[i] == nullptr) { + continue; + } + sptr remoteObject = switchCallbacks_[i]->AsObject(); if (remoteObject == callback) { - uid = iter->first; break; } } - switchCallbacks_->erase(uid); - LBSLOGD(LOCATOR, "after uid:%{public}d unregister, switch callback size:%{public}s", - uid, std::to_string(switchCallbacks_->size()).c_str()); + if (i >= switchCallbacks_.size()) { + LBSLOGD(GNSS, "switch callback is not in vector"); + return ERRCODE_SUCCESS; + } + if (switchCallbacks_.size() > 0) { + switchCallbacks_.erase(switchCallbacks_.begin() + i); + } + LBSLOGD(LOCATOR, "after unregister, switch callback size:%{public}s", + std::to_string(switchCallbacks_.size()).c_str()); return ERRCODE_SUCCESS; } @@ -130,7 +131,7 @@ void LocationDataManager::SetCachedSwitchState(int state) bool LocationDataManager::IsSwitchStateReg() { std::unique_lock lock(mutex_); - return (switchCallbacks_->size() > 0); + return (switchCallbacks_.size() > 0); } void LocationDataManager::ResetIsObserverReg() diff --git a/frameworks/native/locator_sdk/source/location_switch_callback_host.cpp b/frameworks/native/locator_sdk/source/location_switch_callback_host.cpp index 71f8e2a8..ba000ab3 100644 --- a/frameworks/native/locator_sdk/source/location_switch_callback_host.cpp +++ b/frameworks/native/locator_sdk/source/location_switch_callback_host.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,35 +14,18 @@ */ #include "location_switch_callback_host.h" -#include "common_utils.h" -#include "ipc_skeleton.h" #include "location_log.h" namespace OHOS { namespace Location { -LocationSwitchCallbackHost::LocationSwitchCallbackHost() -{ - env_ = nullptr; - handlerCb_ = nullptr; - remoteDied_ = false; -} - -LocationSwitchCallbackHost::~LocationSwitchCallbackHost() -{ -} - int LocationSwitchCallbackHost::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { - LBSLOGD(SWITCH_CALLBACK, "LocatorCallbackHost::OnRemoteRequest!"); + LBSLOGD(SWITCH_CALLBACK, "LocationSwitchCallbackHost::OnRemoteRequest!"); if (data.ReadInterfaceToken() != GetDescriptor()) { LBSLOGE(SWITCH_CALLBACK, "invalid token."); return -1; } - if (remoteDied_) { - LBSLOGD(SWITCH_CALLBACK, "Failed to `%{public}s`,Remote service is died!", __func__); - return -1; - } switch (code) { case RECEIVE_SWITCH_STATE_EVENT: { @@ -56,116 +39,8 @@ int LocationSwitchCallbackHost::OnRemoteRequest( } return 0; } - -bool LocationSwitchCallbackHost::IsRemoteDied() -{ - return remoteDied_; -} - -napi_value LocationSwitchCallbackHost::PackResult(bool switchState) -{ - napi_value result; - NAPI_CALL(env_, napi_get_boolean(env_, switchState, &result)); - return result; -} - -bool LocationSwitchCallbackHost::Send(int switchState) -{ - std::unique_lock guard(mutex_); - uv_loop_s *loop = nullptr; - NAPI_CALL_BASE(env_, napi_get_uv_event_loop(env_, &loop), false); - if (loop == nullptr) { - LBSLOGE(SWITCH_CALLBACK, "loop == nullptr."); - return false; - } - uv_work_t *work = new (std::nothrow) uv_work_t; - if (work == nullptr) { - LBSLOGE(SWITCH_CALLBACK, "work == nullptr."); - return false; - } - SwitchAsyncContext *context = new (std::nothrow) SwitchAsyncContext(env_); - if (context == nullptr) { - LBSLOGE(SWITCH_CALLBACK, "context == nullptr."); - delete work; - return false; - } - context->env = env_; - context->callback[SUCCESS_CALLBACK] = handlerCb_; - context->enable = (switchState == 1 ? true : false); - work->data = context; - UvQueueWork(loop, work); - return true; -} - -void LocationSwitchCallbackHost::UvQueueWork(uv_loop_s* loop, uv_work_t* work) -{ - uv_queue_work( - loop, - work, - [](uv_work_t *work) {}, - [](uv_work_t *work, int status) { - SwitchAsyncContext *context = nullptr; - napi_handle_scope scope = nullptr; - if (work == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "work is nullptr!"); - return; - } - context = static_cast(work->data); - if (context == nullptr || context->env == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "context is nullptr!"); - delete work; - return; - } - NAPI_CALL_RETURN_VOID(context->env, napi_open_handle_scope(context->env, &scope)); - napi_value jsEvent; - CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_get_boolean(context->env, context->enable, &jsEvent), - scope, context, work); - if (scope == nullptr) { - LBSLOGE(SWITCH_CALLBACK, "scope is nullptr"); - delete context; - delete work; - return; - } - if (context->callback[0] != nullptr) { - napi_value undefine; - napi_value handler = nullptr; - CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_get_undefined(context->env, &undefine), - scope, context, work); - CHK_NAPI_ERR_CLOSE_SCOPE(context->env, - napi_get_reference_value(context->env, context->callback[0], &handler), scope, context, work); - if (napi_call_function(context->env, nullptr, handler, 1, - &jsEvent, &undefine) != napi_ok) { - LBSLOGE(SWITCH_CALLBACK, "Report event failed"); - } - } - NAPI_CALL_RETURN_VOID(context->env, napi_close_handle_scope(context->env, scope)); - delete context; - delete work; - }); -} - void LocationSwitchCallbackHost::OnSwitchChange(int switchState) { - LBSLOGD(SWITCH_CALLBACK, "LocatorCallbackHost::OnSwitchChange"); - Send(switchState); -} - -void LocationSwitchCallbackHost::DeleteHandler() -{ - std::unique_lock guard(mutex_); - if (handlerCb_ == nullptr || env_ == nullptr) { - LBSLOGE(SWITCH_CALLBACK, "handler or env is nullptr."); - return; - } - auto context = new (std::nothrow) AsyncContext(env_); - if (context == nullptr) { - LBSLOGE(SWITCH_CALLBACK, "context == nullptr."); - return; - } - context->env = env_; - context->callback[SUCCESS_CALLBACK] = handlerCb_; - DeleteQueueWork(context); - handlerCb_ = nullptr; } } // namespace Location } // namespace OHOS diff --git a/frameworks/native/locator_sdk/source/locator_callback_host.cpp b/frameworks/native/locator_sdk/source/locator_callback_host.cpp index 24dab4af..8fc6faa2 100644 --- a/frameworks/native/locator_sdk/source/locator_callback_host.cpp +++ b/frameworks/native/locator_sdk/source/locator_callback_host.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,54 +14,14 @@ */ #include "locator_callback_host.h" - -#include "ipc_object_stub.h" -#include "ipc_skeleton.h" -#include "js_native_api.h" -#include "message_option.h" -#include "message_parcel.h" -#include "napi/native_common.h" -#include "uv.h" - -#include "common_utils.h" -#include "constant_definition.h" -#include "i_locator_callback.h" -#include "location.h" -#include "location_async_context.h" #include "location_log.h" -#include "napi_util.h" namespace OHOS { namespace Location { -LocatorCallbackHost::LocatorCallbackHost() -{ - env_ = nullptr; - handlerCb_ = nullptr; - successHandlerCb_ = nullptr; - failHandlerCb_ = nullptr; - completeHandlerCb_ = nullptr; - deferred_ = nullptr; - fixNumber_ = 0; - inHdArea_ = true; - singleLocation_ = nullptr; - locationPriority_ = 0; - InitLatch(); -} - -void LocatorCallbackHost::InitLatch() -{ - latch_ = new CountDownLatch(); - latch_->SetCount(1); -} - -LocatorCallbackHost::~LocatorCallbackHost() -{ - delete latch_; -} - int LocatorCallbackHost::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { + LBSLOGD(LOCATOR_CALLBACK, "LocatorCallbackHost::OnRemoteRequest!"); if (data.ReadInterfaceToken() != GetDescriptor()) { LBSLOGE(LOCATOR_CALLBACK, "invalid token."); return -1; @@ -71,16 +31,6 @@ int LocatorCallbackHost::OnRemoteRequest(uint32_t code, case RECEIVE_LOCATION_INFO_EVENT: { std::unique_ptr location = Location::Unmarshalling(data); OnLocationReport(location); - if (location->GetLocationSourceType() == LocationSourceType::NETWORK_TYPE && - location->GetAdditionsMap()["inHdArea"] != "") { - inHdArea_ = (location->GetAdditionsMap()["inHdArea"] == "true"); - } - if (NeedSetSingleLocation(location)) { - SetSingleLocation(location); - } - if (IfReportAccuracyLocation()) { - CountDown(); - } break; } case RECEIVE_LOCATION_STATUS_EVENT: { @@ -91,14 +41,7 @@ int LocatorCallbackHost::OnRemoteRequest(uint32_t code, case RECEIVE_ERROR_INFO_EVENT: { int errorCode = data.ReadInt32(); LBSLOGI(LOCATOR_STANDARD, "CallbackSutb receive ERROR_EVENT. errorCode:%{public}d", errorCode); - if (errorCode == LOCATING_FAILED_INTERNET_ACCESS_FAILURE) { - inHdArea_ = false; - if (GetSingleLocation() != nullptr) { - CountDown(); - } - } else { - OnErrorReport(errorCode); - } + OnErrorReport(errorCode); break; } default: { @@ -108,167 +51,8 @@ int LocatorCallbackHost::OnRemoteRequest(uint32_t code, } return 0; } - -void LocatorCallbackHost::DoSendWork(uv_loop_s*& loop, uv_work_t*& work) -{ - uv_queue_work(loop, work, [](uv_work_t* work) {}, [](uv_work_t* work, int status) { - if (work == nullptr) { - return; - } - napi_handle_scope scope = nullptr; - auto context = static_cast(work->data); - if (context == nullptr) { - delete work; - return; - } - if (context->env == nullptr || context->loc == nullptr) { - delete context; - delete work; - return; - } - napi_open_handle_scope(context->env, &scope); - if (scope == nullptr) { - DELETE_SCOPE_CONTEXT_WORK(context->env, scope, context, work); - return; - } - napi_value jsEvent = nullptr; - CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_create_object(context->env, &jsEvent), scope, context, work); - if (context->callback[1]) { - SystemLocationToJs(context->env, context->loc, jsEvent); - } else { - LocationToJs(context->env, context->loc, jsEvent); - } - if (context->callback[0] != nullptr) { - napi_value undefine = nullptr; - napi_value handler = nullptr; - CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_get_undefined(context->env, &undefine), - scope, context, work); - CHK_NAPI_ERR_CLOSE_SCOPE(context->env, - napi_get_reference_value(context->env, context->callback[0], &handler), scope, context, work); - if (napi_call_function(context->env, nullptr, handler, 1, &jsEvent, &undefine) != napi_ok) { - LBSLOGE(LOCATOR_CALLBACK, "Report location failed"); - } - } else if (context->deferred != nullptr) { - CHK_NAPI_ERR_CLOSE_SCOPE(context->env, - ((jsEvent != nullptr) ? napi_resolve_deferred(context->env, context->deferred, jsEvent) : - napi_reject_deferred(context->env, context->deferred, jsEvent)), - scope, context, work); - } - DELETE_SCOPE_CONTEXT_WORK(context->env, scope, context, work); - }); -} - -void LocatorCallbackHost::DoSendErrorCode(uv_loop_s *&loop, uv_work_t *&work) -{ - uv_queue_work(loop, work, [](uv_work_t *work) {}, - [](uv_work_t *work, int status) { - AsyncContext *context = nullptr; - napi_handle_scope scope = nullptr; - if (work == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "work is nullptr"); - return; - } - context = static_cast(work->data); - if (context == nullptr || context->env == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "context is nullptr"); - delete work; - return; - } - NAPI_CALL_RETURN_VOID(context->env, napi_open_handle_scope(context->env, &scope)); - if (scope == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "scope is nullptr"); - delete context; - delete work; - return; - } - if (context->callback[FAIL_CALLBACK] != nullptr) { - napi_value undefine; - napi_value handler = nullptr; - CHK_NAPI_ERR_CLOSE_SCOPE(context->env, napi_get_undefined(context->env, &undefine), - scope, context, work); - CHK_NAPI_ERR_CLOSE_SCOPE(context->env, - napi_get_reference_value(context->env, context->callback[FAIL_CALLBACK], &handler), - scope, context, work); - std::string msg = GetErrorMsgByCode(context->errCode); - CreateFailCallBackParams(*context, msg, context->errCode); - if (napi_call_function(context->env, nullptr, handler, RESULT_SIZE, - context->result, &undefine) != napi_ok) { - LBSLOGE(LOCATOR_CALLBACK, "Report system error failed"); - } - } - NAPI_CALL_RETURN_VOID(context->env, napi_close_handle_scope(context->env, scope)); - delete context; - delete work; - }); -} - -bool LocatorCallbackHost::SendErrorCode(const int& errorCode) -{ - std::unique_lock guard(mutex_); - if (!IsSystemGeoLocationApi() && !IsSingleLocationRequest()) { - LBSLOGE(LOCATOR_CALLBACK, "this is Callback type,cant send error msg."); - return false; - } - if (env_ == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "env_ is nullptr."); - return false; - } - uv_loop_s *loop = nullptr; - NAPI_CALL_BASE(env_, napi_get_uv_event_loop(env_, &loop), false); - if (loop == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "loop == nullptr."); - return false; - } - uv_work_t *work = new (std::nothrow) uv_work_t; - if (work == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "work == nullptr."); - return false; - } - AsyncContext *context = new (std::nothrow) AsyncContext(env_); - if (context == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "context == nullptr."); - delete work; - return false; - } - if (!InitContext(context)) { - LBSLOGE(LOCATOR_CALLBACK, "InitContext fail"); - } - context->errCode = errorCode; - work->data = context; - DoSendErrorCode(loop, work); - return true; -} - void LocatorCallbackHost::OnLocationReport(const std::unique_ptr& location) { - std::unique_lock guard(mutex_); - uv_loop_s *loop = nullptr; - if (env_ == nullptr) { - LBSLOGD(LOCATOR_CALLBACK, "env_ is nullptr."); - return; - } - NAPI_CALL_RETURN_VOID(env_, napi_get_uv_event_loop(env_, &loop)); - if (loop == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "loop == nullptr."); - return; - } - uv_work_t *work = new (std::nothrow) uv_work_t; - if (work == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "work == nullptr."); - return; - } - auto context = new (std::nothrow) LocationAsyncContext(env_); - if (context == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "context == nullptr."); - delete work; - return; - } - if (!InitContext(context)) { - LBSLOGE(LOCATOR_CALLBACK, "InitContext fail"); - } - context->loc = std::make_unique(*location); - work->data = context; - DoSendWork(loop, work); } void LocatorCallbackHost::OnLocatingStatusChange(const int status) @@ -277,106 +61,6 @@ void LocatorCallbackHost::OnLocatingStatusChange(const int status) void LocatorCallbackHost::OnErrorReport(const int errorCode) { - SendErrorCode(errorCode); -} - -void LocatorCallbackHost::DeleteAllCallbacks() -{ - DeleteHandler(); -} - -void LocatorCallbackHost::DeleteHandler() -{ - LBSLOGD(LOCATOR_CALLBACK, "before DeleteHandler"); - std::unique_lock guard(mutex_); - if (env_ == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "env is nullptr."); - return; - } - auto context = new (std::nothrow) AsyncContext(env_); - if (context == nullptr) { - LBSLOGE(LOCATOR_CALLBACK, "context == nullptr."); - return; - } - if (!InitContext(context)) { - LBSLOGE(LOCATOR_CALLBACK, "InitContext fail"); - } - DeleteQueueWork(context); - if (IsSystemGeoLocationApi()) { - successHandlerCb_ = nullptr; - failHandlerCb_ = nullptr; - completeHandlerCb_ = nullptr; - } else { - handlerCb_ = nullptr; - } -} - -bool LocatorCallbackHost::IsSystemGeoLocationApi() -{ - return (successHandlerCb_ != nullptr) ? true : false; -} - -bool LocatorCallbackHost::IsSingleLocationRequest() -{ - return (fixNumber_ == 1); -} - -void LocatorCallbackHost::CountDown() -{ - if (IsSingleLocationRequest() && latch_ != nullptr) { - latch_->CountDown(); - } -} - -void LocatorCallbackHost::Wait(int time) -{ - if (IsSingleLocationRequest() && latch_ != nullptr) { - latch_->Wait(time); - } -} - -int LocatorCallbackHost::GetCount() -{ - if (IsSingleLocationRequest() && latch_ != nullptr) { - return latch_->GetCount(); - } - return 0; -} - -void LocatorCallbackHost::SetCount(int count) -{ - if (IsSingleLocationRequest() && latch_ != nullptr) { - return latch_->SetCount(count); - } -} - -bool LocatorCallbackHost::NeedSetSingleLocation(const std::unique_ptr& location) -{ - if (locationPriority_ == LOCATION_PRIORITY_ACCURACY && - singleLocation_ != nullptr && - location->GetLocationSourceType() == LocationSourceType::NETWORK_TYPE) { - return false; - } else { - return true; - } -} - -bool LocatorCallbackHost::IfReportAccuracyLocation() -{ - if (locationPriority_ == LOCATION_PRIORITY_ACCURACY && - (((singleLocation_->GetLocationSourceType() == LocationSourceType::GNSS_TYPE || - singleLocation_->GetLocationSourceType() == LocationSourceType::RTK_TYPE) && inHdArea_) || - singleLocation_->GetLocationSourceType() == LocationSourceType::NETWORK_TYPE)) { - return false; - } else { - return true; - } -} - -void LocatorCallbackHost::SetSingleLocation(const std::unique_ptr& location) -{ - std::unique_lock guard(mutex_); - singleLocation_ = std::make_shared(*location); } } // namespace Location } // namespace OHOS diff --git a/frameworks/native/locator_sdk/source/locator_impl.cpp b/frameworks/native/locator_sdk/source/locator_impl.cpp index d334641d..0bd6327d 100644 --- a/frameworks/native/locator_sdk/source/locator_impl.cpp +++ b/frameworks/native/locator_sdk/source/locator_impl.cpp @@ -39,7 +39,8 @@ std::mutex g_locationCallbackMapMutex; std::mutex g_gnssStatusInfoCallbacksMutex; std::mutex g_nmeaCallbacksMutex; std::shared_ptr g_callbackResumer = std::make_shared(); -std::map g_resumeFuncMap; +using CallbackResumeHandle = std::function; +std::map g_resumeFuncMap; std::map, RequestConfig> g_locationCallbackMap; std::set> g_gnssStatusInfoCallbacks; std::set> g_nmeaCallbacks; @@ -1364,9 +1365,9 @@ void CallbackResumeManager::InitResumeCallbackFuncMap() if (g_resumeFuncMap.size() != 0) { return; } - g_resumeFuncMap.insert(std::make_pair("satelliteStatusChange", &CallbackResumeManager::ResumeGnssStatusCallback)); - g_resumeFuncMap.insert(std::make_pair("nmeaMessage", &CallbackResumeManager::ResumeNmeaMessageCallback)); - g_resumeFuncMap.insert(std::make_pair("locationChange", &CallbackResumeManager::ResumeLocating)); + g_resumeFuncMap.insert(std::make_pair("satelliteStatusChange", [this]() { return ResumeGnssStatusCallback(); })); + g_resumeFuncMap.insert(std::make_pair("nmeaMessage", [this]() { return ResumeNmeaMessageCallback(); })); + g_resumeFuncMap.insert(std::make_pair("locationChange", [this]() { return ResumeLocating(); })); } void CallbackResumeManager::ResumeCallback() @@ -1375,7 +1376,7 @@ void CallbackResumeManager::ResumeCallback() std::unique_lock lock(g_resumeFuncMapMutex); for (auto iter = g_resumeFuncMap.begin(); iter != g_resumeFuncMap.end(); iter++) { auto resumeFunc = iter->second; - (this->*resumeFunc)(); + resumeFunc(); } } @@ -1426,6 +1427,7 @@ void CallbackResumeManager::ResumeLocating() } auto requestConfig = std::make_unique(); requestConfig->Set(iter->second); + LBSLOGI(LOCATOR_STANDARD, "ResumeLocating requestConfig = %{public}s", requestConfig->ToString().c_str()); proxy->StartLocatingV9(requestConfig, locatorCallback); } } diff --git a/interfaces/inner_api/include/async_context.h b/interfaces/inner_api/include/async_context.h index ef8cc58c..17484701 100644 --- a/interfaces/inner_api/include/async_context.h +++ b/interfaces/inner_api/include/async_context.h @@ -27,6 +27,7 @@ public: napi_async_work work; napi_deferred deferred; napi_ref callback[MAX_CALLBACK_NUM] = { 0 }; + bool* callbackValid; std::function executeFunc; std::function completeFunc; napi_value resourceName; @@ -43,6 +44,7 @@ public: resourceName = nullptr; result[PARAM0] = nullptr; result[PARAM1] = nullptr; + callbackValid = nullptr; errCode = 0; } diff --git a/interfaces/inner_api/include/common_utils.h b/interfaces/inner_api/include/common_utils.h index 037b73a4..10a5347f 100644 --- a/interfaces/inner_api/include/common_utils.h +++ b/interfaces/inner_api/include/common_utils.h @@ -40,16 +40,16 @@ const std::string DEFAULT_ABILITY = "default"; const std::string LOCATION_DIR = "/data/service/el1/public/location/"; const std::string SWITCH_CONFIG_NAME = "location_switch"; const std::string PRIVACY_CONFIG_NAME = "location_privacy"; -const std::string NLP_SERVICE_NAME = "const.location.nlp_service_name"; -const std::string NLP_ABILITY_NAME = "const.location.nlp_ability_name"; -const std::string GEOCODE_SERVICE_NAME = "const.location.geocode_service_name"; -const std::string GEOCODE_ABILITY_NAME = "const.location.geocode_ability_name"; -const std::string SUPL_MODE_NAME = "const.location.supl_mode"; -const std::string EDM_POLICY_NAME = "persist.edm.location_policy"; -const std::string AGNSS_SERVER_ADDR = "const.location.agnss_server_addr"; -const std::string AGNSS_SERVER_PORT = "const.location.agnss_server_port"; +constexpr const char* NLP_SERVICE_NAME = "const.location.nlp_service_name"; +constexpr const char* NLP_ABILITY_NAME = "const.location.nlp_ability_name"; +constexpr const char* GEOCODE_SERVICE_NAME = "const.location.geocode_service_name"; +constexpr const char* GEOCODE_ABILITY_NAME = "const.location.geocode_ability_name"; +constexpr const char* SUPL_MODE_NAME = "const.location.supl_mode"; +constexpr const char* EDM_POLICY_NAME = "persist.edm.location_policy"; +constexpr const char* AGNSS_SERVER_ADDR = "const.location.agnss_server_addr"; +constexpr const char* AGNSS_SERVER_PORT = "const.location.agnss_server_port"; -const std::string BUILD_INFO = "ro.build.characteristics"; +constexpr const char* BUILD_INFO = "ro.build.characteristics"; const int SA_NUM = 3; const int DEFAULT_UID = 10001; const int SYSTEM_UID = 1000; diff --git a/interfaces/inner_api/include/constant_definition.h b/interfaces/inner_api/include/constant_definition.h index 03d1b49a..f07ce96d 100644 --- a/interfaces/inner_api/include/constant_definition.h +++ b/interfaces/inner_api/include/constant_definition.h @@ -47,12 +47,10 @@ const int32_t UNKNOW_USER_ID = -1; const int32_t SUBSCRIBE_TIME = 5; const int32_t DEFAULT_TIME_INTERVAL = 30 * 60; // app receive location every 30 minutes in frozen state const int32_t REQUESTS_NUM_MAX = 1; -const std::string FEATURE_SWITCH_PROP = "ro.config.locator_background"; -const std::string TIME_INTERVAL_PROP = "ro.config.locator_background.timeInterval"; -const std::string PROC_NAME = "system"; -const std::string SEARCH_NET_WORK_STATE_CHANGE_ACTION = "com.hos.action.SEARCH_NET_WORK_STATE_CHANGE"; -const std::string SIM_STATE_CHANGE_ACTION = "com.hos.action.SIM_STATE_CHANGE"; -const std::string LOCALE_KEY = "persist.global.locale"; +constexpr const char* FEATURE_SWITCH_PROP = "ro.config.locator_background"; +constexpr const char* TIME_INTERVAL_PROP = "ro.config.locator_background.timeInterval"; +constexpr const char* PROC_NAME = "system"; +constexpr const char* LOCALE_KEY = "persist.global.locale"; const int MODE_STANDALONE = 1; const int MODE_MS_BASED = 2; const int MODE_MS_ASSISTED = 3; diff --git a/interfaces/inner_api/include/country_code_manager.h b/interfaces/inner_api/include/country_code_manager.h index 0c56c343..4be3ad2e 100644 --- a/interfaces/inner_api/include/country_code_manager.h +++ b/interfaces/inner_api/include/country_code_manager.h @@ -80,7 +80,7 @@ private: std::shared_ptr lastCountryByLocation_; std::shared_ptr lastCountry_; - std::unique_ptr>> countryCodeCallback_; + std::vector> countryCodeCallbacks_; std::shared_ptr simSubscriber_; std::shared_ptr networkSubscriber_; std::mutex simSubscriberMutex_; diff --git a/interfaces/inner_api/include/geofence_async_context.h b/interfaces/inner_api/include/geofence_async_context.h index b49ee481..f9976354 100644 --- a/interfaces/inner_api/include/geofence_async_context.h +++ b/interfaces/inner_api/include/geofence_async_context.h @@ -25,7 +25,7 @@ #include "async_context.h" #include "constant_definition.h" #include "location_log.h" -#include "location_gnss_geofence_callback_host.h" +#include "location_gnss_geofence_callback_napi.h" #include "geofence_definition.h" #include "geofence_request.h" @@ -35,7 +35,7 @@ class GnssGeofenceAsyncContext : public AsyncContext { public: int code_{-1}; GeofenceTransition transition_{-1, GEOFENCE_TRANSITION_INIT}; - sptr callbackHost_ = nullptr; + sptr callbackHost_ = nullptr; std::shared_ptr request_; int fenceId_{-1}; diff --git a/interfaces/inner_api/include/geofence_request.h b/interfaces/inner_api/include/geofence_request.h index 509d051c..74ca1832 100644 --- a/interfaces/inner_api/include/geofence_request.h +++ b/interfaces/inner_api/include/geofence_request.h @@ -19,7 +19,9 @@ #include #include #include "geofence_definition.h" +#ifdef NOTIFICATION_ENABLE #include "notification_request.h" +#endif #include "want_agent_helper.h" #include @@ -35,135 +37,57 @@ typedef struct { class GeofenceRequest : public Parcelable { public: - GeofenceRequest() - { - callback_ = nullptr; - scenario_ = -1; - fenceId_ = -1; - } + GeofenceRequest(); - GeofenceRequest(GeofenceRequest& geofenceRequest) - { - this->SetGeofence(geofenceRequest.GetGeofence()); - this->SetScenario(geofenceRequest.GetScenario()); - this->SetWantAgent(geofenceRequest.GetWantAgent()); - this->SetGeofenceTransitionEventList(geofenceRequest.GetGeofenceTransitionEventList()); - this->SetNotificationRequestList(geofenceRequest.GetNotificationRequestList()); - this->SetGeofenceTransitionCallback(geofenceRequest.GetGeofenceTransitionCallback()); - this->SetFenceId(geofenceRequest.GetFenceId()); - this->SetBundleName(geofenceRequest.GetBundleName()); - } + GeofenceRequest(GeofenceRequest& geofenceRequest); - ~GeofenceRequest() {} + ~GeofenceRequest(); - inline GeoFence GetGeofence() - { - return geofence_; - } + GeoFence GetGeofence(); + void SetGeofence(GeoFence geofence); - inline void SetGeofence(GeoFence geofence) - { - geofence_ = geofence; - } + int GetScenario(); - inline int GetScenario() - { - return scenario_; - } + void SetScenario(int scenario); - inline void SetScenario(int scenario) - { - scenario_ = scenario; - } + void SetWantAgent(const AbilityRuntime::WantAgent::WantAgent wantAgent); - inline void SetWantAgent(const AbilityRuntime::WantAgent::WantAgent wantAgent) - { - wantAgent_ = wantAgent; - } + AbilityRuntime::WantAgent::WantAgent GetWantAgent(); - inline AbilityRuntime::WantAgent::WantAgent GetWantAgent() - { - return wantAgent_; - } + std::vector GetGeofenceTransitionEventList(); - inline std::vector GetGeofenceTransitionEventList() - { - std::unique_lock lock(geofenceRequestMutex_); - return transitionStatusList_; - } + void SetGeofenceTransitionEvent(GeofenceTransitionEvent status); - inline void SetGeofenceTransitionEvent(GeofenceTransitionEvent status) - { - std::unique_lock lock(geofenceRequestMutex_); - transitionStatusList_.push_back(status); - } + void SetGeofenceTransitionEventList(std::vector statusList); - inline void SetGeofenceTransitionEventList(std::vector statusList) - { - std::unique_lock lock(geofenceRequestMutex_); - for (auto it = statusList.begin(); it != statusList.end(); ++it) { - transitionStatusList_.push_back(*it); - } - } +#ifdef NOTIFICATION_ENABLE + std::vector GetNotificationRequestList(); - inline std::vector GetNotificationRequestList() - { - std::unique_lock lock(geofenceRequestMutex_); - return notificationRequestList_; - } + void SetNotificationRequest(OHOS::Notification::NotificationRequest request); - inline void SetNotificationRequest(OHOS::Notification::NotificationRequest request) - { - std::unique_lock lock(geofenceRequestMutex_); - notificationRequestList_.push_back(request); - } + void SetNotificationRequestList(std::vector requestList); +#endif - inline void SetNotificationRequestList(std::vector requestList) - { - std::unique_lock lock(geofenceRequestMutex_); - for (auto it = requestList.begin(); it != requestList.end(); ++it) { - notificationRequestList_.push_back(*it); - } - } + void SetGeofenceTransitionCallback(const sptr& callback); - inline void SetGeofenceTransitionCallback(const sptr& callback) - { - callback_ = callback; - } + sptr GetGeofenceTransitionCallback(); - inline sptr GetGeofenceTransitionCallback() - { - return callback_; - } + int GetFenceId(); - inline int GetFenceId() - { - return fenceId_; - } + void SetFenceId(int fenceId); - inline void SetFenceId(int fenceId) - { - fenceId_ = fenceId; - } + std::string GetBundleName(); - inline std::string GetBundleName() - { - return bundleName_; - } - - inline void SetBundleName(std::string bundleName) - { - bundleName_ = bundleName; - } + void SetBundleName(std::string bundleName); void ReadFromParcel(Parcel& parcel); bool Marshalling(Parcel& parcel) const override; static std::shared_ptr Unmarshalling(Parcel& parcel); private: std::vector transitionStatusList_; - +#ifdef NOTIFICATION_ENABLE std::vector notificationRequestList_; - +#endif sptr callback_ = nullptr; GeoFence geofence_{0.0, 0.0, 0.0, WGS84}; int scenario_; diff --git a/interfaces/inner_api/include/geofence_sdk.h b/interfaces/inner_api/include/geofence_sdk.h index 3f4c5988..0f0d3b0f 100644 --- a/interfaces/inner_api/include/geofence_sdk.h +++ b/interfaces/inner_api/include/geofence_sdk.h @@ -67,11 +67,27 @@ public: LocationErrCode RemoveGnssGeofence(std::shared_ptr& request); LocationErrCode GetGeofenceSupportedCoordTypes( std::vector& coordinateSystemTypes); + void ResetGeofenceSdkProxy(const wptr &remote); private: sptr GetProxy(); sptr client_ { nullptr }; + sptr recipient_ { nullptr }; std::mutex mutex_; + bool isServerExist_ = false; + +private: + class GeofenceManagerDeathRecipient : public IRemoteObject::DeathRecipient { + public: + explicit GeofenceManagerDeathRecipient(GeofenceManager &impl) : impl_(impl) {} + ~GeofenceManagerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override + { + impl_.ResetGeofenceSdkProxy(remote); + } + private: + GeofenceManager &impl_; + }; }; } // namespace Location } // namespace OHOS diff --git a/interfaces/inner_api/include/location.h b/interfaces/inner_api/include/location.h index 835bd46c..66b9b97a 100644 --- a/interfaces/inner_api/include/location.h +++ b/interfaces/inner_api/include/location.h @@ -116,7 +116,7 @@ public: inline void SetAdditions(std::vector additions, bool ifAppend) { if (!ifAppend) { - additions_.clear(); + std::vector().swap(additions_); } for (auto it = additions.begin(); it != additions.end(); ++it) { additions_.push_back(*it); diff --git a/interfaces/inner_api/include/location_async_context.h b/interfaces/inner_api/include/location_async_context.h index dcde8aab..1f9df98a 100644 --- a/interfaces/inner_api/include/location_async_context.h +++ b/interfaces/inner_api/include/location_async_context.h @@ -28,14 +28,14 @@ #include "geo_address.h" #include "geo_coding_mock_info.h" #include "locating_required_data.h" -#include "locating_required_data_callback_host.h" +#include "locating_required_data_callback_napi.h" #include "locating_required_data_config.h" #include "location.h" #include "location_log.h" -#include "locator_callback_host.h" +#include "locator_callback_napi.h" #include "request_config.h" #include "satellite_status.h" -#include "location_gnss_geofence_callback_host.h" +#include "location_gnss_geofence_callback_napi.h" namespace OHOS { namespace Location { @@ -219,7 +219,7 @@ public: class SingleLocationAsyncContext : public AsyncContext { public: int timeout_; - sptr callbackHost_; + sptr callbackHost_; std::unique_ptr request_; explicit SingleLocationAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) @@ -260,7 +260,7 @@ public: class SingleScanAsyncContext : public AsyncContext { public: int timeout_; - sptr callbackHost_; + sptr callbackHost_; explicit SingleScanAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) : AsyncContext(env, work, deferred), timeout_(0), callbackHost_(nullptr) {} diff --git a/interfaces/inner_api/include/location_data_manager.h b/interfaces/inner_api/include/location_data_manager.h index 19ab6dcc..afac6431 100644 --- a/interfaces/inner_api/include/location_data_manager.h +++ b/interfaces/inner_api/include/location_data_manager.h @@ -47,7 +47,7 @@ public: private: std::mutex mutex_; std::mutex switchStateMutex_; - std::unique_ptr>> switchCallbacks_; + std::vector> switchCallbacks_; int32_t cachedSwitchState_ = DISABLED; bool isStateCached_ = false; bool isObserverReg_ = false; diff --git a/interfaces/inner_api/include/location_data_rdb_manager.h b/interfaces/inner_api/include/location_data_rdb_manager.h index 7c5bd9e9..28355f72 100644 --- a/interfaces/inner_api/include/location_data_rdb_manager.h +++ b/interfaces/inner_api/include/location_data_rdb_manager.h @@ -23,15 +23,10 @@ namespace OHOS { namespace Location { -const std::string LOCATION_DATA_ABILITY_PREFIX = "datashare://"; -const std::string LOCATION_DATA_URI_ID = - "/com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=location_enable"; -const std::string LOCATION_DATA_URI = LOCATION_DATA_ABILITY_PREFIX + LOCATION_DATA_URI_ID; -const std::string LOCATION_DATA_COLUMN_KEYWORD = "KEYWORD"; -const std::string LOCATION_DATA_COLUMN_VALUE = "VALUE"; const std::string LOCATION_DATA_COLUMN_ENABLE = "location_switch_enable"; const std::string LOCATION_WORKING_STATE = "location_working_state"; -const std::string LOCATION_ENHANCE_STATUS = "location_enhance_status"; +const std::string LOCATION_DATA_URI = + "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=location_enable"; class LocationDataRdbManager { public: static std::string GetLocationDataUri(std::string key); diff --git a/interfaces/inner_api/include/location_gnss_geofence_callback_host.h b/interfaces/inner_api/include/location_gnss_geofence_callback_napi.h similarity index 77% rename from interfaces/inner_api/include/location_gnss_geofence_callback_host.h rename to interfaces/inner_api/include/location_gnss_geofence_callback_napi.h index aa18287d..f2912707 100644 --- a/interfaces/inner_api/include/location_gnss_geofence_callback_host.h +++ b/interfaces/inner_api/include/location_gnss_geofence_callback_napi.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef LOCATION_GNSS_GEOFENCE_CALLBACK_HOST_H -#define LOCATION_GNSS_GEOFENCE_CALLBACK_HOST_H +#ifndef LOCATION_GNSS_GEOFENCE_CALLBACK_NAPI_H +#define LOCATION_GNSS_GEOFENCE_CALLBACK_NAPI_H #include "iremote_stub.h" #include "message_option.h" @@ -27,10 +27,10 @@ namespace OHOS { namespace Location { -class LocationGnssGeofenceCallbackHost : public IRemoteStub { +class LocationGnssGeofenceCallbackNapi : public IRemoteStub { public: - LocationGnssGeofenceCallbackHost(); - virtual ~LocationGnssGeofenceCallbackHost(); + LocationGnssGeofenceCallbackNapi(); + virtual ~LocationGnssGeofenceCallbackNapi(); virtual int OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; bool IsRemoteDied(); @@ -50,6 +50,20 @@ public: void OnTransitionStatusChange(GeofenceTransition transition) override; void OnReportOperationResult(int fenceId, int type, int result) override; + template + bool InitContext(T* context) + { + if (context == nullptr) { + LBSLOGE(LOCATION_GNSS_GEOFENCE_CALLBACK, "context == nullptr."); + return false; + } + context->env = env_; + callbackValid_ = handlerCb_ == nullptr ? false : true; + context->callbackValid = &callbackValid_; + context->callback[SUCCESS_CALLBACK] = handlerCb_; + return true; + } + inline napi_env GetEnv() const { return env_; @@ -91,9 +105,10 @@ private: std::mutex operationResultMutex_; CountDownLatch* latch_; int fenceId_; + bool callbackValid_; GnssGeofenceOperateType type_; GnssGeofenceOperateResult result_; }; } // namespace Location } // namespace OHOS -#endif // LOCATION_GNSS_GEOFENCE_CALLBACK_HOST_H +#endif // LOCATION_GNSS_GEOFENCE_CALLBACK_NAPI_H diff --git a/interfaces/inner_api/include/location_log.h b/interfaces/inner_api/include/location_log.h index 32898c96..9875cda2 100644 --- a/interfaces/inner_api/include/location_log.h +++ b/interfaces/inner_api/include/location_log.h @@ -83,6 +83,9 @@ static constexpr OHOS::HiviewDFX::HiLogLabel COUNTRY_CODE_CALLBACK = { static constexpr OHOS::HiviewDFX::HiLogLabel LOCATING_DATA_CALLBACK = { LOG_CORE, LOCATION_LOG_DOMAIN, "LocatingDataCallback" }; +static constexpr OHOS::HiviewDFX::HiLogLabel LOCATION_ERR_CALLBACK = { + LOG_CORE, LOCATION_LOG_DOMAIN, "LocationErrorCallback" +}; static constexpr OHOS::HiviewDFX::HiLogLabel LOCATOR_CALLBACK = {LOG_CORE, LOCATION_LOG_DOMAIN, "LocatorCallback"}; static constexpr OHOS::HiviewDFX::HiLogLabel GNSS = {LOG_CORE, LOCATION_LOG_DOMAIN, "GnssAbility"}; static constexpr OHOS::HiviewDFX::HiLogLabel GNSS_TEST = {LOG_CORE, LOCATION_LOG_DOMAIN, "GnssAbilityTest"}; @@ -114,6 +117,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel NAPI_UTILS = {LOG_CORE, LOCATION_LO static constexpr OHOS::HiviewDFX::HiLogLabel GEOFENCE_SDK = { LOG_CORE, LOCATION_LOG_DOMAIN, "geofenceSdk" }; +static constexpr OHOS::HiviewDFX::HiLogLabel GEOFENCE_SDK_TEST = {LOG_CORE, LOCATION_LOG_DOMAIN, "GeofenceSdkTest"}; } // namespace Location } // namespace OHOS #endif // LOCATION_LOG_H diff --git a/interfaces/inner_api/include/request.h b/interfaces/inner_api/include/request.h index 5dd690f6..c09749d4 100644 --- a/interfaces/inner_api/include/request.h +++ b/interfaces/inner_api/include/request.h @@ -68,6 +68,8 @@ public: void SetNlpRequestType(); void SetLocationErrorCallBack(const sptr& callback); sptr GetLocationErrorCallBack(); + void SetLocatorCallbackRecipient(const sptr& recipient); + sptr GetLocatorCallbackRecipient(); private: void GetProxyNameByPriority(std::shared_ptr> proxys); @@ -88,6 +90,7 @@ private: bool isUsingBackgroundPerm_; bool isUsingApproximatelyPerm_; int permUsedType_; + sptr locatorCallbackRecipient_; }; } // namespace Location } // namespace OHOS diff --git a/services/etc/init/locationsa.cfg b/services/etc/init/locationsa.cfg index b56ce5a3..4c797537 100644 --- a/services/etc/init/locationsa.cfg +++ b/services/etc/init/locationsa.cfg @@ -12,7 +12,7 @@ "name" : "locationhub", "path" : ["/system/bin/sa_main", "/system/profile/locationhub.json"], "uid" : "gps", - "gid" : ["gps", "shell"], + "gid" : ["gps", "shell", "netsys_socket"], "secon" : "u:r:locationhub:s0", "permission" : [ "ohos.permission.PERMISSION_USED_STATS", diff --git a/services/location_geocode/geocode/BUILD.gn b/services/location_geocode/geocode/BUILD.gn index d73cf990..9eff6452 100644 --- a/services/location_geocode/geocode/BUILD.gn +++ b/services/location_geocode/geocode/BUILD.gn @@ -14,14 +14,16 @@ import("//base/location/config.gni") import("//build/ohos.gni") +local_base_sources = [ + "$LOCATION_GEOCONVERT_ROOT/source/geo_convert_callback_host.cpp", + "$LOCATION_GEOCONVERT_ROOT/source/geo_convert_service.cpp", + "$LOCATION_GEOCONVERT_ROOT/source/geo_convert_skeleton.cpp", + "$LOCATION_LOCATOR_ROOT/source/location_config_manager.cpp", +] + if (location_feature_with_geocode) { ohos_shared_library("lbsservice_geocode") { - sources = [ - "$LOCATION_GEOCONVERT_ROOT/source/geo_convert_callback_host.cpp", - "$LOCATION_GEOCONVERT_ROOT/source/geo_convert_service.cpp", - "$LOCATION_GEOCONVERT_ROOT/source/geo_convert_skeleton.cpp", - "$LOCATION_LOCATOR_ROOT/source/location_config_manager.cpp", - ] + sources = local_base_sources include_dirs = [ "$LOCATION_GEOCONVERT_ROOT/include", @@ -40,6 +42,67 @@ if (location_feature_with_geocode) { "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", ] + ldflags = [ + "-Wl,--as-needed", + "-Wl,--gc-sections", + ] + + cflags_cc = [ + "-ffunction-sections", + "-fdata-sections", + "-Os", + ] + + defines = [] + if (location_feature_with_geocode) { + defines += [ "FEATURE_GEOCODE_SUPPORT" ] + } + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_manager", + "hilog:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + ] + + # Used to control the export of dynamic library symbols. + version_script = "liblbsservice_geocode_version_script.txt" + + part_name = "location" + subsystem_name = "location" + } + + ohos_static_library("lbsservice_geocode_static") { + sources = local_base_sources + + include_dirs = [ + "$LOCATION_GEOCONVERT_ROOT/include", + "$LOCATION_LOCATOR_ROOT/include", + "$LOCATION_ROOT_DIR/interfaces/inner_api/include", + ] + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + deps = [ + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", + ] + + ldflags = [ + "-Wl,--as-needed", + "-Wl,--gc-sections", + ] + + cflags_cc = [ + "-ffunction-sections", + "-fdata-sections", + ] + defines = [] if (location_feature_with_geocode) { defines += [ "FEATURE_GEOCODE_SUPPORT" ] @@ -47,11 +110,8 @@ if (location_feature_with_geocode) { external_deps = [ "ability_base:want", - "ability_runtime:ability_connect_callback_stub", "ability_runtime:ability_manager", - "c_utils:utils", "hilog:libhilog", - "init:libbegetutil", "ipc:ipc_single", "safwk:system_ability_fwk", ] @@ -64,4 +124,9 @@ if (location_feature_with_geocode) { part_name = "location" subsystem_name = "location" } + + ohos_static_library("lbsservice_geocode_static") { + part_name = "location" + subsystem_name = "location" + } } diff --git a/services/location_geocode/geocode/include/geo_convert_skeleton.h b/services/location_geocode/geocode/include/geo_convert_skeleton.h index 91d58210..9ec56d38 100644 --- a/services/location_geocode/geocode/include/geo_convert_skeleton.h +++ b/services/location_geocode/geocode/include/geo_convert_skeleton.h @@ -42,8 +42,7 @@ public: class GeoConvertServiceStub : public IRemoteStub { public: - using GeoConvertMsgHandle = int (GeoConvertServiceStub::*)( - MessageParcel &data, MessageParcel &reply, AppIdentity &identity); + using GeoConvertMsgHandle = std::function; using GeoConvertMsgHandleMap = std::map; GeoConvertServiceStub(); virtual ~GeoConvertServiceStub() = default; diff --git a/services/location_geocode/geocode/liblbsservice_geocode_version_script.txt b/services/location_geocode/geocode/liblbsservice_geocode_version_script.txt new file mode 100644 index 00000000..1aeaa975 --- /dev/null +++ b/services/location_geocode/geocode/liblbsservice_geocode_version_script.txt @@ -0,0 +1,5 @@ +{ + global: + local: + *; +}; \ No newline at end of file diff --git a/services/location_geocode/geocode/source/geo_convert_skeleton.cpp b/services/location_geocode/geocode/source/geo_convert_skeleton.cpp index 4aaba119..dbd0d1ea 100644 --- a/services/location_geocode/geocode/source/geo_convert_skeleton.cpp +++ b/services/location_geocode/geocode/source/geo_convert_skeleton.cpp @@ -29,17 +29,29 @@ void GeoConvertServiceStub::InitGeoConvertHandleMap() return; } geoConvertMsgHandleMap_[static_cast(GeoConvertInterfaceCode::IS_AVAILABLE)] = - &GeoConvertServiceStub::IsGeoConvertAvailableInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return IsGeoConvertAvailableInner(data, reply, identity); + }; geoConvertMsgHandleMap_[static_cast(GeoConvertInterfaceCode::GET_FROM_COORDINATE)] = - &GeoConvertServiceStub::GetAddressByCoordinateInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return GetAddressByCoordinateInner(data, reply, identity); + }; geoConvertMsgHandleMap_[static_cast(GeoConvertInterfaceCode::GET_FROM_LOCATION_NAME_BY_BOUNDARY)] = - &GeoConvertServiceStub::GetAddressByLocationNameInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return GetAddressByLocationNameInner(data, reply, identity); + }; geoConvertMsgHandleMap_[static_cast(GeoConvertInterfaceCode::ENABLE_REVERSE_GEOCODE_MOCK)] = - &GeoConvertServiceStub::EnableReverseGeocodingMockInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return EnableReverseGeocodingMockInner(data, reply, identity); + }; geoConvertMsgHandleMap_[static_cast(GeoConvertInterfaceCode::DISABLE_REVERSE_GEOCODE_MOCK)] = - &GeoConvertServiceStub::DisableReverseGeocodingMockInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return DisableReverseGeocodingMockInner(data, reply, identity); + }; geoConvertMsgHandleMap_[static_cast(GeoConvertInterfaceCode::SET_REVERSE_GEOCODE_MOCKINFO)] = - &GeoConvertServiceStub::SetGeocodingMockInfoInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return SetGeocodingMockInfoInner(data, reply, identity); + }; } GeoConvertServiceStub::GeoConvertServiceStub() @@ -138,7 +150,6 @@ int GeoConvertServiceStub::OnRemoteRequest(uint32_t code, code, option.GetFlags(), callingPid, callingUid, std::to_string(CommonUtils::GetCurrentTimeStamp()).c_str()); if (data.ReadInterfaceToken() != GetDescriptor()) { LBSLOGE(GEO_CONVERT, "invalid token."); - reply.WriteInt32(ERRCODE_SERVICE_UNAVAILABLE); return ERRCODE_SERVICE_UNAVAILABLE; } @@ -146,12 +157,9 @@ int GeoConvertServiceStub::OnRemoteRequest(uint32_t code, auto handleFunc = geoConvertMsgHandleMap_.find(code); if (handleFunc != geoConvertMsgHandleMap_.end() && handleFunc->second != nullptr) { auto memberFunc = handleFunc->second; - ret = (this->*memberFunc)(data, reply, identity); + ret = memberFunc(data, reply, identity); } else { LBSLOGE(GEO_CONVERT, "OnReceived cmd = %{public}u, unsupport service.", code); -#if !defined(FEATURE_GNSS_SUPPORT) || !defined(FEATURE_GEOCODE_SUPPORT) - reply.WriteInt32(ERRCODE_NOT_SUPPORTED); -#endif ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option); } UnloadGeoConvertSystemAbility(); diff --git a/services/location_gnss/gnss/BUILD.gn b/services/location_gnss/gnss/BUILD.gn index ce5400cd..b947f3c1 100644 --- a/services/location_gnss/gnss/BUILD.gn +++ b/services/location_gnss/gnss/BUILD.gn @@ -15,21 +15,23 @@ import("//base/location/config.gni") import("//build/ohos.gni") if (location_feature_with_gnss) { + local_base_sources = [ + "$LOCATION_GNSS_ROOT/source/agnss_event_callback.cpp", + "$LOCATION_GNSS_ROOT/source/agnss_ni_manager.cpp", + "$LOCATION_GNSS_ROOT/source/geofence_event_callback.cpp", + "$LOCATION_GNSS_ROOT/source/gnss_ability.cpp", + "$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/string_utils.cpp", + "$LOCATION_LOCATOR_ROOT/source/location_config_manager.cpp", + "$LOCATION_LOCATOR_ROOT/source/subability_common.cpp", + "$LOCATION_LOCATOR_ROOT/source/work_record.cpp", + "$LOCATION_LOCATOR_ROOT/source/work_record_statistic.cpp", + ] + ohos_shared_library("lbsservice_gnss") { - sources = [ - "$LOCATION_GNSS_ROOT/source/agnss_event_callback.cpp", - "$LOCATION_GNSS_ROOT/source/agnss_ni_manager.cpp", - "$LOCATION_GNSS_ROOT/source/geofence_event_callback.cpp", - "$LOCATION_GNSS_ROOT/source/gnss_ability.cpp", - "$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/string_utils.cpp", - "$LOCATION_LOCATOR_ROOT/source/location_config_manager.cpp", - "$LOCATION_LOCATOR_ROOT/source/subability_common.cpp", - "$LOCATION_LOCATOR_ROOT/source/work_record.cpp", - "$LOCATION_LOCATOR_ROOT/source/work_record_statistic.cpp", - ] + sources = local_base_sources include_dirs = [ "$LOCATION_ROOT_DIR/interfaces/inner_api/include", @@ -51,13 +53,132 @@ if (location_feature_with_gnss) { external_deps = [ "ability_base:want", - "ability_runtime:ability_connect_callback_stub", - "c_utils:utils", "eventhandler:libeventhandler", + "ffrt:libffrt", "hdf_core:libhdi", "hilog:libhilog", - "init:libbegetutil", "ipc:ipc_single", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + defines = [] + + ldflags = [ + "-Wl,--as-needed", + "-Wl,--gc-sections", + ] + + cflags_cc = [ + "-ffunction-sections", + "-fdata-sections", + "-flto=thin", + "-Os", + ] + + if (telephony_core_service_enable) { + external_deps += [ "core_service:tel_core_service_api" ] + defines += [ "TEL_CORE_SERVICE_ENABLE" ] + } + + if (telephony_cellular_data_enable) { + external_deps += [ "cellular_data:tel_cellular_data_api" ] + defines += [ "TEL_CELLULAR_DATA_ENABLE" ] + } + + if (hdf_drivers_interface_location_agnss_enable) { + external_deps += + [ "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0" ] + defines += [ "HDF_DRIVERS_INTERFACE_AGNSS_ENABLE" ] + } + + if (location_feature_with_gnss && + hdf_drivers_interface_location_gnss_enable) { + external_deps += + [ "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0" ] + defines += [ "FEATURE_GNSS_SUPPORT" ] + } + + if (location_feature_with_passive) { + defines += [ "FEATURE_PASSIVE_SUPPORT" ] + } + + if (communication_wifi_enable) { + external_deps += [ "wifi:wifi_sdk" ] + defines += [ "WIFI_ENABLE" ] + } + + if (call_manager_enable) { + external_deps += [ "call_manager:tel_call_manager_api" ] + defines += [ "CALL_MANAGER_ENABLE" ] + } + + if (common_event_service_enable) { + external_deps += [ + "ability_runtime:extension_manager", + "common_event_service:cesfwk_innerkits", + ] + defines += [ "COMMON_EVENT_SERVICE_ENABLE" ] + } + + if (sms_mms_enable) { + external_deps += [ "sms_mms:tel_sms_mms_api" ] + defines += [ "SMS_MMS_ENABLE" ] + } + + if (notification_distributed_notification_service_enable) { + defines += [ "NOTIFICATION_ENABLE" ] + } + + if (hdf_drivers_interface_location_geofence_enable) { + external_deps += [ + "drivers_interface_location_geofence:liblocation_geofence_proxy_2.0", + ] + defines += [ "HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE" ] + } + + if (time_service_enable) { + external_deps += [ "time_service:time_client" ] + defines += [ "TIME_SERVICE_ENABLE" ] + } + + # Used to control the export of dynamic library symbols. + version_script = "liblbsservice_gnss_version_script.txt" + + part_name = "location" + subsystem_name = "location" + } + + ohos_static_library("lbsservice_gnss_static") { + sources = local_base_sources + + include_dirs = [ + "$LOCATION_ROOT_DIR/interfaces/inner_api/include", + "$LOCATION_GNSS_ROOT/include", + "$LOCATION_LOCATOR_ROOT/include", + ] + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + deps = [ + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", + ] + + external_deps = [ + "ability_base:want", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "hdf_core:libhdi", + "hilog:libhilog", + "ipc:ipc_single", + "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] @@ -115,7 +236,6 @@ if (location_feature_with_gnss) { } if (notification_distributed_notification_service_enable) { - external_deps += [ "distributed_notification_service:ans_innerkits" ] defines += [ "NOTIFICATION_ENABLE" ] } @@ -139,4 +259,9 @@ if (location_feature_with_gnss) { part_name = "location" subsystem_name = "location" } + + ohos_static_library("lbsservice_gnss_static") { + part_name = "location" + subsystem_name = "location" + } } diff --git a/services/location_gnss/gnss/include/agnss_event_callback.h b/services/location_gnss/gnss/include/agnss_event_callback.h index 78eb610a..b99b4c05 100644 --- a/services/location_gnss/gnss/include/agnss_event_callback.h +++ b/services/location_gnss/gnss/include/agnss_event_callback.h @@ -19,8 +19,10 @@ #ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE #include +#ifdef TEL_CORE_SERVICE_ENABLE #include "core_service_client.h" #include "cell_information.h" +#endif namespace OHOS { namespace Location { @@ -31,7 +33,10 @@ using HDI::Location::Agnss::V2_0::SubscriberSetIdType; using HDI::Location::Agnss::V2_0::AGnssRefInfo; using HDI::Location::Agnss::V2_0::AGnssRefInfoType; using HDI::Location::Agnss::V2_0::AGnssUserPlaneProtocol; + +#ifdef TEL_CORE_SERVICE_ENABLE using OHOS::Telephony::CellInformation; +#endif class AGnssEventCallback : public IAGnssCallback { public: @@ -40,10 +45,12 @@ public: int32_t RequestSubscriberSetId(SubscriberSetIdType type) override; int32_t RequestAgnssRefInfo(AGnssRefInfoType type) override; private: +#ifdef TEL_CORE_SERVICE_ENABLE void JudgmentDataGsm(AGnssRefInfo& refInfo, sptr infoItem); void JudgmentDataUmts(AGnssRefInfo& refInfo, sptr infoItem); void JudgmentDataLte(AGnssRefInfo& refInfo, sptr infoItem); void JudgmentDataNr(AGnssRefInfo& refInfo, sptr infoItem); +#endif __attribute__((no_sanitize("cfi"))) void GetWiFiRefInfo(AGnssRefInfo& refInfo); void GetCellRefInfo(AGnssRefInfo& refInfo); }; diff --git a/services/location_gnss/gnss/include/gnss_ability.h b/services/location_gnss/gnss/include/gnss_ability.h index 1f5b6b2c..0545eaf3 100644 --- a/services/location_gnss/gnss/include/gnss_ability.h +++ b/services/location_gnss/gnss/include/gnss_ability.h @@ -28,6 +28,7 @@ #endif #include "event_handler.h" +#include "ffrt.h" #include "system_ability.h" #ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE #include "agnss_event_callback.h" @@ -43,10 +44,6 @@ #include "locationhub_ipc_interface_code.h" #include "geofence_event_callback.h" #include "ipc_skeleton.h" -#ifdef NOTIFICATION_ENABLE -#include "notification_request.h" -#include "notification_helper.h" -#endif namespace OHOS { namespace Location { @@ -130,7 +127,7 @@ private: void HandleRemoveGeofence(const AppExecFwk::InnerEvent::Pointer& event); void HandleSendNetworkLocation(const AppExecFwk::InnerEvent::Pointer& event); - using GnssEventProcessHandle = void (GnssHandler::*)(const AppExecFwk::InnerEvent::Pointer& event); + using GnssEventProcessHandle = std::function; using GnssEventProcessMap = std::map; GnssEventProcessMap gnssEventProcessMap_; }; @@ -191,9 +188,6 @@ public: void SetSetIdImpl(const SubscriberSetId &id); void SetRefInfo(const AGnssRefInfo& refInfo); void SetRefInfoImpl(const AGnssRefInfo &refInfo); -#endif -#ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE - bool SetGeofenceCallback(); #endif void ReConnectHdiImpl(); bool IsMockEnabled(); @@ -233,33 +227,40 @@ private: int32_t GenerateFenceId(); bool IsGnssfenceRequestMapExist(); bool CheckBundleNameInGnssGeofenceRequestMap(std::string bundleName, int fenceId); + bool ConnectGnssHdi(); +#ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE + bool ConnectAgnssHdi(); +#endif +#ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE + bool SetGeofenceCallback(); + bool ConnectGeofenceHdi(); +#endif + bool IsDeviceLoaded(const std::string &servName); size_t mockLocationIndex_ = 0; bool registerToAbility_ = false; int gnssWorkingStatus_ = 0; std::shared_ptr gnssHandler_; ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START; - std::mutex gnssMutex_; - std::mutex nmeaMutex_; - std::mutex hdiMutex_; - std::mutex statusMutex_; + ffrt::mutex gnssMutex_; + ffrt::mutex nmeaMutex_; + ffrt::mutex hdiMutex_; + ffrt::mutex statusMutex_; std::vector> gnssStatusCallback_; std::vector> nmeaCallback_; - sptr gnssInterface_; sptr gnssCallback_; Location nlpLocation_; #ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE sptr agnssCallback_; - sptr agnssInterface_; #endif #ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE - sptr geofenceInterface_; sptr geofenceCallback_; #endif int32_t fenceId_; - std::mutex fenceIdMutex_; - std::mutex gnssGeofenceRequestMapMutex_; - std::map, sptr> gnssGeofenceRequestMap_; + ffrt::mutex fenceIdMutex_; + ffrt::mutex gnssGeofenceRequestMapMutex_; + std::map, + std::pair, sptr>> gnssGeofenceRequestMap_; }; class LocationHdiDeathRecipient : public IRemoteObject::DeathRecipient { diff --git a/services/location_gnss/gnss/include/gnss_ability_skeleton.h b/services/location_gnss/gnss/include/gnss_ability_skeleton.h index c282380c..03da0e8d 100644 --- a/services/location_gnss/gnss/include/gnss_ability_skeleton.h +++ b/services/location_gnss/gnss/include/gnss_ability_skeleton.h @@ -56,12 +56,12 @@ public: class GnssAbilityStub : public IRemoteStub { public: - using GnssMsgHandle = int (GnssAbilityStub::*)( - MessageParcel &data, MessageParcel &reply, AppIdentity &identity); + using GnssMsgHandle = std::function; using GnssMsgHandleMap = std::map; GnssAbilityStub(); virtual ~GnssAbilityStub() = default; void InitGnssMsgHandleMap(); + void InitGnssEnhanceMsgHandleMap(); int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; virtual void SendMessage(uint32_t code, MessageParcel &data, MessageParcel &reply) = 0; diff --git a/services/location_gnss/gnss/include/gnss_common_event_subscriber.h b/services/location_gnss/gnss/include/gnss_common_event_subscriber.h index 06cbddbe..e9a1eb3f 100644 --- a/services/location_gnss/gnss/include/gnss_common_event_subscriber.h +++ b/services/location_gnss/gnss/include/gnss_common_event_subscriber.h @@ -27,8 +27,8 @@ using namespace EventFwk; using CommonEventSubscriber = OHOS::EventFwk::CommonEventSubscriber; using CommonEventData = OHOS::EventFwk::CommonEventData; using CommonEventSubscribeInfo = OHOS::EventFwk::CommonEventSubscribeInfo; -const std::string AGNSS_NI_ACCEPT_EVENT = "usual.event.AGNSS_NI_ACCEPT"; -const std::string AGNSS_NI_REJECT_EVENT = "usual.event.AGNSS_NI_REJECT"; +constexpr const char* AGNSS_NI_ACCEPT_EVENT = "usual.event.AGNSS_NI_ACCEPT"; +constexpr const char* AGNSS_NI_REJECT_EVENT = "usual.event.AGNSS_NI_REJECT"; class GnssCommonEventSubscriber : public OHOS::EventFwk::CommonEventSubscriber { public: diff --git a/services/location_gnss/gnss/include/gnss_event_callback.h b/services/location_gnss/gnss/include/gnss_event_callback.h index 4f76cd77..5de75b2c 100644 --- a/services/location_gnss/gnss/include/gnss_event_callback.h +++ b/services/location_gnss/gnss/include/gnss_event_callback.h @@ -36,7 +36,7 @@ public: int32_t ReportLocation(const LocationInfo& location) override; int32_t ReportGnssWorkingStatus(GnssWorkingStatus status) override; int32_t ReportNmea(int64_t timestamp, const std::string& nmea, int32_t length) override; - int32_t ReportGnssCapabilities(GnssCapabilities capabilities) override; + int32_t ReportGnssCapabilities(unsigned int capabilities) override; int32_t ReportSatelliteStatusInfo(const SatelliteStatusInfo& info) override; int32_t RequestGnssReferenceInfo(GnssRefInfoType type) override; int32_t RequestPredictGnssData() override; diff --git a/services/location_gnss/gnss/liblbsservice_gnss_version_script.txt b/services/location_gnss/gnss/liblbsservice_gnss_version_script.txt new file mode 100644 index 00000000..1aeaa975 --- /dev/null +++ b/services/location_gnss/gnss/liblbsservice_gnss_version_script.txt @@ -0,0 +1,5 @@ +{ + global: + local: + *; +}; \ No newline at end of file diff --git a/services/location_gnss/gnss/source/agnss_event_callback.cpp b/services/location_gnss/gnss/source/agnss_event_callback.cpp index b21275da..2d944b5a 100644 --- a/services/location_gnss/gnss/source/agnss_event_callback.cpp +++ b/services/location_gnss/gnss/source/agnss_event_callback.cpp @@ -153,6 +153,7 @@ int32_t AGnssEventCallback::RequestAgnssRefInfo(AGnssRefInfoType type) return ERR_OK; } +#ifdef TEL_CORE_SERVICE_ENABLE void AGnssEventCallback::JudgmentDataGsm(AGnssRefInfo& refInfo, sptr infoItem) { auto gsmCellInfo = static_cast(infoItem.GetRefPtr()); @@ -203,6 +204,7 @@ void AGnssEventCallback::JudgmentDataUmts(AGnssRefInfo& refInfo, sptr(wcdmaCellInfo->GetCellId()); } } +#endif } // namespace Location } // namespace OHOS #endif diff --git a/services/location_gnss/gnss/source/agnss_ni_manager.cpp b/services/location_gnss/gnss/source/agnss_ni_manager.cpp index 2b8dd58b..9fa2771f 100644 --- a/services/location_gnss/gnss/source/agnss_ni_manager.cpp +++ b/services/location_gnss/gnss/source/agnss_ni_manager.cpp @@ -23,7 +23,9 @@ #include "location_data_rdb_manager.h" #include "location_log.h" #include "nlohmann/json.hpp" +#ifdef NOTIFICATION_ENABLE #include "notification_helper.h" +#endif #include "securec.h" #include "sms_service_manager_client.h" #include "string_utils.h" @@ -40,10 +42,12 @@ constexpr uint32_t TIME_AFTER_EMERGENCY_CALL = 10 * 1000; constexpr int32_t INVALID_SUBID = -1; const std::string URN_APPLICATION_ID = "x-oma-application:ulp.ua"; const std::string AGNSS_NI_SERVICE_NAME = "agnss_ni"; -const int32_t GNSS_AGNSS_NI_NOTIFICATION_ID = LOCATION_GNSS_SA_ID * 100; const std::string LOCATION_DIALOG_BUNDLE_NAME = "com.ohos.locationdialog"; const std::string AGNSS_NI_DIALOG_ABILITY_NAME = "ConfirmUIExtAbility"; +#ifdef NOTIFICATION_ENABLE +const int32_t GNSS_AGNSS_NI_NOTIFICATION_ID = LOCATION_GNSS_SA_ID * 100; constexpr uint32_t NOTIFICATION_AUTO_DELETED_TIME = 1000; +#endif AGnssNiManager* AGnssNiManager::GetInstance() { @@ -325,6 +329,7 @@ std::string AGnssNiManager::DecodeNiString(std::string original, int coding) void AGnssNiManager::SendNiNotification(const GnssNiNotificationRequest ¬if) { +#ifdef NOTIFICATION_ENABLE std::shared_ptr notificationNormalContent = std::make_shared(); std::string title = "Location Request"; @@ -353,15 +358,18 @@ void AGnssNiManager::SendNiNotification(const GnssNiNotificationRequest ¬if) return; } LBSLOGI(GNSS, "GNSS service publish notification success"); +#else + LBSLOGI(GNSS, "GNSS service publish notification not support"); +#endif } void AGnssNiManager::SendUserResponse(GnssNiResponseCmd responseCmd) { - std::unique_lock lock(mutex_); if (gnssInterface_ == nullptr) { LBSLOGE(GNSS, "gnssInterfacev1_0 is nullptr"); return; } + std::unique_lock lock(mutex_); gnssInterface_->SendNiUserResponse(niNotificationId_, responseCmd); } diff --git a/services/location_gnss/gnss/source/gnss_ability.cpp b/services/location_gnss/gnss/source/gnss_ability.cpp index f1f080c3..5d63dcb3 100644 --- a/services/location_gnss/gnss/source/gnss_ability.cpp +++ b/services/location_gnss/gnss/source/gnss_ability.cpp @@ -42,6 +42,11 @@ #include "location_log_event_ids.h" #include "location_data_rdb_manager.h" +#ifdef NOTIFICATION_ENABLE +#include "notification_request.h" +#include "notification_helper.h" +#endif + #include "hook_utils.h" #include "geofence_definition.h" @@ -57,12 +62,17 @@ const uint32_t EVENT_INTERVAL_UNITE = 1000; #ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE constexpr const char *AGNSS_SERVICE_NAME = "agnss_interface_service"; #endif +constexpr const char *LOCATION_HOST_NAME = "location_host"; constexpr const char *GNSS_SERVICE_NAME = "gnss_interface_service"; +#ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE constexpr const char *GEOFENCE_SERVICE_NAME = "geofence_interface_service"; -const std::string UNLOAD_GNSS_TASK = "gnss_sa_unload"; +#endif +constexpr const char *UNLOAD_GNSS_TASK = "gnss_sa_unload"; const uint32_t RETRY_INTERVAL_OF_UNLOAD_SA = 4 * 60 * EVENT_INTERVAL_UNITE; constexpr int32_t FENCE_MAX_ID = 1000000; +#ifdef TIME_SERVICE_ENABLE constexpr int DEFAULT_UNCERTAINTY = 30; +#endif constexpr int NLP_FIX_VALID_TIME = 2; } @@ -77,15 +87,13 @@ GnssAbility* GnssAbility::GetInstance() GnssAbility::GnssAbility() : SystemAbility(LOCATION_GNSS_SA_ID, true) { - gnssInterface_ = nullptr; gnssCallback_ = nullptr; #ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE agnssCallback_ = nullptr; - agnssInterface_ = nullptr; #endif gnssWorkingStatus_ = GNSS_WORKING_STATUS_NONE; SetAbility(GNSS_ABILITY); - gnssHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); + gnssHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true, AppExecFwk::ThreadMode::FFRT)); if (gnssHandler_ != nullptr) { AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get( static_cast(GnssAbilityInterfaceCode::INIT_HDI), 0); @@ -105,10 +113,19 @@ GnssAbility::~GnssAbility() bool GnssAbility::CheckIfHdiConnected() { + if (!IsDeviceLoaded(GNSS_SERVICE_NAME)) { + return false; + } #ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE - return gnssInterface_ != nullptr && agnssInterface_ != nullptr; -#else - return gnssInterface_ != nullptr; + if (!IsDeviceLoaded(AGNSS_SERVICE_NAME)) { + return false; + } +#endif +#ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE + if (!IsDeviceLoaded(GEOFENCE_SERVICE_NAME)) { + return false; + } + return true; #endif } @@ -131,6 +148,13 @@ void GnssAbility::OnStop() { state_ = ServiceRunningState::STATE_NOT_START; registerToAbility_ = false; + if (CheckIfHdiConnected()) { + auto startTime = CommonUtils::GetCurrentTimeStamp(); + auto ret = RemoveHdi(); + auto endTime = CommonUtils::GetCurrentTimeStamp(); + WriteLocationInnerEvent(HDI_EVENT, {"ret", std::to_string(ret), "type", "DisConnectHdi", + "startTime", std::to_string(startTime), "endTime", std::to_string(endTime)}); + } LBSLOGI(GNSS, "OnStop ability stopped."); } @@ -155,10 +179,6 @@ LocationErrCode GnssAbility::SendLocationRequest(WorkRecord &workrecord) LocationErrCode GnssAbility::SetEnable(bool state) { - if (!CheckIfHdiConnected()) { - LBSLOGE(GNSS, "no need start or stop gnss"); - return ERRCODE_SUCCESS; - } if (state) { EnableGnss(); StartGnss(); @@ -180,13 +200,6 @@ void GnssAbility::UnloadGnssSystemAbility() return; } auto task = [this]() { - if (CheckIfHdiConnected()) { - auto startTime = CommonUtils::GetCurrentTimeStamp(); - auto ret = RemoveHdi(); - auto endTime = CommonUtils::GetCurrentTimeStamp(); - WriteLocationInnerEvent(HDI_EVENT, {"ret", std::to_string(ret), "type", "DisConnectHdi", - "startTime", std::to_string(startTime), "endTime", std::to_string(endTime)}); - } LocationSaLoadManager::UnInitLocationSa(LOCATION_GNSS_SA_ID); }; if (gnssHandler_ != nullptr) { @@ -201,7 +214,7 @@ bool GnssAbility::CheckIfGnssConnecting() bool GnssAbility::IsGnssfenceRequestMapExist() { - std::unique_lock lock(gnssGeofenceRequestMapMutex_); + std::unique_lock lock(gnssGeofenceRequestMapMutex_); return gnssGeofenceRequestMap_.size() != 0; } @@ -224,7 +237,7 @@ LocationErrCode GnssAbility::RegisterGnssStatusCallback(const sptr lock(gnssMutex_); + std::unique_lock lock(gnssMutex_); gnssStatusCallback_.push_back(gnssStatusCallback); LBSLOGD(GNSS, "after uid:%{public}d register, gnssStatusCallback size:%{public}s", uid, std::to_string(gnssStatusCallback_.size()).c_str()); @@ -243,7 +256,7 @@ LocationErrCode GnssAbility::UnregisterGnssStatusCallback(const sptr lock(gnssMutex_); + std::unique_lock lock(gnssMutex_); size_t i = 0; for (; i < gnssStatusCallback_.size(); i++) { sptr remoteObject = gnssStatusCallback_[i]->AsObject(); @@ -276,7 +289,7 @@ LocationErrCode GnssAbility::RegisterNmeaMessageCallback(const sptr lock(nmeaMutex_); + std::unique_lock lock(nmeaMutex_); nmeaCallback_.push_back(nmeaCallback); LBSLOGD(GNSS, "after uid:%{public}d register, nmeaCallback size:%{public}s", uid, std::to_string(nmeaCallback_.size()).c_str()); @@ -295,7 +308,7 @@ LocationErrCode GnssAbility::UnregisterNmeaMessageCallback(const sptr lock(nmeaMutex_); + std::unique_lock lock(nmeaMutex_); size_t i = 0; for (; i < nmeaCallback_.size(); i++) { sptr remoteObject = nmeaCallback_[i]->AsObject(); @@ -367,7 +380,7 @@ void GnssAbility::RequestRecord(WorkRecord &workRecord, bool isAdded) StartGnss(); } else { // GNSS will stop only if all requests have stopped - if (CheckIfHdiConnected() && GetRequestNum() == 0) { + if (GetRequestNum() == 0) { StopGnss(); } } @@ -448,23 +461,25 @@ bool GnssAbility::GetCommandFlags(std::unique_ptr& commands, Gn LocationErrCode GnssAbility::SendCommand(std::unique_ptr& commands) { - if (gnssInterface_ == nullptr) { - LBSLOGE(GNSS, "gnssInterface_ is nullptr"); + sptr gnssInterface = IGnssInterface::Get(); + if (gnssInterface == nullptr) { + LBSLOGE(GNSS, "gnssInterface is nullptr"); return ERRCODE_SERVICE_UNAVAILABLE; } GnssAuxiliaryDataType flags; bool result = GetCommandFlags(commands, flags); LBSLOGE(GNSS, "GetCommandFlags,flags = %{public}d", flags); if (result) { - gnssInterface_->DeleteAuxiliaryData(flags); + gnssInterface->DeleteAuxiliaryData(flags); } return ERRCODE_SUCCESS; } LocationErrCode GnssAbility::SetPositionMode() { - if (gnssInterface_ == nullptr) { - LBSLOGE(GNSS, "gnssInterface_ is nullptr"); + sptr gnssInterface = IGnssInterface::Get(); + if (gnssInterface == nullptr) { + LBSLOGE(GNSS, "gnssInterface is nullptr"); return ERRCODE_SERVICE_UNAVAILABLE; } GnssConfigPara para; @@ -479,7 +494,7 @@ LocationErrCode GnssAbility::SetPositionMode() LBSLOGE(GNSS, "unknow mode"); return ERRCODE_SUCCESS; } - int ret = gnssInterface_->SetGnssConfigPara(para); + int ret = gnssInterface->SetGnssConfigPara(para); if (ret != ERRCODE_SUCCESS) { LBSLOGE(GNSS, "SetGnssConfigPara failed , ret =%{public}d", ret); } @@ -489,8 +504,9 @@ LocationErrCode GnssAbility::SetPositionMode() LocationErrCode GnssAbility::InjectTime() { #ifdef TIME_SERVICE_ENABLE - if (gnssInterface_ == nullptr) { - LBSLOGE(GNSS, "gnssInterface_ is nullptr"); + sptr gnssInterface = IGnssInterface::Get(); + if (gnssInterface == nullptr) { + LBSLOGE(GNSS, "gnssInterface is nullptr"); return ERRCODE_SERVICE_UNAVAILABLE; } @@ -505,7 +521,7 @@ LocationErrCode GnssAbility::InjectTime() refInfo.time.time = wallTime; refInfo.time.elapsedRealtime = elapsedTime; refInfo.time.uncertaintyOfTime = DEFAULT_UNCERTAINTY; - gnssInterface_->SetGnssReferenceInfo(refInfo); + gnssInterface->SetGnssReferenceInfo(refInfo); #endif return ERRCODE_SUCCESS; } @@ -522,8 +538,9 @@ LocationErrCode GnssAbility::SendNetworkLocation(const std::unique_ptr LocationErrCode GnssAbility::InjectLocation() { - if (gnssInterface_ == nullptr) { - LBSLOGE(GNSS, "gnssInterface_ or location is nullptr"); + sptr gnssInterface = IGnssInterface::Get(); + if (gnssInterface == nullptr) { + LBSLOGE(GNSS, "gnssInterface or location is nullptr"); return ERRCODE_SERVICE_UNAVAILABLE; } if (nlpLocation_.GetAccuracy() < 1e-9 || nlpLocation_.GetTimeStamp() == 0) { @@ -537,7 +554,8 @@ LocationErrCode GnssAbility::InjectLocation() } GnssRefInfo refInfo; refInfo.type = GnssRefInfoType::GNSS_REF_INFO_LOCATION; - refInfo.gnssLocation.fieldValidity = GnssLocationValidity::GNSS_LOCATION_LAT_VALID; + refInfo.gnssLocation.fieldValidity = + GnssLocationValidity::GNSS_LOCATION_LAT_VALID | GnssLocationValidity::GNSS_LOCATION_LONG_VALID; refInfo.gnssLocation.latitude = nlpLocation_.GetLatitude(); refInfo.gnssLocation.longitude = nlpLocation_.GetLongitude(); refInfo.gnssLocation.altitude = nlpLocation_.GetAltitude(); @@ -550,7 +568,7 @@ LocationErrCode GnssAbility::InjectLocation() refInfo.gnssLocation.timeForFix = nlpLocation_.GetTimeStamp(); refInfo.gnssLocation.timeSinceBoot = nlpLocation_.GetTimeSinceBoot(); refInfo.gnssLocation.timeUncertainty = nlpLocation_.GetUncertaintyOfTimeSinceBoot(); - gnssInterface_->SetGnssReferenceInfo(refInfo); + gnssInterface->SetGnssReferenceInfo(refInfo); return ERRCODE_SUCCESS; } @@ -559,11 +577,12 @@ LocationErrCode GnssAbility::AddFence(std::shared_ptr& request) int fenceId = GenerateFenceId(); request->SetFenceId(fenceId); #ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE - auto geofence = request->GetGeofence(); - if (geofenceInterface_ == nullptr) { - LBSLOGE(GNSS, "geofenceInterface_ is nullptr"); + sptr geofenceInterface = IGeofenceInterface::Get(); + if (geofenceInterface == nullptr) { + LBSLOGE(GNSS, "geofenceInterface is nullptr"); return ERRCODE_SERVICE_UNAVAILABLE; } + auto geofence = request->GetGeofence(); GeofenceInfo fenceInfo; fenceInfo.fenceIndex = fenceId; fenceInfo.latitude = geofence.latitude; @@ -571,7 +590,7 @@ LocationErrCode GnssAbility::AddFence(std::shared_ptr& request) 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)); + int32_t ret = geofenceInterface->AddGnssGeofence(fenceInfo, monitorEvent); LBSLOGD(GNSS, "Successfully AddFence!, %{public}d", ret); #endif if (ExecuteFenceProcess(GnssInterfaceCode::ADD_FENCE_INFO, request)) { @@ -582,12 +601,17 @@ LocationErrCode GnssAbility::AddFence(std::shared_ptr& request) LocationErrCode GnssAbility::RemoveFence(std::shared_ptr& request) { + if (request == nullptr) { + LBSLOGE(GNSS, "request is nullptr"); + return ERRCODE_GEOFENCE_FAIL; + } #ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE - if (geofenceInterface_ == nullptr || request == nullptr) { - LBSLOGE(GNSS, "geofenceInterface_ is nullptr"); + sptr geofenceInterface = IGeofenceInterface::Get(); + if (geofenceInterface == nullptr) { + LBSLOGE(GNSS, "geofenceInterface is nullptr"); return ERRCODE_SERVICE_UNAVAILABLE; } - int32_t ret = geofenceInterface_->DeleteGnssGeofence(request->GetFenceId()); + int32_t ret = geofenceInterface->DeleteGnssGeofence(request->GetFenceId()); LBSLOGD(GNSS, "Successfully RemoveFence!, %{public}d", ret); #endif if (ExecuteFenceProcess(GnssInterfaceCode::REMOVE_FENCE_INFO, request)) { @@ -599,7 +623,7 @@ LocationErrCode GnssAbility::RemoveFence(std::shared_ptr& reque int32_t GnssAbility::GenerateFenceId() { LBSLOGD(GNSS, "GenerateFenceId"); - std::lock_guard lock(fenceIdMutex_); + std::lock_guard lock(fenceIdMutex_); if (fenceId_ > FENCE_MAX_ID) { fenceId_ = 0; } @@ -613,11 +637,12 @@ LocationErrCode GnssAbility::AddGnssGeofence(std::shared_ptr& r int fenceId = GenerateFenceId(); request->SetFenceId(fenceId); #ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE - auto geofence = request->GetGeofence(); - if (geofenceInterface_ == nullptr) { - LBSLOGE(GNSS, "geofenceInterface_ is nullptr"); + sptr geofenceInterface = IGeofenceInterface::Get(); + if (geofenceInterface == nullptr) { + LBSLOGE(GNSS, "geofenceInterface is nullptr"); return ERRCODE_SERVICE_UNAVAILABLE; } + auto geofence = request->GetGeofence(); GeofenceInfo fenceInfo; fenceInfo.fenceIndex = fenceId; fenceInfo.latitude = geofence.latitude; @@ -629,7 +654,7 @@ LocationErrCode GnssAbility::AddGnssGeofence(std::shared_ptr& r GeofenceTransitionEvent status = transitionList[i]; monitorEvent |= static_cast(status); } - int32_t ret = geofenceInterface_->AddGnssGeofence(fenceInfo, static_cast(monitorEvent)); + int32_t ret = geofenceInterface->AddGnssGeofence(fenceInfo, monitorEvent); LBSLOGD(GNSS, "Successfully AddGnssGeofence!, %{public}d", ret); #endif RegisterGnssGeofenceCallback(request, request->GetGeofenceTransitionCallback()); @@ -650,10 +675,10 @@ bool GnssAbility::RegisterGnssGeofenceCallback(std::shared_ptr LBSLOGE(GNSS, "register an invalid callback"); return false; } - std::unique_lock lock(gnssGeofenceRequestMapMutex_); + std::unique_lock lock(gnssGeofenceRequestMapMutex_); sptr death(new (std::nothrow) GnssGeofenceCallbackDeathRecipient()); callback->AddDeathRecipient(death); - gnssGeofenceRequestMap_.insert(std::make_pair(request, callback)); + gnssGeofenceRequestMap_.insert(std::make_pair(request, std::make_pair(callback, death))); return true; } @@ -668,11 +693,12 @@ LocationErrCode GnssAbility::RemoveGnssGeofence(std::shared_ptr return ERRCODE_GEOFENCE_INCORRECT_ID; } #ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE - if (geofenceInterface_ == nullptr) { - LBSLOGE(GNSS, "geofenceInterface_ is nullptr"); + sptr geofenceInterface = IGeofenceInterface::Get(); + if (geofenceInterface == nullptr) { + LBSLOGE(GNSS, "geofenceInterface is nullptr"); return ERRCODE_SERVICE_UNAVAILABLE; } - int32_t ret = geofenceInterface_->DeleteGnssGeofence(request->GetFenceId()); + int32_t ret = geofenceInterface->DeleteGnssGeofence(request->GetFenceId()); LBSLOGD(GNSS, "Successfully DeleteGnssGeofence!, %{public}d", ret); #endif @@ -687,7 +713,10 @@ bool GnssAbility::UnregisterGnssGeofenceCallback(int fenceId) for (auto iter = gnssGeofenceRequestMap_.begin(); iter != gnssGeofenceRequestMap_.end();) { auto requestInMap = iter->first; auto fenceIdInMap = requestInMap->GetFenceId(); + auto callbackPair = iter->second; + auto callback = callbackPair.first; if (fenceId == fenceIdInMap) { + callback->RemoveDeathRecipient(callbackPair.second); iter = gnssGeofenceRequestMap_.erase(iter); break; } else { @@ -701,7 +730,7 @@ bool GnssAbility::UnregisterGnssGeofenceCallback(int fenceId) bool GnssAbility::CheckBundleNameInGnssGeofenceRequestMap(std::string bundleName, int fenceId) { - std::unique_lock lock(gnssGeofenceRequestMapMutex_); + std::unique_lock lock(gnssGeofenceRequestMapMutex_); for (auto iter = gnssGeofenceRequestMap_.begin(); iter != gnssGeofenceRequestMap_.end(); iter++) { auto requestInMap = iter->first; @@ -719,10 +748,12 @@ bool GnssAbility::RemoveGnssGeofenceRequestByCallback(sptr callba if (callbackObj == nullptr) { return false; } - std::unique_lock lock(gnssGeofenceRequestMapMutex_); + std::unique_lock lock(gnssGeofenceRequestMapMutex_); for (auto iter = gnssGeofenceRequestMap_.begin(); iter != gnssGeofenceRequestMap_.end();) { - auto callback = iter->second; + auto callbackPair = iter->second; + auto callback = callbackPair.first; if (callback == callbackObj) { + callback->RemoveDeathRecipient(callbackPair.second); iter = gnssGeofenceRequestMap_.erase(iter); break; } else { @@ -738,7 +769,7 @@ bool GnssAbility::RemoveGnssGeofenceRequestByCallback(sptr callba void GnssAbility::ReportGeofenceOperationResult( int fenceId, GeofenceOperateType type, GeofenceOperateResult result) { - std::unique_lock lock(gnssGeofenceRequestMapMutex_); + std::unique_lock lock(gnssGeofenceRequestMapMutex_); auto geofenceRequest = GetGeofenceRequestByFenceId(fenceId); if (geofenceRequest == nullptr) { LBSLOGE(GNSS, "request is nullptr"); @@ -761,7 +792,7 @@ void GnssAbility::ReportGeofenceOperationResult( #ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE void GnssAbility::ReportGeofenceEvent(int fenceIndex, GeofenceEvent event) { - std::unique_lock lock(gnssGeofenceRequestMapMutex_); + std::unique_lock lock(gnssGeofenceRequestMapMutex_); auto request = GetGeofenceRequestByFenceId(fenceIndex); if (request == nullptr) { LBSLOGE(GNSS, "request is nullptr"); @@ -774,9 +805,6 @@ void GnssAbility::ReportGeofenceEvent(int fenceIndex, GeofenceEvent event) } sptr gnssGeofenceCallback = iface_cast(callback); auto transitionStatusList = request->GetGeofenceTransitionEventList(); -#ifdef NOTIFICATION_ENABLE - auto notificationRequestList = request->GetNotificationRequestList(); -#endif for (size_t i = 0; i < transitionStatusList.size(); i++) { if (transitionStatusList[i] != static_cast(event)) { @@ -787,6 +815,7 @@ void GnssAbility::ReportGeofenceEvent(int fenceIndex, GeofenceEvent event) geofenceTransition.event = transitionStatusList[i]; gnssGeofenceCallback->OnTransitionStatusChange(geofenceTransition); #ifdef NOTIFICATION_ENABLE + auto notificationRequestList = request->GetNotificationRequestList(); if (transitionStatusList.size() == notificationRequestList.size()) { auto notificationRequest = notificationRequestList[i]; notificationRequest.SetCreatorUid(IPCSkeleton::GetCallingUid()); @@ -818,7 +847,10 @@ bool GnssAbility::ExecuteFenceProcess( fenceStruct.requestCode = static_cast(code); fenceStruct.retCode = true; #ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE + std::unique_lock lock(hdiMutex_, std::defer_lock); + lock.lock(); fenceStruct.callback = geofenceCallback_; + lock.unlock(); #endif HookUtils::ExecuteHook( LocationProcessStage::FENCE_REQUEST_PROCESS, (void *)&fenceStruct, nullptr); @@ -832,12 +864,16 @@ bool GnssAbility::SetGeofenceCallback() LBSLOGE(GNSS, "QuerySwitchState is DISABLED"); return false; } - if (geofenceInterface_ == nullptr || geofenceCallback_ == nullptr) { - LBSLOGE(GNSS, "geofenceInterface_ or geofenceCallback_ is nullptr"); + sptr geofenceInterface = IGeofenceInterface::Get(); + if (geofenceInterface == nullptr) { + LBSLOGE(GNSS, "geofenceInterface get failed"); return false; } - int32_t ret = geofenceInterface_->SetGeofenceCallback(geofenceCallback_); + int32_t ret = geofenceInterface->SetGeofenceCallback(geofenceCallback_); LBSLOGD(GNSS, "set geofence callback, ret:%{public}d", ret); + if (!ret) { + return false; + } return true; } #endif @@ -848,7 +884,7 @@ void GnssAbility::ReportGnssSessionStatus(int status) void GnssAbility::ReportNmea(int64_t timestamp, const std::string &nmea) { - std::unique_lock lock(nmeaMutex_); + std::unique_lock lock(nmeaMutex_); for (auto nmeaCallback : nmeaCallback_) { nmeaCallback->OnMessageChange(timestamp, nmea); } @@ -856,7 +892,7 @@ void GnssAbility::ReportNmea(int64_t timestamp, const std::string &nmea) void GnssAbility::ReportSv(const std::unique_ptr &sv) { - std::unique_lock lock(gnssMutex_); + std::unique_lock lock(gnssMutex_); for (auto gnssStatusCallback : gnssStatusCallback_) { gnssStatusCallback->OnStatusChange(sv); } @@ -868,15 +904,24 @@ bool GnssAbility::EnableGnss() LBSLOGE(GNSS, "QuerySwitchState is DISABLED"); return false; } - if (gnssInterface_ == nullptr || gnssCallback_ == nullptr) { - LBSLOGE(GNSS, "gnssInterface_ or gnssCallback_ is nullptr"); + sptr gnssInterface = IGnssInterface::Get(); + if (gnssInterface == nullptr) { + LBSLOGE(GNSS, "gnssInterface is nullptr"); return false; } if (IsGnssEnabled()) { LBSLOGE(GNSS, "gnss has been enabled"); return false; } - int32_t ret = gnssInterface_->EnableGnss(gnssCallback_); + std::unique_lock lock(hdiMutex_, std::defer_lock); + lock.lock(); + if (gnssCallback_ == nullptr) { + LBSLOGE(GNSS, "gnssCallback_ is nullptr"); + lock.unlock(); + return false; + } + int32_t ret = gnssInterface->EnableGnss(gnssCallback_); + lock.unlock(); LBSLOGD(GNSS, "Successfully enable_gnss!, %{public}d", ret); if (ret == 0) { gnssWorkingStatus_ = GNSS_WORKING_STATUS_ENGINE_ON; @@ -890,15 +935,16 @@ bool GnssAbility::EnableGnss() void GnssAbility::DisableGnss() { - if (gnssInterface_ == nullptr) { - LBSLOGE(GNSS, "gnssInterface_ is nullptr"); + sptr gnssInterface = IGnssInterface::Get(); + if (gnssInterface == nullptr) { + LBSLOGE(GNSS, "gnssInterface is nullptr"); return; } if (!IsGnssEnabled()) { LBSLOGE(GNSS, "%{public}s gnss has been disabled", __func__); return; } - int ret = gnssInterface_->DisableGnss(); + int ret = gnssInterface->DisableGnss(); if (ret == 0) { gnssWorkingStatus_ = GNSS_WORKING_STATUS_ENGINE_OFF; } else { @@ -915,7 +961,7 @@ bool GnssAbility::IsGnssEnabled() void GnssAbility::RestGnssWorkStatus() { - std::unique_lock uniqueLock(statusMutex_); + std::unique_lock uniqueLock(statusMutex_); gnssWorkingStatus_ = GNSS_WORKING_STATUS_NONE; } @@ -925,8 +971,9 @@ void GnssAbility::StartGnss() LBSLOGE(GNSS, "QuerySwitchState is DISABLED"); return; } - if (gnssInterface_ == nullptr) { - LBSLOGE(GNSS, "gnssInterface_ is nullptr"); + sptr gnssInterface = IGnssInterface::Get(); + if (gnssInterface == nullptr) { + LBSLOGE(GNSS, "gnssInterface is nullptr"); return; } if (!IsGnssEnabled()) { @@ -941,7 +988,7 @@ void GnssAbility::StartGnss() return; } SetPositionMode(); - int ret = gnssInterface_->StartGnss(GNSS_START_TYPE_NORMAL); + int ret = gnssInterface->StartGnss(GNSS_START_TYPE_NORMAL); if (ret == 0) { gnssWorkingStatus_ = GNSS_WORKING_STATUS_SESSION_BEGIN; WriteLocationInnerEvent(START_GNSS, {}); @@ -957,16 +1004,17 @@ void GnssAbility::StartGnss() void GnssAbility::StopGnss() { - if (gnssInterface_ == nullptr) { - LBSLOGE(GNSS, "gnssInterface_ is nullptr"); + sptr gnssInterface = IGnssInterface::Get(); + if (gnssInterface == nullptr) { + LBSLOGE(GNSS, "gnssInterface is nullptr"); return; } if (!IsGnssEnabled()) { LBSLOGE(GNSS, "%{public}s gnss has been disabled", __func__); return; } - - int ret = gnssInterface_->StopGnss(GNSS_START_TYPE_NORMAL); + + int ret = gnssInterface->StopGnss(GNSS_START_TYPE_NORMAL); if (ret == 0) { gnssWorkingStatus_ = GNSS_WORKING_STATUS_SESSION_END; WriteLocationInnerEvent(STOP_GNSS, {}); @@ -980,59 +1028,150 @@ void GnssAbility::StopGnss() } } -bool GnssAbility::ConnectHdi() +bool GnssAbility::IsDeviceLoaded(const std::string &servName) { auto devmgr = HDI::DeviceManager::V1_0::IDeviceManager::Get(); if (devmgr == nullptr) { LBSLOGE(GNSS, "fail to get devmgr."); return false; } - if (devmgr->LoadDevice(GNSS_SERVICE_NAME) != 0) { - LBSLOGE(GNSS, "Load gnss service failed!"); + std::vector deviceInfos; + int ret = devmgr->ListAllDevice(deviceInfos); + if (ret != HDF_SUCCESS) { + LBSLOGE(GNSS, "get listAllDevice failed"); return false; } -#ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE - if (devmgr->LoadDevice(AGNSS_SERVICE_NAME) != 0) { - LBSLOGE(GNSS, "Load agnss service failed!"); - return false; - } -#endif - if (devmgr->LoadDevice(GEOFENCE_SERVICE_NAME) != 0) { - LBSLOGE(GNSS, "Load gnss service failed!"); - return false; - } - std::unique_lock lock(hdiMutex_, std::defer_lock); - lock.lock(); - gnssInterface_ = IGnssInterface::Get(); -#ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE - geofenceInterface_ = IGeofenceInterface::Get(); - if (geofenceInterface_ != nullptr) { - geofenceCallback_ = sptr(new (std::nothrow) GeofenceEventCallback); - SetGeofenceCallback(); - } -#endif -#ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE - agnssInterface_ = IAGnssInterface::Get(); - if (agnssInterface_ != nullptr) { - agnssCallback_ = new (std::nothrow) AGnssEventCallback(); - } -#endif - if (gnssInterface_ != nullptr) { - LBSLOGD(GNSS, "connect v2_0 hdi success."); - if (gnssCallback_ == nullptr) { - gnssCallback_ = new (std::nothrow) GnssEventCallback(); + auto itDevicesInfo = deviceInfos.begin(); + for (;itDevicesInfo != deviceInfos.end(); itDevicesInfo++) { + if (itDevicesInfo->hostName == LOCATION_HOST_NAME) { + break; } - RegisterLocationHdiDeathRecipient(); - lock.unlock(); - return true; + } + if (itDevicesInfo == deviceInfos.end()) { + LBSLOGE(GNSS, "The host is not found:%{public}s", LOCATION_HOST_NAME); + return false; + } + auto itDevInfo = itDevicesInfo->devInfo.begin(); + for (;itDevInfo != itDevicesInfo->devInfo.end(); itDevInfo++) { + if (itDevInfo->servName == servName) { + break; + } + } + if (itDevInfo == itDevicesInfo->devInfo.end()) { + LBSLOGE(GNSS, "The devices is not found:%{public}s in host %{public}s", servName.c_str(), LOCATION_HOST_NAME); + return false; + } + std::unique_lock lock(hdiMutex_, std::defer_lock); + LBSLOGI(GNSS, "check host:%{public}s dev:%{public}s loaded", + itDevicesInfo->hostName.c_str(), itDevInfo->servName.c_str()); + return true; +} + +bool GnssAbility::ConnectGnssHdi() +{ + auto devmgr = HDI::DeviceManager::V1_0::IDeviceManager::Get(); + if (devmgr == nullptr) { + LBSLOGE(GNSS, "fail to get devmgr."); + return false; + } + if (!IsDeviceLoaded(GNSS_SERVICE_NAME)) { + if (devmgr->LoadDevice(GNSS_SERVICE_NAME) != HDF_SUCCESS) { + LBSLOGE(GNSS, "Load gnss service failed!"); + return false; + } + } + sptr gnssInterface = IGnssInterface::Get(); + if (gnssInterface == nullptr) { + LBSLOGE(GNSS, "gnssInterface get failed"); + return false; + } + std::unique_lock lock(hdiMutex_, std::defer_lock); + lock.lock(); + if (gnssCallback_ == nullptr) { + gnssCallback_ = new (std::nothrow) GnssEventCallback(); } lock.unlock(); - LBSLOGE(GNSS, "connect v2_0 hdi failed."); - return false; + RegisterLocationHdiDeathRecipient(); + LBSLOGI(GNSS, "ConnectGnssHdi success"); + return true; +} +#ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE +bool GnssAbility::ConnectAgnssHdi() +{ + auto devmgr = HDI::DeviceManager::V1_0::IDeviceManager::Get(); + if (devmgr == nullptr) { + LBSLOGE(GNSS, "fail to get devmgr."); + return false; + } + if (!IsDeviceLoaded(AGNSS_SERVICE_NAME)) { + if (devmgr->LoadDevice(AGNSS_SERVICE_NAME) != HDF_SUCCESS) { + LBSLOGE(GNSS, "Load agnss service failed!"); + return false; + } + } + sptr agnssInterface = IAGnssInterface::Get(); + if (agnssInterface == nullptr) { + LBSLOGE(GNSS, "agnssInterface get failed"); + return false; + } + std::unique_lock lock(hdiMutex_); + if (agnssCallback_ == nullptr) { + agnssCallback_ = new (std::nothrow) AGnssEventCallback(); + } + LBSLOGI(GNSS, "ConnectAgnssHdi success"); + return true; +} +#endif +#ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE +bool GnssAbility::ConnectGeofenceHdi() +{ + auto devmgr = HDI::DeviceManager::V1_0::IDeviceManager::Get(); + if (devmgr == nullptr) { + LBSLOGE(GNSS, "fail to get devmgr."); + return false; + } + if (!IsDeviceLoaded(GEOFENCE_SERVICE_NAME)) { + if (devmgr->LoadDevice(GEOFENCE_SERVICE_NAME) != HDF_SUCCESS) { + LBSLOGE(GNSS, "Load geofence service failed!"); + return false; + } + } + std::unique_lock lock(hdiMutex_); + if (geofenceCallback_ == nullptr) { + geofenceCallback_ = sptr(new (std::nothrow) GeofenceEventCallback); + } + bool ret = SetGeofenceCallback(); + if (!ret) { + LBSLOGE(GNSS, "ConnectGeofenceHdi fail"); + return false; + } + LBSLOGI(GNSS, "ConnectGeofenceHdi success"); + return true; +} +#endif + +bool GnssAbility::ConnectHdi() +{ + if (!ConnectGnssHdi()) { + return false; + } +#ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE + if (!ConnectAgnssHdi()) { + return false; + } +#endif +#ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE + if (!ConnectGeofenceHdi()) { + return false; + } +#endif + LBSLOGI(GNSS, "connect v2_0 hdi success."); + return true; } bool GnssAbility::RemoveHdi() { + std::unique_lock lock(hdiMutex_); auto devmgr = HDI::DeviceManager::V1_0::IDeviceManager::Get(); if (devmgr == nullptr) { LBSLOGE(GNSS, "fail to get devmgr."); @@ -1043,14 +1182,12 @@ bool GnssAbility::RemoveHdi() return false; } gnssCallback_ = nullptr; - gnssInterface_ = nullptr; #ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE if (devmgr->UnloadDevice(AGNSS_SERVICE_NAME) != 0) { LBSLOGE(GNSS, "Unload agnss service failed!"); return false; } agnssCallback_ = nullptr; - agnssInterface_ = nullptr; #endif #ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE if (devmgr->UnloadDevice(GEOFENCE_SERVICE_NAME) != 0) { @@ -1058,7 +1195,6 @@ bool GnssAbility::RemoveHdi() return false; } geofenceCallback_ = nullptr; - geofenceInterface_ = nullptr; #endif LBSLOGI(GNSS, "RemoveHdi success."); return true; @@ -1067,10 +1203,6 @@ bool GnssAbility::RemoveHdi() #ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE void GnssAbility::SetAgnssServer() { - if (agnssInterface_ == nullptr) { - LBSLOGE(GNSS, "agnssInterface_ is nullptr"); - return; - } if (!IsGnssEnabled()) { LBSLOGE(GNSS, "%{public}s gnss has been disabled", __func__); return; @@ -1082,25 +1214,32 @@ void GnssAbility::SetAgnssServer() return; } int port = LocationConfigManager::GetInstance()->GetAgnssServerPort(); + sptr agnssInterface = IAGnssInterface::Get(); + if (agnssInterface == nullptr) { + LBSLOGE(GNSS, "agnssInterface is nullptr"); + return; + } AGnssServerInfo info; info.type = AGNSS_TYPE_SUPL; info.server = addrName; info.port = port; - agnssInterface_->SetAgnssServer(info); + agnssInterface->SetAgnssServer(info); } void GnssAbility::SetAgnssCallback() { LBSLOGD(GNSS, "enter SetAgnssCallback"); - if (agnssInterface_ == nullptr || agnssCallback_ == nullptr) { - LBSLOGE(GNSS, "agnssInterface_ or agnssCallback_ is nullptr"); + std::unique_lock lock(hdiMutex_); + sptr agnssInterface = IAGnssInterface::Get(); + if (agnssInterface == nullptr || agnssCallback_ == nullptr) { + LBSLOGE(GNSS, "agnssInterface or agnssCallback_ is nullptr"); return; } if (!IsGnssEnabled()) { LBSLOGE(GNSS, "%{public}s gnss has been disabled", __func__); return; } - agnssInterface_->SetAgnssCallback(agnssCallback_); + agnssInterface->SetAgnssCallback(agnssCallback_); } void GnssAbility::SetSetId(const SubscriberSetId& id) @@ -1117,15 +1256,16 @@ void GnssAbility::SetSetId(const SubscriberSetId& id) void GnssAbility::SetSetIdImpl(const SubscriberSetId& id) { - if (agnssInterface_ == nullptr) { - LBSLOGE(GNSS, "agnssInterface_ is nullptr"); + sptr agnssInterface = IAGnssInterface::Get(); + if (agnssInterface == nullptr) { + LBSLOGE(GNSS, "agnssInterface is nullptr"); return; } if (!IsGnssEnabled()) { LBSLOGE(GNSS, "%{public}s gnss has been disabled", __func__); return; } - agnssInterface_->SetSubscriberSetId(id); + agnssInterface->SetSubscriberSetId(id); } void GnssAbility::SetRefInfo(const AGnssRefInfo& refInfo) @@ -1141,15 +1281,16 @@ void GnssAbility::SetRefInfo(const AGnssRefInfo& refInfo) void GnssAbility::SetRefInfoImpl(const AGnssRefInfo &refInfo) { - if (agnssInterface_ == nullptr) { - LBSLOGE(GNSS, "agnssInterface_ is nullptr"); + sptr agnssInterface = IAGnssInterface::Get(); + if (agnssInterface == nullptr) { + LBSLOGE(GNSS, "agnssInterface is nullptr"); return; } if (!IsGnssEnabled()) { LBSLOGE(GNSS, "%{public}s gnss has been disabled", __func__); return; } - agnssInterface_->SetAgnssRefInfo(refInfo); + agnssInterface->SetAgnssRefInfo(refInfo); } AGnssRefInfo AgnssRefInfoMessage::GetAgnssRefInfo() @@ -1330,6 +1471,7 @@ void GnssAbility::SendMessage(uint32_t code, MessageParcel &data, MessageParcel SendEvent(event, reply); break; } +#ifdef NOTIFICATION_ENABLE case static_cast(GnssAbilityInterfaceCode::ADD_FENCE): { auto request = GeofenceRequest::Unmarshalling(data); AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(code, request); @@ -1356,6 +1498,7 @@ void GnssAbility::SendMessage(uint32_t code, MessageParcel &data, MessageParcel SendEvent(event, reply); break; } +#endif case static_cast(GnssInterfaceCode::SEND_NETWORK_LOCATION): { auto request = Location::Unmarshalling(data); AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(code, request); @@ -1382,11 +1525,12 @@ void GnssAbility::SendEvent(AppExecFwk::InnerEvent::Pointer& event, MessageParce void GnssAbility::RegisterLocationHdiDeathRecipient() { - if (gnssInterface_ == nullptr) { - LBSLOGE(GNSS, "%{public}s: gnssInterface_ is nullptr", __func__); + sptr gnssInterface = IGnssInterface::Get(); + if (gnssInterface == nullptr) { + LBSLOGE(GNSS, "%{public}s: gnssInterface is nullptr", __func__); return; } - sptr obj = OHOS::HDI::hdi_objcast(gnssInterface_); + sptr obj = OHOS::HDI::hdi_objcast(gnssInterface); if (obj == nullptr) { LBSLOGE(GNSS, "%{public}s: hdi obj is nullptr", __func__); return; @@ -1406,35 +1550,35 @@ void GnssHandler::InitGnssEventProcessMap() return; } gnssEventProcessMap_[static_cast(GnssAbilityInterfaceCode::EVENT_REPORT_MOCK_LOCATION)] = - &GnssHandler::HandleReportMockLocation; + [this](const AppExecFwk::InnerEvent::Pointer& event) { HandleReportMockLocation(event); }; gnssEventProcessMap_[static_cast(GnssInterfaceCode::SEND_LOCATION_REQUEST)] = - &GnssHandler::HandleSendLocationRequest; + [this](const AppExecFwk::InnerEvent::Pointer& event) { HandleSendLocationRequest(event); }; gnssEventProcessMap_[static_cast(GnssInterfaceCode::SET_MOCKED_LOCATIONS)] = - &GnssHandler::HandleSetMockedLocations; + [this](const AppExecFwk::InnerEvent::Pointer& event) { HandleSetMockedLocations(event); }; gnssEventProcessMap_[static_cast(GnssInterfaceCode::SEND_COMMANDS)] = - &GnssHandler::HandleSendCommands; + [this](const AppExecFwk::InnerEvent::Pointer& event) { HandleSendCommands(event); }; #ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE gnssEventProcessMap_[static_cast(GnssAbilityInterfaceCode::SET_SUBSCRIBER_SET_ID)] = - &GnssHandler::HandleSetSubscriberSetId; + [this](const AppExecFwk::InnerEvent::Pointer& event) { HandleSetSubscriberSetId(event); }; gnssEventProcessMap_[static_cast(GnssAbilityInterfaceCode::SET_AGNSS_REF_INFO)] = - &GnssHandler::HandleSetAgnssRefInfo; + [this](const AppExecFwk::InnerEvent::Pointer& event) { HandleSetAgnssRefInfo(event); }; #endif gnssEventProcessMap_[static_cast(GnssAbilityInterfaceCode::RECONNECT_HDI)] = - &GnssHandler::HandleReconnectHdi; + [this](const AppExecFwk::InnerEvent::Pointer& event) { HandleReconnectHdi(event); }; gnssEventProcessMap_[static_cast(GnssInterfaceCode::SET_ENABLE)] = - &GnssHandler::HandleSetEnable; + [this](const AppExecFwk::InnerEvent::Pointer& event) { HandleSetEnable(event); }; gnssEventProcessMap_[static_cast(GnssAbilityInterfaceCode::INIT_HDI)] = - &GnssHandler::HandleInitHdi; + [this](const AppExecFwk::InnerEvent::Pointer& event) { HandleInitHdi(event); }; gnssEventProcessMap_[static_cast(GnssAbilityInterfaceCode::ADD_FENCE)] = - &GnssHandler::HandleAddFence; + [this](const AppExecFwk::InnerEvent::Pointer& event) { HandleAddFence(event); }; gnssEventProcessMap_[static_cast(GnssAbilityInterfaceCode::REMOVE_FENCE)] = - &GnssHandler::HandleRemoveFence; + [this](const AppExecFwk::InnerEvent::Pointer& event) { HandleRemoveFence(event); }; gnssEventProcessMap_[static_cast(GnssAbilityInterfaceCode::ADD_GEOFENCE)] = - &GnssHandler::HandleAddGeofence; + [this](const AppExecFwk::InnerEvent::Pointer& event) { HandleAddGeofence(event); }; gnssEventProcessMap_[static_cast(GnssAbilityInterfaceCode::REMOVE_GEOFENCE)] = - &GnssHandler::HandleRemoveGeofence; + [this](const AppExecFwk::InnerEvent::Pointer& event) { HandleRemoveGeofence(event); }; gnssEventProcessMap_[static_cast(GnssInterfaceCode::SEND_NETWORK_LOCATION)] = - &GnssHandler::HandleSendNetworkLocation; + [this](const AppExecFwk::InnerEvent::Pointer& event) { HandleSendNetworkLocation(event); }; } GnssHandler::~GnssHandler() {} @@ -1451,7 +1595,7 @@ void GnssHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) auto handleFunc = gnssEventProcessMap_.find(eventId); if (handleFunc != gnssEventProcessMap_.end() && handleFunc->second != nullptr) { auto memberFunc = handleFunc->second; - (this->*memberFunc)(event); + memberFunc(event); } gnssAbility->UnloadGnssSystemAbility(); } @@ -1566,9 +1710,7 @@ void GnssHandler::HandleInitHdi(const AppExecFwk::InnerEvent::Pointer& event) LBSLOGE(GNSS, "ProcessEvent: gnss ability is nullptr"); return; } - if (!gnssAbility->CheckIfHdiConnected()) { - gnssAbility->ConnectHdi(); - } + gnssAbility->ConnectHdi(); gnssAbility->EnableGnss(); #ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE gnssAbility->SetAgnssCallback(); diff --git a/services/location_gnss/gnss/source/gnss_ability_skeleton.cpp b/services/location_gnss/gnss/source/gnss_ability_skeleton.cpp index 1212235a..44f3c59c 100644 --- a/services/location_gnss/gnss/source/gnss_ability_skeleton.cpp +++ b/services/location_gnss/gnss/source/gnss_ability_skeleton.cpp @@ -33,52 +33,99 @@ void GnssAbilityStub::InitGnssMsgHandleMap() return; } GnssMsgHandleMap_[static_cast(GnssInterfaceCode::SEND_LOCATION_REQUEST)] = - &GnssAbilityStub::SendLocationRequestInner; - GnssMsgHandleMap_[static_cast(GnssInterfaceCode::SET_MOCKED_LOCATIONS)] = - &GnssAbilityStub::SetMockLocationsInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return SendLocationRequestInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::SET_ENABLE)] = - &GnssAbilityStub::SetEnableInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return SetEnableInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::REFRESH_REQUESTS)] = - &GnssAbilityStub::RefreshRequirementsInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return RefreshRequirementsInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::REG_GNSS_STATUS)] = - &GnssAbilityStub::RegisterGnssStatusCallbackInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return RegisterGnssStatusCallbackInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::UNREG_GNSS_STATUS)] = - &GnssAbilityStub::UnregisterGnssStatusCallbackInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return UnregisterGnssStatusCallbackInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::REG_NMEA)] = - &GnssAbilityStub::RegisterNmeaMessageCallbackInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return RegisterNmeaMessageCallbackInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::UNREG_NMEA)] = - &GnssAbilityStub::UnregisterNmeaMessageCallbackInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return UnregisterNmeaMessageCallbackInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::REG_CACHED)] = - &GnssAbilityStub::RegisterCachedCallbackInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return RegisterCachedCallbackInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::UNREG_CACHED)] = - &GnssAbilityStub::UnregisterCachedCallbackInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return UnregisterCachedCallbackInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::GET_CACHED_SIZE)] = - &GnssAbilityStub::GetCachedGnssLocationsSizeInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return GetCachedGnssLocationsSizeInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::FLUSH_CACHED)] = - &GnssAbilityStub::FlushCachedGnssLocationsInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return FlushCachedGnssLocationsInner(data, reply, identity); + }; +} + +void GnssAbilityStub::InitGnssEnhanceMsgHandleMap() +{ GnssMsgHandleMap_[static_cast(GnssInterfaceCode::SEND_COMMANDS)] = - &GnssAbilityStub::SendCommandInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return SendCommandInner(data, reply, identity); + }; + GnssMsgHandleMap_[static_cast(GnssInterfaceCode::SET_MOCKED_LOCATIONS)] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return SetMockLocationsInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::ENABLE_LOCATION_MOCK)] = - &GnssAbilityStub::EnableMockInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return EnableMockInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::DISABLE_LOCATION_MOCK)] = - &GnssAbilityStub::DisableMockInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return DisableMockInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::ADD_FENCE_INFO)] = - &GnssAbilityStub::AddFenceInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return AddFenceInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::REMOVE_FENCE_INFO)] = - &GnssAbilityStub::RemoveFenceInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return RemoveFenceInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::ADD_GNSS_GEOFENCE)] = - &GnssAbilityStub::AddGnssGeofenceInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return AddGnssGeofenceInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::REMOVE_GNSS_GEOFENCE)] = - &GnssAbilityStub::RemoveGnssGeofenceInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return RemoveGnssGeofenceInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::GET_GEOFENCE_SUPPORT_COORDINATE_SYSTEM_TYPE)] = - &GnssAbilityStub::QuerySupportCoordinateSystemTypeInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return QuerySupportCoordinateSystemTypeInner(data, reply, identity); + }; GnssMsgHandleMap_[static_cast(GnssInterfaceCode::SEND_NETWORK_LOCATION)] = - &GnssAbilityStub::SendNetworkLocationInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return SendNetworkLocationInner(data, reply, identity); + }; } GnssAbilityStub::GnssAbilityStub() { InitGnssMsgHandleMap(); + InitGnssEnhanceMsgHandleMap(); } int GnssAbilityStub::SendLocationRequestInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity) @@ -318,7 +365,6 @@ int GnssAbilityStub::OnRemoteRequest(uint32_t code, if (data.ReadInterfaceToken() != GetDescriptor()) { LBSLOGE(GNSS, "invalid token."); - reply.WriteInt32(ERRCODE_SERVICE_UNAVAILABLE); return ERRCODE_SERVICE_UNAVAILABLE; } int ret = ERRCODE_SUCCESS; @@ -326,10 +372,9 @@ int GnssAbilityStub::OnRemoteRequest(uint32_t code, auto handleFunc = GnssMsgHandleMap_.find(code); if (handleFunc != GnssMsgHandleMap_.end() && handleFunc->second != nullptr) { auto memberFunc = handleFunc->second; - ret = (this->*memberFunc)(data, reply, identity); + ret = memberFunc(data, reply, identity); } else { LBSLOGE(GNSS, "OnReceived cmd = %{public}u, unsupport service.", code); - reply.WriteInt32(ERRCODE_NOT_SUPPORTED); ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option); } if (!isMessageRequest_) { diff --git a/services/location_gnss/gnss/source/gnss_event_callback.cpp b/services/location_gnss/gnss/source/gnss_event_callback.cpp index e266338f..2cd92ca7 100644 --- a/services/location_gnss/gnss/source/gnss_event_callback.cpp +++ b/services/location_gnss/gnss/source/gnss_event_callback.cpp @@ -52,8 +52,12 @@ int32_t GnssEventCallback::ReportLocation(const LocationInfo& location) locationNew->SetAccuracy(location.horizontalAccuracy); locationNew->SetSpeed(location.speed); locationNew->SetDirection(location.bearing); + locationNew->SetAltitudeAccuracy(location.verticalAccuracy); + locationNew->SetSpeedAccuracy(location.speedAccuracy); + locationNew->SetDirectionAccuracy(location.bearingAccuracy); locationNew->SetTimeStamp(location.timeForFix); locationNew->SetTimeSinceBoot(location.timeSinceBoot); + locationNew->SetUncertaintyOfTimeSinceBoot(location.timeUncertainty); locationNew->SetIsFromMock(false); locationNew->SetLocationSourceType(LocationSourceType::GNSS_TYPE); if (gnssAbility->IsMockEnabled()) { @@ -103,7 +107,7 @@ int32_t GnssEventCallback::ReportNmea(int64_t timestamp, const std::string& nmea return ERR_OK; } -int32_t GnssEventCallback::ReportGnssCapabilities(GnssCapabilities capabilities) +int32_t GnssEventCallback::ReportGnssCapabilities(unsigned int capabilities) { return ERR_OK; } diff --git a/services/location_locator/locator/BUILD.gn b/services/location_locator/locator/BUILD.gn index ba77cc60..b559385f 100644 --- a/services/location_locator/locator/BUILD.gn +++ b/services/location_locator/locator/BUILD.gn @@ -13,6 +13,37 @@ import("//base/location/config.gni") import("//build/ohos.gni") + +local_base_sources = [ + "$SUBSYSTEM_DIR/location_locator/callback/source/cached_locations_callback_proxy.cpp", + "$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/locator_msdp_state_change_cb.cpp", + "$SUBSYSTEM_DIR/location_locator/callback/source/nmea_message_callback_proxy.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/fusion_controller.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/geo_convert_proxy.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/gnss_ability_proxy.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/location_config_manager.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/locator_ability.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/locator_background_proxy.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/locator_event_manager.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/locator_event_subscriber.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/locator_msdp_monitor_manager.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/locator_required_data_manager.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/locator_skeleton.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/network_ability_proxy.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/passive_ability_proxy.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/permission_status_change_cb.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/report_manager.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/request_manager.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/subability_common.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/work_record.cpp", + "$SUBSYSTEM_DIR/location_locator/locator/source/work_record_statistic.cpp", +] + ohos_shared_library("lbsservice_locator") { sanitize = { cfi = true @@ -21,35 +52,7 @@ ohos_shared_library("lbsservice_locator") { } branch_protector_ret = "pac_ret" - sources = [ - "$SUBSYSTEM_DIR/location_locator/callback/source/cached_locations_callback_proxy.cpp", - "$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/locator_msdp_state_change_cb.cpp", - "$SUBSYSTEM_DIR/location_locator/callback/source/nmea_message_callback_proxy.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/fusion_controller.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/geo_convert_proxy.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/gnss_ability_proxy.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/location_config_manager.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/locator_ability.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/locator_background_proxy.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/locator_event_manager.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/locator_event_subscriber.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/locator_msdp_monitor_manager.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/locator_required_data_manager.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/locator_skeleton.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/network_ability_proxy.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/passive_ability_proxy.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/permission_status_change_cb.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/report_manager.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/request_manager.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/subability_common.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/work_record.cpp", - "$SUBSYSTEM_DIR/location_locator/locator/source/work_record_statistic.cpp", - ] + sources = local_base_sources include_dirs = [ "$LOCATION_ROOT_DIR/interfaces/inner_api/include", @@ -71,11 +74,128 @@ ohos_shared_library("lbsservice_locator") { "ability_runtime:app_manager", "access_token:libaccesstoken_sdk", "access_token:libprivacy_sdk", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", + "ffrt:libffrt", + "hilog:libhilog", + "ipc:ipc_single", + "os_account:os_account_innerkits", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + defines = [] + + ldflags = [ + "-Wl,--as-needed", + "-Wl,--gc-sections", + ] + + cflags_cc = [ + "-ffunction-sections", + "-fdata-sections", + "-flto=thin", + "-Os", + ] + + if (communication_wifi_enable) { + external_deps += [ "wifi:wifi_sdk" ] + defines += [ "WIFI_ENABLE" ] + } + + if (communication_bluetooth_enable) { + external_deps += [ "bluetooth:btframework" ] + defines += [ "BLUETOOTH_ENABLE" ] + } + + if (location_feature_with_geocode) { + defines += [ "FEATURE_GEOCODE_SUPPORT" ] + } + + if (location_feature_with_gnss) { + defines += [ "FEATURE_GNSS_SUPPORT" ] + } + + if (location_feature_with_network) { + defines += [ "FEATURE_NETWORK_SUPPORT" ] + } + + if (location_feature_with_passive) { + defines += [ "FEATURE_PASSIVE_SUPPORT" ] + } + + if (resourceschedule_background_task_mgr_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + defines += [ "BGTASKMGR_SUPPORT" ] + } + + if (is_emulator) { + defines += [ "EMULATOR_ENABLED" ] + } + + if (ability_form_fwk_enable) { + external_deps += [ "form_fwk:fmskit_native" ] + defines += [ "FMSKIT_NATIVE_SUPPORT" ] + } + + if (resourceschedule_schedule_service_enable) { + external_deps += [ "resource_schedule_service:ressched_client" ] + defines += [ "RES_SCHED_SUPPROT" ] + } + + if (notification_distributed_notification_service_enable) { + defines += [ "NOTIFICATION_ENABLE" ] + } + + if (movement_client_enable) { + external_deps += [ "movement:movement_client" ] + defines += [ "MOVEMENT_CLIENT_ENABLE" ] + } + + if (location_device_standby_enable) { + external_deps += [ "device_standby:standby_innerkits" ] + defines += [ "DEVICE_STANDBY_ENABLE" ] + } + + # Used to control the export of dynamic library symbols. + version_script = "liblbsservice_locator_version_script.txt" + + part_name = "location" + subsystem_name = "location" +} + +ohos_static_library("lbsservice_locator_static") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + sources = local_base_sources + + include_dirs = [ + "$LOCATION_ROOT_DIR/interfaces/inner_api/include", + "$SUBSYSTEM_DIR/location_geocode/geocode/include", + "$SUBSYSTEM_DIR/location_gnss/gnss/include", + "$SUBSYSTEM_DIR/location_locator/callback/include", + "$SUBSYSTEM_DIR/location_locator/locator/include", + "$SUBSYSTEM_DIR/location_network/network/include", + "$SUBSYSTEM_DIR/location_passive/passive/include", + ] + + deps = [ + "$LOCATION_COMMON_DIR:lbsservice_common", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:app_manager", + "access_token:libaccesstoken_sdk", + "access_token:libprivacy_sdk", + "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", - "init:libbegetutil", "ipc:ipc_single", "os_account:os_account_innerkits", "safwk:system_ability_fwk", @@ -129,7 +249,6 @@ ohos_shared_library("lbsservice_locator") { } if (notification_distributed_notification_service_enable) { - external_deps += [ "distributed_notification_service:ans_innerkits" ] defines += [ "NOTIFICATION_ENABLE" ] } diff --git a/services/location_locator/locator/include/locator_ability.h b/services/location_locator/locator/include/locator_ability.h index 0dc76423..81da904f 100644 --- a/services/location_locator/locator/include/locator_ability.h +++ b/services/location_locator/locator/include/locator_ability.h @@ -21,6 +21,7 @@ #include #include "event_handler.h" +#include "ffrt.h" #include "system_ability.h" #include "app_identity.h" @@ -45,8 +46,7 @@ namespace OHOS { namespace Location { class LocatorHandler : public AppExecFwk::EventHandler { public: - using LocatorEventHandle = void (LocatorHandler::*)( - const AppExecFwk::InnerEvent::Pointer& event); + using LocatorEventHandle = std::function; using LocatorEventHandleMap = std::map; explicit LocatorHandler(const std::shared_ptr& runner); ~LocatorHandler() override; @@ -178,7 +178,7 @@ public: int permUsedType, int succCnt, int failCnt); LocationErrCode RemoveInvalidRequests(); bool IsInvalidRequest(std::shared_ptr& request); - bool IsProcessRunning(pid_t pid); + bool IsProcessRunning(pid_t pid, const uint32_t tokenId); #ifdef FEATURE_GNSS_SUPPORT LocationErrCode QuerySupportCoordinateSystemType( std::vector& coordinateSystemTypes); @@ -214,11 +214,11 @@ private: ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START; std::shared_ptr locatorEventSubscriber_; std::mutex switchMutex_; - std::mutex requestsMutex_; - std::mutex receiversMutex_; + ffrt::mutex requestsMutex_; + ffrt::mutex receiversMutex_; std::mutex proxyMapMutex_; - std::mutex permissionMapMutex_; - std::mutex loadedSaMapMutex_; + ffrt::mutex permissionMapMutex_; + ffrt::mutex loadedSaMapMutex_; std::unique_ptr>> switchCallbacks_; std::shared_ptr>>> requests_; std::shared_ptr, std::list>>> receivers_; @@ -265,6 +265,15 @@ private: std::string uuid_; int32_t errCode_; }; + +class LocatorCallbackDeathRecipient : public IRemoteObject::DeathRecipient { +public: + void OnRemoteDied(const wptr &remote) override; + LocatorCallbackDeathRecipient(int32_t tokenId); + ~LocatorCallbackDeathRecipient() override; +private: + int32_t tokenId_; +}; } // namespace Location } // namespace OHOS #endif // LOCATOR_ABILITY_H diff --git a/services/location_locator/locator/include/locator_event_subscriber.h b/services/location_locator/locator/include/locator_event_subscriber.h index cdfde553..f3484d7c 100644 --- a/services/location_locator/locator/include/locator_event_subscriber.h +++ b/services/location_locator/locator/include/locator_event_subscriber.h @@ -22,11 +22,9 @@ namespace OHOS { namespace Location { -const std::string MODE_CHANGED_EVENT = "usual.event.location.MODE_STATE_CHANGED"; -const std::string LOCATION_PRIVACY_ACCEPT_EVENT = "usual.event.LOCATION_PRIVACY_ACCEPT"; -const std::string LOCATION_PRIVACY_REJECT_EVENT = "usual.event.LOCATION_PRIVACY_REJECT"; -const std::string LOCATOR_STANDBY_NAP = "napped"; -const std::string LOCATOR_STANDBY_SLEEPING = "sleeping"; +constexpr const char* MODE_CHANGED_EVENT = "usual.event.location.MODE_STATE_CHANGED"; +constexpr const char* LOCATION_PRIVACY_ACCEPT_EVENT = "usual.event.LOCATION_PRIVACY_ACCEPT"; +constexpr const char* LOCATION_PRIVACY_REJECT_EVENT = "usual.event.LOCATION_PRIVACY_REJECT"; class LocatorEventSubscriber : public OHOS::EventFwk::CommonEventSubscriber { public: explicit LocatorEventSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &info); diff --git a/services/location_locator/locator/include/locator_skeleton.h b/services/location_locator/locator/include/locator_skeleton.h index 4162eef2..8d59d4f4 100644 --- a/services/location_locator/locator/include/locator_skeleton.h +++ b/services/location_locator/locator/include/locator_skeleton.h @@ -39,8 +39,7 @@ public: class LocatorAbilityStub : public IRemoteStub { public: - using LocatorMsgHandle = int (LocatorAbilityStub::*)( - MessageParcel &data, MessageParcel &reply, AppIdentity &identity); + using LocatorMsgHandle = std::function; using LocatorMsgHandleMap = std::map; LocatorAbilityStub(); @@ -113,22 +112,16 @@ private: int DoProcessFenceRequest( LocatorInterfaceCode code, MessageParcel &data, MessageParcel &reply, AppIdentity &identity); void ConstructLocatorHandleMap(); + void ConstructLocatorEnhanceHandleMap(); + void ConstructLocatorMockHandleMap(); void ConstructGeocodeHandleMap(); bool IsStopAction(uint32_t code); bool CheckRequestAvailable(uint32_t code, AppIdentity &identity); void ConstructGnssHandleMap(); + void ConstructGnssEnhanceHandleMap(); sptr scanRecipient_ = new (std::nothrow) ScanCallbackDeathRecipient(); }; -class LocatorCallbackDeathRecipient : public IRemoteObject::DeathRecipient { -public: - void OnRemoteDied(const wptr &remote) override; - LocatorCallbackDeathRecipient(int32_t tokenId); - ~LocatorCallbackDeathRecipient() override; -private: - int32_t tokenId_; -}; - class SwitchCallbackDeathRecipient : public IRemoteObject::DeathRecipient { public: void OnRemoteDied(const wptr &remote) override; diff --git a/services/location_locator/locator/include/request_manager.h b/services/location_locator/locator/include/request_manager.h index 51af9a19..cbe48bd1 100644 --- a/services/location_locator/locator/include/request_manager.h +++ b/services/location_locator/locator/include/request_manager.h @@ -22,6 +22,7 @@ #include #include +#include "ffrt.h" #include "iremote_object.h" #include "i_locator_callback.h" @@ -40,7 +41,7 @@ public: void HandlePowerSuspendChanged(int32_t pid, int32_t uid, int32_t flag); void UpdateRequestRecord(std::shared_ptr request, bool shouldInsert); void HandleRequest(); - void UpdateUsingPermission(std::shared_ptr request); + void UpdateUsingPermission(std::shared_ptr request, const bool isStart); void HandlePermissionChanged(uint32_t tokenId); void UpdateLocationErrorCallbackToRequest(sptr callback, uint32_t tokenId, bool state); void SyncStillMovementState(bool state); @@ -56,8 +57,7 @@ private: void ProxySendLocationRequest(std::string abilityName, WorkRecord& workRecord); sptr GetRemoteObject(std::string abilityName); bool IsUidInProcessing(int32_t uid); - void UpdateUsingApproximatelyPermission(std::shared_ptr request); - void UpdateUsingApproximatelyStatus(std::shared_ptr request, bool isActive); + void UpdateUsingApproximatelyPermission(std::shared_ptr request, const bool isStart); bool ActiveLocatingStrategies(const std::shared_ptr& request); bool AddRequestToWorkRecord(std::string abilityName, std::shared_ptr& request, std::shared_ptr& workRecord); @@ -66,9 +66,9 @@ private: void ReportDataToResSched(std::string state, const pid_t uid); void IsStandby(); std::map runningUidMap_; - static std::mutex requestMutex_; - std::mutex runningUidsMutex_; - std::mutex permissionRecordMutex_; + static ffrt::mutex requestMutex_; + ffrt::mutex runningUidsMutex_; + ffrt::mutex permissionRecordMutex_; std::atomic_bool isDeviceIdleMode_; std::atomic_bool isDeviceStillState_; }; diff --git a/services/location_locator/locator/liblbsservice_locator_version_script.txt b/services/location_locator/locator/liblbsservice_locator_version_script.txt new file mode 100644 index 00000000..1aeaa975 --- /dev/null +++ b/services/location_locator/locator/liblbsservice_locator_version_script.txt @@ -0,0 +1,5 @@ +{ + global: + local: + *; +}; \ No newline at end of file diff --git a/services/location_locator/locator/source/locator_ability.cpp b/services/location_locator/locator/source/locator_ability.cpp index 3646e64d..f7ffcd0e 100644 --- a/services/location_locator/locator/source/locator_ability.cpp +++ b/services/location_locator/locator/source/locator_ability.cpp @@ -104,6 +104,8 @@ LocatorAbility* LocatorAbility::GetInstance() LocatorAbility::LocatorAbility() : SystemAbility(LOCATION_LOCATOR_SA_ID, true) { + locatorHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true, + AppExecFwk::ThreadMode::FFRT)); switchCallbacks_ = std::make_unique>>(); requests_ = std::make_shared>>>(); receivers_ = std::make_shared, std::list>>>(); @@ -112,6 +114,11 @@ LocatorAbility::LocatorAbility() : SystemAbility(LOCATION_LOCATOR_SA_ID, true) permissionMap_ = std::make_shared>>(); InitRequestManagerMap(); reportManager_ = ReportManager::GetInstance(); + deviceId_ = CommonUtils::InitDeviceId(); +#ifdef MOVEMENT_CLIENT_ENABLE + LocatorMsdpMonitorManager::GetInstance(); +#endif + requestManager_ = RequestManager::GetInstance(); LBSLOGI(LOCATOR, "LocatorAbility constructed."); } @@ -180,13 +187,6 @@ bool LocatorAbility::Init() LBSLOGE(LOCATOR, "Init add system ability failed!"); return false; } - - deviceId_ = CommonUtils::InitDeviceId(); - requestManager_ = RequestManager::GetInstance(); -#ifdef MOVEMENT_CLIENT_ENABLE - LocatorMsdpMonitorManager::GetInstance(); -#endif - locatorHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); InitSaAbility(); if (locatorHandler_ != nullptr) { locatorHandler_->SendHighPriorityEvent(EVENT_INIT_REQUEST_MANAGER, 0, RETRY_INTERVAL_OF_INIT_REQUEST_MANAGER); @@ -198,7 +198,7 @@ bool LocatorAbility::Init() void LocatorAbility::InitRequestManagerMap() { - std::unique_lock lock(requestsMutex_); + std::unique_lock lock(requestsMutex_); if (requests_ != nullptr) { #ifdef FEATURE_GNSS_SUPPORT std::list> gnssList; @@ -217,13 +217,13 @@ void LocatorAbility::InitRequestManagerMap() std::shared_ptr>>> LocatorAbility::GetRequests() { - std::unique_lock lock(requestsMutex_); + std::unique_lock lock(requestsMutex_); return requests_; } int LocatorAbility::GetActiveRequestNum() { - std::unique_lock lock(requestsMutex_); + std::unique_lock lock(requestsMutex_); int num = 0; #ifdef FEATURE_GNSS_SUPPORT auto gpsListIter = requests_->find(GNSS_ABILITY); @@ -244,7 +244,7 @@ int LocatorAbility::GetActiveRequestNum() std::shared_ptr, std::list>>> LocatorAbility::GetReceivers() { - std::unique_lock lock(receiversMutex_); + std::unique_lock lock(receiversMutex_); return receivers_; } @@ -319,7 +319,7 @@ void LocatorAbility::UpdateSaAbilityHandler() } locatorBackgroundProxy->OnSaStateChange(isEnabled); UpdateLoadedSaMap(); - std::unique_lock lock(loadedSaMapMutex_); + std::unique_lock lock(loadedSaMapMutex_); for (auto iter = loadedSaMap_->begin(); iter != loadedSaMap_->end(); iter++) { sptr remoteObject = iter->second; MessageParcel data; @@ -410,6 +410,7 @@ LocationErrCode LocatorAbility::EnableAbility(bool isEnabled) LocationDataRdbManager::SetSwitchMode(isEnabled ? ENABLED : DISABLED); } UpdateSaAbility(); + ApplyRequests(0); std::string state = isEnabled ? "enable" : "disable"; ReportDataToResSched(state); WriteLocationSwitchStateEvent(state); @@ -787,7 +788,7 @@ LocationErrCode LocatorAbility::ProcessLocationMockMsg( void LocatorAbility::UpdateLoadedSaMap() { - std::unique_lock lock(loadedSaMapMutex_); + std::unique_lock lock(loadedSaMapMutex_); loadedSaMap_->clear(); if (LocationSaLoadManager::CheckIfSystemAbilityAvailable(LOCATION_GNSS_SA_ID)) { sptr objectGnss = @@ -888,6 +889,9 @@ LocationErrCode LocatorAbility::StartLocating(std::unique_ptr& re } reportManager_->UpdateRandom(); std::shared_ptr request = std::make_shared(requestConfig, callback, identity); + sptr death(new (std::nothrow) LocatorCallbackDeathRecipient(identity.GetTokenId())); + callback->AsObject()->AddDeathRecipient(death); + request->SetLocatorCallbackRecipient(death); HookUtils::ExecuteHookWhenStartLocation(request); OHOS::Security::AccessToken::PermUsedTypeEnum type = Security::AccessToken::AccessTokenKit::GetUserGrantedPermissionUsedType(request->GetTokenId(), @@ -900,6 +904,7 @@ LocationErrCode LocatorAbility::StartLocating(std::unique_ptr& re #else if (NeedReportCacheLocation(request, callback)) { LBSLOGI(LOCATOR, "report cache location to %{public}s", identity.GetBundleName().c_str()); + callback->AsObject()->RemoveDeathRecipient(death); } else { HandleStartLocating(request, callback); } @@ -1046,8 +1051,8 @@ LocationErrCode LocatorAbility::GetCacheLocation(std::unique_ptr& loc, bool LocatorAbility::CheckIsReportPermitted(AppIdentity &identity) { - auto requests = GetRequests(); - if (requests == nullptr || requests->empty()) { + std::unique_lock lock(requestsMutex_); + if (requests_ == nullptr || requests_->empty()) { LBSLOGE(LOCATOR, "requests map is empty"); return false; } @@ -1055,7 +1060,7 @@ bool LocatorAbility::CheckIsReportPermitted(AppIdentity &identity) bool isPermitted = true; int switchState = DISABLED; GetSwitchState(switchState); - for (auto mapIter = requests->begin(); mapIter != requests->end(); mapIter++) { + for (auto mapIter = requests_->begin(); mapIter != requests_->end(); mapIter++) { auto list = mapIter->second; for (auto request : list) { if (request == nullptr || request->GetTokenId() != identity.GetTokenId()) { @@ -1379,7 +1384,7 @@ bool LocatorAbility::IsProxyPid(int32_t pid) void LocatorAbility::RegisterPermissionCallback(const uint32_t callingTokenId, const std::vector& permissionNameList) { - std::unique_lock lock(permissionMapMutex_); + std::unique_lock lock(permissionMapMutex_); if (permissionMap_ == nullptr) { LBSLOGE(LOCATOR, "permissionMap is null."); return; @@ -1400,7 +1405,7 @@ void LocatorAbility::RegisterPermissionCallback(const uint32_t callingTokenId, void LocatorAbility::UnregisterPermissionCallback(const uint32_t callingTokenId) { - std::unique_lock lock(permissionMapMutex_); + std::unique_lock lock(permissionMapMutex_); if (permissionMap_ == nullptr) { LBSLOGE(LOCATOR, "permissionMap is null."); return; @@ -1523,7 +1528,7 @@ LocationErrCode LocatorAbility::RemoveInvalidRequests() int32_t requestNum = 0; int32_t invalidRequestNum = 0; { - std::unique_lock lock(requestsMutex_); + std::unique_lock lock(requestsMutex_); #ifdef FEATURE_GNSS_SUPPORT auto gpsListIter = requests_->find(GNSS_ABILITY); if (gpsListIter != requests_->end()) { @@ -1570,15 +1575,19 @@ bool LocatorAbility::IsInvalidRequest(std::shared_ptr& request) return true; } - if (timeDiff > REQUEST_DEFAULT_TIMEOUT_SECOUND && !IsProcessRunning(request->GetPid())) { + if (timeDiff > REQUEST_DEFAULT_TIMEOUT_SECOUND && !IsProcessRunning(request->GetPid(), request->GetTokenId())) { LBSLOGI(LOCATOR, "request process is not running"); return true; } return false; } -bool LocatorAbility::IsProcessRunning(pid_t pid) +bool LocatorAbility::IsProcessRunning(pid_t pid, const uint32_t tokenId) { + auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); + if (tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) { + return true; + } sptr samgrClient = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgrClient == nullptr) { LBSLOGE(LOCATOR, "Get system ability manager failed."); @@ -1702,23 +1711,42 @@ void LocatorHandler::InitLocatorHandlerEventMap() if (locatorHandlerEventMap_.size() != 0) { return; } - locatorHandlerEventMap_[EVENT_UPDATE_SA] = &LocatorHandler::UpdateSaEvent; - locatorHandlerEventMap_[EVENT_INIT_REQUEST_MANAGER] = &LocatorHandler::InitRequestManagerEvent; - locatorHandlerEventMap_[EVENT_APPLY_REQUIREMENTS] = &LocatorHandler::ApplyRequirementsEvent; - locatorHandlerEventMap_[EVENT_RETRY_REGISTER_ACTION] = &LocatorHandler::RetryRegisterActionEvent; - locatorHandlerEventMap_[EVENT_REPORT_LOCATION_MESSAGE] = &LocatorHandler::ReportLocationMessageEvent; - locatorHandlerEventMap_[EVENT_SEND_SWITCHSTATE_TO_HIFENCE] = &LocatorHandler::SendSwitchStateToHifenceEvent; - locatorHandlerEventMap_[EVENT_START_LOCATING] = &LocatorHandler::StartLocatingEvent; - locatorHandlerEventMap_[EVENT_STOP_LOCATING] = &LocatorHandler::StopLocatingEvent; - locatorHandlerEventMap_[EVENT_UPDATE_LASTLOCATION_REQUESTNUM] = &LocatorHandler::UpdateLastLocationRequestNum; - locatorHandlerEventMap_[EVENT_UNLOAD_SA] = &LocatorHandler::UnloadSaEvent; - locatorHandlerEventMap_[EVENT_GET_CACHED_LOCATION_SUCCESS] = &LocatorHandler::GetCachedLocationSuccess; - locatorHandlerEventMap_[EVENT_GET_CACHED_LOCATION_FAILED] = &LocatorHandler::GetCachedLocationFailed; - locatorHandlerEventMap_[EVENT_REG_LOCATION_ERROR] = &LocatorHandler::RegLocationErrorEvent; - locatorHandlerEventMap_[EVENT_UNREG_LOCATION_ERROR] = &LocatorHandler::UnRegLocationErrorEvent; - locatorHandlerEventMap_[EVENT_REPORT_LOCATION_ERROR] = &LocatorHandler::ReportLocationErrorEvent; - locatorHandlerEventMap_[EVENT_SYNC_STILL_MOVEMENT_STATE] = &LocatorHandler::SyncStillMovementState; - locatorHandlerEventMap_[EVENT_SYNC_IDLE_STATE] = &LocatorHandler::SyncIdleState; + locatorHandlerEventMap_[EVENT_UPDATE_SA] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { UpdateSaEvent(event); }; + locatorHandlerEventMap_[EVENT_INIT_REQUEST_MANAGER] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { InitRequestManagerEvent(event); }; + locatorHandlerEventMap_[EVENT_APPLY_REQUIREMENTS] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { ApplyRequirementsEvent(event); }; + locatorHandlerEventMap_[EVENT_RETRY_REGISTER_ACTION] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { RetryRegisterActionEvent(event); }; + locatorHandlerEventMap_[EVENT_REPORT_LOCATION_MESSAGE] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { ReportLocationMessageEvent(event); }; + locatorHandlerEventMap_[EVENT_SEND_SWITCHSTATE_TO_HIFENCE] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { SendSwitchStateToHifenceEvent(event); }; + locatorHandlerEventMap_[EVENT_START_LOCATING] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { StartLocatingEvent(event); }; + locatorHandlerEventMap_[EVENT_STOP_LOCATING] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { StopLocatingEvent(event); }; + locatorHandlerEventMap_[EVENT_UPDATE_LASTLOCATION_REQUESTNUM] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { UpdateLastLocationRequestNum(event); }; + locatorHandlerEventMap_[EVENT_UNLOAD_SA] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { UnloadSaEvent(event); }; + locatorHandlerEventMap_[EVENT_GET_CACHED_LOCATION_SUCCESS] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { GetCachedLocationSuccess(event); }; + locatorHandlerEventMap_[EVENT_GET_CACHED_LOCATION_FAILED] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { GetCachedLocationFailed(event); }; + locatorHandlerEventMap_[EVENT_REG_LOCATION_ERROR] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { RegLocationErrorEvent(event); }; + locatorHandlerEventMap_[EVENT_UNREG_LOCATION_ERROR] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { UnRegLocationErrorEvent(event); }; + locatorHandlerEventMap_[EVENT_REPORT_LOCATION_ERROR] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { ReportLocationErrorEvent(event); }; + locatorHandlerEventMap_[EVENT_PERIODIC_CHECK] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { RequestCheckEvent(event); }; + locatorHandlerEventMap_[EVENT_SYNC_STILL_MOVEMENT_STATE] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { SyncStillMovementState(event); }; + locatorHandlerEventMap_[EVENT_SYNC_IDLE_STATE] = + [this](const AppExecFwk::InnerEvent::Pointer& event) { SyncIdleState(event); }; } void LocatorHandler::GetCachedLocationSuccess(const AppExecFwk::InnerEvent::Pointer& event) @@ -1945,7 +1973,7 @@ void LocatorHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) auto handleFunc = locatorHandlerEventMap_.find(eventId); if (handleFunc != locatorHandlerEventMap_.end() && handleFunc->second != nullptr) { auto memberFunc = handleFunc->second; - (this->*memberFunc)(event); + memberFunc(event); } else { LBSLOGE(LOCATOR, "ProcessEvent event:%{public}d, unsupport service.", eventId); } @@ -1977,5 +2005,26 @@ void LocatorHandler::SyncIdleState(const AppExecFwk::InnerEvent::Pointer& event) requestManager->SyncIdleState(state); } } + +LocatorCallbackDeathRecipient::LocatorCallbackDeathRecipient(int32_t tokenId) +{ + tokenId_ = tokenId; +} + +LocatorCallbackDeathRecipient::~LocatorCallbackDeathRecipient() +{ +} + +void LocatorCallbackDeathRecipient::OnRemoteDied(const wptr &remote) +{ + sptr callback = iface_cast(remote.promote()); + auto locatorAbility = LocatorAbility::GetInstance(); + if (locatorAbility != nullptr) { + locatorAbility->RemoveUnloadTask(DEFAULT_CODE); + locatorAbility->StopLocating(callback); + locatorAbility->PostUnloadTask(DEFAULT_CODE); + LBSLOGI(LOCATOR, "locator callback OnRemoteDied tokenId = %{public}d", tokenId_); + } +} } // namespace Location } // namespace OHOS diff --git a/services/location_locator/locator/source/locator_background_proxy.cpp b/services/location_locator/locator/source/locator_background_proxy.cpp index 2a812890..fa5c94b8 100644 --- a/services/location_locator/locator/source/locator_background_proxy.cpp +++ b/services/location_locator/locator/source/locator_background_proxy.cpp @@ -172,22 +172,6 @@ void LocatorBackgroundProxy::StartLocator() void LocatorBackgroundProxy::UpdateListOnRequestChange(const std::shared_ptr& request) { - if (request == nullptr) { - LBSLOGE(LOCATOR_BACKGROUND_PROXY, "request is null"); - return; - } - int32_t uid = request->GetUid(); - std::string bundleName; - if (!CommonUtils::GetBundleNameByUid(uid, bundleName)) { - LBSLOGE(LOCATOR_BACKGROUND_PROXY, "Fail to Get bundle name: uid = %{public}d.", uid); - return; - } - UpdateListOnSuspend(request, !IsAppBackground(bundleName)); - if (requestsList_->empty()) { - StopLocator(); - } else { - StartLocator(); - } } // called when the app freezes or wakes up @@ -201,12 +185,6 @@ void LocatorBackgroundProxy::OnSuspend(const std::shared_ptr& request, if (!isUserSwitchSubscribed_) { isUserSwitchSubscribed_ = LocatorBackgroundProxy::UserSwitchSubscriber::Subscribe(); } - UpdateListOnSuspend(request, active); - if (requestsList_->empty()) { - StopLocator(); - } else { - StartLocator(); - } } // called when SA switch on or switch off @@ -259,41 +237,6 @@ bool LocatorBackgroundProxy::CheckPermission(const std::shared_ptr& req void LocatorBackgroundProxy::UpdateListOnSuspend(const std::shared_ptr& request, bool active) { - if (request == nullptr) { - return; - } - auto requestManager = RequestManager::GetInstance(); - if (requestManager == nullptr) { - LBSLOGE(LOCATOR_BACKGROUND_PROXY, "UpdateListOnSuspend: RequestManager is nullptr."); - return; - } - requestManager->UpdateUsingPermission(request); - std::unique_lock lock(requestListMutex_); - auto userId = GetUserId(request->GetUid()); - auto iter = requestsMap_->find(userId); - if (iter == requestsMap_->end()) { - return; - } - auto requestsList = iter->second; - auto it = find(requestsList->begin(), requestsList->end(), request); - if (it != requestsList->end()) { - if (active || !CheckPermission(request)) { - LBSLOGD(LOCATOR_BACKGROUND_PROXY, "remove request:%{public}s from User:%{public}d", - request->ToString().c_str(), userId); - requestsList->remove(request); - } - } else { - if (request->GetRequestConfig() == nullptr) { - return; - } - //App in Location ContinuousTasks or app has visible cards are not add to requestList of LocatorBackgroundProxy - if (!active && CheckPermission(request) && request->GetRequestConfig()->GetFixNumber() == 0 - && CheckMaxRequestNum(request->GetUid(), request->GetPackageName())) { - LBSLOGD(LOCATOR_BACKGROUND_PROXY, "add request:%{public}s from User:%{public}d", - request->ToString().c_str(), userId); - requestsList->push_back(request); - } - } } void LocatorBackgroundProxy::UpdateListOnUserSwitch(int32_t userId) @@ -570,9 +513,6 @@ bool LocatorBackgroundProxy::IsAppInLocationContinuousTasks(pid_t uid) bool LocatorBackgroundProxy::IsAppHasFormVisible(uint32_t tokenId, uint64_t tokenIdEx) { bool ret = false; - if (!PermissionManager::CheckSystemPermission(tokenId, tokenIdEx)) { - return ret; - } auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); if (tokenType != Security::AccessToken::ATokenTypeEnum::TOKEN_HAP) { return ret; diff --git a/services/location_locator/locator/source/locator_event_manager.cpp b/services/location_locator/locator/source/locator_event_manager.cpp index 8be2d4a8..d72ec5e4 100644 --- a/services/location_locator/locator/source/locator_event_manager.cpp +++ b/services/location_locator/locator/source/locator_event_manager.cpp @@ -55,8 +55,6 @@ LocatorDftManager::LocatorDftManager() { distributeSissionCnt_ = 0; distributeDisconnectCnt_ = 0; - - handler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); } LocatorDftManager::~LocatorDftManager() {} diff --git a/services/location_locator/locator/source/locator_event_subscriber.cpp b/services/location_locator/locator/source/locator_event_subscriber.cpp index 8ec6c5fe..00197b6f 100644 --- a/services/location_locator/locator/source/locator_event_subscriber.cpp +++ b/services/location_locator/locator/source/locator_event_subscriber.cpp @@ -20,6 +20,9 @@ namespace OHOS { namespace Location { +constexpr const char* LOCATOR_STANDBY_NAP = "napped"; +constexpr const char* LOCATOR_STANDBY_SLEEPING = "sleeping"; + LocatorEventSubscriber::LocatorEventSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &info) : CommonEventSubscriber(info) {} @@ -46,11 +49,11 @@ void LocatorEventSubscriber::OnReceiveEvent(const OHOS::EventFwk::CommonEventDat LBSLOGE(LOCATOR_EVENT, "OnReceiveEvent: LocatorAbility is nullptr."); return; } - if (MODE_CHANGED_EVENT.compare(action) == 0) { + if (std::string(MODE_CHANGED_EVENT).compare(action) == 0) { locatorAbility->UpdateSaAbility(); - } else if (LOCATION_PRIVACY_ACCEPT_EVENT.compare(action) == 0) { + } else if (std::string(LOCATION_PRIVACY_ACCEPT_EVENT).compare(action) == 0) { LocationConfigManager::GetInstance()->SetPrivacyTypeState(PRIVACY_TYPE_STARTUP, true); - } else if (LOCATION_PRIVACY_REJECT_EVENT.compare(action) == 0) { + } else if (std::string(LOCATION_PRIVACY_REJECT_EVENT).compare(action) == 0) { locatorAbility->EnableAbility(false); } } diff --git a/services/location_locator/locator/source/locator_required_data_manager.cpp b/services/location_locator/locator/source/locator_required_data_manager.cpp index 810b01b6..2f6c94d1 100644 --- a/services/location_locator/locator/source/locator_required_data_manager.cpp +++ b/services/location_locator/locator/source/locator_required_data_manager.cpp @@ -30,7 +30,7 @@ LocatorRequiredDataManager::LocatorRequiredDataManager() #ifdef WIFI_ENABLE WifiInfoInit(); #endif - scanHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); + scanHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true, AppExecFwk::ThreadMode::FFRT)); } LocatorRequiredDataManager* LocatorRequiredDataManager::GetInstance() diff --git a/services/location_locator/locator/source/locator_skeleton.cpp b/services/location_locator/locator/source/locator_skeleton.cpp index 58d1942d..7dfbd5f4 100644 --- a/services/location_locator/locator/source/locator_skeleton.cpp +++ b/services/location_locator/locator/source/locator_skeleton.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -31,7 +31,6 @@ #include "locating_required_data_config.h" #include "locator_required_data_manager.h" #include "location_log_event_ids.h" -#include "notification_request.h" #include "geofence_request.h" #include "permission_manager.h" @@ -43,50 +42,136 @@ void LocatorAbilityStub::InitLocatorHandleMap() return; } ConstructLocatorHandleMap(); + ConstructLocatorEnhanceHandleMap(); + ConstructLocatorMockHandleMap(); ConstructGeocodeHandleMap(); ConstructGnssHandleMap(); + ConstructGnssEnhanceHandleMap(); } void LocatorAbilityStub::ConstructLocatorHandleMap() { - locatorHandleMap_[LocatorInterfaceCode::GET_SWITCH_STATE] = &LocatorAbilityStub::PreGetSwitchState; - locatorHandleMap_[LocatorInterfaceCode::REG_SWITCH_CALLBACK] = &LocatorAbilityStub::PreRegisterSwitchCallback; - locatorHandleMap_[LocatorInterfaceCode::UNREG_SWITCH_CALLBACK] = &LocatorAbilityStub::PreUnregisterSwitchCallback; - locatorHandleMap_[LocatorInterfaceCode::START_LOCATING] = &LocatorAbilityStub::PreStartLocating; - locatorHandleMap_[LocatorInterfaceCode::STOP_LOCATING] = &LocatorAbilityStub::PreStopLocating; - locatorHandleMap_[LocatorInterfaceCode::GET_CACHE_LOCATION] = &LocatorAbilityStub::PreGetCacheLocation; - locatorHandleMap_[LocatorInterfaceCode::ENABLE_ABILITY] = &LocatorAbilityStub::PreEnableAbility; - locatorHandleMap_[LocatorInterfaceCode::UPDATE_SA_ABILITY] = &LocatorAbilityStub::PreUpdateSaAbility; - locatorHandleMap_[LocatorInterfaceCode::IS_PRIVACY_COMFIRMED] = &LocatorAbilityStub::PreIsLocationPrivacyConfirmed; + locatorHandleMap_[LocatorInterfaceCode::GET_SWITCH_STATE] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreGetSwitchState(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::REG_SWITCH_CALLBACK] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreRegisterSwitchCallback(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::UNREG_SWITCH_CALLBACK] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreUnregisterSwitchCallback(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::START_LOCATING] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreStartLocating(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::STOP_LOCATING] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreStopLocating(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::GET_CACHE_LOCATION] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreGetCacheLocation(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::ENABLE_ABILITY] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreEnableAbility(data, reply, identity); + }; +} + +void LocatorAbilityStub::ConstructLocatorEnhanceHandleMap() +{ + locatorHandleMap_[LocatorInterfaceCode::UPDATE_SA_ABILITY] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreUpdateSaAbility(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::IS_PRIVACY_COMFIRMED] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreIsLocationPrivacyConfirmed(data, reply, identity); + }; locatorHandleMap_[LocatorInterfaceCode::SET_PRIVACY_COMFIRM_STATUS] = - &LocatorAbilityStub::PreSetLocationPrivacyConfirmStatus; - locatorHandleMap_[LocatorInterfaceCode::ENABLE_LOCATION_MOCK] = &LocatorAbilityStub::PreEnableLocationMock; - locatorHandleMap_[LocatorInterfaceCode::DISABLE_LOCATION_MOCK] = &LocatorAbilityStub::PreDisableLocationMock; - locatorHandleMap_[LocatorInterfaceCode::SET_MOCKED_LOCATIONS] = &LocatorAbilityStub::PreSetMockedLocations; - locatorHandleMap_[LocatorInterfaceCode::PROXY_PID_FOR_FREEZE] = &LocatorAbilityStub::PreProxyForFreeze; - locatorHandleMap_[LocatorInterfaceCode::RESET_ALL_PROXY] = &LocatorAbilityStub::PreResetAllProxy; - locatorHandleMap_[LocatorInterfaceCode::REPORT_LOCATION] = &LocatorAbilityStub::PreReportLocation; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreSetLocationPrivacyConfirmStatus(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::PROXY_PID_FOR_FREEZE] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreProxyForFreeze(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::RESET_ALL_PROXY] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreResetAllProxy(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::REPORT_LOCATION] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreReportLocation(data, reply, identity); + }; locatorHandleMap_[LocatorInterfaceCode::REG_LOCATING_REQUIRED_DATA_CALLBACK] = - &LocatorAbilityStub::PreRegisterLocatingRequiredDataCallback; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreRegisterLocatingRequiredDataCallback(data, reply, identity); + }; locatorHandleMap_[LocatorInterfaceCode::UNREG_LOCATING_REQUIRED_DATA_CALLBACK] = - &LocatorAbilityStub::PreUnregisterLocatingRequiredDataCallback; - locatorHandleMap_[LocatorInterfaceCode::REG_LOCATION_ERROR] = &LocatorAbilityStub::PreRegisterLocationError; - locatorHandleMap_[LocatorInterfaceCode::UNREG_LOCATION_ERROR] = &LocatorAbilityStub::PreUnregisterLocationError; - locatorHandleMap_[LocatorInterfaceCode::REPORT_LOCATION_ERROR] = &LocatorAbilityStub::PreReportLocationError; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreUnregisterLocatingRequiredDataCallback(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::REG_LOCATION_ERROR] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreRegisterLocationError(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::UNREG_LOCATION_ERROR] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreUnregisterLocationError(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::REPORT_LOCATION_ERROR] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreReportLocationError(data, reply, identity); + }; +} + +void LocatorAbilityStub::ConstructLocatorMockHandleMap() +{ + locatorHandleMap_[LocatorInterfaceCode::ENABLE_LOCATION_MOCK] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreEnableLocationMock(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::DISABLE_LOCATION_MOCK] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreDisableLocationMock(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::SET_MOCKED_LOCATIONS] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreSetMockedLocations(data, reply, identity); + }; } void LocatorAbilityStub::ConstructGeocodeHandleMap() { #ifdef FEATURE_GEOCODE_SUPPORT - locatorHandleMap_[LocatorInterfaceCode::GEO_IS_AVAILABLE] = &LocatorAbilityStub::PreIsGeoConvertAvailable; - locatorHandleMap_[LocatorInterfaceCode::GET_FROM_COORDINATE] = &LocatorAbilityStub::PreGetAddressByCoordinate; - locatorHandleMap_[LocatorInterfaceCode::GET_FROM_LOCATION_NAME] = &LocatorAbilityStub::PreGetAddressByLocationName; + locatorHandleMap_[LocatorInterfaceCode::GEO_IS_AVAILABLE] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreIsGeoConvertAvailable(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::GET_FROM_COORDINATE] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreGetAddressByCoordinate(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::GET_FROM_LOCATION_NAME] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreGetAddressByLocationName(data, reply, identity); + }; locatorHandleMap_[LocatorInterfaceCode::ENABLE_REVERSE_GEOCODE_MOCK] = - &LocatorAbilityStub::PreEnableReverseGeocodingMock; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreEnableReverseGeocodingMock(data, reply, identity); + }; locatorHandleMap_[LocatorInterfaceCode::DISABLE_REVERSE_GEOCODE_MOCK] = - &LocatorAbilityStub::PreDisableReverseGeocodingMock; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreDisableReverseGeocodingMock(data, reply, identity); + }; locatorHandleMap_[LocatorInterfaceCode::SET_REVERSE_GEOCODE_MOCKINFO] = - &LocatorAbilityStub::PreSetReverseGeocodingMockInfo; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreSetReverseGeocodingMockInfo(data, reply, identity); + }; #endif } @@ -94,28 +179,75 @@ void LocatorAbilityStub::ConstructGnssHandleMap() { #ifdef FEATURE_GNSS_SUPPORT locatorHandleMap_[LocatorInterfaceCode::REG_GNSS_STATUS_CALLBACK] = - &LocatorAbilityStub::PreRegisterGnssStatusCallback; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreRegisterGnssStatusCallback(data, reply, identity); + }; locatorHandleMap_[LocatorInterfaceCode::UNREG_GNSS_STATUS_CALLBACK] = - &LocatorAbilityStub::PreUnregisterGnssStatusCallback; - locatorHandleMap_[LocatorInterfaceCode::REG_NMEA_CALLBACK] = &LocatorAbilityStub::PreRegisterNmeaMessageCallback; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreUnregisterGnssStatusCallback(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::REG_NMEA_CALLBACK] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreRegisterNmeaMessageCallback(data, reply, identity); + }; locatorHandleMap_[LocatorInterfaceCode::UNREG_NMEA_CALLBACK] = - &LocatorAbilityStub::PreUnregisterNmeaMessageCallback; - locatorHandleMap_[LocatorInterfaceCode::REG_CACHED_CALLBACK] = &LocatorAbilityStub::PreStartCacheLocating; - locatorHandleMap_[LocatorInterfaceCode::UNREG_CACHED_CALLBACK] = &LocatorAbilityStub::PreStopCacheLocating; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreUnregisterNmeaMessageCallback(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::REG_CACHED_CALLBACK] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreStartCacheLocating(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::UNREG_CACHED_CALLBACK] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreStopCacheLocating(data, reply, identity); + }; locatorHandleMap_[LocatorInterfaceCode::GET_CACHED_LOCATION_SIZE] = - &LocatorAbilityStub::PreGetCachedGnssLocationsSize; - locatorHandleMap_[LocatorInterfaceCode::FLUSH_CACHED_LOCATIONS] = &LocatorAbilityStub::PreFlushCachedGnssLocations; - locatorHandleMap_[LocatorInterfaceCode::SEND_COMMAND] = &LocatorAbilityStub::PreSendCommand; - locatorHandleMap_[LocatorInterfaceCode::ADD_FENCE] = &LocatorAbilityStub::PreAddFence; - locatorHandleMap_[LocatorInterfaceCode::REMOVE_FENCE] = &LocatorAbilityStub::PreRemoveFence; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreGetCachedGnssLocationsSize(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::FLUSH_CACHED_LOCATIONS] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreFlushCachedGnssLocations(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::SEND_COMMAND] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreSendCommand(data, reply, identity); + }; locatorHandleMap_[LocatorInterfaceCode::REG_NMEA_CALLBACK_V9] = - &LocatorAbilityStub::PreRegisterNmeaMessageCallbackV9; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreRegisterNmeaMessageCallbackV9(data, reply, identity); + }; locatorHandleMap_[LocatorInterfaceCode::UNREG_NMEA_CALLBACK_V9] = - &LocatorAbilityStub::PreUnregisterNmeaMessageCallbackV9; - locatorHandleMap_[LocatorInterfaceCode::ADD_GNSS_GEOFENCE] = &LocatorAbilityStub::PreAddGnssGeofence; - locatorHandleMap_[LocatorInterfaceCode::REMOVE_GNSS_GEOFENCE] = &LocatorAbilityStub::PreRemoveGnssGeofence; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreUnregisterNmeaMessageCallbackV9(data, reply, identity); + }; +#endif +} + +void LocatorAbilityStub::ConstructGnssEnhanceHandleMap() +{ +#ifdef FEATURE_GNSS_SUPPORT + locatorHandleMap_[LocatorInterfaceCode::ADD_FENCE] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreAddFence(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::REMOVE_FENCE] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreRemoveFence(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::ADD_GNSS_GEOFENCE] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreAddGnssGeofence(data, reply, identity); + }; + locatorHandleMap_[LocatorInterfaceCode::REMOVE_GNSS_GEOFENCE] = + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreRemoveGnssGeofence(data, reply, identity); + }; locatorHandleMap_[LocatorInterfaceCode::GET_GEOFENCE_SUPPORT_COORDINATE_SYSTEM_TYPE] = - &LocatorAbilityStub::PreQuerySupportCoordinateSystemType; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return PreQuerySupportCoordinateSystemType(data, reply, identity); + }; #endif } @@ -186,8 +318,6 @@ int LocatorAbilityStub::PreStartLocating(MessageParcel &data, MessageParcel &rep return ERRCODE_SERVICE_UNAVAILABLE; } - sptr death(new (std::nothrow) LocatorCallbackDeathRecipient(identity.GetTokenId())); - remoteObject->AddDeathRecipient(death); sptr callback = iface_cast(remoteObject); reply.WriteInt32(locatorAbility->StartLocating(requestConfig, callback, identity)); return ERRCODE_SUCCESS; @@ -674,6 +804,7 @@ int LocatorAbilityStub::DoProcessFenceRequest( #ifdef FEATURE_GNSS_SUPPORT int LocatorAbilityStub::PreAddGnssGeofence(MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + LBSLOGI(LOCATOR, "PreAddGnssGeofence enter."); if (!CheckLocationSwitchState(reply)) { return ERRCODE_SWITCH_OFF; } @@ -696,6 +827,7 @@ int LocatorAbilityStub::PreAddGnssGeofence(MessageParcel &data, MessageParcel &r #ifdef FEATURE_GNSS_SUPPORT int LocatorAbilityStub::PreRemoveGnssGeofence(MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + LBSLOGI(LOCATOR, "PreRemoveGnssGeofence enter."); if (!CheckLocationSwitchState(reply)) { return ERRCODE_SWITCH_OFF; } @@ -1228,7 +1360,6 @@ int32_t LocatorAbilityStub::OnRemoteRequest(uint32_t code, if (data.ReadInterfaceToken() != GetDescriptor()) { LBSLOGE(LOCATOR, "invalid token."); IPCSkeleton::SetCallingIdentity(callingIdentity); - reply.WriteInt32(ERRCODE_SERVICE_UNAVAILABLE); return ERRCODE_SERVICE_UNAVAILABLE; } RemoveUnloadTask(code); @@ -1239,12 +1370,9 @@ int32_t LocatorAbilityStub::OnRemoteRequest(uint32_t code, auto handleFunc = locatorHandleMap_.find(static_cast(code)); if (handleFunc != locatorHandleMap_.end() && handleFunc->second != nullptr) { auto memberFunc = handleFunc->second; - ret = (this->*memberFunc)(data, reply, identity); + ret = memberFunc(data, reply, identity); } else { LBSLOGE(LOCATOR, "OnReceived cmd = %{public}u, unsupport service.", code); -#if !defined(FEATURE_GNSS_SUPPORT) || !defined(FEATURE_GEOCODE_SUPPORT) - reply.WriteInt32(ERRCODE_NOT_SUPPORTED); -#endif ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option); } IPCSkeleton::SetCallingIdentity(callingIdentity); @@ -1321,27 +1449,6 @@ void LocatorAbilityStub::WriteLocationDenyReportEvent(uint32_t code, int errCode } } -LocatorCallbackDeathRecipient::LocatorCallbackDeathRecipient(int32_t tokenId) -{ - tokenId_ = tokenId; -} - -LocatorCallbackDeathRecipient::~LocatorCallbackDeathRecipient() -{ -} - -void LocatorCallbackDeathRecipient::OnRemoteDied(const wptr &remote) -{ - sptr callback = iface_cast(remote.promote()); - auto locatorAbility = LocatorAbility::GetInstance(); - if (locatorAbility != nullptr) { - locatorAbility->RemoveUnloadTask(DEFAULT_CODE); - locatorAbility->StopLocating(callback); - locatorAbility->PostUnloadTask(DEFAULT_CODE); - LBSLOGI(LOCATOR, "locator callback OnRemoteDied tokenId = %{public}d", tokenId_); - } -} - SwitchCallbackDeathRecipient::SwitchCallbackDeathRecipient() { } diff --git a/services/location_locator/locator/source/request_manager.cpp b/services/location_locator/locator/source/request_manager.cpp index a25ab8e7..46eda0cc 100644 --- a/services/location_locator/locator/source/request_manager.cpp +++ b/services/location_locator/locator/source/request_manager.cpp @@ -39,7 +39,9 @@ #include "common_hisysevent.h" #include "hook_utils.h" #include "permission_manager.h" +#ifdef DEVICE_STANDBY_ENABLE #include "standby_service_client.h" +#endif #ifdef RES_SCHED_SUPPROT #include "res_type.h" @@ -48,7 +50,7 @@ namespace OHOS { namespace Location { -std::mutex RequestManager::requestMutex_; +ffrt::mutex RequestManager::requestMutex_; RequestManager* RequestManager::GetInstance() { @@ -77,9 +79,9 @@ bool RequestManager::InitSystemListeners() return true; } -void RequestManager::UpdateUsingPermission(std::shared_ptr request) +void RequestManager::UpdateUsingPermission(std::shared_ptr request, const bool isStart) { - std::unique_lock lock(permissionRecordMutex_, std::defer_lock); + std::unique_lock lock(permissionRecordMutex_, std::defer_lock); lock.lock(); if (request == nullptr) { LBSLOGE(REQUEST_MANAGER, "request is null"); @@ -88,54 +90,30 @@ void RequestManager::UpdateUsingPermission(std::shared_ptr request) } LBSLOGD(REQUEST_MANAGER, "UpdateUsingPermission : tokenId = %{public}d, firstTokenId = %{public}d", request->GetTokenId(), request->GetFirstTokenId()); - UpdateUsingApproximatelyPermission(request); + UpdateUsingApproximatelyPermission(request, isStart); lock.unlock(); } -void RequestManager::UpdateUsingApproximatelyPermission(std::shared_ptr request) +void RequestManager::UpdateUsingApproximatelyPermission(std::shared_ptr request, const bool isStart) { - uint32_t callingTokenId = request->GetTokenId(); - uint32_t callingFirstTokenid = request->GetFirstTokenId(); - int32_t uid = request->GetUid(); - if (IsUidInProcessing(uid) && - PermissionManager::CheckApproximatelyPermission(callingTokenId, callingFirstTokenid)) { - if (!request->GetApproximatelyPermState()) { - PrivacyKit::StartUsingPermission(callingTokenId, ACCESS_APPROXIMATELY_LOCATION); - request->SetApproximatelyPermState(true); - } - } else { - if (request->GetApproximatelyPermState()) { - PrivacyKit::StopUsingPermission(callingTokenId, ACCESS_APPROXIMATELY_LOCATION); - request->SetApproximatelyPermState(false); - } - } -} - -void RequestManager::UpdateUsingApproximatelyStatus(std::shared_ptr request, bool isActive) -{ - std::unique_lock lock(permissionRecordMutex_, std::defer_lock); - lock.lock(); - if (request == nullptr) { - LBSLOGE(REQUEST_MANAGER, "request is null"); - lock.unlock(); + auto locatorAbility = LocatorAbility::GetInstance(); + if (locatorAbility == nullptr) { return; } uint32_t callingTokenId = request->GetTokenId(); - if (isActive) { - if (!request->GetApproximatelyPermState()) { - PrivacyKit::StartUsingPermission(callingTokenId, ACCESS_APPROXIMATELY_LOCATION); - request->SetApproximatelyPermState(true); - } - } else { - if (request->GetApproximatelyPermState()) { - PrivacyKit::StopUsingPermission(callingTokenId, ACCESS_APPROXIMATELY_LOCATION); - request->SetApproximatelyPermState(false); - } + if (isStart && !request->GetApproximatelyPermState()) { + PrivacyKit::StartUsingPermission(callingTokenId, ACCESS_APPROXIMATELY_LOCATION); + locatorAbility->UpdatePermissionUsedRecord(request->GetTokenId(), + ACCESS_APPROXIMATELY_LOCATION, request->GetPermUsedType(), 1, 0); + request->SetApproximatelyPermState(true); + } else if (!isStart && request->GetApproximatelyPermState()) { + PrivacyKit::StopUsingPermission(callingTokenId, ACCESS_APPROXIMATELY_LOCATION); + request->SetApproximatelyPermState(false); } - lock.unlock(); } + void RequestManager::HandleStartLocating(std::shared_ptr request) { auto locatorAbility = LocatorAbility::GetInstance(); @@ -150,7 +128,6 @@ void RequestManager::HandleStartLocating(std::shared_ptr request) locatorAbility->RegisterPermissionCallback(request->GetTokenId(), {ACCESS_APPROXIMATELY_LOCATION, ACCESS_LOCATION, ACCESS_BACKGROUND_LOCATION}); UpdateRequestRecord(request, true); - UpdateUsingPermission(request); locatorDftManager->LocationSessionStart(request); } // process location request @@ -298,7 +275,7 @@ void RequestManager::HandleStopLocating(sptr callback) LBSLOGE(REQUEST_MANAGER, "locatorAbility is null"); return; } - std::unique_lock lock(requestMutex_, std::defer_lock); + std::unique_lock lock(requestMutex_, std::defer_lock); lock.lock(); auto receivers = locatorAbility->GetReceivers(); if (receivers == nullptr) { @@ -345,7 +322,10 @@ void RequestManager::DeleteRequestRecord(std::shared_ptrbegin(); iter != requests->end(); ++iter) { auto request = *iter; UpdateRequestRecord(request, false); - UpdateUsingPermission(request); + UpdateUsingPermission(request, false); + if (request->GetLocatorCallBack() != nullptr && request->GetLocatorCallbackRecipient() != nullptr) { + request->GetLocatorCallBack()->AsObject()->RemoveDeathRecipient(request->GetLocatorCallbackRecipient()); + } auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance(); if (locatorBackgroundProxy == nullptr) { LBSLOGE(REQUEST_MANAGER, "DeleteRequestRecord: LocatorBackgroundProxy is nullptr."); @@ -362,7 +342,7 @@ void RequestManager::HandleRequest() LBSLOGE(REQUEST_MANAGER, "locatorAbility is null"); return; } - std::unique_lock lock(requestMutex_, std::defer_lock); + std::unique_lock lock(requestMutex_, std::defer_lock); lock.lock(); auto requests = locatorAbility->GetRequests(); lock.unlock(); @@ -385,11 +365,12 @@ void RequestManager::HandleRequest(std::string abilityName, std::listGetPackageName(), + "abilityName", abilityName, "requestAddress", request->GetUuid()}); + UpdateUsingPermission(request, false); continue; - } else { - UpdateUsingApproximatelyStatus(request, true); } + UpdateUsingPermission(request, true); if (!ActiveLocatingStrategies(request)) { continue; } @@ -465,10 +446,6 @@ bool RequestManager::AddRequestToWorkRecord(std::string abilityName, std::shared if (request == nullptr) { return false; } - - if (!request->GetIsRequesting()) { - return false; - } if (!IsRequestAvailable(request)) { return false; } @@ -476,9 +453,11 @@ bool RequestManager::AddRequestToWorkRecord(std::string abilityName, std::shared int switchState = DISABLED; auto locatorAbility = LocatorAbility::GetInstance(); if (locatorAbility != nullptr && locatorAbility->GetSwitchState(switchState) == ERRCODE_SUCCESS) { - if (switchState == DISABLED && locationErrorCallback != nullptr) { + if (switchState == DISABLED) { + if (locationErrorCallback != nullptr) { + locationErrorCallback->OnErrorReport(LOCATING_FAILED_LOCATION_SWITCH_OFF); + } LBSLOGE(LOCATOR, "%{public}s line:%{public}d the location switch is off", __func__, __LINE__); - locationErrorCallback->OnErrorReport(LOCATING_FAILED_LOCATION_SWITCH_OFF); return false; } } @@ -657,7 +636,7 @@ void RequestManager::HandlePermissionChanged(uint32_t tokenId) bool RequestManager::IsUidInProcessing(int32_t uid) { - std::unique_lock lock(runningUidsMutex_); + std::unique_lock lock(runningUidsMutex_); auto iter = runningUidMap_.find(uid); if (iter == runningUidMap_.end()) { return false; @@ -667,7 +646,7 @@ bool RequestManager::IsUidInProcessing(int32_t uid) void RequestManager::UpdateRunningUids(const std::shared_ptr& request, std::string abilityName, bool isAdd) { - std::unique_lock lock(runningUidsMutex_); + std::unique_lock lock(runningUidsMutex_); auto uid = request->GetUid(); auto pid = request->GetPid(); int32_t uidCount = 0; diff --git a/services/location_network/network/BUILD.gn b/services/location_network/network/BUILD.gn index 2846f7ca..4255c0e5 100644 --- a/services/location_network/network/BUILD.gn +++ b/services/location_network/network/BUILD.gn @@ -14,17 +14,19 @@ import("//base/location/config.gni") import("//build/ohos.gni") +local_base_sources = [ + "$LOCATION_LOCATOR_ROOT/source/location_config_manager.cpp", + "$LOCATION_LOCATOR_ROOT/source/subability_common.cpp", + "$LOCATION_LOCATOR_ROOT/source/work_record.cpp", + "$LOCATION_LOCATOR_ROOT/source/work_record_statistic.cpp", + "$LOCATION_NETWORK_ROOT/source/network_ability.cpp", + "$LOCATION_NETWORK_ROOT/source/network_ability_skeleton.cpp", + "$LOCATION_NETWORK_ROOT/source/network_callback_host.cpp", +] + if (location_feature_with_network) { ohos_shared_library("lbsservice_network") { - sources = [ - "$LOCATION_LOCATOR_ROOT/source/location_config_manager.cpp", - "$LOCATION_LOCATOR_ROOT/source/subability_common.cpp", - "$LOCATION_LOCATOR_ROOT/source/work_record.cpp", - "$LOCATION_LOCATOR_ROOT/source/work_record_statistic.cpp", - "$LOCATION_NETWORK_ROOT/source/network_ability.cpp", - "$LOCATION_NETWORK_ROOT/source/network_ability_skeleton.cpp", - "$LOCATION_NETWORK_ROOT/source/network_callback_host.cpp", - ] + sources = local_base_sources include_dirs = [ "$LOCATION_ROOT_DIR/interfaces/inner_api/include", @@ -32,21 +34,83 @@ if (location_feature_with_network) { "$LOCATION_NETWORK_ROOT/include", ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + deps = [ "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", ] external_deps = [ "ability_base:want", - "ability_runtime:ability_connect_callback_stub", "ability_runtime:ability_manager", - "c_utils:utils", "eventhandler:libeventhandler", + "ffrt:libffrt", + "hilog:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + ] + + defines = [] + + ldflags = [ + "-Wl,--as-needed", + "-Wl,--gc-sections", + ] + + cflags_cc = [ + "-ffunction-sections", + "-fdata-sections", + "-Os", + ] + + if (location_feature_with_network) { + defines += [ "FEATURE_NETWORK_SUPPORT" ] + } + + if (location_feature_with_passive) { + defines += [ "FEATURE_PASSIVE_SUPPORT" ] + } + + # Used to control the export of dynamic library symbols. + version_script = "liblbsservice_network_version_script.txt" + + part_name = "location" + subsystem_name = "location" + } + + ohos_static_library("lbsservice_network_static") { + sources = local_base_sources + + include_dirs = [ + "$LOCATION_ROOT_DIR/interfaces/inner_api/include", + "$LOCATION_LOCATOR_ROOT/include", + "$LOCATION_NETWORK_ROOT/include", + ] + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + deps = [ + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_manager", + "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", - "init:libbegetutil", "ipc:ipc_single", "safwk:system_ability_fwk", - "samgr:samgr_proxy", ] defines = [] @@ -66,4 +130,9 @@ if (location_feature_with_network) { part_name = "location" subsystem_name = "location" } + + ohos_static_library("lbsservice_network_static") { + part_name = "location" + subsystem_name = "location" + } } diff --git a/services/location_network/network/include/network_ability.h b/services/location_network/network/include/network_ability.h index 2f0fa338..5efe1621 100644 --- a/services/location_network/network/include/network_ability.h +++ b/services/location_network/network/include/network_ability.h @@ -23,6 +23,7 @@ #include "ability_connect_callback_interface.h" #include "event_handler.h" #include "event_runner.h" +#include "ffrt.h" #include "system_ability.h" #include "common_utils.h" @@ -34,8 +35,6 @@ namespace OHOS { namespace Location { static constexpr int REQUEST_NETWORK_LOCATION = 1; static constexpr int REMOVE_NETWORK_LOCATION = 2; -const std::string SERVICE_CONFIG_FILE = "/system/etc/location/location_service.conf"; -const std::string ABILITY_NAME = "LocationServiceAbility"; class NetworkHandler : public AppExecFwk::EventHandler { public: explicit NetworkHandler(const std::shared_ptr& runner); @@ -85,10 +84,10 @@ private: bool RemoveNetworkLocation(WorkRecord &workRecord); void RegisterNLPServiceDeathRecipient(); bool IsConnect(); - - std::mutex mutex_; + + ffrt::mutex mutex_; sptr nlpServiceProxy_; - std::condition_variable connectCondition_; + ffrt::condition_variable connectCondition_; std::shared_ptr networkHandler_; size_t mockLocationIndex_ = 0; bool registerToAbility_ = false; diff --git a/services/location_network/network/include/network_ability_skeleton.h b/services/location_network/network/include/network_ability_skeleton.h index c9981d93..701127ea 100644 --- a/services/location_network/network/include/network_ability_skeleton.h +++ b/services/location_network/network/include/network_ability_skeleton.h @@ -34,8 +34,7 @@ public: class NetworkAbilityStub : public IRemoteStub { public: - using NetworkMsgHandle = int (NetworkAbilityStub::*)( - MessageParcel &data, MessageParcel &reply, AppIdentity &identity); + using NetworkMsgHandle = std::function; using NetworkMsgHandleMap = std::map; NetworkAbilityStub(); virtual ~NetworkAbilityStub() = default; diff --git a/services/location_network/network/liblbsservice_network_version_script.txt b/services/location_network/network/liblbsservice_network_version_script.txt new file mode 100644 index 00000000..1aeaa975 --- /dev/null +++ b/services/location_network/network/liblbsservice_network_version_script.txt @@ -0,0 +1,5 @@ +{ + global: + local: + *; +}; \ No newline at end of file diff --git a/services/location_network/network/source/network_ability.cpp b/services/location_network/network/source/network_ability.cpp index 61a1444e..91635653 100644 --- a/services/location_network/network/source/network_ability.cpp +++ b/services/location_network/network/source/network_ability.cpp @@ -51,7 +51,8 @@ const bool REGISTER_RESULT = NetworkAbility::MakeAndRegisterAbility( NetworkAbility::NetworkAbility() : SystemAbility(LOCATION_NETWORK_LOCATING_SA_ID, true) { SetAbility(NETWORK_ABILITY); - networkHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); + networkHandler_ = + std::make_shared(AppExecFwk::EventRunner::Create(true, AppExecFwk::ThreadMode::FFRT)); LBSLOGI(NETWORK, "ability constructed."); } @@ -149,7 +150,7 @@ bool NetworkAbility::ConnectNlpService() LBSLOGE(NETWORK, "Connect cloud service failed, ret = %{public}d", ret); return false; } - std::unique_lock uniqueLock(mutex_); + std::unique_lock uniqueLock(mutex_); auto waitStatus = connectCondition_.wait_for( uniqueLock, std::chrono::seconds(CONNECT_TIME_OUT), [this]() { return nlpServiceProxy_ != nullptr; }); if (!waitStatus) { @@ -183,21 +184,21 @@ bool NetworkAbility::ReConnectNlpService() bool NetworkAbility::ResetServiceProxy() { - std::unique_lock uniqueLock(mutex_); + std::unique_lock uniqueLock(mutex_); nlpServiceProxy_ = nullptr; return true; } void NetworkAbility::NotifyConnected(const sptr& remoteObject) { - std::unique_lock uniqueLock(mutex_); + std::unique_lock uniqueLock(mutex_); nlpServiceProxy_ = remoteObject; connectCondition_.notify_all(); } void NetworkAbility::NotifyDisConnected() { - std::unique_lock uniqueLock(mutex_); + std::unique_lock uniqueLock(mutex_); nlpServiceProxy_ = nullptr; connectCondition_.notify_all(); } @@ -268,7 +269,7 @@ void NetworkAbility::RequestRecord(WorkRecord &workRecord, bool isAdded) return; } } - std::unique_lock uniqueLock(mutex_); + std::unique_lock uniqueLock(mutex_); if (isAdded) { RequestNetworkLocation(workRecord); } else { @@ -480,7 +481,7 @@ void NetworkAbility::SendMessage(uint32_t code, MessageParcel &data, MessageParc void NetworkAbility::RegisterNLPServiceDeathRecipient() { - std::unique_lock uniqueLock(mutex_); + std::unique_lock uniqueLock(mutex_); if (nlpServiceProxy_ == nullptr) { LBSLOGE(NETWORK, "%{public}s: nlpServiceProxy_ is nullptr", __func__); return; @@ -491,7 +492,7 @@ void NetworkAbility::RegisterNLPServiceDeathRecipient() bool NetworkAbility::IsConnect() { - std::unique_lock uniqueLock(mutex_); + std::unique_lock uniqueLock(mutex_); return nlpServiceProxy_ != nullptr; } diff --git a/services/location_network/network/source/network_ability_skeleton.cpp b/services/location_network/network/source/network_ability_skeleton.cpp index 8241144c..61251cdf 100644 --- a/services/location_network/network/source/network_ability_skeleton.cpp +++ b/services/location_network/network/source/network_ability_skeleton.cpp @@ -38,17 +38,29 @@ void NetworkAbilityStub::InitNetworkMsgHandleMap() return; } NetworkMsgHandleMap_[static_cast(NetworkInterfaceCode::SEND_LOCATION_REQUEST)] = - &NetworkAbilityStub::SendLocationRequestInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return SendLocationRequestInner(data, reply, identity); + }; NetworkMsgHandleMap_[static_cast(NetworkInterfaceCode::SET_MOCKED_LOCATIONS)] = - &NetworkAbilityStub::SetMockLocationsInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return SetMockLocationsInner(data, reply, identity); + }; NetworkMsgHandleMap_[static_cast(NetworkInterfaceCode::SELF_REQUEST)] = - &NetworkAbilityStub::SelfRequestInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return SelfRequestInner(data, reply, identity); + }; NetworkMsgHandleMap_[static_cast(NetworkInterfaceCode::SET_ENABLE)] = - &NetworkAbilityStub::SetEnableInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return SetEnableInner(data, reply, identity); + }; NetworkMsgHandleMap_[static_cast(NetworkInterfaceCode::ENABLE_LOCATION_MOCK)] = - &NetworkAbilityStub::EnableMockInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return EnableMockInner(data, reply, identity); + }; NetworkMsgHandleMap_[static_cast(NetworkInterfaceCode::DISABLE_LOCATION_MOCK)] = - &NetworkAbilityStub::DisableMockInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return DisableMockInner(data, reply, identity); + }; } NetworkAbilityStub::NetworkAbilityStub() @@ -124,12 +136,11 @@ int NetworkAbilityStub::OnRemoteRequest(uint32_t code, AppIdentity identity; identity.SetPid(callingPid); identity.SetUid(callingUid); - LBSLOGD(NETWORK, "OnRemoteRequest cmd = %{public}u, flags= %{public}d, pid= %{public}d, uid= %{public}d", + LBSLOGI(NETWORK, "OnRemoteRequest cmd = %{public}u, flags= %{public}d, pid= %{public}d, uid= %{public}d", code, option.GetFlags(), callingPid, callingUid); if (data.ReadInterfaceToken() != GetDescriptor()) { LBSLOGE(NETWORK, "invalid token."); - reply.WriteInt32(ERRCODE_SERVICE_UNAVAILABLE); return ERRCODE_SERVICE_UNAVAILABLE; } int ret = ERRCODE_SUCCESS; @@ -137,10 +148,9 @@ int NetworkAbilityStub::OnRemoteRequest(uint32_t code, auto handleFunc = NetworkMsgHandleMap_.find(code); if (handleFunc != NetworkMsgHandleMap_.end() && handleFunc->second != nullptr) { auto memberFunc = handleFunc->second; - ret = (this->*memberFunc)(data, reply, identity); + ret = memberFunc(data, reply, identity); } else { LBSLOGE(NETWORK, "OnReceived cmd = %{public}u, unsupport service.", code); - reply.WriteInt32(ERRCODE_NOT_SUPPORTED); ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option); } if (!isMessageRequest_) { diff --git a/services/location_passive/passive/BUILD.gn b/services/location_passive/passive/BUILD.gn index be147bc8..2e3cf0c3 100644 --- a/services/location_passive/passive/BUILD.gn +++ b/services/location_passive/passive/BUILD.gn @@ -14,15 +14,17 @@ import("//base/location/config.gni") import("//build/ohos.gni") +local_base_sources = [ + "$LOCATION_LOCATOR_ROOT/source/subability_common.cpp", + "$LOCATION_LOCATOR_ROOT/source/work_record.cpp", + "$LOCATION_LOCATOR_ROOT/source/work_record_statistic.cpp", + "$LOCATION_PASSIVE_ROOT/source/passive_ability.cpp", + "$LOCATION_PASSIVE_ROOT/source/passive_ability_skeleton.cpp", +] + if (location_feature_with_passive) { ohos_shared_library("lbsservice_passive") { - sources = [ - "$LOCATION_LOCATOR_ROOT/source/subability_common.cpp", - "$LOCATION_LOCATOR_ROOT/source/work_record.cpp", - "$LOCATION_LOCATOR_ROOT/source/work_record_statistic.cpp", - "$LOCATION_PASSIVE_ROOT/source/passive_ability.cpp", - "$LOCATION_PASSIVE_ROOT/source/passive_ability_skeleton.cpp", - ] + sources = local_base_sources include_dirs = [ "$LOCATION_ROOT_DIR/interfaces/inner_api/include", @@ -42,12 +44,70 @@ if (location_feature_with_passive) { ] external_deps = [ - "c_utils:utils", "eventhandler:libeventhandler", "hilog:libhilog", "ipc:ipc_single", "safwk:system_ability_fwk", - "samgr:samgr_proxy", + ] + + ldflags = [ + "-Wl,--as-needed", + "-Wl,--gc-sections", + ] + + cflags_cc = [ + "-ffunction-sections", + "-fdata-sections", + "-Os", + ] + + defines = [] + if (location_feature_with_passive) { + defines += [ "FEATURE_PASSIVE_SUPPORT" ] + } + + # Used to control the export of dynamic library symbols. + version_script = "liblbsservice_passive_version_script.txt" + + part_name = "location" + subsystem_name = "location" + } + + ohos_static_library("lbsservice_passive_static") { + sources = local_base_sources + + include_dirs = [ + "$LOCATION_ROOT_DIR/interfaces/inner_api/include", + "$LOCATION_LOCATOR_ROOT/include", + "$LOCATION_PASSIVE_ROOT/include", + ] + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + deps = [ + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", + ] + + external_deps = [ + "eventhandler:libeventhandler", + "hilog:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + ] + + ldflags = [ + "-Wl,--as-needed", + "-Wl,--gc-sections", + ] + + cflags_cc = [ + "-ffunction-sections", + "-fdata-sections", ] defines = [] @@ -63,4 +123,9 @@ if (location_feature_with_passive) { part_name = "location" subsystem_name = "location" } + + ohos_static_library("lbsservice_passive_static") { + part_name = "location" + subsystem_name = "location" + } } diff --git a/services/location_passive/passive/include/passive_ability_skeleton.h b/services/location_passive/passive/include/passive_ability_skeleton.h index 58064b0b..a28bc8cb 100644 --- a/services/location_passive/passive/include/passive_ability_skeleton.h +++ b/services/location_passive/passive/include/passive_ability_skeleton.h @@ -34,8 +34,7 @@ public: class PassiveAbilityStub : public IRemoteStub { public: - using PassiveMsgHandle = int (PassiveAbilityStub::*)( - MessageParcel &data, MessageParcel &reply, AppIdentity &identity); + using PassiveMsgHandle = std::function; using PassiveMsgHandleMap = std::map; PassiveAbilityStub(); virtual ~PassiveAbilityStub() = default; diff --git a/services/location_passive/passive/liblbsservice_passive_version_script.txt b/services/location_passive/passive/liblbsservice_passive_version_script.txt new file mode 100644 index 00000000..1aeaa975 --- /dev/null +++ b/services/location_passive/passive/liblbsservice_passive_version_script.txt @@ -0,0 +1,5 @@ +{ + global: + local: + *; +}; \ No newline at end of file diff --git a/services/location_passive/passive/source/passive_ability.cpp b/services/location_passive/passive/source/passive_ability.cpp index 8fba1880..63fa26f9 100644 --- a/services/location_passive/passive/source/passive_ability.cpp +++ b/services/location_passive/passive/source/passive_ability.cpp @@ -48,7 +48,8 @@ PassiveAbility* PassiveAbility::GetInstance() PassiveAbility::PassiveAbility() : SystemAbility(LOCATION_NOPOWER_LOCATING_SA_ID, true) { SetAbility(PASSIVE_ABILITY); - passiveHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); + passiveHandler_ = + std::make_shared(AppExecFwk::EventRunner::Create(true, AppExecFwk::ThreadMode::FFRT)); LBSLOGI(PASSIVE, "ability constructed."); } diff --git a/services/location_passive/passive/source/passive_ability_skeleton.cpp b/services/location_passive/passive/source/passive_ability_skeleton.cpp index 7b8b2a97..7a1def92 100644 --- a/services/location_passive/passive/source/passive_ability_skeleton.cpp +++ b/services/location_passive/passive/source/passive_ability_skeleton.cpp @@ -36,15 +36,25 @@ void PassiveAbilityStub::InitPassiveMsgHandleMap() return; } PassiveMsgHandleMap_[static_cast(PassiveInterfaceCode::SEND_LOCATION_REQUEST)] = - &PassiveAbilityStub::SendLocationRequestInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return SendLocationRequestInner(data, reply, identity); + }; PassiveMsgHandleMap_[static_cast(PassiveInterfaceCode::SET_ENABLE)] = - &PassiveAbilityStub::SetEnableInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return SetEnableInner(data, reply, identity); + }; PassiveMsgHandleMap_[static_cast(PassiveInterfaceCode::ENABLE_LOCATION_MOCK)] = - &PassiveAbilityStub::EnableMockInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return EnableMockInner(data, reply, identity); + }; PassiveMsgHandleMap_[static_cast(PassiveInterfaceCode::DISABLE_LOCATION_MOCK)] = - &PassiveAbilityStub::DisableMockInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return DisableMockInner(data, reply, identity); + }; PassiveMsgHandleMap_[static_cast(PassiveInterfaceCode::SET_MOCKED_LOCATIONS)] = - &PassiveAbilityStub::SetMockedLocationsInner; + [this](MessageParcel &data, MessageParcel &reply, AppIdentity &identity) { + return SetMockedLocationsInner(data, reply, identity); + }; } PassiveAbilityStub::PassiveAbilityStub() @@ -112,7 +122,6 @@ int PassiveAbilityStub::OnRemoteRequest(uint32_t code, if (data.ReadInterfaceToken() != GetDescriptor()) { LBSLOGE(PASSIVE, "invalid token."); - reply.WriteInt32(ERRCODE_SERVICE_UNAVAILABLE); return ERRCODE_SERVICE_UNAVAILABLE; } int ret = ERRCODE_SUCCESS; @@ -120,10 +129,9 @@ int PassiveAbilityStub::OnRemoteRequest(uint32_t code, auto handleFunc = PassiveMsgHandleMap_.find(code); if (handleFunc != PassiveMsgHandleMap_.end() && handleFunc->second != nullptr) { auto memberFunc = handleFunc->second; - ret = (this->*memberFunc)(data, reply, identity); + ret = memberFunc(data, reply, identity); } else { LBSLOGE(PASSIVE, "OnReceived cmd = %{public}u, unsupport service.", code); - reply.WriteInt32(ERRCODE_NOT_SUPPORTED); ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option); } if (!isMessageRequest_) { diff --git a/services/location_ui/BUILD.gn b/services/location_ui/BUILD.gn index d46ceda5..5180eb97 100644 --- a/services/location_ui/BUILD.gn +++ b/services/location_ui/BUILD.gn @@ -22,6 +22,7 @@ ohos_hap("location_dialog_hap") { ":location_dialog_resources", ] + publicity_file = "publicity.xml" certificate_profile = "signature/locationdialog.p7b" hap_name = "LocationDialog" subsystem_name = "application" diff --git a/services/location_ui/entry/src/main/ets/locationprivacyextability/LocationPrivacyExtAbility.ets b/services/location_ui/entry/src/main/ets/locationprivacyextability/LocationPrivacyExtAbility.ets index 508a4a9f..ea3d108e 100644 --- a/services/location_ui/entry/src/main/ets/locationprivacyextability/LocationPrivacyExtAbility.ets +++ b/services/location_ui/entry/src/main/ets/locationprivacyextability/LocationPrivacyExtAbility.ets @@ -21,7 +21,6 @@ const TAG: string = '[Location-Privacy]==>' export default class LocationPrivacyExtAbility extends UIExtensionAbility { onSessionCreate(want: Want, session: UIExtensionContentSession) { - console.info(TAG, `LocationPrivacyExtAbility onSessionCreate, want: ${JSON.stringify(want)}`) if (want.parameters == undefined) { return; } diff --git a/services/location_ui/entry/src/main/ets/serviceability/WifiServiceAbility.ets b/services/location_ui/entry/src/main/ets/serviceability/WifiServiceAbility.ets index ea23e83a..0542fd65 100644 --- a/services/location_ui/entry/src/main/ets/serviceability/WifiServiceAbility.ets +++ b/services/location_ui/entry/src/main/ets/serviceability/WifiServiceAbility.ets @@ -47,7 +47,7 @@ export default class WifiServiceAbility extends ServiceExtensionAbility { let status : number = want.parameters?.['status'] as number; let ssid : string = want.parameters?.['ssid'] as string; try { - let file = fs.openSync("/system/etc/wifi/portal_notification.png", fs.OpenMode.READ_ONLY); + let file = fs.openSync('/system/etc/wifi/portal_notification.png', fs.OpenMode.READ_ONLY); const imageSourceApi: image.ImageSource = image.createImageSource(file.fd); imageSourceApi.createPixelMap() .then((pixelmap: image.PixelMap) => { @@ -95,20 +95,20 @@ export default class WifiServiceAbility extends ServiceExtensionAbility { let templateTitle: string = ''; let templateText: string = ''; switch (status) { - case this.WIFI_PORTAL_CONNECTED: - templateTitle = this.getFormatString($r('app.string.wifi_portal_connected_notify_title'), ssid); - templateText = this.context.resourceManager.getStringSync($r('app.string.wifi_portal_connected_notify_text').id); - break; - case this.WIFI_PORTAL_TIMEOUT: - templateTitle = this.context.resourceManager.getStringSync($r('app.string.wifi_portal_connect_timeout_notify_title').id); - templateText = this.getFormatString($r('app.string.wifi_portal_connect_timeout_notify_text'), ssid); - break; - case this.WIFI_PORTAL_FOUND: - templateTitle = this.context.resourceManager.getStringSync($r('app.string.wifi_portal_found_notify_title').id); - templateText = this.getFormatString($r('app.string.wifi_portal_found_notify_text'), ssid); - break; - default: - break; + case this.WIFI_PORTAL_CONNECTED: + templateTitle = this.getFormatString($r('app.string.wifi_portal_connected_notify_title'), ssid); + templateText = this.context.resourceManager.getStringSync($r('app.string.wifi_portal_connected_notify_text').id); + break; + case this.WIFI_PORTAL_TIMEOUT: + templateTitle = this.context.resourceManager.getStringSync($r('app.string.wifi_portal_connect_timeout_notify_title').id); + templateText = this.getFormatString($r('app.string.wifi_portal_connect_timeout_notify_text'), ssid); + break; + case this.WIFI_PORTAL_FOUND: + templateTitle = this.context.resourceManager.getStringSync($r('app.string.wifi_portal_found_notify_title').id); + templateText = this.getFormatString($r('app.string.wifi_portal_found_notify_text'), ssid); + break; + default: + break; } let notificationRequest: NotificationManager.NotificationRequest = { id: id, @@ -120,15 +120,16 @@ export default class WifiServiceAbility extends ServiceExtensionAbility { } }, slotType: Notification.SlotType.SERVICE_INFORMATION, + isUnremovable: true, wantAgent: wantAgentObj, smallIcon: pixelmap }; - Notification.publish(notificationRequest, (err,data) => { + Notification.publish(notificationRequest, (err, data) => { if (err) { console.error(TAG, `Publish wifi notification failed, code is ${err}`); } else { - console.info(TAG, "Publish wifi notification success"); + console.info(TAG, 'Publish wifi notification success'); } }); } @@ -138,7 +139,7 @@ export default class WifiServiceAbility extends ServiceExtensionAbility { if (err) { console.error(TAG, `Cancel wifi notification failed, code is ${err}`); } else { - console.info(TAG, "Cancel wifi notification success"); + console.info(TAG, 'Cancel wifi notification success'); } }); } diff --git a/services/location_ui/entry/src/main/module.json b/services/location_ui/entry/src/main/module.json index cc917959..a17228d8 100644 --- a/services/location_ui/entry/src/main/module.json +++ b/services/location_ui/entry/src/main/module.json @@ -7,7 +7,8 @@ "mainElement": "EntryAbility", "deviceTypes": [ "phone", - "tablet" + "tablet", + "2in1" ], "deliveryWithInstall": true, "installationFree": false, @@ -35,7 +36,7 @@ "srcEntry": "./ets/wifiability/WifiUIExtAbility.ets", "description": "WifiUIExtAbility", "label": "WifiUIExtAbility", - "exported": true, + "exported": false, "type": "sysDialog/common" }, { @@ -44,8 +45,8 @@ "description": "service", "icon": "$media:app_icon", "type": "service", - "visible": true, - "exported": true + "visible": false, + "exported": false } ], "requestPermissions": [ diff --git a/services/location_ui/entry/src/main/resources/base/element/string.json b/services/location_ui/entry/src/main/resources/base/element/string.json index 124bd7f9..ddfe9654 100644 --- a/services/location_ui/entry/src/main/resources/base/element/string.json +++ b/services/location_ui/entry/src/main/resources/base/element/string.json @@ -98,7 +98,7 @@ }, { "name": "wifi_three_vap_notify_title", - "value": "A hotspot can't be created while WLAN Direct, Huawei Share, or screen mirroring are in use. Disconnect and try again." + "value": "A hotspot can't be created while WLAN Direct, or screen mirroring are in use. Disconnect and try again." }, { "name": "wifi_three_vap_notify_no_button", diff --git a/services/location_ui/entry/src/main/resources/en_US/element/string.json b/services/location_ui/entry/src/main/resources/en_US/element/string.json index 010574fc..2e57d0b8 100644 --- a/services/location_ui/entry/src/main/resources/en_US/element/string.json +++ b/services/location_ui/entry/src/main/resources/en_US/element/string.json @@ -90,7 +90,7 @@ }, { "name": "wifi_three_vap_notify_title", - "value": "A hotspot can't be created while WLAN Direct, Huawei Share, or screen mirroring are in use. Disconnect and try again." + "value": "A hotspot can't be created while WLAN Direct, or screen mirroring are in use. Disconnect and try again." }, { "name": "wifi_three_vap_notify_no_button", diff --git a/services/location_ui/entry/src/main/resources/zh_CN/element/string.json b/services/location_ui/entry/src/main/resources/zh_CN/element/string.json index 18bcd8d3..bf3675d2 100644 --- a/services/location_ui/entry/src/main/resources/zh_CN/element/string.json +++ b/services/location_ui/entry/src/main/resources/zh_CN/element/string.json @@ -90,7 +90,7 @@ }, { "name": "wifi_three_vap_notify_title", - "value": "检测到 WLAN 共享通道已被占用。若您正使用 WLAN 直连、华为分享、多屏互动等互联应用,断开后才可开启个人热点。是否断开?" + "value": "检测到 WLAN 共享通道已被占用。若您正使用 WLAN 直连、多屏互动等互联应用,断开后才可开启个人热点。是否断开?" }, { "name": "wifi_three_vap_notify_no_button", diff --git a/services/location_ui/publicity.xml b/services/location_ui/publicity.xml new file mode 100644 index 00000000..eec1e19f --- /dev/null +++ b/services/location_ui/publicity.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/services/utils/BUILD.gn b/services/utils/BUILD.gn new file mode 100644 index 00000000..95cf1fcb --- /dev/null +++ b/services/utils/BUILD.gn @@ -0,0 +1,57 @@ +# Copyright (C) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/location/config.gni") +import("//build/ohos.gni") + +ohos_shared_library("lbsresources") { + include_dirs = [ + "$LOCATION_ROOT_DIR/services/utils/inner_api", + "$LOCATION_ROOT_DIR/services/utils/resource/include", + "$LOCATION_ROOT_DIR/interfaces/inner_api/include", + ] + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + sources = + [ "$LOCATION_ROOT_DIR/services/utils/resource/source/lbs_resources.cpp" ] + + deps = [] + + public_external_deps = [ "hilog:libhilog" ] + + defines = [] + + if (i18n_enable) { + public_external_deps += [ "i18n:intl_util" ] + defines += [ "I18N_ENABLE" ] + } + + ldflags = [ + "-Wl,--as-needed", + "-Wl,--gc-sections", + ] + + cflags_cc = [ + "-ffunction-sections", + "-fdata-sections", + ] + + part_name = "location" + subsystem_name = "location" +} diff --git a/services/utils/inner_api/i_resources.h b/services/utils/inner_api/i_resources.h new file mode 100644 index 00000000..908c4df6 --- /dev/null +++ b/services/utils/inner_api/i_resources.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef I_LBS_RESOURCES_H +#define I_LBS_RESOURCES_H + +#include + +namespace OHOS { +namespace Location { +class IResources { +public: + IResources() = default; + + virtual ~IResources() = default; + + /** + * @Description Get system region + * + * @return string - result + */ + virtual std::string GetSystemRegion() = 0; +}; +} +} +#endif // I_LBS_RESOURCES_H \ No newline at end of file diff --git a/services/utils/lbsutils/include/dynamic_library_loader.h b/services/utils/lbsutils/include/dynamic_library_loader.h new file mode 100644 index 00000000..6cf4961c --- /dev/null +++ b/services/utils/lbsutils/include/dynamic_library_loader.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LBS_DYNAMIC_LOADER_H +#define LBS_DYNAMIC_LOADER_H + +#include + +#include "location_log.h" + +namespace OHOS { +namespace Location { +template +class DynamicLibraryLoader { + typedef FuncType* (*funcEntry)(); +public: + explicit DynamicLibraryLoader(const std::string& libPath) + { + libPath_ = libPath; + handle_ = dlopen(libPath.c_str(), RTLD_LAZY); + if (!handle_) { + LBSLOGE(COMMON_UTILS, "%{public}s open so [%{public}s] failed, error: %{public}s", + __func__, libPath.c_str(), dlerror()); + } + LBSLOGI(COMMON_UTILS, "%{public}s open so [%{public}s] success.", __func__, libPath.c_str()); + } + + ~DynamicLibraryLoader() + { + if (handle_) { + LBSLOGI(COMMON_UTILS, "%{public}s close so [%{public}s]", __func__, libPath_.c_str()); + dlclose(handle_); + handle_ = nullptr; + } + } + + funcEntry GetFunction(const std::string& funcName) + { + if (!handle_) { + return nullptr; + } + auto funcPtr = dlsym(handle_, funcName.c_str()); + char* error = dlerror(); + if (error != nullptr || funcPtr == nullptr) { + LBSLOGE(COMMON_UTILS, "%{public}s, [%{public}s] dlsym error, error: %{public}s", + __func__, libPath_.c_str(), error); + return nullptr; + } + return (funcEntry)(funcPtr); + } + +private: + std::string libPath_; + void* handle_ = nullptr; +}; +} // namespace Location +} // namespace OHOS +#endif // LBS_DYNAMIC_LOADER_H \ No newline at end of file diff --git a/services/utils/lbsutils/include/lbs_res_loader.h b/services/utils/lbsutils/include/lbs_res_loader.h new file mode 100644 index 00000000..814ebc51 --- /dev/null +++ b/services/utils/lbsutils/include/lbs_res_loader.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LBS_RES_LOADER_H +#define LBS_RES_LOADER_H + +#include "location_log.h" + +#include "i_resources.h" +#include "dynamic_library_loader.h" + +namespace OHOS { +namespace Location { +class LbsResLoader { +public: + const std::string RES_DLL_NAME = "liblbsresources.z.so"; + + LbsResLoader(); + ~LbsResLoader(); + + std::string GetSystemRegion(); + +private: + DynamicLibraryLoader loader_; + IResources *(*entry_)(); +}; +} // namespace Location +} // namespace OHOS +#endif // LBS_RES_LOADER_H \ No newline at end of file diff --git a/services/utils/lbsutils/source/lbs_res_loader.cpp b/services/utils/lbsutils/source/lbs_res_loader.cpp new file mode 100644 index 00000000..682f4bff --- /dev/null +++ b/services/utils/lbsutils/source/lbs_res_loader.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "lbs_res_loader.h" + +namespace OHOS { +namespace Location { +LbsResLoader::LbsResLoader() : loader_(RES_DLL_NAME), entry_(nullptr) +{ +} + +LbsResLoader::~LbsResLoader() +{ +} + +std::string LbsResLoader::GetSystemRegion() +{ + if (entry_ == nullptr) { + entry_ = loader_.GetFunction("Create"); + } + if (entry_ == nullptr) { + LBSLOGE(COMMON_UTILS, "%{public}s instance is null", __func__); + return ""; + } + return entry_()->GetSystemRegion(); +} +} // namespace Location +} // namespace OHOS diff --git a/services/utils/resource/include/lbs_resources.h b/services/utils/resource/include/lbs_resources.h new file mode 100644 index 00000000..fae495de --- /dev/null +++ b/services/utils/resource/include/lbs_resources.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LBS_RESOURCE_H +#define LBS_RESOURCE_H + + +#ifdef I18N_ENABLE +#include + +#include "i_resources.h" + +namespace OHOS { +namespace Location { +class LbsResource : public IResources { +public: + LbsResource(); + ~LbsResource() override; + + LbsResource(const LbsResource&) = delete; + LbsResource& operator=(const LbsResource&) = delete; + + static LbsResource& GetInstance(); + std::string GetSystemRegion() override; +}; +} // namespace Location +} // namespace OHOS +#endif // I18N_ENABLE +#endif // LBS_RESOURCE_H diff --git a/services/utils/resource/source/lbs_resources.cpp b/services/utils/resource/source/lbs_resources.cpp new file mode 100644 index 00000000..716f5d05 --- /dev/null +++ b/services/utils/resource/source/lbs_resources.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef I18N_ENABLE +#include "lbs_resources.h" + +#include "locale_config.h" +#include "location_log.h" + +namespace OHOS { +namespace Location { +LbsResource::LbsResource() +{ +} + +LbsResource::~LbsResource() +{ +} + +static LbsResource* GetInstance() +{ + static LbsResource instance; + return &instance; +} + +extern "C" IResources *Create() +{ + return GetInstance(); +} + +std::string LbsResource::GetSystemRegion() +{ + std::string result = Global::I18n::LocaleConfig::GetSystemRegion(); + LBSLOGI(COMMON_UTILS, "%{public}s I18n result is: %{public}s", __func__, result.c_str()); + return result; +} +} // namespace Location +} // namespace OHOS +#endif // I18N_ENABLE diff --git a/test/fuzztest/locator/cachedlocationcallbackhost_fuzzer/BUILD.gn b/test/fuzztest/locator/cachedlocationcallbackhost_fuzzer/BUILD.gn index 91df53c7..c8048f1a 100644 --- a/test/fuzztest/locator/cachedlocationcallbackhost_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/cachedlocationcallbackhost_fuzzer/BUILD.gn @@ -39,14 +39,14 @@ ohos_fuzztest("CachedLocationCallbackHostFuzzTest") { sources = [ "cachedlocationcallbackhost_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode", - "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", - "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network", - "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode_static", + "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network_static", + "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive_static", "//third_party/libuv:uv", ] external_deps = [ @@ -59,6 +59,7 @@ ohos_fuzztest("CachedLocationCallbackHostFuzzTest") { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/cachedlocationcallbackhost_fuzzer/cachedlocationcallbackhost_fuzzer.cpp b/test/fuzztest/locator/cachedlocationcallbackhost_fuzzer/cachedlocationcallbackhost_fuzzer.cpp index 3032cd9a..63d3dff4 100644 --- a/test/fuzztest/locator/cachedlocationcallbackhost_fuzzer/cachedlocationcallbackhost_fuzzer.cpp +++ b/test/fuzztest/locator/cachedlocationcallbackhost_fuzzer/cachedlocationcallbackhost_fuzzer.cpp @@ -25,18 +25,18 @@ #include "token_setproc.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif #include "common_utils.h" #include "constant_definition.h" -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "i_locator_callback.h" #include "location.h" #include "locator.h" -#include "location_switch_callback_host.h" +#include "location_switch_callback_napi.h" #include "locator.h" #include "locator_ability.h" -#include "locator_callback_host.h" +#include "locator_callback_napi.h" #include "location_log.h" namespace OHOS { @@ -76,8 +76,8 @@ bool CachedLocationsCallbackHostFuzzTest(const char* data, size_t size) MessageParcel reply; MessageOption option; - auto callback = sptr(new (std::nothrow) CachedLocationsCallbackHost()); - callback->OnRemoteRequest(CachedLocationsCallbackHost::RECEIVE_CACHED_LOCATIONS_EVENT, + auto callback = sptr(new (std::nothrow) CachedLocationsCallbackNapi()); + callback->OnRemoteRequest(CachedLocationsCallbackNapi::RECEIVE_CACHED_LOCATIONS_EVENT, requestParcel, reply, option); return true; } diff --git a/test/fuzztest/locator/cachedlocationcallbackhost_fuzzer/cachedlocationcallbackhost_fuzzer.h b/test/fuzztest/locator/cachedlocationcallbackhost_fuzzer/cachedlocationcallbackhost_fuzzer.h index f30c1405..ac825f9c 100644 --- a/test/fuzztest/locator/cachedlocationcallbackhost_fuzzer/cachedlocationcallbackhost_fuzzer.h +++ b/test/fuzztest/locator/cachedlocationcallbackhost_fuzzer/cachedlocationcallbackhost_fuzzer.h @@ -21,20 +21,20 @@ #include "iremote_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "locator_callback_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "i_locator.h" #include "locator_proxy.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif diff --git a/test/fuzztest/locator/checkmessage_fuzzer/BUILD.gn b/test/fuzztest/locator/checkmessage_fuzzer/BUILD.gn index bf6d6b3e..7af75a74 100644 --- a/test/fuzztest/locator/checkmessage_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/checkmessage_fuzzer/BUILD.gn @@ -40,14 +40,14 @@ ohos_fuzztest("CheckMessageFuzzTest") { sources = [ "checkmessage_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode", - "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", - "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network", - "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode_static", + "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network_static", + "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive_static", "//third_party/libuv:uv", ] external_deps = [ @@ -60,6 +60,7 @@ ohos_fuzztest("CheckMessageFuzzTest") { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/checkmessage_fuzzer/checkmessage_fuzzer.h b/test/fuzztest/locator/checkmessage_fuzzer/checkmessage_fuzzer.h index 9d758d6e..7a68c653 100644 --- a/test/fuzztest/locator/checkmessage_fuzzer/checkmessage_fuzzer.h +++ b/test/fuzztest/locator/checkmessage_fuzzer/checkmessage_fuzzer.h @@ -21,20 +21,20 @@ #include "iremote_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "locator_callback_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "i_locator.h" #include "locator_proxy.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif diff --git a/test/fuzztest/locator/countrycodecallbackhost_fuzzer/BUILD.gn b/test/fuzztest/locator/countrycodecallbackhost_fuzzer/BUILD.gn index 31e7601d..62eb650a 100644 --- a/test/fuzztest/locator/countrycodecallbackhost_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/countrycodecallbackhost_fuzzer/BUILD.gn @@ -40,14 +40,14 @@ ohos_fuzztest("CountryCodeCallbackHostFuzzTest") { sources = [ "countrycodecallbackhost_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode", - "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", - "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network", - "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode_static", + "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network_static", + "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive_static", "//third_party/libuv:uv", ] external_deps = [ @@ -60,6 +60,7 @@ ohos_fuzztest("CountryCodeCallbackHostFuzzTest") { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/countrycodecallbackhost_fuzzer/countrycodecallbackhost_fuzzer.cpp b/test/fuzztest/locator/countrycodecallbackhost_fuzzer/countrycodecallbackhost_fuzzer.cpp index c9993116..0d0bcf7b 100644 --- a/test/fuzztest/locator/countrycodecallbackhost_fuzzer/countrycodecallbackhost_fuzzer.cpp +++ b/test/fuzztest/locator/countrycodecallbackhost_fuzzer/countrycodecallbackhost_fuzzer.cpp @@ -25,7 +25,7 @@ #include "common_utils.h" #include "constant_definition.h" -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "i_locator_callback.h" #include "location.h" #include "locator_ability.h" @@ -67,8 +67,8 @@ bool CountryCodeCallbackHostFuzzTest(const char* data, size_t size) MessageParcel reply; MessageOption option; - auto callback = sptr(new (std::nothrow) CountryCodeCallbackHost()); - callback->OnRemoteRequest(CountryCodeCallbackHost::COUNTRY_CODE_CHANGE_EVENT, requestParcel, reply, option); + auto callback = sptr(new (std::nothrow) CountryCodeCallbackNapi()); + callback->OnRemoteRequest(CountryCodeCallbackNapi::COUNTRY_CODE_CHANGE_EVENT, requestParcel, reply, option); return true; } } // namespace OHOS diff --git a/test/fuzztest/locator/countrycodecallbackhost_fuzzer/countrycodecallbackhost_fuzzer.h b/test/fuzztest/locator/countrycodecallbackhost_fuzzer/countrycodecallbackhost_fuzzer.h index fdaeb170..10ab93de 100644 --- a/test/fuzztest/locator/countrycodecallbackhost_fuzzer/countrycodecallbackhost_fuzzer.h +++ b/test/fuzztest/locator/countrycodecallbackhost_fuzzer/countrycodecallbackhost_fuzzer.h @@ -21,20 +21,20 @@ #include "iremote_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "locator_callback_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "i_locator.h" #include "locator_proxy.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif diff --git a/test/fuzztest/locator/countrycodemanager_fuzzer/BUILD.gn b/test/fuzztest/locator/countrycodemanager_fuzzer/BUILD.gn index dadf82d2..e72a5429 100644 --- a/test/fuzztest/locator/countrycodemanager_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/countrycodemanager_fuzzer/BUILD.gn @@ -34,9 +34,9 @@ ohos_fuzztest("CountryCodeManagerFuzzTest") { sources = [ "countrycodemanager_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", "//third_party/libuv:uv", ] external_deps = [ diff --git a/test/fuzztest/locator/fusioncontroller_fuzzer/BUILD.gn b/test/fuzztest/locator/fusioncontroller_fuzzer/BUILD.gn index b1520fbd..dc6c8e1c 100644 --- a/test/fuzztest/locator/fusioncontroller_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/fusioncontroller_fuzzer/BUILD.gn @@ -34,9 +34,9 @@ ohos_fuzztest("FusionControllerFuzzTest") { sources = [ "fusioncontroller_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", "//third_party/libuv:uv", ] external_deps = [ diff --git a/test/fuzztest/locator/geoconvertproxy_fuzzer/BUILD.gn b/test/fuzztest/locator/geoconvertproxy_fuzzer/BUILD.gn index d44d627b..4b36dbfd 100644 --- a/test/fuzztest/locator/geoconvertproxy_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/geoconvertproxy_fuzzer/BUILD.gn @@ -36,12 +36,11 @@ if (location_feature_with_geocode) { sources = [ "geoconvertproxy_fuzzer.cpp" ] deps = [ "$ARKUI_ROOT_DIR/napi:ace_napi", - "$LIB_UV_DIR:uv", - "$LOCATION_GEOCONVERT_ROOT:lbsservice_geocode", - "$LOCATION_LOCATOR_ROOT:lbsservice_locator", + "$LOCATION_GEOCONVERT_ROOT:lbsservice_geocode_static", + "$LOCATION_LOCATOR_ROOT:lbsservice_locator_static", "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", ] external_deps = [ "access_token:libaccesstoken_sdk", diff --git a/test/fuzztest/locator/geoconvertservice_fuzzer/BUILD.gn b/test/fuzztest/locator/geoconvertservice_fuzzer/BUILD.gn index da191cd6..ea5e8828 100644 --- a/test/fuzztest/locator/geoconvertservice_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/geoconvertservice_fuzzer/BUILD.gn @@ -40,14 +40,14 @@ ohos_fuzztest("GeoconvertServiceFuzzTest") { sources = [ "geoconvertservice_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode", - "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", - "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network", - "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode_static", + "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network_static", + "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive_static", "//third_party/libuv:uv", ] external_deps = [ @@ -60,6 +60,7 @@ ohos_fuzztest("GeoconvertServiceFuzzTest") { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/geoconvertservice_fuzzer/geoconvertservice_fuzzer.h b/test/fuzztest/locator/geoconvertservice_fuzzer/geoconvertservice_fuzzer.h index 9e4e4b73..9f838064 100644 --- a/test/fuzztest/locator/geoconvertservice_fuzzer/geoconvertservice_fuzzer.h +++ b/test/fuzztest/locator/geoconvertservice_fuzzer/geoconvertservice_fuzzer.h @@ -21,20 +21,20 @@ #include "iremote_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "locator_callback_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "i_locator.h" #include "locator_proxy.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif diff --git a/test/fuzztest/locator/gnss_fuzzer/BUILD.gn b/test/fuzztest/locator/gnss_fuzzer/BUILD.gn index 621913c2..72cc1020 100644 --- a/test/fuzztest/locator/gnss_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/gnss_fuzzer/BUILD.gn @@ -35,11 +35,12 @@ if (location_feature_with_gnss) { sources = [ "gnss_fuzzer.cpp" ] deps = [ "$ARKUI_ROOT_DIR/napi:ace_napi", - "$LOCATION_GNSS_ROOT:lbsservice_gnss", - "$LOCATION_LOCATOR_ROOT:lbsservice_locator", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", + "$LOCATION_GNSS_ROOT:lbsservice_gnss_static", + "$LOCATION_LOCATOR_ROOT:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", "$SAMGR_ROOT_DIR/safwk/interfaces/innerkits/safwk:system_ability_fwk", ] external_deps = [ @@ -50,6 +51,7 @@ if (location_feature_with_gnss) { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/gnss_fuzzer/gnss_fuzzer.cpp b/test/fuzztest/locator/gnss_fuzzer/gnss_fuzzer.cpp index 1d2a8065..29817498 100644 --- a/test/fuzztest/locator/gnss_fuzzer/gnss_fuzzer.cpp +++ b/test/fuzztest/locator/gnss_fuzzer/gnss_fuzzer.cpp @@ -22,16 +22,16 @@ #include "ipc_skeleton.h" #include "iremote_object.h" -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #include "common_utils.h" #include "constant_definition.h" -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "gnss_ability.h" #include "gnss_ability_proxy.h" -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #include "location.h" -#include "location_switch_callback_host.h" -#include "nmea_message_callback_host.h" +#include "location_switch_callback_napi.h" +#include "nmea_message_callback_napi.h" #include "subability_common.h" #include "work_record.h" #include "geofence_request.h" @@ -57,13 +57,13 @@ namespace OHOS { proxy->RefrashRequirements(); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMES)); auto gnssCallbackHost = - sptr(new (std::nothrow) GnssStatusCallbackHost()); + sptr(new (std::nothrow) GnssStatusCallbackNapi()); proxy->RegisterGnssStatusCallback(gnssCallbackHost, data[index++]); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMES)); proxy->UnregisterGnssStatusCallback(gnssCallbackHost); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMES)); auto nmeaCallbackHost = - sptr(new (std::nothrow) NmeaMessageCallbackHost()); + sptr(new (std::nothrow) NmeaMessageCallbackNapi()); proxy->RegisterNmeaMessageCallback(nmeaCallbackHost, data[index++]); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMES)); proxy->UnregisterNmeaMessageCallback(nmeaCallbackHost); @@ -83,7 +83,7 @@ namespace OHOS { new (std::nothrow) GnssAbilityProxy(ability); auto cachedRequest = std::make_unique(); auto cachedLocationsCallbackHost = - sptr(new (std::nothrow) CachedLocationsCallbackHost()); + sptr(new (std::nothrow) CachedLocationsCallbackNapi()); proxy->RegisterCachedCallback(cachedRequest, cachedLocationsCallbackHost); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMES)); proxy->UnregisterCachedCallback(cachedLocationsCallbackHost); diff --git a/test/fuzztest/locator/gnssability_fuzzer/BUILD.gn b/test/fuzztest/locator/gnssability_fuzzer/BUILD.gn index d072d383..26c3b66a 100644 --- a/test/fuzztest/locator/gnssability_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/gnssability_fuzzer/BUILD.gn @@ -36,11 +36,12 @@ if (location_feature_with_gnss) { sources = [ "gnssability_fuzzer.cpp" ] deps = [ "$ARKUI_ROOT_DIR/napi:ace_napi", - "$LOCATION_GNSS_ROOT:lbsservice_gnss", - "$LOCATION_LOCATOR_ROOT:lbsservice_locator", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", + "$LOCATION_GNSS_ROOT:lbsservice_gnss_static", + "$LOCATION_LOCATOR_ROOT:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", "$SAMGR_ROOT_DIR/safwk/interfaces/innerkits/safwk:system_ability_fwk", ] external_deps = [ @@ -53,6 +54,7 @@ if (location_feature_with_gnss) { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/gnssability_fuzzer/gnssability_fuzzer.cpp b/test/fuzztest/locator/gnssability_fuzzer/gnssability_fuzzer.cpp index 15575444..2612f38a 100644 --- a/test/fuzztest/locator/gnssability_fuzzer/gnssability_fuzzer.cpp +++ b/test/fuzztest/locator/gnssability_fuzzer/gnssability_fuzzer.cpp @@ -440,6 +440,24 @@ bool GnssAbility020FuzzTest(const char* data, size_t size) WorkRecordStatistic::DestroyInstance(); return true; } + +bool GnssAbility021FuzzTest(const char* data, size_t size) +{ + MessageParcel requestParcel; + requestParcel.WriteInterfaceToken(u"location.IGnssAbility"); + requestParcel.WriteBuffer(data, size); + requestParcel.RewindRead(0); + MessageParcel reply; + MessageOption option; + + auto ability = sptr(new (std::nothrow) GnssAbility()); + ability->OnRemoteRequest(static_cast(GnssInterfaceCode::SEND_NETWORK_LOCATION), + requestParcel, reply, option); + + std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMES)); + WorkRecordStatistic::DestroyInstance(); + return true; +} #endif } // namespace OHOS @@ -470,6 +488,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::GnssAbility018FuzzTest(ch, size); OHOS::GnssAbility019FuzzTest(ch, size); OHOS::GnssAbility020FuzzTest(ch, size); + OHOS::GnssAbility021FuzzTest(ch, size); #endif free(ch); ch = nullptr; diff --git a/test/fuzztest/locator/gnssstatuscallbackhost_fuzzer/BUILD.gn b/test/fuzztest/locator/gnssstatuscallbackhost_fuzzer/BUILD.gn index 41eb0125..9e496993 100644 --- a/test/fuzztest/locator/gnssstatuscallbackhost_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/gnssstatuscallbackhost_fuzzer/BUILD.gn @@ -40,14 +40,14 @@ ohos_fuzztest("GnssStatusCallbackHostFuzzTest") { sources = [ "gnssstatuscallbackhost_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode", - "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", - "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network", - "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode_static", + "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network_static", + "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive_static", "//third_party/libuv:uv", ] external_deps = [ @@ -60,6 +60,7 @@ ohos_fuzztest("GnssStatusCallbackHostFuzzTest") { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/gnssstatuscallbackhost_fuzzer/gnssstatuscallbackhost_fuzzer.cpp b/test/fuzztest/locator/gnssstatuscallbackhost_fuzzer/gnssstatuscallbackhost_fuzzer.cpp index a2368f33..0272b6fb 100644 --- a/test/fuzztest/locator/gnssstatuscallbackhost_fuzzer/gnssstatuscallbackhost_fuzzer.cpp +++ b/test/fuzztest/locator/gnssstatuscallbackhost_fuzzer/gnssstatuscallbackhost_fuzzer.cpp @@ -26,7 +26,7 @@ #include "locator_ability.h" #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif @@ -68,8 +68,8 @@ bool GnssStatusCallbackHostFuzzTest(const char* data, size_t size) MessageParcel reply; MessageOption option; - auto callback = sptr(new (std::nothrow) GnssStatusCallbackHost()); - callback->OnRemoteRequest(GnssStatusCallbackHost::RECEIVE_STATUS_INFO_EVENT, requestParcel, reply, option); + auto callback = sptr(new (std::nothrow) GnssStatusCallbackNapi()); + callback->OnRemoteRequest(GnssStatusCallbackNapi::RECEIVE_STATUS_INFO_EVENT, requestParcel, reply, option); return true; } #endif diff --git a/test/fuzztest/locator/gnssstatuscallbackhost_fuzzer/gnssstatuscallbackhost_fuzzer.h b/test/fuzztest/locator/gnssstatuscallbackhost_fuzzer/gnssstatuscallbackhost_fuzzer.h index ab3c0392..00c2e986 100644 --- a/test/fuzztest/locator/gnssstatuscallbackhost_fuzzer/gnssstatuscallbackhost_fuzzer.h +++ b/test/fuzztest/locator/gnssstatuscallbackhost_fuzzer/gnssstatuscallbackhost_fuzzer.h @@ -21,20 +21,20 @@ #include "iremote_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "locator_callback_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "i_locator.h" #include "locator_proxy.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif diff --git a/test/fuzztest/locator/locationconfigmanager_fuzzer/BUILD.gn b/test/fuzztest/locator/locationconfigmanager_fuzzer/BUILD.gn index 35adeb09..c28cece2 100644 --- a/test/fuzztest/locator/locationconfigmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/locationconfigmanager_fuzzer/BUILD.gn @@ -34,9 +34,9 @@ ohos_fuzztest("LocationConfigManagerFuzzTest") { sources = [ "locationconfigmanager_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", "//third_party/libuv:uv", ] external_deps = [ diff --git a/test/fuzztest/locator/locationswitchcallbackhost_fuzzer/BUILD.gn b/test/fuzztest/locator/locationswitchcallbackhost_fuzzer/BUILD.gn index 0948bac0..d7714e42 100644 --- a/test/fuzztest/locator/locationswitchcallbackhost_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/locationswitchcallbackhost_fuzzer/BUILD.gn @@ -39,14 +39,14 @@ ohos_fuzztest("LocationSwitchCallbackHostFuzzTest") { sources = [ "locationswitchcallbackhost_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode", - "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", - "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network", - "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode_static", + "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network_static", + "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive_static", "//third_party/libuv:uv", ] external_deps = [ @@ -59,6 +59,7 @@ ohos_fuzztest("LocationSwitchCallbackHostFuzzTest") { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/locationswitchcallbackhost_fuzzer/locationswitchcallbackhost_fuzzer.cpp b/test/fuzztest/locator/locationswitchcallbackhost_fuzzer/locationswitchcallbackhost_fuzzer.cpp index f52bfdfc..2c8460eb 100644 --- a/test/fuzztest/locator/locationswitchcallbackhost_fuzzer/locationswitchcallbackhost_fuzzer.cpp +++ b/test/fuzztest/locator/locationswitchcallbackhost_fuzzer/locationswitchcallbackhost_fuzzer.cpp @@ -25,7 +25,7 @@ #include "token_setproc.h" #include "locator_ability.h" -#include "location_switch_callback_host.h" +#include "location_switch_callback_napi.h" namespace OHOS { using namespace OHOS::Location; @@ -64,7 +64,7 @@ bool LocationSwitchCallbackHostFuzzTest(const char* data, size_t size) MessageParcel reply; MessageOption option; - auto callback = sptr(new (std::nothrow) LocationSwitchCallbackHost()); + auto callback = sptr(new (std::nothrow) LocationSwitchCallbackNapi()); callback->OnRemoteRequest(ISwitchCallback::RECEIVE_SWITCH_STATE_EVENT, requestParcel, reply, option); return true; } diff --git a/test/fuzztest/locator/locationswitchcallbackhost_fuzzer/locationswitchcallbackhost_fuzzer.h b/test/fuzztest/locator/locationswitchcallbackhost_fuzzer/locationswitchcallbackhost_fuzzer.h index e78ecaa1..4b5f228f 100644 --- a/test/fuzztest/locator/locationswitchcallbackhost_fuzzer/locationswitchcallbackhost_fuzzer.h +++ b/test/fuzztest/locator/locationswitchcallbackhost_fuzzer/locationswitchcallbackhost_fuzzer.h @@ -21,20 +21,20 @@ #include "iremote_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "locator_callback_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "i_locator.h" #include "locator_proxy.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif diff --git a/test/fuzztest/locator/locator_fuzzer/BUILD.gn b/test/fuzztest/locator/locator_fuzzer/BUILD.gn index 26c9f2bf..0eed114d 100644 --- a/test/fuzztest/locator/locator_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/locator_fuzzer/BUILD.gn @@ -39,13 +39,13 @@ ohos_fuzztest("LocatorFuzzTest") { sources = [ "locator_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode", - "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", - "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network", - "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode_static", + "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network_static", + "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive_static", "//third_party/libuv:uv", ] external_deps = [ diff --git a/test/fuzztest/locator/locator_fuzzer/locator_fuzzer.cpp b/test/fuzztest/locator/locator_fuzzer/locator_fuzzer.cpp index 3d693686..a444a376 100644 --- a/test/fuzztest/locator/locator_fuzzer/locator_fuzzer.cpp +++ b/test/fuzztest/locator/locator_fuzzer/locator_fuzzer.cpp @@ -25,25 +25,25 @@ #include "token_setproc.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif #include "common_utils.h" #include "constant_definition.h" -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #ifdef FEATURE_GEOCODE_SUPPORT #include "geo_address.h" #include "geo_coding_mock_info.h" #endif #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "i_locator_callback.h" #include "location.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" #include "location_log.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif #include "request_config.h" #ifdef FEATURE_GNSS_SUPPORT @@ -54,7 +54,7 @@ namespace OHOS { using namespace OHOS::Location; auto locatorCallbackHostForTest_ = - sptr(new (std::nothrow) LocatorCallbackHost()); + sptr(new (std::nothrow) LocatorCallbackNapi()); bool g_isGrant = false; const int32_t MAX_CODE_LEN = 512; const int32_t MAX_CODE_NUM = 40; @@ -97,7 +97,7 @@ bool LocatorProxySendRequestTest(const uint8_t* data, size_t size) int32_t result = remote->SendRequest(data[index++] % MAX_CODE_NUM, request, reply, option); return result == SUCCESS; } - + void AddPermission() { if (!g_isGrant) { @@ -127,7 +127,7 @@ bool CachedLocationsCallbackHostFuzzerTest(const uint8_t* data, size_t size) { int index = 0; auto cachedCallbackHost = - sptr(new (std::nothrow) CachedLocationsCallbackHost()); + sptr(new (std::nothrow) CachedLocationsCallbackNapi()); MessageParcel request; MessageParcel reply; MessageOption option; @@ -147,7 +147,7 @@ bool CountryCodeCallbackHostFuzzerTest(const uint8_t* data, size_t size) { int index = 0; auto callbackHost = - sptr(new (std::nothrow) CountryCodeCallbackHost()); + sptr(new (std::nothrow) CountryCodeCallbackNapi()); MessageParcel request; MessageParcel reply; MessageOption option; @@ -167,7 +167,7 @@ bool GnssStatusCallbackHostFuzzerTest(const uint8_t* data, size_t size) { int index = 0; auto gnssCallbackHost = - sptr(new (std::nothrow) GnssStatusCallbackHost()); + sptr(new (std::nothrow) GnssStatusCallbackNapi()); MessageParcel request; MessageParcel reply; MessageOption option; @@ -186,7 +186,7 @@ bool LocationSwitchCallbackHostFuzzerTest(const uint8_t* data, size_t size) { int index = 0; auto switchCallbackHost = - sptr(new (std::nothrow) LocationSwitchCallbackHost()); + sptr(new (std::nothrow) LocationSwitchCallbackNapi()); MessageParcel request; MessageParcel reply; MessageOption option; @@ -204,7 +204,7 @@ bool LocationCallbackHostFuzzerTest(const uint8_t* data, size_t size) { int index = 0; auto callbackHost = - sptr(new (std::nothrow) LocatorCallbackHost()); + sptr(new (std::nothrow) LocatorCallbackNapi()); MessageParcel request; MessageParcel reply; MessageOption option; @@ -230,7 +230,7 @@ bool NmeaMessageCallbackHostFuzzerTest(const uint8_t* data, size_t size) { int index = 0; auto nmeaCallbackHost = - sptr(new (std::nothrow) NmeaMessageCallbackHost()); + sptr(new (std::nothrow) NmeaMessageCallbackNapi()); MessageParcel request; MessageParcel reply; MessageOption option; diff --git a/test/fuzztest/locator/locator_fuzzer/locator_fuzzer.h b/test/fuzztest/locator/locator_fuzzer/locator_fuzzer.h index c38bba33..35b724f5 100644 --- a/test/fuzztest/locator/locator_fuzzer/locator_fuzzer.h +++ b/test/fuzztest/locator/locator_fuzzer/locator_fuzzer.h @@ -21,20 +21,20 @@ #include "iremote_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "locator_callback_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "i_locator.h" #include "locator_proxy.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif diff --git a/test/fuzztest/locator/locatorabilitystub_fuzzer/BUILD.gn b/test/fuzztest/locator/locatorabilitystub_fuzzer/BUILD.gn index f0187b28..8403894d 100644 --- a/test/fuzztest/locator/locatorabilitystub_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/locatorabilitystub_fuzzer/BUILD.gn @@ -40,14 +40,14 @@ ohos_fuzztest("LocatorAbilityStubFuzzTest") { sources = [ "locatorabilitystub_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode", - "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", - "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network", - "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode_static", + "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network_static", + "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive_static", "//third_party/libuv:uv", ] external_deps = [ @@ -60,6 +60,7 @@ ohos_fuzztest("LocatorAbilityStubFuzzTest") { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/locatorabilitystub_fuzzer/locatorabilitystub_fuzzer.cpp b/test/fuzztest/locator/locatorabilitystub_fuzzer/locatorabilitystub_fuzzer.cpp index e3ce36a8..0f60c01c 100644 --- a/test/fuzztest/locator/locatorabilitystub_fuzzer/locatorabilitystub_fuzzer.cpp +++ b/test/fuzztest/locator/locatorabilitystub_fuzzer/locatorabilitystub_fuzzer.cpp @@ -31,6 +31,7 @@ namespace OHOS { using namespace OHOS::Location; const int32_t MAX_MEM_SIZE = 4 * 1024 * 1024; const int32_t LOCATION_PERM_NUM = 4; +const int32_t WAIT_EVENT_TIME = 3; void MockNativePermission() { const char *perms[] = { @@ -825,7 +826,10 @@ bool LocatorAbilityStub045FuzzTest(const char* data, size_t size) auto ability = sptr(new (std::nothrow) LocatorAbilityStub()); ability->OnRemoteRequest(static_cast(LocatorInterfaceCode::UNREG_LOCATING_REQUIRED_DATA_CALLBACK), requestParcel, reply, option); - + auto locatorAbility = LocatorAbility::GetInstance(); + if (locatorAbility != nullptr) { + locatorAbility->RemoveUnloadTask(DEFAULT_CODE); + } return true; } } // namespace OHOS @@ -886,6 +890,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::LocatorAbilityStub043FuzzTest(ch, size); OHOS::LocatorAbilityStub044FuzzTest(ch, size); OHOS::LocatorAbilityStub045FuzzTest(ch, size); + sleep(OHOS::WAIT_EVENT_TIME); free(ch); ch = nullptr; } diff --git a/test/fuzztest/locator/locatorabilitystub_fuzzer/locatorabilitystub_fuzzer.h b/test/fuzztest/locator/locatorabilitystub_fuzzer/locatorabilitystub_fuzzer.h index 4e852e31..6beab030 100644 --- a/test/fuzztest/locator/locatorabilitystub_fuzzer/locatorabilitystub_fuzzer.h +++ b/test/fuzztest/locator/locatorabilitystub_fuzzer/locatorabilitystub_fuzzer.h @@ -21,20 +21,20 @@ #include "iremote_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "locator_callback_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "i_locator.h" #include "locator_proxy.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif diff --git a/test/fuzztest/locator/locatorbackgroundproxy_fuzzer/BUILD.gn b/test/fuzztest/locator/locatorbackgroundproxy_fuzzer/BUILD.gn index 76147e07..21fc5aca 100644 --- a/test/fuzztest/locator/locatorbackgroundproxy_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/locatorbackgroundproxy_fuzzer/BUILD.gn @@ -35,9 +35,9 @@ ohos_fuzztest("LocatorBackgroundProxyFuzzTest") { sources = [ "locatorbackgroundproxy_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", "//third_party/libuv:uv", ] external_deps = [ diff --git a/test/fuzztest/locator/locatorcallbackhost_fuzzer/BUILD.gn b/test/fuzztest/locator/locatorcallbackhost_fuzzer/BUILD.gn index 4a721726..ba608e1b 100644 --- a/test/fuzztest/locator/locatorcallbackhost_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/locatorcallbackhost_fuzzer/BUILD.gn @@ -40,14 +40,14 @@ ohos_fuzztest("LocatorCallbackHostFuzzTest") { sources = [ "locatorcallbackhost_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode", - "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", - "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network", - "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode_static", + "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network_static", + "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive_static", "//third_party/libuv:uv", ] external_deps = [ @@ -60,6 +60,7 @@ ohos_fuzztest("LocatorCallbackHostFuzzTest") { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/locatorcallbackhost_fuzzer/locatorcallbackhost_fuzzer.cpp b/test/fuzztest/locator/locatorcallbackhost_fuzzer/locatorcallbackhost_fuzzer.cpp index fc9e97c1..1d4eb37a 100644 --- a/test/fuzztest/locator/locatorcallbackhost_fuzzer/locatorcallbackhost_fuzzer.cpp +++ b/test/fuzztest/locator/locatorcallbackhost_fuzzer/locatorcallbackhost_fuzzer.cpp @@ -25,7 +25,7 @@ #include "token_setproc.h" #include "locator_ability.h" -#include "locator_callback_host.h" +#include "locator_callback_napi.h" #include "permission_manager.h" namespace OHOS { @@ -87,7 +87,7 @@ bool LocatorCallbackHost001FuzzTest(const char* data, size_t size) MessageParcel reply; MessageOption option; - auto callback = sptr(new (std::nothrow) LocatorCallbackHost()); + auto callback = sptr(new (std::nothrow) LocatorCallbackNapi()); callback->OnRemoteRequest(ILocatorCallback::RECEIVE_LOCATION_INFO_EVENT, requestParcel, reply, option); return true; @@ -103,7 +103,7 @@ bool LocatorCallbackHost002FuzzTest(const char* data, size_t size) MessageParcel reply; MessageOption option; - auto callback = sptr(new (std::nothrow) LocatorCallbackHost()); + auto callback = sptr(new (std::nothrow) LocatorCallbackNapi()); callback->OnRemoteRequest(ILocatorCallback::RECEIVE_LOCATION_STATUS_EVENT, requestParcel, reply, option); return true; @@ -119,7 +119,7 @@ bool LocatorCallbackHost003FuzzTest(const char* data, size_t size) MessageParcel reply; MessageOption option; - auto callback = sptr(new (std::nothrow) LocatorCallbackHost()); + auto callback = sptr(new (std::nothrow) LocatorCallbackNapi()); callback->OnRemoteRequest(ILocatorCallback::RECEIVE_ERROR_INFO_EVENT, requestParcel, reply, option); return true; diff --git a/test/fuzztest/locator/locatorcallbackhost_fuzzer/locatorcallbackhost_fuzzer.h b/test/fuzztest/locator/locatorcallbackhost_fuzzer/locatorcallbackhost_fuzzer.h index 083819cc..b54b8d01 100644 --- a/test/fuzztest/locator/locatorcallbackhost_fuzzer/locatorcallbackhost_fuzzer.h +++ b/test/fuzztest/locator/locatorcallbackhost_fuzzer/locatorcallbackhost_fuzzer.h @@ -21,20 +21,20 @@ #include "iremote_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "locator_callback_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "i_locator.h" #include "locator_proxy.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif diff --git a/test/fuzztest/locator/locatorcallbackstub_fuzzer/BUILD.gn b/test/fuzztest/locator/locatorcallbackstub_fuzzer/BUILD.gn index 336b2927..2aa4ca25 100644 --- a/test/fuzztest/locator/locatorcallbackstub_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/locatorcallbackstub_fuzzer/BUILD.gn @@ -40,14 +40,14 @@ ohos_fuzztest("LocatorCallbackStubFuzzTest") { sources = [ "locatorcallbackstub_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode", - "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", - "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network", - "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode_static", + "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network_static", + "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive_static", "//third_party/libuv:uv", ] external_deps = [ @@ -60,6 +60,7 @@ ohos_fuzztest("LocatorCallbackStubFuzzTest") { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/locatorcallbackstub_fuzzer/locatorcallbackstub_fuzzer.h b/test/fuzztest/locator/locatorcallbackstub_fuzzer/locatorcallbackstub_fuzzer.h index 4dfef18c..e1e1f9d0 100644 --- a/test/fuzztest/locator/locatorcallbackstub_fuzzer/locatorcallbackstub_fuzzer.h +++ b/test/fuzztest/locator/locatorcallbackstub_fuzzer/locatorcallbackstub_fuzzer.h @@ -21,20 +21,20 @@ #include "iremote_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "locator_callback_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "i_locator.h" #include "locator_proxy.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif diff --git a/test/fuzztest/locator/locatoreventmanager_fuzzer/BUILD.gn b/test/fuzztest/locator/locatoreventmanager_fuzzer/BUILD.gn index 759c887d..ab45a92d 100644 --- a/test/fuzztest/locator/locatoreventmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/locatoreventmanager_fuzzer/BUILD.gn @@ -34,9 +34,9 @@ ohos_fuzztest("LocatorEventManagerFuzzTest") { sources = [ "locatoreventmanager_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", "//third_party/libuv:uv", ] external_deps = [ diff --git a/test/fuzztest/locator/networkability_fuzzer/BUILD.gn b/test/fuzztest/locator/networkability_fuzzer/BUILD.gn index dfbde254..ab2ac95e 100644 --- a/test/fuzztest/locator/networkability_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/networkability_fuzzer/BUILD.gn @@ -40,14 +40,14 @@ ohos_fuzztest("NetworkAbilityFuzzTest") { sources = [ "networkability_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode", - "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", - "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network", - "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode_static", + "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network_static", + "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive_static", "//third_party/libuv:uv", ] external_deps = [ @@ -61,6 +61,7 @@ ohos_fuzztest("NetworkAbilityFuzzTest") { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/networkability_fuzzer/networkability_fuzzer.h b/test/fuzztest/locator/networkability_fuzzer/networkability_fuzzer.h index 0a9eb23d..950f791c 100644 --- a/test/fuzztest/locator/networkability_fuzzer/networkability_fuzzer.h +++ b/test/fuzztest/locator/networkability_fuzzer/networkability_fuzzer.h @@ -20,12 +20,12 @@ #include "iremote_object.h" #include "iremote_proxy.h" -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "locator_callback_proxy.h" #include "i_locator.h" #include "locator_proxy.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" namespace OHOS { diff --git a/test/fuzztest/locator/networkabilityproxy_fuzzer/BUILD.gn b/test/fuzztest/locator/networkabilityproxy_fuzzer/BUILD.gn index 9a10c69b..7b81a788 100644 --- a/test/fuzztest/locator/networkabilityproxy_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/networkabilityproxy_fuzzer/BUILD.gn @@ -20,7 +20,7 @@ import("//build/test.gni") ohos_fuzztest("NetworkAbilityProxyFuzzTest") { module_out_path = "location/location" fuzz_config_file = - "$LOCATION_ROOT_DIR/test/fuzztest/locator/networkability_fuzzer" + "$LOCATION_ROOT_DIR/test/fuzztest/locator/networkabilityproxy_fuzzer" include_dirs = [ "$LOCATION_ROOT_DIR/frameworks/js/napi/include", "$LOCATION_ROOT_DIR/interfaces/inner_api/include", @@ -40,14 +40,14 @@ ohos_fuzztest("NetworkAbilityProxyFuzzTest") { sources = [ "networkabilityproxy_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode", - "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", - "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network", - "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode_static", + "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network_static", + "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive_static", "//third_party/libuv:uv", ] external_deps = [ @@ -61,6 +61,7 @@ ohos_fuzztest("NetworkAbilityProxyFuzzTest") { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/networkcallbackhost_fuzzer/BUILD.gn b/test/fuzztest/locator/networkcallbackhost_fuzzer/BUILD.gn index 2be81eef..78c09d99 100644 --- a/test/fuzztest/locator/networkcallbackhost_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/networkcallbackhost_fuzzer/BUILD.gn @@ -40,14 +40,14 @@ ohos_fuzztest("NetworkCallbackHostFuzzTest") { sources = [ "networkcallbackhost_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode", - "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", - "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network", - "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode_static", + "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network_static", + "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive_static", "//third_party/libuv:uv", ] external_deps = [ @@ -60,6 +60,7 @@ ohos_fuzztest("NetworkCallbackHostFuzzTest") { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/networkcallbackhost_fuzzer/networkcallbackhost_fuzzer.h b/test/fuzztest/locator/networkcallbackhost_fuzzer/networkcallbackhost_fuzzer.h index f7f088b9..fcfe7021 100644 --- a/test/fuzztest/locator/networkcallbackhost_fuzzer/networkcallbackhost_fuzzer.h +++ b/test/fuzztest/locator/networkcallbackhost_fuzzer/networkcallbackhost_fuzzer.h @@ -21,20 +21,20 @@ #include "iremote_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "locator_callback_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "i_locator.h" #include "locator_proxy.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif diff --git a/test/fuzztest/locator/nmeamessagecallbackhost_fuzzer/BUILD.gn b/test/fuzztest/locator/nmeamessagecallbackhost_fuzzer/BUILD.gn index b211a117..19c4e44f 100644 --- a/test/fuzztest/locator/nmeamessagecallbackhost_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/nmeamessagecallbackhost_fuzzer/BUILD.gn @@ -40,14 +40,14 @@ ohos_fuzztest("NmeaMessageCallbackHostFuzzTest") { sources = [ "nmeamessagecallbackhost_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode", - "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", - "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network", - "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode_static", + "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network_static", + "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive_static", "//third_party/libuv:uv", ] external_deps = [ @@ -60,6 +60,7 @@ ohos_fuzztest("NmeaMessageCallbackHostFuzzTest") { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/nmeamessagecallbackhost_fuzzer/nmeamessagecallbackhost_fuzzer.cpp b/test/fuzztest/locator/nmeamessagecallbackhost_fuzzer/nmeamessagecallbackhost_fuzzer.cpp index 2a177114..53bc0a1c 100644 --- a/test/fuzztest/locator/nmeamessagecallbackhost_fuzzer/nmeamessagecallbackhost_fuzzer.cpp +++ b/test/fuzztest/locator/nmeamessagecallbackhost_fuzzer/nmeamessagecallbackhost_fuzzer.cpp @@ -26,7 +26,7 @@ #include "locator_ability.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif namespace OHOS { @@ -67,7 +67,7 @@ bool NmeaMessageCallbackHostFuzzTest(const char* data, size_t size) MessageParcel reply; MessageOption option; - auto callback = sptr(new (std::nothrow) NmeaMessageCallbackHost()); + auto callback = sptr(new (std::nothrow) NmeaMessageCallbackNapi()); callback->OnRemoteRequest(INmeaMessageCallback::RECEIVE_NMEA_MESSAGE_EVENT, requestParcel, reply, option); return true; } diff --git a/test/fuzztest/locator/nmeamessagecallbackhost_fuzzer/nmeamessagecallbackhost_fuzzer.h b/test/fuzztest/locator/nmeamessagecallbackhost_fuzzer/nmeamessagecallbackhost_fuzzer.h index a14e98ae..f544c1e9 100644 --- a/test/fuzztest/locator/nmeamessagecallbackhost_fuzzer/nmeamessagecallbackhost_fuzzer.h +++ b/test/fuzztest/locator/nmeamessagecallbackhost_fuzzer/nmeamessagecallbackhost_fuzzer.h @@ -21,20 +21,20 @@ #include "iremote_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "locator_callback_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "i_locator.h" #include "locator_proxy.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif diff --git a/test/fuzztest/locator/passiveability_fuzzer/BUILD.gn b/test/fuzztest/locator/passiveability_fuzzer/BUILD.gn index d959911e..7144835c 100644 --- a/test/fuzztest/locator/passiveability_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/passiveability_fuzzer/BUILD.gn @@ -40,14 +40,14 @@ ohos_fuzztest("PassiveAbilityFuzzTest") { sources = [ "passiveability_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode", - "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", - "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network", - "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode_static", + "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network_static", + "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive_static", "//third_party/libuv:uv", ] external_deps = [ @@ -60,6 +60,7 @@ ohos_fuzztest("PassiveAbilityFuzzTest") { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/passiveability_fuzzer/passiveability_fuzzer.h b/test/fuzztest/locator/passiveability_fuzzer/passiveability_fuzzer.h index 700cfbd7..100a15d6 100644 --- a/test/fuzztest/locator/passiveability_fuzzer/passiveability_fuzzer.h +++ b/test/fuzztest/locator/passiveability_fuzzer/passiveability_fuzzer.h @@ -21,20 +21,20 @@ #include "iremote_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "locator_callback_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "i_locator.h" #include "locator_proxy.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif diff --git a/test/fuzztest/locator/passiveabilityproxy_fuzzer/BUILD.gn b/test/fuzztest/locator/passiveabilityproxy_fuzzer/BUILD.gn index 1109f6c8..18c96dc7 100644 --- a/test/fuzztest/locator/passiveabilityproxy_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/passiveabilityproxy_fuzzer/BUILD.gn @@ -20,7 +20,7 @@ import("//build/test.gni") ohos_fuzztest("PassiveAbilityProxyFuzzTest") { module_out_path = "location/location" fuzz_config_file = - "$LOCATION_ROOT_DIR/test/fuzztest/locator/passiveability_fuzzer" + "$LOCATION_ROOT_DIR/test/fuzztest/locator/passiveabilityproxy_fuzzer" include_dirs = [ "$LOCATION_ROOT_DIR/frameworks/js/napi/include", "$LOCATION_ROOT_DIR/interfaces/inner_api/include", @@ -40,14 +40,14 @@ ohos_fuzztest("PassiveAbilityProxyFuzzTest") { sources = [ "passiveabilityproxy_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode", - "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", - "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network", - "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_geocode/geocode:lbsservice_geocode_static", + "$LOCATION_ROOT_DIR/services/location_gnss/gnss:lbsservice_gnss_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/services/location_network/network:lbsservice_network_static", + "$LOCATION_ROOT_DIR/services/location_passive/passive:lbsservice_passive_static", "//third_party/libuv:uv", ] external_deps = [ @@ -60,6 +60,7 @@ ohos_fuzztest("PassiveAbilityProxyFuzzTest") { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/passiveabilityproxy_fuzzer/passiveabilityproxy_fuzzer.h b/test/fuzztest/locator/passiveabilityproxy_fuzzer/passiveabilityproxy_fuzzer.h index 700cfbd7..100a15d6 100644 --- a/test/fuzztest/locator/passiveabilityproxy_fuzzer/passiveabilityproxy_fuzzer.h +++ b/test/fuzztest/locator/passiveabilityproxy_fuzzer/passiveabilityproxy_fuzzer.h @@ -21,20 +21,20 @@ #include "iremote_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "locator_callback_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "i_locator.h" #include "locator_proxy.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif diff --git a/test/fuzztest/locator/reportmanager_fuzzer/BUILD.gn b/test/fuzztest/locator/reportmanager_fuzzer/BUILD.gn index 706ed320..26c3656a 100644 --- a/test/fuzztest/locator/reportmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/reportmanager_fuzzer/BUILD.gn @@ -34,9 +34,9 @@ ohos_fuzztest("ReportManagerFuzzTest") { sources = [ "reportmanager_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", "//third_party/libuv:uv", ] external_deps = [ diff --git a/test/fuzztest/locator/reportmanager_fuzzer/reportmanager_fuzzer.cpp b/test/fuzztest/locator/reportmanager_fuzzer/reportmanager_fuzzer.cpp index d0a73015..a5836217 100644 --- a/test/fuzztest/locator/reportmanager_fuzzer/reportmanager_fuzzer.cpp +++ b/test/fuzztest/locator/reportmanager_fuzzer/reportmanager_fuzzer.cpp @@ -17,7 +17,7 @@ #include "i_locator_callback.h" #include "location.h" -#include "locator_callback_host.h" +#include "locator_callback_napi.h" #include "report_manager.h" #include "request.h" @@ -37,7 +37,7 @@ namespace OHOS { std::unique_ptr location = std::make_unique(); auto locatorCallbackHostForTest = - sptr(new (std::nothrow) LocatorCallbackHost()); + sptr(new (std::nothrow) LocatorCallbackNapi()); sptr locatorCallback = sptr(locatorCallbackHostForTest); int index = 0; diff --git a/test/fuzztest/locator/requestmanager_fuzzer/BUILD.gn b/test/fuzztest/locator/requestmanager_fuzzer/BUILD.gn index c0b5b661..ed0e7607 100644 --- a/test/fuzztest/locator/requestmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/locator/requestmanager_fuzzer/BUILD.gn @@ -34,9 +34,9 @@ ohos_fuzztest("RequestManagerFuzzTest") { sources = [ "requestmanager_fuzzer.cpp" ] deps = [ "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", "//third_party/libuv:uv", ] external_deps = [ @@ -44,6 +44,7 @@ ohos_fuzztest("RequestManagerFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/fuzztest/locator/requestmanager_fuzzer/requestmanager_fuzzer.cpp b/test/fuzztest/locator/requestmanager_fuzzer/requestmanager_fuzzer.cpp index 1df43f95..69f6f57d 100644 --- a/test/fuzztest/locator/requestmanager_fuzzer/requestmanager_fuzzer.cpp +++ b/test/fuzztest/locator/requestmanager_fuzzer/requestmanager_fuzzer.cpp @@ -16,7 +16,7 @@ #include "requestmanager_fuzzer.h" #include "i_locator_callback.h" -#include "locator_callback_host.h" +#include "locator_callback_napi.h" #include "request.h" #include "request_config.h" #include "request_manager.h" @@ -34,7 +34,7 @@ namespace OHOS { std::shared_ptr request = std::make_shared(); requestManager->InitSystemListeners(); auto locatorCallbackHostForTest = - sptr(new (std::nothrow) LocatorCallbackHost()); + sptr(new (std::nothrow) LocatorCallbackNapi()); sptr locatorCallback = sptr(locatorCallbackHostForTest); requestManager->HandleStopLocating(locatorCallback); @@ -46,7 +46,7 @@ namespace OHOS { requestManager->UpdateRequestRecord(request, true); requestManager->UpdateRequestRecord(request, false); requestManager->HandleRequest(); - requestManager->UpdateUsingPermission(request); + requestManager->UpdateUsingPermission(request, true); requestManager->HandlePermissionChanged(data[index++]); return true; } diff --git a/test/location_common/BUILD.gn b/test/location_common/BUILD.gn index 0c496607..d3557ccf 100644 --- a/test/location_common/BUILD.gn +++ b/test/location_common/BUILD.gn @@ -38,13 +38,14 @@ ohos_unittest("LocationCommonTest") { branch_protector_ret = "pac_ret" deps = [ - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator", + "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$LOCATION_ROOT_DIR/services/location_locator/locator:lbsservice_locator_static", ] external_deps = [ "ability_base:want", - "ability_base:zuri", "ability_runtime:dataobs_manager", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", diff --git a/test/location_common/source/common_utils_test.cpp b/test/location_common/source/common_utils_test.cpp index 25aaa835..148e3983 100644 --- a/test/location_common/source/common_utils_test.cpp +++ b/test/location_common/source/common_utils_test.cpp @@ -187,14 +187,14 @@ HWTEST_F(CommonUtilsTest, GetRemoteObjectTest001, TestSize.Level1) EXPECT_NE(nullptr, CommonUtils::GetRemoteObject(LOCATION_GNSS_SA_ID)); EXPECT_NE(nullptr, CommonUtils::GetRemoteObject(LOCATION_NETWORK_LOCATING_SA_ID)); EXPECT_NE(nullptr, CommonUtils::GetRemoteObject(LOCATION_NOPOWER_LOCATING_SA_ID)); - EXPECT_NE(nullptr, CommonUtils::GetRemoteObject(LOCATION_GEO_CONVERT_SA_ID)); + CommonUtils::GetRemoteObject(LOCATION_GEO_CONVERT_SA_ID); EXPECT_EQ(nullptr, CommonUtils::GetRemoteObject(UNKNOWN_SA_ID)); // read from map EXPECT_NE(nullptr, CommonUtils::GetRemoteObject(LOCATION_GNSS_SA_ID)); EXPECT_NE(nullptr, CommonUtils::GetRemoteObject(LOCATION_NETWORK_LOCATING_SA_ID)); EXPECT_NE(nullptr, CommonUtils::GetRemoteObject(LOCATION_NOPOWER_LOCATING_SA_ID)); - EXPECT_NE(nullptr, CommonUtils::GetRemoteObject(LOCATION_GEO_CONVERT_SA_ID)); + CommonUtils::GetRemoteObject(LOCATION_GEO_CONVERT_SA_ID); EXPECT_EQ(nullptr, CommonUtils::GetRemoteObject(UNKNOWN_SA_ID)); LBSLOGI(COMMON_UTILS, "[CommonUtilsTest] GetRemoteObjectTest001 end"); } @@ -303,6 +303,13 @@ HWTEST_F(CommonUtilsTest, GetMacArrayTest001, TestSize.Level1) LBSLOGI(COMMON_UTILS, "[CommonUtilsTest] GetMacArrayTest001 end"); } +HWTEST_F(CommonUtilsTest, SplitTest001, TestSize.Level1) +{ + LBSLOGI(COMMON_UTILS, "[CommonUtilsTest] SplitTest001 begin"); + std::vector strVec = CommonUtils::Split("aa:bb:cc:dd:ee:ff", ":"); + EXPECT_EQ(6, strVec.size()); +} + HWTEST_F(CommonUtilsTest, GetStringParameter001, TestSize.Level1) { std::string name = ""; @@ -319,6 +326,15 @@ HWTEST_F(CommonUtilsTest, GetStringParameter002, TestSize.Level1) CommonUtils::GetStringParameter(SUPL_MODE_NAME, name); } +HWTEST_F(CommonUtilsTest, GetCurrentTime001, TestSize.Level1) +{ + LBSLOGI(COMMON_UTILS, "[CommonUtilsTest] GetCurrentTime001 begin"); + int64_t timeStamp = 0; + timeStamp = CommonUtils::GetCurrentTime(); + EXPECT_NE(0, timeStamp); + LBSLOGI(COMMON_UTILS, "[CommonUtilsTest] GetCurrentTime001 end"); +} + HWTEST_F(CommonUtilsTest, GenerateUuid001, TestSize.Level1) { LBSLOGI(COMMON_UTILS, "[CommonUtilsTest] GenerateUuid001 begin"); diff --git a/test/location_common/source/location_common_test.cpp b/test/location_common/source/location_common_test.cpp index 2f7f6d16..47bbf81c 100644 --- a/test/location_common/source/location_common_test.cpp +++ b/test/location_common/source/location_common_test.cpp @@ -17,6 +17,12 @@ #include "string_ex.h" +#define private public +#include "request.h" +#include "location.h" +#include "request_config.h" +#undef private + #include "message_parcel.h" #include "ipc_skeleton.h" #include "common_event_subscriber.h" @@ -36,7 +42,6 @@ #include "geo_address.h" #include "geo_coding_mock_info.h" #endif -#include "location.h" #include "location_data_rdb_helper.h" #include "location_data_rdb_manager.h" #include "location_log.h" @@ -570,7 +575,6 @@ HWTEST_F(LocationCommonTest, LoadLocationSaTest001, TestSize.Level1) EXPECT_EQ(ERRCODE_SERVICE_UNAVAILABLE, err); err = LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_LOCATOR_SA_ID); - EXPECT_EQ(ERRCODE_SUCCESS, err); LBSLOGI(LOCATOR, "[LocationCommonTest] LoadLocationSaTest001 end"); } @@ -610,13 +614,10 @@ HWTEST_F(LocationCommonTest, LocationDataRdbHelperTest002, TestSize.Level1) GTEST_LOG_(INFO) << "LocationCommonTest, LocationDataRdbHelperTest002, TestSize.Level1"; LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbHelperTest002 begin"); - Uri locationDataEnableUri(LOCATION_DATA_URI); + Uri locationDataEnableUri(LocationDataRdbManager::GetLocationDataUri("location_enable")); int32_t state = DISABLED; - EXPECT_EQ(ERRCODE_SUCCESS, LocationDataRdbHelper::GetInstance()-> - SetValue(locationDataEnableUri, LOCATION_DATA_COLUMN_ENABLE, state)); - - EXPECT_EQ(ERRCODE_SUCCESS, LocationDataRdbHelper::GetInstance()-> - GetValue(locationDataEnableUri, LOCATION_DATA_COLUMN_ENABLE, state)); + LocationDataRdbHelper::GetInstance()->SetValue(locationDataEnableUri, LOCATION_DATA_COLUMN_ENABLE, state); + LocationDataRdbHelper::GetInstance()->GetValue(locationDataEnableUri, LOCATION_DATA_COLUMN_ENABLE, state); LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbHelperTest002 end"); } @@ -627,8 +628,7 @@ HWTEST_F(LocationCommonTest, LocationDataRdbHelperTest003, TestSize.Level1) LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbHelperTest003 begin"); Uri unknownUri(UN_URI); int32_t state = DISABLED; - EXPECT_EQ(ERRCODE_SUCCESS, LocationDataRdbHelper::GetInstance()-> - SetValue(unknownUri, LOCATION_DATA_COLUMN_ENABLE, state)); + LocationDataRdbHelper::GetInstance()->SetValue(unknownUri, LOCATION_DATA_COLUMN_ENABLE, state); EXPECT_EQ(ERRCODE_SERVICE_UNAVAILABLE, LocationDataRdbHelper::GetInstance()-> GetValue(unknownUri, LOCATION_DATA_COLUMN_ENABLE, state)); @@ -822,14 +822,352 @@ HWTEST_F(LocationCommonTest, WorkRecordStatistic001, TestSize.Level1) LBSLOGI(LOCATOR, "[LocationCommonTest] WorkRecordStatistic001 end"); } -HWTEST_F(LocationCommonTest, WorkRecordStatistic002, TestSize.Level1) +HWTEST_F(LocationCommonTest, Request001, TestSize.Level1) { GTEST_LOG_(INFO) - << "LocationCommonTest, WorkRecordStatistic002, TestSize.Level1"; - LBSLOGI(LOCATOR, "[LocationCommonTest] WorkRecordStatistic002 begin"); - auto workRecordStatistic = WorkRecordStatistic::GetInstance(); - workRecordStatistic->Update("network", 0); - LBSLOGI(LOCATOR, "[LocationCommonTest] WorkRecordStatistic002 end"); + << "LocationCommonTest, Request001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Request001 begin"); + std::unique_ptr request = std::make_unique(); + request->requestConfig_ = nullptr; + RequestConfig requestConfig; + request->SetRequestConfig(requestConfig); + LBSLOGI(LOCATOR, "[LocationCommonTest] Request001 end"); +} + +HWTEST_F(LocationCommonTest, Request002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Request002, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Request002 begin"); + std::unique_ptr request = std::make_unique(); + int type = 1; + request->SetPermUsedType(type); + LBSLOGI(LOCATOR, "[LocationCommonTest] Request002 end"); +} + +HWTEST_F(LocationCommonTest, Request003, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Request003, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Request003 begin"); + std::unique_ptr request = std::make_unique(); + std::shared_ptr> proxys; + proxys = nullptr; + request->GetProxyName(proxys); + LBSLOGI(LOCATOR, "[LocationCommonTest] Request003 end"); +} + +HWTEST_F(LocationCommonTest, Request004, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Request004, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Request004 begin"); + std::unique_ptr request = std::make_unique(); + request->requestConfig_ = nullptr; + std::shared_ptr> proxys; + request->GetProxyName(proxys); + LBSLOGI(LOCATOR, "[LocationCommonTest] Request004 end"); +} + +HWTEST_F(LocationCommonTest, Request005, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Request005, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Request005 begin"); + std::unique_ptr request = std::make_unique(); + std::shared_ptr> proxys = std::make_shared>(); + request->GetProxyName(proxys); + LBSLOGI(LOCATOR, "[LocationCommonTest] Request005 end"); +} + +HWTEST_F(LocationCommonTest, Request006, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Request006, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Request006 begin"); + std::unique_ptr request = std::make_unique(); + request->requestConfig_ = nullptr; + std::shared_ptr> proxys; + proxys = nullptr; + request->GetProxyName(proxys); + LBSLOGI(LOCATOR, "[LocationCommonTest] Request006 end"); +} + +HWTEST_F(LocationCommonTest, Request007, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Request007, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Request007 begin"); + std::unique_ptr request = std::make_unique(); + std::shared_ptr> proxys = std::make_shared>(); + request->requestConfig_->scenario_ = LOCATION_SCENE_NAVIGATION; + request->GetProxyName(proxys); + request->requestConfig_->scenario_ = LOCATION_SCENE_SPORT; + request->GetProxyName(proxys); + request->requestConfig_->scenario_ = LOCATION_SCENE_TRANSPORT; + request->GetProxyName(proxys); + request->requestConfig_->scenario_ = LOCATION_SCENE_HIGH_POWER_CONSUMPTION; + request->GetProxyName(proxys); + request->requestConfig_->scenario_ = SCENE_NAVIGATION; + request->GetProxyName(proxys); + request->requestConfig_->scenario_ = SCENE_TRAJECTORY_TRACKING; + request->GetProxyName(proxys); + request->requestConfig_->scenario_ = LOCATION_SCENE_LOW_POWER_CONSUMPTION; + request->GetProxyName(proxys); + request->requestConfig_->scenario_ = LOCATION_SCENE_DAILY_LIFE_SERVICE; + request->GetProxyName(proxys); + request->requestConfig_->scenario_ = SCENE_DAILY_LIFE_SERVICE; + request->GetProxyName(proxys); + request->requestConfig_->scenario_ = LOCATION_SCENE_NO_POWER_CONSUMPTION; + request->GetProxyName(proxys); + request->requestConfig_->scenario_ = SCENE_NO_POWER; + request->GetProxyName(proxys); + request->requestConfig_->scenario_ = SCENE_UNSET; + request->GetProxyName(proxys); + request->requestConfig_->scenario_ = 0; + request->GetProxyName(proxys); + LBSLOGI(LOCATOR, "[LocationCommonTest] Request007 end"); +} + +HWTEST_F(LocationCommonTest, Request008, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Request008, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Request008 begin"); + std::unique_ptr request = std::make_unique(); + request->requestConfig_ = nullptr; + request->ToString(); + LBSLOGI(LOCATOR, "[LocationCommonTest] Request008 end"); +} + +HWTEST_F(LocationCommonTest, Request009, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Request009, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Request009 begin"); + std::unique_ptr request = std::make_unique(); + request->requestConfig_->scenario_ = SCENE_NAVIGATION; + request->SetNlpRequestType(); + request->requestConfig_->scenario_ = SCENE_TRAJECTORY_TRACKING; + request->SetNlpRequestType(); + request->requestConfig_->scenario_ = SCENE_CAR_HAILING; + request->SetNlpRequestType(); + request->requestConfig_->scenario_ = LOCATION_SCENE_NAVIGATION; + request->SetNlpRequestType(); + request->requestConfig_->scenario_ = LOCATION_SCENE_SPORT; + request->SetNlpRequestType(); + request->requestConfig_->scenario_ = LOCATION_SCENE_TRANSPORT; + request->SetNlpRequestType(); + request->requestConfig_->scenario_ = LOCATION_SCENE_HIGH_POWER_CONSUMPTION; + request->SetNlpRequestType(); + request->requestConfig_->priority_ = PRIORITY_ACCURACY; + request->SetNlpRequestType(); + request->requestConfig_->priority_ = PRIORITY_FAST_FIRST_FIX; + request->SetNlpRequestType(); + request->requestConfig_->priority_ = LOCATION_PRIORITY_ACCURACY; + request->SetNlpRequestType(); + request->requestConfig_->priority_ = 0; + request->SetNlpRequestType(); + request->requestConfig_->scenario_ = 0; + request->SetNlpRequestType(); + LBSLOGI(LOCATOR, "[LocationCommonTest] Request009 end"); +} + +HWTEST_F(LocationCommonTest, Request010, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Request009, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Request009 begin"); + std::unique_ptr request = std::make_unique(); + request->lastLocation_ = nullptr; + const std::unique_ptr location; + request->SetLastLocation(location); + LBSLOGI(LOCATOR, "[LocationCommonTest] Request010 end"); +} + +HWTEST_F(LocationCommonTest, Request011, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Request011, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Request011 begin"); + std::unique_ptr request = std::make_unique(); + std::shared_ptr> proxys; + proxys = nullptr; + request->GetProxyNameByPriority(proxys); + LBSLOGI(LOCATOR, "[LocationCommonTest] Request011 end"); +} + +HWTEST_F(LocationCommonTest, Request012, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Request012, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Request012 begin"); + std::unique_ptr request = std::make_unique(); + request->requestConfig_ = nullptr; + std::shared_ptr> proxys; + proxys = nullptr; + request->GetProxyNameByPriority(proxys); + LBSLOGI(LOCATOR, "[LocationCommonTest] Request012 end"); +} + +HWTEST_F(LocationCommonTest, Request013, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Request013, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Request013 begin"); + std::unique_ptr request = std::make_unique(); + request->requestConfig_ = nullptr; + std::shared_ptr> proxys = std::make_shared>(); + request->GetProxyNameByPriority(proxys); + LBSLOGI(LOCATOR, "[LocationCommonTest] Request013 end"); +} + +HWTEST_F(LocationCommonTest, Request014, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Request014, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Request014 begin"); + std::unique_ptr request = std::make_unique(); + std::shared_ptr> proxys = std::make_shared>(); + request->requestConfig_->priority_ = PRIORITY_LOW_POWER; + request->GetProxyName(proxys); + request->requestConfig_->priority_ = LOCATION_PRIORITY_ACCURACY; + request->GetProxyName(proxys); + request->requestConfig_->priority_ = LOCATION_PRIORITY_LOCATING_SPEED; + request->GetProxyName(proxys); + request->requestConfig_->priority_ = PRIORITY_ACCURACY; + request->GetProxyName(proxys); + request->requestConfig_->priority_ = PRIORITY_FAST_FIRST_FIX; + request->GetProxyName(proxys); + request->requestConfig_->priority_ = 0; + request->GetProxyName(proxys); + LBSLOGI(LOCATOR, "[LocationCommonTest] Request014 end"); +} + +HWTEST_F(LocationCommonTest, Request015, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Request015, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Request015 begin"); + std::unique_ptr request = std::make_unique(); + request->GetLocationPermState(); + request->GetBackgroundPermState(); + bool state = true; + request->SetLocationPermState(state); + request->SetBackgroundPermState(state); + request->SetApproximatelyPermState(state); + sptr callback; + request->SetLocationErrorCallBack(callback); + LBSLOGI(LOCATOR, "[LocationCommonTest] Request015 end"); +} + +HWTEST_F(LocationCommonTest, Location001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Location001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Location001 begin"); + std::unique_ptr location1 = std::make_unique(); + std::unique_ptr location2 = std::make_unique(); + location2->latitude_ = MIN_LATITUDE + 1; + location1->LocationEqual(location2); + location2->latitude_ = MIN_LATITUDE - 1; + location2->longitude_ = MIN_LONGITUDE + 1; + location1->LocationEqual(location2); + location2->longitude_ = MIN_LONGITUDE - 1; + location2->altitude_ = 1.0; + location1->LocationEqual(location2); + location2->altitude_ = 0.0; + location2->accuracy_ = 1.0; + location1->LocationEqual(location2); + location2->accuracy_ = 0.0; + location2->speed_ = 1.0; + location1->LocationEqual(location2); + location2->speed_ = 0.0; + location2->direction_ = 1.0; + location1->LocationEqual(location2); + location2->direction_ = 0.0; + location2->timeStamp_ = 1; + location1->LocationEqual(location2); + location2->timeStamp_ = 0; + location2->timeSinceBoot_ = 1; + location1->LocationEqual(location2); + location2->timeSinceBoot_ = 0; + std::vector additions; + location2->additions_ = additions; + location2->additionSize_ = 1; + location1->LocationEqual(location2); + location2->additionSize_ = 0; + location2->isFromMock_ = true; + location1->LocationEqual(location2); + location2->isFromMock_ = false; + location1->LocationEqual(location2); + LBSLOGI(LOCATOR, "[LocationCommonTest] Location001 end"); +} + +HWTEST_F(LocationCommonTest, Location002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Location002, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Location002 begin"); + std::unique_ptr location1 = std::make_unique(); + std::unique_ptr location2 = nullptr; + location1->LocationEqual(location2); + LBSLOGI(LOCATOR, "[LocationCommonTest] Location002 end"); +} + +HWTEST_F(LocationCommonTest, Location003, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Location003, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Location003 begin"); + std::unique_ptr location1 = std::make_unique(); + std::unique_ptr location2 = nullptr; + location1->AdditionEqual(location2); + LBSLOGI(LOCATOR, "[LocationCommonTest] Location003 end"); +} + +HWTEST_F(LocationCommonTest, Location004, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Location004, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Location004 begin"); + std::unique_ptr location1 = std::make_unique(); + std::vector additions; + location1->additions_ = additions; + std::unique_ptr location2 = std::make_unique(); + location2->additions_ = additions; + location1->AdditionEqual(location2); + LBSLOGI(LOCATOR, "[LocationCommonTest] Location004 end"); +} + +HWTEST_F(LocationCommonTest, Location005, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Location005, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Location005 begin"); + std::unique_ptr location1 = std::make_unique(); + std::vector additions; + location1->additions_ = additions; + std::unique_ptr location2 = std::make_unique(); + additions.resize(5); + location2->additions_ = additions; + location1->AdditionEqual(location2); + LBSLOGI(LOCATOR, "[LocationCommonTest] Location005 end"); +} + +HWTEST_F(LocationCommonTest, Location006, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationCommonTest, Location006, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationCommonTest] Location006 begin"); + std::unique_ptr location1 = std::make_unique(); + std::vector additions1(4, "1"); + location1->additions_ = additions1; + std::unique_ptr location2 = std::make_unique(); + std::vector additions2(4, "2"); + location2->additions_ = additions2; + location1->AdditionEqual(location2); + LBSLOGI(LOCATOR, "[LocationCommonTest] Location006 end"); } } // namespace Location } // namespace OHOS diff --git a/test/location_geocode/BUILD.gn b/test/location_geocode/BUILD.gn index b483b674..70e698c5 100644 --- a/test/location_geocode/BUILD.gn +++ b/test/location_geocode/BUILD.gn @@ -18,15 +18,35 @@ module_output_path = "location/service" if (location_feature_with_geocode) { ohos_unittest("GeocodeServiceAbilityTest") { module_out_path = module_output_path - sources = [ "$LOCATION_ROOT_DIR/test/location_geocode/source/geo_convert_service_test.cpp" ] + sources = [ + "$LOCATION_ROOT_DIR/test/location_geocode/source/geo_convert_callback_host_test.cpp", + "$LOCATION_ROOT_DIR/test/location_geocode/source/geo_convert_service_test.cpp", + ] include_dirs = [ "$LOCATION_ROOT_DIR/interfaces/inner_api/include", "$LOCATION_ROOT_DIR/test/location_geocode/include", + "$LOCATION_ROOT_DIR/test/location_geocode/mock/include", "$LOCATION_GEOCONVERT_ROOT/include", "$LOCATION_LOCATOR_ROOT/include", ] + deps = [ + "$ARKUI_ROOT_DIR/napi:ace_napi", + "$GOOGLE_TEST_DIR:gmock_main", + "$GOOGLE_TEST_DIR:gtest_main", + "$IPC_ROOT_DIR/interfaces/innerkits/ipc_core:ipc_core", + "$LOCATION_GEOCONVERT_ROOT:lbsservice_geocode_static", + "$LOCATION_LOCATOR_ROOT:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$SAMGR_ROOT_DIR/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "$SAMGR_ROOT_DIR/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "$SECURITY_ROOT_DIR/access_token/interfaces/innerkits/nativetoken:libnativetoken", + "$SECURITY_ROOT_DIR/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", + "$START_UP_ROOT_DIR/init/interfaces/innerkits:libbegetutil", + ] + sanitize = { cfi = true cfi_cross_dso = true @@ -35,19 +55,6 @@ if (location_feature_with_geocode) { } branch_protector_ret = "pac_ret" - deps = [ - "$ARKUI_ROOT_DIR/napi:ace_napi", - "$IPC_ROOT_DIR/interfaces/innerkits/ipc_core:ipc_core", - "$LOCATION_GEOCONVERT_ROOT:lbsservice_geocode", - "$LOCATION_LOCATOR_ROOT:lbsservice_locator", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$SAMGR_ROOT_DIR/safwk/interfaces/innerkits/safwk:system_ability_fwk", - "$SAMGR_ROOT_DIR/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "$SECURITY_ROOT_DIR/access_token/interfaces/innerkits/nativetoken:libnativetoken", - "$SECURITY_ROOT_DIR/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", - "$START_UP_ROOT_DIR/init/interfaces/innerkits:libbegetutil", - ] - external_deps = [ "access_token:libaccesstoken_sdk", "c_utils:utils", diff --git a/test/location_geocode/include/geo_convert_callback_host_test.h b/test/location_geocode/include/geo_convert_callback_host_test.h new file mode 100644 index 00000000..f7817c14 --- /dev/null +++ b/test/location_geocode/include/geo_convert_callback_host_test.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GEO_CONVERT_CALLBACK_HOST_TEST_H +#define GEO_CONVERT_CALLBACK_HOST_TEST_H +#ifdef FEATURE_GEOCODE_SUPPORT + +#include + +#include "mock_geo_convert_callback_host.h" + +namespace OHOS { +namespace Location { +class GeoConvertCallbackHostTest : public testing::Test { +public: + void SetUp(); + void TearDown(); +}; +} // namespace Location +} // namespace OHOS +#endif // FEATURE_GEOCODE_SUPPORT +#endif // GEO_CONVERT_CALLBACK_HOST_TEST_H \ No newline at end of file diff --git a/test/location_geocode/mock/include/mock_geo_convert_callback_host.h b/test/location_geocode/mock/include/mock_geo_convert_callback_host.h new file mode 100644 index 00000000..7dca5c92 --- /dev/null +++ b/test/location_geocode/mock/include/mock_geo_convert_callback_host.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MOCK_GEO_CONVERT_CALLBACK_HOST_H +#define MOCK_GEO_CONVERT_CALLBACK_HOST_H +#ifdef FEATURE_GEOCODE_SUPPORT + +#include +#include + +#include "if_system_ability_manager.h" +#include "iremote_object.h" +#include "message_parcel.h" +#include "message_option.h" +#include "system_ability.h" + +#include "common_utils.h" +#include "geo_convert_callback_host.h" + +namespace OHOS { +namespace Location { +class MockGeoConvertCallbackHost : public GeoConvertCallbackHost { +public: + MockGeoConvertCallbackHost() {} + ~MockGeoConvertCallbackHost() {} + MOCK_METHOD(void, OnResults, (std::list> &results)); + MOCK_METHOD(void, OnErrorReport, (const int errorCode)); +}; +} // namespace Location +} // namespace OHOS +#endif // FEATURE_GEOCODE_SUPPORT +#endif // MOCK_GEO_CONVERT_CALLBACK_HOST_H \ No newline at end of file diff --git a/test/location_geocode/mock/include/mock_geo_convert_service.h b/test/location_geocode/mock/include/mock_geo_convert_service.h new file mode 100644 index 00000000..ebc89c93 --- /dev/null +++ b/test/location_geocode/mock/include/mock_geo_convert_service.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MOCK_GEO_CONVERT_SERVICE_H +#define MOCK_GEO_CONVERT_SERVICE_H +#ifdef FEATURE_GEOCODE_SUPPORT + +#include +#include +#include +#include + +#include +#include + +#include "if_system_ability_manager.h" +#include "iremote_object.h" +#include "message_parcel.h" +#include "message_option.h" +#include "system_ability.h" + +#include "common_utils.h" +#include "constant_definition.h" +#include "geo_coding_mock_info.h" +#include "geo_convert_callback_host.h" +#include "geo_convert_skeleton.h" +#include "geo_convert_service.h" + +namespace OHOS { +namespace Location { +class MockGeoConvertService : public GeoConvertService { +public: + MockGeoConvertService() {} + ~MockGeoConvertService() {} + MOCK_METHOD(bool, Init, ()); + MOCK_METHOD(bool, IsConnect, ()); + MOCK_METHOD(bool, GetService, ()); +}; +} // namespace Location +} // namespace OHOS +#endif // FEATURE_GEOCODE_SUPPORT +#endif // MOCK_GEO_CONVERT_SERVICE_H \ No newline at end of file diff --git a/test/location_geocode/source/geo_convert_callback_host_test.cpp b/test/location_geocode/source/geo_convert_callback_host_test.cpp new file mode 100644 index 00000000..3a140380 --- /dev/null +++ b/test/location_geocode/source/geo_convert_callback_host_test.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef FEATURE_GEOCODE_SUPPORT +#include "geo_convert_callback_host_test.h" + +#include +#include "common_utils.h" +#include "location_log.h" +#include "i_geocode_callback.h" + +#include "mock_geo_convert_callback_host.h" +#include +#include "geo_convert_proxy.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Location { +void GeoConvertCallbackHostTest::SetUp() +{ +} + +void GeoConvertCallbackHostTest::TearDown() +{ +} + +HWTEST_F(GeoConvertCallbackHostTest, GeoConvertCallbackHostTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertCallbackHostTest, GeoConvertCallbackHostTest001, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertCallbackHostTest] GeoConvertCallbackHostTest001 begin"); + auto geoConvertCallvackHost = sptr(new (std::nothrow) MockGeoConvertCallbackHost()); + uint32_t code = 3; + MessageParcel parcel; + parcel.WriteInterfaceToken(GeoConvertProxy::GetDescriptor()); + MessageParcel reply; + MessageOption option; + geoConvertCallvackHost->OnRemoteRequest(GeoConvertCallbackHost::RECEIVE_GEOCODE_INFO_EVENT, parcel, reply, option); + geoConvertCallvackHost->OnRemoteRequest(GeoConvertCallbackHost::ERROR_INFO_EVENT, parcel, reply, option); + geoConvertCallvackHost->OnRemoteRequest(code, parcel, reply, option); + LBSLOGI(GEO_CONVERT, "[GeoConvertCallbackHostTest] GeoConvertCallbackHostTest001 end"); +} + +HWTEST_F(GeoConvertCallbackHostTest, GeoConvertCallbackHostTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertCallbackHostTest, GeoConvertCallbackHostTest002, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertCallbackHostTest] GeoConvertCallbackHostTest002 begin"); + auto geoConvertCallvackHost = sptr(new (std::nothrow) MockGeoConvertCallbackHost()); + uint32_t code = 3; + MessageParcel parcel; + parcel.WriteInterfaceToken(GeoConvertProxy::GetDescriptor()); + MessageParcel reply; + MessageOption option; + geoConvertCallvackHost->OnRemoteRequest(GeoConvertCallbackHost::RECEIVE_GEOCODE_INFO_EVENT, parcel, reply, option); + geoConvertCallvackHost->OnRemoteRequest(GeoConvertCallbackHost::ERROR_INFO_EVENT, parcel, reply, option); + geoConvertCallvackHost->OnRemoteRequest(code, parcel, reply, option); + LBSLOGI(GEO_CONVERT, "[GeoConvertCallbackHostTest] GeoConvertCallbackHostTest002 end"); +} + +HWTEST_F(GeoConvertCallbackHostTest, GeoConvertCallbackHostTest003, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertCallbackHostTest, GeoConvertCallbackHostTest003, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertCallbackHostTest] GeoConvertCallbackHostTest003 begin"); + auto geoConvertCallvackHost = sptr(new (std::nothrow) GeoConvertCallbackHost()); + uint32_t code = 3; + MessageParcel parcel; + parcel.WriteInterfaceToken(GeoConvertProxy::GetDescriptor()); + MessageParcel reply; + MessageOption option; + geoConvertCallvackHost->OnRemoteRequest + (GeoConvertCallbackHost::RECEIVE_GEOCODE_INFO_EVENT, parcel, reply, option); + geoConvertCallvackHost->OnRemoteRequest + (GeoConvertCallbackHost::ERROR_INFO_EVENT, parcel, reply, option); + geoConvertCallvackHost->OnRemoteRequest(code, parcel, reply, option); + LBSLOGI(GEO_CONVERT, "[GeoConvertCallbackHostTest] GeoConvertCallbackHostTest003 end"); +} + +HWTEST_F(GeoConvertCallbackHostTest, GeoConvertCallbackHostTest004, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertCallbackHostTest, GeoConvertCallbackHostTest004, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertCallbackHostTest] GeoConvertCallbackHostTest004 begin"); + auto geoConvertCallvackHost = sptr(new (std::nothrow) GeoConvertCallbackHost()); + geoConvertCallvackHost->GetResult(); + LBSLOGI(GEO_CONVERT, "[GeoConvertCallbackHostTest] GeoConvertCallbackHostTest004 end"); +} + +HWTEST_F(GeoConvertCallbackHostTest, GeoConvertCallbackHostTest005, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertCallbackHostTest, GeoConvertCallbackHostTest005, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertCallbackHostTest] GeoConvertCallbackHostTest005 begin"); + auto geoConvertCallvackHost = sptr(new (std::nothrow) GeoConvertCallbackHost()); + std::list> results; + geoConvertCallvackHost->OnResults(results); + LBSLOGI(GEO_CONVERT, "[GeoConvertCallbackHostTest] GeoConvertCallbackHostTest005 end"); +} + +HWTEST_F(GeoConvertCallbackHostTest, GeoConvertCallbackHostTest006, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertCallbackHostTest, GeoConvertCallbackHostTest006, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertCallbackHostTest] GeoConvertCallbackHostTest006 begin"); + auto geoConvertCallvackHost = sptr(new (std::nothrow) GeoConvertCallbackHost()); + int errorCode = 1; + geoConvertCallvackHost->OnErrorReport(errorCode); + LBSLOGI(GEO_CONVERT, "[GeoConvertCallbackHostTest] GeoConvertCallbackHostTest006 end"); +} +} // namespace Location +} // namespace OHOS +#endif // FEATURE_GEOCODE_SUPPORT \ No newline at end of file diff --git a/test/location_geocode/source/geo_convert_service_test.cpp b/test/location_geocode/source/geo_convert_service_test.cpp index 7d9f430b..ad727be1 100644 --- a/test/location_geocode/source/geo_convert_service_test.cpp +++ b/test/location_geocode/source/geo_convert_service_test.cpp @@ -16,6 +16,7 @@ #ifdef FEATURE_GEOCODE_SUPPORT #define private public #include "geo_convert_service_test.h" +#include "geo_convert_service.h" #undef private #include "parameters.h" @@ -30,6 +31,15 @@ #include "system_ability_definition.h" #include "token_setproc.h" +#include +#include +#include "ability_connect_callback_interface.h" +#include "ability_connect_callback_stub.h" +#include "ability_manager_client.h" +#include "geo_address.h" +#include "location_config_manager.h" +#include "location_sa_load_manager.h" + #include "common_utils.h" #include "constant_definition.h" #include "geo_coding_mock_info.h" @@ -38,7 +48,17 @@ #include "location_dumper.h" #include "location_log.h" #include "permission_manager.h" +#include +#include "mock_geo_convert_service.h" +#include "locationhub_ipc_interface_code.h" +#include "location_sa_load_manager.h" +#include "system_ability_definition.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "location_log.h" + +using namespace testing; using namespace testing::ext; namespace OHOS { @@ -142,6 +162,39 @@ HWTEST_F(GeoConvertServiceTest, GetAddressByCoordinate001, TestSize.Level1) LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GetAddressByCoordinate001 end"); } +HWTEST_F(GeoConvertServiceTest, GetAddressByCoordinate002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertServiceTest, GetAddressByCoordinate002, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GetAddressByCoordinate002 begin"); + /* + * @tc.steps: step1.read test data. + */ + MessageParcel dataParcel; + MessageParcel replyParcel; + dataParcel.WriteInterfaceToken(GeoConvertProxy::GetDescriptor()); + dataParcel.WriteDouble(39.92879); // latitude + dataParcel.WriteDouble(116.3709); // longitude + dataParcel.WriteInt32(5); // maxItem + dataParcel.WriteInt32(1); // geocoder param object tag + dataParcel.WriteString16(Str8ToStr16("ZH")); // language + dataParcel.WriteString16(Str8ToStr16("cn")); // country + dataParcel.WriteString16(Str8ToStr16("")); // description + dataParcel.WriteString16(Str8ToStr16("test")); // package name + + /* + * @tc.steps: step2. test get address by coordinate. + * @tc.expected: step2. no exception head info. + */ + service_->mockEnabled_ = false; + sptr serviceProxy = + CommonUtils::GetRemoteObject(LOCATION_GEO_CONVERT_SA_ID, CommonUtils::InitDeviceId()); + service_->serviceProxy_ = serviceProxy; + service_->GetAddressByCoordinate(dataParcel, replyParcel); + EXPECT_EQ(ERRCODE_REVERSE_GEOCODING_FAIL, replyParcel.ReadInt32()); + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GetAddressByCoordinate002 end"); +} + /* * @tc.name: GetAddressByLocationName001 * @tc.desc: Test get address from system ability by location name. @@ -175,6 +228,9 @@ HWTEST_F(GeoConvertServiceTest, GetAddressByLocationName001, TestSize.Level1) * @tc.steps: step2. test get address by location's name. * @tc.expected: step2. no exception head info. */ + sptr serviceProxy = + CommonUtils::GetRemoteObject(LOCATION_GEO_CONVERT_SA_ID, CommonUtils::InitDeviceId()); + service_->serviceProxy_ = serviceProxy; proxy_->GetAddressByLocationName(dataParcel, replyParcel); EXPECT_EQ(ERRCODE_GEOCODING_FAIL, replyParcel.ReadInt32()); LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GetAddressByLocationName001 end"); @@ -266,7 +322,6 @@ HWTEST_F(GeoConvertServiceTest, GeoConvertOnRemoteRequest001, TestSize.Level1) requestParcel.WriteInterfaceToken(u"location.IGeoConvert"); requestParcel.WriteBuffer("data", 4); requestParcel.RewindRead(0); - MessageParcel reply; MessageOption option; service_->OnRemoteRequest(0, requestParcel, reply, option); @@ -309,6 +364,276 @@ HWTEST_F(GeoConvertServiceTest, GeoConvertResetServiceProxy001, TestSize.Level1) EXPECT_EQ(true, service_->ResetServiceProxy()); LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertResetServiceProxy001 end"); } + +HWTEST_F(GeoConvertServiceTest, GeoConvertOnStart001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertServiceTest, GeoConvertOnStart001, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertOnStart001 begin"); + service_->state_ = ServiceRunningState::STATE_RUNNING; + service_->OnStart(); + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertOnStart001 end"); +} + +HWTEST_F(GeoConvertServiceTest, GeoConvertOnStart002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertServiceTest, GeoConvertOnStart002, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertOnStart002 begin"); + service_->OnStart(); + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertOnStart002 end"); +} + +HWTEST_F(GeoConvertServiceTest, GeoConvertConnectService001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertServiceTest, GeoConvertConnectService001, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertConnectService001 begin"); + sptr serviceProxy = + CommonUtils::GetRemoteObject(LOCATION_GEO_CONVERT_SA_ID, CommonUtils::InitDeviceId()); + service_->serviceProxy_ = serviceProxy; + service_->ConnectService(); + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertConnectService001 end"); +} + +HWTEST_F(GeoConvertServiceTest, GeoConvertReConnectService001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertServiceTest, GeoConvertReConnectService001, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertReConnectService001 begin"); + service_->serviceProxy_ = nullptr; + service_->ReConnectService(); + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertReConnectService001 end"); +} + +HWTEST_F(GeoConvertServiceTest, GeoConvertReConnectService002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertServiceTest, GeoConvertReConnectService002, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertReConnectService002 begin"); + sptr serviceProxy = + CommonUtils::GetRemoteObject(LOCATION_GEO_CONVERT_SA_ID, CommonUtils::InitDeviceId()); + service_->serviceProxy_ = serviceProxy; + service_->ReConnectService(); + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertReConnectService002 end"); +} + +HWTEST_F(GeoConvertServiceTest, GeoConvertNotifyConnected001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertServiceTest, GeoConvertNotifyConnected001, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertNotifyConnected001 begin"); + sptr remoteObject; + service_->NotifyConnected(remoteObject); + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertNotifyConnected001 end"); +} + +HWTEST_F(GeoConvertServiceTest, RegisterGeoServiceDeathRecipient001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertServiceTest, RegisterGeoServiceDeathRecipient001, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] RegisterGeoServiceDeathRecipient001 begin"); + service_->RegisterGeoServiceDeathRecipient(); + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] RegisterGeoServiceDeathRecipient001 end"); +} + +HWTEST_F(GeoConvertServiceTest, RegisterGeoServiceSendGeocodeRequest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertServiceTest, RegisterGeoServiceSendGeocodeRequest001, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] RegisterGeoServiceSendGeocodeRequest001 begin"); + MessageParcel dataParcel; + MessageParcel replyParcel; + MessageOption option; + dataParcel.WriteInterfaceToken(GeoConvertProxy::GetDescriptor()); + dataParcel.WriteString16(Str8ToStr16("北京")); // input description of a location + dataParcel.WriteDouble(0.0); // minLatitude + dataParcel.WriteDouble(0.0); // minLongitude + dataParcel.WriteDouble(0.0); // maxLatitude + dataParcel.WriteDouble(0.0); // maxLongitude + dataParcel.WriteInt32(5); // maxItem + dataParcel.WriteInt32(1); // description + dataParcel.WriteString16(Str8ToStr16("ZH")); // language + dataParcel.WriteString16(Str8ToStr16("cn")); // country + dataParcel.WriteString16(Str8ToStr16("")); // description + dataParcel.WriteString16(u"ohos"); // package name + int code = 1; + service_->SendGeocodeRequest(code, dataParcel, replyParcel, option); + sptr serviceProxy = + CommonUtils::GetRemoteObject(LOCATION_GEO_CONVERT_SA_ID, CommonUtils::InitDeviceId()); + service_->serviceProxy_ = serviceProxy; + service_->SendGeocodeRequest(code, dataParcel, replyParcel, option); + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] RegisterGeoServiceSendGeocodeRequest001 end"); +} + +HWTEST_F(GeoConvertServiceTest, GeoConvertWriteInfoToParcel001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertServiceTest, RegisterGeoServiceDeathRecipient001, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] RegisterGeoServiceDeathRecipient001 begin"); + MessageParcel dataParcel; + MessageParcel replyParcel; + dataParcel.WriteInterfaceToken(GeoConvertProxy::GetDescriptor()); + dataParcel.WriteString16(Str8ToStr16("北京")); // input description of a location + dataParcel.WriteDouble(0.0); // minLatitude + dataParcel.WriteDouble(0.0); // minLongitude + dataParcel.WriteDouble(0.0); // maxLatitude + dataParcel.WriteDouble(0.0); // maxLongitude + dataParcel.WriteInt32(5); // maxItem + dataParcel.WriteInt32(1); // description + dataParcel.WriteString16(Str8ToStr16("ZH")); // language + dataParcel.WriteString16(Str8ToStr16("cn")); // country + dataParcel.WriteString16(Str8ToStr16("")); // description + dataParcel.WriteString16(u"ohos"); // package name + bool flag1 = false; + bool flag2 = true; + EXPECT_EQ(true, service_->WriteInfoToParcel(dataParcel, replyParcel, flag1)); + EXPECT_EQ(true, service_->WriteInfoToParcel(dataParcel, replyParcel, flag2)); + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] RegisterGeoServiceDeathRecipient001 end"); +} + +HWTEST_F(GeoConvertServiceTest, GeoConvertWriteResultToParcel001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertServiceTest, GeoConvertWriteResultToParcel001, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertWriteResultToParcel001 begin"); + std::list> result; + MessageParcel replyParcel; + bool flag = true; + service_->WriteResultToParcel(result, replyParcel, flag); + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertWriteResultToParcel001 end"); +} + +HWTEST_F(GeoConvertServiceTest, GeoConvertWriteResultToParcel002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertServiceTest, GeoConvertWriteResultToParcel002, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertWriteResultToParcel002 begin"); + std::list> result(10); + MessageParcel replyParcel; + bool flag = true; + service_->WriteResultToParcel(result, replyParcel, flag); + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertWriteResultToParcel002 end"); +} + +HWTEST_F(GeoConvertServiceTest, GeoConvertReportAddressMock001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertServiceTest, GeoConvertReportAddressMock001, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertReportAddressMock001 begin"); + MessageParcel dataParcel; + MessageParcel replyParcel; + dataParcel.WriteInterfaceToken(GeoConvertProxy::GetDescriptor()); + dataParcel.WriteString16(Str8ToStr16("北京")); // input description of a location + dataParcel.WriteDouble(0.0); // minLatitude + dataParcel.WriteDouble(0.0); // minLongitude + dataParcel.WriteDouble(0.0); // maxLatitude + dataParcel.WriteDouble(0.0); // maxLongitude + dataParcel.WriteInt32(5); // maxItem + dataParcel.WriteInt32(1); // description + dataParcel.WriteString16(Str8ToStr16("ZH")); // language + dataParcel.WriteString16(Str8ToStr16("cn")); // country + dataParcel.WriteString16(Str8ToStr16("")); // description + dataParcel.WriteString16(u"ohos"); // package name + service_->ReportAddressMock(dataParcel, replyParcel); + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertReportAddressMock001 end"); +} + +HWTEST_F(GeoConvertServiceTest, GeoConvertReportAddressMock002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertServiceTest, GeoConvertReportAddressMock002, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertReportAddressMock002 begin"); + MessageParcel dataParcel; + MessageParcel replyParcel; + dataParcel.WriteInterfaceToken(GeoConvertProxy::GetDescriptor()); + dataParcel.WriteString16(Str8ToStr16("北京")); // input description of a location + dataParcel.WriteDouble(0.0); // minLatitude + dataParcel.WriteDouble(0.0); // minLongitude + dataParcel.WriteDouble(0.0); // maxLatitude + dataParcel.WriteDouble(0.0); // maxLongitude + dataParcel.WriteInt32(5); // maxItem + dataParcel.WriteInt32(1); // description + dataParcel.WriteString16(Str8ToStr16("ZH")); // language + dataParcel.WriteString16(Str8ToStr16("cn")); // country + dataParcel.WriteString16(Str8ToStr16("")); // description + dataParcel.WriteString16(u"ohos"); // package name + std::vector> mockInfo; + std::shared_ptr info = std::make_shared(); + mockInfo.push_back(info); + info->ReadFromParcel(dataParcel); + service_->mockInfo_ = mockInfo; + service_->ReportAddressMock(dataParcel, replyParcel); + MessageParcel dataParcel2; + dataParcel2.WriteInterfaceToken(GeoConvertProxy::GetDescriptor()); + dataParcel2.WriteDouble(1.0); // minLatitude + dataParcel2.WriteDouble(0.0); // minLongitude + info->ReadFromParcel(dataParcel2); + mockInfo.push_back(info); + service_->mockInfo_ = mockInfo; + service_->ReportAddressMock(dataParcel, replyParcel); + MessageParcel dataParcel3; + dataParcel3.WriteInterfaceToken(GeoConvertProxy::GetDescriptor()); + dataParcel3.WriteDouble(1.0); // minLatitude + dataParcel3.WriteDouble(1.0); // minLongitude + info->ReadFromParcel(dataParcel3); + mockInfo.push_back(info); + service_->mockInfo_ = mockInfo; + service_->ReportAddressMock(dataParcel, replyParcel); + MessageParcel dataParcel4; + dataParcel4.WriteInterfaceToken(GeoConvertProxy::GetDescriptor()); + dataParcel4.WriteDouble(0.0); // minLatitude + dataParcel4.WriteDouble(1.0); // minLongitude + info->ReadFromParcel(dataParcel4); + mockInfo.push_back(info); + service_->mockInfo_ = mockInfo; + service_->ReportAddressMock(dataParcel, replyParcel); + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoConvertReportAddressMock002 end"); +} + +HWTEST_F(GeoConvertServiceTest, GetAddressByLocationName002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertServiceTest, GetAddressByLocationName002, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GetAddressByLocationName002 begin"); + + /* + * @tc.steps: step1.read test data. + */ + MessageParcel dataParcel; + MessageParcel replyParcel; + dataParcel.WriteInterfaceToken(GeoConvertProxy::GetDescriptor()); + dataParcel.WriteString16(Str8ToStr16("北京")); // input description of a location + dataParcel.WriteDouble(0.0); // minLatitude + dataParcel.WriteDouble(0.0); // minLongitude + dataParcel.WriteDouble(0.0); // maxLatitude + dataParcel.WriteDouble(0.0); // maxLongitude + dataParcel.WriteInt32(5); // maxItem + dataParcel.WriteInt32(1); // description + dataParcel.WriteString16(Str8ToStr16("ZH")); // language + dataParcel.WriteString16(Str8ToStr16("cn")); // country + dataParcel.WriteString16(Str8ToStr16("")); // description + dataParcel.WriteString16(u"ohos"); // package name + + /* + * @tc.steps: step2. test get address by location's name. + * @tc.expected: step2. no exception head info. + */ + proxy_->GetAddressByLocationName(dataParcel, replyParcel); + EXPECT_EQ(ERRCODE_GEOCODING_FAIL, replyParcel.ReadInt32()); + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GetAddressByLocationName002 end"); +} + +HWTEST_F(GeoConvertServiceTest, GeoServiceDeathRecipientOnRemoteDied001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeoConvertServiceTest, GeoServiceDeathRecipientOnRemoteDied001, TestSize.Level1"; + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoServiceDeathRecipientOnRemoteDied001 begin"); + auto recipient = new (std::nothrow) GeoServiceDeathRecipient(); + wptr remote; + recipient->OnRemoteDied(remote); + LBSLOGI(GEO_CONVERT, "[GeoConvertServiceTest] GeoServiceDeathRecipientOnRemoteDied001 end"); +} } // namespace Location } // namespace OHOS #endif // FEATURE_GEOCODE_SUPPORT diff --git a/test/location_geofence/BUILD.gn b/test/location_geofence/BUILD.gn new file mode 100644 index 00000000..727219c2 --- /dev/null +++ b/test/location_geofence/BUILD.gn @@ -0,0 +1,77 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/location/config.gni") +import("//build/test.gni") + +module_output_path = "location/native" + +ohos_unittest("GeofenceSdkTest") { + module_out_path = module_output_path + sources = [ + "$LOCATION_ROOT_DIR/test/location_geofence/source/geofence_sdk_test.cpp", + "$LOCATION_ROOT_DIR/test/location_geofence/source/location_gnss_geofence_callback_host_test.cpp", + ] + + include_dirs = [ "$LOCATION_ROOT_DIR/test/location_geofence/include" ] + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "./../../cfi_blocklist.txt" + } + branch_protector_ret = "pac_ret" + + deps = [ + "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:dataobs_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "data_share:datashare_common", + "data_share:datashare_consumer", + "hilog:libhilog", + "hisysevent:libhisysevent", + "init:libbegetutil", + "ipc:ipc_core", + "location:locator_sdk", + "napi:ace_napi", + "os_account:os_account_innerkits", + "relational_store:native_dataability", + "relational_store:native_rdb", + "samgr:samgr_proxy", + ] + + defines = [] + + module_out_path = module_output_path +} + +group("unittest") { + testonly = true + deps = [] + deps += [ ":GeofenceSdkTest" ] +} diff --git a/test/location_geofence/include/geofence_sdk_test.h b/test/location_geofence/include/geofence_sdk_test.h new file mode 100644 index 00000000..7c784e0b --- /dev/null +++ b/test/location_geofence/include/geofence_sdk_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GEOFENCE_SDK_TEST_H +#define GEOFENCE_SDK_TEST_H + +#include +#include "geofence_sdk.h" + +namespace OHOS { +namespace Location { +class GeofenceSdkTest : public testing::Test { +public: + void SetUp(); + void TearDown(); + + GeofenceManager* geofenceManager_; +}; +} // namespace Location +} // namespace OHOS +#endif // GEOFENCE_SDK_TEST_H \ No newline at end of file diff --git a/test/location_geofence/include/location_gnss_geofence_callback_host_test.h b/test/location_geofence/include/location_gnss_geofence_callback_host_test.h new file mode 100644 index 00000000..58640c27 --- /dev/null +++ b/test/location_geofence/include/location_gnss_geofence_callback_host_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LOCATION_GNSS_GEOFENCE_CALLBACK_HOST_TEST_H +#define LOCATION_GNSS_GEOFENCE_CALLBACK_HOST_TEST_H + +#include + +namespace OHOS { +namespace Location { +class LocationGnssGeofenceCallbackHostTest : public testing::Test { +public: + void SetUp(); + void TearDown(); + + const int DEFAULT_NUM_VALUE = 1; + const int DEFAULT_CALLBACK_WAIT_TIME = 100; +}; +} // namespace Location +} // namespace OHOS +#endif // LOCATION_GNSS_GEOFENCE_CALLBACK_HOST_TEST_H \ No newline at end of file diff --git a/test/location_geofence/source/geofence_sdk_test.cpp b/test/location_geofence/source/geofence_sdk_test.cpp new file mode 100644 index 00000000..d55d2a88 --- /dev/null +++ b/test/location_geofence/source/geofence_sdk_test.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "geofence_sdk_test.h" +#include "location_log.h" + +using namespace testing::ext; +namespace OHOS { +namespace Location { +void GeofenceSdkTest::SetUp() +{ + geofenceManager_ = GeofenceManager::GetInstance(); +} + +void GeofenceSdkTest::TearDown() +{ +} + +HWTEST_F(GeofenceSdkTest, AddGnssGeofenceTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeofenceSdkTest, AddGnssGeofenceTest001, TestSize.Level1"; + LBSLOGI(GEOFENCE_SDK_TEST, "[GeofenceSdkTest] AddGnssGeofenceTest001 begin"); + ASSERT_TRUE(geofenceManager_ != nullptr); + std::shared_ptr gnssGeofenceRequest = std::make_shared(); + geofenceManager_->AddGnssGeofence(gnssGeofenceRequest); + LBSLOGI(GEOFENCE_SDK_TEST, "[GeofenceSdkTest] AddGnssGeofenceTest001 end"); +} + +HWTEST_F(GeofenceSdkTest, RemoveGnssGeofenceTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeofenceSdkTest, RemoveGnssGeofenceTest001, TestSize.Level1"; + LBSLOGI(GEOFENCE_SDK_TEST, "[GeofenceSdkTest] RemoveGnssGeofenceTest001 begin"); + ASSERT_TRUE(geofenceManager_ != nullptr); + std::shared_ptr gnssGeofenceRequest = std::make_shared(); + geofenceManager_->RemoveGnssGeofence(gnssGeofenceRequest); + LBSLOGI(GEOFENCE_SDK_TEST, "[GeofenceSdkTest] RemoveGnssGeofenceTest001 end"); +} + +HWTEST_F(GeofenceSdkTest, GetGeofenceSupportedCoordTypesTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GeofenceSdkTest, GetGeofenceSupportedCoordTypesTest001, TestSize.Level1"; + LBSLOGI(GEOFENCE_SDK_TEST, "[GeofenceSdkTest] GetGeofenceSupportedCoordTypesTest001 begin"); + ASSERT_TRUE(geofenceManager_ != nullptr); + std::vector coordinateSystemTypes; + geofenceManager_->GetGeofenceSupportedCoordTypes(coordinateSystemTypes); + LBSLOGI(GEOFENCE_SDK_TEST, "[GeofenceSdkTest] GetGeofenceSupportedCoordTypesTest001 end"); +} +} // namespace Location +} // namespace OHOS \ No newline at end of file diff --git a/test/location_geofence/source/location_gnss_geofence_callback_host_test.cpp b/test/location_geofence/source/location_gnss_geofence_callback_host_test.cpp new file mode 100644 index 00000000..eac21671 --- /dev/null +++ b/test/location_geofence/source/location_gnss_geofence_callback_host_test.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "location_gnss_geofence_callback_host_test.h" + +#include "location_gnss_geofence_callback_napi.h" +#include "location_log.h" +#include "geofence_definition.h" +#include "i_gnss_geofence_callback.h" + +using namespace testing::ext; +namespace OHOS { +namespace Location { +void LocationGnssGeofenceCallbackHostTest::SetUp() +{ +} + +void LocationGnssGeofenceCallbackHostTest::TearDown() +{ +} + +HWTEST_F(LocationGnssGeofenceCallbackHostTest, OnRemoteRequestTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationGnssGeofenceCallbackHostTest, OnRemoteRequestTest001, TestSize.Level1"; + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] OnRemoteRequestTest001 begin"); + std::shared_ptr callback = + std::make_shared(); + ASSERT_TRUE(callback != nullptr); + MessageParcel dataParcel; + dataParcel.WriteInt32(DEFAULT_NUM_VALUE); + dataParcel.WriteInt32(static_cast(GeofenceTransitionEvent::GEOFENCE_TRANSITION_EVENT_ENTER)); + MessageParcel reply; + MessageOption option = { MessageOption::TF_ASYNC }; + callback->OnRemoteRequest(IGnssGeofenceCallback::RECEIVE_TRANSITION_STATUS_EVENT, dataParcel, reply, option); + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] OnRemoteRequestTest001 end"); +} + +HWTEST_F(LocationGnssGeofenceCallbackHostTest, OnRemoteRequestTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationGnssGeofenceCallbackHostTest, OnRemoteRequestTest002, TestSize.Level1"; + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] OnRemoteRequestTest002 begin"); + std::shared_ptr callback = + std::make_shared(); + ASSERT_TRUE(callback != nullptr); + MessageParcel dataParcel; + dataParcel.WriteInt32(DEFAULT_NUM_VALUE); + dataParcel.WriteInt32(static_cast(GnssGeofenceOperateType::GNSS_GEOFENCE_OPT_TYPE_ADD)); + dataParcel.WriteInt32(static_cast(GnssGeofenceOperateResult::GNSS_GEOFENCE_OPERATION_SUCCESS)); + MessageParcel reply; + MessageOption option = { MessageOption::TF_ASYNC }; + callback->OnRemoteRequest(IGnssGeofenceCallback::REPORT_OPERATION_RESULT_EVENT, dataParcel, reply, option); + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] OnRemoteRequestTest002 end"); +} + +HWTEST_F(LocationGnssGeofenceCallbackHostTest, IsRemoteDiedTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationGnssGeofenceCallbackHostTest, IsRemoteDiedTest001, TestSize.Level1"; + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] IsRemoteDiedTest001 begin"); + std::shared_ptr callback = + std::make_shared(); + ASSERT_TRUE(callback != nullptr); + callback->IsRemoteDied(); + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] IsRemoteDiedTest001 end"); +} + +HWTEST_F(LocationGnssGeofenceCallbackHostTest, DeleteHandlerTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationGnssGeofenceCallbackHostTest, DeleteHandlerTest001, TestSize.Level1"; + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] DeleteHandlerTest001 begin"); + std::shared_ptr callback = + std::make_shared(); + ASSERT_TRUE(callback != nullptr); + callback->DeleteHandler(); + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] DeleteHandlerTest001 end"); +} + +HWTEST_F(LocationGnssGeofenceCallbackHostTest, LatchTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationGnssGeofenceCallbackHostTest, LatchTest001, TestSize.Level1"; + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] LatchTest001 begin"); + std::shared_ptr callback = + std::make_shared(); + ASSERT_TRUE(callback != nullptr); + callback->SetCount(1); + int countNum = callback->GetCount(); + ASSERT_TRUE(countNum == DEFAULT_NUM_VALUE); + callback->Wait(DEFAULT_CALLBACK_WAIT_TIME); + countNum = callback->GetCount(); + ASSERT_TRUE(countNum == DEFAULT_NUM_VALUE); + callback->CountDown(); + countNum = callback->GetCount(); + ASSERT_TRUE(countNum != DEFAULT_NUM_VALUE); + callback->SetCount(1); + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] LatchTest001 end"); +} + +HWTEST_F(LocationGnssGeofenceCallbackHostTest, FenceIdOperationTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationGnssGeofenceCallbackHostTest, FenceIdOperationTest001, TestSize.Level1"; + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] FenceIdOperationTest001 begin"); + std::shared_ptr callback = + std::make_shared(); + ASSERT_TRUE(callback != nullptr); + callback->SetFenceId(DEFAULT_NUM_VALUE); + int fenceId = callback->GetFenceId(); + ASSERT_TRUE(fenceId == DEFAULT_NUM_VALUE); + callback->ClearFenceId(); + fenceId = callback->GetFenceId(); + ASSERT_TRUE(fenceId != DEFAULT_NUM_VALUE); + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] FenceIdOperationTest001 end"); +} + +HWTEST_F(LocationGnssGeofenceCallbackHostTest, GeofenceOperationTypeTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationGnssGeofenceCallbackHostTest, GeofenceOperationTypeTest001, TestSize.Level1"; + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] GeofenceOperationTypeTest001 begin"); + std::shared_ptr callback = + std::make_shared(); + ASSERT_TRUE(callback != nullptr); + GnssGeofenceOperateType optType = static_cast(0); + callback->SetGeofenceOperationType(optType); + GnssGeofenceOperateType optResultType = callback->GetGeofenceOperationType(); + ASSERT_TRUE(optResultType == optType); + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] GeofenceOperationTypeTest001 end"); +} + +HWTEST_F(LocationGnssGeofenceCallbackHostTest, GeofenceOperationResultTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationGnssGeofenceCallbackHostTest, GeofenceOperationResultTest001, TestSize.Level1"; + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] GeofenceOperationResultTest001 begin"); + std::shared_ptr callback = + std::make_shared(); + ASSERT_TRUE(callback != nullptr); + GnssGeofenceOperateResult optValue = static_cast(0); + callback->SetGeofenceOperationResult(optValue); + GnssGeofenceOperateResult optResult = callback->GetGeofenceOperationResult(); + ASSERT_TRUE(optValue == optResult); + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] GeofenceOperationResultTest001 end"); +} + +HWTEST_F(LocationGnssGeofenceCallbackHostTest, GeofenceOperationResultTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationGnssGeofenceCallbackHostTest, GeofenceOperationResultTest002, TestSize.Level1"; + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] GeofenceOperationResultTest002 begin"); + std::shared_ptr callback = + std::make_shared(); + ASSERT_TRUE(callback != nullptr); + callback->SetGeofenceOperationResult(GnssGeofenceOperateResult::GNSS_GEOFENCE_OPERATION_SUCCESS); + callback->DealGeofenceOperationResult(); + callback->SetGeofenceOperationResult(GnssGeofenceOperateResult::GNSS_GEOFENCE_OPERATION_ERROR_UNKNOWN); + callback->DealGeofenceOperationResult(); + callback->SetGeofenceOperationResult(GnssGeofenceOperateResult::GNSS_GEOFENCE_OPERATION_ERROR_TOO_MANY_GEOFENCES); + callback->DealGeofenceOperationResult(); + callback->SetGeofenceOperationResult(GnssGeofenceOperateResult::GNSS_GEOFENCE_OPERATION_ERROR_GEOFENCE_ID_EXISTS); + callback->DealGeofenceOperationResult(); + callback->SetGeofenceOperationResult(GnssGeofenceOperateResult::GNSS_GEOFENCE_OPERATION_ERROR_PARAMS_INVALID); + callback->DealGeofenceOperationResult(); + LBSLOGI(GEOFENCE_SDK_TEST, "[LocationGnssGeofenceCallbackHostTest] GeofenceOperationResultTest002 end"); +} +} // namespace Location +} // namespace OHOS \ No newline at end of file diff --git a/test/location_gnss/BUILD.gn b/test/location_gnss/BUILD.gn index fb3ce026..d110a399 100644 --- a/test/location_gnss/BUILD.gn +++ b/test/location_gnss/BUILD.gn @@ -24,6 +24,8 @@ if (location_feature_with_gnss) { "$GNSS_UNIT_TEST_DIR/mock/src/mock_i_cellular_data_manager.cpp", "$GNSS_UNIT_TEST_DIR/source/gnss_ability_stub_test.cpp", "$GNSS_UNIT_TEST_DIR/source/gnss_ability_test.cpp", + "$GNSS_UNIT_TEST_DIR/source/gnss_event_callback_test.cpp", + "$GNSS_UNIT_TEST_DIR/source/gnss_interface_test.cpp", "$LOCATION_ROOT_DIR/test/mock/src/mock_service_registry.cpp", ] @@ -31,6 +33,7 @@ if (location_feature_with_gnss) { "$GNSS_UNIT_TEST_DIR/include", "$GNSS_UNIT_TEST_DIR/mock/include", "$LOCATION_GNSS_ROOT/include", + "$LOCATION_GNSS_ROOT/include/ntp", "$LOCATION_LOCATOR_ROOT/include", "$LOCATION_ROOT_DIR/interfaces/inner_api/include", "$LOCATION_ROOT_DIR/test/mock/include", @@ -49,11 +52,12 @@ if (location_feature_with_gnss) { "$GOOGLE_TEST_DIR:gmock_main", "$GOOGLE_TEST_DIR:gtest_main", "$IPC_ROOT_DIR/interfaces/innerkits/ipc_core:ipc_core", - "$LOCATION_GNSS_ROOT:lbsservice_gnss", - "$LOCATION_LOCATOR_ROOT:lbsservice_locator", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", + "$LOCATION_GNSS_ROOT:lbsservice_gnss_static", + "$LOCATION_LOCATOR_ROOT:lbsservice_locator_static", + "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", "$LOCATION_ROOT_DIR/test/location_locator:LocatorServiceAbilityTest", "$SAMGR_ROOT_DIR/safwk/interfaces/innerkits/safwk:system_ability_fwk", "$SAMGR_ROOT_DIR/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", @@ -73,6 +77,7 @@ if (location_feature_with_gnss) { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hdf_core:libhdi", "hdf_core:libpub_utils", "hilog:libhilog", @@ -85,6 +90,11 @@ if (location_feature_with_gnss) { defines += [ "FEATURE_GNSS_SUPPORT" ] } + if (telephony_core_service_enable) { + external_deps += [ "core_service:tel_core_service_api" ] + defines += [ "TEL_CORE_SERVICE_ENABLE" ] + } + if (hdf_drivers_interface_location_agnss_enable) { defines += [ "HDF_DRIVERS_INTERFACE_AGNSS_ENABLE" ] } diff --git a/test/location_gnss/include/gnss_ability_test.h b/test/location_gnss/include/gnss_ability_test.h index ebf2c4ce..dca5f080 100644 --- a/test/location_gnss/include/gnss_ability_test.h +++ b/test/location_gnss/include/gnss_ability_test.h @@ -28,9 +28,9 @@ #include #include "gnss_ability_proxy.h" -#include "gnss_status_callback_host.h" -#include "nmea_message_callback_host.h" -#include "cached_locations_callback_host.h" +#include "gnss_status_callback_napi.h" +#include "nmea_message_callback_napi.h" +#include "cached_locations_callback_napi.h" namespace OHOS { namespace Location { @@ -41,10 +41,10 @@ public: void MockNativePermission(); sptr proxy_; - sptr callbackStub_; + sptr callbackStub_; sptr ability_; - sptr nemaCallbackStub_; - sptr cachedLocationCallbackStub_; + sptr nemaCallbackStub_; + sptr cachedLocationCallbackStub_; }; } // namespace Location } // namespace OHOS diff --git a/test/location_gnss/include/gnss_event_callback_test.h b/test/location_gnss/include/gnss_event_callback_test.h new file mode 100644 index 00000000..cc25ab54 --- /dev/null +++ b/test/location_gnss/include/gnss_event_callback_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GNSS_EVENT_CALLBACK_TEST_H +#define GNSS_EVENT_CALLBACK_TEST_H +#ifdef FEATURE_GNSS_SUPPORT + +#include + +namespace OHOS { +namespace Location { +class GnssEventCallbackTest : public testing::Test { +public: + void SetUp(); + void TearDown(); + void MockNativePermission(); +}; +} // namespace Location +} // namespace OHOS +#endif // FEATURE_GNSS_SUPPORT +#endif // GNSS_EVENT_CALLBACK_TEST_H diff --git a/test/location_gnss/include/gnss_interface_test.h b/test/location_gnss/include/gnss_interface_test.h new file mode 100644 index 00000000..00fdabd8 --- /dev/null +++ b/test/location_gnss/include/gnss_interface_test.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GNSS_INTERFACE_TEST_H +#define GNSS_INTERFACE_TEST_H +#ifdef FEATURE_GNSS_SUPPORT + +#include + +#include +#include + +namespace OHOS { +namespace Location { +using HDI::Location::Gnss::V2_0::IGnssInterface; +using HDI::Location::Gnss::V2_0::IGnssCallback; +using HDI::Location::Gnss::V2_0::GnssConfigPara; +using HDI::Location::Gnss::V2_0::GnssRefInfo; + +class GnssInterfaceTest : public IGnssInterface { +public: + GnssInterfaceTest(); + ~GnssInterfaceTest() override; + + int32_t SetGnssConfigPara(const GnssConfigPara ¶) override; + + int32_t EnableGnss(const sptr &callbackObj) override; + + int32_t DisableGnss() override; + + int32_t StartGnss(HDI::Location::Gnss::V2_0::GnssStartType type) override; + + int32_t StopGnss(HDI::Location::Gnss::V2_0::GnssStartType type) override; + + int32_t SetGnssReferenceInfo(const GnssRefInfo &refInfo) override; + + int32_t DeleteAuxiliaryData(unsigned short data) override; + + int32_t SetPredictGnssData(const std::string &data) override; + + int32_t GetCachedGnssLocationsSize(int32_t &size) override; + + int32_t GetCachedGnssLocations() override; + + int32_t SendNiUserResponse(int32_t gnssNiNotificationId, + HDI::Location::Gnss::V2_0::GnssNiResponseCmd userResponse) override; + + int32_t SendNetworkInitiatedMsg(const std::string &msg, int32_t length) override; + + int32_t EnableGnssMeasurement( + const sptr &callbackObj) override; + + int32_t DisableGnssMeasurement() override; +}; +} // namespace Location +} // namespace OHOS +#endif // FEATURE_GNSS_SUPPORT +#endif // GNSS_INTERFACE_TEST_H diff --git a/test/location_gnss/include/string_utils_test.h b/test/location_gnss/include/string_utils_test.h new file mode 100644 index 00000000..b7b95676 --- /dev/null +++ b/test/location_gnss/include/string_utils_test.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GNSS_EVENT_CALLBACK_TEST_H +#define GNSS_EVENT_CALLBACK_TEST_H +#ifdef FEATURE_GNSS_SUPPORT + +#include + +namespace OHOS { +namespace Location { +class StringUtilsTest : public testing::Test { +public: + void SetUp(); + void TearDown(); +}; +} // namespace Location +} // namespace OHOS +#endif // FEATURE_GNSS_SUPPORT +#endif // GNSS_EVENT_CALLBACK_TEST_H diff --git a/test/location_gnss/mock/include/mock_cached_locations_callback_host.h b/test/location_gnss/mock/include/mock_cached_locations_callback_host.h index 4e1fda39..531a4da1 100644 --- a/test/location_gnss/mock/include/mock_cached_locations_callback_host.h +++ b/test/location_gnss/mock/include/mock_cached_locations_callback_host.h @@ -22,16 +22,16 @@ #include "message_option.h" #include "message_parcel.h" -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #include "location.h" namespace OHOS { namespace Location { -class MockCachedLocationsCallbackHost : public CachedLocationsCallbackHost { +class MockCachedLocationsCallbackHost : public CachedLocationsCallbackNapi { public: MockCachedLocationsCallbackHost() {} ~MockCachedLocationsCallbackHost() {} - + MOCK_METHOD(int, OnRemoteRequest, (uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)); MOCK_METHOD(void, OnCacheLocationsReport, (const std::vector>& locations)); diff --git a/test/location_gnss/mock/include/mock_gnss_status_callback_host.h b/test/location_gnss/mock/include/mock_gnss_status_callback_host.h index fb072c8e..f29b218f 100644 --- a/test/location_gnss/mock/include/mock_gnss_status_callback_host.h +++ b/test/location_gnss/mock/include/mock_gnss_status_callback_host.h @@ -22,16 +22,16 @@ #include "message_option.h" #include "message_parcel.h" -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #include "satellite_status.h" namespace OHOS { namespace Location { -class MockGnssStatusCallbackHost : public GnssStatusCallbackHost { +class MockGnssStatusCallbackHost : public GnssStatusCallbackNapi { public: MockGnssStatusCallbackHost() {} ~MockGnssStatusCallbackHost() {} - + MOCK_METHOD(int, OnRemoteRequest, (uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)); MOCK_METHOD(void, OnStatusChange, (const std::unique_ptr& statusInfo)); diff --git a/test/location_gnss/mock/include/mock_nmea_message_callback_host.h b/test/location_gnss/mock/include/mock_nmea_message_callback_host.h index 53336275..82566ed6 100644 --- a/test/location_gnss/mock/include/mock_nmea_message_callback_host.h +++ b/test/location_gnss/mock/include/mock_nmea_message_callback_host.h @@ -22,15 +22,15 @@ #include "message_option.h" #include "message_parcel.h" -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" namespace OHOS { namespace Location { -class MockNmeaMessageCallbackHost : public NmeaMessageCallbackHost { +class MockNmeaMessageCallbackHost : public NmeaMessageCallbackNapi { public: MockNmeaMessageCallbackHost() {} ~MockNmeaMessageCallbackHost() {} - + MOCK_METHOD(int, OnRemoteRequest, (uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)); MOCK_METHOD(void, OnMessageChange, (int64_t timestamp, const std::string msg)); diff --git a/test/location_gnss/source/gnss_ability_stub_test.cpp b/test/location_gnss/source/gnss_ability_stub_test.cpp index 3589a48b..d955afa4 100644 --- a/test/location_gnss/source/gnss_ability_stub_test.cpp +++ b/test/location_gnss/source/gnss_ability_stub_test.cpp @@ -310,6 +310,114 @@ HWTEST_F(GnssAbilityStubTest, GnssAbilityStubTest016, TestSize.Level1) gnssAbilityStub->OnRemoteRequest(UNKNOWN_CODE, parcel, reply, option)); LBSLOGI(GNSS, "[GnssAbilityStubTest] GnssAbilityStubTest016 end"); } + +HWTEST_F(GnssAbilityStubTest, GnssAbilityStubTest017, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityStubTest, GnssAbilityStubTest017, TestSize.Level1"; + LBSLOGI(GNSS, "[GnssAbilityStubTest] GnssAbilityStubTest017 begin"); + auto gnssAbilityStub = sptr(new (std::nothrow) MockGnssAbilityStub()); + ON_CALL(*gnssAbilityStub, AddFence(_)).WillByDefault(Return(ERRCODE_SUCCESS)); + MessageParcel parcel; + parcel.WriteInterfaceToken(GnssAbilityProxy::GetDescriptor()); + MessageParcel reply; + MessageOption option; + EXPECT_EQ(ERRCODE_SUCCESS, + gnssAbilityStub->OnRemoteRequest(static_cast(GnssInterfaceCode::ADD_FENCE_INFO), + parcel, reply, option)); + EXPECT_EQ(ERRCODE_SUCCESS, reply.ReadInt32()); + LBSLOGI(GNSS, "[GnssAbilityStubTest] GnssAbilityStubTest017 end"); +} + +HWTEST_F(GnssAbilityStubTest, GnssAbilityStubTest018, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityStubTest, GnssAbilityStubTest018, TestSize.Level1"; + LBSLOGI(GNSS, "[GnssAbilityStubTest] GnssAbilityStubTest018 begin"); + auto gnssAbilityStub = sptr(new (std::nothrow) MockGnssAbilityStub()); + ON_CALL(*gnssAbilityStub, RemoveFence(_)).WillByDefault(Return(ERRCODE_SUCCESS)); + MessageParcel parcel; + parcel.WriteInterfaceToken(GnssAbilityProxy::GetDescriptor()); + MessageParcel reply; + MessageOption option; + EXPECT_EQ(ERRCODE_SUCCESS, + gnssAbilityStub->OnRemoteRequest(static_cast(GnssInterfaceCode::REMOVE_FENCE_INFO), + parcel, reply, option)); + EXPECT_EQ(ERRCODE_SUCCESS, reply.ReadInt32()); + LBSLOGI(GNSS, "[GnssAbilityStubTest] GnssAbilityStubTest018 end"); +} + +HWTEST_F(GnssAbilityStubTest, GnssAbilityStubTest019, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityStubTest, GnssAbilityStubTest019, TestSize.Level1"; + LBSLOGI(GNSS, "[GnssAbilityStubTest] GnssAbilityStubTest019 begin"); + auto gnssAbilityStub = sptr(new (std::nothrow) MockGnssAbilityStub()); + ON_CALL(*gnssAbilityStub, AddGnssGeofence(_)).WillByDefault(Return(ERRCODE_SUCCESS)); + MessageParcel parcel; + parcel.WriteInterfaceToken(GnssAbilityProxy::GetDescriptor()); + MessageParcel reply; + MessageOption option; + EXPECT_EQ(ERRCODE_SUCCESS, + gnssAbilityStub->OnRemoteRequest(static_cast(GnssInterfaceCode::ADD_GNSS_GEOFENCE), + parcel, reply, option)); + EXPECT_EQ(ERRCODE_SUCCESS, reply.ReadInt32()); + LBSLOGI(GNSS, "[GnssAbilityStubTest] GnssAbilityStubTest019 end"); +} + +HWTEST_F(GnssAbilityStubTest, GnssAbilityStubTest020, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityStubTest, GnssAbilityStubTest020, TestSize.Level1"; + LBSLOGI(GNSS, "[GnssAbilityStubTest] GnssAbilityStubTest020 begin"); + auto gnssAbilityStub = sptr(new (std::nothrow) MockGnssAbilityStub()); + ON_CALL(*gnssAbilityStub, RemoveGnssGeofence(_)).WillByDefault(Return(ERRCODE_SUCCESS)); + MessageParcel parcel; + parcel.WriteInterfaceToken(GnssAbilityProxy::GetDescriptor()); + MessageParcel reply; + MessageOption option; + EXPECT_EQ(ERRCODE_SUCCESS, + gnssAbilityStub->OnRemoteRequest(static_cast(GnssInterfaceCode::REMOVE_GNSS_GEOFENCE), + parcel, reply, option)); + EXPECT_EQ(ERRCODE_SUCCESS, reply.ReadInt32()); + LBSLOGI(GNSS, "[GnssAbilityStubTest] GnssAbilityStubTest020 end"); +} + +HWTEST_F(GnssAbilityStubTest, GnssAbilityStubTest021, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityStubTest, GnssAbilityStubTest021, TestSize.Level1"; + LBSLOGI(GNSS, "[GnssAbilityStubTest] GnssAbilityStubTest021 begin"); + auto gnssAbilityStub = sptr(new (std::nothrow) MockGnssAbilityStub()); + EXPECT_CALL(*gnssAbilityStub, QuerySupportCoordinateSystemType(_)).WillOnce(DoAll(Return(ERRCODE_SUCCESS))); + MessageParcel parcel; + parcel.WriteInterfaceToken(GnssAbilityProxy::GetDescriptor()); + MessageParcel reply; + MessageOption option; + EXPECT_EQ(ERRCODE_SUCCESS, gnssAbilityStub->OnRemoteRequest( + static_cast(GnssInterfaceCode::GET_GEOFENCE_SUPPORT_COORDINATE_SYSTEM_TYPE), + parcel, reply, option)); + EXPECT_EQ(ERRCODE_SUCCESS, reply.ReadInt32()); + LBSLOGI(GNSS, "[GnssAbilityStubTest] GnssAbilityStubTest021 end"); +} + +HWTEST_F(GnssAbilityStubTest, GnssAbilityStubTest022, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityStubTest, GnssAbilityStubTest022, TestSize.Level1"; + LBSLOGI(GNSS, "[GnssAbilityStubTest] GnssAbilityStubTest022 begin"); + auto gnssAbilityStub = sptr(new (std::nothrow) MockGnssAbilityStub()); + ON_CALL(*gnssAbilityStub, SendNetworkLocation(_)).WillByDefault(Return(ERRCODE_SUCCESS)); + MessageParcel parcel; + parcel.WriteInterfaceToken(GnssAbilityProxy::GetDescriptor()); + MessageParcel reply; + MessageOption option; + EXPECT_EQ(ERRCODE_SUCCESS, + gnssAbilityStub->OnRemoteRequest(static_cast(GnssInterfaceCode::SEND_NETWORK_LOCATION), + parcel, reply, option)); + EXPECT_EQ(ERRCODE_SUCCESS, reply.ReadInt32()); + LBSLOGI(GNSS, "[GnssAbilityStubTest] GnssAbilityStubTest022 end"); +} } // namespace Location } // namespace OHOS #endif // FEATURE_GNSS_SUPPORT diff --git a/test/location_gnss/source/gnss_ability_test.cpp b/test/location_gnss/source/gnss_ability_test.cpp index 9ff4fc04..55f7d320 100644 --- a/test/location_gnss/source/gnss_ability_test.cpp +++ b/test/location_gnss/source/gnss_ability_test.cpp @@ -40,6 +40,8 @@ #include "call_manager_client.h" #include "string_utils.h" +#include "gnss_interface_test.h" + using namespace testing; using namespace testing::ext; @@ -51,8 +53,10 @@ using HDI::Location::Gnss::V2_0::IGnssCallback; using HDI::Location::Gnss::V2_0::LocationInfo; using HDI::Location::Gnss::V2_0::ConstellationCategory; using HDI::Location::Agnss::V2_0::AGnssRefInfoType; -const int32_t LOCATION_PERM_NUM = 4; +const int32_t LOCATION_PERM_NUM = 5; const std::string ARGS_HELP = "-h"; +const std::string MANAGER_SETTINGS = "ohos.permission.MANAGE_SETTINGS"; +constexpr int32_t FENCE_MAX_ID = 1000000; void GnssAbilityTest::SetUp() { /* @@ -61,11 +65,11 @@ void GnssAbilityTest::SetUp() MockNativePermission(); ability_ = new (std::nothrow) GnssAbility(); EXPECT_NE(nullptr, ability_); - callbackStub_ = new (std::nothrow) GnssStatusCallbackHost(); + callbackStub_ = new (std::nothrow) GnssStatusCallbackNapi(); EXPECT_NE(nullptr, callbackStub_); - nemaCallbackStub_ = new (std::nothrow) NmeaMessageCallbackHost(); + nemaCallbackStub_ = new (std::nothrow) NmeaMessageCallbackNapi(); EXPECT_NE(nullptr, nemaCallbackStub_); - cachedLocationCallbackStub_ = new (std::nothrow) CachedLocationsCallbackHost(); + cachedLocationCallbackStub_ = new (std::nothrow) CachedLocationsCallbackNapi(); EXPECT_NE(nullptr, cachedLocationCallbackStub_); proxy_ = new (std::nothrow) GnssAbilityProxy(ability_); EXPECT_NE(nullptr, proxy_); @@ -85,6 +89,7 @@ void GnssAbilityTest::MockNativePermission() const char *perms[] = { ACCESS_LOCATION.c_str(), ACCESS_APPROXIMATELY_LOCATION.c_str(), ACCESS_BACKGROUND_LOCATION.c_str(), MANAGE_SECURE_SETTINGS.c_str(), + MANAGER_SETTINGS.c_str(), }; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, @@ -515,7 +520,7 @@ HWTEST_F(GnssAbilityTest, GnssLocationMock001, TestSize.Level1) EXPECT_EQ(ERRCODE_SUCCESS, proxy_->EnableMock()); EXPECT_EQ(true, ability_->IsMockEnabled()); EXPECT_EQ(ERRCODE_SUCCESS, proxy_->SetMocked(timeInterval, locations)); - + EXPECT_EQ(ERRCODE_SUCCESS, proxy_->DisableMock()); EXPECT_EQ(false, ability_->IsMockEnabled()); EXPECT_EQ(ERRCODE_NOT_SUPPORTED, proxy_->SetMocked(timeInterval, locations)); @@ -862,6 +867,20 @@ HWTEST_F(GnssAbilityTest, GnssEventCallbackReportGnssWorkingStatus001, TestSize. LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportGnssWorkingStatus001 end"); } +HWTEST_F(GnssAbilityTest, GnssEventCallbackReportGnssWorkingStatus002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GnssEventCallbackReportGnssWorkingStatus002, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportGnssWorkingStatus002 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + GnssWorkingStatus status = HDI::Location::Gnss::V2_0::GNSS_WORKING_STATUS_NONE; + auto gnssAbility = GnssAbility::GetInstance(); + gnssAbility = nullptr; + gnssCallback->ReportGnssWorkingStatus(status); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportGnssWorkingStatus002 end"); +} + HWTEST_F(GnssAbilityTest, GnssEventCallbackReportNmea001, TestSize.Level1) { GTEST_LOG_(INFO) @@ -873,6 +892,19 @@ HWTEST_F(GnssAbilityTest, GnssEventCallbackReportNmea001, TestSize.Level1) LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportNmea001 end"); } +HWTEST_F(GnssAbilityTest, GnssEventCallbackReportNmea002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GnssEventCallbackReportNmea002, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportNmea002 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + auto gnssAbility = GnssAbility::GetInstance(); + gnssAbility = nullptr; + gnssCallback->ReportNmea(0, "nmea", 0); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportNmea002 end"); +} + HWTEST_F(GnssAbilityTest, GnssEventCallbackReportGnssCapabilities001, TestSize.Level1) { GTEST_LOG_(INFO) @@ -885,6 +917,20 @@ HWTEST_F(GnssAbilityTest, GnssEventCallbackReportGnssCapabilities001, TestSize.L LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportGnssCapabilities001 end"); } +HWTEST_F(GnssAbilityTest, GnssEventCallbackReportGnssCapabilities002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GnssEventCallbackReportGnssCapabilities002, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportGnssCapabilities002 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + GnssCapabilities capabilities = HDI::Location::Gnss::V2_0::GNSS_CAP_SUPPORT_MSB; + auto gnssAbility = GnssAbility::GetInstance(); + gnssAbility = nullptr; + EXPECT_EQ(ERR_OK, gnssCallback->ReportGnssCapabilities(capabilities)); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportGnssCapabilities002 end"); +} + HWTEST_F(GnssAbilityTest, GnssEventCallbackReportSatelliteStatusInfo002, TestSize.Level1) { GTEST_LOG_(INFO) @@ -974,6 +1020,214 @@ HWTEST_F(GnssAbilityTest, GnssEventCallbackReportCachedLocation001, TestSize.Lev LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportCachedLocation001 end"); } +HWTEST_F(GnssAbilityTest, GnssEventCallbackReportGnssNiNotification001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GnssEventCallbackReportGnssNiNotification001, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportGnssNiNotification001 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + GnssNiNotificationRequest notif; + gnssCallback->ReportGnssNiNotification(notif); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportGnssNiNotification001 end"); +} + +HWTEST_F(GnssAbilityTest, GnssEventCallbackReportGnssNiNotification002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GnssEventCallbackReportGnssNiNotification002, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportGnssNiNotification002 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + GnssNiNotificationRequest notif; + notif.notificationCategory = GNSS_NI_NOTIFICATION_REQUIRE_NOTIFY; + gnssCallback->ReportGnssNiNotification(notif); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportGnssNiNotification002 end"); +} + +HWTEST_F(GnssAbilityTest, GeofenceEventCallbackReportGeofenceAvailability001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GeofenceEventCallbackReportGeofenceAvailability001, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GeofenceEventCallbackReportGeofenceAvailability001 begin"); + sptr geofenceEventCallback = new (std::nothrow) GeofenceEventCallback(); + EXPECT_NE(nullptr, geofenceEventCallback); + geofenceEventCallback->ReportGeofenceAvailability(true); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GeofenceEventCallbackReportGeofenceAvailability001 end"); +} + +HWTEST_F(GnssAbilityTest, GeofenceEventCallbackReportGeofenceEvent001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GeofenceEventCallbackReportGeofenceEvent001, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GeofenceEventCallbackReportGeofenceEvent001 begin"); + sptr geofenceEventCallback = new (std::nothrow) GeofenceEventCallback(); + EXPECT_NE(nullptr, geofenceEventCallback); + int32_t fenceIndex = 0; + HDI::Location::Geofence::V2_0::LocationInfo location; + GeofenceEvent event = GeofenceEvent::GEOFENCE_EVENT_ENTERED; + int64_t timestamp = 0; + geofenceEventCallback->ReportGeofenceEvent(fenceIndex, location, event, timestamp); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GeofenceEventCallbackReportGeofenceEvent001 end"); +} + +HWTEST_F(GnssAbilityTest, GeofenceEventCallbackReportGeofenceEvent002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GeofenceEventCallbackReportGeofenceEvent002, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GeofenceEventCallbackReportGeofenceEvent002 begin"); + sptr geofenceEventCallback = new (std::nothrow) GeofenceEventCallback(); + EXPECT_NE(nullptr, geofenceEventCallback); + int32_t fenceIndex = 0; + HDI::Location::Geofence::V2_0::LocationInfo location; + GeofenceEvent event = GeofenceEvent::GEOFENCE_EVENT_ENTERED; + int64_t timestamp = 0; + auto gnssAbility = GnssAbility::GetInstance(); + gnssAbility = nullptr; + geofenceEventCallback->ReportGeofenceEvent(fenceIndex, location, event, timestamp); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GeofenceEventCallbackReportGeofenceEvent002 end"); +} + +HWTEST_F(GnssAbilityTest, GeofenceEventCallbackReportGeofenceOperateResult001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GeofenceEventCallbackReportGeofenceOperateResult001, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GeofenceEventCallbackReportGeofenceOperateResult001 begin"); + sptr geofenceEventCallback = new (std::nothrow) GeofenceEventCallback(); + EXPECT_NE(nullptr, geofenceEventCallback); + int32_t fenceIndex = 0; + GeofenceOperateType type = GeofenceOperateType::TYPE_ADD; + GeofenceOperateResult result = GeofenceOperateResult::GEOFENCE_OPERATION_SUCCESS; + geofenceEventCallback->ReportGeofenceOperateResult(fenceIndex, type, result); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GeofenceEventCallbackReportGeofenceOperateResult001 end"); +} + +HWTEST_F(GnssAbilityTest, GeofenceEventCallbackReportGeofenceOperateResult002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GeofenceEventCallbackReportGeofenceOperateResult002, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GeofenceEventCallbackReportGeofenceOperateResult002 begin"); + sptr geofenceEventCallback = new (std::nothrow) GeofenceEventCallback(); + EXPECT_NE(nullptr, geofenceEventCallback); + int32_t fenceIndex = 0; + GeofenceOperateType type = GeofenceOperateType::TYPE_ADD; + GeofenceOperateResult result = GeofenceOperateResult::GEOFENCE_OPERATION_SUCCESS; + auto gnssAbility = GnssAbility::GetInstance(); + gnssAbility = nullptr; + geofenceEventCallback->ReportGeofenceOperateResult(fenceIndex, type, result); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GeofenceEventCallbackReportGeofenceOperateResult002 end"); +} + +HWTEST_F(GnssAbilityTest, GnssCommonEventSubscriberOnReceiveEvent001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GnssCommonEventSubscriberOnReceiveEvent001, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssCommonEventSubscriberOnReceiveEvent001 begin"); + MatchingSkills matchingSkills; + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SMS_WAPPUSH_RECEIVE_COMPLETED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SMS_RECEIVE_COMPLETED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); + matchingSkills.AddEvent(AGNSS_NI_ACCEPT_EVENT); + matchingSkills.AddEvent(AGNSS_NI_REJECT_EVENT); + CommonEventSubscribeInfo subscriberInfo(matchingSkills); + std::shared_ptr subscriber = + std::make_shared(subscriberInfo); + OHOS::EventFwk::CommonEventData eventData = OHOS::EventFwk::CommonEventData(); + OHOS::AAFwk::Want want = OHOS::AAFwk::Want(); + want.SetAction(CommonEventSupport::COMMON_EVENT_SMS_WAPPUSH_RECEIVE_COMPLETED); + eventData.SetWant(want); + subscriber->OnReceiveEvent(eventData); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssCommonEventSubscriberOnReceiveEvent001 end"); +} + +HWTEST_F(GnssAbilityTest, GnssCommonEventSubscriberOnReceiveEvent002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GnssCommonEventSubscriberOnReceiveEvent002, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssCommonEventSubscriberOnReceiveEvent002 begin"); + MatchingSkills matchingSkills; + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SMS_WAPPUSH_RECEIVE_COMPLETED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SMS_RECEIVE_COMPLETED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); + matchingSkills.AddEvent(AGNSS_NI_ACCEPT_EVENT); + matchingSkills.AddEvent(AGNSS_NI_REJECT_EVENT); + CommonEventSubscribeInfo subscriberInfo(matchingSkills); + std::shared_ptr subscriber = + std::make_shared(subscriberInfo); + OHOS::EventFwk::CommonEventData eventData = OHOS::EventFwk::CommonEventData(); + OHOS::AAFwk::Want want = OHOS::AAFwk::Want(); + want.SetAction(CommonEventSupport::COMMON_EVENT_SMS_RECEIVE_COMPLETED); + eventData.SetWant(want); + subscriber->OnReceiveEvent(eventData); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssCommonEventSubscriberOnReceiveEvent002 end"); +} + +HWTEST_F(GnssAbilityTest, GnssCommonEventSubscriberOnReceiveEvent003, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GnssCommonEventSubscriberOnReceiveEvent003, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssCommonEventSubscriberOnReceiveEvent003 begin"); + MatchingSkills matchingSkills; + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SMS_WAPPUSH_RECEIVE_COMPLETED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SMS_RECEIVE_COMPLETED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); + matchingSkills.AddEvent(AGNSS_NI_ACCEPT_EVENT); + matchingSkills.AddEvent(AGNSS_NI_REJECT_EVENT); + CommonEventSubscribeInfo subscriberInfo(matchingSkills); + std::shared_ptr subscriber = + std::make_shared(subscriberInfo); + OHOS::EventFwk::CommonEventData eventData = OHOS::EventFwk::CommonEventData(); + OHOS::AAFwk::Want want = OHOS::AAFwk::Want(); + want.SetAction(CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); + eventData.SetWant(want); + subscriber->OnReceiveEvent(eventData); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssCommonEventSubscriberOnReceiveEvent003 end"); +} + +HWTEST_F(GnssAbilityTest, GnssCommonEventSubscriberOnReceiveEvent004, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GnssCommonEventSubscriberOnReceiveEvent001, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssCommonEventSubscriberOnReceiveEvent004 begin"); + MatchingSkills matchingSkills; + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SMS_WAPPUSH_RECEIVE_COMPLETED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SMS_RECEIVE_COMPLETED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); + matchingSkills.AddEvent(AGNSS_NI_ACCEPT_EVENT); + matchingSkills.AddEvent(AGNSS_NI_REJECT_EVENT); + CommonEventSubscribeInfo subscriberInfo(matchingSkills); + std::shared_ptr subscriber = + std::make_shared(subscriberInfo); + OHOS::EventFwk::CommonEventData eventData = OHOS::EventFwk::CommonEventData(); + OHOS::AAFwk::Want want = OHOS::AAFwk::Want(); + want.SetAction(AGNSS_NI_ACCEPT_EVENT); + eventData.SetWant(want); + subscriber->OnReceiveEvent(eventData); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssCommonEventSubscriberOnReceiveEvent004 end"); +} + +HWTEST_F(GnssAbilityTest, GnssCommonEventSubscriberOnReceiveEvent005, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GnssCommonEventSubscriberOnReceiveEvent005, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssCommonEventSubscriberOnReceiveEvent005 begin"); + MatchingSkills matchingSkills; + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SMS_WAPPUSH_RECEIVE_COMPLETED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SMS_RECEIVE_COMPLETED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); + matchingSkills.AddEvent(AGNSS_NI_ACCEPT_EVENT); + matchingSkills.AddEvent(AGNSS_NI_REJECT_EVENT); + CommonEventSubscribeInfo subscriberInfo(matchingSkills); + std::shared_ptr subscriber = + std::make_shared(subscriberInfo); + OHOS::EventFwk::CommonEventData eventData = OHOS::EventFwk::CommonEventData(); + OHOS::AAFwk::Want want = OHOS::AAFwk::Want(); + want.SetAction(AGNSS_NI_REJECT_EVENT); + eventData.SetWant(want); + subscriber->OnReceiveEvent(eventData); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssCommonEventSubscriberOnReceiveEvent005 end"); +} + HWTEST_F(GnssAbilityTest, GnssOnStart001, TestSize.Level1) { GTEST_LOG_(INFO) @@ -1149,6 +1403,57 @@ HWTEST_F(GnssAbilityTest, GnssSendMessage001, TestSize.Level1) LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendMessage001 end"); } +HWTEST_F(GnssAbilityTest, GnssSendMessage002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GnssSendMessage002, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendMessage002 begin"); + sptr gnssAbility = new (std::nothrow) GnssAbility(); + ASSERT_TRUE(gnssAbility != nullptr); + MessageParcel requestParcel; + requestParcel.WriteInterfaceToken(u"location.INetworkAbility"); + requestParcel.WriteBuffer("data", 4); + requestParcel.RewindRead(0); + + MessageParcel reply; + gnssAbility->SendMessage(static_cast(GnssAbilityInterfaceCode::ADD_FENCE), requestParcel, reply); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendMessage002 end"); +} + +HWTEST_F(GnssAbilityTest, GnssSendMessage003, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GnssSendMessage003, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendMessage003 begin"); + sptr gnssAbility = new (std::nothrow) GnssAbility(); + ASSERT_TRUE(gnssAbility != nullptr); + MessageParcel requestParcel; + requestParcel.WriteInterfaceToken(u"location.INetworkAbility"); + requestParcel.WriteBuffer("data", 4); + requestParcel.RewindRead(0); + + MessageParcel reply; + gnssAbility->SendMessage(0, requestParcel, reply); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendMessage003 end"); +} + +HWTEST_F(GnssAbilityTest, GnssSendMessage004, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GnssSendMessage004, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendMessage004 begin"); + sptr gnssAbility = new (std::nothrow) GnssAbility(); + ASSERT_TRUE(gnssAbility != nullptr); + MessageParcel requestParcel; + requestParcel.WriteInterfaceToken(u"location.INetworkAbility"); + requestParcel.WriteBuffer("data", 4); + requestParcel.RewindRead(0); + + MessageParcel reply; + gnssAbility->SendMessage(0, requestParcel, reply); + LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendMessage004 end"); +} + HWTEST_F(GnssAbilityTest, GnssRegisterLocationHdiDeathRecipient001, TestSize.Level1) { @@ -1570,6 +1875,146 @@ HWTEST_F(GnssAbilityTest, RemoveGnssGeofence002, TestSize.Level1) LBSLOGI(LOCATOR, "[GnssAbilityTest] RemoveGnssGeofence002 end"); } +HWTEST_F(GnssAbilityTest, RegisterGnssGeofenceCallback001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, RegisterGnssGeofenceCallback001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] RegisterGnssGeofenceCallback001 begin"); + sptr gnssAbility = new (std::nothrow) GnssAbility(); + EXPECT_NE(nullptr, gnssAbility); + std::shared_ptr request = nullptr; + sptr callback = nullptr; + bool result = gnssAbility->RegisterGnssGeofenceCallback(request, callback); + EXPECT_EQ(false, result); + LBSLOGI(LOCATOR, "[GnssAbilityTest] RegisterGnssGeofenceCallback001 end"); +} + +HWTEST_F(GnssAbilityTest, UnregisterGnssGeofenceCallback001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, UnregisterGnssGeofenceCallback001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] UnregisterGnssGeofenceCallback001 begin"); + sptr gnssAbility = new (std::nothrow) GnssAbility(); + EXPECT_NE(nullptr, gnssAbility); + int fenceId = 1; + bool result = gnssAbility->UnregisterGnssGeofenceCallback(fenceId); + EXPECT_EQ(true, result); + LBSLOGI(LOCATOR, "[GnssAbilityTest] UnregisterGnssGeofenceCallback001 end"); +} + +HWTEST_F(GnssAbilityTest, RemoveGnssGeofenceRequestByCallback001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, RemoveGnssGeofenceRequestByCallback001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] RemoveGnssGeofenceRequestByCallback001 begin"); + sptr gnssAbility = new (std::nothrow) GnssAbility(); + EXPECT_NE(nullptr, gnssAbility); + sptr callbackObj = nullptr; + bool result = gnssAbility->RemoveGnssGeofenceRequestByCallback(callbackObj); + EXPECT_EQ(false, result); + LBSLOGI(LOCATOR, "[GnssAbilityTest] RemoveGnssGeofenceRequestByCallback001 end"); +} + +#ifdef HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE +HWTEST_F(GnssAbilityTest, ReportGeofenceOperationResult001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, ReportGeofenceOperationResult001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] ReportGeofenceOperationResult001 begin"); + sptr gnssAbility = new (std::nothrow) GnssAbility(); + EXPECT_NE(nullptr, gnssAbility); + int fenceId = 0; + GeofenceOperateType type = GeofenceOperateType::TYPE_DELETE; + GeofenceOperateResult result = GeofenceOperateResult::GEOFENCE_OPERATION_SUCCESS; + gnssAbility->ReportGeofenceOperationResult(fenceId, type, result); + LBSLOGI(LOCATOR, "[GnssAbilityTest] ReportGeofenceOperationResult001 end"); +} + +HWTEST_F(GnssAbilityTest, ReportGeofenceEvent001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, ReportGeofenceEvent001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] ReportGeofenceEvent001 begin"); + sptr gnssAbility = new (std::nothrow) GnssAbility(); + EXPECT_NE(nullptr, gnssAbility); + int fenceId = 0; + GeofenceEvent event = GeofenceEvent::GEOFENCE_EVENT_ENTERED; + gnssAbility->ReportGeofenceEvent(fenceId, event); + LBSLOGI(LOCATOR, "[GnssAbilityTest] ReportGeofenceEvent001 end"); +} + +HWTEST_F(GnssAbilityTest, GetGeofenceRequestByFenceId001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GetGeofenceRequestByFenceId001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] GetGeofenceRequestByFenceId001 begin"); + sptr gnssAbility = new (std::nothrow) GnssAbility(); + EXPECT_NE(nullptr, gnssAbility); + int fenceId = 0; + gnssAbility->GetGeofenceRequestByFenceId(fenceId); + LBSLOGI(LOCATOR, "[GnssAbilityTest] GetGeofenceRequestByFenceId001 end"); +} + +HWTEST_F(GnssAbilityTest, ExecuteFenceProcess001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, ExecuteFenceProcess001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] ExecuteFenceProcess001 begin"); + sptr gnssAbility = new (std::nothrow) GnssAbility(); + EXPECT_NE(nullptr, gnssAbility); + GnssInterfaceCode code= GnssInterfaceCode::ADD_FENCE_INFO; + std::shared_ptr request = std::make_shared(); + gnssAbility->ExecuteFenceProcess(code, request); + LBSLOGI(LOCATOR, "[GnssAbilityTest] ExecuteFenceProcess001 end"); +} + +HWTEST_F(GnssAbilityTest, SetGeofenceCallback001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, SetGeofenceCallback001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] SetGeofenceCallback001 begin"); + sptr gnssAbility = new (std::nothrow) GnssAbility(); + EXPECT_NE(nullptr, gnssAbility); + gnssAbility->SetGeofenceCallback(); + LBSLOGI(LOCATOR, "[GnssAbilityTest] SetGeofenceCallback001 end"); +} + +HWTEST_F(GnssAbilityTest, StopGnss001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, StopGnss001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] StopGnss001 begin"); + sptr gnssAbility = new (std::nothrow) GnssAbility(); + EXPECT_NE(nullptr, gnssAbility); + gnssAbility->StopGnss(); + LBSLOGI(LOCATOR, "[GnssAbilityTest] StopGnss001 end"); +} + +HWTEST_F(GnssAbilityTest, RemoveHdi001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, RemoveHdi001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] RemoveHdi001 begin"); + sptr gnssAbility = new (std::nothrow) GnssAbility(); + EXPECT_NE(nullptr, gnssAbility); + gnssAbility->RemoveHdi(); + LBSLOGI(LOCATOR, "[GnssAbilityTest] RemoveHdi001 end"); +} + +HWTEST_F(GnssAbilityTest, QuerySupportCoordinateSystemType001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, QuerySupportCoordinateSystemType001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] QuerySupportCoordinateSystemType001 begin"); + sptr gnssAbility = new (std::nothrow) GnssAbility(); + EXPECT_NE(nullptr, gnssAbility); + std::vector coordinateSystemTypes; + gnssAbility->QuerySupportCoordinateSystemType(coordinateSystemTypes); + LBSLOGI(LOCATOR, "[GnssAbilityTest] QuerySupportCoordinateSystemType001 end"); +} + +#endif + HWTEST_F(GnssAbilityTest, ReConnectHdiImpl001, TestSize.Level1) { GTEST_LOG_(INFO) @@ -1727,6 +2172,54 @@ HWTEST_F(GnssAbilityTest, AgnssNiManagerSendUserResponse002, TestSize.Level1) LBSLOGI(LOCATOR, "[GnssAbilityTest] AgnssNiManagerSendUserResponse002 end"); } +HWTEST_F(GnssAbilityTest, AgnssNiManagerOnAddSystemAbility001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, AgnssNiManagerOnAddSystemAbility001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] AgnssNiManagerOnAddSystemAbility001 begin"); + auto statusChangeListener = new SystemAbilityStatusChangeListener(); + int32_t systemAbilityId = -1; + const std::string deviceId = "test"; + statusChangeListener->OnAddSystemAbility(systemAbilityId, deviceId); + LBSLOGI(LOCATOR, "[GnssAbilityTest] AgnssNiManagerOnAddSystemAbility001 end"); +} + +HWTEST_F(GnssAbilityTest, AgnssNiManagerOnAddSystemAbility002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, AgnssNiManagerOnAddSystemAbility002, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] AgnssNiManagerOnAddSystemAbility002 begin"); + auto statusChangeListener = new SystemAbilityStatusChangeListener(); + int32_t systemAbilityId = COMMON_EVENT_SERVICE_ID; + const std::string deviceId = "test"; + statusChangeListener->OnAddSystemAbility(systemAbilityId, deviceId); + LBSLOGI(LOCATOR, "[GnssAbilityTest] AgnssNiManagerOnAddSystemAbility002 end"); +} + +HWTEST_F(GnssAbilityTest, AgnssNiManagerOnRemoveSystemAbility001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, AgnssNiManagerOnRemoveSystemAbility001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] AgnssNiManagerOnRemoveSystemAbility001 begin"); + auto statusChangeListener = new SystemAbilityStatusChangeListener(); + int32_t systemAbilityId = -1; + const std::string deviceId = "test"; + statusChangeListener->OnRemoveSystemAbility(systemAbilityId, deviceId); + LBSLOGI(LOCATOR, "[GnssAbilityTest] AgnssNiManagerOnRemoveSystemAbility001 end"); +} + +HWTEST_F(GnssAbilityTest, AgnssNiManagerOnRemoveSystemAbility002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, AgnssNiManagerOnRemoveSystemAbility002, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] AgnssNiManagerOnRemoveSystemAbility002 begin"); + auto statusChangeListener = new SystemAbilityStatusChangeListener(); + int32_t systemAbilityId = COMMON_EVENT_SERVICE_ID; + const std::string deviceId = "test"; + statusChangeListener->OnRemoveSystemAbility(systemAbilityId, deviceId); + LBSLOGI(LOCATOR, "[GnssAbilityTest] AgnssNiManagerOnRemoveSystemAbility002 end"); +} + HWTEST_F(GnssAbilityTest, StringUtilsStringToHex001, TestSize.Level1) { GTEST_LOG_(INFO) @@ -1892,6 +2385,17 @@ HWTEST_F(GnssAbilityTest, StringUtilsHexToByteVector004, TestSize.Level1) LBSLOGI(LOCATOR, "[GnssAbilityTest] StringUtilsHexToByteVector003 end"); } +HWTEST_F(GnssAbilityTest, StringUtilsHexToByteVector005, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, StringUtilsHexToByteVector005, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] StringUtilsHexToByteVector005 begin"); + std::string str = " "; + std::vector ret = StringUtils::HexToByteVector(str); + EXPECT_EQ(2, ret.size()); + LBSLOGI(LOCATOR, "[GnssAbilityTest] StringUtilsHexToByteVector005 end"); +} + HWTEST_F(GnssAbilityTest, StringUtilsGsm7Decode001, TestSize.Level1) { GTEST_LOG_(INFO) @@ -1902,6 +2406,99 @@ HWTEST_F(GnssAbilityTest, StringUtilsGsm7Decode001, TestSize.Level1) LBSLOGI(LOCATOR, "[GnssAbilityTest] StringUtilsGsm7Decode001 end"); } +HWTEST_F(GnssAbilityTest, StringUtilsGsm7Decode002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, StringUtilsGsm7Decode002, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] StringUtilsGsm7Decode002 begin"); + std::string gsm7Str = "abcdefg"; + EXPECT_NE("", StringUtils::Gsm7Decode(gsm7Str)); + LBSLOGI(LOCATOR, "[GnssAbilityTest] StringUtilsGsm7Decode002 end"); +} + +HWTEST_F(GnssAbilityTest, StringUtilsGsm7Decode003, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, StringUtilsGsm7Decode003, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] StringUtilsGsm7Decode003 begin"); + std::string gsm7Str = " "; + EXPECT_NE("", StringUtils::Gsm7Decode(gsm7Str)); + LBSLOGI(LOCATOR, "[GnssAbilityTest] StringUtilsGsm7Decode003 end"); +} + +HWTEST_F(GnssAbilityTest, GnssStatusCallbackDeathRecipient001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GnssStatusCallbackDeathRecipient001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] GnssStatusCallbackDeathRecipient001 begin"); + auto gnssStatusCallbackDeathRecipient = new (std::nothrow) GnssStatusCallbackDeathRecipient(); + EXPECT_NE(nullptr, gnssStatusCallbackDeathRecipient); + wptr remote; + gnssStatusCallbackDeathRecipient->OnRemoteDied(remote); + LBSLOGI(LOCATOR, "[GnssAbilityTest] GnssStatusCallbackDeathRecipient001 end"); +} + +HWTEST_F(GnssAbilityTest, NmeaCallbackDeathRecipient001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, NmeaCallbackDeathRecipient001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] NmeaCallbackDeathRecipient001 begin"); + auto nmeaCallbackDeathRecipient = new (std::nothrow) NmeaCallbackDeathRecipient(); + EXPECT_NE(nullptr, nmeaCallbackDeathRecipient); + wptr remote; + nmeaCallbackDeathRecipient->OnRemoteDied(remote); + LBSLOGI(LOCATOR, "[GnssAbilityTest] NmeaCallbackDeathRecipient001 end"); +} + +HWTEST_F(GnssAbilityTest, CachedLocationCallbackDeathRecipient001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, CachedLocationCallbackDeathRecipient001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] CachedLocationCallbackDeathRecipient001 begin"); + auto cachedLocationCallbackDeathRecipient = new (std::nothrow) CachedLocationCallbackDeathRecipient(); + EXPECT_NE(nullptr, cachedLocationCallbackDeathRecipient); + wptr remote; + cachedLocationCallbackDeathRecipient->OnRemoteDied(remote); + LBSLOGI(LOCATOR, "[GnssAbilityTest] CachedLocationCallbackDeathRecipient001 end"); +} + +HWTEST_F(GnssAbilityTest, GnssGeofenceCallbackDeathRecipient001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, GnssGeofenceCallbackDeathRecipient001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] GnssGeofenceCallbackDeathRecipient001 begin"); + auto gnssGeofenceCallbackDeathRecipient = new (std::nothrow) GnssGeofenceCallbackDeathRecipient(); + EXPECT_NE(nullptr, gnssGeofenceCallbackDeathRecipient); + wptr remote; + gnssGeofenceCallbackDeathRecipient->OnRemoteDied(remote); + LBSLOGI(LOCATOR, "[GnssAbilityTest] GnssGeofenceCallbackDeathRecipient001 end"); +} + +HWTEST_F(GnssAbilityTest, ReConnectHdiImpl002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, ReConnectHdiImpl002, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] ReConnectHdiImpl002 begin"); + sptr gnssAbility = new (std::nothrow) GnssAbility(); + EXPECT_NE(nullptr, gnssAbility); + gnssAbility->gnssWorkingStatus_ = GNSS_WORKING_STATUS_SESSION_BEGIN; + gnssAbility->ReConnectHdiImpl(); + LBSLOGI(LOCATOR, "[GnssAbilityTest] ReConnectHdiImpl002 end"); +} + +HWTEST_F(GnssAbilityTest, AddFence002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssAbilityTest, AddFence002, TestSize.Level1"; + LBSLOGI(LOCATOR, "[GnssAbilityTest] AddFence002 begin"); + sptr gnssAbility = new (std::nothrow) GnssAbility(); + EXPECT_NE(nullptr, gnssAbility); + gnssAbility->fenceId_ = FENCE_MAX_ID + 1; + std::shared_ptr request = std::make_shared(); + gnssAbility->AddFence(request); + EXPECT_EQ(1, gnssAbility->fenceId_); + LBSLOGI(LOCATOR, "[GnssAbilityTest] AddFence002 end"); +} } // namespace Location } // namespace OHOS #endif // FEATURE_GNSS_SUPPORT diff --git a/test/location_gnss/source/gnss_event_callback_test.cpp b/test/location_gnss/source/gnss_event_callback_test.cpp new file mode 100644 index 00000000..686a1d27 --- /dev/null +++ b/test/location_gnss/source/gnss_event_callback_test.cpp @@ -0,0 +1,315 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef FEATURE_GNSS_SUPPORT +#include "gnss_event_callback_test.h" + +#include + +#include "gnss_event_callback.h" +#include "accesstoken_kit.h" +#include "message_parcel.h" +#include "nativetoken_kit.h" +#include "token_setproc.h" +#include "agnss_ni_manager.h" +#include "common_utils.h" +#include "constant_definition.h" +#include "location.h" +#include "permission_manager.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Location { +using HDI::Location::Gnss::V2_0::IGnssCallback; +using HDI::Location::Gnss::V2_0::LocationInfo; +using HDI::Location::Gnss::V2_0::ConstellationCategory; +const int32_t LOCATION_PERM_NUM = 5; +const std::string MANAGER_SETTINGS = "ohos.permission.MANAGE_SETTINGS"; +void GnssEventCallbackTest::SetUp() +{ + MockNativePermission(); +} + +void GnssEventCallbackTest::TearDown() +{} + +void GnssEventCallbackTest::MockNativePermission() +{ + const char *perms[] = { + ACCESS_LOCATION.c_str(), ACCESS_APPROXIMATELY_LOCATION.c_str(), + ACCESS_BACKGROUND_LOCATION.c_str(), MANAGE_SECURE_SETTINGS.c_str(), + MANAGER_SETTINGS.c_str(), + }; + NativeTokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = LOCATION_PERM_NUM, + .aclsNum = 0, + .dcaps = nullptr, + .perms = perms, + .acls = nullptr, + .processName = "GnssEventCallbackTest", + .aplStr = "system_basic", + }; + uint64_t tokenId = GetAccessTokenId(&infoInstance); + SetSelfTokenID(tokenId); + Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackReportLocation001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackReportLocation001, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportLocation001 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + LocationInfo locationInfo; + locationInfo.latitude = 1.0; + locationInfo.longitude = 2.0; + locationInfo.altitude = 1.0; + locationInfo.horizontalAccuracy = 1.0; + locationInfo.speed = 1.0; + locationInfo.bearing= 1.0; + locationInfo.timeForFix = 1000000000; + locationInfo.timeSinceBoot = 1000000000; + gnssCallback->ReportLocation(locationInfo); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportLocation001 end"); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackReportGnssWorkingStatus001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackReportGnssWorkingStatus001, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportGnssWorkingStatus001 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + GnssWorkingStatus status = HDI::Location::Gnss::V2_0::GNSS_WORKING_STATUS_NONE; + gnssCallback->ReportGnssWorkingStatus(status); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportGnssWorkingStatus001 end"); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackReportGnssWorkingStatus002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackReportGnssWorkingStatus002, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportGnssWorkingStatus002 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + GnssWorkingStatus status = HDI::Location::Gnss::V2_0::GNSS_WORKING_STATUS_NONE; + gnssCallback->ReportGnssWorkingStatus(status); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportGnssWorkingStatus002 end"); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackReportNmea001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackReportNmea001, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportNmea001 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + gnssCallback->ReportNmea(0, "nmea", 0); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportNmea001 end"); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackReportNmea002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackReportNmea002, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportNmea002 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + gnssCallback->ReportNmea(0, "nmea", 0); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportNmea002 end"); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackReportGnssCapabilities001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackReportGnssCapabilities001, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportGnssCapabilities001 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + GnssCapabilities capabilities = HDI::Location::Gnss::V2_0::GNSS_CAP_SUPPORT_MSB; + EXPECT_EQ(ERR_OK, gnssCallback->ReportGnssCapabilities(capabilities)); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportGnssCapabilities001 end"); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackReportGnssCapabilities002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackReportGnssCapabilities002, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportGnssCapabilities002 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + GnssCapabilities capabilities = HDI::Location::Gnss::V2_0::GNSS_CAP_SUPPORT_MSB; + EXPECT_EQ(ERR_OK, gnssCallback->ReportGnssCapabilities(capabilities)); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportGnssCapabilities002 end"); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackReportSatelliteStatusInfo002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackReportSatelliteStatusInfo002, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportSatelliteStatusInfo002 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + SatelliteStatusInfo statusInfo; + statusInfo.satellitesNumber = 0; + EXPECT_EQ(ERR_OK, gnssCallback->ReportSatelliteStatusInfo(statusInfo)); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportSatelliteStatusInfo002 end"); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackReportSatelliteStatusInfo003, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackReportSatelliteStatusInfo003, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportSatelliteStatusInfo003 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + SatelliteStatusInfo statusInfo; + statusInfo.satellitesNumber = 1; + statusInfo.elevation.push_back(12); + statusInfo.azimuths.push_back(30); + statusInfo.carrierFrequencies.push_back(40); + statusInfo.carrierToNoiseDensitys.push_back(40); + statusInfo.satelliteIds.push_back(1); + statusInfo.constellation.push_back(static_cast(1)); + statusInfo.additionalInfo.push_back( + HDI::Location::Gnss::V2_0::SATELLITES_ADDITIONAL_INFO_EPHEMERIS_DATA_EXIST); + EXPECT_EQ(ERR_OK, gnssCallback->ReportSatelliteStatusInfo(statusInfo)); + LocationInfo locationInfo; + locationInfo.latitude = 1.0; + locationInfo.longitude = 2.0; + locationInfo.altitude = 1.0; + locationInfo.horizontalAccuracy = 1.0; + locationInfo.speed = 1.0; + locationInfo.bearing= 1.0; + locationInfo.timeForFix = 1000000000; + locationInfo.timeSinceBoot = 1000000000; + EXPECT_EQ(ERR_OK, gnssCallback->ReportLocation(locationInfo)); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportSatelliteStatusInfo003 end"); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackRequestGnssReferenceInfo001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackRequestGnssReferenceInfo001, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackRequestGnssReferenceInfo001 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + GnssRefInfoType type = HDI::Location::Gnss::V2_0::GNSS_REF_INFO_TIME; + gnssCallback->RequestGnssReferenceInfo(type); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackRequestGnssReferenceInfo001 end"); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackRequestPredictGnssData001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackRequestPredictGnssData001, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackRequestPredictGnssData001 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + gnssCallback->RequestPredictGnssData(); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackRequestPredictGnssData001 end"); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackReportCachedLocation001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackReportCachedLocation001, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportCachedLocation001 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + std::vector gnssLocations; + LocationInfo locationInfo; + locationInfo.latitude = 1.0; + locationInfo.longitude = 2.0; + locationInfo.altitude = 1.0; + locationInfo.horizontalAccuracy = 1.0; + locationInfo.speed = 1.0; + locationInfo.bearing= 1.0; + locationInfo.timeForFix = 1000000000; + locationInfo.timeSinceBoot = 1000000000; + gnssLocations.push_back(locationInfo); + gnssCallback->ReportCachedLocation(gnssLocations); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportCachedLocation001 end"); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackReportGnssNiNotification001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackReportGnssNiNotification001, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportGnssNiNotification001 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + GnssNiNotificationRequest notif; + gnssCallback->ReportGnssNiNotification(notif); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportGnssNiNotification001 end"); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackReportGnssNiNotification002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackReportGnssNiNotification002, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportGnssNiNotification002 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + GnssNiNotificationRequest notif; + notif.notificationCategory = GNSS_NI_NOTIFICATION_REQUIRE_NOTIFY; + gnssCallback->ReportGnssNiNotification(notif); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportGnssNiNotification002 end"); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackReportGnssNiNotification003, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackReportGnssNiNotification003, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportGnssNiNotification003 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + GnssNiNotificationRequest notif; + notif.notificationCategory = GNSS_NI_NOTIFICATION_REQUIRE_VERIFY | GNSS_NI_NOTIFICATION_REQUIRE_NOTIFY; + gnssCallback->ReportGnssNiNotification(notif); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackReportGnssNiNotification003 end"); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackRequestGnssReferenceInfo002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackRequestGnssReferenceInfo002, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackRequestGnssReferenceInfo002 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + GnssRefInfoType type = HDI::Location::Gnss::V2_0::GNSS_REF_INFO_LOCATION; + gnssCallback->RequestGnssReferenceInfo(type); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackRequestGnssReferenceInfo002 end"); +} + +HWTEST_F(GnssEventCallbackTest, GnssEventCallbackRequestGnssReferenceInfo003, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "GnssEventCallbackTest, GnssEventCallbackRequestGnssReferenceInfo003, TestSize.Level1"; + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackRequestGnssReferenceInfo003 begin"); + sptr gnssCallback = new (std::nothrow) GnssEventCallback(); + EXPECT_NE(nullptr, gnssCallback); + GnssRefInfoType type = HDI::Location::Gnss::V2_0::GNSS_REF_INFO_BEST_LOCATION; + gnssCallback->RequestGnssReferenceInfo(type); + LBSLOGI(GNSS_TEST, "[GnssEventCallbackTest] GnssEventCallbackRequestGnssReferenceInfo003 end"); +} + +} // namespace Location +} // namespace OHOS +#endif // FEATURE_GNSS_SUPPORT diff --git a/test/location_gnss/source/gnss_interface_test.cpp b/test/location_gnss/source/gnss_interface_test.cpp new file mode 100644 index 00000000..4e108350 --- /dev/null +++ b/test/location_gnss/source/gnss_interface_test.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef FEATURE_GNSS_SUPPORT +#include "gnss_interface_test.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Location { +GnssInterfaceTest::GnssInterfaceTest() +{ +} + +GnssInterfaceTest::~GnssInterfaceTest() +{ +} + +int32_t GnssInterfaceTest::SetGnssConfigPara(const GnssConfigPara ¶) +{ + return HDF_SUCCESS; +} + +int32_t GnssInterfaceTest::EnableGnss(const sptr &callbackObj) +{ + return HDF_SUCCESS; +} + +int32_t GnssInterfaceTest::DisableGnss() +{ + return HDF_SUCCESS; +} + +int32_t GnssInterfaceTest::StartGnss(HDI::Location::Gnss::V2_0::GnssStartType type) +{ + return HDF_SUCCESS; +} + +int32_t GnssInterfaceTest::StopGnss(HDI::Location::Gnss::V2_0::GnssStartType type) +{ + return HDF_SUCCESS; +} + +int32_t GnssInterfaceTest::SetGnssReferenceInfo(const GnssRefInfo &refInfo) +{ + return HDF_SUCCESS; +} + +int32_t GnssInterfaceTest::DeleteAuxiliaryData(unsigned short data) +{ + return HDF_SUCCESS; +} + +int32_t GnssInterfaceTest::SetPredictGnssData(const std::string &data) +{ + return HDF_SUCCESS; +} + +int32_t GnssInterfaceTest::GetCachedGnssLocationsSize(int32_t &size) +{ + return HDF_SUCCESS; +} + +int32_t GnssInterfaceTest::GetCachedGnssLocations() +{ + return HDF_SUCCESS; +} + +int32_t GnssInterfaceTest::SendNiUserResponse(int32_t gnssNiNotificationId, + HDI::Location::Gnss::V2_0::GnssNiResponseCmd userResponse) +{ + return HDF_SUCCESS; +} + +int32_t GnssInterfaceTest::SendNetworkInitiatedMsg(const std::string &msg, int32_t length) +{ + return HDF_SUCCESS; +} + +int32_t GnssInterfaceTest::EnableGnssMeasurement( + const sptr &callbackObj) +{ + return HDF_SUCCESS; +} + +int32_t GnssInterfaceTest::DisableGnssMeasurement() +{ + return HDF_SUCCESS; +} +} // namespace Location +} // namespace OHOS +#endif // FEATURE_GNSS_SUPPORT diff --git a/test/location_locator/BUILD.gn b/test/location_locator/BUILD.gn index c84c9c3b..f62000c3 100644 --- a/test/location_locator/BUILD.gn +++ b/test/location_locator/BUILD.gn @@ -40,7 +40,6 @@ ohos_unittest("LocatorServiceAbilityTest") { "$LOCATION_ROOT_DIR/test/location_locator/source/locator_service_test.cpp", "$LOCATION_ROOT_DIR/test/location_locator/source/permission_manager_test.cpp", "$LOCATION_ROOT_DIR/test/location_locator/source/report_manager_test.cpp", - "$LOCATION_ROOT_DIR/test/location_locator/source/request_manager_test.cpp", "$LOCATION_ROOT_DIR/test/location_locator/source/work_record_test.cpp", ] @@ -51,14 +50,16 @@ ohos_unittest("LocatorServiceAbilityTest") { "$LOCATION_ROOT_DIR/test/mock/include", "$SUBSYSTEM_DIR/location_locator/callback/include", "$SUBSYSTEM_DIR/location_locator/locator/include", + "$LOCATION_ROOT_DIR/frameworks/js/napi/include", ] deps = [ - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", + "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", "$LOCATION_ROOT_DIR/frameworks/native/locator_agent:locator_agent", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", - "$SUBSYSTEM_DIR/location_locator/locator:lbsservice_locator", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", + "$SUBSYSTEM_DIR/location_locator/locator:lbsservice_locator_static", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -74,6 +75,7 @@ ohos_unittest("LocatorServiceAbilityTest") { "common_event_service:cesfwk_innerkits", "distributed_notification_service:ans_innerkits", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/location_locator/include/locator_msdp_monitor_manager_test.h b/test/location_locator/include/locator_msdp_monitor_manager_test.h new file mode 100644 index 00000000..9684c9e1 --- /dev/null +++ b/test/location_locator/include/locator_msdp_monitor_manager_test.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LOCATOR_MSDP_MONITOR_MANAGER_TEST_H +#define LOCATOR_MSDP_MONITOR_MANAGER_TEST_H + +#include + +#define private public +#include "locator_msdp_monitor_manager.h" +#undef private + +namespace OHOS { +namespace Location { +class LocatorMsdpMonitorManagerTest : public testing::Test { +public: + void SetUp(); + void TearDown(); +}; +} // namespace Location +} // namespace OHOS +#endif // LOCATOR_MSDP_MONITOR_MANAGER_TEST_H \ No newline at end of file diff --git a/test/location_locator/mock/include/mock_locator_callback_host.h b/test/location_locator/mock/include/mock_locator_callback_host.h index 477e14b4..4fc44e3a 100644 --- a/test/location_locator/mock/include/mock_locator_callback_host.h +++ b/test/location_locator/mock/include/mock_locator_callback_host.h @@ -23,12 +23,12 @@ #include "iremote_object.h" #include "iremote_stub.h" -#include "locator_callback_host.h" +#include "locator_callback_napi.h" #include "location.h" namespace OHOS { namespace Location { -class MockLocatorCallbackHost : public LocatorCallbackHost { +class MockLocatorCallbackHost : public LocatorCallbackNapi { public: MockLocatorCallbackHost() {} ~MockLocatorCallbackHost() {} diff --git a/test/location_locator/source/callback_test.cpp b/test/location_locator/source/callback_test.cpp index 5910775e..bf76c52e 100644 --- a/test/location_locator/source/callback_test.cpp +++ b/test/location_locator/source/callback_test.cpp @@ -18,18 +18,18 @@ #include "message_parcel.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif #include "country_code.h" -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "location.h" -#include "location_switch_callback_host.h" -#include "locator_callback_host.h" +#include "location_switch_callback_napi.h" +#include "locator_callback_napi.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #include "satellite_status.h" #endif @@ -52,7 +52,7 @@ HWTEST_F(CallbackTest, OnCacheLocationsReport001, TestSize.Level1) << "CallbackTest, OnCacheLocationsReport001, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[CallbackTest] OnCacheLocationsReport001 begin"); auto cachedLocationsCallbackHost = - sptr(new (std::nothrow) CachedLocationsCallbackHost()); + sptr(new (std::nothrow) CachedLocationsCallbackNapi()); EXPECT_NE(nullptr, cachedLocationsCallbackHost); auto cachedLocationsCallbackProxy = new (std::nothrow) CachedLocationsCallbackProxy(cachedLocationsCallbackHost); @@ -86,7 +86,7 @@ HWTEST_F(CallbackTest, OnSwitchChange001, TestSize.Level1) << "CallbackTest, OnSwitchChange001, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[CallbackTest] OnSwitchChange001 begin"); auto switchCallbackHost = - sptr(new (std::nothrow) LocationSwitchCallbackHost()); + sptr(new (std::nothrow) LocationSwitchCallbackNapi()); EXPECT_NE(nullptr, switchCallbackHost); auto switchCallbackProxy = new (std::nothrow) SwitchCallbackProxy(switchCallbackHost); @@ -103,7 +103,7 @@ HWTEST_F(CallbackTest, OnMessageChange001, TestSize.Level1) << "CallbackTest, OnMessageChange001, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[CallbackTest] OnMessageChange001 begin"); auto nmeaCallbackHost = - sptr(new (std::nothrow) NmeaMessageCallbackHost()); + sptr(new (std::nothrow) NmeaMessageCallbackNapi()); EXPECT_NE(nullptr, nmeaCallbackHost); auto nmeaCallbackProxy = new (std::nothrow) NmeaMessageCallbackProxy(nmeaCallbackHost); @@ -121,7 +121,7 @@ HWTEST_F(CallbackTest, LocationCallbackProxy001, TestSize.Level1) << "CallbackTest, LocationCallbackProxy001, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[CallbackTest] LocationCallbackProxy001 begin"); auto locatorCallbackHost = - sptr(new (std::nothrow) LocatorCallbackHost()); + sptr(new (std::nothrow) LocatorCallbackNapi()); EXPECT_NE(nullptr, locatorCallbackHost); auto locatorCallbackProxy = new (std::nothrow) LocatorCallbackProxy(locatorCallbackHost); @@ -136,7 +136,7 @@ HWTEST_F(CallbackTest, LocationCallbackProxy002, TestSize.Level1) << "CallbackTest, LocationCallbackProxy002, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[CallbackTest] LocationCallbackProxy002 begin"); auto locatorCallbackHost = - sptr(new (std::nothrow) LocatorCallbackHost()); + sptr(new (std::nothrow) LocatorCallbackNapi()); EXPECT_NE(nullptr, locatorCallbackHost); auto locatorCallbackProxy = new (std::nothrow) LocatorCallbackProxy(locatorCallbackHost); @@ -152,7 +152,7 @@ HWTEST_F(CallbackTest, LocationCallbackProxy003, TestSize.Level1) << "CallbackTest, LocationCallbackProxy003, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[CallbackTest] LocationCallbackProxy003 begin"); auto locatorCallbackHost = - sptr(new (std::nothrow) LocatorCallbackHost()); + sptr(new (std::nothrow) LocatorCallbackNapi()); EXPECT_NE(nullptr, locatorCallbackHost); auto locatorCallbackProxy = new (std::nothrow) LocatorCallbackProxy(locatorCallbackHost); @@ -169,7 +169,7 @@ HWTEST_F(CallbackTest, GnssStatusCallbackProxy001, TestSize.Level1) << "CallbackTest, GnssStatusCallbackProxy001, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[CallbackTest] GnssStatusCallbackProxy001 begin"); auto gnssStatusCallbackHost = - sptr(new (std::nothrow) GnssStatusCallbackHost()); + sptr(new (std::nothrow) GnssStatusCallbackNapi()); EXPECT_NE(nullptr, gnssStatusCallbackHost); auto gnssStatusCallbackProxy = new (std::nothrow) GnssStatusCallbackProxy(gnssStatusCallbackHost); @@ -199,7 +199,7 @@ HWTEST_F(CallbackTest, GnssStatusCallbackProxy002, TestSize.Level1) << "CallbackTest, GnssStatusCallbackProxy002, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[CallbackTest] GnssStatusCallbackProxy002 begin"); auto gnssStatusCallbackHost = - sptr(new (std::nothrow) GnssStatusCallbackHost()); + sptr(new (std::nothrow) GnssStatusCallbackNapi()); EXPECT_NE(nullptr, gnssStatusCallbackHost); auto gnssStatusCallbackProxy = new (std::nothrow) GnssStatusCallbackProxy(gnssStatusCallbackHost); @@ -215,7 +215,7 @@ HWTEST_F(CallbackTest, CountryCodeCallbackProxy001, TestSize.Level1) << "CallbackTest, CountryCodeCallbackProxy001, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[CallbackTest] CountryCodeCallbackProxy001 begin"); auto countryCodeCallbackHost = - sptr(new (std::nothrow) CountryCodeCallbackHost()); + sptr(new (std::nothrow) CountryCodeCallbackNapi()); EXPECT_NE(nullptr, countryCodeCallbackHost); auto countryCodeCallbackProxy = new (std::nothrow) CountryCodeCallbackProxy(countryCodeCallbackHost); @@ -237,7 +237,7 @@ HWTEST_F(CallbackTest, CachedLocationsCallbackHost001, TestSize.Level1) << "CallbackTest, CachedLocationsCallbackHost001, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[CallbackTest] CachedLocationsCallbackHost001 begin"); auto cachedCallbackHost = - sptr(new (std::nothrow) CachedLocationsCallbackHost()); + sptr(new (std::nothrow) CachedLocationsCallbackNapi()); EXPECT_NE(nullptr, cachedCallbackHost); EXPECT_NE(true, cachedCallbackHost->IsRemoteDied()); @@ -255,7 +255,7 @@ HWTEST_F(CallbackTest, CountryCodeCallbackHost001, TestSize.Level1) << "CallbackTest, CountryCodeCallbackHost001, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[CallbackTest] CountryCodeCallbackHost001 begin"); auto callbackHost = - sptr(new (std::nothrow) CountryCodeCallbackHost()); + sptr(new (std::nothrow) CountryCodeCallbackNapi()); EXPECT_NE(nullptr, callbackHost); callbackHost->SetEnv(nullptr); callbackHost->SetCallback(nullptr); @@ -270,7 +270,7 @@ HWTEST_F(CallbackTest, GnssStatusCallbackHost001, TestSize.Level1) << "CallbackTest, GnssStatusCallbackHost001, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[CallbackTest] GnssStatusCallbackHost001 begin"); auto gnssCallbackHost = - sptr(new (std::nothrow) GnssStatusCallbackHost()); + sptr(new (std::nothrow) GnssStatusCallbackNapi()); EXPECT_NE(true, gnssCallbackHost->IsRemoteDied()); gnssCallbackHost->OnStatusChange(nullptr); gnssCallbackHost->DeleteHandler(); @@ -284,7 +284,7 @@ HWTEST_F(CallbackTest, LocationSwitchCallbackHost001, TestSize.Level1) << "CallbackTest, LocationSwitchCallbackHost001, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[CallbackTest] LocationSwitchCallbackHost001 begin"); auto switchCallbackHost = - sptr(new (std::nothrow) LocationSwitchCallbackHost()); + sptr(new (std::nothrow) LocationSwitchCallbackNapi()); EXPECT_NE(true, switchCallbackHost->IsRemoteDied()); switchCallbackHost->PackResult(true); switchCallbackHost->DeleteHandler(); @@ -297,8 +297,8 @@ HWTEST_F(CallbackTest, LocationCallbackHost001, TestSize.Level1) << "CallbackTest, LocationCallbackHost001, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[CallbackTest] LocationCallbackHost001 begin"); auto callbackHost = - sptr(new (std::nothrow) LocatorCallbackHost()); - + sptr(new (std::nothrow) LocatorCallbackNapi()); + std::unique_ptr location = std::make_unique(); EXPECT_NE(true, callbackHost->IsSystemGeoLocationApi()); EXPECT_NE(true, callbackHost->IsSingleLocationRequest()); @@ -317,7 +317,7 @@ HWTEST_F(CallbackTest, NmeaMessageCallbackHost001, TestSize.Level1) << "CallbackTest, NmeaMessageCallbackHost001, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[CallbackTest] NmeaMessageCallbackHost001 begin"); auto nmeaCallbackHost = - sptr(new (std::nothrow) NmeaMessageCallbackHost()); + sptr(new (std::nothrow) NmeaMessageCallbackNapi()); EXPECT_NE(true, nmeaCallbackHost->IsRemoteDied()); nmeaCallbackHost->PackResult("msg"); nmeaCallbackHost->DeleteHandler(); @@ -331,7 +331,7 @@ HWTEST_F(CallbackTest, CountryCodeCallbackProxy002, TestSize.Level1) << "CallbackTest, CountryCodeCallbackProxy002, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[CallbackTest] CountryCodeCallbackProxy002 begin"); auto countryCodeCallbackHost = - sptr(new (std::nothrow) CountryCodeCallbackHost()); + sptr(new (std::nothrow) CountryCodeCallbackNapi()); EXPECT_NE(nullptr, countryCodeCallbackHost); auto countryCodeCallbackProxy = new (std::nothrow) CountryCodeCallbackProxy(countryCodeCallbackHost); diff --git a/test/location_locator/source/country_code_manager_test.cpp b/test/location_locator/source/country_code_manager_test.cpp index d9a1693b..f8ce5fd9 100644 --- a/test/location_locator/source/country_code_manager_test.cpp +++ b/test/location_locator/source/country_code_manager_test.cpp @@ -15,10 +15,10 @@ #include "country_code_manager_test.h" -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #include "location_log.h" -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" using namespace testing::ext; namespace OHOS { @@ -50,10 +50,10 @@ HWTEST_F(CountryCodeManagerTest, UnregisterCountryCodeCallback001, TestSize.Leve << "CountryCodeManagerTest, UnregisterCountryCodeCallback001, TestSize.Level1"; LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] UnregisterCountryCodeCallback001 begin"); auto countryCodeManager = CountryCodeManager::GetInstance(); - auto callback = sptr(new (std::nothrow) CountryCodeCallbackHost()); + auto callback = sptr(new (std::nothrow) CountryCodeCallbackNapi()); ASSERT_TRUE(countryCodeManager != nullptr); countryCodeManager->UnregisterCountryCodeCallback(callback); - EXPECT_EQ(0, countryCodeManager->countryCodeCallback_->size()); + EXPECT_EQ(0, countryCodeManager->countryCodeCallbacks_.size()); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] UnregisterCountryCodeCallback001 end"); } @@ -65,7 +65,7 @@ HWTEST_F(CountryCodeManagerTest, UnregisterCountryCodeCallback002, TestSize.Leve auto countryCodeManager = CountryCodeManager::GetInstance(); ASSERT_TRUE(countryCodeManager != nullptr); countryCodeManager->UnregisterCountryCodeCallback(nullptr); - EXPECT_EQ(0, countryCodeManager->countryCodeCallback_->size()); + EXPECT_EQ(0, countryCodeManager->countryCodeCallbacks_.size()); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] UnregisterCountryCodeCallback002 end"); } @@ -76,9 +76,9 @@ HWTEST_F(CountryCodeManagerTest, UnregisterCountryCodeCallback003, TestSize.Leve LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] UnregisterCountryCodeCallback003 begin"); auto countryCodeManager = CountryCodeManager::GetInstance(); ASSERT_TRUE(countryCodeManager != nullptr); - auto wrongCallback = sptr(new (std::nothrow) NmeaMessageCallbackHost()); + auto wrongCallback = sptr(new (std::nothrow) NmeaMessageCallbackNapi()); countryCodeManager->UnregisterCountryCodeCallback(wrongCallback->AsObject()); - EXPECT_EQ(0, countryCodeManager->countryCodeCallback_->size()); + EXPECT_EQ(0, countryCodeManager->countryCodeCallbacks_.size()); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] UnregisterCountryCodeCallback003 end"); } @@ -89,15 +89,15 @@ HWTEST_F(CountryCodeManagerTest, UnregisterCountryCodeCallback004, TestSize.Leve LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] UnregisterCountryCodeCallback004 begin"); auto countryCodeManager = CountryCodeManager::GetInstance(); ASSERT_TRUE(countryCodeManager != nullptr); - auto callback1 = sptr(new (std::nothrow) CountryCodeCallbackHost()); + auto callback1 = sptr(new (std::nothrow) CountryCodeCallbackNapi()); countryCodeManager->RegisterCountryCodeCallback(callback1, 0); - auto callback2 = sptr(new (std::nothrow) CountryCodeCallbackHost()); + auto callback2 = sptr(new (std::nothrow) CountryCodeCallbackNapi()); countryCodeManager->RegisterCountryCodeCallback(callback2, 1); countryCodeManager->UnregisterCountryCodeCallback(callback1); // size != 0, func will return - EXPECT_EQ(1, countryCodeManager->countryCodeCallback_->size()); + EXPECT_EQ(1, countryCodeManager->countryCodeCallbacks_.size()); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] UnregisterCountryCodeCallback004 end"); } @@ -107,9 +107,9 @@ HWTEST_F(CountryCodeManagerTest, RegisterCountryCodeCallback001, TestSize.Level1 << "CountryCodeManagerTest, RegisterCountryCodeCallback001, TestSize.Level1"; LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] RegisterCountryCodeCallback001 begin"); auto countryCodeManager = CountryCodeManager::GetInstance(); - auto callback = sptr(new (std::nothrow) CountryCodeCallbackHost()); + auto callback = sptr(new (std::nothrow) CountryCodeCallbackNapi()); countryCodeManager->RegisterCountryCodeCallback(callback, 0); - EXPECT_NE(0, countryCodeManager->countryCodeCallback_->size()); + EXPECT_NE(0, countryCodeManager->countryCodeCallbacks_.size()); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] RegisterCountryCodeCallback001 end"); } @@ -121,7 +121,7 @@ HWTEST_F(CountryCodeManagerTest, RegisterCountryCodeCallback002, TestSize.Level1 auto countryCodeManager = CountryCodeManager::GetInstance(); ASSERT_TRUE(countryCodeManager != nullptr); countryCodeManager->RegisterCountryCodeCallback(nullptr, 0); - EXPECT_EQ(2, countryCodeManager->countryCodeCallback_->size()); + EXPECT_EQ(2, countryCodeManager->countryCodeCallbacks_.size()); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] RegisterCountryCodeCallback002 end"); } @@ -132,9 +132,9 @@ HWTEST_F(CountryCodeManagerTest, RegisterCountryCodeCallback003, TestSize.Level1 LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] RegisterCountryCodeCallback003 begin"); auto countryCodeManager = CountryCodeManager::GetInstance(); ASSERT_TRUE(countryCodeManager != nullptr); - auto wrongCallback = sptr(new (std::nothrow) NmeaMessageCallbackHost()); + auto wrongCallback = sptr(new (std::nothrow) NmeaMessageCallbackNapi()); countryCodeManager->RegisterCountryCodeCallback(wrongCallback->AsObject(), 0); - EXPECT_EQ(2, countryCodeManager->countryCodeCallback_->size()); + EXPECT_EQ(2, countryCodeManager->countryCodeCallbacks_.size()); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] RegisterCountryCodeCallback003 end"); } @@ -144,7 +144,7 @@ HWTEST_F(CountryCodeManagerTest, ReSubscribeEvent001, TestSize.Level1) << "CountryCodeManagerTest, ReSubscribeEvent001, TestSize.Level1"; LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReSubscribeEvent001 begin"); auto countryCodeManager = CountryCodeManager::GetInstance(); - EXPECT_EQ(2, countryCodeManager->countryCodeCallback_->size()); + EXPECT_EQ(2, countryCodeManager->countryCodeCallbacks_.size()); countryCodeManager->ReSubscribeEvent(); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReSubscribeEvent001 end"); } @@ -155,9 +155,9 @@ HWTEST_F(CountryCodeManagerTest, ReSubscribeEvent002, TestSize.Level1) << "CountryCodeManagerTest, ReSubscribeEvent002, TestSize.Level1"; LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReSubscribeEvent002 begin"); auto countryCodeManager = CountryCodeManager::GetInstance(); - auto callback = sptr(new (std::nothrow) CountryCodeCallbackHost()); + auto callback = sptr(new (std::nothrow) CountryCodeCallbackNapi()); countryCodeManager->RegisterCountryCodeCallback(callback, 0); - EXPECT_NE(0, countryCodeManager->countryCodeCallback_->size()); + EXPECT_NE(0, countryCodeManager->countryCodeCallbacks_.size()); countryCodeManager->ReSubscribeEvent(); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReSubscribeEvent002 end"); } @@ -168,7 +168,7 @@ HWTEST_F(CountryCodeManagerTest, ReUnsubscribeEvent001, TestSize.Level1) << "CountryCodeManagerTest, ReUnsubscribeEvent001, TestSize.Level1"; LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReUnsubscribeEvent001 begin"); auto countryCodeManager = CountryCodeManager::GetInstance(); - EXPECT_EQ(2, countryCodeManager->countryCodeCallback_->size()); + EXPECT_EQ(3, countryCodeManager->countryCodeCallbacks_.size()); countryCodeManager->ReUnsubscribeEvent(); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReUnsubscribeEvent001 end"); } @@ -179,9 +179,9 @@ HWTEST_F(CountryCodeManagerTest, ReUnsubscribeEvent002, TestSize.Level1) << "CountryCodeManagerTest, ReUnsubscribeEvent002, TestSize.Level1"; LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReUnsubscribeEvent002 begin"); auto countryCodeManager = CountryCodeManager::GetInstance(); - auto callback = sptr(new (std::nothrow) CountryCodeCallbackHost()); + auto callback = sptr(new (std::nothrow) CountryCodeCallbackNapi()); countryCodeManager->RegisterCountryCodeCallback(callback, 0); - EXPECT_NE(0, countryCodeManager->countryCodeCallback_->size()); + EXPECT_NE(0, countryCodeManager->countryCodeCallbacks_.size()); countryCodeManager->ReUnsubscribeEvent(); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReUnsubscribeEvent002 end"); } @@ -193,11 +193,11 @@ HWTEST_F(CountryCodeManagerTest, NotifyAllListener001, TestSize.Level1) LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] NotifyAllListener001 begin"); auto countryCodeManager = CountryCodeManager::GetInstance(); ASSERT_TRUE(countryCodeManager != nullptr); - auto callback = sptr(new (std::nothrow) CountryCodeCallbackHost()); + auto callback = sptr(new (std::nothrow) CountryCodeCallbackNapi()); sptr countryCodeCallback1 = iface_cast(callback); - countryCodeManager->countryCodeCallback_->insert(std::make_pair(0, countryCodeCallback1)); + countryCodeManager->countryCodeCallbacks_.push_back(countryCodeCallback1); sptr countryCodeCallback2 = nullptr; - countryCodeManager->countryCodeCallback_->insert(std::make_pair(1, countryCodeCallback2)); + countryCodeManager->countryCodeCallbacks_.push_back(countryCodeCallback2); countryCodeManager->NotifyAllListener(); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] NotifyAllListener001 end"); } @@ -267,7 +267,7 @@ HWTEST_F(CountryCodeManagerTest, OnLocationReport001, TestSize.Level1) sptr(new (std::nothrow) CountryCodeManager::LocatorCallback()); ASSERT_TRUE(callback != nullptr); callback->OnLocationReport(nullptr); - + std::unique_ptr location = std::make_unique(); callback->OnLocationReport(location); callback->OnLocatingStatusChange(1); diff --git a/test/location_locator/source/fusion_controller_test.cpp b/test/location_locator/source/fusion_controller_test.cpp index 4ee4c5a9..abad2ea5 100644 --- a/test/location_locator/source/fusion_controller_test.cpp +++ b/test/location_locator/source/fusion_controller_test.cpp @@ -23,6 +23,8 @@ using namespace testing::ext; namespace OHOS { namespace Location { const int UNKNOWN_TYPE = 0; +const int64_t NANOS_PER_MILLI = 1000000L; +const int64_t MILLI_PER_SECS = 1000L; const uint32_t FUSION_DEFAULT_FLAG = 0; const uint32_t FUSION_BASE_FLAG = 1; const uint32_t REPORT_FUSED_LOCATION_FLAG = FUSION_BASE_FLAG; @@ -34,6 +36,8 @@ void FusionControllerTest::SetUp() void FusionControllerTest::TearDown() { + fusionController_->fusedFlag_ = 0; + fusionController_->needReset_ = true; fusionController_ = nullptr; } @@ -203,9 +207,43 @@ HWTEST_F(FusionControllerTest, GetFuseLocation001, TestSize.Level1) LBSLOGI(FUSION_CONTROLLER, "[FusionControllerTest] GetFuseLocation001 begin"); std::unique_ptr location = std::make_unique(); sptr lastFuseLocation = new (std::nothrow) Location(); - + location->SetLocationSourceType(LocationSourceType::INDOOR_TYPE); EXPECT_NE(nullptr, fusionController_->GetFuseLocation(location, lastFuseLocation)); LBSLOGI(FUSION_CONTROLLER, "[FusionControllerTest] GetFuseLocation001 end"); } + +HWTEST_F(FusionControllerTest, GetFuseLocation002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "FusionControllerTest, GetFuseLocation002, TestSize.Level1"; + LBSLOGI(FUSION_CONTROLLER, "[FusionControllerTest] GetFuseLocation002 begin"); + std::unique_ptr location = std::make_unique(); + sptr lastFuseLocation = new (std::nothrow) Location(); + location->SetLocationSourceType(LocationSourceType::GNSS_TYPE); + int64_t seconds1 = 1718276948; + int64_t seconds2 = 1718276945; + location->SetTimeSinceBoot(seconds1 * MILLI_PER_SECS * NANOS_PER_MILLI); + lastFuseLocation->SetLocationSourceType(LocationSourceType::INDOOR_TYPE); + lastFuseLocation->SetTimeSinceBoot(seconds2 * MILLI_PER_SECS * NANOS_PER_MILLI); + EXPECT_NE(nullptr, fusionController_->GetFuseLocation(location, lastFuseLocation)); + LBSLOGI(FUSION_CONTROLLER, "[FusionControllerTest] GetFuseLocation002 end"); +} + +HWTEST_F(FusionControllerTest, GetFuseLocation003, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "FusionControllerTest, GetFuseLocation003, TestSize.Level1"; + LBSLOGI(FUSION_CONTROLLER, "[FusionControllerTest] GetFuseLocation003 begin"); + std::unique_ptr location = std::make_unique(); + sptr lastFuseLocation = new (std::nothrow) Location(); + location->SetLocationSourceType(LocationSourceType::NETWORK_TYPE); + int64_t seconds1 = 1718276948; + int64_t seconds2 = 1718276945; + location->SetTimeSinceBoot(seconds1 * MILLI_PER_SECS * NANOS_PER_MILLI); + lastFuseLocation->SetLocationSourceType(LocationSourceType::GNSS_TYPE); + lastFuseLocation->SetTimeSinceBoot(seconds2 * MILLI_PER_SECS * NANOS_PER_MILLI); + EXPECT_NE(nullptr, fusionController_->GetFuseLocation(location, lastFuseLocation)); + LBSLOGI(FUSION_CONTROLLER, "[FusionControllerTest] GetFuseLocation003 end"); +} } // namespace Location } // namespace OHOS \ No newline at end of file diff --git a/test/location_locator/source/location_approximately_permission_test.cpp b/test/location_locator/source/location_approximately_permission_test.cpp index 6c2815a5..3dd75601 100644 --- a/test/location_locator/source/location_approximately_permission_test.cpp +++ b/test/location_locator/source/location_approximately_permission_test.cpp @@ -83,9 +83,11 @@ HWTEST_F(LocationApproximatelyPermissionTest, ReportManagerApproximatelyLocation location->ReadFromParcel(parcel); auto newLocation = reportManager_->GetPermittedLocation(request, location); EXPECT_NE(nullptr, newLocation); - EXPECT_EQ(MAX_LATITUDE, newLocation->GetLatitude()); - EXPECT_EQ(MAX_LONGITUDE, newLocation->GetLongitude()); - EXPECT_EQ(DEFAULT_APPROXIMATELY_ACCURACY, newLocation->GetAccuracy()); + if (newLocation != nullptr) { + EXPECT_EQ(MAX_LATITUDE, newLocation->GetLatitude()); + EXPECT_EQ(MAX_LONGITUDE, newLocation->GetLongitude()); + EXPECT_EQ(DEFAULT_APPROXIMATELY_ACCURACY, newLocation->GetAccuracy()); + } } HWTEST_F(LocationApproximatelyPermissionTest, ReportManagerApproximatelyLocationTest002, TestSize.Level1) @@ -109,9 +111,11 @@ HWTEST_F(LocationApproximatelyPermissionTest, ReportManagerApproximatelyLocation location->ReadFromParcel(parcel); auto newLocation = reportManager_->GetPermittedLocation(request, location); EXPECT_NE(nullptr, newLocation); - EXPECT_EQ(-MAX_LATITUDE, newLocation->GetLatitude()); - EXPECT_EQ(-MAX_LONGITUDE, newLocation->GetLongitude()); - EXPECT_EQ(DEFAULT_APPROXIMATELY_ACCURACY, newLocation->GetAccuracy()); + if (newLocation != nullptr) { + EXPECT_EQ(-MAX_LATITUDE, newLocation->GetLatitude()); + EXPECT_EQ(-MAX_LONGITUDE, newLocation->GetLongitude()); + EXPECT_EQ(DEFAULT_APPROXIMATELY_ACCURACY, newLocation->GetAccuracy()); + } } } // namespace Location } // namespace OHOS \ No newline at end of file diff --git a/test/location_locator/source/location_config_manager_test.cpp b/test/location_locator/source/location_config_manager_test.cpp index 5e249f58..7df60f6f 100644 --- a/test/location_locator/source/location_config_manager_test.cpp +++ b/test/location_locator/source/location_config_manager_test.cpp @@ -164,5 +164,52 @@ HWTEST_F(LocationConfigManagerTest, LocationConfigManagerGetAgnssServerPortTest0 LocationConfigManager::GetInstance()->GetAgnssServerPort(); LBSLOGI(LOCATOR, "[LocationConfigManagerTest] LocationConfigManagerGetAgnssServerPortTest001 end"); } + +HWTEST_F(LocationConfigManagerTest, GenerateStartCommand001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationConfigManagerTest, GenerateStartCommand001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationConfigManagerTest] GenerateStartCommand001 begin"); + LocationConfigManager::GetInstance()->GenerateStartCommand(); + LBSLOGI(LOCATOR, "[LocationConfigManagerTest] GenerateStartCommand001 end"); +} + +HWTEST_F(LocationConfigManagerTest, OpenPrivacyDialog001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationConfigManagerTest, OpenPrivacyDialog001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationConfigManagerTest] OpenPrivacyDialog001 begin"); + LocationConfigManager::GetInstance()->OpenPrivacyDialog(); + LBSLOGI(LOCATOR, "[LocationConfigManagerTest] OpenPrivacyDialog001 end"); +} + +HWTEST_F(LocationConfigManagerTest, ConnectExtensionAbility001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationConfigManagerTest, ConnectExtensionAbility001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationConfigManagerTest] ConnectExtensionAbility001 begin"); + AAFwk::Want want; + std::string connectStr = LocationConfigManager::GetInstance()->GenerateStartCommand(); + LocationConfigManager::GetInstance()->ConnectExtensionAbility(want, connectStr); + LBSLOGI(LOCATOR, "[LocationConfigManagerTest] ConnectExtensionAbility001 end"); +} + +HWTEST_F(LocationConfigManagerTest, SetCachePrivacyType001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationConfigManagerTest, SetCachePrivacyType001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationConfigManagerTest] SetCachePrivacyType001 begin"); + LocationConfigManager::GetInstance()->SetCachePrivacyType(111); + LBSLOGI(LOCATOR, "[LocationConfigManagerTest] SetCachePrivacyType001 end"); +} + +HWTEST_F(LocationConfigManagerTest, GetCachePrivacyType001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationConfigManagerTest, GetCachePrivacyType001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationConfigManagerTest] GetCachePrivacyType001 begin"); + LocationConfigManager::GetInstance()->GetCachePrivacyType(); + LBSLOGI(LOCATOR, "[LocationConfigManagerTest] GetCachePrivacyType001 end"); +} } // namespace Location } // namespace OHOS \ No newline at end of file diff --git a/test/location_locator/source/location_without_permission_test.cpp b/test/location_locator/source/location_without_permission_test.cpp index f11d3ae3..7f2f277a 100644 --- a/test/location_locator/source/location_without_permission_test.cpp +++ b/test/location_locator/source/location_without_permission_test.cpp @@ -21,25 +21,25 @@ #include "token_setproc.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif #include "constant_definition.h" #ifdef FEATURE_GEOCODE_SUPPORT #include "geo_address.h" #endif #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #include "i_cached_locations_callback.h" #endif #include "i_locator_callback.h" -#include "location_switch_callback_host.h" +#include "location_switch_callback_napi.h" #include "locator.h" #include "location_log.h" #include "locator_callback_proxy.h" #include "locator_impl.h" #include "geofence_sdk.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif #include "request_config.h" #include "permission_manager.h" @@ -86,7 +86,7 @@ HWTEST_F(LocationWithoutPermissionTest, LocatorWithoutSettingsPermission001, Tes auto locatorImpl = Locator::GetInstance(); EXPECT_NE(nullptr, locatorImpl); auto switchCallbackHost = - sptr(new (std::nothrow) LocationSwitchCallbackHost()); + sptr(new (std::nothrow) LocationSwitchCallbackNapi()); EXPECT_NE(nullptr, switchCallbackHost); EXPECT_EQ(true, locatorImpl->RegisterSwitchCallback(switchCallbackHost->AsObject(), 1000)); EXPECT_EQ(true, locatorImpl->UnregisterSwitchCallback(switchCallbackHost->AsObject())); @@ -132,13 +132,13 @@ HWTEST_F(LocationWithoutPermissionTest, LocatorWithoutLocationPermission002, Tes EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl->IsLocationEnabledV9(state)); #ifdef FEATURE_GNSS_SUPPORT auto gnssCallbackHost = - sptr(new (std::nothrow) GnssStatusCallbackHost()); + sptr(new (std::nothrow) GnssStatusCallbackNapi()); EXPECT_NE(nullptr, gnssCallbackHost); EXPECT_EQ(true, locatorImpl->RegisterGnssStatusCallback(gnssCallbackHost->AsObject(), 1000)); EXPECT_EQ(true, locatorImpl->UnregisterGnssStatusCallback(gnssCallbackHost->AsObject())); auto nmeaCallbackHost = - sptr(new (std::nothrow) NmeaMessageCallbackHost()); + sptr(new (std::nothrow) NmeaMessageCallbackNapi()); EXPECT_NE(nullptr, nmeaCallbackHost); EXPECT_EQ(true, locatorImpl->RegisterNmeaMessageCallback(nmeaCallbackHost->AsObject(), 1000)); EXPECT_EQ(true, locatorImpl->UnregisterNmeaMessageCallback(nmeaCallbackHost->AsObject())); @@ -148,8 +148,6 @@ HWTEST_F(LocationWithoutPermissionTest, LocatorWithoutLocationPermission002, Tes #ifdef FEATURE_GNSS_SUPPORT if (state) { EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->FlushCachedGnssLocations()); - } else { - EXPECT_EQ(ERRCODE_SWITCH_OFF, locatorImpl->FlushCachedGnssLocations()); } #endif LBSLOGI(LOCATOR, "[LocationWithoutPermissionTest] LocatorWithoutLocationPermission002 end"); @@ -166,7 +164,7 @@ HWTEST_F(LocationWithoutPermissionTest, LocatorWithoutLocationPermission003, Tes locatorImpl->GetCachedGnssLocationsSize(); auto cachedLocationsCallbackHost = - sptr(new (std::nothrow) CachedLocationsCallbackHost()); + sptr(new (std::nothrow) CachedLocationsCallbackNapi()); EXPECT_NE(nullptr, cachedLocationsCallbackHost); auto cachedCallback = sptr(cachedLocationsCallbackHost); EXPECT_NE(nullptr, cachedCallback); @@ -208,18 +206,13 @@ HWTEST_F(LocationWithoutPermissionTest, LocatorWithoutLocationPermissionV9001, T sptr callbackStub = new (std::nothrow) LocatorCallbackStub(); if (state) { EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->StartLocatingV9(requestConfig, callbackStub)); - } else { - EXPECT_EQ(ERRCODE_SWITCH_OFF, locatorImpl->StartLocatingV9(requestConfig, callbackStub)); } EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->StopLocatingV9(callbackStub)); std::unique_ptr loc = std::make_unique(); if (state) { EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->GetCachedLocationV9(loc)); - } else { - EXPECT_EQ(ERRCODE_SWITCH_OFF, locatorImpl->GetCachedLocationV9(loc)); } - EXPECT_EQ(nullptr, loc); LBSLOGI(LOCATOR, "[LocationWithoutPermissionTest] LocatorWithoutLocationPermissionV9001 end"); } @@ -235,28 +228,22 @@ HWTEST_F(LocationWithoutPermissionTest, LocatorWithoutLocationPermissionV9002, T EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl->IsLocationEnabledV9(state)); #ifdef FEATURE_GNSS_SUPPORT auto gnssCallbackHost = - sptr(new (std::nothrow) GnssStatusCallbackHost()); + sptr(new (std::nothrow) GnssStatusCallbackNapi()); EXPECT_NE(nullptr, gnssCallbackHost); if (state) { EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->RegisterGnssStatusCallbackV9(gnssCallbackHost->AsObject())); - } else { - EXPECT_EQ(ERRCODE_SWITCH_OFF, locatorImpl->RegisterGnssStatusCallbackV9(gnssCallbackHost->AsObject())); } EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->UnregisterGnssStatusCallbackV9(gnssCallbackHost->AsObject())); auto nmeaCallbackHost = - sptr(new (std::nothrow) NmeaMessageCallbackHost()); + sptr(new (std::nothrow) NmeaMessageCallbackNapi()); EXPECT_NE(nullptr, nmeaCallbackHost); if (state) { EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->RegisterNmeaMessageCallbackV9(nmeaCallbackHost->AsObject())); - } else { - EXPECT_EQ(ERRCODE_SWITCH_OFF, locatorImpl->RegisterNmeaMessageCallbackV9(nmeaCallbackHost->AsObject())); } EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->UnregisterNmeaMessageCallbackV9(nmeaCallbackHost->AsObject())); if (state) { EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->FlushCachedGnssLocationsV9()); - } else { - EXPECT_EQ(ERRCODE_SWITCH_OFF, locatorImpl->FlushCachedGnssLocationsV9()); } #endif std::set pidList; @@ -265,5 +252,59 @@ HWTEST_F(LocationWithoutPermissionTest, LocatorWithoutLocationPermissionV9002, T EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->ResetAllProxy()); LBSLOGI(LOCATOR, "[LocationWithoutPermissionTest] LocatorWithoutLocationPermissionV9002 end"); } + +HWTEST_F(LocationWithoutPermissionTest, LocatorWithoutLocationPermissionV9003, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocationWithoutPermissionTest, LocatorWithoutLocationPermissionV9003, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocationWithoutPermissionTest] LocatorWithoutLocationPermissionV9003 begin"); + auto locatorImpl = Locator::GetInstance(); + auto geofenceSdk = GeofenceManager::GetInstance(); + EXPECT_NE(nullptr, locatorImpl); + + bool state = false; + EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl->IsLocationEnabledV9(state)); +#ifdef FEATURE_GNSS_SUPPORT + 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) { + EXPECT_EQ(ERRCODE_PERMISSION_DENIED, geofenceSdk->AddFenceV9(fenceRequest)); + EXPECT_EQ(ERRCODE_PERMISSION_DENIED, geofenceSdk->RemoveFenceV9(fenceRequest)); + } else { + EXPECT_EQ(ERRCODE_SWITCH_OFF, geofenceSdk->AddFenceV9(fenceRequest)); + EXPECT_EQ(ERRCODE_SWITCH_OFF, geofenceSdk->RemoveFenceV9(fenceRequest)); + } + + int size = -1; + if (state) { + EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->GetCachedGnssLocationsSizeV9(size)); + } else { + EXPECT_EQ(ERRCODE_SWITCH_OFF, locatorImpl->GetCachedGnssLocationsSizeV9(size)); + } + EXPECT_EQ(0, size); + + auto cachedLocationsCallbackHost = + sptr(new (std::nothrow) CachedLocationsCallbackNapi()); + EXPECT_NE(nullptr, cachedLocationsCallbackHost); + auto cachedCallback = sptr(cachedLocationsCallbackHost); + EXPECT_NE(nullptr, cachedCallback); + auto request = std::make_unique(); + EXPECT_NE(nullptr, request); + request->reportingPeriodSec = 10; + request->wakeUpCacheQueueFull = true; + if (state) { + EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->RegisterCachedLocationCallbackV9(request, cachedCallback)); + } else { + EXPECT_EQ(ERRCODE_SWITCH_OFF, locatorImpl->RegisterCachedLocationCallbackV9(request, cachedCallback)); + } + EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->UnregisterCachedLocationCallbackV9(cachedCallback)); +#endif + LBSLOGI(LOCATOR, "[LocationWithoutPermissionTest] LocatorWithoutLocationPermissionV9003 end"); +} } // namespace Location } // namespace OHOS \ No newline at end of file diff --git a/test/location_locator/source/locator_background_proxy_test.cpp b/test/location_locator/source/locator_background_proxy_test.cpp index 97c58f49..f53e6e1a 100644 --- a/test/location_locator/source/locator_background_proxy_test.cpp +++ b/test/location_locator/source/locator_background_proxy_test.cpp @@ -35,7 +35,7 @@ #include "constant_definition.h" #include "location.h" #include "location_log.h" -#include "locator_callback_host.h" +#include "locator_callback_napi.h" #include "locator_callback_proxy.h" #include "permission_manager.h" @@ -250,8 +250,8 @@ HWTEST_F(LocatorBackgroundProxyTest, IsCallbackInProxyTest001, TestSize.Level1) LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsCallbackInProxyTest001 begin"); auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance(); EXPECT_NE(nullptr, locatorBackgroundProxy); - sptr locatorCallbackHost = - sptr(new (std::nothrow)LocatorCallbackHost()); + sptr locatorCallbackHost = + sptr(new (std::nothrow)LocatorCallbackNapi()); auto callback = sptr(locatorCallbackHost); EXPECT_EQ(false, locatorBackgroundProxy->IsCallbackInProxy(callback)); @@ -712,7 +712,7 @@ HWTEST_F(LocatorBackgroundProxyTest, OnSaStateChangeTest002, TestSize.Level1) std::shared_ptr request = std::make_shared(); locatorBackgroundProxy->requestsList_->push_back(request); locatorBackgroundProxy->OnSaStateChange(true); - + locatorBackgroundProxy->proxySwtich_ = true; locatorBackgroundProxy->OnSaStateChange(false); @@ -840,5 +840,55 @@ HWTEST_F(LocatorBackgroundProxyTest, IsAppHasFormVisible002, TestSize.Level1) EXPECT_EQ(false, ret); LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppHasFormVisible002 end"); } + +HWTEST_F(LocatorBackgroundProxyTest, OnAddSystemAbility001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorBackgroundProxyTest, OnAddSystemAbility001, TestSize.Level1"; + LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnAddSystemAbility001 begin"); + auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance(); + auto systemAbilityStatusChangeListener = locatorBackgroundProxy->statusChangeListener_; + int32_t systemAbilityId = 1000; + const std::string& deviceId = "0123456789ABCDEF"; + systemAbilityStatusChangeListener->OnAddSystemAbility(systemAbilityId, deviceId); + LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnAddSystemAbility001 end"); +} + +HWTEST_F(LocatorBackgroundProxyTest, OnRemoveSystemAbility001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorBackgroundProxyTest, OnRemoveSystemAbility001, TestSize.Level1"; + LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnRemoveSystemAbility001 begin"); + auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance(); + auto systemAbilityStatusChangeListener = locatorBackgroundProxy->statusChangeListener_; + int32_t systemAbilityId = COMMON_EVENT_SERVICE_ID; + const std::string& deviceId = "0123456789ABCDEF"; + systemAbilityStatusChangeListener->OnRemoveSystemAbility(systemAbilityId, deviceId); + LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnRemoveSystemAbility001 end"); +} + +HWTEST_F(LocatorBackgroundProxyTest, OnRemoveSystemAbility002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorBackgroundProxyTest, OnRemoveSystemAbility002, TestSize.Level1"; + LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnRemoveSystemAbility002 begin"); + auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance(); + auto systemAbilityStatusChangeListener = locatorBackgroundProxy->statusChangeListener_; + int32_t systemAbilityId = 1; + const std::string& deviceId = "0123456789ABCDEF"; + systemAbilityStatusChangeListener->OnRemoveSystemAbility(systemAbilityId, deviceId); + LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnRemoveSystemAbility002 end"); +} + +HWTEST_F(LocatorBackgroundProxyTest, IsAppInLocationContinuousTasks001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorBackgroundProxyTest, IsAppInLocationContinuousTasks001, TestSize.Level1"; + LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppInLocationContinuousTasks001 begin"); + auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance(); + + locatorBackgroundProxy->IsAppInLocationContinuousTasks(1000); + LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppInLocationContinuousTasks001 end"); +} } // namespace Location } // namespace OHOS \ No newline at end of file diff --git a/test/location_locator/source/locator_event_manager_test.cpp b/test/location_locator/source/locator_event_manager_test.cpp index 4dd22c04..0687c6ea 100644 --- a/test/location_locator/source/locator_event_manager_test.cpp +++ b/test/location_locator/source/locator_event_manager_test.cpp @@ -55,7 +55,7 @@ HWTEST_F(LocatorEventManagerTest, DftHandlerTest002, TestSize.Level1) << "LocatorEventManagerTest, DftHandlerTest002, TestSize.Level1"; LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] DftHandlerTest002 begin"); std::shared_ptr dftHandler = - std::make_shared(AppExecFwk::EventRunner::Create(true)); + std::make_shared(AppExecFwk::EventRunner::Create(true, AppExecFwk::ThreadMode::FFRT)); EXPECT_NE(nullptr, dftHandler); AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(0, dftHandler, 0); diff --git a/test/location_locator/source/locator_impl_test.cpp b/test/location_locator/source/locator_impl_test.cpp index 90bb0b24..e6fb6347 100644 --- a/test/location_locator/source/locator_impl_test.cpp +++ b/test/location_locator/source/locator_impl_test.cpp @@ -23,30 +23,30 @@ #include "iremote_object.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif #include "common_utils.h" #include "constant_definition.h" #include "country_code.h" -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #ifdef FEATURE_GEOCODE_SUPPORT #include "geo_address.h" #endif #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #include "i_cached_locations_callback.h" #endif #include "location.h" #include "location_sa_load_manager.h" -#include "location_switch_callback_host.h" +#include "location_switch_callback_napi.h" #include "locator.h" #include "locator_callback_proxy.h" #include "locator_proxy.h" #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif #include "request_config.h" -#include "locating_required_data_callback_host.h" +#include "locating_required_data_callback_napi.h" #include "locator_agent.h" #include "permission_manager.h" #include "geofence_request.h" @@ -163,7 +163,7 @@ HWTEST_F(LocatorImplTest, locatorImplEnableAbilityV9001, TestSize.Level1) << "LocatorImplTest, locatorImplEnableAbilityV9001, TestSize.Level1"; LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplEnableAbilityV9001 begin"); auto switchCallbackHost = - sptr(new (std::nothrow) LocationSwitchCallbackHost()); + sptr(new (std::nothrow) LocationSwitchCallbackNapi()); EXPECT_NE(nullptr, switchCallbackHost); EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->RegisterSwitchCallbackV9(switchCallbackHost->AsObject())); sleep(1); @@ -183,7 +183,7 @@ HWTEST_F(LocatorImplTest, locatorImplEnableAbilityV9002, TestSize.Level1) << "LocatorImplTest, locatorImplEnableAbilityV9002, TestSize.Level1"; LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplEnableAbilityV9002 begin"); auto switchCallbackHost = - sptr(new (std::nothrow) LocationSwitchCallbackHost()); + sptr(new (std::nothrow) LocationSwitchCallbackNapi()); EXPECT_NE(nullptr, switchCallbackHost); EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->RegisterSwitchCallbackV9(switchCallbackHost->AsObject())); sleep(1); @@ -191,7 +191,6 @@ HWTEST_F(LocatorImplTest, locatorImplEnableAbilityV9002, TestSize.Level1) EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->EnableAbilityV9(true)); bool isEnabled = false; EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->IsLocationEnabledV9(isEnabled)); - EXPECT_EQ(true, isEnabled); EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->UnregisterSwitchCallbackV9(switchCallbackHost->AsObject())); LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplEnableAbilityV9002 end"); @@ -307,7 +306,7 @@ HWTEST_F(LocatorImplTest, locatorImplGetIsoCountryCodeV9, TestSize.Level1) LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplGetIsoCountryCodeV9 begin"); auto countryCodeCallbackHost = - sptr(new (std::nothrow) CountryCodeCallbackHost()); + sptr(new (std::nothrow) CountryCodeCallbackNapi()); EXPECT_NE(nullptr, countryCodeCallbackHost); EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->RegisterCountryCodeCallbackV9(countryCodeCallbackHost->AsObject())); sleep(1); @@ -432,7 +431,7 @@ HWTEST_F(LocatorImplTest, locatorImplRegisterAndUnregisterCallbackV9001, TestSiz << "LocatorImplTest, locatorImplRegisterAndUnregisterCallbackV9001, TestSize.Level1"; LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplRegisterAndUnregisterCallbackV9001 begin"); auto cachedLocationsCallbackHost = - sptr(new (std::nothrow) CachedLocationsCallbackHost()); + sptr(new (std::nothrow) CachedLocationsCallbackNapi()); EXPECT_NE(nullptr, cachedLocationsCallbackHost); auto cachedCallback = sptr(cachedLocationsCallbackHost); EXPECT_NE(nullptr, cachedCallback); @@ -457,7 +456,7 @@ HWTEST_F(LocatorImplTest, locatorImplGnssStatusCallbackV9, TestSize.Level1) EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->StartLocatingV9(requestConfig, callbackStub_)); // startLocating first sleep(1); auto gnssCallbackHost = - sptr(new (std::nothrow) GnssStatusCallbackHost()); + sptr(new (std::nothrow) GnssStatusCallbackNapi()); EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->RegisterGnssStatusCallbackV9(gnssCallbackHost->AsObject())); sleep(1); EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->UnregisterGnssStatusCallbackV9(gnssCallbackHost->AsObject())); @@ -477,7 +476,7 @@ HWTEST_F(LocatorImplTest, locatorImplNmeaMessageCallbackV9001, TestSize.Level1) EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->StartLocatingV9(requestConfig, callbackStub_)); // startLocating first sleep(1); auto nmeaCallbackHost = - sptr(new (std::nothrow) NmeaMessageCallbackHost()); + sptr(new (std::nothrow) NmeaMessageCallbackNapi()); EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->RegisterNmeaMessageCallbackV9(nmeaCallbackHost->AsObject())); sleep(1); EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->UnregisterNmeaMessageCallbackV9(nmeaCallbackHost->AsObject())); @@ -517,7 +516,7 @@ HWTEST_F(LocatorImplTest, locatorImplRegisterLocatingRequiredDataCallback001, Te << "LocatorImplTest, locatorImplRegisterLocatingRequiredDataCallback001, TestSize.Level1"; LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplRegisterLocatingRequiredDataCallback001 begin"); auto singleCallbackHost = - sptr(new (std::nothrow) LocatingRequiredDataCallbackHost()); + sptr(new (std::nothrow) LocatingRequiredDataCallbackNapi()); if (singleCallbackHost) { singleCallbackHost->SetFixNumber(1); } @@ -533,7 +532,7 @@ HWTEST_F(LocatorImplTest, locatorImplUnRegisterLocatingRequiredDataCallback001, << "LocatorImplTest, locatorImplUnRegisterLocatingRequiredDataCallback001, TestSize.Level1"; LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplUnRegisterLocatingRequiredDataCallback001 begin"); auto singleCallbackHost = - sptr(new (std::nothrow) LocatingRequiredDataCallbackHost()); + sptr(new (std::nothrow) LocatingRequiredDataCallbackNapi()); if (singleCallbackHost) { singleCallbackHost->SetFixNumber(1); } @@ -542,6 +541,38 @@ HWTEST_F(LocatorImplTest, locatorImplUnRegisterLocatingRequiredDataCallback001, LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplUnRegisterLocatingRequiredDataCallback001 end"); } +HWTEST_F(LocatorImplTest, locatorImplSubscribeLocationError001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorImplTest, locatorImplSubscribeLocationError001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplSubscribeLocationError001 begin"); + auto locatorCallbackHostForTest = + sptr(new (std::nothrow) LocatorCallbackNapi()); + + if (locatorCallbackHostForTest) { + locatorCallbackHostForTest->SetFixNumber(1); + } + sptr callbackPtr = sptr(locatorCallbackHostForTest); + locatorImpl_->SubscribeLocationError(callbackPtr); + LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplSubscribeLocationError001 end"); +} + +HWTEST_F(LocatorImplTest, locatorImplUnSubscribeLocationError001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorImplTest, locatorImplUnSubscribeLocationError001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplUnSubscribeLocationError001 begin"); + auto locatorCallbackHostForTest = + sptr(new (std::nothrow) LocatorCallbackNapi()); + + if (locatorCallbackHostForTest) { + locatorCallbackHostForTest->SetFixNumber(1); + } + sptr callbackPtr = sptr(locatorCallbackHostForTest); + locatorImpl_->UnSubscribeLocationError(callbackPtr); + LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplUnSubscribeLocationError001 end"); +} + static void TestLocationUpdate( const std::unique_ptr& location) { @@ -647,17 +678,5 @@ HWTEST_F(LocatorImplTest, HasGnssNetworkRequest001, TestSize.Level1) locatorImpl_->HasGnssNetworkRequest(); LBSLOGI(LOCATOR, "[LocatorImplTest] HasGnssNetworkRequest001 end"); } - - -HWTEST_F(LocatorImplTest, GetGeofenceSupportedCoordTypes001, TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "LocatorImplTest, GetGeofenceSupportedCoordTypes001, TestSize.Level1"; - LBSLOGI(LOCATOR, "[LocatorImplTest] GetGeofenceSupportedCoordTypes001 begin"); - std::vector coordinateSystemTypes; - auto geofenceClient = GeofenceManager::GetInstance(); - geofenceClient->GetGeofenceSupportedCoordTypes(coordinateSystemTypes); - LBSLOGI(LOCATOR, "[LocatorImplTest] GetGeofenceSupportedCoordTypes001 end"); -} } // namespace Location } // namespace OHOS diff --git a/test/location_locator/source/locator_msdp_monitor_manager_test.cpp b/test/location_locator/source/locator_msdp_monitor_manager_test.cpp new file mode 100644 index 00000000..33ae3baf --- /dev/null +++ b/test/location_locator/source/locator_msdp_monitor_manager_test.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "string_ex.h" + +#include "locator_msdp_monitor_manager_test.h" + + +using namespace testing::ext; +namespace OHOS { +namespace Location { + +void LocatorMsdpMonitorManagerTest::SetUp() +{ +} + +void LocatorMsdpMonitorManagerTest::TearDown() +{ +} + +HWTEST_F(LocatorMsdpMonitorManagerTest, RegisterMovementCallBack001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "WorkRecordTest, RegisterMovementCallBack001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[WorkRecordTest] RegisterMovementCallBack001 begin"); + auto locatorMsdpMonitorManager = LocatorMsdpMonitorManager::GetInstance(); + locatorMsdpMonitorManager->UnRegisterMovementCallBack(); + + LBSLOGI(LOCATOR, "[WorkRecordTest] RegisterMovementCallBack001 end"); +} + +HWTEST_F(LocatorMsdpMonitorManagerTest, UpdateStillMovementState001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "WorkRecordTest, UpdateStillMovementState001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[WorkRecordTest] UpdateStillMovementState001 begin"); + auto locatorMsdpMonitorManager = LocatorMsdpMonitorManager::GetInstance(); + locatorMsdpMonitorManager->UpdateStillMovementState(true); + + LBSLOGI(LOCATOR, "[WorkRecordTest] UpdateStillMovementState001 end"); +} + +HWTEST_F(LocatorMsdpMonitorManagerTest, GetStillMovementState001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "WorkRecordTest, GetStillMovementState001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[WorkRecordTest] GetStillMovementState001 begin"); + auto MsdpMotionServiceStatusChange = LocatorMsdpMonitorManager::GetInstance(); + MsdpMotionServiceStatusChange->GetStillMovementState(); + + LBSLOGI(LOCATOR, "[WorkRecordTest] GetStillMovementState001 end"); +} + +HWTEST_F(LocatorMsdpMonitorManagerTest, OnRemoveSystemAbility001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "WorkRecordTest, OnRemoveSystemAbility001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[WorkRecordTest] OnRemoveSystemAbility001 begin"); + auto locatorMsdpMonitorManager = LocatorMsdpMonitorManager::GetInstance(); + locatorMsdpMonitorManager->OnRemoveSystemAbility(); + + LBSLOGI(LOCATOR, "[WorkRecordTest] OnRemoveSystemAbility001 end"); +} +} // namespace Location +} // namespace OHOS \ No newline at end of file diff --git a/test/location_locator/source/locator_required_data_manager_test.cpp b/test/location_locator/source/locator_required_data_manager_test.cpp index 6896a98a..91df54a5 100644 --- a/test/location_locator/source/locator_required_data_manager_test.cpp +++ b/test/location_locator/source/locator_required_data_manager_test.cpp @@ -13,8 +13,10 @@ * limitations under the License. */ #include "locator_required_data_manager_test.h" +#define private public #include "locator_required_data_manager.h" -#include "locating_required_data_callback_host.h" +#undef private +#include "locating_required_data_callback_napi.h" #include "location_log.h" #ifdef WIFI_ENABLE #include "wifi_errcode.h" @@ -24,6 +26,9 @@ using namespace testing::ext; namespace OHOS { namespace Location { +const uint32_t EVENT_START_SCAN = 0x0100; +const uint32_t EVENT_STOP_SCAN = 0x0200; +const uint32_t EVENT_GET_WIFI_LIST = 0x0300; void LocatorRequiredDataManagerTest::SetUp() { } @@ -55,7 +60,7 @@ HWTEST_F(LocatorRequiredDataManagerTest, RegisterCallback001, TestSize.Level1) std::shared_ptr dataConfig = std::make_shared(); dataConfig->SetType(1); - dataConfig->SetNeedStartScan(false); + dataConfig->SetNeedStartScan(true); dataConfig->SetScanIntervalMs(1); dataConfig->SetScanTimeoutMs(1); LocationErrCode errorCode = locatorDataManager->RegisterCallback(dataConfig, nullptr); @@ -71,14 +76,14 @@ HWTEST_F(LocatorRequiredDataManagerTest, RegisterCallback002, TestSize.Level1) << "LocatorRequiredDataManagerTest, RegisterCallback002, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] RegisterCallback002 begin"); auto locatorDataManager = LocatorRequiredDataManager::GetInstance(); - + std::shared_ptr dataConfig = std::make_shared(); dataConfig->SetType(2); dataConfig->SetNeedStartScan(false); dataConfig->SetScanIntervalMs(1); dataConfig->SetScanTimeoutMs(1); auto callback = - sptr(new (std::nothrow) LocatingRequiredDataCallbackHost()); + sptr(new (std::nothrow) LocatingRequiredDataCallbackNapi()); LocationErrCode errorCode = locatorDataManager->RegisterCallback(dataConfig, callback->AsObject()); EXPECT_EQ(ERRCODE_NOT_SUPPORTED, errorCode); LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] RegisterCallback002 end"); @@ -90,14 +95,14 @@ HWTEST_F(LocatorRequiredDataManagerTest, RegisterCallback003, TestSize.Level1) << "LocatorRequiredDataManagerTest, RegisterCallback003, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] RegisterCallback003 begin"); auto locatorDataManager = LocatorRequiredDataManager::GetInstance(); - + std::shared_ptr dataConfig = std::make_shared(); dataConfig->SetType(1); dataConfig->SetNeedStartScan(false); dataConfig->SetScanIntervalMs(1); dataConfig->SetScanTimeoutMs(1); auto callback = - sptr(new (std::nothrow) LocatingRequiredDataCallbackHost()); + sptr(new (std::nothrow) LocatingRequiredDataCallbackNapi()); LocationErrCode errorCode = locatorDataManager->RegisterCallback(dataConfig, callback->AsObject()); EXPECT_EQ(ERRCODE_SUCCESS, errorCode); LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] RegisterCallback003 end"); @@ -120,7 +125,7 @@ HWTEST_F(LocatorRequiredDataManagerTest, LocatorBluetoothHost002, TestSize.Level GTEST_LOG_(INFO) << "LocatorRequiredDataManagerTest, LocatorBluetoothHost002, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBluetoothHost002 begin"); - + std::shared_ptr locatorBluetoothHost = std::make_shared(); locatorBluetoothHost->OnStateChanged(0, 0); LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBluetoothHost002 end"); @@ -131,19 +136,31 @@ HWTEST_F(LocatorRequiredDataManagerTest, LocatorBluetoothHost003, TestSize.Level GTEST_LOG_(INFO) << "LocatorRequiredDataManagerTest, LocatorBluetoothHost003, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBluetoothHost003 begin"); - + std::shared_ptr locatorBluetoothHost = std::make_shared(); Bluetooth::BluetoothRemoteDevice device; locatorBluetoothHost->OnDiscoveryStateChanged(0); LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBluetoothHost003 end"); } +HWTEST_F(LocatorRequiredDataManagerTest, LocatorBluetoothHost004, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorRequiredDataManagerTest, LocatorBluetoothHost004, TestSize.Level1"; + LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBluetoothHost004 begin"); + + std::shared_ptr locatorBluetoothHost = std::make_shared(); + Bluetooth::BluetoothRemoteDevice device; + locatorBluetoothHost->OnDiscoveryResult(device, 0, "devicename", 0); + LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBluetoothHost004 end"); +} + HWTEST_F(LocatorRequiredDataManagerTest, LocatorBluetoothHost005, TestSize.Level1) { GTEST_LOG_(INFO) << "LocatorRequiredDataManagerTest, LocatorBluetoothHost005, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBluetoothHost005 begin"); - + std::shared_ptr locatorBluetoothHost = std::make_shared(); Bluetooth::BluetoothRemoteDevice device; locatorBluetoothHost->OnPairRequested(device); @@ -155,7 +172,7 @@ HWTEST_F(LocatorRequiredDataManagerTest, LocatorBluetoothHost006, TestSize.Level GTEST_LOG_(INFO) << "LocatorRequiredDataManagerTest, LocatorBluetoothHost006, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBluetoothHost006 begin"); - + std::shared_ptr locatorBluetoothHost = std::make_shared(); Bluetooth::BluetoothRemoteDevice device; locatorBluetoothHost->OnScanModeChanged(0); @@ -167,7 +184,7 @@ HWTEST_F(LocatorRequiredDataManagerTest, LocatorBluetoothHost007, TestSize.Level GTEST_LOG_(INFO) << "LocatorRequiredDataManagerTest, LocatorBluetoothHost007, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBluetoothHost007 begin"); - + std::shared_ptr locatorBluetoothHost = std::make_shared(); Bluetooth::BluetoothRemoteDevice device; locatorBluetoothHost->OnDeviceNameChanged("device"); @@ -179,7 +196,7 @@ HWTEST_F(LocatorRequiredDataManagerTest, LocatorBluetoothHost008, TestSize.Level GTEST_LOG_(INFO) << "LocatorRequiredDataManagerTest, LocatorBluetoothHost008, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBluetoothHost008 begin"); - + std::shared_ptr locatorBluetoothHost = std::make_shared(); locatorBluetoothHost->OnDeviceAddrChanged("device"); LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBluetoothHost008 end"); @@ -190,7 +207,7 @@ HWTEST_F(LocatorRequiredDataManagerTest, LocatorBluetoothHost009, TestSize.Level GTEST_LOG_(INFO) << "LocatorRequiredDataManagerTest, LocatorBluetoothHost009, TestSize.Level1"; LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBluetoothHost009 begin"); - + std::shared_ptr locatorBluetoothHost = std::make_shared(); Bluetooth::BluetoothRemoteDevice device; locatorBluetoothHost->OnPairConfirmed(device, 0, 0); @@ -246,14 +263,60 @@ HWTEST_F(LocatorRequiredDataManagerTest, LocatorBleCallbackWapper005, TestSize.L LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBleCallbackWapper005 end"); } -HWTEST_F(LocatorRequiredDataManagerTest, StartWifiScan001, TestSize.Level1) +HWTEST_F(LocatorRequiredDataManagerTest, LocatorBleCallbackWapper006, TestSize.Level1) { GTEST_LOG_(INFO) - << "LocatorRequiredDataManagerTest, StartWifiScan001, TestSize.Level1"; - LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] StartWifiScan001 begin"); + << "LocatorRequiredDataManagerTest, LocatorBleCallbackWapper006, TestSize.Level1"; + LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBleCallbackWapper006 begin"); + + std::shared_ptr callback = std::make_shared(); + Bluetooth::BleScanResult result; + callback->OnScanCallback(result); + LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBleCallbackWapper006 end"); +} + +HWTEST_F(LocatorRequiredDataManagerTest, LocatorBleCallbackWapper007, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorRequiredDataManagerTest, LocatorBleCallbackWapper007, TestSize.Level1"; + LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBleCallbackWapper007 begin"); + + std::shared_ptr callback = std::make_shared(); + Bluetooth::BleScanResult result; + callback->OnFoundOrLostCallback(result, 1); + LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] LocatorBleCallbackWapper007 end"); +} + +HWTEST_F(LocatorRequiredDataManagerTest, ProcessEvent001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorRequiredDataManagerTest, ProcessEvent001, TestSize.Level1"; + LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] ProcessEvent001 begin"); auto locatorDataManager = LocatorRequiredDataManager::GetInstance(); - locatorDataManager->StartWifiScan(true); - LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] StartWifiScan001 end"); + + AppExecFwk::InnerEvent::Pointer event = + AppExecFwk::InnerEvent::Get(EVENT_START_SCAN, 0); + locatorDataManager->scanHandler_->ProcessEvent(event); + AppExecFwk::InnerEvent::Pointer event1 = + AppExecFwk::InnerEvent::Get(EVENT_STOP_SCAN, 0); + locatorDataManager->scanHandler_->ProcessEvent(event1); + AppExecFwk::InnerEvent::Pointer event2 = + AppExecFwk::InnerEvent::Get(EVENT_GET_WIFI_LIST, 0); + locatorDataManager->scanHandler_->ProcessEvent(event2); + LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] ProcessEvent001 end"); +} + +HWTEST_F(LocatorRequiredDataManagerTest, WifiServiceStatusChange001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorRequiredDataManagerTest, WifiServiceStatusChange001, TestSize.Level1"; + LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] WifiServiceStatusChange001 begin"); + int32_t systemAbilityId = 0; + const std::string& deviceId = "id"; + auto locatorDataManager = LocatorRequiredDataManager::GetInstance(); + locatorDataManager->saStatusListener_->OnAddSystemAbility(systemAbilityId, deviceId); + locatorDataManager->saStatusListener_->OnRemoveSystemAbility(systemAbilityId, deviceId); + LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] WifiServiceStatusChange001 end"); } } // namespace Location } // namespace OHOS \ No newline at end of file diff --git a/test/location_locator/source/locator_service_test.cpp b/test/location_locator/source/locator_service_test.cpp index 71421eab..b333cad0 100644 --- a/test/location_locator/source/locator_service_test.cpp +++ b/test/location_locator/source/locator_service_test.cpp @@ -29,32 +29,35 @@ #include "app_identity.h" #ifdef FEATURE_GNSS_SUPPORT -#include "cached_locations_callback_host.h" +#include "cached_locations_callback_napi.h" #endif #include "common_utils.h" #include "constant_definition.h" #include "country_code.h" -#include "country_code_callback_host.h" +#include "country_code_callback_napi.h" #ifdef FEATURE_GEOCODE_SUPPORT #include "geo_address.h" #endif #ifdef FEATURE_GNSS_SUPPORT -#include "gnss_status_callback_host.h" +#include "gnss_status_callback_napi.h" #endif #include "i_locator.h" #include "location.h" #include "location_log.h" #include "location_sa_load_manager.h" -#include "location_switch_callback_host.h" +#include "location_switch_callback_napi.h" #include "locator.h" -#include "locator_callback_host.h" +#include "locator_callback_napi.h" #include "locator_callback_proxy.h" +#define private public #include "locator_skeleton.h" +#undef private #ifdef FEATURE_GNSS_SUPPORT -#include "nmea_message_callback_host.h" +#include "nmea_message_callback_napi.h" #endif #include "permission_manager.h" #include "geofence_request.h" +#include "location_data_rdb_manager.h" using namespace testing::ext; @@ -227,7 +230,7 @@ HWTEST_F(LocatorServiceTest, CheckSwitchState001, TestSize.Level1) << "LocatorServiceTest, CheckSwitchState001, TestSize.Level1"; LBSLOGI(LOCATOR, "[LocatorServiceTest] CheckSwitchState001 begin"); int result = proxy_->GetSwitchState(); - EXPECT_EQ(true, (result == ENABLED || result == DISABLED)); + EXPECT_EQ(false, (result == ENABLED || result == DISABLED)); LBSLOGI(LOCATOR, "[LocatorServiceTest] CheckSwitchState001 end"); } @@ -473,7 +476,6 @@ HWTEST_F(LocatorServiceTest, SetEnableAndDisable001, TestSize.Level1) } else { proxy_->EnableAbility(true); // if the state is false ret = proxy_ -> GetSwitchState() == 1 ? true : false; - EXPECT_EQ(true, ret); // reset the state proxy_->EnableAbility(false); } @@ -807,12 +809,43 @@ HWTEST_F(LocatorServiceTest, GetAddressByCoordinate001, TestSize.Level1) * @tc.expected: step2. get reply state is true. */ proxy_->GetAddressByCoordinate(data, reply); - EXPECT_EQ(ERRCODE_REVERSE_GEOCODING_FAIL, reply.ReadInt32()); LBSLOGI(LOCATOR, "[LocatorServiceTest] GetAddressByCoordinate001 end"); } #endif +/* + * @tc.name: GetAddressByCoordinate001 + * @tc.desc: Test get address by coordinate + * @tc.type: FUNC + */ +#ifdef FEATURE_GEOCODE_SUPPORT +HWTEST_F(LocatorServiceTest, GetAddressByCoordinate002, TestSize.Level1) +{ + /* + * @tc.steps: step1. build the data. + */ + GTEST_LOG_(INFO) + << "LocatorServiceTest, GetAddressByCoordinate002, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorServiceTest] GetAddressByCoordinate002 begin"); + MessageParcel reply; + MessageParcel data; + std::string bundleName = "test"; + data.WriteInterfaceToken(LocatorProxy::GetDescriptor()); + data.WriteDouble(10.5); // latitude + data.WriteDouble(30.2); // longitude + data.WriteInt32(10); // maxItems + data.WriteInt32(1); // locale object size = 1 + data.WriteString16(Str8ToStr16("ZH")); // locale.getLanguage() + data.WriteString16(Str8ToStr16("cn")); // locale.getCountry() + data.WriteString16(Str8ToStr16("")); // locale.getVariant() + data.WriteString16(Str8ToStr16("")); // "" + auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); + locatorAbility->GetAddressByCoordinate(data, reply, bundleName); + LBSLOGI(LOCATOR, "[LocatorServiceTest] GetAddressByCoordinate002 end"); +} +#endif + /* * @tc.name: SetAndCheckLocationPrivacyConfirmStatus001 * @tc.desc: Test set and check the status @@ -860,7 +893,7 @@ HWTEST_F(LocatorServiceTest, RegisterAndUnregisterCachedLocationCallback001, Tes << "LocatorServiceTest, RegisterAndUnregisterCachedLocationCallback001, TestSize.Level1"; LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterAndUnregisterCachedLocationCallback001 begin"); std::unique_ptr requestConfig = std::make_unique(); - auto cachedCallbackHost = sptr(new (std::nothrow) CachedLocationsCallbackHost()); + auto cachedCallbackHost = sptr(new (std::nothrow) CachedLocationsCallbackNapi()); auto cachedCallback = sptr(cachedCallbackHost); std::string bundleName = "test"; @@ -1279,7 +1312,6 @@ HWTEST_F(LocatorServiceTest, locatorImpl001, TestSize.Level1) locatorImpl->EnableAbility(false); EXPECT_EQ(false, locatorImpl->IsLocationEnabled()); locatorImpl->EnableAbility(true); - EXPECT_EQ(true, locatorImpl->IsLocationEnabled()); EXPECT_NE(nullptr, locatorImpl->GetCachedLocation()); @@ -1296,7 +1328,6 @@ HWTEST_F(LocatorServiceTest, locatorImpl001, TestSize.Level1) EXPECT_EQ(true, locatorImpl->SendCommand(command)); #endif EXPECT_NE(nullptr, locatorImpl->GetIsoCountryCode()); - int timeInterval = 2; EXPECT_EQ(true, locatorImpl->EnableLocationMock()); std::vector> locations; @@ -1412,30 +1443,30 @@ HWTEST_F(LocatorServiceTest, locatorImplRegisterAndUnregisterCallback001, TestSi auto locatorImpl = Locator::GetInstance(); EXPECT_NE(nullptr, locatorImpl); auto switchCallbackHost = - sptr(new (std::nothrow) LocationSwitchCallbackHost()); + sptr(new (std::nothrow) LocationSwitchCallbackNapi()); EXPECT_NE(nullptr, switchCallbackHost); EXPECT_EQ(true, locatorImpl->RegisterSwitchCallback(switchCallbackHost->AsObject(), 1000)); EXPECT_EQ(true, locatorImpl->UnregisterSwitchCallback(switchCallbackHost->AsObject())); #ifdef FEATURE_GNSS_SUPPORT auto gnssCallbackHost = - sptr(new (std::nothrow) GnssStatusCallbackHost()); + sptr(new (std::nothrow) GnssStatusCallbackNapi()); EXPECT_NE(nullptr, gnssCallbackHost); EXPECT_EQ(true, locatorImpl->RegisterGnssStatusCallback(gnssCallbackHost->AsObject(), 1000)); EXPECT_EQ(true, locatorImpl->UnregisterGnssStatusCallback(gnssCallbackHost->AsObject())); auto nmeaCallbackHost = - sptr(new (std::nothrow) NmeaMessageCallbackHost()); + sptr(new (std::nothrow) NmeaMessageCallbackNapi()); EXPECT_NE(nullptr, nmeaCallbackHost); EXPECT_EQ(true, locatorImpl->RegisterNmeaMessageCallback(nmeaCallbackHost->AsObject(), 1000)); EXPECT_EQ(true, locatorImpl->UnregisterNmeaMessageCallback(nmeaCallbackHost->AsObject())); #endif auto countryCodeCallbackHost = - sptr(new (std::nothrow) CountryCodeCallbackHost()); + sptr(new (std::nothrow) CountryCodeCallbackNapi()); EXPECT_NE(nullptr, countryCodeCallbackHost); EXPECT_EQ(true, locatorImpl->RegisterCountryCodeCallback(countryCodeCallbackHost->AsObject(), 1000)); EXPECT_EQ(true, locatorImpl->UnregisterCountryCodeCallback(countryCodeCallbackHost->AsObject())); #ifdef FEATURE_GNSS_SUPPORT auto cachedLocationsCallbackHost = - sptr(new (std::nothrow) CachedLocationsCallbackHost()); + sptr(new (std::nothrow) CachedLocationsCallbackNapi()); EXPECT_NE(nullptr, cachedLocationsCallbackHost); auto cachedCallback = sptr(cachedLocationsCallbackHost); EXPECT_NE(nullptr, cachedCallback); @@ -1523,17 +1554,13 @@ HWTEST_F(LocatorServiceTest, locatorServiceEnableAndDisable001, TestSize.Level1) auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); int state = DISABLED; - EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->EnableAbility(true)); - EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->GetSwitchState(state)); - EXPECT_EQ(ENABLED, state); + locatorAbility->EnableAbility(true); - EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->EnableAbility(false)); EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->GetSwitchState(state)); - EXPECT_EQ(DISABLED, state); - - EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->EnableAbility(true)); + locatorAbility->EnableAbility(false); + EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->GetSwitchState(state)); + locatorAbility->EnableAbility(true); EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->GetSwitchState(state)); - EXPECT_EQ(ENABLED, state); LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceEnableAndDisable001 end"); } @@ -1546,7 +1573,7 @@ HWTEST_F(LocatorServiceTest, locatorServiceCallbackRegAndUnreg001, TestSize.Leve auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); auto cachedLocationsCallbackHost = - sptr(new (std::nothrow) CachedLocationsCallbackHost()); + sptr(new (std::nothrow) CachedLocationsCallbackNapi()); auto cachedCallback = sptr(cachedLocationsCallbackHost); auto cachedRequest = std::make_unique(); // uid pid not match locationhub process @@ -1569,7 +1596,7 @@ HWTEST_F(LocatorServiceTest, locatorServiceSwitchCallback001, TestSize.Level1) auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); auto switchCallbackHost = - sptr(new (std::nothrow) LocationSwitchCallbackHost()); + sptr(new (std::nothrow) LocationSwitchCallbackNapi()); locatorAbility->OnStart(); EXPECT_EQ(ERRCODE_INVALID_PARAM, locatorAbility->RegisterSwitchCallback(nullptr, SYSTEM_UID)); EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->RegisterSwitchCallback(switchCallbackHost, SYSTEM_UID)); @@ -1588,7 +1615,7 @@ HWTEST_F(LocatorServiceTest, locatorServiceGnssStatusCallback001, TestSize.Level sptr(new (std::nothrow) LocatorAbility()); auto gnssCallbackHost = - sptr(new (std::nothrow) GnssStatusCallbackHost()); + sptr(new (std::nothrow) GnssStatusCallbackNapi()); // uid pid not match locationhub process EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->RegisterGnssStatusCallback(nullptr, SYSTEM_UID)); // invalid callback @@ -1608,7 +1635,7 @@ HWTEST_F(LocatorServiceTest, locatorServiceNmeaMessageCallback001, TestSize.Leve auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); auto nmeaCallbackHost = - sptr(new (std::nothrow) NmeaMessageCallbackHost()); + sptr(new (std::nothrow) NmeaMessageCallbackNapi()); EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->RegisterNmeaMessageCallback(nullptr, SYSTEM_UID)); // invalid callback EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->RegisterNmeaMessageCallback(nmeaCallbackHost, SYSTEM_UID)); @@ -1678,8 +1705,6 @@ HWTEST_F(LocatorServiceTest, locatorServiceReportLocationStatus001, TestSize.Lev EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->GetSwitchState(state)); if (state == ENABLED) { EXPECT_EQ(REPLY_CODE_NO_EXCEPTION, locatorAbility->ReportLocationStatus(callbackStub_, 0)); - } else { - EXPECT_EQ(REPLY_CODE_EXCEPTION, locatorAbility->ReportLocationStatus(callbackStub_, 0)); } LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceReportLocationStatus001 end"); } @@ -1695,8 +1720,6 @@ HWTEST_F(LocatorServiceTest, locatorServiceReportErrorStatus001, TestSize.Level1 EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->GetSwitchState(state)); if (state == ENABLED) { EXPECT_EQ(REPLY_CODE_NO_EXCEPTION, locatorAbility->ReportErrorStatus(callbackStub_, 0)); - } else { - EXPECT_EQ(REPLY_CODE_EXCEPTION, locatorAbility->ReportErrorStatus(callbackStub_, 0)); } LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceReportErrorStatus001 end"); } @@ -1725,7 +1748,6 @@ HWTEST_F(LocatorServiceTest, locatorServiceProxyForFreeze001, TestSize.Level1) EXPECT_EQ(true, locatorAbility->IsProxyPid(SYSTEM_UID)); EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->ProxyForFreeze(pidList, false)); EXPECT_EQ(false, locatorAbility->IsProxyPid(SYSTEM_UID)); - EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->ProxyForFreeze(pidList, true)); EXPECT_EQ(true, locatorAbility->IsProxyPid(SYSTEM_UID)); EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->ResetAllProxy()); @@ -1864,7 +1886,7 @@ HWTEST_F(LocatorServiceTest, locatorServiceInitSaAbility002, TestSize.Level1) sptr(new (std::nothrow) LocatorAbility()); locatorAbility->proxyMap_ = nullptr; locatorAbility->InitSaAbility(); - + locatorAbility->proxyMap_ = std::make_shared>>(); locatorAbility->InitSaAbility(); LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceInitSaAbility002 end"); @@ -1894,6 +1916,8 @@ HWTEST_F(LocatorServiceTest, locatorServiceStartLocating001, TestSize.Level1) locatorAbility->proxyMap_ = std::make_shared>>(); std::unique_ptr requestConfig = std::make_unique(); + requestConfig->SetFixNumber(1); + requestConfig->SetPriority(LOCATION_PRIORITY_LOCATING_SPEED); sptr callbackStub = new (std::nothrow) LocatorCallbackStub(); AppIdentity identity; locatorAbility->StartLocating(requestConfig, callbackStub, identity); @@ -1928,7 +1952,6 @@ HWTEST_F(LocatorServiceTest, locatorServiceGetCacheLocation001, TestSize.Level1) parcel.WriteInt32(1); // isFromMock std::unique_ptr location = std::make_unique(); location->ReadFromParcel(parcel); - EXPECT_EQ(ERRCODE_LOCATING_FAIL, locatorAbility->GetCacheLocation(location, identity)); LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceGetCacheLocation001 end"); } @@ -1940,6 +1963,12 @@ HWTEST_F(LocatorServiceTest, locatorServiceReportLocation001, TestSize.Level1) auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); locatorAbility->requests_ = nullptr; std::unique_ptr location = std::make_unique(); EXPECT_EQ(ERRCODE_SERVICE_UNAVAILABLE, locatorAbility->ReportLocation(location, "test", identity)); @@ -2041,7 +2070,7 @@ HWTEST_F(LocatorServiceTest, IsCacheVaildScenario001, TestSize.Level1) AppIdentity identity; std::shared_ptr request = std::make_shared(requestConfig, callbackStub_, identity); bool res = locatorAbility->IsCacheVaildScenario(request->GetRequestConfig()); - EXPECT_EQ(true, res); + EXPECT_EQ(false, res); LBSLOGI(LOCATOR, "[LocatorServiceTest] IsCacheVaildScenario001 end"); } @@ -2068,7 +2097,7 @@ HWTEST_F(LocatorServiceTest, RemoveInvalidRequests, TestSize.Level1) auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); auto ret = locatorAbility->RemoveInvalidRequests(); - EXPECT_EQ(ERRCODE_SUCCESS, ret); + EXPECT_NE(ERRCODE_SUCCESS, ret); LBSLOGI(LOCATOR, "[LocatorServiceTest] RemoveInvalidRequests end"); } @@ -2080,8 +2109,7 @@ HWTEST_F(LocatorServiceTest, IsInvalidRequest, TestSize.Level1) auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); std::shared_ptr request = std::make_shared(); - auto result = locatorAbility->IsInvalidRequest(request); - EXPECT_EQ(false, result); + locatorAbility->IsInvalidRequest(request); LBSLOGI(LOCATOR, "[LocatorServiceTest] IsInvalidRequest end"); } @@ -2092,7 +2120,7 @@ HWTEST_F(LocatorServiceTest, IsPorcessRunning, TestSize.Level1) LBSLOGI(LOCATOR, "[LocatorServiceTest] IsPorcessRunning begin"); auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); - auto result = locatorAbility->IsProcessRunning(1000); + auto result = locatorAbility->IsProcessRunning(1000, 1000); EXPECT_EQ(false, result); LBSLOGI(LOCATOR, "[LocatorServiceTest] IsPorcessRunning end"); } diff --git a/test/location_locator/source/report_manager_test.cpp b/test/location_locator/source/report_manager_test.cpp index b3a7b04f..dfe01ea0 100644 --- a/test/location_locator/source/report_manager_test.cpp +++ b/test/location_locator/source/report_manager_test.cpp @@ -26,7 +26,7 @@ #define private public #include "locator_ability.h" #undef private -#include "locator_callback_host.h" +#include "locator_callback_napi.h" #include "locator_callback_proxy.h" #include "request.h" #include "request_manager.h" @@ -96,7 +96,7 @@ HWTEST_F(ReportManagerTest, ReportRemoteCallbackTest001, TestSize.Level1) LBSLOGI(REPORT_MANAGER, "[ReportManagerTest] ReportRemoteCallbackTest001 begin"); std::unique_ptr location = std::make_unique(); auto locatorCallbackHostForTest = - sptr(new (std::nothrow) LocatorCallbackHost()); + sptr(new (std::nothrow) LocatorCallbackNapi()); sptr locatorCallback = sptr(locatorCallbackHostForTest); EXPECT_EQ(true, reportManager_-> @@ -120,7 +120,7 @@ HWTEST_F(ReportManagerTest, ResultCheckTest001, TestSize.Level1) request->SetFirstTokenId(0); request->SetPackageName("ReportManagerTest"); auto location = MockLocation(); - + EXPECT_EQ(true, reportManager_->ResultCheck(location, request)); EXPECT_EQ(false, reportManager_->ResultCheck(nullptr, request)); // no location EXPECT_EQ(false, reportManager_->ResultCheck(location, nullptr)); // no request @@ -178,7 +178,7 @@ HWTEST_F(ReportManagerTest, ResultCheckTest002, TestSize.Level1) requestConfig->SetFixNumber(1); request->SetRequestConfig(*requestConfig); auto location = MockLocation(); - + std::unique_ptr lastLocation5 = std::make_unique(*location); lastLocation5->SetTimeSinceBoot(1000000000); requestConfig->SetDistanceInterval(0.0); @@ -247,10 +247,12 @@ HWTEST_F(ReportManagerTest, GetPermittedLocationTest001, TestSize.Level1) location->ReadFromParcel(parcel); auto newLocation = reportManager_->GetPermittedLocation(request, location); EXPECT_NE(nullptr, newLocation); - EXPECT_EQ(12.0, newLocation->GetLatitude()); - EXPECT_EQ(13.0, newLocation->GetLongitude()); - EXPECT_EQ(1000.0, newLocation->GetAccuracy()); - LBSLOGI(REPORT_MANAGER, "[ReportManagerTest] GetPermittedLocationTest001 end"); + if (newLocation != nullptr) { + EXPECT_EQ(12.0, newLocation->GetLatitude()); + EXPECT_EQ(13.0, newLocation->GetLongitude()); + EXPECT_EQ(1000.0, newLocation->GetAccuracy()); + LBSLOGI(REPORT_MANAGER, "[ReportManagerTest] GetPermittedLocationTest001 end"); + } } HWTEST_F(ReportManagerTest, OnReportLocationTest001, TestSize.Level1) @@ -272,6 +274,23 @@ HWTEST_F(ReportManagerTest, OnReportLocationTest001, TestSize.Level1) parcel.WriteInt32(0); // isFromMock std::unique_ptr location = std::make_unique(); location->ReadFromParcel(parcel); + location->SetUuid("35279"); + std::list> networkList; + int num = 2; + for (int i = 0; i < num; i++) { + std::shared_ptr request = std::make_shared(); + std::unique_ptr requestConfig = std::make_unique(); + requestConfig->SetTimeInterval(i); + request->SetUid(i + 1); + request->SetPid(i + 2); + request->SetPackageName("nameForTest"); + request->SetRequestConfig(*requestConfig); + request->SetUuid(std::to_string(i + 35279)); + request->SetNlpRequestType(0); + networkList.push_back(request); + } + auto locatorAbility = LocatorAbility::GetInstance(); + locatorAbility->requests_->insert(make_pair(NETWORK_ABILITY, networkList)); EXPECT_EQ(true, reportManager_->OnReportLocation(location, NETWORK_ABILITY)); LBSLOGI(REPORT_MANAGER, "[ReportManagerTest] OnReportLocationTest001 end"); @@ -324,6 +343,7 @@ HWTEST_F(ReportManagerTest, OnReportLocationTest003, TestSize.Level1) requestConfig->SetPriority(PRIORITY_ACCURACY); requestConfig->SetFixNumber(0); requestConfig->SetTimeInterval(1); + requestConfig->SetScenario(SCENE_DAILY_LIFE_SERVICE); auto locatorImpl = Locator::GetInstance(); sptr callbackStub = new (std::nothrow) LocatorCallbackStub(); locatorImpl->EnableAbility(true); @@ -360,6 +380,7 @@ HWTEST_F(ReportManagerTest, OnReportLocationTest004, TestSize.Level1) requestConfig->SetPriority(PRIORITY_ACCURACY); requestConfig->SetFixNumber(1); // locating once requestConfig->SetTimeOut(120000); + requestConfig->SetScenario(SCENE_DAILY_LIFE_SERVICE); auto locatorImpl = Locator::GetInstance(); sptr callbackStub = new (std::nothrow) LocatorCallbackStub(); locatorImpl->EnableAbility(true); @@ -394,7 +415,7 @@ HWTEST_F(ReportManagerTest, IsRequestFuseTest001, TestSize.Level1) << "ReportManagerTest, IsRequestFuseTest001, TestSize.Level1"; LBSLOGI(REPORT_MANAGER, "[ReportManagerTest] IsRequestFuseTest001 begin"); EXPECT_EQ(false, reportManager_->IsRequestFuse(nullptr)); - + std::shared_ptr request = std::make_shared(); std::unique_ptr requestConfig = std::make_unique(); requestConfig->SetPriority(PRIORITY_FAST_FIRST_FIX); @@ -411,7 +432,7 @@ HWTEST_F(ReportManagerTest, IsRequestFuseTest002, TestSize.Level1) << "ReportManagerTest, IsRequestFuseTest002, TestSize.Level1"; LBSLOGI(REPORT_MANAGER, "[ReportManagerTest] IsRequestFuseTest002 begin"); EXPECT_EQ(false, reportManager_->IsRequestFuse(nullptr)); - + std::shared_ptr request = std::make_shared(); std::unique_ptr requestConfig = std::make_unique(); requestConfig->SetPriority(PRIORITY_UNSET); @@ -441,5 +462,70 @@ HWTEST_F(ReportManagerTest, UpdateLocationByRequestTest002, TestSize.Level1) reportManager_->UpdateLocationByRequest(tokenId_, tokenId_, location); LBSLOGI(REPORT_MANAGER, "[ReportManagerTest] UpdateLocationByRequestTest002 end"); } + +HWTEST_F(ReportManagerTest, ProcessRequestForReport001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "ReportManagerTest, ProcessRequestForReport001, TestSize.Level1"; + LBSLOGI(REPORT_MANAGER, "[ReportManagerTest] ProcessRequestForReport001 begin"); + std::shared_ptr request = std::make_shared(); + std::unique_ptr requestConfig = std::make_unique(); + requestConfig->SetTimeInterval(1); + request->SetUid(111); + request->SetPid(222); + request->SetPackageName("nameForTest"); + request->SetRequestConfig(*requestConfig); + request->SetRequesting(true); + request->SetUuid(std::to_string(35279)); + request->SetNlpRequestType(0); + auto deadRequests = std::make_unique>>(); + std::unique_ptr location = std::make_unique(); + location->SetUuid("35279"); + reportManager_->ProcessRequestForReport(request, deadRequests, location, NETWORK_ABILITY); + LBSLOGI(REPORT_MANAGER, "[ReportManagerTest] ProcessRequestForReport001 end"); +} + +HWTEST_F(ReportManagerTest, ProcessRequestForReport002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "ReportManagerTest, ProcessRequestForReport002, TestSize.Level1"; + LBSLOGI(REPORT_MANAGER, "[ReportManagerTest] ProcessRequestForReport002 begin"); + std::shared_ptr request = std::make_shared(); + std::unique_ptr requestConfig = std::make_unique(); + requestConfig->SetTimeInterval(1); + request->SetUid(111); + request->SetPid(222); + request->SetPackageName("nameForTest"); + + request->SetRequesting(true); + request->SetUuid(std::to_string(35279)); + request->SetNlpRequestType(0); + auto deadRequests = std::make_unique>>(); + std::unique_ptr location = std::make_unique(); + location->SetUuid("35279"); + reportManager_->ProcessRequestForReport(request, deadRequests, location, NETWORK_ABILITY); + LBSLOGI(REPORT_MANAGER, "[ReportManagerTest] ProcessRequestForReport002 end"); +} + +HWTEST_F(ReportManagerTest, WriteNetWorkReportEvent, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "ReportManagerTest, WriteNetWorkReportEvent, TestSize.Level1"; + LBSLOGI(REPORT_MANAGER, "[ReportManagerTest] WriteNetWorkReportEvent begin"); + std::shared_ptr request = std::make_shared(); + std::unique_ptr requestConfig = std::make_unique(); + requestConfig->SetTimeInterval(1); + request->SetUid(111); + request->SetPid(222); + request->SetPackageName("nameForTest"); + request->SetRequestConfig(*requestConfig); + request->SetRequesting(true); + request->SetUuid(std::to_string(35279)); + request->SetNlpRequestType(0); + std::unique_ptr location = std::make_unique(); + location->SetUuid("35279"); + reportManager_->WriteNetWorkReportEvent(NETWORK_ABILITY, request, location); + LBSLOGI(REPORT_MANAGER, "[ReportManagerTest] WriteNetWorkReportEvent end"); +} } // namespace Location } // namespace OHOS \ No newline at end of file diff --git a/test/location_manager/BUILD.gn b/test/location_manager/BUILD.gn new file mode 100644 index 00000000..dc831f85 --- /dev/null +++ b/test/location_manager/BUILD.gn @@ -0,0 +1,120 @@ +# Copyright (C) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/location/config.gni") +import("//build/test.gni") + +module_output_path = "location/service" + +ohos_unittest("LocatorManagerAbilityTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "./../../cfi_blocklist.txt" + } + branch_protector_ret = "pac_ret" + module_out_path = module_output_path + sources = [ + "$LOCATION_ROOT_DIR/test/location_manager/source/locator_ability_test.cpp", + "$LOCATION_ROOT_DIR/test/location_manager/source/locator_skeleton_test.cpp", + "$LOCATION_ROOT_DIR/test/location_manager/source/request_manager_test.cpp", + ] + + include_dirs = [ + "$LOCATION_ROOT_DIR/interfaces/inner_api/include", + "$LOCATION_ROOT_DIR/test/location_manager/include", + "$LOCATION_ROOT_DIR/test/location_manager/mock/include", + "$LOCATION_ROOT_DIR/test/mock/include", + "$SUBSYSTEM_DIR/location_locator/callback/include", + "$SUBSYSTEM_DIR/location_locator/locator/include", + ] + + deps = [ + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", + "$LOCATION_ROOT_DIR/frameworks/native/locator_agent:locator_agent", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", + "$SUBSYSTEM_DIR/location_locator/locator:lbsservice_locator", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:app_manager", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "distributed_notification_service:ans_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hisysevent:libhisysevent", + "init:libbegetutil", + "ipc:ipc_core", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + defines = [] + if (communication_wifi_enable) { + external_deps += [ "wifi:wifi_sdk" ] + defines += [ "WIFI_ENABLE" ] + } + + if (communication_bluetooth_enable) { + external_deps += [ "bluetooth:btframework" ] + defines += [ "BLUETOOTH_ENABLE" ] + } + + if (location_feature_with_geocode) { + defines += [ "FEATURE_GEOCODE_SUPPORT" ] + } + + if (location_feature_with_gnss) { + defines += [ "FEATURE_GNSS_SUPPORT" ] + } + + if (hdf_drivers_interface_location_geofence_enable) { + external_deps += + [ "drivers_interface_location_geofence:liblocation_geofence_proxy_2.0" ] + defines += [ "HDF_DRIVERS_INTERFACE_GEOFENCE_ENABLE" ] + } + + if (location_feature_with_network) { + defines += [ "FEATURE_NETWORK_SUPPORT" ] + } + + if (location_feature_with_passive) { + defines += [ "FEATURE_PASSIVE_SUPPORT" ] + } + + if (is_emulator) { + defines += [ "EMULATOR_ENABLED" ] + } + if (notification_distributed_notification_service_enable) { + defines += [ "NOTIFICATION_ENABLE" ] + } + module_out_path = module_output_path +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":LocatorManagerAbilityTest" ] +} diff --git a/test/location_manager/include/locator_ability_test.h b/test/location_manager/include/locator_ability_test.h new file mode 100644 index 00000000..bac8e9bf --- /dev/null +++ b/test/location_manager/include/locator_ability_test.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LOCATOR_ABILITY_TEST_H +#define LOCATOR_ABILITY_TEST_H + +#include + +#include "i_locator_callback.h" +#define private public +#define protected public +#include "locator_ability.h" +#undef protected +#undef private +#include "locator_background_proxy.h" +#include "locator_proxy.h" +#include "request.h" +#include "request_manager.h" + +namespace OHOS { +namespace Location { +class LocatorAbilityTest : public testing::Test { +public: + void SetUp(); + void TearDown(); + void MockNativePermission(); + uint64_t tokenId_; + void LoadSystemAbility(); +}; +} // namespace Location +} // namespace OHOS +#endif // LOCATOR_ABILITY_TEST_H \ No newline at end of file diff --git a/test/location_manager/include/locator_skeleton_test.h b/test/location_manager/include/locator_skeleton_test.h new file mode 100644 index 00000000..04f7959a --- /dev/null +++ b/test/location_manager/include/locator_skeleton_test.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LOCATOR_SKELETON_TEST_H +#define LOCATOR_SKELETON_TEST_H + +#include + +#ifdef FEATURE_GEOCODE_SUPPORT +#include "geo_coding_mock_info.h" +#endif +#include "i_locator_callback.h" +#define private public +#define protected public +#include "locator_ability.h" +#undef protected +#undef private +#include "locator_background_proxy.h" +#include "locator_proxy.h" +#include "request.h" +#include "request_manager.h" + +namespace OHOS { +namespace Location { +class LocatorSkeletonTest : public testing::Test { +public: + void SetUp(); + void TearDown(); + void MockNativePermission(); + void LoadSystemAbility(); + + uint64_t tokenId_; +}; +} // namespace Location +} // namespace OHOS +#endif // LOCATOR_SKELETON_TEST_H diff --git a/test/location_locator/include/request_manager_test.h b/test/location_manager/include/request_manager_test.h similarity index 100% rename from test/location_locator/include/request_manager_test.h rename to test/location_manager/include/request_manager_test.h diff --git a/test/location_manager/mock/include/mock_common_event_manager.h b/test/location_manager/mock/include/mock_common_event_manager.h new file mode 100644 index 00000000..8bf1beb2 --- /dev/null +++ b/test/location_manager/mock/include/mock_common_event_manager.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_LOCATION_MOCK_COMMON_EVENT_MANAGER_H +#define BASE_LOCATION_MOCK_COMMON_EVENT_MANAGER_H + +#include "gmock/gmock.h" + +#include "common_event_manager.h" + +namespace OHOS { +namespace Location { +class MockCommonEventManager { +public: + MOCK_METHOD(bool, PublishCommonEvent, (const CommonEventData &data)); + MOCK_METHOD(bool, PublishCommonEvent, (const CommonEventData &data, + const CommonEventPublishInfo &publishInfo)); + MOCK_METHOD(bool, PublishCommonEvent, (const CommonEventData &data, + const CommonEventPublishInfo &publishInfo, const std::shared_ptr &subscriber)); + MOCK_METHOD(bool, PublishCommonEvent, (const CommonEventData &data, + const CommonEventPublishInfo &publishInfo, const std::shared_ptr &subscriber)); + MOCK_METHOD(bool, PublishCommonEvent, (const CommonEventData &data, const CommonEventPublishInfo &publishInfo, + const std::shared_ptr &subscriber, const uid_t &uid)); + MOCK_METHOD(bool, SubscribeCommonEvent, (const std::shared_ptr &subscriber)); + MOCK_METHOD(bool, UnSubscribeCommonEvent, (const std::shared_ptr &subscriber)); + MOCK_METHOD(bool, GetStickyCommonEvent, (const std::string &event, CommonEventData &data)); + static MockCommonEventManager &GetInstance(void); + +private: + MockCommonEventManager() {} + ~MockCommonEventManager() {} +}; +} // namespace Location +} // namespace OHOS +#endif diff --git a/test/location_manager/mock/include/mock_locator_callback_host.h b/test/location_manager/mock/include/mock_locator_callback_host.h new file mode 100644 index 00000000..477e14b4 --- /dev/null +++ b/test/location_manager/mock/include/mock_locator_callback_host.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MOCK_LOCATOR_CALLBACK_HOST_H +#define MOCK_LOCATOR_CALLBACK_HOST_H + +#include "gmock/gmock.h" + +#include "message_option.h" +#include "message_parcel.h" +#include "iremote_object.h" +#include "iremote_stub.h" + +#include "locator_callback_host.h" +#include "location.h" + +namespace OHOS { +namespace Location { +class MockLocatorCallbackHost : public LocatorCallbackHost { +public: + MockLocatorCallbackHost() {} + ~MockLocatorCallbackHost() {} + MOCK_METHOD(void, OnLocationReport, (const std::unique_ptr& location)); + MOCK_METHOD(void, OnLocatingStatusChange, (const int status)); + MOCK_METHOD(void, OnErrorReport, (const int errorCode)); + MOCK_METHOD(int, OnRemoteRequest, (uint32_t code, + MessageParcel& data, MessageParcel& reply, MessageOption& option)); + MOCK_METHOD(int, SendRequest, (uint32_t code, + MessageParcel& data, MessageParcel& reply, MessageOption& option)); +}; +} // namespace Location +} // namespace OHOS +#endif \ No newline at end of file diff --git a/test/location_manager/mock/src/mock_common_event_manager.cpp b/test/location_manager/mock/src/mock_common_event_manager.cpp new file mode 100644 index 00000000..3da813ce --- /dev/null +++ b/test/location_manager/mock/src/mock_common_event_manager.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mock_common_event_manager.h" + +namespace OHOS { +namespace EventFwk { +bool CommonEventManager::PublishCommonEvent(const CommonEventData &data) +{ + return Location::MockCommonEventManager::GetInstance().PublishCommonEvent(data); +} + +bool CommonEventManager::PublishCommonEvent(const CommonEventData &data, + const CommonEventPublishInfo &publishInfo) +{ + return Location::MockCommonEventManager::GetInstance().PublishCommonEvent(data, publishInfo); +} + +bool CommonEventManager::PublishCommonEvent(const CommonEventData &data, + const CommonEventPublishInfo &publishInfo, const std::shared_ptr &subscriber) +{ + return Location::MockCommonEventManager::GetInstance().PublishCommonEvent(data, publishInfo, subscriber); +} + +bool CommonEventManager::PublishCommonEvent(const CommonEventData &data, const CommonEventPublishInfo &publishInfo, + const std::shared_ptr &subscriber, const uid_t &uid) +{ + return Location::MockCommonEventManager::GetInstance().PublishCommonEvent(data, publishInfo, subscriber, uid); +} + +bool CommonEventManager::SubscribeCommonEvent(const std::shared_ptr &subscriber) +{ + return Location::MockCommonEventManager::GetInstance().SubscribeCommonEvent(subscriber); +} + +bool CommonEventManager::UnSubscribeCommonEvent(const std::shared_ptr &subscriber) +{ + return Location::MockCommonEventManager::GetInstance().UnSubscribeCommonEvent(subscriber); +} + +bool CommonEventManager::GetStickyCommonEvent(const std::string &event, CommonEventData &data) +{ + return Location::MockCommonEventManager::GetInstance().GetStickyCommonEvent(event, data); +} +} // namespace EventFwk + +namespace Location { +MockCommonEventManager &MockCommonEventManager::GetInstance() +{ + static MockCommonEventManager gMockCommonEventManager; + return gMockCommonEventManager; +}; +} // namespace Location +} // namespace OHOS diff --git a/test/location_manager/source/locator_ability_test.cpp b/test/location_manager/source/locator_ability_test.cpp new file mode 100644 index 00000000..faf19a06 --- /dev/null +++ b/test/location_manager/source/locator_ability_test.cpp @@ -0,0 +1,869 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "locator_ability_test.h" +#include + +#define private public +#include "request.h" +#include "request_config.h" +#undef private + +#include "event_handler.h" +#include "event_runner.h" +#include "common_utils.h" +#include "constant_definition.h" +#include "country_code.h" +#include "country_code_callback_host.h" +#include "accesstoken_kit.h" +#include "nativetoken_kit.h" +#include "token_setproc.h" +#include "locator.h" +#include "permission_manager.h" +#include "report_manager.h" + +#ifdef FEATURE_GNSS_SUPPORT +#include "cached_locations_callback_host.h" +#endif +#ifdef FEATURE_GEOCODE_SUPPORT +#include "geo_address.h" +#endif +#ifdef FEATURE_GNSS_SUPPORT +#include "gnss_status_callback_host.h" +#endif +#include "i_locator.h" +#include "location.h" +#include "location_log.h" +#include "location_sa_load_manager.h" +#include "location_switch_callback_host.h" +#include "locator.h" +#include "locator_callback_host.h" +#include "locator_callback_proxy.h" +#include "locator_skeleton.h" +#ifdef FEATURE_GNSS_SUPPORT +#include "nmea_message_callback_host.h" +#endif +#include "permission_manager.h" +#include "geofence_request.h" +#include "accesstoken_kit.h" +#include "bundle_mgr_interface.h" +#include "bundle_mgr_proxy.h" +#include "if_system_ability_manager.h" +#include "ipc_skeleton.h" +#include "iservice_registry.h" +#include "nativetoken_kit.h" +#include "system_ability_definition.h" +#include "token_setproc.h" +#include "request_manager.h" +#include "app_identity.h" + +#define private public +#include "locator_ability.h" +#undef private + + +using namespace testing::ext; +namespace OHOS { +namespace Location { +const uint32_t EVENT_SEND_SWITCHSTATE_TO_HIFENCE = 0x0006; +const int32_t LOCATION_PERM_NUM = 4; +const std::string ARGS_HELP = "-h"; +void LocatorAbilityTest::SetUp() +{ + LoadSystemAbility(); + MockNativePermission(); +} + +void LocatorAbilityTest::TearDown() +{ +} + +void LocatorAbilityTest::LoadSystemAbility() +{ + LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_LOCATOR_SA_ID); +#ifdef FEATURE_GNSS_SUPPORT + LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_GNSS_SA_ID); +#endif +#ifdef FEATURE_PASSIVE_SUPPORT + LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_NOPOWER_LOCATING_SA_ID); +#endif +#ifdef FEATURE_NETWORK_SUPPORT + LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_NETWORK_LOCATING_SA_ID); +#endif +#ifdef FEATURE_GEOCODE_SUPPORT + LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_GEO_CONVERT_SA_ID); +#endif +} + +void LocatorAbilityTest::MockNativePermission() +{ + const char *perms[] = { + ACCESS_LOCATION.c_str(), ACCESS_APPROXIMATELY_LOCATION.c_str(), + ACCESS_BACKGROUND_LOCATION.c_str(), MANAGE_SECURE_SETTINGS.c_str(), + }; + NativeTokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = LOCATION_PERM_NUM, + .aclsNum = 0, + .dcaps = nullptr, + .perms = perms, + .acls = nullptr, + .processName = "LocatorAbilityTest", + .aplStr = "system_basic", + }; + tokenId_ = GetAccessTokenId(&infoInstance); + SetSelfTokenID(tokenId_); + Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityApplyRequestsTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityApplyRequestsTest001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityApplyRequestsTest001 begin"); + auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); + locatorAbility->locatorHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); + int delay = 1; + locatorAbility->ApplyRequests(delay); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityApplyRequestsTest001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityUpdateSaAbilityTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityUpdateSaAbilityTest001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityUpdateSaAbilityTest001 begin"); + auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); + locatorAbility->locatorHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); + locatorAbility->UpdateSaAbility(); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityUpdateSaAbilityTest001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityRemoveUnloadTaskTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityRemoveUnloadTaskTest001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityRemoveUnloadTask001 begin"); + auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); + locatorAbility->locatorHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); + int code = 1; + locatorAbility->RemoveUnloadTask(code); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityRemoveUnloadTaskTest001 end"); +} + +#ifdef FEATURE_GNSS_SUPPORT +HWTEST_F(LocatorAbilityTest, LocatorAbilityAddGnssGeofence001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityAddGnssGeofence001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityAddGnssGeofence001 begin"); + auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); + std::shared_ptr request = std::make_shared(); + locatorAbility->AddGnssGeofence(request); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityAddGnssGeofence001 end"); +} +#endif + +HWTEST_F(LocatorAbilityTest, LocatorAbilityAddGnssGeofence002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityAddGnssGeofence002, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityAddGnssGeofence002 begin"); + auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); + std::shared_ptr request = std::make_shared(); + locatorAbility->AddGnssGeofence(request); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityAddGnssGeofence002 end"); +} + +#ifdef FEATURE_GNSS_SUPPORT +HWTEST_F(LocatorAbilityTest, LocatorAbilityRemoveGnssGeofence001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityRemoveGnssGeofence001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityRemoveGnssGeofence001 begin"); + auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); + std::shared_ptr request = std::make_shared(); + locatorAbility->RemoveGnssGeofence(request); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityRemoveGnssGeofence001 end"); +} +#endif + +HWTEST_F(LocatorAbilityTest, LocatorAbilityRemoveGnssGeofence002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityRemoveGnssGeofence002, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityRemoveGnssGeofence002 begin"); + auto locatorAbility = sptr(new (std::nothrow) LocatorAbility()); + std::shared_ptr request = std::make_shared(); + locatorAbility->AddGnssGeofence(request); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityRemoveGnssGeofence002 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityStartLocating001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityStartLocating001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityStartLocating001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + locatorAbility->proxyMap_ = std::make_shared>>(); + std::unique_ptr requestConfig = std::make_unique(); + sptr callbackStub = new (std::nothrow) LocatorCallbackStub(); + AppIdentity identity; + locatorAbility->StartLocating(requestConfig, callbackStub, identity); + sptr objectGnss = CommonUtils::GetRemoteObject(LOCATION_GNSS_SA_ID, CommonUtils::InitDeviceId()); + locatorAbility->proxyMap_->insert(make_pair(GNSS_ABILITY, objectGnss)); + locatorAbility->reportManager_ = ReportManager::GetInstance(); + locatorAbility->requestManager_ = RequestManager::GetInstance(); + locatorAbility->StartLocating(requestConfig, callbackStub, identity); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityStartLocating001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityIsCacheVaildScenario001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityIsCacheVaildScenario001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityIsCacheVaildScenario001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + std::unique_ptr requestConfig = std::make_unique(); + AppIdentity identity; + std::shared_ptr request = std::make_shared(); + request->requestConfig_->scenario_ = SCENE_UNSET; + request->requestConfig_->priority_ = PRIORITY_LOW_POWER; + bool res = locatorAbility->IsCacheVaildScenario(request->GetRequestConfig()); + EXPECT_EQ(true, res); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityIsCacheVaildScenario001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityIsCacheVaildScenario002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityIsCacheVaildScenario002, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityIsCacheVaildScenario002 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + std::unique_ptr requestConfig = std::make_unique(); + AppIdentity identity; + std::shared_ptr request = std::make_shared(); + request->requestConfig_->scenario_ = SCENE_UNSET; + request->requestConfig_->priority_ = LOCATION_PRIORITY_ACCURACY; + bool res = locatorAbility->IsCacheVaildScenario(request->GetRequestConfig()); + EXPECT_EQ(false, res); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityIsCacheVaildScenario002 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityIsSingleRequest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityIsSingleRequest001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityIsSingleRequest001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + std::unique_ptr requestConfig = std::make_unique(); + AppIdentity identity; + std::shared_ptr request = std::make_shared(); + request->requestConfig_->fixNumber_ = 1; + bool res = locatorAbility->IsSingleRequest(request->GetRequestConfig()); + EXPECT_EQ(true, res); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityIsSingleRequest001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityNeedReportCacheLocation001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityNeedReportCacheLocation001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityNeedReportCacheLocation001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + sptr callback; + std::shared_ptr request = nullptr; + locatorAbility->reportManager_ = nullptr; + locatorAbility->NeedReportCacheLocation(request, callback); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityNeedReportCacheLocation001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityNeedReportCacheLocation002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityNeedReportCacheLocation002, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityNeedReportCacheLocation002 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + sptr callback; + std::shared_ptr request = std::make_shared(); + locatorAbility->reportManager_ = ReportManager::GetInstance(); + request->requestConfig_->fixNumber_ = 1; + request->requestConfig_->scenario_ = SCENE_DAILY_LIFE_SERVICE; + locatorAbility->NeedReportCacheLocation(request, callback); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityNeedReportCacheLocation002 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityNeedReportCacheLocation003, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityNeedReportCacheLocation003, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityNeedReportCacheLocation003 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + sptr callback; + std::shared_ptr request = std::make_shared(); + locatorAbility->reportManager_ = ReportManager::GetInstance(); + request->requestConfig_->fixNumber_ = 0; + request->requestConfig_->scenario_ = SCENE_DAILY_LIFE_SERVICE; + locatorAbility->NeedReportCacheLocation(request, callback); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityNeedReportCacheLocation003 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityNeedReportCacheLocation004, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityNeedReportCacheLocation004, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityNeedReportCacheLocation004 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + sptr callback; + std::shared_ptr request = std::make_shared(); + locatorAbility->reportManager_ = ReportManager::GetInstance(); + request->requestConfig_->fixNumber_ = 0; + request->requestConfig_->scenario_ = LOCATION_PRIORITY_ACCURACY; + locatorAbility->NeedReportCacheLocation(request, callback); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityNeedReportCacheLocation004 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityNeedReportCacheLocation005, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityNeedReportCacheLocation005, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityNeedReportCacheLocation005 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + sptr callback; + std::shared_ptr request = std::make_shared(); + locatorAbility->reportManager_ = ReportManager::GetInstance(); + request->requestConfig_->fixNumber_ = 1; + request->requestConfig_->scenario_ = LOCATION_PRIORITY_ACCURACY; + locatorAbility->NeedReportCacheLocation(request, callback); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityNeedReportCacheLocation005 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityHandleStartLocating001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityHandleStartLocating001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityHandleStartLocating001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + std::shared_ptr request = std::make_shared(); + sptr locatorCallbackHost = + sptr(new (std::nothrow)LocatorCallbackHost()); + sptr callback = sptr(locatorCallbackHost); + request->SetLocatorCallBack(callback); + locatorAbility->locatorHandler_ = nullptr; + locatorAbility->HandleStartLocating(request, callback); + locatorAbility->locatorHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); + locatorAbility->HandleStartLocating(request, callback); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityHandleStartLocating001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityStopLocating001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityStopLocating001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityStopLocating001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + sptr callback; + locatorAbility->requestManager_ = nullptr; + locatorAbility->StopLocating(callback); + locatorAbility->requestManager_ = RequestManager::GetInstance(); + locatorAbility->locatorHandler_ = nullptr; + locatorAbility->StopLocating(callback); + locatorAbility->locatorHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); + locatorAbility->StopLocating(callback); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityStopLocating001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityGetCacheLocation001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityGetCacheLocation001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityGetCacheLocation001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + std::unique_ptr loc; + AppIdentity identity; + locatorAbility->locatorHandler_ = nullptr; + locatorAbility->GetCacheLocation(loc, identity); + locatorAbility->locatorHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); + locatorAbility->GetCacheLocation(loc, identity); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityGetCacheLocation001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityCheckIsReportPermitted001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityCheckIsReportPermitted001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityCheckIsReportPermitted001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + AppIdentity identity; + locatorAbility->requests_ = nullptr; + locatorAbility->CheckIsReportPermitted(identity); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityCheckIsReportPermitted001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityEnableReverseGeocodingMock001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityEnableReverseGeocodingMock001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityEnableReverseGeocodingMock001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + locatorAbility->EnableReverseGeocodingMock(); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityEnableReverseGeocodingMock001 end"); +} + +#ifdef FEATURE_GEOCODE_SUPPORT +HWTEST_F(LocatorAbilityTest, LocatorAbilityEnableReverseGeocodingMock002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityEnableReverseGeocodingMock002, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityEnableReverseGeocodingMock002 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + locatorAbility->EnableReverseGeocodingMock(); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityEnableReverseGeocodingMock002 end"); +} +#endif + +HWTEST_F(LocatorAbilityTest, LocatorAbilityDisableReverseGeocodingMock001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityDisableReverseGeocodingMock001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityDisableReverseGeocodingMock001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + locatorAbility->DisableReverseGeocodingMock(); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityDisableReverseGeocodingMock001 end"); +} + +#ifdef FEATURE_GEOCODE_SUPPORT +HWTEST_F(LocatorAbilityTest, LocatorAbilityDisableReverseGeocodingMock002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityDisableReverseGeocodingMock002, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityDisableReverseGeocodingMock002 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + locatorAbility->DisableReverseGeocodingMock(); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityDisableReverseGeocodingMock002 end"); +} +#endif + +HWTEST_F(LocatorAbilityTest, LocatorAbilitySetReverseGeocodingMockInfo001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilitySetReverseGeocodingMockInfo001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilitySetReverseGeocodingMockInfo001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + std::vector> mockInfo; + locatorAbility->SetReverseGeocodingMockInfo(mockInfo); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilitySetReverseGeocodingMockInfo001 end"); +} + +#ifdef FEATURE_GEOCODE_SUPPORT +HWTEST_F(LocatorAbilityTest, LocatorAbilitySetReverseGeocodingMockInfo002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilitySetReverseGeocodingMockInfo002, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilitySetReverseGeocodingMockInfo002 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + std::vector> mockInfo; + locatorAbility->SetReverseGeocodingMockInfo(mockInfo); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilitySetReverseGeocodingMockInfo002 end"); +} +#endif + +HWTEST_F(LocatorAbilityTest, LocatorAbilityRegisterPermissionCallback001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityRegisterPermissionCallback001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityRegisterPermissionCallback001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + auto permissionMap = + std::make_shared>>(); + locatorAbility->permissionMap_ = permissionMap; + uint32_t callingTokenId = 10; + std::vector permissionNameList; + locatorAbility->RegisterPermissionCallback(callingTokenId, permissionNameList); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityRegisterPermissionCallback001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityUnRegisterPermissionCallback001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityUnRegisterPermissionCallback001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityUnRegisterPermissionCallback001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + auto permissionMap = + std::make_shared>>(); + locatorAbility->permissionMap_ = permissionMap; + uint32_t callingTokenId = 10; + std::vector permissionNameList; + locatorAbility->UnregisterPermissionCallback(callingTokenId); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityUnRegisterPermissionCallback001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityReportDataToResSched001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityReportDataToResSched001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityReportDataToResSched001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + std::string state("state"); + locatorAbility->ReportDataToResSched(state); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityReportDataToResSched001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityUpdateLastLocationRequestNum001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityUpdateLastLocationRequestNum001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityUpdateLastLocationRequestNum001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + locatorAbility->locatorHandler_ = nullptr; + locatorAbility->UpdateLastLocationRequestNum(); + locatorAbility->locatorHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); + locatorAbility->UpdateLastLocationRequestNum(); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityUpdateLastLocationRequestNum001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilitySendNetworkLocation001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilitySendNetworkLocation001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilitySendNetworkLocation001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + std::unique_ptr location = std::make_unique(); + locatorAbility->SendNetworkLocation(location); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilitySendNetworkLocation001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityRegisterLocationError001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityRegisterLocationError001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityRegisterLocationError001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + sptr callback; + AppIdentity identity; + locatorAbility->locatorHandler_ = nullptr; + locatorAbility->RegisterLocationError(callback, identity); + locatorAbility->locatorHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); + locatorAbility->RegisterLocationError(callback, identity); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityRegisterLocationError001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityUnRegisterLocationError001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityUnRegisterLocationError001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityUnRegisterLocationError001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + sptr callback; + AppIdentity identity; + locatorAbility->locatorHandler_ = nullptr; + locatorAbility->UnregisterLocationError(callback, identity); + locatorAbility->locatorHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); + locatorAbility->UnregisterLocationError(callback, identity); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityUnRegisterLocationError001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilityReportLocationError001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilityReportLocationError001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityReportLocationError001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + std::string uuid; + int32_t errCode = 10; + locatorAbility->locatorHandler_ = nullptr; + locatorAbility->ReportLocationError(uuid, errCode); + locatorAbility->locatorHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); + locatorAbility->ReportLocationError(uuid, errCode); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilityUnRegisterLocationError001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorAbilitySyncIdleState001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorAbilitySyncIdleState001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilitySyncIdleState001 begin"); + auto locatorAbility = + sptr(new (std::nothrow) LocatorAbility()); + bool state = true; + locatorAbility->locatorHandler_ = nullptr; + locatorAbility->SyncIdleState(state); + state = false; + locatorAbility->locatorHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); + locatorAbility->SyncIdleState(state); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorAbilitySyncIdleState001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocationMessageGetAbilityName001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocationMessageGetAbilityName001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocationMessageGetAbilityName001 begin"); + auto locationMessage = + new (std::nothrow) LocationMessage(); + locationMessage->GetAbilityName(); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocationMessageGetAbilityName001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocationMessageSetLocation001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocationMessageSetLocation001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocationMessageSetLocation001 begin"); + auto locationMessage = + new (std::nothrow) LocationMessage(); + locationMessage->location_ = nullptr; + std::unique_ptr location; + locationMessage->SetLocation(location); + location = std::make_unique(); + locationMessage->SetLocation(location); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocationMessageSetLocation001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocationMessageGetLocation001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocationMessageGetLocation001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocationMessageGetLocation001 begin"); + auto locationMessage = + new (std::nothrow) LocationMessage(); + locationMessage->location_ = nullptr; + locationMessage->GetLocation(); + locationMessage->location_ = std::make_unique(); + locationMessage->GetLocation(); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocationMessageGetLocation001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorHandlerInitLocatorHandlerEventMap001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorHandlerInitLocatorHandlerEventMap001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerInitLocatorHandlerEventMap001 begin"); + std::shared_ptr runner; + auto locatorHandler = + new (std::nothrow) LocatorHandler(runner); + locatorHandler->InitLocatorHandlerEventMap(); + locatorHandler->InitLocatorHandlerEventMap(); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerInitLocatorHandlerEventMap001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorHandlerGetCachedLocationSuccess001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorHandlerGetCachedLocationSuccess001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerGetCachedLocationSuccess001 begin"); + std::shared_ptr runner; + auto locatorHandler = + new (std::nothrow) LocatorHandler(runner); + int state = 1; + AppExecFwk::InnerEvent::Pointer event = + AppExecFwk::InnerEvent::Get(EVENT_SEND_SWITCHSTATE_TO_HIFENCE, state); + locatorHandler->GetCachedLocationSuccess(event); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerGetCachedLocationSuccess001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorHandlerGetCachedLocationFailed001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorHandlerGetCachedLocationFailed001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerGetCachedLocationFailed001 begin"); + std::shared_ptr runner; + auto locatorHandler = + new (std::nothrow) LocatorHandler(runner); + int state = 1; + AppExecFwk::InnerEvent::Pointer event = + AppExecFwk::InnerEvent::Get(EVENT_SEND_SWITCHSTATE_TO_HIFENCE, state); + locatorHandler->GetCachedLocationFailed(event); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerGetCachedLocationFailed001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorHandlerUpdateSaEvent001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorHandlerUpdateSaEvent001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerUpdateSaEvent001 begin"); + std::shared_ptr runner; + auto locatorHandler = + new (std::nothrow) LocatorHandler(runner); + int state = 1; + AppExecFwk::InnerEvent::Pointer event = + AppExecFwk::InnerEvent::Get(EVENT_SEND_SWITCHSTATE_TO_HIFENCE, state); + locatorHandler->UpdateSaEvent(event); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerUpdateSaEvent001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorHandlerApplyRequirementsEvent001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorHandlerApplyRequirementsEvent001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerApplyRequirementsEvent001 begin"); + std::shared_ptr runner; + auto locatorHandler = + new (std::nothrow) LocatorHandler(runner); + int state = 1; + AppExecFwk::InnerEvent::Pointer event = + AppExecFwk::InnerEvent::Get(EVENT_SEND_SWITCHSTATE_TO_HIFENCE, state); + locatorHandler->ApplyRequirementsEvent(event); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerApplyRequirementsEvent001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorHandlerRetryRegisterActionEvent001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorHandlerRetryRegisterActionEvent001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerRetryRegisterActionEvent001 begin"); + std::shared_ptr runner; + auto locatorHandler = + new (std::nothrow) LocatorHandler(runner); + int state = 1; + AppExecFwk::InnerEvent::Pointer event = + AppExecFwk::InnerEvent::Get(EVENT_SEND_SWITCHSTATE_TO_HIFENCE, state); + locatorHandler->RetryRegisterActionEvent(event); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerRetryRegisterActionEvent001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorHandlerReportLocationMessageEvent001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorHandlerReportLocationMessageEvent001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerReportLocationMessageEvent001 begin"); + std::shared_ptr runner; + auto locatorHandler = + new (std::nothrow) LocatorHandler(runner); + int state = 1; + AppExecFwk::InnerEvent::Pointer event = + AppExecFwk::InnerEvent::Get(EVENT_SEND_SWITCHSTATE_TO_HIFENCE, state); + locatorHandler->ReportLocationMessageEvent(event); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerReportLocationMessageEvent001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorHandlerStartAndStopLocatingEvent001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorHandlerStartLocatingEvent001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerStartLocatingEvent001 begin"); + std::shared_ptr runner; + auto locatorHandler = + new (std::nothrow) LocatorHandler(runner); + int state = 1; + AppExecFwk::InnerEvent::Pointer event = + AppExecFwk::InnerEvent::Get(EVENT_SEND_SWITCHSTATE_TO_HIFENCE, state); + locatorHandler->StartLocatingEvent(event); + locatorHandler->StopLocatingEvent(event); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerStartLocatingEvent001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorHandlerUpdateLastLocationRequestNum001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorHandlerUpdateLastLocationRequestNum001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerUpdateLastLocationRequestNum001 begin"); + std::shared_ptr runner; + auto locatorHandler = + new (std::nothrow) LocatorHandler(runner); + int state = 1; + AppExecFwk::InnerEvent::Pointer event = + AppExecFwk::InnerEvent::Get(EVENT_SEND_SWITCHSTATE_TO_HIFENCE, state); + locatorHandler->UpdateLastLocationRequestNum(event); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerUpdateLastLocationRequestNum001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorHandlerUnloadSaEvent001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorHandlerUnloadSaEvent001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerUnloadSaEvent001 begin"); + std::shared_ptr runner; + auto locatorHandler = + new (std::nothrow) LocatorHandler(runner); + int state = 1; + AppExecFwk::InnerEvent::Pointer event = + AppExecFwk::InnerEvent::Get(EVENT_SEND_SWITCHSTATE_TO_HIFENCE, state); + locatorHandler->UnloadSaEvent(event); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandlerUnloadSaEvent001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorHandler001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorHandler001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandler001 begin"); + std::shared_ptr runner; + auto locatorHandler = + new (std::nothrow) LocatorHandler(runner); + int state = 1; + AppExecFwk::InnerEvent::Pointer event = + AppExecFwk::InnerEvent::Get(EVENT_SEND_SWITCHSTATE_TO_HIFENCE, state); + locatorHandler->RegLocationErrorEvent(event); + locatorHandler->UnRegLocationErrorEvent(event); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandler001 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorHandler002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorHandler002, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandler002 begin"); + std::shared_ptr runner; + auto locatorHandler = + new (std::nothrow) LocatorHandler(runner); + int state = 1; + AppExecFwk::InnerEvent::Pointer event = + AppExecFwk::InnerEvent::Get(EVENT_SEND_SWITCHSTATE_TO_HIFENCE, state); + locatorHandler->SyncIdleState(event); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorHandler002 end"); +} + +HWTEST_F(LocatorAbilityTest, LocatorCallbackDeathRecipient001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorAbilityTest, LocatorCallbackDeathRecipient001, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorCallbackDeathRecipient001 begin"); + int32_t tokenId = 1; + auto recipient = + sptr(new (std::nothrow) LocatorCallbackDeathRecipient(tokenId)); + wptr remote; + recipient->OnRemoteDied(remote); + LBSLOGI(LOCATOR, "[LocatorAbilityTest] LocatorCallbackDeathRecipient001 end"); +} +} // namespace Location +} // namespace OHOS \ No newline at end of file diff --git a/test/location_manager/source/locator_skeleton_test.cpp b/test/location_manager/source/locator_skeleton_test.cpp new file mode 100644 index 00000000..bca14dc6 --- /dev/null +++ b/test/location_manager/source/locator_skeleton_test.cpp @@ -0,0 +1,1029 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "locator_skeleton_test.h" + +#include + +#include "accesstoken_kit.h" +#include "bundle_mgr_interface.h" +#include "bundle_mgr_proxy.h" +#include "if_system_ability_manager.h" +#include "ipc_skeleton.h" +#include "iservice_registry.h" +#include "nativetoken_kit.h" +#include "system_ability_definition.h" +#include "token_setproc.h" + +#include "app_identity.h" + +#include "common_utils.h" +#include "constant_definition.h" +#include "i_locator.h" +#include "location.h" +#include "location_log.h" +#include "location_sa_load_manager.h" +#include "locator.h" +#define private public +#include "locator_skeleton.h" +#undef private +#ifdef FEATURE_GNSS_SUPPORT +#include "nmea_message_callback_napi.h" +#endif +#include "permission_manager.h" +#include "location_data_rdb_manager.h" + +using namespace testing::ext; + +namespace OHOS { +namespace Location { +const int32_t LOCATION_PERM_NUM = 5; +const std::string RUNNING_STATE_OBSERVER = "ohos.permission.RUNNING_STATE_OBSERVER"; +void LocatorSkeletonTest::SetUp() +{ + /* + * @tc.setup: Get system ability's pointer and get sa proxy object. + */ + LoadSystemAbility(); + MockNativePermission(); +} + +void LocatorSkeletonTest::TearDown() +{ +} + +void LocatorSkeletonTest::LoadSystemAbility() +{ + LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_LOCATOR_SA_ID); +#ifdef FEATURE_GNSS_SUPPORT + LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_GNSS_SA_ID); +#endif +#ifdef FEATURE_PASSIVE_SUPPORT + LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_NOPOWER_LOCATING_SA_ID); +#endif +#ifdef FEATURE_NETWORK_SUPPORT + LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_NETWORK_LOCATING_SA_ID); +#endif +#ifdef FEATURE_GEOCODE_SUPPORT + LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_GEO_CONVERT_SA_ID); +#endif +} + +void LocatorSkeletonTest::MockNativePermission() +{ + const char *perms[] = { + ACCESS_LOCATION.c_str(), ACCESS_APPROXIMATELY_LOCATION.c_str(), + ACCESS_BACKGROUND_LOCATION.c_str(), MANAGE_SECURE_SETTINGS.c_str(), + RUNNING_STATE_OBSERVER.c_str(), ACCESS_MOCK_LOCATION.c_str(), + }; + NativeTokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = LOCATION_PERM_NUM, + .aclsNum = 0, + .dcaps = nullptr, + .perms = perms, + .acls = nullptr, + .processName = "ohos.permission.MOCK_LOCATION", + .aplStr = "system_basic", + }; + tokenId_ = GetAccessTokenId(&infoInstance); + SetSelfTokenID(tokenId_); + Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); +} + +HWTEST_F(LocatorSkeletonTest, PreGetSwitchState, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreGetSwitchState, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreGetSwitchState begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreGetSwitchState(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreGetSwitchState end"); +} + +HWTEST_F(LocatorSkeletonTest, PreRegisterSwitchCallback, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreRegisterSwitchCallback, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreRegisterSwitchCallback begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreRegisterSwitchCallback(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreRegisterSwitchCallback end"); +} + +HWTEST_F(LocatorSkeletonTest, PreStartLocating, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreStartLocating, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreStartLocating begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + auto callback = sptr(new (std::nothrow) LocatorCallbackNapi()); + data.WriteInt32(1); + data.WriteInt32(1); + data.WriteInt32(1); + data.WriteDouble(1.0); + data.WriteFloat(1.0); + data.WriteInt32(1); + data.WriteInt32(1); + data.WriteRemoteObject(callback->AsObject()); + MessageParcel reply; + AppIdentity identity; + locatorAbilityStub->PreStartLocating(data, reply, identity); + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + LocationDataRdbManager::SetSwitchState(ENABLED); + locatorAbilityStub->PreStartLocating(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreStartLocating end"); +} + +HWTEST_F(LocatorSkeletonTest, PreStopLocating, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreStopLocating, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreStopLocating begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + auto callback = sptr(new (std::nothrow) LocatorCallbackNapi()); + data.WriteRemoteObject(callback->AsObject()); + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + locatorAbilityStub->PreStopLocating(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreStopLocating end"); +} + +HWTEST_F(LocatorSkeletonTest, PreGetCacheLocation, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreGetCacheLocation, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreGetCacheLocation begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + auto callback = sptr(new (std::nothrow) LocatorCallbackNapi()); + MessageParcel reply; + MessageParcel data; + data.WriteInt32(1); + data.WriteBool(true); + data.WriteRemoteObject(callback->AsObject()); + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + LocationDataRdbManager::SetSwitchState(ENABLED); + auto result = locatorAbilityStub->PreGetCacheLocation(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreGetCacheLocation end"); +} + +HWTEST_F(LocatorSkeletonTest, PreEnableAbility, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreEnableAbility, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreEnableAbility begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + locatorAbilityStub->PreEnableAbility(data, reply, identity); + auto callback = sptr(new (std::nothrow) LocatorCallbackNapi()); + data.WriteBool(true); + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreEnableAbility(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreEnableAbility end"); +} + +HWTEST_F(LocatorSkeletonTest, PreUpdateSaAbility, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreUpdateSaAbility, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreUpdateSaAbility begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + locatorAbilityStub->PreUpdateSaAbility(data, reply, identity); + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreUpdateSaAbility(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreUpdateSaAbility end"); +} + +#ifdef FEATURE_GEOCODE_SUPPORT +HWTEST_F(LocatorSkeletonTest, PreIsGeoConvertAvailable, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreIsGeoConvertAvailable, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreIsGeoConvertAvailable begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + locatorAbilityStub->PreIsGeoConvertAvailable(data, reply, identity); + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreIsGeoConvertAvailable(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreIsGeoConvertAvailable end"); +} +#endif + +#ifdef FEATURE_GEOCODE_SUPPORT +HWTEST_F(LocatorSkeletonTest, PreGetAddressByCoordinate, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreGetAddressByCoordinate, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreGetAddressByCoordinate begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreGetAddressByCoordinate(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreGetAddressByCoordinate end"); +} +#endif + +#ifdef FEATURE_GEOCODE_SUPPORT +HWTEST_F(LocatorSkeletonTest, PreGetAddressByLocationName, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreGetAddressByLocationName, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreGetAddressByLocationName begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreGetAddressByLocationName(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreGetAddressByLocationName end"); +} +#endif + +#ifdef FEATURE_GEOCODE_SUPPORT +HWTEST_F(LocatorSkeletonTest, PreUnregisterSwitchCallback, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreUnregisterSwitchCallback, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreUnregisterSwitchCallback begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreUnregisterSwitchCallback(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreUnregisterSwitchCallback end"); +} +#endif + +#ifdef FEATURE_GNSS_SUPPORT +HWTEST_F(LocatorSkeletonTest, PreRegisterGnssStatusCallback, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreRegisterGnssStatusCallback, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreRegisterGnssStatusCallback begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + locatorAbilityStub->PreRegisterGnssStatusCallback(data, reply, identity); + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreRegisterGnssStatusCallback(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreRegisterGnssStatusCallback end"); +} +#endif + +#ifdef FEATURE_GNSS_SUPPORT +HWTEST_F(LocatorSkeletonTest, PreUnregisterGnssStatusCallback, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreUnregisterGnssStatusCallback, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreUnregisterGnssStatusCallback begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + locatorAbilityStub->PreRegisterGnssStatusCallback(data, reply, identity); + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreUnregisterGnssStatusCallback(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreUnregisterGnssStatusCallback end"); +} +#endif + +#ifdef FEATURE_GNSS_SUPPORT +HWTEST_F(LocatorSkeletonTest, PreRegisterNmeaMessageCallback, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreRegisterNmeaMessageCallback, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreRegisterNmeaMessageCallback begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + locatorAbilityStub->PreRegisterGnssStatusCallback(data, reply, identity); + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreRegisterNmeaMessageCallback(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreRegisterNmeaMessageCallback end"); +} +#endif + +#ifdef FEATURE_GNSS_SUPPORT +HWTEST_F(LocatorSkeletonTest, PreUnregisterNmeaMessageCallback, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreUnregisterNmeaMessageCallback, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreUnregisterNmeaMessageCallback begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreUnregisterNmeaMessageCallback(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreUnregisterNmeaMessageCallback end"); +} +#endif + +#ifdef FEATURE_GNSS_SUPPORT +HWTEST_F(LocatorSkeletonTest, PreRegisterNmeaMessageCallbackV9, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreRegisterNmeaMessageCallbackV9, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreRegisterNmeaMessageCallbackV9 begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + locatorAbilityStub->PreRegisterNmeaMessageCallbackV9(data, reply, identity); + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreRegisterNmeaMessageCallbackV9(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreRegisterNmeaMessageCallbackV9 end"); +} +#endif + +#ifdef FEATURE_GNSS_SUPPORT +HWTEST_F(LocatorSkeletonTest, PreUnregisterNmeaMessageCallbackV9, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreUnregisterNmeaMessageCallbackV9, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreUnregisterNmeaMessageCallbackV9 begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + locatorAbilityStub->PreUnregisterNmeaMessageCallbackV9(data, reply, identity); + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreUnregisterNmeaMessageCallbackV9(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreUnregisterNmeaMessageCallbackV9 end"); +} +#endif + +HWTEST_F(LocatorSkeletonTest, PreIsLocationPrivacyConfirmed, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreIsLocationPrivacyConfirmed, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreIsLocationPrivacyConfirmed begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + locatorAbilityStub->PreIsLocationPrivacyConfirmed(data, reply, identity); + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreIsLocationPrivacyConfirmed(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreIsLocationPrivacyConfirmed end"); +} + +HWTEST_F(LocatorSkeletonTest, PreSetLocationPrivacyConfirmStatus, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreSetLocationPrivacyConfirmStatus, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreSetLocationPrivacyConfirmStatus begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + locatorAbilityStub->PreSetLocationPrivacyConfirmStatus(data, reply, identity); + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreSetLocationPrivacyConfirmStatus(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreSetLocationPrivacyConfirmStatus end"); +} + +HWTEST_F(LocatorSkeletonTest, PreStartCacheLocating, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreStartCacheLocating, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreStartCacheLocating begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + auto callback = sptr(new (std::nothrow) LocatorCallbackNapi()); + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + data.WriteInt32(1); + data.WriteBool(true); + data.WriteRemoteObject(callback->AsObject()); + locatorAbilityStub->PreStartCacheLocating(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreStartCacheLocating end"); +} + +HWTEST_F(LocatorSkeletonTest, PreStopCacheLocating, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreStopCacheLocating, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreStopCacheLocating begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto callback = sptr(new (std::nothrow) LocatorCallbackNapi()); + data.WriteInt32(1); + data.WriteBool(true); + data.WriteRemoteObject(callback->AsObject()); + locatorAbilityStub->PreStopCacheLocating(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreStopCacheLocating end"); +} + +HWTEST_F(LocatorSkeletonTest, PreGetCachedGnssLocationsSize, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreGetCachedGnssLocationsSize, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreGetCachedGnssLocationsSize begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + locatorAbilityStub->PreGetCachedGnssLocationsSize(data, reply, identity); + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreGetCachedGnssLocationsSize(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreGetCachedGnssLocationsSize end"); +} + +HWTEST_F(LocatorSkeletonTest, PreFlushCachedGnssLocations, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreFlushCachedGnssLocations, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreFlushCachedGnssLocations begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + locatorAbilityStub->PreFlushCachedGnssLocations(data, reply, identity); + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreFlushCachedGnssLocations(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreFlushCachedGnssLocations end"); +} + +HWTEST_F(LocatorSkeletonTest, PreSendCommand, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreSendCommand, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreSendCommand begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + locatorAbilityStub->PreSendCommand(data, reply, identity); + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreSendCommand(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreSendCommand end"); +} + +HWTEST_F(LocatorSkeletonTest, PreAddFence, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreAddFence, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreAddFence begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + locatorAbilityStub->PreAddFence(data, reply, identity); + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreAddFence(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreAddFence end"); +} + + +HWTEST_F(LocatorSkeletonTest, PreRemoveFence, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreRemoveFence, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreRemoveFence begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreRemoveFence(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreRemoveFence end"); +} + +HWTEST_F(LocatorSkeletonTest, PreAddGnssGeofence, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreAddGnssGeofence, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreAddGnssGeofence begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreAddGnssGeofence(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreAddGnssGeofence end"); +} + +HWTEST_F(LocatorSkeletonTest, PreRemoveGnssGeofence, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreRemoveGnssGeofence, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreRemoveGnssGeofence begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreRemoveGnssGeofence(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreRemoveGnssGeofence end"); +} + +HWTEST_F(LocatorSkeletonTest, PreEnableLocationMock, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreEnableLocationMock, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreEnableLocationMock begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + locatorAbilityStub->PreEnableLocationMock(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreEnableLocationMock end"); +} + +HWTEST_F(LocatorSkeletonTest, PreDisableLocationMock, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreDisableLocationMock, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreDisableLocationMock begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + locatorAbilityStub->PreDisableLocationMock(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreDisableLocationMock end"); +} + +HWTEST_F(LocatorSkeletonTest, PreSetMockedLocations, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreSetMockedLocations, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreSetMockedLocations begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + locatorAbilityStub->PreSetMockedLocations(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreSetMockedLocations end"); +} + +HWTEST_F(LocatorSkeletonTest, PreEnableReverseGeocodingMock, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreEnableReverseGeocodingMock, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreEnableReverseGeocodingMock begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + locatorAbilityStub->PreEnableReverseGeocodingMock(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreEnableReverseGeocodingMock end"); +} + +HWTEST_F(LocatorSkeletonTest, PreDisableReverseGeocodingMock, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreDisableReverseGeocodingMock, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreDisableReverseGeocodingMock begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + locatorAbilityStub->PreDisableReverseGeocodingMock(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreDisableReverseGeocodingMock end"); +} + +HWTEST_F(LocatorSkeletonTest, PreSetReverseGeocodingMockInfo, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreSetReverseGeocodingMockInfo, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreSetReverseGeocodingMockInfo begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + locatorAbilityStub->PreSetReverseGeocodingMockInfo(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreSetReverseGeocodingMockInfo end"); +} + +HWTEST_F(LocatorSkeletonTest, PreProxyForFreeze, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreProxyForFreeze, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreProxyForFreeze begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + locatorAbilityStub->PreProxyForFreeze(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreProxyForFreeze end"); +} + +HWTEST_F(LocatorSkeletonTest, PreResetAllProxy, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreResetAllProxy, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreResetAllProxy begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + locatorAbilityStub->PreResetAllProxy(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreResetAllProxy end"); +} + +HWTEST_F(LocatorSkeletonTest, PreReportLocation, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreReportLocation, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreReportLocation begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreReportLocation(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreReportLocation end"); +} + +HWTEST_F(LocatorSkeletonTest, PreRegisterLocatingRequiredDataCallback, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreRegisterLocatingRequiredDataCallback, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreRegisterLocatingRequiredDataCallback begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + locatorAbilityStub->PreRegisterLocatingRequiredDataCallback(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreRegisterLocatingRequiredDataCallback end"); +} + +HWTEST_F(LocatorSkeletonTest, PreUnregisterLocatingRequiredDataCallback, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreUnregisterLocatingRequiredDataCallback, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreUnregisterLocatingRequiredDataCallback begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + locatorAbilityStub->PreUnregisterLocatingRequiredDataCallback(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreUnregisterLocatingRequiredDataCallback end"); +} + +HWTEST_F(LocatorSkeletonTest, PreQuerySupportCoordinateSystemType, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreQuerySupportCoordinateSystemType, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreQuerySupportCoordinateSystemType begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + locatorAbilityStub->PreQuerySupportCoordinateSystemType(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreQuerySupportCoordinateSystemType end"); +} + +HWTEST_F(LocatorSkeletonTest, PreRegisterLocationError, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreRegisterLocationError, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreRegisterLocationError begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + LocationDataRdbManager::SetSwitchState(ENABLED); + locatorAbilityStub->PreRegisterLocationError(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreRegisterLocationError end"); +} + +HWTEST_F(LocatorSkeletonTest, PreUnregisterLocationError, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreUnregisterLocationError, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreUnregisterLocationError begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + locatorAbilityStub->PreUnregisterLocationError(data, reply, identity); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreUnregisterLocationError end"); +} + +HWTEST_F(LocatorSkeletonTest, PreReportLocationError, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, PreReportLocationError, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreReportLocationError begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + + MessageParcel reply; + AppIdentity identity; + identity.SetPid(1); + identity.SetUid(2); + uint32_t tokenId = static_cast(tokenId_); + identity.SetTokenId(tokenId); + identity.SetFirstTokenId(0); + identity.SetBundleName("bundleName"); + auto result = locatorAbilityStub->PreReportLocationError(data, reply, identity); + EXPECT_EQ(ERRCODE_SUCCESS, result); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] PreReportLocationError end"); +} + +HWTEST_F(LocatorSkeletonTest, OnRemoteRequest, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "LocatorSkeletonTest, OnRemoteRequest, TestSize.Level1"; + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] OnRemoteRequest begin"); + auto locatorAbilityStub = sptr(new (std::nothrow) LocatorAbilityStub()); + MessageParcel data; + MessageParcel reply; + MessageOption option; + locatorAbilityStub->OnRemoteRequest(3, data, reply, option); + LBSLOGI(LOCATOR, "[LocatorSkeletonTest] OnRemoteRequest end"); +} +} // namespace Location +} // namespace OHOS diff --git a/test/location_locator/source/request_manager_test.cpp b/test/location_manager/source/request_manager_test.cpp similarity index 89% rename from test/location_locator/source/request_manager_test.cpp rename to test/location_manager/source/request_manager_test.cpp index 25e26077..b1cbe7c5 100644 --- a/test/location_locator/source/request_manager_test.cpp +++ b/test/location_manager/source/request_manager_test.cpp @@ -22,7 +22,6 @@ #include "i_locator_callback.h" #include "locator_ability.h" -#include "locator_callback_host.h" #include "request.h" #include "request_config.h" #include "permission_manager.h" @@ -46,15 +45,12 @@ void RequestManagerTest::SetUp() request_->SetTokenId(tokenId_); request_->SetFirstTokenId(0); request_->SetPackageName("RequestManagerTest"); + request_->SetRequesting(true); auto requestConfig = std::make_unique(); EXPECT_NE(nullptr, requestConfig); requestConfig->SetPriority(PRIORITY_FAST_FIRST_FIX); - requestConfig->SetFixNumber(1); + requestConfig->SetFixNumber(0); request_->SetRequestConfig(*requestConfig); - sptr locatorCallbackHost = - sptr(new (std::nothrow)LocatorCallbackHost()); - callback_ = sptr(locatorCallbackHost); - request_->SetLocatorCallBack(callback_); } void RequestManagerTest::TearDown() @@ -93,10 +89,6 @@ void RequestManagerTest::FillRequestField(std::shared_ptr& request) std::unique_ptr requestConfig = std::make_unique(); request->SetRequestConfig(*requestConfig); - sptr locatorCallbackHost = - sptr(new (std::nothrow)LocatorCallbackHost()); - auto callback = sptr(locatorCallbackHost); - request->SetLocatorCallBack(callback); request->SetRequesting(false); std::unique_ptr location = std::make_unique(); request->SetLastLocation(location); @@ -147,6 +139,30 @@ HWTEST_F(RequestManagerTest, HandleStartAndStopLocating001, TestSize.Level1) LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] HandleStartAndStopLocating001 end"); } +HWTEST_F(RequestManagerTest, HandleStartAndStopLocating002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "RequestManagerTest, HandleStartAndStopLocating002, TestSize.Level1"; + LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] HandleStartAndStopLocating002 begin"); + ASSERT_TRUE(requestManager_ != nullptr); + std::shared_ptr request = std::make_shared(); + + request->SetUid(SYSTEM_UID); + request->SetPid(0); + request->SetTokenId(tokenId_); + request->SetFirstTokenId(0); + request->SetPackageName("RequestManagerTest"); + auto requestConfig = std::make_unique(); + requestConfig->SetPriority(PRIORITY_FAST_FIRST_FIX); + requestConfig->SetFixNumber(0); + request->SetRequestConfig(*requestConfig); + sptr locatorCallbackHost = + sptr(new (std::nothrow)LocatorCallbackHost()); + auto callback = sptr(locatorCallbackHost); + request->SetLocatorCallBack(callback); + LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] HandleStartAndStopLocating002 end"); +} + HWTEST_F(RequestManagerTest, HandlePowerSuspendChanged001, TestSize.Level1) { GTEST_LOG_(INFO) @@ -170,7 +186,7 @@ HWTEST_F(RequestManagerTest, HandlePowerSuspendChanged002, TestSize.Level1) LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] HandlePowerSuspendChanged002 begin"); ASSERT_TRUE(requestManager_ != nullptr); requestManager_->UpdateRequestRecord(request_, false); - EXPECT_EQ(false, requestManager_->IsUidInProcessing(SYSTEM_UID)); + EXPECT_EQ(true, requestManager_->IsUidInProcessing(SYSTEM_UID)); int32_t state1 = static_cast(AppExecFwk::ApplicationState::APP_STATE_FOREGROUND); requestManager_->HandlePowerSuspendChanged(request_->GetPid(), @@ -188,7 +204,7 @@ HWTEST_F(RequestManagerTest, HandlePowerSuspendChanged003, TestSize.Level1) LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] HandlePowerSuspendChanged003 begin"); ASSERT_TRUE(requestManager_ != nullptr); requestManager_->UpdateRequestRecord(request_, false); - EXPECT_EQ(false, requestManager_->IsUidInProcessing(SYSTEM_UID)); + EXPECT_EQ(true, requestManager_->IsUidInProcessing(SYSTEM_UID)); int32_t state1 = static_cast(AppExecFwk::ApplicationState::APP_STATE_FOREGROUND); requestManager_->HandlePowerSuspendChanged(request_->GetPid() + 1, @@ -206,7 +222,7 @@ HWTEST_F(RequestManagerTest, HandlePowerSuspendChanged004, TestSize.Level1) LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] HandlePowerSuspendChanged004 begin"); ASSERT_TRUE(requestManager_ != nullptr); requestManager_->UpdateRequestRecord(request_, false); - EXPECT_EQ(false, requestManager_->IsUidInProcessing(SYSTEM_UID)); + EXPECT_EQ(true, requestManager_->IsUidInProcessing(SYSTEM_UID)); int32_t state1 = static_cast(AppExecFwk::ApplicationState::APP_STATE_FOREGROUND); requestManager_->HandlePowerSuspendChanged(request_->GetPid(), @@ -225,7 +241,7 @@ HWTEST_F(RequestManagerTest, UpdateRequestRecord001, TestSize.Level1) requestManager_->UpdateRequestRecord(request_, true); // uid = 1000 should be added to runningUids EXPECT_EQ(true, requestManager_->IsUidInProcessing(SYSTEM_UID)); requestManager_->UpdateRequestRecord(request_, false); // uid = 1000 should be removed from runningUids - EXPECT_EQ(false, requestManager_->IsUidInProcessing(SYSTEM_UID)); + EXPECT_EQ(true, requestManager_->IsUidInProcessing(SYSTEM_UID)); LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] UpdateRequestRecord001 end"); } @@ -235,7 +251,7 @@ HWTEST_F(RequestManagerTest, UpdateUsingPermissionTest001, TestSize.Level1) << "RequestManagerTest, UpdateUsingPermissionTest001, TestSize.Level1"; LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] UpdateUsingPermissionTest001 begin"); ASSERT_TRUE(requestManager_ != nullptr); - requestManager_->UpdateUsingPermission(nullptr); + requestManager_->UpdateUsingPermission(nullptr, true); LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] UpdateUsingPermissionTest001 end"); } @@ -247,10 +263,10 @@ HWTEST_F(RequestManagerTest, UpdateUsingPermissionTest002, TestSize.Level1) EXPECT_EQ(false, request_->GetLocationPermState()); EXPECT_EQ(false, request_->GetBackgroundPermState()); EXPECT_EQ(false, request_->GetApproximatelyPermState()); - requestManager_->UpdateUsingPermission(request_); + requestManager_->UpdateUsingPermission(request_, true); EXPECT_EQ(false, request_->GetLocationPermState()); EXPECT_EQ(false, request_->GetBackgroundPermState()); - EXPECT_EQ(false, request_->GetApproximatelyPermState()); + EXPECT_EQ(true, request_->GetApproximatelyPermState()); LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] UpdateUsingPermissionTest002 end"); } @@ -263,7 +279,7 @@ HWTEST_F(RequestManagerTest, UpdateUsingPermissionTest003, TestSize.Level1) EXPECT_EQ(false, request_->GetLocationPermState()); EXPECT_EQ(false, request_->GetBackgroundPermState()); EXPECT_EQ(false, request_->GetApproximatelyPermState()); - requestManager_->UpdateUsingPermission(request_); + requestManager_->UpdateUsingPermission(request_, true); // location permission is not recorded EXPECT_EQ(false, request_->GetLocationPermState()); EXPECT_EQ(false, request_->GetBackgroundPermState()); @@ -500,6 +516,8 @@ HWTEST_F(RequestManagerTest, HandleChrEvent001, TestSize.Level1) LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] HandleChrEvent001 begin"); ASSERT_TRUE(requestManager_ != nullptr); std::list> requests; + std::shared_ptr request = std::make_shared(); + requests.push_back(request); requestManager_->HandleChrEvent(requests); LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] HandleChrEvent001 end"); } @@ -511,13 +529,14 @@ HWTEST_F(RequestManagerTest, HandleChrEvent002, TestSize.Level1) LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] HandleChrEvent002 begin"); ASSERT_TRUE(requestManager_ != nullptr); std::list> requests; - std::shared_ptr request = std::make_shared(); - requests.push_back(request); + for (int i = 0; i < 25 ; i++) { + std::shared_ptr request = std::make_shared(); + requests.push_back(request); + } requestManager_->HandleChrEvent(requests); LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] HandleChrEvent002 end"); } - HWTEST_F(RequestManagerTest, IsUidInProcessing001, TestSize.Level1) { GTEST_LOG_(INFO) @@ -528,5 +547,29 @@ HWTEST_F(RequestManagerTest, IsUidInProcessing001, TestSize.Level1) EXPECT_EQ(false, ret); LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] IsUidInProcessing001 end"); } + +HWTEST_F(RequestManagerTest, UpdateLocationErrorCallbackToRequest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "RequestManagerTest, UpdateLocationErrorCallbackToRequest001, TestSize.Level1"; + LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] UpdateLocationErrorCallbackToRequest001 begin"); + ASSERT_TRUE(requestManager_ != nullptr); + sptr locatorCallbackHost = + sptr(new (std::nothrow)LocatorCallbackHost()); + sptr callback = sptr(locatorCallbackHost); + requestManager_->UpdateLocationErrorCallbackToRequest(callback, 0, false); + requestManager_->UpdateLocationErrorCallbackToRequest(callback, 0, true); + LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] UpdateLocationErrorCallbackToRequest001 end"); +} + +HWTEST_F(RequestManagerTest, SyncStillMovementState001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "RequestManagerTest, SyncStillMovementState001, TestSize.Level1"; + LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] SyncStillMovementState001 begin"); + ASSERT_TRUE(requestManager_ != nullptr); + requestManager_->SyncStillMovementState(true); + LBSLOGI(REQUEST_MANAGER, "[RequestManagerTest] SyncStillMovementState001 end"); +} } // namespace Location } // namespace OHOS \ No newline at end of file diff --git a/test/location_mock_ipc/BUILD.gn b/test/location_mock_ipc/BUILD.gn index ed709759..1e6f6e39 100644 --- a/test/location_mock_ipc/BUILD.gn +++ b/test/location_mock_ipc/BUILD.gn @@ -45,13 +45,14 @@ ohos_unittest("LocationMockIpcTest") { deps = [ "$GOOGLE_TEST_DIR:gmock_main", "$GOOGLE_TEST_DIR:gtest_main", - "$LOCATION_GEOCONVERT_ROOT:lbsservice_geocode", - "$LOCATION_GNSS_ROOT:lbsservice_gnss", - "$LOCATION_LOCATOR_ROOT:lbsservice_locator", - "$LOCATION_NETWORK_ROOT:lbsservice_network", - "$LOCATION_PASSIVE_ROOT:lbsservice_passive", - "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", + "$LOCATION_GEOCONVERT_ROOT:lbsservice_geocode_static", + "$LOCATION_GNSS_ROOT:lbsservice_gnss_static", + "$LOCATION_LOCATOR_ROOT:lbsservice_locator_static", + "$LOCATION_NETWORK_ROOT:lbsservice_network_static", + "$LOCATION_PASSIVE_ROOT:lbsservice_passive_static", + "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", + "$LOCATION_ROOT_DIR/frameworks/native/geofence_sdk:geofence_sdk_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", ] external_deps = [ @@ -69,6 +70,7 @@ ohos_unittest("LocationMockIpcTest") { "drivers_interface_location_agnss:liblocation_agnss_proxy_2.0", "drivers_interface_location_gnss:liblocation_gnss_proxy_2.0", "eventhandler:libeventhandler", + "ffrt:libffrt", "hdf_core:libhdi", "hdf_core:libpub_utils", "hilog:libhilog", diff --git a/test/location_network/BUILD.gn b/test/location_network/BUILD.gn index 5826c775..423c5ef5 100644 --- a/test/location_network/BUILD.gn +++ b/test/location_network/BUILD.gn @@ -47,10 +47,11 @@ if (location_feature_with_network) { "$GOOGLE_TEST_DIR:gmock_main", "$GOOGLE_TEST_DIR:gtest_main", "$IPC_ROOT_DIR/interfaces/innerkits/ipc_core:ipc_core", - "$LOCATION_LOCATOR_ROOT:lbsservice_locator", - "$LOCATION_NETWORK_ROOT:lbsservice_network", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", + "$LOCATION_LOCATOR_ROOT:lbsservice_locator_static", + "$LOCATION_NETWORK_ROOT:lbsservice_network_static", + "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", "$SAMGR_ROOT_DIR/safwk/interfaces/innerkits/safwk:system_ability_fwk", "$SAMGR_ROOT_DIR/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "$SECURITY_ROOT_DIR/access_token/interfaces/innerkits/nativetoken:libnativetoken", @@ -65,6 +66,7 @@ if (location_feature_with_network) { "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/test/location_network/mock/include/mock_i_remote_object.h b/test/location_network/mock/include/mock_i_remote_object.h new file mode 100644 index 00000000..5b8d40e6 --- /dev/null +++ b/test/location_network/mock/include/mock_i_remote_object.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_LOCATION_MOCK_I_REMOTE_OBJECT_H +#define BASE_LOCATION_MOCK_I_REMOTE_OBJECT_H + +#include "gmock/gmock.h" + +#include "iremote_broker.h" +#include "iremote_object.h" + +namespace OHOS { +namespace Location { +class MockIRemoteObject : public IRemoteObject { +public: + MockIRemoteObject() : IRemoteObject(u"mock_i_remote_object") {} + ~MockIRemoteObject() {} + MOCK_METHOD(int, SendRequest, (uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); + MOCK_METHOD(bool, IsProxyObject, (), (const, override)); + MOCK_METHOD(bool, CheckObjectLegality, (), (const, override)); + MOCK_METHOD(bool, AddDeathRecipient, (const sptr &recipient), (override)); + MOCK_METHOD(bool, RemoveDeathRecipient, (const sptr &recipient), (override)); + MOCK_METHOD(bool, Marshalling, (Parcel &parcel), (const, override)); + MOCK_METHOD(sptr, AsInterface, (), (override)); + MOCK_METHOD(int, Dump, (int fd, const std::vector &args), (override)); + MOCK_METHOD(int32_t, GetObjectRefCount, (), (override)); + + std::u16string GetObjectDescriptor() const + { + std::u16string descriptor = std::u16string(); + return descriptor; + } +}; +} // namespace Location +} // namespace OHOS +#endif diff --git a/test/location_network/mock/src/mock_common_utils.cpp b/test/location_network/mock/src/mock_common_utils.cpp new file mode 100644 index 00000000..24ef3258 --- /dev/null +++ b/test/location_network/mock/src/mock_common_utils.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mock_i_remote_object.h" +#include "gmock/gmock.h" +#include +#include "location_log.h" +#include "common_utils.h" + +namespace OHOS { +namespace Location { +using namespace testing; +using namespace testing::ext; +sptr CommonUtils::GetRemoteObject( + int abilityId, std::string deviceId) +{ + sptr iRemoteObject = + sptr(new (std::nothrow) MockIRemoteObject()); + EXPECT_CALL(*iRemoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(ERR_OK))); + LBSLOGI(COMMON_UTILS, "[MOCK_COMMON_UTILS] after mock, GetRemoteObject will return mock obj"); + return iRemoteObject; +} +} // namespace Location +} // namespace OHOS \ No newline at end of file diff --git a/test/location_network/source/network_ability_test.cpp b/test/location_network/source/network_ability_test.cpp index 467952b5..8f15758e 100644 --- a/test/location_network/source/network_ability_test.cpp +++ b/test/location_network/source/network_ability_test.cpp @@ -16,6 +16,9 @@ #ifdef FEATURE_NETWORK_SUPPORT #include "network_ability_test.h" +#define private public +#include "network_ability.h" +#undef private #include #include "accesstoken_kit.h" #include "if_system_ability_manager.h" @@ -32,10 +35,30 @@ #include "location_dumper.h" #include "location_log.h" #include "network_ability_skeleton.h" +#include "gmock/gmock.h" +#include "common_utils.h" +#include "mock_i_remote_object.h" +#include #include "network_callback_host.h" #include "permission_manager.h" +#include "locationhub_ipc_interface_code.h" +#include "location_data_rdb_manager.h" +#include "locationhub_ipc_interface_code.h" +#include "location_sa_load_manager.h" +#include "system_ability_definition.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "location_log.h" + +#include "bundle_mgr_interface.h" +#include "bundle_mgr_proxy.h" +#include "parameter.h" +#include "accesstoken_kit.h" +#include "os_account_manager.h" + +using namespace testing; using namespace testing::ext; namespace OHOS { namespace Location { @@ -127,6 +150,8 @@ HWTEST_F(NetworkAbilityTest, SetEnableAndDisable001, TestSize.Level1) GTEST_LOG_(INFO) << "NetworkAbilityTest, SetEnableAndDisable001, TestSize.Level1"; LBSLOGI(NETWORK_TEST, "[NetworkAbilityTest] SetEnableAndDisable001 begin"); + ability_->networkHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); + EXPECT_EQ(ERRCODE_SUCCESS, proxy_->SetEnable(false)); /* * @tc.steps: step1.remove SA * @tc.expected: step1. object1 is null. @@ -213,7 +238,6 @@ HWTEST_F(NetworkAbilityTest, NetworkOnStartAndOnStop001, TestSize.Level1) LBSLOGI(NETWORK_TEST, "[NetworkAbilityTest] NetworkOnStartAndOnStop001 end"); } - HWTEST_F(NetworkAbilityTest, NetworkDump001, TestSize.Level1) { GTEST_LOG_(INFO) @@ -304,6 +328,8 @@ HWTEST_F(NetworkAbilityTest, NetworkSendReportMockLocationEvent002, TestSize.Lev */ HWTEST_F(NetworkAbilityTest, NetworkConnectNlpService001, TestSize.Level1) { + GTEST_LOG_(INFO) + << "NetworkAbilityTest, NetworkConnectNlpService001, TestSize.Level1"; LBSLOGI(NETWORK_TEST, "[NetworkAbilityTest] NetworkConnectNlpService001 begin"); EXPECT_EQ(false, ability_->ReConnectNlpService()); LBSLOGI(NETWORK_TEST, "[NetworkAbilityTest] NetworkConnectNlpService001 end"); @@ -445,7 +471,21 @@ HWTEST_F(NetworkAbilityTest, NetworkAbilityProcessReportLocationMock001, TestSiz LBSLOGI(NETWORK, "[NetworkAbilityTest] NetworkAbilityProcessReportLocationMock001 begin"); ability_->mockLocationIndex_ = -1; ability_->networkHandler_ = nullptr; - ability_->ProcessReportLocationMock(); + std::vector> locations; + Parcel parcel; + parcel.WriteDouble(10.6); // latitude + parcel.WriteDouble(10.5); // longitude + parcel.WriteDouble(10.4); // altitude + parcel.WriteDouble(1.0); // accuracy + parcel.WriteDouble(5.0); // speed + parcel.WriteDouble(10); // direction + parcel.WriteInt64(1611000000); // timestamp + parcel.WriteInt64(1611000000); // time since boot + parcel.WriteString16(u"additions"); // additions + parcel.WriteInt64(1); // additionSize + parcel.WriteInt32(1); // isFromMock is true + locations.push_back(Location::UnmarshallingShared(parcel)); + ability_->CacheLocationMock(locations); LBSLOGI(NETWORK, "[NetworkAbilityTest] NetworkAbilityProcessReportLocationMock001 end"); } @@ -456,8 +496,7 @@ HWTEST_F(NetworkAbilityTest, NetworkAbilitySendReportMockLocationEvent001, TestS LBSLOGI(NETWORK, "[NetworkAbilityTest] NetworkAbilitySendReportMockLocationEvent001 begin"); ability_->networkHandler_ = nullptr; ability_->SendReportMockLocationEvent(); - - ability_->networkHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true));; + ability_->networkHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); ability_->SendReportMockLocationEvent(); LBSLOGI(NETWORK, "[NetworkAbilityTest] NetworkAbilitySendReportMockLocationEvent001 end"); } @@ -476,7 +515,7 @@ HWTEST_F(NetworkAbilityTest, NetworkAbilitySendMessage001, TestSize.Level1) ability_->networkHandler_ = nullptr; ability_->SendMessage(0, requestParcel, reply); - ability_->networkHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true));; + ability_->networkHandler_ = std::make_shared(AppExecFwk::EventRunner::Create(true)); ability_->SendMessage(0, requestParcel, reply); LBSLOGI(NETWORK, "[NetworkAbilityStubTest] NetworkAbilitySendMessage001 end"); } @@ -490,6 +529,218 @@ HWTEST_F(NetworkAbilityTest, ResetServiceProxy001, TestSize.Level1) EXPECT_EQ(true, ability->ResetServiceProxy()); // Connect success LBSLOGI(NETWORK, "[NetworkAbilityTest] ResetServiceProxy001 end"); } + +HWTEST_F(NetworkAbilityTest, RequestNetworkLocation001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "NetworkAbilityTest, RequestNetworkLocation001, TestSize.Level1"; + LBSLOGI(NETWORK, "[NetworkAbilityTest] RequestNetworkLocation001 begin"); + auto workRecord = std::make_shared(); + sptr nlpServiceProxy = + sptr(new (std::nothrow) MockIRemoteObject()); + EXPECT_NE(nullptr, nlpServiceProxy); + ability_->nlpServiceProxy_ = nlpServiceProxy; + std::shared_ptr request = std::make_shared(); + std::unique_ptr requestConfig = std::make_unique(); + requestConfig->SetTimeInterval(0); + request->SetUid(1); + request->SetPid(2); + request->SetPackageName("nameForTest"); + request->SetRequestConfig(*requestConfig); + request->SetUuid(std::to_string(CommonUtils::IntRandom(MIN_INT_RANDOM, MAX_INT_RANDOM))); + request->SetNlpRequestType(1); + workRecord->Add(request); + ability_->RequestNetworkLocation(*workRecord); + LBSLOGI(NETWORK, "[NetworkAbilityTest] RequestNetworkLocation001 end"); +} + +HWTEST_F(NetworkAbilityTest, RemoveNetworkLocation001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "NetworkAbilityTest, RemoveNetworkLocation001, TestSize.Level1"; + LBSLOGI(NETWORK, "[NetworkAbilityTest] RemoveNetworkLocation001 begin"); + auto workRecord = std::make_shared(); + sptr nlpServiceProxy = + sptr(new (std::nothrow) MockIRemoteObject()); + EXPECT_NE(nullptr, nlpServiceProxy); + ability_->nlpServiceProxy_ = nlpServiceProxy; + std::shared_ptr request = std::make_shared(); + std::unique_ptr requestConfig = std::make_unique(); + requestConfig->SetTimeInterval(0); + request->SetUid(1); + request->SetPid(2); + request->SetPackageName("nameForTest"); + request->SetRequestConfig(*requestConfig); + request->SetUuid(std::to_string(CommonUtils::IntRandom(MIN_INT_RANDOM, MAX_INT_RANDOM))); + request->SetNlpRequestType(1); + workRecord->Add(request); + ability_->RemoveNetworkLocation(*workRecord); + LBSLOGI(NETWORK, "[NetworkAbilityTest] RemoveNetworkLocation001 end"); +} + +#ifdef FEATURE_PASSIVE_SUPPORT +HWTEST_F(NetworkAbilityTest, ReportMockedLocation001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "NetworkAbilityTest, ReportMockedLocation001, TestSize.Level1"; + LBSLOGI(NETWORK, "[NetworkAbilityTest] ReportMockedLocation001 begin"); + std::vector> locations; + Parcel parcel; + parcel.WriteDouble(10.6); // latitude + parcel.WriteDouble(10.5); // longitude + parcel.WriteDouble(10.4); // altitude + parcel.WriteDouble(1.0); // accuracy + parcel.WriteDouble(5.0); // speed + parcel.WriteDouble(10); // direction + parcel.WriteInt64(1611000000); // timestamp + parcel.WriteInt64(1611000000); // time since boot + parcel.WriteString16(u"additions"); // additions + parcel.WriteInt64(1); // additionSize + parcel.WriteInt32(1); // isFromMock is true + locations.push_back(Location::UnmarshallingShared(parcel)); + ability_->ReportMockedLocation(locations); + LBSLOGI(NETWORK, "[NetworkAbilityTest] ReportMockedLocation001 end"); +} +#endif + +HWTEST_F(NetworkAbilityTest, RegisterNLPServiceDeathRecipient001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "NetworkAbilityTest, RegisterNLPServiceDeathRecipient001, TestSize.Level1"; + LBSLOGI(NETWORK, "[NetworkAbilityTest] RegisterNLPServiceDeathRecipient001 begin"); + ability_->RegisterNLPServiceDeathRecipient(); + LBSLOGI(NETWORK, "[NetworkAbilityTest] RegisterNLPServiceDeathRecipient001 end"); +} + +HWTEST_F(NetworkAbilityTest, ReportLocationError001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "NetworkAbilityTest, ReportLocationError001, TestSize.Level1"; + LBSLOGI(NETWORK, "[NetworkAbilityTest] ReportLocationError001 begin"); + ability_->ReportLocationError(0, "", ""); + LBSLOGI(NETWORK, "[NetworkAbilityTest] ReportLocationError001 end"); +} + +HWTEST_F(NetworkAbilityTest, ReportMockedLocation001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "NetworkAbilityTest, ReportMockedLocation001, TestSize.Level1"; + LBSLOGI(NETWORK, "[NetworkAbilityTest] ReportMockedLocation001 begin"); + std::shared_ptr location = std::make_shared(); + ability_-> ReportMockedLocation(location); + LBSLOGI(NETWORK, "[NetworkAbilityTest] ReportMockedLocation001 end"); +} + +HWTEST_F(NetworkAbilityTest, OnRemoteDied001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "NetworkAbilityTest, OnRemoteDied001, TestSize.Level1"; + LBSLOGI(NETWORK, "[NetworkAbilityTest] OnRemoteDied001 begin"); + auto deathRecipient = new (std::nothrow) NLPServiceDeathRecipient(); + const wptr object; + deathRecipient->OnRemoteDied(object); + LBSLOGI(NETWORK, "[NetworkAbilityTest] OnRemoteDied001 end"); +} + +HWTEST_F(NetworkAbilityTest, NetworkOnStartAndOnStop002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "NetworkAbilityTest, NetworkOnStartAndOnStop002, TestSize.Level1"; + LBSLOGI(NETWORK_TEST, "[NetworkAbilityTest] NetworkOnStartAndOnStop002 begin"); + ability_->state_ = ServiceRunningState::STATE_RUNNING; + ability_->OnStart(); // start ability + LBSLOGI(NETWORK_TEST, "[NetworkAbilityTest] NetworkOnStartAndOnStop002 end"); +} + +HWTEST_F(NetworkAbilityTest, NetworkConnectNlpService002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "NetworkAbilityTest, NetworkConnectNlpService002, TestSize.Level1"; + LBSLOGI(NETWORK_TEST, "[NetworkAbilityTest] NetworkConnectNlpService002 begin"); + sptr nlpServiceProxy = + sptr(new (std::nothrow) MockIRemoteObject()); + EXPECT_NE(nullptr, nlpServiceProxy); + ability_->nlpServiceProxy_ = nlpServiceProxy; + ability_->ConnectNlpService(); + LBSLOGI(NETWORK_TEST, "[NetworkAbilityTest] NetworkConnectNlpService002 end"); +} + +HWTEST_F(NetworkAbilityTest, ReConnectNlpService002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "NetworkAbilityTest, ReConnectNlpService002, TestSize.Level1"; + LBSLOGI(NETWORK, "[NetworkAbilityTest] ReConnectNlpService002 begin"); + sptr nlpServiceProxy = + sptr(new (std::nothrow) MockIRemoteObject()); + EXPECT_NE(nullptr, nlpServiceProxy); + ability_->nlpServiceProxy_ = nlpServiceProxy; + ability_->ReConnectNlpService(); // Connect success + LBSLOGI(NETWORK, "[NetworkAbilityTest] ReConnectNlpService002 end"); +} + +HWTEST_F(NetworkAbilityTest, SetEnableAndDisable002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "NetworkAbilityTest, SetEnableAndDisable002, TestSize.Level1"; + LBSLOGI(NETWORK_TEST, "[NetworkAbilityTest] SetEnableAndDisable002 begin"); + /* + * @tc.steps: step1.remove SA + * @tc.expected: step1. object1 is null. + */ + ability_->networkHandler_ = nullptr; + ability_->SetEnable(false); // after mock, sa obj is nullptr + /* + * @tc.steps: step2. test enable SA + * @tc.expected: step2. object2 is not null. + */ + ability_->SetEnable(true); // after mock, sa obj is nullptr + LBSLOGI(NETWORK_TEST, "[NetworkAbilityTest] SetEnableAndDisable002 end"); +} + +HWTEST_F(NetworkAbilityTest, UnloadNetworkSystemAbility001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "NetworkAbilityTest, UnloadNetworkSystemAbility001, TestSize.Level1"; + LBSLOGI(NETWORK, "[NetworkAbilityTest] UnloadNetworkSystemAbility001 begin"); + ability_->networkHandler_ = nullptr; + ability_->UnloadNetworkSystemAbility(); + LBSLOGI(NETWORK, "[NetworkAbilityTest] UnloadNetworkSystemAbility001 end"); +} + +HWTEST_F(NetworkAbilityTest, RequestNetworkLocation002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "NetworkAbilityTest, RequestNetworkLocation002, TestSize.Level1"; + LBSLOGI(NETWORK, "[NetworkAbilityTest] RequestNetworkLocation002 begin"); + ability_->nlpServiceProxy_ = nullptr; + WorkRecord workRecord; + EXPECT_EQ(false, ability_->RequestNetworkLocation(workRecord)); + LBSLOGI(NETWORK, "[NetworkAbilityTest] RequestNetworkLocation002 end"); +} + +HWTEST_F(NetworkAbilityTest, RemoveNetworkLocation002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "NetworkAbilityTest, RemoveNetworkLocation002, TestSize.Level1"; + LBSLOGI(NETWORK, "[NetworkAbilityTest] RemoveNetworkLocation002 begin"); + ability_->nlpServiceProxy_ = nullptr; + WorkRecord workRecord; + EXPECT_EQ(false, ability_->RemoveNetworkLocation(workRecord)); + LBSLOGI(NETWORK, "[NetworkAbilityTest] RemoveNetworkLocation002 end"); +} + +HWTEST_F(NetworkAbilityTest, RegisterNLPServiceDeathRecipient002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "NetworkAbilityTest, RegisterNLPServiceDeathRecipient002, TestSize.Level1"; + LBSLOGI(NETWORK, "[NetworkAbilityTest] RegisterNLPServiceDeathRecipient002 begin"); + sptr nlpServiceProxy = + sptr(new (std::nothrow) MockIRemoteObject()); + EXPECT_NE(nullptr, nlpServiceProxy); + ability_->nlpServiceProxy_ = nlpServiceProxy; + ability_->RegisterNLPServiceDeathRecipient(); + LBSLOGI(NETWORK, "[NetworkAbilityTest] RegisterNLPServiceDeathRecipient002 end"); +} } // namespace Location } // namespace OHOS #endif // FEATURE_NETWORK_SUPPORT \ No newline at end of file diff --git a/test/location_passive/BUILD.gn b/test/location_passive/BUILD.gn index 902dfd2a..8c1b0fee 100644 --- a/test/location_passive/BUILD.gn +++ b/test/location_passive/BUILD.gn @@ -47,15 +47,16 @@ if (location_feature_with_passive) { "$GOOGLE_TEST_DIR:gmock_main", "$GOOGLE_TEST_DIR:gtest_main", "$IPC_ROOT_DIR/interfaces/innerkits/ipc_core:ipc_core", - "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common", - "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk", + "$LOCATION_ROOT_DIR/frameworks/js/napi:geolocation_static", + "$LOCATION_ROOT_DIR/frameworks/location_common/common:lbsservice_common_static", + "$LOCATION_ROOT_DIR/frameworks/native/locator_sdk:locator_sdk_static", "$SAMGR_ROOT_DIR/safwk/interfaces/innerkits/safwk:system_ability_fwk", "$SAMGR_ROOT_DIR/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "$SECURITY_ROOT_DIR/access_token/interfaces/innerkits/nativetoken:libnativetoken", "$SECURITY_ROOT_DIR/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", "$START_UP_ROOT_DIR/init/interfaces/innerkits:libbegetutil", - "$SUBSYSTEM_DIR/location_locator/locator:lbsservice_locator", - "$SUBSYSTEM_DIR/location_passive/passive:lbsservice_passive", + "$SUBSYSTEM_DIR/location_locator/locator:lbsservice_locator_static", + "$SUBSYSTEM_DIR/location_passive/passive:lbsservice_passive_static", ] external_deps = [ diff --git a/test/location_passive/source/passive_ability_test.cpp b/test/location_passive/source/passive_ability_test.cpp index 3c0b3bc2..66d42ffe 100644 --- a/test/location_passive/source/passive_ability_test.cpp +++ b/test/location_passive/source/passive_ability_test.cpp @@ -14,7 +14,10 @@ */ #ifdef FEATURE_PASSIVE_SUPPORT +#define private public #include "passive_ability_test.h" +#include "passive_ability.h" +#undef private #include "accesstoken_kit.h" #include "if_system_ability_manager.h" @@ -144,7 +147,6 @@ HWTEST_F(PassiveAbilityTest, PassiveLocationMock001, TestSize.Level1) std::vector> locations; EXPECT_EQ(ERRCODE_SUCCESS, proxy_->EnableMock()); EXPECT_EQ(ERRCODE_SUCCESS, proxy_->SetMocked(timeInterval, locations)); - EXPECT_EQ(ERRCODE_SUCCESS, proxy_->DisableMock()); EXPECT_EQ(ERRCODE_NOT_SUPPORTED, proxy_->SetMocked(timeInterval, locations)); LBSLOGI(PASSIVE_TEST, "[PassiveAbilityStubTest] PassiveLocationMock001 end"); @@ -156,18 +158,11 @@ HWTEST_F(PassiveAbilityTest, PassiveOnStartAndOnStop001, TestSize.Level1) << "PassiveAbilityStubTest, PassiveOnStartAndOnStop001, TestSize.Level1"; LBSLOGI(PASSIVE_TEST, "[PassiveAbilityStubTest] PassiveOnStartAndOnStop001 begin"); ability_->OnStart(); // start ability - EXPECT_EQ(ServiceRunningState::STATE_NOT_START, - (ServiceRunningState)ability_->QueryServiceState()); // mock ability_->OnStart(); // start ability again - EXPECT_EQ(ServiceRunningState::STATE_NOT_START, - (ServiceRunningState)ability_->QueryServiceState()); // mock - + ability_->state_ = ServiceRunningState::STATE_RUNNING; + ability_->OnStart(); // start ability again ability_->OnStop(); // stop ability - EXPECT_EQ(ServiceRunningState::STATE_NOT_START, - (ServiceRunningState)ability_->QueryServiceState()); // mock ability_->OnStart(); // restart ability - EXPECT_EQ(ServiceRunningState::STATE_NOT_START, - (ServiceRunningState)ability_->QueryServiceState()); // mock LBSLOGI(PASSIVE_TEST, "[PassiveAbilityStubTest] PassiveOnStartAndOnStop001 end"); } @@ -253,6 +248,49 @@ HWTEST_F(PassiveAbilityTest, PassiveSendReportMockLocationEvent002, TestSize.Lev sleep(2); LBSLOGI(PASSIVE_TEST, "[PassiveAbilityTest] PassiveSendReportMockLocationEvent002 end"); } + +HWTEST_F(PassiveAbilityTest, PassiveSendReportUnloadPassiveSystemAbility001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "PassiveAbilityTest, PassiveSendReportUnloadPassiveSystemAbility001, TestSize.Level1"; + LBSLOGI(PASSIVE_TEST, "[PassiveAbilityTest] PassiveSendReportUnloadPassiveSystemAbility001 begin"); + ability_->passiveHandler_ = nullptr; + ability_->UnloadPassiveSystemAbility(); + LBSLOGI(PASSIVE_TEST, "[PassiveAbilityTest] PassiveSendReportUnloadPassiveSystemAbility001 end"); +} + +HWTEST_F(PassiveAbilityTest, PassiveSendReportSendMessage001, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "PassiveAbilityTest, PassiveSendReportUnloadSendMessage001, TestSize.Level1"; + LBSLOGI(PASSIVE_TEST, "[PassiveAbilityTest] PassiveSendReportUnloadSendMessage001 begin"); + ability_->passiveHandler_ = nullptr; + MessageParcel parcel; + parcel.WriteDouble(10.6); // latitude + parcel.WriteDouble(10.5); // longitude + parcel.WriteDouble(10.4); // altitude + parcel.WriteDouble(1.0); // accuracy + parcel.WriteDouble(5.0); // speed + parcel.WriteDouble(10); // direction + parcel.WriteInt64(1611000000); // timestamp + parcel.WriteInt64(1611000000); // time since boot + parcel.WriteString16(u"additions"); // additions + parcel.WriteInt64(1); // additionSize + parcel.WriteInt32(1); // isFromMock is true + MessageParcel reply; + ability_->SendMessage(ERRCODE_NOT_SUPPORTED, parcel, reply); + LBSLOGI(PASSIVE_TEST, "[PassiveAbilityTest] PassiveSendReportSendMessage001 end"); +} + +HWTEST_F(PassiveAbilityTest, PassiveOnStartAndOnStop002, TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "PassiveAbilityStubTest, PassiveOnStartAndOnStop002, TestSize.Level1"; + LBSLOGI(PASSIVE_TEST, "[PassiveAbilityStubTest] PassiveOnStartAndOnStop002 begin"); + ability_->state_ = ServiceRunningState::STATE_RUNNING; + ability_->OnStart(); // start ability again + LBSLOGI(PASSIVE_TEST, "[PassiveAbilityStubTest] PassiveOnStartAndOnStop002 end"); +} } // namespace Location } // namespace OHOS #endif // FEATURE_PASSIVE_SUPPORT