From 50aa51b43a5984bdcf1d032180ff3de1a98c642d Mon Sep 17 00:00:00 2001 From: daiyunlong Date: Fri, 24 Jul 2026 23:32:11 +0800 Subject: [PATCH 1/6] feat: add C ABI for GetLocalDeviceName Sync the public NDK header with device_manager: add OH_DeviceManager_GetLocalDeviceNameC(char **, unsigned int *) using pointer output parameters. Mark the legacy OH_DeviceManager_GetLocalDeviceName (unsigned int &) as deprecated and point users to the new C ABI. Add the new symbol to libdevicemanager.ndk.json with first_introduced 26. Co-Authored-By: Agent Signed-off-by: daiyunlong --- .../include/oh_device_manager.h | 31 +++++++++++++++++-- .../device_manager/libdevicemanager.ndk.json | 6 +++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/distributedhardware/device_manager/include/oh_device_manager.h b/distributedhardware/device_manager/include/oh_device_manager.h index 51d7a86c4..3b130126a 100644 --- a/distributedhardware/device_manager/include/oh_device_manager.h +++ b/distributedhardware/device_manager/include/oh_device_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2025-2026 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 @@ -40,7 +40,6 @@ #ifdef __cplusplus extern "C" { -#endif /** * @brief Obtains the display name of the local device. @@ -62,9 +61,37 @@ extern "C" { * Returns {@link ERR_INVALID_PARAMETER} is returned if the localDeviceName is nullptr or * *localDeviceName is not nullptr. * @since 20 + * @deprecated since 20 + * @useinstead OH_DeviceManager_GetLocalDeviceNameC */ int32_t OH_DeviceManager_GetLocalDeviceName(char **localDeviceName, unsigned int &len); +#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 Pointer to the length of the display name of the local device. + * After using this API, you need to manually release resources to free up space. + * @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. + * Returns {@link ERR_INVALID_PARAMETER} is returned if the localDeviceName is nullptr, + * *localDeviceName is not nullptr, or len is nullptr. + * @since 26.0.0 + */ +int32_t OH_DeviceManager_GetLocalDeviceNameC(char **localDeviceName, unsigned int *len); + #ifdef __cplusplus }; #endif diff --git a/distributedhardware/device_manager/libdevicemanager.ndk.json b/distributedhardware/device_manager/libdevicemanager.ndk.json index b77563c5d..556f81246 100644 --- a/distributedhardware/device_manager/libdevicemanager.ndk.json +++ b/distributedhardware/device_manager/libdevicemanager.ndk.json @@ -2,5 +2,9 @@ { "first_introduced": "20", "name": "OH_DeviceManager_GetLocalDeviceName" + }, + { + "first_introduced": "26", + "name": "OH_DeviceManager_GetLocalDeviceNameC" } -] \ No newline at end of file +] From 6dac78da24a9794053fe259feb2abac1615249bd Mon Sep 17 00:00:00 2001 From: daiyunlong Date: Sat, 25 Jul 2026 10:14:22 +0800 Subject: [PATCH 2/6] docs: refine GetLocalDeviceName len param wording Update the public NDK header so the @param len description reads 'Character length of the display name of the local device.' for the deprecated OH_DeviceManager_GetLocalDeviceName, aligning wording with the device_manager in-tree copy. No semantic change. Co-Authored-By: Agent Signed-off-by: daiyunlong --- distributedhardware/device_manager/include/oh_device_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distributedhardware/device_manager/include/oh_device_manager.h b/distributedhardware/device_manager/include/oh_device_manager.h index 3b130126a..89d8a0703 100644 --- a/distributedhardware/device_manager/include/oh_device_manager.h +++ b/distributedhardware/device_manager/include/oh_device_manager.h @@ -52,7 +52,7 @@ extern "C" { * 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. + * @param len Character 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. From 566df5726df21e95a25827aaa6c0f9555233fce5 Mon Sep 17 00:00:00 2001 From: daiyunlong Date: Sat, 25 Jul 2026 10:23:31 +0800 Subject: [PATCH 3/6] docs: correct deprecated version to 26.0.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OH_DeviceManager_GetLocalDeviceName is deprecated starting from 26.0.0, when OH_DeviceManager_GetLocalDeviceNameC is introduced. The previous '@deprecated since 20' was wrong because the API itself is @since 20 and only becomes deprecated at 26.0.0. Co-Authored-By: Agent Signed-off-by: daiyunlong 🤖 AI[100%] 🔧 Human Fixed[0%] 🧑 Human[0%] 👌 AI Adopted[100%] Co-authored-by: claude (glm-5.2) --- distributedhardware/device_manager/include/oh_device_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distributedhardware/device_manager/include/oh_device_manager.h b/distributedhardware/device_manager/include/oh_device_manager.h index 89d8a0703..fb89a5538 100644 --- a/distributedhardware/device_manager/include/oh_device_manager.h +++ b/distributedhardware/device_manager/include/oh_device_manager.h @@ -61,7 +61,7 @@ extern "C" { * Returns {@link ERR_INVALID_PARAMETER} is returned if the localDeviceName is nullptr or * *localDeviceName is not nullptr. * @since 20 - * @deprecated since 20 + * @deprecated since 26.0.0 * @useinstead OH_DeviceManager_GetLocalDeviceNameC */ int32_t OH_DeviceManager_GetLocalDeviceName(char **localDeviceName, unsigned int &len); From f50edad24e45f48065d3eaf0fbf50a7214b5d971 Mon Sep 17 00:00:00 2001 From: daiyunlong Date: Sat, 25 Jul 2026 10:59:50 +0800 Subject: [PATCH 4/6] style: drop blank line after extern C opening brace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cpplint reports 'Do not add blank lines on the start of a code block defined by braces' on the extern "C" { block. Remove the blank line so the doxygen comment directly follows the opening brace. Co-Authored-By: Agent Signed-off-by: daiyunlong 🤖 AI[0%] 🔧 Human Fixed[0%] 🧑 Human[0%] 👌 AI Adopted[0%] --- distributedhardware/device_manager/include/oh_device_manager.h | 1 - 1 file changed, 1 deletion(-) diff --git a/distributedhardware/device_manager/include/oh_device_manager.h b/distributedhardware/device_manager/include/oh_device_manager.h index fb89a5538..46972e48c 100644 --- a/distributedhardware/device_manager/include/oh_device_manager.h +++ b/distributedhardware/device_manager/include/oh_device_manager.h @@ -40,7 +40,6 @@ #ifdef __cplusplus extern "C" { - /** * @brief Obtains the display name of the local device. * The device display name involves user privacy. From 7fd4823f2a4764b27353b779ac2acaa55942b89a Mon Sep 17 00:00:00 2001 From: daiyunlong Date: Sat, 25 Jul 2026 11:35:32 +0800 Subject: [PATCH 5/6] docs: unify ERR_INVALID_PARAMETER wording with deprecated API Use the same 'A or B or C' connector style as the deprecated OH_DeviceManager_GetLocalDeviceName instead of the Oxford-comma 'A, B, or C' form, so the parameter-error description reads consistently across both APIs. Co-Authored-By: Agent Signed-off-by: daiyunlong --- .../device_manager/include/oh_device_manager.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/distributedhardware/device_manager/include/oh_device_manager.h b/distributedhardware/device_manager/include/oh_device_manager.h index 46972e48c..792c20194 100644 --- a/distributedhardware/device_manager/include/oh_device_manager.h +++ b/distributedhardware/device_manager/include/oh_device_manager.h @@ -85,8 +85,8 @@ int32_t OH_DeviceManager_GetLocalDeviceName(char **localDeviceName, unsigned int * 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. - * Returns {@link ERR_INVALID_PARAMETER} is returned if the localDeviceName is nullptr, - * *localDeviceName is not nullptr, or len is nullptr. + * Returns {@link ERR_INVALID_PARAMETER} is returned if the localDeviceName is nullptr or + * *localDeviceName is not nullptr or len is nullptr. * @since 26.0.0 */ int32_t OH_DeviceManager_GetLocalDeviceNameC(char **localDeviceName, unsigned int *len); From c989392830a23d9de5a128b17cbe2444b3fca82d Mon Sep 17 00:00:00 2001 From: daiyunlong Date: Mon, 27 Jul 2026 14:08:49 +0800 Subject: [PATCH 6/6] fix: align first_introduced version with API since tag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OH_DeviceManager_GetLocalDeviceNameC is declared with @since 26.0.0 in the header, so the first_introduced field in libdevicemanager.ndk.json should be '26.0.0' instead of '26' to match the canonical version string. Co-Authored-By: Agent Signed-off-by: daiyunlong 🤖 AI[100%] 🔧 Human Fixed[0%] 🧑 Human[0%] 👌 AI Adopted[100%] Co-authored-by: claude (glm-5.2) --- distributedhardware/device_manager/libdevicemanager.ndk.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distributedhardware/device_manager/libdevicemanager.ndk.json b/distributedhardware/device_manager/libdevicemanager.ndk.json index 556f81246..8d30fe5c0 100644 --- a/distributedhardware/device_manager/libdevicemanager.ndk.json +++ b/distributedhardware/device_manager/libdevicemanager.ndk.json @@ -4,7 +4,7 @@ "name": "OH_DeviceManager_GetLocalDeviceName" }, { - "first_introduced": "26", + "first_introduced": "26.0.0", "name": "OH_DeviceManager_GetLocalDeviceNameC" } ]