手表增加应用市场处理 1761/1 1761/head
authorCaisking <Casiking@zhihuishixun.com>
Mon, 19 May 2025 08:58:24 +0000 (16:58 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Mon, 19 May 2025 08:58:24 +0000 (16:58 +0800)
code/sdk/application/wearable/fd230/service/app_store/app_store.cpp
code/sdk/application/wearable/fd230/service/app_store/app_store.h
code/sdk/zhihui/services/ble_service/blemoder/CMakeLists.txt
code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.cpp
code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.h
code/sdk/zhihui/services/ble_service/blemoder/ble_instruct_init.cpp
code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c
code/sdk/zhihui/services/ble_service/bleservice/bleEvent.h

index 8c6efbe..8a712b8 100644 (file)
@@ -127,3 +127,139 @@ errcode_t AppStoreGetPkgList(uint8_t cmd_id, uint8_t type, void *usr_data, uint1
     }
     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
+
index 7bbc93b..4706473 100644 (file)
@@ -65,6 +65,10 @@ typedef struct {
 errcode_t AppStorePkgOperation(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len);
 errcode_t AppStoreGetPkgList(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len);
 
+#ifdef BLE_INSTRUCT
+void ble_app_store_init(void);
+#endif
+
 #ifdef __cplusplus
 #if __cplusplus
 }
index dfd4d78..13f422c 100644 (file)
@@ -13,6 +13,7 @@ set(PRIVATE_HEADER
     ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits
     ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits
     ${ROOT_DIR}/application/wearable/nativeapp/nativeui/heartrate/include
+    ${ROOT_DIR}/application/wearable/fd230/service/app_store/
     ${ROOT_DIR}/application/wearable/fd230/nativeapp/nativeui/weather/include
     ${ROOT_DIR}/application/wearable/fd230/nativeapp/nativeui/heart_blood/health_service
     ${ROOT_DIR}/application/wearable/fd230/nativeapp/nativeui/sleep/include/
index ecbebe9..ddb6c43 100644 (file)
@@ -1229,13 +1229,13 @@ bool IS_free_save_Mp3(uint32_t size)
 }
 
 
-void ble_bin_install(void)
+bool ble_bin_install(const char * data)
 {
-     return bleInstruct_t.ble_bin_install();
+     return bleInstruct_t.ble_bin_install(data);
 }
 
 
-bool ble_app_delete(char *data)
+bool ble_app_delete(const char *data)
 {
      return bleInstruct_t.ble_app_delete(data);
 }
index 2ae025a..73df6e7 100644 (file)
@@ -416,7 +416,7 @@ errcode_t get_dial_file_path(char* input_dialname ,uint32_t input_size, char* ou
 
 uint16_t get_str_nodisplay_number(char *str, uint32_t max_len);
 
-void ble_bin_install(void);
+bool ble_bin_install(const char * data);
 typedef struct bleInstruct
 {
     uint16_t (*get_str_nodisplay_number_cb)(char *str, uint32_t max_len);
@@ -631,9 +631,9 @@ typedef struct bleInstruct
     void (*ble_disconnect_ok)(void);
     void (*hand_watch_first_time_Paired)(void);
 
-    void (*ble_bin_install)(void);
+    bool (*ble_bin_install)(const char * data);
 
-    bool (*ble_app_delete)(char * data);
+    bool (*ble_app_delete)(const char * data);
 
     cJSON* (*ble_app_list)(void);
 
@@ -649,7 +649,7 @@ void ble_instruct_init(void);
 
 void ble_mp3_init(void);
 
-bool ble_app_delete(char *data);
+bool ble_app_delete(const char *data);
 
 cJSON* ble_app_list(void);
 
index dc2de89..351ec7b 100644 (file)
@@ -10,6 +10,7 @@
 // #include "SetDialModel.h"
 #include "SleepModel.h"
 // #include "PlayersModel.h"
+#include "app_store.h"
 
 void ble_instruct_init(void)
 {
@@ -33,4 +34,6 @@ void ble_instruct_init(void)
 
     ble_config_init();
 
+    ble_app_store_init();
+
 }
\ No newline at end of file
index dd706a8..3b2ccdb 100644 (file)
@@ -7959,7 +7959,7 @@ void decode_file_checksum_2AE6(ble_read_data *buffer_handle)
                     CustomEventPublish(TOPIC_EVENT_BLE_TRANSMIT,&TRANSMIT_DATA,1);\r
                     \r
                     ble_reply_cmd(FILE_SUCC_TRANSFER,1);\r
-                    ble_bin_install();\r
+                    // ble_bin_install();\r
 \r
                     // ble_mp3_list_update();\r
 \r
index c003899..71de42b 100644 (file)
@@ -294,9 +294,8 @@ typedef struct
 #pragma pack(1)
 typedef struct
 {
-   
-    
-}msg_stop_sport_mode_info_t;//开启指定运动模式 SWITCH_SPORT_MODE
+    uint8_t sport_mode;////0 健走 1跑步 2骑行
+}msg_stop_sport_mode_info_t;//停止指定运动模式 SWITCH_SPORT_MODE
 #pragma pack()
 
 #pragma pack(1)
@@ -309,6 +308,7 @@ typedef struct
 #pragma pack(1)
 typedef struct
 {
+    uint8_t switch_hr; //0关闭 1开启
     //对应数据的指令类型
 }msg_switch_get_realhr_info_t;//开启/关闭自动获取实时训练数据SWITCH_GET_REAL_HEART_CMD
 #pragma pack()
@@ -475,24 +475,24 @@ typedef struct
 #pragma pack()
 
 #pragma pack(1)
-typedef struct
-{
-    //对应数据的指令类型
-}msg_factory_param_info_t;//app发送恢复出厂设置
+// typedef struct
+// {
+//     //对应数据的指令类型
+// }msg_factory_param_info_t;//app发送恢复出厂设置
 #pragma pack()
 
 #pragma pack(1)
-typedef struct
-{
-    //对应数据的指令类型
-}msg_reset_param_info_t;//app发送重新启动
+// typedef struct
+// {
+//     //对应数据的指令类型
+// }msg_reset_param_info_t;//app发送重新启动
 #pragma pack()
 
 #pragma pack(1)
-typedef struct
-{
-    //对应数据的指令类型
-}msg_poweroff_param_info_t;//app关机
+// typedef struct
+// {
+//     //对应数据的指令类型
+// }msg_poweroff_param_info_t;//app关机
 #pragma pack()
 
 #pragma pack(1)
@@ -720,11 +720,11 @@ typedef struct
 #pragma pack()
 
 #pragma pack(1)
-typedef struct
-{
-    //对应数据的指令类型
+// typedef struct
+// {
+//     //对应数据的指令类型
     
-}msg_get_sys_time_info_t;//获取系统时间
+// }msg_get_sys_time_info_t;//获取系统时间
 #pragma pack()
 
 #pragma pack(1)