From 6d861d093abfc5f31b80a7f3fbe2d5f892b277dd Mon Sep 17 00:00:00 2001 From: Caisking Date: Sat, 24 May 2025 11:19:44 +0800 Subject: [PATCH] =?utf8?q?=E5=BA=94=E7=94=A8=E5=B8=82=E5=9C=BA=E5=88=A0?= =?utf8?q?=E9=99=A4=E5=A2=9E=E5=8A=A0=E5=AE=89=E8=A3=85=E5=8C=85=E5=88=A0?= =?utf8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../fd230/service/app_store/app_store.cpp | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 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 06d7ae484..8fcc4e8b3 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 @@ -10,6 +10,7 @@ #include "appexecfwk_errors.h" #include "ui_service.h" + void AppStoreReplyAck(uint8_t cmd_id, uint8_t type, uint32_t ack) { int ret = msg_center_send_data(cmd_id, type, &ack, sizeof(ack)); @@ -163,20 +164,42 @@ bool ble_install_pkg(const char *pkgName) bool ble_uninstall_pkg(const char *pkgName) { - if (pkgName == nullptr || strlen(pkgName) == 0) { + // 快速失败检查 + if (pkgName == nullptr || *pkgName == '\0') { WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "ble_uninstall_pkg: null or empty pkgName"); return false; } + // 停止应用 StopJsApp((char*)pkgName); + + // 预先计算路径长度 + const size_t dirLen = strlen(FS_DIR_APP_STORE); + const size_t nameLen = strlen(pkgName); + const size_t fullLen = dirLen + nameLen + 5; + + // 使用栈上的固定大小缓冲区,避免频繁堆分配 + char pkgFullName[256]; + if (fullLen > sizeof(pkgFullName)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "ble_uninstall_pkg: path too long"); + return false; + } + + // 安全的路径拼接 + snprintf(pkgFullName, sizeof(pkgFullName), "%s%s.bin", FS_DIR_APP_STORE, pkgName); + + // 删除文件 + if (uapi_delete_files(pkgFullName) != 0) { + WEARABLE_LOGW(WEARABLE_LOG_MODULE_BLE, "Failed to delete file: %s", pkgFullName); + } + 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; + return OHOS::BundleMsClient::GetInstance().Uninstall((char*)pkgName, &installParam, UninstallCallbackFunc); } - // 获取应用列表 cJSON* ble_get_pkg_list() { BundleInfo *bundleInfos = nullptr; -- 2.17.1