From 70d720743be9c1fdbc4d57820bb99a7378894a94 Mon Sep 17 00:00:00 2001 From: guoyi Date: Wed, 18 Jun 2025 19:08:37 +0800 Subject: [PATCH] =?UTF-8?q?dm=E5=A2=9E=E5=8A=A0ndk=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: guoyi --- distributedhardware/device_manager/BUILD.gn | 36 ++++++++ .../include/oh_device_manager.h | 73 ++++++++++++++++ .../include/oh_device_manager_err_code.h | 83 +++++++++++++++++++ .../device_manager/libdevicemanager.ndk.json | 6 ++ ndk_targets.gni | 2 + 5 files changed, 200 insertions(+) create mode 100644 distributedhardware/device_manager/BUILD.gn create mode 100644 distributedhardware/device_manager/include/oh_device_manager.h create mode 100644 distributedhardware/device_manager/include/oh_device_manager_err_code.h create mode 100644 distributedhardware/device_manager/libdevicemanager.ndk.json diff --git a/distributedhardware/device_manager/BUILD.gn b/distributedhardware/device_manager/BUILD.gn new file mode 100644 index 000000000..c0542514b --- /dev/null +++ b/distributedhardware/device_manager/BUILD.gn @@ -0,0 +1,36 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") +import("//foundation/distributedhardware/device_manager/device_manager.gni") + +ohos_ndk_headers("devicemanager_ndk_header") { + dest_dir = "$ndk_headers_out_dir/distributedhardware/device_manager/" + sources = [ + "./include/oh_device_manager.h", + "./include/oh_device_manager_err_code.h", + ] +} + +ohos_ndk_library("libdevicemanager_ndk") { + output_name = "devicemanager_ndk" + output_extension = "so" + system_capability = "SystemCapability.DistributedHardware.DeviceManager" + ndk_description_file = "./libdevicemanager.ndk.json" + min_compact_version = "20" + system_capability_headers = [ + "$ndk_headers_out_dir/distributedhardware/device_manager/oh_device_manager.h", + "$ndk_headers_out_dir/distributedhardware/device_manager/oh_device_manager_err_code.h", + ] +} diff --git a/distributedhardware/device_manager/include/oh_device_manager.h b/distributedhardware/device_manager/include/oh_device_manager.h new file mode 100644 index 000000000..096615960 --- /dev/null +++ b/distributedhardware/device_manager/include/oh_device_manager.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup DeviceManager + * @{ + * + * @brief Distributed device management module, + * which provides APIs to obtain information about trusted devices and local devices. + * + * @since 20 + */ + +/** + * @file oh_device_manager.h + * + * @brief Provides APIs to obtain information about trusted devices and local devices. + * File to include: + * + * @kit DistributedServiceKit + * @library libdevicemanager_ndk.so + * @syscap SystemCapability.DistributedHardware.DeviceManager + * + * @since 20 + */ + +#ifndef OH_DEVICE_MANAGER_H +#define OH_DEVICE_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Obtains the display name of the local device. + * The device display name involves user privacy. + * You need to provide a privacy statement to declare the purpose of the device display name. + * + * @permission ohos.permission.READ_LOCAL_DEVICE_NAME + * @param localDeviceName Pointer to the display name of the local device. + * After using this API, you need to manually release resources to free up space. + * If the application has the ohos.permission.READ_LOCAL_DEVICE_NAME permission, the device display name is returned. + * Otherwise, the default device name is returned. + * @param len Length of the display name of the local device. + * @return Error code. For details about the error code definitions, see {@link DeviceManager_ErrorCode}. + * Returns {@link ERR_OK} is returned if the execution is successful. + * Returns {@link DM_ERR_FAILED} is returned if the function fails to be executed. + * Returns {@link DM_ERR_OBTAIN_SERVICE} is returned if the device management service fails to be obtained. + * Returns {@link DM_ERR_OBTAIN_BUNDLE_NAME} is returned if the bundle name fails to be obtained. + * @since 20 + */ +int32_t OH_DeviceManager_GetLocalDeviceName(char **localDeviceName, unsigned int &len); + +#ifdef __cplusplus +}; +#endif + +/** @} */ +#endif \ No newline at end of file diff --git a/distributedhardware/device_manager/include/oh_device_manager_err_code.h b/distributedhardware/device_manager/include/oh_device_manager_err_code.h new file mode 100644 index 000000000..227f0950a --- /dev/null +++ b/distributedhardware/device_manager/include/oh_device_manager_err_code.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup DeviceManager + * @{ + * + * @brief Distributed device management module, + * which provides APIs to obtain information about trusted devices and local devices. + * + * @since 20 + */ + +/** + * @file oh_device_manager_err_code.h + * + * @brief Declares the error codes of the distributed device management module. + * File to include: + * + * @kit DistributedServiceKit + * @library libdevicemanager_ndk.so + * @syscap SystemCapability.DistributedHardware.DeviceManager + * + * @since 20 + */ + + +#ifndef OH_DEVICE_MANAGER_ERR_CODE_H +#define OH_DEVICE_MANAGER_ERR_CODE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Error code information of distributed device management module. + * + * @since 20 + */ +typedef enum DeviceManager_ErrorCode { + /** + * @error Operation success. + */ + ERR_OK = 0, + /** + * @error Permission verification failed. + */ + ERR_PERMISSION_ERROR = 201, + /** + * @error Invalid parameter. + */ + ERR_INVALID_PARAMETER = 401, + /** + * @error Function execution failed. + */ + DM_ERR_FAILED = 11600101, + /** + * @error Failed to obtain the device management service. + */ + DM_ERR_OBTAIN_SERVICE = 11600102, + /** + * @error Failed to obtain the bundle name. + */ + DM_ERR_OBTAIN_BUNDLE_NAME = 11600109, +} DeviceManager_ErrorCode; +#ifdef __cplusplus +}; +#endif + +/** @} */ +#endif diff --git a/distributedhardware/device_manager/libdevicemanager.ndk.json b/distributedhardware/device_manager/libdevicemanager.ndk.json new file mode 100644 index 000000000..b77563c5d --- /dev/null +++ b/distributedhardware/device_manager/libdevicemanager.ndk.json @@ -0,0 +1,6 @@ +[ + { + "first_introduced": "20", + "name": "OH_DeviceManager_GetLocalDeviceName" + } +] \ No newline at end of file diff --git a/ndk_targets.gni b/ndk_targets.gni index 73066be68..5edaf48ee 100644 --- a/ndk_targets.gni +++ b/ndk_targets.gni @@ -198,6 +198,8 @@ _ndk_library_targets = [ "//interface/sdk_c/distributeddatamgr/pasteboard:pasteboard_ndk_header", "//interface/sdk_c/distributeddatamgr/preferences:preferences_ndk_header", "//interface/sdk_c/distributeddatamgr/preferences:libohpreferences", + "//interface/sdk_c/distributedhardware/device_manager:libdevicemanager_ndk", + "//interface/sdk_c/distributedhardware/device_manager:devicemanager_ndk_header", "//interface/sdk_c/drivers/external_device_manager/usb:libusb_ndk", "//interface/sdk_c/drivers/external_device_manager/usb:usb_header", "//interface/sdk_c/drivers/external_device_manager/usb_serial:libusb_serial", -- Gitee