From 4d795dd1fa7679763deb0bf3043dffd0c9d0db5a Mon Sep 17 00:00:00 2001 From: liuth <@lzq> Date: Wed, 30 Oct 2024 17:23:31 +0800 Subject: [PATCH 01/49] =?UTF-8?q?[cj]:=20=E4=BB=93=E9=A2=89FFI=E5=B1=82?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=8F=8A=E5=85=B6=E5=AE=9E=E7=8E=B0=20Change?= =?UTF-8?q?-Id:=20Ib6750bd21aa820ec73b60a0c84f7c20645eebbf3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BUILD.gn | 1 + README.md | 1 + README_zh.md | 1 + interfaces/cj/BUILD.gn | 75 ++ interfaces/cj/include/device_manager_ffi.h | 87 ++ interfaces/cj/include/device_manager_impl.h | 99 +++ interfaces/cj/include/device_manager_utils.h | 135 ++++ interfaces/cj/src/device_manager_ffi.cpp | 135 ++++ interfaces/cj/src/device_manager_impl.cpp | 796 +++++++++++++++++++ interfaces/cj/src/device_manager_utils.cpp | 257 ++++++ 10 files changed, 1587 insertions(+) create mode 100644 interfaces/cj/BUILD.gn create mode 100644 interfaces/cj/include/device_manager_ffi.h create mode 100644 interfaces/cj/include/device_manager_impl.h create mode 100644 interfaces/cj/include/device_manager_utils.h create mode 100644 interfaces/cj/src/device_manager_ffi.cpp create mode 100644 interfaces/cj/src/device_manager_impl.cpp create mode 100644 interfaces/cj/src/device_manager_utils.cpp diff --git a/BUILD.gn b/BUILD.gn index 71aed6844..d7f8932ac 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -61,6 +61,7 @@ if (defined(ohos_lite)) { deps = [ "interfaces/inner_kits/native_cpp:devicemanagersdk", "interfaces/kits:devicemanager_native_js", + "interfaces/cj:cj_distributed_device_manager_ffi", ] } group("device_manager_test") { diff --git a/README.md b/README.md index e5359e382..db56f0a48 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ foundation/distributedhardware/device_manager │ └── resources # Resource configuration files for PIN display ServiceExtensionAbility ├── figures ├── interfaces +| ├── cj # Cangjie FFI interfaces and their implementation │ ├── inner_kits # Internal interfaces and their implementation │ │ └── native_cpp # Internal native interfaces and their implementation │ │ ├── include diff --git a/README_zh.md b/README_zh.md index a69927fa1..33fd30bc9 100644 --- a/README_zh.md +++ b/README_zh.md @@ -38,6 +38,7 @@ foundation/distributedhardware/distributedhardware_device_manager │ └── resources # DM PIN码显示ServiceExtensionAbility相关资源配置文件目录 ├── figures ├── interfaces +| ├── cj # 仓颉接口ffi层实现存放目录 │ ├── inner_kits # 内部接口及实现存放目录 │ │ └── native_cpp # 内部native接口及实现存放目录 │ │ ├── include diff --git a/interfaces/cj/BUILD.gn b/interfaces/cj/BUILD.gn new file mode 100644 index 000000000..e0a8f72be --- /dev/null +++ b/interfaces/cj/BUILD.gn @@ -0,0 +1,75 @@ +# 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 +# +# 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") +import("//foundation/distributedhardware/device_manager/device_manager.gni") + +ohos_shared_library("cj_distributed_device_manager_ffi") { + branch_protector_ret = "pac_ret" + + sanitize = { + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + integer_overflow = true + ubsan = true + } + + cflags = [ + "-fdata-sections", + "-ffunction-sections", + "-fvisibility=hidden", + ] + + include_dirs = [ + "include", + "${common_path}/include", + "${common_path}/include/ipc", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/ipc/standard", + ] + + sources = [ + "${common_path}/src/dm_anonymous.cpp", + "${common_path}/src/dm_error_message.cpp", + "src/device_manager_ffi.cpp", + "src/device_manager_impl.cpp", + "src/device_manager_utils.cpp", + ] + + deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"cj_distrubuted_devicemanager\"", + "LOG_DOMAIN=0xD004110", + ] + + external_deps = [ + "access_token:libtokenid_sdk", + "bounds_checking_function:libsec_shared", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + "json:nlohmann_json_static", + "napi:cj_bind_native", + "napi:cj_bind_ffi", + ] + + innerapi_tags = ["platformsdk"] + subsystem_name = "distributedhardware" + part_name = "device_manager" +} diff --git a/interfaces/cj/include/device_manager_ffi.h b/interfaces/cj/include/device_manager_ffi.h new file mode 100644 index 000000000..8fe320e19 --- /dev/null +++ b/interfaces/cj/include/device_manager_ffi.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2022-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 OHOS_DEVICE_MANAGER_FFI_H +#define OHOS_DEVICE_MANAGER_FFI_H + +#include "cj_common_ffi.h" +#include "ffi_remote_data.h" + +#ifdef __cplusplus +#if __plusplus +extern "C" { +#endif +#endif + +typedef struct { + char *deviceId; + char *deviceName; + char *deviceType; + char *networkId; +} FfiDeviceBasicInfo; + +typedef struct { + FfiDeviceBasicInfo *head; + int64_t size; +} FfiDeviceBasicInfoArray; + +typedef struct { + char *deviceId; + int32_t errCode; + char *errInfo; +} FfiErrInfo; + +FFI_EXPORT int64_t FfiCreateDeviceManager(const char *name, int32_t *errCode); + +FFI_EXPORT void FfiRelaseDeviceManager(int64_t id); + +FFI_EXPORT void FfiGetAvailableDeviceList(int64_t id, FfiDeviceBasicInfoArray deviceInfoList, int32_t *errCode); + +FFI_EXPORT void FfiFreeDeviceInfoList(FfiDeviceBasicInfoArray *deviceInfoList); + +FFI_EXPORT const char *FfiGetLocalDeviceNetworkId(int64_t id, int32_t *errCode); + +FFI_EXPORT const char *FfiGetLocalDeviceName(int64_t id, int32_t *errCode); + +FFI_EXPORT int32_t FfiGetLocalDeviceType(int64_t id, int32_t *errCode); + +FFI_EXPORT const char *FfiGetLocalDeviceId(int64_t id, int32_t *errCode); + +FFI_EXPORT const char *FfiGetDeviceName(int64_t id, const char *networkId, int32_t *errCode); + +FFI_EXPORT int32_t FfiGetDeviceType(int64_t id, const char *networkId, int32_t *errCode); + +FFI_EXPORT void FfiStartDiscovering(int64_t id, const char *extra, int32_t *errCode); + +FFI_EXPORT void FfiStopDiscovering(int64_t id, int32_t *errCode); + +FFI_EXPORT void FfiBindTarget(int64_t id, const char *deviceId, const char *bindParam, int32_t authType, + bool isMetaType, int32_t *errCode, FfiErrInfo *errInfo); + +FFI_EXPORT void FfiUnbindTarget(int64_t id, const char *deviceId, int32_t *errCode); + +FFI_EXPORT void FfiOn(int64_t id, const char *type, void *callback, int32_t *errCode); + +FFI_EXPORT void FfiOff(int64_t id, const char *type, int32_t *errCode); + +#ifdef __cplusplus +#if __plusplus +} +#endif +#endif + + + +#endif // OHOS_DEVICE_MANAGER_FFI_H + diff --git a/interfaces/cj/include/device_manager_impl.h b/interfaces/cj/include/device_manager_impl.h new file mode 100644 index 000000000..49e9ca9f3 --- /dev/null +++ b/interfaces/cj/include/device_manager_impl.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2022-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 OHOS_DEVICE_MANAGER_IMPL_H +#define OHOS_DEVICE_MANAGER_IMPL_H + +#include "device_manager_utils.h" +#include "device_manager_ffi.h" + +#include +#include +#include +#include + +#include "ffi_remote_data.h" + +namespace OHOS { +namespace DistributedHardware { +class DeviceManagerFfiImpl : public OHOS::FFI::FFIData { +public: + explicit DeviceManagerFfiImpl(const std::string &bundleName, int32_t *errCode); + ~DeviceManagerFfiImpl() override = default; + + static DeviceManagerFfiImpl *GetDeviceManagerFfi(std::string &bundleName); + + int32_t ReleaseDeviceManager(); + int32_t GetAvailableDeviceList(FfiDeviceBasicInfoArray &deviceInfoList); + static void DeviceListFree(FfiDeviceBasicInfoArray &deviceInfoList, int64_t size = -1); + int32_t GetLocalDeviceNetworkId(const char *&networkId); + int32_t GetLocalDeviceName(const char *&deviceName); + int32_t GetLocalDeviceType(int32_t &deviceType); + int32_t GetLocalDeviceId(const char *&deviceId); + int32_t GetDeviceName(const std::string &networkId, const char *&deviceName); + int32_t GetDeviceType(const std::string &networkId, int32_t &deviceType); + int32_t StartDiscovering(const std::string &extra); + int32_t StopDiscovering(); + int32_t BindTarget(const std::string &deviceId, + const std::string &bindParam, int32_t authType, bool isMetaType, FfiErrInfo &errInfo); + int32_t UnbindTarget(const std::string &deviceId); + int32_t EventOn(const std::string &type, void *callback); + int32_t EventOff(const std::string &type); + + void OnDeviceStatusChange(int32_t action, const DmDeviceBasicInfo &deviceBasicInfo); + void OnDeviceFound(uint16_t subscribeId, const DmDeviceBasicInfo &deviceBasicInfo); + void OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason); + void OnPublishResult(int32_t publishId, int32_t publishResult); + void OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status, int32_t reason); + void OnDmUiCall(const std::string ¶mJson); + void OnRemoteDied(); + +private: + void ClearBundleCallbacks(); + static int32_t Transform2FfiDeviceBasicInfo(const DmDeviceBasicInfo &in, FfiDeviceBasicInfo &out); + int32_t BindTargetWarpper(const std::string &deviceId, + const std::string &bindParam, std::shared_ptr callback); + int32_t WaitForCallbackCv(FfiErrInfo &errInfo); + + int32_t RegisterDevStatusCallback(); + int32_t RegisterDiscoveryCallback(); + int32_t RegisterPublishCallback(); + int32_t RegisterReplyCallback(); + + int32_t ReleaseDevStatusCallback(); + int32_t ReleaseDiscoveryCallback(); + int32_t ReleasePublishCallback(); + int32_t ReleaseReplyCallback(); + + void RegisterCallbackByType(const std::string &type, void *callback); + void Off(const std::string &type); + + std::string bundleName_; + std::function deviceStateChangedCallback; + std::function discoverSuccessCallback; + std::function deviceNameChangedCallback; + std::function deviceDiscoverFailedCallback; + std::function deviceServiceDiedCallback; + std::mutex lock_; + + std::condition_variable callbackFinishedCv; + std::mutex callbackFinishedMutex; + std::shared_ptr errInfo_; + std::mutex errInfoMutex; +}; + + +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IMPL_H \ No newline at end of file diff --git a/interfaces/cj/include/device_manager_utils.h b/interfaces/cj/include/device_manager_utils.h new file mode 100644 index 000000000..fa3328fb7 --- /dev/null +++ b/interfaces/cj/include/device_manager_utils.h @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2022-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 OHOS_DEVICE_MANAGER_UTILS_H +#define OHOS_DEVICE_MANAGER_UTILS_H + +#include + +#include "device_manager_callback.h" +#include "dm_device_info.h" +#include "nlohmann/json.hpp" + +namespace OHOS { +namespace DistributedHardware { + +enum DmFfiDevStatusChange { UNKNOWN = 0, AVAILABLE = 1, UNAVAILABLE = 2, CHANGE = 3}; + +class DmFfiInitCallback : public DmInitCallback { +public: + explicit DmFfiInitCallback(const std::string &bundleName) : bundleName_(bundleName) + { + } + ~DmFfiInitCallback() override = default; + void OnRemoteDied() override; + +private: + std::string bundleName_; +}; + +class DmFfiDeviceStatusCallback : public DeviceStatusCallback { +public: + explicit DmFfiDeviceStatusCallback(const std::string &bundleName) : bundleName_(bundleName) + { + } + ~DmFfiDeviceStatusCallback() override = default; + void OnDeviceOnline(const DmDeviceBasicInfo &deviceBasicInfo) override; + void OnDeviceReady(const DmDeviceBasicInfo &deviceBasicInfo) override; + void OnDeviceOffline(const DmDeviceBasicInfo &deviceBasicInfo) override; + void OnDeviceChanged(const DmDeviceBasicInfo &deviceBasicInfo) override; +private: + std::string bundleName_; +}; + +class DmFfiDiscoveryCallback : public DiscoveryCallback { +public: + explicit DmFfiDiscoveryCallback(const std::string &bundleName): refCount_(0), bundleName_(bundleName) + { + } + ~DmFfiDiscoveryCallback() override = default; + 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_; +}; + +class DmFfiPublishCallback : public PublishCallback { +public: + explicit DmFfiPublishCallback(const std::string &bundleName): refCount_(0), bundleName_(bundleName) + { + } + ~DmFfiPublishCallback() override = default; + void OnPublishResult(int32_t publishId, int32_t publishResult) override; + void IncreaseRefCount(); + void DecreaseRefCount(); + int32_t GetRefCount(); + +private: + std::atomic refCount_; + std::string bundleName_; +}; + +class DmFfiDeviceManagerUiCallback : public DeviceManagerUiCallback { +public: + explicit DmFfiDeviceManagerUiCallback(const std::string &bundleName) : bundleName_(bundleName) + { + } + ~DmFfiDeviceManagerUiCallback() override = default; + void OnCall(const std::string ¶mJson) override; + +private: + std::string bundleName_; +}; + +class DmFfiAuthenticateCallback : public AuthenticateCallback { +public: + explicit DmFfiAuthenticateCallback(const std::string &bundleName) : bundleName_(bundleName) + { + } + ~DmFfiAuthenticateCallback() override = default; + void OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status, int32_t reason) override; + +private: + std::string bundleName_; +}; + +class DmFfiBindTargetCallback : public BindTargetCallback { +public: + explicit DmFfiBindTargetCallback(std::string &bundleName) : bundleName_(bundleName) + { + } + ~DmFfiBindTargetCallback() override = default; + void OnBindResult(const PeerTargetId &targetId, int32_t result, int32_t status, std::string content) override; + +private: + std::string bundleName_; +}; + + +const std::string &GetDeviceTypeById(DmDeviceType type); +char *MallocCStr(const char *in); +void InsertMapParames(nlohmann::json &bindParamObj, std::map &bindParamMap); + +} // namespace DistributedHardware +} // namespace OHOS + + +#endif // OHOS_DEVICE_MANAGER_IMPL_H \ No newline at end of file diff --git a/interfaces/cj/src/device_manager_ffi.cpp b/interfaces/cj/src/device_manager_ffi.cpp new file mode 100644 index 000000000..dbae8c5e4 --- /dev/null +++ b/interfaces/cj/src/device_manager_ffi.cpp @@ -0,0 +1,135 @@ +/* + * 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 + * + * 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 "device_manager_ffi.h" +#include "device_manager_impl.h" + +#include + +#include "device_manager.h" +#include "dm_log.h" + + +int64_t FfiCreateDeviceManager(const char *name, int32_t *errCode) +{ + auto deviceManager = OHOS::FFI::FFIData::Create( + std::string(name), errCode); + if (!deviceManager || errCode) { + delete static_cast(deviceManager); + return 0; + } + return deviceManager->GetID(); +} + +void FfiReleaseDeviceManager(int64_t id, int32_t *errCode) +{ + auto instance = OHOS::FFI::FFIData::GetData(id); + *errCode = instance->ReleaseDeviceManager(); +} + +void FfiGetAvailableDeviceList(int64_t id, FfiDeviceBasicInfoArray *deviceInfoList, int32_t *errCode) +{ + auto instance = OHOS::FFI::FFIData::GetData(id); + *errCode = instance->GetAvailableDeviceList(*deviceInfoList); +} + +void FfiFreeDeviceInfoList(FfiDeviceBasicInfoArray *deviceInfoList) +{ + OHOS::DistributedHardware::DeviceManagerFfiImpl::DeviceListFree(*deviceInfoList); +} + +const char *FfiGetLocalDeviceNetworkId(int64_t id, int32_t *errCode) +{ + auto instance = OHOS::FFI::FFIData::GetData(id); + const char *networkIdPtr = nullptr; + *errCode = instance->GetLocalDeviceNetworkId(networkIdPtr); + return networkIdPtr; +} + +const char *FfiGetLocalDeviceName(int64_t id, int32_t *errCode) +{ + auto instance = OHOS::FFI::FFIData::GetData(id); + const char *deviceName = nullptr; + *errCode = instance->GetLocalDeviceName(deviceName); + return deviceName; +} + +int32_t FfiGetLocalDeviceType(int64_t id, int32_t *errCode) +{ + auto instance = OHOS::FFI::FFIData::GetData(id); + int32_t deviceType = 0; + *errCode = instance->GetLocalDeviceType(deviceType); + return deviceType; +} + +const char *FfiGetLocalDeviceId(int64_t id, int32_t *errCode) +{ + auto instance = OHOS::FFI::FFIData::GetData(id); + const char *deviceId = nullptr; + *errCode = instance->GetLocalDeviceId(deviceId); + return deviceId; +} + +const char *FfiGetDeviceName(int64_t id, const char *networkId, int32_t *errCode) +{ + auto instance = OHOS::FFI::FFIData::GetData(id); + const char *deviceName = nullptr; + *errCode = instance->GetDeviceName(networkId, deviceName); + return deviceName; +} + +int32_t FfiGetDeviceType(int64_t id, const char *networkId, int32_t *errCode) +{ + auto instance = OHOS::FFI::FFIData::GetData(id); + int32_t deviceType = 0; + *errCode = instance->GetDeviceType(networkId, deviceType); + return deviceType; +} + +void FfiStartDiscovering(int64_t id, const char *extra, int32_t *errCode) +{ + auto instance = OHOS::FFI::FFIData::GetData(id); + *errCode = instance->StartDiscovering(extra); +} + +void FfiStopDiscovering(int64_t id, int32_t *errCode) +{ + auto instance = OHOS::FFI::FFIData::GetData(id); + *errCode = instance->StopDiscovering(); +} + +void FfiBindTarget(int64_t id, const char *deviceId, const char *bindParam, int32_t authType, + bool isMetaType, int32_t *errCode, FfiErrInfo *errInfo) +{ + auto instance = OHOS::FFI::FFIData::GetData(id); + *errCode = instance->BindTarget(deviceId, bindParam, authType, isMetaType, *errInfo); +} + +void FfiUnbindTarget(int64_t id, const char *deviceId, int32_t *errCode) +{ + auto instance = OHOS::FFI::FFIData::GetData(id); + *errCode = instance->UnbindTarget(deviceId); +} + +void FfiOn(int64_t id, const char *type, void *callback, int32_t *errCode) +{ + auto instance = OHOS::FFI::FFIData::GetData(id); + *errCode = instance->EventOn(type, callback); +} + +void FfiOff(int64_t id, const char *type, int32_t *errCode) +{ + auto instance = OHOS::FFI::FFIData::GetData(id); + *errCode = instance->EventOff(type); +} diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp new file mode 100644 index 000000000..970467c4d --- /dev/null +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -0,0 +1,796 @@ +/* + * 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 + * + * 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 "device_manager_impl.h" + +#include +#include + +#include "dm_log.h" +#include "device_manager.h" +#include "dm_anonymous.h" +#include "ipc_skeleton.h" +#include "dm_error_message.h" +#include "dm_constants.h" +#include "cj_lambda.h" + +namespace OHOS::DistributedHardware { + +namespace { +std::map g_deviceManagerMap; +std::map> g_initCallbackMap; +std::map> g_deviceStatusCallbackMap; +std::map> g_DiscoveryCallbackMap; +std::map> g_publishCallbackMap; +std::map> g_authCallbackMap; +std::map> g_bindCallbackMap; +std::map> g_dmUiCallbackMap; + +std::mutex g_deviceManagerMapMutex; +std::mutex g_initCallbackMapMutex; +std::mutex g_deviceStatusCallbackMapMutex; +std::mutex g_discoveryCallbackMapMutex; +std::mutex g_publishCallbackMapMutex; +std::mutex g_authCallbackMapMutex; +std::mutex g_bindCallbackMapMutex; +std::mutex g_dmUiCallbackMapMutex; + +const int32_t DM_AUTH_REQUEST_SUCCESS_STATUS = 7; + +const std::string DM_FFI_EVENT_DEVICE_STATE_CHANGE = "deviceStateChange"; +const std::string DM_FFI_EVENT_DEVICE_DISCOVER_SUCCESS = "discoverSuccess"; +const std::string DM_FFI_EVENT_DEVICE_DISCOVER_FAIL = "discoverFailure"; +const std::string DM_FFI_EVENT_DEVICE_PUBLISH_SUCCESS = "publishSuccess"; +const std::string DM_FFI_EVENT_DEVICE_PUBLISH_FAIL = "publishFailure"; +const std::string DM_FFI_EVENT_DEVICE_SERVICE_DIE = "serviceDie"; +const std::string DEVICE_MANAGER_FFI_CLASS_NAME = "DeviceManager"; +const std::string DM_FFI_EVENT_REPLY_RESULT = "replyResult"; +const std::string DM_FFI_EVENT_DEVICE_NAME_CHANGE = "deviceNameChange"; + +enum ErrorCode { + // OK + ERR_OK = 0, + // Permission verify failed. + ERR_NO_PERMISSION = 201, + // The caller is not a system application. + ERR_NOT_SYSTEM_APP = 202, + // Input parameter error. + ERR_INVALID_PARAMS = 401, + // Failed to execute the function. + DM_ERR_FAILED = 11600101, + // Failed to obtain the service. + DM_ERR_OBTAIN_SERVICE = 11600102, + // Authentication invalid. + DM_ERR_AUTHENTICALTION_INVALID = 11600103, + // Discovery invalid. + DM_ERR_DISCOVERY_INVALID = 11600104, + // Publish invalid. + DM_ERR_PUBLISH_INVALID = 11600105, +}; + +} // namespace + +DeviceManagerFfiImpl::DeviceManagerFfiImpl(const std::string &bundleName, int32_t *errCode) : bundleName_(bundleName) +{ + std::shared_ptr initCallback = std::make_shared(bundleName_); + *errCode = DeviceManager::GetInstance().InitDeviceManager(bundleName_, initCallback); + if (*errCode != 0) { + LOGE("CreateDeviceManager for bundleName %{public}s failed, ret %{public}d.", bundleName_.c_str(), *errCode); + return; + } + { + std::lock_guard autoLock(g_initCallbackMapMutex); + g_initCallbackMap[bundleName_] = initCallback; + } + + std::lock_guard autoLock(g_deviceManagerMapMutex); + g_deviceManagerMap[bundleName_] = this; +} + +int32_t DeviceManagerFfiImpl::ReleaseDeviceManager() { + int ret = DeviceManager::GetInstance().UnInitDeviceManager(bundleName_); + if (ret != 0) { + LOGE("ReleaseDeviceManager for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); + return ret; + } + ClearBundleCallbacks(); + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::GetAvailableDeviceList(FfiDeviceBasicInfoArray &deviceInfoList) +{ + int32_t ret = DeviceManager::GetInstance().CheckNewAPIAccessPermission(); + if (ret != 0) { + return ret; + } + std::vector result; + ret = DeviceManager::GetInstance().GetAvailableDeviceList(bundleName_, result); + if (ret != 0) { + LOGE("GetTrustedDeviceList for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); + return ret; + } + + if (result.size() == 0) { + return ERR_OK; + } + + deviceInfoList.head = static_cast(malloc(sizeof(FfiDeviceBasicInfo) * result.size())); + if (deviceInfoList.head == nullptr) { + LOGE("Malloc failed"); + return DM_ERR_FAILED; + } + deviceInfoList.size = result.size(); + for (int64_t i = 0; i < result.size(); ++i) { + ret = Transform2FfiDeviceBasicInfo(result[i], deviceInfoList.head[i]); + if (ret != 0) { + DeviceListFree(deviceInfoList, i); + return ret; + } + } + return ERR_OK; +} + +void DeviceManagerFfiImpl::DeviceListFree(FfiDeviceBasicInfoArray &deviceInfoList, int64_t size) +{ + if (size == -1) { + size = deviceInfoList.size; + } + for (int32_t i = 0; i < size; ++i) { + free(deviceInfoList.head[i].deviceId); + free(deviceInfoList.head[i].deviceName); + free(deviceInfoList.head[i].deviceType); + free(deviceInfoList.head[i].networkId); + } + free(deviceInfoList.head); + deviceInfoList.head = nullptr; + deviceInfoList.size = 0; +} + +int32_t DeviceManagerFfiImpl::Transform2FfiDeviceBasicInfo(const DmDeviceBasicInfo &in, FfiDeviceBasicInfo &out) +{ + out.deviceId = MallocCStr(in.deviceId); + out.deviceName = MallocCStr(in.deviceName); + out.deviceType = MallocCStr(GetDeviceTypeById(static_cast(in.deviceTypeId)).c_str()); + out.networkId = MallocCStr(in.networkId); + if (out.deviceId == nullptr || out.deviceName == nullptr || + out.deviceType == nullptr || out.networkId == nullptr) { + free(out.deviceId); + free(out.deviceName); + free(out.deviceType); + free(out.networkId); + return DM_ERR_FAILED; + } + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::GetLocalDeviceNetworkId(const char *&networkId) +{ + if (DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + return ERR_NO_PERMISSION; + } + + std::string result; + int32_t ret = DeviceManager::GetInstance().GetLocalDeviceNetWorkId(bundleName_, result); + if (ret != 0) { + LOGE("GetLocalDeviceNetworkId for failed, ret %{public}d", ret); + return ret; + } + LOGI("DeviceManager::GetLocalDeviceNetworkId networkId:%{public}s", GetAnonyString(result).c_str()); + + networkId = MallocCStr(result.c_str()); + if (networkId == nullptr) { + return DM_ERR_FAILED; + } + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::GetLocalDeviceName(const char *&deviceName) +{ + if (DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + return ERR_NO_PERMISSION; + } + + std::string result; + int32_t ret = DeviceManager::GetInstance().GetLocalDeviceName(bundleName_, result); + if (ret != 0) { + LOGE("GetLocalDeviceName for failed, ret %{public}d", ret); + return ret; + } + LOGI("DeviceManager::GetLocalDeviceName deviceName:%{public}s", GetAnonyString(result).c_str()); + + deviceName = MallocCStr(result.c_str()); + if (deviceName == nullptr) { + return DM_ERR_FAILED; + } + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::GetLocalDeviceType(int32_t &deviceType) +{ + if (DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + return ERR_NO_PERMISSION; + } + + int32_t ret = DeviceManager::GetInstance().GetLocalDeviceType(bundleName_, deviceType); + if (ret != 0) { + LOGE("GetLocalDeviceType for failed, ret %{public}d", ret); + return ret; + } + LOGI("DeviceManager::GetLocalDeviceType deviceType:%{public}d", deviceType); + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::GetLocalDeviceId(const char *&deviceId) +{ + if (DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + return ERR_NO_PERMISSION; + } + + std::string result; + int32_t ret = DeviceManager::GetInstance().GetLocalDeviceId(bundleName_, result); + if (ret != 0) { + LOGE("GetLocalDeviceId for failed, ret %{public}d", ret); + return ret; + } + LOGI("DeviceManager::GetLocalDeviceId deviceId:%{public}s", GetAnonyString(result).c_str()); + + deviceId = MallocCStr(result.c_str()); + if (deviceId == nullptr) { + return DM_ERR_FAILED; + } + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::GetDeviceName(const std::string &networkId, const char *&deviceName) +{ + std::string result; + int32_t ret = DeviceManager::GetInstance().GetDeviceName(bundleName_, networkId, result); + if (ret != 0) { + LOGE("GetDeviceName for failed, ret %{public}d", ret); + return ret; + } + LOGI("DeviceManager::GetDeviceName deviceName:%{public}s", GetAnonyString(deviceName).c_str()); + + deviceName = MallocCStr(result.c_str()); + if (deviceName == nullptr) { + return DM_ERR_FAILED; + } + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::GetDeviceType(const std::string &networkId, int32_t &deviceType) +{ + int32_t ret = DeviceManager::GetInstance().GetDeviceType(bundleName_, networkId, deviceType); + if (ret != 0) { + LOGE("GetDeviceType for failed, ret %{public}d", ret); + return ret; + } + LOGI("DeviceManager::GetDeviceType deviceType:%{public}d", deviceType); + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::StartDiscovering(const std::string &extra) +{ + std::shared_ptr discoveryCallback = nullptr; + { + std::lock_guard autoLock(g_discoveryCallbackMapMutex); + auto iter = g_DiscoveryCallbackMap.find(bundleName_); + if (iter == g_DiscoveryCallbackMap.end()) { + discoveryCallback = std::make_shared(bundleName_); + g_DiscoveryCallbackMap[bundleName_] = discoveryCallback; + } else { + discoveryCallback = iter->second; + } + } + uint64_t tokenId = OHOS::IPCSkeleton::GetSelfTokenID(); + int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(bundleName_, tokenId, extra, discoveryCallback); + if (ret != 0) { + LOGE("Discovery failed, bundleName %{public}s, ret %{public}d", bundleName_.c_str(), ret); + discoveryCallback->OnDiscoveryFailed(static_cast(0), ret); + return ret; + } + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::StopDiscovering() +{ + uint64_t tokenId = OHOS::IPCSkeleton::GetSelfTokenID(); + int32_t ret = DeviceManager::GetInstance().StopDeviceDiscovery(tokenId, bundleName_); + if (ret != 0) { + LOGE("StopDeviceDiscovery for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); + return ret; + } + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, + const std::string &bindParam, const int32_t authType, const bool isMetaType, FfiErrInfo &errInfo) +{ + if (isMetaType) { + std::shared_ptr bindTargetCallback = nullptr; + { + std::lock_guard autoLock(g_bindCallbackMapMutex); + auto iter = g_bindCallbackMap.find(bundleName_); + if (iter == g_bindCallbackMap.end()) { + bindTargetCallback = std::make_shared(bundleName_); + g_bindCallbackMap[bundleName_] = bindTargetCallback; + } else { + bindTargetCallback = iter->second; + } + } + int32_t ret = BindTargetWarpper(deviceId, bindParam, bindTargetCallback); + if (ret != 0) { + LOGE("BindTarget for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); + return ret; + } + return WaitForCallbackCv(errInfo); + } + + std::shared_ptr bindDeviceCallback = nullptr; + { + std::lock_guard autoLock(g_authCallbackMapMutex); + auto iter = g_authCallbackMap.find(bundleName_); + if (iter == g_authCallbackMap.end()) { + bindDeviceCallback = std::make_shared(bundleName_); + g_authCallbackMap[bundleName_] = bindDeviceCallback; + } else { + bindDeviceCallback = iter->second; + } + } + int32_t ret = DeviceManager::GetInstance().BindDevice(bundleName_, + authType, deviceId, bindParam, bindDeviceCallback); + if (ret != 0) { + LOGE("BindDevice for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); + return ret; + } + return WaitForCallbackCv(errInfo); +} + +int32_t DeviceManagerFfiImpl::WaitForCallbackCv(FfiErrInfo &errInfo) +{ + { + std::unique_lock autoLock(callbackFinishedMutex); + callbackFinishedCv.wait(autoLock); + } + { + std::lock_guard autoLock(errInfoMutex); + if (errInfo_.get() != nullptr) { + errInfo.deviceId = errInfo_->deviceId; + errInfo.errCode = errInfo_->errCode; + errInfo.errInfo = errInfo_->errInfo; + } + errInfo_.reset(); + } + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::UnbindTarget(const std::string &deviceId) +{ + LOGI("UnBindDevice deviceId = %{public}s", GetAnonyString(deviceId).c_str()); + int32_t ret = DeviceManager::GetInstance().UnBindDevice(bundleName_, deviceId); + if (ret != 0) { + LOGE("UnBindDevice for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); + return ret; + } + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::EventOn(const std::string &type, void *callback) +{ + int32_t ret = DeviceManager::GetInstance().CheckNewAPIAccessPermission(); + if (ret != 0) { + return ret; + } + + LOGI("On for bundleName %{public}s, eventType %{public}s ", bundleName_.c_str(), type.c_str()); + RegisterCallbackByType(type, callback); + + if (type == DM_FFI_EVENT_DEVICE_STATE_CHANGE || type == DM_FFI_EVENT_DEVICE_NAME_CHANGE) { + return RegisterDevStatusCallback(); + } else if (type == DM_FFI_EVENT_DEVICE_DISCOVER_SUCCESS || type == DM_FFI_EVENT_DEVICE_DISCOVER_FAIL) { + RegisterDiscoveryCallback(); + } else if (type == DM_FFI_EVENT_DEVICE_PUBLISH_SUCCESS || type == DM_FFI_EVENT_DEVICE_PUBLISH_FAIL) { + RegisterPublishCallback(); + } else if (type == DM_FFI_EVENT_REPLY_RESULT) { + RegisterReplyCallback(); + } + + return ERR_INVALID_PARAMS; +} + +int32_t DeviceManagerFfiImpl::EventOff(const std::string &type) +{ + int32_t ret = DeviceManager::GetInstance().CheckNewAPIAccessPermission(); + if (ret != 0) { + return ret; + } + + LOGI("JsOff for bundleName %{public}s, eventType %{public}s ", bundleName_.c_str(), type.c_str()); + Off(type); + if (type == DM_FFI_EVENT_DEVICE_STATE_CHANGE || type == DM_FFI_EVENT_DEVICE_NAME_CHANGE) { + return ReleaseDevStatusCallback(); + } else if (type == DM_FFI_EVENT_DEVICE_DISCOVER_SUCCESS || type == DM_FFI_EVENT_DEVICE_DISCOVER_FAIL) { + return ReleaseDiscoveryCallback(); + } else if (type == DM_FFI_EVENT_DEVICE_PUBLISH_SUCCESS || type == DM_FFI_EVENT_DEVICE_PUBLISH_FAIL) { + return ReleasePublishCallback(); + } else if (type == DM_FFI_EVENT_REPLY_RESULT) { + return ReleaseReplyCallback(); + } + return ERR_INVALID_PARAMS; +} + + +void DeviceManagerFfiImpl::OnDeviceStatusChange(int32_t action, const DmDeviceBasicInfo &deviceBasicInfo) +{ + std::lock_guard autoLock(lock_); + if (deviceStateChangedCallback) { + auto ptr = static_cast(malloc(sizeof(FfiDeviceBasicInfo))); + if (ptr == nullptr) { + LOGE("OnDeviceStatusChange malloc FfiDeviceBasicInfo failed."); + } + int32_t ret = Transform2FfiDeviceBasicInfo(deviceBasicInfo, *ptr); + if (ret != 0) { + LOGE("OnDeviceStatusChange failed to transform DmDeviceBasicInfo."); + return; + } + deviceStateChangedCallback(action, ptr); + free(ptr->deviceId); + free(ptr->deviceName); + free(ptr->deviceType); + free(ptr->networkId); + free(ptr); + } +} + +void DeviceManagerFfiImpl::OnDeviceFound(uint16_t subscribeId, const DmDeviceBasicInfo &deviceBasicInfo) +{ + std::lock_guard autoLock(lock_); + if (discoverSuccessCallback) { + auto ptr = static_cast(malloc(sizeof(FfiDeviceBasicInfo))); + if (ptr == nullptr) { + LOGE("OnDeviceStatusChange malloc FfiDeviceBasicInfo failed."); + } + int32_t ret = Transform2FfiDeviceBasicInfo(deviceBasicInfo, *ptr); + if (ret != 0) { + LOGE("OnDeviceStatusChange failed to transform DmDeviceBasicInfo."); + return; + } + discoverSuccessCallback(ptr); + free(ptr->deviceId); + free(ptr->deviceName); + free(ptr->deviceType); + free(ptr->networkId); + free(ptr); + } +} + +void DeviceManagerFfiImpl::OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason) +{ + std::lock_guard autoLock(lock_); + LOGI("OnDiscoveryFailed for subscribeId %{public}d", (int32_t)subscribeId); + if (deviceDiscoverFailedCallback) { + deviceDiscoverFailedCallback(failedReason); + } +} + +void DeviceManagerFfiImpl::OnPublishResult(int32_t publishId, int32_t publishResult) +{ + LOGI("OnPublishResult for publishId %{public}d, publishResult %{public}d", publishId, publishResult); +} + +void DeviceManagerFfiImpl::OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status, + int32_t reason) +{ + LOGI("OnAuthResult for status: %{public}d, reason: %{public}d", status, reason); + + if (status == DM_AUTH_REQUEST_SUCCESS_STATUS && reason == 0) { + LOGI("OnAuthResult success"); + std::lock_guard autoLock(errInfoMutex); + errInfo_.reset(); + } else { + LOGI("OnAuthResult failed"); + std::lock_guard autoLock(errInfoMutex); + errInfo_.reset(new FfiErrInfo); + errInfo_->deviceId = MallocCStr(deviceId.c_str()); + errInfo_->errCode = status; + errInfo_->errInfo = MallocCStr(GetErrorString((int)reason).c_str()); + if (errInfo_->deviceId == nullptr || errInfo_->errInfo == nullptr) { + LOGE("OnAuthResult, Malloc memory for errInfo failed."); + free(errInfo_->deviceId); + free(errInfo_->errInfo); + errInfo_.reset(); + } + } + + if (reason == DM_OK && (status <= STATUS_DM_CLOSE_PIN_INPUT_UI && status >= STATUS_DM_SHOW_AUTHORIZE_UI)) { + LOGI("update ui change, status: %{public}d, reason: %{public}d", status, reason); + } else { + std::lock_guard autoLock(g_authCallbackMapMutex); + g_authCallbackMap.erase(bundleName_); + } + callbackFinishedCv.notify_one(); +} + +void DeviceManagerFfiImpl::OnDmUiCall(const std::string ¶mJson) +{ + LOGI("OnCall for paramJson"); +} + +void DeviceManagerFfiImpl::OnRemoteDied() +{ + if (deviceServiceDiedCallback) { + deviceServiceDiedCallback(); + } +} + +DeviceManagerFfiImpl *DeviceManagerFfiImpl::GetDeviceManagerFfi(std::string &bundleName) +{ + std::lock_guard autoLock(g_deviceManagerMapMutex); + auto iter = g_deviceManagerMap.find(bundleName); + if (iter == g_deviceManagerMap.end()) { + return nullptr; + } + return iter->second; +} + +void DeviceManagerFfiImpl::ClearBundleCallbacks() +{ + LOGI("ClearBundleCallbacks start for bundleName %{public}s", bundleName_.c_str()); + { + std::lock_guard autoLock(g_deviceManagerMapMutex); + g_deviceManagerMap.erase(bundleName_); + } + { + std::lock_guard autoLock(g_initCallbackMapMutex); + g_initCallbackMap.erase(bundleName_); + } + { + std::lock_guard autoLock(g_deviceStatusCallbackMapMutex); + g_deviceStatusCallbackMap.erase(bundleName_); + } + { + std::lock_guard autoLock(g_discoveryCallbackMapMutex); + g_DiscoveryCallbackMap.erase(bundleName_); + } + { + std::lock_guard autoLock(g_publishCallbackMapMutex); + g_publishCallbackMap.erase(bundleName_); + } + { + std::lock_guard autoLock(g_authCallbackMapMutex); + g_authCallbackMap.erase(bundleName_); + } + { + std::lock_guard autoLock(g_bindCallbackMapMutex); + g_bindCallbackMap.erase(bundleName_); + } + return; +} + +int32_t DeviceManagerFfiImpl::BindTargetWarpper(const std::string &deviceId, + const std::string &bindParam, std::shared_ptr callback) +{ + if (bindParam.empty()) { + return ERR_INVALID_PARAMS; + } + nlohmann::json bindParamObj = nlohmann::json::parse(bindParam, nullptr, false); + if (bindParamObj.is_discarded()) { + return ERR_INVALID_PARAMS; + } + PeerTargetId targetId; + targetId.deviceId = deviceId; + if (IsString(bindParamObj, PARAM_KEY_BR_MAC)) { + targetId.brMac = bindParamObj[PARAM_KEY_BR_MAC].get(); + } + if (IsString(bindParamObj, PARAM_KEY_BLE_MAC)) { + targetId.bleMac = bindParamObj[PARAM_KEY_BLE_MAC].get(); + } + if (IsString(bindParamObj, PARAM_KEY_WIFI_IP)) { + targetId.wifiIp = bindParamObj[PARAM_KEY_WIFI_IP].get(); + } + if (IsInt32(bindParamObj, PARAM_KEY_WIFI_PORT)) { + targetId.wifiPort = (uint16_t)(bindParamObj[PARAM_KEY_WIFI_PORT].get()); + } + + std::map bindParamMap; + InsertMapParames(bindParamObj, bindParamMap); + return DeviceManager::GetInstance().BindTarget(bundleName_, targetId, bindParamMap, callback); +} + + +int32_t DeviceManagerFfiImpl::RegisterDevStatusCallback() +{ + LOGI("RegisterDevStatusCallback start for bundleName %{public}s", bundleName_.c_str()); + { + std::lock_guard autoLock(g_deviceStatusCallbackMapMutex); + if (g_deviceStatusCallbackMap.find(bundleName_) != g_deviceStatusCallbackMap.end()) { + LOGI("bundleName already register."); + return ERR_OK; + } + } + auto callback = std::make_shared(bundleName_); + int32_t ret = DeviceManager::GetInstance().RegisterDevStatusCallback(bundleName_, "", callback); + if (ret != 0) { + LOGE("RegisterDevStatusCallback failed for bundleName %{public}s", bundleName_.c_str()); + return ret; + } + { + std::lock_guard autoLock(g_deviceStatusCallbackMapMutex); + g_deviceStatusCallbackMap[bundleName_] = callback; + } + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::RegisterDiscoveryCallback() +{ + auto discoveryCallback = std::make_shared(bundleName_); + { + std::lock_guard autoLock(g_discoveryCallbackMapMutex); + g_DiscoveryCallbackMap[bundleName_] = discoveryCallback; + } + discoveryCallback->IncreaseRefCount(); + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::RegisterPublishCallback() +{ + auto publishCallback = std::make_shared(bundleName_); + { + std::lock_guard autoLock(g_publishCallbackMapMutex); + g_publishCallbackMap[bundleName_] = publishCallback; + } + publishCallback->IncreaseRefCount(); + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::RegisterReplyCallback() +{ + auto dmUiCallback = std::make_shared(bundleName_); + int32_t ret = DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(bundleName_, dmUiCallback); + if (ret != 0) { + LOGE("RegisterDeviceManagerFaCallback failed for bundleName %{public}s", bundleName_.c_str()); + return ret; + } + { + std::lock_guard autoLock(g_dmUiCallbackMapMutex); + g_dmUiCallbackMap[bundleName_] = dmUiCallback; + } + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::ReleaseDevStatusCallback() +{ + { + std::lock_guard autoLock(g_deviceStatusCallbackMapMutex); + auto iter = g_deviceStatusCallbackMap.find(bundleName_); + if (iter == g_deviceStatusCallbackMap.end()) { + LOGE("ReleaseDmCallback: cannot find statusCallback for bundleName %{public}s", bundleName_.c_str()); + return ERR_INVALID_PARAMS; + } + } + int32_t ret = DeviceManager::GetInstance().UnRegisterDevStatusCallback(bundleName_); + if (ret != 0) { + LOGE("UnRegisterDevStatusCallback failed for bundleName %{public}s", bundleName_.c_str()); + return ret; + } + { + std::lock_guard autoLock(g_deviceStatusCallbackMapMutex); + g_deviceStatusCallbackMap.erase(bundleName_); + } + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::ReleaseDiscoveryCallback() +{ + LOGI("ReleaseDiscoveryCallback for bundleName %{public}s", bundleName_.c_str()); + std::shared_ptr DiscoveryCallback = nullptr; + { + std::lock_guard autoLock(g_discoveryCallbackMapMutex); + auto iter = g_DiscoveryCallbackMap.find(bundleName_); + if (iter == g_DiscoveryCallbackMap.end()) { + return ERR_OK; + } + DiscoveryCallback = iter->second; + } + DiscoveryCallback->DecreaseRefCount(); + if (DiscoveryCallback->GetRefCount() == 0) { + std::lock_guard autoLock(g_discoveryCallbackMapMutex); + g_DiscoveryCallbackMap.erase(bundleName_); + } + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::ReleasePublishCallback() +{ + LOGI("ReleasePublishCallback for bundleName %{public}s", bundleName_.c_str()); + std::shared_ptr publishCallback = nullptr; + { + std::lock_guard autoLock(g_publishCallbackMapMutex); + auto iter = g_publishCallbackMap.find(bundleName_); + if (iter == g_publishCallbackMap.end()) { + return ERR_OK; + } + publishCallback = iter->second; + } + publishCallback->DecreaseRefCount(); + if (publishCallback->GetRefCount() == 0) { + std::lock_guard autoLock(g_publishCallbackMapMutex); + g_publishCallbackMap.erase(bundleName_); + } + return ERR_OK; +} + +int32_t DeviceManagerFfiImpl::ReleaseReplyCallback() +{ + { + 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 ERR_INVALID_PARAMS; + } + } + int32_t ret = DeviceManager::GetInstance().UnRegisterDeviceManagerFaCallback(bundleName_); + if (ret != 0) { + LOGE("UnRegisterDeviceManagerFaCallback failed for bundleName %{public}s", bundleName_.c_str()); + return ret; + } + { + std::lock_guard autoLock(g_dmUiCallbackMapMutex); + g_dmUiCallbackMap.erase(bundleName_); + } + return ERR_OK; +} + + +void DeviceManagerFfiImpl::RegisterCallbackByType(const std::string &type, void *callback) +{ + std::lock_guard autoLock(lock_); + if (type == DM_FFI_EVENT_DEVICE_STATE_CHANGE) { + deviceStateChangedCallback = CJLambda::Create(reinterpret_cast(callback)); + } else if (type == DM_FFI_EVENT_DEVICE_DISCOVER_SUCCESS) { + discoverSuccessCallback = CJLambda::Create(reinterpret_cast(callback)); + } else if (type == DM_FFI_EVENT_DEVICE_NAME_CHANGE) { + deviceNameChangedCallback = CJLambda::Create(reinterpret_cast(callback)); + } else if (type == DM_FFI_EVENT_DEVICE_DISCOVER_FAIL) { + deviceDiscoverFailedCallback = CJLambda::Create(reinterpret_cast(callback)); + } else if (type == DM_FFI_EVENT_DEVICE_SERVICE_DIE) { + deviceServiceDiedCallback = CJLambda::Create(reinterpret_cast(callback)); + } else { + LOGE("RegisterCallbackByType call with wrong type."); + } +} + +void DeviceManagerFfiImpl::Off(const std::string &type) +{ + std::lock_guard autoLock(lock_); + if (type == DM_FFI_EVENT_DEVICE_STATE_CHANGE) { + deviceStateChangedCallback = nullptr; + } else if (type == DM_FFI_EVENT_DEVICE_DISCOVER_SUCCESS) { + discoverSuccessCallback = nullptr; + } else if (type == DM_FFI_EVENT_DEVICE_NAME_CHANGE) { + deviceNameChangedCallback = nullptr; + } else if (type == DM_FFI_EVENT_DEVICE_DISCOVER_FAIL) { + deviceDiscoverFailedCallback = nullptr; + } else if (type == DM_FFI_EVENT_DEVICE_SERVICE_DIE) { + deviceServiceDiedCallback = nullptr; + } else { + LOGE("Off call with wrong type."); + } +} + + +} // namespace OHOS::DistributedHardware + + diff --git a/interfaces/cj/src/device_manager_utils.cpp b/interfaces/cj/src/device_manager_utils.cpp new file mode 100644 index 000000000..14ee67267 --- /dev/null +++ b/interfaces/cj/src/device_manager_utils.cpp @@ -0,0 +1,257 @@ +/* + * Copyright (c) 2022-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 "device_manager_utils.h" +#include "device_manager_impl.h" + +#include +#include +#include + +#include "dm_log.h" +#include "dm_constants.h" +#include "dm_anonymous.h" + +namespace OHOS::DistributedHardware { + +void DmFfiInitCallback::OnRemoteDied() +{ + DeviceManagerFfiImpl *deviceManagerFfi = DeviceManagerFfiImpl::GetDeviceManagerFfi(bundleName_); + if (deviceManagerFfi == nullptr) { + LOGE("OnRemoteDied, deviceManagerFfi not find for bundleName %{public}s", bundleName_.c_str()); + } else { + deviceManagerFfi->OnRemoteDied(); + } + LOGI("OnRemoteDied, deviceManagerFfi bundleName %{public}s", bundleName_.c_str()); +} + +void DmFfiDeviceStatusCallback::OnDeviceOnline(const DmDeviceBasicInfo &deviceBasicInfo) +{ + DeviceManagerFfiImpl *deviceManagerFfi = DeviceManagerFfiImpl::GetDeviceManagerFfi(bundleName_); + if (deviceManagerFfi == nullptr) { + LOGE("OnDeviceOnline, deviceManagerFfi not find for bundleName %{public}s", bundleName_.c_str()); + } else { + deviceManagerFfi->OnDeviceStatusChange(DmFfiDevStatusChange::UNKNOWN, deviceBasicInfo); + } +} + +void DmFfiDeviceStatusCallback::OnDeviceReady(const DmDeviceBasicInfo &deviceBasicInfo) +{ + DeviceManagerFfiImpl *deviceManagerFfi = DeviceManagerFfiImpl::GetDeviceManagerFfi(bundleName_); + if (deviceManagerFfi == nullptr) { + LOGE("OnDeviceReady, deviceManagerFfi not find for bundleName %{public}s", bundleName_.c_str()); + } else { + deviceManagerFfi->OnDeviceStatusChange(DmFfiDevStatusChange::AVAILABLE, deviceBasicInfo); + } +} + +void DmFfiDeviceStatusCallback::OnDeviceOffline(const DmDeviceBasicInfo &deviceBasicInfo) +{ + DeviceManagerFfiImpl *deviceManagerFfi = DeviceManagerFfiImpl::GetDeviceManagerFfi(bundleName_); + if (deviceManagerFfi == nullptr) { + LOGE("OnDeviceOffline, deviceManagerFfi not find for bundleName %{public}s", bundleName_.c_str()); + } else { + deviceManagerFfi->OnDeviceStatusChange(DmFfiDevStatusChange::UNAVAILABLE, deviceBasicInfo); + } +} + +void DmFfiDeviceStatusCallback::OnDeviceChanged(const DmDeviceBasicInfo &deviceBasicInfo) +{ + DeviceManagerFfiImpl *deviceManagerFfi = DeviceManagerFfiImpl::GetDeviceManagerFfi(bundleName_); + if (deviceManagerFfi == nullptr) { + LOGE("OnDeviceChanged, deviceManagerFfi not find for bundleName %{public}s", bundleName_.c_str()); + } else { + deviceManagerFfi->OnDeviceStatusChange(DmFfiDevStatusChange::CHANGE, deviceBasicInfo); + } +} + +void DmFfiDiscoveryCallback::OnDeviceFound(uint16_t subscribeId, + const DmDeviceBasicInfo &deviceBasicInfo) +{ + LOGI("OnDeviceFound for %{public}s, subscribeId %{public}d", bundleName_.c_str(), (int32_t)subscribeId); + DeviceManagerFfiImpl *deviceManagerFfi = DeviceManagerFfiImpl::GetDeviceManagerFfi(bundleName_); + if (deviceManagerFfi == nullptr) { + LOGE("OnDeviceFound, deviceManagerFfi not find for bundleName %{public}s", bundleName_.c_str()); + } else { + deviceManagerFfi->OnDeviceFound(subscribeId, deviceBasicInfo); + } +} + +void DmFfiDiscoveryCallback::OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason) +{ + LOGI("OnDiscoveryFailed for %{public}s, subscribeId %{public}d", bundleName_.c_str(), (int32_t)subscribeId); + DeviceManagerFfiImpl *deviceManagerFfi = DeviceManagerFfiImpl::GetDeviceManagerFfi(bundleName_); + if (deviceManagerFfi == nullptr) { + LOGE("OnDiscoveryFailed, deviceManagerFfi not find for bundleName %{public}s", bundleName_.c_str()); + } else { + deviceManagerFfi->OnDiscoveryFailed(subscribeId, failedReason); + } +} + +void DmFfiDiscoveryCallback::OnDiscoverySuccess(uint16_t subscribeId) +{ + DeviceManagerFfiImpl *deviceManagerFfi = DeviceManagerFfiImpl::GetDeviceManagerFfi(bundleName_); + if (deviceManagerFfi == nullptr) { + LOGE("OnDiscoverySuccess, deviceManagerFfi not find for bundleName %{public}s", bundleName_.c_str()); + return; + } + LOGI("DiscoverySuccess for %{public}s, subscribeId %{public}d", bundleName_.c_str(), (int32_t)subscribeId); +} + +void DmFfiDiscoveryCallback::IncreaseRefCount() +{ + refCount_++; +} + +void DmFfiDiscoveryCallback::DecreaseRefCount() +{ + refCount_--; +} + +int32_t DmFfiDiscoveryCallback::GetRefCount() +{ + return refCount_; +} + +void DmFfiPublishCallback::OnPublishResult(int32_t publishId, int32_t publishResult) +{ + LOGI("OnPublishResult for %{public}s, publishId %{public}d, publishResult %{public}d", bundleName_.c_str(), + publishId, publishResult); + DeviceManagerFfiImpl *deviceManagerFfi = DeviceManagerFfiImpl::GetDeviceManagerFfi(bundleName_); + if (deviceManagerFfi == nullptr) { + LOGE("OnPublishResult, deviceManagerFfi failed for bundleName %{public}s", bundleName_.c_str()); + } else { + deviceManagerFfi->OnPublishResult(publishId, publishResult); + } +} + +void DmFfiPublishCallback::IncreaseRefCount() +{ + refCount_++; +} + +void DmFfiPublishCallback::DecreaseRefCount() +{ + refCount_--; +} + +int32_t DmFfiPublishCallback::GetRefCount() +{ + return refCount_; +} + +void DmFfiAuthenticateCallback::OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status, + int32_t reason) +{ + DeviceManagerFfiImpl *deviceManagerFfi = DeviceManagerFfiImpl::GetDeviceManagerFfi(bundleName_); + if (deviceManagerFfi == nullptr) { + LOGE("OnAuthResult, deviceManagerFfi not find for bundleName %{public}s", bundleName_.c_str()); + } else { + deviceManagerFfi->OnAuthResult(deviceId, token, status, reason); + } +} + +void DmFfiDeviceManagerUiCallback::OnCall(const std::string ¶mJson) +{ + DeviceManagerFfiImpl *deviceManagerFfi = DeviceManagerFfiImpl::GetDeviceManagerFfi(bundleName_); + if (deviceManagerFfi == nullptr) { + LOGE("OnCall, deviceManagerFfi not find for bundleName %{public}s", bundleName_.c_str()); + } else { + deviceManagerFfi->OnDmUiCall(paramJson); + } +} + +void DmFfiBindTargetCallback::OnBindResult(const PeerTargetId &targetId, int32_t result, int32_t status, + std::string content) +{ + (void)targetId; + DeviceManagerFfiImpl *deviceManagerFfi = DeviceManagerFfiImpl::GetDeviceManagerFfi(bundleName_); + if (deviceManagerFfi == nullptr) { + LOGE("OnBindResult, deviceManagerFfi not find for bundleName %{public}s", bundleName_.c_str()); + } else { + deviceManagerFfi->OnAuthResult(content, "",status, result); + } +} + +const std::string &GetDeviceTypeById(DmDeviceType type) +{ + const static std::pair mapArray[] = { + {DEVICE_TYPE_UNKNOWN, DEVICE_TYPE_UNKNOWN_STRING}, + {DEVICE_TYPE_PHONE, DEVICE_TYPE_PHONE_STRING}, + {DEVICE_TYPE_PAD, DEVICE_TYPE_PAD_STRING}, + {DEVICE_TYPE_TV, DEVICE_TYPE_TV_STRING}, + {DEVICE_TYPE_CAR, DEVICE_TYPE_CAR_STRING}, + {DEVICE_TYPE_WATCH, DEVICE_TYPE_WATCH_STRING}, + {DEVICE_TYPE_WIFI_CAMERA, DEVICE_TYPE_WIFICAMERA_STRING}, + {DEVICE_TYPE_PC, DEVICE_TYPE_PC_STRING}, + {DEVICE_TYPE_SMART_DISPLAY, DEVICE_TYPE_SMART_DISPLAY_STRING}, + {DEVICE_TYPE_2IN1, DEVICE_TYPE_2IN1_STRING}, + }; + for (const auto& item : mapArray) { + if (item.first == type) { + return item.second; + } + } + return DEVICE_TYPE_UNKNOWN_STRING; +} + +char *MallocCStr(const char *in) +{ + int64_t len = strlen(in); + char *result = static_cast(malloc(len + 1)); + if (result == nullptr) { + LOGE("Malloc failed."); + return nullptr; + } + std::char_traits::copy(result, in, len+1); + return result; +} + +void InsertMapParames(nlohmann::json &bindParamObj, std::map &bindParamMap) +{ + LOGI("Insert map parames start"); + if (IsInt32(bindParamObj, AUTH_TYPE)) { + int32_t authType = bindParamObj[AUTH_TYPE].get(); + bindParamMap.insert(std::pair(PARAM_KEY_AUTH_TYPE, std::to_string(authType))); + } + if (IsString(bindParamObj, APP_OPERATION)) { + std::string appOperation = bindParamObj[APP_OPERATION].get(); + bindParamMap.insert(std::pair(PARAM_KEY_APP_OPER, appOperation)); + } + if (IsString(bindParamObj, CUSTOM_DESCRIPTION)) { + std::string appDescription = bindParamObj[CUSTOM_DESCRIPTION].get(); + bindParamMap.insert(std::pair(PARAM_KEY_APP_DESC, appDescription)); + } + if (IsString(bindParamObj, PARAM_KEY_TARGET_PKG_NAME)) { + std::string targetPkgName = bindParamObj[PARAM_KEY_TARGET_PKG_NAME].get(); + bindParamMap.insert(std::pair(PARAM_KEY_TARGET_PKG_NAME, targetPkgName)); + } + if (IsString(bindParamObj, PARAM_KEY_META_TYPE)) { + std::string metaType = bindParamObj[PARAM_KEY_META_TYPE].get(); + bindParamMap.insert(std::pair(PARAM_KEY_META_TYPE, metaType)); + } + if (IsString(bindParamObj, PARAM_KEY_PIN_CODE)) { + std::string pinCode = bindParamObj[PARAM_KEY_PIN_CODE].get(); + bindParamMap.insert(std::pair(PARAM_KEY_PIN_CODE, pinCode)); + } + if (IsString(bindParamObj, PARAM_KEY_AUTH_TOKEN)) { + std::string authToken = bindParamObj[PARAM_KEY_AUTH_TOKEN].get(); + bindParamMap.insert(std::pair(PARAM_KEY_AUTH_TOKEN, authToken)); + } + if (IsInt32(bindParamObj, BIND_LEVEL)) { + int32_t bindLevel = bindParamObj[BIND_LEVEL].get(); + bindParamMap.insert(std::pair(BIND_LEVEL, std::to_string(bindLevel))); + } +} +} // OHOS::DistributedHardware \ No newline at end of file -- Gitee From 33bb1110bbdcd3a5e3465fd45eee7637d1961c86 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sat, 2 Nov 2024 11:05:35 +0800 Subject: [PATCH 02/49] =?UTF-8?q?=E5=AF=B9ffi=E6=8E=A5=E5=8F=A3=E5=8F=8A?= =?UTF-8?q?=E5=85=B6=E5=AE=9E=E7=8E=B0=E8=BF=9B=E8=A1=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/cj/include/device_manager_ffi.h | 4 ++-- interfaces/cj/include/device_manager_impl.h | 2 +- interfaces/cj/src/device_manager_ffi.cpp | 4 ++-- interfaces/cj/src/device_manager_impl.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/interfaces/cj/include/device_manager_ffi.h b/interfaces/cj/include/device_manager_ffi.h index 8fe320e19..391a2108f 100644 --- a/interfaces/cj/include/device_manager_ffi.h +++ b/interfaces/cj/include/device_manager_ffi.h @@ -44,11 +44,11 @@ typedef struct { FFI_EXPORT int64_t FfiCreateDeviceManager(const char *name, int32_t *errCode); -FFI_EXPORT void FfiRelaseDeviceManager(int64_t id); +FFI_EXPORT void FfiRelaseDeviceManager(int64_t id, int32_t *errCode); FFI_EXPORT void FfiGetAvailableDeviceList(int64_t id, FfiDeviceBasicInfoArray deviceInfoList, int32_t *errCode); -FFI_EXPORT void FfiFreeDeviceInfoList(FfiDeviceBasicInfoArray *deviceInfoList); +FFI_EXPORT void FfiFreeDeviceInfoList(const FfiDeviceBasicInfoArray deviceInfoList); FFI_EXPORT const char *FfiGetLocalDeviceNetworkId(int64_t id, int32_t *errCode); diff --git a/interfaces/cj/include/device_manager_impl.h b/interfaces/cj/include/device_manager_impl.h index 49e9ca9f3..441b46010 100644 --- a/interfaces/cj/include/device_manager_impl.h +++ b/interfaces/cj/include/device_manager_impl.h @@ -36,7 +36,7 @@ public: int32_t ReleaseDeviceManager(); int32_t GetAvailableDeviceList(FfiDeviceBasicInfoArray &deviceInfoList); - static void DeviceListFree(FfiDeviceBasicInfoArray &deviceInfoList, int64_t size = -1); + static void DeviceListFree(const FfiDeviceBasicInfoArray &deviceInfoList, int64_t size = -1); int32_t GetLocalDeviceNetworkId(const char *&networkId); int32_t GetLocalDeviceName(const char *&deviceName); int32_t GetLocalDeviceType(int32_t &deviceType); diff --git a/interfaces/cj/src/device_manager_ffi.cpp b/interfaces/cj/src/device_manager_ffi.cpp index dbae8c5e4..d77b08c10 100644 --- a/interfaces/cj/src/device_manager_ffi.cpp +++ b/interfaces/cj/src/device_manager_ffi.cpp @@ -44,9 +44,9 @@ void FfiGetAvailableDeviceList(int64_t id, FfiDeviceBasicInfoArray *deviceInfoLi *errCode = instance->GetAvailableDeviceList(*deviceInfoList); } -void FfiFreeDeviceInfoList(FfiDeviceBasicInfoArray *deviceInfoList) +void FfiFreeDeviceInfoList(const FfiDeviceBasicInfoArray deviceInfoList) { - OHOS::DistributedHardware::DeviceManagerFfiImpl::DeviceListFree(*deviceInfoList); + OHOS::DistributedHardware::DeviceManagerFfiImpl::DeviceListFree(deviceInfoList); } const char *FfiGetLocalDeviceNetworkId(int64_t id, int32_t *errCode) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 970467c4d..adae346cd 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -141,7 +141,7 @@ int32_t DeviceManagerFfiImpl::GetAvailableDeviceList(FfiDeviceBasicInfoArray &de return ERR_OK; } -void DeviceManagerFfiImpl::DeviceListFree(FfiDeviceBasicInfoArray &deviceInfoList, int64_t size) +void DeviceManagerFfiImpl::DeviceListFree(const FfiDeviceBasicInfoArray &deviceInfoList, int64_t size) { if (size == -1) { size = deviceInfoList.size; -- Gitee From 91bc528c98931a97ea0faa883d7d5d61228d3bdf Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sat, 2 Nov 2024 17:18:17 +0800 Subject: [PATCH 03/49] =?UTF-8?q?=E4=BF=AE=E6=94=B9bindTarget=E7=9A=84ffi?= =?UTF-8?q?=E5=B1=82=E6=8E=A5=E5=8F=A3=E4=BB=A5=E5=8F=8AC++=E5=B1=82?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3,=20=E5=87=8F=E5=B0=91=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=97=A0=E6=95=88=E5=8F=82=E6=95=B0,=20=E8=AF=A5=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=8F=AA=E8=83=BD=E4=B8=BA1.=20Change-Id:=20I87234f83?= =?UTF-8?q?da7128d9300eecb64dd87225a7a6a4ad?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/cj/include/device_manager_ffi.h | 2 +- interfaces/cj/include/device_manager_impl.h | 2 +- interfaces/cj/src/device_manager_ffi.cpp | 2 +- interfaces/cj/src/device_manager_impl.cpp | 5 ++--- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/interfaces/cj/include/device_manager_ffi.h b/interfaces/cj/include/device_manager_ffi.h index 391a2108f..189857467 100644 --- a/interfaces/cj/include/device_manager_ffi.h +++ b/interfaces/cj/include/device_manager_ffi.h @@ -66,7 +66,7 @@ FFI_EXPORT void FfiStartDiscovering(int64_t id, const char *extra, int32_t *errC FFI_EXPORT void FfiStopDiscovering(int64_t id, int32_t *errCode); -FFI_EXPORT void FfiBindTarget(int64_t id, const char *deviceId, const char *bindParam, int32_t authType, +FFI_EXPORT void FfiBindTarget(int64_t id, const char *deviceId, const char *bindParam, bool isMetaType, int32_t *errCode, FfiErrInfo *errInfo); FFI_EXPORT void FfiUnbindTarget(int64_t id, const char *deviceId, int32_t *errCode); diff --git a/interfaces/cj/include/device_manager_impl.h b/interfaces/cj/include/device_manager_impl.h index 441b46010..0ec863d35 100644 --- a/interfaces/cj/include/device_manager_impl.h +++ b/interfaces/cj/include/device_manager_impl.h @@ -46,7 +46,7 @@ public: int32_t StartDiscovering(const std::string &extra); int32_t StopDiscovering(); int32_t BindTarget(const std::string &deviceId, - const std::string &bindParam, int32_t authType, bool isMetaType, FfiErrInfo &errInfo); + const std::string &bindParam, bool isMetaType, FfiErrInfo &errInfo); int32_t UnbindTarget(const std::string &deviceId); int32_t EventOn(const std::string &type, void *callback); int32_t EventOff(const std::string &type); diff --git a/interfaces/cj/src/device_manager_ffi.cpp b/interfaces/cj/src/device_manager_ffi.cpp index d77b08c10..c9416fb49 100644 --- a/interfaces/cj/src/device_manager_ffi.cpp +++ b/interfaces/cj/src/device_manager_ffi.cpp @@ -109,7 +109,7 @@ void FfiStopDiscovering(int64_t id, int32_t *errCode) *errCode = instance->StopDiscovering(); } -void FfiBindTarget(int64_t id, const char *deviceId, const char *bindParam, int32_t authType, +void FfiBindTarget(int64_t id, const char *deviceId, const char *bindParam, bool isMetaType, int32_t *errCode, FfiErrInfo *errInfo) { auto instance = OHOS::FFI::FFIData::GetData(id); diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index adae346cd..1f1b8c085 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -315,7 +315,7 @@ int32_t DeviceManagerFfiImpl::StopDiscovering() } int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, - const std::string &bindParam, const int32_t authType, const bool isMetaType, FfiErrInfo &errInfo) + const std::string &bindParam, const bool isMetaType, FfiErrInfo &errInfo) { if (isMetaType) { std::shared_ptr bindTargetCallback = nullptr; @@ -348,8 +348,7 @@ int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, bindDeviceCallback = iter->second; } } - int32_t ret = DeviceManager::GetInstance().BindDevice(bundleName_, - authType, deviceId, bindParam, bindDeviceCallback); + int32_t ret = DeviceManager::GetInstance().BindDevice(bundleName_, 1, deviceId, bindParam, bindDeviceCallback); if (ret != 0) { LOGE("BindDevice for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); return ret; -- Gitee From bcd2ec9938629d15ab1b10bcd8abf0b6f5c0c874 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sun, 3 Nov 2024 15:46:52 +0800 Subject: [PATCH 04/49] =?UTF-8?q?=E4=BF=AE=E6=94=B9BindTarget=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=8F=8A=E5=85=B6=E5=AE=9E=E7=8E=B0,=20=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=97=A0=E7=94=A8=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I1684265f9719c87b8ee4c35650ac2ba9eea87ae1 --- interfaces/cj/include/device_manager_ffi.h | 4 +- interfaces/cj/include/device_manager_impl.h | 12 +++--- interfaces/cj/src/device_manager_ffi.cpp | 7 ++-- interfaces/cj/src/device_manager_impl.cpp | 46 ++++++--------------- 4 files changed, 23 insertions(+), 46 deletions(-) diff --git a/interfaces/cj/include/device_manager_ffi.h b/interfaces/cj/include/device_manager_ffi.h index 189857467..e4558dbbd 100644 --- a/interfaces/cj/include/device_manager_ffi.h +++ b/interfaces/cj/include/device_manager_ffi.h @@ -48,7 +48,7 @@ FFI_EXPORT void FfiRelaseDeviceManager(int64_t id, int32_t *errCode); FFI_EXPORT void FfiGetAvailableDeviceList(int64_t id, FfiDeviceBasicInfoArray deviceInfoList, int32_t *errCode); -FFI_EXPORT void FfiFreeDeviceInfoList(const FfiDeviceBasicInfoArray deviceInfoList); +FFI_EXPORT void FfiFreeDeviceInfoList(FfiDeviceBasicInfoArray deviceInfoList); FFI_EXPORT const char *FfiGetLocalDeviceNetworkId(int64_t id, int32_t *errCode); @@ -67,7 +67,7 @@ FFI_EXPORT void FfiStartDiscovering(int64_t id, const char *extra, int32_t *errC FFI_EXPORT void FfiStopDiscovering(int64_t id, int32_t *errCode); FFI_EXPORT void FfiBindTarget(int64_t id, const char *deviceId, const char *bindParam, - bool isMetaType, int32_t *errCode, FfiErrInfo *errInfo); + bool isMetaType, int32_t *errCode); FFI_EXPORT void FfiUnbindTarget(int64_t id, const char *deviceId, int32_t *errCode); diff --git a/interfaces/cj/include/device_manager_impl.h b/interfaces/cj/include/device_manager_impl.h index 0ec863d35..dba7c1140 100644 --- a/interfaces/cj/include/device_manager_impl.h +++ b/interfaces/cj/include/device_manager_impl.h @@ -36,7 +36,7 @@ public: int32_t ReleaseDeviceManager(); int32_t GetAvailableDeviceList(FfiDeviceBasicInfoArray &deviceInfoList); - static void DeviceListFree(const FfiDeviceBasicInfoArray &deviceInfoList, int64_t size = -1); + static void DeviceListFree(FfiDeviceBasicInfoArray &deviceInfoList, int64_t size = -1); int32_t GetLocalDeviceNetworkId(const char *&networkId); int32_t GetLocalDeviceName(const char *&deviceName); int32_t GetLocalDeviceType(int32_t &deviceType); @@ -45,8 +45,7 @@ public: int32_t GetDeviceType(const std::string &networkId, int32_t &deviceType); int32_t StartDiscovering(const std::string &extra); int32_t StopDiscovering(); - int32_t BindTarget(const std::string &deviceId, - const std::string &bindParam, bool isMetaType, FfiErrInfo &errInfo); + int32_t BindTarget(const std::string &deviceId, const std::string &bindParam, bool isMetaType); int32_t UnbindTarget(const std::string &deviceId); int32_t EventOn(const std::string &type, void *callback); int32_t EventOff(const std::string &type); @@ -64,7 +63,7 @@ private: static int32_t Transform2FfiDeviceBasicInfo(const DmDeviceBasicInfo &in, FfiDeviceBasicInfo &out); int32_t BindTargetWarpper(const std::string &deviceId, const std::string &bindParam, std::shared_ptr callback); - int32_t WaitForCallbackCv(FfiErrInfo &errInfo); + int32_t WaitForCallbackCv(); int32_t RegisterDevStatusCallback(); int32_t RegisterDiscoveryCallback(); @@ -85,12 +84,11 @@ private: std::function deviceNameChangedCallback; std::function deviceDiscoverFailedCallback; std::function deviceServiceDiedCallback; - std::mutex lock_; + std::mutex callbackLock; std::condition_variable callbackFinishedCv; std::mutex callbackFinishedMutex; - std::shared_ptr errInfo_; - std::mutex errInfoMutex; + std::atomic errCode_; }; diff --git a/interfaces/cj/src/device_manager_ffi.cpp b/interfaces/cj/src/device_manager_ffi.cpp index c9416fb49..afd8e17cd 100644 --- a/interfaces/cj/src/device_manager_ffi.cpp +++ b/interfaces/cj/src/device_manager_ffi.cpp @@ -44,7 +44,7 @@ void FfiGetAvailableDeviceList(int64_t id, FfiDeviceBasicInfoArray *deviceInfoLi *errCode = instance->GetAvailableDeviceList(*deviceInfoList); } -void FfiFreeDeviceInfoList(const FfiDeviceBasicInfoArray deviceInfoList) +void FfiFreeDeviceInfoList(FfiDeviceBasicInfoArray deviceInfoList) { OHOS::DistributedHardware::DeviceManagerFfiImpl::DeviceListFree(deviceInfoList); } @@ -109,11 +109,10 @@ void FfiStopDiscovering(int64_t id, int32_t *errCode) *errCode = instance->StopDiscovering(); } -void FfiBindTarget(int64_t id, const char *deviceId, const char *bindParam, - bool isMetaType, int32_t *errCode, FfiErrInfo *errInfo) +void FfiBindTarget(int64_t id, const char *deviceId, const char *bindParam, bool isMetaType, int32_t *errCode) { auto instance = OHOS::FFI::FFIData::GetData(id); - *errCode = instance->BindTarget(deviceId, bindParam, authType, isMetaType, *errInfo); + *errCode = instance->BindTarget(deviceId, bindParam, isMetaType); } void FfiUnbindTarget(int64_t id, const char *deviceId, int32_t *errCode) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 1f1b8c085..69b2cbc65 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -141,7 +141,7 @@ int32_t DeviceManagerFfiImpl::GetAvailableDeviceList(FfiDeviceBasicInfoArray &de return ERR_OK; } -void DeviceManagerFfiImpl::DeviceListFree(const FfiDeviceBasicInfoArray &deviceInfoList, int64_t size) +void DeviceManagerFfiImpl::DeviceListFree(FfiDeviceBasicInfoArray &deviceInfoList, int64_t size) { if (size == -1) { size = deviceInfoList.size; @@ -315,7 +315,7 @@ int32_t DeviceManagerFfiImpl::StopDiscovering() } int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, - const std::string &bindParam, const bool isMetaType, FfiErrInfo &errInfo) + const std::string &bindParam, const bool isMetaType) { if (isMetaType) { std::shared_ptr bindTargetCallback = nullptr; @@ -334,7 +334,7 @@ int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, LOGE("BindTarget for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); return ret; } - return WaitForCallbackCv(errInfo); + return WaitForCallbackCv(); } std::shared_ptr bindDeviceCallback = nullptr; @@ -353,25 +353,16 @@ int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, LOGE("BindDevice for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); return ret; } - return WaitForCallbackCv(errInfo); + return WaitForCallbackCv(); } -int32_t DeviceManagerFfiImpl::WaitForCallbackCv(FfiErrInfo &errInfo) +int32_t DeviceManagerFfiImpl::WaitForCallbackCv() { { std::unique_lock autoLock(callbackFinishedMutex); callbackFinishedCv.wait(autoLock); } - { - std::lock_guard autoLock(errInfoMutex); - if (errInfo_.get() != nullptr) { - errInfo.deviceId = errInfo_->deviceId; - errInfo.errCode = errInfo_->errCode; - errInfo.errInfo = errInfo_->errInfo; - } - errInfo_.reset(); - } - return ERR_OK; + return errCode_; } int32_t DeviceManagerFfiImpl::UnbindTarget(const std::string &deviceId) @@ -432,7 +423,7 @@ int32_t DeviceManagerFfiImpl::EventOff(const std::string &type) void DeviceManagerFfiImpl::OnDeviceStatusChange(int32_t action, const DmDeviceBasicInfo &deviceBasicInfo) { - std::lock_guard autoLock(lock_); + std::lock_guard autoLock(callbackLock); if (deviceStateChangedCallback) { auto ptr = static_cast(malloc(sizeof(FfiDeviceBasicInfo))); if (ptr == nullptr) { @@ -454,7 +445,7 @@ void DeviceManagerFfiImpl::OnDeviceStatusChange(int32_t action, const DmDeviceBa void DeviceManagerFfiImpl::OnDeviceFound(uint16_t subscribeId, const DmDeviceBasicInfo &deviceBasicInfo) { - std::lock_guard autoLock(lock_); + std::lock_guard autoLock(callbackLock); if (discoverSuccessCallback) { auto ptr = static_cast(malloc(sizeof(FfiDeviceBasicInfo))); if (ptr == nullptr) { @@ -476,7 +467,7 @@ void DeviceManagerFfiImpl::OnDeviceFound(uint16_t subscribeId, const DmDeviceBas void DeviceManagerFfiImpl::OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason) { - std::lock_guard autoLock(lock_); + std::lock_guard autoLock(callbackLock); LOGI("OnDiscoveryFailed for subscribeId %{public}d", (int32_t)subscribeId); if (deviceDiscoverFailedCallback) { deviceDiscoverFailedCallback(failedReason); @@ -495,21 +486,10 @@ void DeviceManagerFfiImpl::OnAuthResult(const std::string &deviceId, const std:: if (status == DM_AUTH_REQUEST_SUCCESS_STATUS && reason == 0) { LOGI("OnAuthResult success"); - std::lock_guard autoLock(errInfoMutex); - errInfo_.reset(); + errCode_ = ERR_OK; } else { LOGI("OnAuthResult failed"); - std::lock_guard autoLock(errInfoMutex); - errInfo_.reset(new FfiErrInfo); - errInfo_->deviceId = MallocCStr(deviceId.c_str()); - errInfo_->errCode = status; - errInfo_->errInfo = MallocCStr(GetErrorString((int)reason).c_str()); - if (errInfo_->deviceId == nullptr || errInfo_->errInfo == nullptr) { - LOGE("OnAuthResult, Malloc memory for errInfo failed."); - free(errInfo_->deviceId); - free(errInfo_->errInfo); - errInfo_.reset(); - } + errCode_ = status; } if (reason == DM_OK && (status <= STATUS_DM_CLOSE_PIN_INPUT_UI && status >= STATUS_DM_SHOW_AUTHORIZE_UI)) { @@ -755,7 +735,7 @@ int32_t DeviceManagerFfiImpl::ReleaseReplyCallback() void DeviceManagerFfiImpl::RegisterCallbackByType(const std::string &type, void *callback) { - std::lock_guard autoLock(lock_); + std::lock_guard autoLock(callbackLock); if (type == DM_FFI_EVENT_DEVICE_STATE_CHANGE) { deviceStateChangedCallback = CJLambda::Create(reinterpret_cast(callback)); } else if (type == DM_FFI_EVENT_DEVICE_DISCOVER_SUCCESS) { @@ -773,7 +753,7 @@ void DeviceManagerFfiImpl::RegisterCallbackByType(const std::string &type, void void DeviceManagerFfiImpl::Off(const std::string &type) { - std::lock_guard autoLock(lock_); + std::lock_guard autoLock(callbackLock); if (type == DM_FFI_EVENT_DEVICE_STATE_CHANGE) { deviceStateChangedCallback = nullptr; } else if (type == DM_FFI_EVENT_DEVICE_DISCOVER_SUCCESS) { -- Gitee From 1fd85ca9a8f139bfc9bb5a39c526f59234547850 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Mon, 4 Nov 2024 15:31:52 +0800 Subject: [PATCH 05/49] =?UTF-8?q?=E4=BF=AE=E6=94=B9wait=E5=92=8Cnotify?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0,=20=E4=BD=BF=E5=85=B6=E6=BB=A1?= =?UTF-8?q?=E8=B6=B3=E8=A7=84=E8=8C=83.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I009b14fe06d176f37fe1b210ae8aa252c39b033d --- interfaces/cj/include/device_manager_impl.h | 1 + interfaces/cj/src/device_manager_impl.cpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/interfaces/cj/include/device_manager_impl.h b/interfaces/cj/include/device_manager_impl.h index dba7c1140..688973dfe 100644 --- a/interfaces/cj/include/device_manager_impl.h +++ b/interfaces/cj/include/device_manager_impl.h @@ -88,6 +88,7 @@ private: std::condition_variable callbackFinishedCv; std::mutex callbackFinishedMutex; + bool calbackFinished = false; std::atomic errCode_; }; diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 69b2cbc65..6e31378d4 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -317,6 +317,7 @@ int32_t DeviceManagerFfiImpl::StopDiscovering() int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, const std::string &bindParam, const bool isMetaType) { + callbackFinished = false; if (isMetaType) { std::shared_ptr bindTargetCallback = nullptr; { @@ -348,7 +349,9 @@ int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, bindDeviceCallback = iter->second; } } - int32_t ret = DeviceManager::GetInstance().BindDevice(bundleName_, 1, deviceId, bindParam, bindDeviceCallback); + constexpr int32_t bindType = 1; + int32_t ret = DeviceManager::GetInstance().BindDevice( + bundleName_, bindType, deviceId, bindParam, bindDeviceCallback); if (ret != 0) { LOGE("BindDevice for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); return ret; @@ -356,11 +359,11 @@ int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, return WaitForCallbackCv(); } -int32_t DeviceManagerFfiImpl::WaitForCallbackCv() +void DeviceManagerFfiImpl::WaitForCallbackCv() { - { + if (!callbackFinished) { std::unique_lock autoLock(callbackFinishedMutex); - callbackFinishedCv.wait(autoLock); + callbackFinishedCv.wait(autoLock, callbackFinished); } return errCode_; } @@ -498,6 +501,7 @@ void DeviceManagerFfiImpl::OnAuthResult(const std::string &deviceId, const std:: std::lock_guard autoLock(g_authCallbackMapMutex); g_authCallbackMap.erase(bundleName_); } + callbackFinished = true; callbackFinishedCv.notify_one(); } -- Gitee From 1295371803e33fdd35948d3e53000d5eae747e20 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Tue, 5 Nov 2024 10:21:27 +0800 Subject: [PATCH 06/49] Delete unused FfiErrInfo struct. Change-Id: I461a8ebbc54195a532d6538e2ecfd0d44989774c --- interfaces/cj/include/device_manager_ffi.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/interfaces/cj/include/device_manager_ffi.h b/interfaces/cj/include/device_manager_ffi.h index e4558dbbd..2385daafe 100644 --- a/interfaces/cj/include/device_manager_ffi.h +++ b/interfaces/cj/include/device_manager_ffi.h @@ -36,12 +36,6 @@ typedef struct { int64_t size; } FfiDeviceBasicInfoArray; -typedef struct { - char *deviceId; - int32_t errCode; - char *errInfo; -} FfiErrInfo; - FFI_EXPORT int64_t FfiCreateDeviceManager(const char *name, int32_t *errCode); FFI_EXPORT void FfiRelaseDeviceManager(int64_t id, int32_t *errCode); -- Gitee From b3a1216ed5cf21a9bcdee28f352328022f6b14c7 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Tue, 5 Nov 2024 16:07:40 +0800 Subject: [PATCH 07/49] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=A9=BA=E8=A1=8C=E6=A0=BC=E5=BC=8F=E4=BB=A5=E5=8F=8A=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E6=8B=BC=E5=86=99=E9=97=AE=E9=A2=98,=20=E8=BF=99?= =?UTF-8?q?=E4=BA=9B=E6=8B=BC=E5=86=99=E9=97=AE=E9=A2=98=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=A3=B0=E6=98=8E=E5=92=8C=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E4=B8=8D=E4=B8=80=E8=87=B4,=20=E7=BC=96=E8=AF=91=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E9=80=9A=E8=BF=87=E4=BD=86=E5=87=BD=E6=95=B0=E4=B8=8D?= =?UTF-8?q?=E5=8F=AF=E8=A7=81.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I4c8a9a26557bd7be9853f37b441356adf92e1d96 --- interfaces/cj/include/device_manager_ffi.h | 16 +++------------- interfaces/cj/include/device_manager_impl.h | 2 +- interfaces/cj/include/device_manager_utils.h | 3 +-- interfaces/cj/src/device_manager_impl.cpp | 4 ---- interfaces/cj/src/device_manager_utils.cpp | 2 +- 5 files changed, 6 insertions(+), 21 deletions(-) diff --git a/interfaces/cj/include/device_manager_ffi.h b/interfaces/cj/include/device_manager_ffi.h index 2385daafe..fd011833d 100644 --- a/interfaces/cj/include/device_manager_ffi.h +++ b/interfaces/cj/include/device_manager_ffi.h @@ -18,11 +18,8 @@ #include "cj_common_ffi.h" #include "ffi_remote_data.h" -#ifdef __cplusplus -#if __plusplus + extern "C" { -#endif -#endif typedef struct { char *deviceId; @@ -38,9 +35,9 @@ typedef struct { FFI_EXPORT int64_t FfiCreateDeviceManager(const char *name, int32_t *errCode); -FFI_EXPORT void FfiRelaseDeviceManager(int64_t id, int32_t *errCode); +FFI_EXPORT void FfiReleaseDeviceManager(int64_t id, int32_t *errCode); -FFI_EXPORT void FfiGetAvailableDeviceList(int64_t id, FfiDeviceBasicInfoArray deviceInfoList, int32_t *errCode); +FFI_EXPORT void FfiGetAvailableDeviceList(int64_t id, FfiDeviceBasicInfoArray *deviceInfoList, int32_t *errCode); FFI_EXPORT void FfiFreeDeviceInfoList(FfiDeviceBasicInfoArray deviceInfoList); @@ -69,13 +66,6 @@ FFI_EXPORT void FfiOn(int64_t id, const char *type, void *callback, int32_t *err FFI_EXPORT void FfiOff(int64_t id, const char *type, int32_t *errCode); -#ifdef __cplusplus -#if __plusplus } -#endif -#endif - - #endif // OHOS_DEVICE_MANAGER_FFI_H - diff --git a/interfaces/cj/include/device_manager_impl.h b/interfaces/cj/include/device_manager_impl.h index b7f2c9fa6..b12657863 100644 --- a/interfaces/cj/include/device_manager_impl.h +++ b/interfaces/cj/include/device_manager_impl.h @@ -95,4 +95,4 @@ private: } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IMPL_H \ No newline at end of file +#endif // OHOS_DEVICE_MANAGER_IMPL_H diff --git a/interfaces/cj/include/device_manager_utils.h b/interfaces/cj/include/device_manager_utils.h index fa3328fb7..f5bc4e888 100644 --- a/interfaces/cj/include/device_manager_utils.h +++ b/interfaces/cj/include/device_manager_utils.h @@ -131,5 +131,4 @@ void InsertMapParames(nlohmann::json &bindParamObj, std::map(BIND_LEVEL, std::to_string(bindLevel))); } } -} // OHOS::DistributedHardware \ No newline at end of file +} // OHOS::DistributedHardware -- Gitee From 73ff95420ec846dc42413b8038f6b433f38592e6 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Wed, 6 Nov 2024 17:26:05 +0800 Subject: [PATCH 08/49] =?UTF-8?q?=E5=A2=9E=E5=8A=A0info=E4=BF=A1=E6=81=AF.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I3287b6ce35ddc34426cd812c63034273d874773a --- interfaces/cj/src/device_manager_ffi.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/cj/src/device_manager_ffi.cpp b/interfaces/cj/src/device_manager_ffi.cpp index afd8e17cd..d7697de83 100644 --- a/interfaces/cj/src/device_manager_ffi.cpp +++ b/interfaces/cj/src/device_manager_ffi.cpp @@ -26,6 +26,7 @@ int64_t FfiCreateDeviceManager(const char *name, int32_t *errCode) auto deviceManager = OHOS::FFI::FFIData::Create( std::string(name), errCode); if (!deviceManager || errCode) { + LOGI("deviceManager create fail."); delete static_cast(deviceManager); return 0; } -- Gitee From 57984dedf96595787fc22a9875edb7b9667b817c Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Thu, 7 Nov 2024 09:41:10 +0800 Subject: [PATCH 09/49] =?UTF-8?q?=E7=BB=8F=E4=B8=8E=E7=BB=88=E7=AB=AF?= =?UTF-8?q?=E6=B2=9F=E9=80=9A,=20=E7=A1=AE=E8=AE=A4serviceDie=E5=BA=9F?= =?UTF-8?q?=E5=BC=83.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ic96013b9b810053524244a93e85f0c3dd67c781c --- interfaces/cj/include/device_manager_impl.h | 2 -- interfaces/cj/src/device_manager_impl.cpp | 12 ------------ 2 files changed, 14 deletions(-) diff --git a/interfaces/cj/include/device_manager_impl.h b/interfaces/cj/include/device_manager_impl.h index b12657863..79dc8f5dd 100644 --- a/interfaces/cj/include/device_manager_impl.h +++ b/interfaces/cj/include/device_manager_impl.h @@ -56,7 +56,6 @@ public: void OnPublishResult(int32_t publishId, int32_t publishResult); void OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status, int32_t reason); void OnDmUiCall(const std::string ¶mJson); - void OnRemoteDied(); private: void ClearBundleCallbacks(); @@ -83,7 +82,6 @@ private: std::function discoverSuccessCallback; std::function deviceNameChangedCallback; std::function deviceDiscoverFailedCallback; - std::function deviceServiceDiedCallback; std::mutex callbackLock; std::condition_variable callbackFinishedCv; diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 740c790d7..b5a7e5cdc 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -53,7 +53,6 @@ const std::string DM_FFI_EVENT_DEVICE_DISCOVER_SUCCESS = "discoverSuccess"; const std::string DM_FFI_EVENT_DEVICE_DISCOVER_FAIL = "discoverFailure"; const std::string DM_FFI_EVENT_DEVICE_PUBLISH_SUCCESS = "publishSuccess"; const std::string DM_FFI_EVENT_DEVICE_PUBLISH_FAIL = "publishFailure"; -const std::string DM_FFI_EVENT_DEVICE_SERVICE_DIE = "serviceDie"; const std::string DEVICE_MANAGER_FFI_CLASS_NAME = "DeviceManager"; const std::string DM_FFI_EVENT_REPLY_RESULT = "replyResult"; const std::string DM_FFI_EVENT_DEVICE_NAME_CHANGE = "deviceNameChange"; @@ -508,13 +507,6 @@ void DeviceManagerFfiImpl::OnDmUiCall(const std::string ¶mJson) LOGI("OnCall for paramJson"); } -void DeviceManagerFfiImpl::OnRemoteDied() -{ - if (deviceServiceDiedCallback) { - deviceServiceDiedCallback(); - } -} - DeviceManagerFfiImpl *DeviceManagerFfiImpl::GetDeviceManagerFfi(std::string &bundleName) { std::lock_guard autoLock(g_deviceManagerMapMutex); @@ -746,8 +738,6 @@ void DeviceManagerFfiImpl::RegisterCallbackByType(const std::string &type, void deviceNameChangedCallback = CJLambda::Create(reinterpret_cast(callback)); } else if (type == DM_FFI_EVENT_DEVICE_DISCOVER_FAIL) { deviceDiscoverFailedCallback = CJLambda::Create(reinterpret_cast(callback)); - } else if (type == DM_FFI_EVENT_DEVICE_SERVICE_DIE) { - deviceServiceDiedCallback = CJLambda::Create(reinterpret_cast(callback)); } else { LOGE("RegisterCallbackByType call with wrong type."); } @@ -764,8 +754,6 @@ void DeviceManagerFfiImpl::Off(const std::string &type) deviceNameChangedCallback = nullptr; } else if (type == DM_FFI_EVENT_DEVICE_DISCOVER_FAIL) { deviceDiscoverFailedCallback = nullptr; - } else if (type == DM_FFI_EVENT_DEVICE_SERVICE_DIE) { - deviceServiceDiedCallback = nullptr; } else { LOGE("Off call with wrong type."); } -- Gitee From cad9f3994514c5fea92352f4fa0ca5c2a65f12d7 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Thu, 7 Nov 2024 09:51:28 +0800 Subject: [PATCH 10/49] bugfix. Change-Id: I625aa3dec60bd780b9476282309e2353ddfd1356 --- interfaces/cj/src/device_manager_utils.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/interfaces/cj/src/device_manager_utils.cpp b/interfaces/cj/src/device_manager_utils.cpp index 17ec6bd01..10927e63a 100644 --- a/interfaces/cj/src/device_manager_utils.cpp +++ b/interfaces/cj/src/device_manager_utils.cpp @@ -30,8 +30,6 @@ void DmFfiInitCallback::OnRemoteDied() DeviceManagerFfiImpl *deviceManagerFfi = DeviceManagerFfiImpl::GetDeviceManagerFfi(bundleName_); if (deviceManagerFfi == nullptr) { LOGE("OnRemoteDied, deviceManagerFfi not find for bundleName %{public}s", bundleName_.c_str()); - } else { - deviceManagerFfi->OnRemoteDied(); } LOGI("OnRemoteDied, deviceManagerFfi bundleName %{public}s", bundleName_.c_str()); } -- Gitee From e574dcaa931e9000a20ff048ad11a90c8fbaa879 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Thu, 7 Nov 2024 14:29:07 +0800 Subject: [PATCH 11/49] =?UTF-8?q?=E6=89=93log.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ia385ddb0cb330881840949ea925a2e19e1b39d34 --- interfaces/cj/src/device_manager_ffi.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interfaces/cj/src/device_manager_ffi.cpp b/interfaces/cj/src/device_manager_ffi.cpp index d7697de83..2b1ebd79c 100644 --- a/interfaces/cj/src/device_manager_ffi.cpp +++ b/interfaces/cj/src/device_manager_ffi.cpp @@ -26,10 +26,11 @@ int64_t FfiCreateDeviceManager(const char *name, int32_t *errCode) auto deviceManager = OHOS::FFI::FFIData::Create( std::string(name), errCode); if (!deviceManager || errCode) { - LOGI("deviceManager create fail."); + LOGE("deviceManager create fail, the errcode is %{public}d", errCode); delete static_cast(deviceManager); return 0; } + LOGI("deviceManager create successed, the ID is %{public}d", deviceManager->GetID()); return deviceManager->GetID(); } -- Gitee From ec9416390d1aaba585a3e6fca6b3117ce7f75af9 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Thu, 7 Nov 2024 14:56:23 +0800 Subject: [PATCH 12/49] bugfix. Change-Id: I81c2bbc3e39cf410fa10a9e36e5aed611da88297 --- interfaces/cj/src/device_manager_ffi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/cj/src/device_manager_ffi.cpp b/interfaces/cj/src/device_manager_ffi.cpp index 2b1ebd79c..7ec6c2bd5 100644 --- a/interfaces/cj/src/device_manager_ffi.cpp +++ b/interfaces/cj/src/device_manager_ffi.cpp @@ -26,7 +26,7 @@ int64_t FfiCreateDeviceManager(const char *name, int32_t *errCode) auto deviceManager = OHOS::FFI::FFIData::Create( std::string(name), errCode); if (!deviceManager || errCode) { - LOGE("deviceManager create fail, the errcode is %{public}d", errCode); + LOGE("deviceManager create fail, the errcode is %{public}d", *errCode); delete static_cast(deviceManager); return 0; } -- Gitee From 4c434b726f0200e83f46db4d9ca8d715048d1bd6 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Thu, 7 Nov 2024 15:06:40 +0800 Subject: [PATCH 13/49] bugfix. Change-Id: Id0659ee1ac50193a75691c279045d5949802fb1b --- interfaces/cj/src/device_manager_ffi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/cj/src/device_manager_ffi.cpp b/interfaces/cj/src/device_manager_ffi.cpp index 7ec6c2bd5..15133bb0e 100644 --- a/interfaces/cj/src/device_manager_ffi.cpp +++ b/interfaces/cj/src/device_manager_ffi.cpp @@ -30,7 +30,7 @@ int64_t FfiCreateDeviceManager(const char *name, int32_t *errCode) delete static_cast(deviceManager); return 0; } - LOGI("deviceManager create successed, the ID is %{public}d", deviceManager->GetID()); + LOGI("deviceManager create successed, the ID is %{public}ld", deviceManager->GetID()); return deviceManager->GetID(); } -- Gitee From 75e2ae50054bbe2aa5c1675c7834231e681453d7 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Thu, 7 Nov 2024 16:53:50 +0800 Subject: [PATCH 14/49] =?UTF-8?q?=E4=BF=AE=E6=94=B9build.gn=E4=B8=ADlog=5F?= =?UTF-8?q?domain.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I2e8349e6a751dde948f0e64c8fda6796d655cade --- interfaces/cj/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/cj/BUILD.gn b/interfaces/cj/BUILD.gn index e0a8f72be..30d83f97d 100644 --- a/interfaces/cj/BUILD.gn +++ b/interfaces/cj/BUILD.gn @@ -54,7 +54,7 @@ ohos_shared_library("cj_distributed_device_manager_ffi") { defines = [ "HI_LOG_ENABLE", "DH_LOG_TAG=\"cj_distrubuted_devicemanager\"", - "LOG_DOMAIN=0xD004110", + "LOG_DOMAIN=0xD004112", ] external_deps = [ -- Gitee From 7ec0e2d6fc33bc4b6cac8dcffda8d48cea335bf3 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Thu, 7 Nov 2024 17:09:25 +0800 Subject: [PATCH 15/49] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=88=A4=E6=96=AD,=20=E6=89=93=E4=B8=8D=E5=87=BALOG!!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Idcfb6587d143c9dcf41c10957f06f66a5ac4615f --- .vscode/settings.json | 66 ++++++++++++++++++++++++ interfaces/cj/BUILD.gn | 2 +- interfaces/cj/src/device_manager_ffi.cpp | 3 ++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..412d3d1e1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,66 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "cinttypes": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "ranges": "cpp", + "semaphore": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/interfaces/cj/BUILD.gn b/interfaces/cj/BUILD.gn index 30d83f97d..4835a76ff 100644 --- a/interfaces/cj/BUILD.gn +++ b/interfaces/cj/BUILD.gn @@ -54,7 +54,7 @@ ohos_shared_library("cj_distributed_device_manager_ffi") { defines = [ "HI_LOG_ENABLE", "DH_LOG_TAG=\"cj_distrubuted_devicemanager\"", - "LOG_DOMAIN=0xD004112", + "LOG_DOMAIN=0xD004111", ] external_deps = [ diff --git a/interfaces/cj/src/device_manager_ffi.cpp b/interfaces/cj/src/device_manager_ffi.cpp index 15133bb0e..3c84ea571 100644 --- a/interfaces/cj/src/device_manager_ffi.cpp +++ b/interfaces/cj/src/device_manager_ffi.cpp @@ -27,6 +27,9 @@ int64_t FfiCreateDeviceManager(const char *name, int32_t *errCode) std::string(name), errCode); if (!deviceManager || errCode) { LOGE("deviceManager create fail, the errcode is %{public}d", *errCode); + if (errCode == 0) { + errcode = 1231 + } delete static_cast(deviceManager); return 0; } -- Gitee From 6980df62d02fca91ef9135d950316f64698b1b82 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Thu, 7 Nov 2024 17:29:18 +0800 Subject: [PATCH 16/49] bugfix. Change-Id: I372efbcea757afbd9435c08b009d3fb3d3b1599e --- interfaces/cj/src/device_manager_ffi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/cj/src/device_manager_ffi.cpp b/interfaces/cj/src/device_manager_ffi.cpp index 3c84ea571..435803dca 100644 --- a/interfaces/cj/src/device_manager_ffi.cpp +++ b/interfaces/cj/src/device_manager_ffi.cpp @@ -28,7 +28,7 @@ int64_t FfiCreateDeviceManager(const char *name, int32_t *errCode) if (!deviceManager || errCode) { LOGE("deviceManager create fail, the errcode is %{public}d", *errCode); if (errCode == 0) { - errcode = 1231 + errcode = 1231; } delete static_cast(deviceManager); return 0; -- Gitee From 956d757d101d83540eb76835758daba22d7612b7 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Thu, 7 Nov 2024 19:09:54 +0800 Subject: [PATCH 17/49] =?UTF-8?q?=E4=BC=BC=E4=B9=8E=E6=89=BE=E5=88=B0?= =?UTF-8?q?=E4=BA=86=E9=97=AE=E9=A2=98,=20push!!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I1c6db185819aef9c42ea90babb222e1036447456 --- interfaces/cj/src/device_manager_ffi.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/interfaces/cj/src/device_manager_ffi.cpp b/interfaces/cj/src/device_manager_ffi.cpp index 435803dca..3717543c4 100644 --- a/interfaces/cj/src/device_manager_ffi.cpp +++ b/interfaces/cj/src/device_manager_ffi.cpp @@ -25,11 +25,8 @@ int64_t FfiCreateDeviceManager(const char *name, int32_t *errCode) { auto deviceManager = OHOS::FFI::FFIData::Create( std::string(name), errCode); - if (!deviceManager || errCode) { + if (!deviceManager || *errCode) { LOGE("deviceManager create fail, the errcode is %{public}d", *errCode); - if (errCode == 0) { - errcode = 1231; - } delete static_cast(deviceManager); return 0; } -- Gitee From ed0dff51e6fa66bff7c573026488070f66971fe2 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Thu, 7 Nov 2024 20:54:23 +0800 Subject: [PATCH 18/49] bugfix. Change-Id: I27ce3fbb22a7adcd3c5463e5a4e51270c87cc6c7 --- interfaces/cj/src/device_manager_ffi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/cj/src/device_manager_ffi.cpp b/interfaces/cj/src/device_manager_ffi.cpp index 3717543c4..e9ccda0c9 100644 --- a/interfaces/cj/src/device_manager_ffi.cpp +++ b/interfaces/cj/src/device_manager_ffi.cpp @@ -25,7 +25,7 @@ int64_t FfiCreateDeviceManager(const char *name, int32_t *errCode) { auto deviceManager = OHOS::FFI::FFIData::Create( std::string(name), errCode); - if (!deviceManager || *errCode) { + if (*errCode != 0) { LOGE("deviceManager create fail, the errcode is %{public}d", *errCode); delete static_cast(deviceManager); return 0; -- Gitee From e72999d4681ec315132137862bc7bf1ff5ffceb2 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Fri, 8 Nov 2024 11:22:08 +0800 Subject: [PATCH 19/49] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=E5=B9=B6=E5=AF=B9?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=8A=9F=E8=83=BD.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I71e1b4b86b1bce622e20fd1692fef2f6b5bfbe90 --- interfaces/cj/src/device_manager_impl.cpp | 84 ++++++++++++++++++++--- 1 file changed, 76 insertions(+), 8 deletions(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index b5a7e5cdc..fec6fdca9 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -78,13 +78,48 @@ enum ErrorCode { DM_ERR_PUBLISH_INVALID = 11600105, }; +inline int32_t stringCheck(const std::string &str) { + if (str.size() == 0 || str.size() >= 256) { + return ERR_INVALID_PARAMS; + } + return ERR_OK; +} + +inline int32_t transformErrCode(const int32_t errCode) { + switch (errCode) { + case ERR_DM_NO_PERMISSION: + return ERR_NO_PERMISSION + case ERR_DM_DISCOVERY_REPEATED: + return DM_ERR_DISCOVERY_INVALID; + case ERR_DM_PUBLISH_REPEATED: + return DM_ERR_PUBLISH_INVALID; + case ERR_DM_AUTH_BUSINESS_BUSY: + return DM_ERR_AUTHENTICALTION_INVALID; + case ERR_DM_INPUT_PARA_INVALID: + case ERR_DM_UNSUPPORTED_AUTH_TYPE: + return ERR_INVALID_PARAMS; + case ERR_DM_INIT_FAILED: + return DM_ERR_OBTAIN_SERVICE; + case ERR_NOT_SYSTEM_APP: + return ERR_NOT_SYSTEM_APP; + default: + return DM_ERR_FAILED; + } + return 0; +} } // namespace DeviceManagerFfiImpl::DeviceManagerFfiImpl(const std::string &bundleName, int32_t *errCode) : bundleName_(bundleName) { + *errCode = stringCheck(bundleName); + if (*errCode != 0) { + LOGE("CreateDeviceManager for bundleName %{public}s failed, ret %{public}d.", bundleName_.c_str(), *errCode); + return; + } std::shared_ptr initCallback = std::make_shared(bundleName_); - *errCode = DeviceManager::GetInstance().InitDeviceManager(bundleName_, initCallback); + *errCode = transformErrCode(DeviceManager::GetInstance().InitDeviceManager(bundleName_, initCallback)); if (*errCode != 0) { + *errCode = transformErrCode(*errCode); LOGE("CreateDeviceManager for bundleName %{public}s failed, ret %{public}d.", bundleName_.c_str(), *errCode); return; } @@ -100,6 +135,7 @@ DeviceManagerFfiImpl::DeviceManagerFfiImpl(const std::string &bundleName, int32_ int32_t DeviceManagerFfiImpl::ReleaseDeviceManager() { int ret = DeviceManager::GetInstance().UnInitDeviceManager(bundleName_); if (ret != 0) { + ret = transformErrCode(ret); LOGE("ReleaseDeviceManager for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); return ret; } @@ -111,11 +147,12 @@ int32_t DeviceManagerFfiImpl::GetAvailableDeviceList(FfiDeviceBasicInfoArray &de { int32_t ret = DeviceManager::GetInstance().CheckNewAPIAccessPermission(); if (ret != 0) { - return ret; + return transformErrCode(ret); } std::vector result; ret = DeviceManager::GetInstance().GetAvailableDeviceList(bundleName_, result); if (ret != 0) { + ret = transformErrCode(ret); LOGE("GetTrustedDeviceList for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); return ret; } @@ -182,6 +219,7 @@ int32_t DeviceManagerFfiImpl::GetLocalDeviceNetworkId(const char *&networkId) std::string result; int32_t ret = DeviceManager::GetInstance().GetLocalDeviceNetWorkId(bundleName_, result); if (ret != 0) { + ret = transformErrCode(ret); LOGE("GetLocalDeviceNetworkId for failed, ret %{public}d", ret); return ret; } @@ -203,6 +241,7 @@ int32_t DeviceManagerFfiImpl::GetLocalDeviceName(const char *&deviceName) std::string result; int32_t ret = DeviceManager::GetInstance().GetLocalDeviceName(bundleName_, result); if (ret != 0) { + ret = transformErrCode(ret); LOGE("GetLocalDeviceName for failed, ret %{public}d", ret); return ret; } @@ -223,6 +262,7 @@ int32_t DeviceManagerFfiImpl::GetLocalDeviceType(int32_t &deviceType) int32_t ret = DeviceManager::GetInstance().GetLocalDeviceType(bundleName_, deviceType); if (ret != 0) { + ret = transformErrCode(ret); LOGE("GetLocalDeviceType for failed, ret %{public}d", ret); return ret; } @@ -239,6 +279,7 @@ int32_t DeviceManagerFfiImpl::GetLocalDeviceId(const char *&deviceId) std::string result; int32_t ret = DeviceManager::GetInstance().GetLocalDeviceId(bundleName_, result); if (ret != 0) { + ret = transformErrCode(ret); LOGE("GetLocalDeviceId for failed, ret %{public}d", ret); return ret; } @@ -253,9 +294,14 @@ int32_t DeviceManagerFfiImpl::GetLocalDeviceId(const char *&deviceId) int32_t DeviceManagerFfiImpl::GetDeviceName(const std::string &networkId, const char *&deviceName) { + int32_t ret = stringCheck(networkId); + if (ret != 0) { + return ret; + } std::string result; - int32_t ret = DeviceManager::GetInstance().GetDeviceName(bundleName_, networkId, result); + ret = DeviceManager::GetInstance().GetDeviceName(bundleName_, networkId, result); if (ret != 0) { + ret = transformErrCode(ret); LOGE("GetDeviceName for failed, ret %{public}d", ret); return ret; } @@ -270,8 +316,13 @@ int32_t DeviceManagerFfiImpl::GetDeviceName(const std::string &networkId, const int32_t DeviceManagerFfiImpl::GetDeviceType(const std::string &networkId, int32_t &deviceType) { - int32_t ret = DeviceManager::GetInstance().GetDeviceType(bundleName_, networkId, deviceType); + int32_t ret = checkString(networkId); if (ret != 0) { + return ret; + } + ret = DeviceManager::GetInstance().GetDeviceType(bundleName_, networkId, deviceType); + if (ret != 0) { + ret = transformErrCode(ret); LOGE("GetDeviceType for failed, ret %{public}d", ret); return ret; } @@ -295,6 +346,7 @@ int32_t DeviceManagerFfiImpl::StartDiscovering(const std::string &extra) uint64_t tokenId = OHOS::IPCSkeleton::GetSelfTokenID(); int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(bundleName_, tokenId, extra, discoveryCallback); if (ret != 0) { + ret = transformErrCode(ret); LOGE("Discovery failed, bundleName %{public}s, ret %{public}d", bundleName_.c_str(), ret); discoveryCallback->OnDiscoveryFailed(static_cast(0), ret); return ret; @@ -307,6 +359,7 @@ int32_t DeviceManagerFfiImpl::StopDiscovering() uint64_t tokenId = OHOS::IPCSkeleton::GetSelfTokenID(); int32_t ret = DeviceManager::GetInstance().StopDeviceDiscovery(tokenId, bundleName_); if (ret != 0) { + ret = transformErrCode(ret); LOGE("StopDeviceDiscovery for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); return ret; } @@ -316,6 +369,11 @@ int32_t DeviceManagerFfiImpl::StopDiscovering() int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, const std::string &bindParam, const bool isMetaType) { + int32_t ret = checkString(deviceId); + if (ret != 0) { + return ret; + } + callbackFinished = false; if (isMetaType) { std::shared_ptr bindTargetCallback = nullptr; @@ -331,6 +389,7 @@ int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, } int32_t ret = BindTargetWarpper(deviceId, bindParam, bindTargetCallback); if (ret != 0) { + ret = transformErrCode(ret); LOGE("BindTarget for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); return ret; } @@ -349,9 +408,9 @@ int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, } } constexpr int32_t bindType = 1; - int32_t ret = DeviceManager::GetInstance().BindDevice( - bundleName_, bindType, deviceId, bindParam, bindDeviceCallback); + ret = DeviceManager::GetInstance().BindDevice(bundleName_, bindType, deviceId, bindParam, bindDeviceCallback); if (ret != 0) { + ret = transformErrCode(ret); LOGE("BindDevice for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); return ret; } @@ -367,9 +426,14 @@ int32_t DeviceManagerFfiImpl::WaitForCallbackCv() int32_t DeviceManagerFfiImpl::UnbindTarget(const std::string &deviceId) { + int32_t ret = checkString(deviceId); + if (ret != 0) { + return ret; + } LOGI("UnBindDevice deviceId = %{public}s", GetAnonyString(deviceId).c_str()); - int32_t ret = DeviceManager::GetInstance().UnBindDevice(bundleName_, deviceId); + ret = DeviceManager::GetInstance().UnBindDevice(bundleName_, deviceId); if (ret != 0) { + ret = transformErrCode(ret); LOGE("UnBindDevice for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); return ret; } @@ -380,7 +444,7 @@ int32_t DeviceManagerFfiImpl::EventOn(const std::string &type, void *callback) { int32_t ret = DeviceManager::GetInstance().CheckNewAPIAccessPermission(); if (ret != 0) { - return ret; + return transformErrCode(ret); } LOGI("On for bundleName %{public}s, eventType %{public}s ", bundleName_.c_str(), type.c_str()); @@ -595,6 +659,7 @@ int32_t DeviceManagerFfiImpl::RegisterDevStatusCallback() auto callback = std::make_shared(bundleName_); int32_t ret = DeviceManager::GetInstance().RegisterDevStatusCallback(bundleName_, "", callback); if (ret != 0) { + ret = transformErrCode(ret); LOGE("RegisterDevStatusCallback failed for bundleName %{public}s", bundleName_.c_str()); return ret; } @@ -632,6 +697,7 @@ int32_t DeviceManagerFfiImpl::RegisterReplyCallback() auto dmUiCallback = std::make_shared(bundleName_); int32_t ret = DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(bundleName_, dmUiCallback); if (ret != 0) { + ret = transformErrCode(ret); LOGE("RegisterDeviceManagerFaCallback failed for bundleName %{public}s", bundleName_.c_str()); return ret; } @@ -654,6 +720,7 @@ int32_t DeviceManagerFfiImpl::ReleaseDevStatusCallback() } int32_t ret = DeviceManager::GetInstance().UnRegisterDevStatusCallback(bundleName_); if (ret != 0) { + ret = transformErrCode(ret); LOGE("UnRegisterDevStatusCallback failed for bundleName %{public}s", bundleName_.c_str()); return ret; } @@ -716,6 +783,7 @@ int32_t DeviceManagerFfiImpl::ReleaseReplyCallback() } int32_t ret = DeviceManager::GetInstance().UnRegisterDeviceManagerFaCallback(bundleName_); if (ret != 0) { + ret = transformErrCode(ret); LOGE("UnRegisterDeviceManagerFaCallback failed for bundleName %{public}s", bundleName_.c_str()); return ret; } -- Gitee From 79b1ff9c9173a1fee2a9caef7a617a56190f99be Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Fri, 8 Nov 2024 11:33:16 +0800 Subject: [PATCH 20/49] bugfix. Change-Id: I0273c2c8c3f8e0b30356e600930805667e8c3971 --- interfaces/cj/src/device_manager_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index fec6fdca9..def4ffce0 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -88,7 +88,7 @@ inline int32_t stringCheck(const std::string &str) { inline int32_t transformErrCode(const int32_t errCode) { switch (errCode) { case ERR_DM_NO_PERMISSION: - return ERR_NO_PERMISSION + return ERR_NO_PERMISSION; case ERR_DM_DISCOVERY_REPEATED: return DM_ERR_DISCOVERY_INVALID; case ERR_DM_PUBLISH_REPEATED: -- Gitee From 82d2aec8754ebc34024245b3c0114adaf20d00ec Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Fri, 8 Nov 2024 11:37:30 +0800 Subject: [PATCH 21/49] bugfix. Change-Id: I18088b6142ada74652ae928d420cc9b1c4a47622 --- interfaces/cj/src/device_manager_impl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index def4ffce0..575514bb5 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -316,7 +316,7 @@ int32_t DeviceManagerFfiImpl::GetDeviceName(const std::string &networkId, const int32_t DeviceManagerFfiImpl::GetDeviceType(const std::string &networkId, int32_t &deviceType) { - int32_t ret = checkString(networkId); + int32_t ret = stringCheck(networkId); if (ret != 0) { return ret; } @@ -369,7 +369,7 @@ int32_t DeviceManagerFfiImpl::StopDiscovering() int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, const std::string &bindParam, const bool isMetaType) { - int32_t ret = checkString(deviceId); + int32_t ret = stringCheck(deviceId); if (ret != 0) { return ret; } @@ -426,7 +426,7 @@ int32_t DeviceManagerFfiImpl::WaitForCallbackCv() int32_t DeviceManagerFfiImpl::UnbindTarget(const std::string &deviceId) { - int32_t ret = checkString(deviceId); + int32_t ret = stringCheck(deviceId); if (ret != 0) { return ret; } -- Gitee From 1c4d7dcaf3e1cb9a7becf550e7961544636e93b0 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Fri, 8 Nov 2024 11:52:25 +0800 Subject: [PATCH 22/49] bugfix. Change-Id: I1ef158f12d6772538fc32602243666ba88b0d411 --- interfaces/cj/src/device_manager_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 575514bb5..6346932b9 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -117,7 +117,7 @@ DeviceManagerFfiImpl::DeviceManagerFfiImpl(const std::string &bundleName, int32_ return; } std::shared_ptr initCallback = std::make_shared(bundleName_); - *errCode = transformErrCode(DeviceManager::GetInstance().InitDeviceManager(bundleName_, initCallback)); + *errCode = DeviceManager::GetInstance().InitDeviceManager(bundleName_, initCallback); if (*errCode != 0) { *errCode = transformErrCode(*errCode); LOGE("CreateDeviceManager for bundleName %{public}s failed, ret %{public}d.", bundleName_.c_str(), *errCode); -- Gitee From 4c6bd7f6ea542ee42fd8bc051827ecffc83dca6b Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sat, 9 Nov 2024 10:09:32 +0800 Subject: [PATCH 23/49] bugfix. Change-Id: I4cda932200b66263d79b1bf6790145e7bbddde14 --- interfaces/cj/src/device_manager_impl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 6346932b9..e40a19287 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -453,11 +453,11 @@ int32_t DeviceManagerFfiImpl::EventOn(const std::string &type, void *callback) if (type == DM_FFI_EVENT_DEVICE_STATE_CHANGE || type == DM_FFI_EVENT_DEVICE_NAME_CHANGE) { return RegisterDevStatusCallback(); } else if (type == DM_FFI_EVENT_DEVICE_DISCOVER_SUCCESS || type == DM_FFI_EVENT_DEVICE_DISCOVER_FAIL) { - RegisterDiscoveryCallback(); + return RegisterDiscoveryCallback(); } else if (type == DM_FFI_EVENT_DEVICE_PUBLISH_SUCCESS || type == DM_FFI_EVENT_DEVICE_PUBLISH_FAIL) { - RegisterPublishCallback(); + return RegisterPublishCallback(); } else if (type == DM_FFI_EVENT_REPLY_RESULT) { - RegisterReplyCallback(); + return RegisterReplyCallback(); } return ERR_INVALID_PARAMS; -- Gitee From 1d916890b9e81004b26d9314d6029555f27afbbb Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sat, 9 Nov 2024 10:37:29 +0800 Subject: [PATCH 24/49] =?UTF-8?q?bugfix=E4=BB=A5=E5=8F=8A=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=B1=BB=E5=9E=8B=E6=94=B9=E5=8F=98.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: If8e7baefb30a0128d25fb0a57962801bdabed754 --- interfaces/cj/include/device_manager_ffi.h | 2 +- interfaces/cj/src/device_manager_impl.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/cj/include/device_manager_ffi.h b/interfaces/cj/include/device_manager_ffi.h index fd011833d..7ff264a26 100644 --- a/interfaces/cj/include/device_manager_ffi.h +++ b/interfaces/cj/include/device_manager_ffi.h @@ -24,7 +24,7 @@ extern "C" { typedef struct { char *deviceId; char *deviceName; - char *deviceType; + uint16_t deviceType; char *networkId; } FfiDeviceBasicInfo; diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index e40a19287..b1103b597 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -197,7 +197,7 @@ int32_t DeviceManagerFfiImpl::Transform2FfiDeviceBasicInfo(const DmDeviceBasicIn { out.deviceId = MallocCStr(in.deviceId); out.deviceName = MallocCStr(in.deviceName); - out.deviceType = MallocCStr(GetDeviceTypeById(static_cast(in.deviceTypeId)).c_str()); + out.deviceType = in.deviceTypeId; out.networkId = MallocCStr(in.networkId); if (out.deviceId == nullptr || out.deviceName == nullptr || out.deviceType == nullptr || out.networkId == nullptr) { -- Gitee From d584392ca34fe2cf05c449b8108f1b726f9bd4e2 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sat, 9 Nov 2024 10:48:36 +0800 Subject: [PATCH 25/49] =?UTF-8?q?bugfix=E5=B9=B6=E5=B0=81=E8=A3=85?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=B7=A5=E5=85=B7=E5=87=BD=E6=95=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I5a86351625467f3ebb5838aa0e477ba57c3fbc38 --- interfaces/cj/include/device_manager_impl.h | 6 ++++++ interfaces/cj/src/device_manager_impl.cpp | 23 +++++---------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/interfaces/cj/include/device_manager_impl.h b/interfaces/cj/include/device_manager_impl.h index 79dc8f5dd..6d59bf83a 100644 --- a/interfaces/cj/include/device_manager_impl.h +++ b/interfaces/cj/include/device_manager_impl.h @@ -77,6 +77,12 @@ private: void RegisterCallbackByType(const std::string &type, void *callback); void Off(const std::string &type); + inline static void FreeDeviceInfo(const FfiDeviceBasicInfo &info) { + free(info.deviceId); + free(info.deviceName); + free(info.networkId); + }; + std::string bundleName_; std::function deviceStateChangedCallback; std::function discoverSuccessCallback; diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index b1103b597..2e15f37dd 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -183,10 +183,7 @@ void DeviceManagerFfiImpl::DeviceListFree(FfiDeviceBasicInfoArray &deviceInfoLis size = deviceInfoList.size; } for (int32_t i = 0; i < size; ++i) { - free(deviceInfoList.head[i].deviceId); - free(deviceInfoList.head[i].deviceName); - free(deviceInfoList.head[i].deviceType); - free(deviceInfoList.head[i].networkId); + free(deviceInfoList.head[i]); } free(deviceInfoList.head); deviceInfoList.head = nullptr; @@ -199,12 +196,8 @@ int32_t DeviceManagerFfiImpl::Transform2FfiDeviceBasicInfo(const DmDeviceBasicIn out.deviceName = MallocCStr(in.deviceName); out.deviceType = in.deviceTypeId; out.networkId = MallocCStr(in.networkId); - if (out.deviceId == nullptr || out.deviceName == nullptr || - out.deviceType == nullptr || out.networkId == nullptr) { - free(out.deviceId); - free(out.deviceName); - free(out.deviceType); - free(out.networkId); + if (out.deviceId == nullptr || out.deviceName == nullptr || out.networkId == nullptr) { + FreeDeviceInfo(out); return DM_ERR_FAILED; } return ERR_OK; @@ -499,10 +492,7 @@ void DeviceManagerFfiImpl::OnDeviceStatusChange(int32_t action, const DmDeviceBa return; } deviceStateChangedCallback(action, ptr); - free(ptr->deviceId); - free(ptr->deviceName); - free(ptr->deviceType); - free(ptr->networkId); + FreeDeviceInfo(ptr); free(ptr); } } @@ -521,10 +511,7 @@ void DeviceManagerFfiImpl::OnDeviceFound(uint16_t subscribeId, const DmDeviceBas return; } discoverSuccessCallback(ptr); - free(ptr->deviceId); - free(ptr->deviceName); - free(ptr->deviceType); - free(ptr->networkId); + FreeDeviceInfo(ptr); free(ptr); } } -- Gitee From a496fb4914a6c3ddf95e5b4627795ddf777d9a05 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sat, 9 Nov 2024 10:50:09 +0800 Subject: [PATCH 26/49] bugfix. Change-Id: Iccb1c0be5599a8891b0dd50ec9e434226ebe316d --- interfaces/cj/src/device_manager_impl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 2e15f37dd..0ab2c1c32 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -492,7 +492,7 @@ void DeviceManagerFfiImpl::OnDeviceStatusChange(int32_t action, const DmDeviceBa return; } deviceStateChangedCallback(action, ptr); - FreeDeviceInfo(ptr); + FreeDeviceInfo(*ptr); free(ptr); } } @@ -511,7 +511,7 @@ void DeviceManagerFfiImpl::OnDeviceFound(uint16_t subscribeId, const DmDeviceBas return; } discoverSuccessCallback(ptr); - FreeDeviceInfo(ptr); + FreeDeviceInfo(*ptr); free(ptr); } } -- Gitee From 5c18a7342d506c445d8424636c7f2e192dd74fea Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sat, 9 Nov 2024 10:52:21 +0800 Subject: [PATCH 27/49] bugfix. Change-Id: Ic15b4f72aad662e9e7b00902069c736eb2789771 --- interfaces/cj/src/device_manager_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 0ab2c1c32..16e1acbee 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -183,7 +183,7 @@ void DeviceManagerFfiImpl::DeviceListFree(FfiDeviceBasicInfoArray &deviceInfoLis size = deviceInfoList.size; } for (int32_t i = 0; i < size; ++i) { - free(deviceInfoList.head[i]); + free(*(deviceInfoList.head[i])); } free(deviceInfoList.head); deviceInfoList.head = nullptr; -- Gitee From a28c63462fa9f19167c786ad525452218aedc8b0 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sat, 9 Nov 2024 10:53:39 +0800 Subject: [PATCH 28/49] bugfix. Change-Id: I7d419abe824ab05401a2bb3b07c8a7c6c3398c85 --- interfaces/cj/src/device_manager_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 16e1acbee..30e5c176a 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -183,7 +183,7 @@ void DeviceManagerFfiImpl::DeviceListFree(FfiDeviceBasicInfoArray &deviceInfoLis size = deviceInfoList.size; } for (int32_t i = 0; i < size; ++i) { - free(*(deviceInfoList.head[i])); + FreeDeviceInfo(*(deviceInfoList.head[i])); } free(deviceInfoList.head); deviceInfoList.head = nullptr; -- Gitee From bf6f4b7e7e174a1dad636a234da6b49d2b906912 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sat, 9 Nov 2024 10:54:57 +0800 Subject: [PATCH 29/49] bugfix. Change-Id: Ic172e1285e0d6142d13df8dcd864eeccf29bbb59 --- interfaces/cj/src/device_manager_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 30e5c176a..0505e011d 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -183,7 +183,7 @@ void DeviceManagerFfiImpl::DeviceListFree(FfiDeviceBasicInfoArray &deviceInfoLis size = deviceInfoList.size; } for (int32_t i = 0; i < size; ++i) { - FreeDeviceInfo(*(deviceInfoList.head[i])); + FreeDeviceInfo(deviceInfoList.head[i]); } free(deviceInfoList.head); deviceInfoList.head = nullptr; -- Gitee From b94f908193583e24265bf845cada919f0affaf7d Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sat, 9 Nov 2024 17:25:18 +0800 Subject: [PATCH 30/49] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=80=BB=E8=BE=91,=20d?= =?UTF-8?q?eviceNameChange=E6=89=BE=E5=88=B0=E5=AF=B9=E5=BA=94=E5=85=A5?= =?UTF-8?q?=E5=8F=A3,=20napi=E5=B1=82=E5=AE=9E=E7=8E=B0=E6=9C=89=E9=97=AE?= =?UTF-8?q?=E9=A2=98.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iac306d0466296d14c2d25646145235e35def1f6c --- interfaces/cj/include/device_manager_impl.h | 1 + interfaces/cj/src/device_manager_impl.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/interfaces/cj/include/device_manager_impl.h b/interfaces/cj/include/device_manager_impl.h index 6d59bf83a..cf58c0ac4 100644 --- a/interfaces/cj/include/device_manager_impl.h +++ b/interfaces/cj/include/device_manager_impl.h @@ -51,6 +51,7 @@ public: int32_t EventOff(const std::string &type); void OnDeviceStatusChange(int32_t action, const DmDeviceBasicInfo &deviceBasicInfo); + void OnDeviceNameChange(const std::string &deviceName); void OnDeviceFound(uint16_t subscribeId, const DmDeviceBasicInfo &deviceBasicInfo); void OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason); void OnPublishResult(int32_t publishId, int32_t publishResult); diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 0505e011d..f46d1e7f6 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -485,6 +485,7 @@ void DeviceManagerFfiImpl::OnDeviceStatusChange(int32_t action, const DmDeviceBa auto ptr = static_cast(malloc(sizeof(FfiDeviceBasicInfo))); if (ptr == nullptr) { LOGE("OnDeviceStatusChange malloc FfiDeviceBasicInfo failed."); + return; } int32_t ret = Transform2FfiDeviceBasicInfo(deviceBasicInfo, *ptr); if (ret != 0) { @@ -497,6 +498,19 @@ void DeviceManagerFfiImpl::OnDeviceStatusChange(int32_t action, const DmDeviceBa } } +void DeviceManagerFfiImpl::OnDeviceNameChange(const std::string &deviceName) { + std::lock_guard autoLock(callbackLock); + if (deviceNameChangedCallback) { + cDeviceName = MallocCString(deviceName); + if (cDeviceName == nullptr) { + LOGE("OnDeviceNameChange malloc deviname failed.") + return; + } + deviceNameChangedCallback(cDeviceName); + free(cDeviceName) + } +} + void DeviceManagerFfiImpl::OnDeviceFound(uint16_t subscribeId, const DmDeviceBasicInfo &deviceBasicInfo) { std::lock_guard autoLock(callbackLock); @@ -504,6 +518,7 @@ void DeviceManagerFfiImpl::OnDeviceFound(uint16_t subscribeId, const DmDeviceBas auto ptr = static_cast(malloc(sizeof(FfiDeviceBasicInfo))); if (ptr == nullptr) { LOGE("OnDeviceStatusChange malloc FfiDeviceBasicInfo failed."); + return; } int32_t ret = Transform2FfiDeviceBasicInfo(deviceBasicInfo, *ptr); if (ret != 0) { -- Gitee From 7cd5f77c8302d382f91b0911b41f95133e06486c Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sat, 9 Nov 2024 17:29:38 +0800 Subject: [PATCH 31/49] bugfix. Change-Id: Ia7d1de9502eee3d1bbf40011cfe87fd71a7dad47 --- interfaces/cj/src/device_manager_impl.cpp | 2 +- interfaces/cj/src/device_manager_utils.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index f46d1e7f6..9250324ca 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -501,7 +501,7 @@ void DeviceManagerFfiImpl::OnDeviceStatusChange(int32_t action, const DmDeviceBa void DeviceManagerFfiImpl::OnDeviceNameChange(const std::string &deviceName) { std::lock_guard autoLock(callbackLock); if (deviceNameChangedCallback) { - cDeviceName = MallocCString(deviceName); + const char *cDeviceName = MallocCStr(deviceName.c_str()); if (cDeviceName == nullptr) { LOGE("OnDeviceNameChange malloc deviname failed.") return; diff --git a/interfaces/cj/src/device_manager_utils.cpp b/interfaces/cj/src/device_manager_utils.cpp index 10927e63a..cf3a8f5ba 100644 --- a/interfaces/cj/src/device_manager_utils.cpp +++ b/interfaces/cj/src/device_manager_utils.cpp @@ -70,7 +70,7 @@ void DmFfiDeviceStatusCallback::OnDeviceChanged(const DmDeviceBasicInfo &deviceB if (deviceManagerFfi == nullptr) { LOGE("OnDeviceChanged, deviceManagerFfi not find for bundleName %{public}s", bundleName_.c_str()); } else { - deviceManagerFfi->OnDeviceStatusChange(DmFfiDevStatusChange::CHANGE, deviceBasicInfo); + deviceManagerFfi->OnDeviceNameChange(deviceBasicInfo.deviceName); } } -- Gitee From 1c0c10c5b922684306600e5684d7c01f292365d0 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sat, 9 Nov 2024 17:30:50 +0800 Subject: [PATCH 32/49] bugfix. Change-Id: I3a0f5edd66756daab36da212178b041852ea5052 --- interfaces/cj/src/device_manager_impl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 9250324ca..39eb73fe4 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -503,11 +503,11 @@ void DeviceManagerFfiImpl::OnDeviceNameChange(const std::string &deviceName) { if (deviceNameChangedCallback) { const char *cDeviceName = MallocCStr(deviceName.c_str()); if (cDeviceName == nullptr) { - LOGE("OnDeviceNameChange malloc deviname failed.") + LOGE("OnDeviceNameChange malloc deviname failed."); return; } deviceNameChangedCallback(cDeviceName); - free(cDeviceName) + free(cDeviceName); } } -- Gitee From 2b1226956b044f18c9ccbc30641ace42e6f60015 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sun, 10 Nov 2024 16:09:57 +0800 Subject: [PATCH 33/49] bugfix. Change-Id: Ib95a8eadfddf81021ed8d5d81aeafb030d559010 --- interfaces/cj/src/device_manager_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 39eb73fe4..58d3e9e80 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -501,7 +501,7 @@ void DeviceManagerFfiImpl::OnDeviceStatusChange(int32_t action, const DmDeviceBa void DeviceManagerFfiImpl::OnDeviceNameChange(const std::string &deviceName) { std::lock_guard autoLock(callbackLock); if (deviceNameChangedCallback) { - const char *cDeviceName = MallocCStr(deviceName.c_str()); + char *cDeviceName = MallocCStr(deviceName.c_str()); if (cDeviceName == nullptr) { LOGE("OnDeviceNameChange malloc deviname failed."); return; -- Gitee From b2cf826c00e2d8ac2525bebb51306aa53539335f Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sun, 10 Nov 2024 21:23:33 +0800 Subject: [PATCH 34/49] =?UTF-8?q?=E6=89=93log.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iae1de3296ee30aeac57aa49c854020e8e2936f93 --- interfaces/cj/src/device_manager_impl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 58d3e9e80..5ae605cbe 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -293,6 +293,7 @@ int32_t DeviceManagerFfiImpl::GetDeviceName(const std::string &networkId, const } std::string result; ret = DeviceManager::GetInstance().GetDeviceName(bundleName_, networkId, result); + LOGI("DeviceManager::GetDeviceName getinstance return.") if (ret != 0) { ret = transformErrCode(ret); LOGE("GetDeviceName for failed, ret %{public}d", ret); -- Gitee From fdeb93a83a879556b036a7c7cb90f2d27ae50f33 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sun, 10 Nov 2024 21:24:49 +0800 Subject: [PATCH 35/49] bugfix. Change-Id: I144a9b35a3c69755e7db206c965b96d7f33341f9 --- interfaces/cj/src/device_manager_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 5ae605cbe..0044a56d5 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -293,7 +293,7 @@ int32_t DeviceManagerFfiImpl::GetDeviceName(const std::string &networkId, const } std::string result; ret = DeviceManager::GetInstance().GetDeviceName(bundleName_, networkId, result); - LOGI("DeviceManager::GetDeviceName getinstance return.") + LOGI("DeviceManager::GetDeviceName getinstance return."); if (ret != 0) { ret = transformErrCode(ret); LOGE("GetDeviceName for failed, ret %{public}d", ret); -- Gitee From a15da87d288c102ed8a782dae889b8dde889e912 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Sun, 10 Nov 2024 21:30:37 +0800 Subject: [PATCH 36/49] bugfix. Change-Id: I140673e8527fa537508c35c5327f7eb5b4252c56 --- interfaces/cj/src/device_manager_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 0044a56d5..0a00b8b9d 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -299,7 +299,7 @@ int32_t DeviceManagerFfiImpl::GetDeviceName(const std::string &networkId, const LOGE("GetDeviceName for failed, ret %{public}d", ret); return ret; } - LOGI("DeviceManager::GetDeviceName deviceName:%{public}s", GetAnonyString(deviceName).c_str()); + LOGI("DeviceManager::GetDeviceName deviceName:%{public}s", GetAnonyString(result).c_str()); deviceName = MallocCStr(result.c_str()); if (deviceName == nullptr) { -- Gitee From 2e7321be78ba8de4e3d8e16ef0c4e28beaae1b93 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Mon, 11 Nov 2024 11:39:26 +0800 Subject: [PATCH 37/49] =?UTF-8?q?=E6=89=93=E6=97=A5=E5=BF=97,=20=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E6=98=AF=E5=90=A6=E6=AD=A4=E6=AD=A5=E5=87=BA=E9=94=99?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ibcbb4119938d332010d1934bea69c80169392933 --- services/service/src/softbus/softbus_listener.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index a945c24bf..62b8b4309 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -1080,6 +1080,7 @@ int32_t SoftbusListener::GetIPAddrTypeFromCache(const std::string &deviceId, con } } } + LOGE("!!!!!GetTargetInfoFromCache failed, cannot found deviceVectorIter in cached discovered map."); return ERR_DM_BIND_INPUT_PARA_INVALID; } -- Gitee From cec067d1960e9d6122870bf73195826f3ebdac2d Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Mon, 11 Nov 2024 15:00:40 +0800 Subject: [PATCH 38/49] =?UTF-8?q?=E6=89=93log.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ie784250039f93fd77af4841778955d76965a9f6b --- interfaces/cj/src/device_manager_impl.cpp | 3 +++ interfaces/kits/js4.0/src/native_devicemanager_js.cpp | 4 ++++ services/service/src/softbus/softbus_listener.cpp | 1 - 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 0a00b8b9d..a1aac9d28 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -363,10 +363,12 @@ int32_t DeviceManagerFfiImpl::StopDiscovering() int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, const std::string &bindParam, const bool isMetaType) { + LOGI("BindTarget in."); int32_t ret = stringCheck(deviceId); if (ret != 0) { return ret; } + LOGI("checkstring success."); callbackFinished = false; if (isMetaType) { @@ -387,6 +389,7 @@ int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, LOGE("BindTarget for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); return ret; } + LOGI("register success.") return WaitForCallbackCv(); } diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index 72d024acc..06f2c4465 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -1567,6 +1567,10 @@ void DeviceManagerNapi::BindDevOrTarget(DeviceManagerNapi *deviceManagerWrapper, std::string bindParam; bool isMetaType = false; JsToBindParam(env, object, bindParam, authAsyncCallbackInfo_.authType, isMetaType); + LOGI("the bindParam is %{public}s", bindParam.c_str()); + LOGI("the isMetaType is %{public}d", isMetaType); + LOGI("the deviceId is %{public}s", deviceId.c_str()); + LOGI("the auth type is %{public}d", authAsyncCallbackInfo_.authType); if (isMetaType) { std::shared_ptr bindTargetCallback = nullptr; diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index 62b8b4309..a945c24bf 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -1080,7 +1080,6 @@ int32_t SoftbusListener::GetIPAddrTypeFromCache(const std::string &deviceId, con } } } - LOGE("!!!!!GetTargetInfoFromCache failed, cannot found deviceVectorIter in cached discovered map."); return ERR_DM_BIND_INPUT_PARA_INVALID; } -- Gitee From d4c5eadff4310b6b2f2c5904082c233c5710a6d5 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Mon, 11 Nov 2024 15:02:12 +0800 Subject: [PATCH 39/49] bugfix. Change-Id: I8e85290379f2e62f54990b6ae78f4d7973855942 --- interfaces/cj/src/device_manager_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index a1aac9d28..022144fa6 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -389,7 +389,7 @@ int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, LOGE("BindTarget for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); return ret; } - LOGI("register success.") + LOGI("register success."); return WaitForCallbackCv(); } -- Gitee From 172bca4d0ce1f3c4a85f0e13ade5a6d765570db4 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Mon, 11 Nov 2024 17:16:17 +0800 Subject: [PATCH 40/49] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=89=B4=E6=9D=83.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I671747b8b718eea86542ba501223542da0e70bfe --- interfaces/cj/src/device_manager_impl.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 022144fa6..638b73a20 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -326,6 +326,9 @@ int32_t DeviceManagerFfiImpl::GetDeviceType(const std::string &networkId, int32_ int32_t DeviceManagerFfiImpl::StartDiscovering(const std::string &extra) { + if (DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + return ERR_NO_PERMISSION; + } std::shared_ptr discoveryCallback = nullptr; { std::lock_guard autoLock(g_discoveryCallbackMapMutex); @@ -350,6 +353,9 @@ int32_t DeviceManagerFfiImpl::StartDiscovering(const std::string &extra) int32_t DeviceManagerFfiImpl::StopDiscovering() { + if (DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + return ERR_NO_PERMISSION; + } uint64_t tokenId = OHOS::IPCSkeleton::GetSelfTokenID(); int32_t ret = DeviceManager::GetInstance().StopDeviceDiscovery(tokenId, bundleName_); if (ret != 0) { @@ -364,6 +370,9 @@ int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, const std::string &bindParam, const bool isMetaType) { LOGI("BindTarget in."); + if (DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + return ERR_NO_PERMISSION; + } int32_t ret = stringCheck(deviceId); if (ret != 0) { return ret; @@ -423,6 +432,9 @@ int32_t DeviceManagerFfiImpl::WaitForCallbackCv() int32_t DeviceManagerFfiImpl::UnbindTarget(const std::string &deviceId) { + if (DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + return ERR_NO_PERMISSION; + } int32_t ret = stringCheck(deviceId); if (ret != 0) { return ret; -- Gitee From d4d1a695ed6cc56b305e2af21d046a6915a17ed2 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Mon, 11 Nov 2024 17:21:23 +0800 Subject: [PATCH 41/49] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=89=B4=E6=9D=83.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: If65ad668ee944fd728f9a45a0a32aa0974699634 --- interfaces/cj/src/device_manager_impl.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 638b73a20..deb71e09b 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -133,6 +133,9 @@ DeviceManagerFfiImpl::DeviceManagerFfiImpl(const std::string &bundleName, int32_ } int32_t DeviceManagerFfiImpl::ReleaseDeviceManager() { + if (DeviceManager::GetInstance().CheckNewAPIAccessPermission() != 0) { + return ERR_NO_PERMISSION; + } int ret = DeviceManager::GetInstance().UnInitDeviceManager(bundleName_); if (ret != 0) { ret = transformErrCode(ret); -- Gitee From 7346f12d4b1fde6c30a7c2fbd40464634e5a60f4 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Mon, 11 Nov 2024 18:44:48 +0800 Subject: [PATCH 42/49] =?UTF-8?q?=E9=98=B2=E6=AD=A2=E5=A4=9A=E4=B8=AAon?= =?UTF-8?q?=E6=97=B6=E5=8D=95=E4=B8=AAoff=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E7=B1=BB=E8=A7=A3=E6=B3=A8=E5=86=8C.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iee7a8936f11245d48ffdc745129d961aa332d1b2 --- interfaces/cj/src/device_manager_impl.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index deb71e09b..687182b0e 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -466,10 +466,6 @@ int32_t DeviceManagerFfiImpl::EventOn(const std::string &type, void *callback) return RegisterDevStatusCallback(); } else if (type == DM_FFI_EVENT_DEVICE_DISCOVER_SUCCESS || type == DM_FFI_EVENT_DEVICE_DISCOVER_FAIL) { return RegisterDiscoveryCallback(); - } else if (type == DM_FFI_EVENT_DEVICE_PUBLISH_SUCCESS || type == DM_FFI_EVENT_DEVICE_PUBLISH_FAIL) { - return RegisterPublishCallback(); - } else if (type == DM_FFI_EVENT_REPLY_RESULT) { - return RegisterReplyCallback(); } return ERR_INVALID_PARAMS; @@ -484,14 +480,10 @@ int32_t DeviceManagerFfiImpl::EventOff(const std::string &type) LOGI("JsOff for bundleName %{public}s, eventType %{public}s ", bundleName_.c_str(), type.c_str()); Off(type); - if (type == DM_FFI_EVENT_DEVICE_STATE_CHANGE || type == DM_FFI_EVENT_DEVICE_NAME_CHANGE) { + if (!deviceStateChangedCallback && !deviceNameChangedCallback) { return ReleaseDevStatusCallback(); - } else if (type == DM_FFI_EVENT_DEVICE_DISCOVER_SUCCESS || type == DM_FFI_EVENT_DEVICE_DISCOVER_FAIL) { + } else if (!discoverSuccessCallback && !deviceDiscoverFailedCallback) { return ReleaseDiscoveryCallback(); - } else if (type == DM_FFI_EVENT_DEVICE_PUBLISH_SUCCESS || type == DM_FFI_EVENT_DEVICE_PUBLISH_FAIL) { - return ReleasePublishCallback(); - } else if (type == DM_FFI_EVENT_REPLY_RESULT) { - return ReleaseReplyCallback(); } return ERR_INVALID_PARAMS; } -- Gitee From 70efdce43a24117174b08888980946c864ec0202 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Mon, 11 Nov 2024 20:21:16 +0800 Subject: [PATCH 43/49] bugfix, Change-Id: Ic2ba00650c23bb0eeaec31fd130573c54eb1a09a --- interfaces/cj/src/device_manager_impl.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 687182b0e..a366b1a8a 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -480,10 +480,14 @@ int32_t DeviceManagerFfiImpl::EventOff(const std::string &type) LOGI("JsOff for bundleName %{public}s, eventType %{public}s ", bundleName_.c_str(), type.c_str()); Off(type); - if (!deviceStateChangedCallback && !deviceNameChangedCallback) { - return ReleaseDevStatusCallback(); - } else if (!discoverSuccessCallback && !deviceDiscoverFailedCallback) { - return ReleaseDiscoveryCallback(); + if (type == DM_FFI_EVENT_DEVICE_STATE_CHANGE || type == DM_FFI_EVENT_DEVICE_NAME_CHANGE) { + if (!deviceStateChangedCallback && !deviceNameChangedCallback) { + return ReleaseDevStatusCallback(); + } + } else if (type == DM_FFI_EVENT_DEVICE_DISCOVER_SUCCESS || type == DM_FFI_EVENT_DEVICE_DISCOVER_FAIL) { + if (!discoverSuccessCallback && !deviceDiscoverFailedCallback) { + return ReleaseDiscoveryCallback(); + } } return ERR_INVALID_PARAMS; } -- Gitee From 1f10de5eb07ad04ba94a695db42c6e25a34148cb Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Mon, 11 Nov 2024 20:28:44 +0800 Subject: [PATCH 44/49] bugfix. Change-Id: I22e23b950a424cd5d85bf3340f7e5abf05389b79 --- interfaces/cj/src/device_manager_impl.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index a366b1a8a..1d0942add 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -485,9 +485,7 @@ int32_t DeviceManagerFfiImpl::EventOff(const std::string &type) return ReleaseDevStatusCallback(); } } else if (type == DM_FFI_EVENT_DEVICE_DISCOVER_SUCCESS || type == DM_FFI_EVENT_DEVICE_DISCOVER_FAIL) { - if (!discoverSuccessCallback && !deviceDiscoverFailedCallback) { - return ReleaseDiscoveryCallback(); - } + return ReleaseDiscoveryCallback(); } return ERR_INVALID_PARAMS; } -- Gitee From ee83c55f409d481a5e1360d30cd2e1d33ac5d8ac Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Mon, 11 Nov 2024 20:37:44 +0800 Subject: [PATCH 45/49] bugfix. Change-Id: Idb35769a8152423a054d309530bfb59441c26792 --- interfaces/cj/src/device_manager_impl.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 1d0942add..ba82a7807 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -459,7 +459,7 @@ int32_t DeviceManagerFfiImpl::EventOn(const std::string &type, void *callback) return transformErrCode(ret); } - LOGI("On for bundleName %{public}s, eventType %{public}s ", bundleName_.c_str(), type.c_str()); + LOGI("EventOn for bundleName %{public}s, eventType %{public}s ", bundleName_.c_str(), type.c_str()); RegisterCallbackByType(type, callback); if (type == DM_FFI_EVENT_DEVICE_STATE_CHANGE || type == DM_FFI_EVENT_DEVICE_NAME_CHANGE) { @@ -478,12 +478,13 @@ int32_t DeviceManagerFfiImpl::EventOff(const std::string &type) return ret; } - LOGI("JsOff for bundleName %{public}s, eventType %{public}s ", bundleName_.c_str(), type.c_str()); + LOGI("EventOff for bundleName %{public}s, eventType %{public}s ", bundleName_.c_str(), type.c_str()); Off(type); if (type == DM_FFI_EVENT_DEVICE_STATE_CHANGE || type == DM_FFI_EVENT_DEVICE_NAME_CHANGE) { if (!deviceStateChangedCallback && !deviceNameChangedCallback) { return ReleaseDevStatusCallback(); } + return ERR_OK; } else if (type == DM_FFI_EVENT_DEVICE_DISCOVER_SUCCESS || type == DM_FFI_EVENT_DEVICE_DISCOVER_FAIL) { return ReleaseDiscoveryCallback(); } -- Gitee From 27be8ff0492ad9379de0dd2bd8b8529ebd6f9890 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Mon, 11 Nov 2024 21:01:20 +0800 Subject: [PATCH 46/49] bugfix. Change-Id: Id612117eab2985c271c513c4e7426153bbf718bc --- interfaces/cj/src/device_manager_impl.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index ba82a7807..8eb7ae092 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -423,6 +423,7 @@ int32_t DeviceManagerFfiImpl::BindTarget(const std::string &deviceId, LOGE("BindDevice for bundleName %{public}s failed, ret %{public}d", bundleName_.c_str(), ret); return ret; } + LOGI("BindDevice return %{public}d", ret); return WaitForCallbackCv(); } @@ -430,6 +431,7 @@ int32_t DeviceManagerFfiImpl::WaitForCallbackCv() { std::unique_lock autoLock(callbackFinishedMutex); callbackFinishedCv.wait(autoLock, [this] { return this->callbackFinished; }); + LOGI("WaitForCallbackCv got notified, errCode is %{public}d", errCode_); return errCode_; } @@ -574,6 +576,7 @@ void DeviceManagerFfiImpl::OnAuthResult(const std::string &deviceId, const std:: if (reason == DM_OK && (status <= STATUS_DM_CLOSE_PIN_INPUT_UI && status >= STATUS_DM_SHOW_AUTHORIZE_UI)) { LOGI("update ui change, status: %{public}d, reason: %{public}d", status, reason); + return; } else { std::lock_guard autoLock(g_authCallbackMapMutex); g_authCallbackMap.erase(bundleName_); -- Gitee From f8409e23803a8a42a8dfc7483ad120f4c84fd963 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Mon, 11 Nov 2024 21:03:38 +0800 Subject: [PATCH 47/49] bugfix. Change-Id: I2fa323b07778f8be7013ca6b476d202f2aa9c43d --- interfaces/cj/src/device_manager_impl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 8eb7ae092..9e364f0f5 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -431,7 +431,7 @@ int32_t DeviceManagerFfiImpl::WaitForCallbackCv() { std::unique_lock autoLock(callbackFinishedMutex); callbackFinishedCv.wait(autoLock, [this] { return this->callbackFinished; }); - LOGI("WaitForCallbackCv got notified, errCode is %{public}d", errCode_); + LOGI("WaitForCallbackCv got notified, errCode is %{public}d", errCode_.load()); return errCode_; } @@ -577,10 +577,10 @@ void DeviceManagerFfiImpl::OnAuthResult(const std::string &deviceId, const std:: if (reason == DM_OK && (status <= STATUS_DM_CLOSE_PIN_INPUT_UI && status >= STATUS_DM_SHOW_AUTHORIZE_UI)) { LOGI("update ui change, status: %{public}d, reason: %{public}d", status, reason); return; - } else { - std::lock_guard autoLock(g_authCallbackMapMutex); - g_authCallbackMap.erase(bundleName_); } + + std::lock_guard autoLock(g_authCallbackMapMutex); + g_authCallbackMap.erase(bundleName_); callbackFinished = true; callbackFinishedCv.notify_one(); } -- Gitee From 5ab2fd89c999f7907f40efaaea6f7c0a91e162da Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Mon, 11 Nov 2024 21:26:01 +0800 Subject: [PATCH 48/49] bugfix. Change-Id: I08bcd6b7d31cfa79609ab1e3953c34d0d2d279f9 --- interfaces/cj/src/device_manager_impl.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/interfaces/cj/src/device_manager_impl.cpp b/interfaces/cj/src/device_manager_impl.cpp index 9e364f0f5..4038b2120 100644 --- a/interfaces/cj/src/device_manager_impl.cpp +++ b/interfaces/cj/src/device_manager_impl.cpp @@ -565,18 +565,17 @@ void DeviceManagerFfiImpl::OnAuthResult(const std::string &deviceId, const std:: int32_t reason) { LOGI("OnAuthResult for status: %{public}d, reason: %{public}d", status, reason); + if (reason == DM_OK && (status <= STATUS_DM_CLOSE_PIN_INPUT_UI && status >= STATUS_DM_SHOW_AUTHORIZE_UI)) { + LOGI("update ui change, status: %{public}d, reason: %{public}d", status, reason); + return; + } if (status == DM_AUTH_REQUEST_SUCCESS_STATUS && reason == 0) { LOGI("OnAuthResult success"); errCode_ = ERR_OK; } else { LOGI("OnAuthResult failed"); - errCode_ = status; - } - - if (reason == DM_OK && (status <= STATUS_DM_CLOSE_PIN_INPUT_UI && status >= STATUS_DM_SHOW_AUTHORIZE_UI)) { - LOGI("update ui change, status: %{public}d, reason: %{public}d", status, reason); - return; + errCode_ = reason; } std::lock_guard autoLock(g_authCallbackMapMutex); -- Gitee From 0f9d6dd8dbdc7d4cb302b9b1e45e93bb656cf420 Mon Sep 17 00:00:00 2001 From: liuth <15027445+liuth88@user.noreply.gitee.com> Date: Tue, 12 Nov 2024 11:33:10 +0800 Subject: [PATCH 49/49] =?UTF-8?q?=E5=88=A0=E9=99=A4vscode=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ic9bf67a956108823645eaba6a0e4244ab124e911 --- .vscode/settings.json | 66 ------------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 412d3d1e1..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "files.associations": { - "array": "cpp", - "atomic": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "cctype": "cpp", - "chrono": "cpp", - "cinttypes": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "compare": "cpp", - "concepts": "cpp", - "condition_variable": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "list": "cpp", - "map": "cpp", - "set": "cpp", - "string": "cpp", - "unordered_map": "cpp", - "unordered_set": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "ratio": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "mutex": "cpp", - "new": "cpp", - "numbers": "cpp", - "ostream": "cpp", - "ranges": "cpp", - "semaphore": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "stop_token": "cpp", - "streambuf": "cpp", - "thread": "cpp", - "typeinfo": "cpp" - } -} \ No newline at end of file -- Gitee