From 80e2f3f528e947b019bd1a01af65a7669bf63d2b Mon Sep 17 00:00:00 2001 From: chensihan Date: Tue, 18 Mar 2025 15:57:32 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9session=E5=86=B2=E7=AA=81?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=80=BC=20Signed-off-by:=20chensihan=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kits/js/backup/session_backup_n_exporter.cpp | 4 ++-- .../backup/session_incremental_backup_n_exporter.cpp | 4 ++-- .../kits/js/backup/session_restore_n_exporter.cpp | 4 ++-- services/backup_sa/src/module_external/bms_adapter.cpp | 8 +++----- utils/src/b_jsonutil/b_jsonutil.cpp | 10 ++-------- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/interfaces/kits/js/backup/session_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_backup_n_exporter.cpp index ee0c14adc..7911b183f 100644 --- a/interfaces/kits/js/backup/session_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_backup_n_exporter.cpp @@ -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 d3a84c628..90488f18b 100644 --- a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp @@ -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 23df85f3d..b323a41a5 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -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 12a70dd62..71d20672a 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -47,6 +47,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 +153,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/utils/src/b_jsonutil/b_jsonutil.cpp b/utils/src/b_jsonutil/b_jsonutil.cpp index bc3bebd9b..584f3b2d6 100644 --- a/utils/src/b_jsonutil/b_jsonutil.cpp +++ b/utils/src/b_jsonutil/b_jsonutil.cpp @@ -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"); -- Gitee From f73400ca18c1b0bebb317a027e9d7f9370ac68cf Mon Sep 17 00:00:00 2001 From: chensihan Date: Tue, 18 Mar 2025 15:59:41 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6=20Signed-off-by:=20chensihan=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/kits/js/backup/session_backup_n_exporter.cpp | 2 +- .../kits/js/backup/session_incremental_backup_n_exporter.cpp | 2 +- interfaces/kits/js/backup/session_restore_n_exporter.cpp | 2 +- services/backup_sa/src/module_external/bms_adapter.cpp | 3 ++- utils/src/b_jsonutil/b_jsonutil.cpp | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/js/backup/session_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_backup_n_exporter.cpp index 7911b183f..f331a15f3 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 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 90488f18b..5d61b6db4 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 diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.cpp b/interfaces/kits/js/backup/session_restore_n_exporter.cpp index b323a41a5..bb507b410 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 diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index 71d20672a..cfef8b47b 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" diff --git a/utils/src/b_jsonutil/b_jsonutil.cpp b/utils/src/b_jsonutil/b_jsonutil.cpp index 584f3b2d6..cdd7a085d 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 -- Gitee From 6326fa0d8280d645728a9a605338ae20e366fd7a Mon Sep 17 00:00:00 2001 From: chensihan Date: Tue, 18 Mar 2025 08:54:45 +0000 Subject: [PATCH 3/6] update services/backup_sa/src/module_external/bms_adapter.cpp. Signed-off-by: chensihan --- services/backup_sa/src/module_external/bms_adapter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index cfef8b47b..bf1a73223 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -154,7 +154,7 @@ vector BundleMgrAdapter::GetBundleInfos(const vecto string BundleMgrAdapter::GetAppGalleryBundleName() { - string bundleName = OHOS::system::GetParameter(APP_GALLERY_BUNDLE_NAME,""); + string bundleName = OHOS::system::GetParameter(APP_GALLERY_BUNDLE_NAME, ""); if (bundleName.empty()) { HILOGI("Get App Gallery BundleName fail!"); } else { -- Gitee From 6635e76338cdc3a7daa8c0bf873b63abfe39e03b Mon Sep 17 00:00:00 2001 From: chensihan Date: Wed, 19 Mar 2025 10:57:09 +0800 Subject: [PATCH 4/6] =?UTF-8?q?ut=E4=BF=AE=E5=A4=8D=20Signed-off-by:=20che?= =?UTF-8?q?nsihan=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../b_jsonutil/b_jsonutil_other_test.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) 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 397424299..e17a2374e 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,19 @@ 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_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); 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); -- Gitee From 5de957d7e5f686783ad8e13b55e46f566f5d6292 Mon Sep 17 00:00:00 2001 From: chensihan Date: Wed, 19 Mar 2025 03:36:04 +0000 Subject: [PATCH 5/6] update tests/unittests/backup_utils/b_jsonutil/b_jsonutil_other_test.cpp. Signed-off-by: chensihan --- .../unittests/backup_utils/b_jsonutil/b_jsonutil_other_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e17a2374e..51cf056cf 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 @@ -332,7 +332,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildInitSessionErrInfo_0701, testing::ext::T EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); EXPECT_CALL(*cJsonMock, cJSON_AddStringToObject(_, _, _)) - .WillOnce(Return(nullptr)); + .WillOnce(Return(nullptr)) .WillOnce(Return(nullptr)) .WillOnce(Return(nullptr)) .WillOnce(Return(nullptr)); -- Gitee From f8df40314383e53a052b50161542727584a426ae Mon Sep 17 00:00:00 2001 From: chensihan Date: Wed, 19 Mar 2025 06:29:28 +0000 Subject: [PATCH 6/6] update tests/unittests/backup_utils/b_jsonutil/b_jsonutil_other_test.cpp. Signed-off-by: chensihan --- .../backup_utils/b_jsonutil/b_jsonutil_other_test.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 51cf056cf..b8ae4c34a 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 @@ -330,7 +330,9 @@ 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_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_CreateObject()) + .WillOnce(Return(reinterpret_cast(&cjson))) + .WillOnce(Return(nullptr)); EXPECT_CALL(*cJsonMock, cJSON_AddStringToObject(_, _, _)) .WillOnce(Return(nullptr)) .WillOnce(Return(nullptr)) -- Gitee