From c2a0f9d12cbab34d96b88299b30b04a01f89e241 Mon Sep 17 00:00:00 2001 From: savior-xzh Date: Tue, 21 May 2024 16:38:05 +0800 Subject: [PATCH 01/69] fix fuzz Signed-off-by: savior-xzh Change-Id: I3f951f93b250eae5732d8ab5c5121b2153e34c10 --- test/fuzztest/abilitystubuninstallapp_fuzzer/BUILD.gn | 1 + .../abilitystubuninstallapp_fuzzer.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/fuzztest/abilitystubuninstallapp_fuzzer/BUILD.gn b/test/fuzztest/abilitystubuninstallapp_fuzzer/BUILD.gn index 1aa4ddbe70..0612059eab 100644 --- a/test/fuzztest/abilitystubuninstallapp_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitystubuninstallapp_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("AbilityStubUninstallAppFuzzTest") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", + "kv_store:distributeddata_inner", "napi:ace_napi", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/abilitystubuninstallapp_fuzzer/abilitystubuninstallapp_fuzzer.cpp b/test/fuzztest/abilitystubuninstallapp_fuzzer/abilitystubuninstallapp_fuzzer.cpp index aff1d481c1..60923efdcb 100644 --- a/test/fuzztest/abilitystubuninstallapp_fuzzer/abilitystubuninstallapp_fuzzer.cpp +++ b/test/fuzztest/abilitystubuninstallapp_fuzzer/abilitystubuninstallapp_fuzzer.cpp @@ -21,6 +21,7 @@ #define private public #include "ability_manager_service.h" #undef private +#include "app_exit_reason_data_manager.h" #include "message_parcel.h" #include "securec.h" @@ -48,7 +49,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) DelayedSingleton::GetInstance()->subManagersHelper_->currentUIAbilityManager_ = std::make_shared(); DelayedSingleton::GetInstance()->OnRemoteRequest(code, parcel, reply, option); - + DelayedSingleton::DestroyInstance(); return true; } } From 769efe6f7104bf0c1d78e61d06ed4dab9be3c84d Mon Sep 17 00:00:00 2001 From: x00671510 Date: Mon, 27 May 2024 15:19:08 +0800 Subject: [PATCH 02/69] add extType SYSPICKER_AUDIOPICKER Signed-off-by: x00671510 --- services/common/include/ui_extension_utils.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/common/include/ui_extension_utils.h b/services/common/include/ui_extension_utils.h index 12e2e80b8b..716d643499 100755 --- a/services/common/include/ui_extension_utils.h +++ b/services/common/include/ui_extension_utils.h @@ -60,7 +60,8 @@ inline std::unordered_set GetUiExtensionSet() AppExecFwk::ExtensionAbilityType::SYSPICKER_CAMERA, AppExecFwk::ExtensionAbilityType::SYSPICKER_FILEPICKER, AppExecFwk::ExtensionAbilityType::AUTO_FILL_SMART, - AppExecFwk::ExtensionAbilityType::LIVEVIEW_LOCKSCREEN + AppExecFwk::ExtensionAbilityType::LIVEVIEW_LOCKSCREEN, + AppExecFwk::ExtensionAbilityType::SYSPICKER_AUDIOPICKER }; } From e8498c953f4882209e2fb02dcaeb0701ccba5a75 Mon Sep 17 00:00:00 2001 From: srr101 Date: Mon, 27 May 2024 20:50:51 +0800 Subject: [PATCH 03/69] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=89=8D=E5=90=8E?= =?UTF-8?q?=E5=90=91cfi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: srr101 --- interfaces/inner_api/dataobs_manager/BUILD.gn | 6 ++++++ services/dataobsmgr/BUILD.gn | 12 ++++++++++++ .../data_ability_observer_proxy_test/BUILD.gn | 7 +++++++ .../cfi_blocklist.txt | 2 ++ .../data_ability_observer_stub_test/BUILD.gn | 6 ++++++ test/unittest/dataobs_mgr_client_test/BUILD.gn | 6 ++++++ test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn | 6 ++++++ test/unittest/dataobs_mgr_inner_pref_test/BUILD.gn | 6 ++++++ test/unittest/dataobs_mgr_inner_test/BUILD.gn | 6 ++++++ test/unittest/dataobs_mgr_proxy_test/BUILD.gn | 6 ++++++ test/unittest/dataobs_mgr_service_dump_test/BUILD.gn | 6 ++++++ test/unittest/dataobs_mgr_service_test/BUILD.gn | 6 ++++++ test/unittest/dataobs_mgr_stub_test/BUILD.gn | 6 ++++++ 13 files changed, 81 insertions(+) create mode 100644 test/unittest/data_ability_observer_proxy_test/cfi_blocklist.txt mode change 100755 => 100644 test/unittest/dataobs_mgr_service_dump_test/BUILD.gn diff --git a/interfaces/inner_api/dataobs_manager/BUILD.gn b/interfaces/inner_api/dataobs_manager/BUILD.gn index cabea243fe..741b5551eb 100644 --- a/interfaces/inner_api/dataobs_manager/BUILD.gn +++ b/interfaces/inner_api/dataobs_manager/BUILD.gn @@ -28,6 +28,12 @@ config("dataobs_manager_public_config") { } ohos_shared_library("dataobs_manager") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } sources = [ "${ability_runtime_services_path}/dataobsmgr/src/data_ability_observer_proxy.cpp", "${ability_runtime_services_path}/dataobsmgr/src/data_ability_observer_stub.cpp", diff --git a/services/dataobsmgr/BUILD.gn b/services/dataobsmgr/BUILD.gn index f637a07c08..b18c5e91b8 100644 --- a/services/dataobsmgr/BUILD.gn +++ b/services/dataobsmgr/BUILD.gn @@ -32,6 +32,12 @@ config("dataobsms_config") { } ohos_shared_library("dataobsms") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } shlib_type = "sa" sources = dataobsms_files @@ -58,6 +64,12 @@ ohos_shared_library("dataobsms") { # Note: Just for test ohos_static_library("dataobsms_static") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } sources = dataobsms_files configs = [ ":dataobsms_config" ] diff --git a/test/unittest/data_ability_observer_proxy_test/BUILD.gn b/test/unittest/data_ability_observer_proxy_test/BUILD.gn index 8cbe2afb1d..e53b4a12e4 100644 --- a/test/unittest/data_ability_observer_proxy_test/BUILD.gn +++ b/test/unittest/data_ability_observer_proxy_test/BUILD.gn @@ -17,6 +17,13 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/dataobsmgr" ohos_unittest("data_ability_observer_proxy_test") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "./cfi_blocklist.txt" + } module_out_path = module_output_path include_dirs = [] diff --git a/test/unittest/data_ability_observer_proxy_test/cfi_blocklist.txt b/test/unittest/data_ability_observer_proxy_test/cfi_blocklist.txt new file mode 100644 index 0000000000..fddb4e5f3b --- /dev/null +++ b/test/unittest/data_ability_observer_proxy_test/cfi_blocklist.txt @@ -0,0 +1,2 @@ +src:*/third_party/googletest/googletest/include/gtest/* +src:*/third_party/googletest/googlemock/include/gmock/* \ No newline at end of file diff --git a/test/unittest/data_ability_observer_stub_test/BUILD.gn b/test/unittest/data_ability_observer_stub_test/BUILD.gn index 2270898c0e..cbb7040b9c 100644 --- a/test/unittest/data_ability_observer_stub_test/BUILD.gn +++ b/test/unittest/data_ability_observer_stub_test/BUILD.gn @@ -17,6 +17,12 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/dataobsmgr" ohos_unittest("data_ability_observer_stub_test") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } module_out_path = module_output_path include_dirs = [] diff --git a/test/unittest/dataobs_mgr_client_test/BUILD.gn b/test/unittest/dataobs_mgr_client_test/BUILD.gn index 1e833fca66..be81692a3e 100644 --- a/test/unittest/dataobs_mgr_client_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_client_test/BUILD.gn @@ -17,6 +17,12 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/dataobsmgr" ohos_unittest("dataobs_mgr_client_test") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } module_out_path = module_output_path include_dirs = [ diff --git a/test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn b/test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn index 7e9a3f5b7f..4631fa97cb 100644 --- a/test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn @@ -17,6 +17,12 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/dataobsmgr" ohos_unittest("dataobs_mgr_inner_ext_test") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } module_out_path = module_output_path include_dirs = [] diff --git a/test/unittest/dataobs_mgr_inner_pref_test/BUILD.gn b/test/unittest/dataobs_mgr_inner_pref_test/BUILD.gn index ed4fbbaaa8..2156c94da4 100644 --- a/test/unittest/dataobs_mgr_inner_pref_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_inner_pref_test/BUILD.gn @@ -17,6 +17,12 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/dataobsmgr" ohos_unittest("dataobs_mgr_inner_pref_test") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } module_out_path = module_output_path include_dirs = [] diff --git a/test/unittest/dataobs_mgr_inner_test/BUILD.gn b/test/unittest/dataobs_mgr_inner_test/BUILD.gn index 0a76be3056..5e699f4455 100644 --- a/test/unittest/dataobs_mgr_inner_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_inner_test/BUILD.gn @@ -17,6 +17,12 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/dataobsmgr" ohos_unittest("dataobs_mgr_inner_test") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } module_out_path = module_output_path include_dirs = [] diff --git a/test/unittest/dataobs_mgr_proxy_test/BUILD.gn b/test/unittest/dataobs_mgr_proxy_test/BUILD.gn index a3be219ac7..07b4bb942e 100644 --- a/test/unittest/dataobs_mgr_proxy_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_proxy_test/BUILD.gn @@ -17,6 +17,12 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/dataobsmgr" ohos_unittest("dataobs_mgr_proxy_test") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } module_out_path = module_output_path include_dirs = [] diff --git a/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn b/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn old mode 100755 new mode 100644 index 953f3a539a..47f09424c2 --- a/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn @@ -17,6 +17,12 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/dataobsmgr" ohos_unittest("dataobs_mgr_service_dump_test") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } module_out_path = module_output_path include_dirs = [ "${ability_runtime_test_path}/mock/common/include" ] diff --git a/test/unittest/dataobs_mgr_service_test/BUILD.gn b/test/unittest/dataobs_mgr_service_test/BUILD.gn index 759a62fe90..1b685b5517 100644 --- a/test/unittest/dataobs_mgr_service_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_service_test/BUILD.gn @@ -17,6 +17,12 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/dataobsmgr" ohos_unittest("dataobs_mgr_service_test") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } module_out_path = module_output_path include_dirs = [ "${distributedschedule_path}/safwk/services/safwk/include" ] diff --git a/test/unittest/dataobs_mgr_stub_test/BUILD.gn b/test/unittest/dataobs_mgr_stub_test/BUILD.gn index 5977c51543..bfef7bdb38 100644 --- a/test/unittest/dataobs_mgr_stub_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_stub_test/BUILD.gn @@ -17,6 +17,12 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/dataobsmgr" ohos_unittest("dataobs_mgr_stub_test") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } module_out_path = module_output_path include_dirs = [] From eff76fae01e4b41dbf11b8ed45fe8d2cfc92c549 Mon Sep 17 00:00:00 2001 From: x00671510 Date: Tue, 28 May 2024 15:01:48 +0800 Subject: [PATCH 04/69] =?UTF-8?q?=E9=9F=B3=E9=A2=91=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=96=B0=E5=A2=9EsysPicker/audioPicker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: x00671510 --- services/abilitymgr/resource/uiextension_picker_config.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/abilitymgr/resource/uiextension_picker_config.json b/services/abilitymgr/resource/uiextension_picker_config.json index bcaf262969..08c333cbd2 100644 --- a/services/abilitymgr/resource/uiextension_picker_config.json +++ b/services/abilitymgr/resource/uiextension_picker_config.json @@ -23,6 +23,10 @@ { "type": "filePicker", "typePicker": "sysPicker/filePicker" + }, + { + "type": "sysPicker", + "typePicker": "sysPicker/audioPicker" } ] } \ No newline at end of file From 087f9d1d0fd1e16a29db9fa0ebc957bd1cf9c467 Mon Sep 17 00:00:00 2001 From: srr101 Date: Tue, 28 May 2024 15:21:36 +0800 Subject: [PATCH 05/69] =?UTF-8?q?=E9=83=A8=E5=88=86=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0blocklist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: srr101 --- .../cfi_blocklist.txt => cfi_blocklist.txt | 0 test/unittest/data_ability_observer_proxy_test/BUILD.gn | 2 +- test/unittest/data_ability_observer_stub_test/BUILD.gn | 1 + test/unittest/dataobs_mgr_service_test/BUILD.gn | 1 + 4 files changed, 3 insertions(+), 1 deletion(-) rename test/unittest/data_ability_observer_proxy_test/cfi_blocklist.txt => cfi_blocklist.txt (100%) diff --git a/test/unittest/data_ability_observer_proxy_test/cfi_blocklist.txt b/cfi_blocklist.txt similarity index 100% rename from test/unittest/data_ability_observer_proxy_test/cfi_blocklist.txt rename to cfi_blocklist.txt diff --git a/test/unittest/data_ability_observer_proxy_test/BUILD.gn b/test/unittest/data_ability_observer_proxy_test/BUILD.gn index e53b4a12e4..816edad365 100644 --- a/test/unittest/data_ability_observer_proxy_test/BUILD.gn +++ b/test/unittest/data_ability_observer_proxy_test/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("data_ability_observer_proxy_test") { cfi = true cfi_cross_dso = true debug = false - blocklist = "./cfi_blocklist.txt" + blocklist = "../../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/data_ability_observer_stub_test/BUILD.gn b/test/unittest/data_ability_observer_stub_test/BUILD.gn index cbb7040b9c..91f366dda4 100644 --- a/test/unittest/data_ability_observer_stub_test/BUILD.gn +++ b/test/unittest/data_ability_observer_stub_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("data_ability_observer_stub_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/dataobs_mgr_service_test/BUILD.gn b/test/unittest/dataobs_mgr_service_test/BUILD.gn index 1b685b5517..c5c5d30378 100644 --- a/test/unittest/dataobs_mgr_service_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_service_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("dataobs_mgr_service_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../../cfi_blocklist.txt" } module_out_path = module_output_path From 426cc2043ac7a9d4600ecceb7007ebadca396110 Mon Sep 17 00:00:00 2001 From: srr101 Date: Tue, 28 May 2024 17:46:02 +0800 Subject: [PATCH 06/69] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=B2=97=E7=B2=92?= =?UTF-8?q?=E5=BA=A6=E5=B1=8F=E8=94=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: srr101 --- cfi_blocklist.txt | 14 ++++++++++++++ test/unittest/dataobs_mgr_client_test/BUILD.gn | 1 + test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn | 1 + test/unittest/dataobs_mgr_inner_pref_test/BUILD.gn | 1 + test/unittest/dataobs_mgr_inner_test/BUILD.gn | 1 + test/unittest/dataobs_mgr_proxy_test/BUILD.gn | 1 + .../dataobs_mgr_service_dump_test/BUILD.gn | 1 + test/unittest/dataobs_mgr_stub_test/BUILD.gn | 1 + 8 files changed, 21 insertions(+) diff --git a/cfi_blocklist.txt b/cfi_blocklist.txt index fddb4e5f3b..7e6de6f7f1 100644 --- a/cfi_blocklist.txt +++ b/cfi_blocklist.txt @@ -1,2 +1,16 @@ +# Copyright (c) 2024 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[cfi] src:*/third_party/googletest/googletest/include/gtest/* src:*/third_party/googletest/googlemock/include/gmock/* \ No newline at end of file diff --git a/test/unittest/dataobs_mgr_client_test/BUILD.gn b/test/unittest/dataobs_mgr_client_test/BUILD.gn index be81692a3e..e817b52d07 100644 --- a/test/unittest/dataobs_mgr_client_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_client_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("dataobs_mgr_client_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn b/test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn index 4631fa97cb..09ffdbeff4 100644 --- a/test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("dataobs_mgr_inner_ext_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/dataobs_mgr_inner_pref_test/BUILD.gn b/test/unittest/dataobs_mgr_inner_pref_test/BUILD.gn index 2156c94da4..48f72f0404 100644 --- a/test/unittest/dataobs_mgr_inner_pref_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_inner_pref_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("dataobs_mgr_inner_pref_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/dataobs_mgr_inner_test/BUILD.gn b/test/unittest/dataobs_mgr_inner_test/BUILD.gn index 5e699f4455..774e06c27b 100644 --- a/test/unittest/dataobs_mgr_inner_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_inner_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("dataobs_mgr_inner_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/dataobs_mgr_proxy_test/BUILD.gn b/test/unittest/dataobs_mgr_proxy_test/BUILD.gn index 07b4bb942e..4d934655de 100644 --- a/test/unittest/dataobs_mgr_proxy_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_proxy_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("dataobs_mgr_proxy_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn b/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn index 47f09424c2..c3edf1e94f 100644 --- a/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("dataobs_mgr_service_dump_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/dataobs_mgr_stub_test/BUILD.gn b/test/unittest/dataobs_mgr_stub_test/BUILD.gn index bfef7bdb38..b4c8ee904f 100644 --- a/test/unittest/dataobs_mgr_stub_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_stub_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("dataobs_mgr_stub_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../../cfi_blocklist.txt" } module_out_path = module_output_path From d65dad2381b8e552156e9816513fb385fc4a90f9 Mon Sep 17 00:00:00 2001 From: huangjieliang Date: Tue, 28 May 2024 20:27:54 +0800 Subject: [PATCH 07/69] =?UTF-8?q?Feature:=20=E6=94=AF=E6=8C=81el5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=8A=A0=E5=AF=86=E5=88=86=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangjieliang Change-Id: Ib98c84e21d68990deaf14cd899c7bcc513e7e349 --- .../application_context_constant_module.cpp | 2 + .../ability_runtime/context/context_impl.cpp | 9 ++-- .../src/ability_stage_context.cpp | 2 +- .../context_impl_test.cpp | 52 ++++++++++++++++++- 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/frameworks/js/napi/application_context_constant/application_context_constant_module.cpp b/frameworks/js/napi/application_context_constant/application_context_constant_module.cpp index 661c7524d3..5bbb4576ac 100644 --- a/frameworks/js/napi/application_context_constant/application_context_constant_module.cpp +++ b/frameworks/js/napi/application_context_constant/application_context_constant_module.cpp @@ -21,6 +21,7 @@ const int32_t CREATE_VALUE_ZERO = 0; const int32_t CREATE_VALUE_ONE = 1; const int32_t CREATE_VALUE_TWO = 2; const int32_t CREATE_VALUE_THREE = 3; +const int32_t CREATE_VALUE_FOUR = 4; static napi_status SetEnumItem(napi_env env, napi_value object, const char* name, int32_t value) { napi_status status; @@ -45,6 +46,7 @@ static napi_value InitAreaModeObject(napi_env env) NAPI_CALL(env, SetEnumItem(env, object, "EL2", CREATE_VALUE_ONE)); NAPI_CALL(env, SetEnumItem(env, object, "EL3", CREATE_VALUE_TWO)); NAPI_CALL(env, SetEnumItem(env, object, "EL4", CREATE_VALUE_THREE)); + NAPI_CALL(env, SetEnumItem(env, object, "EL5", CREATE_VALUE_FOUR)); return object; } diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index 4d0b97849d..0f674266cf 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -71,7 +71,7 @@ const std::string ContextImpl::CONTEXT_DATABASE("database"); const std::string ContextImpl::CONTEXT_TEMP("/temp"); const std::string ContextImpl::CONTEXT_FILES("/files"); const std::string ContextImpl::CONTEXT_HAPS("/haps"); -const std::string ContextImpl::CONTEXT_ELS[] = {"el1", "el2", "el3", "el4"}; +const std::string ContextImpl::CONTEXT_ELS[] = {"el1", "el2", "el3", "el4", "el5"}; const std::string ContextImpl::CONTEXT_RESOURCE_END = "/resources/resfile"; Global::Resource::DeviceType ContextImpl::deviceType_ = Global::Resource::DeviceType::DEVICE_NOT_SET; const std::string OVERLAY_STATE_CHANGED = "usual.event.OVERLAY_STATE_CHANGED"; @@ -82,6 +82,7 @@ const int32_t API_VERSION_MOD = 100; const int32_t ERR_ABILITY_RUNTIME_EXTERNAL_NOT_SYSTEM_HSP = 16400001; const int AREA2 = 2; const int AREA3 = 3; +const int AREA4 = 4; std::string ContextImpl::GetBundleName() const { @@ -328,8 +329,10 @@ std::string ContextImpl::GetDistributedFilesDir() dir = CONTEXT_DISTRIBUTEDFILES_BASE_BEFORE + std::to_string(GetCurrentAccountId()) + CONTEXT_DISTRIBUTEDFILES_BASE_MIDDLE + GetBundleName(); } else { - if (currArea_ == CONTEXT_ELS[1] || currArea_ == CONTEXT_ELS[AREA2] || currArea_ == CONTEXT_ELS[AREA3]) { - //when areamode swith to el3/el4, the distributedfiles dir should be always el2's distributedfilesdir dir + if (currArea_ == CONTEXT_ELS[1] || currArea_ == CONTEXT_ELS[AREA2] || currArea_ == CONTEXT_ELS[AREA3] || + currArea_ == CONTEXT_ELS[AREA4]) { + // when areamode swith to el3/el4/el5, the distributedfiles dir should be always el2's + // distributedfilesdir dir dir = CONTEXT_DATA_STORAGE + CONTEXT_ELS[1] + CONTEXT_FILE_SEPARATOR + CONTEXT_DISTRIBUTEDFILES; } else { dir = CONTEXT_DATA_STORAGE + currArea_ + CONTEXT_FILE_SEPARATOR + CONTEXT_DISTRIBUTEDFILES; diff --git a/frameworks/simulator/ability_simulator/src/ability_stage_context.cpp b/frameworks/simulator/ability_simulator/src/ability_stage_context.cpp index c2dfe5b837..ca90bfb1cb 100644 --- a/frameworks/simulator/ability_simulator/src/ability_stage_context.cpp +++ b/frameworks/simulator/ability_simulator/src/ability_stage_context.cpp @@ -34,7 +34,7 @@ constexpr const char *CONTEXT_TEMP("temp"); constexpr const char *CONTEXT_FILES("files"); constexpr const char *CONTEXT_HAPS("haps"); constexpr const char *CONTEXT_ASSET("asset"); -constexpr const char *CONTEXT_ELS[] = {"el1", "el2", "el3", "el4"}; +constexpr const char *CONTEXT_ELS[] = {"el1", "el2", "el3", "el4", "el5"}; constexpr const char *CONTEXT_RESOURCE_BASE("/data/storage/el1/bundle"); constexpr const char *CONTEXT_RESOURCE_END("/resources/resfile"); constexpr int DIR_DEFAULT_PERM = 0770; diff --git a/test/unittest/frameworks_kits_appkit_native_test/context_impl_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/context_impl_test.cpp index bf34a35a8d..ecc9b76e9b 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/context_impl_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/context_impl_test.cpp @@ -280,6 +280,47 @@ HWTEST_F(ContextImplTest, GetDatabaseDir_0200, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); } +/** + * @tc.name: GetDatabaseDir_0300 + * @tc.desc: Get el5 base directory basic test. + * @tc.type: FUNC + * @tc.require: issuesI9SXYW + */ +HWTEST_F(ContextImplTest, GetDatabaseDir_0300, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__); + auto contextImpl = std::make_shared(); + EXPECT_NE(contextImpl, nullptr); + + // not create by system app and parent context is nullptr + contextImpl->SwitchArea(4); + auto databaseDir = contextImpl->GetDatabaseDir(); + EXPECT_EQ(databaseDir, "/data/storage/el5/database"); + + // create by system app and parent context is not nullptr + contextImpl->SetFlags(CONTEXT_CREATE_BY_SYSTEM_APP); + auto parentContext = std::make_shared(); + EXPECT_NE(parentContext, nullptr); + auto applicationInfo = std::make_shared(); + EXPECT_NE(applicationInfo, nullptr); + applicationInfo->bundleName = "com.test.database"; + parentContext->SetApplicationInfo(applicationInfo); + contextImpl->SetParentContext(parentContext); + contextImpl->SwitchArea(4); + databaseDir = contextImpl->GetDatabaseDir(); + EXPECT_EQ(databaseDir, "/data/app/el5/0/database/com.test.database/"); + + // create by system app and hap module info of parent context is not nullptr + AppExecFwk::HapModuleInfo hapModuleInfo; + hapModuleInfo.moduleName = "test_moduleName"; + contextImpl->InitHapModuleInfo(hapModuleInfo); + contextImpl->SwitchArea(4); + databaseDir = contextImpl->GetDatabaseDir(); + EXPECT_EQ(databaseDir, "/data/app/el5/0/database/com.test.database/test_moduleName"); + + TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); +} + /** * @tc.name: GetPreferencesDir_0100 * @tc.desc: Get preference directory basic test. @@ -379,6 +420,11 @@ HWTEST_F(ContextImplTest, GetDistributedFilesDir_0100, TestSize.Level1) distributedDir = contextImpl->GetDistributedFilesDir(); EXPECT_EQ(distributedDir, "/data/storage/el2/distributedfiles"); + //for areamode is el5, the distributedfiles dir is also el2's distributedfiles dir + contextImpl->SwitchArea(4); + distributedDir = contextImpl->GetDistributedFilesDir(); + EXPECT_EQ(distributedDir, "/data/storage/el2/distributedfiles"); + // create by system app and bundleName is empty contextImpl->SetFlags(CONTEXT_CREATE_BY_SYSTEM_APP); distributedDir = contextImpl->GetDistributedFilesDir(); @@ -457,7 +503,7 @@ HWTEST_F(ContextImplTest, SwitchArea_0100, TestSize.Level1) // invalid mode contextImpl->SwitchArea(-1); - contextImpl->SwitchArea(4); + contextImpl->SwitchArea(5); // valid mode contextImpl->SwitchArea(0); @@ -494,6 +540,10 @@ HWTEST_F(ContextImplTest, GetAreaArea_0100, TestSize.Level1) mode = contextImpl->GetArea(); EXPECT_EQ(mode, 3); + contextImpl->SwitchArea(4); + mode = contextImpl->GetArea(); + EXPECT_EQ(mode, 4); + // invalid area_ contextImpl->currArea_ = "invalid"; mode = contextImpl->GetArea(); From fa5cfa5cff6db4b70a3c93bd265469363f108f43 Mon Sep 17 00:00:00 2001 From: XKK Date: Wed, 29 May 2024 16:05:07 +0800 Subject: [PATCH 08/69] close fd Signed-off-by: XKK --- .../src/scene_board/ui_ability_lifecycle_manager.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp index d7a0b36cbb..8f2a8b88df 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -104,6 +104,8 @@ int UIAbilityLifecycleManager::StartUIAbility(AbilityRequest &abilityRequest, sp if (sessionInfo->isNewWant) { uiAbilityRecord->SetWant(abilityRequest.want); uiAbilityRecord->GetSessionInfo()->want.CloseAllFd(); + } else { + sessionInfo->want.CloseAllFd(); } } else { uiAbilityRecord = CreateAbilityRecord(abilityRequest, sessionInfo); @@ -356,7 +358,9 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(const AbilityRequest &a sessionInfo->processOptions = abilityRequest.processOptions; TAG_LOGI( AAFwkTag::ABILITYMGR, "Reused sessionId: %{public}d, userId: %{public}d.", sessionInfo->persistentId, userId_); - return NotifySCBPendingActivation(sessionInfo, abilityRequest); + int ret = NotifySCBPendingActivation(sessionInfo, abilityRequest); + sessionInfo->want.CloseAllFd(); + return ret; } int UIAbilityLifecycleManager::DispatchState(const std::shared_ptr &abilityRecord, int state) From 359470482d3286c90c82c9c52a3d07333bf2d346 Mon Sep 17 00:00:00 2001 From: zhubingwei Date: Wed, 29 May 2024 15:22:05 +0800 Subject: [PATCH 09/69] =?UTF-8?q?=E3=80=90TDD=E8=A1=A5=E5=85=85=E3=80=91?= =?UTF-8?q?=E7=9B=B8=E5=85=B3API=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhubingwei --- .../js_environment_test.cpp | 12 +++++ .../ability_manager_client_branch_test.cpp | 14 ++++++ .../app_mgr_client_test.cpp | 38 +++++++++++++++ .../application_context_test.cpp | 48 +++++++++++++++++++ .../ability_runtime_test.cpp | 15 ++++++ 5 files changed, 127 insertions(+) diff --git a/js_environment/test/unittest/js_environment_test/js_environment_test.cpp b/js_environment/test/unittest/js_environment_test/js_environment_test.cpp index ce7445f884..b0e905f062 100644 --- a/js_environment/test/unittest/js_environment_test/js_environment_test.cpp +++ b/js_environment/test/unittest/js_environment_test/js_environment_test.cpp @@ -538,5 +538,17 @@ HWTEST_F(JsEnvironmentTest, GetHeapPrepare_0200, TestSize.Level0) jsEnv->GetHeapPrepare(); ASSERT_NE(jsEnv, nullptr); } + +/** + * @tc.name: GetSourceMapOperator_0100 + * @tc.desc: Js environment GetSourceMapOperator. + * @tc.type: FUNC + */ +HWTEST_F(JsEnvironmentTest, GetSourceMapOperator_0100, TestSize.Level0) +{ + auto jsEnv = std::make_shared(std::make_unique()); + jsEnv->GetSourceMapOperator(); + ASSERT_NE(jsEnv, nullptr); +} } // namespace JsEnv } // namespace OHOS diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp b/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp index 7b683da6ac..fbb6b102c1 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp @@ -2620,5 +2620,19 @@ HWTEST_F(AbilityManagerClientBranchTest, AbilityManagerClient_TransferAbilityRes EXPECT_EQ(result, NO_ERROR); GTEST_LOG_(INFO) << "AbilityManagerClient_TransferAbilityResultForExtension_0100 end"; } + +/** + * @tc.name: AbilityManagerClient_SetResidentProcessEnabled_0100 + * @tc.desc: SetResidentProcessEnabled + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerClientBranchTest, AbilityManagerClient_SetResidentProcessEnabled_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityManagerClient_SetResidentProcessEnabled_0100 start"; + bool enable = false; + auto result = client_->SetResidentProcessEnabled(BUNDLE_NAME, enable); + EXPECT_TRUE(client_ != nullptr); + GTEST_LOG_(INFO) << "AbilityManagerClient_SetResidentProcessEnabled_0100 end"; +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp b/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp index 1781f7576d..5be42fec83 100644 --- a/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp +++ b/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp @@ -1344,5 +1344,43 @@ HWTEST_F(AppMgrClientTest, SetSupportedProcessCacheSelf_001, TestSize.Level0) int32_t ret = appMgrClient->SetSupportedProcessCacheSelf(isSupport); EXPECT_NE(appMgrClient, nullptr); } + +/** + * @tc.name: AppMgrClient_AttachRenderProcess_001 + * @tc.desc: AttachRenderProcess. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrClientTest, AttachRenderProcess_001, TestSize.Level0) +{ + auto appMgrClient = std::make_unique(); + appMgrClient->AttachRenderProcess(nullptr); + EXPECT_NE(appMgrClient, nullptr); +} + +/** + * @tc.name: AppMgrClient_SetKeepAliveEnableState_001 + * @tc.desc: SetKeepAliveEnableState. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrClientTest, SetKeepAliveEnableState_001, TestSize.Level0) +{ + auto appMgrClient = std::make_unique(); + std::string bundleName = "com.ix.First.Test"; + bool enable = false; + appMgrClient->SetKeepAliveEnableState(bundleName, enable); + EXPECT_NE(appMgrClient, nullptr); +} + +/** + * @tc.name: AppMgrClient_SaveBrowserChannel_001 + * @tc.desc: SaveBrowserChannel. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrClientTest, SaveBrowserChannel_001, TestSize.Level0) +{ + auto appMgrClient = std::make_unique(); + appMgrClient->SaveBrowserChannel(nullptr); + EXPECT_NE(appMgrClient, nullptr); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/application_context_test/application_context_test.cpp b/test/unittest/application_context_test/application_context_test.cpp index 91f81a71c7..1c82a5896a 100644 --- a/test/unittest/application_context_test/application_context_test.cpp +++ b/test/unittest/application_context_test/application_context_test.cpp @@ -1268,5 +1268,53 @@ HWTEST_F(ApplicationContextTest, SetSupportedProcessCacheSelf_0100, TestSize.Lev int32_t res = context_->SetSupportedProcessCacheSelf(isSupport); EXPECT_EQ(res, OHOS::ERR_INVALID_VALUE); } + +/** + * @tc.number: GetCurrentAppCloneIndex_0100 + * @tc.name: GetCurrentAppCloneIndex + * @tc.desc: GetCurrentAppCloneIndex fail with no permission + */ +HWTEST_F(ApplicationContextTest, GetCurrentAppCloneIndex_0100, TestSize.Level1) +{ + int32_t res = context_->GetCurrentAppCloneIndex(); + EXPECT_EQ(res, 0); +} + +/** + * @tc.number: SetCurrentAppCloneIndex_0100 + * @tc.name: SetCurrentAppCloneIndex + * @tc.desc: SetCurrentAppCloneIndex fail with no permission + */ +HWTEST_F(ApplicationContextTest, SetCurrentAppCloneIndex_0100, TestSize.Level1) +{ + int32_t appIndex = 3; + context_->SetCurrentAppCloneIndex(appIndex); + int32_t res = context_->GetCurrentAppCloneIndex(); + EXPECT_EQ(res, appIndex); +} + +/** + * @tc.number: GetCurrentAppMode_0100 + * @tc.name: GetCurrentAppMode + * @tc.desc: GetCurrentAppMode fail with no permission + */ +HWTEST_F(ApplicationContextTest, GetCurrentAppMode_0100, TestSize.Level1) +{ + int32_t res = context_->GetCurrentAppMode(); + EXPECT_EQ(res, 0); +} + +/** + * @tc.number:SetCurrentAppMode_0100 + * @tc.name: SetCurrentAppMode + * @tc.desc: SetCurrentAppMode fail with no permission + */ +HWTEST_F(ApplicationContextTest, SetCurrentAppMode_0100, TestSize.Level1) +{ + int32_t appMode = 7; + context_->SetCurrentAppMode(appMode); + int32_t res = context_->GetCurrentAppMode(); + EXPECT_EQ(res, appMode); +} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/frameworks_kits_ability_native_test/ability_runtime_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ability_runtime_test.cpp index 7ea213c7f2..4f71c6b056 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ability_runtime_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ability_runtime_test.cpp @@ -114,5 +114,20 @@ HWTEST_F(RuntimeTest, GetPreloaded_0100, TestSize.Level0) EXPECT_TRUE(runtime->GetPreloaded() != nullptr); GTEST_LOG_(INFO) << "RuntimeTest GetPreloaded_0100 end"; } + +/** + * @tc.number: SetModuleLoadChecker_0100 + * @tc.name: SetModuleLoadChecker + * @tc.desc: Runtime test for SetModuleLoadChecker, runtime is not nullptr. + */ +HWTEST_F(RuntimeTest, SetModuleLoadChecker_0100, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "RuntimeTest SetModuleLoadChecker_0100 start"; + Runtime::Options options; + std::unique_ptr runtime = std::make_unique(); + runtime->SetModuleLoadChecker(nullptr); + EXPECT_TRUE(runtime != nullptr); + GTEST_LOG_(INFO) << "RuntimeTest SetModuleLoadChecker_0100 end"; +} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file From d3d2b1ae8580ab8fb1d2fc5768292ca985885840 Mon Sep 17 00:00:00 2001 From: zhubingwei Date: Wed, 22 May 2024 19:27:30 +0800 Subject: [PATCH 10/69] =?UTF-8?q?dataobs=5Fmgr=5Finner=5Fpref=5Ftest?= =?UTF-8?q?=E5=92=8Cdataobs=5Fmgr=5Finner=5Ftest=20tdd=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E7=8E=87=E4=BF=AE=E6=94=B9=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhubingwei --- .../dataobs_mgr_inner_pref_test.cpp | 4 +--- .../dataobs_mgr_inner_test/dataobs_mgr_inner_test.cpp | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/test/unittest/dataobs_mgr_inner_pref_test/dataobs_mgr_inner_pref_test.cpp b/test/unittest/dataobs_mgr_inner_pref_test/dataobs_mgr_inner_pref_test.cpp index 823e9f1c9e..1cacae4d06 100644 --- a/test/unittest/dataobs_mgr_inner_pref_test/dataobs_mgr_inner_pref_test.cpp +++ b/test/unittest/dataobs_mgr_inner_pref_test/dataobs_mgr_inner_pref_test.cpp @@ -45,7 +45,7 @@ void DataObsMgrInnerPrefTest::SetUpTestCase(void) {} void DataObsMgrInnerPrefTest::TearDownTestCase(void) {} void DataObsMgrInnerPrefTest::SetUp() { - std::shared_ptr dataObsMgrInnerPref_ = std::make_shared(); + dataObsMgrInnerPref_ = std::make_shared(); } void DataObsMgrInnerPrefTest::TearDown() {} @@ -272,14 +272,12 @@ HWTEST_F(DataObsMgrInnerPrefTest, DataObsMgrInnerPref_RemoveObs_HaveRegistered_0 EXPECT_EQ(false, dataObsMgrInnerPref_->HaveRegistered(callback)); obsPair->second.clear(); obsPair = dataObsMgrInnerPref_->observers_.find(uri.ToString()); - EXPECT_EQ((std::size_t)1, obsPair->second.size()); EXPECT_EQ(false, dataObsMgrInnerPref_->HaveRegistered(callback)); dataObsMgrInnerPref_->RemoveObs(callback2->AsObject()); EXPECT_EQ(false, dataObsMgrInnerPref_->HaveRegistered(callback2)); obsPair->second.clear(); obsPair = dataObsMgrInnerPref_->observers_.find(uri.ToString()); - EXPECT_EQ((std::size_t)0, obsPair->second.size()); EXPECT_EQ(false, dataObsMgrInnerPref_->HaveRegistered(callback2)); } diff --git a/test/unittest/dataobs_mgr_inner_test/dataobs_mgr_inner_test.cpp b/test/unittest/dataobs_mgr_inner_test/dataobs_mgr_inner_test.cpp index d964dab037..33f2b90e8d 100644 --- a/test/unittest/dataobs_mgr_inner_test/dataobs_mgr_inner_test.cpp +++ b/test/unittest/dataobs_mgr_inner_test/dataobs_mgr_inner_test.cpp @@ -45,7 +45,7 @@ void DataObsMgrInnerTest::SetUpTestCase(void) {} void DataObsMgrInnerTest::TearDownTestCase(void) {} void DataObsMgrInnerTest::SetUp() { - std::shared_ptr dataObsMgrInner_ = std::make_shared(); + dataObsMgrInner_ = std::make_shared(); } void DataObsMgrInnerTest::TearDown() {} @@ -272,14 +272,12 @@ HWTEST_F(DataObsMgrInnerTest, DataObsMgrInner_RemoveObs_HaveRegistered_0100, Tes EXPECT_EQ(false, dataObsMgrInner_->HaveRegistered(callback)); obsPair->second.clear(); obsPair = dataObsMgrInner_->observers_.find(uri.ToString()); - EXPECT_EQ((std::size_t)1, obsPair->second.size()); EXPECT_EQ(false, dataObsMgrInner_->HaveRegistered(callback)); dataObsMgrInner_->RemoveObs(callback2->AsObject()); EXPECT_EQ(false, dataObsMgrInner_->HaveRegistered(callback2)); obsPair->second.clear(); obsPair = dataObsMgrInner_->observers_.find(uri.ToString()); - EXPECT_EQ((std::size_t)0, obsPair->second.size()); EXPECT_EQ(false, dataObsMgrInner_->HaveRegistered(callback2)); } From 45a1af75fbae056d369632618eccdb8fe9b37ac5 Mon Sep 17 00:00:00 2001 From: zhubingwei Date: Fri, 24 May 2024 18:26:13 +0800 Subject: [PATCH 11/69] =?UTF-8?q?dump=5Fipc=5Fhelper=5Ftest=E3=80=81extens?= =?UTF-8?q?ion=5Fplugin=5Finfo=5Ftest=E3=80=81idle=5Ftime=5Ftest=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhubingwei --- .../BUILD.gn | 84 ++++++++++ .../dump_ipc_helper_test.cpp | 99 ++++++++++++ .../extension_plugin_info_test.cpp | 148 ++++++++++++++++++ .../idle_time_test.cpp | 137 ++++++++++++++++ 4 files changed, 468 insertions(+) create mode 100644 test/unittest/frameworks_kits_appkit_native_test/dump_ipc_helper_test.cpp create mode 100644 test/unittest/frameworks_kits_appkit_native_test/extension_plugin_info_test.cpp create mode 100644 test/unittest/frameworks_kits_appkit_native_test/idle_time_test.cpp diff --git a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn index 30ad2c07cd..1765794194 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn @@ -585,6 +585,87 @@ ohos_unittest("assert_fault_test") { } } +ohos_unittest("dump_ipc_helper_test") { + include_dirs = [] + module_out_path = module_output_path + sources = [ + "${ability_runtime_native_path}/appkit/app/dump_ipc_helper.cpp", + "dump_ipc_helper_test.cpp", + ] + + configs = [ ":module_context_config" ] + + deps = [ + "${ability_runtime_native_path}/appkit:appkit_native", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_runtime:runtime", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + "napi:ace_napi", + ] +} + +config("appkit_exception_config") { + cflags_cc = [ "-fexceptions" ] +} + +ohos_unittest("extension_plugin_info_test") { + module_out_path = module_output_path + sources = [ + "${ability_runtime_native_path}/appkit/app/extension_plugin_info.cpp", + "extension_plugin_info_test.cpp", + ] + + configs = [ + ":module_context_config", + ":appkit_exception_config", + ] + + deps = [ + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/appkit:appkit_native", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:string_utils", + "ability_runtime:runtime", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + "napi:ace_napi", + ] +} + +ohos_unittest("idle_time_test") { + module_out_path = module_output_path + sources = [ + "${ability_runtime_native_path}/appkit/app/idle_time.cpp", + "idle_time_test.cpp", + ] + + configs = [ ":module_context_config" ] + + deps = [ + "${ability_runtime_native_path}/appkit:appkit_native", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_runtime:runtime", + "c_utils:utils", + "eventhandler:libeventhandler", + "graphic_2d:librender_service_client", + "hilog:libhilog", + "ipc:ipc_core", + "napi:ace_napi", + ] +} + ############################################################################### group("unittest") { @@ -601,7 +682,10 @@ group("unittest") { ":context_container_by_mock_bms_test", ":context_container_test", ":context_deal_test", + ":dump_ipc_helper_test", + ":extension_plugin_info_test", ":form_extension_context_test", + ":idle_time_test", ] deps += [ "ability_delegator:unittest" ] diff --git a/test/unittest/frameworks_kits_appkit_native_test/dump_ipc_helper_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/dump_ipc_helper_test.cpp new file mode 100644 index 0000000000..153ac807fe --- /dev/null +++ b/test/unittest/frameworks_kits_appkit_native_test/dump_ipc_helper_test.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#define private public +#define protected public +#include "dump_ipc_helper.h" +#undef private +#undef protected + +using namespace testing::ext; + +namespace OHOS { +namespace AppExecFwk { +class DumpIpcHelperTest : public testing::Test { +public: + DumpIpcHelperTest() + {} + ~DumpIpcHelperTest() + {} + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void DumpIpcHelperTest::SetUpTestCase(void) +{} + +void DumpIpcHelperTest::TearDownTestCase(void) +{} + +void DumpIpcHelperTest::SetUp(void) +{} + +void DumpIpcHelperTest::TearDown(void) +{} + +/** + * @tc.number: DumpIpcStart_0100 + * @tc.name: DumpIpcStart + * @tc.desc: Test whether DumpIpcStart and are called normally. + */ +HWTEST_F(DumpIpcHelperTest, DumpIpcStart_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "DumpIpcHelperTest DumpIpcStart_0100 start"; + std::string result = ""; + DumpIpcHelper::DumpIpcStart(result); + EXPECT_NE(result, ""); + + GTEST_LOG_(INFO) << "DumpIpcHelperTest DumpIpcStart_0100 end"; +} + +/** + * @tc.number: DumpIpcStop_0100 + * @tc.name: DumpIpcStop + * @tc.desc: Test whether DumpIpcStop and are called normally. + */ +HWTEST_F(DumpIpcHelperTest, DumpIpcStop_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "DumpIpcHelperTest DumpIpcStop_0100 start"; + std::string result = ""; + DumpIpcHelper::DumpIpcStop(result); + EXPECT_NE(result, ""); + + GTEST_LOG_(INFO) << "DumpIpcHelperTest DumpIpcStop_0100 end"; +} + +/** + * @tc.number: DumpIpcStat_0100 + * @tc.name: DumpIpcStat + * @tc.desc: Test whether DumpIpcStat and are called normally. + */ +HWTEST_F(DumpIpcHelperTest, DumpIpcStat_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "DumpIpcHelperTest DumpIpcStat_0100 start"; + std::string result = ""; + DumpIpcHelper::DumpIpcStat(result); + EXPECT_NE(result, ""); + + GTEST_LOG_(INFO) << "DumpIpcHelperTest DumpIpcStat_0100 end"; +} + +} +} \ No newline at end of file diff --git a/test/unittest/frameworks_kits_appkit_native_test/extension_plugin_info_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/extension_plugin_info_test.cpp new file mode 100644 index 0000000000..66ed87920b --- /dev/null +++ b/test/unittest/frameworks_kits_appkit_native_test/extension_plugin_info_test.cpp @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#define private public +#define protected public +#include "extension_plugin_info.h" +#include "file_ex.h" +#undef private +#undef protected + +using namespace testing::ext; +using namespace OHOS::AbilityRuntime; + +namespace OHOS { +namespace AppExecFwk { +class ExtensionPluginInfoTest : public testing::Test { +public: + ExtensionPluginInfoTest() + {} + ~ExtensionPluginInfoTest() + {} + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ExtensionPluginInfoTest::SetUpTestCase(void) +{} + +void ExtensionPluginInfoTest::TearDownTestCase(void) +{} + +void ExtensionPluginInfoTest::SetUp(void) +{} + +void ExtensionPluginInfoTest::TearDown(void) +{} + +/** + * @tc.number: Preload_0100 + * @tc.name: Preload + * @tc.desc: Test whether Preload and are called normally. + */ +HWTEST_F(ExtensionPluginInfoTest, Preload_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "ExtensionPluginInfoTest Preload_0100 start"; + ExtensionPluginInfo::GetInstance().Preload(); + + GTEST_LOG_(INFO) << "ExtensionPluginInfoTest Preload_0100 end"; +} + +/** + * @tc.number: GetExtensionPlugins_0100 + * @tc.name: GetExtensionPlugins + * @tc.desc: Test whether GetExtensionPlugins and are called normally. + */ +HWTEST_F(ExtensionPluginInfoTest, GetExtensionPlugins_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "ExtensionPluginInfoTest GetExtensionPlugins_0100 start"; + ExtensionPluginInfo::GetInstance().extensionPlugins_.clear(); + auto extensionPlugins = ExtensionPluginInfo::GetInstance().GetExtensionPlugins(); + EXPECT_EQ(extensionPlugins.size(), 0); + + GTEST_LOG_(INFO) << "ExtensionPluginInfoTest GetExtensionPlugins_0100 end"; +} + +/** + * @tc.number: ScanExtensions_0100 + * @tc.name: ScanExtensions + * @tc.desc: Test whether ScanExtensions and are called normally. + */ +HWTEST_F(ExtensionPluginInfoTest, ScanExtensions_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "ExtensionPluginInfoTest ScanExtensions_0100 start"; + std::vector files; + bool res = ExtensionPluginInfo::GetInstance().ScanExtensions(files); + if (OHOS::FileExists("system/lib/extensionability")) { + EXPECT_EQ(res, true); + EXPECT_NE(files.size(), 0); + } else { + EXPECT_EQ(res, false); + EXPECT_EQ(files.size(), 0); + } + + GTEST_LOG_(INFO) << "ExtensionPluginInfoTest ScanExtensions_0100 end"; +} + +/** + * @tc.number: ParseExtensions_0100 + * @tc.name: ParseExtensions + * @tc.desc: Test whether ParseExtensions and are called normally. + */ +HWTEST_F(ExtensionPluginInfoTest, ParseExtensions_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "ExtensionPluginInfoTest ParseExtensions_0100 start"; + std::vector files; + bool res = ExtensionPluginInfo::GetInstance().ScanExtensions(files); + if (OHOS::FileExists("system/lib/extensionability")) { + EXPECT_EQ(res, true); + EXPECT_NE(files.size(), 0); + } else { + EXPECT_EQ(res, false); + EXPECT_EQ(files.size(), 0); + } + ExtensionPluginInfo::GetInstance().ParseExtensions(files); + GTEST_LOG_(INFO) << "ExtensionPluginInfoTest ParseExtensions_0100 end"; +} + +/** + * @tc.number: CheckFileType_0100 + * @tc.name: CheckFileType + * @tc.desc: Test whether CheckFileType and are called normally. + */ +HWTEST_F(ExtensionPluginInfoTest, CheckFileType_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "ExtensionPluginInfoTest CheckFileType_0100 start"; + std::string fileName = ""; + bool res = ExtensionPluginInfo::GetInstance().CheckFileType(fileName, ".so"); + EXPECT_EQ(res, false); + + fileName = "ability"; + res = ExtensionPluginInfo::GetInstance().CheckFileType(fileName, ".so"); + EXPECT_EQ(res, false); + + fileName = "ability.so"; + res = ExtensionPluginInfo::GetInstance().CheckFileType(fileName, ".so"); + EXPECT_EQ(res, true); + + GTEST_LOG_(INFO) << "ExtensionPluginInfoTest CheckFileType_0100 end"; +} +} +} \ No newline at end of file diff --git a/test/unittest/frameworks_kits_appkit_native_test/idle_time_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/idle_time_test.cpp new file mode 100644 index 0000000000..3aa34a21f3 --- /dev/null +++ b/test/unittest/frameworks_kits_appkit_native_test/idle_time_test.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#define private public +#define protected public +#include "idle_time.h" +#include "main_thread.h" +#undef private +#undef protected + +using namespace testing::ext; +using namespace OHOS::AbilityRuntime; + +namespace OHOS { +namespace AppExecFwk { +class IdleTimeTest : public testing::Test { +public: + IdleTimeTest() + { + std::function callback = nullptr; + std::shared_ptr mainHandler = std::make_shared(EventRunner::GetMainEventRunner()); + idleTime_ = std::make_shared(mainHandler, callback); + } + ~IdleTimeTest() + {} + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + std::shared_ptr idleTime_ = nullptr; +}; + +void IdleTimeTest::SetUpTestCase(void) +{ +} + +void IdleTimeTest::TearDownTestCase(void) +{} + +void IdleTimeTest::SetUp(void) +{ +} + +void IdleTimeTest::TearDown(void) +{} + +/** + * @tc.number: Preload_0100 + * @tc.name: Preload + * @tc.desc: Test whether Preload and are called normally. + */ +HWTEST_F(IdleTimeTest, Preload_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "IdleTimeTest Preload_0100 start"; + + int64_t time = 0; + time = idleTime_->GetSysTimeNs(); + EXPECT_NE(time, 0); + + GTEST_LOG_(INFO) << "IdleTimeTest Preload_0100 end"; +} + +/** + * @tc.number: InitVSyncReceiver_0100 + * @tc.name: InitVSyncReceiver + * @tc.desc: Test whether InitVSyncReceiver and are called normally. + */ +HWTEST_F(IdleTimeTest, InitVSyncReceiver_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "IdleTimeTest InitVSyncReceiver_0100 start"; + idleTime_->needStop_ = true; + idleTime_->receiver_ = nullptr; + idleTime_->InitVSyncReceiver(); + EXPECT_EQ(idleTime_->receiver_, nullptr); + GTEST_LOG_(INFO) << "IdleTimeTest InitVSyncReceiver_0100 end"; +} + +/** + * @tc.number: EventTask_0100 + * @tc.name: EventTask + * @tc.desc: Test whether EventTask and are called normally. + */ +HWTEST_F(IdleTimeTest, EventTask_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "IdleTimeTest EventTask_0100 start"; + idleTime_->needStop_ = false; + idleTime_->EventTask(); + EXPECT_EQ(idleTime_->callback_, nullptr); + + GTEST_LOG_(INFO) << "IdleTimeTest EventTask_0100 end"; +} + +/** + * @tc.number: PostTask_0100 + * @tc.name: PostTask + * @tc.desc: Test whether PostTask and are called normally. + */ +HWTEST_F(IdleTimeTest, PostTask_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "IdleTimeTest PostTask_0100 start"; + idleTime_->needStop_ = true; + idleTime_->PostTask(); + EXPECT_NE(idleTime_->eventHandler_, nullptr); + + GTEST_LOG_(INFO) << "IdleTimeTest PostTask_0100 end"; +} + +/** + * @tc.number: GetIdleNotifyFunc_0100 + * @tc.name: GetIdleNotifyFunc + * @tc.desc: Test whether GetIdleNotifyFunc and are called normally. + */ +HWTEST_F(IdleTimeTest, GetIdleNotifyFunc_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "IdleTimeTest GetIdleNotifyFunc_0100 start"; + IdleNotifyStatusCallback callBack = idleTime_->GetIdleNotifyFunc(); + EXPECT_NE(callBack, nullptr); + + GTEST_LOG_(INFO) << "IdleTimeTest GetIdleNotifyFunc_0100 end"; +} +} +} \ No newline at end of file From cde96f67e4a2e13e9a9c6738039f3ee5abad88b3 Mon Sep 17 00:00:00 2001 From: srr101 Date: Thu, 30 May 2024 15:15:11 +0800 Subject: [PATCH 12/69] =?UTF-8?q?=E7=A7=BB=E5=8A=A8blocklist=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: srr101 --- cfi_blocklist.txt => test/cfi_blocklist.txt | 0 test/unittest/data_ability_observer_proxy_test/BUILD.gn | 2 +- test/unittest/data_ability_observer_stub_test/BUILD.gn | 2 +- test/unittest/dataobs_mgr_client_test/BUILD.gn | 2 +- test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn | 2 +- test/unittest/dataobs_mgr_inner_pref_test/BUILD.gn | 2 +- test/unittest/dataobs_mgr_inner_test/BUILD.gn | 2 +- test/unittest/dataobs_mgr_proxy_test/BUILD.gn | 2 +- test/unittest/dataobs_mgr_service_dump_test/BUILD.gn | 2 +- test/unittest/dataobs_mgr_service_test/BUILD.gn | 2 +- test/unittest/dataobs_mgr_stub_test/BUILD.gn | 2 +- 11 files changed, 10 insertions(+), 10 deletions(-) rename cfi_blocklist.txt => test/cfi_blocklist.txt (100%) diff --git a/cfi_blocklist.txt b/test/cfi_blocklist.txt similarity index 100% rename from cfi_blocklist.txt rename to test/cfi_blocklist.txt diff --git a/test/unittest/data_ability_observer_proxy_test/BUILD.gn b/test/unittest/data_ability_observer_proxy_test/BUILD.gn index 816edad365..e22237a672 100644 --- a/test/unittest/data_ability_observer_proxy_test/BUILD.gn +++ b/test/unittest/data_ability_observer_proxy_test/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("data_ability_observer_proxy_test") { cfi = true cfi_cross_dso = true debug = false - blocklist = "../../../cfi_blocklist.txt" + blocklist = "../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/data_ability_observer_stub_test/BUILD.gn b/test/unittest/data_ability_observer_stub_test/BUILD.gn index 91f366dda4..556dbef5ca 100644 --- a/test/unittest/data_ability_observer_stub_test/BUILD.gn +++ b/test/unittest/data_ability_observer_stub_test/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("data_ability_observer_stub_test") { cfi = true cfi_cross_dso = true debug = false - blocklist = "../../../cfi_blocklist.txt" + blocklist = "../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/dataobs_mgr_client_test/BUILD.gn b/test/unittest/dataobs_mgr_client_test/BUILD.gn index e817b52d07..e6990f393e 100644 --- a/test/unittest/dataobs_mgr_client_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_client_test/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("dataobs_mgr_client_test") { cfi = true cfi_cross_dso = true debug = false - blocklist = "../../../cfi_blocklist.txt" + blocklist = "../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn b/test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn index 09ffdbeff4..6898aba459 100644 --- a/test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("dataobs_mgr_inner_ext_test") { cfi = true cfi_cross_dso = true debug = false - blocklist = "../../../cfi_blocklist.txt" + blocklist = "../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/dataobs_mgr_inner_pref_test/BUILD.gn b/test/unittest/dataobs_mgr_inner_pref_test/BUILD.gn index 48f72f0404..b8824ad922 100644 --- a/test/unittest/dataobs_mgr_inner_pref_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_inner_pref_test/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("dataobs_mgr_inner_pref_test") { cfi = true cfi_cross_dso = true debug = false - blocklist = "../../../cfi_blocklist.txt" + blocklist = "../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/dataobs_mgr_inner_test/BUILD.gn b/test/unittest/dataobs_mgr_inner_test/BUILD.gn index 774e06c27b..94e5eb00a3 100644 --- a/test/unittest/dataobs_mgr_inner_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_inner_test/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("dataobs_mgr_inner_test") { cfi = true cfi_cross_dso = true debug = false - blocklist = "../../../cfi_blocklist.txt" + blocklist = "../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/dataobs_mgr_proxy_test/BUILD.gn b/test/unittest/dataobs_mgr_proxy_test/BUILD.gn index 4d934655de..44eb1a2731 100644 --- a/test/unittest/dataobs_mgr_proxy_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_proxy_test/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("dataobs_mgr_proxy_test") { cfi = true cfi_cross_dso = true debug = false - blocklist = "../../../cfi_blocklist.txt" + blocklist = "../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn b/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn index c3edf1e94f..fc7e7c1dd1 100644 --- a/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("dataobs_mgr_service_dump_test") { cfi = true cfi_cross_dso = true debug = false - blocklist = "../../../cfi_blocklist.txt" + blocklist = "../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/dataobs_mgr_service_test/BUILD.gn b/test/unittest/dataobs_mgr_service_test/BUILD.gn index c5c5d30378..537f54bf67 100644 --- a/test/unittest/dataobs_mgr_service_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_service_test/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("dataobs_mgr_service_test") { cfi = true cfi_cross_dso = true debug = false - blocklist = "../../../cfi_blocklist.txt" + blocklist = "../../cfi_blocklist.txt" } module_out_path = module_output_path diff --git a/test/unittest/dataobs_mgr_stub_test/BUILD.gn b/test/unittest/dataobs_mgr_stub_test/BUILD.gn index b4c8ee904f..0a2374e52e 100644 --- a/test/unittest/dataobs_mgr_stub_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_stub_test/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("dataobs_mgr_stub_test") { cfi = true cfi_cross_dso = true debug = false - blocklist = "../../../cfi_blocklist.txt" + blocklist = "../../cfi_blocklist.txt" } module_out_path = module_output_path From 650df423bd366c300f1972980bc062b3f9b91e29 Mon Sep 17 00:00:00 2001 From: zhubingwei Date: Thu, 30 May 2024 16:51:25 +0800 Subject: [PATCH 13/69] =?UTF-8?q?=E3=80=90TDD=E8=A1=A5=E5=85=85=E3=80=91?= =?UTF-8?q?=E7=9B=B8=E5=85=B3API=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhubingwei --- .../start_options_test/start_options_test.cpp | 14 +++++++ .../trigger_Info_test/trigger_Info_test.cpp | 15 +++++++ .../want_agent_test/want_agent_test.cpp | 41 +++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/test/unittest/start_options_test/start_options_test.cpp b/test/unittest/start_options_test/start_options_test.cpp index c3597ec05c..a8ad63f60a 100755 --- a/test/unittest/start_options_test/start_options_test.cpp +++ b/test/unittest/start_options_test/start_options_test.cpp @@ -108,5 +108,19 @@ HWTEST_F(StartOptionsTest, start_options_test_002, TestSize.Level1) ret = startOptions.GetWindowFocused(); EXPECT_FALSE(ret); } + +/** + * @tc.name: start_options_test_003 + * @tc.desc: test class StartOptions &operator= function + * @tc.type: FUNC + */ +HWTEST_F(StartOptionsTest, start_options_test_003, TestSize.Level1) +{ + StartOptions firstStartOptions; + int32_t windowMode = 10; + firstStartOptions.SetWindowMode(windowMode); + StartOptions secondStartOptions = firstStartOptions; + EXPECT_EQ(secondStartOptions.GetWindowMode(), firstStartOptions.windowMode_); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/trigger_Info_test/trigger_Info_test.cpp b/test/unittest/trigger_Info_test/trigger_Info_test.cpp index 8d173ac7f1..7286916e7d 100644 --- a/test/unittest/trigger_Info_test/trigger_Info_test.cpp +++ b/test/unittest/trigger_Info_test/trigger_Info_test.cpp @@ -29,6 +29,7 @@ #include "want_params.h" #include "want_receiver_stub.h" #include "bool_wrapper.h" +#include "start_options.h" using namespace testing::ext; using namespace OHOS::AAFwk; @@ -223,6 +224,20 @@ HWTEST_F(TriggerInfoTest, TriggerInfo_0800, Function | MediumTest | Level1) EXPECT_EQ(info->resultCode_, resultCode); } + +/* + * @tc.number : TriggerInfo_0900 + * @tc.name : TriggerInfo::Builder SetStartOptions + * @tc.desc : 1.SetStartOptions + */ +HWTEST_F(TriggerInfoTest, TriggerInfo_0900, Function | MediumTest | Level1) +{ + std::shared_ptr builder = std::make_shared(); + std::shared_ptr startOptions = std::make_shared(); + builder->SetStartOptions(startOptions); + EXPECT_EQ(builder->startOptions_->GetWindowMode(), 0); +} + /* * @tc.number : TriggerInfo_0100 * @tc.name : TriggerInfo Constructors diff --git a/test/unittest/want_agent_test/want_agent_test.cpp b/test/unittest/want_agent_test/want_agent_test.cpp index bc25baab97..f60bb094f9 100644 --- a/test/unittest/want_agent_test/want_agent_test.cpp +++ b/test/unittest/want_agent_test/want_agent_test.cpp @@ -197,4 +197,45 @@ HWTEST_F(WantAgentTest, ProcessOptionsTest_0500, TestSize.Level1) option->IsNewProcessMode(value); EXPECT_NE(option, nullptr); } + +/* + * @tc.number : ProcessOptionsTest_0600 + * @tc.name : IsAttachToStatusBarMode + * @tc.desc : IsAttachToStatusBarMode + */ +HWTEST_F(WantAgentTest, ProcessOptionsTest_0600, TestSize.Level1) +{ + auto option = std::make_shared(); + ProcessMode value = ProcessMode::NEW_PROCESS_ATTACH_TO_STATUS_BAR_ITEM; + bool ret = option->IsAttachToStatusBarMode(value); + EXPECT_EQ(ret, true); +} + + +/* + * @tc.number : ProcessOptionsTest_0700 + * @tc.name : IsAttachToStatusBarMode + * @tc.desc : IsAttachToStatusBarMode + */ +HWTEST_F(WantAgentTest, ProcessOptionsTest_0700, TestSize.Level1) +{ + auto option = std::make_shared(); + ProcessMode value = ProcessMode::ATTACH_TO_STATUS_BAR_ITEM; + bool ret = option->IsAttachToStatusBarMode(value); + EXPECT_EQ(ret, true); +} + + +/* + * @tc.number : ProcessOptionsTest_0800 + * @tc.name : IsAttachToStatusBarMode + * @tc.desc : IsAttachToStatusBarMode + */ +HWTEST_F(WantAgentTest, ProcessOptionsTest_0800, TestSize.Level1) +{ + auto option = std::make_shared(); + ProcessMode value = ProcessMode::UNSPECIFIED; + bool ret = option->IsAttachToStatusBarMode(value); + EXPECT_EQ(ret, false); +} } // namespace OHOS::AbilityRuntime::WantAgent From b93b7dcab8139ed161f7e695930249889d766edf Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Thu, 30 May 2024 17:23:05 +0800 Subject: [PATCH 14/69] Issue: https://gitee.com/openharmony/ability_ability_runtime/issues/I9TJEE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Comment: 独立编译整改 Signed-off-by: jiangzhijun8 --- frameworks/native/ability/native/BUILD.gn | 2 ++ frameworks/native/appkit/BUILD.gn | 5 ++++- interfaces/inner_api/auto_fill_manager/BUILD.gn | 1 + interfaces/inner_api/wantagent/BUILD.gn | 2 -- js_environment/frameworks/js_environment/BUILD.gn | 5 +---- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 28729108bd..19a7eae8e4 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -148,8 +148,10 @@ ohos_shared_library("abilitykit_utils") { "bundle_framework:appexecfwk_base", "c_utils:utils", "eventhandler:libeventhandler", + "graphic_2d:2d_graphics", "hilog:libhilog", "hitrace:hitrace_meter", + "ipc:ipc_core", "ipc:ipc_napi", "json:nlohmann_json_static", "napi:ace_napi", diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index bbcde25f9d..369ed9a040 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -499,7 +499,10 @@ ohos_shared_library("application_context_manager") { cflags += [ "-DBINDER_IPC_32BIT" ] } - external_deps = [ "napi:ace_napi" ] + external_deps = [ + "ets_runtime:libark_jsruntime", + "napi:ace_napi", + ] public_configs = [ ":application_context_manager_config" ] diff --git a/interfaces/inner_api/auto_fill_manager/BUILD.gn b/interfaces/inner_api/auto_fill_manager/BUILD.gn index 1174cfa84b..90f33ca340 100644 --- a/interfaces/inner_api/auto_fill_manager/BUILD.gn +++ b/interfaces/inner_api/auto_fill_manager/BUILD.gn @@ -50,6 +50,7 @@ ohos_shared_library("auto_fill_manager") { "eventhandler:libeventhandler", "hilog:libhilog", "init:libbegetutil", + "ipc:ipc_core", ] if (ability_runtime_graphics) { diff --git a/interfaces/inner_api/wantagent/BUILD.gn b/interfaces/inner_api/wantagent/BUILD.gn index bcc4d00546..ee0b960139 100644 --- a/interfaces/inner_api/wantagent/BUILD.gn +++ b/interfaces/inner_api/wantagent/BUILD.gn @@ -66,8 +66,6 @@ ohos_shared_library("wantagent_innerkits") { "src/want_agent_log_wrapper.cpp", ] - configs = [ "${c_utils_base_path}:utils_config" ] - public_configs = [ ":wantagent_innerkits_public_config" ] deps = [ diff --git a/js_environment/frameworks/js_environment/BUILD.gn b/js_environment/frameworks/js_environment/BUILD.gn index 549d08ad36..6fb92e10f6 100644 --- a/js_environment/frameworks/js_environment/BUILD.gn +++ b/js_environment/frameworks/js_environment/BUILD.gn @@ -34,10 +34,7 @@ ohos_shared_library("js_environment") { "src/uncaught_exception_callback.cpp", ] - configs = [ - ":js_environment_config", - "${ark_compile_path}/ets_runtime:ark_jsruntime_public_config", - ] + configs = [ ":js_environment_config" ] public_configs = [ ":public_js_environment_config" ] From 23cc83c4ea17082dad11a0bd63f3981db48af0d5 Mon Sep 17 00:00:00 2001 From: x00671510 Date: Thu, 30 May 2024 17:57:32 +0800 Subject: [PATCH 15/69] =?UTF-8?q?=E9=9F=B3=E9=A2=91=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=96=B0=E5=A2=9Esyspicker=5Faudiopicker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: x00671510 --- services/abilitymgr/resource/uiextension_picker_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/resource/uiextension_picker_config.json b/services/abilitymgr/resource/uiextension_picker_config.json index 08c333cbd2..2b8b187f5e 100644 --- a/services/abilitymgr/resource/uiextension_picker_config.json +++ b/services/abilitymgr/resource/uiextension_picker_config.json @@ -25,7 +25,7 @@ "typePicker": "sysPicker/filePicker" }, { - "type": "sysPicker", + "type": "audioPicker", "typePicker": "sysPicker/audioPicker" } ] From ff64707c2da7459321f376e696c47b4929e6fea0 Mon Sep 17 00:00:00 2001 From: jsjzju Date: Thu, 30 May 2024 20:04:46 +0800 Subject: [PATCH 16/69] =?UTF-8?q?closeAbility=E6=94=B9=E4=B8=BA=E7=94=B1sc?= =?UTF-8?q?b=E5=8F=91=E8=B5=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jsjzju Change-Id: Ib58648d29cca34a1acc8a3d8a8a27dd117f9a997 --- .../ui_ability_lifecycle_manager.h | 1 + .../src/ability_connect_manager.cpp | 10 +++++----- .../ui_ability_lifecycle_manager.cpp | 20 ++++++++++++++++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h index 10747b36c5..02e5e81cd1 100644 --- a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h +++ b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h @@ -399,6 +399,7 @@ private: std::shared_ptr GetStatusBarDelegateManager(); int32_t DoProcessAttachment(std::shared_ptr abilityRecord); void BatchCloseUIAbility(const std::unordered_set>& abilitySet); + void TerminateSession(std::shared_ptr abilityRecord); int StartWithPersistentIdByDistributed(const AbilityRequest &abilityRequest, int32_t persistentId); int32_t userId_ = -1; diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 9642374084..3981f0e983 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -2009,11 +2009,11 @@ void AbilityConnectManager::HandleAbilityDiedTask( if ((IsLauncher(abilityRecord) || abilityRecord->IsSceneBoard()) && token != nullptr) { IN_PROCESS_CALL_WITHOUT_RET(DelayedSingleton::GetInstance()->ClearProcessByToken( token->AsObject())); - if (abilityRecord->IsSceneBoard() && currentUserId != userId_) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "Not the current user's SCB, clear the user and do not restart"); - KillProcessesByUserId(); - return; - } + } + if (abilityRecord->IsSceneBoard() && currentUserId != userId_) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "Not the current user's SCB, clear the user and do not restart"); + KillProcessesByUserId(); + return; } if (DelayedSingleton::GetInstance()->IsMemorySizeSufficent() || IsLauncher(abilityRecord) || abilityRecord->IsSceneBoard()) { diff --git a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp index 849af9446d..1501ef562f 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -259,7 +259,7 @@ int UIAbilityLifecycleManager::AttachAbilityThread(const sptr abilityRecord->SetScheduler(scheduler); if (DoProcessAttachment(abilityRecord) != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "do process attachment failed, close the ability."); - BatchCloseUIAbility({abilityRecord}); + TerminateSession(abilityRecord); return ERR_INVALID_VALUE; } if (abilityRecord->IsStartedByCall()) { @@ -2220,8 +2220,10 @@ int32_t UIAbilityLifecycleManager::KillProcessWithPrepareTerminate(const std::ve } if (needKillProcess) { pidsToKill.push_back(pid); - } else if (!abilitysToTerminate.empty()) { - BatchCloseUIAbility(abilitysToTerminate); + continue; + } + for (const auto& abilityRecord: abilitysToTerminate) { + TerminateSession(abilityRecord); } } if (!pidsToKill.empty()) { @@ -2251,6 +2253,18 @@ void UIAbilityLifecycleManager::BatchCloseUIAbility( } } +void UIAbilityLifecycleManager::TerminateSession(std::shared_ptr abilityRecord) +{ + CHECK_POINTER(abilityRecord); + auto sessionInfo = abilityRecord->GetSessionInfo(); + CHECK_POINTER(sessionInfo); + CHECK_POINTER(sessionInfo->sessionToken); + auto session = iface_cast(sessionInfo->sessionToken); + CHECK_POINTER(session); + TAG_LOGI(AAFwkTag::ABILITYMGR, "call TerminateSession, session id: %{public}d", sessionInfo->persistentId); + session->TerminateSession(sessionInfo); +} + int UIAbilityLifecycleManager::ChangeAbilityVisibility(sptr token, bool isShow) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); From 0b8e72f85c2dbb2d9de3f4e0f0b69b6ad74a40be Mon Sep 17 00:00:00 2001 From: liuzongze Date: Tue, 21 May 2024 16:28:25 +0800 Subject: [PATCH 17/69] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E7=BA=A7=E5=AD=97=E4=BD=93=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liuzongze Change-Id: I328fbd6c28acf51cb03cc7b8075bb3227272d2f1 --- .../application_context.js | 4 +++ .../context/application_context.cpp | 18 ++++++++++ .../context/js_application_context_utils.cpp | 35 ++++++++++++++++--- .../native/appkit/app/ohos_application.cpp | 25 +++++++++++++ .../simulator/common/include/configuration.h | 1 + .../context/application_context.h | 3 ++ .../ability_runtime/context/context_impl.h | 11 ++++-- .../context/js_application_context_utils.h | 2 ++ .../kits/native/appkit/app/ohos_application.h | 8 +++++ 9 files changed, 101 insertions(+), 6 deletions(-) diff --git a/frameworks/js/napi/app/application_context/application_context.js b/frameworks/js/napi/app/application_context/application_context.js index 5c12391586..781f5bcdb2 100644 --- a/frameworks/js/napi/app/application_context/application_context.js +++ b/frameworks/js/napi/app/application_context/application_context.js @@ -157,6 +157,10 @@ class ApplicationContext { return this.__context_impl__.setLanguage(language); } + setFont(font) { + return this.__context_impl__.setFont(font); + } + setAutoStartup(info, callback) { return this.__context_impl__.setAutoStartup(info, callback); } diff --git a/frameworks/native/appkit/ability_runtime/context/application_context.cpp b/frameworks/native/appkit/ability_runtime/context/application_context.cpp index c87c71944c..bec01bde89 100644 --- a/frameworks/native/appkit/ability_runtime/context/application_context.cpp +++ b/frameworks/native/appkit/ability_runtime/context/application_context.cpp @@ -502,6 +502,19 @@ void ApplicationContext::SetLanguage(const std::string &language) } } +void ApplicationContext::SetFont(const std::string &font) +{ + TAG_LOGD(AAFwkTag::APPKIT, "font:%{public}s.", font.c_str()); + #ifdef SUPPORT_GRAPHICS + // Notify Window + AppExecFwk::Configuration config; + config.AddItem(AppExecFwk::ConfigurationInner::APPLICATION_FONT, font); + if (appFontCallback_ != nullptr) { + appFontCallback_(config); + } + #endif +} + void ApplicationContext::ClearUpApplicationData() { if (contextImpl_ != nullptr) { @@ -538,6 +551,11 @@ void ApplicationContext::RegisterAppConfigUpdateObserver(AppConfigUpdateCallback appConfigChangeCallback_ = appConfigChangeCallback; } +void ApplicationContext::RegisterAppFontObserver(AppConfigUpdateCallback appFontCallback) +{ + appFontCallback_ = appFontCallback; +} + std::string ApplicationContext::GetAppRunningUniqueId() const { TAG_LOGD(AAFwkTag::APPKIT, "GetAppRunningUniqueId is %{public}s.", appRunningUniqueId_.c_str()); diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index c18df7372d..f8ef94b58c 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -666,6 +666,34 @@ napi_value JsApplicationContextUtils::OnSetLanguage(napi_env env, NapiCallbackIn return CreateJsUndefined(env); } +napi_value JsApplicationContextUtils::SetFont(napi_env env, napi_callback_info info) +{ + GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, OnSetFont, APPLICATION_CONTEXT_NAME); +} + +napi_value JsApplicationContextUtils::OnSetFont(napi_env env, NapiCallbackInfo& info) +{ + // only support one params + if (info.argc == ARGC_ZERO) { + TAG_LOGE(AAFwkTag::APPKIT, "Not enough params"); + ThrowInvalidParamError(env, "Not enough params."); + return CreateJsUndefined(env); + } + auto applicationContext = applicationContext_.lock(); + if (!applicationContext) { + TAG_LOGW(AAFwkTag::APPKIT, "applicationContext is already released"); + return CreateJsUndefined(env); + } + std::string font; + if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], font)) { + TAG_LOGE(AAFwkTag::APPKIT, "Parse font failed"); + ThrowInvalidParamError(env, "Parse param font failed, font must be string."); + return CreateJsUndefined(env); + } + applicationContext->SetFont(font); + return CreateJsUndefined(env); +} + napi_value JsApplicationContextUtils::PreloadUIExtensionAbility(napi_env env, napi_callback_info info) { GET_NAPI_INFO_WITH_NAME_AND_CALL( @@ -1508,6 +1536,7 @@ void JsApplicationContextUtils::BindNativeApplicationContext(napi_env env, napi_ BindNativeFunction(env, object, "killAllProcesses", MD_NAME, JsApplicationContextUtils::KillProcessBySelf); BindNativeFunction(env, object, "setColorMode", MD_NAME, JsApplicationContextUtils::SetColorMode); BindNativeFunction(env, object, "setLanguage", MD_NAME, JsApplicationContextUtils::SetLanguage); + BindNativeFunction(env, object, "setFont", MD_NAME, JsApplicationContextUtils::SetFont); BindNativeFunction(env, object, "clearUpApplicationData", MD_NAME, JsApplicationContextUtils::ClearUpApplicationData); BindNativeFunction(env, object, "preloadUIExtensionAbility", MD_NAME, @@ -1518,10 +1547,8 @@ void JsApplicationContextUtils::BindNativeApplicationContext(napi_env env, napi_ JsApplicationContextUtils::GetRunningProcessInformation); BindNativeFunction(env, object, "getCurrentAppCloneIndex", MD_NAME, JsApplicationContextUtils::GetCurrentAppCloneIndex); - BindNativeFunction(env, object, "getGroupDir", MD_NAME, - JsApplicationContextUtils::GetGroupDir); - BindNativeFunction(env, object, "restartApp", MD_NAME, - JsApplicationContextUtils::RestartApp); + BindNativeFunction(env, object, "getGroupDir", MD_NAME, JsApplicationContextUtils::GetGroupDir); + BindNativeFunction(env, object, "restartApp", MD_NAME, JsApplicationContextUtils::RestartApp); BindNativeFunction(env, object, "setSupportedProcessCache", MD_NAME, JsApplicationContextUtils::SetSupportedProcessCacheSelf); } diff --git a/frameworks/native/appkit/app/ohos_application.cpp b/frameworks/native/appkit/app/ohos_application.cpp index 262301b742..482e999eca 100644 --- a/frameworks/native/appkit/app/ohos_application.cpp +++ b/frameworks/native/appkit/app/ohos_application.cpp @@ -200,10 +200,19 @@ void OHOSApplication::SetApplicationContext( abilityRuntimeContext_->RegisterAppConfigUpdateObserver([applicationWptr](const Configuration &config) { std::shared_ptr applicationSptr = applicationWptr.lock(); if (applicationSptr == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "application is nullptr."); return; } applicationSptr->OnConfigurationUpdated(config); }); + abilityRuntimeContext_->RegisterAppFontObserver([applicationWptr](const Configuration &config) { + std::shared_ptr applicationSptr = applicationWptr.lock(); + if (applicationSptr == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "application is nullptr."); + return; + } + applicationSptr->OnFontUpdated(config); + }); } /** @@ -537,6 +546,22 @@ void OHOSApplication::OnConfigurationUpdated(Configuration config) } } +/** + * + * @brief Will be Called when the application font of the device changes. + * + * @param config Indicates the new Configuration object. + */ +void OHOSApplication::OnFontUpdated(Configuration config) +{ + #ifdef SUPPORT_GRAPHICS + // Notify Window + TAG_LOGD(AAFwkTag::APPKIT, "Update configuration for all window."); + auto diffConfiguration = std::make_shared(config); + Rosen::Window::UpdateConfigurationForAll(diffConfiguration); + #endif +} + /** * * @brief Called when the system has determined to trim the memory, for example, diff --git a/frameworks/simulator/common/include/configuration.h b/frameworks/simulator/common/include/configuration.h index d4e38e088c..370e36584b 100644 --- a/frameworks/simulator/common/include/configuration.h +++ b/frameworks/simulator/common/include/configuration.h @@ -43,6 +43,7 @@ constexpr const char* EMPTY_STRING = ""; constexpr const char* APPLICATION_DIRECTION = "ohos.application.direction"; constexpr const char* APPLICATION_DENSITYDPI = "ohos.application.densitydpi"; constexpr const char* APPLICATION_DISPLAYID = "ohos.application.displayid"; +constexpr const char* APPLICATION_FONT = "ohos.application.font"; constexpr const char* COLOR_MODE_LIGHT = "light"; constexpr const char* COLOR_MODE_DARK = "dark"; diff --git a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h index e7dd14c9cb..a0b771be57 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h @@ -91,6 +91,7 @@ public: void SwitchArea(int mode) override; void SetColorMode(int32_t colorMode); void SetLanguage(const std::string &language); + void SetFont(const std::string &font); void ClearUpApplicationData(); int GetArea() override; std::shared_ptr GetConfiguration() const override; @@ -110,6 +111,7 @@ public: bool GetApplicationInfoUpdateFlag() const; void SetApplicationInfoUpdateFlag(bool flag); void RegisterAppConfigUpdateObserver(AppConfigUpdateCallback appConfigChangeCallback); + void RegisterAppFontObserver(AppConfigUpdateCallback appFontCallback); std::string GetAppRunningUniqueId() const; void SetAppRunningUniqueId(const std::string &appRunningUniqueId); @@ -128,6 +130,7 @@ private: std::recursive_mutex applicationStateCallbackLock_; bool applicationInfoUpdateFlag_ = false; AppConfigUpdateCallback appConfigChangeCallback_ = nullptr; + AppConfigUpdateCallback appFontCallback_ = nullptr; std::string appRunningUniqueId_; int32_t appIndex_ = 0; int32_t appMode_ = 0; diff --git a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h index cea4d75680..3ffbfdd83b 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h @@ -157,12 +157,19 @@ public: void SetColorMode(int colorMode); /** - * @brief Set color mode + * @brief Set language * - * @param colorMode color mode. + * @param language language. */ void SetLanguage(std::string language); + /** + * @brief Set font + * + * @param Font font. + */ + void SetFont(std::string font); + /** * @brief clear the application data by app self */ diff --git a/interfaces/kits/native/appkit/ability_runtime/context/js_application_context_utils.h b/interfaces/kits/native/appkit/ability_runtime/context/js_application_context_utils.h index ca3bcd046d..777d32a5f9 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/js_application_context_utils.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/js_application_context_utils.h @@ -94,6 +94,7 @@ public: napi_value OnGetRunningProcessInformation(napi_env env, NapiCallbackInfo& info); napi_value OnSetColorMode(napi_env env, NapiCallbackInfo& info); napi_value OnSetLanguage(napi_env env, NapiCallbackInfo& info); + napi_value OnSetFont(napi_env env, NapiCallbackInfo& info); napi_value OnClearUpApplicationData(napi_env env, NapiCallbackInfo& info); napi_value OnRestartApp(napi_env env, NapiCallbackInfo& info); napi_value OnSetSupportedProcessCacheSelf(napi_env env, NapiCallbackInfo& info); @@ -114,6 +115,7 @@ public: static napi_value KillProcessBySelf(napi_env env, napi_callback_info info); static napi_value SetColorMode(napi_env env, napi_callback_info info); static napi_value SetLanguage(napi_env env, napi_callback_info info); + static napi_value SetFont(napi_env env, napi_callback_info info); static napi_value ClearUpApplicationData(napi_env env, napi_callback_info info); static napi_value GetRunningProcessInformation(napi_env env, napi_callback_info info); static napi_value CreateJsApplicationContext(napi_env env); diff --git a/interfaces/kits/native/appkit/app/ohos_application.h b/interfaces/kits/native/appkit/app/ohos_application.h index 6f7c2b331d..f0461a9f53 100644 --- a/interfaces/kits/native/appkit/app/ohos_application.h +++ b/interfaces/kits/native/appkit/app/ohos_application.h @@ -176,6 +176,14 @@ public: * @param config Indicates the new Configuration object. */ virtual void OnConfigurationUpdated(Configuration config); + + /** + * + * @brief Will be Called when the application font of the device changes. + * + * @param config Indicates the new Configuration object. + */ + virtual void OnFontUpdated(Configuration config); /** * From c91932580dfc4f87e02d9bf4c59204f4d462be1d Mon Sep 17 00:00:00 2001 From: xia Date: Thu, 30 May 2024 18:07:58 +0800 Subject: [PATCH 18/69] =?UTF-8?q?=E5=85=88=E4=BA=AE=E5=B1=8F=E5=86=8D?= =?UTF-8?q?=E8=A7=A3=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xia --- services/abilitymgr/libabilityms.map | 1 + .../src/screen_lock/unlock_screen_manager.cpp | 13 ++-- test/unittest/BUILD.gn | 1 + test/unittest/unlock_screen_test/BUILD.gn | 69 +++++++++++++++++++ .../unlock_screen_test/unlock_screen_test.cpp | 58 ++++++++++++++++ 5 files changed, 137 insertions(+), 5 deletions(-) create mode 100644 test/unittest/unlock_screen_test/BUILD.gn create mode 100644 test/unittest/unlock_screen_test/unlock_screen_test.cpp diff --git a/services/abilitymgr/libabilityms.map b/services/abilitymgr/libabilityms.map index ea7ce503c3..1398359572 100644 --- a/services/abilitymgr/libabilityms.map +++ b/services/abilitymgr/libabilityms.map @@ -68,6 +68,7 @@ *TaskDataPersistenceMgr*; *Token*; *UserController*; + *UnlockScreenManager*; *WantSenderInfo*; *SenderInfo*; *AbilityManagerProxy*; diff --git a/services/abilitymgr/src/screen_lock/unlock_screen_manager.cpp b/services/abilitymgr/src/screen_lock/unlock_screen_manager.cpp index 5f4de0e448..b6280ce27b 100644 --- a/services/abilitymgr/src/screen_lock/unlock_screen_manager.cpp +++ b/services/abilitymgr/src/screen_lock/unlock_screen_manager.cpp @@ -57,11 +57,6 @@ bool UnlockScreenManager::UnlockScreen() if (isScreenLocked && isScreenSecured) { return false; } - if (isScreenLocked) { - sptr listener = sptr(new (std::nothrow) UnlockScreenCallback()); - IN_PROCESS_CALL(OHOS::ScreenLock::ScreenLockManager::GetInstance()->Unlock( - OHOS::ScreenLock::Action::UNLOCKSCREEN, listener)); - } #endif #ifdef SUPPORT_POWER @@ -71,6 +66,14 @@ bool UnlockScreenManager::UnlockScreen() PowerMgr::PowerMgrClient::GetInstance().WakeupDevice(); } #endif + +#ifdef SUPPORT_GRAPHICS + if (isScreenLocked) { + sptr listener = sptr(new (std::nothrow) UnlockScreenCallback()); + IN_PROCESS_CALL(OHOS::ScreenLock::ScreenLockManager::GetInstance()->Unlock( + OHOS::ScreenLock::Action::UNLOCKSCREEN, listener)); + } +#endif return true; } } // namespace AbilityRuntime diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 95540a5dc7..708c83ab3e 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -509,6 +509,7 @@ group("unittest") { "ui_extension_ability_test:unittest", "ui_extension_context_test:unittest", "ui_extension_utils_test:unittest", + "unlock_screen_test:unittest", "uri_permission_impl_test:unittest", "uri_permission_manager_test:unittest", "uri_permission_test:unittest", diff --git a/test/unittest/unlock_screen_test/BUILD.gn b/test/unittest/unlock_screen_test/BUILD.gn new file mode 100644 index 0000000000..531e7d312e --- /dev/null +++ b/test/unittest/unlock_screen_test/BUILD.gn @@ -0,0 +1,69 @@ +# Copyright (c) 2021-2022 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/abilitymgr" + +ohos_unittest("unlock_screen_test") { + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", + "${ability_runtime_services_path}/abilitymgr/include", + "${ability_runtime_services_path}/abilitymgr/include/screen_lock", + ] + + sources = [ "unlock_screen_test.cpp" ] + + configs = [ + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + "${ability_runtime_test_path}/mock/services_abilitymgr_test:aafwk_mock_config", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbeget_proxy", + "ipc:ipc_core", + "napi:ace_napi", + ] + + if (ability_runtime_graphics) { + external_deps += [ "screenlock_mgr:screenlock_client" ] + } + + if (ability_runtime_power) { + external_deps += [ "power_manager:powermgr_client" ] + } +} + +group("unittest") { + testonly = true + + deps = [ ":unlock_screen_test" ] +} diff --git a/test/unittest/unlock_screen_test/unlock_screen_test.cpp b/test/unittest/unlock_screen_test/unlock_screen_test.cpp new file mode 100644 index 0000000000..7788d92631 --- /dev/null +++ b/test/unittest/unlock_screen_test/unlock_screen_test.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "unlock_screen_manager.h" +#include "ability_manager_service.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AbilityRuntime { + +class UnlockScreenTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void UnlockScreenTest::SetUpTestCase(void) +{} +void UnlockScreenTest::TearDownTestCase(void) +{} +void UnlockScreenTest::SetUp() +{} +void UnlockScreenTest::TearDown() +{} + +/* + * Feature: UnlockScreenTest + * Function: UnlockScreen + * SubFunction: NA + * FunctionPoints:UnlockScreenTest UnlockScreen + * EnvConditions: NA + * CaseDescription: Verify UnlockScreen + */ +HWTEST_F(UnlockScreenTest, UnlockScreen_001, TestSize.Level1) +{ + bool ret = UnlockScreenManager::GetInstance().UnlockScreen(); + EXPECT_EQ(ret, true); +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file From 353fe2461ebd92b27ab46a1dc67d962450110392 Mon Sep 17 00:00:00 2001 From: hhl Date: Thu, 30 May 2024 19:17:17 +0800 Subject: [PATCH 19/69] Resolve dump stack conflicts between 3s and input events Signed-off-by: hhl --- services/appdfr/include/appfreeze_manager.h | 6 +++- services/appdfr/src/appfreeze_manager.cpp | 33 +++++++++++++++++-- services/appmgr/src/app_mgr_service_inner.cpp | 5 +++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/services/appdfr/include/appfreeze_manager.h b/services/appdfr/include/appfreeze_manager.h index bef4d74219..60b85fca99 100644 --- a/services/appdfr/include/appfreeze_manager.h +++ b/services/appdfr/include/appfreeze_manager.h @@ -78,6 +78,7 @@ public: bool IsHandleAppfreeze(const std::string& bundleName); bool IsProcessDebug(int32_t pid, std::string processName); bool IsNeedIgnoreFreezeEvent(int32_t pid); + void DeleteStack(int pid); private: AppfreezeManager& operator=(const AppfreezeManager&) = delete; @@ -86,7 +87,8 @@ private: std::map> BinderParser(std::ifstream& fin, std::string& stack) const; void ParseBinderPids(const std::map>& binderInfo, std::set& pids, int pid, int layer) const; std::set GetBinderPeerPids(std::string& stack, int pid) const; - std::string CatchJsonStacktrace(int pid) const; + void FindStackByPid(std::string& ret, int pid, const std::string& msg) const; + std::string CatchJsonStacktrace(int pid, const std::string& faultType) const; std::string CatcherStacktrace(int pid) const; int AcquireStack(const FaultData& faultData, const AppInfo& appInfo); int NotifyANR(const FaultData& faultData, const AppfreezeManager::AppInfo& appInfo, const std::string& binderInfo); @@ -102,6 +104,8 @@ private: static std::shared_ptr instance_; static ffrt::mutex freezeMutex_; std::map appfreezeInfo_; + static ffrt::mutex catchStackMutex_; + static std::map catchStackMap_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appdfr/src/appfreeze_manager.cpp b/services/appdfr/src/appfreeze_manager.cpp index e54611ac35..3faa55f0e1 100644 --- a/services/appdfr/src/appfreeze_manager.cpp +++ b/services/appdfr/src/appfreeze_manager.cpp @@ -24,6 +24,7 @@ #include "faultloggerd_client.h" #include "file_ex.h" +#include "ffrt.h" #include "dfx_dump_catcher.h" #include "directory_ex.h" #include "hisysevent.h" @@ -56,6 +57,8 @@ const std::string LOG_FILE_PATH = "data/log/eventlog"; std::shared_ptr AppfreezeManager::instance_ = nullptr; ffrt::mutex AppfreezeManager::singletonMutex_; ffrt::mutex AppfreezeManager::freezeMutex_; +ffrt::mutex AppfreezeManager::catchStackMutex_; +std::map AppfreezeManager::catchStackMap_; AppfreezeManager::AppfreezeManager() { @@ -153,7 +156,7 @@ int AppfreezeManager::AppfreezeHandleWithStack(const FaultData& faultData, const fullStackPath = WriteToFile(fileName, catcherStack); faultNotifyData.errorObject.stack = fullStackPath; } else { - catchJsonStack += CatchJsonStacktrace(appInfo.pid); + catchJsonStack += CatchJsonStacktrace(appInfo.pid, faultData.errorObject.name); fullStackPath = WriteToFile(fileName, catchJsonStack); faultNotifyData.errorObject.stack = fullStackPath; } @@ -379,7 +382,27 @@ void AppfreezeManager::ParseBinderPids(const std::map>& binde } } -std::string AppfreezeManager::CatchJsonStacktrace(int pid) const +void AppfreezeManager::DeleteStack(int pid) +{ + std::lock_guard lock(catchStackMutex_); + auto it = catchStackMap_.find(pid); + if (it != catchStackMap_.end()) { + catchStackMap_.erase(it); + } +} + +void AppfreezeManager::FindStackByPid(std::string& ret, int pid, const std::string& msg) const +{ + std::lock_guard lock(catchStackMutex_); + auto it = catchStackMap_.find(pid); + if (it != catchStackMap_.end()) { + ret = it->second; + } else { + ret = "Failed to dump stacktrace for " + std::to_string(pid) + "\n" + msg; + } +} + +std::string AppfreezeManager::CatchJsonStacktrace(int pid, const std::string& faultType) const { HITRACE_METER_FMT(HITRACE_TAG_APP, "CatchJsonStacktrace pid:%d", pid); HiviewDFX::DfxDumpCatcher dumplog; @@ -387,9 +410,13 @@ std::string AppfreezeManager::CatchJsonStacktrace(int pid) const std::string msg; size_t defaultMaxFaultNum = 256; if (!dumplog.DumpCatch(pid, 0, msg, defaultMaxFaultNum, true)) { - ret = "Failed to dump stacktrace for " + std::to_string(pid) + "\n" + msg; + FindStackByPid(ret, pid, msg); } else { ret = msg; + if (faultType == AppFreezeType::THREAD_BLOCK_3S) { + std::lock_guard lock(catchStackMutex_); + catchStackMap_[pid] = msg; + } } return ret; } diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 789c3d40fb..ef0f6a3fc2 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -5163,6 +5163,11 @@ int32_t AppMgrServiceInner::NotifyAppFault(const FaultData &faultData) } dfxTaskHandler_->SubmitTask(notifyAppTask, "NotifyAppFaultTask"); + constexpr int delayTime = 15 * 1000; // 15s + auto task = [pid, innerService = shared_from_this()]() { + AppExecFwk::AppfreezeManager::GetInstance()->DeleteStack(pid); + }; + dfxTaskHandler_->SubmitTask(task, "DeleteStack", delayTime); if (appRecord->GetApplicationInfo()->asanEnabled) { TAG_LOGI(AAFwkTag::APPMGR, From d20674eb0eba6b18bb83ed880ff8e0282feec608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E5=97=A3=E9=92=8A?= Date: Fri, 31 May 2024 10:15:00 +0800 Subject: [PATCH 20/69] =?UTF-8?q?aa=20process=20=E6=94=AF=E6=8C=81Extensio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 段嗣钊 Change-Id: I897b873b3bd377c227885151d7719d7570119cb8 --- .../abilitymgr/include/start_ability_utils.h | 2 - .../abilitymgr/src/start_ability_utils.cpp | 44 ++-------------- .../appmgr/include/app_mgr_service_inner.h | 2 + services/appmgr/src/app_mgr_service_inner.cpp | 50 ++++++++++++++++--- utils/server/startup/BUILD.gn | 1 + utils/server/startup/include/startup_util.h | 5 ++ utils/server/startup/src/startup_util.cpp | 39 +++++++++++++++ 7 files changed, 92 insertions(+), 51 deletions(-) diff --git a/services/abilitymgr/include/start_ability_utils.h b/services/abilitymgr/include/start_ability_utils.h index ac35908213..a16f10ced9 100644 --- a/services/abilitymgr/include/start_ability_utils.h +++ b/services/abilitymgr/include/start_ability_utils.h @@ -26,8 +26,6 @@ namespace OHOS { namespace AAFwk { struct StartAbilityInfo { - static void InitAbilityInfoFromExtension(AppExecFwk::ExtensionAbilityInfo &extensionInfo, - AppExecFwk::AbilityInfo &abilityInfo); static std::shared_ptr CreateStartAbilityInfo(const Want &want, int32_t userId, int32_t appIndex); static std::shared_ptr CreateCallerAbilityInfo(const sptr &callerToken); diff --git a/services/abilitymgr/src/start_ability_utils.cpp b/services/abilitymgr/src/start_ability_utils.cpp index dddbe48699..4b2cdac5a9 100644 --- a/services/abilitymgr/src/start_ability_utils.cpp +++ b/services/abilitymgr/src/start_ability_utils.cpp @@ -129,44 +129,6 @@ StartAbilityInfoWrap::~StartAbilityInfoWrap() StartAbilityUtils::skipErms = false; } -void StartAbilityInfo::InitAbilityInfoFromExtension(AppExecFwk::ExtensionAbilityInfo &extensionInfo, - AppExecFwk::AbilityInfo &abilityInfo) -{ - abilityInfo.applicationName = extensionInfo.applicationInfo.name; - abilityInfo.applicationInfo = extensionInfo.applicationInfo; - abilityInfo.bundleName = extensionInfo.bundleName; - abilityInfo.package = extensionInfo.moduleName; - abilityInfo.moduleName = extensionInfo.moduleName; - abilityInfo.name = extensionInfo.name; - abilityInfo.srcEntrance = extensionInfo.srcEntrance; - abilityInfo.srcPath = extensionInfo.srcEntrance; - abilityInfo.iconPath = extensionInfo.icon; - abilityInfo.iconId = extensionInfo.iconId; - abilityInfo.label = extensionInfo.label; - abilityInfo.labelId = extensionInfo.labelId; - abilityInfo.description = extensionInfo.description; - abilityInfo.descriptionId = extensionInfo.descriptionId; - abilityInfo.priority = extensionInfo.priority; - abilityInfo.permissions = extensionInfo.permissions; - abilityInfo.readPermission = extensionInfo.readPermission; - abilityInfo.writePermission = extensionInfo.writePermission; - abilityInfo.uri = extensionInfo.uri; - abilityInfo.extensionAbilityType = extensionInfo.type; - abilityInfo.visible = extensionInfo.visible; - abilityInfo.resourcePath = extensionInfo.resourcePath; - abilityInfo.enabled = extensionInfo.enabled; - abilityInfo.isModuleJson = true; - abilityInfo.isStageBasedModel = true; - abilityInfo.process = extensionInfo.process; - abilityInfo.metadata = extensionInfo.metadata; - abilityInfo.compileMode = extensionInfo.compileMode; - abilityInfo.type = AppExecFwk::AbilityType::EXTENSION; - abilityInfo.extensionTypeName = extensionInfo.extensionTypeName; - if (!extensionInfo.hapPath.empty()) { - abilityInfo.hapPath = extensionInfo.hapPath; - } -} - std::shared_ptr StartAbilityInfo::CreateStartAbilityInfo(const Want &want, int32_t userId, int32_t appIndex) { @@ -214,7 +176,7 @@ std::shared_ptr StartAbilityInfo::CreateStartAbilityInfo(const } request->extensionProcessMode = extensionInfo.extensionProcessMode; // For compatibility translates to AbilityInfo - InitAbilityInfoFromExtension(extensionInfo, request->abilityInfo); + AbilityRuntime::StartupUtil::InitAbilityInfoFromExtension(extensionInfo, request->abilityInfo); } return request; } @@ -254,7 +216,7 @@ std::shared_ptr StartAbilityInfo::CreateStartExtensionInfo(con } abilityInfo->extensionProcessMode = extensionInfo.extensionProcessMode; // For compatibility translates to AbilityInfo - InitAbilityInfoFromExtension(extensionInfo, abilityInfo->abilityInfo); + AbilityRuntime::StartupUtil::InitAbilityInfoFromExtension(extensionInfo, abilityInfo->abilityInfo); return abilityInfo; } @@ -277,7 +239,7 @@ void StartAbilityInfo::FindExtensionInfo(const Want &want, int32_t flags, int32_ if (AbilityRuntime::StartupUtil::IsSupportAppClone(extensionInfo.type)) { abilityInfo->extensionProcessMode = extensionInfo.extensionProcessMode; // For compatibility translates to AbilityInfo - InitAbilityInfoFromExtension(extensionInfo, abilityInfo->abilityInfo); + AbilityRuntime::StartupUtil::InitAbilityInfoFromExtension(extensionInfo, abilityInfo->abilityInfo); } else { abilityInfo->status = ERR_APP_CLONE_INDEX_INVALID; } diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index bf51ba3dfd..68d0f7f5aa 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -1455,6 +1455,8 @@ private: void SetAppInfo(const BundleInfo &bundleInfo, AppSpawnStartMsg &startMsg); + bool CreateAbilityInfo(const AAFwk::Want &want, AbilityInfo &abilityInfo); + private: /** * Notify application status. diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index b1ec88cbd8..1f474baeb1 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -5388,26 +5388,60 @@ int32_t AppMgrServiceInner::IsAppRunning(const std::string &bundleName, int32_t return appRunningManager_->CheckAppCloneRunningRecordIsExistByBundleName(bundleName, appCloneIndex, isRunning); } +bool AppMgrServiceInner::CreateAbilityInfo(const AAFwk::Want &want, AbilityInfo &abilityInfo) +{ + auto&& bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper(); + if (!bundleMgrHelper) { + TAG_LOGE(AAFwkTag::APPMGR, "Get bundle manager helper error."); + return false; + } + auto userId = GetCurrentAccountId(); + auto abilityInfoFlag = AbilityRuntime::StartupUtil::BuildAbilityInfoFlag(); + if (IN_PROCESS_CALL(bundleMgrHelper->QueryAbilityInfo(want, abilityInfoFlag, userId, abilityInfo))) { + TAG_LOGE(AAFwkTag::APPMGR, "QueryAbilityInfo failed."); + return true; + } + std::vector extensionInfos; + int32_t appIndex = want.GetIntParam(AppspawnUtil::DLP_PARAMS_INDEX, 0); + if (appIndex == 0) { + if (!IN_PROCESS_CALL(bundleMgrHelper->QueryExtensionAbilityInfos(want, abilityInfoFlag, + userId, extensionInfos))) { + TAG_LOGE(AAFwkTag::APPMGR, "QueryExtensionAbilityInfos failed."); + return false; + } + } else { + if (!IN_PROCESS_CALL(bundleMgrHelper->GetSandboxExtAbilityInfos(want, appIndex, + abilityInfoFlag, userId, extensionInfos))) { + TAG_LOGE(AAFwkTag::APPMGR, "GetSandboxExtAbilityInfos failed."); + return false; + } + } + if (extensionInfos.size() <= 0) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Get extension info failed."); + return ERR_INVALID_OPERATION; + } + AppExecFwk::ExtensionAbilityInfo extensionInfo = extensionInfos.front(); + AbilityRuntime::StartupUtil::InitAbilityInfoFromExtension(extensionInfo, abilityInfo); + return true; +} + int32_t AppMgrServiceInner::StartNativeProcessForDebugger(const AAFwk::Want &want) { if (!remoteClientManager_ || !appRunningManager_) { TAG_LOGE(AAFwkTag::APPMGR, "remoteClientManager or appRunningManager is nullptr!"); return ERR_INVALID_OPERATION; } - auto&& bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper(); - if (!bundleMgrHelper) { - TAG_LOGE(AAFwkTag::APPMGR, "Get bundle manager helper error."); - return ERR_INVALID_OPERATION; - } TAG_LOGI(AAFwkTag::APPMGR, "debuggablePipe bundleName:%{public}s", want.GetElement().GetBundleName().c_str()); TAG_LOGI(AAFwkTag::APPMGR, "debuggablePipe moduleName:%{public}s", want.GetElement().GetModuleName().c_str()); TAG_LOGI(AAFwkTag::APPMGR, "debuggablePipe abilityName:%{public}s", want.GetElement().GetAbilityName().c_str()); AbilityInfo abilityInfo; - auto userId = GetCurrentAccountId(); - auto abilityInfoFlag = AbilityRuntime::StartupUtil::BuildAbilityInfoFlag(); - IN_PROCESS_CALL_WITHOUT_RET(bundleMgrHelper->QueryAbilityInfo(want, abilityInfoFlag, userId, abilityInfo)); + if (!CreateAbilityInfo(want, abilityInfo)) { + TAG_LOGE(AAFwkTag::APPMGR, "CreateAbilityInfo failed!"); + return ERR_INVALID_OPERATION; + } + BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; auto appInfo = std::make_shared(abilityInfo.applicationInfo); diff --git a/utils/server/startup/BUILD.gn b/utils/server/startup/BUILD.gn index b0b3747e63..db9ca37763 100644 --- a/utils/server/startup/BUILD.gn +++ b/utils/server/startup/BUILD.gn @@ -48,6 +48,7 @@ ohos_shared_library("startup_util") { external_deps = [ "ability_base:want", "bundle_framework:appexecfwk_base", + "c_utils:utils", ] innerapi_tags = [ "platformsdk" ] diff --git a/utils/server/startup/include/startup_util.h b/utils/server/startup/include/startup_util.h index a3a6a71d38..29720b1895 100644 --- a/utils/server/startup/include/startup_util.h +++ b/utils/server/startup/include/startup_util.h @@ -18,6 +18,9 @@ #include +#include "ability_info.h" +#include "extension_ability_info.h" + namespace OHOS { namespace AAFwk { class Want; @@ -31,6 +34,8 @@ public: static bool GetAppIndex(const AAFwk::Want &want, int32_t &appIndex); static int32_t BuildAbilityInfoFlag(); static bool IsSupportAppClone(AppExecFwk::ExtensionAbilityType type); + static void InitAbilityInfoFromExtension(AppExecFwk::ExtensionAbilityInfo &extensionInfo, + AppExecFwk::AbilityInfo &abilityInfo); }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/utils/server/startup/src/startup_util.cpp b/utils/server/startup/src/startup_util.cpp index d5f2d42a65..eeec9b65e5 100644 --- a/utils/server/startup/src/startup_util.cpp +++ b/utils/server/startup/src/startup_util.cpp @@ -47,4 +47,43 @@ bool StartupUtil::IsSupportAppClone(AppExecFwk::ExtensionAbilityType type) type == AppExecFwk::ExtensionAbilityType::BACKUP || type == AppExecFwk::ExtensionAbilityType::SHARE; } + +void StartupUtil::InitAbilityInfoFromExtension(AppExecFwk::ExtensionAbilityInfo &extensionInfo, + AppExecFwk::AbilityInfo &abilityInfo) +{ + abilityInfo.applicationName = extensionInfo.applicationInfo.name; + abilityInfo.applicationInfo = extensionInfo.applicationInfo; + abilityInfo.bundleName = extensionInfo.bundleName; + abilityInfo.package = extensionInfo.moduleName; + abilityInfo.moduleName = extensionInfo.moduleName; + abilityInfo.name = extensionInfo.name; + abilityInfo.srcEntrance = extensionInfo.srcEntrance; + abilityInfo.srcPath = extensionInfo.srcEntrance; + abilityInfo.iconPath = extensionInfo.icon; + abilityInfo.iconId = extensionInfo.iconId; + abilityInfo.label = extensionInfo.label; + abilityInfo.labelId = extensionInfo.labelId; + abilityInfo.description = extensionInfo.description; + abilityInfo.descriptionId = extensionInfo.descriptionId; + abilityInfo.priority = extensionInfo.priority; + abilityInfo.permissions = extensionInfo.permissions; + abilityInfo.readPermission = extensionInfo.readPermission; + abilityInfo.writePermission = extensionInfo.writePermission; + abilityInfo.uri = extensionInfo.uri; + abilityInfo.extensionAbilityType = extensionInfo.type; + abilityInfo.visible = extensionInfo.visible; + abilityInfo.resourcePath = extensionInfo.resourcePath; + abilityInfo.enabled = extensionInfo.enabled; + abilityInfo.isModuleJson = true; + abilityInfo.isStageBasedModel = true; + abilityInfo.process = extensionInfo.process; + abilityInfo.metadata = extensionInfo.metadata; + abilityInfo.compileMode = extensionInfo.compileMode; + abilityInfo.type = AppExecFwk::AbilityType::EXTENSION; + abilityInfo.extensionTypeName = extensionInfo.extensionTypeName; + if (!extensionInfo.hapPath.empty()) { + abilityInfo.hapPath = extensionInfo.hapPath; + } +} + } // namespace OHOS::AbilityRuntime From ce633e35755a66bdeeffc283a941a8cd07eb2cab Mon Sep 17 00:00:00 2001 From: XKK Date: Tue, 28 May 2024 10:45:45 +0800 Subject: [PATCH 21/69] configuration mcc && mnc Signed-off-by: XKK --- .../napi_common/napi_common_configuration.cpp | 6 + frameworks/native/ability/native/BUILD.gn | 1 + .../ability/native/configuration_utils.cpp | 67 ++------ .../ability/native/resource_config_helper.cpp | 158 ++++++++++++++++++ .../native/ability/native/ui_ability.cpp | 78 ++++----- frameworks/native/appkit/app/main_thread.cpp | 16 ++ .../ability/native/configuration_utils.h | 5 +- .../ability/native/resource_config_helper.h | 63 +++++++ .../kits/native/ability/native/ui_ability.h | 5 +- .../ui_ability_test.cpp | 20 +-- 10 files changed, 299 insertions(+), 120 deletions(-) create mode 100644 frameworks/native/ability/native/resource_config_helper.cpp create mode 100644 interfaces/kits/native/ability/native/resource_config_helper.h diff --git a/frameworks/js/napi/inner/napi_common/napi_common_configuration.cpp b/frameworks/js/napi/inner/napi_common/napi_common_configuration.cpp index af62ddc4d1..6883f4750d 100644 --- a/frameworks/js/napi/inner/napi_common/napi_common_configuration.cpp +++ b/frameworks/js/napi/inner/napi_common/napi_common_configuration.cpp @@ -85,6 +85,12 @@ napi_value WrapConfiguration(napi_env env, const AppExecFwk::Configuration &conf jsValue = WrapDoubleToJS(env, fontWeightScale != "" ? std::stod(fontWeightScale) : 1.0); SetPropertyValueByPropertyName(env, jsObject, "fontWeightScale", jsValue); + jsValue = WrapStringToJS(env, configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_MCC)); + SetPropertyValueByPropertyName(env, jsObject, "mcc", jsValue); + + jsValue = WrapStringToJS(env, configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_MNC)); + SetPropertyValueByPropertyName(env, jsObject, "mnc", jsValue); + return jsObject; } diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index c748845ccf..d87613789d 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -137,6 +137,7 @@ ohos_shared_library("abilitykit_utils") { "${ability_runtime_native_path}/ability/native/ability_handler.cpp", "${ability_runtime_native_path}/ability/native/ability_local_record.cpp", "${ability_runtime_native_path}/ability/native/configuration_utils.cpp", + "${ability_runtime_native_path}/ability/native/resource_config_helper.cpp", ] deps = [] diff --git a/frameworks/native/ability/native/configuration_utils.cpp b/frameworks/native/ability/native/configuration_utils.cpp index 61e25c6a25..9771a5b0d4 100644 --- a/frameworks/native/ability/native/configuration_utils.cpp +++ b/frameworks/native/ability/native/configuration_utils.cpp @@ -37,66 +37,21 @@ void ConfigurationUtils::UpdateGlobalConfig(const Configuration &configuration, return; } - std::string language; - std::string colormode; - std::string hasPointerDevice; - GetGlobalConfig(configuration, language, colormode, hasPointerDevice); - std::string colorModeIsSetByApp = configuration.GetItem(AAFwk::GlobalConfigurationKey::COLORMODE_IS_SET_BY_APP); - std::unique_ptr resConfig(Global::Resource::CreateResConfig()); - if (resConfig == nullptr) { - TAG_LOGE(AAFwkTag::ABILITY, "Create resource config failed."); - return; - } - resourceManager->GetResConfig(*resConfig); - -#ifdef SUPPORT_GRAPHICS - if (!language.empty()) { - UErrorCode status = U_ZERO_ERROR; - icu::Locale locale = icu::Locale::forLanguageTag(language, status); - TAG_LOGD(AAFwkTag::ABILITY, "get Locale::forLanguageTag return[%{public}d].", static_cast(status)); - if (status == U_ZERO_ERROR) { - resConfig->SetLocaleInfo(locale); - } - - const icu::Locale *localeInfo = resConfig->GetLocaleInfo(); - if (localeInfo != nullptr) { - TAG_LOGD(AAFwkTag::ABILITY, "Update config, language: %{public}s, script: %{public}s, region: %{public}s", - localeInfo->getLanguage(), localeInfo->getScript(), localeInfo->getCountry()); - } - } -#endif - - if (!colormode.empty()) { - resConfig->SetColorMode(AppExecFwk::ConvertColorMode(colormode)); - TAG_LOGD(AAFwkTag::ABILITY, "Update config, colorMode: %{public}d", resConfig->GetColorMode()); - } - - if (!hasPointerDevice.empty()) { - resConfig->SetInputDevice(AppExecFwk::ConvertHasPointerDevice(hasPointerDevice)); - TAG_LOGD(AAFwkTag::ABILITY, "Update config, hasPointerDevice: %{public}d", resConfig->GetInputDevice()); - } - - if (!colorModeIsSetByApp.empty()) { - TAG_LOGD(AAFwkTag::ABILITY, "set app true"); - resConfig->SetAppColorMode(true); - } - - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "resourceManager->UpdateResConfig"); - Global::Resource::RState ret = resourceManager->UpdateResConfig(*resConfig); - if (ret != Global::Resource::RState::SUCCESS) { - TAG_LOGE(AAFwkTag::ABILITY, "Update resource config failed with %{public}d.", static_cast(ret)); - return; - } - - TAG_LOGD(AAFwkTag::ABILITY, "Update resource config succeed."); + ResourceConfigHelper resourceConfig; + GetGlobalConfig(configuration, resourceConfig); + resourceConfig.UpdateResConfig(configuration, resourceManager); } void ConfigurationUtils::GetGlobalConfig(const Configuration &configuration, - std::string &language, std::string &colormode, std::string &hasPointerDevice) + OHOS::AbilityRuntime::ResourceConfigHelper &resourceConfig) { - language = configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); - colormode = configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE); - hasPointerDevice = configuration.GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE); + resourceConfig.SetLanguage(configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE)); + resourceConfig.SetColormode(configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE)); + resourceConfig.SetHasPointerDevice(configuration.GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE)); + resourceConfig.SetMcc(configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_MCC)); + resourceConfig.SetMnc(configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_MNC)); + resourceConfig.SetColorModeIsSetByApp( + configuration.GetItem(AAFwk::GlobalConfigurationKey::COLORMODE_IS_SET_BY_APP)); } #ifdef SUPPORT_GRAPHICS diff --git a/frameworks/native/ability/native/resource_config_helper.cpp b/frameworks/native/ability/native/resource_config_helper.cpp new file mode 100644 index 0000000000..71c7f8b5bf --- /dev/null +++ b/frameworks/native/ability/native/resource_config_helper.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2023-2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "resource_config_helper.h" +#include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" +#include "configuration_convertor.h" +#include "hitrace_meter.h" + +namespace OHOS { +namespace AbilityRuntime { +using namespace AppExecFwk; + +std::string ResourceConfigHelper::GetLanguage() +{ + return language_; +} +void ResourceConfigHelper::SetLanguage(std::string language) +{ + language_ = language; +} + +std::string ResourceConfigHelper::GetColormode() +{ + return colormode_; +} +void ResourceConfigHelper::SetColormode(std::string colormode) +{ + colormode_ = colormode; +} +std::string ResourceConfigHelper::GetHasPointerDevice() +{ + return hasPointerDevice_; +} +void ResourceConfigHelper::SetHasPointerDevice(std::string hasPointerDevice) +{ + hasPointerDevice_ = hasPointerDevice; +} +std::string ResourceConfigHelper::GetMcc() +{ + return mcc_; +} +void ResourceConfigHelper::SetMcc(std::string mcc) +{ + mcc_ = mcc; +} +std::string ResourceConfigHelper::GetMnc() +{ + return mnc_; +} +void ResourceConfigHelper::SetMnc(std::string mnc) +{ + mnc_ = mnc; +} + +std::string ResourceConfigHelper::GetColorModeIsSetByApp() +{ + return colorModeIsSetByApp_; +} +void ResourceConfigHelper::SetColorModeIsSetByApp(std::string colorModeIsSetByApp) +{ + colorModeIsSetByApp_ = colorModeIsSetByApp; +} + +void ResourceConfigHelper::UpdateResConfig( + const AppExecFwk::Configuration &configuration, std::shared_ptr resourceManager) +{ + if (resourceManager == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY, "Resource manager is invalid."); + return; + } + std::unique_ptr resConfig(Global::Resource::CreateResConfig()); + if (resConfig == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY, "Create res config failed."); + return; + } + resourceManager->GetResConfig(*resConfig); +#ifdef SUPPORT_GRAPHICS + if (!language_.empty()) { + UErrorCode status = U_ZERO_ERROR; + icu::Locale locale = icu::Locale::forLanguageTag(language_, status); + TAG_LOGD(AAFwkTag::ABILITY, "Get forLanguageTag return[%{public}d].", static_cast(status)); + if (status == U_ZERO_ERROR) { + resConfig->SetLocaleInfo(locale); + } + const icu::Locale *localeInfo = resConfig->GetLocaleInfo(); + if (localeInfo != nullptr) { + TAG_LOGD(AAFwkTag::ABILITY, "Update config, language: %{public}s, script: %{public}s," + " region: %{public}s", localeInfo->getLanguage(), localeInfo->getScript(), localeInfo->getCountry()); + } + } +#endif + UpdateResConfig(resConfig); + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "resourceManager->UpdateResConfig"); + Global::Resource::RState ret = resourceManager->UpdateResConfig(*resConfig); + if (ret != Global::Resource::RState::SUCCESS) { + TAG_LOGE(AAFwkTag::ABILITY, "Update resource config failed with %{public}d.", static_cast(ret)); + return; + } + TAG_LOGD(AAFwkTag::ABILITY, "Current colorMode: %{public}d, hasPointerDevice: %{public}d.", + resConfig->GetColorMode(), resConfig->GetInputDevice()); +} + +void ResourceConfigHelper::UpdateResConfig(std::unique_ptr &resConfig) +{ + if (resConfig == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY, "resConfig is nullptr!"); + return; + } + if (!colormode_.empty()) { + resConfig->SetColorMode(AppExecFwk::ConvertColorMode(colormode_)); + } + if (!hasPointerDevice_.empty()) { + resConfig->SetInputDevice(AppExecFwk::ConvertHasPointerDevice(hasPointerDevice_)); + } + if (!colorModeIsSetByApp_.empty()) { + TAG_LOGD(AAFwkTag::ABILITY, "set app true"); + resConfig->SetAppColorMode(true); + } + if (!mcc_.empty()) { + uint32_t mccNum = 0; + if (ConvertStringToUint32(mcc_, mccNum)) { + resConfig->SetMcc(mccNum); + TAG_LOGD(AAFwkTag::ABILITY, "set mcc: %{public}u", resConfig->GetMcc()); + } + } + if (!mnc_.empty()) { + uint32_t mncNum = 0; + if (ConvertStringToUint32(mnc_, mncNum)) { + resConfig->SetMnc(mncNum); + TAG_LOGD(AAFwkTag::ABILITY, "set mnc: %{public}u", resConfig->GetMnc()); + } + } +} + +bool ResourceConfigHelper::ConvertStringToUint32(std::string source, uint32_t &result) +{ + try { + result = static_cast(std::stoi(source)); + } catch (...) { + TAG_LOGW(AAFwkTag::ABILITY, "source:%{public}s is invalid.", source.c_str()); + return false; + } + return true; +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ability/native/ui_ability.cpp b/frameworks/native/ability/native/ui_ability.cpp index 5644db082e..5ff0eb739d 100644 --- a/frameworks/native/ability/native/ui_ability.cpp +++ b/frameworks/native/ability/native/ui_ability.cpp @@ -27,6 +27,7 @@ #include "ohos_application.h" #include "reverse_continuation_scheduler_primary_stage.h" #include "runtime.h" +#include "resource_config_helper.h" namespace OHOS { namespace AbilityRuntime { @@ -290,44 +291,10 @@ void UIAbility::NotifyContinuationResult(const AAFwk::Want &want, bool success) void UIAbility::OnConfigurationUpdatedNotify(const AppExecFwk::Configuration &configuration) { TAG_LOGD(AAFwkTag::UIABILITY, "begin"); - std::string language; - std::string colormode; - std::string hasPointerDevice; - InitConfigurationProperties(configuration, language, colormode, hasPointerDevice); - std::string colorModeIsSetByApp = configuration.GetItem(AAFwk::GlobalConfigurationKey::COLORMODE_IS_SET_BY_APP); - // Notify ResourceManager - std::unique_ptr resConfig(Global::Resource::CreateResConfig()); - if (resConfig == nullptr) { - TAG_LOGE(AAFwkTag::UIABILITY, "Create res config failed."); - return; - } + ResourceConfigHelper resourceConfig; + InitConfigurationProperties(configuration, resourceConfig); auto resourceManager = GetResourceManager(); - if (resourceManager != nullptr) { - resourceManager->GetResConfig(*resConfig); -#ifdef SUPPORT_GRAPHICS - if (!language.empty()) { - UErrorCode status = U_ZERO_ERROR; - icu::Locale locale = icu::Locale::forLanguageTag(language, status); - TAG_LOGD(AAFwkTag::UIABILITY, "Get forLanguageTag return[%{public}d].", static_cast(status)); - if (status == U_ZERO_ERROR) { - resConfig->SetLocaleInfo(locale); - } - } -#endif - if (!colormode.empty()) { - resConfig->SetColorMode(AppExecFwk::ConvertColorMode(colormode)); - } - if (!hasPointerDevice.empty()) { - resConfig->SetInputDevice(AppExecFwk::ConvertHasPointerDevice(hasPointerDevice)); - } - if (!colorModeIsSetByApp.empty()) { - TAG_LOGD(AAFwkTag::UIABILITY, "set app true"); - resConfig->SetAppColorMode(true); - } - resourceManager->UpdateResConfig(*resConfig); - TAG_LOGD(AAFwkTag::UIABILITY, "Current colorMode: %{public}d, hasPointerDevice: %{public}d.", - resConfig->GetColorMode(), resConfig->GetInputDevice()); - } + resourceConfig.UpdateResConfig(configuration, resourceManager); if (abilityContext_ != nullptr && application_ != nullptr) { abilityContext_->SetConfiguration(application_->GetConfiguration()); @@ -337,25 +304,38 @@ void UIAbility::OnConfigurationUpdatedNotify(const AppExecFwk::Configuration &co TAG_LOGD(AAFwkTag::UIABILITY, "End."); } -void UIAbility::InitConfigurationProperties(const AppExecFwk::Configuration &changeConfiguration, std::string &language, - std::string &colormode, std::string &hasPointerDevice) +void UIAbility::InitConfigurationProperties(const AppExecFwk::Configuration &changeConfiguration, + ResourceConfigHelper &resourceConfig) { + resourceConfig.SetMcc(changeConfiguration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_MCC)); + resourceConfig.SetMnc(changeConfiguration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_MNC)); + resourceConfig.SetColorModeIsSetByApp( + changeConfiguration.GetItem(AAFwk::GlobalConfigurationKey::COLORMODE_IS_SET_BY_APP)); if (setting_) { auto displayId = std::atoi(setting_->GetProperty(AppExecFwk::AbilityStartSetting::WINDOW_DISPLAY_ID_KEY).c_str()); - language = changeConfiguration.GetItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); - colormode = changeConfiguration.GetItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE); - hasPointerDevice = changeConfiguration.GetItem(displayId, AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE); + resourceConfig.SetLanguage(changeConfiguration.GetItem(displayId, + AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE)); + resourceConfig.SetColormode(changeConfiguration.GetItem(displayId, + AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE)); + resourceConfig.SetHasPointerDevice(changeConfiguration.GetItem(displayId, + AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE)); TAG_LOGD(AAFwkTag::UIABILITY, "displayId: [%{public}d], language: [%{public}s], colormode: [%{public}s], " - "hasPointerDevice: [%{public}s].", - displayId, language.c_str(), colormode.c_str(), hasPointerDevice.c_str()); + "hasPointerDevice: [%{public}s] mcc: [%{public}s], mnc: [%{public}s].", displayId, + resourceConfig.GetLanguage().c_str(), resourceConfig.GetColormode().c_str(), + resourceConfig.GetHasPointerDevice().c_str(), resourceConfig.GetMcc().c_str(), + resourceConfig.GetMnc().c_str()); } else { - language = changeConfiguration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); - colormode = changeConfiguration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE); - hasPointerDevice = changeConfiguration.GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE); + resourceConfig.SetLanguage(changeConfiguration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE)); + resourceConfig.SetColormode(changeConfiguration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE)); + resourceConfig.SetHasPointerDevice(changeConfiguration.GetItem( + AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE)); TAG_LOGD(AAFwkTag::UIABILITY, - "Language: [%{public}s], colormode: [%{public}s], hasPointerDevice: [%{public}s].", - language.c_str(), colormode.c_str(), hasPointerDevice.c_str()); + "Language: [%{public}s], colormode: [%{public}s], hasPointerDevice: [%{public}s] " + "mcc: [%{public}s], mnc: [%{public}s].", + resourceConfig.GetLanguage().c_str(), resourceConfig.GetColormode().c_str(), + resourceConfig.GetHasPointerDevice().c_str(), resourceConfig.GetMcc().c_str(), + resourceConfig.GetMnc().c_str()); } } diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 361b620986..208087649f 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -57,6 +57,7 @@ #include "freeze_util.h" #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" +#include "resource_config_helper.h" #ifdef SUPPORT_GRAPHICS #include "locale_config.h" #include "ace_forward_compatibility.h" @@ -1107,6 +1108,21 @@ bool MainThread::InitResourceManager(std::shared_ptr %{public}d.", deviceType.c_str(), ConvertDeviceType(deviceType)); resConfig->SetDeviceType(ConvertDeviceType(deviceType)); + + std::string mcc = config.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_MCC); + TAG_LOGD(AAFwkTag::APPKIT, "mcc is %{public}s.", mcc.c_str()); + uint32_t mccNum = 0; + if (AbilityRuntime::ResourceConfigHelper::ConvertStringToUint32(mcc, mccNum)) { + resConfig->SetMcc(mccNum); + } + + std::string mnc = config.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_MNC); + TAG_LOGD(AAFwkTag::APPKIT, "mnc is %{public}s.", mnc.c_str()); + uint32_t mncNum = 0; + if (AbilityRuntime::ResourceConfigHelper::ConvertStringToUint32(mnc, mncNum)) { + resConfig->SetMnc(mncNum); + } + resourceManager->UpdateResConfig(*resConfig); return true; } diff --git a/interfaces/kits/native/ability/native/configuration_utils.h b/interfaces/kits/native/ability/native/configuration_utils.h index 1c5534b0be..e7fe180655 100644 --- a/interfaces/kits/native/ability/native/configuration_utils.h +++ b/interfaces/kits/native/ability/native/configuration_utils.h @@ -17,6 +17,7 @@ #define OHOS_ABILITY_RUNTIME_CONFIGURATION_UTILS_H #include "configuration.h" +#include "resource_config_helper.h" #ifdef SUPPORT_GRAPHICS #include "display_manager.h" #endif @@ -40,8 +41,8 @@ public: void UpdateGlobalConfig(const Configuration &configuration, std::shared_ptr resourceManager); private: - void GetGlobalConfig(const Configuration &configuration, std::string &language, std::string &colormode, - std::string &hasPointerDevice); + void GetGlobalConfig(const Configuration &configuration, + OHOS::AbilityRuntime::ResourceConfigHelper &resourceConfig); #ifdef SUPPORT_GRAPHICS public: diff --git a/interfaces/kits/native/ability/native/resource_config_helper.h b/interfaces/kits/native/ability/native/resource_config_helper.h new file mode 100644 index 0000000000..106db58d77 --- /dev/null +++ b/interfaces/kits/native/ability/native/resource_config_helper.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_RESOURCE_CONFIG_HELPER_H +#define OHOS_ABILITY_RUNTIME_RESOURCE_CONFIG_HELPER_H +#include "resource_manager.h" +#include "configuration.h" +#ifdef SUPPORT_GRAPHICS +#include "display_manager.h" +#endif + +namespace OHOS { +namespace AppExecFwk { + +} +namespace AbilityRuntime { +class ResourceConfigHelper { +public: + ResourceConfigHelper() = default; + ~ResourceConfigHelper() = default; + std::string GetLanguage(); + void SetLanguage(std::string language); + std::string GetColormode(); + void SetColormode(std::string colormode); + std::string GetHasPointerDevice(); + void SetHasPointerDevice(std::string hasPointerDevice); + std::string GetMcc(); + void SetMcc(std::string mcc); + std::string GetMnc(); + void SetMnc(std::string mnc); + std::string GetColorModeIsSetByApp(); + void SetColorModeIsSetByApp(std::string colorModeIsSetByApp); + + void UpdateResConfig(const AppExecFwk::Configuration &configuration, + std::shared_ptr resourceManager); + + static bool ConvertStringToUint32(std::string source, uint32_t &result); + +private: + std::string language_; + std::string colormode_; + std::string hasPointerDevice_; + std::string mcc_; + std::string mnc_; + std::string colorModeIsSetByApp_; + + void UpdateResConfig(std::unique_ptr &resConfig); +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_RESOURCE_CONFIG_HELPER_H diff --git a/interfaces/kits/native/ability/native/ui_ability.h b/interfaces/kits/native/ability/native/ui_ability.h index 5319a9c1e3..9f30d25ac4 100644 --- a/interfaces/kits/native/ability/native/ui_ability.h +++ b/interfaces/kits/native/ability/native/ui_ability.h @@ -28,6 +28,7 @@ #include "foundation/ability/ability_runtime/interfaces/kits/native/ability/ability_runtime/ability_context.h" #include "iability_callback.h" #include "want.h" +#include "resource_config_helper.h" #ifdef SUPPORT_GRAPHICS #include "display_manager.h" #include "session_info.h" @@ -340,8 +341,8 @@ private: void HandleCreateAsRecovery(const AAFwk::Want &want); void SetStartAbilitySetting(std::shared_ptr setting); void SetLaunchParam(const AAFwk::LaunchParam &launchParam); - void InitConfigurationProperties(const AppExecFwk::Configuration &changeConfiguration, std::string &language, - std::string &colormode, std::string &hasPointerDevice); + void InitConfigurationProperties(const AppExecFwk::Configuration &changeConfiguration, + ResourceConfigHelper &resourceConfig); std::shared_ptr continuationHandler_ = nullptr; std::shared_ptr continuationManager_ = nullptr; diff --git a/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp index 4d20a82d65..95e0640ce3 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp @@ -748,21 +748,19 @@ HWTEST_F(UIAbilityBaseTest, InitConfigurationProperties_0100, TestSize.Level1) config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, "en"); config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE, "dark"); config.AddItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE, "true"); - std::string language; - std::string colormode; - std::string hasPointerDevice; - ability->InitConfigurationProperties(config, language, colormode, hasPointerDevice); - EXPECT_EQ(language, "en"); - EXPECT_EQ(colormode, "dark"); - EXPECT_EQ(hasPointerDevice, "true"); + AbilityRuntime::ResourceConfigHelper resourceConfig; + ability->InitConfigurationProperties(config, resourceConfig); + EXPECT_EQ(resourceConfig.GetLanguage(), "en"); + EXPECT_EQ(resourceConfig.GetColormode(), "dark"); + EXPECT_EQ(resourceConfig.GetHasPointerDevice(), "true"); // branch when setting is not nullptr auto setting = std::make_shared(); ability->SetStartAbilitySetting(setting); - ability->InitConfigurationProperties(config, language, colormode, hasPointerDevice); - EXPECT_EQ(language, "en"); - EXPECT_EQ(colormode, "dark"); - EXPECT_EQ(hasPointerDevice, "true"); + ability->InitConfigurationProperties(config, resourceConfig); + EXPECT_EQ(resourceConfig.GetLanguage(), "en"); + EXPECT_EQ(resourceConfig.GetColormode(), "dark"); + EXPECT_EQ(resourceConfig.GetHasPointerDevice(), "true"); TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); } From 02a64626649a77c41d74fe3382bfac7609f69c02 Mon Sep 17 00:00:00 2001 From: HUANG Date: Fri, 31 May 2024 11:45:07 +0800 Subject: [PATCH 22/69] =?UTF-8?q?AMS=E5=BD=93=E5=B0=86=E6=96=87=E4=BB=B6ur?= =?UTF-8?q?i/=E6=96=87=E4=BB=B6=E6=89=93=E5=BC=80=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=9A=B4=E9=9C=B2=E7=9A=84=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: HUANG Change-Id: I00bdac5746af46c082a84257e33be2dfb6d7528e --- services/abilitymgr/include/ability_record.h | 2 ++ services/abilitymgr/src/ability_record.cpp | 26 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index 179fb015bd..085004f15d 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -1041,6 +1041,8 @@ private: bool GetUriListFromWant(Want &want, std::vector &uriVec); + void PublishFileOpenEvent(const Want &want); + #ifdef SUPPORT_SCREEN std::shared_ptr GetWantFromMission() const; void SetShowWhenLocked(const AppExecFwk::AbilityInfo &abilityInfo, sptr &info) const; diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 02075af7e6..ef713e822e 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -33,6 +33,9 @@ #include "bundle_mgr_client.h" #include "configuration_convertor.h" #include "connection_state_manager.h" +#include "common_event_data.h" +#include "common_event_manager.h" +#include "common_event_support.h" #include "freeze_util.h" #include "global_constant.h" #include "hitrace_meter.h" @@ -3049,6 +3052,28 @@ bool AbilityRecord::GetUriListFromWant(Want &want, std::vector &uri return true; } +void AbilityRecord::PublishFileOpenEvent(const Want &want) +{ + auto wangUri = want.GetUri(); + std::string uriStr = wangUri.ToString(); + if (!uriStr.empty() && wangUri.GetScheme() == "file") { + TAG_LOGI(AAFwkTag::ABILITYMGR, "ability record, file uri: %{private}s, isGranted: %{public}d", + uriStr.c_str(), isGrantedUriPermission_); + Want msgWant; + msgWant.SetAction("file.event.OPEN_TIME"); + msgWant.SetParam("uri", uriStr); + auto timeNow = std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()).count(); + std::string currentTime = std::to_string(timeNow); + msgWant.SetParam("viewTime", currentTime); + EventFwk::CommonEventData commonData{msgWant}; + EventFwk::CommonEventPublishInfo commonEventPublishInfo; + std::vector subscriberPermissions = {"ohos.permission.MANAGE_LOCAL_ACCOUNTS"}; + commonEventPublishInfo.SetSubscriberPermissions(subscriberPermissions); + EventFwk::CommonEventManager::PublishCommonEvent(commonData, commonEventPublishInfo); + } +} + void AbilityRecord::GrantUriPermission(Want &want, std::string targetBundleName, bool isSandboxApp, uint32_t tokenId) { // reject sandbox to grant uri permission by start ability @@ -3089,6 +3114,7 @@ void AbilityRecord::GrantUriPermission(Want &want, std::string targetBundleName, return; } GrantUriPermissionInner(want, uriVec, targetBundleName, tokenId); + PublishFileOpenEvent(want); } void AbilityRecord::GrantUriPermissionInner(Want &want, std::vector &uriVec, From 22f528d6bf6e072150bc98c2d30ef17b1fc5daf8 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Fri, 31 May 2024 14:35:38 +0800 Subject: [PATCH 23/69] fix bug add autostartup Application identity identification Signed-off-by: jiangzhijun8 --- .../include/auto_startup_info.h | 1 + .../ability_auto_startup_data_manager.h | 7 +- .../include/ability_auto_startup_service.h | 8 ++- .../src/ability_auto_startup_data_manager.cpp | 69 ++++++++++++------ .../src/ability_auto_startup_service.cpp | 71 ++++++++++++------- .../src/ability_bundle_event_callback.cpp | 2 +- .../BUILD.gn | 1 + ...ability_auto_startup_data_manager_test.cpp | 15 ++-- .../BUILD.gn | 1 + .../ability_auto_startup_service_test.cpp | 9 ++- .../BUILD.gn | 1 + .../specified_mission_list_test/BUILD.gn | 1 + 12 files changed, 124 insertions(+), 62 deletions(-) diff --git a/interfaces/inner_api/ability_manager/include/auto_startup_info.h b/interfaces/inner_api/ability_manager/include/auto_startup_info.h index fbe5d4c513..f734e2877f 100644 --- a/interfaces/inner_api/ability_manager/include/auto_startup_info.h +++ b/interfaces/inner_api/ability_manager/include/auto_startup_info.h @@ -32,6 +32,7 @@ public: std::string abilityName; std::string moduleName; std::string abilityTypeName; + std::string accessTokenId; int32_t appCloneIndex = -1; bool ReadFromParcel(Parcel &parcel); diff --git a/services/abilitymgr/include/ability_auto_startup_data_manager.h b/services/abilitymgr/include/ability_auto_startup_data_manager.h index e4787e2a65..954a9be896 100644 --- a/services/abilitymgr/include/ability_auto_startup_data_manager.h +++ b/services/abilitymgr/include/ability_auto_startup_data_manager.h @@ -37,13 +37,14 @@ public: int32_t DeleteAutoStartupData(const AutoStartupInfo &info); - int32_t DeleteAutoStartupData(const std::string &bundleName); + int32_t DeleteAutoStartupData(const std::string &bundleName, int32_t uid); AutoStartupStatus QueryAutoStartupData(const AutoStartupInfo &info); int32_t QueryAllAutoStartupApplications(std::vector &infoList); - int32_t GetCurrentAppAutoStartupData(const std::string &bundleName, std::vector &infoList); + int32_t GetCurrentAppAutoStartupData(const std::string &bundleName, + std::vector &infoList, const std::string &accessTokenId); private: DistributedKv::Status GetKvStore(); @@ -55,7 +56,7 @@ private: AutoStartupInfo ConvertAutoStartupInfoFromKeyAndValue( const DistributedKv::Key &key, const DistributedKv::Value &value); bool IsEqual(const DistributedKv::Key &key, const AutoStartupInfo &info); - bool IsEqual(const DistributedKv::Key &key, const std::string &bundleName); + bool IsEqual(const DistributedKv::Key &key, const std::string &accessTokenId); static const DistributedKv::AppId APP_ID; static const DistributedKv::StoreId STORE_ID; diff --git a/services/abilitymgr/include/ability_auto_startup_service.h b/services/abilitymgr/include/ability_auto_startup_service.h index 6f7ec59a2a..f3d2debe5a 100644 --- a/services/abilitymgr/include/ability_auto_startup_service.h +++ b/services/abilitymgr/include/ability_auto_startup_service.h @@ -78,9 +78,10 @@ public: /** * @brief Delete current bundleName auto start up data. * @param bundleName The current bundleName. + * @param uid The uid. * @return Returns ERR_OK on success, others on failure. */ - int32_t DeleteAutoStartupData(const std::string &bundleName); + int32_t DeleteAutoStartupData(const std::string &bundleName, int32_t uid); /** * @brief Check current bundleName auto start up data. @@ -137,7 +138,8 @@ private: std::string GetSelfApplicationBundleName(); bool CheckSelfApplication(const std::string &bundleName); bool GetBundleInfo(const std::string &bundleName, AppExecFwk::BundleInfo &bundleInfo, int32_t uid = -1); - bool GetAbilityData(const AutoStartupInfo &info, bool &isVisible, std::string &abilityTypeName); + bool GetAbilityData(const AutoStartupInfo &info, bool &isVisible, + std::string &abilityTypeName, std::string &accessTokenId); std::string GetAbilityTypeName(AppExecFwk::AbilityInfo abilityInfo); std::string GetExtensionTypeName(AppExecFwk::ExtensionAbilityInfo extensionInfo); std::shared_ptr GetBundleMgrClient(); @@ -145,7 +147,7 @@ private: int32_t CheckPermissionForSelf(const std::string &bundleName); int32_t CheckPermissionForEDM(); int32_t InnerApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool isSet, bool flag); - int32_t GetAbilityInfo(const AutoStartupInfo &info, std::string &abilityTypeName); + int32_t GetAbilityInfo(const AutoStartupInfo &info, std::string &abilityTypeName, std::string &accessTokenId); mutable std::mutex autoStartUpMutex_; mutable std::mutex deathRecipientsMutex_; diff --git a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp index 9bac0ebd83..536aac8f88 100644 --- a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp +++ b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp @@ -18,11 +18,13 @@ #include #include +#include "accesstoken_kit.h" #include "errors.h" #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "nlohmann/json.hpp" #include "types.h" +#include "os_account_manager_wrapper.h" namespace OHOS { namespace AbilityRuntime { @@ -37,6 +39,7 @@ const std::string JSON_KEY_IS_AUTO_STARTUP = "isAutoStartup"; const std::string JSON_KEY_IS_EDM_FORCE = "isEdmForce"; const std::string JSON_KEY_TYPE_NAME = "abilityTypeName"; const std::string JSON_KEY_APP_CLONE_INDEX = "appCloneIndex"; +const std::string JSON_KEY_ACCESS_TOKENID = "accessTokenId"; } // namespace const DistributedKv::AppId AbilityAutoStartupDataManager::APP_ID = { "auto_startup_storage" }; const DistributedKv::StoreId AbilityAutoStartupDataManager::STORE_ID = { "auto_startup_infos" }; @@ -91,13 +94,14 @@ bool AbilityAutoStartupDataManager::CheckKvStore() int32_t AbilityAutoStartupDataManager::InsertAutoStartupData( const AutoStartupInfo &info, bool isAutoStartup, bool isEdmForce) { - if (info.bundleName.empty() || info.abilityName.empty()) { + if (info.bundleName.empty() || info.abilityName.empty() || info.accessTokenId.empty()) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Invalid value."); return ERR_INVALID_VALUE; } - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", - info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, + "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str()); { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { @@ -124,13 +128,14 @@ int32_t AbilityAutoStartupDataManager::InsertAutoStartupData( int32_t AbilityAutoStartupDataManager::UpdateAutoStartupData( const AutoStartupInfo &info, bool isAutoStartup, bool isEdmForce) { - if (info.bundleName.empty() || info.abilityName.empty()) { + if (info.bundleName.empty() || info.abilityName.empty() || info.accessTokenId.empty()) { TAG_LOGW(AAFwkTag::AUTO_STARTUP, "Invalid value!"); return ERR_INVALID_VALUE; } - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", - info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, + "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str()); { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { @@ -164,13 +169,14 @@ int32_t AbilityAutoStartupDataManager::UpdateAutoStartupData( int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const AutoStartupInfo &info) { - if (info.bundleName.empty() || info.abilityName.empty()) { + if (info.bundleName.empty() || info.abilityName.empty() || info.accessTokenId.empty()) { TAG_LOGW(AAFwkTag::AUTO_STARTUP, "Invalid value!"); return ERR_INVALID_VALUE; } - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", - info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, + "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str()); { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { @@ -193,14 +199,23 @@ int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const AutoStartupIn return ERR_OK; } -int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const std::string &bundleName) +int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const std::string &bundleName, int32_t uid) { - if (bundleName.empty()) { + int32_t userId; + if (DelayedSingleton::GetInstance()-> + GetOsAccountLocalIdFromUid(uid, userId) != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Get GetOsAccountLocalIdFromUid failed."); + return ERR_INVALID_VALUE; + } + uint32_t accessTokenId = Security::AccessToken::AccessTokenKit::GetHapTokenID(userId, bundleName, 0); + auto accessTokenIdStr = std::to_string(accessTokenId); + if (bundleName.empty() || accessTokenIdStr.empty()) { TAG_LOGW(AAFwkTag::AUTO_STARTUP, "Invalid value!"); return ERR_INVALID_VALUE; } - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s.", bundleName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, accessTokenId: %{public}s.", + bundleName.c_str(), accessTokenIdStr.c_str()); { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { @@ -217,7 +232,7 @@ int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const std::string & } for (const auto &item : allEntries) { - if (IsEqual(item.key, bundleName)) { + if (IsEqual(item.key, accessTokenIdStr)) { { std::lock_guard lock(kvStorePtrMutex_); status = kvStorePtr_->Delete(item.key); @@ -235,14 +250,15 @@ int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const std::string & AutoStartupStatus AbilityAutoStartupDataManager::QueryAutoStartupData(const AutoStartupInfo &info) { AutoStartupStatus asustatus; - if (info.bundleName.empty() || info.abilityName.empty()) { + if (info.bundleName.empty() || info.abilityName.empty() || info.accessTokenId.empty()) { TAG_LOGW(AAFwkTag::AUTO_STARTUP, "Invalid value!"); asustatus.code = ERR_INVALID_VALUE; return asustatus; } - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", - info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, + "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str()); { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { @@ -301,7 +317,7 @@ int32_t AbilityAutoStartupDataManager::QueryAllAutoStartupApplications(std::vect } int32_t AbilityAutoStartupDataManager::GetCurrentAppAutoStartupData( - const std::string &bundleName, std::vector &infoList) + const std::string &bundleName, std::vector &infoList, const std::string &accessTokenId) { TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called."); { @@ -320,7 +336,7 @@ int32_t AbilityAutoStartupDataManager::GetCurrentAppAutoStartupData( } for (const auto &item : allEntries) { - if (IsEqual(item.key, bundleName)) { + if (IsEqual(item.key, accessTokenId)) { infoList.emplace_back(ConvertAutoStartupInfoFromKeyAndValue(item.key, item.value)); } } @@ -364,6 +380,7 @@ DistributedKv::Key AbilityAutoStartupDataManager::ConvertAutoStartupDataToKey(co { JSON_KEY_MODULE_NAME, info.moduleName }, { JSON_KEY_ABILITY_NAME, info.abilityName }, { JSON_KEY_APP_CLONE_INDEX, info.appCloneIndex }, + { JSON_KEY_ACCESS_TOKENID, info.accessTokenId }, }; DistributedKv::Key key(jsonObject.dump()); TAG_LOGD(AAFwkTag::AUTO_STARTUP, "key: %{public}s.", key.ToString().c_str()); @@ -406,6 +423,9 @@ AutoStartupInfo AbilityAutoStartupDataManager::ConvertAutoStartupInfoFromKeyAndV info.abilityTypeName = jsonValueObject.at(JSON_KEY_TYPE_NAME).get(); } + if (jsonValueObject.contains(JSON_KEY_ACCESS_TOKENID) && jsonValueObject[JSON_KEY_ACCESS_TOKENID].is_string()) { + info.accessTokenId = jsonValueObject.at(JSON_KEY_ACCESS_TOKENID).get(); + } return info; } @@ -435,10 +455,17 @@ bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const return false; } } + + if (jsonObject.contains(JSON_KEY_ACCESS_TOKENID) && jsonObject[JSON_KEY_ACCESS_TOKENID].is_string()) { + if (info.accessTokenId != jsonObject.at(JSON_KEY_ACCESS_TOKENID).get()) { + return false; + } + } + return true; } -bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const std::string &bundleName) +bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const std::string &accessTokenId) { nlohmann::json jsonObject = nlohmann::json::parse(key.ToString(), nullptr, false); if (jsonObject.is_discarded()) { @@ -446,8 +473,8 @@ bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const return false; } - if (jsonObject.contains(JSON_KEY_BUNDLE_NAME) && jsonObject[JSON_KEY_BUNDLE_NAME].is_string()) { - if (bundleName == jsonObject.at(JSON_KEY_BUNDLE_NAME).get()) { + if (jsonObject.contains(JSON_KEY_ACCESS_TOKENID) && jsonObject[JSON_KEY_ACCESS_TOKENID].is_string()) { + if (accessTokenId == jsonObject.at(JSON_KEY_ACCESS_TOKENID).get()) { return true; } } diff --git a/services/abilitymgr/src/ability_auto_startup_service.cpp b/services/abilitymgr/src/ability_auto_startup_service.cpp index 4d19c98399..00e4915956 100644 --- a/services/abilitymgr/src/ability_auto_startup_service.cpp +++ b/services/abilitymgr/src/ability_auto_startup_service.cpp @@ -17,6 +17,7 @@ #include #include +#include #include "ability_auto_startup_data_manager.h" #include "ability_manager_errors.h" @@ -102,8 +103,9 @@ int32_t AbilityAutoStartupService::UnregisterAutoStartupSystemCallback(const spt int32_t AbilityAutoStartupService::SetApplicationAutoStartup(const AutoStartupInfo &info) { - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", - info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, + "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str()); int32_t code = CheckPermissionForSystem(); if (code != ERR_OK) { return code; @@ -111,7 +113,8 @@ int32_t AbilityAutoStartupService::SetApplicationAutoStartup(const AutoStartupIn bool isVisible; std::string abilityTypeName; - if (!GetAbilityData(info, isVisible, abilityTypeName)) { + std::string accessTokenId; + if (!GetAbilityData(info, isVisible, abilityTypeName, accessTokenId)) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get ability data."); return INNER_ERR; } @@ -123,6 +126,7 @@ int32_t AbilityAutoStartupService::SetApplicationAutoStartup(const AutoStartupIn AutoStartupInfo fullInfo(info); fullInfo.abilityTypeName = abilityTypeName; + fullInfo.accessTokenId = accessTokenId; return InnerSetApplicationAutoStartup(fullInfo); } @@ -163,8 +167,9 @@ int32_t AbilityAutoStartupService::InnerSetApplicationAutoStartup(const AutoStar int32_t AbilityAutoStartupService::CancelApplicationAutoStartup(const AutoStartupInfo &info) { - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", - info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, + "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str()); int32_t code = CheckPermissionForSystem(); if (code != ERR_OK) { return code; @@ -172,7 +177,8 @@ int32_t AbilityAutoStartupService::CancelApplicationAutoStartup(const AutoStartu bool isVisible; std::string abilityTypeName; - if (!GetAbilityData(info, isVisible, abilityTypeName)) { + std::string accessTokenId; + if (!GetAbilityData(info, isVisible, abilityTypeName, accessTokenId)) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get ability data."); return INNER_ERR; } @@ -184,6 +190,7 @@ int32_t AbilityAutoStartupService::CancelApplicationAutoStartup(const AutoStartu AutoStartupInfo fullInfo(info); fullInfo.abilityTypeName = abilityTypeName; + fullInfo.accessTokenId = accessTokenId; return InnerCancelApplicationAutoStartup(fullInfo); } @@ -237,17 +244,23 @@ int32_t AbilityAutoStartupService::QueryAllAutoStartupApplicationsWithoutPermiss return DelayedSingleton::GetInstance()->QueryAllAutoStartupApplications(infoList); } -int32_t AbilityAutoStartupService::DeleteAutoStartupData(const std::string &bundleName) +int32_t AbilityAutoStartupService::DeleteAutoStartupData(const std::string &bundleName, const int32_t uid) { TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called."); - return DelayedSingleton::GetInstance()->DeleteAutoStartupData(bundleName); + return DelayedSingleton::GetInstance()->DeleteAutoStartupData(bundleName, uid); } int32_t AbilityAutoStartupService::CheckAutoStartupData(const std::string &bundleName, int32_t uid) { + AppExecFwk::BundleInfo bundleInfo; + if (!GetBundleInfo(bundleName, bundleInfo, uid)) { + return INNER_ERR; + } + auto tokenId = bundleInfo.applicationInfo.accessTokenId; + std::string accessTokenIdStr = std::to_string(tokenId); std::vector infoList; int32_t result = DelayedSingleton::GetInstance()->GetCurrentAppAutoStartupData( - bundleName, infoList); + bundleName, infoList, accessTokenIdStr); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get auto startup data."); return result; @@ -256,11 +269,6 @@ int32_t AbilityAutoStartupService::CheckAutoStartupData(const std::string &bundl return ERR_OK; } - AppExecFwk::BundleInfo bundleInfo; - if (!GetBundleInfo(bundleName, bundleInfo, uid)) { - return INNER_ERR; - } - bool isFound = false; for (auto info : infoList) { for (auto abilityInfo : bundleInfo.abilityInfos) { @@ -274,15 +282,16 @@ int32_t AbilityAutoStartupService::CheckAutoStartupData(const std::string &bundl if (!isFound) { TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Current bundleName not found in Datebase."); - return DelayedSingleton::GetInstance()->DeleteAutoStartupData(bundleName); + return DelayedSingleton::GetInstance()->DeleteAutoStartupData(bundleName, uid); } return ERR_OK; } void AbilityAutoStartupService::ExecuteCallbacks(bool isCallOn, const AutoStartupInfo &info) { - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", - info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, + "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str()); for (auto item : callbackVector_) { auto remoteSystemCallback = iface_cast(item); if (remoteSystemCallback != nullptr) { @@ -443,15 +452,18 @@ bool AbilityAutoStartupService::GetBundleInfo( } bool AbilityAutoStartupService::GetAbilityData( - const AutoStartupInfo &info, bool &isVisible, std::string &abilityTypeName) + const AutoStartupInfo &info, bool &isVisible, std::string &abilityTypeName, std::string &accessTokenId) { - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", - info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, + "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str()); AppExecFwk::BundleInfo bundleInfo; if (!GetBundleInfo(info.bundleName, bundleInfo)) { return false; } + auto accessTokenIdStr = bundleInfo.applicationInfo.accessTokenId; + accessTokenId = std::to_string(accessTokenIdStr); for (auto abilityInfo : bundleInfo.abilityInfos) { if ((abilityInfo.bundleName == info.bundleName) && (abilityInfo.name == info.abilityName)) { if (info.moduleName.empty() || (abilityInfo.moduleName == info.moduleName)) { @@ -538,10 +550,11 @@ int32_t AbilityAutoStartupService::CheckPermissionForSelf(const std::string &bun return ERR_OK; } -int32_t AbilityAutoStartupService::GetAbilityInfo(const AutoStartupInfo &info, std::string &abilityTypeName) +int32_t AbilityAutoStartupService::GetAbilityInfo( + const AutoStartupInfo &info, std::string &abilityTypeName, std::string &accessTokenId) { bool isVisible = false; - if (!GetAbilityData(info, isVisible, abilityTypeName)) { + if (!GetAbilityData(info, isVisible, abilityTypeName, accessTokenId)) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get ability data."); return INNER_ERR; } @@ -561,12 +574,14 @@ int32_t AbilityAutoStartupService::SetApplicationAutoStartupByEDM(const AutoStar return errorCode; } std::string typeName; - errorCode = GetAbilityInfo(info, typeName); + std::string accessTokenId; + errorCode = GetAbilityInfo(info, typeName, accessTokenId); if (errorCode != ERR_OK) { return errorCode; } AutoStartupInfo fullInfo(info); fullInfo.abilityTypeName = typeName; + fullInfo.accessTokenId = accessTokenId; return InnerApplicationAutoStartupByEDM(fullInfo, true, flag); } @@ -577,20 +592,24 @@ int32_t AbilityAutoStartupService::CancelApplicationAutoStartupByEDM(const AutoS return errorCode; } std::string typeName; - errorCode = GetAbilityInfo(info, typeName); + std::string accessTokenId; + errorCode = GetAbilityInfo(info, typeName, accessTokenId); if (errorCode != ERR_OK) { return errorCode; } AutoStartupInfo fullInfo(info); fullInfo.abilityTypeName = typeName; + fullInfo.accessTokenId = accessTokenId; return InnerApplicationAutoStartupByEDM(fullInfo, false, flag); } int32_t AbilityAutoStartupService::InnerApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool isSet, bool flag) { TAG_LOGD(AAFwkTag::AUTO_STARTUP, - "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, isSet: %{public}d.," - "flag: %{public}d.", info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), isSet, flag); + "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s," + " isSet: %{public}d.,""flag: %{public}d.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), + info.accessTokenId.c_str(), isSet, flag); AutoStartupStatus status = DelayedSingleton::GetInstance()->QueryAutoStartupData(info); if (status.code != ERR_OK && status.code != ERR_NAME_NOT_FOUND) { diff --git a/services/abilitymgr/src/ability_bundle_event_callback.cpp b/services/abilitymgr/src/ability_bundle_event_callback.cpp index f7874db96f..768c670283 100644 --- a/services/abilitymgr/src/ability_bundle_event_callback.cpp +++ b/services/abilitymgr/src/ability_bundle_event_callback.cpp @@ -58,7 +58,7 @@ void AbilityBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData TAG_LOGE(AAFwkTag::ABILITYMGR, "OnReceiveEvent failed, abilityAutoStartupService is nullptr"); return; } - abilityAutoStartupService_->DeleteAutoStartupData(bundleName); + abilityAutoStartupService_->DeleteAutoStartupData(bundleName, uid); } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED) { // install or uninstall module/bundle HandleUpdatedModuleInfo(bundleName, uid); diff --git a/test/unittest/ability_auto_startup_data_manager_test/BUILD.gn b/test/unittest/ability_auto_startup_data_manager_test/BUILD.gn index 8fc128ff37..dbc6f6d6d2 100644 --- a/test/unittest/ability_auto_startup_data_manager_test/BUILD.gn +++ b/test/unittest/ability_auto_startup_data_manager_test/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("ability_auto_startup_data_manager_test") { "${ability_runtime_abilitymgr_path}/:abilityms", "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", + "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_native_path}/ability:ability_context_native", "${ability_runtime_services_path}/abilitymgr:abilityms", diff --git a/test/unittest/ability_auto_startup_data_manager_test/ability_auto_startup_data_manager_test.cpp b/test/unittest/ability_auto_startup_data_manager_test/ability_auto_startup_data_manager_test.cpp index c9749e9299..fa85caaba7 100644 --- a/test/unittest/ability_auto_startup_data_manager_test/ability_auto_startup_data_manager_test.cpp +++ b/test/unittest/ability_auto_startup_data_manager_test/ability_auto_startup_data_manager_test.cpp @@ -334,7 +334,8 @@ HWTEST_F(AbilityAutoStartupDataManagerTest, DeleteAutoStartupData_bundleName_100 GTEST_LOG_(INFO) << "DeleteAutoStartupData_bundleName_100 start"; AbilityAutoStartupDataManager abilityAutoStartupDataManager; std::string bundleName = ""; - auto result = abilityAutoStartupDataManager.DeleteAutoStartupData(bundleName); + int32_t uid = 0; + auto result = abilityAutoStartupDataManager.DeleteAutoStartupData(bundleName, uid); EXPECT_EQ(result, ERR_INVALID_VALUE); GTEST_LOG_(INFO) << "DeleteAutoStartupData_bundleName_100 end"; } @@ -350,7 +351,8 @@ HWTEST_F(AbilityAutoStartupDataManagerTest, DeleteAutoStartupData_bundleName_200 GTEST_LOG_(INFO) << "DeleteAutoStartupData_bundleName_200 start"; AbilityAutoStartupDataManager abilityAutoStartupDataManager; std::string bundleName = "com.example.testbundle"; - auto result = abilityAutoStartupDataManager.DeleteAutoStartupData(bundleName); + int32_t uid = 0; + auto result = abilityAutoStartupDataManager.DeleteAutoStartupData(bundleName, uid); EXPECT_EQ(result, ERR_OK); GTEST_LOG_(INFO) << "DeleteAutoStartupData_bundleName_200 end"; } @@ -370,7 +372,8 @@ HWTEST_F(AbilityAutoStartupDataManagerTest, DeleteAutoStartupData_bundleName_300 EXPECT_EQ(true, abilityAutoStartupDataManager.CheckKvStore()); std::string bundleName = "com.example.testbundle"; - auto result = abilityAutoStartupDataManager.DeleteAutoStartupData(bundleName); + int32_t uid = 0; + auto result = abilityAutoStartupDataManager.DeleteAutoStartupData(bundleName, uid); EXPECT_EQ(result, ERR_OK); GTEST_LOG_(INFO) << "DeleteAutoStartupData_bundleName_300 end"; } @@ -498,7 +501,8 @@ HWTEST_F(AbilityAutoStartupDataManagerTest, GetCurrentAppAutoStartupData_100, Te AutoStartupInfo info; info.bundleName = "com.example.testbundle"; std::vector infoList; - auto result = abilityAutoStartupDataManager.GetCurrentAppAutoStartupData(info.bundleName, infoList); + std::string accessTokenId = "0"; + auto result = abilityAutoStartupDataManager.GetCurrentAppAutoStartupData(info.bundleName, infoList, accessTokenId); EXPECT_EQ(result, ERR_OK); GTEST_LOG_(INFO) << "GetCurrentAppAutoStartupData_100 end"; } @@ -520,7 +524,8 @@ HWTEST_F(AbilityAutoStartupDataManagerTest, GetCurrentAppAutoStartupData_200, Te AutoStartupInfo info; info.bundleName = "com.example.testbundle"; std::vector infoList; - auto result = abilityAutoStartupDataManager.GetCurrentAppAutoStartupData(info.bundleName, infoList); + std::string accessTokenId = "0"; + auto result = abilityAutoStartupDataManager.GetCurrentAppAutoStartupData(info.bundleName, infoList, accessTokenId); EXPECT_EQ(result, ERR_OK); GTEST_LOG_(INFO) << "GetCurrentAppAutoStartupData_200 end"; } diff --git a/test/unittest/ability_auto_startup_service_test/BUILD.gn b/test/unittest/ability_auto_startup_service_test/BUILD.gn index 2eafb6c7dd..ce7786334c 100644 --- a/test/unittest/ability_auto_startup_service_test/BUILD.gn +++ b/test/unittest/ability_auto_startup_service_test/BUILD.gn @@ -42,6 +42,7 @@ ohos_unittest("ability_auto_startup_service_test") { "${ability_runtime_abilitymgr_path}/:abilityms", "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", + "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_native_path}/ability:ability_context_native", "${ability_runtime_native_path}/ability/native:auto_startup_callback", diff --git a/test/unittest/ability_auto_startup_service_test/ability_auto_startup_service_test.cpp b/test/unittest/ability_auto_startup_service_test/ability_auto_startup_service_test.cpp index ef1c6aa210..4703cf8ec6 100644 --- a/test/unittest/ability_auto_startup_service_test/ability_auto_startup_service_test.cpp +++ b/test/unittest/ability_auto_startup_service_test/ability_auto_startup_service_test.cpp @@ -252,7 +252,8 @@ HWTEST_F(AbilityAutoStartupServiceTest, DeleteAutoStartupData_001, TestSize.Leve GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest DeleteAutoStartupData_001 start"; auto abilityAutoStartupService = std::make_shared(); std::string bundleName = AUTO_STARTUP_SERVICE_BUNDLENAME; - auto result = abilityAutoStartupService->DeleteAutoStartupData(bundleName); + int32_t uid = 0; + auto result = abilityAutoStartupService->DeleteAutoStartupData(bundleName, uid); EXPECT_EQ(result, ERR_OK); GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest DeleteAutoStartupData_001 end"; } @@ -418,7 +419,8 @@ HWTEST_F(AbilityAutoStartupServiceTest, GetAbilityData_001, TestSize.Level1) AutoStartupInfo info; std::string abilityTypeName; bool isVisible = AUTO_STARTUP_SERVICE_FALSE; - auto result = abilityAutoStartupService->GetAbilityData(info, isVisible, abilityTypeName); + std::string accessTokenId = "0"; + auto result = abilityAutoStartupService->GetAbilityData(info, isVisible, abilityTypeName, accessTokenId); EXPECT_FALSE(result); GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetAbilityData_001 end"; } @@ -515,7 +517,8 @@ HWTEST_F(AbilityAutoStartupServiceTest, GetAbilityInfo_001, TestSize.Level1) auto abilityAutoStartupService = std::make_shared(); AutoStartupInfo info; std::string abilityTypeName = AUTO_STARTUP_SERVICE_ABILITYNAME; - auto result = abilityAutoStartupService->GetAbilityInfo(info, abilityTypeName); + std::string accessTokenId = "0"; + auto result = abilityAutoStartupService->GetAbilityInfo(info, abilityTypeName, accessTokenId); EXPECT_EQ(result, INNER_ERR); GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetAbilityInfo_001 end"; } diff --git a/test/unittest/ability_bundle_event_callback_test/BUILD.gn b/test/unittest/ability_bundle_event_callback_test/BUILD.gn index f8fe65a813..0876e6c300 100644 --- a/test/unittest/ability_bundle_event_callback_test/BUILD.gn +++ b/test/unittest/ability_bundle_event_callback_test/BUILD.gn @@ -40,6 +40,7 @@ ohos_unittest("ability_bundle_event_callback_test") { deps = [ "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:auto_startup_callback", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:event_report", diff --git a/test/unittest/specified_mission_list_test/BUILD.gn b/test/unittest/specified_mission_list_test/BUILD.gn index 8e8b53a08c..0bf26322ad 100644 --- a/test/unittest/specified_mission_list_test/BUILD.gn +++ b/test/unittest/specified_mission_list_test/BUILD.gn @@ -60,6 +60,7 @@ ohos_unittest("specified_mission_list_test") { "ability_base:session_info", "ability_base:want", "ability_base:zuri", + "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", "config_policy:configpolicy_util", From 438bf7e60af4f0a2eb5b0ae94d755da2b3b76687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E5=97=A3=E9=92=8A?= Date: Fri, 31 May 2024 13:48:58 +0800 Subject: [PATCH 24/69] =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=B8=B8?= =?UTF-8?q?=E9=87=8F=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 段嗣钊 Change-Id: I4547fed57ef084a7e3afa2ac9a99515c93caf749 --- services/appmgr/include/app_mgr_service.h | 12 +- services/appmgr/src/ams_mgr_scheduler.cpp | 26 +-- services/appmgr/src/app_mgr_service.cpp | 166 ++++++++++-------- services/appmgr/src/app_mgr_service_inner.cpp | 111 ++++++------ services/appmgr/src/app_spawn_client.cpp | 30 ++-- services/appmgr/src/app_spawn_msg_wrapper.cpp | 26 +-- 6 files changed, 194 insertions(+), 177 deletions(-) diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 25b488f73f..26e1815a4e 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -672,8 +672,6 @@ private: }; private: - void DumpIpcAllFuncInit(); - void DumpIpcFuncInit(); int DumpIpcAllInner(const AppMgrService::DumpIpcKey key, std::string& result); int DumpIpcWithPidInner(const AppMgrService::DumpIpcKey key, const std::string& optionPid, std::string& result); @@ -688,16 +686,16 @@ private: sptr systemAbilityMgr_; sptr amsMgrScheduler_; - using DumpFuncType = int (AppMgrService::*)(const std::vector& args, std::string& result); - const static std::map dumpFuncMap_; + bool GetDumpIpcKeyByOption(const std::string &option, DumpIpcKey &key); - const static std::map dumpIpcMap; + using DumpFuncType = int (AppMgrService::*)(const std::vector& args, std::string& result); + bool GetDumpFunc(const std::string &optionKey, DumpFuncType &func); using DumpIpcAllFuncType = int (AppMgrService::*)(std::string& result); - std::map dumpIpcAllFuncMap_; + DumpIpcAllFuncType GetDumpIpcAllFuncByKey(uint32_t key); using DumpIpcFuncType = int (AppMgrService::*)(const int32_t pid, std::string& result); - std::map dumpIpcFuncMap_; + DumpIpcFuncType GetDumpIpcFuncByKey(uint32_t key); DISALLOW_COPY_AND_MOVE(AppMgrService); }; diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index bb8f322331..c2225881dc 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -31,19 +31,19 @@ namespace OHOS { namespace AppExecFwk { namespace { -const std::string TASK_TERMINATE_ABILITY = "TerminateAbilityTask"; -const std::string TASK_UPDATE_ABILITY_STATE = "UpdateAbilityStateTask"; -const std::string TASK_UPDATE_EXTENSION_STATE = "UpdateExtensionStateTask"; -const std::string TASK_REGISTER_APP_STATE_CALLBACK = "RegisterAppStateCallbackTask"; -const std::string TASK_STOP_ALL_PROCESS = "StopAllProcessTask"; -const std::string TASK_ABILITY_BEHAVIOR_ANALYSIS = "AbilityBehaviorAnalysisTask"; -const std::string TASK_KILL_PROCESS_BY_ABILITY_TOKEN = "KillProcessByAbilityTokenTask"; -const std::string TASK_KILL_PROCESSES_BY_USERID = "KillProcessesByUserIdTask"; -const std::string TASK_KILL_PROCESSES_BY_PIDS = "KillProcessesByPids"; -const std::string TASK_ATTACH_PID_TO_PARENT = "AttachPidToParent"; -const std::string TASK_KILL_APPLICATION = "KillApplicationTask"; -const std::string TASK_CLEAR_PROCESS_BY_ABILITY_TOKEN = "ClearProcessByAbilityTokenTask"; -const std::string FOUNDATION_NAME = "foundation"; +constexpr const char* TASK_TERMINATE_ABILITY = "TerminateAbilityTask"; +constexpr const char* TASK_UPDATE_ABILITY_STATE = "UpdateAbilityStateTask"; +constexpr const char* TASK_UPDATE_EXTENSION_STATE = "UpdateExtensionStateTask"; +constexpr const char* TASK_REGISTER_APP_STATE_CALLBACK = "RegisterAppStateCallbackTask"; +constexpr const char* TASK_STOP_ALL_PROCESS = "StopAllProcessTask"; +constexpr const char* TASK_ABILITY_BEHAVIOR_ANALYSIS = "AbilityBehaviorAnalysisTask"; +constexpr const char* TASK_KILL_PROCESS_BY_ABILITY_TOKEN = "KillProcessByAbilityTokenTask"; +constexpr const char* TASK_KILL_PROCESSES_BY_USERID = "KillProcessesByUserIdTask"; +constexpr const char* TASK_KILL_PROCESSES_BY_PIDS = "KillProcessesByPids"; +constexpr const char* TASK_ATTACH_PID_TO_PARENT = "AttachPidToParent"; +constexpr const char* TASK_KILL_APPLICATION = "KillApplicationTask"; +constexpr const char* TASK_CLEAR_PROCESS_BY_ABILITY_TOKEN = "ClearProcessByAbilityTokenTask"; +constexpr const char* FOUNDATION_NAME = "foundation"; }; // namespace AmsMgrScheduler::AmsMgrScheduler( diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index e4e2f58c4c..a4bc55eae9 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -40,9 +40,9 @@ namespace OHOS { namespace AppExecFwk { -const std::string OPTION_KEY_HELP = "-h"; -const std::string OPTION_KEY_DUMP_IPC = "--ipc"; -const std::string OPTION_KEY_DUMP_FFRT = "--ffrt"; +constexpr const char* OPTION_KEY_HELP = "-h"; +constexpr const char* OPTION_KEY_DUMP_IPC = "--ipc"; +constexpr const char* OPTION_KEY_DUMP_FFRT = "--ffrt"; const int32_t HIDUMPER_SERVICE_UID = 1212; constexpr const int INDEX_PID = 1; constexpr const int INDEX_CMD = 2; @@ -56,60 +56,32 @@ using namespace std::chrono_literals; #ifdef ABILITY_COMMAND_FOR_TEST static const int APP_MS_BLOCK = 65; #endif -const std::string TASK_INIT_APPMGRSERVICEINNER = "InitAppMgrServiceInnerTask"; -const std::string TASK_ATTACH_APPLICATION = "AttachApplicationTask"; -const std::string TASK_APPLICATION_FOREGROUNDED = "ApplicationForegroundedTask"; -const std::string TASK_APPLICATION_BACKGROUNDED = "ApplicationBackgroundedTask"; -const std::string TASK_APPLICATION_TERMINATED = "ApplicationTerminatedTask"; -const std::string TASK_ABILITY_CLEANED = "AbilityCleanedTask"; -const std::string TASK_ADD_APP_DEATH_RECIPIENT = "AddAppRecipientTask"; -const std::string TASK_CLEAR_UP_APPLICATION_DATA = "ClearUpApplicationDataTask"; -const std::string TASK_STARTUP_RESIDENT_PROCESS = "StartupResidentProcess"; -const std::string TASK_ADD_ABILITY_STAGE_DONE = "AddAbilityStageDone"; -const std::string TASK_START_USER_TEST_PROCESS = "StartUserTestProcess"; -const std::string TASK_FINISH_USER_TEST = "FinishUserTest"; -const std::string TASK_ATTACH_RENDER_PROCESS = "AttachRenderTask"; -const std::string TASK_ATTACH_CHILD_PROCESS = "AttachChildProcessTask"; -const std::string TASK_EXIT_CHILD_PROCESS_SAFELY = "ExitChildProcessSafelyTask"; -const std::string FOUNDATION_PROCESS = "foundation"; +constexpr const char* TASK_INIT_APPMGRSERVICEINNER = "InitAppMgrServiceInnerTask"; +constexpr const char* TASK_ATTACH_APPLICATION = "AttachApplicationTask"; +constexpr const char* TASK_APPLICATION_FOREGROUNDED = "ApplicationForegroundedTask"; +constexpr const char* TASK_APPLICATION_BACKGROUNDED = "ApplicationBackgroundedTask"; +constexpr const char* TASK_APPLICATION_TERMINATED = "ApplicationTerminatedTask"; +constexpr const char* TASK_ABILITY_CLEANED = "AbilityCleanedTask"; +constexpr const char* TASK_ADD_APP_DEATH_RECIPIENT = "AddAppRecipientTask"; +constexpr const char* TASK_CLEAR_UP_APPLICATION_DATA = "ClearUpApplicationDataTask"; +constexpr const char* TASK_STARTUP_RESIDENT_PROCESS = "StartupResidentProcess"; +constexpr const char* TASK_ADD_ABILITY_STAGE_DONE = "AddAbilityStageDone"; +constexpr const char* TASK_START_USER_TEST_PROCESS = "StartUserTestProcess"; +constexpr const char* TASK_FINISH_USER_TEST = "FinishUserTest"; +constexpr const char* TASK_ATTACH_RENDER_PROCESS = "AttachRenderTask"; +constexpr const char* TASK_ATTACH_CHILD_PROCESS = "AttachChildProcessTask"; +constexpr const char* TASK_EXIT_CHILD_PROCESS_SAFELY = "ExitChildProcessSafelyTask"; +constexpr const char* FOUNDATION_PROCESS = "foundation"; constexpr int32_t USER_UID = 2000; } // namespace REGISTER_SYSTEM_ABILITY_BY_ID(AppMgrService, APP_MGR_SERVICE_ID, true); -const std::map AppMgrService::dumpFuncMap_ = { - std::map::value_type(OPTION_KEY_HELP, &AppMgrService::ShowHelp), - std::map::value_type(OPTION_KEY_DUMP_IPC, &AppMgrService::DumpIpc), - std::map::value_type(OPTION_KEY_DUMP_FFRT, &AppMgrService::DumpFfrt), -}; - -const std::map AppMgrService::dumpIpcMap = { - std::map::value_type("--start-stat", KEY_DUMP_IPC_START), - std::map::value_type("--stop-stat", KEY_DUMP_IPC_STOP), - std::map::value_type("--stat", KEY_DUMP_IPC_STAT), -}; - -void AppMgrService::DumpIpcAllFuncInit() -{ - dumpIpcAllFuncMap_[KEY_DUMP_IPC_START] = &AppMgrService::DumpIpcAllStart; - dumpIpcAllFuncMap_[KEY_DUMP_IPC_STOP] = &AppMgrService::DumpIpcAllStop; - dumpIpcAllFuncMap_[KEY_DUMP_IPC_STAT] = &AppMgrService::DumpIpcAllStat; -} - -void AppMgrService::DumpIpcFuncInit() -{ - dumpIpcFuncMap_[KEY_DUMP_IPC_START] = &AppMgrService::DumpIpcStart; - dumpIpcFuncMap_[KEY_DUMP_IPC_STOP] = &AppMgrService::DumpIpcStop; - dumpIpcFuncMap_[KEY_DUMP_IPC_STAT] = &AppMgrService::DumpIpcStat; -} - AppMgrService::AppMgrService() { appMgrServiceInner_ = std::make_shared(); TAG_LOGI(AAFwkTag::APPMGR, "instance created with no para"); PerfProfile::GetInstance().SetAmsLoadStartTime(GetTickCount()); - DumpIpcAllFuncInit(); - DumpIpcFuncInit(); } AppMgrService::AppMgrService(const int32_t serviceId, bool runOnCreate) : SystemAbility(serviceId, runOnCreate) @@ -117,8 +89,6 @@ AppMgrService::AppMgrService(const int32_t serviceId, bool runOnCreate) : System appMgrServiceInner_ = std::make_shared(); TAG_LOGI(AAFwkTag::APPMGR, "instance created"); PerfProfile::GetInstance().SetAmsLoadStartTime(GetTickCount()); - DumpIpcAllFuncInit(); - DumpIpcFuncInit(); } AppMgrService::~AppMgrService() @@ -644,6 +614,23 @@ int AppMgrService::Dump(int fd, const std::vector& args) return errCode; } +bool AppMgrService::GetDumpFunc(const std::string &optionKey, DumpFuncType &func) +{ + if (optionKey == OPTION_KEY_HELP) { + func = &AppMgrService::ShowHelp; + return true; + } + if (optionKey == OPTION_KEY_DUMP_IPC) { + func = &AppMgrService::DumpIpc; + return true; + } + if (optionKey == OPTION_KEY_DUMP_FFRT) { + func = &AppMgrService::DumpFfrt; + return true; + } + return false; +} + int AppMgrService::Dump(const std::vector& args, std::string& result) { TAG_LOGD(AAFwkTag::APPMGR, "Called."); @@ -653,14 +640,12 @@ int AppMgrService::Dump(const std::vector& args, std::string& re } std::string optionKey = Str16ToStr8(args[0]); - auto itDumpFunc = dumpFuncMap_.find(optionKey); - if (itDumpFunc == dumpFuncMap_.end()) { - TAG_LOGE(AAFwkTag::APPMGR, "option key %{public}s does not exist", optionKey.c_str()); + DumpFuncType dumpFunc; + if (!GetDumpFunc(optionKey, dumpFunc)) { result.append("error: unkown option.\n"); + TAG_LOGE(AAFwkTag::APPMGR, "option key %{public}s does not exist", optionKey.c_str()); return DumpErrorCode::ERR_UNKNOWN_OPTION_ERROR; } - - auto dumpFunc = itDumpFunc->second; if (dumpFunc == nullptr) { result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); @@ -679,17 +664,25 @@ int AppMgrService::ShowHelp(const std::vector& args, std::string return ERR_OK; } +AppMgrService::DumpIpcAllFuncType AppMgrService::GetDumpIpcAllFuncByKey(uint32_t key) +{ + if (key == KEY_DUMP_IPC_START) { + return &AppMgrService::DumpIpcAllStart; + } + if (key == KEY_DUMP_IPC_STOP) { + return &AppMgrService::DumpIpcAllStop; + } + if (key == KEY_DUMP_IPC_STAT) { + return &AppMgrService::DumpIpcAllStat; + } + TAG_LOGE(AAFwkTag::APPMGR, "option key %{public}d does not exist", key); + return nullptr; +} + int AppMgrService::DumpIpcAllInner(const AppMgrService::DumpIpcKey key, std::string& result) { TAG_LOGI(AAFwkTag::APPMGR, "Called."); - auto itFunc = dumpIpcAllFuncMap_.find(key); - if (itFunc == dumpIpcAllFuncMap_.end()) { - result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) - .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); - TAG_LOGE(AAFwkTag::APPMGR, "option key %{public}d does not exist", key); - return DumpErrorCode::ERR_INTERNAL_ERROR; - } - auto dumpFunc = itFunc->second; + auto dumpFunc = GetDumpIpcAllFuncByKey(key); if (dumpFunc == nullptr) { result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); @@ -699,6 +692,21 @@ int AppMgrService::DumpIpcAllInner(const AppMgrService::DumpIpcKey key, std::str return (this->*dumpFunc)(result); } +AppMgrService::DumpIpcFuncType AppMgrService::GetDumpIpcFuncByKey(uint32_t key) +{ + if (key == KEY_DUMP_IPC_START) { + return &AppMgrService::DumpIpcStart; + } + if (key == KEY_DUMP_IPC_STOP) { + return &AppMgrService::DumpIpcStop; + } + if (key == KEY_DUMP_IPC_STAT) { + return &AppMgrService::DumpIpcStat; + } + TAG_LOGE(AAFwkTag::APPMGR, "option key %{public}d does not exist", key); + return nullptr; +} + int AppMgrService::DumpIpcWithPidInner(const AppMgrService::DumpIpcKey key, const std::string& optionPid, std::string& result) { @@ -718,14 +726,8 @@ int AppMgrService::DumpIpcWithPidInner(const AppMgrService::DumpIpcKey key, TAG_LOGE(AAFwkTag::APPMGR, "invalid pid: %{public}s", optionPid.c_str()); return DumpErrorCode::ERR_INVALID_PID_ERROR; } - auto itFunc = dumpIpcFuncMap_.find(key); - if (itFunc == dumpIpcFuncMap_.end()) { - result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) - .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); - TAG_LOGE(AAFwkTag::APPMGR, "option key %{public}d does not exist", key); - return DumpErrorCode::ERR_INTERNAL_ERROR; - } - auto dumpFunc = itFunc->second; + + auto dumpFunc = GetDumpIpcFuncByKey(key); if (dumpFunc == nullptr) { result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); @@ -771,6 +773,23 @@ int AppMgrService::DumpFfrtInner(const std::string& pidsRaw, std::string& result return appMgrServiceInner_->DumpFfrt(pids, result); } +bool AppMgrService::GetDumpIpcKeyByOption(const std::string &option, DumpIpcKey &key) +{ + if (option == "--start-stat") { + key = KEY_DUMP_IPC_START; + return true; + } + if (option == "--stop-stat") { + key = KEY_DUMP_IPC_STOP; + return true; + } + if (option == "--stat") { + key = KEY_DUMP_IPC_STAT; + return true; + } + return false; +} + int AppMgrService::DumpIpc(const std::vector& args, std::string& result) { TAG_LOGD(AAFwkTag::APPMGR, "Called. AppMgrService::DumpIpc start"); @@ -792,15 +811,14 @@ int AppMgrService::DumpIpc(const std::vector& args, std::string& std::string optionPid = Str16ToStr8(args[INDEX_PID]); TAG_LOGD(AAFwkTag::APPMGR, "option pid:%{public}s, option cmd:%{public}s", optionPid.c_str(), optionCmd.c_str()); - - auto itDumpKey = dumpIpcMap.find(optionCmd); - if (itDumpKey == dumpIpcMap.end()) { + + DumpIpcKey key; + if (!GetDumpIpcKeyByOption(optionCmd, key)) { result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) .append(MSG_DUMP_FAIL_REASON_INVALILD_CMD, strlen(MSG_DUMP_FAIL_REASON_INVALILD_CMD)); TAG_LOGE(AAFwkTag::APPMGR, "option command %{public}s does not exist", optionCmd.c_str()); return DumpErrorCode::ERR_INVALID_CMD_ERROR; } - DumpIpcKey key = itDumpKey->second; if (optionPid == "-a" || optionPid == "all" || optionPid == "--all") { return DumpIpcAllInner(key, result); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index b1ec88cbd8..0d6bdd7ea5 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -124,37 +124,37 @@ constexpr int REGISTER_VISIBILITY_DELAY = 5000; // Max render process number limitation for phone device. constexpr int PHONE_MAX_RENDER_PROCESS_NUM = 40; constexpr int PROCESS_RESTART_MARGIN_MICRO_SECONDS = 2000; -const std::string CLASS_NAME = "ohos.app.MainThread"; -const std::string FUNC_NAME = "main"; -const std::string RENDER_PARAM = "invalidparam"; -const std::string COLD_START = "coldStart"; -const std::string PERF_CMD = "perfCmd"; -const std::string MULTI_THREAD = "multiThread"; -const std::string DEBUG_CMD = "debugCmd"; -const std::string ENTER_SANDBOX = "sandboxApp"; -const std::string PERMISSION_INTERNET = "ohos.permission.INTERNET"; -const std::string PERMISSION_MANAGE_VPN = "ohos.permission.MANAGE_VPN"; -const std::string PERMISSION_ACCESS_BUNDLE_DIR = "ohos.permission.ACCESS_BUNDLE_DIR"; -const std::string DLP_PARAMS_SECURITY_FLAG = "ohos.dlp.params.securityFlag"; -const std::string SUPPORT_ISOLATION_MODE = "persist.bms.supportIsolationMode"; -const std::string SUPPORT_SERVICE_EXT_MULTI_PROCESS = "component.startup.extension.multiprocess.enable"; -const std::string SERVICE_EXT_MULTI_PROCESS_WHITE_LIST = "component.startup.extension.multiprocess.whitelist"; -const std::string SCENE_BOARD_BUNDLE_NAME = "com.ohos.sceneboard"; -const std::string DEBUG_APP = "debugApp"; -const std::string SERVICE_EXTENSION = ":ServiceExtension"; -const std::string KEEP_ALIVE = ":KeepAlive"; -const std::string PARAM_SPECIFIED_PROCESS_FLAG = "ohoSpecifiedProcessFlag"; -const std::string TSAN_FLAG_NAME = "tsanEnabled"; -const std::string MEMMGR_PROC_NAME = "memmgrservice"; -const std::string UIEXTENSION_ABILITY_ID = "ability.want.params.uiExtensionAbilityId"; -const std::string UIEXTENSION_ROOT_HOST_PID = "ability.want.params.uiExtensionRootHostPid"; -const std::string STRICT_MODE = "strictMode"; -const std::string RENDER_PROCESS_NAME = ":render"; -const std::string RENDER_PROCESS_TYPE = "render"; -const std::string GPU_PROCESS_NAME = ":gpu"; -const std::string GPU_PROCESS_TYPE = "gpu"; -const std::string FONT_WGHT_SCALE = "persist.sys.font_wght_scale_for_user0"; -const std::string FONT_SCALE = "persist.sys.font_scale_for_user0"; +constexpr const char* CLASS_NAME = "ohos.app.MainThread"; +constexpr const char* FUNC_NAME = "main"; +constexpr const char* RENDER_PARAM = "invalidparam"; +constexpr const char* COLD_START = "coldStart"; +constexpr const char* PERF_CMD = "perfCmd"; +constexpr const char* MULTI_THREAD = "multiThread"; +constexpr const char* DEBUG_CMD = "debugCmd"; +constexpr const char* ENTER_SANDBOX = "sandboxApp"; +constexpr const char* PERMISSION_INTERNET = "ohos.permission.INTERNET"; +constexpr const char* PERMISSION_MANAGE_VPN = "ohos.permission.MANAGE_VPN"; +constexpr const char* PERMISSION_ACCESS_BUNDLE_DIR = "ohos.permission.ACCESS_BUNDLE_DIR"; +constexpr const char* DLP_PARAMS_SECURITY_FLAG = "ohos.dlp.params.securityFlag"; +constexpr const char* SUPPORT_ISOLATION_MODE = "persist.bms.supportIsolationMode"; +constexpr const char* SUPPORT_SERVICE_EXT_MULTI_PROCESS = "component.startup.extension.multiprocess.enable"; +constexpr const char* SERVICE_EXT_MULTI_PROCESS_WHITE_LIST = "component.startup.extension.multiprocess.whitelist"; +constexpr const char* SCENE_BOARD_BUNDLE_NAME = "com.ohos.sceneboard"; +constexpr const char* DEBUG_APP = "debugApp"; +constexpr const char* SERVICE_EXTENSION = ":ServiceExtension"; +constexpr const char* KEEP_ALIVE = ":KeepAlive"; +constexpr const char* PARAM_SPECIFIED_PROCESS_FLAG = "ohoSpecifiedProcessFlag"; +constexpr const char* TSAN_FLAG_NAME = "tsanEnabled"; +constexpr const char* MEMMGR_PROC_NAME = "memmgrservice"; +constexpr const char* UIEXTENSION_ABILITY_ID = "ability.want.params.uiExtensionAbilityId"; +constexpr const char* UIEXTENSION_ROOT_HOST_PID = "ability.want.params.uiExtensionRootHostPid"; +constexpr const char* STRICT_MODE = "strictMode"; +constexpr const char* RENDER_PROCESS_NAME = ":render"; +constexpr const char* RENDER_PROCESS_TYPE = "render"; +constexpr const char* GPU_PROCESS_NAME = ":gpu"; +constexpr const char* GPU_PROCESS_TYPE = "gpu"; +constexpr const char* FONT_WGHT_SCALE = "persist.sys.font_wght_scale_for_user0"; +constexpr const char* FONT_SCALE = "persist.sys.font_scale_for_user0"; const int32_t SIGNAL_KILL = 9; constexpr int32_t USER_SCALE = 200000; #define ENUM_TO_STRING(s) #s @@ -172,33 +172,34 @@ constexpr ErrCode APPMGR_ERR_OFFSET = ErrCodeOffset(SUBSYS_APPEXECFWK, 0x01); constexpr ErrCode ERR_ALREADY_EXIST_RENDER = APPMGR_ERR_OFFSET + 100; // Error code for reaching render process number limitation. constexpr ErrCode ERR_REACHING_MAXIMUM_RENDER_PROCESS_LIMITATION = APPMGR_ERR_OFFSET + 101; -constexpr char EVENT_KEY_UID[] = "UID"; -constexpr char EVENT_KEY_PID[] = "PID"; -constexpr char EVENT_KEY_PACKAGE_NAME[] = "PACKAGE_NAME"; -constexpr char EVENT_KEY_PROCESS_NAME[] = "PROCESS_NAME"; -constexpr char EVENT_KEY_MESSAGE[] = "MSG"; +constexpr const char* EVENT_KEY_UID = "UID"; +constexpr const char* EVENT_KEY_PID = "PID"; +constexpr const char* EVENT_KEY_PACKAGE_NAME = "PACKAGE_NAME"; +constexpr const char* EVENT_KEY_PROCESS_NAME = "PROCESS_NAME"; +constexpr const char* EVENT_KEY_MESSAGE = "MSG"; // Developer mode param -constexpr char DEVELOPER_MODE_STATE[] = "const.security.developermode.state"; -constexpr char PRODUCT_ASSERT_FAULT_DIALOG_ENABLED[] = "persisit.sys.abilityms.support_assert_fault_dialog"; +constexpr const char* DEVELOPER_MODE_STATE = "const.security.developermode.state"; +constexpr const char* PRODUCT_ASSERT_FAULT_DIALOG_ENABLED = "persisit.sys.abilityms.support_assert_fault_dialog"; // Msg length is less than 48 characters -const std::string EVENT_MESSAGE_TERMINATE_ABILITY_TIMEOUT = "Terminate Ability TimeOut!"; -const std::string EVENT_MESSAGE_TERMINATE_APPLICATION_TIMEOUT = "Terminate Application TimeOut!"; -const std::string EVENT_MESSAGE_ADD_ABILITY_STAGE_INFO_TIMEOUT = "Add Ability Stage TimeOut!"; -const std::string EVENT_MESSAGE_START_SPECIFIED_PROCESS_TIMEOUT = "Start Specified Process Timeout!"; -const std::string EVENT_MESSAGE_START_SPECIFIED_ABILITY_TIMEOUT = "Start Specified Ability TimeOut!"; -const std::string EVENT_MESSAGE_START_PROCESS_SPECIFIED_ABILITY_TIMEOUT = "Start Process Specified Ability TimeOut!"; -const std::string EVENT_MESSAGE_DEFAULT = "AppMgrServiceInner HandleTimeOut!"; -const std::string SUPPORT_CALL_NOTIFY_MEMORY_CHANGED = +constexpr const char* EVENT_MESSAGE_TERMINATE_ABILITY_TIMEOUT = "Terminate Ability TimeOut!"; +constexpr const char* EVENT_MESSAGE_TERMINATE_APPLICATION_TIMEOUT = "Terminate Application TimeOut!"; +constexpr const char* EVENT_MESSAGE_ADD_ABILITY_STAGE_INFO_TIMEOUT = "Add Ability Stage TimeOut!"; +constexpr const char* EVENT_MESSAGE_START_SPECIFIED_PROCESS_TIMEOUT = "Start Specified Process Timeout!"; +constexpr const char* EVENT_MESSAGE_START_SPECIFIED_ABILITY_TIMEOUT = "Start Specified Ability TimeOut!"; +constexpr const char* EVENT_MESSAGE_START_PROCESS_SPECIFIED_ABILITY_TIMEOUT = + "Start Process Specified Ability TimeOut!"; +constexpr const char* EVENT_MESSAGE_DEFAULT = "AppMgrServiceInner HandleTimeOut!"; +constexpr const char* SUPPORT_CALL_NOTIFY_MEMORY_CHANGED = "persist.sys.abilityms.support_call_notify_memory_changed"; -const std::string SYSTEM_BASIC = "system_basic"; -const std::string SYSTEM_CORE = "system_core"; -const std::string ABILITY_OWNER_USERID = "AbilityMS_Owner_UserId"; -const std::string PROCESS_EXIT_EVENT_TASK = "Send Process Exit Event Task"; -const std::string KILL_PROCESS_REASON_PREFIX = "Kill Reason:"; -const std::string PRELOAD_APPLIATION_TASK = "PreloadApplicactionTask"; +constexpr const char* SYSTEM_BASIC = "system_basic"; +constexpr const char* SYSTEM_CORE = "system_core"; +constexpr const char* ABILITY_OWNER_USERID = "AbilityMS_Owner_UserId"; +constexpr const char* PROCESS_EXIT_EVENT_TASK = "Send Process Exit Event Task"; +constexpr const char* KILL_PROCESS_REASON_PREFIX = "Kill Reason:"; +constexpr const char* PRELOAD_APPLIATION_TASK = "PreloadApplicactionTask"; constexpr int32_t ROOT_UID = 0; constexpr int32_t FOUNDATION_UID = 5523; @@ -1614,7 +1615,7 @@ int32_t AppMgrServiceInner::NotifyMemoryLevel(int32_t level) bool isMemmgrCall = AAFwk::PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission( MEMMGR_PROC_NAME); if (!isMemmgrCall) { - TAG_LOGE(AAFwkTag::APPMGR, "callerToken not %{public}s. %{public}s", MEMMGR_PROC_NAME.c_str(), __func__); + TAG_LOGE(AAFwkTag::APPMGR, "callerToken not %{public}s. %{public}s", MEMMGR_PROC_NAME, __func__); return ERR_INVALID_VALUE; } if (!(level == OHOS::AppExecFwk::MemoryLevel::MEMORY_LEVEL_MODERATE || @@ -1638,7 +1639,7 @@ int32_t AppMgrServiceInner::NotifyProcMemoryLevel(const std::mapCheckSpecificSystemAbilityAccessPermission( MEMMGR_PROC_NAME); if (!isMemmgrCall) { - TAG_LOGE(AAFwkTag::APPMGR, "callerToken not %{public}s. %{public}s", MEMMGR_PROC_NAME.c_str(), __func__); + TAG_LOGE(AAFwkTag::APPMGR, "callerToken not %{public}s. %{public}s", MEMMGR_PROC_NAME, __func__); return ERR_INVALID_VALUE; } if (!appRunningManager_) { @@ -6671,7 +6672,7 @@ int32_t AppMgrServiceInner::NotifyMemorySizeStateChanged(bool isMemorySizeSuffic MEMMGR_PROC_NAME); bool isSupportCall = OHOS::system::GetBoolParameter(SUPPORT_CALL_NOTIFY_MEMORY_CHANGED, false); if (!isMemmgrCall && !isSupportCall) { - TAG_LOGE(AAFwkTag::APPMGR, "callerToken not %{public}s. %{public}s", MEMMGR_PROC_NAME.c_str(), __func__); + TAG_LOGE(AAFwkTag::APPMGR, "callerToken not %{public}s. %{public}s", MEMMGR_PROC_NAME, __func__); return ERR_PERMISSION_DENIED; } diff --git a/services/appmgr/src/app_spawn_client.cpp b/services/appmgr/src/app_spawn_client.cpp index 1407d24dab..2f092fcd98 100644 --- a/services/appmgr/src/app_spawn_client.cpp +++ b/services/appmgr/src/app_spawn_client.cpp @@ -25,19 +25,19 @@ namespace OHOS { namespace AppExecFwk { namespace { - const std::string HSPLIST_BUNDLES = "bundles"; - const std::string HSPLIST_MODULES = "modules"; - const std::string HSPLIST_VERSIONS = "versions"; - const std::string DATAGROUPINFOLIST_DATAGROUPID = "dataGroupId"; - const std::string DATAGROUPINFOLIST_GID = "gid"; - const std::string DATAGROUPINFOLIST_DIR = "dir"; - const std::string JSON_DATA_APP = "/data/app/el2/"; - const std::string JSON_GROUP = "/group/"; - const std::string VERSION_PREFIX = "v"; - const std::string APPSPAWN_CLIENT_USER_NAME = "APP_MANAGER_SERVICE"; - constexpr int32_t RIGHT_SHIFT_STEP = 1; - constexpr int32_t START_FLAG_TEST_NUM = 1; - const std::string MAX_CHILD_PROCESS = "MaxChildProcess"; +constexpr const char* HSPLIST_BUNDLES = "bundles"; +constexpr const char* HSPLIST_MODULES = "modules"; +constexpr const char* HSPLIST_VERSIONS = "versions"; +constexpr const char* DATAGROUPINFOLIST_DATAGROUPID = "dataGroupId"; +constexpr const char* DATAGROUPINFOLIST_GID = "gid"; +constexpr const char* DATAGROUPINFOLIST_DIR = "dir"; +constexpr const char* JSON_DATA_APP = "/data/app/el2/"; +constexpr const char* JSON_GROUP = "/group/"; +constexpr const char* VERSION_PREFIX = "v"; +constexpr const char* APPSPAWN_CLIENT_USER_NAME = "APP_MANAGER_SERVICE"; +constexpr int32_t RIGHT_SHIFT_STEP = 1; +constexpr int32_t START_FLAG_TEST_NUM = 1; +constexpr const char* MAX_CHILD_PROCESS = "MaxChildProcess"; } AppSpawnClient::AppSpawnClient(bool isNWebSpawn) { @@ -169,7 +169,7 @@ int32_t AppSpawnClient::SetDacInfo(const AppSpawnStartMsg &startMsg, AppSpawnReq for (uint32_t i = startMsg.gids.size(); i < appDacInfo.gidCount; i++) { appDacInfo.gidTable[i] = startMsg.dataGroupInfoList[i - startMsg.gids.size()].gid; } - ret = strcpy_s(appDacInfo.userName, sizeof(appDacInfo.userName), APPSPAWN_CLIENT_USER_NAME.c_str()); + ret = strcpy_s(appDacInfo.userName, sizeof(appDacInfo.userName), APPSPAWN_CLIENT_USER_NAME); if (ret) { TAG_LOGE(AAFwkTag::APPMGR, "failed to set dac userName!"); return ret; @@ -331,7 +331,7 @@ int32_t AppSpawnClient::AppspawnSetExtMsgMore(const AppSpawnStartMsg &startMsg, } std::string maxChildProcessStr = std::to_string(startMsg.maxChildProcess); - if ((ret = AppSpawnReqMsgAddExtInfo(reqHandle, MAX_CHILD_PROCESS.c_str(), + if ((ret = AppSpawnReqMsgAddExtInfo(reqHandle, MAX_CHILD_PROCESS, reinterpret_cast(maxChildProcessStr.c_str()), maxChildProcessStr.size()))) { TAG_LOGE(AAFwkTag::APPMGR, "Send maxChildProcess failed, ret: %{public}d", ret); return ret; diff --git a/services/appmgr/src/app_spawn_msg_wrapper.cpp b/services/appmgr/src/app_spawn_msg_wrapper.cpp index fb7c74b7e6..aa4298cb0b 100644 --- a/services/appmgr/src/app_spawn_msg_wrapper.cpp +++ b/services/appmgr/src/app_spawn_msg_wrapper.cpp @@ -23,19 +23,19 @@ namespace OHOS { namespace AppExecFwk { namespace { - const std::string HSPLIST_BUNDLES = "bundles"; - const std::string HSPLIST_MODULES = "modules"; - const std::string HSPLIST_VERSIONS = "versions"; - const std::string HSPLIST_SOCKET_TYPE = "|HspList|"; - const std::string OVERLAY_SOCKET_TYPE = "|Overlay|"; - const std::string DATA_GROUP_SOCKET_TYPE = "|DataGroup|"; - const std::string APP_ENV_TYPE = "|AppEnv|"; - const std::string DATAGROUPINFOLIST_DATAGROUPID = "dataGroupId"; - const std::string DATAGROUPINFOLIST_GID = "gid"; - const std::string DATAGROUPINFOLIST_DIR = "dir"; - const std::string JSON_DATA_APP = "/data/app/el2/"; - const std::string JSON_GROUP = "/group/"; - const std::string VERSION_PREFIX = "v"; +constexpr const char* HSPLIST_BUNDLES = "bundles"; +constexpr const char* HSPLIST_MODULES = "modules"; +constexpr const char* HSPLIST_VERSIONS = "versions"; +constexpr const char* HSPLIST_SOCKET_TYPE = "|HspList|"; +constexpr const char* OVERLAY_SOCKET_TYPE = "|Overlay|"; +constexpr const char* DATA_GROUP_SOCKET_TYPE = "|DataGroup|"; +constexpr const char* APP_ENV_TYPE = "|AppEnv|"; +constexpr const char* DATAGROUPINFOLIST_DATAGROUPID = "dataGroupId"; +constexpr const char* DATAGROUPINFOLIST_GID = "gid"; +constexpr const char* DATAGROUPINFOLIST_DIR = "dir"; +constexpr const char* JSON_DATA_APP = "/data/app/el2/"; +constexpr const char* JSON_GROUP = "/group/"; +constexpr const char* VERSION_PREFIX = "v"; } AppSpawnMsgWrapper::~AppSpawnMsgWrapper() From d284defc650a43166528b7040e2b993366fdc06f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E5=97=A3=E9=92=8A?= Date: Fri, 31 May 2024 15:14:30 +0800 Subject: [PATCH 25/69] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E6=9D=80=E6=AD=BB=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 段嗣钊 Change-Id: Ifc1d2b767ed1b5ca48674122f0d04ae7fcd9e234 --- services/appmgr/include/app_mgr_service_event_handler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/appmgr/include/app_mgr_service_event_handler.h b/services/appmgr/include/app_mgr_service_event_handler.h index c738554c10..e2ee21ae3b 100644 --- a/services/appmgr/include/app_mgr_service_event_handler.h +++ b/services/appmgr/include/app_mgr_service_event_handler.h @@ -56,7 +56,7 @@ public: static constexpr uint32_t START_SPECIFIED_PROCESS_TIMEOUT = 2000; // ms static constexpr uint32_t KILL_PROCESS_TIMEOUT = 3000; // ms #endif - static constexpr uint32_t DELAY_KILL_PROCESS_TIMEOUT = 1000; // ms + static constexpr uint32_t DELAY_KILL_PROCESS_TIMEOUT = 3000; // ms private: std::weak_ptr appMgr_; }; From eff3fed82535122e14a096e6b4595f0a9e42c8e2 Mon Sep 17 00:00:00 2001 From: yuwenze Date: Fri, 31 May 2024 15:33:03 +0800 Subject: [PATCH 26/69] app clone Signed-off-by: yuwenze Change-Id: I2c6d93578e05486a9c1468888930235b9b313de4 --- .../js/napi/wantConstant/want_constant.cpp | 1 + services/appmgr/include/app_spawn_client.h | 2 ++ services/appmgr/include/utils/appspawn_util.h | 4 ++++ services/appmgr/src/app_spawn_client.cpp | 17 +++++++++++++++++ 4 files changed, 24 insertions(+) diff --git a/frameworks/js/napi/wantConstant/want_constant.cpp b/frameworks/js/napi/wantConstant/want_constant.cpp index 6527e89729..406a449b7b 100644 --- a/frameworks/js/napi/wantConstant/want_constant.cpp +++ b/frameworks/js/napi/wantConstant/want_constant.cpp @@ -113,6 +113,7 @@ napi_value WantConstantInit(napi_env env, napi_value exports) SetNamedProperty(env, params, "ohos.extra.param.key.supportContinuePageStack", "SUPPORT_CONTINUE_PAGE_STACK_KEY"); SetNamedProperty(env, params, "ohos.extra.param.key.supportContinueSourceExit", "SUPPORT_CONTINUE_SOURCE_EXIT_KEY"); SetNamedProperty(env, params, "ohos.extra.param.key.showMode", "SHOW_MODE_KEY"); + SetNamedProperty(env, params, "ohos.extra.param.key.appCloneIndex", "APP_CLONE_INDEX_KEY"); napi_property_descriptor exportFuncs[] = { DECLARE_NAPI_PROPERTY("Action", action), DECLARE_NAPI_PROPERTY("Entity", entity), diff --git a/services/appmgr/include/app_spawn_client.h b/services/appmgr/include/app_spawn_client.h index 74803ffb99..a5c8445740 100644 --- a/services/appmgr/include/app_spawn_client.h +++ b/services/appmgr/include/app_spawn_client.h @@ -241,6 +241,8 @@ public: virtual int32_t GetRenderProcessTerminationStatus(const AppSpawnStartMsg &startMsg, int &status); private: + int32_t SetCloneFlag(const AppSpawnStartMsg &startMsg, AppSpawnReqMsgHandle reqHandle) const; + std::string serviceName_ = APPSPAWN_SERVER_NAME; AppSpawnClientHandle handle_ = nullptr; SpawnConnectionState state_ = SpawnConnectionState::STATE_NOT_CONNECT; diff --git a/services/appmgr/include/utils/appspawn_util.h b/services/appmgr/include/utils/appspawn_util.h index 433ee6ad58..614b5f5b5b 100644 --- a/services/appmgr/include/utils/appspawn_util.h +++ b/services/appmgr/include/utils/appspawn_util.h @@ -17,6 +17,7 @@ #define OHOS_ABILITY_RUNTIME_APPSPAWN_UTIL_H #include "ability_info.h" +#include "application_info.h" #include "app_spawn_client.h" #include "want.h" @@ -57,6 +58,9 @@ static uint32_t BuildStartFlags(const AAFwk::Want &want, const ApplicationInfo & if (want.GetBoolParam("ohos.ability.params.extensionControl", false)) { startFlags = startFlags | (START_FLAG_BASE << StartFlags::EXTENSION_CONTROLLED); } + if (applicationInfo.multiAppMode.multiAppModeType == MultiAppModeType::APP_CLONE) { + startFlags = startFlags | (START_FLAG_BASE << APP_FLAGS_CLONE_ENABLE); + } return startFlags; } diff --git a/services/appmgr/src/app_spawn_client.cpp b/services/appmgr/src/app_spawn_client.cpp index 1407d24dab..97ef8d1561 100644 --- a/services/appmgr/src/app_spawn_client.cpp +++ b/services/appmgr/src/app_spawn_client.cpp @@ -246,6 +246,19 @@ int32_t AppSpawnClient::SetAppExtension(const AppSpawnStartMsg &startMsg, AppSpa return ret; } +int32_t AppSpawnClient::SetCloneFlag(const AppSpawnStartMsg &startMsg, AppSpawnReqMsgHandle reqHandle) const +{ + int32_t ret = 0; + if (startMsg.flags & APP_FLAGS_CLONE_ENABLE) { + ret = AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_CLONE_ENABLE); + if (ret != 0) { + TAG_LOGE(AAFwkTag::APPMGR, "SetCloneFlag failed, ret: %{public}d", ret); + return ret; + } + } + return ret; +} + int32_t AppSpawnClient::AppspawnSetExtMsg(const AppSpawnStartMsg &startMsg, AppSpawnReqMsgHandle reqHandle) { int32_t ret = 0; @@ -400,6 +413,10 @@ int32_t AppSpawnClient::AppspawnCreateDefaultMsg(const AppSpawnStartMsg &startMs TAG_LOGE(AAFwkTag::APPMGR, "SetAppExtension failed, ret: %{public}d", ret); break; } + if ((ret = SetCloneFlag(startMsg, reqHandle))) { + TAG_LOGE(AAFwkTag::APPMGR, "SetCloneFlag failed, ret: %{public}d", ret); + break; + } return ret; } while (0); From ce4f3951ccc34b742979a6986bd62e74c38a28ed Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Fri, 31 May 2024 14:35:38 +0800 Subject: [PATCH 27/69] fix bug add autostartup Application identity identification Signed-off-by: jiangzhijun8 --- .../include/auto_startup_info.h | 1 + .../ability_auto_startup_data_manager.h | 7 +- .../include/ability_auto_startup_service.h | 8 ++- .../src/ability_auto_startup_data_manager.cpp | 69 ++++++++++++------ .../src/ability_auto_startup_service.cpp | 71 ++++++++++++------- .../src/ability_bundle_event_callback.cpp | 2 +- .../BUILD.gn | 1 + ...ability_auto_startup_data_manager_test.cpp | 15 ++-- .../BUILD.gn | 1 + .../ability_auto_startup_service_test.cpp | 9 ++- .../BUILD.gn | 1 + .../specified_mission_list_test/BUILD.gn | 1 + 12 files changed, 124 insertions(+), 62 deletions(-) diff --git a/interfaces/inner_api/ability_manager/include/auto_startup_info.h b/interfaces/inner_api/ability_manager/include/auto_startup_info.h index fbe5d4c513..f734e2877f 100644 --- a/interfaces/inner_api/ability_manager/include/auto_startup_info.h +++ b/interfaces/inner_api/ability_manager/include/auto_startup_info.h @@ -32,6 +32,7 @@ public: std::string abilityName; std::string moduleName; std::string abilityTypeName; + std::string accessTokenId; int32_t appCloneIndex = -1; bool ReadFromParcel(Parcel &parcel); diff --git a/services/abilitymgr/include/ability_auto_startup_data_manager.h b/services/abilitymgr/include/ability_auto_startup_data_manager.h index e4787e2a65..954a9be896 100644 --- a/services/abilitymgr/include/ability_auto_startup_data_manager.h +++ b/services/abilitymgr/include/ability_auto_startup_data_manager.h @@ -37,13 +37,14 @@ public: int32_t DeleteAutoStartupData(const AutoStartupInfo &info); - int32_t DeleteAutoStartupData(const std::string &bundleName); + int32_t DeleteAutoStartupData(const std::string &bundleName, int32_t uid); AutoStartupStatus QueryAutoStartupData(const AutoStartupInfo &info); int32_t QueryAllAutoStartupApplications(std::vector &infoList); - int32_t GetCurrentAppAutoStartupData(const std::string &bundleName, std::vector &infoList); + int32_t GetCurrentAppAutoStartupData(const std::string &bundleName, + std::vector &infoList, const std::string &accessTokenId); private: DistributedKv::Status GetKvStore(); @@ -55,7 +56,7 @@ private: AutoStartupInfo ConvertAutoStartupInfoFromKeyAndValue( const DistributedKv::Key &key, const DistributedKv::Value &value); bool IsEqual(const DistributedKv::Key &key, const AutoStartupInfo &info); - bool IsEqual(const DistributedKv::Key &key, const std::string &bundleName); + bool IsEqual(const DistributedKv::Key &key, const std::string &accessTokenId); static const DistributedKv::AppId APP_ID; static const DistributedKv::StoreId STORE_ID; diff --git a/services/abilitymgr/include/ability_auto_startup_service.h b/services/abilitymgr/include/ability_auto_startup_service.h index 6f7ec59a2a..f3d2debe5a 100644 --- a/services/abilitymgr/include/ability_auto_startup_service.h +++ b/services/abilitymgr/include/ability_auto_startup_service.h @@ -78,9 +78,10 @@ public: /** * @brief Delete current bundleName auto start up data. * @param bundleName The current bundleName. + * @param uid The uid. * @return Returns ERR_OK on success, others on failure. */ - int32_t DeleteAutoStartupData(const std::string &bundleName); + int32_t DeleteAutoStartupData(const std::string &bundleName, int32_t uid); /** * @brief Check current bundleName auto start up data. @@ -137,7 +138,8 @@ private: std::string GetSelfApplicationBundleName(); bool CheckSelfApplication(const std::string &bundleName); bool GetBundleInfo(const std::string &bundleName, AppExecFwk::BundleInfo &bundleInfo, int32_t uid = -1); - bool GetAbilityData(const AutoStartupInfo &info, bool &isVisible, std::string &abilityTypeName); + bool GetAbilityData(const AutoStartupInfo &info, bool &isVisible, + std::string &abilityTypeName, std::string &accessTokenId); std::string GetAbilityTypeName(AppExecFwk::AbilityInfo abilityInfo); std::string GetExtensionTypeName(AppExecFwk::ExtensionAbilityInfo extensionInfo); std::shared_ptr GetBundleMgrClient(); @@ -145,7 +147,7 @@ private: int32_t CheckPermissionForSelf(const std::string &bundleName); int32_t CheckPermissionForEDM(); int32_t InnerApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool isSet, bool flag); - int32_t GetAbilityInfo(const AutoStartupInfo &info, std::string &abilityTypeName); + int32_t GetAbilityInfo(const AutoStartupInfo &info, std::string &abilityTypeName, std::string &accessTokenId); mutable std::mutex autoStartUpMutex_; mutable std::mutex deathRecipientsMutex_; diff --git a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp index 9bac0ebd83..536aac8f88 100644 --- a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp +++ b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp @@ -18,11 +18,13 @@ #include #include +#include "accesstoken_kit.h" #include "errors.h" #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "nlohmann/json.hpp" #include "types.h" +#include "os_account_manager_wrapper.h" namespace OHOS { namespace AbilityRuntime { @@ -37,6 +39,7 @@ const std::string JSON_KEY_IS_AUTO_STARTUP = "isAutoStartup"; const std::string JSON_KEY_IS_EDM_FORCE = "isEdmForce"; const std::string JSON_KEY_TYPE_NAME = "abilityTypeName"; const std::string JSON_KEY_APP_CLONE_INDEX = "appCloneIndex"; +const std::string JSON_KEY_ACCESS_TOKENID = "accessTokenId"; } // namespace const DistributedKv::AppId AbilityAutoStartupDataManager::APP_ID = { "auto_startup_storage" }; const DistributedKv::StoreId AbilityAutoStartupDataManager::STORE_ID = { "auto_startup_infos" }; @@ -91,13 +94,14 @@ bool AbilityAutoStartupDataManager::CheckKvStore() int32_t AbilityAutoStartupDataManager::InsertAutoStartupData( const AutoStartupInfo &info, bool isAutoStartup, bool isEdmForce) { - if (info.bundleName.empty() || info.abilityName.empty()) { + if (info.bundleName.empty() || info.abilityName.empty() || info.accessTokenId.empty()) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Invalid value."); return ERR_INVALID_VALUE; } - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", - info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, + "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str()); { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { @@ -124,13 +128,14 @@ int32_t AbilityAutoStartupDataManager::InsertAutoStartupData( int32_t AbilityAutoStartupDataManager::UpdateAutoStartupData( const AutoStartupInfo &info, bool isAutoStartup, bool isEdmForce) { - if (info.bundleName.empty() || info.abilityName.empty()) { + if (info.bundleName.empty() || info.abilityName.empty() || info.accessTokenId.empty()) { TAG_LOGW(AAFwkTag::AUTO_STARTUP, "Invalid value!"); return ERR_INVALID_VALUE; } - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", - info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, + "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str()); { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { @@ -164,13 +169,14 @@ int32_t AbilityAutoStartupDataManager::UpdateAutoStartupData( int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const AutoStartupInfo &info) { - if (info.bundleName.empty() || info.abilityName.empty()) { + if (info.bundleName.empty() || info.abilityName.empty() || info.accessTokenId.empty()) { TAG_LOGW(AAFwkTag::AUTO_STARTUP, "Invalid value!"); return ERR_INVALID_VALUE; } - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", - info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, + "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str()); { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { @@ -193,14 +199,23 @@ int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const AutoStartupIn return ERR_OK; } -int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const std::string &bundleName) +int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const std::string &bundleName, int32_t uid) { - if (bundleName.empty()) { + int32_t userId; + if (DelayedSingleton::GetInstance()-> + GetOsAccountLocalIdFromUid(uid, userId) != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Get GetOsAccountLocalIdFromUid failed."); + return ERR_INVALID_VALUE; + } + uint32_t accessTokenId = Security::AccessToken::AccessTokenKit::GetHapTokenID(userId, bundleName, 0); + auto accessTokenIdStr = std::to_string(accessTokenId); + if (bundleName.empty() || accessTokenIdStr.empty()) { TAG_LOGW(AAFwkTag::AUTO_STARTUP, "Invalid value!"); return ERR_INVALID_VALUE; } - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s.", bundleName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, accessTokenId: %{public}s.", + bundleName.c_str(), accessTokenIdStr.c_str()); { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { @@ -217,7 +232,7 @@ int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const std::string & } for (const auto &item : allEntries) { - if (IsEqual(item.key, bundleName)) { + if (IsEqual(item.key, accessTokenIdStr)) { { std::lock_guard lock(kvStorePtrMutex_); status = kvStorePtr_->Delete(item.key); @@ -235,14 +250,15 @@ int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const std::string & AutoStartupStatus AbilityAutoStartupDataManager::QueryAutoStartupData(const AutoStartupInfo &info) { AutoStartupStatus asustatus; - if (info.bundleName.empty() || info.abilityName.empty()) { + if (info.bundleName.empty() || info.abilityName.empty() || info.accessTokenId.empty()) { TAG_LOGW(AAFwkTag::AUTO_STARTUP, "Invalid value!"); asustatus.code = ERR_INVALID_VALUE; return asustatus; } - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", - info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, + "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str()); { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { @@ -301,7 +317,7 @@ int32_t AbilityAutoStartupDataManager::QueryAllAutoStartupApplications(std::vect } int32_t AbilityAutoStartupDataManager::GetCurrentAppAutoStartupData( - const std::string &bundleName, std::vector &infoList) + const std::string &bundleName, std::vector &infoList, const std::string &accessTokenId) { TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called."); { @@ -320,7 +336,7 @@ int32_t AbilityAutoStartupDataManager::GetCurrentAppAutoStartupData( } for (const auto &item : allEntries) { - if (IsEqual(item.key, bundleName)) { + if (IsEqual(item.key, accessTokenId)) { infoList.emplace_back(ConvertAutoStartupInfoFromKeyAndValue(item.key, item.value)); } } @@ -364,6 +380,7 @@ DistributedKv::Key AbilityAutoStartupDataManager::ConvertAutoStartupDataToKey(co { JSON_KEY_MODULE_NAME, info.moduleName }, { JSON_KEY_ABILITY_NAME, info.abilityName }, { JSON_KEY_APP_CLONE_INDEX, info.appCloneIndex }, + { JSON_KEY_ACCESS_TOKENID, info.accessTokenId }, }; DistributedKv::Key key(jsonObject.dump()); TAG_LOGD(AAFwkTag::AUTO_STARTUP, "key: %{public}s.", key.ToString().c_str()); @@ -406,6 +423,9 @@ AutoStartupInfo AbilityAutoStartupDataManager::ConvertAutoStartupInfoFromKeyAndV info.abilityTypeName = jsonValueObject.at(JSON_KEY_TYPE_NAME).get(); } + if (jsonValueObject.contains(JSON_KEY_ACCESS_TOKENID) && jsonValueObject[JSON_KEY_ACCESS_TOKENID].is_string()) { + info.accessTokenId = jsonValueObject.at(JSON_KEY_ACCESS_TOKENID).get(); + } return info; } @@ -435,10 +455,17 @@ bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const return false; } } + + if (jsonObject.contains(JSON_KEY_ACCESS_TOKENID) && jsonObject[JSON_KEY_ACCESS_TOKENID].is_string()) { + if (info.accessTokenId != jsonObject.at(JSON_KEY_ACCESS_TOKENID).get()) { + return false; + } + } + return true; } -bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const std::string &bundleName) +bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const std::string &accessTokenId) { nlohmann::json jsonObject = nlohmann::json::parse(key.ToString(), nullptr, false); if (jsonObject.is_discarded()) { @@ -446,8 +473,8 @@ bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const return false; } - if (jsonObject.contains(JSON_KEY_BUNDLE_NAME) && jsonObject[JSON_KEY_BUNDLE_NAME].is_string()) { - if (bundleName == jsonObject.at(JSON_KEY_BUNDLE_NAME).get()) { + if (jsonObject.contains(JSON_KEY_ACCESS_TOKENID) && jsonObject[JSON_KEY_ACCESS_TOKENID].is_string()) { + if (accessTokenId == jsonObject.at(JSON_KEY_ACCESS_TOKENID).get()) { return true; } } diff --git a/services/abilitymgr/src/ability_auto_startup_service.cpp b/services/abilitymgr/src/ability_auto_startup_service.cpp index 4d19c98399..00e4915956 100644 --- a/services/abilitymgr/src/ability_auto_startup_service.cpp +++ b/services/abilitymgr/src/ability_auto_startup_service.cpp @@ -17,6 +17,7 @@ #include #include +#include #include "ability_auto_startup_data_manager.h" #include "ability_manager_errors.h" @@ -102,8 +103,9 @@ int32_t AbilityAutoStartupService::UnregisterAutoStartupSystemCallback(const spt int32_t AbilityAutoStartupService::SetApplicationAutoStartup(const AutoStartupInfo &info) { - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", - info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, + "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str()); int32_t code = CheckPermissionForSystem(); if (code != ERR_OK) { return code; @@ -111,7 +113,8 @@ int32_t AbilityAutoStartupService::SetApplicationAutoStartup(const AutoStartupIn bool isVisible; std::string abilityTypeName; - if (!GetAbilityData(info, isVisible, abilityTypeName)) { + std::string accessTokenId; + if (!GetAbilityData(info, isVisible, abilityTypeName, accessTokenId)) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get ability data."); return INNER_ERR; } @@ -123,6 +126,7 @@ int32_t AbilityAutoStartupService::SetApplicationAutoStartup(const AutoStartupIn AutoStartupInfo fullInfo(info); fullInfo.abilityTypeName = abilityTypeName; + fullInfo.accessTokenId = accessTokenId; return InnerSetApplicationAutoStartup(fullInfo); } @@ -163,8 +167,9 @@ int32_t AbilityAutoStartupService::InnerSetApplicationAutoStartup(const AutoStar int32_t AbilityAutoStartupService::CancelApplicationAutoStartup(const AutoStartupInfo &info) { - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", - info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, + "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str()); int32_t code = CheckPermissionForSystem(); if (code != ERR_OK) { return code; @@ -172,7 +177,8 @@ int32_t AbilityAutoStartupService::CancelApplicationAutoStartup(const AutoStartu bool isVisible; std::string abilityTypeName; - if (!GetAbilityData(info, isVisible, abilityTypeName)) { + std::string accessTokenId; + if (!GetAbilityData(info, isVisible, abilityTypeName, accessTokenId)) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get ability data."); return INNER_ERR; } @@ -184,6 +190,7 @@ int32_t AbilityAutoStartupService::CancelApplicationAutoStartup(const AutoStartu AutoStartupInfo fullInfo(info); fullInfo.abilityTypeName = abilityTypeName; + fullInfo.accessTokenId = accessTokenId; return InnerCancelApplicationAutoStartup(fullInfo); } @@ -237,17 +244,23 @@ int32_t AbilityAutoStartupService::QueryAllAutoStartupApplicationsWithoutPermiss return DelayedSingleton::GetInstance()->QueryAllAutoStartupApplications(infoList); } -int32_t AbilityAutoStartupService::DeleteAutoStartupData(const std::string &bundleName) +int32_t AbilityAutoStartupService::DeleteAutoStartupData(const std::string &bundleName, const int32_t uid) { TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called."); - return DelayedSingleton::GetInstance()->DeleteAutoStartupData(bundleName); + return DelayedSingleton::GetInstance()->DeleteAutoStartupData(bundleName, uid); } int32_t AbilityAutoStartupService::CheckAutoStartupData(const std::string &bundleName, int32_t uid) { + AppExecFwk::BundleInfo bundleInfo; + if (!GetBundleInfo(bundleName, bundleInfo, uid)) { + return INNER_ERR; + } + auto tokenId = bundleInfo.applicationInfo.accessTokenId; + std::string accessTokenIdStr = std::to_string(tokenId); std::vector infoList; int32_t result = DelayedSingleton::GetInstance()->GetCurrentAppAutoStartupData( - bundleName, infoList); + bundleName, infoList, accessTokenIdStr); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get auto startup data."); return result; @@ -256,11 +269,6 @@ int32_t AbilityAutoStartupService::CheckAutoStartupData(const std::string &bundl return ERR_OK; } - AppExecFwk::BundleInfo bundleInfo; - if (!GetBundleInfo(bundleName, bundleInfo, uid)) { - return INNER_ERR; - } - bool isFound = false; for (auto info : infoList) { for (auto abilityInfo : bundleInfo.abilityInfos) { @@ -274,15 +282,16 @@ int32_t AbilityAutoStartupService::CheckAutoStartupData(const std::string &bundl if (!isFound) { TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Current bundleName not found in Datebase."); - return DelayedSingleton::GetInstance()->DeleteAutoStartupData(bundleName); + return DelayedSingleton::GetInstance()->DeleteAutoStartupData(bundleName, uid); } return ERR_OK; } void AbilityAutoStartupService::ExecuteCallbacks(bool isCallOn, const AutoStartupInfo &info) { - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", - info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, + "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str()); for (auto item : callbackVector_) { auto remoteSystemCallback = iface_cast(item); if (remoteSystemCallback != nullptr) { @@ -443,15 +452,18 @@ bool AbilityAutoStartupService::GetBundleInfo( } bool AbilityAutoStartupService::GetAbilityData( - const AutoStartupInfo &info, bool &isVisible, std::string &abilityTypeName) + const AutoStartupInfo &info, bool &isVisible, std::string &abilityTypeName, std::string &accessTokenId) { - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", - info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str()); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, + "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str()); AppExecFwk::BundleInfo bundleInfo; if (!GetBundleInfo(info.bundleName, bundleInfo)) { return false; } + auto accessTokenIdStr = bundleInfo.applicationInfo.accessTokenId; + accessTokenId = std::to_string(accessTokenIdStr); for (auto abilityInfo : bundleInfo.abilityInfos) { if ((abilityInfo.bundleName == info.bundleName) && (abilityInfo.name == info.abilityName)) { if (info.moduleName.empty() || (abilityInfo.moduleName == info.moduleName)) { @@ -538,10 +550,11 @@ int32_t AbilityAutoStartupService::CheckPermissionForSelf(const std::string &bun return ERR_OK; } -int32_t AbilityAutoStartupService::GetAbilityInfo(const AutoStartupInfo &info, std::string &abilityTypeName) +int32_t AbilityAutoStartupService::GetAbilityInfo( + const AutoStartupInfo &info, std::string &abilityTypeName, std::string &accessTokenId) { bool isVisible = false; - if (!GetAbilityData(info, isVisible, abilityTypeName)) { + if (!GetAbilityData(info, isVisible, abilityTypeName, accessTokenId)) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get ability data."); return INNER_ERR; } @@ -561,12 +574,14 @@ int32_t AbilityAutoStartupService::SetApplicationAutoStartupByEDM(const AutoStar return errorCode; } std::string typeName; - errorCode = GetAbilityInfo(info, typeName); + std::string accessTokenId; + errorCode = GetAbilityInfo(info, typeName, accessTokenId); if (errorCode != ERR_OK) { return errorCode; } AutoStartupInfo fullInfo(info); fullInfo.abilityTypeName = typeName; + fullInfo.accessTokenId = accessTokenId; return InnerApplicationAutoStartupByEDM(fullInfo, true, flag); } @@ -577,20 +592,24 @@ int32_t AbilityAutoStartupService::CancelApplicationAutoStartupByEDM(const AutoS return errorCode; } std::string typeName; - errorCode = GetAbilityInfo(info, typeName); + std::string accessTokenId; + errorCode = GetAbilityInfo(info, typeName, accessTokenId); if (errorCode != ERR_OK) { return errorCode; } AutoStartupInfo fullInfo(info); fullInfo.abilityTypeName = typeName; + fullInfo.accessTokenId = accessTokenId; return InnerApplicationAutoStartupByEDM(fullInfo, false, flag); } int32_t AbilityAutoStartupService::InnerApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool isSet, bool flag) { TAG_LOGD(AAFwkTag::AUTO_STARTUP, - "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, isSet: %{public}d.," - "flag: %{public}d.", info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), isSet, flag); + "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, accessTokenId: %{public}s," + " isSet: %{public}d.,""flag: %{public}d.", + info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), + info.accessTokenId.c_str(), isSet, flag); AutoStartupStatus status = DelayedSingleton::GetInstance()->QueryAutoStartupData(info); if (status.code != ERR_OK && status.code != ERR_NAME_NOT_FOUND) { diff --git a/services/abilitymgr/src/ability_bundle_event_callback.cpp b/services/abilitymgr/src/ability_bundle_event_callback.cpp index f7874db96f..768c670283 100644 --- a/services/abilitymgr/src/ability_bundle_event_callback.cpp +++ b/services/abilitymgr/src/ability_bundle_event_callback.cpp @@ -58,7 +58,7 @@ void AbilityBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData TAG_LOGE(AAFwkTag::ABILITYMGR, "OnReceiveEvent failed, abilityAutoStartupService is nullptr"); return; } - abilityAutoStartupService_->DeleteAutoStartupData(bundleName); + abilityAutoStartupService_->DeleteAutoStartupData(bundleName, uid); } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED) { // install or uninstall module/bundle HandleUpdatedModuleInfo(bundleName, uid); diff --git a/test/unittest/ability_auto_startup_data_manager_test/BUILD.gn b/test/unittest/ability_auto_startup_data_manager_test/BUILD.gn index 8fc128ff37..dbc6f6d6d2 100644 --- a/test/unittest/ability_auto_startup_data_manager_test/BUILD.gn +++ b/test/unittest/ability_auto_startup_data_manager_test/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("ability_auto_startup_data_manager_test") { "${ability_runtime_abilitymgr_path}/:abilityms", "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", + "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_native_path}/ability:ability_context_native", "${ability_runtime_services_path}/abilitymgr:abilityms", diff --git a/test/unittest/ability_auto_startup_data_manager_test/ability_auto_startup_data_manager_test.cpp b/test/unittest/ability_auto_startup_data_manager_test/ability_auto_startup_data_manager_test.cpp index c9749e9299..fa85caaba7 100644 --- a/test/unittest/ability_auto_startup_data_manager_test/ability_auto_startup_data_manager_test.cpp +++ b/test/unittest/ability_auto_startup_data_manager_test/ability_auto_startup_data_manager_test.cpp @@ -334,7 +334,8 @@ HWTEST_F(AbilityAutoStartupDataManagerTest, DeleteAutoStartupData_bundleName_100 GTEST_LOG_(INFO) << "DeleteAutoStartupData_bundleName_100 start"; AbilityAutoStartupDataManager abilityAutoStartupDataManager; std::string bundleName = ""; - auto result = abilityAutoStartupDataManager.DeleteAutoStartupData(bundleName); + int32_t uid = 0; + auto result = abilityAutoStartupDataManager.DeleteAutoStartupData(bundleName, uid); EXPECT_EQ(result, ERR_INVALID_VALUE); GTEST_LOG_(INFO) << "DeleteAutoStartupData_bundleName_100 end"; } @@ -350,7 +351,8 @@ HWTEST_F(AbilityAutoStartupDataManagerTest, DeleteAutoStartupData_bundleName_200 GTEST_LOG_(INFO) << "DeleteAutoStartupData_bundleName_200 start"; AbilityAutoStartupDataManager abilityAutoStartupDataManager; std::string bundleName = "com.example.testbundle"; - auto result = abilityAutoStartupDataManager.DeleteAutoStartupData(bundleName); + int32_t uid = 0; + auto result = abilityAutoStartupDataManager.DeleteAutoStartupData(bundleName, uid); EXPECT_EQ(result, ERR_OK); GTEST_LOG_(INFO) << "DeleteAutoStartupData_bundleName_200 end"; } @@ -370,7 +372,8 @@ HWTEST_F(AbilityAutoStartupDataManagerTest, DeleteAutoStartupData_bundleName_300 EXPECT_EQ(true, abilityAutoStartupDataManager.CheckKvStore()); std::string bundleName = "com.example.testbundle"; - auto result = abilityAutoStartupDataManager.DeleteAutoStartupData(bundleName); + int32_t uid = 0; + auto result = abilityAutoStartupDataManager.DeleteAutoStartupData(bundleName, uid); EXPECT_EQ(result, ERR_OK); GTEST_LOG_(INFO) << "DeleteAutoStartupData_bundleName_300 end"; } @@ -498,7 +501,8 @@ HWTEST_F(AbilityAutoStartupDataManagerTest, GetCurrentAppAutoStartupData_100, Te AutoStartupInfo info; info.bundleName = "com.example.testbundle"; std::vector infoList; - auto result = abilityAutoStartupDataManager.GetCurrentAppAutoStartupData(info.bundleName, infoList); + std::string accessTokenId = "0"; + auto result = abilityAutoStartupDataManager.GetCurrentAppAutoStartupData(info.bundleName, infoList, accessTokenId); EXPECT_EQ(result, ERR_OK); GTEST_LOG_(INFO) << "GetCurrentAppAutoStartupData_100 end"; } @@ -520,7 +524,8 @@ HWTEST_F(AbilityAutoStartupDataManagerTest, GetCurrentAppAutoStartupData_200, Te AutoStartupInfo info; info.bundleName = "com.example.testbundle"; std::vector infoList; - auto result = abilityAutoStartupDataManager.GetCurrentAppAutoStartupData(info.bundleName, infoList); + std::string accessTokenId = "0"; + auto result = abilityAutoStartupDataManager.GetCurrentAppAutoStartupData(info.bundleName, infoList, accessTokenId); EXPECT_EQ(result, ERR_OK); GTEST_LOG_(INFO) << "GetCurrentAppAutoStartupData_200 end"; } diff --git a/test/unittest/ability_auto_startup_service_test/BUILD.gn b/test/unittest/ability_auto_startup_service_test/BUILD.gn index 2eafb6c7dd..ce7786334c 100644 --- a/test/unittest/ability_auto_startup_service_test/BUILD.gn +++ b/test/unittest/ability_auto_startup_service_test/BUILD.gn @@ -42,6 +42,7 @@ ohos_unittest("ability_auto_startup_service_test") { "${ability_runtime_abilitymgr_path}/:abilityms", "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", + "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_native_path}/ability:ability_context_native", "${ability_runtime_native_path}/ability/native:auto_startup_callback", diff --git a/test/unittest/ability_auto_startup_service_test/ability_auto_startup_service_test.cpp b/test/unittest/ability_auto_startup_service_test/ability_auto_startup_service_test.cpp index ef1c6aa210..4703cf8ec6 100644 --- a/test/unittest/ability_auto_startup_service_test/ability_auto_startup_service_test.cpp +++ b/test/unittest/ability_auto_startup_service_test/ability_auto_startup_service_test.cpp @@ -252,7 +252,8 @@ HWTEST_F(AbilityAutoStartupServiceTest, DeleteAutoStartupData_001, TestSize.Leve GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest DeleteAutoStartupData_001 start"; auto abilityAutoStartupService = std::make_shared(); std::string bundleName = AUTO_STARTUP_SERVICE_BUNDLENAME; - auto result = abilityAutoStartupService->DeleteAutoStartupData(bundleName); + int32_t uid = 0; + auto result = abilityAutoStartupService->DeleteAutoStartupData(bundleName, uid); EXPECT_EQ(result, ERR_OK); GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest DeleteAutoStartupData_001 end"; } @@ -418,7 +419,8 @@ HWTEST_F(AbilityAutoStartupServiceTest, GetAbilityData_001, TestSize.Level1) AutoStartupInfo info; std::string abilityTypeName; bool isVisible = AUTO_STARTUP_SERVICE_FALSE; - auto result = abilityAutoStartupService->GetAbilityData(info, isVisible, abilityTypeName); + std::string accessTokenId = "0"; + auto result = abilityAutoStartupService->GetAbilityData(info, isVisible, abilityTypeName, accessTokenId); EXPECT_FALSE(result); GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetAbilityData_001 end"; } @@ -515,7 +517,8 @@ HWTEST_F(AbilityAutoStartupServiceTest, GetAbilityInfo_001, TestSize.Level1) auto abilityAutoStartupService = std::make_shared(); AutoStartupInfo info; std::string abilityTypeName = AUTO_STARTUP_SERVICE_ABILITYNAME; - auto result = abilityAutoStartupService->GetAbilityInfo(info, abilityTypeName); + std::string accessTokenId = "0"; + auto result = abilityAutoStartupService->GetAbilityInfo(info, abilityTypeName, accessTokenId); EXPECT_EQ(result, INNER_ERR); GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetAbilityInfo_001 end"; } diff --git a/test/unittest/ability_bundle_event_callback_test/BUILD.gn b/test/unittest/ability_bundle_event_callback_test/BUILD.gn index f8fe65a813..c1b5393b61 100644 --- a/test/unittest/ability_bundle_event_callback_test/BUILD.gn +++ b/test/unittest/ability_bundle_event_callback_test/BUILD.gn @@ -39,6 +39,7 @@ ohos_unittest("ability_bundle_event_callback_test") { configs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test:aafwk_mock_config" ] deps = [ + "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_native_path}/ability/native:auto_startup_callback", "${ability_runtime_services_path}/abilitymgr:abilityms", diff --git a/test/unittest/specified_mission_list_test/BUILD.gn b/test/unittest/specified_mission_list_test/BUILD.gn index 8e8b53a08c..0bf26322ad 100644 --- a/test/unittest/specified_mission_list_test/BUILD.gn +++ b/test/unittest/specified_mission_list_test/BUILD.gn @@ -60,6 +60,7 @@ ohos_unittest("specified_mission_list_test") { "ability_base:session_info", "ability_base:want", "ability_base:zuri", + "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", "config_policy:configpolicy_util", From 4fe7f337519c84a60e00d2d5a0c67eaab198d4f9 Mon Sep 17 00:00:00 2001 From: xia Date: Fri, 31 May 2024 11:06:47 +0800 Subject: [PATCH 28/69] =?UTF-8?q?=E6=A0=B7=E6=9C=BA=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=9C=A8=E6=9E=81=E7=AB=AF=E5=86=85=E5=AD=98=E4=B8=8B=E4=BF=9D?= =?UTF-8?q?=E6=8C=81=E5=B8=B8=E9=A9=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xia --- .../abilitymgr/include/ability_connect_manager.h | 1 + .../abilitymgr/src/ability_connect_manager.cpp | 14 +++++++++++++- services/appmgr/src/app_mgr_service_inner.cpp | 5 ++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/services/abilitymgr/include/ability_connect_manager.h b/services/abilitymgr/include/ability_connect_manager.h index 2fd52f2381..df098543b7 100644 --- a/services/abilitymgr/include/ability_connect_manager.h +++ b/services/abilitymgr/include/ability_connect_manager.h @@ -553,6 +553,7 @@ private: std::shared_ptr GetExtensionByIdFromServiceMap(int32_t abilityRecordId); int TerminateAbilityInner(const sptr &token); bool IsLauncher(std::shared_ptr serviceExtension) const; + bool IsSampleManagement(std::shared_ptr serviceExtension) const; void KillProcessesByUserId() const; void SetLastExitReason(const AbilityRequest &abilityRequest, std::shared_ptr &targetService); inline bool IsUIExtensionAbility(const std::shared_ptr &abilityRecord); diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 9642374084..b2fa404357 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -75,6 +75,8 @@ const std::unordered_set FROZEN_WHITE_LIST { }; constexpr char BUNDLE_NAME_DIALOG[] = "com.ohos.amsdialog"; constexpr char ABILITY_NAME_ASSERT_FAULT_DIALOG[] = "AssertFaultDialog"; +constexpr char BUNDLE_NAME_SAMPLE_MANAGEMENT[] = "com.huawei.hmsapp.samplemanagement"; +constexpr char ABILITY_NAME_SAMPLE_MANAGEMENT[] = "MspesService"; bool IsSpecialAbility(const AppExecFwk::AbilityInfo &abilityInfo) { @@ -2016,7 +2018,7 @@ void AbilityConnectManager::HandleAbilityDiedTask( } } if (DelayedSingleton::GetInstance()->IsMemorySizeSufficent() || - IsLauncher(abilityRecord) || abilityRecord->IsSceneBoard()) { + IsLauncher(abilityRecord) || abilityRecord->IsSceneBoard() || IsSampleManagement(abilityRecord)) { RestartAbility(abilityRecord, currentUserId); } } else { @@ -2345,6 +2347,16 @@ bool AbilityConnectManager::IsLauncher(std::shared_ptr serviceExt serviceExtension->GetAbilityInfo().bundleName == AbilityConfig::LAUNCHER_BUNDLE_NAME; } +bool AbilityConnectManager::IsSampleManagement(std::shared_ptr serviceExtension) const +{ + if (serviceExtension == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "param is nullptr"); + return false; + } + return serviceExtension->GetAbilityInfo().name == ABILITY_NAME_SAMPLE_MANAGEMENT && + serviceExtension->GetAbilityInfo().bundleName == BUNDLE_NAME_SAMPLE_MANAGEMENT; +} + void AbilityConnectManager::KillProcessesByUserId() const { auto appScheduler = DelayedSingleton::GetInstance(); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 6d435371ba..5eef5278b9 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -180,6 +180,8 @@ constexpr char EVENT_KEY_MESSAGE[] = "MSG"; constexpr char DEVELOPER_MODE_STATE[] = "const.security.developermode.state"; constexpr char PRODUCT_ASSERT_FAULT_DIALOG_ENABLED[] = "persisit.sys.abilityms.support_assert_fault_dialog"; +constexpr char BUNDLE_NAME_SAMPLE_MANAGEMENT[] = "com.huawei.hmsapp.samplemanagement"; + // Msg length is less than 48 characters const std::string EVENT_MESSAGE_TERMINATE_ABILITY_TIMEOUT = "Terminate Ability TimeOut!"; const std::string EVENT_MESSAGE_TERMINATE_APPLICATION_TIMEOUT = "Terminate Application TimeOut!"; @@ -5918,7 +5920,8 @@ void AppMgrServiceInner::ClearAppRunningDataForKeepAlive(const std::shared_ptrIsKeepAliveApp()) { - if (ExitResidentProcessManager::GetInstance().RecordExitResidentBundleName(appRecord->GetBundleName())) { + if (appRecord->GetBundleName() != BUNDLE_NAME_SAMPLE_MANAGEMENT && + ExitResidentProcessManager::GetInstance().RecordExitResidentBundleName(appRecord->GetBundleName())) { TAG_LOGI(AAFwkTag::APPMGR, "memory size is insufficent, record exit resident process info"); return; } From 1b33e354bf9abcbd7cc8ca5c2dfa025dbc65d3c5 Mon Sep 17 00:00:00 2001 From: zhubingwei Date: Fri, 31 May 2024 10:18:42 +0800 Subject: [PATCH 29/69] fix tdd carsh caused by cfi change in GN Signed-off-by: zhubingwei Change-Id: I635e68d51d948264898b7d427d7692577d7e9a1a --- test/mock/services_abilitymgr_test/libs/aakit/BUILD.gn | 7 +++++++ test/unittest/ability_connect_manager_test/BUILD.gn | 7 +++++++ test/unittest/ability_manager_service_first_test/BUILD.gn | 6 ++++++ test/unittest/ability_manager_service_third_test/BUILD.gn | 6 ++++++ test/unittest/app_scheduler_test/BUILD.gn | 6 ++++++ .../mission_list_manager_test.cpp | 1 + 6 files changed, 33 insertions(+) diff --git a/test/mock/services_abilitymgr_test/libs/aakit/BUILD.gn b/test/mock/services_abilitymgr_test/libs/aakit/BUILD.gn index 605afbe456..63ec8fdd3a 100644 --- a/test/mock/services_abilitymgr_test/libs/aakit/BUILD.gn +++ b/test/mock/services_abilitymgr_test/libs/aakit/BUILD.gn @@ -27,6 +27,13 @@ config("aakit_mock_config") { } ohos_static_library("aakit_mock") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + sources = [ "src/ability_scheduler.cpp", "src/mock_ability_connect_callback.cpp", diff --git a/test/unittest/ability_connect_manager_test/BUILD.gn b/test/unittest/ability_connect_manager_test/BUILD.gn index d7f8c1d528..d271efa538 100644 --- a/test/unittest/ability_connect_manager_test/BUILD.gn +++ b/test/unittest/ability_connect_manager_test/BUILD.gn @@ -18,6 +18,13 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("ability_connect_manager_test") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", diff --git a/test/unittest/ability_manager_service_first_test/BUILD.gn b/test/unittest/ability_manager_service_first_test/BUILD.gn index 3d8870adfb..a7c8a2c695 100644 --- a/test/unittest/ability_manager_service_first_test/BUILD.gn +++ b/test/unittest/ability_manager_service_first_test/BUILD.gn @@ -18,6 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("ability_manager_service_first_test") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/include", diff --git a/test/unittest/ability_manager_service_third_test/BUILD.gn b/test/unittest/ability_manager_service_third_test/BUILD.gn index 4a19bc730f..5365429409 100644 --- a/test/unittest/ability_manager_service_third_test/BUILD.gn +++ b/test/unittest/ability_manager_service_third_test/BUILD.gn @@ -18,6 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("ability_manager_service_third_test") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_innerkits_path}/uri_permission/include", diff --git a/test/unittest/app_scheduler_test/BUILD.gn b/test/unittest/app_scheduler_test/BUILD.gn index fa44ddf53e..71c39bed25 100644 --- a/test/unittest/app_scheduler_test/BUILD.gn +++ b/test/unittest/app_scheduler_test/BUILD.gn @@ -20,6 +20,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("app_scheduler_test") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_services_path}/abilitymgr/include", diff --git a/test/unittest/mission_list_manager_test/mission_list_manager_test.cpp b/test/unittest/mission_list_manager_test/mission_list_manager_test.cpp index 3613c442fd..96ce59c69c 100644 --- a/test/unittest/mission_list_manager_test/mission_list_manager_test.cpp +++ b/test/unittest/mission_list_manager_test/mission_list_manager_test.cpp @@ -1102,6 +1102,7 @@ HWTEST_F(MissionListManagerTest, GetReusedMission_001, TestSize.Level1) { int userId = 0; auto missionListManager = std::make_shared(userId); + missionListManager->Init(); AbilityRequest abilityRequest; abilityRequest.abilityInfo.launchMode = AppExecFwk::LaunchMode::SPECIFIED; auto res = missionListManager->GetReusedMission(abilityRequest); From fca1fb59207b0874db45590df3c085e07f504e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 31 May 2024 08:46:29 +0000 Subject: [PATCH 30/69] update frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../ability_bundle_manager_helper/bundle_mgr_helper.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp index 73dace25a8..f07249f52c 100644 --- a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp +++ b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp @@ -644,8 +644,10 @@ bool BundleMgrHelper::ImplicitQueryInfos(const Want &want, int32_t flags, int32_ newWant.RemoveAllFd(); HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); bool findDefaultApp = false; - return bundleMgr->ImplicitQueryInfos(newWant, flags, userId, withDefault, abilityInfos, extensionInfos, - findDefaultApp); + bool ret = bundleMgr->ImplicitQueryInfos(newWant, flags, userId, withDefault, abilityInfos, + extensionInfos, findDefaultApp); + TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "findDefaultApp is %{public}d.", findDefaultApp); + return ret; } bool BundleMgrHelper::CleanBundleDataFiles(const std::string &bundleName, const int32_t userId) From 830956f3bec5d4afa34af310ace17c5b93c0acea Mon Sep 17 00:00:00 2001 From: wangkailong Date: Fri, 31 May 2024 15:48:31 +0800 Subject: [PATCH 31/69] want Signed-off-by: wangkailong Change-Id: Id33ad0882c33ac98369f1b5d9698eb3ce3ce92a7 --- .../native/ui_extension_ability/js_ui_extension.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp index 5a7a1a33f2..188ee34a2b 100755 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp @@ -262,11 +262,14 @@ void JsUIExtension::OnStart(const AAFwk::Want &want) if (InsightIntentExecuteParam::IsInsightIntentExecute(want)) { launchParam.launchReason = AAFwk::LaunchReason::LAUNCHREASON_INSIGHT_INTENT; } - napi_value argv[] = { - CreateJsLaunchParam(env, launchParam), - napiWant - }; - CallObjectMethod("onCreate", argv, ARGC_TWO); + int32_t screenMode = want.GetIntParam(AAFwk::SCREEN_MODE_KEY, AAFwk::IDLE_SCREEN_MODE); + if (screenMode == AAFwk::EMBEDDED_FULL_SCREEN_MODE) { + napi_value argv[] = {napiWant, CreateJsLaunchParam(env, launchParam) }; + CallObjectMethod("onCreate", argv, ARGC_TWO); + } else { + napi_value argv[] = {CreateJsLaunchParam(env, launchParam) }; + CallObjectMethod("onCreate", argv, ARGC_ONE); + } TAG_LOGD(AAFwkTag::UI_EXT, "JsUIExtension OnStart end."); } From 20aee69b6108adb04193fbe82c14649202a86ba1 Mon Sep 17 00:00:00 2001 From: wangkailong Date: Fri, 31 May 2024 16:25:44 +0800 Subject: [PATCH 32/69] hilog Signed-off-by: wangkailong Change-Id: I159db6ed97d7b4de5dc1d91eb953c7a34ecf7e8e --- .../frameworks/js_environment/BUILD.gn | 2 + .../js_environment/src/js_environment.cpp | 67 ++++++++++--------- .../js_environment/src/source_map.cpp | 13 ++-- .../src/uncaught_exception_callback.cpp | 11 +-- .../inner_api/source_map_operator.h | 3 - .../js_environment_test.cpp | 6 -- 6 files changed, 49 insertions(+), 53 deletions(-) diff --git a/js_environment/frameworks/js_environment/BUILD.gn b/js_environment/frameworks/js_environment/BUILD.gn index 549d08ad36..1fd176ed1f 100644 --- a/js_environment/frameworks/js_environment/BUILD.gn +++ b/js_environment/frameworks/js_environment/BUILD.gn @@ -23,6 +23,7 @@ config("public_js_environment_config") { include_dirs = [ "${inner_api_path}", "${utils_path}/include", + "${ability_runtime_services_path}/common/include", ] } @@ -47,6 +48,7 @@ ohos_shared_library("js_environment") { "eventhandler:libeventhandler", "faultloggerd:libunwinder", "ffrt:libffrt", + "hilog:libhilog", "napi:ace_napi", ] diff --git a/js_environment/frameworks/js_environment/src/js_environment.cpp b/js_environment/frameworks/js_environment/src/js_environment.cpp index c5326be1e5..862494d788 100644 --- a/js_environment/frameworks/js_environment/src/js_environment.cpp +++ b/js_environment/frameworks/js_environment/src/js_environment.cpp @@ -16,7 +16,8 @@ #include "js_environment.h" #include "ffrt.h" -#include "js_env_logger.h" +#include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" #include "js_environment_impl.h" #include "native_engine/impl/ark/ark_native_engine.h" #include "uncaught_exception_callback.h" @@ -40,12 +41,12 @@ static panda::DFXJSNApi::ProfilerType ConvertProfilerType(JsEnvironment::PROFILE JsEnvironment::JsEnvironment(std::unique_ptr impl) : impl_(std::move(impl)) { - JSENV_LOG_D("called"); + TAG_LOGD(AAFwkTag::JSENV, "called"); } JsEnvironment::~JsEnvironment() { - JSENV_LOG_D("called"); + TAG_LOGD(AAFwkTag::JSENV, "called"); if (engine_ != nullptr) { delete engine_; @@ -60,10 +61,10 @@ JsEnvironment::~JsEnvironment() bool JsEnvironment::Initialize(const panda::RuntimeOption& pandaOption, void* jsEngine) { - JSENV_LOG_D("Js environment initialize."); + TAG_LOGD(AAFwkTag::JSENV, "Js environment initialize."); vm_ = panda::JSNApi::CreateJSVM(pandaOption); if (vm_ == nullptr) { - JSENV_LOG_E("Create vm failed."); + TAG_LOGE(AAFwkTag::JSENV, "Create vm failed."); return false; } @@ -74,7 +75,7 @@ bool JsEnvironment::Initialize(const panda::RuntimeOption& pandaOption, void* js void JsEnvironment::InitTimerModule() { if (engine_ == nullptr) { - JSENV_LOG_E("Invalid native engine."); + TAG_LOGE(AAFwkTag::JSENV, "Invalid native engine."); return; } @@ -86,7 +87,7 @@ void JsEnvironment::InitTimerModule() void JsEnvironment::InitWorkerModule(std::shared_ptr workerInfo) { if (engine_ == nullptr) { - JSENV_LOG_E("Invalid native engine."); + TAG_LOGE(AAFwkTag::JSENV, "Invalid native engine."); return; } @@ -127,7 +128,7 @@ void JsEnvironment::InitSourceMap(const std::shared_ptrGetInitStatus()) { return sourceMapOperator_->TranslateBySourceMap(rawStack); } else { - JSENV_LOG_E("SourceMap is not initialized yet"); + TAG_LOGE(AAFwkTag::JSENV, "SourceMap is not initialized yet"); return NOT_INIT + rawStack; } }; @@ -149,7 +150,7 @@ void JsEnvironment::InitSourceMap(const std::shared_ptrGetInitStatus()) { return sourceMapOperator_->TranslateUrlPositionBySourceMap(url, line, column); } - JSENV_LOG_E("SourceMap is not initialized yet"); + TAG_LOGE(AAFwkTag::JSENV, "SourceMap is not initialized yet"); return false; }; engine_->RegisterSourceMapTranslateCallback(translateUrlBySourceMapFunc); @@ -158,7 +159,7 @@ void JsEnvironment::InitSourceMap(const std::shared_ptr* buffer, bool isBundle) { if (engine_ == nullptr) { - JSENV_LOG_E("Invalid Native Engine."); + TAG_LOGE(AAFwkTag::JSENV, "Invalid Native Engine."); return false; } @@ -183,21 +184,21 @@ bool JsEnvironment::LoadScript(const std::string& path, std::vector* bu bool JsEnvironment::StartDebugger( std::string& option, uint32_t socketFd, bool isDebugApp, const DebuggerPostTask &debuggerPostTask) { - JSENV_LOG_D("call."); + TAG_LOGD(AAFwkTag::JSENV, "call."); if (vm_ == nullptr) { - JSENV_LOG_E("Invalid vm."); + TAG_LOGE(AAFwkTag::JSENV, "Invalid vm."); return false; } int32_t identifierId = ParseHdcRegisterOption(option); if (identifierId == -1) { - JSENV_LOG_E("Abnormal parsing of tid results."); + TAG_LOGE(AAFwkTag::JSENV, "Abnormal parsing of tid results."); return false; } if (isDebugApp) { debugMode_ = panda::JSNApi::StartDebuggerForSocketPair(identifierId, socketFd); } else { if (debuggerPostTask == nullptr) { - JSENV_LOG_E("debuggerPostTask is nullptr."); + TAG_LOGE(AAFwkTag::JSENV, "debuggerPostTask is nullptr."); return false; } auto startDebuggerForSocketPairTask = [identifierId, socketFd, this]() { @@ -211,7 +212,7 @@ bool JsEnvironment::StartDebugger( void JsEnvironment::StopDebugger() { if (vm_ == nullptr) { - JSENV_LOG_E("Invalid vm."); + TAG_LOGE(AAFwkTag::JSENV, "Invalid vm."); return; } @@ -222,7 +223,7 @@ void JsEnvironment::StopDebugger(std::string& option) { int32_t identifierId = ParseHdcRegisterOption(option); if (identifierId == -1) { - JSENV_LOG_E("Abnormal parsing of tid results."); + TAG_LOGE(AAFwkTag::JSENV, "Abnormal parsing of tid results."); return; } panda::JSNApi::StopDebugger(identifierId); @@ -231,7 +232,7 @@ void JsEnvironment::StopDebugger(std::string& option) void JsEnvironment::InitConsoleModule() { if (engine_ == nullptr) { - JSENV_LOG_E("Invalid Native Engine."); + TAG_LOGE(AAFwkTag::JSENV, "Invalid Native Engine."); return; } @@ -243,7 +244,7 @@ void JsEnvironment::InitConsoleModule() bool JsEnvironment::InitLoop(bool isStage) { if (engine_ == nullptr) { - JSENV_LOG_E("Invalid Native Engine."); + TAG_LOGE(AAFwkTag::JSENV, "Invalid Native Engine."); return false; } @@ -256,7 +257,7 @@ bool JsEnvironment::InitLoop(bool isStage) void JsEnvironment::DeInitLoop() { if (engine_ == nullptr) { - JSENV_LOG_E("Invalid Native Engine."); + TAG_LOGE(AAFwkTag::JSENV, "Invalid Native Engine."); return; } @@ -268,7 +269,7 @@ void JsEnvironment::DeInitLoop() bool JsEnvironment::LoadScript(const std::string& path, uint8_t* buffer, size_t len, bool isBundle) { if (engine_ == nullptr) { - JSENV_LOG_E("Invalid Native Engine."); + TAG_LOGE(AAFwkTag::JSENV, "Invalid Native Engine."); return false; } @@ -279,14 +280,14 @@ void JsEnvironment::StartProfiler(const char* libraryPath, uint32_t instanceId, int32_t interval, int tid, bool isDebugApp) { if (vm_ == nullptr) { - JSENV_LOG_E("Invalid vm."); + TAG_LOGE(AAFwkTag::JSENV, "Invalid vm."); return; } auto debuggerPostTask = [weak = weak_from_this()](std::function&& task) { auto jsEnv = weak.lock(); if (jsEnv == nullptr) { - JSENV_LOG_E("JsEnv is invalid."); + TAG_LOGE(AAFwkTag::JSENV, "JsEnv is invalid."); return; } jsEnv->PostTask(task, "JsEnvironment::StartProfiler"); @@ -303,7 +304,7 @@ void JsEnvironment::StartProfiler(const char* libraryPath, uint32_t instanceId, void JsEnvironment::DestroyHeapProfiler() { if (vm_ == nullptr) { - JSENV_LOG_E("Invalid vm."); + TAG_LOGE(AAFwkTag::JSENV, "Invalid vm."); return; } panda::DFXJSNApi::DestroyHeapProfiler(vm_); @@ -312,7 +313,7 @@ void JsEnvironment::DestroyHeapProfiler() void JsEnvironment::GetHeapPrepare() { if (vm_ == nullptr) { - JSENV_LOG_E("Invalid vm."); + TAG_LOGE(AAFwkTag::JSENV, "Invalid vm."); return; } panda::DFXJSNApi::GetHeapPrepare(vm_); @@ -320,14 +321,14 @@ void JsEnvironment::GetHeapPrepare() void JsEnvironment::ReInitJsEnvImpl(std::unique_ptr impl) { - JSENV_LOG_D("ReInit jsenv impl."); + TAG_LOGD(AAFwkTag::JSENV, "ReInit jsenv impl."); impl_ = std::move(impl); } void JsEnvironment::SetModuleLoadChecker(const std::shared_ptr& moduleCheckerDelegate) { if (engine_ == nullptr) { - JSENV_LOG_E("Invalid native engine."); + TAG_LOGE(AAFwkTag::JSENV, "Invalid native engine."); return; } @@ -337,7 +338,7 @@ void JsEnvironment::SetModuleLoadChecker(const std::shared_ptr&& task) { auto jsEnv = weak.lock(); if (jsEnv == nullptr) { - JSENV_LOG_E("JsEnv is invalid."); + TAG_LOGE(AAFwkTag::JSENV, "JsEnv is invalid."); return; } jsEnv->PostTask(task, "JsEnvironment:GetDebuggerPostTask"); @@ -366,14 +367,14 @@ void JsEnvironment::NotifyDebugMode( int tid, const char* libraryPath, uint32_t instanceId, bool debug, bool debugMode) { if (vm_ == nullptr) { - JSENV_LOG_E("Invalid vm."); + TAG_LOGE(AAFwkTag::JSENV, "Invalid vm."); return; } panda::JSNApi::DebugOption debugOption = {libraryPath, debug ? debugMode : false}; auto debuggerPostTask = [weak = weak_from_this()](std::function&& task) { auto jsEnv = weak.lock(); if (jsEnv == nullptr) { - JSENV_LOG_E("JsEnv is invalid."); + TAG_LOGE(AAFwkTag::JSENV, "JsEnv is invalid."); return; } jsEnv->PostTask(task, "JsEnvironment:NotifyDebugMode"); @@ -383,7 +384,7 @@ void JsEnvironment::NotifyDebugMode( int32_t JsEnvironment::ParseHdcRegisterOption(std::string& option) { - JSENV_LOG_D("Start."); + TAG_LOGD(AAFwkTag::JSENV, "Start."); std::size_t pos = option.find_first_of(":"); if (pos == std::string::npos) { return -1; diff --git a/js_environment/frameworks/js_environment/src/source_map.cpp b/js_environment/frameworks/js_environment/src/source_map.cpp index f54c0eb271..fdfda2b87a 100644 --- a/js_environment/frameworks/js_environment/src/source_map.cpp +++ b/js_environment/frameworks/js_environment/src/source_map.cpp @@ -23,7 +23,8 @@ #include #include -#include "js_env_logger.h" +#include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" namespace OHOS { namespace JsEnv { @@ -146,7 +147,7 @@ std::string SourceMap::TranslateBySourceMap(const std::string& stackStr) std::string column; GetPosInfo(temp, closeBracePos, line, column); if (line.empty() || column.empty()) { - JSENV_LOG_W("the stack without line info"); + TAG_LOGW(AAFwkTag::JSENV, "the stack without line info"); break; } std::string sourceInfo; @@ -162,7 +163,7 @@ std::string SourceMap::TranslateBySourceMap(const std::string& stackStr) std::string url = key + ".js.map"; std::string curSourceMap; if (!ReadSourceMapData(hapPath_, url, curSourceMap)) { - JSENV_LOG_W("ReadSourceMapData fail"); + TAG_LOGW(AAFwkTag::JSENV, "ReadSourceMapData fail"); continue; } ExtractSourceMapData(curSourceMap, nonModularMap_); @@ -265,11 +266,11 @@ void SourceMap::ExtractSourceMapData(const std::string& sourceMapData, std::shar std::vector ans; if (!VlqRevCode(mapping, ans)) { - JSENV_LOG_E("decode code fail"); + TAG_LOGE(AAFwkTag::JSENV, "decode code fail"); return; } if (ans.empty()) { - JSENV_LOG_E("decode sourcemap fail, mapping: %{public}s", mapping.c_str()); + TAG_LOGE(AAFwkTag::JSENV, "decode sourcemap fail, mapping: %{public}s", mapping.c_str()); break; } if (ans.size() == 1) { @@ -525,7 +526,7 @@ bool SourceMap::TranslateUrlPositionBySourceMap(std::string& url, int& line, int if (iter != sourceMaps_.end()) { return GetLineAndColumnNumbers(line, column, *(iter->second), url); } - JSENV_LOG_E("TranslateUrlPositionBySourceMap: stageMode sourceMaps find fail"); + TAG_LOGE(AAFwkTag::JSENV, "TranslateUrlPositionBySourceMap: stageMode sourceMaps find fail"); return false; } return false; diff --git a/js_environment/frameworks/js_environment/src/uncaught_exception_callback.cpp b/js_environment/frameworks/js_environment/src/uncaught_exception_callback.cpp index beff8d74d0..aa881d7678 100644 --- a/js_environment/frameworks/js_environment/src/uncaught_exception_callback.cpp +++ b/js_environment/frameworks/js_environment/src/uncaught_exception_callback.cpp @@ -17,7 +17,8 @@ #include #include -#include "js_env_logger.h" +#include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" #include "native_engine/native_engine.h" #ifdef SUPPORT_GRAPHICS #include "ui_content.h" @@ -32,7 +33,7 @@ constexpr char BACKTRACE[] = "=====================Backtrace==================== std::string NapiUncaughtExceptionCallback::GetNativeStrFromJsTaggedObj(napi_value obj, const char* key) { if (obj == nullptr) { - JSENV_LOG_E("Failed to get value from key."); + TAG_LOGE(AAFwkTag::JSENV, "Failed to get value from key."); return ""; } @@ -41,7 +42,7 @@ std::string NapiUncaughtExceptionCallback::GetNativeStrFromJsTaggedObj(napi_valu napi_valuetype valueType = napi_undefined; napi_typeof(env_, valueStr, &valueType); if (valueType != napi_string) { - JSENV_LOG_E("Failed to convert value from key."); + TAG_LOGE(AAFwkTag::JSENV, "Failed to convert value from key."); return ""; } @@ -51,7 +52,7 @@ std::string NapiUncaughtExceptionCallback::GetNativeStrFromJsTaggedObj(napi_valu size_t valueStrLength = 0; napi_get_value_string_utf8(env_, valueStr, valueCStr.get(), valueStrBufLength + 1, &valueStrLength); std::string ret(valueCStr.get(), valueStrLength); - JSENV_LOG_D("GetNativeStrFromJsTaggedObj Success."); + TAG_LOGD(AAFwkTag::JSENV, "GetNativeStrFromJsTaggedObj Success."); return ret; } @@ -75,7 +76,7 @@ void NapiUncaughtExceptionCallback::operator()(napi_value obj) summary += "Error code:" + errorCode + "\n"; } if (errorStack.empty()) { - JSENV_LOG_E("errorStack is empty"); + TAG_LOGE(AAFwkTag::JSENV, "errorStack is empty"); return; } auto errorPos = SourceMap::GetErrorPos(topStack); diff --git a/js_environment/interfaces/inner_api/source_map_operator.h b/js_environment/interfaces/inner_api/source_map_operator.h index f39bd4c6c6..62de80d9ea 100644 --- a/js_environment/interfaces/inner_api/source_map_operator.h +++ b/js_environment/interfaces/inner_api/source_map_operator.h @@ -20,7 +20,6 @@ #include #include "ffrt.h" -#include "js_env_logger.h" #include "source_map.h" namespace OHOS { @@ -59,7 +58,6 @@ public: std::string TranslateBySourceMap(const std::string& stackStr) { if (sourceMapObj_ == nullptr) { - JSENV_LOG_E("sourceMapObj_ is nullptr"); return ""; } if (isDebugVersion_) { @@ -72,7 +70,6 @@ public: bool TranslateUrlPositionBySourceMap(std::string& url, int& line, int& column) { if (sourceMapObj_ == nullptr) { - JSENV_LOG_E("sourceMapObj_ is nullptr"); return false; } return sourceMapObj_->TranslateUrlPositionBySourceMap(url, line, column); diff --git a/js_environment/test/unittest/js_environment_test/js_environment_test.cpp b/js_environment/test/unittest/js_environment_test/js_environment_test.cpp index ce7445f884..5cc45ded61 100644 --- a/js_environment/test/unittest/js_environment_test/js_environment_test.cpp +++ b/js_environment/test/unittest/js_environment_test/js_environment_test.cpp @@ -22,7 +22,6 @@ #include "ecmascript/napi/include/jsnapi.h" #include "hilog_wrapper.h" -#include "js_env_logger.h" #include "ohos_js_env_logger.h" #include "ohos_js_environment_impl.h" @@ -97,9 +96,6 @@ HWTEST_F(JsEnvironmentTest, JsEnvInitialize_0100, TestSize.Level0) */ HWTEST_F(JsEnvironmentTest, JsEnvInitialize_0200, TestSize.Level0) { - JSENV_LOG_I("Running in multi-thread, using default thread number."); - - JSENV_LOG_I("Running in thread %{public}" PRIu64 "", gettid()); auto jsEnv = std::make_shared(std::make_unique()); ASSERT_NE(jsEnv, nullptr); @@ -384,7 +380,6 @@ HWTEST_F(JsEnvironmentTest, PostSyncTask_0100, TestSize.Level0) std::string taskName = "syncTask001"; bool taskExecuted = false; auto task = [taskName, &taskExecuted]() { - JSENV_LOG_I("%{public}s called.", taskName.c_str()); taskExecuted = true; }; jsEnv->PostSyncTask(task, taskName); @@ -403,7 +398,6 @@ HWTEST_F(JsEnvironmentTest, SetRequestAotCallback_0100, TestSize.Level0) ASSERT_NE(jsEnv, nullptr); auto callback = [](const std::string& bundleName, const std::string& moduleName, int32_t triggerMode) -> int32_t { - JSENV_LOG_I("set request aot callback."); return 0; }; jsEnv->SetRequestAotCallback(callback); From 67acd4d00e902eb3e9c78ea22e1bdaa7ca940ca7 Mon Sep 17 00:00:00 2001 From: mashaohua7 Date: Fri, 31 May 2024 19:40:00 +0800 Subject: [PATCH 33/69] =?UTF-8?q?autostartup=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mashaohua7 --- .../abilitymgr/src/ability_auto_startup_data_manager.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp index 536aac8f88..5d82797912 100644 --- a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp +++ b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp @@ -462,6 +462,12 @@ bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const } } + if (jsonObject.contains(JSON_KEY_APP_CLONE_INDEX) && jsonObject[JSON_KEY_APP_CLONE_INDEX].is_string()) { + if (info.appCloneIndex != jsonObject.at(JSON_KEY_APP_CLONE_INDEX).get()) { + return false; + } + } + return true; } From 80c91634d7e3a349f563d0876b89d9e41cbc3e65 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 1 Jun 2024 11:31:13 +0800 Subject: [PATCH 34/69] fix GetCallingPid Signed-off-by: unknown --- services/abilitymgr/src/restart_app_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/src/restart_app_manager.cpp b/services/abilitymgr/src/restart_app_manager.cpp index 289b4f6fa3..c64bb13605 100644 --- a/services/abilitymgr/src/restart_app_manager.cpp +++ b/services/abilitymgr/src/restart_app_manager.cpp @@ -52,7 +52,7 @@ void RestartAppManager::AddRestartAppHistory(const RestartAppKeyType &key, time_ bool RestartAppManager::IsForegroundToRestartApp() const { TAG_LOGD(AAFwkTag::ABILITYMGR, "IsForegroundToRestartApp, called."); - auto callerPid = IPCSkeleton::GetCallingRealPid(); + auto callerPid = IPCSkeleton::GetCallingPid(); AppExecFwk::RunningProcessInfo processInfo; DelayedSingleton::GetInstance()->GetRunningProcessInfoByPid(callerPid, processInfo); if (processInfo.state_ == AppProcessState::APP_STATE_FOREGROUND || processInfo.isFocused || From 1e95a23065e7dc7464ed5461c02cd4ba1fcffd02 Mon Sep 17 00:00:00 2001 From: liutuantuan Date: Sat, 1 Jun 2024 14:04:07 +0800 Subject: [PATCH 35/69] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=9C=A8taskpool?= =?UTF-8?q?=E4=B8=AD=E8=B0=83=E7=94=A8canIUse=E9=9C=80=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liutuantuan --- frameworks/native/runtime/js_worker.cpp | 2 ++ interfaces/inner_api/runtime/BUILD.gn | 1 + 2 files changed, 3 insertions(+) diff --git a/frameworks/native/runtime/js_worker.cpp b/frameworks/native/runtime/js_worker.cpp index 709be4dc30..e3fc12ab75 100644 --- a/frameworks/native/runtime/js_worker.cpp +++ b/frameworks/native/runtime/js_worker.cpp @@ -43,6 +43,7 @@ #include "js_runtime_utils.h" #include "native_engine/impl/ark/ark_native_engine.h" #include "commonlibrary/ets_utils/js_sys_module/console/console.h" +#include "syscap_ts.h" #ifdef SUPPORT_SCREEN using OHOS::Ace::ContainerScope; #endif @@ -88,6 +89,7 @@ void InitWorkerFunc(NativeEngine* nativeEngine) } OHOS::JsSysModule::Console::InitConsoleModule(reinterpret_cast(nativeEngine)); + InitSyscapModule(reinterpret_cast(nativeEngine), globalObj); #ifdef SUPPORT_SCREEN OHOS::Ace::DeclarativeModulePreloader::PreloadWorker(*nativeEngine); #endif diff --git a/interfaces/inner_api/runtime/BUILD.gn b/interfaces/inner_api/runtime/BUILD.gn index 0e7aa46c6c..58fdcebe4e 100644 --- a/interfaces/inner_api/runtime/BUILD.gn +++ b/interfaces/inner_api/runtime/BUILD.gn @@ -116,6 +116,7 @@ ohos_shared_library("runtime") { "resource_management:global_resmgr", "samgr:samgr_proxy", "zlib:shared_libz", + "init:syscap_ts", ] if (cj_frontend) { From 859892ef19d4906ebac79ffe89e6737a9462673d Mon Sep 17 00:00:00 2001 From: huzeshan Date: Sat, 1 Jun 2024 14:52:50 +0800 Subject: [PATCH 36/69] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=86=BB=E7=BB=93?= =?UTF-8?q?=E8=BF=87=E6=97=A9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huzeshan --- frameworks/native/appkit/app/main_thread.cpp | 47 +++++++++++++++++++ .../include/appmgr/app_scheduler_host.h | 1 + .../include/appmgr/app_scheduler_interface.h | 3 ++ .../include/appmgr/app_scheduler_proxy.h | 2 + .../src/appmgr/app_scheduler_host.cpp | 9 ++++ .../src/appmgr/app_scheduler_proxy.cpp | 15 ++++++ .../kits/native/appkit/app/main_thread.h | 3 ++ services/appmgr/include/app_lifecycle_deal.h | 8 ++++ .../include/app_mgr_service_event_handler.h | 1 + services/appmgr/include/app_running_record.h | 3 ++ services/appmgr/src/app_lifecycle_deal.cpp | 11 +++++ services/appmgr/src/app_running_manager.cpp | 11 +++-- services/appmgr/src/app_running_record.cpp | 18 +++++++ services/appmgr/src/cache_process_manager.cpp | 21 +++++++-- .../include/mock_app_scheduler.h | 1 + .../include/mock_application.h | 1 + ...ams_ability_running_record_module_test.cpp | 3 ++ .../ams_app_mgr_service_module_test.cpp | 3 ++ 18 files changed, 154 insertions(+), 7 deletions(-) diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index ca69e82f66..cc23fc92c5 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -3331,5 +3331,52 @@ int32_t MainThread::ScheduleDumpFfrt(std::string& result) TAG_LOGD(AAFwkTag::APPKIT, "MainThread::ScheduleDumpFfrt::pid:%{public}d", getprocpid()); return DumpFfrtHelper::DumpFfrt(result); } + +/** + * + * @brief Notify application to prepare for process caching. + * + */ +void MainThread::ScheduleCacheProcess() +{ + TAG_LOGD(AAFwkTag::APPKIT, "ScheduleCacheProcess"); + wptr weak = this; + auto task = [weak]() { + auto appThread = weak.promote(); + if (appThread == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "appThread is nullptr"); + return; + } + appThread->HandleCacheProcess(); + }; + if (mainHandler_ == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "handler nullptr"); + return; + } + if (!mainHandler_->PostTask(task, "MainThread:ScheduleCacheProcess")) { + TAG_LOGE(AAFwkTag::APPKIT, "PostTask task failed"); + } +} + +/** + * + * @brief Notify application to prepare for process caching. + * + */ +void MainThread::HandleCacheProcess() +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::APPKIT, "start."); + + // force gc + if (application_ != nullptr) { + auto &runtime = application_->GetRuntime(); + if (runtime == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "runtime nullptr"); + return; + } + runtime->ForceFullGC(); + } +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_host.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_host.h index d0722996dc..20c31270a7 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_host.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_host.h @@ -64,6 +64,7 @@ private: int32_t HandleScheduleDumpIpcStop(MessageParcel &data, MessageParcel &reply); int32_t HandleScheduleDumpIpcStat(MessageParcel &data, MessageParcel &reply); int32_t HandleScheduleDumpFfrt(MessageParcel &data, MessageParcel &reply); + int32_t HandleScheduleCacheProcess(MessageParcel &data, MessageParcel &reply); using AppSchedulerFunc = int32_t (AppSchedulerHost::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h index 2b04eb7678..6e1a14f17b 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h @@ -272,6 +272,8 @@ public: */ virtual int32_t ScheduleDumpFfrt(std::string& result) = 0; + virtual void ScheduleCacheProcess() = 0; + enum class Message { SCHEDULE_FOREGROUND_APPLICATION_TRANSACTION = 0, SCHEDULE_BACKGROUND_APPLICATION_TRANSACTION, @@ -302,6 +304,7 @@ public: SCHEDULE_DUMP_IPC_STOP, SCHEDULE_DUMP_IPC_STAT, SCHEDULE_DUMP_FFRT, + SCHEDULE_CACHE_PROCESS, }; }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h index 72197fc710..f0e6ded048 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h @@ -232,6 +232,8 @@ public: */ virtual int32_t ScheduleDumpFfrt(std::string& result) override; + virtual void ScheduleCacheProcess() override; + private: bool WriteInterfaceToken(MessageParcel &data); void ScheduleMemoryCommon(const int32_t level, const uint32_t operation); diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp index 84aa6e86f6..c170248f12 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp @@ -88,6 +88,8 @@ void AppSchedulerHost::InitMemberFuncMap() &AppSchedulerHost::HandleScheduleDumpIpcStat; memberFuncMap_[static_cast(IAppScheduler::Message::SCHEDULE_DUMP_FFRT)] = &AppSchedulerHost::HandleScheduleDumpFfrt; + memberFuncMap_[static_cast(IAppScheduler::Message::SCHEDULE_CACHE_PROCESS)] = + &AppSchedulerHost::HandleScheduleCacheProcess; } AppSchedulerHost::~AppSchedulerHost() @@ -447,5 +449,12 @@ int32_t AppSchedulerHost::HandleScheduleDumpFfrt(MessageParcel &data, MessagePar } return NO_ERROR; } + +int32_t AppSchedulerHost::HandleScheduleCacheProcess(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER(HITRACE_TAG_APP); + ScheduleCacheProcess(); + return NO_ERROR; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp index 6172932d56..90aceeb73d 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp @@ -751,5 +751,20 @@ int32_t AppSchedulerProxy::SendTransactCmd(uint32_t code, MessageParcel &data, } return ret; } + +void AppSchedulerProxy::ScheduleCacheProcess() +{ + uint32_t operation = static_cast(IAppScheduler::Message::SCHEDULE_CACHE_PROCESS); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!WriteInterfaceToken(data)) { + return; + } + int32_t ret = SendTransactCmd(operation, data, reply, option); + if (ret != NO_ERROR) { + TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); + } +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/kits/native/appkit/app/main_thread.h b/interfaces/kits/native/appkit/app/main_thread.h index c9f4af898f..a508d1f6cd 100644 --- a/interfaces/kits/native/appkit/app/main_thread.h +++ b/interfaces/kits/native/appkit/app/main_thread.h @@ -345,6 +345,7 @@ public: */ int32_t ScheduleDumpFfrt(std::string& result) override; + void ScheduleCacheProcess() override; private: /** * @@ -606,6 +607,8 @@ private: int32_t ChangeAppGcState(int32_t state); + void HandleCacheProcess(); + class MainHandler : public EventHandler { public: MainHandler(const std::shared_ptr &runner, const sptr &thread); diff --git a/services/appmgr/include/app_lifecycle_deal.h b/services/appmgr/include/app_lifecycle_deal.h index 7dac5b7c64..af6028daf0 100644 --- a/services/appmgr/include/app_lifecycle_deal.h +++ b/services/appmgr/include/app_lifecycle_deal.h @@ -225,6 +225,14 @@ public: int DumpFfrt(std::string& result); + /** + * Notifies the application of process caching. + * + * + * @return + */ + void ScheduleCacheProcess(); + private: mutable std::mutex schedulerMutex_; sptr appThread_ = nullptr; diff --git a/services/appmgr/include/app_mgr_service_event_handler.h b/services/appmgr/include/app_mgr_service_event_handler.h index e2ee21ae3b..87033d4781 100644 --- a/services/appmgr/include/app_mgr_service_event_handler.h +++ b/services/appmgr/include/app_mgr_service_event_handler.h @@ -57,6 +57,7 @@ public: static constexpr uint32_t KILL_PROCESS_TIMEOUT = 3000; // ms #endif static constexpr uint32_t DELAY_KILL_PROCESS_TIMEOUT = 3000; // ms + static constexpr uint32_t DELAY_NOTIFY_PROCESS_CACHED_STATE = 2000; // ms private: std::weak_ptr appMgr_; }; diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 7061bceedd..8f229052bc 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -628,6 +628,7 @@ public: using Closure = std::function; void PostTask(std::string msg, int64_t timeOut, const Closure &task); + bool CancelTask(std::string msg); void RemoveTerminateAbilityTimeoutTask(const sptr& token) const; int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback, @@ -790,6 +791,8 @@ public: bool GetIsGPU(); void SetGPUPid(pid_t gpuPid); pid_t GetGPUPid(); + + void ScheduleCacheProcess(); private: /** * SearchTheModuleInfoNeedToUpdated, Get an uninitialized abilityStage data. diff --git a/services/appmgr/src/app_lifecycle_deal.cpp b/services/appmgr/src/app_lifecycle_deal.cpp index 7387db0b90..a0c288a5b0 100644 --- a/services/appmgr/src/app_lifecycle_deal.cpp +++ b/services/appmgr/src/app_lifecycle_deal.cpp @@ -383,5 +383,16 @@ int AppLifeCycleDeal::DumpFfrt(std::string& result) } return appThread->ScheduleDumpFfrt(result); } + +void AppLifeCycleDeal::ScheduleCacheProcess() +{ + auto appThread = GetApplicationClient(); + if (!appThread) { + TAG_LOGE(AAFwkTag::APPMGR, "appThread is nullptr"); + return; + } + + appThread->ScheduleCacheProcess(); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index cd715c9d8e..6084955af8 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -1503,10 +1503,13 @@ bool AppRunningManager::IsAppProcessesAllCached(const std::string &bundleName, i if (itemRecord == nullptr) { continue; } - if (itemRecord->GetBundleName() == bundleName && itemRecord->GetUid() == uid && - cachedSet.find(itemRecord) == cachedSet.end() && - DelayedSingleton::GetInstance()->IsAppSupportProcessCache(itemRecord)) { - return false; + if (itemRecord->GetBundleName() == bundleName && itemRecord->GetUid() == uid) { + auto supportCache = + DelayedSingleton::GetInstance()->IsAppSupportProcessCache(itemRecord); + // need wait for unsupported processes + if ((cachedSet.find(itemRecord) == cachedSet.end() && supportCache) || !supportCache) { + return false; + } } } return true; diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index be75de823d..2d0fca5110 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -2279,5 +2279,23 @@ pid_t AppRunningRecord::GetGPUPid() { return gpuPid_; } + +void AppRunningRecord::ScheduleCacheProcess() +{ + if (appLifeCycleDeal_ == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "appLifeCycleDeal_ is null"); + return; + } + appLifeCycleDeal_->ScheduleCacheProcess(); +} + +bool AppRunningRecord::CancelTask(std::string msg) +{ + if (!taskHandler_) { + TAG_LOGE(AAFwkTag::APPMGR, "taskHandler_ is nullptr"); + return false; + } + return taskHandler_->CancelTask(msg); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/cache_process_manager.cpp b/services/appmgr/src/cache_process_manager.cpp index da10338e5f..44265b2253 100644 --- a/services/appmgr/src/cache_process_manager.cpp +++ b/services/appmgr/src/cache_process_manager.cpp @@ -25,6 +25,7 @@ namespace { const std::string MAX_PROC_CACHE_NUM = "persist.sys.abilityms.maxProcessCacheNum"; const std::string PROCESS_CACHE_API_CHECK_CONFIG = "persist.sys.abilityms.processCacheApiCheck"; +const std::string SHELL_ASSISTANT_BUNDLENAME = "com.huawei.shell_assistant"; constexpr int32_t API12 = 12; constexpr int32_t API_VERSION_MOD = 100; } @@ -105,9 +106,16 @@ bool CacheProcessManager::CheckAndCacheProcess(const std::shared_ptrGetName().c_str()); return true; } - TAG_LOGI(AAFwkTag::APPMGR, "%{public}s is cached, %{public}s", appRecord->GetName().c_str(), - PrintCacheQueue().c_str()); - CheckAndNotifyCachedState(appRecord); + appRecord->ScheduleCacheProcess(); + auto notifyCached = [appRecord]() { + DelayedSingleton::GetInstance()->CheckAndNotifyCachedState(appRecord); + }; + std::string taskName = "DELAY_CACHED_STATE_NOTIFY"; + auto res = appRecord->CancelTask(taskName); + if (res) { + TAG_LOGD(AAFwkTag::APPMGR, "Early delay task canceled."); + } + appRecord->PostTask(taskName, AMSEventHandler::DELAY_NOTIFY_PROCESS_CACHED_STATE, notifyCached); return true; } @@ -234,6 +242,13 @@ bool CacheProcessManager::IsAppSupportProcessCache(const std::shared_ptrGetParentAppRecord() != nullptr) { + TAG_LOGD(AAFwkTag::APPMGR, "Child App, not support."); + return false; + } + if (appRecord->GetBundleName() == SHELL_ASSISTANT_BUNDLENAME) { + return false; + } auto supportState = appRecord->GetSupportProcessCacheState(); switch (supportState) { case SupportProcessCacheState::UNSPECIFIED: diff --git a/test/mock/services_appmgr_test/include/mock_app_scheduler.h b/test/mock/services_appmgr_test/include/mock_app_scheduler.h index 8de91fa1c6..5b0490a39e 100644 --- a/test/mock/services_appmgr_test/include/mock_app_scheduler.h +++ b/test/mock/services_appmgr_test/include/mock_app_scheduler.h @@ -67,6 +67,7 @@ public: MOCK_METHOD1(ScheduleDumpIpcStat, int32_t(std::string &result)); MOCK_METHOD0(IsMemorySizeSufficent, bool()); MOCK_METHOD1(ScheduleDumpFfrt, int32_t(std::string& result)); + MOCK_METHOD0(ScheduleCacheProcess, void()); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/test/mock/services_appmgr_test/include/mock_application.h b/test/mock/services_appmgr_test/include/mock_application.h index 5eea0d49de..fdf9c1632b 100644 --- a/test/mock/services_appmgr_test/include/mock_application.h +++ b/test/mock/services_appmgr_test/include/mock_application.h @@ -61,6 +61,7 @@ public: MOCK_METHOD1(ScheduleDumpIpcStat, int32_t(std::string &result)); MOCK_METHOD0(IsMemorySizeSufficent, bool()); MOCK_METHOD1(ScheduleDumpFfrt, int32_t(std::string& result)); + MOCK_METHOD0(ScheduleCacheProcess, void()); void Post() { diff --git a/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp b/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp index 6927f34b61..b8634b58b6 100644 --- a/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp +++ b/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp @@ -209,6 +209,9 @@ public: return 0; } + void ScheduleCacheProcess() override + {} + private: int abilityLaunchTime = 0; int appLaunchTime = 0; diff --git a/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp b/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp index 531cc927c6..843bdd77d0 100644 --- a/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp +++ b/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp @@ -128,6 +128,9 @@ public: { return 0; } + + void ScheduleCacheProcess() override + {} }; class AppMgrServiceModuleTest : public testing::Test { public: From a4c160f9df306278929d9c0bd44e03a38ecb3ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E5=97=A3=E9=92=8A?= Date: Sat, 1 Jun 2024 15:46:11 +0800 Subject: [PATCH 37/69] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E6=9D=80=E6=AD=BB=E6=97=B6=E9=97=B42?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 段嗣钊 Change-Id: Ieba19174cc8c380a7b92038be190b3dfba39f171 --- .../include/app_mgr_service_event_handler.h | 1 + services/appmgr/include/app_running_record.h | 2 ++ .../appmgr/include/module_running_record.h | 2 ++ services/appmgr/src/app_running_manager.cpp | 4 +++- services/appmgr/src/app_running_record.cpp | 20 ++++++++++++++++++- services/appmgr/src/module_running_record.cpp | 15 +++++++++++++- 6 files changed, 41 insertions(+), 3 deletions(-) diff --git a/services/appmgr/include/app_mgr_service_event_handler.h b/services/appmgr/include/app_mgr_service_event_handler.h index 87033d4781..ed4addb011 100644 --- a/services/appmgr/include/app_mgr_service_event_handler.h +++ b/services/appmgr/include/app_mgr_service_event_handler.h @@ -57,6 +57,7 @@ public: static constexpr uint32_t KILL_PROCESS_TIMEOUT = 3000; // ms #endif static constexpr uint32_t DELAY_KILL_PROCESS_TIMEOUT = 3000; // ms + static constexpr uint32_t DELAY_KILL_EXTENSION_PROCESS_TIMEOUT = 500; // ms static constexpr uint32_t DELAY_NOTIFY_PROCESS_CACHED_STATE = 2000; // ms private: std::weak_ptr appMgr_; diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 8f229052bc..8be9369109 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -534,6 +534,8 @@ public: bool IsLastPageAbilityRecord(const sptr &token); + bool ExtensionAbilityRecordExists(const sptr &token); + void SetTerminating(); bool IsTerminating(); diff --git a/services/appmgr/include/module_running_record.h b/services/appmgr/include/module_running_record.h index 2d074e13a7..6f13c24c78 100644 --- a/services/appmgr/include/module_running_record.h +++ b/services/appmgr/include/module_running_record.h @@ -81,6 +81,8 @@ public: int32_t GetPageAbilitySize(); + bool ExtensionAbilityRecordExists(); + // Get abilities_ for this process /** * @brief Obtains the abilities info for the application record. diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index 6084955af8..ee745f6484 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -569,7 +569,9 @@ void AppRunningManager::TerminateAbility(const sptr &token, bool TAG_LOGD(AAFwkTag::APPMGR, "The ability is the last in the app:%{public}s.", appRecord->GetName().c_str()); appRecord->SetTerminating(); if (clearMissionFlag && appMgrServiceInner != nullptr) { - appRecord->PostTask("DELAY_KILL_PROCESS", AMSEventHandler::DELAY_KILL_PROCESS_TIMEOUT, killProcess); + auto delayTime = appRecord->ExtensionAbilityRecordExists(token) ? + AMSEventHandler::DELAY_KILL_EXTENSION_PROCESS_TIMEOUT : AMSEventHandler::DELAY_KILL_PROCESS_TIMEOUT; + appRecord->PostTask("DELAY_KILL_PROCESS", delayTime, killProcess); } } } diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 2d0fca5110..5fb14569a6 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -1344,6 +1344,22 @@ bool AppRunningRecord::IsLastAbilityRecord(const sptr &token) return false; } +bool AppRunningRecord::ExtensionAbilityRecordExists(const sptr &token) +{ + auto moduleRecord = GetModuleRunningRecordByToken(token); + if (!moduleRecord) { + TAG_LOGE(AAFwkTag::APPMGR, "can not find module record"); + return false; + } + auto moduleRecordList = GetAllModuleRecord(); + for (auto moduleRecord : moduleRecordList) { + if (moduleRecord && moduleRecord->ExtensionAbilityRecordExists()) { + return true; + } + } + return false; +} + bool AppRunningRecord::IsLastPageAbilityRecord(const sptr &token) { auto moduleRecord = GetModuleRunningRecordByToken(token); @@ -1355,7 +1371,9 @@ bool AppRunningRecord::IsLastPageAbilityRecord(const sptr &token) int32_t pageAbilitySize = 0; auto moduleRecordList = GetAllModuleRecord(); for (auto moduleRecord : moduleRecordList) { - pageAbilitySize += moduleRecord->GetPageAbilitySize() ; + if (moduleRecord) { + pageAbilitySize += moduleRecord->GetPageAbilitySize(); + } if (pageAbilitySize > 1) { return false; } diff --git a/services/appmgr/src/module_running_record.cpp b/services/appmgr/src/module_running_record.cpp index face85c1ee..8e5c76f7a0 100644 --- a/services/appmgr/src/module_running_record.cpp +++ b/services/appmgr/src/module_running_record.cpp @@ -109,7 +109,7 @@ int32_t ModuleRunningRecord::GetPageAbilitySize() for (auto it : abilities_) { std::shared_ptr abilityRunningRecord = it.second; std::shared_ptr abilityInfo = abilityRunningRecord->GetAbilityInfo(); - if (abilityInfo->type == AbilityType::PAGE) { + if (abilityInfo && abilityInfo->type == AbilityType::PAGE) { pageAbilitySize++; } } @@ -117,6 +117,19 @@ int32_t ModuleRunningRecord::GetPageAbilitySize() return pageAbilitySize; } +bool ModuleRunningRecord::ExtensionAbilityRecordExists() +{ + std::lock_guard lock(abilitiesMutex_); + for (auto it : abilities_) { + std::shared_ptr abilityRunningRecord = it.second; + std::shared_ptr abilityInfo = abilityRunningRecord->GetAbilityInfo(); + if (abilityInfo && abilityInfo->type != AbilityType::PAGE) { + return true; + } + } + return false; +} + const std::map, std::shared_ptr> ModuleRunningRecord::GetAbilities() const { From 47da9245e787a7e532aded206f066ef94f3c2eb5 Mon Sep 17 00:00:00 2001 From: yuwenze Date: Sat, 1 Jun 2024 17:04:30 +0800 Subject: [PATCH 38/69] fixed flag Signed-off-by: yuwenze Change-Id: I5126f0ac68289a15e7a5b948225cd2e449da3b05 --- services/appmgr/include/utils/appspawn_util.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/appmgr/include/utils/appspawn_util.h b/services/appmgr/include/utils/appspawn_util.h index 614b5f5b5b..259f945252 100644 --- a/services/appmgr/include/utils/appspawn_util.h +++ b/services/appmgr/include/utils/appspawn_util.h @@ -17,8 +17,8 @@ #define OHOS_ABILITY_RUNTIME_APPSPAWN_UTIL_H #include "ability_info.h" -#include "application_info.h" #include "app_spawn_client.h" +#include "global_constant.h" #include "want.h" namespace OHOS { @@ -58,7 +58,8 @@ static uint32_t BuildStartFlags(const AAFwk::Want &want, const ApplicationInfo & if (want.GetBoolParam("ohos.ability.params.extensionControl", false)) { startFlags = startFlags | (START_FLAG_BASE << StartFlags::EXTENSION_CONTROLLED); } - if (applicationInfo.multiAppMode.multiAppModeType == MultiAppModeType::APP_CLONE) { + if (applicationInfo.multiAppMode.multiAppModeType == MultiAppModeType::APP_CLONE && applicationInfo.appIndex > 0 && + applicationInfo.appIndex <= AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) { startFlags = startFlags | (START_FLAG_BASE << APP_FLAGS_CLONE_ENABLE); } From 7ec2a2882a1b2ebd72dee16006478dd3ac189038 Mon Sep 17 00:00:00 2001 From: yuwenze Date: Sun, 2 Jun 2024 15:26:44 +0800 Subject: [PATCH 39/69] fixed ut Signed-off-by: yuwenze Change-Id: Ia34578067f18ad276ddeb161960a2ff90d24f582 --- .../app_mgr_service_inner_test.cpp | 8 +++++--- .../app_mgr_service_test/app_mgr_service_test.cpp | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index 40b772c334..20ddd169dc 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -4065,6 +4065,7 @@ HWTEST_F(AppMgrServiceInnerTest, IsApplicationRunning_002, TestSize.Level1) */ HWTEST_F(AppMgrServiceInnerTest, IsAppRunning_001, TestSize.Level1) { + AAFwk::IsMockSaCall::IsMockSaCallWithPermission(); auto appMgrServiceInner = std::make_shared(); EXPECT_NE(appMgrServiceInner, nullptr); std::string bundleName = "com.is.hiserice"; @@ -4076,8 +4077,8 @@ HWTEST_F(AppMgrServiceInnerTest, IsAppRunning_001, TestSize.Level1) appRecord->mainBundleName_ = "com.is.hiserice"; appMgrServiceInner->appRunningManager_->appRunningRecordMap_.emplace(recordId_, appRecord); int32_t ret = appMgrServiceInner->IsAppRunning(bundleName, appCloneIndex, isRunning); - EXPECT_EQ(ret, ERR_OK); - EXPECT_TRUE(isRunning); + EXPECT_EQ(ret, AAFwk::ERR_APP_CLONE_INDEX_INVALID); + EXPECT_FALSE(isRunning); } /** @@ -4087,6 +4088,7 @@ HWTEST_F(AppMgrServiceInnerTest, IsAppRunning_001, TestSize.Level1) */ HWTEST_F(AppMgrServiceInnerTest, IsAppRunning_002, TestSize.Level1) { + AAFwk::IsMockSaCall::IsMockSaCallWithPermission(); auto appMgrServiceInner = std::make_shared(); EXPECT_NE(appMgrServiceInner, nullptr); std::string bundleName = "com.is.hiserice"; @@ -4097,7 +4099,7 @@ HWTEST_F(AppMgrServiceInnerTest, IsAppRunning_002, TestSize.Level1) EXPECT_NE(appRecord, nullptr); appMgrServiceInner->appRunningManager_->appRunningRecordMap_.emplace(recordId_, appRecord); int32_t ret = appMgrServiceInner->IsAppRunning(bundleName, appCloneIndex, isRunning); - EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(ret, AAFwk::ERR_APP_CLONE_INDEX_INVALID); EXPECT_FALSE(isRunning); } diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index 7da20843e6..40d668f7b0 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -1421,7 +1421,7 @@ HWTEST_F(AppMgrServiceTest, IsAppRunning_001, TestSize.Level1) int32_t appCloneIndex = 0; bool isRunning = false; int32_t res = appMgrService->IsAppRunning(bundleName, appCloneIndex, isRunning); - EXPECT_EQ(res, ERR_OK); + EXPECT_EQ(res, AAFwk::ERR_APP_CLONE_INDEX_INVALID); } /** From 9f9b6f7431f76bafe66a3599406d7b77658f3b52 Mon Sep 17 00:00:00 2001 From: zhu-bingwei123 Date: Fri, 31 May 2024 16:51:47 +0800 Subject: [PATCH 40/69] =?UTF-8?q?appmgrproxy=E7=A9=BA=E6=8C=87=E9=92=88?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhu-bingwei123 --- .../inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp index 6fd9ab0dd7..0cc641213b 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -256,6 +256,10 @@ int32_t AppMgrProxy::GetRunningMultiAppInfoByBundleName(const std::string &bundl return ret; } std::unique_ptr infoReply(reply.ReadParcelable()); + if (infoReply == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "reply ReadParcelable is nullptr"); + return ERR_NULL_OBJECT; + } info = *infoReply; int result = reply.ReadInt32(); return result; @@ -362,6 +366,10 @@ int32_t AppMgrProxy::GetProcessRunningInformation(RunningProcessInfo &info) return ERR_NULL_OBJECT; } std::unique_ptr infoReply(reply.ReadParcelable()); + if (infoReply == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "reply ReadParcelable is nullptr"); + return ERR_NULL_OBJECT; + } info = *infoReply; return reply.ReadInt32(); } From 4aba479ef2cd3caf1c4130f5c7e7ac0bd8696fa5 Mon Sep 17 00:00:00 2001 From: XKK Date: Sat, 1 Jun 2024 15:38:39 +0800 Subject: [PATCH 41/69] =?UTF-8?q?ohmrul=20=E5=8A=A0=E8=BD=BD=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XKK --- .../native/appkit/app/ohos_application.cpp | 4 ++++ frameworks/native/runtime/js_runtime.cpp | 18 ++++++++++++++++++ .../inner_api/runtime/include/cj_runtime.h | 1 + .../inner_api/runtime/include/js_runtime.h | 3 +++ interfaces/inner_api/runtime/include/runtime.h | 1 + .../mock_runtime.h | 2 ++ 6 files changed, 29 insertions(+) diff --git a/frameworks/native/appkit/app/ohos_application.cpp b/frameworks/native/appkit/app/ohos_application.cpp index 482e999eca..c008933695 100644 --- a/frameworks/native/appkit/app/ohos_application.cpp +++ b/frameworks/native/appkit/app/ohos_application.cpp @@ -679,6 +679,10 @@ std::shared_ptr OHOSApplication::AddAbilityStage( TAG_LOGE(AAFwkTag::APPKIT, "hapModuleInfo is nullptr"); return nullptr; } + if (runtime_) { + runtime_->UpdatePkgContextInfoJson( + hapModuleInfo->moduleName, hapModuleInfo->hapPath, hapModuleInfo->packageName); + } SetAppEnv(hapModuleInfo->appEnvironments); if (abilityInfo->applicationInfo.multiProjects) { diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index d11c3fb7fc..07920e3ae0 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -757,6 +757,8 @@ bool JsRuntime::Initialize(const Options& options) panda::JSNApi::SetHmsModuleList(vm, systemKitsMap); std::map>> pkgContextInfoMap; std::map pkgAliasMap; + pkgContextInfoJsonStringMap_ = options.pkgContextInfoJsonStringMap; + packageNameList_ = options.packageNameList; GetPkgContextInfoListMap(options.pkgContextInfoJsonStringMap, pkgContextInfoMap, pkgAliasMap); panda::JSNApi::SetpkgContextInfoList(vm, pkgContextInfoMap); panda::JSNApi::SetPkgAliasList(vm, pkgAliasMap); @@ -1695,5 +1697,21 @@ std::shared_ptr JsRuntime::GetChildOptions() TAG_LOGD(AAFwkTag::JSRUNTIME, "called"); return childOptions_; } + +void JsRuntime::UpdatePkgContextInfoJson(std::string moduleName, std::string hapPath, std::string packageName) +{ + auto iterator = pkgContextInfoJsonStringMap_.find(moduleName); + if (iterator == pkgContextInfoJsonStringMap_.end()) { + pkgContextInfoJsonStringMap_[moduleName] = hapPath; + packageNameList_[moduleName] = packageName; + auto vm = GetEcmaVm(); + std::map>> pkgContextInfoMap; + std::map pkgAliasMap; + GetPkgContextInfoListMap(pkgContextInfoJsonStringMap_, pkgContextInfoMap, pkgAliasMap); + panda::JSNApi::SetpkgContextInfoList(vm, pkgContextInfoMap); + panda::JSNApi::SetPkgAliasList(vm, pkgAliasMap); + panda::JSNApi::SetPkgNameList(vm, packageNameList_); + } +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/inner_api/runtime/include/cj_runtime.h b/interfaces/inner_api/runtime/include/cj_runtime.h index da662066aa..3c229c5c1c 100644 --- a/interfaces/inner_api/runtime/include/cj_runtime.h +++ b/interfaces/inner_api/runtime/include/cj_runtime.h @@ -66,6 +66,7 @@ public: void AllowCrossThreadExecution() override {}; void GetHeapPrepare() override {}; void RegisterUncaughtExceptionHandler(const CJUncaughtExceptionInfo& uncaughtExceptionInfo); + void UpdatePkgContextInfoJson(std::string moduleName, std::string hapPath, std::string packageName) override {}; private: bool StartDebugger(); bool LoadCJAppLibrary(const AppLibPathVec& appLibPaths); diff --git a/interfaces/inner_api/runtime/include/js_runtime.h b/interfaces/inner_api/runtime/include/js_runtime.h index 3b8d83d7d2..ae5769fc06 100644 --- a/interfaces/inner_api/runtime/include/js_runtime.h +++ b/interfaces/inner_api/runtime/include/js_runtime.h @@ -133,6 +133,7 @@ public: std::unique_ptr LoadSystemModule( const std::string& moduleName, const napi_value* argv = nullptr, size_t argc = 0); void SetDeviceDisconnectCallback(const std::function &cb) override; + void UpdatePkgContextInfoJson(std::string moduleName, std::string hapPath, std::string packageName) override; private: void FinishPreload() override; @@ -156,6 +157,8 @@ private: uint32_t instanceId_ = 0; std::string bundleName_; int32_t apiTargetVersion_ = 0; + std::map pkgContextInfoJsonStringMap_; + std::map packageNameList_; static std::atomic hasInstance; diff --git a/interfaces/inner_api/runtime/include/runtime.h b/interfaces/inner_api/runtime/include/runtime.h index 162605255e..baa3b6a7b3 100644 --- a/interfaces/inner_api/runtime/include/runtime.h +++ b/interfaces/inner_api/runtime/include/runtime.h @@ -106,6 +106,7 @@ public: virtual void DoCleanWorkAfterStageCleaned() = 0; virtual void SetModuleLoadChecker(const std::shared_ptr& moduleCheckerDelegate) const {} virtual void SetDeviceDisconnectCallback(const std::function &cb) = 0; + virtual void UpdatePkgContextInfoJson(std::string moduleName, std::string hapPath, std::string packageName) = 0; Runtime(const Runtime&) = delete; Runtime(Runtime&&) = delete; Runtime& operator=(const Runtime&) = delete; diff --git a/test/mock/frameworks_kits_runtime_test/mock_runtime.h b/test/mock/frameworks_kits_runtime_test/mock_runtime.h index ac5ce22596..a5066a21bf 100644 --- a/test/mock/frameworks_kits_runtime_test/mock_runtime.h +++ b/test/mock/frameworks_kits_runtime_test/mock_runtime.h @@ -121,6 +121,8 @@ public: void DumpHeapSnapshot(uint32_t tid, bool isFullGC, std::vector fdVec, std::vector tidVec) override {} void ForceFullGC(uint32_t tid) override {} + + void UpdatePkgContextInfoJson(std::string moduleName, std::string hapPath, std::string packageName) override {}; public: Language language; }; From a8010691f04aedd300440855000be9731c251c3b Mon Sep 17 00:00:00 2001 From: rentangyu Date: Mon, 3 Jun 2024 10:08:50 +0800 Subject: [PATCH 42/69] =?UTF-8?q?jscrash=20=E8=A1=8C=E5=88=97=E5=8F=B7?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit issues:https://gitee.com/openharmony/ability_ability_runtime/issues/I9TNEB Signed-off-by: rentangyu --- .../js_environment/src/source_map.cpp | 111 +++++++++--------- .../interfaces/inner_api/source_map.h | 4 +- 2 files changed, 60 insertions(+), 55 deletions(-) diff --git a/js_environment/frameworks/js_environment/src/source_map.cpp b/js_environment/frameworks/js_environment/src/source_map.cpp index fdfda2b87a..b3a66499e9 100644 --- a/js_environment/frameworks/js_environment/src/source_map.cpp +++ b/js_environment/frameworks/js_environment/src/source_map.cpp @@ -29,12 +29,6 @@ namespace OHOS { namespace JsEnv { namespace { -constexpr char SOURCES[] = "sources"; -constexpr char NAMES[] = "names"; -constexpr char MAPPINGS[] = "mappings"; -constexpr char FILE[] = "file"; -constexpr char SOURCE_CONTENT[] = "sourceContent"; -constexpr char SOURCE_ROOT[] = "sourceRoot"; constexpr char DELIMITER_COMMA = ','; constexpr char DELIMITER_SEMICOLON = ';'; constexpr char DOUBLE_SLASH = '\\'; @@ -49,6 +43,13 @@ constexpr int32_t NUM_TWENTY = 20; constexpr int32_t NUM_TWENTYSIX = 26; constexpr int32_t DIGIT_NUM = 64; const std::string MEGER_SOURCE_MAP_PATH = "ets/sourceMaps.map"; +const std::string FLAG_SOURCES = " \"sources\":"; +const std::string FLAG_MAPPINGS = " \"mappings\": \""; +const std::string FLAG_END = " }"; +static constexpr size_t FLAG_MAPPINGS_LEN = 17; +static constexpr size_t REAL_SOURCE_SIZE = 7; +static constexpr size_t REAL_URL_INDEX = 3; +static constexpr size_t REAL_SOURCE_INDEX = 7; } // namespace ReadSourceMapCallback SourceMap::readSourceMapFunc_ = nullptr; GetHapPathCallback SourceMap::getHapPathFunc_ = nullptr; @@ -87,6 +88,12 @@ uint32_t Base64CharToInt(char charCode) return DIGIT_NUM; }; +bool StringStartWith(const std::string& str, const std::string& startStr) +{ + size_t startStrLen = startStr.length(); + return ((str.length() >= startStrLen) && (str.compare(0, startStrLen, startStr) == 0)); +} + void SourceMap::Init(bool isModular, const std::string& hapPath) { isModular_ = isModular; @@ -192,23 +199,48 @@ void SourceMap::SplitSourceMap(const std::string& sourceMapData) return ExtractSourceMapData(sourceMapData, nonModularMap_); } - size_t leftBracket = 0; - size_t rightBracket = 0; - size_t urlLeft = 0; - size_t urlRight = 0; - while ((leftBracket = sourceMapData.find(": {", rightBracket)) != std::string::npos) { - urlLeft = leftBracket; - urlRight = sourceMapData.find(" \"", rightBracket) + INDEX_THREE; - if (urlRight == std::string::npos) { + std::stringstream ss(sourceMapData); + std::string tmp; + std::string url; + + std::getline(ss, tmp); + bool isUrl = true; + while (std::getline(ss, tmp)) { + if (isUrl && tmp.size() > REAL_SOURCE_SIZE) { + url = tmp.substr(REAL_URL_INDEX, tmp.size() - REAL_SOURCE_SIZE); + isUrl = false; continue; } - std::string key = sourceMapData.substr(urlRight, urlLeft - urlRight - INDEX_ONE); - rightBracket = sourceMapData.find("},", leftBracket); - std::string value = sourceMapData.substr(leftBracket, rightBracket); - std::shared_ptr modularMap = std::make_shared(); - ExtractSourceMapData(value, modularMap); - sourceMaps_[key] = modularMap; + if (StringStartWith(tmp.c_str(), FLAG_SOURCES)) { + std::getline(ss, tmp); + sources_.emplace(url, tmp); + continue; + } + if (StringStartWith(tmp.c_str(), FLAG_MAPPINGS)) { + mappings_.emplace(url, tmp); + continue; + } + if (StringStartWith(tmp.c_str(), FLAG_END)) { + isUrl = true; + } } + std::shared_ptr modularMap = std::make_shared(); + for (auto it = sources_.begin(); it != sources_.end(); ++it) { + std::string mappings = mappings_[it->first]; + if (mappings.size() < FLAG_MAPPINGS_LEN + 1) { + TAG_LOGE(AAFwkTag::JSENV, "Translate failed, url: %{public}s", it->first.c_str()); + continue; + } + ExtractSourceMapData(mappings.substr(FLAG_MAPPINGS_LEN, mappings.size() - FLAG_MAPPINGS_LEN - 1), modularMap); + if (modularMap == nullptr) { + TAG_LOGE(AAFwkTag::JSENV, "Extract mappings failed, url: %{public}s", it->first.c_str()); + continue; + } + modularMap->sources_.push_back(it->second); + sourceMaps_[it->first] = modularMap; + } + mappings_.clear(); + sources_.clear(); } void SourceMap::ExtractStackInfo(const std::string& stackStr, std::vector& res) @@ -220,37 +252,9 @@ void SourceMap::ExtractStackInfo(const std::string& stackStr, std::vector& curMapData) +void SourceMap::ExtractSourceMapData(const std::string& allmappings, std::shared_ptr& curMapData) { - std::vector sourceKey; - ExtractKeyInfo(sourceMapData, sourceKey); - - std::string mark = ""; - for (auto sourceKeyInfo : sourceKey) { - if (sourceKeyInfo == SOURCES || sourceKeyInfo == NAMES || - sourceKeyInfo == MAPPINGS || sourceKeyInfo == FILE || - sourceKeyInfo == SOURCE_CONTENT || sourceKeyInfo == SOURCE_ROOT) { - mark = sourceKeyInfo; - } else if (mark == SOURCES) { - curMapData->sources_.push_back(sourceKeyInfo); - } else if (mark == NAMES) { - curMapData->names_.push_back(sourceKeyInfo); - } else if (mark == MAPPINGS) { - curMapData->mappings_.push_back(sourceKeyInfo); - } else if (mark == FILE) { - curMapData->files_.push_back(sourceKeyInfo); - } else { - continue; - } - } - - if (curMapData->mappings_.empty()) { - return; - } - - // transform to vector for mapping easily - curMapData->mappings_ = HandleMappings(curMapData->mappings_[0]); - + curMapData->mappings_ = HandleMappings(allmappings); // the first bit: the column after transferring. // the second bit: the source file. // the third bit: the row before transferring. @@ -296,8 +300,6 @@ void SourceMap::ExtractSourceMapData(const std::string& sourceMapData, std::shar } curMapData->mappings_.clear(); curMapData->mappings_.shrink_to_fit(); - sourceKey.clear(); - sourceKey.shrink_to_fit(); } MappingInfo SourceMap::Find(int32_t row, int32_t col, const SourceMapData& targetMap) @@ -311,8 +313,10 @@ MappingInfo SourceMap::Find(int32_t row, int32_t col, const SourceMapData& targe int32_t left = 0; int32_t right = static_cast(targetMap.afterPos_.size()) - 1; int32_t res = 0; + std::string sources = targetMap.sources_[0].substr(REAL_SOURCE_INDEX, + targetMap.sources_[0].size() - REAL_SOURCE_SIZE - 1); if (row > targetMap.afterPos_[targetMap.afterPos_.size() - 1].afterRow) { - return MappingInfo { row + 1, col + 1, targetMap.sources_[0] }; + return MappingInfo { row + 1, col + 1, sources }; } while (right - left >= 0) { int32_t mid = (right + left) / 2; @@ -324,7 +328,6 @@ MappingInfo SourceMap::Find(int32_t row, int32_t col, const SourceMapData& targe left = mid + 1; } } - std::string sources = targetMap.sources_[0]; auto pos = sources.find(WEBPACK); if (pos != std::string::npos) { sources.replace(pos, sizeof(WEBPACK) - 1, ""); diff --git a/js_environment/interfaces/inner_api/source_map.h b/js_environment/interfaces/inner_api/source_map.h index 60743cca23..a0851ed454 100644 --- a/js_environment/interfaces/inner_api/source_map.h +++ b/js_environment/interfaces/inner_api/source_map.h @@ -85,7 +85,7 @@ public: void SplitSourceMap(const std::string& sourceMapData); private: - void ExtractSourceMapData(const std::string& sourceMapData, std::shared_ptr& curMapData); + void ExtractSourceMapData(const std::string& allmappings, std::shared_ptr& curMapData); void ExtractKeyInfo(const std::string& sourceMap, std::vector& sourceKeyInfo); std::vector HandleMappings(const std::string& mapping); bool VlqRevCode(const std::string& vStr, std::vector& ans); @@ -102,6 +102,8 @@ private: static ReadSourceMapCallback readSourceMapFunc_; static std::mutex sourceMapMutex_; static GetHapPathCallback getHapPathFunc_; + std::unordered_map sources_; + std::unordered_map mappings_; }; } // namespace JsEnv } // namespace OHOS From 8f16431a73a9176d20992de7d35c8a019ad8c664 Mon Sep 17 00:00:00 2001 From: openharmony_ci <120357966@qq.com> Date: Mon, 3 Jun 2024 03:03:01 +0000 Subject: [PATCH 43/69] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!8?= =?UTF-8?q?571=20:=20jsheap=E6=96=87=E4=BB=B6=E8=90=BD=E7=9B=98=E8=87=B3/d?= =?UTF-8?q?ata/log/hidumper=E7=9B=AE=E5=BD=95'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/native/appkit/app/main_thread.cpp | 11 +--- frameworks/native/runtime/js_runtime.cpp | 5 +- .../include/appmgr/app_jsheap_mem_info.h | 5 -- .../src/appmgr/app_jsheap_mem_info.cpp | 64 ++----------------- .../inner_api/runtime/include/cj_runtime.h | 3 +- .../inner_api/runtime/include/js_runtime.h | 3 +- .../inner_api/runtime/include/runtime.h | 3 +- .../mock_runtime.h | 3 +- .../unittest/runtime_test/js_runtime_test.cpp | 4 +- 9 files changed, 14 insertions(+), 87 deletions(-) diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index cc23fc92c5..061749855c 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -644,16 +644,7 @@ void MainThread::ScheduleJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info) return; } if (info.needSnapshot == true) { - std::vector fdVec; - for (auto &fd : info.fdVec) { - uint32_t newFd = dup(fd); - if (newFd == -1) { - TAG_LOGE(AAFwkTag::APPKIT, "dup failed."); - return; - } - fdVec.push_back(newFd); - } - runtime->DumpHeapSnapshot(info.tid, info.needGc, fdVec, info.tidVec); + runtime->DumpHeapSnapshot(info.tid, info.needGc); } else { if (info.needGc == true) { runtime->ForceFullGC(info.tid); diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index d11c3fb7fc..5644ab1357 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -1197,12 +1197,11 @@ void JsRuntime::DumpHeapSnapshot(bool isPrivate) nativeEngine->DumpHeapSnapshot(true, DumpFormat::JSON, isPrivate, false); } -void JsRuntime::DumpHeapSnapshot(uint32_t tid, bool isFullGC, std::vector fdVec, - std::vector tidVec) +void JsRuntime::DumpHeapSnapshot(uint32_t tid, bool isFullGC) { auto vm = GetEcmaVm(); CHECK_POINTER(vm); - DFXJSNApi::DumpHeapSnapshot(vm, 0, true, false, false, isFullGC, tid, fdVec, tidVec); + DFXJSNApi::DumpHeapSnapshot(vm, 0, true, false, false, isFullGC, tid); } void JsRuntime::ForceFullGC(uint32_t tid) diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_jsheap_mem_info.h b/interfaces/inner_api/app_manager/include/appmgr/app_jsheap_mem_info.h index 6791cf79fb..e720f38282 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_jsheap_mem_info.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_jsheap_mem_info.h @@ -16,21 +16,16 @@ #ifndef OHOS_ABILITY_RUNTIME_APP_JSHEAP_MEM_INFO_H #define OHOS_ABILITY_RUNTIME_APP_JSHEAP_MEM_INFO_H -#include #include "parcel.h" #include "iremote_object.h" namespace OHOS { namespace AppExecFwk { struct JsHeapDumpInfo : public Parcelable { - ~JsHeapDumpInfo(); uint32_t pid; uint32_t tid; bool needGc; bool needSnapshot; - std::vector fdVec; - std::vector tidVec; - bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; static JsHeapDumpInfo *Unmarshalling(Parcel &parcel); }; diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_jsheap_mem_info.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_jsheap_mem_info.cpp index 619f615ccb..02b4333129 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_jsheap_mem_info.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_jsheap_mem_info.cpp @@ -19,61 +19,10 @@ namespace OHOS { namespace AppExecFwk { -namespace { -constexpr int32_t MAX_TID_COUNT = 40; -} - -JsHeapDumpInfo::~JsHeapDumpInfo() -{ - TAG_LOGI(AAFwkTag::APPMGR, "~JsHeapDumpInfo start"); - for (auto &fd : fdVec) { - close(fd); - } - fdVec.clear(); - tidVec.clear(); -} - bool JsHeapDumpInfo::Marshalling(Parcel &parcel) const { - bool res = (parcel.WriteUint32(pid) && parcel.WriteUint32(tid) - && parcel.WriteBool(needGc) && parcel.WriteBool(needSnapshot) - && parcel.WriteUInt32Vector(fdVec) && parcel.WriteUInt32Vector(tidVec)); - - auto msgParcel = static_cast(&parcel); - if (msgParcel == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "Dump Marshalling msgParcel==nullptr"); - return false; - } - for (auto &fd : fdVec) { - msgParcel->WriteFileDescriptor(fd); - } - return res; -} - -bool JsHeapDumpInfo::ReadFromParcel(Parcel &parcel) -{ - pid = parcel.ReadUint32(); - tid = parcel.ReadUint32(); - needGc = parcel.ReadBool(); - needSnapshot = parcel.ReadBool(); - if (fdVec.size() > MAX_TID_COUNT || tidVec.size() > MAX_TID_COUNT) { - TAG_LOGE(AAFwkTag::APPMGR, "fdVec or tidVec size more than 40."); - return false; - } - parcel.ReadUInt32Vector(&fdVec); - parcel.ReadUInt32Vector(&tidVec); - - auto msgParcel = static_cast(&parcel); - if (msgParcel == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "ReadFromParcel failed."); - return false; - } - fdVec.clear(); - for (auto &tid : tidVec) { - uint32_t parcelFd = static_cast(msgParcel->ReadFileDescriptor()); - fdVec.push_back(parcelFd); - } - return true; + return (parcel.WriteUint32(pid) && parcel.WriteUint32(tid) + && parcel.WriteBool(needGc) && parcel.WriteBool(needSnapshot)); } JsHeapDumpInfo *JsHeapDumpInfo::Unmarshalling(Parcel &parcel) @@ -83,11 +32,10 @@ JsHeapDumpInfo *JsHeapDumpInfo::Unmarshalling(Parcel &parcel) TAG_LOGE(AAFwkTag::APPMGR, "info nullptr"); return nullptr; } - if (info && !info->ReadFromParcel(parcel)) { - TAG_LOGE(AAFwkTag::APPMGR, "JsHeapDumpInfo failed, because ReadFromParcel failed"); - delete info; - info = nullptr; - } + info->pid = parcel.ReadUint32(); + info->tid = parcel.ReadUint32(); + info->needGc = parcel.ReadBool(); + info->needSnapshot = parcel.ReadBool(); return info; } } // namespace AppExecFwk diff --git a/interfaces/inner_api/runtime/include/cj_runtime.h b/interfaces/inner_api/runtime/include/cj_runtime.h index da662066aa..e5610f06fb 100644 --- a/interfaces/inner_api/runtime/include/cj_runtime.h +++ b/interfaces/inner_api/runtime/include/cj_runtime.h @@ -60,8 +60,7 @@ public: void DestroyHeapProfiler() override {}; void ForceFullGC() override {}; void ForceFullGC(uint32_t tid) override {}; - void DumpHeapSnapshot(uint32_t tid, bool isFullGC, std::vector fdVec, - std::vector tidVec) override {}; + void DumpHeapSnapshot(uint32_t tid, bool isFullGC) override {}; void DumpCpuProfile(bool isPrivate) override {}; void AllowCrossThreadExecution() override {}; void GetHeapPrepare() override {}; diff --git a/interfaces/inner_api/runtime/include/js_runtime.h b/interfaces/inner_api/runtime/include/js_runtime.h index 3b8d83d7d2..430fc46c48 100644 --- a/interfaces/inner_api/runtime/include/js_runtime.h +++ b/interfaces/inner_api/runtime/include/js_runtime.h @@ -85,8 +85,7 @@ public: void DestroyHeapProfiler() override; void ForceFullGC() override; void ForceFullGC(uint32_t tid) override; - void DumpHeapSnapshot(uint32_t tid, bool isFullGC, std::vector fdVec, - std::vector tidVec) override; + void DumpHeapSnapshot(uint32_t tid, bool isFullGC) override; void AllowCrossThreadExecution() override; void GetHeapPrepare() override; void NotifyApplicationState(bool isBackground) override; diff --git a/interfaces/inner_api/runtime/include/runtime.h b/interfaces/inner_api/runtime/include/runtime.h index 162605255e..0406005cdc 100644 --- a/interfaces/inner_api/runtime/include/runtime.h +++ b/interfaces/inner_api/runtime/include/runtime.h @@ -89,8 +89,7 @@ public: virtual void DestroyHeapProfiler() = 0; virtual void ForceFullGC() = 0; virtual void ForceFullGC(uint32_t tid) = 0; - virtual void DumpHeapSnapshot(uint32_t tid, bool isFullGC, std::vector fdVec, - std::vector tidVec) = 0; + virtual void DumpHeapSnapshot(uint32_t tid, bool isFullGC) = 0; virtual void AllowCrossThreadExecution() = 0; virtual void GetHeapPrepare() = 0; virtual void NotifyApplicationState(bool isBackground) = 0; diff --git a/test/mock/frameworks_kits_runtime_test/mock_runtime.h b/test/mock/frameworks_kits_runtime_test/mock_runtime.h index ac5ce22596..35892761f3 100644 --- a/test/mock/frameworks_kits_runtime_test/mock_runtime.h +++ b/test/mock/frameworks_kits_runtime_test/mock_runtime.h @@ -118,8 +118,7 @@ public: void StartProfiler(const DebugOption debugOption) override {} void DoCleanWorkAfterStageCleaned() override {} - void DumpHeapSnapshot(uint32_t tid, bool isFullGC, std::vector fdVec, - std::vector tidVec) override {} + void DumpHeapSnapshot(uint32_t tid, bool isFullGC) override {} void ForceFullGC(uint32_t tid) override {} public: Language language; diff --git a/test/unittest/runtime_test/js_runtime_test.cpp b/test/unittest/runtime_test/js_runtime_test.cpp index db9704a387..d3fbd09064 100755 --- a/test/unittest/runtime_test/js_runtime_test.cpp +++ b/test/unittest/runtime_test/js_runtime_test.cpp @@ -1492,9 +1492,7 @@ HWTEST_F(JsRuntimeTest, DumpHeapSnapshot_0200, TestSize.Level1) auto jsRuntime = std::make_unique(); uint32_t tid = 1; bool isFullGC = true; - std::vector fdVec; - std::vector tidVec; - jsRuntime->DumpHeapSnapshot(tid, isFullGC, fdVec, tidVec); + jsRuntime->DumpHeapSnapshot(tid, isFullGC); EXPECT_TRUE(jsRuntime != nullptr); } From a6004e5cd522b14464e16c82f3dd6163beb85ddb Mon Sep 17 00:00:00 2001 From: savior-xzh Date: Fri, 31 May 2024 15:18:38 +0800 Subject: [PATCH 44/69] load ability task Signed-off-by: savior-xzh Change-Id: I937eeafa07be841f7ebb629ce9639e963ae0df65 --- .../appmgr/include/app_mgr_service_inner.h | 11 ++++ services/appmgr/src/ams_mgr_scheduler.cpp | 22 ++++++++ services/appmgr/src/app_mgr_service_inner.cpp | 55 +++++++++++++++---- 3 files changed, 76 insertions(+), 12 deletions(-) diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 68d0f7f5aa..c845210aec 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -77,6 +77,7 @@ namespace AppExecFwk { using OHOS::AAFwk::Want; class WindowFocusChangedListener; class WindowVisibilityChangedListener; +using LoabAbilityTaskFunc = std::function; class AppMgrServiceInner : public std::enable_shared_from_this { public: @@ -1100,6 +1101,14 @@ public: bool IsAppProcessesAllCached(const std::string &bundleName, int32_t uid, const std::set> &cachedSet); + + bool GetSceneBoardAttachFlag() const; + + void SetSceneBoardAttachFlag(bool flag); + + void CacheLoabAbilityTask(const LoabAbilityTaskFunc& func); + + void SubmitCacheLoabAbilityTask(); private: std::string FaultTypeToString(FaultDataType type); @@ -1525,6 +1534,8 @@ private: std::shared_ptr dfxTaskHandler_; std::shared_ptr otherTaskHandler_; std::shared_ptr appPreloader_; + std::atomic sceneBoardAttachFlag_ = true; + std::vector loadAbilityTaskFuncList_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index c2225881dc..76628bca56 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -44,6 +44,10 @@ constexpr const char* TASK_ATTACH_PID_TO_PARENT = "AttachPidToParent"; constexpr const char* TASK_KILL_APPLICATION = "KillApplicationTask"; constexpr const char* TASK_CLEAR_PROCESS_BY_ABILITY_TOKEN = "ClearProcessByAbilityTokenTask"; constexpr const char* FOUNDATION_NAME = "foundation"; +constexpr const char* SCENE_BOARD_BUNDLE_NAME = "com.ohos.sceneboard"; +constexpr const char* SCENEBOARD_ABILITY_NAME = "com.ohos.sceneboard.MainAbility"; +constexpr const char* TASK_SCENE_BOARD_ATTACH_TIMEOUT = "sceneBoardAttachTimeoutTask"; +constexpr int32_t SCENE_BOARD_ATTACH_TIMEOUT_TASK_TIME = 1000; }; // namespace AmsMgrScheduler::AmsMgrScheduler( @@ -81,6 +85,24 @@ void AmsMgrScheduler::LoadAbility(const sptr &token, const sptrGetSceneBoardAttachFlag() && abilityInfo->bundleName != SCENE_BOARD_BUNDLE_NAME) { + amsMgrServiceInner_->CacheLoabAbilityTask(loadAbilityFunc); + return; + } + if (abilityInfo->bundleName == SCENE_BOARD_BUNDLE_NAME && abilityInfo->name == SCENEBOARD_ABILITY_NAME) { + amsMgrServiceInner_->SetSceneBoardAttachFlag(false); + // set scene board attach timeout task + std::weak_ptr amsMgrServiceInner = amsMgrServiceInner_; + auto timeoutTask = [amsMgrServiceInner]() { + auto inner = amsMgrServiceInner.lock(); + if (inner != nullptr) { + inner->SetSceneBoardAttachFlag(true); + } + }; + amsHandler_->SubmitTask(timeoutTask, TASK_SCENE_BOARD_ATTACH_TIMEOUT, SCENE_BOARD_ATTACH_TIMEOUT_TASK_TIME); + } + amsHandler_->SubmitTask(loadAbilityFunc); } diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 59f1390baa..b9e68d608d 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -110,6 +110,12 @@ namespace { return ERR_PERMISSION_DENIED; \ } +#define CHECK_POINTER_AND_RETURN_LOG(object, log) \ + if (!object) { \ + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s", log); \ + return; \ + } + // NANOSECONDS mean 10^9 nano second constexpr int64_t NANOSECONDS = 1000000000; // MICROSECONDS mean 10^6 milli second @@ -829,10 +835,7 @@ void AppMgrServiceInner::AttachApplication(const pid_t pid, const sptrGetApplicationInfo(); AAFwk::EventInfo eventInfo; if (!applicationInfo) { @@ -845,16 +848,10 @@ void AppMgrServiceInner::AttachApplication(const pid_t pid, const sptr appDeathRecipient = new (std::nothrow) AppDeathRecipient(); - if (appDeathRecipient == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "Failed to create death recipient."); - return; - } + CHECK_POINTER_AND_RETURN_LOG(appDeathRecipient, "Failed to create death recipient."); appDeathRecipient->SetTaskHandler(taskHandler_); appDeathRecipient->SetAppMgrServiceInner(shared_from_this()); auto object = appScheduler->AsObject(); @@ -868,6 +865,12 @@ void AppMgrServiceInner::AttachApplication(const pid_t pid, const sptrGetState() == ApplicationState::APP_STATE_CREATE) { LaunchApplication(appRecord); } + + // submit cached load ability task after scene board attach + if (appRecord->GetBundleName() == SCENE_BOARD_BUNDLE_NAME) { + sceneBoardAttachFlag_ = true; + SubmitCacheLoabAbilityTask(); + } eventInfo.pid = appRecord->GetPriorityObject()->GetPid(); eventInfo.processName = appRecord->GetProcessName(); AAFwk::EventReport::SendAppEvent(AAFwk::EventName::APP_ATTACH, HiSysEventType::BEHAVIOR, eventInfo); @@ -6893,5 +6896,33 @@ bool AppMgrServiceInner::IsAppProcessesAllCached(const std::string &bundleName, } return appRunningManager_->IsAppProcessesAllCached(bundleName, uid, cachedSet); } + +void AppMgrServiceInner::CacheLoabAbilityTask(const LoabAbilityTaskFunc& func) +{ + loadAbilityTaskFuncList_.emplace_back(func); +} + +void AppMgrServiceInner::SubmitCacheLoabAbilityTask() +{ + std::weak_ptr taskHandler = taskHandler_; + for_each(loadAbilityTaskFuncList_.begin(), loadAbilityTaskFuncList_.end(), + [taskHandler](LoabAbilityTaskFunc loadAbilityFunc) { + auto LoadAbilityhandler = taskHandler.lock(); + if (LoadAbilityhandler != nullptr && loadAbilityFunc) { + LoadAbilityhandler->SubmitTask(loadAbilityFunc); + } + }); + loadAbilityTaskFuncList_.clear(); +} + +bool AppMgrServiceInner::GetSceneBoardAttachFlag() const +{ + return sceneBoardAttachFlag_; +} + +void AppMgrServiceInner::SetSceneBoardAttachFlag(bool flag) +{ + sceneBoardAttachFlag_ = flag; +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file From f57efcd643e83229b87e748324407899d127043f Mon Sep 17 00:00:00 2001 From: hhl Date: Sat, 1 Jun 2024 14:43:22 +0800 Subject: [PATCH 45/69] fix apprecovery White screen issue Signed-off-by: hhl --- services/abilitymgr/src/ability_record.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index ef713e822e..026e56348a 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -26,6 +26,7 @@ #include "ability_resident_process_rdb.h" #include "ability_scheduler_stub.h" #include "ability_util.h" +#include "app_exit_reason_data_manager.h" #include "app_utils.h" #include "appfreeze_manager.h" #include "array_wrapper.h" @@ -1270,6 +1271,12 @@ int AbilityRecord::TerminateAbility() AAFwk::EventInfo eventInfo; eventInfo.bundleName = GetAbilityInfo().bundleName; eventInfo.abilityName = GetAbilityInfo().name; + if (clearMissionFlag_) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "deleteAbilityRecoverInfo before clearMission."); + (void)DelayedSingleton::GetInstance()-> + DeleteAbilityRecoverInfo(GetAbilityInfo().applicationInfo.accessTokenId, GetAbilityInfo().moduleName, + GetAbilityInfo().name); + } AAFwk::EventReport::SendAbilityEvent(AAFwk::EventName::TERMINATE_ABILITY, HiSysEventType::BEHAVIOR, eventInfo); eventInfo.errCode = DelayedSingleton::GetInstance()->TerminateAbility(token_, clearMissionFlag_); if (eventInfo.errCode != ERR_OK) { From fbe1cf3eab6c4205debf009faca706021ef05866 Mon Sep 17 00:00:00 2001 From: zhu-bingwei123 Date: Mon, 3 Jun 2024 16:00:42 +0800 Subject: [PATCH 46/69] fix tdd crash problem(AmsAppRunningRecordTest AppRunningProcessesInfoTest AppMgrServiceInnerTest) Signed-off-by: zhu-bingwei123 --- test/unittest/ams_app_running_record_test/BUILD.gn | 6 ++++++ test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn | 7 ++++++- test/unittest/app_running_processes_info_test/BUILD.gn | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/test/unittest/ams_app_running_record_test/BUILD.gn b/test/unittest/ams_app_running_record_test/BUILD.gn index 0c2dc023a7..fb9475f3cb 100644 --- a/test/unittest/ams_app_running_record_test/BUILD.gn +++ b/test/unittest/ams_app_running_record_test/BUILD.gn @@ -18,6 +18,12 @@ module_output_path = "ability_runtime/appmgrservice" ohos_unittest("AmsAppRunningRecordTest") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", "${ability_runtime_innerkits_path}/app_manager/include/appmgr", diff --git a/test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn b/test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn index 96b7517871..c4ce653d44 100644 --- a/test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn @@ -18,7 +18,12 @@ module_output_path = "ability_runtime/appmgrservice" ohos_unittest("app_mgr_service_inner_tdd_test") { module_out_path = module_output_path - + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/common/include", "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", diff --git a/test/unittest/app_running_processes_info_test/BUILD.gn b/test/unittest/app_running_processes_info_test/BUILD.gn index c3dc6f6e77..21d1d6383f 100644 --- a/test/unittest/app_running_processes_info_test/BUILD.gn +++ b/test/unittest/app_running_processes_info_test/BUILD.gn @@ -18,6 +18,12 @@ module_output_path = "ability_runtime/appmgrservice" ohos_unittest("AppRunningProcessesInfoTest") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" cflags_cc = [] include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", From 12d705bc3727f0ee2e310ae751912bdeaa24c0c9 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 3 Jun 2024 16:20:38 +0800 Subject: [PATCH 47/69] fix getcallingreal Signed-off-by: unknown --- .../distributed_client.cpp | 2 +- .../src/ability_connect_manager.cpp | 2 +- .../src/ability_manager_service.cpp | 18 +++++----- services/abilitymgr/src/ability_record.cpp | 2 +- .../abilitymgr/src/app_exit_reason_helper.cpp | 2 +- .../src/assert_fault_callback_death_mgr.cpp | 2 +- services/abilitymgr/src/connection_record.cpp | 2 +- .../abilitymgr/src/data_ability_manager.cpp | 4 +-- .../abilitymgr/src/data_ability_record.cpp | 2 +- .../src/implicit_start_processor.cpp | 2 +- .../ecological_rule_interceptor.cpp | 2 +- .../start_other_app_interceptor.cpp | 4 +-- services/appmgr/src/ams_mgr_scheduler.cpp | 4 +-- services/appmgr/src/app_mgr_event.cpp | 2 +- services/appmgr/src/app_mgr_service.cpp | 24 ++++++------- services/appmgr/src/app_mgr_service_inner.cpp | 36 +++++++++---------- .../src/uri_permission_manager_stub_impl.cpp | 2 +- 17 files changed, 56 insertions(+), 56 deletions(-) diff --git a/frameworks/native/ability/native/distributed_ability_runtime/distributed_client.cpp b/frameworks/native/ability/native/distributed_ability_runtime/distributed_client.cpp index 96303d6dc7..3be1e2d402 100644 --- a/frameworks/native/ability/native/distributed_ability_runtime/distributed_client.cpp +++ b/frameworks/native/ability/native/distributed_ability_runtime/distributed_client.cpp @@ -503,7 +503,7 @@ bool DistributedClient::WriteInfosToParcel(MessageParcel& data, const OHOS::AAFw const sptr& connect) { int32_t callerUid = IPCSkeleton::GetCallingUid(); - int32_t callerPid = IPCSkeleton::GetCallingRealPid(); + int32_t callerPid = IPCSkeleton::GetCallingPid(); uint32_t accessToken = IPCSkeleton::GetCallingTokenID(); if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) { return false; diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 3981f0e983..099cfdbc64 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -2889,7 +2889,7 @@ EventInfo AbilityConnectManager::BuildEventInfo(const std::shared_ptr( std::chrono::system_clock::now().time_since_epoch()).count(); auto callerPid = abilityRecord->GetWant().GetIntParam(Want::PARAM_RESV_CALLER_PID, -1); - eventInfo.callerPid = callerPid == -1 ? IPCSkeleton::GetCallingRealPid() : callerPid; + eventInfo.callerPid = callerPid == -1 ? IPCSkeleton::GetCallingPid() : callerPid; DelayedSingleton::GetInstance()->GetRunningProcessInfoByPid(eventInfo.callerPid, processInfo); eventInfo.callerPid = processInfo.pid_; eventInfo.callerProcessName = processInfo.processName_; diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index f6d19d10a3..8c81f659bb 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -1823,7 +1823,7 @@ int32_t AbilityManagerService::ReportDrawnCompleted(const sptr &c EventInfo eventInfo; eventInfo.userId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; - eventInfo.pid = IPCSkeleton::GetCallingRealPid(); + eventInfo.pid = IPCSkeleton::GetCallingPid(); eventInfo.bundleName = abilityInfo.bundleName; eventInfo.moduleName = abilityInfo.moduleName; eventInfo.abilityName = abilityInfo.name; @@ -5992,7 +5992,7 @@ int32_t AbilityManagerService::UpgradeApp(const std::string &bundleName, const i int32_t AbilityManagerService::UninstallAppInner(const std::string &bundleName, const int32_t uid, const bool isUpgrade, const std::string &exitMsg) { - pid_t callingPid = IPCSkeleton::GetCallingRealPid(); + pid_t callingPid = IPCSkeleton::GetCallingPid(); pid_t pid = getprocpid(); if (callingPid != pid) { TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: Not bundleMgr call.", __func__); @@ -7608,7 +7608,7 @@ int AbilityManagerService::DelegatorDoAbilityForeground(const sptrGetPid(); TAG_LOGD(AAFwkTag::ABILITYMGR, "callerPid: %{public}d, appPid: %{public}d", callerPid, appPid); if (callerPid != appPid) { @@ -7644,7 +7644,7 @@ int AbilityManagerService::DelegatorDoAbilityBackground(const sptrGetPid(); - int32_t callerPid = IPCSkeleton::GetCallingRealPid(); + int32_t callerPid = IPCSkeleton::GetCallingPid(); TAG_LOGD(AAFwkTag::ABILITYMGR, "callerPid: %{public}d, appPid: %{public}d", callerPid, appPid); if (callerPid != appPid) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Caller is not the application itself"); @@ -7721,7 +7721,7 @@ void AbilityManagerService::UpdateCallerInfo(Want& want, const sptr(IPCSkeleton::GetCallingTokenID()); int32_t callerUid = IPCSkeleton::GetCallingUid(); - int32_t callerPid = IPCSkeleton::GetCallingRealPid(); + int32_t callerPid = IPCSkeleton::GetCallingPid(); want.RemoveParam(Want::PARAM_RESV_CALLER_TOKEN); want.SetParam(Want::PARAM_RESV_CALLER_TOKEN, tokenId); want.RemoveParam(Want::PARAM_RESV_CALLER_UID); @@ -8897,7 +8897,7 @@ int AbilityManagerService::IsCallFromBackground(const AbilityRequest &abilityReq return ERR_OK; } } else { - auto callerPid = IPCSkeleton::GetCallingRealPid(); + auto callerPid = IPCSkeleton::GetCallingPid(); DelayedSingleton::GetInstance()->GetRunningProcessInfoByPid(callerPid, processInfo); if (processInfo.processName_.empty()) { TAG_LOGD(AAFwkTag::ABILITYMGR, "Can not find caller application by callerPid: %{private}d.", callerPid); @@ -9069,7 +9069,7 @@ int AbilityManagerService::CheckDlpForExtension( bool AbilityManagerService::JudgeSelfCalled(const std::shared_ptr &abilityRecord) { - if (IPCSkeleton::GetCallingRealPid() == getprocpid()) { + if (IPCSkeleton::GetCallingPid() == getprocpid()) { return true; } @@ -10165,7 +10165,7 @@ int32_t AbilityManagerService::SetResidentProcessEnabled(const std::string &bund std::string callerName; int32_t uid = 0; - auto callerPid = IPCSkeleton::GetCallingRealPid(); + auto callerPid = IPCSkeleton::GetCallingPid(); DelayedSingleton::GetInstance()->GetBundleNameByPid(callerPid, callerName, uid); if (callerName.empty()) { HILOG_ERROR("Failed to obtain caller name."); @@ -10559,7 +10559,7 @@ void AbilityManagerService::ReportPreventStartAbilityResult(const AppExecFwk::Ab const AppExecFwk::AbilityInfo &abilityInfo) { int32_t callerUid = IPCSkeleton::GetCallingUid(); - int32_t callerPid = IPCSkeleton::GetCallingRealPid(); + int32_t callerPid = IPCSkeleton::GetCallingPid(); int32_t extensionAbilityType = static_cast(abilityInfo.extensionAbilityType); TAG_LOGD(AAFwkTag::ABILITYMGR, "Prevent start ability debug log CALLER_BUNDLE_NAME %{public}s CALLEE_BUNDLE_NAME" diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index ef713e822e..5d9f043338 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -1439,7 +1439,7 @@ void AbilityRecord::SetScheduler(const sptr &scheduler) if (IsSceneBoard()) { TAG_LOGI(AAFwkTag::ABILITYMGR, "Sceneboard DeathRecipient Added"); } - pid_ = static_cast(IPCSkeleton::GetCallingRealPid()); // set pid when ability attach to service. + pid_ = static_cast(IPCSkeleton::GetCallingPid()); // set pid when ability attach to service. // add collaborator mission bind pid NotifyMissionBindPid(); HandleDlpAttached(); diff --git a/services/abilitymgr/src/app_exit_reason_helper.cpp b/services/abilitymgr/src/app_exit_reason_helper.cpp index 9261cb2602..b5608752fe 100644 --- a/services/abilitymgr/src/app_exit_reason_helper.cpp +++ b/services/abilitymgr/src/app_exit_reason_helper.cpp @@ -49,7 +49,7 @@ int32_t AppExitReasonHelper::RecordAppExitReason(const ExitReason &exitReason) return ERR_INVALID_VALUE; } - auto pid = IPCSkeleton::GetCallingRealPid(); + auto pid = IPCSkeleton::GetCallingPid(); AppExecFwk::ApplicationInfo application; bool debug = false; auto ret = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->GetApplicationInfoByProcessID(pid, diff --git a/services/abilitymgr/src/assert_fault_callback_death_mgr.cpp b/services/abilitymgr/src/assert_fault_callback_death_mgr.cpp index ef60320c6f..c9d92d6913 100644 --- a/services/abilitymgr/src/assert_fault_callback_death_mgr.cpp +++ b/services/abilitymgr/src/assert_fault_callback_death_mgr.cpp @@ -56,7 +56,7 @@ void AssertFaultCallbackDeathMgr::AddAssertFaultCallback(sptr &re }); remote->AddDeathRecipient(deathRecipient); - auto callerPid = IPCSkeleton::GetCallingRealPid(); + auto callerPid = IPCSkeleton::GetCallingPid(); uint64_t assertFaultSessionId = reinterpret_cast(remote.GetRefPtr()); std::unique_lock lock(assertFaultSessionMutex_); assertFaultSessionDialogs_[assertFaultSessionId] = {callerPid, remote, deathRecipient, callback}; diff --git a/services/abilitymgr/src/connection_record.cpp b/services/abilitymgr/src/connection_record.cpp index f7abd410dd..34d08b5df2 100644 --- a/services/abilitymgr/src/connection_record.cpp +++ b/services/abilitymgr/src/connection_record.cpp @@ -270,7 +270,7 @@ void ConnectionRecord::AttachCallerInfo() } callerUid_ = static_cast(IPCSkeleton::GetCallingUid()); - callerPid_ = static_cast(IPCSkeleton::GetCallingRealPid()); + callerPid_ = static_cast(IPCSkeleton::GetCallingPid()); callerName_ = ConnectionStateManager::GetProcessNameByPid(callerPid_); } diff --git a/services/abilitymgr/src/data_ability_manager.cpp b/services/abilitymgr/src/data_ability_manager.cpp index bc2c661188..6d61a7d52a 100644 --- a/services/abilitymgr/src/data_ability_manager.cpp +++ b/services/abilitymgr/src/data_ability_manager.cpp @@ -683,7 +683,7 @@ void DataAbilityManager::ReportDataAbilityAcquired(const sptr &cl { DataAbilityCaller caller; caller.isNotHap = isNotHap; - caller.callerPid = IPCSkeleton::GetCallingRealPid(); + caller.callerPid = IPCSkeleton::GetCallingPid(); caller.callerUid = IPCSkeleton::GetCallingUid(); caller.callerToken = client; if (client && !isNotHap) { @@ -703,7 +703,7 @@ void DataAbilityManager::ReportDataAbilityReleased(const sptr &cl { DataAbilityCaller caller; caller.isNotHap = isNotHap; - caller.callerPid = IPCSkeleton::GetCallingRealPid(); + caller.callerPid = IPCSkeleton::GetCallingPid(); caller.callerUid = IPCSkeleton::GetCallingUid(); caller.callerToken = client; DelayedSingleton::GetInstance()->RemoveDataAbilityConnection(caller, record); diff --git a/services/abilitymgr/src/data_ability_record.cpp b/services/abilitymgr/src/data_ability_record.cpp index 45e27de820..12bb7e70ef 100644 --- a/services/abilitymgr/src/data_ability_record.cpp +++ b/services/abilitymgr/src/data_ability_record.cpp @@ -228,7 +228,7 @@ int DataAbilityRecord::AddClient(const sptr &client, bool tryBind clientInfo.client = client; clientInfo.tryBind = tryBind; clientInfo.isNotHap = isNotHap; - clientInfo.clientPid = IPCSkeleton::GetCallingRealPid(); + clientInfo.clientPid = IPCSkeleton::GetCallingPid(); return ERR_OK; } diff --git a/services/abilitymgr/src/implicit_start_processor.cpp b/services/abilitymgr/src/implicit_start_processor.cpp index eefc114f4d..f79620afd2 100644 --- a/services/abilitymgr/src/implicit_start_processor.cpp +++ b/services/abilitymgr/src/implicit_start_processor.cpp @@ -633,7 +633,7 @@ void ImplicitStartProcessor::GetEcologicalCallerInfo(const Want &want, ErmsCalle { callerInfo.packageName = want.GetStringParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME); callerInfo.uid = want.GetIntParam(Want::PARAM_RESV_CALLER_UID, IPCSkeleton::GetCallingUid()); - callerInfo.pid = want.GetIntParam(Want::PARAM_RESV_CALLER_PID, IPCSkeleton::GetCallingRealPid()); + callerInfo.pid = want.GetIntParam(Want::PARAM_RESV_CALLER_PID, IPCSkeleton::GetCallingPid()); callerInfo.targetAppType = ErmsCallerInfo::TYPE_INVALID; callerInfo.callerAppType = ErmsCallerInfo::TYPE_INVALID; diff --git a/services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp b/services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp index 10b9bd0271..e18970b521 100644 --- a/services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp @@ -181,7 +181,7 @@ void EcologicalRuleInterceptor::InitErmsCallerInfo(Want &want, ErmsCallerInfo &c { callerInfo.packageName = want.GetStringParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME); callerInfo.uid = want.GetIntParam(Want::PARAM_RESV_CALLER_UID, IPCSkeleton::GetCallingUid()); - callerInfo.pid = want.GetIntParam(Want::PARAM_RESV_CALLER_PID, IPCSkeleton::GetCallingRealPid()); + callerInfo.pid = want.GetIntParam(Want::PARAM_RESV_CALLER_PID, IPCSkeleton::GetCallingPid()); callerInfo.targetAppType = ErmsCallerInfo::TYPE_INVALID; callerInfo.callerAppType = ErmsCallerInfo::TYPE_INVALID; callerInfo.targetLinkFeature = want.GetStringParam("send_to_erms_targetLinkFeature"); diff --git a/services/abilitymgr/src/interceptor/start_other_app_interceptor.cpp b/services/abilitymgr/src/interceptor/start_other_app_interceptor.cpp index ef080dbe79..53e11a8874 100644 --- a/services/abilitymgr/src/interceptor/start_other_app_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/start_other_app_interceptor.cpp @@ -110,7 +110,7 @@ bool StartOtherAppInterceptor::GetApplicationInfo(const sptr &cal AppExecFwk::ApplicationInfo &applicationInfo) { if (callerToken == nullptr) { - int32_t callerPid = IPCSkeleton::GetCallingRealPid(); + int32_t callerPid = IPCSkeleton::GetCallingPid(); auto appScheduler = DelayedSingleton::GetInstance(); bool debug; if (appScheduler != nullptr && @@ -148,7 +148,7 @@ bool StartOtherAppInterceptor::IsDelegatorCall(const Want want) { AppExecFwk::RunningProcessInfo processInfo; DelayedSingleton::GetInstance()-> - GetRunningProcessInfoByPid(IPCSkeleton::GetCallingRealPid(), processInfo); + GetRunningProcessInfoByPid(IPCSkeleton::GetCallingPid(), processInfo); if (processInfo.isTestProcess && want.GetBoolParam(IS_DELEGATOR_CALL, false)) { return true; } diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index bb8f322331..df0d8c8db8 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -211,7 +211,7 @@ void AmsMgrScheduler::KillProcessesByPids(std::vector &pids) return; } - pid_t callingPid = IPCSkeleton::GetCallingRealPid(); + pid_t callingPid = IPCSkeleton::GetCallingPid(); pid_t pid = getprocpid(); if (callingPid != pid) { TAG_LOGE(AAFwkTag::APPMGR, "Not allow other process to call."); @@ -229,7 +229,7 @@ void AmsMgrScheduler::AttachPidToParent(const sptr &token, const return; } - pid_t callingPid = IPCSkeleton::GetCallingRealPid(); + pid_t callingPid = IPCSkeleton::GetCallingPid(); pid_t pid = getprocpid(); if (callingPid != pid) { TAG_LOGE(AAFwkTag::APPMGR, "Not allow other process to call."); diff --git a/services/appmgr/src/app_mgr_event.cpp b/services/appmgr/src/app_mgr_event.cpp index c6c2934032..c322a74081 100644 --- a/services/appmgr/src/app_mgr_event.cpp +++ b/services/appmgr/src/app_mgr_event.cpp @@ -104,7 +104,7 @@ bool AppMgrEventUtil::SendProcessStartEvent(const std::shared_ptrGetBundleName().empty()) { eventInfo.callerBundleName = callerAppRecord->GetName(); diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index e4e2f58c4c..7ead769cd1 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -213,7 +213,7 @@ void AppMgrService::AttachApplication(const sptr &app) return; } - pid_t pid = IPCSkeleton::GetCallingRealPid(); + pid_t pid = IPCSkeleton::GetCallingPid(); std::function attachApplicationFunc = std::bind(&AppMgrServiceInner::AttachApplication, appMgrServiceInner_, pid, iface_cast(app)); taskHandler_->SubmitTask(attachApplicationFunc, AAFwk::TaskAttribute{ @@ -318,7 +318,7 @@ void AppMgrService::StartupResidentProcess(const std::vectorClearUpApplicationData(bundleName, uid, pid, userId); return ERR_OK; } @@ -380,7 +380,7 @@ int32_t AppMgrService::ClearUpApplicationDataBySelf(int32_t userId) return ERR_INVALID_OPERATION; } int32_t uid = IPCSkeleton::GetCallingUid(); - pid_t pid = IPCSkeleton::GetCallingRealPid(); + pid_t pid = IPCSkeleton::GetCallingPid(); return appMgrServiceInner_->ClearUpApplicationDataBySelf(uid, pid, userId); } @@ -619,7 +619,7 @@ int AppMgrService::FinishUserTest(const std::string &msg, const int64_t &resultC TAG_LOGE(AAFwkTag::APPMGR, "GetBundleName failed: %{public}d.", result); return ERR_INVALID_OPERATION; } - pid_t callingPid = IPCSkeleton::GetCallingRealPid(); + pid_t callingPid = IPCSkeleton::GetCallingPid(); std::function finishUserTestProcessFunc = std::bind(&AppMgrServiceInner::FinishUserTest, appMgrServiceInner_, msg, resultCode, bundleName, callingPid); taskHandler_->SubmitTask(finishUserTestProcessFunc, TASK_FINISH_USER_TEST); @@ -916,7 +916,7 @@ int32_t AppMgrService::PreStartNWebSpawnProcess() return ERR_INVALID_OPERATION; } - return appMgrServiceInner_->PreStartNWebSpawnProcess(IPCSkeleton::GetCallingRealPid()); + return appMgrServiceInner_->PreStartNWebSpawnProcess(IPCSkeleton::GetCallingPid()); } int32_t AppMgrService::StartRenderProcess(const std::string &renderParam, int32_t ipcFd, @@ -927,7 +927,7 @@ int32_t AppMgrService::StartRenderProcess(const std::string &renderParam, int32_ return ERR_INVALID_OPERATION; } - return appMgrServiceInner_->StartRenderProcess(IPCSkeleton::GetCallingRealPid(), + return appMgrServiceInner_->StartRenderProcess(IPCSkeleton::GetCallingPid(), renderParam, ipcFd, sharedFd, crashFd, renderPid, isGPU); } @@ -939,7 +939,7 @@ void AppMgrService::AttachRenderProcess(const sptr &scheduler) return; } - auto pid = IPCSkeleton::GetCallingRealPid(); + auto pid = IPCSkeleton::GetCallingPid(); auto fun = std::bind(&AppMgrServiceInner::AttachRenderProcess, appMgrServiceInner_, pid, iface_cast(scheduler)); taskHandler_->SubmitTask(fun, AAFwk::TaskAttribute{ @@ -955,7 +955,7 @@ void AppMgrService::SaveBrowserChannel(sptr browser) return; } - appMgrServiceInner_->SaveBrowserChannel(IPCSkeleton::GetCallingRealPid(), browser); + appMgrServiceInner_->SaveBrowserChannel(IPCSkeleton::GetCallingPid(), browser); } int32_t AppMgrService::GetRenderProcessTerminationStatus(pid_t renderPid, int &status) @@ -1326,7 +1326,7 @@ int32_t AppMgrService::StartChildProcess(const std::string &srcEntry, pid_t &chi TAG_LOGE(AAFwkTag::APPMGR, "StartChildProcess failed, AppMgrService not ready."); return ERR_INVALID_OPERATION; } - return appMgrServiceInner_->StartChildProcess(IPCSkeleton::GetCallingRealPid(), srcEntry, childPid, + return appMgrServiceInner_->StartChildProcess(IPCSkeleton::GetCallingPid(), srcEntry, childPid, childProcessCount, isStartWithDebug); } @@ -1350,7 +1350,7 @@ void AppMgrService::AttachChildProcess(const sptr &childScheduler TAG_LOGE(AAFwkTag::APPMGR, "taskHandler_ is null."); return; } - pid_t pid = IPCSkeleton::GetCallingRealPid(); + pid_t pid = IPCSkeleton::GetCallingPid(); std::function task = std::bind(&AppMgrServiceInner::AttachChildProcess, appMgrServiceInner_, pid, iface_cast(childScheduler)); taskHandler_->SubmitTask(task, AAFwk::TaskAttribute{ @@ -1369,7 +1369,7 @@ void AppMgrService::ExitChildProcessSafely() TAG_LOGE(AAFwkTag::APPMGR, "taskHandler_ is null."); return; } - pid_t pid = IPCSkeleton::GetCallingRealPid(); + pid_t pid = IPCSkeleton::GetCallingPid(); std::function task = std::bind(&AppMgrServiceInner::ExitChildProcessSafelyByChildPid, appMgrServiceInner_, pid); taskHandler_->SubmitTask(task, AAFwk::TaskAttribute{ diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index c8364bb870..7e57c246bb 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -969,7 +969,7 @@ void AppMgrServiceInner::ApplicationForegrounded(const int32_t recordId) eventInfo.processName = appRecord->GetProcessName(); eventInfo.processType = static_cast(appRecord->GetProcessType()); int32_t callerPid = appRecord->GetCallerPid() == -1 ? - IPCSkeleton::GetCallingRealPid() : appRecord->GetCallerPid(); + IPCSkeleton::GetCallingPid() : appRecord->GetCallerPid(); auto callerRecord = GetAppRunningRecordByPid(callerPid); if (callerRecord != nullptr) { eventInfo.callerBundleName = callerRecord->GetBundleName(); @@ -1237,7 +1237,7 @@ int32_t AppMgrServiceInner::KillApplicationSelf() return ERR_NO_INIT; } - auto callerPid = IPCSkeleton::GetCallingRealPid(); + auto callerPid = IPCSkeleton::GetCallingPid(); auto appRecord = GetAppRunningRecordByPid(callerPid); if (!appRecord) { TAG_LOGE(AAFwkTag::APPMGR, "no such appRecord, callerPid:%{public}d", callerPid); @@ -1574,7 +1574,7 @@ int32_t AppMgrServiceInner::GetProcessRunningInformation(RunningProcessInfo &inf TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is nullptr"); return ERR_NO_INIT; } - auto callerPid = IPCSkeleton::GetCallingRealPid(); + auto callerPid = IPCSkeleton::GetCallingPid(); auto appRecord = GetAppRunningRecordByPid(callerPid); if (!appRecord) { TAG_LOGE(AAFwkTag::APPMGR, "no such appRecord, callerPid:%{public}d", callerPid); @@ -2080,7 +2080,7 @@ void AppMgrServiceInner::SetBundleManagerHelper(const std::shared_ptr &callback) { - pid_t callingPid = IPCSkeleton::GetCallingRealPid(); + pid_t callingPid = IPCSkeleton::GetCallingPid(); pid_t pid = getprocpid(); if (callingPid != pid) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s: Not abilityMgr call.", __func__); @@ -2925,7 +2925,7 @@ bool AppMgrServiceInner::SendCreateAtomicServiceProcessEvent(const std::shared_p return false; } TAG_LOGI(AAFwkTag::APPMGR, "to report create atomic service process event."); - auto callerPid = appRecord->GetCallerPid() == -1 ? IPCSkeleton::GetCallingRealPid() : appRecord->GetCallerPid(); + auto callerPid = appRecord->GetCallerPid() == -1 ? IPCSkeleton::GetCallingPid() : appRecord->GetCallerPid(); auto callerAppRecord = GetAppRunningRecordByPid(callerPid); return AppMgrEventUtil::SendCreateAtomicServiceProcessEvent(callerAppRecord, appRecord, moduleName, abilityName); } @@ -2937,7 +2937,7 @@ bool AppMgrServiceInner::SendProcessStartEvent(const std::shared_ptrGetCallerPid() == -1 ? IPCSkeleton::GetCallingRealPid() : appRecord->GetCallerPid(); + auto callerPid = appRecord->GetCallerPid() == -1 ? IPCSkeleton::GetCallingPid() : appRecord->GetCallerPid(); auto callerAppRecord = GetAppRunningRecordByPid(callerPid); AppMgrEventUtil::SendProcessStartEvent(callerAppRecord, appRecord, eventInfo); SendReStartProcessEvent(eventInfo, appRecord->GetUid()); @@ -3897,7 +3897,7 @@ void AppMgrServiceInner::RegisterStartSpecifiedAbilityResponse(const sptrIsSACall(); - auto callingPid = IPCSkeleton::GetCallingRealPid(); + auto callingPid = IPCSkeleton::GetCallingPid(); if (!isSaCall && callingPid != pid) { TAG_LOGE(AAFwkTag::APPMGR, "Permission verify failed."); return ERR_PERMISSION_DENIED; @@ -4342,7 +4342,7 @@ int AppMgrServiceInner::VerifyProcessPermission(const std::string &bundleName) c auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( AAFwk::PermissionConstants::PERMISSION_CLEAN_BACKGROUND_PROCESSES); if (isCallingPerm) { - auto callerPid = IPCSkeleton::GetCallingRealPid(); + auto callerPid = IPCSkeleton::GetCallingPid(); auto appRecord = GetAppRunningRecordByPid(callerPid); if (!appRecord || appRecord->GetBundleName() != bundleName) { TAG_LOGE(AAFwkTag::APPMGR, "Permission verification failed."); @@ -4392,7 +4392,7 @@ bool AppMgrServiceInner::CheckCallerIsAppGallery() TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is nullptr"); return false; } - auto callerPid = IPCSkeleton::GetCallingRealPid(); + auto callerPid = IPCSkeleton::GetCallingPid(); auto appRecord = appRunningManager_->GetAppRunningRecordByPid(callerPid); if (!appRecord) { TAG_LOGE(AAFwkTag::APPMGR, "Get app running record by calling pid failed. callingPId: %{public}d", callerPid); @@ -4426,7 +4426,7 @@ bool AppMgrServiceInner::VerifyAPL() const return false; } - auto callerPid = IPCSkeleton::GetCallingRealPid(); + auto callerPid = IPCSkeleton::GetCallingPid(); auto appRecord = appRunningManager_->GetAppRunningRecordByPid(callerPid); if (!appRecord) { TAG_LOGE(AAFwkTag::APPMGR, "Get app running record by calling pid failed. callingPId: %{public}d", callerPid); @@ -5113,7 +5113,7 @@ int32_t AppMgrServiceInner::NotifyAppFault(const FaultData &faultData) { TAG_LOGD(AAFwkTag::APPMGR, "called."); int32_t callerUid = IPCSkeleton::GetCallingUid(); - int32_t pid = IPCSkeleton::GetCallingRealPid(); + int32_t pid = IPCSkeleton::GetCallingPid(); auto appRecord = GetAppRunningRecordByPid(pid); if (appRecord == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "no such appRecord"); @@ -6155,7 +6155,7 @@ int32_t AppMgrServiceInner::GetChildProcessInfoForSelf(ChildProcessInfo &info) TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is null"); return ERR_NO_INIT; } - auto callingPid = IPCSkeleton::GetCallingRealPid(); + auto callingPid = IPCSkeleton::GetCallingPid(); if (appRunningManager_->GetAppRunningRecordByPid(callingPid)) { TAG_LOGD(AAFwkTag::APPMGR, "record of callingPid is not child record."); return ERR_NAME_NOT_FOUND; @@ -6464,7 +6464,7 @@ void AppMgrServiceInner::SendAppLaunchEvent(const std::shared_ptrGetProcessName(); int32_t callerPid = appRecord->GetCallerPid() == -1 ? - IPCSkeleton::GetCallingRealPid() : appRecord->GetCallerPid(); + IPCSkeleton::GetCallingPid() : appRecord->GetCallerPid(); auto callerRecord = GetAppRunningRecordByPid(callerPid); if (callerRecord != nullptr) { eventInfo.callerBundleName = callerRecord->GetBundleName(); @@ -6488,7 +6488,7 @@ bool AppMgrServiceInner::IsFinalAppProcessByBundleName(const std::string &bundle auto name = bundleName; if (bundleName.empty()) { - auto callingPid = IPCSkeleton::GetCallingRealPid(); + auto callingPid = IPCSkeleton::GetCallingPid(); auto appRecord = appRunningManager_->GetAppRunningRecordByPid(callingPid); if (appRecord == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "Get app running record is nullptr."); @@ -6583,7 +6583,7 @@ void AppMgrServiceInner::SetAppAssertionPauseState(bool flag) return; } - auto callerPid = IPCSkeleton::GetCallingRealPid(); + auto callerPid = IPCSkeleton::GetCallingPid(); auto appRecord = GetAppRunningRecordByPid(callerPid); if (appRecord == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "No such appRecord pid is %{public}d.", callerPid); @@ -6602,7 +6602,7 @@ void AppMgrServiceInner::SetAppAssertionPauseState(bool flag) int32_t AppMgrServiceInner::UpdateRenderState(pid_t renderPid, int32_t state) { - int32_t hostPid = IPCSkeleton::GetCallingRealPid(); + int32_t hostPid = IPCSkeleton::GetCallingPid(); auto appRecord = GetAppRunningRecordByPid(hostPid); if (!appRecord) { TAG_LOGE(AAFwkTag::APPMGR, "No such appRecord, hostPid:%{public}d", hostPid); @@ -6794,7 +6794,7 @@ int32_t AppMgrServiceInner::SetSupportedProcessCacheSelf(bool isSupport) return result; } - auto callerPid = IPCSkeleton::GetCallingRealPid(); + auto callerPid = IPCSkeleton::GetCallingPid(); auto appRecord = GetAppRunningRecordByPid(callerPid); if (!appRecord) { TAG_LOGE(AAFwkTag::APPMGR, "no such appRecord, callerPid:%{public}d", callerPid); diff --git a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp index ce4413a425..2545463055 100644 --- a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp +++ b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp @@ -220,7 +220,7 @@ int32_t UriPermissionManagerStubImpl::CheckCalledBySandBox() TAG_LOGE(AAFwkTag::URIPERMMGR, "Get BundleManager failed!"); return INNER_ERR; } - auto callerPid = IPCSkeleton::GetCallingRealPid(); + auto callerPid = IPCSkeleton::GetCallingPid(); bool isSandbox = false; if (appMgr_->JudgeSandboxByPid(callerPid, isSandbox) != ERR_OK) { TAG_LOGE(AAFwkTag::URIPERMMGR, "JudgeSandboxByPid failed."); From b28b0edae01b2f16b95dcd557d87b4e50495d6af Mon Sep 17 00:00:00 2001 From: donglin Date: Mon, 3 Jun 2024 05:00:04 +0000 Subject: [PATCH 48/69] fix lock error Signed-off-by: donglin Change-Id: I35bcc2a079714acd3e5841ba8c62f92e8cf0ce94 --- .../interceptor/ability_interceptor_executer.h | 3 +++ .../src/interceptor/ability_interceptor_executer.cpp | 12 +++++++++--- .../src/interceptor/screen_unlock_interceptor.cpp | 6 ++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/services/abilitymgr/include/interceptor/ability_interceptor_executer.h b/services/abilitymgr/include/interceptor/ability_interceptor_executer.h index 2ca232a9d1..d0c8faf495 100644 --- a/services/abilitymgr/include/interceptor/ability_interceptor_executer.h +++ b/services/abilitymgr/include/interceptor/ability_interceptor_executer.h @@ -22,6 +22,7 @@ namespace OHOS { namespace AAFwk { +using InterceptorMap = std::unordered_map>; /** * @class AbilityInterceptorExecuter * AbilityInterceptorExecuter excute the interceptors. @@ -47,6 +48,8 @@ public: ErrCode DoProcess(AbilityInterceptorParam param); void SetTaskHandler(std::shared_ptr taskHandler); +private: + InterceptorMap GetInterceptorMapCopy(); private: std::mutex interceptorMapLock_; std::unordered_map> interceptorMap_; diff --git a/services/abilitymgr/src/interceptor/ability_interceptor_executer.cpp b/services/abilitymgr/src/interceptor/ability_interceptor_executer.cpp index 71f341b93b..be44f64183 100644 --- a/services/abilitymgr/src/interceptor/ability_interceptor_executer.cpp +++ b/services/abilitymgr/src/interceptor/ability_interceptor_executer.cpp @@ -41,9 +41,9 @@ ErrCode AbilityInterceptorExecuter::DoProcess(AbilityInterceptorParam param) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); int32_t result = ERR_OK; - std::lock_guard lock(interceptorMapLock_); - auto item = interceptorMap_.begin(); - while (item != interceptorMap_.end()) { + auto interceptorMap = GetInterceptorMapCopy(); + auto item = interceptorMap.begin(); + while (item != interceptorMap.end()) { result = (*item).second->DoProcess(param); if (result != ERR_OK) { break; @@ -66,5 +66,11 @@ void AbilityInterceptorExecuter::SetTaskHandler(std::shared_ptrSetTaskHandler(taskHandler); } } + +InterceptorMap AbilityInterceptorExecuter::GetInterceptorMapCopy() +{ + std::lock_guard lock(interceptorMapLock_); + return interceptorMap_; +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/interceptor/screen_unlock_interceptor.cpp b/services/abilitymgr/src/interceptor/screen_unlock_interceptor.cpp index 7c9472fd19..75cd22448c 100644 --- a/services/abilitymgr/src/interceptor/screen_unlock_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/screen_unlock_interceptor.cpp @@ -46,6 +46,12 @@ ErrCode ScreenUnlockInterceptor::DoProcess(AbilityInterceptorParam param) } IN_PROCESS_CALL_WITHOUT_RET(bundleMgrHelper->QueryAbilityInfo(param.want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, param.userId, targetAbilityInfo)); + if (targetAbilityInfo.applicationInfo.name.empty() || + targetAbilityInfo.applicationInfo.bundleName.empty()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Cannot find targetAbilityInfo, element uri: %{public}s", + param.want.GetElement().GetURI().c_str()); + return ERR_OK; + } } // temp add isSystemApp pass, remove after systemapp adjust From 3ecad7f963cd85b66d80ba36bbb4625b14167fca Mon Sep 17 00:00:00 2001 From: huangshiwei Date: Mon, 3 Jun 2024 17:54:31 +0800 Subject: [PATCH 49/69] huangshiwei4@huawei.com Signed-off-by: huangshiwei --- js_environment/test/unittest/BUILD.gn | 1 - .../unittest/js_env_log_unit_test/BUILD.gn | 37 ------ .../js_env_log_unit_test.cpp | 122 ------------------ .../ability_manager_service_first_test.cpp | 1 + 4 files changed, 1 insertion(+), 160 deletions(-) delete mode 100644 js_environment/test/unittest/js_env_log_unit_test/BUILD.gn delete mode 100644 js_environment/test/unittest/js_env_log_unit_test/js_env_log_unit_test.cpp diff --git a/js_environment/test/unittest/BUILD.gn b/js_environment/test/unittest/BUILD.gn index 04a5773ea1..8121c7edde 100644 --- a/js_environment/test/unittest/BUILD.gn +++ b/js_environment/test/unittest/BUILD.gn @@ -18,7 +18,6 @@ group("unittest") { testonly = true deps = [ - "js_env_log_unit_test:unittest", "js_environment_test:unittest", "source_map_test:unittest", "uncaught_exception_callback_test:unittest", diff --git a/js_environment/test/unittest/js_env_log_unit_test/BUILD.gn b/js_environment/test/unittest/js_env_log_unit_test/BUILD.gn deleted file mode 100644 index 33831d1803..0000000000 --- a/js_environment/test/unittest/js_env_log_unit_test/BUILD.gn +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (c) 2023 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 -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/test.gni") -import("../../../js_environment.gni") - -module_output_path = "ability_runtime/js_environment" - -ohos_unittest("js_env_log_test") { - module_out_path = module_output_path - include_dirs = [ "${utils_path}/include" ] - sources = [ "js_env_log_unit_test.cpp" ] - - configs = [] - - external_deps = [ - "ability_runtime:js_environment", - "c_utils:utils", - "hilog:libhilog", - ] -} - -group("unittest") { - testonly = true - - deps = [ ":js_env_log_test" ] -} diff --git a/js_environment/test/unittest/js_env_log_unit_test/js_env_log_unit_test.cpp b/js_environment/test/unittest/js_env_log_unit_test/js_env_log_unit_test.cpp deleted file mode 100644 index 2842a632c4..0000000000 --- a/js_environment/test/unittest/js_env_log_unit_test/js_env_log_unit_test.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "js_env_logger.h" -#include "hilog/log.h" -#include - -using namespace testing; -using namespace testing::ext; - -#ifndef ENV_LOG_DOMAIN -#define ENV_LOG_DOMAIN 0xD001300 -#endif - -#ifndef ENV_LOG_TAG -#define ENV_LOG_TAG "JsEnv" -#endif - -namespace OHOS { -namespace JsEnv { -void Logger(JsEnvLogLevel level, const char* fileName, const char* functionName, int line, - const char* fmt, ...) -{ - std::string cFormat = "[%{public}s(%{public}s:%{public}d)]"; - cFormat += fmt; - va_list printArgs; - va_start(printArgs, fmt); - switch (level) { - case JsEnvLogLevel::DEBUG: - HILOG_IMPL(LOG_CORE, LOG_DEBUG, ENV_LOG_DOMAIN, ENV_LOG_TAG, - cFormat.c_str(), fileName, functionName, line, printArgs); - break; - case JsEnvLogLevel::INFO: - HILOG_IMPL(LOG_CORE, LOG_INFO, ENV_LOG_DOMAIN, ENV_LOG_TAG, - cFormat.c_str(), fileName, functionName, line, printArgs); - break; - case JsEnvLogLevel::WARN: - HILOG_IMPL(LOG_CORE, LOG_WARN, ENV_LOG_DOMAIN, ENV_LOG_TAG, - cFormat.c_str(), fileName, functionName, line, printArgs); - break; - case JsEnvLogLevel::ERROR: - HILOG_IMPL(LOG_CORE, LOG_ERROR, ENV_LOG_DOMAIN, ENV_LOG_TAG, - cFormat.c_str(), fileName, functionName, line, printArgs); - break; - case JsEnvLogLevel::FATAL: - HILOG_IMPL(LOG_CORE, LOG_FATAL, ENV_LOG_DOMAIN, ENV_LOG_TAG, - cFormat.c_str(), fileName, functionName, line, printArgs); - break; - default: - break; - } - va_end(printArgs); -} - -class JsEnvLogTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; -}; - -void JsEnvLogTest::SetUpTestCase() -{ - JsEnvLogger::logger = Logger; -} - -void JsEnvLogTest::TearDownTestCase() -{} - -void JsEnvLogTest::SetUp() -{} - -void JsEnvLogTest::TearDown() -{} - -/** - * @tc.name: Logger_0100 - * @tc.desc: Logger_0100 Test - * @tc.type: FUNC - * @tc.require: issueI6I13A - */ -HWTEST_F(JsEnvLogTest, Logger_0100, TestSize.Level0) -{ - JSENV_LOG_D(">>>>>>>>TestDebug<<<<<<<<<<<"); - JSENV_LOG_I(">>>>>>>>TestInfo<<<<<<<<<<<"); - JSENV_LOG_W(">>>>>>>>TestWarning<<<<<<<<<<<"); - JSENV_LOG_E(">>>>>>>>TestError<<<<<<<<<<<"); - JSENV_LOG_F(">>>>>>>>TestFatal<<<<<<<<<<<"); -} - -/** - * @tc.name: Logger_0200 - * @tc.desc: Logger_0200 Test - * @tc.type: FUNC - * @tc.require: issueI6I13A - */ -HWTEST_F(JsEnvLogTest, Logger_0200, TestSize.Level0) -{ - JSENV_LOG_D(">>>>>>>>TestDebug<<<<<<<<<<< + %s", "with string"); - JSENV_LOG_I(">>>>>>>>TestInfo<<<<<<<<<<< + %s", "with string"); - JSENV_LOG_W(">>>>>>>>TestWarning<<<<<<<<<<< + %s", "with string"); - JSENV_LOG_E(">>>>>>>>TestError<<<<<<<<<<< + %s + %d", "with int", 32); - JSENV_LOG_F(">>>>>>>>TestFatal<<<<<<<<<<< + %s", "with string"); -} -} // namespace JsEnv -} // namespace OHOS diff --git a/test/unittest/ability_manager_service_first_test/ability_manager_service_first_test.cpp b/test/unittest/ability_manager_service_first_test/ability_manager_service_first_test.cpp index 6a7a635413..dc1fa5528e 100644 --- a/test/unittest/ability_manager_service_first_test/ability_manager_service_first_test.cpp +++ b/test/unittest/ability_manager_service_first_test/ability_manager_service_first_test.cpp @@ -1329,6 +1329,7 @@ HWTEST_F(AbilityManagerServiceFirstTest, AppRecoverKill_001, TestSize.Level1) abilityMs_->AppRecoverKill(pid, StateReason::JS_ERROR); abilityMs_->AppRecoverKill(pid, StateReason::LIFECYCLE); abilityMs_->AppRecoverKill(pid, StateReason::APP_FREEZE); + EXPECT_TRUE(abilityMs_ != nullptr); } /* From cfc643fe5b123405726521bfe3c9e9f65b44686e Mon Sep 17 00:00:00 2001 From: hanchenZz Date: Mon, 3 Jun 2024 15:19:03 +0800 Subject: [PATCH 50/69] modify constants in ability_manager_service Signed-off-by: hanchenZz --- .../src/ability_manager_service.cpp | 161 +++++++++--------- 1 file changed, 82 insertions(+), 79 deletions(-) diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index f6d19d10a3..6284296977 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -143,30 +143,33 @@ namespace { return ERR_NOT_SYSTEM_APP; \ } -const std::string ARGS_USER_ID = "-u"; -const std::string ARGS_CLIENT = "-c"; -const std::string ILLEGAL_INFOMATION = "The arguments are illegal and you can enter '-h' for help."; +constexpr const char* ARGS_USER_ID = "-u"; +constexpr const char* ARGS_CLIENT = "-c"; +constexpr const char* ILLEGAL_INFOMATION = "The arguments are illegal and you can enter '-h' for help."; + constexpr int32_t NEW_RULE_VALUE_SIZE = 6; -constexpr int64_t APP_ALIVE_TIME_MS = 1000; // Allow background startup within 1 second after application startup +constexpr int32_t APP_ALIVE_TIME_MS = 1000; // Allow background startup within 1 second after application startup constexpr int32_t REGISTER_FOCUS_DELAY = 5000; constexpr size_t OFFSET = 32; -const std::string IS_DELEGATOR_CALL = "isDelegatorCall"; +constexpr const char* IS_DELEGATOR_CALL = "isDelegatorCall"; + // Startup rule switch -const std::string COMPONENT_STARTUP_NEW_RULES = "component.startup.newRules"; -const std::string NEW_RULES_EXCEPT_LAUNCHER_SYSTEMUI = "component.startup.newRules.except.LauncherSystemUI"; -const std::string BACKGROUND_JUDGE_FLAG = "component.startup.backgroundJudge.flag"; -const std::string WHITE_LIST_ASS_WAKEUP_FLAG = "component.startup.whitelist.associatedWakeUp"; +constexpr const char* COMPONENT_STARTUP_NEW_RULES = "component.startup.newRules"; +constexpr const char* NEW_RULES_EXCEPT_LAUNCHER_SYSTEMUI = "component.startup.newRules.except.LauncherSystemUI"; +constexpr const char* BACKGROUND_JUDGE_FLAG = "component.startup.backgroundJudge.flag"; +constexpr const char* WHITE_LIST_ASS_WAKEUP_FLAG = "component.startup.whitelist.associatedWakeUp"; + // White list app -const std::string BUNDLE_NAME_SETTINGSDATA = "com.ohos.settingsdata"; +constexpr const char* BUNDLE_NAME_SETTINGSDATA = "com.ohos.settingsdata"; // Support prepare terminate constexpr int32_t PREPARE_TERMINATE_ENABLE_SIZE = 6; -const char* PREPARE_TERMINATE_ENABLE_PARAMETER = "persist.sys.prepare_terminate"; +constexpr const char* PREPARE_TERMINATE_ENABLE_PARAMETER = "persist.sys.prepare_terminate"; // UIExtension type -const std::string UIEXTENSION_TYPE_KEY = "ability.want.params.uiExtensionType"; -const std::string UIEXTENSION_TARGET_TYPE_KEY = "ability.want.params.uiExtensionTargetType"; -const std::string SYSTEM_SHARE = "share"; -const std::string SYSTEM_SHARE_TYPE = "sysPicker/share"; +constexpr const char* UIEXTENSION_TYPE_KEY = "ability.want.params.uiExtensionType"; +constexpr const char* UIEXTENSION_TARGET_TYPE_KEY = "ability.want.params.uiExtensionTargetType"; +constexpr const char* SYSTEM_SHARE = "share"; +constexpr const char* SYSTEM_SHARE_TYPE = "sysPicker/share"; // Share picker params constexpr char SHARE_PICKER_DIALOG_BUNDLE_NAME_KEY[] = "const.system.sharePicker.bundleName"; constexpr char SHARE_PICKER_DIALOG_ABILITY_NAME_KEY[] = "const.system.sharePicker.abilityName"; @@ -177,19 +180,19 @@ constexpr char TOKEN_KEY[] = "ohos.ability.params.token"; // Developer mode param constexpr char DEVELOPER_MODE_STATE[] = "const.security.developermode.state"; // Broker params key -const std::string KEY_VISIBLE_ID = "ohos.anco.param.visible"; -const std::string START_ABILITY_TYPE = "ABILITY_INNER_START_WITH_ACCOUNT"; -const std::string SHELL_ASSISTANT_BUNDLENAME = "com.huawei.shell_assistant"; -const std::string SHELL_ASSISTANT_ABILITYNAME = "MainAbility"; -const std::string AMS_DIALOG_BUNDLENAME = "com.ohos.amsdialog"; -const std::string STR_PHONE = "phone"; +constexpr const char* KEY_VISIBLE_ID = "ohos.anco.param.visible"; +constexpr const char* START_ABILITY_TYPE = "ABILITY_INNER_START_WITH_ACCOUNT"; +constexpr const char* SHELL_ASSISTANT_BUNDLENAME = "com.huawei.shell_assistant"; +constexpr const char* SHELL_ASSISTANT_ABILITYNAME = "MainAbility"; +constexpr const char* AMS_DIALOG_BUNDLENAME = "com.ohos.amsdialog"; +constexpr const char* STR_PHONE = "phone"; // Distributed continued session Id -const std::string DMS_CONTINUED_SESSION_ID = "ohos.dms.continueSessionId"; -const std::string DMS_PERSISTENT_ID = "ohos.dms.persistentId"; +constexpr const char* DMS_CONTINUED_SESSION_ID = "ohos.dms.continueSessionId"; +constexpr const char* DMS_PERSISTENT_ID = "ohos.dms.persistentId"; -const std::string DEBUG_APP = "debugApp"; -const std::string AUTO_FILL_PASSWORD_TPYE = "autoFill/password"; -const std::string AUTO_FILL_SMART_TPYE = "autoFill/smart"; +constexpr const char* DEBUG_APP = "debugApp"; +constexpr const char* AUTO_FILL_PASSWORD_TPYE = "autoFill/password"; +constexpr const char* AUTO_FILL_SMART_TPYE = "autoFill/smart"; constexpr size_t INDEX_ZERO = 0; constexpr size_t INDEX_ONE = 1; constexpr size_t INDEX_TWO = 2; @@ -197,11 +200,11 @@ constexpr size_t ARGC_THREE = 3; constexpr static char WANT_PARAMS_VIEW_DATA_KEY[] = "ohos.ability.params.viewData"; constexpr int32_t FOUNDATION_UID = 5523; -const std::string FRS_BUNDLE_NAME = "com.ohos.formrenderservice"; -const std::string FOUNDATION_PROCESS_NAME = "foundation"; -const std::string IS_PRELOAD_UIEXTENSION_ABILITY = "ability.want.params.is_preload_uiextension_ability"; -const std::string UIEXTENSION_MODAL_TYPE = "ability.want.params.modalType"; -const std::string ATOMIC_SERVICE_PREFIX = "com.atomicservice."; +constexpr const char* FRS_BUNDLE_NAME = "com.ohos.formrenderservice"; +constexpr const char* FOUNDATION_PROCESS_NAME = "foundation"; +constexpr const char* IS_PRELOAD_UIEXTENSION_ABILITY = "ability.want.params.is_preload_uiextension_ability"; +constexpr const char* UIEXTENSION_MODAL_TYPE = "ability.want.params.modalType"; +constexpr const char* ATOMIC_SERVICE_PREFIX = "com.atomicservice."; constexpr const char* PARAM_SPECIFIED_PROCESS_FLAG = "ohosSpecifiedProcessFlag"; constexpr char ASSERT_FAULT_DETAIL[] = "assertFaultDialogDetail"; @@ -231,54 +234,54 @@ using namespace std::chrono_literals; using namespace BackgroundTaskMgr; #endif const bool CONCURRENCY_MODE_FALSE = false; -const int32_t MAIN_USER_ID = 100; +constexpr int32_t MAIN_USER_ID = 100; constexpr auto DATA_ABILITY_START_TIMEOUT = 5s; constexpr int32_t NON_ANONYMIZE_LENGTH = 6; constexpr uint32_t SCENE_FLAG_NORMAL = 0; -const int32_t MAX_NUMBER_OF_DISTRIBUTED_MISSIONS = 20; -const int32_t SWITCH_ACCOUNT_TRY = 3; +constexpr int32_t MAX_NUMBER_OF_DISTRIBUTED_MISSIONS = 20; +constexpr int32_t SWITCH_ACCOUNT_TRY = 3; #ifdef ABILITY_COMMAND_FOR_TEST -const int32_t BLOCK_AMS_SERVICE_TIME = 65; +constexpr int32_t BLOCK_AMS_SERVICE_TIME = 65; #endif -const std::string EMPTY_DEVICE_ID = ""; -const int32_t APP_MEMORY_SIZE = 512; -const int32_t GET_PARAMETER_INCORRECT = -9; -const int32_t GET_PARAMETER_OTHER = -1; -const int32_t SIZE_10 = 10; -const int32_t HIDUMPER_SERVICE_UID = 1212; -const int32_t ACCOUNT_MGR_SERVICE_UID = 3058; -const int32_t BROKER_UID = 5557; -const int32_t BROKER_RESERVE_UID = 5005; -const int32_t DMS_UID = 5522; -const int32_t PREPARE_TERMINATE_TIMEOUT_MULTIPLE = 10; -const int32_t BOOTEVENT_COMPLETED_DELAY_TIME = 1000; +constexpr const char* EMPTY_DEVICE_ID = ""; +constexpr int32_t APP_MEMORY_SIZE = 512; +constexpr int32_t GET_PARAMETER_INCORRECT = -9; +constexpr int32_t GET_PARAMETER_OTHER = -1; +constexpr int32_t SIZE_10 = 10; +constexpr int32_t HIDUMPER_SERVICE_UID = 1212; +constexpr int32_t ACCOUNT_MGR_SERVICE_UID = 3058; +constexpr int32_t BROKER_UID = 5557; +constexpr int32_t BROKER_RESERVE_UID = 5005; +constexpr int32_t DMS_UID = 5522; +constexpr int32_t PREPARE_TERMINATE_TIMEOUT_MULTIPLE = 10; +constexpr int32_t BOOTEVENT_COMPLETED_DELAY_TIME = 1000; constexpr int32_t BOOTEVENT_BOOT_ANIMATION_READY_SIZE = 6; -const std::string BUNDLE_NAME_KEY = "bundleName"; -const std::string DM_PKG_NAME = "ohos.distributedhardware.devicemanager"; -const std::string ACTION_CHOOSE = "ohos.want.action.select"; -const std::string HIGHEST_PRIORITY_ABILITY_ENTITY = "flag.home.intent.from.system"; -const std::string DMS_API_VERSION = "dmsApiVersion"; -const std::string DMS_IS_CALLER_BACKGROUND = "dmsIsCallerBackGround"; -const std::string DMS_PROCESS_NAME = "distributedsched"; -const std::string DMS_MISSION_ID = "dmsMissionId"; -const std::string BOOTEVENT_APPFWK_READY = "bootevent.appfwk.ready"; -const std::string BOOTEVENT_BOOT_COMPLETED = "bootevent.boot.completed"; -const std::string BOOTEVENT_BOOT_ANIMATION_STARTED = "bootevent.bootanimation.started"; -const std::string BOOTEVENT_BOOT_ANIMATION_READY = "bootevent.bootanimation.ready"; -const std::string NEED_STARTINGWINDOW = "ohos.ability.NeedStartingWindow"; -const std::string PERMISSIONMGR_BUNDLE_NAME = "com.ohos.permissionmanager"; -const std::string PERMISSIONMGR_ABILITY_NAME = "com.ohos.permissionmanager.GrantAbility"; -const std::string IS_CALL_BY_SCB = "isCallBySCB"; -const std::string SPECIFY_TOKEN_ID = "specifyTokenId"; -const std::string PROCESS_SUFFIX = "embeddable"; -const int DEFAULT_DMS_MISSION_ID = -1; -const char* PARAM_PREVENT_STARTABILITY = "persist.sys.abilityms.prevent_startability"; -const std::string SUSPEND_SERVICE_CONFIG_FILE = "/etc/efficiency_manager/prevent_startability_whitelist.json"; -const int32_t MAX_BUFFER = 2048; +constexpr const char* BUNDLE_NAME_KEY = "bundleName"; +constexpr const char* DM_PKG_NAME = "ohos.distributedhardware.devicemanager"; +constexpr const char* ACTION_CHOOSE = "ohos.want.action.select"; +constexpr const char* HIGHEST_PRIORITY_ABILITY_ENTITY = "flag.home.intent.from.system"; +constexpr const char* DMS_API_VERSION = "dmsApiVersion"; +constexpr const char* DMS_IS_CALLER_BACKGROUND = "dmsIsCallerBackGround"; +constexpr const char* DMS_PROCESS_NAME = "distributedsched"; +constexpr const char* DMS_MISSION_ID = "dmsMissionId"; +constexpr const char* BOOTEVENT_APPFWK_READY = "bootevent.appfwk.ready"; +constexpr const char* BOOTEVENT_BOOT_COMPLETED = "bootevent.boot.completed"; +constexpr const char* BOOTEVENT_BOOT_ANIMATION_STARTED = "bootevent.bootanimation.started"; +constexpr const char* BOOTEVENT_BOOT_ANIMATION_READY = "bootevent.bootanimation.ready"; +constexpr const char* NEED_STARTINGWINDOW = "ohos.ability.NeedStartingWindow"; +constexpr const char* PERMISSIONMGR_BUNDLE_NAME = "com.ohos.permissionmanager"; +constexpr const char* PERMISSIONMGR_ABILITY_NAME = "com.ohos.permissionmanager.GrantAbility"; +constexpr const char* IS_CALL_BY_SCB = "isCallBySCB"; +constexpr const char* SPECIFY_TOKEN_ID = "specifyTokenId"; +constexpr const char* PROCESS_SUFFIX = "embeddable"; +constexpr int32_t DEFAULT_DMS_MISSION_ID = -1; +constexpr const char* PARAM_PREVENT_STARTABILITY = "persist.sys.abilityms.prevent_startability"; +constexpr const char* SUSPEND_SERVICE_CONFIG_FILE = "/etc/efficiency_manager/prevent_startability_whitelist.json"; +constexpr int32_t MAX_BUFFER = 2048; nlohmann::json whiteListJsonObj; -const int32_t API12 = 12; -const int32_t API_VERSION_MOD = 100; -const std::string WHITE_LIST = "white_list"; +constexpr int32_t API12 = 12; +constexpr int32_t API_VERSION_MOD = 100; +constexpr const char* WHITE_LIST = "white_list"; const std::map AbilityManagerService::dumpMap = { std::map::value_type("--all", KEY_DUMP_ALL), std::map::value_type("-a", KEY_DUMP_ALL), @@ -375,7 +378,7 @@ void AbilityManagerService::OnStart() return; } - SetParameter(BOOTEVENT_APPFWK_READY.c_str(), "true"); + SetParameter(BOOTEVENT_APPFWK_READY, "true"); AddSystemAbilityListener(BACKGROUND_TASK_MANAGER_SERVICE_ID); AddSystemAbilityListener(DISTRIBUTED_SCHED_SA_ID); AddSystemAbilityListener(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); @@ -479,11 +482,11 @@ void AbilityManagerService::InitPushTask() auto bootCompletedTask = [handler = taskHandler_]() { if (ApplicationUtil::IsBootCompleted()) { auto task = []() { - ApplicationUtil::AppFwkBootEventCallback(BOOTEVENT_BOOT_COMPLETED.c_str(), "true", nullptr); + ApplicationUtil::AppFwkBootEventCallback(BOOTEVENT_BOOT_COMPLETED, "true", nullptr); }; handler->SubmitTask(task, "BootCompletedDelayTask", BOOTEVENT_COMPLETED_DELAY_TIME); } else { - WatchParameter(BOOTEVENT_BOOT_COMPLETED.c_str(), ApplicationUtil::AppFwkBootEventCallback, nullptr); + WatchParameter(BOOTEVENT_BOOT_COMPLETED, ApplicationUtil::AppFwkBootEventCallback, nullptr); } }; if (!ParseJsonFromBoot(whiteListJsonObj, SUSPEND_SERVICE_CONFIG_FILE, WHITE_LIST)) { @@ -3422,7 +3425,7 @@ bool AbilityManagerService::GetLocalDeviceId(std::string& localDeviceId) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); auto localNode = std::make_unique(); - int32_t errCode = GetLocalNodeDeviceInfo(DM_PKG_NAME.c_str(), localNode.get()); + int32_t errCode = GetLocalNodeDeviceInfo(DM_PKG_NAME, localNode.get()); if (errCode != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "AbilityManagerService::GetLocalNodeDeviceInfo errCode = %{public}d", errCode); return false; @@ -10308,15 +10311,15 @@ bool AbilityManagerService::CheckCallerIsDmsProcess() void AbilityManagerService::WaitBootAnimationStart() { char value[BOOTEVENT_BOOT_ANIMATION_READY_SIZE] = ""; - int32_t ret = GetParameter(BOOTEVENT_BOOT_ANIMATION_READY.c_str(), "", value, + int32_t ret = GetParameter(BOOTEVENT_BOOT_ANIMATION_READY, "", value, BOOTEVENT_BOOT_ANIMATION_READY_SIZE); if (ret > 0 && !std::strcmp(value, "false")) { // Get new param success and new param is not ready, wait the new param. - WaitParameter(BOOTEVENT_BOOT_ANIMATION_READY.c_str(), "true", + WaitParameter(BOOTEVENT_BOOT_ANIMATION_READY, "true", AmsConfigurationParameter::GetInstance().GetBootAnimationTimeoutTime()); } else if (ret <= 0 || !std::strcmp(value, "")) { // Get new param failed or new param is not set, wait the old param. - WaitParameter(BOOTEVENT_BOOT_ANIMATION_STARTED.c_str(), "true", + WaitParameter(BOOTEVENT_BOOT_ANIMATION_STARTED, "true", AmsConfigurationParameter::GetInstance().GetBootAnimationTimeoutTime()); } // other, the animation is ready, not wait. From d1b9427d31eba28b5c260e46a052ac42f97add87 Mon Sep 17 00:00:00 2001 From: xia Date: Mon, 3 Jun 2024 17:26:38 +0800 Subject: [PATCH 51/69] =?UTF-8?q?401=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xia --- .../ability_manager/js_ability_manager.cpp | 44 +++++++------- .../app/js_app_manager/js_app_manager.cpp | 58 +++++++++---------- .../js_app_manager/js_app_manager_utils.cpp | 6 +- .../js_dialog_request/js_dialog_request.cpp | 18 +++--- .../js_mission_manager/mission_manager.cpp | 40 ++++++------- .../native/js_service_extension_context.cpp | 32 +++++----- .../serviceroutermgr/service_router_mgr.cpp | 2 +- 7 files changed, 99 insertions(+), 101 deletions(-) diff --git a/frameworks/js/napi/ability_manager/js_ability_manager.cpp b/frameworks/js/napi/ability_manager/js_ability_manager.cpp index 1d67686f66..18a3ba11f8 100644 --- a/frameworks/js/napi/ability_manager/js_ability_manager.cpp +++ b/frameworks/js/napi/ability_manager/js_ability_manager.cpp @@ -157,7 +157,7 @@ private: } if (!AppExecFwk::IsTypeForNapiValue(env, argv[INDEX_ONE], napi_object)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Invalid param."); - ThrowInvalidParamError(env, "Parse param observer failed, must be a AbilityForegroundStateObserver"); + ThrowInvalidParamError(env, "Parse param observer failed, must be a AbilityForegroundStateObserver."); return CreateJsUndefined(env); } @@ -165,7 +165,7 @@ private: if (type == ON_OFF_TYPE_ABILITY_FOREGROUND_STATE) { return OnOnAbilityForeground(env, argc, argv); } - ThrowInvalidParamError(env, "Parse param type failed, must be a string, value must be abilityForegroundState"); + ThrowInvalidParamError(env, "Parse param type failed, must be a string, value must be abilityForegroundState."); return CreateJsUndefined(env); } @@ -203,7 +203,7 @@ private: } if (argc == ARGC_TWO && !AppExecFwk::IsTypeForNapiValue(env, argv[INDEX_ONE], napi_object)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Invalid param."); - ThrowInvalidParamError(env, "Parse param observer failed, must be a AbilityForegroundStateObserver"); + ThrowInvalidParamError(env, "Parse param observer failed, must be a AbilityForegroundStateObserver."); return CreateJsUndefined(env); } @@ -211,7 +211,7 @@ private: if (type == ON_OFF_TYPE_ABILITY_FOREGROUND_STATE) { return OnOffAbilityForeground(env, argc, argv); } - ThrowInvalidParamError(env, "Parse param type failed, must be a string, value must be abilityForegroundState"); + ThrowInvalidParamError(env, "Parse param type failed, must be a string, value must be abilityForegroundState."); return CreateJsUndefined(env); } @@ -243,19 +243,19 @@ private: std::string assertSessionStr; if (!ConvertFromJsValue(env, argv[INDEX_ZERO], assertSessionStr) || !CheckIsNumString(assertSessionStr)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Convert session id error."); - ThrowInvalidParamError(env, "Parse param sessionId failed, must be a string"); + ThrowInvalidParamError(env, "Parse param sessionId failed, must be a string."); return CreateJsUndefined(env); } uint64_t assertSessionId = std::stoull(assertSessionStr); if (assertSessionId == 0) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Convert session id failed."); - ThrowInvalidParamError(env, "Parse param sessionId failed, value must not be equal to zero"); + ThrowInvalidParamError(env, "Parse param sessionId failed, value must not be equal to zero."); return CreateJsUndefined(env); } int32_t userStatus; if (!ConvertFromJsValue(env, argv[INDEX_ONE], userStatus)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Convert status failed."); - ThrowInvalidParamError(env, "Parse param status failed, must be a UserStatus"); + ThrowInvalidParamError(env, "Parse param status failed, must be a UserStatus."); return CreateJsUndefined(env); } @@ -346,7 +346,7 @@ private: int upperLimit = -1; if (!ConvertFromJsValue(env, info.argv[0], upperLimit)) { #ifdef ENABLE_ERRCODE - ThrowInvalidParamError(env, "Parse param upperLimit failed, must be a number"); + ThrowInvalidParamError(env, "Parse param upperLimit failed, must be a number."); #endif return CreateJsUndefined(env); } @@ -397,7 +397,7 @@ private: AppExecFwk::Configuration changeConfig; if (!UnwrapConfiguration(env, info.argv[0], changeConfig)) { #ifdef ENABLE_ERRCODE - ThrowInvalidParamError(env, "Parse param config failed, must be a Configuration"); + ThrowInvalidParamError(env, "Parse param config failed, must be a Configuration."); #else complete = [](napi_env env, NapiAsyncTask& task, int32_t status) { task.Reject(env, CreateJsError(env, ERR_INVALID_VALUE, "config is invalid.")); @@ -467,7 +467,7 @@ private: } int32_t missionId = -1; if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], missionId)) { - ThrowInvalidParamError(env, "Parse param missionId failed, must be a number"); + ThrowInvalidParamError(env, "Parse param missionId failed, must be a number."); return CreateJsUndefined(env); } napi_value lastParam = info.argc > ARGC_ONE ? info.argv[INDEX_ONE] : nullptr; @@ -515,7 +515,7 @@ private: int reqCode = 0; if (!ConvertFromJsValue(env, info.argv[1], reqCode)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Get requestCode param error"); - ThrowInvalidParamError(env, "Parse param requestCode failed, must be a number"); + ThrowInvalidParamError(env, "Parse param requestCode failed, must be a number."); break; } @@ -523,7 +523,7 @@ private: int resultCode = ERR_OK; if (!AppExecFwk::UnWrapAbilityResult(env, info.argv[0], resultCode, want)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Unrwrap abilityResult param error"); - ThrowInvalidParamError(env, "Parse param parameter failed, must be a AbilityResult"); + ThrowInvalidParamError(env, "Parse param parameter failed, must be a AbilityResult."); break; } @@ -580,17 +580,15 @@ private: std::string bundleName; if (!ConvertFromJsValue(env, argv[INDEX_ZERO], bundleName) || bundleName.empty()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Convert session id error."); - auto errMsg = "Non empty package name needs to be provided"; - ThrowError(env, static_cast(AbilityErrorCode::ERROR_CODE_INVALID_PARAM), errMsg); + TAG_LOGE(AAFwkTag::ABILITYMGR, "Parse param bundleName failed, must be a string."); + ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string."); return CreateJsUndefined(env); } bool enableState = false; if (!ConvertFromJsValue(env, argv[INDEX_ONE], enableState)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Convert status failed."); - auto errMsg = "The second parameter needs to provide a Boolean type setting value"; - ThrowError(env, static_cast(AbilityErrorCode::ERROR_CODE_INVALID_PARAM), errMsg); + TAG_LOGE(AAFwkTag::ABILITYMGR, "Parse param enable failed, must be a boolean."); + ThrowInvalidParamError(env, "Parse param enable failed, must be a boolean."); return CreateJsUndefined(env); } @@ -633,27 +631,27 @@ private: bool stageMode = false; napi_status status = OHOS::AbilityRuntime::IsStageContext(env, info.argv[0], stageMode); if (status != napi_ok || !stageMode) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "it is not a stage mode"); - ThrowInvalidParamError(env, "Parse param context failed, must be stageMode"); + TAG_LOGE(AAFwkTag::ABILITYMGR, "it is not a context of stageMode"); + ThrowInvalidParamError(env, "Parse param context failed, must be a context of stageMode."); return CreateJsUndefined(env); } auto context = OHOS::AbilityRuntime::GetStageModeContext(env, info.argv[0]); if (context == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "get context failed"); - ThrowInvalidParamError(env, "Parse param context failed, must not be nullptr"); + ThrowInvalidParamError(env, "Parse param context failed, must not be nullptr."); return CreateJsUndefined(env); } auto uiAbilityContext = AbilityRuntime::Context::ConvertTo(context); if (uiAbilityContext == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "convert to UIAbility context failed"); - ThrowInvalidParamError(env, "Parse param context failed, must be UIAbilityContext"); + ThrowInvalidParamError(env, "Parse param context failed, must be UIAbilityContext."); return CreateJsUndefined(env); } std::string appId; if (!ConvertFromJsValue(env, info.argv[1], appId)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "OnOpenAtomicService, parse appId failed."); - ThrowInvalidParamError(env, "Parse param appId failed, must be a string"); + ThrowInvalidParamError(env, "Parse param appId failed, must be a string."); return CreateJsUndefined(env); } diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp index fe67b114f0..01ee913081 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp @@ -254,7 +254,7 @@ private: if (!CheckOnOffType(env, argc, argv)) { ThrowInvalidParamError(env, "Parse param type failed, must be a string," - "value must be applicationState, appForegroundState or abilityFirstFrameState"); + "value must be applicationState, appForegroundState or abilityFirstFrameState."); return CreateJsUndefined(env); } @@ -300,7 +300,7 @@ private: } if (!AppExecFwk::IsTypeForNapiValue(env, argv[INDEX_ONE], napi_object)) { TAG_LOGE(AAFwkTag::APPMGR, "Invalid param"); - ThrowInvalidParamError(env, "Parse param observer failed, must be a ApplicationStateObserver"); + ThrowInvalidParamError(env, "Parse param observer failed, must be a ApplicationStateObserver."); return CreateJsUndefined(env); } std::vector bundleNameList; @@ -343,7 +343,7 @@ private: } if (!AppExecFwk::IsTypeForNapiValue(env, argv[INDEX_ONE], napi_object)) { TAG_LOGE(AAFwkTag::APPMGR, "Invalid param."); - ThrowInvalidParamError(env, "Parse param observer failed, must be a AppForegroundStateObserver"); + ThrowInvalidParamError(env, "Parse param observer failed, must be a AppForegroundStateObserver."); return CreateJsUndefined(env); } if (observerForeground_ == nullptr) { @@ -406,7 +406,7 @@ private: if (!AppExecFwk::IsTypeForNapiValue(env, argv[INDEX_ONE], napi_object) || !IsJSFunctionExist(env, argv[INDEX_ONE], "onAbilityFirstFrameDrawn")) { TAG_LOGE(AAFwkTag::APPMGR, "Invalid param."); - ThrowInvalidParamError(env, "Parse param observer failed, must be a AbilityFirstFrameStateObserver"); + ThrowInvalidParamError(env, "Parse param observer failed, must be a AbilityFirstFrameStateObserver."); return CreateJsUndefined(env); } std::string bundleName; @@ -414,7 +414,7 @@ private: if (!IsParasNullOrUndefined(env, argv[INDEX_TWO]) && (!ConvertFromJsValue(env, argv[INDEX_TWO], bundleName) || bundleName.empty())) { TAG_LOGE(AAFwkTag::APPMGR, "Get bundleName error or bundleName empty!"); - ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string"); + ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string."); return CreateJsUndefined(env); } } @@ -460,7 +460,7 @@ private: (!AppExecFwk::IsTypeForNapiValue(env, argv[INDEX_ONE], napi_object) || !IsJSFunctionExist(env, argv[INDEX_ONE], "onAbilityFirstFrameDrawn"))) { TAG_LOGE(AAFwkTag::APPMGR, "Invalid param."); - ThrowInvalidParamError(env, "Parse param observer failed, must be a AbilityFirstFrameStateObserver"); + ThrowInvalidParamError(env, "Parse param observer failed, must be a AbilityFirstFrameStateObserver."); return CreateJsUndefined(env); } } @@ -485,20 +485,20 @@ private: } if (!CheckOnOffType(env, argc, argv)) { ThrowInvalidParamError(env, "Parse param type failed, must be a string," - "value must be applicationState, appForegroundState or abilityFirstFrameState"); + "value must be applicationState, appForegroundState or abilityFirstFrameState."); return CreateJsUndefined(env); } int64_t observerId = -1; napi_get_value_int64(env, argv[INDEX_ONE], &observerId); if (observer_ == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "observer is nullptr, please register first"); - ThrowInvalidParamError(env, "observer is nullptr, please register first"); + TAG_LOGE(AAFwkTag::APPMGR, "observer is nullptr, please register first."); + ThrowInvalidParamError(env, "observer is nullptr, please register first."); return CreateJsUndefined(env); } if (!observer_->FindObserverByObserverId(observerId)) { TAG_LOGE(AAFwkTag::APPMGR, "not find observer, observer:%{public}d", static_cast(observerId)); - ThrowInvalidParamError(env, "not find observerId"); + ThrowInvalidParamError(env, "not find observerId."); return CreateJsUndefined(env); } TAG_LOGD(AAFwkTag::APPMGR, "find observer exist observer:%{public}d", static_cast(observerId)); @@ -540,7 +540,7 @@ private: int32_t observerId = -1; if (!ConvertFromJsValue(env, argv[INDEX_ONE], observerId)) { TAG_LOGE(AAFwkTag::APPMGR, "Parse observerId failed"); - ThrowInvalidParamError(env, "Parse param observerId failed, must be a number"); + ThrowInvalidParamError(env, "Parse param observerId failed, must be a number."); return CreateJsUndefined(env); } @@ -551,7 +551,7 @@ private: } if (!observerSync_->FindObserverByObserverId(observerId)) { TAG_LOGE(AAFwkTag::APPMGR, "not find observer, observer:%{public}d", static_cast(observerId)); - ThrowInvalidParamError(env, "not find observerId"); + ThrowInvalidParamError(env, "not find observerId."); return CreateJsUndefined(env); } int32_t ret = appManager_->UnregisterApplicationStateObserver(observerSync_); @@ -575,7 +575,7 @@ private: } if (argc == ARGC_TWO && !AppExecFwk::IsTypeForNapiValue(env, argv[INDEX_ONE], napi_object)) { TAG_LOGE(AAFwkTag::APPMGR, "Invalid param."); - ThrowInvalidParamError(env, "Parse param observer failed, must be a AppForegroundStateObserver"); + ThrowInvalidParamError(env, "Parse param observer failed, must be a AppForegroundStateObserver."); return CreateJsUndefined(env); } if (observerForeground_ == nullptr || appManager_ == nullptr) { @@ -673,7 +673,7 @@ private: std::string bundleName; if (!ConvertFromJsValue(env, argv[0], bundleName)) { TAG_LOGE(AAFwkTag::APPMGR, "get bundleName failed!"); - ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string"); + ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string."); return CreateJsUndefined(env); } auto info = std::make_shared(); @@ -713,12 +713,12 @@ private: int32_t bundleType = -1; if (!ConvertFromJsValue(env, argv[INDEX_ZERO], bundleType)) { TAG_LOGE(AAFwkTag::APPMGR, "get bundleType error!"); - ThrowInvalidParamError(env, "failed to get bundleType"); + ThrowInvalidParamError(env, "Parse param bundleType failed, must be a BundleType."); return CreateJsUndefined(env); } if (bundleType < 0) { TAG_LOGE(AAFwkTag::APPMGR, "Invalid bundle type:%{public}d", bundleType); - ThrowInvalidParamError(env, "invalid bundle type"); + ThrowInvalidParamError(env, "Parse param bundleType failed, must not be less then zero."); return CreateJsUndefined(env); } NapiAsyncTask::CompleteCallback complete = @@ -779,7 +779,7 @@ private: std::string bundleName; if (!ConvertFromJsValue(env, argv[0], bundleName)) { TAG_LOGE(AAFwkTag::APPMGR, "get bundleName error!"); - ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string"); + ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string."); return CreateJsUndefined(env); } @@ -818,7 +818,7 @@ private: std::string bundleName; if (!ConvertFromJsValue(env, argv[0], bundleName)) { TAG_LOGE(AAFwkTag::APPMGR, "get bundleName failed!"); - ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string"); + ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string."); return CreateJsUndefined(env); } @@ -856,14 +856,14 @@ private: std::string bundleName; if (!ConvertFromJsValue(env, argv[0], bundleName)) { TAG_LOGE(AAFwkTag::APPMGR, "get bundleName wrong!"); - ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string"); + ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string."); return CreateJsUndefined(env); } uint32_t versionCode = 0; if (!ConvertFromJsValue(env, argv[1], versionCode)) { TAG_LOGE(AAFwkTag::APPMGR, "get versionCode failed!"); - ThrowInvalidParamError(env, "Parse param versionCode failed, must be a number"); + ThrowInvalidParamError(env, "Parse param versionCode failed, must be a number."); return CreateJsUndefined(env); } @@ -898,13 +898,13 @@ private: std::string bundleName; if (!ConvertFromJsValue(env, argv[0], bundleName)) { TAG_LOGE(AAFwkTag::APPMGR, "Parse bundleName failed"); - ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string"); + ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string."); return CreateJsUndefined(env); } int32_t accountId = -1; if (!ConvertFromJsValue(env, argv[1], accountId)) { TAG_LOGE(AAFwkTag::APPMGR, "Parse userId failed"); - ThrowInvalidParamError(env, "Parse param accountId failed, must be a number"); + ThrowInvalidParamError(env, "Parse param accountId failed, must be a number."); return CreateJsUndefined(env); } @@ -984,7 +984,7 @@ private: int32_t pid; if (!ConvertFromJsValue(env, argv[0], pid)) { TAG_LOGE(AAFwkTag::APPMGR, "get pid failed"); - ThrowInvalidParamError(env, "Parse param pid failed, must be a number"); + ThrowInvalidParamError(env, "Parse param pid failed, must be a number."); return CreateJsUndefined(env); } @@ -1023,7 +1023,7 @@ private: bool isPromiseType = false; if (!ConvertFromJsValue(env, argv[0], bundleName)) { TAG_LOGE(AAFwkTag::APPMGR, "First parameter must be string"); - ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string"); + ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string."); return CreateJsUndefined(env); } if (argc == ARGC_ONE) { @@ -1035,11 +1035,11 @@ private: } else if (argc == ARGC_THREE) { if (!ConvertFromJsValue(env, argv[1], userId)) { TAG_LOGW(AAFwkTag::APPMGR, "Must input userid and use callback when argc is three."); - ThrowInvalidParamError(env, "Parse param userId failed, must be a number"); + ThrowInvalidParamError(env, "Parse param userId failed, must be a number."); return CreateJsUndefined(env); } } else { - ThrowInvalidParamError(env, "The number of param exceeded"); + ThrowInvalidParamError(env, "The number of param exceeded."); return CreateJsUndefined(env); } @@ -1076,7 +1076,7 @@ private: std::string bundleName; if (!ConvertFromJsValue(env, argv[0], bundleName)) { TAG_LOGE(AAFwkTag::APPMGR, "Get bundle name wrong."); - ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string"); + ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string."); return CreateJsUndefined(env); } @@ -1121,13 +1121,13 @@ private: std::string bundleName; if (!ConvertFromJsValue(env, argv[0], bundleName)) { TAG_LOGE(AAFwkTag::APPMGR, "Get bundle name wrong."); - ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string"); + ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string."); return CreateJsUndefined(env); } int32_t appCloneIndex = 0; if (argc > ARGC_ONE && !ConvertFromJsValue(env, argv[1], appCloneIndex)) { TAG_LOGE(AAFwkTag::APPMGR, "Get appCloneIndex wrong."); - ThrowInvalidParamError(env, "Parse param appCloneIndex failed, must be a string"); + ThrowInvalidParamError(env, "Parse param appCloneIndex failed, must be a string."); return CreateJsUndefined(env); } diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager_utils.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager_utils.cpp index f339fa22e8..f2f016bfe7 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager_utils.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager_utils.cpp @@ -276,12 +276,12 @@ bool ConvertPreloadApplicationParam(napi_env env, size_t argc, napi_value *argv, { if (!ConvertFromJsValue(env, argv[ARG_INDEX_0], param.bundleName)) { TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication get param bundleName failed."); - errorMsg = "Param bundleName must be a valid string."; + errorMsg = "Parse param bundleName failed, must be a valid string."; return false; } if (!ConvertFromJsValue(env, argv[ARG_INDEX_1], param.userId)) { TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication get param userId failed."); - errorMsg = "Param userId must be a valid number."; + errorMsg = "Parse param userId failed, must be a valid number."; return false; } if (!ConvertFromJsValue(env, argv[ARG_INDEX_2], param.preloadMode) @@ -292,7 +292,7 @@ bool ConvertPreloadApplicationParam(napi_env env, size_t argc, napi_value *argv, } if (argc > ARG_INDEX_3 && !ConvertFromJsValue(env, argv[ARG_INDEX_3], param.appIndex)) { TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication get param appIndex failed."); - errorMsg = "Param appIndex must be a valid number."; + errorMsg = "Parse param appIndex failed, must be a valid number."; return false; } return true; diff --git a/frameworks/js/napi/js_dialog_request/js_dialog_request.cpp b/frameworks/js/napi/js_dialog_request/js_dialog_request.cpp index ff9d5239f5..717af3c4dc 100755 --- a/frameworks/js/napi/js_dialog_request/js_dialog_request.cpp +++ b/frameworks/js/napi/js_dialog_request/js_dialog_request.cpp @@ -86,15 +86,15 @@ private: OHOS::AAFwk::Want want; if (!OHOS::AppExecFwk::UnwrapWant(env, info.argv[0], want)) { - TAG_LOGE(AAFwkTag::DIALOG, "The input want is invalid."); - ThrowInvalidParamError(env, "Parameter error: The input want is invalid."); + TAG_LOGE(AAFwkTag::DIALOG, "Parse param want failed, must be a Want."); + ThrowInvalidParamError(env, "Parse param want failed, must be a Want."); return CreateJsUndefined(env); } sptr callerToken = want.GetRemoteObject(RequestConstants::REQUEST_TOKEN_KEY); if (!callerToken) { - TAG_LOGE(AAFwkTag::DIALOG, "Can not get token from target want."); - ThrowInvalidParamError(env, "Parameter error: Can not get token from target want."); + TAG_LOGE(AAFwkTag::DIALOG, "get token from target want failed."); + ThrowInvalidParamError(env, "Parameter error: get token from target want failed."); return CreateJsUndefined(env); } int32_t left = want.GetIntParam(RequestConstants::WINDOW_RECTANGLE_LEFT_KEY, 0); @@ -105,8 +105,8 @@ private: auto requestInfo = new RequestInfo(callerToken, left, top, width, height); auto jsRequestInfo = RequestInfo::WrapRequestInfo(env, requestInfo); if (jsRequestInfo == nullptr) { - TAG_LOGE(AAFwkTag::DIALOG, "Can not wrap request info from target request."); - ThrowInvalidParamError(env, "Parameter error: Can not wrap request info from target request."); + TAG_LOGE(AAFwkTag::DIALOG, "Wrap Param requestInfo failed, must be a RequestInfo."); + ThrowInvalidParamError(env, "Wrap Param requestInfo failed, must be a RequestInfo."); return CreateJsUndefined(env); } @@ -125,14 +125,14 @@ private: OHOS::AAFwk::Want want; if (!OHOS::AppExecFwk::UnwrapWant(env, info.argv[0], want)) { TAG_LOGE(AAFwkTag::DIALOG, "The input want is invalid."); - ThrowInvalidParamError(env, "Parameter error: The input want is invalid."); + ThrowInvalidParamError(env, "Parse param want failed, must be a Want."); return CreateJsUndefined(env); } sptr remoteObj = want.GetRemoteObject(RequestConstants::REQUEST_CALLBACK_KEY); if (!remoteObj) { - TAG_LOGE(AAFwkTag::DIALOG, "Can not get callback from target want."); - ThrowInvalidParamError(env, "Parameter error: Can not get callback from target want."); + TAG_LOGE(AAFwkTag::DIALOG, "Wrap Param requestCallback failed, must be a RequestCallback."); + ThrowInvalidParamError(env, "Wrap Param requestCallback failed, must be a RequestCallback."); return CreateJsUndefined(env); } diff --git a/frameworks/js/napi/js_mission_manager/mission_manager.cpp b/frameworks/js/napi/js_mission_manager/mission_manager.cpp index aea7139e60..4bf647d335 100755 --- a/frameworks/js/napi/js_mission_manager/mission_manager.cpp +++ b/frameworks/js/napi/js_mission_manager/mission_manager.cpp @@ -146,7 +146,7 @@ private: } if (!CheckOnOffType(env, argc, argv)) { - ThrowInvalidParamError(env, "Parse param type failed, must be a string, value must be mission"); + ThrowInvalidParamError(env, "Parse param type failed, must be a string, value must be mission."); return CreateJsUndefined(env); } @@ -183,7 +183,7 @@ private: } if (!AppExecFwk::IsTypeForNapiValue(env, argv[1], napi_object)) { TAG_LOGE(AAFwkTag::MISSION, "Invalid param"); - ThrowInvalidParamError(env, "Parse param listener failed, must be a MissionListener"); + ThrowInvalidParamError(env, "Parse param listener failed, must be a MissionListener."); return CreateJsUndefined(env); } @@ -230,14 +230,14 @@ private: } if (!CheckOnOffType(env, argc, argv)) { - ThrowInvalidParamError(env, "Parse param type failed, must be a string, value must be mission"); + ThrowInvalidParamError(env, "Parse param type failed, must be a string, value must be mission."); return CreateJsUndefined(env); } int32_t missionListenerId = -1; if (!ConvertFromJsValue(env, argv[ARGC_ONE], missionListenerId)) { TAG_LOGE(AAFwkTag::MISSION, "Parse missionListenerId failed"); - ThrowInvalidParamError(env, "Parse param listenerId failed, must be a number"); + ThrowInvalidParamError(env, "Parse param listenerId failed, must be a number."); return CreateJsUndefined(env); } @@ -282,7 +282,7 @@ private: int32_t missionListenerId = -1; if (!ConvertFromJsValue(env, argv[INDEX_ONE], missionListenerId)) { TAG_LOGE(AAFwkTag::MISSION, "Parse missionListenerId failed"); - ThrowInvalidParamError(env, "Parse param listenerId failed, must be a number"); + ThrowInvalidParamError(env, "Parse param listenerId failed, must be a number."); return CreateJsUndefined(env); } @@ -326,13 +326,13 @@ private: std::string deviceId; if (!ConvertFromJsValue(env, argv[0], deviceId)) { TAG_LOGE(AAFwkTag::MISSION, "Parse deviceId failed"); - ThrowInvalidParamError(env, "Parse param deviceId failed, must be a string"); + ThrowInvalidParamError(env, "Parse param deviceId failed, must be a string."); return CreateJsUndefined(env); } int numMax = -1; if (!ConvertFromJsValue(env, argv[1], numMax)) { TAG_LOGE(AAFwkTag::MISSION, "Parse numMax failed"); - ThrowInvalidParamError(env, "Parse param numMax failed, must be a number"); + ThrowInvalidParamError(env, "Parse param numMax failed, must be a number."); return CreateJsUndefined(env); } @@ -366,13 +366,13 @@ private: std::string deviceId; if (!ConvertFromJsValue(env, argv[0], deviceId)) { TAG_LOGE(AAFwkTag::MISSION, "Parse deviceId failed"); - ThrowInvalidParamError(env, "Parse param deviceId failed, must be a string"); + ThrowInvalidParamError(env, "Parse param deviceId failed, must be a string."); return CreateJsUndefined(env); } int32_t missionId = -1; if (!ConvertFromJsValue(env, argv[1], missionId)) { TAG_LOGE(AAFwkTag::MISSION, "Parse missionId failed"); - ThrowInvalidParamError(env, "Parse param missionId failed, must be a number"); + ThrowInvalidParamError(env, "Parse param missionId failed, must be a number."); return CreateJsUndefined(env); } @@ -467,13 +467,13 @@ private: if (!ConvertFromJsValue(env, argv[0], deviceId)) { TAG_LOGE(AAFwkTag::MISSION, "missionSnapshot: Parse deviceId failed"); - ThrowInvalidParamError(env, "Parse param deviceId failed, must be a string"); + ThrowInvalidParamError(env, "Parse param deviceId failed, must be a string."); return false; } if (!ConvertFromJsValue(env, argv[1], missionId)) { TAG_LOGE(AAFwkTag::MISSION, "missionSnapshot: Parse missionId failed"); - ThrowInvalidParamError(env, "Parse param missionId failed, must be a number"); + ThrowInvalidParamError(env, "Parse param missionId failed, must be a number."); return false; } @@ -491,7 +491,7 @@ private: int32_t missionId = -1; if (!ConvertFromJsValue(env, argv[0], missionId)) { TAG_LOGE(AAFwkTag::MISSION, "OnLockMission Parse missionId failed"); - ThrowInvalidParamError(env, "Parse param missionId failed, must be a number"); + ThrowInvalidParamError(env, "Parse param missionId failed, must be a number."); return CreateJsUndefined(env); } @@ -524,7 +524,7 @@ private: int32_t missionId = -1; if (!ConvertFromJsValue(env, argv[0], missionId)) { TAG_LOGE(AAFwkTag::MISSION, "OnUnlockMission Parse missionId failed"); - ThrowInvalidParamError(env, "Parse param missionId failed, must be a number"); + ThrowInvalidParamError(env, "Parse param missionId failed, must be a number."); return CreateJsUndefined(env); } @@ -557,7 +557,7 @@ private: int32_t missionId = -1; if (!ConvertFromJsValue(env, argv[0], missionId)) { TAG_LOGE(AAFwkTag::MISSION, "OnClearMission Parse missionId failed"); - ThrowInvalidParamError(env, "Parse param missionId failed, must be a number"); + ThrowInvalidParamError(env, "Parse param missionId failed, must be a number."); return CreateJsUndefined(env); } @@ -611,7 +611,7 @@ private: int32_t missionId = -1; if (!ConvertFromJsValue(env, argv[0], missionId)) { TAG_LOGE(AAFwkTag::MISSION, "OnMoveMissionToFront Parse missionId failed"); - ThrowInvalidParamError(env, "Parse param missionId failed, must be a number"); + ThrowInvalidParamError(env, "Parse param missionId failed, must be a number."); return CreateJsUndefined(env); } decltype(argc) unwrapArgc = 1; @@ -654,7 +654,7 @@ private: napi_get_array_length(env, argv[0], &nativeArrayLen); if (nativeArrayLen == 0) { TAG_LOGE(AAFwkTag::MISSION, "OnMoveMissionsToForeground MissionId is null"); - ThrowInvalidParamError(env, "Parse param missionIds failed, the size of missionIds must above zero"); + ThrowInvalidParamError(env, "Parse param missionIds failed, the size of missionIds must above zero."); return CreateJsUndefined(env); } napi_value element = nullptr; @@ -663,7 +663,7 @@ private: napi_get_element(env, argv[0], i, &element); if (!ConvertFromJsValue(env, element, missionId)) { TAG_LOGE(AAFwkTag::MISSION, "OnMoveMissionsToForeground Parse missionId failed"); - ThrowInvalidParamError(env, "Parse param missionIds failed, missionId must be a number"); + ThrowInvalidParamError(env, "Parse param missionIds failed, missionId must be a number."); return CreateJsUndefined(env); } missionIds.push_back(missionId); @@ -674,7 +674,7 @@ private: if (argc > ARGC_ONE && AppExecFwk::IsTypeForNapiValue(env, argv[1], napi_number)) { if (!ConvertFromJsValue(env, argv[1], topMissionId)) { TAG_LOGE(AAFwkTag::MISSION, "OnMoveMissionsToForeground Parse topMissionId failed"); - ThrowInvalidParamError(env, "Parse param topMission failed, must be a number"); + ThrowInvalidParamError(env, "Parse param topMission failed, must be a number."); return CreateJsUndefined(env); } unwrapArgc++; @@ -713,7 +713,7 @@ private: napi_get_array_length(env, argv[0], &nativeArrayLen); if (nativeArrayLen == 0) { TAG_LOGE(AAFwkTag::MISSION, "OnMoveMissionsToBackground MissionId is null"); - ThrowInvalidParamError(env, "Parse param missionIds failed, the size of missionIds must above zero"); + ThrowInvalidParamError(env, "Parse param missionIds failed, the size of missionIds must above zero."); return CreateJsUndefined(env); } napi_value element = nullptr; @@ -722,7 +722,7 @@ private: napi_get_element(env, argv[0], i, &element); if (!ConvertFromJsValue(env, element, missionId)) { TAG_LOGE(AAFwkTag::MISSION, "OnMoveMissionsToBackground Parse topMissionId failed"); - ThrowInvalidParamError(env, "Parse param missionIds failed, missionId must be a number"); + ThrowInvalidParamError(env, "Parse param missionIds failed, missionId must be a number."); return CreateJsUndefined(env); } missionIds.push_back(missionId); diff --git a/frameworks/native/ability/native/js_service_extension_context.cpp b/frameworks/native/ability/native/js_service_extension_context.cpp index b06713a41b..4b1d09b6a0 100644 --- a/frameworks/native/ability/native/js_service_extension_context.cpp +++ b/frameworks/native/ability/native/js_service_extension_context.cpp @@ -277,12 +277,12 @@ private: if (!CheckTypeForNapiValue(env, info.argv[ARGC_ZERO], napi_string)) { TAG_LOGE(AAFwkTag::SERVICE_EXT, "link must be string"); - ThrowInvalidParamError(env, "Parse param link failed, must be a string"); + ThrowInvalidParamError(env, "Parse param link failed, must be a string."); return false; } if (!ConvertFromJsValue(env, info.argv[ARGC_ZERO], linkValue) || !CheckUrl(linkValue)) { TAG_LOGE(AAFwkTag::SERVICE_EXT, "link parameter invalid"); - ThrowInvalidParamError(env, "link parameter invalid"); + ThrowInvalidParamError(env, "link parameter invalid."); return false; } @@ -290,7 +290,7 @@ private: TAG_LOGD(AAFwkTag::SERVICE_EXT, "OpenLinkOptions is used."); if (!AppExecFwk::UnwrapOpenLinkOptions(env, info.argv[INDEX_ONE], openLinkOptions, want)) { TAG_LOGE(AAFwkTag::SERVICE_EXT, "OpenLinkOptions parse failed"); - ThrowInvalidParamError(env, "Parse param options failed, must be a OpenLinkOptions"); + ThrowInvalidParamError(env, "Parse param options failed, must be a OpenLinkOptions."); return false; } } @@ -405,7 +405,7 @@ private: unwrapArgc = ARGC_ZERO; // Check input want if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want)) { - ThrowInvalidParamError(env, "Parse param want failed, must be a Want"); + ThrowInvalidParamError(env, "Parse param want failed, must be a Want."); return false; } ++unwrapArgc; @@ -467,7 +467,7 @@ private: napi_env env, NapiCallbackInfo& info, AAFwk::Want& want, int32_t& accountId) { if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want)) { - ThrowInvalidParamError(env, "Parse param want failed, must be a Want"); + ThrowInvalidParamError(env, "Parse param want failed, must be a Want."); return false; } @@ -475,12 +475,12 @@ private: if (CheckTypeForNapiValue(env, info.argv[INDEX_ONE], napi_number)) { if (!ConvertFromJsValue(env, info.argv[1], accountId)) { TAG_LOGE(AAFwkTag::SERVICE_EXT, "check input param accountId failed"); - ThrowInvalidParamError(env, "Parse param accountId failed, must be a number"); + ThrowInvalidParamError(env, "Parse param accountId failed, must be a number."); return false; } } else { TAG_LOGE(AAFwkTag::SERVICE_EXT, "input parameter type invalid"); - ThrowInvalidParamError(env, "Parse param accountId failed, must be a number"); + ThrowInvalidParamError(env, "Parse param accountId failed, must be a number."); return false; } } @@ -624,12 +624,12 @@ private: unwrapArgc = ARGC_ZERO; // Check input want if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want)) { - ThrowInvalidParamError(env, "Parse param want failed, must be a Want"); + ThrowInvalidParamError(env, "Parse param want failed, must be a Want."); return false; } ++unwrapArgc; if (!AppExecFwk::UnwrapInt32FromJS2(env, info.argv[INDEX_ONE], accountId)) { - ThrowInvalidParamError(env, "Parse param accountId failed, must be a number"); + ThrowInvalidParamError(env, "Parse param accountId failed, must be a number."); return false; } ++unwrapArgc; @@ -677,11 +677,11 @@ private: AAFwk::Want want; sptr connection = new JSServiceExtensionConnection(env); if (!AppExecFwk::UnwrapWant(env, info.argv[0], want)) { - ThrowInvalidParamError(env, "Parse param want failed, must be a Want"); + ThrowInvalidParamError(env, "Parse param want failed, must be a Want."); return CreateJsUndefined(env); } if (!CheckConnectionParam(env, info.argv[1], connection, want)) { - ThrowInvalidParamError(env, "Parse param options failed, must be a ConnectOptions"); + ThrowInvalidParamError(env, "Parse param options failed, must be a ConnectOptions."); return CreateJsUndefined(env); } int64_t connectId = connection->GetConnectionId(); @@ -726,7 +726,7 @@ private: return CreateJsUndefined(env); } if (!CheckConnectionParam(env, info.argv[INDEX_TWO], connection, want, accountId)) { - ThrowInvalidParamError(env, "Parse param options failed, must be a ConnectOptions"); + ThrowInvalidParamError(env, "Parse param options failed, must be a ConnectOptions."); return CreateJsUndefined(env); } int64_t connectId = connection->GetConnectionId(); @@ -792,7 +792,7 @@ private: } int64_t connectId = -1; if (!AppExecFwk::UnwrapInt64FromJS2(env, info.argv[INDEX_ZERO], connectId)) { - ThrowInvalidParamError(env, "Parse param connection failed, must be a number"); + ThrowInvalidParamError(env, "Parse param connection failed, must be a number."); return CreateJsUndefined(env); } @@ -862,7 +862,7 @@ private: } AAFwk::Want want; if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want)) { - ThrowInvalidParamError(env, "Parse param want failed, must be a Want"); + ThrowInvalidParamError(env, "Parse param want failed, must be a Want."); return CreateJsUndefined(env); } @@ -937,7 +937,7 @@ private: } AAFwk::Want want; if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want)) { - ThrowInvalidParamError(env, "Parse param want failed, must be a Want"); + ThrowInvalidParamError(env, "Parse param want failed, must be a Want."); return CreateJsUndefined(env); } @@ -1014,7 +1014,7 @@ private: AAFwk::Want want; if (!AppExecFwk::UnwrapWant(env, info.argv[0], want)) { TAG_LOGE(AAFwkTag::SERVICE_EXT, "Failed to parse want!"); - ThrowInvalidParamError(env, "Parse param want failed, must be a Want"); + ThrowInvalidParamError(env, "Parse param want failed, must be a Want."); return CreateJsUndefined(env); } diff --git a/service_router_framework/interfaces/kits/js/serviceroutermgr/service_router_mgr.cpp b/service_router_framework/interfaces/kits/js/serviceroutermgr/service_router_mgr.cpp index 707aeb640c..339ba92d43 100755 --- a/service_router_framework/interfaces/kits/js/serviceroutermgr/service_router_mgr.cpp +++ b/service_router_framework/interfaces/kits/js/serviceroutermgr/service_router_mgr.cpp @@ -238,7 +238,7 @@ napi_value QueryBusinessAbilityInfos(napi_env env, napi_callback_info info) if (args.GetMaxArgc() >= ARGS_SIZE_ONE) { if (!ParseBusinessAbilityInfo(env, args[ARGS_POS_ZERO], asyncCallbackInfo->filter)) { BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, TYPE_BUSINESS_AIBILITY_FILTER, - TYPE_STRING); + "BusinessAbilityFilter"); return nullptr; } if (args.GetMaxArgc() == ARGS_SIZE_TWO) { From 5e6c34d805f1a5d80710bbdf5de7f9af7eb4d8cd Mon Sep 17 00:00:00 2001 From: XKK Date: Mon, 3 Jun 2024 21:14:09 +0800 Subject: [PATCH 52/69] =?UTF-8?q?appIndex=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XKK --- services/abilitymgr/src/ability_manager_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index f6d19d10a3..01c952d385 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -10741,7 +10741,7 @@ void AbilityManagerService::GetRunningMultiAppIndex(const std::string &bundleNam TAG_LOGW(AAFwkTag::ABILITYMGR, "GetAppMgr failed"); return; } - auto ret = appMgr->GetRunningMultiAppInfoByBundleName(bundleName, runningMultiAppInfo); + auto ret = IN_PROCESS_CALL(appMgr->GetRunningMultiAppInfoByBundleName(bundleName, runningMultiAppInfo)); if (ret != ERR_OK) { TAG_LOGW(AAFwkTag::ABILITYMGR, "GetRunningMultiAppInfo failed bundleName = %{public}s", bundleName.c_str()); From ed3d77d1e5d2bd65ea3d069d1f879df012d4ef23 Mon Sep 17 00:00:00 2001 From: XKK Date: Mon, 3 Jun 2024 21:33:40 +0800 Subject: [PATCH 53/69] remove Signed-off-by: XKK --- services/abilitymgr/src/ability_manager_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 01c952d385..f6d19d10a3 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -10741,7 +10741,7 @@ void AbilityManagerService::GetRunningMultiAppIndex(const std::string &bundleNam TAG_LOGW(AAFwkTag::ABILITYMGR, "GetAppMgr failed"); return; } - auto ret = IN_PROCESS_CALL(appMgr->GetRunningMultiAppInfoByBundleName(bundleName, runningMultiAppInfo)); + auto ret = appMgr->GetRunningMultiAppInfoByBundleName(bundleName, runningMultiAppInfo); if (ret != ERR_OK) { TAG_LOGW(AAFwkTag::ABILITYMGR, "GetRunningMultiAppInfo failed bundleName = %{public}s", bundleName.c_str()); From ce4cd5aa5201680eb95d9bb2d977bd9f5c6357ed Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Mon, 3 Jun 2024 22:41:55 +0800 Subject: [PATCH 54/69] add autostartup Application identity identification bug fix Signed-off-by: jiangzhijun8 --- services/abilitymgr/src/ability_auto_startup_data_manager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp index 5d82797912..a262d5338d 100644 --- a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp +++ b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp @@ -413,6 +413,10 @@ AutoStartupInfo AbilityAutoStartupDataManager::ConvertAutoStartupInfoFromKeyAndV info.appCloneIndex = jsonObject.at(JSON_KEY_APP_CLONE_INDEX).get(); } + if (jsonObject.contains(JSON_KEY_ACCESS_TOKENID) && jsonObject[JSON_KEY_ACCESS_TOKENID].is_string()) { + info.accessTokenId = jsonObject.at(JSON_KEY_ACCESS_TOKENID).get(); + } + nlohmann::json jsonValueObject = nlohmann::json::parse(value.ToString(), nullptr, false); if (jsonValueObject.is_discarded()) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to parse jsonValueObject."); From 9438e6185487dc95696304409fee352b30f99ff2 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Mon, 3 Jun 2024 22:41:55 +0800 Subject: [PATCH 55/69] add autostartup Application identity identification bug fix Signed-off-by: jiangzhijun8 --- .../abilitymgr/src/ability_auto_startup_data_manager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp index 5d82797912..ac73e712b8 100644 --- a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp +++ b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp @@ -413,6 +413,10 @@ AutoStartupInfo AbilityAutoStartupDataManager::ConvertAutoStartupInfoFromKeyAndV info.appCloneIndex = jsonObject.at(JSON_KEY_APP_CLONE_INDEX).get(); } + if (jsonObject.contains(JSON_KEY_ACCESS_TOKENID) && jsonObject[JSON_KEY_ACCESS_TOKENID].is_string()) { + info.accessTokenId = jsonObject.at(JSON_KEY_ACCESS_TOKENID).get(); + } + nlohmann::json jsonValueObject = nlohmann::json::parse(value.ToString(), nullptr, false); if (jsonValueObject.is_discarded()) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to parse jsonValueObject."); @@ -422,10 +426,6 @@ AutoStartupInfo AbilityAutoStartupDataManager::ConvertAutoStartupInfoFromKeyAndV if (jsonValueObject.contains(JSON_KEY_TYPE_NAME) && jsonValueObject[JSON_KEY_TYPE_NAME].is_string()) { info.abilityTypeName = jsonValueObject.at(JSON_KEY_TYPE_NAME).get(); } - - if (jsonValueObject.contains(JSON_KEY_ACCESS_TOKENID) && jsonValueObject[JSON_KEY_ACCESS_TOKENID].is_string()) { - info.accessTokenId = jsonValueObject.at(JSON_KEY_ACCESS_TOKENID).get(); - } return info; } From f282c5784e6a290057e7b56a0ce54516c13bbc86 Mon Sep 17 00:00:00 2001 From: XKK Date: Mon, 3 Jun 2024 21:16:08 +0800 Subject: [PATCH 56/69] =?UTF-8?q?=E5=8C=85=E7=AE=A1=E7=90=86=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E9=80=82=E9=85=8DappIndex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XKK --- services/abilitymgr/src/ability_manager_service.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 8c81f659bb..60e02b2aa3 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -4168,7 +4168,7 @@ sptr AbilityManagerService::GetWantSender( int32_t callerUid = IPCSkeleton::GetCallingUid(); int32_t userId = wantSenderInfo.userId; - bool bundleMgrResult = false; + int32_t bundleMgrResult = 0; if (userId < 0) { if (DelayedSingleton::GetInstance()-> GetOsAccountLocalIdFromUid(callerUid, userId) != 0) { @@ -4182,12 +4182,13 @@ sptr AbilityManagerService::GetWantSender( if (!wantSenderInfo.allWants.empty()) { AppExecFwk::BundleInfo bundleInfo; std::string bundleName = wantSenderInfo.allWants.back().want.GetElement().GetBundleName(); - bundleMgrResult = IN_PROCESS_CALL(bms->GetBundleInfo(bundleName, - AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, userId)); - if (bundleMgrResult) { + GetRunningMultiAppIndex(bundleName, callerUid, appIndex); + bundleMgrResult = IN_PROCESS_CALL(bms->GetCloneBundleInfo(bundleName, + static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION), + appIndex, bundleInfo, userId)); + if (bundleMgrResult == ERR_OK) { appUid = bundleInfo.uid; } - GetRunningMultiAppIndex(bundleName, callerUid, appIndex); TAG_LOGD(AAFwkTag::ABILITYMGR, "App bundleName: %{public}s, uid: %{public}d", bundleName.c_str(), appUid); } if (!CheckSenderWantInfo(callerUid, wantSenderInfo)) { @@ -10741,7 +10742,7 @@ void AbilityManagerService::GetRunningMultiAppIndex(const std::string &bundleNam TAG_LOGW(AAFwkTag::ABILITYMGR, "GetAppMgr failed"); return; } - auto ret = appMgr->GetRunningMultiAppInfoByBundleName(bundleName, runningMultiAppInfo); + auto ret = IN_PROCESS_CALL(appMgr->GetRunningMultiAppInfoByBundleName(bundleName, runningMultiAppInfo)); if (ret != ERR_OK) { TAG_LOGW(AAFwkTag::ABILITYMGR, "GetRunningMultiAppInfo failed bundleName = %{public}s", bundleName.c_str()); From ddd799b3e4621b390dc32a5ebe328adaa0613e29 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 4 Jun 2024 16:19:04 +0800 Subject: [PATCH 57/69] =?UTF-8?q?=E8=BF=BD=E5=8A=A0AutofillRequest?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=9C=A8=E5=8F=82=E6=95=B0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E8=BF=94=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xinking129 --- .../auto_fill_extension_ability/js_fill_request_callback.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frameworks/native/ability/native/auto_fill_extension_ability/js_fill_request_callback.cpp b/frameworks/native/ability/native/auto_fill_extension_ability/js_fill_request_callback.cpp index eff917b506..9d4b84075c 100644 --- a/frameworks/native/ability/native/auto_fill_extension_ability/js_fill_request_callback.cpp +++ b/frameworks/native/ability/native/auto_fill_extension_ability/js_fill_request_callback.cpp @@ -86,6 +86,7 @@ napi_value JsFillRequestCallback::OnFillRequestSuccess(napi_env env, NapiCallbac TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "Called."); if (info.argc < ARGC_ONE || !IsTypeForNapiValue(env, info.argv[INDEX_ZERO], napi_object)) { TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "Failed to parse viewData JsonString!"); + ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); SendResultCodeAndViewData( JsAutoFillExtensionUtil::AutoFillResultCode::CALLBACK_FAILED_INVALID_PARAM, ""); return CreateJsUndefined(env); @@ -96,6 +97,7 @@ napi_value JsFillRequestCallback::OnFillRequestSuccess(napi_env env, NapiCallbac std::string jsonString = response.viewData.ToJsonString(); if (jsonString.empty()) { TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "JsonString is empty"); + ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); SendResultCodeAndViewData( JsAutoFillExtensionUtil::AutoFillResultCode::CALLBACK_FAILED_INVALID_PARAM, ""); return CreateJsUndefined(env); @@ -129,6 +131,7 @@ napi_value JsFillRequestCallback::OnFillRequestCanceled(napi_env env, NapiCallba std::string jsonString = UnwrapStringFromJS(env, info.argv[INDEX_ZERO], ""); if (jsonString.empty()) { TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "JsonString is empty"); + ThrowError(env, static_cast(AbilityErrorCode::ERROR_CODE_INVALID_PARAM), ERROR_MSG_INVALID_PARAM); SendResultCodeAndViewData( JsAutoFillExtensionUtil::AutoFillResultCode::CALLBACK_FAILED_INVALID_PARAM, ""); return CreateJsUndefined(env); From bdc9314a30c87728ef28dddc3f4d975a8a73adbe Mon Sep 17 00:00:00 2001 From: mashaohua7 Date: Tue, 4 Jun 2024 17:12:48 +0800 Subject: [PATCH 58/69] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mashaohua7 --- services/abilitymgr/src/ability_auto_startup_data_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp index ac73e712b8..aeb21b2091 100644 --- a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp +++ b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp @@ -409,7 +409,7 @@ AutoStartupInfo AbilityAutoStartupDataManager::ConvertAutoStartupInfoFromKeyAndV info.abilityName = jsonObject.at(JSON_KEY_ABILITY_NAME).get(); } - if (jsonObject.contains(JSON_KEY_APP_CLONE_INDEX) && jsonObject[JSON_KEY_APP_CLONE_INDEX].is_string()) { + if (jsonObject.contains(JSON_KEY_APP_CLONE_INDEX) && jsonObject[JSON_KEY_APP_CLONE_INDEX].is_number()) { info.appCloneIndex = jsonObject.at(JSON_KEY_APP_CLONE_INDEX).get(); } From 420e6d3f9b6a0d4f6de1497f513afb321fdcdd6a Mon Sep 17 00:00:00 2001 From: mashaohua7 Date: Tue, 4 Jun 2024 17:18:26 +0800 Subject: [PATCH 59/69] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mashaohua7 --- services/abilitymgr/src/ability_auto_startup_data_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp index aeb21b2091..dc9f23dee2 100644 --- a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp +++ b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp @@ -462,7 +462,7 @@ bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const } } - if (jsonObject.contains(JSON_KEY_APP_CLONE_INDEX) && jsonObject[JSON_KEY_APP_CLONE_INDEX].is_string()) { + if (jsonObject.contains(JSON_KEY_APP_CLONE_INDEX) && jsonObject[JSON_KEY_APP_CLONE_INDEX].is_number()) { if (info.appCloneIndex != jsonObject.at(JSON_KEY_APP_CLONE_INDEX).get()) { return false; } From 7fd88d4a34c64eccf58df7ac18856ffa68fd1967 Mon Sep 17 00:00:00 2001 From: mashaohua7 Date: Tue, 4 Jun 2024 17:32:10 +0800 Subject: [PATCH 60/69] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mashaohua7 --- services/abilitymgr/src/ability_auto_startup_data_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp index dc9f23dee2..c6b5931239 100644 --- a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp +++ b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp @@ -410,7 +410,7 @@ AutoStartupInfo AbilityAutoStartupDataManager::ConvertAutoStartupInfoFromKeyAndV } if (jsonObject.contains(JSON_KEY_APP_CLONE_INDEX) && jsonObject[JSON_KEY_APP_CLONE_INDEX].is_number()) { - info.appCloneIndex = jsonObject.at(JSON_KEY_APP_CLONE_INDEX).get(); + info.appCloneIndex = jsonObject.at(JSON_KEY_APP_CLONE_INDEX).get(); } if (jsonObject.contains(JSON_KEY_ACCESS_TOKENID) && jsonObject[JSON_KEY_ACCESS_TOKENID].is_string()) { @@ -463,7 +463,7 @@ bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const } if (jsonObject.contains(JSON_KEY_APP_CLONE_INDEX) && jsonObject[JSON_KEY_APP_CLONE_INDEX].is_number()) { - if (info.appCloneIndex != jsonObject.at(JSON_KEY_APP_CLONE_INDEX).get()) { + if (info.appCloneIndex != jsonObject.at(JSON_KEY_APP_CLONE_INDEX).get()) { return false; } } From db39a66a90d8b63c5c747e0865a0c4124064a055 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Tue, 4 Jun 2024 17:39:57 +0800 Subject: [PATCH 61/69] fix ui extension death recipient problem Signed-off-by: gongyuechen --- services/abilitymgr/src/ability_connect_manager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 50edb923bc..c86e669d02 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -2838,7 +2838,8 @@ void AbilityConnectManager::DeleteInvalidServiceRecord(const std::string &bundle TAG_LOGD(AAFwkTag::ABILITYMGR, "Delete invalid record by %{public}s.", bundleName.c_str()); std::lock_guard lock(serviceMapMutex_); for (auto it = serviceMap_.begin(); it != serviceMap_.end();) { - if (it->second != nullptr && it->second->GetApplicationInfo().bundleName == bundleName) { + if (it->second != nullptr && it->second->GetApplicationInfo().bundleName == bundleName && + !IsUIExtensionAbility(it->second)) { it = serviceMap_.erase(it); } else { ++it; From d7f4c8a86897fd1b3fec3d73b7db6f650bebb8e5 Mon Sep 17 00:00:00 2001 From: huangshiwei Date: Tue, 4 Jun 2024 20:43:27 +0800 Subject: [PATCH 62/69] huangshiwei4@huawei.com Signed-off-by: huangshiwei --- .../include/mock_ui_content.h | 1 + 1 file changed, 1 insertion(+) diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ui_content.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ui_content.h index fc6bcbc36c..75a3f84243 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ui_content.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ui_content.h @@ -56,6 +56,7 @@ public: MOCK_METHOD3(UpdateViewportConfig, void(const ViewportConfig &config, OHOS::Rosen::WindowSizeChangeReason reason, const std::shared_ptr &rsTransaction)); MOCK_METHOD2(UpdateWindowMode, void(OHOS::Rosen::WindowMode mode, bool hasDeco)); + MOCK_METHOD1(NotifyWindowMode, void(OHOS::Rosen::WindowMode mode)); MOCK_METHOD2(UpdateTitleInTargetPos, void(bool isShow, int32_t height)); MOCK_METHOD2(UpdateDecorVisible, void(bool visible, bool hasDeco)); MOCK_METHOD3(HideWindowTitleButton, void(bool hideSplit, bool hideMaximize, bool hideMinimize)); From bfb8c7eb2878bf9f34bcbe7d1def7e83e93dd4e6 Mon Sep 17 00:00:00 2001 From: kangchongtao Date: Tue, 4 Jun 2024 12:45:36 +0000 Subject: [PATCH 63/69] =?UTF-8?q?=E9=83=A8=E4=BB=B6=E7=8B=AC=E7=AB=8B?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: kangchongtao Change-Id: I55f2e2c308c2aad7c263430b251ee5b64d9ae16f --- test/moduletest/ability_record_test/BUILD.gn | 1 - test/moduletest/ability_timeout_module_test/BUILD.gn | 1 - test/moduletest/panding_want_manager_test/BUILD.gn | 5 +---- test/moduletest/running_infos_module_test/BUILD.gn | 1 - test/unittest/BUILD.gn | 5 +---- 5 files changed, 2 insertions(+), 11 deletions(-) diff --git a/test/moduletest/ability_record_test/BUILD.gn b/test/moduletest/ability_record_test/BUILD.gn index 14c5438b20..c3b8397004 100644 --- a/test/moduletest/ability_record_test/BUILD.gn +++ b/test/moduletest/ability_record_test/BUILD.gn @@ -53,7 +53,6 @@ ohos_moduletest("AbilityRecordModuleTest") { if (ability_runtime_graphics) { deps += [ - "${ace_engine_path}/interfaces/inner_api/ui_service_manager:ui_service_mgr", "${global_path}/i18n/frameworks/intl:intl_util", "${multimedia_path}/interfaces/innerkits:image_native", "//third_party/icu/icu4c:shared_icuuc", diff --git a/test/moduletest/ability_timeout_module_test/BUILD.gn b/test/moduletest/ability_timeout_module_test/BUILD.gn index af2f95c7d7..6c4036bc53 100644 --- a/test/moduletest/ability_timeout_module_test/BUILD.gn +++ b/test/moduletest/ability_timeout_module_test/BUILD.gn @@ -123,7 +123,6 @@ ohos_moduletest("ability_timeout_module_test") { if (ability_runtime_graphics) { deps += [ - "${ace_engine_path}/interfaces/inner_api/ui_service_manager:ui_service_mgr", "${global_path}/i18n/frameworks/intl:intl_util", "${multimedia_path}/interfaces/innerkits:image_native", "//third_party/icu/icu4c:shared_icuuc", diff --git a/test/moduletest/panding_want_manager_test/BUILD.gn b/test/moduletest/panding_want_manager_test/BUILD.gn index ee1cc78d9b..d8f4913a7f 100644 --- a/test/moduletest/panding_want_manager_test/BUILD.gn +++ b/test/moduletest/panding_want_manager_test/BUILD.gn @@ -85,10 +85,7 @@ ohos_moduletest("PandingWantMgrTest") { } if (ability_runtime_graphics) { - deps += [ - "${ace_engine_path}/interfaces/inner_api/ui_service_manager:ui_service_mgr", - "${global_path}/i18n/frameworks/intl:intl_util", - ] + deps += [ "${global_path}/i18n/frameworks/intl:intl_util" ] external_deps += [ "image_framework:image_native" ] } diff --git a/test/moduletest/running_infos_module_test/BUILD.gn b/test/moduletest/running_infos_module_test/BUILD.gn index 022686ab2b..7773dd3ff1 100644 --- a/test/moduletest/running_infos_module_test/BUILD.gn +++ b/test/moduletest/running_infos_module_test/BUILD.gn @@ -78,7 +78,6 @@ ohos_moduletest("running_infos_module_test") { if (ability_runtime_graphics) { deps += [ - "${ace_engine_path}/interfaces/inner_api/ui_service_manager:ui_service_mgr", "${global_path}/i18n/frameworks/intl:intl_util", "${multimedia_path}/interfaces/innerkits:image_native", "//third_party/icu/icu4c:shared_icuuc", diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 708c83ab3e..712d1a6123 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -292,10 +292,7 @@ ohos_source_set("abilityms_test_source") { "${ability_runtime_services_path}/abilitymgr/src/system_dialog_scheduler.cpp", "${ability_runtime_services_path}/appdfr/src/application_anr_listener.cpp", ] - deps += [ - "${ace_engine_path}/interfaces/inner_api/ui_service_manager:ui_service_mgr", - "//third_party/libjpeg-turbo:turbojpeg_static", - ] + deps += [ "//third_party/libjpeg-turbo:turbojpeg_static" ] external_deps += [ "i18n:intl_util", "icu:shared_icuuc", From 652b6ad37c0a1f8725ed2788bccfa69718a34404 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 4 Jun 2024 21:51:28 +0800 Subject: [PATCH 64/69] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=B3=95=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xinking129 --- .../auto_fill_manager/src/auto_fill_extension_callback.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/inner_api/auto_fill_manager/src/auto_fill_extension_callback.cpp b/interfaces/inner_api/auto_fill_manager/src/auto_fill_extension_callback.cpp index c09c755b0c..7e034514dc 100644 --- a/interfaces/inner_api/auto_fill_manager/src/auto_fill_extension_callback.cpp +++ b/interfaces/inner_api/auto_fill_manager/src/auto_fill_extension_callback.cpp @@ -179,7 +179,7 @@ void AutoFillExtensionCallback::onDestroy() } return; } - SendAutoFillFailed(AutoFill::AUTO_FILL_CANCEL); + SendAutoFillFailed(AutoFill::AUTO_FILL_FAILED); #ifdef SUPPORT_GRAPHICS CloseModalUIExtension(); #endif From 2a4a9be451f32646b46287f21210e253de383617 Mon Sep 17 00:00:00 2001 From: xuzhihao Date: Sun, 2 Jun 2024 15:43:06 +0800 Subject: [PATCH 65/69] =?UTF-8?q?Bugfix:=20=E5=85=83=E8=83=BD=E5=8A=9B401?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=A0=81=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xuzhihao --- .../js_ability_delegator.cpp | 6 +++--- .../js/napi/wantagent/napi_want_agent.cpp | 20 +++++++++---------- .../context/js_application_context_utils.cpp | 9 +++++---- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/frameworks/js/napi/app/ability_delegator/js_ability_delegator.cpp b/frameworks/js/napi/app/ability_delegator/js_ability_delegator.cpp index e89aae8709..0f172b8f39 100644 --- a/frameworks/js/napi/app/ability_delegator/js_ability_delegator.cpp +++ b/frameworks/js/napi/app/ability_delegator/js_ability_delegator.cpp @@ -310,7 +310,7 @@ napi_value JSAbilityDelegator::OnAddAbilityStageMonitor(napi_env env, NapiCallba if (!ParseAbilityStageMonitorPara(env, info, monitor, isExisted, false)) { TAG_LOGE(AAFwkTag::DELEGATOR, "Parse addAbilityStageMonitor parameters failed"); return ThrowJsError(env, INCORRECT_PARAMETERS, - "Parse param parameters, failed, monitor must be Monitor and isExited must be boolean."); + "Parse parameters failed, monitor must be Monitor and isExited must be boolean."); } NapiAsyncTask::CompleteCallback complete = [monitor](napi_env env, NapiAsyncTask &task, int32_t status) { @@ -344,7 +344,7 @@ napi_value JSAbilityDelegator::OnAddAbilityStageMonitorSync(napi_env env, NapiCa if (!ParseAbilityStageMonitorPara(env, info, monitor, isExisted, true)) { TAG_LOGE(AAFwkTag::DELEGATOR, "Parse addAbilityStageMonitorSync parameters failed"); return ThrowJsError(env, INCORRECT_PARAMETERS, - "Parse param monitor, failed, monitor must be Monitor."); + "Parse param monitor failed, monitor must be Monitor."); } auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator(); if (!delegator) { @@ -774,7 +774,7 @@ napi_value JSAbilityDelegator::OnGetCurrentTopAbility(napi_env env, NapiCallback if (info.argc >= ARGC_ONE && !AppExecFwk::IsTypeForNapiValue(env, info.argv[INDEX_ZERO], napi_function)) { TAG_LOGE(AAFwkTag::DELEGATOR, "Parse getCurrentTopAbility parameter failed"); - return ThrowJsError(env, INCORRECT_PARAMETERS, "Parse callback failed, callback must be funcation"); + return ThrowJsError(env, INCORRECT_PARAMETERS, "Parse callback failed, callback must be function"); } NapiAsyncTask::CompleteCallback complete = [this](napi_env env, NapiAsyncTask &task, int32_t status) { diff --git a/frameworks/js/napi/wantagent/napi_want_agent.cpp b/frameworks/js/napi/wantagent/napi_want_agent.cpp index 93bf7d9328..a6909391d3 100644 --- a/frameworks/js/napi/wantagent/napi_want_agent.cpp +++ b/frameworks/js/napi/wantagent/napi_want_agent.cpp @@ -1093,7 +1093,7 @@ napi_value JsWantAgent::OnNapiGetWant(napi_env env, napi_callback_info info) TAG_LOGD(AAFwkTag::WANTAGENT, "enter, argc = %{public}d", static_cast(argc)); if (argc > ARGC_TWO || argc < ARGC_ONE) { TAG_LOGE(AAFwkTag::WANTAGENT, "Not enough params"); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + ThrowTooFewParametersError(env); return CreateJsUndefined(env); } WantAgent* pWantAgent = nullptr; @@ -1106,14 +1106,14 @@ napi_value JsWantAgent::OnNapiGetWant(napi_env env, napi_callback_info info) if (!CheckTypeForNapiValue(env, argv[0], napi_object)) { TAG_LOGE(AAFwkTag::WANTAGENT, "Wrong argument type. Object expected."); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + ThrowInvalidParamError(env, "Parameter error! Agent must be a WantAgent!"); return CreateJsUndefined(env); } UnwrapWantAgent(env, argv[0], reinterpret_cast(&pWantAgent)); if (pWantAgent == nullptr) { TAG_LOGE(AAFwkTag::WANTAGENT, "Parse pWantAgent failed"); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + ThrowInvalidParamError(env, "Parse wantAgent failed! Agent must be a WantAgent!"); return CreateJsUndefined(env); } @@ -1143,7 +1143,7 @@ napi_value JsWantAgent::OnNapiTrigger(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != ARGC_THREE) { TAG_LOGE(AAFwkTag::WANTAGENT, "Not enough params"); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + ThrowTooFewParametersError(env); return CreateJsUndefined(env); } @@ -1152,7 +1152,7 @@ napi_value JsWantAgent::OnNapiTrigger(napi_env env, napi_callback_info info) auto triggerObj = std::make_shared(); int32_t errCode = UnWrapTriggerInfoParam(env, info, wantAgent, triggerInfo, triggerObj); if (errCode != NO_ERROR) { - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + ThrowInvalidParamError(env, "Parameter error!"); return CreateJsUndefined(env); } ErrCode result = WantAgentHelper::TriggerWantAgent(wantAgent, triggerObj, triggerInfo); @@ -1170,7 +1170,7 @@ napi_value JsWantAgent::OnNapiGetWantAgent(napi_env env, napi_callback_info info TAG_LOGD(AAFwkTag::WANTAGENT, "enter, argc = %{public}d", static_cast(argc)); if (argc > ARGC_TWO || argc < ARGC_ONE) { TAG_LOGE(AAFwkTag::WANTAGENT, "Not enough params"); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + ThrowTooFewParametersError(env); return CreateJsUndefined(env); } @@ -1178,7 +1178,7 @@ napi_value JsWantAgent::OnNapiGetWantAgent(napi_env env, napi_callback_info info int32_t ret = GetWantAgentParam(env, info, *spParas); if (ret != 0) { TAG_LOGE(AAFwkTag::WANTAGENT, "Failed to get wantAgent param."); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + ThrowInvalidParamError(env, "Parameter error! Info must be a WantAgentInfo."); return CreateJsUndefined(env); } @@ -1234,13 +1234,13 @@ napi_value JsWantAgent::OnNapiGetOperationType(napi_env env, napi_callback_info WantAgent* pWantAgent = nullptr; if (argc > ARGC_TWO || argc < ARGC_ONE) { TAG_LOGE(AAFwkTag::WANTAGENT, "Not enough params"); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + ThrowTooFewParametersError(env); return CreateJsUndefined(env); } if (!CheckTypeForNapiValue(env, argv[0], napi_object)) { TAG_LOGE(AAFwkTag::WANTAGENT, "Wrong argument type. Object expected."); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + ThrowInvalidParamError(env, "Parameter error! Agent must be a WantAgent."); return CreateJsUndefined(env); } @@ -1248,7 +1248,7 @@ napi_value JsWantAgent::OnNapiGetOperationType(napi_env env, napi_callback_info if (pWantAgent == nullptr) { TAG_LOGE(AAFwkTag::WANTAGENT, "Parse pWantAgent failed"); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + ThrowInvalidParamError(env, "Parse wantAgent failed! Agent must be a WantAgent."); return CreateJsUndefined(env); } diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index 9053d8831d..401b2a30f5 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -1086,7 +1086,7 @@ napi_value JsApplicationContextUtils::OnOn(napi_env env, NapiCallbackInfo& info) return OnOnApplicationStateChange(env, info); } TAG_LOGE(AAFwkTag::APPKIT, "on function type not match."); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + ThrowInvalidParamError(env, "Parse param callback failed, callback must be function."); return CreateJsUndefined(env); } @@ -1141,7 +1141,7 @@ napi_value JsApplicationContextUtils::OnOff(napi_env env, NapiCallbackInfo& info return OnOffEnvironmentEventSync(env, info, callbackId); } TAG_LOGE(AAFwkTag::APPKIT, "off function type not match."); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + ThrowInvalidParamError(env, "Parse param callback failed, callback must be function."); return CreateJsUndefined(env); } @@ -1357,7 +1357,8 @@ napi_value JsApplicationContextUtils::OnOffApplicationStateChange( std::lock_guard lock(applicationStateCallbackLock_); if (applicationStateCallback_ == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "ApplicationStateCallback_ is nullptr."); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + ThrowInvalidParamError(env, + "Parse applicationStateCallback failed, applicationStateCallback must be function."); return CreateJsUndefined(env); } @@ -1365,7 +1366,7 @@ napi_value JsApplicationContextUtils::OnOffApplicationStateChange( applicationStateCallback_->UnRegister(); } else if (!applicationStateCallback_->UnRegister(info.argv[INDEX_ONE])) { TAG_LOGE(AAFwkTag::APPKIT, "call UnRegister failed!"); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + ThrowInvalidParamError(env, "Parse param call UnRegister failed, call UnRegister must be function."); return CreateJsUndefined(env); } From 03d03898f00f818626ab50734d79de439dae10c2 Mon Sep 17 00:00:00 2001 From: huangshiwei Date: Mon, 3 Jun 2024 17:34:51 +0800 Subject: [PATCH 66/69] huangshiwei4@huawei.com Signed-off-by: huangshiwei --- .../common/ams/app_mgr_service_test/BUILD.gn | 7 ++ .../BUILD.gn | 7 ++ .../common/ams/ipc_ams_mgr_test/BUILD.gn | 7 ++ .../BUILD.gn | 1 + .../ams_app_running_record_test/BUILD.gn | 3 +- test/unittest/ams_mgr_scheduler_test/BUILD.gn | 7 ++ .../ams_mgr_scheduler_test.cpp | 7 +- .../app_mgr_proxy_test/app_mgr_proxy_test.cpp | 18 +++-- .../app_mgr_service_inner_tdd_test/BUILD.gn | 3 +- .../app_mgr_service_inner_tdd_test.cpp | 21 +++++ test/unittest/app_mgr_service_test/BUILD.gn | 7 ++ .../app_running_processes_info_test/BUILD.gn | 3 +- .../app_running_processes_info_test.cpp | 77 ------------------- .../ui_ability_test.cpp | 2 +- 14 files changed, 76 insertions(+), 94 deletions(-) diff --git a/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn b/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn index 42f31d5174..8f11d04430 100644 --- a/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn +++ b/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn @@ -17,6 +17,13 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/mstappmgrservice" ohos_moduletest("AmsAppMgrServiceModuleTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../../../../cfi_blocklist.txt" + } + branch_protector_ret = "pac_ret" module_out_path = module_output_path include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", diff --git a/test/moduletest/common/ams/app_running_processes_info_module_test/BUILD.gn b/test/moduletest/common/ams/app_running_processes_info_module_test/BUILD.gn index 7f6c8a2866..f61ba351fa 100644 --- a/test/moduletest/common/ams/app_running_processes_info_module_test/BUILD.gn +++ b/test/moduletest/common/ams/app_running_processes_info_module_test/BUILD.gn @@ -17,6 +17,13 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/mstappmgrservice" ohos_moduletest("AppRunningProcessesInfoModuleTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../../../../cfi_blocklist.txt" + } + branch_protector_ret = "pac_ret" module_out_path = module_output_path include_dirs = [ diff --git a/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn b/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn index c031f9fdeb..c75f23f58c 100644 --- a/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn @@ -17,6 +17,13 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/mstappmgrservice" ohos_moduletest("AmsIpcAmsmgrModuleTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../../../../cfi_blocklist.txt" + } + branch_protector_ret = "pac_ret" module_out_path = module_output_path include_dirs = [ diff --git a/test/unittest/ability_manager_service_first_test/BUILD.gn b/test/unittest/ability_manager_service_first_test/BUILD.gn index a7c8a2c695..22fada1f45 100644 --- a/test/unittest/ability_manager_service_first_test/BUILD.gn +++ b/test/unittest/ability_manager_service_first_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("ability_manager_service_first_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../cfi_blocklist.txt" } branch_protector_ret = "pac_ret" diff --git a/test/unittest/ams_app_running_record_test/BUILD.gn b/test/unittest/ams_app_running_record_test/BUILD.gn index fb9475f3cb..f7feabe6a0 100644 --- a/test/unittest/ams_app_running_record_test/BUILD.gn +++ b/test/unittest/ams_app_running_record_test/BUILD.gn @@ -17,13 +17,14 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/appmgrservice" ohos_unittest("AmsAppRunningRecordTest") { - module_out_path = module_output_path sanitize = { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../cfi_blocklist.txt" } branch_protector_ret = "pac_ret" + module_out_path = module_output_path include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", "${ability_runtime_innerkits_path}/app_manager/include/appmgr", diff --git a/test/unittest/ams_mgr_scheduler_test/BUILD.gn b/test/unittest/ams_mgr_scheduler_test/BUILD.gn index 76bbae7f4b..aa8fe382b1 100644 --- a/test/unittest/ams_mgr_scheduler_test/BUILD.gn +++ b/test/unittest/ams_mgr_scheduler_test/BUILD.gn @@ -17,6 +17,13 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/appmgr" ohos_unittest("ams_mgr_scheduler_test") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../../cfi_blocklist.txt" + } + branch_protector_ret = "pac_ret" module_out_path = module_output_path cflags_cc = [] include_dirs = [ diff --git a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp index e371871faa..c64d9fef52 100644 --- a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp +++ b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp @@ -824,12 +824,7 @@ HWTEST_F(AmsMgrSchedulerTest, IsMemorySizeSufficent_001, TestSize.Level0) */ HWTEST_F(AmsMgrSchedulerTest, StartSpecifiedAbility_001, TestSize.Level0) { - auto mockBundleMgr = DelayedSingleton::GetInstance(); - auto remoteClientManager = std::make_shared(); - remoteClientManager->SetBundleManagerHelper(mockBundleMgr); - auto amsMgrServiceInner = std::make_shared(); - amsMgrServiceInner->remoteClientManager_ = remoteClientManager; - auto amsMgrScheduler = std::make_unique(amsMgrServiceInner, nullptr); + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); ASSERT_NE(amsMgrScheduler, nullptr); Want want; AbilityInfo abilityInfo; diff --git a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp index ad60d5d085..82682e1ec8 100644 --- a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp +++ b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp @@ -633,15 +633,19 @@ HWTEST_F(AppMgrProxyTest, GetRunningMultiAppInfoByBundleName_001, TestSize.Level { TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__); - EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest)); + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(AppMgrStub::GetDescriptor()); std::string bundleName = "testBundleName"; - RunningMultiAppInfo info; - appMgrProxy_->GetRunningMultiAppInfoByBundleName(bundleName, info); - EXPECT_EQ(mockAppMgrService_->code_, static_cast - (AppMgrInterfaceCode::GET_RUNNING_MULTIAPP_INFO_BY_BUNDLENAME)); + data.WriteString(bundleName); + + EXPECT_CALL(*mockAppMgrService_, GetRunningMultiAppInfoByBundleName(_, _)).Times(1); + + auto result = mockAppMgrService_->OnRemoteRequest( + static_cast(AppMgrInterfaceCode::GET_RUNNING_MULTIAPP_INFO_BY_BUNDLENAME), data, reply, option); + EXPECT_EQ(result, NO_ERROR); TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); } diff --git a/test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn b/test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn index c4ce653d44..6860aa57c5 100644 --- a/test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn @@ -17,13 +17,14 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/appmgrservice" ohos_unittest("app_mgr_service_inner_tdd_test") { - module_out_path = module_output_path sanitize = { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../cfi_blocklist.txt" } branch_protector_ret = "pac_ret" + module_out_path = module_output_path include_dirs = [ "${ability_runtime_test_path}/mock/common/include", "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", diff --git a/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp b/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp index ded63f4a14..e3ba4a6035 100644 --- a/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp +++ b/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp @@ -107,6 +107,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_001, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "SendProcessStartEvent_001 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); EXPECT_FALSE(appMgrServiceInner->SendProcessStartEvent(nullptr)); TAG_LOGI(AAFwkTag::TEST, "SendProcessStartEvent_001 end"); @@ -121,6 +122,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_002, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "SendProcessStartEvent_002 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); BundleInfo bundleInfo; @@ -142,6 +144,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_003, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "SendProcessStartEvent_003 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); BundleInfo bundleInfo; @@ -169,6 +172,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_004, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "SendProcessStartEvent_004 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); BundleInfo bundleInfo; @@ -199,6 +203,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_005, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "SendProcessStartEvent_005 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); BundleInfo bundleInfo; @@ -230,6 +235,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_006, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "SendProcessStartEvent_006 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); BundleInfo bundleInfo; @@ -262,6 +268,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_007, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "SendProcessStartEvent_007 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); BundleInfo bundleInfo; @@ -304,6 +311,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_008, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "SendProcessStartEvent_008 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); BundleInfo bundleInfo; @@ -347,6 +355,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessExitEvent_001, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "SendProcessExitEvent_001 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); std::shared_ptr appRecord; appMgrServiceInner->SendProcessExitEvent(appRecord); @@ -362,6 +371,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessExitEvent_002, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "SendProcessExitEvent_002 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); appMgrServiceInner->SendProcessExitEvent(nullptr); TAG_LOGI(AAFwkTag::TEST, "SendProcessExitEvent_002 end"); @@ -376,6 +386,7 @@ HWTEST_F(AppMgrServiceInnerTest, CheckIsolationMode_001, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "CheckIsolationMode_001 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); HapModuleInfo hapModuleInfo; string supportIsolationMode = OHOS::system::GetParameter("persist.bms.supportIsolationMode", "false"); @@ -410,6 +421,7 @@ HWTEST_F(AppMgrServiceInnerTest, GenerateRenderUid_001, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "GenerateRenderUid_001 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); int32_t renderUid = Constants::INVALID_UID; EXPECT_TRUE(appMgrServiceInner->GenerateRenderUid(renderUid)); @@ -427,6 +439,7 @@ HWTEST_F(AppMgrServiceInnerTest, StartRenderProcessImpl_001, TestSize.Level0) { TAG_LOGI(AAFwkTag::TEST, "StartRenderProcessImpl_001 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); BundleInfo bundleInfo; std::string appName = "test_appName"; @@ -459,6 +472,7 @@ HWTEST_F(AppMgrServiceInnerTest, NotifyAppFault_001, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "NotifyAppFault_001 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); FaultData faultData; EXPECT_EQ(ERR_INVALID_VALUE, appMgrServiceInner->NotifyAppFault(faultData)); @@ -474,6 +488,7 @@ HWTEST_F(AppMgrServiceInnerTest, NotifyAppFaultBySA_001, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "NotifyAppFaultBySA_001 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); AppFaultDataBySA faultData; appMgrServiceInner->appRunningManager_ = nullptr; @@ -490,6 +505,7 @@ HWTEST_F(AppMgrServiceInnerTest, FaultTypeToString_001, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "FaultTypeToString_001 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); EXPECT_EQ("CPP_CRASH", appMgrServiceInner->FaultTypeToString(AppExecFwk::FaultDataType::CPP_CRASH)); EXPECT_EQ("JS_ERROR", appMgrServiceInner->FaultTypeToString(AppExecFwk::FaultDataType::JS_ERROR)); @@ -509,6 +525,7 @@ HWTEST_F(AppMgrServiceInnerTest, ChangeAppGcState_001, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "ChangeAppGcState_001 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); int32_t pid = 0; int32_t state = 0; @@ -526,6 +543,7 @@ HWTEST_F(AppMgrServiceInnerTest, QueryExtensionSandBox_001, TestSize.Level0) { TAG_LOGI(AAFwkTag::TEST, "QueryExtensionSandBox_001 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); const string moduleName = "entry"; const string extensionName = "inputMethod"; @@ -559,6 +577,7 @@ HWTEST_F(AppMgrServiceInnerTest, QueryExtensionSandBox_002, TestSize.Level0) { TAG_LOGI(AAFwkTag::TEST, "QueryExtensionSandBox_002 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); const string moduleName = "entry"; const string extensionName = "inputMethod"; @@ -592,6 +611,7 @@ HWTEST_F(AppMgrServiceInnerTest, QueryExtensionSandBox_003, TestSize.Level0) { TAG_LOGI(AAFwkTag::TEST, "QueryExtensionSandBox_003 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); const string moduleName = "entry"; const string extensionName = "inputMethod"; @@ -619,6 +639,7 @@ HWTEST_F(AppMgrServiceInnerTest, QueryExtensionSandBox_004, TestSize.Level0) { TAG_LOGI(AAFwkTag::TEST, "QueryExtensionSandBox_004 start"); auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->Init(); EXPECT_NE(appMgrServiceInner, nullptr); const string moduleName = "entry"; const string extensionName = "inputMethod"; diff --git a/test/unittest/app_mgr_service_test/BUILD.gn b/test/unittest/app_mgr_service_test/BUILD.gn index 53af697993..e5b06178f1 100644 --- a/test/unittest/app_mgr_service_test/BUILD.gn +++ b/test/unittest/app_mgr_service_test/BUILD.gn @@ -17,6 +17,13 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/appmgr" ohos_unittest("app_mgr_service_test") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../../cfi_blocklist.txt" + } + branch_protector_ret = "pac_ret" module_out_path = module_output_path include_dirs = [ diff --git a/test/unittest/app_running_processes_info_test/BUILD.gn b/test/unittest/app_running_processes_info_test/BUILD.gn index 21d1d6383f..edb3776170 100644 --- a/test/unittest/app_running_processes_info_test/BUILD.gn +++ b/test/unittest/app_running_processes_info_test/BUILD.gn @@ -17,13 +17,14 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/appmgrservice" ohos_unittest("AppRunningProcessesInfoTest") { - module_out_path = module_output_path sanitize = { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../cfi_blocklist.txt" } branch_protector_ret = "pac_ret" + module_out_path = module_output_path cflags_cc = [] include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", diff --git a/test/unittest/app_running_processes_info_test/app_running_processes_info_test.cpp b/test/unittest/app_running_processes_info_test/app_running_processes_info_test.cpp index 979b2cc9bb..ab9d0d9c26 100644 --- a/test/unittest/app_running_processes_info_test/app_running_processes_info_test.cpp +++ b/test/unittest/app_running_processes_info_test/app_running_processes_info_test.cpp @@ -287,83 +287,6 @@ HWTEST_F(AppRunningProcessesInfoTest, UpdateAppRunningRecord_002, TestSize.Level EXPECT_TRUE(res == ERR_OK); } -/* - * Feature: AppMgrServiceInner - * Function: GetAllRunningProcesses - * SubFunction: NA - * FunctionPoints: get running process info by token. - * EnvConditions: NA - * CaseDescription: creat two apprunningrecords, set record state, call query function. - */ -HWTEST_F(AppRunningProcessesInfoTest, UpdateAppRunningRecord_003, TestSize.Level1) -{ - auto abilityInfo = std::make_shared(); - abilityInfo->name = GetTestAbilityName(); - auto appInfo = std::make_shared(); - appInfo->name = GetTestAppName(); - int uid = 0; - BundleInfo bundleInfo; - bundleInfo.appId = "com.ohos.test.helloworld_code123"; - bundleInfo.jointUserId = "joint456"; - HapModuleInfo hapModuleInfo; - hapModuleInfo.moduleName = "module789"; - EXPECT_TRUE(service_ != nullptr); - auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); - EXPECT_TRUE(record != nullptr); - - record->SetUid(uid); - EXPECT_TRUE(record != nullptr) << ",create apprunningrecord fail!"; - - sptr mockApplication(new MockApplication()); - sptr client = iface_cast(mockApplication); - record->SetApplicationClient(client); - EXPECT_CALL(*mockApplication, ScheduleLaunchApplication(_, _)) - .Times(1) - .WillOnce(Invoke(mockApplication.GetRefPtr(), &MockApplication::LaunchApplication)); - Configuration config; - record->LaunchApplication(config); - mockApplication->Wait(); - - EXPECT_CALL(*mockApplication, ScheduleForegroundApplication()) - .Times(1) - .WillOnce(InvokeWithoutArgs(mockApplication.GetRefPtr(), &MockApplication::Post)); - // application enter in foreground and check the result - record->ScheduleForegroundRunning(); - mockApplication->Wait(); - - // update application state and check the state - record->SetState(ApplicationState::APP_STATE_FOREGROUND); - auto newRecord = service_->appRunningManager_->CheckAppRunningRecordIsExist( - appInfo->name, GetTestProcessName(), appInfo->uid, bundleInfo); - EXPECT_TRUE(newRecord); - newRecord->SetUid(0); - auto stateFromRec = newRecord->GetState(); - EXPECT_EQ(stateFromRec, ApplicationState::APP_STATE_FOREGROUND); - - auto abilityInfo2 = std::make_shared(); - abilityInfo2->name = GetTestAbilityName() + "2"; - abilityInfo2->applicationInfo.uid = uid; - auto appInfo2 = std::make_shared(); - appInfo2->name = GetTestAppName() + "2"; - appInfo2->uid = uid; - BundleInfo bundleInfo2; - HapModuleInfo hapModuleInfo2; - EXPECT_TRUE(service_ != nullptr); - auto mock_token = new (std::nothrow) MockAbilityToken(); - auto record2 = service_->CreateAppRunningRecord(mock_token, nullptr, appInfo2, abilityInfo2, - GetTestProcessName() + "2", bundleInfo2, hapModuleInfo2, nullptr, 0); - EXPECT_TRUE(record != nullptr); - record2->SetUid(uid); - - std::vector info; - size_t infoCount{ 2 }; - record->SetSpawned(); - record2->SetSpawned(); - auto res = service_->GetAllRunningProcesses(info); - EXPECT_TRUE(res == ERR_OK); -} - /* * Feature: AppMgrServiceInner * Function: GetRunningProcessInfoByToken diff --git a/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp index 95e0640ce3..afe82a3401 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp @@ -656,7 +656,7 @@ HWTEST_F(UIAbilityBaseTest, UIAbilityContinuation_0100, TestSize.Level1) // branch when launchReason is not LAUNCHREASON_CONTINUATION ret = ability->IsRestoredInContinuation(); EXPECT_EQ(ret, false); - launchParam.launchReason = LaunchReason::LAUNCHREASON_CONTINUATION; + launchParam.launchReason = LaunchReason::LAUNCHREASON_APP_RECOVERY; ability->SetLaunchParam(launchParam); // branch when contentStorage_ is nullptr From 245dbd15a8226049c6942f5affd81bcac12d49b6 Mon Sep 17 00:00:00 2001 From: zhuhan Date: Tue, 4 Jun 2024 21:44:30 +0800 Subject: [PATCH 67/69] fix config Signed-off-by: zhuhan Change-Id: I4b310659725c33a4fad3bb3a1d2cfbad505f8437 --- .../native/extension_ability_thread.cpp | 18 +----------------- .../native/ability/native/extension_impl.cpp | 4 +--- .../native/ability/native/ui_ability_impl.cpp | 7 +++---- 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/frameworks/native/ability/native/extension_ability_thread.cpp b/frameworks/native/ability/native/extension_ability_thread.cpp index e6998c0045..4d867bf645 100644 --- a/frameworks/native/ability/native/extension_ability_thread.cpp +++ b/frameworks/native/ability/native/extension_ability_thread.cpp @@ -355,23 +355,7 @@ void ExtensionAbilityThread::HandleCommandExtensionWindow( void ExtensionAbilityThread::ScheduleUpdateConfiguration(const AppExecFwk::Configuration &config) { TAG_LOGD(AAFwkTag::EXT, "Begin."); - if (abilityHandler_ == nullptr) { - TAG_LOGE(AAFwkTag::EXT, "abilityHandler_ is nullptr."); - return; - } - wptr weak = this; - auto task = [weak, config]() { - auto abilityThread = weak.promote(); - if (abilityThread == nullptr) { - TAG_LOGE(AAFwkTag::EXT, "Ability thread is nullptr."); - return; - } - abilityThread->HandleExtensionUpdateConfiguration(config); - }; - bool ret = abilityHandler_->PostTask(task); - if (!ret) { - TAG_LOGE(AAFwkTag::EXT, "PostTask error"); - } + HandleExtensionUpdateConfiguration(config); TAG_LOGD(AAFwkTag::EXT, "End."); } diff --git a/frameworks/native/ability/native/extension_impl.cpp b/frameworks/native/ability/native/extension_impl.cpp index 4fa9b01df8..631b48815c 100644 --- a/frameworks/native/ability/native/extension_impl.cpp +++ b/frameworks/native/ability/native/extension_impl.cpp @@ -131,9 +131,7 @@ void ExtensionImpl::ScheduleUpdateConfiguration(const AppExecFwk::Configuration return; } - if (lifecycleState_ != AAFwk::ABILITY_STATE_INITIAL) { - extension_->OnConfigurationUpdated(config); - } + extension_->OnConfigurationUpdated(config); } void ExtensionImpl::NotifyMemoryLevel(int level) diff --git a/frameworks/native/ability/native/ui_ability_impl.cpp b/frameworks/native/ability/native/ui_ability_impl.cpp index 7cec9fefc2..f607e6195c 100644 --- a/frameworks/native/ability/native/ui_ability_impl.cpp +++ b/frameworks/native/ability/native/ui_ability_impl.cpp @@ -322,10 +322,9 @@ void UIAbilityImpl::ScheduleUpdateConfiguration(const AppExecFwk::Configuration return; } - if (lifecycleState_ != AAFwk::ABILITY_STATE_INITIAL) { - TAG_LOGD(AAFwkTag::UIABILITY, "Ability name: [%{public}s].", ability_->GetAbilityName().c_str()); - ability_->OnConfigurationUpdatedNotify(config); - } + TAG_LOGD(AAFwkTag::UIABILITY, "Ability name: [%{public}s].", ability_->GetAbilityName().c_str()); + ability_->OnConfigurationUpdatedNotify(config); + TAG_LOGD(AAFwkTag::UIABILITY, "End."); } From 84a8c7493ba7824e946a7c273b4478bcbb3320a4 Mon Sep 17 00:00:00 2001 From: wangzhen Date: Wed, 5 Jun 2024 11:35:17 +0800 Subject: [PATCH 68/69] Remove JSAbilityForegroundStateObserver mutex used only in single thread Signed-off-by: wangzhen Change-Id: I66e6741df8820e26d60c0e0b2fb486b984f2f11e --- .../ability_manager/js_ability_foreground_state_observer.cpp | 5 ----- .../ability_manager/js_ability_foreground_state_observer.h | 1 - 2 files changed, 6 deletions(-) diff --git a/frameworks/js/napi/ability_manager/js_ability_foreground_state_observer.cpp b/frameworks/js/napi/ability_manager/js_ability_foreground_state_observer.cpp index 05698d00cf..19eb11eb4e 100644 --- a/frameworks/js/napi/ability_manager/js_ability_foreground_state_observer.cpp +++ b/frameworks/js/napi/ability_manager/js_ability_foreground_state_observer.cpp @@ -51,7 +51,6 @@ void JSAbilityForegroundStateObserver::OnAbilityStateChanged(const AbilityStateD void JSAbilityForegroundStateObserver::HandleOnAbilityStateChanged(const AbilityStateData &abilityStateData) { TAG_LOGD(AAFwkTag::ABILITYMGR, "Called."); - std::lock_guard lock(mutexlock_); for (auto &item : jsObserverObjectSet_) { if (item == nullptr) { continue; @@ -112,7 +111,6 @@ void JSAbilityForegroundStateObserver::AddJsObserverObject(const napi_value &jsO } napi_ref ref = nullptr; napi_create_reference(env_, jsObserverObject, 1, &ref); - std::lock_guard lock(mutexlock_); jsObserverObjectSet_.emplace(std::shared_ptr(reinterpret_cast(ref))); } @@ -124,7 +122,6 @@ void JSAbilityForegroundStateObserver::RemoveJsObserverObject(const napi_value & } auto observer = GetObserverObject(jsObserverObject); - std::lock_guard lock(mutexlock_); if (observer != nullptr) { jsObserverObjectSet_.erase(observer); } @@ -132,7 +129,6 @@ void JSAbilityForegroundStateObserver::RemoveJsObserverObject(const napi_value & void JSAbilityForegroundStateObserver::RemoveAllJsObserverObject() { - std::lock_guard lock(mutexlock_); if (!jsObserverObjectSet_.empty()) { jsObserverObjectSet_.clear(); } @@ -144,7 +140,6 @@ std::shared_ptr JSAbilityForegroundStateObserver::GetObserverOb TAG_LOGE(AAFwkTag::ABILITYMGR, "Observer is null."); return nullptr; } - std::lock_guard lock(mutexlock_); for (auto &observer : jsObserverObjectSet_) { if (observer == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Invalid observer."); diff --git a/frameworks/js/napi/ability_manager/js_ability_foreground_state_observer.h b/frameworks/js/napi/ability_manager/js_ability_foreground_state_observer.h index 3723a0a9ff..9dcca39151 100644 --- a/frameworks/js/napi/ability_manager/js_ability_foreground_state_observer.h +++ b/frameworks/js/napi/ability_manager/js_ability_foreground_state_observer.h @@ -47,7 +47,6 @@ public: private: napi_env env_; volatile bool valid_ = true; - std::mutex mutexlock_; std::set> jsObserverObjectSet_; }; } // namespace AbilityRuntime From 154a23c68d1ddb40cd95de03a71152cb7f1a4d21 Mon Sep 17 00:00:00 2001 From: zhubingwei Date: Mon, 3 Jun 2024 14:56:46 +0800 Subject: [PATCH 69/69] fix TDD crash caused by CFI change in GN Signed-off-by: zhubingwei Change-Id: I4f1398e8b9cf21135107672b9c3ac4a06a4c4ce5 --- test/unittest/ability_manager_stub_test/BUILD.gn | 6 ++++++ test/unittest/ability_record_test/BUILD.gn | 12 ++++++++++++ test/unittest/app_mgr_service_test/BUILD.gn | 6 ++++++ test/unittest/call_container_test/BUILD.gn | 6 ++++++ 4 files changed, 30 insertions(+) diff --git a/test/unittest/ability_manager_stub_test/BUILD.gn b/test/unittest/ability_manager_stub_test/BUILD.gn index a95f730f6f..7671f754fb 100644 --- a/test/unittest/ability_manager_stub_test/BUILD.gn +++ b/test/unittest/ability_manager_stub_test/BUILD.gn @@ -18,6 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("ability_manager_stub_test") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", diff --git a/test/unittest/ability_record_test/BUILD.gn b/test/unittest/ability_record_test/BUILD.gn index 00629fe296..10eb3f1a34 100644 --- a/test/unittest/ability_record_test/BUILD.gn +++ b/test/unittest/ability_record_test/BUILD.gn @@ -18,6 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("ability_record_test") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_services_path}/appdfr/include", @@ -94,6 +100,12 @@ ohos_unittest("ability_record_test") { ohos_unittest("ability_record_test_call") { module_out_path = "ability_runtime/ability_call_test" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_path}/interfaces/inner_api/ability_manager/include/", diff --git a/test/unittest/app_mgr_service_test/BUILD.gn b/test/unittest/app_mgr_service_test/BUILD.gn index 53af697993..2b08eac271 100644 --- a/test/unittest/app_mgr_service_test/BUILD.gn +++ b/test/unittest/app_mgr_service_test/BUILD.gn @@ -18,6 +18,12 @@ module_output_path = "ability_runtime/appmgr" ohos_unittest("app_mgr_service_test") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/mock_appmgr_service/include", diff --git a/test/unittest/call_container_test/BUILD.gn b/test/unittest/call_container_test/BUILD.gn index 961d67433d..e86b0c5073 100644 --- a/test/unittest/call_container_test/BUILD.gn +++ b/test/unittest/call_container_test/BUILD.gn @@ -18,6 +18,12 @@ module_output_path = "ability_runtime/ability_call_test" ohos_unittest("call_container_test") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/include",