diff --git a/interfaces/kits/js/backup/session_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_backup_n_exporter.cpp index ee0c14adc9265d0158b8995811969274f49def58..f331a15f3f79dd7635e29f0fc65382897aaa168f 100644 --- a/interfaces/kits/js/backup/session_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_backup_n_exporter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -379,8 +379,8 @@ napi_value SessionBackupNExporter::Constructor(napi_env env, napi_callback_info .onProcess = bind(OnProcess, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onBackupSizeReport = bind(OnBackupSizeReport, backupEntity->callbacks, placeholders::_1)}, errMsg, errCode); if (!backupEntity->session) { - std::tuple errInfo = - std::make_tuple(errCode, BError::GetBackupMsgByErrno(errCode) + ", " + errMsg); + std::tuple errInfo = (errCode == BError(BError::Codes::SA_SESSION_CONFLICT)) ? + std::make_tuple(errCode, errMsg) : std::make_tuple(errCode, BError::GetBackupMsgByErrno(errCode)); ErrParam errorParam = [ errInfo ]() { return errInfo;}; NError(errorParam).ThrowErr(env); return nullptr; diff --git a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp index d3a84c62883959f7b77cd28162ed044eca47881f..5d61b6db4667ac341662a5465dc2782c63a779b8 100644 --- a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -382,8 +382,8 @@ napi_value SessionIncrementalBackupNExporter::Constructor(napi_env env, napi_cal .onProcess = bind(OnProcess, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onBackupSizeReport = bind(OnBackupSizeReport, backupEntity->callbacks, placeholders::_1)}, errMsg, errCode); if (!backupEntity->session) { - std::tuple errInfo = - std::make_tuple(errCode, BError::GetBackupMsgByErrno(errCode) + ", " + errMsg); + std::tuple errInfo = (errCode == BError(BError::Codes::SA_SESSION_CONFLICT)) ? + std::make_tuple(errCode, errMsg) : std::make_tuple(errCode, BError::GetBackupMsgByErrno(errCode)); ErrParam errorParam = [ errInfo ]() { return errInfo;}; NError(errorParam).ThrowErr(env); return nullptr; diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.cpp b/interfaces/kits/js/backup/session_restore_n_exporter.cpp index 23df85f3dcc8bea7bed64d8c10bbe32e17d89cd2..bb507b410306e61cad507e465a2690f87d7b2e97 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -469,8 +469,8 @@ napi_value SessionRestoreNExporter::Constructor(napi_env env, napi_callback_info .onBackupServiceDied = bind(OnBackupServiceDied, restoreEntity->callbacks), .onProcess = bind(OnProcess, restoreEntity->callbacks, placeholders::_1, placeholders::_2)}, errMsg, errCode); if (!restoreEntity->sessionSheet) { - std::tuple errInfo = - std::make_tuple(errCode, BError::GetBackupMsgByErrno(errCode) + ", " + errMsg); + std::tuple errInfo = (errCode == BError(BError::Codes::SA_SESSION_CONFLICT)) ? + std::make_tuple(errCode, errMsg) : std::make_tuple(errCode, BError::GetBackupMsgByErrno(errCode)); ErrParam errorParam = [ errInfo ]() { return errInfo;}; NError(errorParam).ThrowErr(env); return nullptr; diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index 12a70dd621a57bcf50a390f592dfa4f1eecfaf0d..bf1a73223955568bace21fa4149e06371e54e5a6 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -34,6 +34,7 @@ #include "module_ipc/service.h" #include "module_ipc/svc_session_manager.h" #include "module_sched/sched_scheduler.h" +#include "parameters.h" #include "status_receiver_host.h" #include "system_ability_definition.h" #include "if_system_ability_manager.h" @@ -47,6 +48,7 @@ const string HMOS_HAP_CODE_PATH = "1"; const string LINUX_HAP_CODE_PATH = "2"; const string MEDIA_LIBRARY_HAP = "com.ohos.medialibrary.medialibrarydata"; const string EXTERNAL_FILE_HAP = "com.ohos.UserFile.ExternalFileManager"; +const string APP_GALLERY_BUNDLE_NAME = "const.appgallery.shaderowner.bundlename"; const int E_ERR = -1; const vector dataDir = {"app", "local", "distributed", "database", "cache"}; } // namespace @@ -152,11 +154,8 @@ vector BundleMgrAdapter::GetBundleInfos(const vecto string BundleMgrAdapter::GetAppGalleryBundleName() { - auto bms = GetBundleManager(); - - string bundleName = ""; - auto ret = bms->QueryAppGalleryBundleName(bundleName); - if (!ret) { + string bundleName = OHOS::system::GetParameter(APP_GALLERY_BUNDLE_NAME, ""); + if (bundleName.empty()) { HILOGI("Get App Gallery BundleName fail!"); } else { HILOGI("App Gallery BundleName: %{public}s", bundleName.c_str()); diff --git a/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_other_test.cpp b/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_other_test.cpp index 397424299389c68292755f0ce341891c5fffc52f..b8ae4c34a0efa0e81bb50f929da141eaef721c60 100644 --- a/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_other_test.cpp +++ b/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_other_test.cpp @@ -324,30 +324,21 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildInitSessionErrInfo_0701, testing::ext::T EXPECT_EQ(result, ""); EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); - EXPECT_CALL(*cJsonMock, cJSON_CreateArray()).WillOnce(Return(nullptr)); - EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); - result = BJsonUtil::BuildInitSessionErrInfo(userId, callerName, activeTime); - EXPECT_EQ(result, ""); - - EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); - EXPECT_CALL(*cJsonMock, cJSON_CreateArray()).WillOnce(Return(reinterpret_cast(&cjson))); - EXPECT_CALL(*cJsonMock, cJSON_AddItemToObject(_, _, _)).WillOnce(Return(true)); EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(nullptr)); EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); result = BJsonUtil::BuildInitSessionErrInfo(userId, callerName, activeTime); EXPECT_EQ(result, ""); EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); - EXPECT_CALL(*cJsonMock, cJSON_CreateArray()).WillOnce(Return(reinterpret_cast(&cjson))); - EXPECT_CALL(*cJsonMock, cJSON_AddItemToObject(_, _, _)).WillOnce(Return(true)); EXPECT_CALL(*cJsonMock, cJSON_CreateObject()) .WillOnce(Return(reinterpret_cast(&cjson))) .WillOnce(Return(nullptr)); - EXPECT_CALL(*cJsonMock, cJSON_AddItemToArray(_, _)).WillOnce(Return(true)); EXPECT_CALL(*cJsonMock, cJSON_AddStringToObject(_, _, _)) + .WillOnce(Return(nullptr)) .WillOnce(Return(nullptr)) .WillOnce(Return(nullptr)) .WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_AddItemToObject(_, _, _)).WillOnce(Return(true)); EXPECT_CALL(*cJsonMock, cJSON_Print(_)).WillOnce(Return(nullptr)); EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); result = BJsonUtil::BuildInitSessionErrInfo(userId, callerName, activeTime); diff --git a/utils/src/b_jsonutil/b_jsonutil.cpp b/utils/src/b_jsonutil/b_jsonutil.cpp index bc3bebd9b05c95a386f059bf86e18a6ac71fe735..cdd7a085d35e30863d0d897a45318ae78f15c90f 100644 --- a/utils/src/b_jsonutil/b_jsonutil.cpp +++ b/utils/src/b_jsonutil/b_jsonutil.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -468,23 +468,17 @@ std::string BJsonUtil::BuildInitSessionErrInfo(int32_t userId, std::string calle HILOGE("Failed to create cJSON object info, update errMsg failed"); return ""; } - cJSON *sessionInfoArray = cJSON_CreateArray(); - if (sessionInfoArray == nullptr) { - HILOGE("Failed to create cJSON array sessionInfoArray, update errMsg failed"); - cJSON_Delete(info); - return ""; - } - cJSON_AddItemToObject(info, "sessionInfo", sessionInfoArray); cJSON *sessionInfoObject = cJSON_CreateObject(); if (sessionInfoObject == nullptr) { HILOGE("Failed to create cJSON object sessionInfoObject, update errMsg failed"); cJSON_Delete(info); return ""; } - cJSON_AddItemToArray(sessionInfoArray, sessionInfoObject); + cJSON_AddStringToObject(sessionInfoObject, "error", "Session Conflict"); cJSON_AddStringToObject(sessionInfoObject, "userId", to_string(userId).c_str()); cJSON_AddStringToObject(sessionInfoObject, "name", callerName.c_str()); cJSON_AddStringToObject(sessionInfoObject, "activeTime", activeTime.c_str()); + cJSON_AddItemToObject(info, "sessionInfo", sessionInfoObject); char *jsonStr = cJSON_Print(info); if (jsonStr == nullptr) { HILOGE("update errMsg failed");