}
return ret;
}
+///////////////////////////////////////////////////////////////////////////////////
+
+
+#ifdef BLE_INSTRUCT
+
+// #include "bleEvent.h"
+#include "bleInstruct.h"
+#include "cJSON.h"
+#include "adapter.h"
+
+bool ble_install_pkg(const char *pkgName)
+{
+ if (pkgName == nullptr || strlen(pkgName) == 0) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "ble_install_pkg: null or empty pkgName");
+ return false;
+ }
+
+ uint8_t len = strlen(FS_DIR_APP_STORE) + strlen(pkgName) + 1;
+ char *pkgFullName = (char *)malloc(len);
+ if (pkgFullName != nullptr) {
+ (void)sprintf_s(pkgFullName, len, "%s%s", FS_DIR_APP_STORE, pkgName);
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "AppStorePkgOperation install pkgFullName=%s", pkgFullName);
+ InstallParam installParam = { .installLocation = 1, .keepData = false };
+ uint8_t ret = OHOS::BundleMsClient::GetInstance().Install(pkgFullName, &installParam, InstallCallbackFunc);
+ free(pkgFullName);
+ return ret;
+ } else {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "Failed to allocate memory for pkgFullName");
+ return false;
+ }
+}
+
+bool ble_uninstall_pkg(const char *pkgName)
+{
+ if (pkgName == nullptr || strlen(pkgName) == 0) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "ble_uninstall_pkg: null or empty pkgName");
+ return false;
+ }
+
+ StopJsApp((char*)pkgName);
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "AppStorePkgOperation uninstall pkgName=%s", pkgName);
+ InstallParam installParam = { .installLocation = 1, .keepData = false };
+ uint8_t ret = OHOS::BundleMsClient::GetInstance().Uninstall((char*)pkgName, &installParam, UninstallCallbackFunc);
+
+ return ret;
+}
+
+//获取应用列表
+cJSON* ble_get_pkg_list() {
+ BundleInfo *bundleInfos = nullptr;
+ int32_t count = 0;
+
+ // 1. 获取应用列表
+ if (OHOS::BundleMsClient::GetInstance().GetBundleInfos(0, &bundleInfos, &count) !=0 ) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "Failed to get bundle infos");
+ return nullptr;
+ }
+ if (count <= 0) {
+ AdapterFree(bundleInfos);
+ return nullptr;
+ }
+
+ // 2. 创建 JSON 数组
+ cJSON *jsonArray = cJSON_CreateArray();
+ if (jsonArray == nullptr) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "cJSON_CreateArray failed");
+ AdapterFree(bundleInfos);
+ return nullptr;
+ }
+
+ // 3. 填充数组元素
+ for (int32_t i = 0; i < count; i++) {
+ // 创建 JSON 对象
+ cJSON *jsonObject = cJSON_CreateObject();
+ if (jsonObject == nullptr) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "cJSON_CreateObject failed at index %d", i);
+ goto CLEANUP; // 统一错误处理
+ }
+
+ // 添加 "name" 字段
+ if (cJSON_AddStringToObject(jsonObject, "name", bundleInfos[i].bundleName) == NULL) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "cJSON_AddStringToObject failed");
+ cJSON_Delete(jsonObject);
+ goto CLEANUP;
+ }
+
+ // 将对象添加到数组
+ if (cJSON_AddItemToArray(jsonArray, jsonObject) != 1) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "cJSON_AddItemToArray failed");
+ cJSON_Delete(jsonObject);
+ goto CLEANUP;
+ }
+ }
+
+ // 4. 释放资源并返回
+ AdapterFree(bundleInfos);
+ return jsonArray;
+
+CLEANUP:
+ // 释放 JSON 数组及内部对象
+ cJSON_Delete(jsonArray);
+ AdapterFree(bundleInfos);
+ return nullptr;
+}
+
+//获取表端信息
+/**
+watch_app_store_params
+vendorIdentity String 品牌商在聚合平台注册 是
+consumerIdentity String 消费者账号 是
+consumerType String 消费者账号类型,0:品牌商注册账号,1:聚合平台注册账号 是
+deviceSn String 设备序列号,从表端获取,需要品牌商提前将序列号在聚合平台注册 是
+themeMode String H5页面主题, 模式:light(浅色)(默认)/dark(深色) 是
+chipPlatform String 芯片平台,如:hisi 是
+chipModel String 芯片型号, 如:300 是
+os String watch系统,如: openharmony等 是
+osVersion String watch系统版本,如: 5.0.1 是
+sdkVersion String sdk版本号,如: 13 是
+resolution String watch分辨率,格式:宽*高,如:466*466 是
+**/
+cJSON *ble_get_device_info()
+{
+ return nullptr;
+}
+
+
+void ble_app_store_init()
+{
+ bleInstruct_t.ble_bin_install = ble_install_pkg;
+ bleInstruct_t.ble_app_delete = ble_uninstall_pkg;
+ bleInstruct_t.ble_app_list = ble_get_pkg_list;
+ bleInstruct_t.ble_get_watch_msg = ble_get_device_info;
+}
+
+#endif
+