From: Caisking Date: Sat, 24 May 2025 03:19:44 +0000 (+0800) Subject: 应用市场删除增加安装包删除 X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~282^2~1 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=6d861d093abfc5f31b80a7f3fbe2d5f892b277dd;p=mirrors%2FFD230.git 应用市场删除增加安装包删除 --- 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;