diff --git a/distributedhardware/device_manager/BUILD.gn b/distributedhardware/device_manager/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c0542514be977f58f1ab0591b90a2e63d45b62a7 --- /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 0000000000000000000000000000000000000000..096615960c2e0ce979111b1cab8cb37f98fc13b7 --- /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 0000000000000000000000000000000000000000..227f0950a06d5243a674c4111fc7816702be9855 --- /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 0000000000000000000000000000000000000000..b77563c5d26566a8174ff8705da68c4b50eb1e0a --- /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 73066be68ffa95d8aa57bd5f862e92514c84d7de..5edaf48ee24f0fc62ac0cd94869de8a64c3abdbf 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",