From c7cd3c9bcda4e2e029d4ebf881f75df6a9a04627 Mon Sep 17 00:00:00 2001 From: Caisking Date: Wed, 28 May 2025 17:12:11 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E5=BA=94=E7=94=A8=E5=B8=82?= =?utf8?q?=E5=9C=BA=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE=E4=B8=BA=E7=A9=BA?= =?utf8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../fd230/service/app_store/app_store.cpp | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/code/sdk/application/wearable/fd230/service/app_store/app_store.cpp b/code/sdk/application/wearable/fd230/service/app_store/app_store.cpp index 8fcc4e8b3..4570f1b3a 100644 --- a/code/sdk/application/wearable/fd230/service/app_store/app_store.cpp +++ b/code/sdk/application/wearable/fd230/service/app_store/app_store.cpp @@ -206,25 +206,26 @@ cJSON* ble_get_pkg_list() { int32_t count = 0; char *jsonString; + // 2. 创建 JSON 数组 + cJSON *jsonArray = cJSON_CreateArray(); + if (jsonArray == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "cJSON_CreateArray failed"); + AdapterFree(bundleInfos); + return nullptr; + } + + // 1. 获取应用列表 if (OHOS::BundleMsClient::GetInstance().GetBundleInfos(0, &bundleInfos, &count) != 0) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "Failed to get bundle infos"); - return nullptr; + return jsonArray; } WEARABLE_LOGI(WEARABLE_LOG_MODULE_BLE, "Successfully retrieved %d bundle infos", count); if (count <= 0) { AdapterFree(bundleInfos); WEARABLE_LOGW(WEARABLE_LOG_MODULE_BLE, "No packages found"); - return nullptr; - } - - // 2. 创建 JSON 数组 - cJSON *jsonArray = cJSON_CreateArray(); - if (jsonArray == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "cJSON_CreateArray failed"); - AdapterFree(bundleInfos); - return nullptr; + return jsonArray; } // 3. 填充数组元素 @@ -271,9 +272,9 @@ cJSON* ble_get_pkg_list() { return jsonArray; CLEANUP: - cJSON_Delete(jsonArray); + // cJSON_Delete(jsonArray); AdapterFree(bundleInfos); - return nullptr; + return jsonArray; } //获取表端信息 /** -- 2.17.1