diff --git a/wifi/bundle.json b/wifi/bundle.json index 4dd4416823411b0540a9db197e45aa91606188a7..73b63f8fd6d52ad89d21ea06e0145d2cafc9c681 100644 --- a/wifi/bundle.json +++ b/wifi/bundle.json @@ -123,6 +123,7 @@ "jsoncpp", "libxml2", "asset", + "runtime_core", "icu", "window_manager", "security_guard" diff --git a/wifi/frameworks/BUILD.gn b/wifi/frameworks/BUILD.gn index f51e6e46e094755ae9e96322725f46a23fdcd4c8..3420689afd95cac873dafc62166bc42ae26fee5d 100644 --- a/wifi/frameworks/BUILD.gn +++ b/wifi/frameworks/BUILD.gn @@ -24,6 +24,7 @@ group("wifi_kits") { if (!defined(ohos_lite)) { deps += [ "$WIFI_ROOT_DIR/frameworks/cj:cj_wifi_ffi", + "$WIFI_ROOT_DIR/frameworks/ets/ani:wifi_ani", "$WIFI_ROOT_DIR/frameworks/js/napi:wifi", "$WIFI_ROOT_DIR/frameworks/js/napi:wifiext", "$WIFI_ROOT_DIR/frameworks/js/napi:wifimanager", diff --git a/wifi/frameworks/ets/ani/BUILD.gn b/wifi/frameworks/ets/ani/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..eff4f57b32bc16d65a23980aaf531fa64ab11e1e --- /dev/null +++ b/wifi/frameworks/ets/ani/BUILD.gn @@ -0,0 +1,20 @@ +# Copyright (C) 2025 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("//build/ohos.gni") +group("wifi_ani") { + deps = [ + "./wifi_manager:wifimanager_ani", + "./wifi_manager:wifimanager_ani_abc_etc", + ] +} diff --git a/wifi/frameworks/ets/ani/wifi_manager/BUILD.gn b/wifi/frameworks/ets/ani/wifi_manager/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..82c9f404426613f7a11501da280876a1d1e948e2 --- /dev/null +++ b/wifi/frameworks/ets/ani/wifi_manager/BUILD.gn @@ -0,0 +1,50 @@ +# Copyright (C) 2025 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("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//foundation/communication/wifi/wifi/wifi.gni") + +ohos_shared_library("wifimanager_ani") { + include_dirs = [ "./include" ] + sanitize = { + cfi = true # Enable/disable control flow integrity detection + boundary_sanitize = true # Enable boundary san detection + cfi_cross_dso = true # Cross-SO CFI Checks + debug = false + } + sources = [ "src/wifi_manager_ani.cpp" ] + deps = [ "$WIFI_ROOT_DIR/frameworks/native:wifi_sdk" ] + external_deps = [ + "runtime_core:ani", + "runtime_core:libarkruntime", + "samgr:samgr_proxy", + ] + part_name = "wifi" + subsystem_name = "communication" +} + +generate_static_abc("wifimanager_ani_abc") { + base_url = "./ets" + files = [ "./ets/@ohos.wifiManager.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/wifimanager_ani_abc.abc" +} + +ohos_prebuilt_etc("wifimanager_ani_abc_etc") { + source = "$target_out_dir/wifimanager_ani_abc.abc" + module_install_dir = "framework" + part_name = "wifi" + subsystem_name = "communication" + deps = [ ":wifimanager_ani_abc" ] +} diff --git a/wifi/frameworks/ets/ani/wifi_manager/ets/@ohos.wifiManager.ets b/wifi/frameworks/ets/ani/wifi_manager/ets/@ohos.wifiManager.ets new file mode 100644 index 0000000000000000000000000000000000000000..2aa6243ba0c0ffb43f85919336bc7f07ff4d6e32 --- /dev/null +++ b/wifi/frameworks/ets/ani/wifi_manager/ets/@ohos.wifiManager.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +export namespace wifiManager { + loadLibrary("wifimanager_ani.z"); + export native function isWifiActive(): boolean; +} + +function main(){ + console.println("wifi manager") + let c = wifiManager.isWifiActive(); + console.println("isWifiActive: " + c); +} \ No newline at end of file diff --git a/wifi/frameworks/ets/ani/wifi_manager/include/wifi_manager_ani.h b/wifi/frameworks/ets/ani/wifi_manager/include/wifi_manager_ani.h new file mode 100644 index 0000000000000000000000000000000000000000..27b34a213fc17035a1940cd6ca848995db554763 --- /dev/null +++ b/wifi/frameworks/ets/ani/wifi_manager/include/wifi_manager_ani.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 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 WIFI_MANAGER_ANI_H_ +#define WIFI_MANAGER_ANI_H_ + +#include + +static ani_boolean IsWifiActive([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object); + +#endif diff --git a/wifi/frameworks/ets/ani/wifi_manager/src/wifi_manager_ani.cpp b/wifi/frameworks/ets/ani/wifi_manager/src/wifi_manager_ani.cpp new file mode 100644 index 0000000000000000000000000000000000000000..16d6861df031c05ddbe615473c1acc5c57c40e7a --- /dev/null +++ b/wifi/frameworks/ets/ani/wifi_manager/src/wifi_manager_ani.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2025 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 +#include +#include +#include "wifi_manager_ani.h" +#include "wifi_logger.h" +#include "wifi_device.h" + +using namespace OHOS::Wifi; + +std::shared_ptr g_wifiDevicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID); + +ani_boolean IsWifiActive([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +{ + bool activeStatus = false; + ErrCode ret = g_wifiDevicePtr->IsWifiActive(activeStatus); + if (ret != WIFI_OPT_SUCCESS) { + std::cerr << "IsWifiActive failed." << std::endl; + } + return static_cast(activeStatus); +} + +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + std::cerr << "Unsupported ANI_VERSION_1" << std::endl; + return ANI_OUT_OF_REF; + } + + static const char *NameSpaceName = "L@ohos/wifiManager/wifiManager;"; + ani_namespace wifimanager {}; + if (ANI_OK != env->FindNamespace(NameSpaceName, &wifimanager)) { + std::cerr << "Not found '" << NameSpaceName << "'" << std::endl; + return ANI_INVALID_ARGS; + } + + std::array functions = { + ani_native_function {"isWifiActive", ":Z", reinterpret_cast(IsWifiActive)}, + }; + + if (ANI_OK != env->Namespace_BindNativeFunctions(wifimanager, functions.data(), functions.size())) { + std::cerr << "Namespace_BindNativeFunctions not OK" << std::endl; + return ANI_INVALID_ARGS; + } + std::cout << "Start bind native methods to '" << NameSpaceName << "'" << std::endl; + + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file