diff --git a/bundle.json b/bundle.json index c0dfdb9e6..23fc984dc 100644 --- a/bundle.json +++ b/bundle.json @@ -63,6 +63,7 @@ "sub_component": [ "//base/location/frameworks/native:locator_sdk", "//base/location/frameworks/js/napi:geolocation", + "//base/location/frameworks/js/napi:geolocationmanager", "//base/location/frameworks/location_common/common:lbsservice_common", "//base/location/services/location_geocode/geocode:lbsservice_geocode", "//base/location/services/location_gnss/gnss:lbsservice_gnss", diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index f428d3268..a02e283b3 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -44,3 +44,40 @@ ohos_shared_library("geolocation") { part_name = "location" subsystem_name = "location" } + +ohos_shared_library("geolocationmanager") { + install_enable = true + include_dirs = [ + "//third_party/node/src", + "//native_engine", + "//commonlibrary/c_utils/base/include", + "//utils/system/safwk/native/include", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", + "//base/location/frameworks/js/napi/include", + "//base/location/interfaces/inner_api/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + + sources = [ + "//base/location/frameworks/js/napi/source/location_napi_manager_entry.cpp", + ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//base/location/frameworks/js/napi:geolocation", + "//base/location/frameworks/location_common/common:lbsservice_common", + "//base/location/frameworks/native:locator_sdk", + "//foundation/arkui/napi:ace_napi", + "//third_party/libuv:uv", + ] + + external_deps = [ + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "ipc:ipc_core", + ] + + relative_install_dir = "module" + part_name = "location" + subsystem_name = "location" +} diff --git a/frameworks/js/napi/source/location_napi_entry.cpp b/frameworks/js/napi/source/location_napi_entry.cpp index d03cc1d71..ef383c0a6 100644 --- a/frameworks/js/napi/source/location_napi_entry.cpp +++ b/frameworks/js/napi/source/location_napi_entry.cpp @@ -37,8 +37,6 @@ static napi_value Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("getAddressesFromLocation", GetAddressesFromLocation), DECLARE_NAPI_FUNCTION("getAddressesFromLocationName", GetAddressesFromLocationName), DECLARE_NAPI_FUNCTION("isGeoServiceAvailable", IsGeoServiceAvailable), - DECLARE_NAPI_FUNCTION("isLocationPrivacyConfirmed", IsLocationPrivacyConfirmed), - DECLARE_NAPI_FUNCTION("setLocationPrivacyConfirmStatus", SetLocationPrivacyConfirmStatus), DECLARE_NAPI_FUNCTION("getCachedGnssLocationsSize", GetCachedGnssLocationsSize), DECLARE_NAPI_FUNCTION("flushCachedGnssLocations", FlushCachedGnssLocations), DECLARE_NAPI_FUNCTION("sendCommand", SendCommand), @@ -51,13 +49,6 @@ static napi_value Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("subscribe", Subscribe), DECLARE_NAPI_FUNCTION("unsubscribe", Unsubscribe), DECLARE_NAPI_FUNCTION("getSupportedCoordTypes", GetSupportedCoordTypes), - DECLARE_NAPI_FUNCTION("getCountryCode", GetIsoCountryCode), - DECLARE_NAPI_FUNCTION("enableLocationMock", EnableLocationMock), - DECLARE_NAPI_FUNCTION("disableLocationMock", DisableLocationMock), - DECLARE_NAPI_FUNCTION("setMockedLocations", SetMockedLocations), - DECLARE_NAPI_FUNCTION("enableReverseGeocodingMock", EnableReverseGeocodingMock), - DECLARE_NAPI_FUNCTION("disableReverseGeocodingMock", DisableReverseGeocodingMock), - DECLARE_NAPI_FUNCTION("setReverseGeocodingMockInfo", SetReverseGeocodingMockInfo), }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc)); diff --git a/frameworks/js/napi/source/location_napi_manager_entry.cpp b/frameworks/js/napi/source/location_napi_manager_entry.cpp new file mode 100644 index 000000000..3e519ffb3 --- /dev/null +++ b/frameworks/js/napi/source/location_napi_manager_entry.cpp @@ -0,0 +1,82 @@ +/* + * 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 "napi_util.h" +#include "location_log.h" +#include "location_napi_adapter.h" +#include "location_napi_event.h" +#include "location_napi_system.h" + +namespace OHOS { +namespace Location { +/* + * Module initialization function + */ +static napi_value InitManager(napi_env env, napi_value exports) +{ + LBSLOGI(LOCATION_NAPI, "Init, location_napi_manager_entry"); + + napi_property_descriptor desc[] = { + DECLARE_NAPI_FUNCTION("on", On), + DECLARE_NAPI_FUNCTION("off", Off), + DECLARE_NAPI_FUNCTION("getCurrentLocation", GetCurrentLocation), + DECLARE_NAPI_FUNCTION("getLastLocation", GetLastLocation), + DECLARE_NAPI_FUNCTION("isLocationEnabled", IsLocationEnabled), + DECLARE_NAPI_FUNCTION("enableLocation", EnableLocation), + DECLARE_NAPI_FUNCTION("disableLocation", DisableLocation), + DECLARE_NAPI_FUNCTION("requestEnableLocation", RequestEnableLocation), + DECLARE_NAPI_FUNCTION("isGeoServiceAvailable", IsGeoServiceAvailable), + DECLARE_NAPI_FUNCTION("getAddressesFromLocation", GetAddressesFromLocation), + DECLARE_NAPI_FUNCTION("getAddressesFromLocationName", GetAddressesFromLocationName), + DECLARE_NAPI_FUNCTION("isLocationPrivacyConfirmed", IsLocationPrivacyConfirmed), + DECLARE_NAPI_FUNCTION("setLocationPrivacyConfirmStatus", SetLocationPrivacyConfirmStatus), + DECLARE_NAPI_FUNCTION("getCachedGnssLocationsSize", GetCachedGnssLocationsSize), + DECLARE_NAPI_FUNCTION("flushCachedGnssLocations", FlushCachedGnssLocations), + DECLARE_NAPI_FUNCTION("sendCommand", SendCommand), + + DECLARE_NAPI_FUNCTION("subscribe", Subscribe), + DECLARE_NAPI_FUNCTION("unsubscribe", Unsubscribe), + DECLARE_NAPI_FUNCTION("getLocation", GetLocation), + DECLARE_NAPI_FUNCTION("getLocationType", GetLocationType), + DECLARE_NAPI_FUNCTION("getCountryCode", GetIsoCountryCode), + DECLARE_NAPI_FUNCTION("getSupportedCoordTypes", GetSupportedCoordTypes), + DECLARE_NAPI_FUNCTION("enableLocationMock", EnableLocationMock), + DECLARE_NAPI_FUNCTION("disableLocationMock", DisableLocationMock), + DECLARE_NAPI_FUNCTION("setMockedLocations", SetMockedLocations), + DECLARE_NAPI_FUNCTION("enableReverseGeocodingMock", EnableReverseGeocodingMock), + DECLARE_NAPI_FUNCTION("disableReverseGeocodingMock", DisableReverseGeocodingMock), + DECLARE_NAPI_FUNCTION("setReverseGeocodingMockInfo", SetReverseGeocodingMockInfo), + }; + + NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc)); + return exports; +} + +static napi_module g_locationManagerModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = NULL, + .nm_register_func = InitManager, + .nm_modname = "geoLocationManager", + .nm_priv = ((void *)0), + .reserved = { 0 } +}; + +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + napi_module_register(&g_locationManagerModule); +} +} // namespace Location +} // namespace OHOS