From 3ffe8c3a3fb0b3f0a5526b957b0ea15852b8e88e Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 8 Jul 2025 20:21:57 +0800 Subject: [PATCH 1/7] taihe modify Signed-off-by: BrainL --- interfaces/kits/taihe/BUILD.gn | 103 ++++ .../idl/ohos.distributedDeviceManager.taihe | 137 +++++ .../kits/taihe/include/dm_ani_callback.h | 132 +++++ .../include/ohos.distributedDeviceManager.h | 91 ++++ interfaces/kits/taihe/src/ani_constructor.cpp | 30 ++ interfaces/kits/taihe/src/dm_ani_callback.cpp | 142 +++++ .../src/ohos.distributedDeviceManager.cpp | 498 ++++++++++++++++++ 7 files changed, 1133 insertions(+) create mode 100644 interfaces/kits/taihe/BUILD.gn create mode 100644 interfaces/kits/taihe/idl/ohos.distributedDeviceManager.taihe create mode 100644 interfaces/kits/taihe/include/dm_ani_callback.h create mode 100644 interfaces/kits/taihe/include/ohos.distributedDeviceManager.h create mode 100644 interfaces/kits/taihe/src/ani_constructor.cpp create mode 100644 interfaces/kits/taihe/src/dm_ani_callback.cpp create mode 100644 interfaces/kits/taihe/src/ohos.distributedDeviceManager.cpp diff --git a/interfaces/kits/taihe/BUILD.gn b/interfaces/kits/taihe/BUILD.gn new file mode 100644 index 000000000..cae4b187f --- /dev/null +++ b/interfaces/kits/taihe/BUILD.gn @@ -0,0 +1,103 @@ +# 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("//foundation/distributedhardware/device_manager/device_manager.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") + +subsystem_name = "distributedhardware" +part_name = "device_manager" +taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" + +copy_taihe_idl("copy_taihe") { + sources = [ "${devicemanager_path}/interfaces/kits/taihe/idl/ohos.distributedDeviceManager.taihe" ] +} + +ohos_taihe("run_taihe") { + taihe_generated_file_path = "$taihe_generated_file_path" + deps = [ ":copy_taihe" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.distributedDeviceManager.ani.cpp", + "$taihe_generated_file_path/src/ohos.distributedDeviceManager.abi.c", + ] +} + +if (device_manager_enable_ets_frontend) { + taihe_shared_library("device_manager_ani_taihe") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + + taihe_generated_file_path = "$taihe_generated_file_path" + subsystem_name = "$subsystem_name" + part_name = "$part_name" + + include_dirs = [ + "include", + "${innerkits_path}/native_cpp/include", + "${devicemanager_path}/interfaces/kits/taihe/include", + ] + + sources = get_target_outputs(":run_taihe") + sources += [ + "src/ani_constructor.cpp", + "src/ohos.distributedDeviceManager.cpp", + "src/dm_ani_callback.cpp" + ] + + deps = [ + ":run_taihe", + "${innerkits_path}/native_cpp:devicemanagersdk" + ] + + external_deps = [ + "hilog:libhilog", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "eventhandler:libeventhandler", + ] + } + + generate_static_abc("ohos_distributedDeviceManager_abc") { + base_url = "$taihe_generated_file_path" + files = [ "$taihe_generated_file_path/@ohos.distributedDeviceManager.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/ohos_distributedDeviceManager_abc.abc" + dependencies = [ ":run_taihe" ] + } + + ohos_prebuilt_etc("ohos_distributedDeviceManager_etc") { + source = "$target_out_dir/ohos_distributedDeviceManager_abc.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ + ":ohos_distributedDeviceManager_abc" + ] + } +} + +group("devicemanager_ani") { + if (device_manager_enable_ets_frontend) { + deps = [ + ":device_manager_ani_taihe", + ":ohos_distributedDeviceManager_etc", + ] + } +} diff --git a/interfaces/kits/taihe/idl/ohos.distributedDeviceManager.taihe b/interfaces/kits/taihe/idl/ohos.distributedDeviceManager.taihe new file mode 100644 index 000000000..e2ddf2958 --- /dev/null +++ b/interfaces/kits/taihe/idl/ohos.distributedDeviceManager.taihe @@ -0,0 +1,137 @@ +/* + * 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. + */ + +@!namespace("@ohos.distributedDeviceManager", "distributedDeviceManager") + +@!sts_inject(""" +static { loadLibrary("device_manager_ani_taihe.z");} +""") + +struct DeviceBasicInfo { + deviceId: String; + deviceName: String; + deviceType: String; + networkId: String; + extraData: String; +} + +function MakeDeviceBasicInfo(deviceId:String, deviceName:String, deviceType:String, + networkId:String, extraData: String): DeviceBasicInfo; + +struct ServiceProfileInfo { + deviceId: String; +} + +enum DeviceStateChange: i32 { + UNKNOWN = 0, + AVAILABLE = 1, + UNAVAILABLE = 2, +} + +struct DeviceNameChangeResult { + deviceName: String; +} + +function MakeDeviceNameChangeResult(deviceName: String): DeviceNameChangeResult; + +struct ReplyResult { + param: String; +} + +function MakeReplyResult(param: String): ReplyResult; + +struct DiscoveryFailureResult { + reason: i32; +} + +function MakeDiscoveryFailureResult(reason: i32): DiscoveryFailureResult; + +struct DiscoverySuccessResult { + device: DeviceBasicInfo; +} + +function MakeDiscoverySuccessResult(device: DeviceBasicInfo): DiscoverySuccessResult; + +struct DeviceStateChangeResult { + deviceStateChange: DeviceStateChange; + deviceBasicInfo: DeviceBasicInfo; +} + +function MakeDeviceStateChangeResult(deviceStateChange : DeviceStateChange, + deviceBasicInfo : DeviceBasicInfo): DeviceStateChangeResult; + +interface DeviceManager { + GetLocalDeviceId(): String; + UnbindTarget(deviceId: String): void; + GetDeviceType(networkId: String): f64; + GetDeviceName(networkId: String): String; + GetLocalDeviceNetworkId(): String; + + @!sts_inject_into_interface("on(type: string, callback: (data: object) => void): void;") + @!sts_inject_into_class("""on(type: string, callback: object): void { + if (type === "discoverSuccess") { + this.onDiscoverSuccess(callback as (data: DiscoverySuccessResult) => void); + } else if (type === "deviceStateChange") { + this.onDeviceStateChange(callback as (data: DeviceStateChangeResult) => void); + } else if (type === "replyResult") { + this.onReplyResult(callback as (data: ReplyResult) => void); + } else if (type === "deviceNameChange") { + this.onDeviceNameChange(callback as (data: DeviceNameChangeResult) => void); + } else if (type === "discoverFailure") { + this.onDiscoverFailure(callback as (data: DiscoveryFailureResult) => void); + } else if (type ==="serviceDie") { + this.onServiceDie(callback as () => void); + } else { + throw new Error(`Unknown type: ${type}`); + } + } + """) + + @!sts_inject_into_interface("off(type: string, callback?: (data: object) => void): void;") + @!sts_inject_into_class("""off(type: string, callback?: object): void { + if (type === "discoverSuccess") { + this.offDiscoverSuccess(callback as (((data: DiscoverySuccessResult) => void) | undefined)); + } else if (type === "deviceStateChange") { + this.offDeviceStateChange(callback as (((data: DeviceStateChangeResult) => void) | undefined)); + } else if (type === "replyResult") { + this.offReplyResult(callback as (((data: ReplyResult) => void) | undefined)); + } else if (type === "deviceNameChange") { + this.offDeviceNameChange(callback as (((data: DeviceNameChangeResult) => void) | undefined)); + } else if (type === "discoverFailure"){ + this.offDiscoverFailure(callback as (((data: DiscoveryFailureResult) => void) | undefined)); + } else if (type ==="serviceDie") { + this.offServiceDie(callback as () => void); + }else { + throw new Error(`Unknown type: ${type}`); + } + } + """) + + OnDiscoverSuccess(onDiscoverSuccesscb: (device: DiscoverySuccessResult) => void): void; + OffDiscoverSuccess(offDiscoverSuccesscb: Optional<(device: DiscoverySuccessResult) => void>): void; + OnDeviceStateChange(onDeviceStateChangecb: (deviceStateChangeData: DeviceStateChangeResult) => void): void; + OffDeviceStateChange(offDeviceStateChangecb: + Optional<(deviceStateChangeData: DeviceStateChangeResult) => void>): void; + OnReplyResult(onReplyResultcb: (data: ReplyResult) => void): void; + OffReplyResult(offReplyResultcb: Optional<(data: ReplyResult) => void>): void; + OnDeviceNameChange(onDeviceNameChangecb: (deviceName: DeviceNameChangeResult) => void): void; + OffDeviceNameChange(offDeviceNameChangecb: Optional<(deviceName: DeviceNameChangeResult) => void>): void; + OnDiscoverFailure(onDiscoverFailurecb: (reason: DiscoveryFailureResult) => void): void; + OffDiscoverFailure(offDiscoverFailurecb: Optional<(reason: DiscoveryFailureResult) => void>): void; + OnServiceDie(onServiceDiecb: () => void): void; + OffServiceDie(offServiceDiecb: Optional<() => void>): void; +} + +function CreateDeviceManager(bundleName: String): DeviceManager; diff --git a/interfaces/kits/taihe/include/dm_ani_callback.h b/interfaces/kits/taihe/include/dm_ani_callback.h new file mode 100644 index 000000000..46defd754 --- /dev/null +++ b/interfaces/kits/taihe/include/dm_ani_callback.h @@ -0,0 +1,132 @@ +/* + * 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 OHOS_DM_ANI_CALLBACK_H +#define OHOS_DM_ANI_CALLBACK_H + +#include +#include +#include "device_manager_callback.h" +#include "dm_device_info.h" +#include "ohos.distributedDeviceManager.proj.hpp" +#include "ohos.distributedDeviceManager.impl.hpp" +#include "taihe/runtime.hpp" +#include "taihe/callback.hpp" + +class DmAniInitCallback : public OHOS::DistributedHardware::DmInitCallback { +public: + explicit DmAniInitCallback(taihe::string_view bundleName); + ~DmAniInitCallback() override {} + void OnRemoteDied() override; + void SetServiceDieCallback(std::shared_ptr> callback); + void ReleaseServiceDieCallback(); + +private: + std::string bundleName_; + std::shared_ptr> serviceDieCallback_; + std::mutex g_dmInitMutex; +}; + +class DmAniDiscoverySuccessCallback : public OHOS::DistributedHardware::DiscoveryCallback { +public: + explicit DmAniDiscoverySuccessCallback(std::string &bundleName, + taihe::callback + discoverSuccessCallback); + ~DmAniDiscoverySuccessCallback() override {}; + void OnDeviceFound(uint16_t subscribeId, + const OHOS::DistributedHardware::DmDeviceBasicInfo &deviceBasicInfo) override {} + void OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason) override {} + void OnDiscoverySuccess(uint16_t subscribeId) override {} + void IncreaseRefCount(); + void DecreaseRefCount(); + int32_t GetRefCount(); + +private: + std::atomic refCount_; + std::string bundleName_; + std::shared_ptr> discoverSuccessCallback_; + std::mutex g_dmDiscoveryMutex; +}; + +class DmAniDiscoveryFailedCallback : public OHOS::DistributedHardware::DiscoveryCallback { +public: + explicit DmAniDiscoveryFailedCallback(std::string &bundleName, + taihe::callback discoverFailedCallback); + ~DmAniDiscoveryFailedCallback() override {}; + void OnDeviceFound(uint16_t subscribeId, + const OHOS::DistributedHardware::DmDeviceBasicInfo &deviceBasicInfo) override {} + void OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason) override {} + void OnDiscoverySuccess(uint16_t subscribeId) override {} + void IncreaseRefCount(); + void DecreaseRefCount(); + int32_t GetRefCount(); + +private: + std::atomic refCount_; + std::string bundleName_; + std::shared_ptr> discoverFailedCallback_; + std::mutex g_dmDiscoveryMutex; +}; + +class DmAniDeviceNameChangeCallback : public OHOS::DistributedHardware::DeviceStatusCallback { +public: + explicit DmAniDeviceNameChangeCallback(std::string &bundleName, + taihe::callback deviceNameChangeCallback); + ~DmAniDeviceNameChangeCallback() override {} + void OnDeviceOnline(const OHOS::DistributedHardware::DmDeviceBasicInfo &deviceBasicInfo) override {} + void OnDeviceReady(const OHOS::DistributedHardware::DmDeviceBasicInfo &deviceBasicInfo) override {} + void OnDeviceOffline(const OHOS::DistributedHardware::DmDeviceBasicInfo &deviceBasicInfo) override {} + void OnDeviceChanged(const OHOS::DistributedHardware::DmDeviceBasicInfo &deviceBasicInfo) override; + +private: + std::string bundleName_; + std::shared_ptr> deviceNameChangeCallback_; +}; + +class DmAniDeviceStateChangeResultCallback : public OHOS::DistributedHardware::DeviceStatusCallback { +public: + explicit DmAniDeviceStateChangeResultCallback(std::string &bundleName, + taihe::callback + deviceStateChangeDataCallback); + ~DmAniDeviceStateChangeResultCallback() override {} + void OnDeviceOnline(const OHOS::DistributedHardware::DmDeviceBasicInfo &deviceBasicInfo) override {} + void OnDeviceReady(const OHOS::DistributedHardware::DmDeviceBasicInfo &deviceBasicInfo) override {} + void OnDeviceOffline(const OHOS::DistributedHardware::DmDeviceBasicInfo &deviceBasicInfo) override {} + void OnDeviceChanged(const OHOS::DistributedHardware::DmDeviceBasicInfo &deviceBasicInfo) override; + +private: + std::string bundleName_; + std::shared_ptr> + deviceStateChangeDataCallback_; +}; + +class DmAniDeviceManagerUiCallback : public OHOS::DistributedHardware::DeviceManagerUiCallback { +public: + explicit DmAniDeviceManagerUiCallback(taihe::callback replyResultCallback, + std::string &bundleName); + ~DmAniDeviceManagerUiCallback() override {} + void OnCall(const std::string ¶mJson) override; + +private: + std::string bundleName_; + std::shared_ptr> replyResultCallback_; +}; + +#endif //OHOS_DM_ANI_CALLBACK_H \ No newline at end of file diff --git a/interfaces/kits/taihe/include/ohos.distributedDeviceManager.h b/interfaces/kits/taihe/include/ohos.distributedDeviceManager.h new file mode 100644 index 000000000..0242f0efa --- /dev/null +++ b/interfaces/kits/taihe/include/ohos.distributedDeviceManager.h @@ -0,0 +1,91 @@ +/* + * 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 OHOS_DISTRIBUTEDDEVICEMANAGER_H +#define OHOS_DISTRIBUTEDDEVICEMANAGER_H + +#include +#include +#include "device_manager_callback.h" +#include "dm_device_info.h" +#include "ohos.distributedDeviceManager.proj.hpp" +#include "ohos.distributedDeviceManager.impl.hpp" +#include "taihe/callback.hpp" +#include "taihe/runtime.hpp" + +namespace ANI::distributedDeviceManager { + +enum DMBussinessErrorCode { + ERR_NO_PERMISSION = 201, + DM_ERR_FAILED = 11600101, +}; + +class DeviceManagerImpl { +public: + DeviceManagerImpl() = default; + explicit DeviceManagerImpl(std::shared_ptr impl); + explicit DeviceManagerImpl(const std::string& bundleName); + ~DeviceManagerImpl() = default; + std::string GetLocalDeviceId(); + void UnbindTarget(taihe::string_view deviceId); + double GetDeviceType(taihe::string_view networkId); + std::string GetDeviceName(taihe::string_view networkId); + std::string GetLocalDeviceNetworkId(); + + void OnDeviceNameChange(taihe::callback_view onDeviceNameChangecb); + void OnDiscoverFailure(taihe::callback_view onDiscoverFailurecb); + void OnReplyResult(taihe::callback_view onReplyResultcb); + void OnDiscoverSuccess(taihe::callback_view onDiscoverSuccesscb); + void OnDeviceStateChange(taihe::callback_view onDeviceStateChangecb); + void OnServiceDie(taihe::callback_view onServiceDiecb); + + void OffDeviceNameChange(taihe::optional_view> offDeviceNameChangecb); + void OffDiscoverFailure(taihe::optional_view> offDiscoverFailurecb); + void OffReplyResult(taihe::optional_view> offReplyResultcb); + void OffDiscoverSuccess(taihe::optional_view> offDiscoverSuccesscb); + void OffDeviceStateChange(taihe::optional_view> offDeviceStateChangecb); + void OffServiceDie(taihe::optional_view> offServiceDiecb); + + friend ohos::distributedDeviceManager::DeviceManager CreateDeviceManager(taihe::string_view bundleName); + +private: + std::string bundleName_; +}; + +ohos::distributedDeviceManager::DeviceBasicInfo MakeDeviceBasicInfo(taihe::string_view deviceId, + taihe::string_view deviceName, taihe::string_view deviceType, + taihe::string_view networkId, taihe::string_view extraData); + +ohos::distributedDeviceManager::DeviceNameChangeResult MakeDeviceNameChangeResult(taihe::string_view deviceName); +ohos::distributedDeviceManager::ReplyResult MakeReplyResult(taihe::string_view param); +ohos::distributedDeviceManager::DiscoveryFailureResult MakeDiscoveryFailureResult(int32_t reason); +ohos::distributedDeviceManager::DiscoverySuccessResult MakeDiscoverySuccessResult( + ohos::distributedDeviceManager::DeviceBasicInfo const& device); +ohos::distributedDeviceManager::DeviceStateChangeResult MakeDeviceStateChangeResult( + ohos::distributedDeviceManager::DeviceStateChange deviceStateChange, + ohos::distributedDeviceManager::DeviceBasicInfo const& deviceBasicInfo); +ohos::distributedDeviceManager::DeviceManager CreateDeviceManager(taihe::string_view bundleName); +} // namespace ANI::distributedDeviceManager + +#endif //OHOS_DISTRIBUTEDDEVICEMANAGER_H diff --git a/interfaces/kits/taihe/src/ani_constructor.cpp b/interfaces/kits/taihe/src/ani_constructor.cpp new file mode 100644 index 000000000..8e29dd472 --- /dev/null +++ b/interfaces/kits/taihe/src/ani_constructor.cpp @@ -0,0 +1,30 @@ +/* + * 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 "ohos.distributedDeviceManager.ani.hpp" + +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::distributedDeviceManager::ANIRegister(env)) { + std::cerr << "Error from ohos::distributedDeviceManager::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} diff --git a/interfaces/kits/taihe/src/dm_ani_callback.cpp b/interfaces/kits/taihe/src/dm_ani_callback.cpp new file mode 100644 index 000000000..4c6e44920 --- /dev/null +++ b/interfaces/kits/taihe/src/dm_ani_callback.cpp @@ -0,0 +1,142 @@ +/* + * 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 "dm_ani_callback.h" +#include "device_manager.h" +#include "dm_log.h" +#include "event_handler.h" + +#define DH_LOG_TAG "DeviceManager" + +DmAniInitCallback::DmAniInitCallback(taihe::string_view bundleName) + : bundleName_(std::string(bundleName)) +{ + std::lock_guard autoLock(g_dmInitMutex); + serviceDieCallback_ = nullptr; +} + +void DmAniInitCallback::OnRemoteDied() +{ + LOGI("DmAniInitCallback::OnRemoteDied called."); + auto &deviceManager = static_cast( + OHOS::DistributedHardware::DeviceManager::GetInstance()); + deviceManager.UnInitDeviceManager(bundleName_); +} + +void DmAniInitCallback::SetServiceDieCallback(std::shared_ptr> callback) +{ + std::lock_guard autoLock(g_dmInitMutex); + serviceDieCallback_ = callback; +} + +void DmAniInitCallback::ReleaseServiceDieCallback() +{ + std::lock_guard autoLock(g_dmInitMutex); + serviceDieCallback_ = nullptr; +} + +DmAniDiscoveryFailedCallback::DmAniDiscoveryFailedCallback(std::string &bundleName, + taihe::callback discoverFailedCallback) + : refCount_(0), bundleName_(bundleName), + discoverFailedCallback_(std::make_shared>(discoverFailedCallback)) +{ +} + +void DmAniDiscoveryFailedCallback::IncreaseRefCount() +{ + std::lock_guard autoLock(g_dmDiscoveryMutex); + refCount_++; +} + +void DmAniDiscoveryFailedCallback::DecreaseRefCount() +{ + std::lock_guard autoLock(g_dmDiscoveryMutex); + refCount_--; +} + +int32_t DmAniDiscoveryFailedCallback::GetRefCount() +{ + return refCount_; +} + +DmAniDiscoverySuccessCallback::DmAniDiscoverySuccessCallback(std::string &bundleName, + taihe::callback + discoverSuccessCallback) + : refCount_(0), bundleName_(bundleName), + discoverSuccessCallback_(std::make_shared>(discoverSuccessCallback)) +{ +} + +void DmAniDiscoverySuccessCallback::IncreaseRefCount() +{ + std::lock_guard autoLock(g_dmDiscoveryMutex); + refCount_++; +} + +void DmAniDiscoverySuccessCallback::DecreaseRefCount() +{ + std::lock_guard autoLock(g_dmDiscoveryMutex); + refCount_--; +} + +int32_t DmAniDiscoverySuccessCallback::GetRefCount() +{ + return refCount_; +} + +DmAniDeviceNameChangeCallback::DmAniDeviceNameChangeCallback(std::string &bundleName, + taihe::callback deviceNameChangeCallback) + : bundleName_(bundleName), deviceNameChangeCallback_( + std::make_shared>(deviceNameChangeCallback)) +{ +} + +void DmAniDeviceNameChangeCallback::OnDeviceChanged( + const OHOS::DistributedHardware::DmDeviceBasicInfo &deviceBasicInfo) +{ + LOGI("DmAniDeviceNameChangeCallback::OnDeviceChanged called."); +} + +DmAniDeviceStateChangeResultCallback::DmAniDeviceStateChangeResultCallback(std::string &bundleName, + taihe::callback + deviceStateChangeDataCallback) + : bundleName_(bundleName), + deviceStateChangeDataCallback_(std::make_shared>(deviceStateChangeDataCallback)) +{ +} + +void DmAniDeviceStateChangeResultCallback::OnDeviceChanged( + const OHOS::DistributedHardware::DmDeviceBasicInfo &deviceBasicInfo) +{ + LOGI("DmAniDeviceStateChangeResultCallback::OnDeviceChanged called."); +} + +DmAniDeviceManagerUiCallback::DmAniDeviceManagerUiCallback( + taihe::callback replyResultCallback, + std::string &bundleName) + : bundleName_(bundleName), + replyResultCallback_(std::make_shared>(replyResultCallback)) +{ +} + +void DmAniDeviceManagerUiCallback::OnCall(const std::string ¶mJson) +{ + LOGI("DmAniDeviceManagerUiCallback::OnCall called."); +} \ No newline at end of file diff --git a/interfaces/kits/taihe/src/ohos.distributedDeviceManager.cpp b/interfaces/kits/taihe/src/ohos.distributedDeviceManager.cpp new file mode 100644 index 000000000..a05aeefca --- /dev/null +++ b/interfaces/kits/taihe/src/ohos.distributedDeviceManager.cpp @@ -0,0 +1,498 @@ +/* + * 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 "ohos.distributedDeviceManager.h" +#include +#include +#include "device_manager.h" +#include "dm_ani_callback.h" +#include "dm_constants.h" +#include "dm_log.h" + +#define DH_LOG_TAG "DeviceManager" + +namespace ANI::distributedDeviceManager { +namespace { +constexpr double DEVICE_TYPE_UNKNOWN = -1.0; +constexpr const char *DEVICE_TYPE_EMPTY_STR = ""; +constexpr const char *ERROR_DEVICE_ID = "error deviceId"; +constexpr const char *ERROR_NETWORK_ID = "error networkId"; + +std::mutex g_initCallbackMapMutex; +std::mutex g_deviceNameChangeCallbackMapMutex; +std::mutex g_discoveryFailedCallbackMapMutex; +std::mutex g_deviceStateChangeDataCallbackMapMutex; +std::mutex g_discoverySuccessCallbackMapMutex; +std::mutex g_dmUiCallbackMapMutex; + +std::map> g_initCallbackMap; +std::map> g_discoveryFailedCallbackMap; +std::map> g_deviceNameChangeCallbackMap; +std::map> g_deviceStateChangeDataCallbackMap; +std::map> g_discoverySuccessCallbackMap; +std::map> g_dmUiCallbackMap; +} //namespace + +DeviceManagerImpl::DeviceManagerImpl(const std::string& bundleName) + : bundleName_(bundleName) +{ +} + +DeviceManagerImpl::DeviceManagerImpl(std::shared_ptr impl) +{ + std::lock_guard autoLock(g_initCallbackMapMutex); + if (impl == nullptr) { + LOGE("Create DeviceManagerImpl for shared_ptr failed."); + } else { + bundleName_ = impl->bundleName_; + } +} + +ohos::distributedDeviceManager::DeviceManager CreateDeviceManager(taihe::string_view bundleName) +{ + auto impl = std::make_shared(std::string(bundleName)); + std::shared_ptr initCallback = std::make_shared(bundleName); + int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().InitDeviceManager( + std::string(bundleName), initCallback); + if (ret != 0) { + LOGE("CreateDeviceManager for bundleName %{public}s failed, ret %{public}d.", bundleName.c_str(), ret); + taihe::set_business_error(DM_ERR_FAILED, "CreateDeviceManager for failed"); + return taihe::make_holder(); + } + { + std::lock_guard autoLock(g_initCallbackMapMutex); + g_initCallbackMap[std::string(bundleName)] = initCallback; + } + return taihe::make_holder(impl); +} + +ohos::distributedDeviceManager::DeviceBasicInfo MakeDeviceBasicInfo(taihe::string_view deviceId, + taihe::string_view deviceName, taihe::string_view deviceType, + taihe::string_view networkId, taihe::string_view extraData) +{ + return {deviceId, deviceName, deviceType, networkId, extraData}; +} + +ohos::distributedDeviceManager::DeviceNameChangeResult MakeDeviceNameChangeResult(taihe::string_view deviceName) +{ + return {deviceName}; +} + +ohos::distributedDeviceManager::ReplyResult MakeReplyResult(taihe::string_view param) +{ + return {param}; +} + +ohos::distributedDeviceManager::DiscoveryFailureResult MakeDiscoveryFailureResult(int32_t reason) +{ + return {reason}; +} + +ohos::distributedDeviceManager::DiscoverySuccessResult MakeDiscoverySuccessResult( + ohos::distributedDeviceManager::DeviceBasicInfo const& device) +{ + return {device}; +} + +ohos::distributedDeviceManager::DeviceStateChangeResult MakeDeviceStateChangeResult( + ohos::distributedDeviceManager::DeviceStateChange deviceStateChange, + ohos::distributedDeviceManager::DeviceBasicInfo const& deviceBasicInfo) +{ + return {deviceStateChange, deviceBasicInfo}; +} + +std::string DeviceManagerImpl::GetLocalDeviceId() +{ + if (OHOS::DistributedHardware::DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + taihe::set_business_error(OHOS::DistributedHardware::ERR_DM_NO_PERMISSION, "GetLocalDeviceId for failed1"); + return DEVICE_TYPE_EMPTY_STR; + } + std::string deviceId; + int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().GetLocalDeviceId(bundleName_, deviceId); + if (ret != 0) { + taihe::set_business_error(DM_ERR_FAILED, "GetLocalDeviceId for failed2"); + return ERROR_DEVICE_ID; + } + return std::string(deviceId); +} + +void DeviceManagerImpl::UnbindTarget(taihe::string_view deviceId) +{ + int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().UnBindDevice( + bundleName_, std::string(deviceId)); + if (ret != 0) { + LOGE("UnBindDevice for bundleName %{public}s failed, ret %{public}d", + bundleName_.c_str(), ret); + taihe::set_business_error(DM_ERR_FAILED, "UnbindTarget for failed"); + return; + } +} + +double DeviceManagerImpl::GetDeviceType(taihe::string_view networkId) +{ + int32_t deviceType; + int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().GetDeviceType( + bundleName_, std::string(networkId), deviceType); + if (ret != 0) { + taihe::set_business_error(DM_ERR_FAILED, "GetDeviceType for failed"); + return DEVICE_TYPE_UNKNOWN; + } + return static_cast(deviceType); +} + +std::string DeviceManagerImpl::GetDeviceName(taihe::string_view networkId) +{ + std::string deviceName; + int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().GetDeviceName( + bundleName_, std::string(networkId), deviceName); + if (ret != 0) { + taihe::set_business_error(DM_ERR_FAILED, "GetDeviceName for failed"); + return DEVICE_TYPE_EMPTY_STR; + } + return std::string(deviceName); +} + +std::string DeviceManagerImpl::GetLocalDeviceNetworkId() +{ + if (OHOS::DistributedHardware::DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + taihe::set_business_error(OHOS::DistributedHardware::ERR_DM_NO_PERMISSION, "GetLocalDeviceNetworkId failed"); + return DEVICE_TYPE_EMPTY_STR; + } + std::string networkId; + int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().GetLocalDeviceNetWorkId( + bundleName_, networkId); + if (ret != 0) { + LOGE("GetLocalDeviceNetworkId for failed, ret %{public}d", ret); + taihe::set_business_error(DM_ERR_FAILED, "GetLocalDeviceNetworkId failed"); + return ERROR_NETWORK_ID; + } + return std::string(networkId); +} + +void DeviceManagerImpl::OnDeviceNameChange(taihe::callback_view onDeviceNameChangecb) +{ + if (OHOS::DistributedHardware::DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + taihe::set_business_error(OHOS::DistributedHardware::ERR_DM_NO_PERMISSION, + "ondeviceNameChange check permission failed."); + return; + } + + { + std::lock_guard autoLock(g_deviceNameChangeCallbackMapMutex); + if (g_deviceNameChangeCallbackMap.find(bundleName_) != g_deviceNameChangeCallbackMap.end()) { + LOGI("bundleName already register."); + return; + } + } + + auto dmonDeviceNameChangecb = std::make_shared(bundleName_, onDeviceNameChangecb); + std::string extra = ""; + if (OHOS::DistributedHardware::DeviceManager::GetInstance().RegisterDevStatusCallback(bundleName_, extra, + dmonDeviceNameChangecb) != 0) { + LOGE("RegisterDevStatusCallback failed"); + return; + } + { + std::lock_guard autoLock(g_deviceNameChangeCallbackMapMutex); + g_deviceNameChangeCallbackMap[bundleName_] = dmonDeviceNameChangecb; + } + return; +} + +void DeviceManagerImpl::OnDiscoverFailure(taihe::callback_view onDiscoverFailurecb) +{ + int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().CheckNewAPIAccessPermission(); + if (ret != 0) { + taihe::set_business_error(OHOS::DistributedHardware::ERR_DM_NO_PERMISSION, + "ondiscoverFailure check permission failed."); + return; + } + + auto dmDiscoverFailurecb = std::make_shared(bundleName_, onDiscoverFailurecb); + { + std::lock_guard autoLock(g_discoveryFailedCallbackMapMutex); + g_discoveryFailedCallbackMap[bundleName_] = dmDiscoverFailurecb; + } + std::shared_ptr discoveryCallback = dmDiscoverFailurecb; + discoveryCallback->IncreaseRefCount(); + return; +} + +void DeviceManagerImpl::OnReplyResult(taihe::callback_view onReplyResultcb) +{ + if (OHOS::DistributedHardware::DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + taihe::set_business_error(OHOS::DistributedHardware::ERR_DM_NO_PERMISSION, + "OnReplyResult check permission failed"); + return; + } + + auto dmcallback = std::make_shared(onReplyResultcb, bundleName_); + int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().RegisterDeviceManagerFaCallback( + bundleName_, dmcallback); + if (ret != 0) { + LOGE("RegisterDeviceManagerFaCallback failed for bundleName %{public}s", bundleName_.c_str()); + return; + } + { + std::lock_guard autoLock(g_dmUiCallbackMapMutex); + g_dmUiCallbackMap[bundleName_] = dmcallback; + } + return; +} + +void DeviceManagerImpl::OnDiscoverSuccess(taihe::callback_view onDiscoverSuccesscb) +{ + if (OHOS::DistributedHardware::DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + taihe::set_business_error(OHOS::DistributedHardware::ERR_DM_NO_PERMISSION, + "ondiscoverSuccess check Permission failed"); + return; + } + + auto dmCallback = std::make_shared(bundleName_, onDiscoverSuccesscb); + { + std::lock_guard autoLock(g_discoverySuccessCallbackMapMutex); + g_discoverySuccessCallbackMap[bundleName_] = dmCallback; + } + std::shared_ptr discoveryCallback = dmCallback; + discoveryCallback->IncreaseRefCount(); + return ; +} + +void DeviceManagerImpl::OnDeviceStateChange(taihe::callback_view onDeviceStateChangecb) +{ + if (OHOS::DistributedHardware::DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + taihe::set_business_error(OHOS::DistributedHardware::ERR_DM_NO_PERMISSION, + "ondeviceStateChange check Permission failed"); + return; + } + + { + std::lock_guard autoLock(g_deviceStateChangeDataCallbackMapMutex); + if (g_deviceStateChangeDataCallbackMap.find(bundleName_) != g_deviceStateChangeDataCallbackMap.end()) { + LOGI("bundleName already register."); + return; + } + } + + auto dmCallback = std::make_shared(bundleName_, onDeviceStateChangecb); + std::string extra = ""; + int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().RegisterDevStatusCallback(bundleName_, + extra, dmCallback); + if (ret != 0) { + LOGE("RegisterDevStatusCallback failed ret %{public}d", ret); + return; + } + { + std::lock_guard autoLock(g_deviceStateChangeDataCallbackMapMutex); + g_deviceStateChangeDataCallbackMap[bundleName_] = dmCallback; + } + return; +} + +void DeviceManagerImpl::OnServiceDie(taihe::callback_view onServiceDiecb) +{ + if (OHOS::DistributedHardware::DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + taihe::set_business_error(OHOS::DistributedHardware::ERR_DM_NO_PERMISSION, + "OnReplyResult check permission failed"); + return; + } + + { + std::lock_guard autoLock(g_initCallbackMapMutex); + auto dmCallback = g_initCallbackMap[bundleName_]; + dmCallback->SetServiceDieCallback(std::make_shared>(onServiceDiecb)); + } + return; +} + +void DeviceManagerImpl::OffDeviceNameChange(taihe::optional_view> offDeviceNameChangecb) +{ + if (OHOS::DistributedHardware::DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + taihe::set_business_error(OHOS::DistributedHardware::ERR_DM_NO_PERMISSION, + "offdeviceNameChange check permission failed."); + return; + } + + { + std::lock_guard autoLock(g_deviceNameChangeCallbackMapMutex); + auto iter = g_deviceNameChangeCallbackMap.find(bundleName_); + if (iter == g_deviceNameChangeCallbackMap.end()) { + LOGE("ReleaseDmCallback: cannot find statusCallback for bundleName " + "%{public}s", + bundleName_.c_str()); + return; + } + } + + if (OHOS::DistributedHardware::DeviceManager::GetInstance().UnRegisterDevStatusCallback(bundleName_) != 0) { + LOGE("UnRegisterDevStatusCallback failed for bundleName %{public}s", bundleName_.c_str()); + return; + } + { + std::lock_guard autoLock(g_deviceNameChangeCallbackMapMutex); + g_deviceNameChangeCallbackMap.erase(bundleName_); + } + return; +} + +void DeviceManagerImpl::OffDiscoverFailure(taihe::optional_view> offDiscoverFailurecb) +{ + if (OHOS::DistributedHardware::DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + taihe::set_business_error(OHOS::DistributedHardware::ERR_DM_NO_PERMISSION, + "offdiscoverFailure check permission failed."); + return; + } + + std::shared_ptr discoveryCallback = nullptr; + { + std::lock_guard autoLock(g_discoveryFailedCallbackMapMutex); + auto iter = g_discoveryFailedCallbackMap.find(bundleName_); + if (iter == g_discoveryFailedCallbackMap.end()) { + return; + } + discoveryCallback = iter->second; + } + + discoveryCallback->DecreaseRefCount(); + if (discoveryCallback->GetRefCount() == 0) { + std::lock_guard autoLock(g_discoveryFailedCallbackMapMutex); + g_discoveryFailedCallbackMap.erase(bundleName_); + } + return; +} + +void DeviceManagerImpl::OffReplyResult(taihe::optional_view> offReplyResultcb) +{ + if (OHOS::DistributedHardware::DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + taihe::set_business_error(OHOS::DistributedHardware::ERR_DM_NO_PERMISSION, + "OffReplyResult check permission failed"); + return; + } + + { + std::lock_guard autoLock(g_dmUiCallbackMapMutex); + auto iter = g_dmUiCallbackMap.find(bundleName_); + if (iter == g_dmUiCallbackMap.end()) { + LOGE("cannot find dmFaCallback for bundleName %{public}s", bundleName_.c_str()); + return; + } + } + + int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().UnRegisterDeviceManagerFaCallback( + bundleName_); + if (ret != 0) { + LOGE("UnRegisterDeviceManagerFaCallback failed for bundleName %{public}s", bundleName_.c_str()); + return; + } + + { + std::lock_guard autoLock(g_dmUiCallbackMapMutex); + g_dmUiCallbackMap.erase(bundleName_); + } +} + +void DeviceManagerImpl::OffDiscoverSuccess(taihe::optional_view> offDiscoverSuccesscb) +{ + if (OHOS::DistributedHardware::DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + taihe::set_business_error(OHOS::DistributedHardware::ERR_DM_NO_PERMISSION, + "offdiscoverSuccess check Permission failed"); + return; + } + + std::shared_ptr disCoveryCallback = nullptr; + { + std::lock_guard autoLock(g_discoverySuccessCallbackMapMutex); + auto iter = g_discoverySuccessCallbackMap.find(bundleName_); + if (iter == g_discoverySuccessCallbackMap.end()) { + LOGE("Cannot find discoveryCallback for bundleName %{public}s", bundleName_.c_str()); + return; + } + disCoveryCallback = iter->second; + } + + disCoveryCallback->DecreaseRefCount(); + if (disCoveryCallback->GetRefCount() == 0) { + std::lock_guard autoLock(g_discoverySuccessCallbackMapMutex); + g_discoverySuccessCallbackMap.erase(bundleName_); + } + return; +} + +void DeviceManagerImpl::OffDeviceStateChange(taihe::optional_view> offDeviceStateChangecb) +{ + if (OHOS::DistributedHardware::DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + taihe::set_business_error(OHOS::DistributedHardware::ERR_DM_NO_PERMISSION, + "offdeviceStateChange check Permission failed"); + return; + } + + { + std::lock_guard autoLock(g_deviceStateChangeDataCallbackMapMutex); + auto iter = g_deviceStateChangeDataCallbackMap.find(bundleName_); + if (iter == g_deviceStateChangeDataCallbackMap.end()) { + LOGE("Cannot find stateChangeDataCallback for bundleName %{public}s", bundleName_.c_str()); + return; + } + } + + int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().UnRegisterDevStatusCallback(bundleName_); + if (ret != 0) { + LOGE("UnRegisterDevStatusCallback failed for bundleName %{public}s", bundleName_.c_str()); + return; + } + { + std::lock_guard autoLock(g_deviceStateChangeDataCallbackMapMutex); + g_deviceStateChangeDataCallbackMap.erase(bundleName_); + } + return; +} + +void DeviceManagerImpl::OffServiceDie(taihe::optional_view> offServiceDiecb) +{ + if (OHOS::DistributedHardware::DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + taihe::set_business_error(OHOS::DistributedHardware::ERR_DM_NO_PERMISSION, + "offdiscoverFailure check permission failed."); + return; + } + + { + std::lock_guard autoLock(g_initCallbackMapMutex); + auto iter = g_initCallbackMap.find(bundleName_); + if (iter == g_initCallbackMap.end() || !iter->second) { + LOGE("Cannot find ServiceDieCallback for bundleName %{public}s", bundleName_.c_str()); + return; + } + iter->second->ReleaseServiceDieCallback(); + } +} +} // namespace ANI::distributedDeviceManager + +TH_EXPORT_CPP_API_CreateDeviceManager(ANI::distributedDeviceManager::CreateDeviceManager); +TH_EXPORT_CPP_API_MakeDeviceBasicInfo(ANI::distributedDeviceManager::MakeDeviceBasicInfo); +TH_EXPORT_CPP_API_MakeDeviceNameChangeResult(ANI::distributedDeviceManager::MakeDeviceNameChangeResult); +TH_EXPORT_CPP_API_MakeReplyResult(ANI::distributedDeviceManager::MakeReplyResult); +TH_EXPORT_CPP_API_MakeDiscoveryFailureResult(ANI::distributedDeviceManager::MakeDiscoveryFailureResult); +TH_EXPORT_CPP_API_MakeDiscoverySuccessResult(ANI::distributedDeviceManager::MakeDiscoverySuccessResult); +TH_EXPORT_CPP_API_MakeDeviceStateChangeResult(ANI::distributedDeviceManager::MakeDeviceStateChangeResult); -- Gitee From 914e1c9611d57341d07bb08a6a11b2e000fda39f Mon Sep 17 00:00:00 2001 From: BrainL Date: Wed, 9 Jul 2025 20:42:34 +0800 Subject: [PATCH 2/7] taihe modify Signed-off-by: BrainL --- bundle.json | 6 ++- interfaces/kits/taihe/BUILD.gn | 80 ++++++++++++++++------------------ 2 files changed, 42 insertions(+), 44 deletions(-) diff --git a/bundle.json b/bundle.json index aee20468f..c60d9a95a 100644 --- a/bundle.json +++ b/bundle.json @@ -61,7 +61,8 @@ "wifi", "screenlock_mgr", "mbedtls", - "zlib" + "zlib", + "runtime_core" ], "third_party": [] }, @@ -69,7 +70,8 @@ "group_type": { "base_group": [], "fwk_group": [ - "//foundation/distributedhardware/device_manager:device_manager_fwk" + "//foundation/distributedhardware/device_manager:device_manager_fwk", + "//foundation/distributedhardware/device_manager/interfaces/kits/taihe:devicemanager_ani" ], "service_group": [ "//foundation/distributedhardware/device_manager:device_manager", diff --git a/interfaces/kits/taihe/BUILD.gn b/interfaces/kits/taihe/BUILD.gn index cae4b187f..16c3ed638 100644 --- a/interfaces/kits/taihe/BUILD.gn +++ b/interfaces/kits/taihe/BUILD.gn @@ -33,46 +33,45 @@ ohos_taihe("run_taihe") { ] } -if (device_manager_enable_ets_frontend) { - taihe_shared_library("device_manager_ani_taihe") { - sanitize = { - integer_overflow = true - ubsan = true - boundary_sanitize = true - cfi = true - cfi_cross_dso = true - debug = false - } +taihe_shared_library("device_manager_ani_taihe") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } - taihe_generated_file_path = "$taihe_generated_file_path" - subsystem_name = "$subsystem_name" - part_name = "$part_name" + taihe_generated_file_path = "$taihe_generated_file_path" + subsystem_name = "$subsystem_name" + part_name = "$part_name" - include_dirs = [ - "include", - "${innerkits_path}/native_cpp/include", - "${devicemanager_path}/interfaces/kits/taihe/include", - ] + include_dirs = [ + "include", + "${innerkits_path}/native_cpp/include", + "${devicemanager_path}/interfaces/kits/taihe/include", + ] - sources = get_target_outputs(":run_taihe") - sources += [ - "src/ani_constructor.cpp", - "src/ohos.distributedDeviceManager.cpp", - "src/dm_ani_callback.cpp" - ] + sources = get_target_outputs(":run_taihe") + sources += [ + "src/ani_constructor.cpp", + "src/ohos.distributedDeviceManager.cpp", + "src/dm_ani_callback.cpp" + ] - deps = [ - ":run_taihe", - "${innerkits_path}/native_cpp:devicemanagersdk" - ] + deps = [ + ":run_taihe", + "${innerkits_path}/native_cpp:devicemanagersdk" + ] - external_deps = [ - "hilog:libhilog", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "eventhandler:libeventhandler", - ] - } + external_deps = [ + "hilog:libhilog", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "eventhandler:libeventhandler", + ] +} generate_static_abc("ohos_distributedDeviceManager_abc") { base_url = "$taihe_generated_file_path" @@ -91,13 +90,10 @@ if (device_manager_enable_ets_frontend) { ":ohos_distributedDeviceManager_abc" ] } -} group("devicemanager_ani") { - if (device_manager_enable_ets_frontend) { - deps = [ - ":device_manager_ani_taihe", - ":ohos_distributedDeviceManager_etc", - ] - } + deps = [ + ":device_manager_ani_taihe", + ":ohos_distributedDeviceManager_etc", + ] } -- Gitee From d11f181aafbfd01f0476a990e1972e95ba051c6e Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 10 Jul 2025 10:38:18 +0800 Subject: [PATCH 3/7] taihe modify Signed-off-by: BrainL --- device_manager.gni | 1 + interfaces/kits/taihe/BUILD.gn | 80 ++++++++++++++++++---------------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/device_manager.gni b/device_manager.gni index 96682f92a..8f859255c 100644 --- a/device_manager.gni +++ b/device_manager.gni @@ -35,6 +35,7 @@ json_path = "${devicemanager_path}/json" #----------------------compilation options--------------------------# dm_ldflags = [ "-lpthread" ] declare_args() { + device_manager_enable_ets_frontend = true device_manager_no_interaction_auth = false device_manager_feature_product = "default" use_nlohmann_json = true diff --git a/interfaces/kits/taihe/BUILD.gn b/interfaces/kits/taihe/BUILD.gn index 16c3ed638..cae4b187f 100644 --- a/interfaces/kits/taihe/BUILD.gn +++ b/interfaces/kits/taihe/BUILD.gn @@ -33,45 +33,46 @@ ohos_taihe("run_taihe") { ] } -taihe_shared_library("device_manager_ani_taihe") { - sanitize = { - integer_overflow = true - ubsan = true - boundary_sanitize = true - cfi = true - cfi_cross_dso = true - debug = false - } +if (device_manager_enable_ets_frontend) { + taihe_shared_library("device_manager_ani_taihe") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } - taihe_generated_file_path = "$taihe_generated_file_path" - subsystem_name = "$subsystem_name" - part_name = "$part_name" + taihe_generated_file_path = "$taihe_generated_file_path" + subsystem_name = "$subsystem_name" + part_name = "$part_name" - include_dirs = [ - "include", - "${innerkits_path}/native_cpp/include", - "${devicemanager_path}/interfaces/kits/taihe/include", - ] + include_dirs = [ + "include", + "${innerkits_path}/native_cpp/include", + "${devicemanager_path}/interfaces/kits/taihe/include", + ] - sources = get_target_outputs(":run_taihe") - sources += [ - "src/ani_constructor.cpp", - "src/ohos.distributedDeviceManager.cpp", - "src/dm_ani_callback.cpp" - ] + sources = get_target_outputs(":run_taihe") + sources += [ + "src/ani_constructor.cpp", + "src/ohos.distributedDeviceManager.cpp", + "src/dm_ani_callback.cpp" + ] - deps = [ - ":run_taihe", - "${innerkits_path}/native_cpp:devicemanagersdk" - ] + deps = [ + ":run_taihe", + "${innerkits_path}/native_cpp:devicemanagersdk" + ] - external_deps = [ - "hilog:libhilog", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "eventhandler:libeventhandler", - ] -} + external_deps = [ + "hilog:libhilog", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "eventhandler:libeventhandler", + ] + } generate_static_abc("ohos_distributedDeviceManager_abc") { base_url = "$taihe_generated_file_path" @@ -90,10 +91,13 @@ taihe_shared_library("device_manager_ani_taihe") { ":ohos_distributedDeviceManager_abc" ] } +} group("devicemanager_ani") { - deps = [ - ":device_manager_ani_taihe", - ":ohos_distributedDeviceManager_etc", - ] + if (device_manager_enable_ets_frontend) { + deps = [ + ":device_manager_ani_taihe", + ":ohos_distributedDeviceManager_etc", + ] + } } -- Gitee From ffed2d54515b7fde0106bd23f62c92b3697ec772 Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 10 Jul 2025 10:45:11 +0800 Subject: [PATCH 4/7] taihe modify Signed-off-by: BrainL --- interfaces/kits/taihe/idl/ohos.distributedDeviceManager.taihe | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/taihe/idl/ohos.distributedDeviceManager.taihe b/interfaces/kits/taihe/idl/ohos.distributedDeviceManager.taihe index e2ddf2958..2ee9a3b5c 100644 --- a/interfaces/kits/taihe/idl/ohos.distributedDeviceManager.taihe +++ b/interfaces/kits/taihe/idl/ohos.distributedDeviceManager.taihe @@ -75,7 +75,7 @@ function MakeDeviceStateChangeResult(deviceStateChange : DeviceStateChange, interface DeviceManager { GetLocalDeviceId(): String; UnbindTarget(deviceId: String): void; - GetDeviceType(networkId: String): f64; + GetDeviceType(networkId: String): i32; GetDeviceName(networkId: String): String; GetLocalDeviceNetworkId(): String; -- Gitee From eb3ec92e605dc1d7082d88d076b93ac02d351dd0 Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 14 Jul 2025 15:30:26 +0800 Subject: [PATCH 5/7] taihe modify Signed-off-by: BrainL --- device_manager.gni | 1 - interfaces/kits/taihe/BUILD.gn | 110 ++++++++++++++++----------------- 2 files changed, 53 insertions(+), 58 deletions(-) diff --git a/device_manager.gni b/device_manager.gni index 8f859255c..96682f92a 100644 --- a/device_manager.gni +++ b/device_manager.gni @@ -35,7 +35,6 @@ json_path = "${devicemanager_path}/json" #----------------------compilation options--------------------------# dm_ldflags = [ "-lpthread" ] declare_args() { - device_manager_enable_ets_frontend = true device_manager_no_interaction_auth = false device_manager_feature_product = "default" use_nlohmann_json = true diff --git a/interfaces/kits/taihe/BUILD.gn b/interfaces/kits/taihe/BUILD.gn index cae4b187f..db2d07f2b 100644 --- a/interfaces/kits/taihe/BUILD.gn +++ b/interfaces/kits/taihe/BUILD.gn @@ -33,71 +33,67 @@ ohos_taihe("run_taihe") { ] } -if (device_manager_enable_ets_frontend) { - taihe_shared_library("device_manager_ani_taihe") { - sanitize = { - integer_overflow = true - ubsan = true - boundary_sanitize = true - cfi = true - cfi_cross_dso = true - debug = false - } +taihe_shared_library("device_manager_ani_taihe") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } - taihe_generated_file_path = "$taihe_generated_file_path" - subsystem_name = "$subsystem_name" - part_name = "$part_name" + taihe_generated_file_path = "$taihe_generated_file_path" + subsystem_name = "$subsystem_name" + part_name = "$part_name" - include_dirs = [ - "include", - "${innerkits_path}/native_cpp/include", - "${devicemanager_path}/interfaces/kits/taihe/include", - ] + include_dirs = [ + "include", + "${innerkits_path}/native_cpp/include", + "${devicemanager_path}/interfaces/kits/taihe/include", + ] - sources = get_target_outputs(":run_taihe") - sources += [ - "src/ani_constructor.cpp", - "src/ohos.distributedDeviceManager.cpp", - "src/dm_ani_callback.cpp" - ] + sources = get_target_outputs(":run_taihe") + sources += [ + "src/ani_constructor.cpp", + "src/ohos.distributedDeviceManager.cpp", + "src/dm_ani_callback.cpp" + ] - deps = [ - ":run_taihe", - "${innerkits_path}/native_cpp:devicemanagersdk" - ] + deps = [ + ":run_taihe", + "${innerkits_path}/native_cpp:devicemanagersdk" + ] - external_deps = [ - "hilog:libhilog", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "eventhandler:libeventhandler", - ] - } + external_deps = [ + "hilog:libhilog", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "eventhandler:libeventhandler", + ] +} - generate_static_abc("ohos_distributedDeviceManager_abc") { - base_url = "$taihe_generated_file_path" - files = [ "$taihe_generated_file_path/@ohos.distributedDeviceManager.ets" ] - is_boot_abc = "True" - device_dst_file = "/system/framework/ohos_distributedDeviceManager_abc.abc" - dependencies = [ ":run_taihe" ] - } +generate_static_abc("ohos_distributedDeviceManager_abc") { + base_url = "$taihe_generated_file_path" + files = [ "$taihe_generated_file_path/@ohos.distributedDeviceManager.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/ohos_distributedDeviceManager_abc.abc" + dependencies = [ ":run_taihe" ] +} - ohos_prebuilt_etc("ohos_distributedDeviceManager_etc") { - source = "$target_out_dir/ohos_distributedDeviceManager_abc.abc" - module_install_dir = "framework" - part_name = "$part_name" - subsystem_name = "$subsystem_name" - deps = [ - ":ohos_distributedDeviceManager_abc" - ] - } +ohos_prebuilt_etc("ohos_distributedDeviceManager_etc") { + source = "$target_out_dir/ohos_distributedDeviceManager_abc.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ + ":ohos_distributedDeviceManager_abc" + ] } group("devicemanager_ani") { - if (device_manager_enable_ets_frontend) { - deps = [ - ":device_manager_ani_taihe", - ":ohos_distributedDeviceManager_etc", - ] - } + deps = [ + ":device_manager_ani_taihe", + ":ohos_distributedDeviceManager_etc", + ] } -- Gitee From 397150a4b8e327f53b94f8b0b86650181b3681c2 Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 14 Jul 2025 17:34:05 +0800 Subject: [PATCH 6/7] taihe modify Signed-off-by: BrainL --- device_manager.gni | 1 + interfaces/kits/taihe/BUILD.gn | 110 +++++++++++++++++---------------- 2 files changed, 58 insertions(+), 53 deletions(-) diff --git a/device_manager.gni b/device_manager.gni index 96682f92a..8f859255c 100644 --- a/device_manager.gni +++ b/device_manager.gni @@ -35,6 +35,7 @@ json_path = "${devicemanager_path}/json" #----------------------compilation options--------------------------# dm_ldflags = [ "-lpthread" ] declare_args() { + device_manager_enable_ets_frontend = true device_manager_no_interaction_auth = false device_manager_feature_product = "default" use_nlohmann_json = true diff --git a/interfaces/kits/taihe/BUILD.gn b/interfaces/kits/taihe/BUILD.gn index db2d07f2b..cae4b187f 100644 --- a/interfaces/kits/taihe/BUILD.gn +++ b/interfaces/kits/taihe/BUILD.gn @@ -33,67 +33,71 @@ ohos_taihe("run_taihe") { ] } -taihe_shared_library("device_manager_ani_taihe") { - sanitize = { - integer_overflow = true - ubsan = true - boundary_sanitize = true - cfi = true - cfi_cross_dso = true - debug = false - } +if (device_manager_enable_ets_frontend) { + taihe_shared_library("device_manager_ani_taihe") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } - taihe_generated_file_path = "$taihe_generated_file_path" - subsystem_name = "$subsystem_name" - part_name = "$part_name" + taihe_generated_file_path = "$taihe_generated_file_path" + subsystem_name = "$subsystem_name" + part_name = "$part_name" - include_dirs = [ - "include", - "${innerkits_path}/native_cpp/include", - "${devicemanager_path}/interfaces/kits/taihe/include", - ] + include_dirs = [ + "include", + "${innerkits_path}/native_cpp/include", + "${devicemanager_path}/interfaces/kits/taihe/include", + ] - sources = get_target_outputs(":run_taihe") - sources += [ - "src/ani_constructor.cpp", - "src/ohos.distributedDeviceManager.cpp", - "src/dm_ani_callback.cpp" - ] + sources = get_target_outputs(":run_taihe") + sources += [ + "src/ani_constructor.cpp", + "src/ohos.distributedDeviceManager.cpp", + "src/dm_ani_callback.cpp" + ] - deps = [ - ":run_taihe", - "${innerkits_path}/native_cpp:devicemanagersdk" - ] + deps = [ + ":run_taihe", + "${innerkits_path}/native_cpp:devicemanagersdk" + ] - external_deps = [ - "hilog:libhilog", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "eventhandler:libeventhandler", - ] -} + external_deps = [ + "hilog:libhilog", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "eventhandler:libeventhandler", + ] + } -generate_static_abc("ohos_distributedDeviceManager_abc") { - base_url = "$taihe_generated_file_path" - files = [ "$taihe_generated_file_path/@ohos.distributedDeviceManager.ets" ] - is_boot_abc = "True" - device_dst_file = "/system/framework/ohos_distributedDeviceManager_abc.abc" - dependencies = [ ":run_taihe" ] -} + generate_static_abc("ohos_distributedDeviceManager_abc") { + base_url = "$taihe_generated_file_path" + files = [ "$taihe_generated_file_path/@ohos.distributedDeviceManager.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/ohos_distributedDeviceManager_abc.abc" + dependencies = [ ":run_taihe" ] + } -ohos_prebuilt_etc("ohos_distributedDeviceManager_etc") { - source = "$target_out_dir/ohos_distributedDeviceManager_abc.abc" - module_install_dir = "framework" - part_name = "$part_name" - subsystem_name = "$subsystem_name" - deps = [ - ":ohos_distributedDeviceManager_abc" - ] + ohos_prebuilt_etc("ohos_distributedDeviceManager_etc") { + source = "$target_out_dir/ohos_distributedDeviceManager_abc.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ + ":ohos_distributedDeviceManager_abc" + ] + } } group("devicemanager_ani") { - deps = [ - ":device_manager_ani_taihe", - ":ohos_distributedDeviceManager_etc", - ] + if (device_manager_enable_ets_frontend) { + deps = [ + ":device_manager_ani_taihe", + ":ohos_distributedDeviceManager_etc", + ] + } } -- Gitee From fa0a5884d7924ec2b5842b20a12179999c98f366 Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 14 Jul 2025 19:41:31 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0feature=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- bundle.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index c60d9a95a..d1876a31b 100644 --- a/bundle.json +++ b/bundle.json @@ -16,7 +16,8 @@ "syscap": ["SystemCapability.DistributedHardware.DeviceManager"], "features": [ "device_manager_no_interaction_auth", - "device_manager_feature_product" + "device_manager_feature_product", + "device_manager_enable_ets_frontend" ], "adapted_system_type": ["standard", "mini"], "rom": "2048KB", -- Gitee