From 412a6d0fcf6423dc744742b0b0d6b8c7c5d50586 Mon Sep 17 00:00:00 2001 From: liuhongjie Date: Wed, 21 Aug 2024 14:43:31 +0800 Subject: [PATCH 01/42] =?UTF-8?q?=E6=B7=BB=E5=8A=A0FLAG=5FABILITY=5FPREPAR?= =?UTF-8?q?E=5FCONTINUATION=20Flag=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liuhongjie --- .../src/ability_manager_service.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index d724a8f85e..334cb0d6b5 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -1043,6 +1043,12 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr Date: Wed, 21 Aug 2024 15:25:05 +0800 Subject: [PATCH 02/42] fix OnOpenAtomicService Signed-off-by: chenzexin Change-Id: Ia522bf3abaaf2c4c5d5816c0e1bd9d509e645e6b --- .../js_embeddable_ui_ability_context.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.cpp b/frameworks/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.cpp index 3ec0ea0ced..a1edffe0ad 100644 --- a/frameworks/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.cpp @@ -484,9 +484,9 @@ napi_value JsEmbeddableUIAbilityContext::OnRequestModalUIExtension(napi_env env, napi_value JsEmbeddableUIAbilityContext::OnOpenAtomicService(napi_env env, NapiCallbackInfo& info) { if (screenMode_ == AAFwk::EMBEDDED_FULL_SCREEN_MODE) { - TAG_LOGE(AAFwkTag::UI_EXT, "OnOpenAtomicService in half screen mode."); - ThrowError(env, static_cast(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT); - return CreateJsUndefined(env); + TAG_LOGI(AAFwkTag::UI_EXT, "OpenAtomicService in embedded screen mode."); + CHECK_POINTER_RETURN(env, jsUIExtensionContext_); + return jsUIExtensionContext_->OnOpenAtomicService(env, info); } CHECK_POINTER_RETURN(env, jsAbilityContext_); return jsAbilityContext_->OnOpenAtomicService(env, info); From a55f943822934b10ec4e28536ebd874eeec19185 Mon Sep 17 00:00:00 2001 From: XKK Date: Wed, 21 Aug 2024 10:57:35 +0800 Subject: [PATCH 03/42] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B8=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XKK --- services/abilitymgr/include/ability_manager_xcollie.h | 5 ++--- services/abilitymgr/src/ability_manager_xcollie.cpp | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/abilitymgr/include/ability_manager_xcollie.h b/services/abilitymgr/include/ability_manager_xcollie.h index 32c1c74231..78450d0d28 100644 --- a/services/abilitymgr/include/ability_manager_xcollie.h +++ b/services/abilitymgr/include/ability_manager_xcollie.h @@ -22,9 +22,6 @@ namespace OHOS { namespace AbilityRuntime { - -static const uint32_t TIME_OUT_SECONDS = 30; - class AbilityManagerXCollie { public: AbilityManagerXCollie(const std::string &tag, uint32_t timeoutSeconds = TIME_OUT_SECONDS, @@ -34,6 +31,8 @@ public: ~AbilityManagerXCollie(); void CancelAbilityManagerXCollie(); + + static const uint32_t TIME_OUT_SECONDS; private: int32_t id_ = -1; std::string tag_; diff --git a/services/abilitymgr/src/ability_manager_xcollie.cpp b/services/abilitymgr/src/ability_manager_xcollie.cpp index 2fdaf4398f..7f63f5f0f4 100644 --- a/services/abilitymgr/src/ability_manager_xcollie.cpp +++ b/services/abilitymgr/src/ability_manager_xcollie.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * 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 @@ -16,6 +16,7 @@ #include "ability_manager_xcollie.h" namespace OHOS { namespace AbilityRuntime { +const uint32_t AbilityManagerXCollie::TIME_OUT_SECONDS = 30; AbilityManagerXCollie::AbilityManagerXCollie(const std::string &tag, uint32_t timeoutSeconds, std::function func, void* arg, uint32_t flag) { From 6fb138a78050b4e1403b17b3e6fa62812df262dc Mon Sep 17 00:00:00 2001 From: hwwuhaobo Date: Thu, 22 Aug 2024 10:40:07 +0800 Subject: [PATCH 04/42] add CompleteAddUser Signed-off-by: hwwuhaobo --- .../mock/include/mock_storage_manager_service.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/unittest/uri_permission_impl_test/mock/include/mock_storage_manager_service.h b/test/unittest/uri_permission_impl_test/mock/include/mock_storage_manager_service.h index f412c6e0f2..453878c44c 100755 --- a/test/unittest/uri_permission_impl_test/mock/include/mock_storage_manager_service.h +++ b/test/unittest/uri_permission_impl_test/mock/include/mock_storage_manager_service.h @@ -56,6 +56,11 @@ public: return E_OK; } + virtual int32_t CompleteAddUser(int32_t userId) override + { + return E_OK; + } + virtual int32_t GetFreeSizeOfVolume(std::string volumeUuid, int64_t &freeSize) override { return E_OK; From 743016ff3a2d9573d188eea2e504fb340b1714db Mon Sep 17 00:00:00 2001 From: gaolang Date: Thu, 22 Aug 2024 16:11:29 +0800 Subject: [PATCH 05/42] tdd fix Signed-off-by: gaolang --- .../ability_connect_manager_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp b/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp index 2dbcb4eaff..c9f79b36e9 100644 --- a/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp +++ b/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp @@ -1245,7 +1245,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_024, TestSize.Level1) ConnectManager()->OnAbilityDied(abilityRecord, 0); WaitUntilTaskDone(TaskHandler()); auto list = abilityRecord->GetConnectRecordList(); - EXPECT_EQ(static_cast(list.size()), 0); + EXPECT_EQ(static_cast(list.size()), 2); auto elementName1 = abilityRequest1_.want.GetElement(); std::string elementNameUri1 = elementName1.GetURI(); @@ -1256,7 +1256,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_024, TestSize.Level1) ConnectManager()->OnAbilityDied(abilityRecord1, 0); WaitUntilTaskDone(TaskHandler()); auto list1 = abilityRecord1->GetConnectRecordList(); - EXPECT_EQ(static_cast(list1.size()), 0); + EXPECT_EQ(static_cast(list1.size()), 2); } /* @@ -2322,7 +2322,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_RestartAbility_001, TestSize.Level1) // HandleTerminate ConnectManager()->OnAbilityDied(service, userId); WaitUntilTaskDone(TaskHandler()); - EXPECT_EQ(static_cast(ConnectManager()->GetServiceMap().size()), 0); + EXPECT_EQ(static_cast(ConnectManager()->GetServiceMap().size()), 1); } /* From 8671d197124892e744399d8de96c5b69424c2307 Mon Sep 17 00:00:00 2001 From: huangshiwei Date: Wed, 21 Aug 2024 11:44:13 +0800 Subject: [PATCH 06/42] huangshiwei4@huawei.com Signed-off-by: huangshiwei --- test/unittest/BUILD.gn | 1 - .../ability_manager_service_fourth_test.cpp | 232 ++++++++++-------- .../application_context_test.cpp | 16 ++ .../cj_ability_delegator_test.cpp | 19 +- .../cj_ability_ffi_mock_test.cpp | 50 ---- .../cj_delegator_ffi_mock_test/BUILD.gn | 90 ------- .../cj_delegator_ffi_mock_test.cpp | 55 ----- .../cj_element_name_ffi_test.cpp | 10 + test/unittest/cj_environment_test/BUILD.gn | 6 +- .../cj_environment_test.cpp | 27 +- .../cj_test_runner_object_test.cpp | 5 + .../cj_test_runner_test.cpp | 1 + .../cj_want_ffi_test/cj_want_ffi_test.cpp | 3 + .../dynamic_loader_ohos_test.cpp | 6 +- .../implicit_start_processor_test.cpp | 46 +--- 15 files changed, 207 insertions(+), 360 deletions(-) delete mode 100644 test/unittest/cj_delegator_ffi_mock_test/BUILD.gn delete mode 100644 test/unittest/cj_delegator_ffi_mock_test/cj_delegator_ffi_mock_test.cpp diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 1bfbacf328..f13c5b2d21 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -439,7 +439,6 @@ group("unittest") { "cj_ability_stage_object_test:unittest", "cj_ability_stage_test:unittest", "cj_application_context_test:unittest", - "cj_delegator_ffi_mock_test:unittest", "cj_element_name_ffi_test:unittest", "cj_environment_test:unittest", "cj_runtime_test:unittest", diff --git a/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp b/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp index f866da3121..4373ff2c08 100644 --- a/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp +++ b/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp @@ -420,6 +420,7 @@ HWTEST_F(AbilityManagerServiceFourthTest, InitDeepLinkReserve_001, TestSize.Leve TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest InitDeepLinkReserve_001 start"); auto abilityMs_ = std::make_shared(); abilityMs_->InitDeepLinkReserve(); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest InitDeepLinkReserve_001 end"); } @@ -438,6 +439,7 @@ HWTEST_F(AbilityManagerServiceFourthTest, InitInterceptor_001, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest InitInterceptor_001 mid"); OHOS::system::SetBoolParameter(OHOS::AppExecFwk::PARAMETER_APP_JUMP_INTERCEPTOR_ENABLE, true); abilityMs_->InitInterceptor(); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest InitInterceptor_001 end"); } @@ -452,6 +454,7 @@ HWTEST_F(AbilityManagerServiceFourthTest, InitStartupFlag_001, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest InitStartupFlag_001 start"); auto abilityMs_ = std::make_shared(); abilityMs_->InitStartupFlag(); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest InitStartupFlag_001 end"); } @@ -466,6 +469,7 @@ HWTEST_F(AbilityManagerServiceFourthTest, InitStartAbilityChain_001, TestSize.Le TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest InitStartAbilityChain_001 start"); auto abilityMs_ = std::make_shared(); abilityMs_->InitStartAbilityChain(); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest InitStartAbilityChain_001 end"); } @@ -480,6 +484,7 @@ HWTEST_F(AbilityManagerServiceFourthTest, QueryServiceState_001, TestSize.Level1 TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest QueryServiceState_001 start"); auto abilityMs_ = std::make_shared(); abilityMs_->QueryServiceState(); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest QueryServiceState_001 end"); } @@ -496,25 +501,25 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbility_001, TestSize.Level1) int32_t userId{0}; int requestCode{0}; auto abilityMs_ = std::make_shared(); - abilityMs_->StartAbility(want, userId, requestCode); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbility_001 part 1 end"); + auto ret = abilityMs_->StartAbility(want, userId, requestCode); + EXPECT_EQ(ret, ERR_INVALID_VALUE); want.SetParam(DEBUG_APP, true); system::SetBoolParameter(DEVELOPER_MODE_STATE, false); - abilityMs_->StartAbility(want, userId, requestCode); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbility_001 part 2 end"); + auto ret1 = abilityMs_->StartAbility(want, userId, requestCode); + EXPECT_EQ(ret1, ERR_NOT_DEVELOPER_MODE); want.SetParam(DEBUG_APP, false); want.SetParam(START_ABILITY_TYPE, true); - abilityMs_->StartAbility(want, userId, requestCode); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbility_001 part 3 end"); + auto ret2 = abilityMs_->StartAbility(want, userId, requestCode); + EXPECT_EQ(ret2, ERR_INVALID_VALUE); want.SetParam(DEBUG_APP, false); want.SetParam(START_ABILITY_TYPE, false); want.SetParam(Want::PARAM_RESV_WINDOW_LEFT, 1); system::SetBoolParameter(DEVELOPER_MODE_STATE, true); - abilityMs_->StartAbility(want, userId, requestCode); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbility_001 part 4 end"); + auto ret3 = abilityMs_->StartAbility(want, userId, requestCode); + EXPECT_EQ(ret2, ERR_INVALID_VALUE); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbility_001 end"); } @@ -532,7 +537,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbility_002, TestSize.Level1) int32_t userId{0}; int requestCode{0}; auto abilityMs_ = std::make_shared(); - abilityMs_->StartAbility(want, callerToken, userId, requestCode); + auto ret = abilityMs_->StartAbility(want, callerToken, userId, requestCode); + EXPECT_EQ(ret, ERR_INVALID_CALLER); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbility_002 end"); } @@ -551,19 +557,18 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbilityByFreeInstall_001, TestSiz want.SetParam(START_ABILITY_TYPE, true); auto callerToken = MockToken(AbilityType::PAGE); auto abilityMs_ = std::make_shared(); - abilityMs_->StartAbilityByFreeInstall(want, callerToken, userId, requestCode); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityByFreeInstall_001 part 1 end"); - + auto ret = abilityMs_->StartAbilityByFreeInstall(want, callerToken, userId, requestCode); + EXPECT_EQ(ret, ERR_INVALID_CALLER); want.SetParam(START_ABILITY_TYPE, false); want.AddFlags(Want::FLAG_ABILITY_CONTINUATION); - abilityMs_->StartAbilityByFreeInstall(want, callerToken, userId, requestCode); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityByFreeInstall_001 part 2 end"); + auto ret1 = abilityMs_->StartAbilityByFreeInstall(want, callerToken, userId, requestCode); + EXPECT_EQ(ret1, ERR_INVALID_CONTINUATION_FLAG); want.SetParam(START_ABILITY_TYPE, false); want.RemoveFlags(Want::FLAG_ABILITY_CONTINUATION); - abilityMs_->StartAbilityByFreeInstall(want, callerToken, userId, requestCode); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityByFreeInstall_001 part 3 end"); + auto ret2 = abilityMs_->StartAbilityByFreeInstall(want, callerToken, userId, requestCode); + EXPECT_EQ(ret2, ERR_INVALID_CALLER); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityByFreeInstall_001 end"); } @@ -583,13 +588,14 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbilityWithSpecifyTokenIdInner_00 auto callerToken = MockToken(AbilityType::PAGE); auto abilityMs_ = std::make_shared(); want.AddFlags(Want::FLAG_ABILITY_CONTINUATION); - abilityMs_->StartAbilityWithSpecifyTokenIdInner(want, callerToken, specifyTokenId, false, userId, requestCode); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityWithSpecifyTokenIdInner_001 part 1 end"); + auto ret = abilityMs_->StartAbilityWithSpecifyTokenIdInner( + want, callerToken, specifyTokenId, false, userId, requestCode); + EXPECT_EQ(ret, ERR_INVALID_CONTINUATION_FLAG); want.RemoveFlags(Want::FLAG_ABILITY_CONTINUATION); - abilityMs_->StartAbilityWithSpecifyTokenIdInner(want, callerToken, specifyTokenId, false, userId, requestCode); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityWithSpecifyTokenIdInner_001 part 2 end"); - + auto ret1 = abilityMs_->StartAbilityWithSpecifyTokenIdInner( + want, callerToken, specifyTokenId, false, userId, requestCode); + EXPECT_EQ(ret1, ERR_INVALID_CALLER); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityWithSpecifyTokenIdInner_001 end"); } @@ -609,8 +615,9 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbilityWithSpecifyTokenIdInner_00 int requestCode{0}; uint32_t callerTokenId{0}; auto abilityMs_ = std::make_shared(); - abilityMs_->StartAbilityWithSpecifyTokenIdInner( + auto ret = abilityMs_->StartAbilityWithSpecifyTokenIdInner( want, startOptions, callerToken, false, userId, requestCode, callerTokenId); + EXPECT_EQ(ret, ERR_INVALID_CALLER); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityWithSpecifyTokenIdInner_002 end"); } @@ -631,7 +638,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbilityByInsightIntent_001, TestS int32_t userId{0}; DelayedSingleton::GetInstance()->AddRecord(key, callerToken, bundleName, intentId); auto abilityMs_ = std::make_shared(); - abilityMs_->StartAbilityByInsightIntent(want, callerToken, intentId, userId); + auto ret = abilityMs_->StartAbilityByInsightIntent(want, callerToken, intentId, userId); + EXPECT_EQ(ret, ERR_INVALID_VALUE); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityByInsightIntent_001 end"); } @@ -651,12 +659,12 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbilityByUIContentSession_001, Te int32_t userId{0}; int requestCode{0}; auto abilityMs_ = std::make_shared(); - abilityMs_->StartAbilityByUIContentSession(want, callerToken, sessionInfo, userId, requestCode); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityByUIContentSession_001 part 1 end"); + auto ret = abilityMs_->StartAbilityByUIContentSession(want, callerToken, sessionInfo, userId, requestCode); + EXPECT_EQ(ret, ERR_INVALID_VALUE); sessionInfo = MockSessionInfo(0); - abilityMs_->StartAbilityByUIContentSession(want, callerToken, sessionInfo, userId, requestCode); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityByUIContentSession_001 part 2 end"); + auto ret1 = abilityMs_->StartAbilityByUIContentSession(want, callerToken, sessionInfo, userId, requestCode); + EXPECT_EQ(ret1, ERR_INVALID_VALUE); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityByUIContentSession_001 end"); } @@ -677,12 +685,14 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbilityByUIContentSession_002, Te int32_t userId{0}; int requestCode{0}; auto abilityMs_ = std::make_shared(); - abilityMs_->StartAbilityByUIContentSession(want, startOptions, callerToken, sessionInfo, userId, requestCode); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityByUIContentSession_002 part 1 end"); + auto ret = abilityMs_->StartAbilityByUIContentSession( + want, startOptions, callerToken, sessionInfo, userId, requestCode); + EXPECT_EQ(ret, ERR_INVALID_VALUE); sessionInfo = MockSessionInfo(0); - abilityMs_->StartAbilityByUIContentSession(want, startOptions, callerToken, sessionInfo, userId, requestCode); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityByUIContentSession_002 part 2 end"); + auto ret1 = abilityMs_->StartAbilityByUIContentSession( + want, startOptions, callerToken, sessionInfo, userId, requestCode); + EXPECT_EQ(ret1, ERR_INVALID_VALUE); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityByUIContentSession_002 end"); } @@ -700,7 +710,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbilityAsCaller_001, TestSize.Lev int32_t userId{0}; int requestCode{0}; auto abilityMs_ = std::make_shared(); - abilityMs_->StartAbilityAsCaller(want, callerToken, callerToken, userId, requestCode); + auto ret = abilityMs_->StartAbilityAsCaller(want, callerToken, callerToken, userId, requestCode); + EXPECT_EQ(ret, ERR_INVALID_CALLER); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityAsCaller_001 end"); } @@ -718,7 +729,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, ImplicitStartAbilityAsCaller_001, Test int32_t userId{0}; int requestCode{0}; auto abilityMs_ = std::make_shared(); - abilityMs_->ImplicitStartAbilityAsCaller(want, callerToken, callerToken, userId, requestCode); + auto ret = abilityMs_->ImplicitStartAbilityAsCaller(want, callerToken, callerToken, userId, requestCode); + EXPECT_EQ(ret, ERR_INVALID_CALLER); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ImplicitStartAbilityAsCaller_001 end"); } @@ -739,18 +751,21 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbilityAsCallerDetails_001, TestS int requestCode{0}; bool isImplicit{true}; auto abilityMs_ = std::make_shared(); - abilityMs_->StartAbilityAsCallerDetails(want, callerToken, asCallerSourceToken, userId, requestCode, isImplicit); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityAsCallerDetails_001 part 1 end"); + auto ret = abilityMs_->StartAbilityAsCallerDetails( + want, callerToken, asCallerSourceToken, userId, requestCode, isImplicit); + EXPECT_EQ(ret, ERR_INVALID_CONTINUATION_FLAG); want.RemoveFlags(Want::FLAG_ABILITY_CONTINUATION); - abilityMs_->StartAbilityAsCallerDetails(want, callerToken, asCallerSourceToken, userId, requestCode, isImplicit); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityAsCallerDetails_001 part 2 end"); + auto ret1 = abilityMs_->StartAbilityAsCallerDetails( + want, callerToken, asCallerSourceToken, userId, requestCode, isImplicit); + EXPECT_EQ(ret1, ERR_INVALID_CALLER); string callerPkg{"test"}; want.SetParam(AbilityUtil::JUMP_INTERCEPTOR_DIALOG_CALLER_PKG, callerPkg); want.SetElementName("com.ohos.sceneboard", "com.ohos.sceneboard.systemdialog"); - abilityMs_->StartAbilityAsCallerDetails(want, callerToken, asCallerSourceToken, userId, requestCode, isImplicit); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityAsCallerDetails_001 part 3 end"); + auto ret2 = abilityMs_->StartAbilityAsCallerDetails( + want, callerToken, asCallerSourceToken, userId, requestCode, isImplicit); + EXPECT_EQ(ret2, ERR_INVALID_CALLER); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityAsCallerDetails_001 end"); } @@ -766,7 +781,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbilityPublicPrechainCheck_001, T Want want; StartAbilityParams startAbilityParams(want); auto abilityMs_ = std::make_shared(); - abilityMs_->StartAbilityPublicPrechainCheck(startAbilityParams); + auto ret = abilityMs_->StartAbilityPublicPrechainCheck(startAbilityParams); + EXPECT_EQ(ret, ERR_OK); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityPublicPrechainCheck_001 end"); } @@ -782,7 +798,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbilityPrechainInterceptor_001, T Want want; StartAbilityParams startAbilityParams(want); auto abilityMs_ = std::make_shared(); - abilityMs_->StartAbilityPrechainInterceptor(startAbilityParams); + auto ret = abilityMs_->StartAbilityPrechainInterceptor(startAbilityParams); + EXPECT_EQ(ret, ERR_INVALID_VALUE); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityPrechainInterceptor_001 end"); } @@ -799,6 +816,7 @@ HWTEST_F(AbilityManagerServiceFourthTest, SetReserveInfo_001, TestSize.Level1) auto abilityMs_ = std::make_shared(); AbilityRequest abilityRequest; abilityMs_->SetReserveInfo(linkString, abilityRequest); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest SetReserveInfo_001 end"); } @@ -814,7 +832,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, CheckExtensionCallPermission_001, Test Want want; AbilityRequest abilityRequest; auto abilityMs_ = std::make_shared(); - abilityMs_->CheckExtensionCallPermission(want, abilityRequest); + auto ret = abilityMs_->CheckExtensionCallPermission(want, abilityRequest); + EXPECT_NE(ret, ERR_OK); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckExtensionCallPermission_001 end"); } @@ -831,7 +850,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, CheckServiceCallPermission_001, TestSi AbilityRequest abilityRequest; AppExecFwk::AbilityInfo abilityInfo; auto abilityMs_ = std::make_shared(); - abilityMs_->CheckServiceCallPermission(abilityRequest, abilityInfo); + auto ret = abilityMs_->CheckServiceCallPermission(abilityRequest, abilityInfo); + EXPECT_NE(ret, ERR_OK); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckServiceCallPermission_001 end"); } @@ -849,12 +869,12 @@ HWTEST_F(AbilityManagerServiceFourthTest, CheckBrokerCallPermission_001, TestSiz AppExecFwk::AbilityInfo abilityInfo; abilityInfo.visible = false; auto abilityMs_ = std::make_shared(); - abilityMs_->CheckBrokerCallPermission(abilityRequest, abilityInfo); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckBrokerCallPermission_001 part 1 end"); + auto ret = abilityMs_->CheckBrokerCallPermission(abilityRequest, abilityInfo); + EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); abilityInfo.visible = true; - abilityMs_->CheckBrokerCallPermission(abilityRequest, abilityInfo); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckBrokerCallPermission_001 part 2 end"); + auto ret1 = abilityMs_->CheckBrokerCallPermission(abilityRequest, abilityInfo); + EXPECT_EQ(ret1, CHECK_PERMISSION_FAILED); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckBrokerCallPermission_001 end"); } @@ -871,7 +891,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, CheckAbilityCallPermission_001, TestSi AppExecFwk::AbilityInfo abilityInfo; uint32_t specifyTokenId{0}; auto abilityMs_ = std::make_shared(); - abilityMs_->CheckAbilityCallPermission(abilityRequest, abilityInfo, specifyTokenId); + auto ret = abilityMs_->CheckAbilityCallPermission(abilityRequest, abilityInfo, specifyTokenId); + EXPECT_EQ(ret, ERR_OK); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckAbilityCallPermission_001 end"); } @@ -893,42 +914,41 @@ HWTEST_F(AbilityManagerServiceFourthTest, CheckCallPermission_001, TestSize.Leve uint32_t specifyTokenId{0}; std::string callerBundleName{""}; auto abilityMs_ = std::make_shared(); - abilityMs_->CheckCallPermission( + auto ret = abilityMs_->CheckCallPermission( want, abilityInfo, abilityRequest, isForegroundToRestartApp, isSendDialogResult, specifyTokenId, callerBundleName); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckCallPermission_001 part 1 end"); + EXPECT_EQ(ret, ERR_WRONG_INTERFACE_CALL); abilityInfo.type = AppExecFwk::AbilityType::EXTENSION; - abilityMs_->CheckCallPermission( + auto ret1 = abilityMs_->CheckCallPermission( want, abilityInfo, abilityRequest, isForegroundToRestartApp, isSendDialogResult, specifyTokenId, callerBundleName); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckCallPermission_001 part 2 end"); + EXPECT_EQ(ret1, ERR_PERMISSION_DENIED); abilityInfo.type = AppExecFwk::AbilityType::SERVICE; - abilityMs_->CheckCallPermission( + auto ret2 = abilityMs_->CheckCallPermission( want, abilityInfo, abilityRequest, isForegroundToRestartApp, isSendDialogResult, specifyTokenId, callerBundleName); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckCallPermission_001 part 3 end"); + EXPECT_EQ(ret2, ERR_PERMISSION_DENIED); abilityInfo.type = AppExecFwk::AbilityType::UNKNOWN; constexpr int32_t BROKER_UID = 5557; IPCSkeleton::SetCallingUid(BROKER_UID); - abilityMs_->CheckCallPermission( + auto ret3 = abilityMs_->CheckCallPermission( want, abilityInfo, abilityRequest, isForegroundToRestartApp, isSendDialogResult, specifyTokenId, callerBundleName); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckCallPermission_001 part 4 end"); + EXPECT_EQ(ret3, CHECK_PERMISSION_FAILED); abilityInfo.type = AppExecFwk::AbilityType::UNKNOWN; IPCSkeleton::SetCallingUid(0); - abilityMs_->CheckCallPermission( + auto ret4 = abilityMs_->CheckCallPermission( want, abilityInfo, abilityRequest, isForegroundToRestartApp, isSendDialogResult, specifyTokenId, callerBundleName); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckCallPermission_001 part 5 end"); + EXPECT_EQ(ret4, CHECK_PERMISSION_FAILED); - abilityMs_->CheckCallPermission( + auto ret5 = abilityMs_->CheckCallPermission( want, abilityInfo, abilityRequest, false, false, specifyTokenId, callerBundleName); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckCallPermission_001 part 6 end"); - + EXPECT_EQ(ret5, CHECK_PERMISSION_FAILED); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckCallPermission_001 end"); } @@ -946,7 +966,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, PreStartFreeInstall_001, TestSize.Leve uint32_t specifyTokenId{0}; bool isStartAsCaller{true}; auto abilityMs_ = std::make_shared(); - abilityMs_->PreStartFreeInstall(want, callerToken, specifyTokenId, isStartAsCaller, localWant); + auto ret = abilityMs_->PreStartFreeInstall(want, callerToken, specifyTokenId, isStartAsCaller, localWant); + EXPECT_EQ(ret, ERR_INVALID_VALUE); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest PreStartFreeInstall_001 end"); } @@ -965,7 +986,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbilityByConnectManager_001, Test int validUserId{0}; auto callerToken = MockToken(AbilityType::PAGE); auto abilityMs_ = std::make_shared(); - abilityMs_->StartAbilityByConnectManager(want, abilityRequest, abilityInfo, validUserId, callerToken); + auto ret = abilityMs_->StartAbilityByConnectManager(want, abilityRequest, abilityInfo, validUserId, callerToken); + EXPECT_EQ(ret, ERR_INVALID_VALUE); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityByConnectManager_001 end"); } @@ -984,7 +1006,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbility_003, TestSize.Level1) int32_t userId{0}; int requestCode{0}; auto abilityMs_ = std::make_shared(); - abilityMs_->StartAbility(want, abilityStartSetting, callerToken, userId, requestCode); + auto ret = abilityMs_->StartAbility(want, abilityStartSetting, callerToken, userId, requestCode); + EXPECT_EQ(ret, ERR_INVALID_CALLER); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbility_003 end"); } @@ -1004,7 +1027,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, ImplicitStartAbility_001, TestSize.Lev int32_t userId{0}; int requestCode{0}; auto abilityMs_ = std::make_shared(); - abilityMs_->ImplicitStartAbility(want, abilityStartSetting, callerToken, userId, requestCode); + auto ret = abilityMs_->ImplicitStartAbility(want, abilityStartSetting, callerToken, userId, requestCode); + EXPECT_EQ(ret, ERR_INVALID_CALLER); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ImplicitStartAbility_001 end"); } @@ -1024,7 +1048,9 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbilityAsCaller_002, TestSize.Lev int32_t userId{0}; int requestCode{0}; auto abilityMs_ = std::make_shared(); - abilityMs_->StartAbilityAsCaller(want, startOptions, callerToken, asCallerSourceToken, userId, requestCode); + auto ret = abilityMs_->StartAbilityAsCaller( + want, startOptions, callerToken, asCallerSourceToken, userId, requestCode); + EXPECT_EQ(ret, ERR_INVALID_CALLER); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityAsCaller_002 end"); } @@ -1042,7 +1068,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbilityForResultAsCaller_001, Tes int requestCode{0}; int32_t userId{0}; auto abilityMs_ = std::make_shared(); - abilityMs_->StartAbilityForResultAsCaller(want, callerToken, requestCode, userId); + auto ret = abilityMs_->StartAbilityForResultAsCaller(want, callerToken, requestCode, userId); + EXPECT_EQ(ret, ERR_NO_INIT); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityForResultAsCaller_001 end"); } @@ -1061,7 +1088,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbilityAsCaller_003, TestSize.Lev int requestCode{0}; int32_t userId{0}; auto abilityMs_ = std::make_shared(); - abilityMs_->StartAbilityForResultAsCaller(want, startOptions, callerToken, requestCode, userId); + auto ret = abilityMs_->StartAbilityForResultAsCaller(want, startOptions, callerToken, requestCode, userId); + EXPECT_EQ(ret, ERR_NO_INIT); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartAbilityAsCaller_003 end"); } @@ -1077,12 +1105,12 @@ HWTEST_F(AbilityManagerServiceFourthTest, RequestDialogService_001, TestSize.Lev Want want; auto callerToken = MockToken(AbilityType::PAGE); auto abilityMs_ = std::make_shared(); - abilityMs_->RequestDialogService(want, callerToken); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest RequestDialogService_001 part 1 end"); + auto ret = abilityMs_->RequestDialogService(want, callerToken); + EXPECT_EQ(ret, ERR_INVALID_CALLER); want.AddFlags(want.FLAG_ABILITY_CONTINUATION); - abilityMs_->RequestDialogService(want, callerToken); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest RequestDialogService_001 part 2 end"); + auto ret1 = abilityMs_->RequestDialogService(want, callerToken); + EXPECT_EQ(ret1, ERR_INVALID_CONTINUATION_FLAG); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest RequestDialogService_001 end"); } @@ -1097,12 +1125,12 @@ HWTEST_F(AbilityManagerServiceFourthTest, ReportDrawnCompleted_001, TestSize.Lev TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportDrawnCompleted_001 start"); sptr callerToken = nullptr; auto abilityMs_ = std::make_shared(); - abilityMs_->ReportDrawnCompleted(callerToken); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportDrawnCompleted_001 part 1 end"); + auto ret = abilityMs_->ReportDrawnCompleted(callerToken); + EXPECT_EQ(ret, INNER_ERR); callerToken = MockToken(AbilityType::PAGE); - abilityMs_->ReportDrawnCompleted(callerToken); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportDrawnCompleted_001 part 2 end"); + auto ret1 = abilityMs_->ReportDrawnCompleted(callerToken); + EXPECT_EQ(ret1, ERR_OK); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportDrawnCompleted_001 end"); } @@ -1117,7 +1145,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartUIAbilityBySCB_001, TestSize.Leve TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartUIAbilityBySCB_001 start"); bool isColdStart; auto abilityMs_ = std::make_shared(); - abilityMs_->StartUIAbilityBySCB(nullptr, isColdStart); + auto ret = abilityMs_->StartUIAbilityBySCB(nullptr, isColdStart); + EXPECT_EQ(ret, ERR_INVALID_VALUE); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest StartUIAbilityBySCB_001 end"); } @@ -1131,7 +1160,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, IsDmsAlive_001, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest IsDmsAlive_001 start"); auto abilityMs_ = std::make_shared(); - abilityMs_->IsDmsAlive(); + auto ret = abilityMs_->IsDmsAlive(); + EXPECT_EQ(ret, false); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest IsDmsAlive_001 end"); } @@ -1146,7 +1176,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, RecordAppExitReason_001, TestSize.Leve TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest RecordAppExitReason_001 start"); AAFwk::ExitReason exitReason; auto abilityMs_ = std::make_shared(); - abilityMs_->RecordAppExitReason(exitReason); + auto ret = abilityMs_->RecordAppExitReason(exitReason); + EXPECT_EQ(ret, ERR_NULL_OBJECT); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest RecordAppExitReason_001 end"); } @@ -1163,23 +1194,19 @@ HWTEST_F(AbilityManagerServiceFourthTest, OnAddSystemAbility_001, TestSize.Level std::string deviceId{"deviceId"}; auto abilityMs_ = std::make_shared(); abilityMs_->OnAddSystemAbility(systemAbilityId, deviceId); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest OnAddSystemAbility_001 part 1 end"); systemAbilityId = DISTRIBUTED_SCHED_SA_ID; abilityMs_->OnAddSystemAbility(systemAbilityId, deviceId); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest OnAddSystemAbility_001 part 2 end"); systemAbilityId = BUNDLE_MGR_SERVICE_SYS_ABILITY_ID; abilityMs_->OnAddSystemAbility(systemAbilityId, deviceId); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest OnAddSystemAbility_001 part 3 end"); systemAbilityId = MULTIMODAL_INPUT_SERVICE_ID; abilityMs_->OnAddSystemAbility(systemAbilityId, deviceId); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest OnAddSystemAbility_001 part 4 end"); systemAbilityId = WINDOW_MANAGER_SERVICE_ID; abilityMs_->OnAddSystemAbility(systemAbilityId, deviceId); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest OnAddSystemAbility_001 part 5 end"); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest OnAddSystemAbility_001 end"); } @@ -1196,19 +1223,16 @@ HWTEST_F(AbilityManagerServiceFourthTest, OnRemoveSystemAbility_001, TestSize.Le std::string deviceId{"deviceId"}; auto abilityMs_ = std::make_shared(); abilityMs_->OnRemoveSystemAbility(systemAbilityId, deviceId); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest OnRemoveSystemAbility_001 part 1 end"); systemAbilityId = DISTRIBUTED_SCHED_SA_ID; abilityMs_->OnRemoveSystemAbility(systemAbilityId, deviceId); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest OnRemoveSystemAbility_001 part 2 end"); systemAbilityId = BUNDLE_MGR_SERVICE_SYS_ABILITY_ID; abilityMs_->OnRemoveSystemAbility(systemAbilityId, deviceId); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest OnRemoveSystemAbility_001 part 3 end"); systemAbilityId = WINDOW_MANAGER_SERVICE_ID; abilityMs_->OnRemoveSystemAbility(systemAbilityId, deviceId); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest OnRemoveSystemAbility_001 part 4 end"); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest OnRemoveSystemAbility_001 end"); } @@ -1223,6 +1247,7 @@ HWTEST_F(AbilityManagerServiceFourthTest, SubscribeBackgroundTask_001, TestSize. TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest SubscribeBackgroundTask_001 start"); auto abilityMs_ = std::make_shared(); abilityMs_->SubscribeBackgroundTask(); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest SubscribeBackgroundTask_001 end"); } @@ -1236,12 +1261,9 @@ HWTEST_F(AbilityManagerServiceFourthTest, UnSubscribeBackgroundTask_001, TestSiz { TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest UnSubscribeBackgroundTask_001 start"); auto abilityMs_ = std::make_shared(); - abilityMs_->UnSubscribeBackgroundTask(); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest UnSubscribeBackgroundTask_001 part 1 end"); - abilityMs_->SubscribeBackgroundTask(); abilityMs_->UnSubscribeBackgroundTask(); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest UnSubscribeBackgroundTask_002 part 1 end"); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest UnSubscribeBackgroundTask_001 end"); } @@ -1256,10 +1278,7 @@ HWTEST_F(AbilityManagerServiceFourthTest, SubscribeBundleEventCallback_001, Test TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest SubscribeBundleEventCallback_001 start"); auto abilityMs_ = std::make_shared(); abilityMs_->SubscribeBundleEventCallback(); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest SubscribeBundleEventCallback_001 part 1 end"); - - abilityMs_->SubscribeBundleEventCallback(); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest SubscribeBundleEventCallback_001 part 2 end"); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest SubscribeBundleEventCallback_001 end"); } @@ -1275,10 +1294,7 @@ HWTEST_F(AbilityManagerServiceFourthTest, UnsubscribeBundleEventCallback_001, Te auto abilityMs_ = std::make_shared(); abilityMs_->SubscribeBundleEventCallback(); abilityMs_->UnsubscribeBundleEventCallback(); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest UnsubscribeBundleEventCallback_001 part 1 end"); - - abilityMs_->UnsubscribeBundleEventCallback(); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest UnsubscribeBundleEventCallback_001 part 2 end"); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest UnsubscribeBundleEventCallback_001 end"); } @@ -1296,21 +1312,18 @@ HWTEST_F(AbilityManagerServiceFourthTest, ReportEventToRSS_001, TestSize.Level1) auto callerToken = MockToken(AbilityType::PAGE); auto abilityMs_ = std::make_shared(); abilityMs_->ReportEventToRSS(abilityInfo, callerToken); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportEventToRSS_001 part 1 end"); abilityInfo.type = AppExecFwk::AbilityType::EXTENSION; abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SERVICE; abilityMs_->ReportEventToRSS(abilityInfo, callerToken); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportEventToRSS_001 part 2 end"); abilityInfo.type = AppExecFwk::AbilityType::EXTENSION; abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SYSDIALOG_ATOMICSERVICEPANEL; abilityMs_->ReportEventToRSS(abilityInfo, callerToken); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportEventToRSS_001 part 3 end"); abilityInfo.type = AppExecFwk::AbilityType::UNKNOWN; abilityMs_->ReportEventToRSS(abilityInfo, callerToken); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportEventToRSS_001 part 4 end"); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ReportEventToRSS_001 end"); } @@ -1325,7 +1338,8 @@ HWTEST_F(AbilityManagerServiceFourthTest, RequestModalUIExtension_001, TestSize. TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest RequestModalUIExtension_001 start"); Want want; auto abilityMs_ = std::make_shared(); - abilityMs_->RequestModalUIExtension(want); + auto ret = abilityMs_->RequestModalUIExtension(want); + EXPECT_EQ(ret, INNER_ERR); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest RequestModalUIExtension_001 end"); } @@ -1342,6 +1356,7 @@ HWTEST_F(AbilityManagerServiceFourthTest, ChangeAbilityVisibility_001, TestSize. bool isShow{true}; auto abilityMs_ = std::make_shared(); abilityMs_->ChangeAbilityVisibility(callerToken, isShow); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ChangeAbilityVisibility_001 end"); } @@ -1357,6 +1372,7 @@ HWTEST_F(AbilityManagerServiceFourthTest, ChangeUIAbilityVisibilityBySCB_001, Te bool isShow{true}; auto abilityMs_ = std::make_shared(); abilityMs_->ChangeUIAbilityVisibilityBySCB(MockSessionInfo(0), isShow); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ChangeUIAbilityVisibilityBySCB_001 end"); } @@ -1369,12 +1385,12 @@ HWTEST_F(AbilityManagerServiceFourthTest, ChangeUIAbilityVisibilityBySCB_001, Te HWTEST_F(AbilityManagerServiceFourthTest, SetAbilityRequestSessionInfo_001, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest SetAbilityRequestSessionInfo_001 start"); - AbilityRequest abilityRequest; AppExecFwk::ExtensionAbilityType extensionType{AppExecFwk::ExtensionAbilityType::VPN}; auto abilityMs_ = std::make_shared(); abilityMs_->SetAbilityRequestSessionInfo(abilityRequest, extensionType); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest SetAbilityRequestSessionInfo_001 end"); } @@ -1387,7 +1403,6 @@ HWTEST_F(AbilityManagerServiceFourthTest, SetAbilityRequestSessionInfo_001, Test HWTEST_F(AbilityManagerServiceFourthTest, SetAbilityRequestSessionInfo_002, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest SetAbilityRequestSessionInfo_002 start"); - AbilityRequest abilityRequest; abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::UI_SERVICE; abilityRequest.callerToken = MockToken(AbilityType::PAGE); @@ -1395,6 +1410,7 @@ HWTEST_F(AbilityManagerServiceFourthTest, SetAbilityRequestSessionInfo_002, Test auto abilityMs_ = std::make_shared(); abilityMs_->SetAbilityRequestSessionInfo(abilityRequest, extensionType); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest SetAbilityRequestSessionInfo_002 end"); } @@ -1407,7 +1423,6 @@ HWTEST_F(AbilityManagerServiceFourthTest, SetAbilityRequestSessionInfo_002, Test HWTEST_F(AbilityManagerServiceFourthTest, SetAbilityRequestSessionInfo_003, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest SetAbilityRequestSessionInfo_003 start"); - AbilityRequest abilityRequest; abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::VPN; abilityRequest.callerToken = MockToken(AbilityType::PAGE); @@ -1416,6 +1431,7 @@ HWTEST_F(AbilityManagerServiceFourthTest, SetAbilityRequestSessionInfo_003, Test auto abilityMs_ = std::make_shared(); abilityMs_->SetAbilityRequestSessionInfo(abilityRequest, extensionType); + EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest SetAbilityRequestSessionInfo_003 end"); } diff --git a/test/unittest/application_context_test/application_context_test.cpp b/test/unittest/application_context_test/application_context_test.cpp index 7e2e5004f8..b476472c50 100644 --- a/test/unittest/application_context_test/application_context_test.cpp +++ b/test/unittest/application_context_test/application_context_test.cpp @@ -1327,6 +1327,7 @@ HWTEST_F(ApplicationContextTest, DispatchOnAbilityWillContinue_0100, TestSize.Le GTEST_LOG_(INFO) << "DispatchOnAbilityWillContinue_0100 start"; std::shared_ptr ability = nullptr; context_->DispatchOnAbilityWillContinue(ability); + EXPECT_TRUE(context_ != nullptr); GTEST_LOG_(INFO) << "DispatchOnAbilityWillContinue_0100 end"; } @@ -1341,6 +1342,7 @@ HWTEST_F(ApplicationContextTest, DispatchOnWindowStageWillRestore_0100, TestSize std::shared_ptr ability = nullptr; std::shared_ptr winstage = nullptr; context_->DispatchOnWindowStageWillRestore(ability, winstage); + EXPECT_TRUE(context_ != nullptr); GTEST_LOG_(INFO) << "DispatchOnWindowStageWillRestore_0100 end"; } @@ -1355,6 +1357,7 @@ HWTEST_F(ApplicationContextTest, DispatchOnWindowStageRestore_0100, TestSize.Lev std::shared_ptr ability = nullptr; std::shared_ptr winstage = nullptr; context_->DispatchOnWindowStageRestore(ability, winstage); + EXPECT_TRUE(context_ != nullptr); GTEST_LOG_(INFO) << "DispatchOnWindowStageRestore_0100 end"; } @@ -1368,6 +1371,7 @@ HWTEST_F(ApplicationContextTest, DispatchOnAbilityWillSaveState_0100, TestSize.L GTEST_LOG_(INFO) << "DispatchOnAbilityWillSaveState_0100 start"; std::shared_ptr ability = nullptr; context_->DispatchOnAbilityWillSaveState(ability); + EXPECT_TRUE(context_ != nullptr); GTEST_LOG_(INFO) << "DispatchOnAbilityWillSaveState_0100 end"; } @@ -1381,6 +1385,7 @@ HWTEST_F(ApplicationContextTest, DispatchOnAbilitySaveState_0100, TestSize.Level GTEST_LOG_(INFO) << "DispatchOnAbilitySaveState_0100 start"; std::shared_ptr ability = nullptr; context_->DispatchOnAbilitySaveState(ability); + EXPECT_TRUE(context_ != nullptr); GTEST_LOG_(INFO) << "DispatchOnAbilitySaveState_0100 end"; } @@ -1394,6 +1399,7 @@ HWTEST_F(ApplicationContextTest, DispatchOnWillNewWant_0100, TestSize.Level1) GTEST_LOG_(INFO) << "DispatchOnWillNewWant_0100 start"; std::shared_ptr ability = nullptr; context_->DispatchOnWillNewWant(ability); + EXPECT_TRUE(context_ != nullptr); GTEST_LOG_(INFO) << "DispatchOnWillNewWant_0100 end"; } @@ -1407,6 +1413,7 @@ HWTEST_F(ApplicationContextTest, DispatchOnNewWant_0100, TestSize.Level1) GTEST_LOG_(INFO) << "DispatchOnNewWant_0100 start"; std::shared_ptr ability = nullptr; context_->DispatchOnNewWant(ability); + EXPECT_TRUE(context_ != nullptr); GTEST_LOG_(INFO) << "DispatchOnNewWant_0100 end"; } @@ -1420,6 +1427,7 @@ HWTEST_F(ApplicationContextTest, DispatchOnAbilityWillCreate_0100, TestSize.Leve GTEST_LOG_(INFO) << "DispatchOnAbilityWillCreate_0100 start"; std::shared_ptr ability = nullptr; context_->DispatchOnAbilityWillCreate(ability); + EXPECT_TRUE(context_ != nullptr); GTEST_LOG_(INFO) << "DispatchOnAbilityWillCreate_0100 end"; } @@ -1434,6 +1442,7 @@ HWTEST_F(ApplicationContextTest, DispatchOnWindowStageWillCreate_0100, TestSize. std::shared_ptr ability = nullptr; std::shared_ptr winstage = nullptr; context_->DispatchOnWindowStageWillCreate(ability, winstage); + EXPECT_TRUE(context_ != nullptr); GTEST_LOG_(INFO) << "DispatchOnWindowStageWillCreate_0100 end"; } @@ -1448,6 +1457,7 @@ HWTEST_F(ApplicationContextTest, DispatchOnWindowStageWillDestroy_0100, TestSize std::shared_ptr ability = nullptr; std::shared_ptr winstage = nullptr; context_->DispatchOnWindowStageWillDestroy(ability, winstage); + EXPECT_TRUE(context_ != nullptr); GTEST_LOG_(INFO) << "DispatchOnWindowStageWillDestroy_0100 end"; } @@ -1461,6 +1471,7 @@ HWTEST_F(ApplicationContextTest, DispatchOnAbilityWillDestroy_0100, TestSize.Lev GTEST_LOG_(INFO) << "DispatchOnAbilityWillDestroy_0100 start"; std::shared_ptr ability = nullptr; context_->DispatchOnAbilityWillDestroy(ability); + EXPECT_TRUE(context_ != nullptr); GTEST_LOG_(INFO) << "DispatchOnAbilityWillDestroy_0100 end"; } @@ -1474,6 +1485,7 @@ HWTEST_F(ApplicationContextTest, DispatchOnAbilityWillForeground_0100, TestSize. GTEST_LOG_(INFO) << "DispatchOnAbilityWillForeground_0100 start"; std::shared_ptr ability = nullptr; context_->DispatchOnAbilityWillForeground(ability); + EXPECT_TRUE(context_ != nullptr); GTEST_LOG_(INFO) << "DispatchOnAbilityWillForeground_0100 end"; } @@ -1487,6 +1499,7 @@ HWTEST_F(ApplicationContextTest, DispatchOnAbilityWillBackground_0100, TestSize. GTEST_LOG_(INFO) << "DispatchOnAbilityWillBackground_0100 start"; std::shared_ptr ability = nullptr; context_->DispatchOnAbilityWillBackground(ability); + EXPECT_TRUE(context_ != nullptr); GTEST_LOG_(INFO) << "DispatchOnAbilityWillBackground_0100 end"; } @@ -1498,6 +1511,7 @@ HWTEST_F(ApplicationContextTest, DispatchOnAbilityWillBackground_0100, TestSize. HWTEST_F(ApplicationContextTest, SetFont_0100, TestSize.Level1) { context_->SetFont("awk"); + EXPECT_TRUE(context_ != nullptr); } /** @@ -1508,6 +1522,7 @@ HWTEST_F(ApplicationContextTest, SetFont_0100, TestSize.Level1) HWTEST_F(ApplicationContextTest, SetMcc_0100, TestSize.Level1) { context_->SetMcc("mcc"); + EXPECT_TRUE(context_ != nullptr); } /** @@ -1518,6 +1533,7 @@ HWTEST_F(ApplicationContextTest, SetMcc_0100, TestSize.Level1) HWTEST_F(ApplicationContextTest, SetMnc_0100, TestSize.Level1) { context_->SetMnc("mnc"); + EXPECT_TRUE(context_ != nullptr); } } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/cj_ability_delegator_test/cj_ability_delegator_test.cpp b/test/unittest/cj_ability_delegator_test/cj_ability_delegator_test.cpp index 9a215b1980..2cf6fe6ae3 100644 --- a/test/unittest/cj_ability_delegator_test/cj_ability_delegator_test.cpp +++ b/test/unittest/cj_ability_delegator_test/cj_ability_delegator_test.cpp @@ -192,6 +192,7 @@ HWTEST_F(CjAbilityDelegatorTest, CjAbilityDelegatorTestDump_001, TestSize.Level1 auto shellResult = std::make_shared(); CJShellCmdResult shellCmdResult(shellResult); shellCmdResult.Dump(); + EXPECT_TRUE(shellResult != nullptr); } /** @@ -202,7 +203,8 @@ HWTEST_F(CjAbilityDelegatorTest, CjAbilityDelegatorTestDump_001, TestSize.Level1 HWTEST_F(CjAbilityDelegatorTest, CJAbilityDelegatorTestFFIAbilityDelegatorRegistryGetAbilityDelegator_001, TestSize.Level1) { - FFIAbilityDelegatorRegistryGetAbilityDelegator(); + auto result = FFIAbilityDelegatorRegistryGetAbilityDelegator(); + EXPECT_NE(result, ERR_OK); } /** @@ -233,7 +235,8 @@ HWTEST_F(CjAbilityDelegatorTest, CJAbilityDelegatorTestFFIAbilityDelegatorExecut auto delegator = OHOS::AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); auto cjDelegator = FFI::FFIData::Create(delegator); int64_t id = cjDelegator->GetID(); - FFIAbilityDelegatorExecuteShellCommand(id, cmd, timeoutSec); + auto result = FFIAbilityDelegatorExecuteShellCommand(id, cmd, timeoutSec); + EXPECT_TRUE(cjDelegator != nullptr); } /** @@ -249,7 +252,8 @@ HWTEST_F(CjAbilityDelegatorTest, CJAbilityDelegatorTestFFIGetExitCode_001, TestS auto shellResult = std::make_shared(); auto cJShellCmdResult = FFI::FFIData::Create(shellResult); int64_t id = cJShellCmdResult->GetID(); - FFIGetExitCode(id); + auto result = FFIGetExitCode(id); + EXPECT_TRUE(cJShellCmdResult != nullptr); } /** @@ -264,7 +268,8 @@ HWTEST_F(CjAbilityDelegatorTest, CJAbilityDelegatorTestFFIGetStdResult_001, Test auto shellResult = std::make_shared(); auto cJShellCmdResult = FFI::FFIData::Create(shellResult); int64_t id = cJShellCmdResult->GetID(); - FFIGetStdResult(id); + auto result = FFIGetStdResult(id); + EXPECT_TRUE(result == nullptr); } /** @@ -279,7 +284,8 @@ HWTEST_F(CjAbilityDelegatorTest, CJAbilityDelegatorTestFFIDump_001, TestSize.Lev auto shellResult = std::make_shared(); auto cJShellCmdResult = FFI::FFIData::Create(shellResult); int64_t id = cJShellCmdResult->GetID(); - FFIDump(id); + auto result = FFIDump(id); + EXPECT_TRUE(result != nullptr); } /** @@ -292,7 +298,8 @@ HWTEST_F(CjAbilityDelegatorTest, CJAbilityDelegatorTestFFIAbilityDelegatorApplic auto delegator = OHOS::AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); auto cjDelegator = FFI::FFIData::Create(delegator); int64_t id = cjDelegator->GetID(); - FFIAbilityDelegatorApplicationContext(id); + auto result = FFIAbilityDelegatorApplicationContext(id); + EXPECT_TRUE(cjDelegator != nullptr); } } // namespace AbilityRuntime diff --git a/test/unittest/cj_ability_ffi_mock_test/cj_ability_ffi_mock_test.cpp b/test/unittest/cj_ability_ffi_mock_test/cj_ability_ffi_mock_test.cpp index 880992dee4..a476fae59d 100644 --- a/test/unittest/cj_ability_ffi_mock_test/cj_ability_ffi_mock_test.cpp +++ b/test/unittest/cj_ability_ffi_mock_test/cj_ability_ffi_mock_test.cpp @@ -111,54 +111,4 @@ HWTEST_F(CjAbilityFfiMockTest, CjAbilityFfiMockTestGetBroker_0100, TestSize.Leve EXPECT_EQ(1, broker->requestPermissionsFromUser); EXPECT_EQ(1, broker->setMissionLabel); EXPECT_EQ(1, broker->setMissionIcon); -} - -/** - * @tc.name: CjAbilityFfiMockTestRegisterCJAbilityStageFuncs_0100 - * @tc.desc: CjAbilityFfiMockTest test for RegisterCJAbilityStageFuncs. - * @tc.type: FUNC - */ -HWTEST_F(CjAbilityFfiMockTest, CjAbilityFfiMockTestRegisterCJAbilityStageFuncs_0100, TestSize.Level1) -{ - RegisterCJAbilityStageFuncs(); // 实际执行函数 -} - -/** - * @tc.name: CjAbilityFfiMockTestRegisterCJAbilityConnectCallbackFuncs_0100 - * @tc.desc: CjAbilityFfiMockTest test for RegisterCJAbilityConnectCallbackFuncs. - * @tc.type: FUNC - */ -HWTEST_F(CjAbilityFfiMockTest, CjAbilityFfiMockTestRegisterCJAbilityConnectCallbackFuncs_0100, TestSize.Level1) -{ - RegisterCJAbilityConnectCallbackFuncs(); -} - -/** - * @tc.name: CjAbilityFfiMockTestRegisterCJAbilityCallbacks_0100 - * @tc.desc: CjAbilityFfiMockTest test for RegisterCJAbilityCallbacks. - * @tc.type: FUNC - */ -HWTEST_F(CjAbilityFfiMockTest, CjAbilityFfiMockTestRegisterCJAbilityCallbacks_0100, TestSize.Level1) -{ - RegisterCJAbilityCallbacks(); -} - -/** - * @tc.name: CjAbilityFfiMockTestRegisterCJAbilityFuncs_0100 - * @tc.desc: CjAbilityFfiMockTest test for RegisterCJAbilityFuncs. - * @tc.type: FUNC - */ -HWTEST_F(CjAbilityFfiMockTest, CjAbilityFfiMockTestRegisterCJAbilityFuncs_0100, TestSize.Level1) -{ - RegisterCJAbilityFuncs(); -} - -/** - * @tc.name: CjAbilityFfiMockTestRequestDialogService_0100 - * @tc.desc: CjAbilityFfiMockTest test for FFIAbilityContextRequestDialogService. - * @tc.type: FUNC - */ -HWTEST_F(CjAbilityFfiMockTest, CjAbilityFfiMockTestRequestDialogService_0100, TestSize.Level1) -{ - FFIAbilityContextRequestDialogService(); } \ No newline at end of file diff --git a/test/unittest/cj_delegator_ffi_mock_test/BUILD.gn b/test/unittest/cj_delegator_ffi_mock_test/BUILD.gn deleted file mode 100644 index 5fe3c5465b..0000000000 --- a/test/unittest/cj_delegator_ffi_mock_test/BUILD.gn +++ /dev/null @@ -1,90 +0,0 @@ -# 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. - -import("//build/ohos.gni") -import("//build/test.gni") -import("//foundation/ability/ability_runtime/ability_runtime.gni") - -ohos_unittest("cj_delegator_ffi_mock_test") { - module_out_path = "ability_runtime/cj_delegator_ffi_mock_test" - include_dirs = [ - "${ability_runtime_path}/interfaces/kits/native/appkit/ability_delegator", - "${ability_runtime_path}/interfaces/kits/native/appkit/app", - "${bundlefwk_path}/interfaces/inner_api/appexecfwk_base/include", - "${ability_runtime_path}/interfaces/inner_api/ability_manager/include", - "${common_event_service_path}/interfaces/inner_api", - "${ability_runtime_path}/interfaces/inner_api/app_manager/include/appmgr", - "${ability_base_path}/interfaces/kits/native/session_info/include", - "${arkui_path}/ace_engine", - "${ability_runtime_path}/interfaces/kits/native/ability/native", - "${ability_runtime_path}/frameworks/cj/ffi", - "${ability_runtime_path}/frameworks/cj/mock", - "${ace_engine_path}/frameworks", - "${ability_runtime_path}/cj_environment/interfaces/inner_api", - ] - - sources = [ "cj_delegator_ffi_mock_test.cpp" ] - - configs = [ "${c_utils_base_path}:utils_config" ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", - "${ability_runtime_innerkits_path}/ability_manager:mission_info", - "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", - "${ability_runtime_native_path}/ability:ability_context_native", - "${ability_runtime_native_path}/ability/native:ability_thread", - "${ability_runtime_native_path}/ability/native:abilitykit_native", - "${ability_runtime_native_path}/ability/native:uiabilitykit_native", - "${ability_runtime_native_path}/appkit:app_context", - "${ability_runtime_native_path}/appkit:appkit_manager_helper", - "${ability_runtime_native_path}/appkit:appkit_native", - "${ability_runtime_path}/utils/global/freeze:freeze_util", - "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "${global_path}/resource_management/frameworks/resmgr:global_resmgr", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ - "ability_base:base", - "ability_base:configuration", - "ability_base:session_info", - "ability_base:want", - "ability_runtime:ability_context_native", - "ability_runtime:runtime", - "ability_runtime:wantagent_innerkits", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", - "ffrt:libffrt", - "hilog:libhilog", - "hitrace:hitrace_meter", - "init:libbegetutil", - "ipc:ipc_core", - "napi:ace_napi", - "napi:cj_bind_native", - "window_manager:libwsutils", - "window_manager:scene_session", - ] -} - -group("unittest") { - testonly = true - deps = [ ":cj_delegator_ffi_mock_test" ] -} diff --git a/test/unittest/cj_delegator_ffi_mock_test/cj_delegator_ffi_mock_test.cpp b/test/unittest/cj_delegator_ffi_mock_test/cj_delegator_ffi_mock_test.cpp deleted file mode 100644 index 305cd75751..0000000000 --- a/test/unittest/cj_delegator_ffi_mock_test/cj_delegator_ffi_mock_test.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 "foundation/ability/ability_runtime/frameworks/cj/mock/cj_delegator_ffi.cpp" - -using namespace testing; -using namespace testing::ext; - -class CjDelegatorFfiMockTest : public testing::Test { -public: - CjDelegatorFfiMockTest() - {} - ~CjDelegatorFfiMockTest() - {} - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; -}; - -void CjDelegatorFfiMockTest::SetUpTestCase() -{} - -void CjDelegatorFfiMockTest::TearDownTestCase() -{} - -void CjDelegatorFfiMockTest::SetUp() -{} - -void CjDelegatorFfiMockTest::TearDown() -{} - -/** - * @tc.name: CjDelegatorFfiMockTestRegisterCJTestRunnerFuncs_0100 - * @tc.desc: CjDelegatorFfiMockTest test for RegisterCJTestRunnerFuncs. - * @tc.type: FUNC - */ -HWTEST_F(CjDelegatorFfiMockTest, CjDelegatorFfiMockTestRegisterCJTestRunnerFuncs_0100, TestSize.Level1) -{ - RegisterCJTestRunnerFuncs(); -} \ No newline at end of file diff --git a/test/unittest/cj_element_name_ffi_test/cj_element_name_ffi_test.cpp b/test/unittest/cj_element_name_ffi_test/cj_element_name_ffi_test.cpp index dd99ba9ae9..d4b25bb376 100644 --- a/test/unittest/cj_element_name_ffi_test/cj_element_name_ffi_test.cpp +++ b/test/unittest/cj_element_name_ffi_test/cj_element_name_ffi_test.cpp @@ -100,6 +100,12 @@ HWTEST_F(CjElementNameFfiTest, CJElementNameFFITestFFICJElementNameDelete_0100, ElementNameHandle elementNameHandle = FFICJElementNameCreateWithContent(deviceId, bundleName, abilityName, moduleName); + auto actualElementName = reinterpret_cast(elementNameHandle); + EXPECT_EQ(actualElementName->GetDeviceID(), deviceId); + EXPECT_EQ(actualElementName->GetBundleName(), bundleName); + EXPECT_EQ(actualElementName->GetAbilityName(), abilityName); + EXPECT_EQ(actualElementName->GetModuleName(), moduleName); + FFICJElementNameDelete(elementNameHandle); } @@ -162,4 +168,8 @@ HWTEST_F(CjElementNameFfiTest, CJElementNameFFITestFFICJElementNameParamsDelete_ elementNameParams->moduleName = CreateCStringFromString(moduleName); FFICJElementNameParamsDelete(elementNameParams); + EXPECT_TRUE(elementNameParams->deviceId != nullptr); + EXPECT_TRUE(elementNameParams->bundleName != nullptr); + EXPECT_TRUE(elementNameParams->abilityName != nullptr); + EXPECT_TRUE(elementNameParams->moduleName != nullptr); } \ No newline at end of file diff --git a/test/unittest/cj_environment_test/BUILD.gn b/test/unittest/cj_environment_test/BUILD.gn index 99ecd9626e..93efa4da4b 100644 --- a/test/unittest/cj_environment_test/BUILD.gn +++ b/test/unittest/cj_environment_test/BUILD.gn @@ -16,8 +16,8 @@ import("//build/test.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") import("//foundation/ability/ability_runtime/cj_environment/cj_environment.gni") -ohos_unittest("cj_environment_test") { - module_out_path = "ability_runtime/cj_environment_test" +ohos_unittest("cj_environment_other_test") { + module_out_path = "ability_runtime/cj_environment_other_test" include_dirs = [ "${ability_runtime_test_path}/mock/common/include", "${resource_management_path}/frameworks/resmgr/include", @@ -91,5 +91,5 @@ ohos_unittest("cj_environment_test") { group("unittest") { testonly = true - deps = [ ":cj_environment_test" ] + deps = [ ":cj_environment_other_test" ] } diff --git a/test/unittest/cj_environment_test/cj_environment_test.cpp b/test/unittest/cj_environment_test/cj_environment_test.cpp index 98026e302b..e9d9908b0b 100644 --- a/test/unittest/cj_environment_test/cj_environment_test.cpp +++ b/test/unittest/cj_environment_test/cj_environment_test.cpp @@ -69,7 +69,8 @@ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestPostTask_001, TestSize.Level0) { CJEnvironment::GetInstance()->PostTask(nullptr); void (*func)() = TestFunc; - CJEnvironment::GetInstance()->PostTask(func); + auto ret = CJEnvironment::GetInstance()->PostTask(func); + EXPECT_EQ(ret, true); } /** @@ -79,7 +80,8 @@ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestPostTask_001, TestSize.Level0) */ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestHasHigherPriorityTask_001, TestSize.Level0) { - CJEnvironment::GetInstance()->HasHigherPriorityTask(); + auto ret = CJEnvironment::GetInstance()->HasHigherPriorityTask(); + EXPECT_EQ(ret, false); } /** @@ -90,6 +92,7 @@ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestHasHigherPriorityTask_001, TestSize HWTEST_F(CjEnvironmentTest, CjEnvironmentTestInitCJChipSDKNS_001, TestSize.Level0) { CJEnvironment::GetInstance()->InitCJChipSDKNS("path/to/hap"); + EXPECT_NE(CJEnvironment::GetInstance()->cjAppNSName, nullptr); } /** @@ -100,6 +103,7 @@ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestInitCJChipSDKNS_001, TestSize.Level HWTEST_F(CjEnvironmentTest, CjEnvironmentTestInitCJAppNS_001, TestSize.Level0) { CJEnvironment::GetInstance()->InitCJAppNS("path/to/hap"); + EXPECT_NE(CJEnvironment::GetInstance()->cjAppNSName, nullptr); } /** @@ -110,6 +114,7 @@ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestInitCJAppNS_001, TestSize.Level0) HWTEST_F(CjEnvironmentTest, CjEnvironmentTestInitCJSDKNS_001, TestSize.Level0) { CJEnvironment::GetInstance()->InitCJSDKNS("path/to/hap"); + EXPECT_NE(CJEnvironment::GetInstance()->cjAppNSName, nullptr); } /** @@ -120,6 +125,7 @@ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestInitCJSDKNS_001, TestSize.Level0) HWTEST_F(CjEnvironmentTest, CjEnvironmentTestInitCJSysNS_001, TestSize.Level0) { CJEnvironment::GetInstance()->InitCJSysNS("path/to/hap"); + EXPECT_NE(CJEnvironment::GetInstance()->cjAppNSName, nullptr); } /** @@ -129,8 +135,8 @@ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestInitCJSysNS_001, TestSize.Level0) */ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestStartRuntime_001, TestSize.Level0) { - CJEnvironment::GetInstance()->StartRuntime(); - CJEnvironment::GetInstance()->StartRuntime(); + auto ret = CJEnvironment::GetInstance()->StartRuntime(); + EXPECT_EQ(ret, false); } /** @@ -141,7 +147,7 @@ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestStartRuntime_001, TestSize.Level0) HWTEST_F(CjEnvironmentTest, CjEnvironmentTestStopRuntime_001, TestSize.Level0) { CJEnvironment::GetInstance()->StopRuntime(); - CJEnvironment::GetInstance()->StopRuntime(); + EXPECT_NE(CJEnvironment::GetInstance(), nullptr); } /** @@ -152,6 +158,7 @@ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestStopRuntime_001, TestSize.Level0) HWTEST_F(CjEnvironmentTest, CjEnvironmentTestStopUIScheduler_001, TestSize.Level0) { CJEnvironment::GetInstance()->StopUIScheduler(); + EXPECT_NE(CJEnvironment::GetInstance(), nullptr); } /** @@ -161,7 +168,8 @@ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestStopUIScheduler_001, TestSize.Level */ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestLoadCJLibrary_001, TestSize.Level0) { - CJEnvironment::GetInstance()->LoadCJLibrary("dlName"); + auto ret = CJEnvironment::GetInstance()->LoadCJLibrary("dlName"); + EXPECT_EQ(ret, nullptr); } /** @@ -174,6 +182,7 @@ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestLoadCJLibrary_002, TestSize.Level0) CJEnvironment::GetInstance()->LoadCJLibrary(CJEnvironment::GetInstance()->LibraryKind::APP, "dlName"); CJEnvironment::GetInstance()->LoadCJLibrary(CJEnvironment::GetInstance()->LibraryKind::SYSTEM, "dlName"); CJEnvironment::GetInstance()->LoadCJLibrary(CJEnvironment::GetInstance()->LibraryKind::SDK, "dlName"); + EXPECT_NE(CJEnvironment::GetInstance(), nullptr); } /** @@ -183,7 +192,8 @@ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestLoadCJLibrary_002, TestSize.Level0) */ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestStartDebugger_001, TestSize.Level0) { - CJEnvironment::GetInstance()->StartDebugger(); + auto ret = CJEnvironment::GetInstance()->StartDebugger(); + EXPECT_EQ(ret, false); } /** @@ -193,5 +203,6 @@ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestStartDebugger_001, TestSize.Level0) */ HWTEST_F(CjEnvironmentTest, CjEnvironmentTestGetSymbol_001, TestSize.Level0) { - CJEnvironment::GetInstance()->GetSymbol(nullptr, "dlName"); + auto ret = CJEnvironment::GetInstance()->GetSymbol(nullptr, "dlName"); + EXPECT_EQ(ret, nullptr); } diff --git a/test/unittest/cj_test_runner_object_test/cj_test_runner_object_test.cpp b/test/unittest/cj_test_runner_object_test/cj_test_runner_object_test.cpp index 03c907adb4..d8164c7fda 100644 --- a/test/unittest/cj_test_runner_object_test/cj_test_runner_object_test.cpp +++ b/test/unittest/cj_test_runner_object_test/cj_test_runner_object_test.cpp @@ -119,6 +119,7 @@ HWTEST_F(CjTestRunnerObjectTest, CjTestRunnerObjectTestOnRun_Success_001, TestSi auto proxy = CJTestRunnerObject::LoadModule("test_ability"); proxy->OnRun(); proxy.reset(); + EXPECT_EQ(nullptr, proxy); } /** @@ -130,6 +131,7 @@ HWTEST_F(CjTestRunnerObjectTest, CjTestRunnerObjectTestOnRun_Failed_NoRegistrati { auto proxy = CJTestRunnerObject::LoadModule("test_ability"); proxy->OnRun(); + EXPECT_NE(nullptr, proxy); } /** @@ -142,6 +144,7 @@ HWTEST_F(CjTestRunnerObjectTest, CjTestRunnerObjectTestOnPrepare_Success_001, Te RegisterCJTestRunnerFuncs(RegisterCangjieFuncs); auto proxy = CJTestRunnerObject::LoadModule("test_ability"); proxy->OnPrepare(); + EXPECT_NE(nullptr, proxy); } /** @@ -153,6 +156,7 @@ HWTEST_F(CjTestRunnerObjectTest, CjTestRunnerObjectTestOnPrepare_Failed_NoRegist { auto proxy = CJTestRunnerObject::LoadModule("test_ability"); proxy->OnPrepare(); + EXPECT_NE(nullptr, proxy); } /** @@ -165,6 +169,7 @@ HWTEST_F(CjTestRunnerObjectTest, CjTestRunnerObjectTestDestructor_Success_001, T RegisterCJTestRunnerFuncs(RegisterCangjieFuncs); auto proxy = CJTestRunnerObject::LoadModule("test_ability"); proxy.reset(); + EXPECT_EQ(nullptr, proxy); } } // namespace RunnerRuntime } // namespace OHOS diff --git a/test/unittest/cj_test_runner_test/cj_test_runner_test.cpp b/test/unittest/cj_test_runner_test/cj_test_runner_test.cpp index bf66f6df73..85a543e375 100644 --- a/test/unittest/cj_test_runner_test/cj_test_runner_test.cpp +++ b/test/unittest/cj_test_runner_test/cj_test_runner_test.cpp @@ -132,4 +132,5 @@ HWTEST_F(CjTestRunnerTest, CjTestRunnerTestCreate_Failed_RuntimeNull_001, TestSi runtime, abilityArgs, true); + EXPECT_TRUE(runtime == nullptr); } diff --git a/test/unittest/cj_want_ffi_test/cj_want_ffi_test.cpp b/test/unittest/cj_want_ffi_test/cj_want_ffi_test.cpp index 2184cf85e0..af53049c79 100644 --- a/test/unittest/cj_want_ffi_test/cj_want_ffi_test.cpp +++ b/test/unittest/cj_want_ffi_test/cj_want_ffi_test.cpp @@ -118,6 +118,7 @@ HWTEST_F(CjWantFfiTest, CjWantFfiTestFFICJWantDelete_0100, TestSize.Level1) strcpy_s(params.parameters, 11, "moduleName"); WantHandle want = FFICJWantCreateWithWantInfo(params); FFICJWantDelete(want); + EXPECT_NE(want, nullptr); } /** @@ -188,6 +189,7 @@ HWTEST_F(CjWantFfiTest, CjWantFfiTestFFICJWantAddEntity_0100, TestSize.Level1) const char* entity = "test_entity"; FFICJWantAddEntity(want, entity); + EXPECT_NE(want, nullptr); } /** @@ -199,4 +201,5 @@ HWTEST_F(CjWantFfiTest, CjWantFfiTestFFICJWantParseUri_0100, TestSize.Level1) { const char* uri = "test_uri"; WantHandle want = FFICJWantParseUri(uri); + EXPECT_EQ(want, nullptr); } \ No newline at end of file diff --git a/test/unittest/dynamic_loader_ohos_test/dynamic_loader_ohos_test.cpp b/test/unittest/dynamic_loader_ohos_test/dynamic_loader_ohos_test.cpp index 9804833224..a3143d22ee 100644 --- a/test/unittest/dynamic_loader_ohos_test/dynamic_loader_ohos_test.cpp +++ b/test/unittest/dynamic_loader_ohos_test/dynamic_loader_ohos_test.cpp @@ -101,6 +101,10 @@ HWTEST_F(DynamicLoaderOhosTest, DynamicLoaderOhosTestFindSymbol_0100, TestSize.L */ HWTEST_F(DynamicLoaderOhosTest, DynamicLoaderOhosTestGetError_0100, TestSize.Level1) { + const char* symbol = "test_symbol"; + unsigned int mode = RTLD_LAZY; + // Test dlerror with an error message - DynamicLoadLibrary(nullptr, "test_library.so", RTLD_LAZY); + void* result = DynamicLoadLibrary(nullptr, symbol, mode); + EXPECT_EQ(result, dlopen(symbol, mode)); } \ No newline at end of file diff --git a/test/unittest/implicit_start_processor_test/implicit_start_processor_test.cpp b/test/unittest/implicit_start_processor_test/implicit_start_processor_test.cpp index 444f39f88d..dba691be5c 100755 --- a/test/unittest/implicit_start_processor_test/implicit_start_processor_test.cpp +++ b/test/unittest/implicit_start_processor_test/implicit_start_processor_test.cpp @@ -67,7 +67,7 @@ HWTEST_F(ImplicitStartProcessorTest, ImplicitStartAbility_001, TestSize.Level1) AbilityRequest request; int32_t userId = 0; bool res = processor->ImplicitStartAbility(request, userId, - AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED); + AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED, "", true); EXPECT_TRUE(res); } @@ -379,6 +379,7 @@ HWTEST_F(ImplicitStartProcessorTest, ProcessLinkType_001, TestSize.Level1) AbilityInfo abilityInfo2; abilityInfo2.linkType = AppExecFwk::LinkType::APP_LINK; abilityInfos.push_back(abilityInfo2); + EXPECT_TRUE(processor != nullptr); } /* @@ -401,6 +402,7 @@ HWTEST_F(ImplicitStartProcessorTest, OnlyKeepReserveApp_001, TestSize.Level1) abilityInfos.push_back(abilityInfo); AbilityRequest abilityRequest; processor->OnlyKeepReserveApp(abilityInfos, extensionAbInfos, abilityRequest); + EXPECT_TRUE(processor != nullptr); } /* @@ -414,7 +416,8 @@ HWTEST_F(ImplicitStartProcessorTest, OnlyKeepReserveApp_001, TestSize.Level1) HWTEST_F(ImplicitStartProcessorTest, GetDefaultAppProxy_001, TestSize.Level1) { auto processor = std::make_shared(); - processor->GetDefaultAppProxy(); + auto result = processor->GetDefaultAppProxy(); + EXPECT_EQ(result, nullptr); } /* @@ -432,28 +435,8 @@ HWTEST_F(ImplicitStartProcessorTest, FilterAbilityList_001, TestSize.Level1) std::vector abilityInfos; std::vector extensionAbInfos; int32_t userId = 100; - processor->FilterAbilityList(want, abilityInfos, extensionAbInfos, userId); -} - -/* - * Feature: ImplicitStartProcessor - * Function: GetEcologicalCallerInfo - * SubFunction: NA - * FunctionPoints:ImplicitStartProcessor GetEcologicalCallerInfo - * EnvConditions: NA - * CaseDescription: Verify GetEcologicalCallerInfo etc. - */ -HWTEST_F(ImplicitStartProcessorTest, GetEcologicalCallerInfo_001, TestSize.Level1) -{ - auto processor = std::make_shared(); - Want want; - ErmsCallerInfo callerInfo; - int32_t userId = 100; - processor->GetEcologicalCallerInfo(want, callerInfo, userId); - want.SetBundle("haha"); - processor->GetEcologicalCallerInfo(want, callerInfo, userId); - want.SetBundle("com.ix.hiservcie"); - processor->GetEcologicalCallerInfo(want, callerInfo, userId); + auto result = processor->FilterAbilityList(want, abilityInfos, extensionAbInfos, userId); + EXPECT_EQ(result, true); } /* @@ -478,20 +461,7 @@ HWTEST_F(ImplicitStartProcessorTest, AddIdentity_001, TestSize.Level1) processor->AddAbilityInfoToDialogInfos(param, dialogAppInfos); param.isExtension = false; processor->AddAbilityInfoToDialogInfos(param, dialogAppInfos); -} - -/* - * Feature: ImplicitStartProcessor - * Function: IsExistDefaultApp - * SubFunction: NA - * FunctionPoints:ImplicitStartProcessor IsExistDefaultApp - * EnvConditions: NA - * CaseDescription: Verify IsExistDefaultApp etc. - */ -HWTEST_F(ImplicitStartProcessorTest, IsExistDefaultApp_001, TestSize.Level1) -{ - auto processor = std::make_shared(); - int32_t userId = 100; + EXPECT_TRUE(processor != nullptr); } } // namespace AAFwk } // namespace OHOS From ca00cc1396f7e2b2ac202f841a0b419944a3ef1c Mon Sep 17 00:00:00 2001 From: chenzexin Date: Thu, 22 Aug 2024 17:08:47 +0800 Subject: [PATCH 07/42] update onstop callback Signed-off-by: chenzexin --- .../ui_extension_ability/js_ui_extension.cpp | 2 + .../js_ui_extension_base.cpp | 127 +++++++++++++++++- .../js_ui_extension_base.h | 14 +- 3 files changed, 139 insertions(+), 4 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 ffb171b716..a92ca2b831 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 @@ -353,6 +353,7 @@ bool JsUIExtension::CheckPromise(napi_value result) return true; } +namespace { napi_value PromiseCallback(napi_env env, napi_callback_info info) { void *data = nullptr; @@ -367,6 +368,7 @@ napi_value PromiseCallback(napi_env env, napi_callback_info info) data = nullptr; return nullptr; } +} bool JsUIExtension::CallPromise(napi_value result, AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo) { diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp index f577f4b6e5..73cb96c79b 100644 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp @@ -21,7 +21,10 @@ #include "ability_info.h" #include "ability_manager_client.h" #include "configuration_utils.h" +#include "connection_manager.h" +#include "context.h" #include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" #include "hitrace_meter.h" #include "insight_intent_executor_info.h" #include "insight_intent_executor_mgr.h" @@ -227,6 +230,123 @@ void JsUIExtensionBase::OnStop() TAG_LOGD(AAFwkTag::UI_EXT, "called"); HandleScope handleScope(jsRuntime_); CallObjectMethod("onDestroy"); + OnStopCallBack(); + TAG_LOGD(AAFwkTag::UI_EXT, "JsUIExtension OnStop end."); +} + +void JsUIExtensionBase::OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, bool &isAsyncCallback) +{ + if (callbackInfo == nullptr) { + isAsyncCallback = false; + OnStop(); + return; + } + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::UI_EXT, "OnStop begin."); + HandleScope handleScope(jsRuntime_); + napi_value result = CallObjectMethod("onDestroy", nullptr, 0, true); + if (!CheckPromise(result)) { + OnStopCallBack(); + isAsyncCallback = false; + return; + } + + std::weak_ptr weakPtr = shared_from_this(); + auto asyncCallback = [extensionWeakPtr = weakPtr]() { + auto jsUIExtensionBase = extensionWeakPtr.lock(); + if (jsUIExtensionBase == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "extension is nullptr."); + return; + } + jsUIExtensionBase->OnStopCallBack(); + }; + callbackInfo->Push(asyncCallback); + isAsyncCallback = CallPromise(result, callbackInfo); + if (!isAsyncCallback) { + TAG_LOGE(AAFwkTag::UI_EXT, "Failed to call promise."); + OnStopCallBack(); + } + TAG_LOGD(AAFwkTag::UI_EXT, "OnStop end."); +} + +void JsUIExtensionBase::OnStopCallBack() +{ + if (context_ == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Failed to get context"); + return; + } + bool ret = ConnectionManager::GetInstance().DisconnectCaller(context_->GetToken()); + if (ret) { + ConnectionManager::GetInstance().ReportConnectionLeakEvent(getpid(), gettid()); + TAG_LOGD(AAFwkTag::UI_EXT, "The service connection is not disconnected."); + } + + auto applicationContext = Context::GetApplicationContext(); + if (applicationContext != nullptr) { + applicationContext->DispatchOnAbilityDestroy(jsObj_); + } +} + +bool JsUIExtensionBase::CheckPromise(napi_value result) +{ + if (result == nullptr) { + TAG_LOGD(AAFwkTag::UI_EXT, "result is null, no need to call promise."); + return false; + } + napi_env env = jsRuntime_.GetNapiEnv(); + bool isPromise = false; + napi_is_promise(env, result, &isPromise); + if (!isPromise) { + TAG_LOGD(AAFwkTag::UI_EXT, "result is not promise, no need to call promise."); + return false; + } + return true; +} + +namespace { +napi_value PromiseCallback(napi_env env, napi_callback_info info) +{ + void *data = nullptr; + NAPI_CALL_NO_THROW(napi_get_cb_info(env, info, nullptr, nullptr, nullptr, &data), nullptr); + auto *callbackInfo = static_cast *>(data); + if (callbackInfo == nullptr) { + TAG_LOGD(AAFwkTag::UI_EXT, "Invalid input info."); + return nullptr; + } + callbackInfo->Call(); + AppExecFwk::AbilityTransactionCallbackInfo<>::Destroy(callbackInfo); + data = nullptr; + return nullptr; +} +} + +bool JsUIExtensionBase::CallPromise(napi_value result, AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo) +{ + auto env = jsRuntime_.GetNapiEnv(); + if (!CheckTypeForNapiValue(env, result, napi_object)) { + TAG_LOGE(AAFwkTag::UI_EXT, "Failed to convert native value to NativeObject."); + return false; + } + napi_value then = nullptr; + napi_get_named_property(env, result, "then", &then); + if (then == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Failed to get property: then."); + return false; + } + bool isCallable = false; + napi_is_callable(env, then, &isCallable); + if (!isCallable) { + TAG_LOGE(AAFwkTag::UI_EXT, "property then is not callable."); + return false; + } + HandleScope handleScope(jsRuntime_); + napi_value promiseCallback = nullptr; + napi_create_function(env, "promiseCallback", strlen("promiseCallback"), PromiseCallback, + callbackInfo, &promiseCallback); + napi_value argv[1] = { promiseCallback }; + napi_call_function(env, result, then, 1, argv, nullptr); + TAG_LOGD(AAFwkTag::UI_EXT, "exit"); + return true; } void JsUIExtensionBase::OnCommandWindow( @@ -594,7 +714,7 @@ void JsUIExtensionBase::DestroyWindow(const sptr &sessionInf } } -napi_value JsUIExtensionBase::CallObjectMethod(const char *name, napi_value const *argv, size_t argc) +napi_value JsUIExtensionBase::CallObjectMethod(const char *name, napi_value const *argv, size_t argc, bool withResult) { TAG_LOGD(AAFwkTag::UI_EXT, "CallObjectMethod(%{public}s), begin", name); if (!jsObj_) { @@ -614,6 +734,11 @@ napi_value JsUIExtensionBase::CallObjectMethod(const char *name, napi_value cons TAG_LOGE(AAFwkTag::UI_EXT, "Failed to get '%{public}s' object", name); return nullptr; } + if (withResult) { + napi_value result = nullptr; + napi_call_function(env, obj, method, argc, argv, &result); + return handleEscape.Escape(result); + } TAG_LOGD(AAFwkTag::UI_EXT, "CallFunction(%{public}s), success", name); napi_value result = nullptr; napi_call_function(env, obj, method, argc, argv, &result); diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_base.h b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_base.h index 053a52a5f3..a2ea4e4729 100644 --- a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_base.h +++ b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_base.h @@ -24,7 +24,7 @@ #include "native_engine/native_engine.h" #include "ohos_application.h" #include "session_info.h" -#include "ui_extension_base.h" +#include "ui_extension_base_impl.h" #include "ui_extension_context.h" #include "ui_extension_window_command.h" #include "want.h" @@ -95,6 +95,11 @@ public: * You can override this function to implement your own processing logic. */ void OnStop() override; + virtual void OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, bool &isAsyncCallback); + /** + * @brief The callback of OnStop. + */ + virtual void OnStopCallBack(); /** * @brief Called when the system configuration is updated. @@ -153,7 +158,10 @@ public: void BindContext() override; protected: - napi_value CallObjectMethod(const char *name, napi_value const *argv = nullptr, size_t argc = 0); + napi_value CallObjectMethod(const char *name, napi_value const *argv = nullptr, size_t argc = 0, + bool withResult = false); + bool CheckPromise(napi_value result); + bool CallPromise(napi_value result, AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo); void ForegroundWindow(const AAFwk::Want &want, const sptr &sessionInfo); void BackgroundWindow(const sptr &sessionInfo); void DestroyWindow(const sptr &sessionInfo); @@ -171,7 +179,7 @@ protected: protected: JsRuntime &jsRuntime_; std::shared_ptr shellContextRef_; - std::unique_ptr jsObj_; + std::shared_ptr jsObj_; std::shared_ptr context_; std::map> uiWindowMap_; std::set foregroundWindows_; From b45be8b5b019a4b205fe7b5716a7845bbd46a212 Mon Sep 17 00:00:00 2001 From: sodanotgreen Date: Thu, 22 Aug 2024 17:25:01 +0800 Subject: [PATCH 08/42] wendingxing Signed-off-by: sodanotgreen --- interfaces/inner_api/wantagent/include/want_agent_helper.h | 2 +- interfaces/inner_api/wantagent/src/want_agent_helper.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/inner_api/wantagent/include/want_agent_helper.h b/interfaces/inner_api/wantagent/include/want_agent_helper.h index f834bd63c7..d003e21db1 100644 --- a/interfaces/inner_api/wantagent/include/want_agent_helper.h +++ b/interfaces/inner_api/wantagent/include/want_agent_helper.h @@ -108,7 +108,7 @@ public: * * @param agent Indicates the WantAgent to cancel. */ - static ErrCode Cancel(const std::shared_ptr &agent); + static ErrCode Cancel(const std::shared_ptr agent); /** * Checks whether two WantAgent objects are the same. diff --git a/interfaces/inner_api/wantagent/src/want_agent_helper.cpp b/interfaces/inner_api/wantagent/src/want_agent_helper.cpp index 24dc9e7100..ed0ac32123 100644 --- a/interfaces/inner_api/wantagent/src/want_agent_helper.cpp +++ b/interfaces/inner_api/wantagent/src/want_agent_helper.cpp @@ -224,7 +224,7 @@ ErrCode WantAgentHelper::Send(const std::shared_ptr &pendingWant, pendingWant->GetTarget()); } -ErrCode WantAgentHelper::Cancel(const std::shared_ptr &agent) +ErrCode WantAgentHelper::Cancel(const std::shared_ptr agent) { if (agent == nullptr) { TAG_LOGE(AAFwkTag::WANTAGENT, "invalid input param"); From 16f40f831972cb5b4e53c66e1c033f457f21814f Mon Sep 17 00:00:00 2001 From: sodanotgreen Date: Thu, 22 Aug 2024 17:44:02 +0800 Subject: [PATCH 09/42] recovery Signed-off-by: sodanotgreen --- .../ability_manager/include/ability_manager_client.h | 2 +- .../include/ability_manager_interface.h | 2 +- .../app_manager/include/appmgr/ams_mgr_interface.h | 6 +++--- .../app_manager/include/appmgr/ams_mgr_proxy.h | 6 +++--- .../app_manager/include/appmgr/app_mgr_client.h | 4 ++-- .../ability_runtime/context/application_context.h | 2 +- .../appkit/ability_runtime/context/context_impl.h | 2 +- interfaces/kits/native/appkit/app/ability_manager.h | 2 +- services/abilitymgr/include/ability_manager_proxy.h | 2 +- services/abilitymgr/include/ability_manager_service.h | 2 +- services/abilitymgr/include/app_scheduler.h | 2 +- services/appmgr/include/ams_mgr_scheduler.h | 6 +++--- services/appmgr/include/app_mgr_service_inner.h | 10 +++++----- services/appmgr/include/app_running_manager.h | 4 ++-- .../include/mock_ability_manager_service.h | 2 +- .../appexecfwk_core/include/appmgr/app_mgr_client.h | 2 +- .../libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp | 2 +- .../ams_app_mgr_service_module_test.cpp | 2 +- .../mock/include/appmgr/mock_ability_mgr_host.h | 2 +- .../ability_manager_stub_mock_test.h | 2 +- .../ability_manager_stub_mock.h | 2 +- .../ability_manager_stub_impl_mock.h | 2 +- .../ability_manager_test/ability_manager_stub_mock.h | 2 +- .../ability_manager_stub_mock.h | 2 +- 24 files changed, 36 insertions(+), 36 deletions(-) diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_client.h b/interfaces/inner_api/ability_manager/include/ability_manager_client.h index 9a6852ae35..edbb2558eb 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -600,7 +600,7 @@ public: * @param clearPageStack. * @return Returns ERR_OK on success, others on failure. */ - ErrCode KillProcess(const std::string &bundleName, const bool clearpagestack = false); + ErrCode KillProcess(const std::string &bundleName, const bool clearPageStack = true); #ifdef ABILITY_COMMAND_FOR_TEST /** diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index 63a5bc0aab..5707db2202 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -749,7 +749,7 @@ public: * @param bundleName. * @return Returns ERR_OK on success, others on failure. */ - virtual int KillProcess(const std::string &bundleName, const bool clearpagestack = false) = 0; + virtual int KillProcess(const std::string &bundleName, const bool clearPageStack = true) = 0; #ifdef ABILITY_COMMAND_FOR_TEST /** diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h index 309d58016d..bd84a70789 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h @@ -130,7 +130,7 @@ public: * @return ERR_OK, return back success, others fail. */ virtual int KillProcessWithAccount( - const std::string &bundleName, const int accountId, const bool clearpagestack = false) = 0; + const std::string &bundleName, const int accountId, const bool clearPageStack = true) = 0; /** * UpdateApplicationInfoInstalled, call UpdateApplicationInfoInstalled() through proxy object, @@ -148,7 +148,7 @@ public: * @param bundleName, bundle name in Application record. * @return ERR_OK, return back success, others fail. */ - virtual int KillApplication(const std::string &bundleName, const bool clearpagestack = false) = 0; + virtual int KillApplication(const std::string &bundleName, const bool clearPageStack = true) = 0; /** * ForceKillApplication, call ForceKillApplication() through proxy object, force kill the application. @@ -183,7 +183,7 @@ public: * * @return Returns ERR_OK on success, others on failure. */ - virtual int KillApplicationSelf(const bool clearpagestack = false) + virtual int KillApplicationSelf(const bool clearPageStack = true) { return ERR_OK; } diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h index 5192875146..cc61ae03f2 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h @@ -120,7 +120,7 @@ public: * @return ERR_OK, return back success, others fail. */ virtual int32_t KillProcessWithAccount( - const std::string &bundleName, const int accountId, const bool clearpagestack = false) override; + const std::string &bundleName, const int accountId, const bool clearPageStack = true) override; /** * UpdateApplicationInfoInstalled, call UpdateApplicationInfoInstalled() through proxy object, @@ -138,7 +138,7 @@ public: * @param bundleName, bundle name in Application record. * @return ERR_OK, return back success, others fail. */ - virtual int32_t KillApplication(const std::string &bundleName, const bool clearpagestack = false) override; + virtual int32_t KillApplication(const std::string &bundleName, const bool clearPageStack = true) override; /** * ForceKillApplication, call ForceKillApplication() through proxy object, force kill the application. @@ -169,7 +169,7 @@ public: */ virtual int32_t KillApplicationByUid(const std::string &bundleName, const int uid) override; - virtual int KillApplicationSelf(const bool clearpagestack = false) override; + virtual int KillApplicationSelf(const bool clearPageStack = true) override; virtual int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug) override; diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h index e9d7879d0a..8ae8afe3f1 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h @@ -161,7 +161,7 @@ public: * @param bundleName, bundle name in Application record. * @return ERR_OK, return back success, others fail. */ - virtual AppMgrResultCode KillApplication(const std::string &bundleName, const bool clearpagestack = false); + virtual AppMgrResultCode KillApplication(const std::string &bundleName, const bool clearPageStack = true); /** * ForceKillApplication, call ForceKillApplication() through proxy object, force kill the application. @@ -197,7 +197,7 @@ public: * * @return Returns ERR_OK on success, others on failure. */ - virtual AppMgrResultCode KillApplicationSelf(const bool clearpagestack = false); + virtual AppMgrResultCode KillApplicationSelf(const bool clearPageStack = true); /** * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, 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 03c057fbd8..dd03794d0b 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h @@ -120,7 +120,7 @@ public: void AppHasDarkRes(bool &darkRes); std::string GetBaseDir() const override; Global::Resource::DeviceType GetDeviceType() const override; - void KillProcessBySelf(const bool clearpagestack = false); + void KillProcessBySelf(const bool clearPageStack = true); int32_t GetProcessRunningInformation(AppExecFwk::RunningProcessInfo &info); int32_t RestartApp(const AAFwk::Want& want); 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 e4c6e7d276..722ee920cf 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h @@ -341,7 +341,7 @@ public: * * @return error code */ - void KillProcessBySelf(const bool clearpagestack = false); + void KillProcessBySelf(const bool clearPageStack = true); /** * @brief Get running informationfor cuirrent process diff --git a/interfaces/kits/native/appkit/app/ability_manager.h b/interfaces/kits/native/appkit/app/ability_manager.h index a8408ee946..b7f8bec290 100644 --- a/interfaces/kits/native/appkit/app/ability_manager.h +++ b/interfaces/kits/native/appkit/app/ability_manager.h @@ -62,7 +62,7 @@ public: * @param bundleName. * @return Returns ERR_OK on success, others on failure. */ - int KillProcessesByBundleName(const std::string &bundleName, const bool clearpagestack = false); + int KillProcessesByBundleName(const std::string &bundleName, const bool clearPageStack = true); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index b13bf18e91..f71a8c88da 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -590,7 +590,7 @@ public: * @param bundleName. * @return Returns ERR_OK on success, others on failure. */ - virtual int KillProcess(const std::string &bundleName, const bool clearpagestack = false) override; + virtual int KillProcess(const std::string &bundleName, const bool clearPageStack = true) override; #ifdef ABILITY_COMMAND_FOR_TEST /** diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 484a6b2f5e..f4ad13f8a3 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -839,7 +839,7 @@ public: * @param bundleName. * @return Returns ERR_OK on success, others on failure. */ - virtual int KillProcess(const std::string &bundleName, const bool clearpagestack = false) override; + virtual int KillProcess(const std::string &bundleName, const bool clearPageStack = true) override; /** * Uninstall app diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 8a5ebf96ca..b1dd12a8ce 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -231,7 +231,7 @@ public: * * @param bundleName. */ - int KillApplication(const std::string &bundleName, const bool clearpagestack = false); + int KillApplication(const std::string &bundleName, const bool clearPageStack = true); /** * ForceKillApplication, force kill the application. diff --git a/services/appmgr/include/ams_mgr_scheduler.h b/services/appmgr/include/ams_mgr_scheduler.h index e8d866e605..dfa4d3b20e 100644 --- a/services/appmgr/include/ams_mgr_scheduler.h +++ b/services/appmgr/include/ams_mgr_scheduler.h @@ -133,7 +133,7 @@ public: * @return ERR_OK, return back success, others fail. */ virtual int32_t KillProcessWithAccount( - const std::string &bundleName, const int accountId, const bool clearpagestack = false) override; + const std::string &bundleName, const int accountId, const bool clearPageStack = true) override; /** * UpdateApplicationInfoInstalled, call UpdateApplicationInfoInstalled() through proxy object, @@ -151,7 +151,7 @@ public: * @param bundleName, bundle name in Application record. * @return ERR_OK, return back success, others fail. */ - virtual int32_t KillApplication(const std::string &bundleName, const bool clearpagestack = false) override; + virtual int32_t KillApplication(const std::string &bundleName, const bool clearPageStack = true) override; /** * ForceKillApplication, force kill the application. @@ -181,7 +181,7 @@ public: */ virtual int KillApplicationByUid(const std::string &bundleName, const int uid) override; - virtual int KillApplicationSelf(const bool clearpagestack = false) override; + virtual int KillApplicationSelf(const bool clearPageStack = true) override; int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug) override; diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 67030b3263..dafcd34523 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -262,7 +262,7 @@ public: * * @return ERR_OK, return back success, others fail. */ - virtual int32_t KillApplication(const std::string &bundleName, const bool clearpagestack = false); + virtual int32_t KillApplication(const std::string &bundleName, const bool clearPageStack = true); /** * ForceKillApplication, force kill the application. @@ -292,7 +292,7 @@ public: */ virtual int32_t KillApplicationByUid(const std::string &bundleName, const int uid); - virtual int32_t KillApplicationSelf(const bool clearpagestack = false); + virtual int32_t KillApplicationSelf(const bool clearPageStack = true); /** * KillApplicationByUserId, kill the application by user ID. @@ -304,7 +304,7 @@ public: * @return ERR_OK, return back success, others fail. */ virtual int32_t KillApplicationByUserId(const std::string &bundleName, int32_t appCloneIndex, int userId, - const bool clearpagestack = false); + const bool clearPageStack = true); /** * ClearUpApplicationData, clear the application data. @@ -1237,7 +1237,7 @@ private: * @return ERR_OK, return back success, others fail. */ int32_t KillApplicationByUserIdLocked(const std::string &bundleName, int32_t appCloneIndex, int32_t userId, - const bool clearpagestack = false); + const bool clearPageStack = true); /** * WaitForRemoteProcessExit, Wait for the process to exit normally. @@ -1368,7 +1368,7 @@ private: bool CheckGetRunningInfoPermission() const; int32_t KillApplicationByBundleName( - const std::string &bundleName, const bool clearpagestack = false); + const std::string &bundleName, const bool clearPageStack = true); bool SendProcessStartEvent(const std::shared_ptr &appRecord); diff --git a/services/appmgr/include/app_running_manager.h b/services/appmgr/include/app_running_manager.h index 49ef6c5272..12316feb6c 100644 --- a/services/appmgr/include/app_running_manager.h +++ b/services/appmgr/include/app_running_manager.h @@ -169,7 +169,7 @@ public: * @return Return true if found, otherwise return false. */ bool ProcessExitByBundleName( - const std::string &bundleName, std::list &pids, const bool clearpagestack = false); + const std::string &bundleName, std::list &pids, const bool clearPageStack = true); /** * Get Foreground Applications. * @@ -253,7 +253,7 @@ public: int32_t ProcessUpdateApplicationInfoInstalled(const ApplicationInfo &appInfo); bool ProcessExitByBundleNameAndUid( - const std::string &bundleName, const int uid, std::list &pids, const bool clearpagestack = false); + const std::string &bundleName, const int uid, std::list &pids, const bool clearPageStack = true); bool GetPidsByUserId(int32_t userId, std::list &pids); void PrepareTerminate(const sptr &token, bool clearMissionFlag = false); diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h index e102ae8b79..8b74259d38 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h @@ -173,7 +173,7 @@ public: return releaseDataAbility_; } - int KillProcess(const std::string& bundleName, const bool clearpagestack = false) override; + int KillProcess(const std::string& bundleName, const bool clearPageStack = true) override; int UninstallApp(const std::string& bundleName, int32_t uid) override; diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h index ac83433746..092fc3f569 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h @@ -123,7 +123,7 @@ public: * @param bundleName, bundle name in Application record. * @return ERR_OK, return back success, others fail. */ - virtual AppMgrResultCode KillApplication(const std::string& bundleName, const bool clearpagestack = false); + virtual AppMgrResultCode KillApplication(const std::string& bundleName, const bool clearPageStack = true); /** * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp index e80dcecf7b..f6ff62b1d3 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp @@ -78,7 +78,7 @@ AppMgrResultCode AppMgrClient::KillProcessesByUserId(int32_t userId) } AppMgrResultCode AppMgrClient::KillApplication( - const std::string& bundleName, const bool clearpagestack = false) + const std::string& bundleName, const bool clearPageStack = true) { return AppMgrResultCode::RESULT_OK; } 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 0cd754d35a..2895a543f1 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 @@ -418,7 +418,7 @@ HWTEST_F(AppMgrServiceModuleTest, KillApplication_001, TestSize.Level1) Semaphore sem(0); auto mockHandler = [&testResult, testBundleName, &sem]( - const std::string& bundleName, const bool clearpagestack = false) { + const std::string& bundleName, const bool clearPageStack = true) { testResult = (bundleName == testBundleName); sem.Post(); return 0; diff --git a/test/moduletest/mock/include/appmgr/mock_ability_mgr_host.h b/test/moduletest/mock/include/appmgr/mock_ability_mgr_host.h index dfdd68dcea..16c3af0a20 100644 --- a/test/moduletest/mock/include/appmgr/mock_ability_mgr_host.h +++ b/test/moduletest/mock/include/appmgr/mock_ability_mgr_host.h @@ -142,7 +142,7 @@ public: return 0; } - virtual int KillProcess(const std::string& bundleName, const bool clearpagestack = false) override + virtual int KillProcess(const std::string& bundleName, const bool clearPageStack = true) override { return 0; } diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h index 40f7f781e2..d8af5cad48 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h @@ -200,7 +200,7 @@ public: return 0; } - virtual int KillProcess(const std::string& bundleName, const bool clearpagestack = false) + virtual int KillProcess(const std::string& bundleName, const bool clearPageStack = true) { return 0; } diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h index 5eab1a21ea..3e9df7d2d9 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -210,7 +210,7 @@ public: return 0; } - virtual int KillProcess(const std::string& bundleName, const bool clearpagestack = false) + virtual int KillProcess(const std::string& bundleName, const bool clearPageStack = true) { return 0; } diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h index 51d44b36b9..e390d6ebdd 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -220,7 +220,7 @@ public: return 0; } - virtual int KillProcess(const std::string& bundleName, const bool clearpagestack = false) + virtual int KillProcess(const std::string& bundleName, const bool clearPageStack = true) { return 0; } diff --git a/test/unittest/ability_manager_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_test/ability_manager_stub_mock.h index ba936e2a7d..029f0bd121 100644 --- a/test/unittest/ability_manager_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_test/ability_manager_stub_mock.h @@ -193,7 +193,7 @@ public: return 0; } - virtual int KillProcess(const std::string& bundleName, const bool clearpagestack = false) + virtual int KillProcess(const std::string& bundleName, const bool clearPageStack = true) { return 0; } diff --git a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h index d0de972f2b..3d8955c194 100644 --- a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h +++ b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h @@ -174,7 +174,7 @@ public: return 0; } - virtual int KillProcess(const std::string& bundleName, const bool clearpagestack = false) + virtual int KillProcess(const std::string& bundleName, const bool clearPageStack = true) { return 0; } From cc2afde9e1cdcfaf2afed05d824db13bc7976c11 Mon Sep 17 00:00:00 2001 From: chenzexin Date: Thu, 22 Aug 2024 17:48:18 +0800 Subject: [PATCH 10/42] debug Signed-off-by: chenzexin --- .../native/ui_extension_ability/js_ui_extension_base.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp index 73cb96c79b..d5f024de82 100644 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp @@ -727,7 +727,7 @@ napi_value JsUIExtensionBase::CallObjectMethod(const char *name, napi_value cons TAG_LOGE(AAFwkTag::UI_EXT, "Failed to get object"); return nullptr; } - + HandleEscape handleEscape(jsRuntime_); napi_value method = nullptr; napi_get_named_property(env, obj, name, &method); if (!CheckTypeForNapiValue(env, method, napi_function)) { From dd204956846532e96eb5778ad66c750cc15cd29b Mon Sep 17 00:00:00 2001 From: huzeshan Date: Thu, 22 Aug 2024 17:50:19 +0800 Subject: [PATCH 11/42] =?UTF-8?q?=E3=80=90=E5=BA=94=E7=94=A8=E7=83=AD?= =?UTF-8?q?=E5=90=AF=E3=80=91TDD=E9=80=82=E9=85=8D=E4=BA=A7=E5=93=81?= =?UTF-8?q?=E6=9C=AA=E9=85=8D=E7=BD=AE=E7=89=B9=E6=80=A7=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huzeshan --- .../app_mgr_service_test/app_mgr_service_test.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 19da3c79df..1ff9112697 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 @@ -26,6 +26,7 @@ #include "mock_native_token.h" #include "mock_sa_call.h" #include "ipc_skeleton.h" +#include "parameters.h" using namespace testing; using namespace testing::ext; @@ -1749,7 +1750,12 @@ HWTEST_F(AppMgrServiceTest, SetSupportedProcessCacheSelf_002, TestSize.Level0) recordMap.insert({IPCSkeleton::GetCallingPid(), appRecord}); } res = appMgrService->SetSupportedProcessCacheSelf(false); - EXPECT_EQ(res, AAFwk::ERR_CAPABILITY_NOT_SUPPORT); + const std::string MAX_PROC_CACHE_NUM = "persist.sys.abilityms.maxProcessCacheNum"; + if (OHOS::system::GetIntParameter(MAX_PROC_CACHE_NUM, 0) <= 0) { + EXPECT_EQ(res, AAFwk::ERR_CAPABILITY_NOT_SUPPORT); + } else { + EXPECT_EQ(res, ERR_OK); + } } /* From a873f8b41ae7dd06a561bdd2cfce23acfcf64df9 Mon Sep 17 00:00:00 2001 From: zhuhan Date: Thu, 22 Aug 2024 17:25:46 +0800 Subject: [PATCH 12/42] env dfx Signed-off-by: zhuhan Change-Id: I6e6f545b6e2ae549bb54cc23345368b0eef6b3cf --- frameworks/native/appkit/BUILD.gn | 6 +++++- .../context/application_context_manager.cpp | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index 56cf4b7ce3..5dc0c79ddb 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -472,7 +472,10 @@ ohos_shared_library("appkit_delegator") { } config("application_context_manager_config") { - include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context" ] + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", + "${ability_runtime_services_path}/common/include", + ] } ohos_shared_library("appkit_manager_helper") { @@ -529,6 +532,7 @@ ohos_shared_library("application_context_manager") { external_deps = [ "ets_runtime:libark_jsruntime", + "hilog:libhilog", "napi:ace_napi", ] diff --git a/frameworks/native/appkit/ability_runtime/context/application_context_manager.cpp b/frameworks/native/appkit/ability_runtime/context/application_context_manager.cpp index b71a9eb1cc..b90ea0279c 100644 --- a/frameworks/native/appkit/ability_runtime/context/application_context_manager.cpp +++ b/frameworks/native/appkit/ability_runtime/context/application_context_manager.cpp @@ -15,6 +15,8 @@ #include "application_context_manager.h" +#include "hilog_tag_wrapper.h" + namespace OHOS { namespace AbilityRuntime { namespace { @@ -52,7 +54,10 @@ void ApplicationContextManager::AddGlobalObject(napi_env env, if (envData == nullptr) { return; } - napi_add_env_cleanup_hook(env, HandleClean, static_cast(envData)); + auto ret = napi_add_env_cleanup_hook(env, HandleClean, static_cast(envData)); + if (ret != napi_status::napi_ok) { + TAG_LOGE(AAFwkTag::APPKIT, "add hook err"); + } std::lock_guard lock(applicationContextMutex_); auto iter = applicationContextMap_.find(env); if (iter == applicationContextMap_.end()) { From 9676a7c1f53ec89c767972a37bc4c441b2126013 Mon Sep 17 00:00:00 2001 From: tantingting Date: Thu, 22 Aug 2024 19:23:40 +0800 Subject: [PATCH 13/42] Adapt window parameters Signed-off-by: tantingting --- .../ability/native/configuration_utils.cpp | 40 ++++++ .../native/ability/native/extension_impl.cpp | 3 +- .../ui_extension_ability/js_ui_extension.cpp | 121 ++++++++++++++--- .../js_ui_extension_base.cpp | 124 +++++++++++++++--- .../ability/native/configuration_utils.h | 29 +++- .../ui_extension_ability/js_ui_extension.h | 42 +++++- .../js_ui_extension_base.h | 47 ++++++- .../ui_extension_ability/ui_extension_base.h | 4 +- .../ui_extension_base_impl.h | 3 +- 9 files changed, 368 insertions(+), 45 deletions(-) diff --git a/frameworks/native/ability/native/configuration_utils.cpp b/frameworks/native/ability/native/configuration_utils.cpp index cc80324a96..b621e97b50 100644 --- a/frameworks/native/ability/native/configuration_utils.cpp +++ b/frameworks/native/ability/native/configuration_utils.cpp @@ -113,6 +113,46 @@ void ConfigurationUtils::UpdateDisplayConfig(Rosen::DisplayId displayId, std::sh Rosen::Window::UpdateConfigurationForAll(diffConfiguration); } +void ConfigurationUtils::InitDisplayConfig(std::shared_ptr configuration, + std::shared_ptr resourceManager, Rosen::DisplayId displayId, float density, int32_t orientation) +{ + TAG_LOGD(AAFwkTag::ABILITY, "Init display config"); + if (configuration == nullptr || resourceManager == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY, "Input invalid"); + return; + } + auto direction = GetDirectionStr(orientation); + configuration->AddItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI, GetDensityStr(density)); + configuration->AddItem(displayId, ConfigurationInner::APPLICATION_DIRECTION, direction); + configuration->AddItem(ConfigurationInner::APPLICATION_DISPLAYID, std::to_string(displayId)); + UpdateDisplayResConfig(resourceManager, density, direction); +} + +bool ConfigurationUtils::UpdateDisplayConfig(std::shared_ptr configuration, + std::shared_ptr resourceManager, Rosen::DisplayId displayId, float density, + Rosen::DisplayOrientation orientation) +{ + TAG_LOGD(AAFwkTag::ABILITY, "Update display config"); + if (configuration == nullptr || resourceManager == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY, "Input invalid"); + return false; + } + auto direction = GetDirectionStr(static_cast(orientation)); + Configuration newConfig; + newConfig.AddItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI, GetDensityStr(density)); + newConfig.AddItem(displayId, ConfigurationInner::APPLICATION_DIRECTION, direction); + + std::vector changeKeyV; + configuration->CompareDifferent(changeKeyV, newConfig); + if (changeKeyV.empty()) { + TAG_LOGD(AAFwkTag::ABILITY, "There's no changed config"); + return false; + } + configuration->Merge(changeKeyV, newConfig); + UpdateDisplayResConfig(resourceManager, density, direction); + return true; +} + bool ConfigurationUtils::GetDisplayConfig(Rosen::DisplayId displayId, float &density, std::string &directionStr) { diff --git a/frameworks/native/ability/native/extension_impl.cpp b/frameworks/native/ability/native/extension_impl.cpp index 35cd100873..305aa5effc 100644 --- a/frameworks/native/ability/native/extension_impl.cpp +++ b/frameworks/native/ability/native/extension_impl.cpp @@ -189,7 +189,8 @@ void ExtensionImpl::Start(const Want &want, sptr sessionInfo } TAG_LOGD(AAFwkTag::EXT, "ExtensionImpl::Start"); - if (extension_->abilityInfo_->extensionAbilityType == AppExecFwk::ExtensionAbilityType::WINDOW) { + if (extension_->abilityInfo_->extensionAbilityType == AppExecFwk::ExtensionAbilityType::WINDOW || + AAFwk::UIExtensionUtils::IsUIExtension(extension_->abilityInfo_->extensionAbilityType)) { extension_->OnStart(want, sessionInfo); } else { extension_->OnStart(want); 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 ffb171b716..68d34fb5e5 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 @@ -173,6 +173,8 @@ void JsUIExtension::Init(const std::shared_ptr &record, SetExtensionCommon( JsExtensionCommon::Create(jsRuntime_, static_cast(*jsObj_), shellContextRef_)); + handler_ = handler; + RegisterDisplayInfoChangedListener(); } void JsUIExtension::CreateJSContext(napi_env env, napi_value &contextObj, @@ -234,19 +236,17 @@ void JsUIExtension::BindContext(napi_env env, napi_value obj, std::shared_ptr sessionInfo) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::UI_EXT, "begin"); Extension::OnStart(want); auto context = GetContext(); #ifdef SUPPORT_GRAPHICS - if (context != nullptr) { - int32_t displayId = static_cast(Rosen::DisplayManager::GetInstance().GetDefaultDisplayId()); - displayId = want.GetIntParam(Want::PARAM_RESV_DISPLAY_ID, displayId); - TAG_LOGD(AAFwkTag::UI_EXT, "displayId %{public}d", displayId); + if (context != nullptr && sessionInfo != nullptr) { auto configUtils = std::make_shared(); - configUtils->InitDisplayConfig(displayId, context->GetConfiguration(), context->GetResourceManager()); + configUtils->InitDisplayConfig(context->GetConfiguration(), context->GetResourceManager(), + sessionInfo->displayId, sessionInfo->density, sessionInfo->orientation); } #endif // SUPPORT_GRAPHICS @@ -279,6 +279,9 @@ void JsUIExtension::OnStop() TAG_LOGD(AAFwkTag::UI_EXT, "begin"); HandleScope handleScope(jsRuntime_); CallObjectMethod("onDestroy"); +#ifdef SUPPORT_GRAPHICS + UnregisterDisplayInfoChangedListener(); +#endif // SUPPORT_GRAPHICS OnStopCallBack(); TAG_LOGD(AAFwkTag::UI_EXT, "end"); } @@ -294,6 +297,9 @@ void JsUIExtension::OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *callbac UIExtension::OnStop(); HandleScope handleScope(jsRuntime_); napi_value result = CallObjectMethod("onDestroy", nullptr, 0, true); +#ifdef SUPPORT_GRAPHICS + UnregisterDisplayInfoChangedListener(); +#endif // SUPPORT_GRAPHICS if (!CheckPromise(result)) { OnStopCallBack(); isAsyncCallback = false; @@ -927,9 +933,6 @@ void JsUIExtension::OnConfigurationUpdated(const AppExecFwk::Configuration& conf Extension::OnConfigurationUpdated(configuration); TAG_LOGD(AAFwkTag::UI_EXT, "called"); - HandleScope handleScope(jsRuntime_); - napi_env env = jsRuntime_.GetNapiEnv(); - // Notify extension context auto context = GetContext(); if (context == nullptr) { @@ -940,15 +943,7 @@ void JsUIExtension::OnConfigurationUpdated(const AppExecFwk::Configuration& conf auto configUtils = std::make_shared(); configUtils->UpdateGlobalConfig(configuration, context->GetResourceManager()); - auto fullConfig = context->GetConfiguration(); - if (!fullConfig) { - TAG_LOGE(AAFwkTag::UI_EXT, "configuration is nullptr"); - return; - } - JsExtensionContext::ConfigurationUpdated(env, shellContextRef_, fullConfig); - - napi_value napiConfiguration = OHOS::AppExecFwk::WrapConfiguration(env, *fullConfig); - CallObjectMethod("onConfigurationUpdate", &napiConfiguration, ARGC_ONE); + ConfigurationUpdated(); } void JsUIExtension::Dump(const std::vector ¶ms, std::vector &info) @@ -1019,5 +1014,95 @@ void JsUIExtension::OnAbilityResult(int requestCode, int resultCode, const Want abilityResultListeners_->OnAbilityResult(requestCode, resultCode, resultData); TAG_LOGD(AAFwkTag::UI_EXT, "end"); } + +void JsUIExtension::ConfigurationUpdated() +{ + TAG_LOGD(AAFwkTag::UI_EXT, "begin"); + HandleScope handleScope(jsRuntime_); + napi_env env = jsRuntime_.GetNapiEnv(); + + // Notify extension context + auto context = GetContext(); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Failed to get context"); + return; + } + + auto fullConfig = context->GetConfiguration(); + if (fullConfig == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Configuration is nullptr"); + return; + } + JsExtensionContext::ConfigurationUpdated(env, shellContextRef_, fullConfig); + + napi_value napiConfiguration = OHOS::AppExecFwk::WrapConfiguration(env, *fullConfig); + CallObjectMethod("onConfigurationUpdate", &napiConfiguration, ARGC_ONE); +} + +#ifdef SUPPORT_GRAPHICS +void JsUIExtension::OnDisplayInfoChange( + const sptr &token, Rosen::DisplayId displayId, float density, Rosen::DisplayOrientation orientation) +{ + TAG_LOGI(AAFwkTag::UI_EXT, "displayId: %{public}" PRIu64 "", displayId); + auto context = GetContext(); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Context is invalid"); + return; + } + + auto contextConfig = context->GetConfiguration(); + if (contextConfig == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Configuration is invalid"); + return; + } + + TAG_LOGD(AAFwkTag::UI_EXT, "Config dump: %{public}s", contextConfig->GetName().c_str()); + auto configUtils = std::make_shared(); + auto result = + configUtils->UpdateDisplayConfig(contextConfig, context->GetResourceManager(), displayId, density, orientation); + TAG_LOGD(AAFwkTag::UI_EXT, "Config dump after update: %{public}s", contextConfig->GetName().c_str()); + if (result) { + auto jsUiExtension = std::static_pointer_cast(shared_from_this()); + auto task = [jsUiExtension]() { + if (jsUiExtension) { + jsUiExtension->ConfigurationUpdated(); + } + }; + if (handler_ != nullptr) { + handler_->PostTask(task, "JsUIExtension:OnChange"); + } + } +} + +void JsUIExtension::RegisterDisplayInfoChangedListener() +{ + // register displayid change callback + auto jsUiExtension = std::static_pointer_cast(shared_from_this()); + jsUiExtensionAbilityDisplayListener_ = sptr::MakeSptr(jsUiExtension); + if (jsUiExtensionAbilityDisplayListener_ == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "jsUiExtensionAbilityDisplayListener is nullptr"); + return; + } + auto context = GetContext(); + if (context == nullptr || context->GetToken() == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Param is invalid"); + return; + } + TAG_LOGI(AAFwkTag::UI_EXT, "RegisterDisplayInfoChangedListener"); + Rosen::WindowManager::GetInstance().RegisterDisplayInfoChangedListener( + context->GetToken(), jsUiExtensionAbilityDisplayListener_); +} + +void JsUIExtension::UnregisterDisplayInfoChangedListener() +{ + auto context = GetContext(); + if (context == nullptr || context->GetToken() == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Param is invalid"); + return; + } + Rosen::WindowManager::GetInstance().UnregisterDisplayInfoChangedListener( + context->GetToken(), jsUiExtensionAbilityDisplayListener_); +} +#endif // SUPPORT_GRAPHICS } } diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp index f577f4b6e5..b927505abe 100644 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp @@ -149,7 +149,8 @@ std::shared_ptr JsUIExtensionBase::Init(const std::shared_ptr(*jsObj_), shellContextRef_); } @@ -204,12 +205,25 @@ void JsUIExtensionBase::BindContext() nullptr, nullptr); } -void JsUIExtensionBase::OnStart(const AAFwk::Want &want, AAFwk::LaunchParam &launchParam) +void JsUIExtensionBase::OnStart( + const AAFwk::Want &want, AAFwk::LaunchParam &launchParam, sptr sessionInfo) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::UI_EXT, "called"); +#ifdef SUPPORT_GRAPHICS + if (context_ != nullptr && sessionInfo != nullptr) { + auto configUtils = std::make_shared(); + configUtils->InitDisplayConfig(context_->GetConfiguration(), context_->GetResourceManager(), + sessionInfo->displayId, sessionInfo->density, sessionInfo->orientation); + } +#endif // SUPPORT_GRAPHICS + HandleScope handleScope(jsRuntime_); napi_env env = jsRuntime_.GetNapiEnv(); + + if (context_ != nullptr) { + JsExtensionContext::ConfigurationUpdated(env, shellContextRef_, context_->GetConfiguration()); + } napi_value napiWant = OHOS::AppExecFwk::WrapWant(env, want); if (InsightIntentExecuteParam::IsInsightIntentExecute(want)) { launchParam.launchReason = AAFwk::LaunchReason::LAUNCHREASON_INSIGHT_INTENT; @@ -227,6 +241,9 @@ void JsUIExtensionBase::OnStop() TAG_LOGD(AAFwkTag::UI_EXT, "called"); HandleScope handleScope(jsRuntime_); CallObjectMethod("onDestroy"); +#ifdef SUPPORT_GRAPHICS + UnregisterDisplayInfoChangedListener(); +#endif // SUPPORT_GRAPHICS } void JsUIExtensionBase::OnCommandWindow( @@ -632,22 +649,7 @@ void JsUIExtensionBase::OnConfigurationUpdated(const AppExecFwk::Configuration & auto configUtils = std::make_shared(); configUtils->UpdateGlobalConfig(configuration, context_->GetResourceManager()); - HandleScope handleScope(jsRuntime_); - auto fullConfig = context_->GetConfiguration(); - if (!fullConfig) { - TAG_LOGE(AAFwkTag::UI_EXT, "configuration is nullptr"); - return; - } - napi_env env = jsRuntime_.GetNapiEnv(); - JsExtensionContext::ConfigurationUpdated(env, shellContextRef_, fullConfig); - - napi_value napiConfiguration = - OHOS::AppExecFwk::WrapConfiguration(env, *fullConfig); - if (napiConfiguration == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "Failed to get configuration"); - return; - } - CallObjectMethod("onConfigurationUpdate", &napiConfiguration, ARGC_ONE); + ConfigurationUpdated(); } void JsUIExtensionBase::Dump(const std::vector ¶ms, std::vector &info) @@ -722,5 +724,91 @@ void JsUIExtensionBase::SetContext(const std::shared_ptr &co { context_ = context; } + +void JsUIExtensionBase::ConfigurationUpdated() +{ + TAG_LOGD(AAFwkTag::UI_EXT, "begin"); + HandleScope handleScope(jsRuntime_); + napi_env env = jsRuntime_.GetNapiEnv(); + + // Notify extension context + if (context_ == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Failed to get context"); + return; + } + + auto fullConfig = context_->GetConfiguration(); + if (fullConfig == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Configuration is nullptr"); + return; + } + JsExtensionContext::ConfigurationUpdated(env, shellContextRef_, fullConfig); + + napi_value napiConfiguration = OHOS::AppExecFwk::WrapConfiguration(env, *fullConfig); + CallObjectMethod("onConfigurationUpdate", &napiConfiguration, ARGC_ONE); +} + +#ifdef SUPPORT_GRAPHICS +void JsUIExtensionBase::OnDisplayInfoChange( + const sptr &token, Rosen::DisplayId displayId, float density, Rosen::DisplayOrientation orientation) +{ + TAG_LOGI(AAFwkTag::UI_EXT, "displayId: %{public}" PRIu64 "", displayId); + if (context_ == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Context is invalid"); + return; + } + + auto contextConfig = context_->GetConfiguration(); + if (contextConfig == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Configuration is invalid"); + return; + } + + TAG_LOGI(AAFwkTag::UI_EXT, "Config dump: %{public}s", contextConfig->GetName().c_str()); + auto configUtils = std::make_shared(); + auto result = configUtils->UpdateDisplayConfig( + contextConfig, context_->GetResourceManager(), displayId, density, orientation); + TAG_LOGI(AAFwkTag::UI_EXT, "Config dump after update: %{public}s", contextConfig->GetName().c_str()); + if (result) { + auto jsUiExtension = std::static_pointer_cast(shared_from_this()); + auto task = [jsUiExtension]() { + if (jsUiExtension) { + jsUiExtension->ConfigurationUpdated(); + } + }; + if (handler_ != nullptr) { + handler_->PostTask(task, "JsUIExtensionBase:OnChange"); + } + } +} + +void JsUIExtensionBase::RegisterDisplayInfoChangedListener() +{ + // register displayid change callback + auto jsUiExtensionBase = std::static_pointer_cast(shared_from_this()); + jsUIExtensionBaseDisplayListener_ = sptr::MakeSptr(jsUiExtensionBase); + if (jsUIExtensionBaseDisplayListener_ == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "JsUIExtensionBaseDisplayListener is nullptr"); + return; + } + if (context_ == nullptr || context_->GetToken() == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Param is invalid"); + return; + } + TAG_LOGI(AAFwkTag::UI_EXT, "RegisterDisplayInfoChangedListener"); + Rosen::WindowManager::GetInstance().RegisterDisplayInfoChangedListener( + context_->GetToken(), jsUIExtensionBaseDisplayListener_); +} + +void JsUIExtensionBase::UnregisterDisplayInfoChangedListener() +{ + if (context_ == nullptr || context_->GetToken() == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Param is invalid"); + return; + } + Rosen::WindowManager::GetInstance().UnregisterDisplayInfoChangedListener( + context_->GetToken(), jsUIExtensionBaseDisplayListener_); +} +#endif // SUPPORT_GRAPHICS } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/kits/native/ability/native/configuration_utils.h b/interfaces/kits/native/ability/native/configuration_utils.h index e7fe180655..ccbabb9e8d 100644 --- a/interfaces/kits/native/ability/native/configuration_utils.h +++ b/interfaces/kits/native/ability/native/configuration_utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 @@ -67,6 +67,33 @@ public: void UpdateDisplayConfig(Rosen::DisplayId displayId, std::shared_ptr configuration, std::shared_ptr resourceManager, bool &configChanged); + /** + * @brief Init display configuration to resource manager. + * + * @param configuration Context configuration need to update display config + * @param resourceManager Resource manager instance need to update display config + * @param displayId display Id + * @param density display density + * @param orientation display orientation + */ + void InitDisplayConfig(std::shared_ptr configuration, + std::shared_ptr resourceManager, Rosen::DisplayId displayId, float density, + int32_t orientation); + + /** + * @brief Update display configuration to context configuration and resource manager. + * + * @param configuration Context configuration need to update display config + * @param resourceManager Resource manager instance need to update display config + * @param displayId display Id + * @param density display density + * @param orientation display orientation + * @return Returns true on update success, false on update failure. + */ + bool UpdateDisplayConfig(std::shared_ptr configuration, + std::shared_ptr resourceManager, Rosen::DisplayId displayId, float density, + Rosen::DisplayOrientation orientation); + private: bool GetDisplayConfig(Rosen::DisplayId displayId, float &density, std::string &directionStr); void UpdateDisplayResConfig(std::shared_ptr resourceManager, float &density, diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension.h b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension.h index e21d8ac2ac..f0c2454e84 100755 --- a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension.h +++ b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 @@ -16,9 +16,11 @@ #ifndef OHOS_ABILITY_RUNTIME_JS_UI_EXTENSION_H #define OHOS_ABILITY_RUNTIME_JS_UI_EXTENSION_H +#include "ability_handler.h" #include "configuration.h" #ifdef SUPPORT_GRAPHICS #include "display_manager.h" +#include "window_manager.h" #endif // SUPPORT_GRAPHICS #include "js_ui_extension_content_session.h" #include "ui_extension.h" @@ -67,8 +69,9 @@ public: * This function can be called only once in the entire lifecycle of an ui extension. * * @param Want Indicates the {@link Want} structure containing startup information about the ui extension. + * @param sessionInfo The session info of the ability. */ - virtual void OnStart(const AAFwk::Want &want) override; + virtual void OnStart(const AAFwk::Want &want, sptr sessionInfo) override; /** * @brief Called when this ui extension is connected for the first time. @@ -165,6 +168,11 @@ public: */ void OnAbilityResult(int requestCode, int resultCode, const Want &resultData) override; + /** + * @brief Called when configuration changed, including system configuration and window configuration. + */ + void ConfigurationUpdated(); + private: virtual void BindContext(napi_env env, napi_value obj, std::shared_ptr want); void CreateJSContext(napi_env env, napi_value &contextObj, @@ -207,6 +215,36 @@ private: int32_t screenMode_ = AAFwk::IDLE_SCREEN_MODE; std::shared_ptr screenModePtr_; sptr token_ = nullptr; + std::shared_ptr handler_ = nullptr; + +#ifdef SUPPORT_GRAPHICS + class JsUIExtensionAbilityDisplayListener : public OHOS::Rosen::IDisplayInfoChangedListener { + public: + explicit JsUIExtensionAbilityDisplayListener(const std::weak_ptr &jsUiExtension) + { + jsUiExtension_ = jsUiExtension; + } + + void OnDisplayInfoChange(const sptr &token, Rosen::DisplayId displayId, float density, + Rosen::DisplayOrientation orientation) override + { + auto sptr = jsUiExtension_.lock(); + if (sptr != nullptr) { + sptr->OnDisplayInfoChange(token, displayId, density, orientation); + } + } + + private: + std::weak_ptr jsUiExtension_; + }; + + void RegisterDisplayInfoChangedListener(); + void UnregisterDisplayInfoChangedListener(); + void OnDisplayInfoChange(const sptr &token, Rosen::DisplayId displayId, float density, + Rosen::DisplayOrientation orientation); + + sptr jsUiExtensionAbilityDisplayListener_ = nullptr; +#endif }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_base.h b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_base.h index 053a52a5f3..2f6d85c78d 100644 --- a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_base.h +++ b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_base.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 @@ -29,6 +29,10 @@ #include "ui_extension_window_command.h" #include "want.h" #include "window.h" +#ifdef SUPPORT_GRAPHICS +#include "display_manager.h" +#include "window_manager.h" +#endif // SUPPORT_GRAPHICS class NativeReference; @@ -66,8 +70,10 @@ public: * * @param Want Indicates the {@link Want} structure containing startup information about the ui extension. * @param launchParam The launch param. + * @param sessionInfo The session info of the ability. */ - void OnStart(const AAFwk::Want &want, AAFwk::LaunchParam &launchParam) override; + void OnStart( + const AAFwk::Want &want, AAFwk::LaunchParam &launchParam, sptr sessionInfo) override; /** * @brief Called back when ui extension is started. @@ -152,6 +158,12 @@ public: void SetContext(const std::shared_ptr &context) override; void BindContext() override; + + /** + * @brief Called when configuration changed, including system configuration and window configuration. + */ + void ConfigurationUpdated(); + protected: napi_value CallObjectMethod(const char *name, napi_value const *argv = nullptr, size_t argc = 0); void ForegroundWindow(const AAFwk::Want &want, const sptr &sessionInfo); @@ -179,6 +191,37 @@ protected: std::shared_ptr abilityResultListeners_ = nullptr; std::shared_ptr abilityInfo_; sptr token_ = nullptr; + std::shared_ptr handler_ = nullptr; + +#ifdef SUPPORT_GRAPHICS +private: + class JsUIExtensionBaseDisplayListener : public OHOS::Rosen::IDisplayInfoChangedListener { + public: + explicit JsUIExtensionBaseDisplayListener(const std::weak_ptr &jsUiExtensionBase) + { + jsUiExtensionBase_ = jsUiExtensionBase; + } + + void OnDisplayInfoChange(const sptr &token, Rosen::DisplayId displayId, float density, + Rosen::DisplayOrientation orientation) override + { + auto sptr = jsUiExtensionBase_.lock(); + if (sptr != nullptr) { + sptr->OnDisplayInfoChange(token, displayId, density, orientation); + } + } + + private: + std::weak_ptr jsUiExtensionBase_; + }; + + void RegisterDisplayInfoChangedListener(); + void UnregisterDisplayInfoChangedListener(); + void OnDisplayInfoChange(const sptr &token, Rosen::DisplayId displayId, float density, + Rosen::DisplayOrientation orientation); + + sptr jsUIExtensionBaseDisplayListener_ = nullptr; +#endif }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_base.h b/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_base.h index 38e29291c4..701403356f 100644 --- a/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_base.h +++ b/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_base.h @@ -52,12 +52,12 @@ public: } } - void OnStart(const AAFwk::Want &want) override + void OnStart(const AAFwk::Want &want, sptr sessionInfo) override { Extension::OnStart(want); if (impl_ != nullptr) { auto launchParam = Extension::GetLaunchParam(); - impl_->OnStart(want, launchParam); + impl_->OnStart(want, launchParam, sessionInfo); } } diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_base_impl.h b/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_base_impl.h index 15d606939b..7373f34ba0 100644 --- a/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_base_impl.h +++ b/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_base_impl.h @@ -35,7 +35,8 @@ public: std::shared_ptr &handler, const sptr &token) = 0; - virtual void OnStart(const AAFwk::Want &want, AAFwk::LaunchParam &launchParam) = 0; + virtual void OnStart( + const AAFwk::Want &want, AAFwk::LaunchParam &launchParam, sptr sessionInfo) = 0; virtual void OnCommand(const AAFwk::Want &want, bool restart, int startId) = 0; From 109182457ca88b80336eb721d2afda1935c11676 Mon Sep 17 00:00:00 2001 From: savior-xzh Date: Thu, 22 Aug 2024 19:34:19 +0800 Subject: [PATCH 14/42] delete Signed-off-by: savior-xzh Change-Id: I004ac507ccba5ca52f45fe7e74fdb54efdcd20cd --- .../native/ability/native/ability_thread.cpp | 21 ----- .../include/ability_manager_client.h | 24 ----- .../include/ability_manager_interface.h | 24 ----- .../ability_manager_ipc_interface_code.h | 6 -- .../include/ability_scheduler_interface.h | 7 -- .../include/appmgr/app_mgr_client.h | 9 -- .../include/appmgr/app_mgr_interface.h | 8 -- .../appmgr/app_mgr_ipc_interface_code.h | 1 - .../include/appmgr/app_mgr_proxy.h | 9 -- .../app_manager/include/appmgr/app_mgr_stub.h | 3 - .../app_manager/src/appmgr/app_mgr_client.cpp | 13 --- .../app_manager/src/appmgr/app_mgr_proxy.cpp | 20 ---- .../app_manager/src/appmgr/app_mgr_stub.cpp | 14 --- .../native/ability/native/ability_thread.h | 7 -- .../include/ability_manager_proxy.h | 24 ----- .../include/ability_manager_service.h | 20 ---- .../abilitymgr/include/ability_manager_stub.h | 5 - services/abilitymgr/include/ability_record.h | 3 - .../include/ability_scheduler_proxy.h | 4 - .../include/ability_scheduler_stub.h | 4 - services/abilitymgr/include/app_scheduler.h | 9 -- services/abilitymgr/include/mission_list.h | 3 - .../abilitymgr/include/mission_list_manager.h | 10 -- .../include/mission_list_manager_interface.h | 4 - .../ui_ability_lifecycle_manager.h | 10 -- .../abilitymgr/src/ability_manager_client.cpp | 26 ----- .../abilitymgr/src/ability_manager_proxy.cpp | 56 ----------- .../src/ability_manager_service.cpp | 53 ----------- .../abilitymgr/src/ability_manager_stub.cpp | 42 --------- services/abilitymgr/src/ability_record.cpp | 12 --- .../src/ability_scheduler_proxy.cpp | 25 ----- .../abilitymgr/src/ability_scheduler_stub.cpp | 18 ---- services/abilitymgr/src/app_scheduler.cpp | 14 --- services/abilitymgr/src/mission_list.cpp | 19 ---- .../abilitymgr/src/mission_list_manager.cpp | 41 -------- .../ui_ability_lifecycle_manager.cpp | 21 ----- services/appmgr/include/app_mgr_service.h | 9 -- services/appmgr/src/app_mgr_service.cpp | 21 ----- test/fuzztest/BUILD.gn | 3 - .../abilityeventhandler_fuzzer.cpp | 3 - .../abilityschedulerstub_fuzzer.cpp | 4 - .../appmgrclientrest_fuzzer.cpp | 3 - .../appmgrservicefirst_fuzzer.cpp | 3 - .../attachabilitythread_fuzzer.cpp | 6 -- test/fuzztest/blockability_fuzzer/BUILD.gn | 80 ---------------- .../blockability_fuzzer.cpp | 86 ----------------- .../blockability_fuzzer/blockability_fuzzer.h | 21 ----- test/fuzztest/blockability_fuzzer/corpus/init | 16 ---- test/fuzztest/blockability_fuzzer/project.xml | 25 ----- test/fuzztest/blockamsservice_fuzzer/BUILD.gn | 82 ---------------- .../blockamsservice_fuzzer.cpp | 80 ---------------- .../blockamsservice_fuzzer.h | 21 ----- .../blockamsservice_fuzzer/corpus/init | 16 ---- .../blockamsservice_fuzzer/project.xml | 25 ----- test/fuzztest/blockappservice_fuzzer/BUILD.gn | 81 ---------------- .../blockappservice_fuzzer.cpp | 81 ---------------- .../blockappservice_fuzzer.h | 21 ----- .../blockappservice_fuzzer/corpus/init | 16 ---- .../blockappservice_fuzzer/project.xml | 25 ----- .../missionlistmanagersecond_fuzzer.cpp | 3 - .../uiabilitylifecyclemanagerb_fuzzer.cpp | 4 - .../AMS/mock_serviceability_manager_service.h | 5 - .../include/mock_ability_manager_client.h | 6 -- .../include/mock_ability_manager_service.h | 5 - .../mock_ability_scheduler_for_observer.h | 6 -- .../mock_ability_delegator_stub.cpp | 30 ------ .../mock_ability_delegator_stub.h | 6 -- .../include/mock_app_mgr_service.h | 3 - .../AMS/mock_ability_manager_service.h | 5 - .../AMS/mock_serviceability_manager_service.h | 6 -- .../libs/aakit/include/ability_scheduler.h | 6 -- .../ability_scheduler_mock.h | 7 -- .../include/mock_app_mgr_service.h | 3 - .../mock/include/mock_ability_mgr_service.h | 5 - .../mock/include/mock_ability_scheduler.h | 6 -- .../include/mock_ability_scheduler_stub.h | 7 -- .../ability_manager_stub_mock_second_test.h | 5 - .../ability_manager_client_branch_test.cpp | 55 ----------- .../ability_manager_stub_mock_test.h | 5 - .../ability_manager_proxy_test.cpp | 61 ------------ .../ability_manager_stub_mock.h | 6 -- .../ability_manager_service_third_test.cpp | 56 ----------- .../ability_manager_stub_impl_mock.h | 5 - .../ability_manager_stub_test.cpp | 54 ----------- .../ability_manager_stub_mock.h | 5 - .../ability_scheduler_proxy_test.cpp | 19 ---- .../ability_schedule_stub_mock.h | 6 -- .../app_mgr_client_test.cpp | 19 ---- .../app_mgr_service_test.cpp | 36 ------- .../app_scheduler_test/app_mgr_client_mock.h | 1 - .../app_scheduler_test/app_scheduler_test.cpp | 44 --------- .../main_thread_test/main_thread_test.cpp | 7 -- .../mission_list_manager_test.cpp | 94 ------------------- .../mission_list_test/mission_list_test.cpp | 31 ------ .../ability_manager_stub_mock.h | 6 -- .../mock_ability_manager_service.h | 5 - tools/aa/include/ability_command.h | 13 --- tools/aa/src/ability_command.cpp | 56 ----------- tools/test/mock/mock_ability_manager_stub.h | 15 --- 99 files changed, 2034 deletions(-) delete mode 100755 test/fuzztest/blockability_fuzzer/BUILD.gn delete mode 100755 test/fuzztest/blockability_fuzzer/blockability_fuzzer.cpp delete mode 100755 test/fuzztest/blockability_fuzzer/blockability_fuzzer.h delete mode 100755 test/fuzztest/blockability_fuzzer/corpus/init delete mode 100755 test/fuzztest/blockability_fuzzer/project.xml delete mode 100755 test/fuzztest/blockamsservice_fuzzer/BUILD.gn delete mode 100755 test/fuzztest/blockamsservice_fuzzer/blockamsservice_fuzzer.cpp delete mode 100755 test/fuzztest/blockamsservice_fuzzer/blockamsservice_fuzzer.h delete mode 100755 test/fuzztest/blockamsservice_fuzzer/corpus/init delete mode 100755 test/fuzztest/blockamsservice_fuzzer/project.xml delete mode 100755 test/fuzztest/blockappservice_fuzzer/BUILD.gn delete mode 100755 test/fuzztest/blockappservice_fuzzer/blockappservice_fuzzer.cpp delete mode 100755 test/fuzztest/blockappservice_fuzzer/blockappservice_fuzzer.h delete mode 100755 test/fuzztest/blockappservice_fuzzer/corpus/init delete mode 100755 test/fuzztest/blockappservice_fuzzer/project.xml diff --git a/frameworks/native/ability/native/ability_thread.cpp b/frameworks/native/ability/native/ability_thread.cpp index 3a2391f2b1..7d4d8fc374 100644 --- a/frameworks/native/ability/native/ability_thread.cpp +++ b/frameworks/native/ability/native/ability_thread.cpp @@ -23,9 +23,6 @@ namespace OHOS { namespace AppExecFwk { -#ifdef ABILITY_COMMAND_FOR_TEST -const int32_t BLOCK_ABILITY_TIME = 20; -#endif void AbilityThread::AbilityThreadMain(const std::shared_ptr &application, const std::shared_ptr &abilityRecord, const std::shared_ptr &mainRunner, const std::shared_ptr &stageContext) @@ -287,23 +284,5 @@ void AbilityThread::UpdateSessionToken(sptr sessionToken) { TAG_LOGD(AAFwkTag::ABILITY, "called"); } - -#ifdef ABILITY_COMMAND_FOR_TEST -int AbilityThread::BlockAbility() -{ - TAG_LOGD(AAFwkTag::ABILITY, "begin"); - if (abilityHandler_) { - auto task = []() { - while (1) { - std::this_thread::sleep_for(BLOCK_ABILITY_TIME * 1s); - } - }; - abilityHandler_->PostTask(task, "AbilityThread:BlockAbility"); - TAG_LOGD(AAFwkTag::ABILITY, "end"); - return ERR_OK; - } - return ERR_NO_INIT; -} -#endif } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_client.h b/interfaces/inner_api/ability_manager/include/ability_manager_client.h index 9a6852ae35..7a447f1d9e 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -1142,30 +1142,6 @@ public: virtual int SetAbilityController(sptr abilityController, bool imAStabilityTest); - #ifdef ABILITY_COMMAND_FOR_TEST - /** - * Block ability manager service. - * - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode BlockAmsService(); - - /** - * Block ability. - * - * @param abilityRecordId The Ability Record Id. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode BlockAbility(int32_t abilityRecordId); - - /** - * Block app service. - * - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode BlockAppService(); - #endif - /** * Free install ability from remote DMS. * diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index 63a5bc0aab..928dcce2d4 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -1142,30 +1142,6 @@ public: */ virtual void GetAbilityTokenByCalleeObj(const sptr &callStub, sptr &token) = 0; - #ifdef ABILITY_COMMAND_FOR_TEST - /** - * Block ability manager service. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int BlockAmsService() = 0; - - /** - * Block ability. - * - * @param abilityRecordId The Ability Record Id. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int BlockAbility(int32_t abilityRecordId) = 0; - - /** - * Block app service. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int BlockAppService() = 0; - #endif - /** * Called when client complete dump. * diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h index aba7453ad8..1a96035949 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h @@ -310,12 +310,6 @@ enum class AbilityManagerInterfaceCode { START_ABILITY_FOR_OPTIONS = 1028, - BLOCK_AMS_SERVICE = 1029, - - BLOCK_ABILITY = 1030, - - BLOCK_APP_SERVICE = 1031, - // ipc id for call ability START_CALL_ABILITY = 1032, diff --git a/interfaces/inner_api/ability_manager/include/ability_scheduler_interface.h b/interfaces/inner_api/ability_manager/include/ability_scheduler_interface.h index ed122a4061..f3e0df40b5 100644 --- a/interfaces/inner_api/ability_manager/include/ability_scheduler_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_scheduler_interface.h @@ -296,10 +296,6 @@ public: virtual void OnExecuteIntent(const Want &want) = 0; - #ifdef ABILITY_COMMAND_FOR_TEST - virtual int BlockAbility() = 0; - #endif - virtual void CallRequest() = 0; /** @@ -392,9 +388,6 @@ public: // ipc id for dump ability runner DUMP_ABILITY_RUNNER_INNER, - // block ability runner - BLOCK_ABILITY_INNER, - SCHEDULE_CALL, SCHEDULE_SHARE_DATA, diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h index e9d7879d0a..7fd7112aae 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h @@ -378,15 +378,6 @@ public: */ virtual AppMgrResultCode UnregisterConfigurationObserver(const sptr &observer); - #ifdef ABILITY_COMMAND_FOR_TEST - /** - * Block app service. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int BlockAppService(); - #endif - /** * Start a user test */ diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index 3f0a18d704..d19b653132 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -324,14 +324,6 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens) = 0; - #ifdef ABILITY_COMMAND_FOR_TEST - /** - * Block app service. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int BlockAppService() = 0; - #endif /** * Prestart nwebspawn process. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h index b2e5a4762c..db8629673f 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h @@ -38,7 +38,6 @@ enum class AppMgrInterfaceCode { START_USER_TEST_PROCESS = 15, FINISH_USER_TEST = 16, SCHEDULE_ACCEPT_WANT_DONE = 17, - BLOCK_APP_SERVICE = 18, APP_GET_ABILITY_RECORDS_BY_PROCESS_ID = 19, START_RENDER_PROCESS = 20, ATTACH_RENDER_PROCESS = 21, diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h index 11a3a6f5fb..59708f56bc 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h @@ -366,15 +366,6 @@ public: */ virtual bool SetAppFreezeFilter(int32_t pid) override; - #ifdef ABILITY_COMMAND_FOR_TEST - /** - * Block app service. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int BlockAppService() override; - #endif - virtual int32_t GetConfiguration(Configuration& config) override; virtual int32_t UpdateConfiguration(const Configuration &config) override; diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h index 47ea448b15..8cdf532f58 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h @@ -105,9 +105,6 @@ private: int32_t HandleDumpJsHeapMemory(MessageParcel &data, MessageParcel &reply); int32_t HandleGetRunningMultiAppInfoByBundleName(MessageParcel &data, MessageParcel &reply); int32_t HandleIsAppRunning(MessageParcel &data, MessageParcel &reply); -#ifdef ABILITY_COMMAND_FOR_TEST - int32_t HandleBlockAppServiceDone(MessageParcel &data, MessageParcel &reply); -#endif int32_t HandleGetAppRunningStateByBundleName(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyLoadRepairPatch(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyHotReloadPage(MessageParcel &data, MessageParcel &reply); diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp index 632839f147..0062a6efd3 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp @@ -841,19 +841,6 @@ sptr AppMgrClient::GetRemoteObject() return mgrHolder_->GetRemoteObject(); } -#ifdef ABILITY_COMMAND_FOR_TEST -int AppMgrClient::BlockAppService() -{ - TAG_LOGI(AAFwkTag::APPMGR, "%{public}s", __func__); - sptr service = iface_cast(mgrHolder_->GetRemoteObject()); - if (service == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr"); - return AppMgrResultCode::ERROR_SERVICE_NOT_READY; - } - return service->BlockAppService(); -} -#endif - void AppMgrClient::SetCurrentUserId(const int32_t userId) { sptr service = iface_cast(mgrHolder_->GetRemoteObject()); 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 c18a7d64ec..6ecd450810 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 @@ -964,26 +964,6 @@ int32_t AppMgrProxy::UnregisterConfigurationObserver(const sptr(code)) { - #ifdef ABILITY_COMMAND_FOR_TEST - case AppMgrInterfaceCode::BLOCK_APP_SERVICE: - return HandleBlockAppServiceDone(data, reply); - #endif case static_cast(AppMgrInterfaceCode::GET_APP_RUNNING_STATE): return HandleGetAppRunningStateByBundleName(data, reply); case static_cast(AppMgrInterfaceCode::NOTIFY_LOAD_REPAIR_PATCH): @@ -934,16 +930,6 @@ int32_t AppMgrStub::HandleUnregisterConfigurationObserver(MessageParcel &data, M return NO_ERROR; } -#ifdef ABILITY_COMMAND_FOR_TEST -int32_t AppMgrStub::HandleBlockAppServiceDone(MessageParcel &data, MessageParcel &reply) -{ - TAG_LOGI(AAFwkTag::APPMGR, "%{public}s", __func__); - int32_t result = BlockAppService(); - reply.WriteInt32(result); - return result; -} -#endif - int32_t AppMgrStub::HandleGetAppRunningStateByBundleName(MessageParcel &data, MessageParcel &reply) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); diff --git a/interfaces/kits/native/ability/native/ability_thread.h b/interfaces/kits/native/ability/native/ability_thread.h index d9167be4b7..b1c5f293be 100644 --- a/interfaces/kits/native/ability/native/ability_thread.h +++ b/interfaces/kits/native/ability/native/ability_thread.h @@ -356,13 +356,6 @@ public: */ void UpdateSessionToken(sptr sessionToken) override; -#ifdef ABILITY_COMMAND_FOR_TEST - /** - * @brief Block ability. - * @return Returns ERR_OK on success, others on failure. - */ - int BlockAbility() override; -#endif sptr token_; std::shared_ptr abilityHandler_ = nullptr; std::shared_ptr runner_ = nullptr; diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index b13bf18e91..1565c73f2a 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -878,30 +878,6 @@ public: */ void GetAbilityTokenByCalleeObj(const sptr &callStub, sptr &token) override; - #ifdef ABILITY_COMMAND_FOR_TEST - /** - * Block ability manager service. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int BlockAmsService() override; - - /** - * Block ability. - * - * @param abilityRecordId The Ability Record Id. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int BlockAbility(int32_t abilityRecordId) override; - - /** - * Block app service. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int BlockAppService() override; - #endif - /** * Call free install from remote. * diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 7943c842c6..3cd775f896 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1288,26 +1288,6 @@ public: bool IsAbilityControllerStartById(int32_t missionId); #ifdef ABILITY_COMMAND_FOR_TEST - /** - * Block ability manager service. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int BlockAmsService() override; - - /** - * Block ability. - * - * @param abilityRecordId The Ability Record Id. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int BlockAbility(int32_t abilityRecordId) override; - - /** - * Block app manager service. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int BlockAppService() override; - /** * force timeout ability. * diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index 0f40c5e63a..a295d5967b 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -220,11 +220,6 @@ private: int FreeInstallAbilityFromRemoteInner(MessageParcel &data, MessageParcel &reply); int AddFreeInstallObserverInner(MessageParcel &data, MessageParcel &reply); - #ifdef ABILITY_COMMAND_FOR_TEST - int BlockAmsServiceInner(MessageParcel &data, MessageParcel &reply); - int BlockAbilityInner(MessageParcel &data, MessageParcel &reply); - int BlockAppServiceInner(MessageParcel &data, MessageParcel &reply); - #endif int EnableRecoverAbilityInner(MessageParcel &data, MessageParcel &reply); int SubmitSaveRecoveryInfoInner(MessageParcel &data, MessageParcel &reply); int ScheduleRecoverAbilityInner(MessageParcel &data, MessageParcel &reply); diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index 0bc55a7796..8a984c1ed3 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -1002,9 +1002,6 @@ public: void SetWindowMode(int32_t windowMode); void RemoveWindowMode(); LifeCycleStateInfo lifeCycleStateInfo_; // target life state info - #ifdef ABILITY_COMMAND_FOR_TEST - int BlockAbility(); - #endif bool CanRestartRootLauncher(); diff --git a/services/abilitymgr/include/ability_scheduler_proxy.h b/services/abilitymgr/include/ability_scheduler_proxy.h index cdd8571026..7ab622d31b 100644 --- a/services/abilitymgr/include/ability_scheduler_proxy.h +++ b/services/abilitymgr/include/ability_scheduler_proxy.h @@ -331,10 +331,6 @@ public: */ void UpdateSessionToken(sptr sessionToken) override; - #ifdef ABILITY_COMMAND_FOR_TEST - int BlockAbility() override; - #endif - private: bool WriteInterfaceToken(MessageParcel &data); int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); diff --git a/services/abilitymgr/include/ability_scheduler_stub.h b/services/abilitymgr/include/ability_scheduler_stub.h index 50e26ca37b..32ea2ff922 100644 --- a/services/abilitymgr/include/ability_scheduler_stub.h +++ b/services/abilitymgr/include/ability_scheduler_stub.h @@ -67,10 +67,6 @@ private: int DumpAbilityInfoInner(MessageParcel& data, MessageParcel& reply); int CallRequestInner(MessageParcel &data, MessageParcel &reply); int OnExecuteIntentInner(MessageParcel &data, MessageParcel &reply); - #ifdef ABILITY_COMMAND_FOR_TEST - int BlockAbilityInner(MessageParcel &data, MessageParcel &reply); - #endif - int ContinueAbilityInner(MessageParcel &data, MessageParcel &reply); int ShareDataInner(MessageParcel &data, MessageParcel &reply); int CreateModalUIExtensionInner(MessageParcel &data, MessageParcel &reply); diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 8a5ebf96ca..7f204b0275 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -364,15 +364,6 @@ public: */ void SetCurrentUserId(int32_t userId); - #ifdef ABILITY_COMMAND_FOR_TEST - /** - * Block app service. - * - * @return Returns ERR_OK on success, others on failure. - */ - int BlockAppService(); - #endif - /** * Get bundleName by pid. * diff --git a/services/abilitymgr/include/mission_list.h b/services/abilitymgr/include/mission_list.h index f38731267b..a47ad8a3c3 100644 --- a/services/abilitymgr/include/mission_list.h +++ b/services/abilitymgr/include/mission_list.h @@ -216,9 +216,6 @@ public: std::vector &info, bool isClient, int32_t abilityRecordId, const std::vector ¶ms); std::shared_ptr GetMissionBySpecifiedFlag(const AAFwk::Want &want, const std::string &flag) const; - #ifdef ABILITY_COMMAND_FOR_TEST - int BlockAbilityByRecordId(int32_t abilityRecordId); - #endif int32_t GetMissionCountByUid(int32_t targetUid) const; void FindEarliestMission(std::shared_ptr& targetMission) const; diff --git a/services/abilitymgr/include/mission_list_manager.h b/services/abilitymgr/include/mission_list_manager.h index d9c3e13dc6..2650768a3b 100644 --- a/services/abilitymgr/include/mission_list_manager.h +++ b/services/abilitymgr/include/mission_list_manager.h @@ -342,16 +342,6 @@ public: void EnableRecoverAbility(int32_t missionId) override; -#ifdef ABILITY_COMMAND_FOR_TEST - /** - * Block ability. - * - * @param abilityRecordId The Ability Record Id. - * @return Returns ERR_OK on success, others on failure. - */ - int BlockAbility(int abilityRecordId) override; -#endif - void UninstallApp(const std::string &bundleName, int32_t uid) override; bool IsStarted() override; diff --git a/services/abilitymgr/include/mission_list_manager_interface.h b/services/abilitymgr/include/mission_list_manager_interface.h index 2661a5ba78..3dde2482e5 100644 --- a/services/abilitymgr/include/mission_list_manager_interface.h +++ b/services/abilitymgr/include/mission_list_manager_interface.h @@ -98,10 +98,6 @@ public: virtual void EnableRecoverAbility(int32_t missionId) = 0; -#ifdef ABILITY_COMMAND_FOR_TEST - virtual int BlockAbility(int abilityRecordId) = 0; -#endif - virtual void UninstallApp(const std::string &bundleName, int32_t uid) = 0; virtual bool IsStarted() = 0; 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 1c6198d25f..50a276cd06 100644 --- a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h +++ b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h @@ -310,16 +310,6 @@ public: void GetAbilityRunningInfos(std::vector &info, bool isPerm) const; - #ifdef ABILITY_COMMAND_FOR_TEST - /** - * Block ability. - * - * @param abilityRecordId The Ability Record Id. - * @return Returns ERR_OK on success, others on failure. - */ - int BlockAbility(int abilityRecordId) const; - #endif - /** * @brief dump all abilities * diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 97905ed9a8..58159f2c75 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -1426,32 +1426,6 @@ void AbilityManagerClient::ScheduleClearRecoveryPageStack() return abms->ScheduleClearRecoveryPageStack(); } -#ifdef ABILITY_COMMAND_FOR_TEST -ErrCode AbilityManagerClient::BlockAmsService() -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "enter"); - auto abms = GetAbilityManager(); - CHECK_POINTER_RETURN_NOT_CONNECTED(abms); - return abms->BlockAmsService(); -} - -ErrCode AbilityManagerClient::BlockAbility(int32_t abilityRecordId) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "enter"); - auto abms = GetAbilityManager(); - CHECK_POINTER_RETURN_NOT_CONNECTED(abms); - return abms->BlockAbility(abilityRecordId); -} - -ErrCode AbilityManagerClient::BlockAppService() -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "enter"); - auto abms = GetAbilityManager(); - CHECK_POINTER_RETURN_NOT_CONNECTED(abms); - return abms->BlockAppService(); -} -#endif - sptr AbilityManagerClient::GetAbilityManager() { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 4321e70c03..3355d70f61 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -3913,62 +3913,6 @@ int32_t AbilityManagerProxy::GetMissionIdByToken(const sptr &toke return reply.ReadInt32(); } -#ifdef ABILITY_COMMAND_FOR_TEST -int AbilityManagerProxy::BlockAmsService() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return INNER_ERR; - } - - auto error = SendRequest(AbilityManagerInterfaceCode::BLOCK_AMS_SERVICE, data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "BlockAmsService error: %d", error); - return error; - } - return reply.ReadInt32(); -} - -int AbilityManagerProxy::BlockAbility(int32_t abilityRecordId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return INNER_ERR; - } - if (!data.WriteInt32(abilityRecordId)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "pid WriteInt32 fail."); - return ERR_INVALID_VALUE; - } - - auto error = SendRequest(AbilityManagerInterfaceCode::BLOCK_ABILITY, data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "BlockAbility error: %d", error); - return error; - } - return reply.ReadInt32(); -} - -int AbilityManagerProxy::BlockAppService() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return INNER_ERR; - } - - auto error = SendRequest(AbilityManagerInterfaceCode::BLOCK_APP_SERVICE, data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "BlockAmsService error: %d", error); - return error; - } - return reply.ReadInt32(); -} -#endif int AbilityManagerProxy::FreeInstallAbilityFromRemote(const Want &want, const sptr &callback, int32_t userId, int requestCode) { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 14b8e95c5d..a6f3befc74 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -204,9 +204,6 @@ constexpr int32_t NON_ANONYMIZE_LENGTH = 6; constexpr uint32_t SCENE_FLAG_NORMAL = 0; constexpr int32_t MAX_NUMBER_OF_DISTRIBUTED_MISSIONS = 20; constexpr int32_t SWITCH_ACCOUNT_TRY = 3; -#ifdef ABILITY_COMMAND_FOR_TEST -constexpr int32_t BLOCK_AMS_SERVICE_TIME = 65; -#endif constexpr int32_t CONVERT_CALLBACK_TIMEOUT_SECONDS = 2; // 2s constexpr const char* EMPTY_DEVICE_ID = ""; constexpr int32_t APP_MEMORY_SIZE = 512; @@ -8599,56 +8596,6 @@ int AbilityManagerService::VerifyAccountPermission(int32_t userId) return AAFwk::PermissionVerification::GetInstance()->VerifyAccountPermission(); } -#ifdef ABILITY_COMMAND_FOR_TEST -int AbilityManagerService::BlockAmsService() -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "%{public}s", __func__); - if (AAFwk::PermissionVerification::GetInstance()->IsShellCall()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Not shell call"); - return ERR_PERMISSION_DENIED; - } - if (taskHandler_) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "%{public}s begin post block ability manager service task", __func__); - auto BlockAmsServiceTask = [aams = shared_from_this()]() { - while (1) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "%{public}s begin waiting", __func__); - std::this_thread::sleep_for(BLOCK_AMS_SERVICE_TIME*1s); - } - }; - taskHandler_->SubmitTask(BlockAmsServiceTask, "blockamsservice"); - return ERR_OK; - } - return ERR_NO_INIT; -} - -int AbilityManagerService::BlockAbility(int32_t abilityRecordId) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "%{public}s", __func__); - if (AAFwk::PermissionVerification::GetInstance()->IsShellCall()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Not shell call"); - return ERR_PERMISSION_DENIED; - } - if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto uiAbilityManager = GetCurrentUIAbilityManager(); - CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE); - return uiAbilityManager->BlockAbility(abilityRecordId); - } - auto missionListManager = GetCurrentMissionListManager(); - CHECK_POINTER_AND_RETURN(missionListManager, ERR_NO_INIT); - return missionListManager->BlockAbility(abilityRecordId); -} - -int AbilityManagerService::BlockAppService() -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "%{public}s", __func__); - if (AAFwk::PermissionVerification::GetInstance()->IsShellCall()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Not shell call"); - return ERR_PERMISSION_DENIED; - } - return DelayedSingleton::GetInstance()->BlockAppService(); -} -#endif - int AbilityManagerService::FreeInstallAbilityFromRemote(const Want &want, const sptr &callback, int32_t userId, int requestCode) { diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index d1f6d2c7b3..269e0c12f3 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -442,17 +442,6 @@ int AbilityManagerStub::OnRemoteRequestInnerEleventh(uint32_t code, MessageParce if (interfaceCode == AbilityManagerInterfaceCode::REGISTER_SESSION_HANDLER) { return RegisterSessionHandlerInner(data, reply); } -#ifdef ABILITY_COMMAND_FOR_TEST - if (interfaceCode == AbilityManagerInterfaceCode::BLOCK_ABILITY) { - return BlockAbilityInner(data, reply); - } - if (interfaceCode == AbilityManagerInterfaceCode::BLOCK_AMS_SERVICE) { - return BlockAmsServiceInner(data, reply); - } - if (interfaceCode == AbilityManagerInterfaceCode::BLOCK_APP_SERVICE) { - return BlockAppServiceInner(data, reply); - } -#endif return ERR_CODE_NOT_EXIST; } @@ -2688,37 +2677,6 @@ int AbilityManagerStub::ForceTimeoutForTestInner(MessageParcel &data, MessagePar } return NO_ERROR; } - -int AbilityManagerStub::BlockAbilityInner(MessageParcel &data, MessageParcel &reply) -{ - int32_t abilityRecordId = data.ReadInt32(); - int32_t result = BlockAbility(abilityRecordId); - if (!reply.WriteInt32(result)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "reply write failed."); - return ERR_INVALID_VALUE; - } - return NO_ERROR; -} - -int AbilityManagerStub::BlockAmsServiceInner(MessageParcel &data, MessageParcel &reply) -{ - int32_t result = BlockAmsService(); - if (!reply.WriteInt32(result)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "reply write failed."); - return ERR_INVALID_VALUE; - } - return NO_ERROR; -} - -int AbilityManagerStub::BlockAppServiceInner(MessageParcel &data, MessageParcel &reply) -{ - int32_t result = BlockAppService(); - if (!reply.WriteInt32(result)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "reply write failed."); - return ERR_INVALID_VALUE; - } - return NO_ERROR; -} #endif int AbilityManagerStub::FreeInstallAbilityFromRemoteInner(MessageParcel &data, MessageParcel &reply) diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 508023aba8..8dcf9b7d22 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -3462,18 +3462,6 @@ AbilityState AbilityRecord::GetPendingState() const return pendingState_.load(); } -#ifdef ABILITY_COMMAND_FOR_TEST -int AbilityRecord::BlockAbility() -{ - TAG_LOGI(AAFwkTag::ABILITYMGR, "BlockAbility."); - if (scheduler_) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "scheduler_ begin to call BlockAbility %{public}s", __func__); - return scheduler_->BlockAbility(); - } - return ERR_NO_INIT; -} -#endif - bool AbilityRecord::IsNeedBackToOtherMissionStack() { return isNeedBackToOtherMissionStack_; diff --git a/services/abilitymgr/src/ability_scheduler_proxy.cpp b/services/abilitymgr/src/ability_scheduler_proxy.cpp index 5f785dee07..2c1434a4b5 100644 --- a/services/abilitymgr/src/ability_scheduler_proxy.cpp +++ b/services/abilitymgr/src/ability_scheduler_proxy.cpp @@ -1170,31 +1170,6 @@ void AbilitySchedulerProxy::UpdateSessionToken(sptr sessionToken) } } -#ifdef ABILITY_COMMAND_FOR_TEST -int AbilitySchedulerProxy::BlockAbility() -{ - TAG_LOGI(AAFwkTag::ABILITYMGR, "AbilitySchedulerProxy::BlockAbility start"); - int ret = -1; - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!WriteInterfaceToken(data)) { - return ret; - } - int32_t err = SendTransactCmd(IAbilityScheduler::BLOCK_ABILITY_INNER, data, reply, option); - if (err != NO_ERROR) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "BlockAbility fail to SendRequest. err: %d", err); - return ret; - } - if (!reply.ReadInt32(ret)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadInt32 ret"); - return ret; - } - return ret; -} -#endif - int32_t AbilitySchedulerProxy::SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { diff --git a/services/abilitymgr/src/ability_scheduler_stub.cpp b/services/abilitymgr/src/ability_scheduler_stub.cpp index e60fb03d5d..7c6bd208cf 100644 --- a/services/abilitymgr/src/ability_scheduler_stub.cpp +++ b/services/abilitymgr/src/ability_scheduler_stub.cpp @@ -154,10 +154,6 @@ int AbilitySchedulerStub::OnRemoteRequestInnerThird( return CreateModalUIExtensionInner(data, reply); case UPDATE_SESSION_TOKEN: return UpdateSessionTokenInner(data, reply); -#ifdef ABILITY_COMMAND_FOR_TEST - case BLOCK_ABILITY_INNER: - return BlockAbilityInner(data, reply); -#endif } return ERR_CODE_NOT_EXIST; } @@ -742,20 +738,6 @@ int AbilitySchedulerStub::UpdateSessionTokenInner(MessageParcel &data, MessagePa return NO_ERROR; } -#ifdef ABILITY_COMMAND_FOR_TEST -int AbilitySchedulerStub::BlockAbilityInner(MessageParcel &data, MessageParcel &reply) -{ - TAG_LOGI(AAFwkTag::ABILITYMGR, "AbilitySchedulerStub::BlockAbilityInner start"); - - auto result = BlockAbility(); - if (!reply.WriteInt32(result)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 result"); - return ERR_INVALID_VALUE; - } - return NO_ERROR; -} -#endif - void AbilitySchedulerRecipient::OnRemoteDied(const wptr &remote) { TAG_LOGE(AAFwkTag::ABILITYMGR, "call"); diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index 55121ed69b..aafeb501ee 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -484,20 +484,6 @@ int32_t AppScheduler::NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, return ERR_OK; } -#ifdef ABILITY_COMMAND_FOR_TEST -int AppScheduler::BlockAppService() -{ - TAG_LOGI(AAFwkTag::ABILITYMGR, "[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); - CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); - auto ret = static_cast(IN_PROCESS_CALL(appMgrClient_->BlockAppService())); - if (ret != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "BlockAppService failed."); - return INNER_ERR; - } - return ERR_OK; -} -#endif - int32_t AppScheduler::GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) { CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); diff --git a/services/abilitymgr/src/mission_list.cpp b/services/abilitymgr/src/mission_list.cpp index 87f0ac5460..aecd2d4e35 100644 --- a/services/abilitymgr/src/mission_list.cpp +++ b/services/abilitymgr/src/mission_list.cpp @@ -401,25 +401,6 @@ void MissionList::DumpList(std::vector &info, bool isClient) } } -#ifdef ABILITY_COMMAND_FOR_TEST -int MissionList::BlockAbilityByRecordId(int32_t abilityRecordId) -{ - int ret = -1; - for (const auto& mission : missions_) { - if (mission) { - auto abilityRecord = mission->GetAbilityRecord(); - if (abilityRecord) { - if (abilityRecord->GetRecordId() == abilityRecordId) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "record begin to call BlockAbilityByRecordId %{public}s", __func__); - return abilityRecord->BlockAbility(); - } - } - } - } - return ret; -} -#endif - int32_t MissionList::GetMissionCountByUid(int32_t targetUid) const { int32_t count = 0; diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index 64894ebaee..fd65202fdc 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -3923,47 +3923,6 @@ bool MissionListManager::IsExcludeFromMissions(const std::shared_ptr &m return abilityRecord && abilityRecord->GetAbilityInfo().excludeFromMissions; } -#ifdef ABILITY_COMMAND_FOR_TEST -int MissionListManager::BlockAbility(int32_t abilityRecordId) -{ - int ret = -1; - for (const auto &missionList : currentMissionLists_) { - if (missionList && missionList != launcherList_) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "missionList begin to call BlockAbilityByRecordId %{public}s", __func__); - if (missionList->BlockAbilityByRecordId(abilityRecordId) == ERR_OK) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "missionList call BlockAbilityByRecordId success"); - ret = ERR_OK; - } - } - } - - if (defaultStandardList_) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "defaultStandardList begin to call BlockAbilityByRecordId %{public}s", __func__); - if (defaultStandardList_->BlockAbilityByRecordId(abilityRecordId) == ERR_OK) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "defaultStandardList call BlockAbilityByRecordId success"); - ret = ERR_OK; - } - } - - if (defaultSingleList_) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "defaultSingleList begin to call BlockAbilityByRecordId %{public}s", __func__); - if (defaultSingleList_->BlockAbilityByRecordId(abilityRecordId) == ERR_OK) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "defaultSingleList_ call BlockAbilityByRecordId success"); - ret = ERR_OK; - } - } - - if (launcherList_) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "launcherList begin to call BlockAbilityByRecordId %{public}s", __func__); - if (launcherList_->BlockAbilityByRecordId(abilityRecordId) == ERR_OK) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "launcherList_ call BlockAbilityByRecordId success"); - ret = ERR_OK; - } - } - return ret; -} -#endif - void MissionListManager::SetMissionANRStateByTokens(const std::vector> &tokens) { TAG_LOGI(AAFwkTag::ABILITYMGR, "call"); 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 37c81e9e83..440b546dbc 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -2250,27 +2250,6 @@ void UIAbilityLifecycleManager::GetAbilityRunningInfos(std::vector guard(sessionLock_); - TAG_LOGI(AAFwkTag::ABILITYMGR, "Call."); - for (const auto& [first, second] : sessionAbilityMap_) { - if (second == nullptr) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "abilityRecord is nullptr."); - continue; - } - if (second->GetRecordId() == abilityRecordId) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "Call BlockAbility."); - return second->BlockAbility(); - } - } - TAG_LOGE(AAFwkTag::ABILITYMGR, "The abilityRecordId is invalid."); - return -1; -} -#endif - void UIAbilityLifecycleManager::Dump(std::vector &info) { TAG_LOGI(AAFwkTag::ABILITYMGR, "Call begin."); diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index f990121573..73c66e6d3b 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -338,15 +338,6 @@ public: virtual int32_t UnregisterConfigurationObserver(const sptr &observer) override; - #ifdef ABILITY_COMMAND_FOR_TEST - /** - * Block app service. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int BlockAppService() override; - #endif - bool GetAppRunningStateByBundleName(const std::string &bundleName) override; int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback) override; diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 4b5f756de0..82c157c13b 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -54,9 +54,6 @@ constexpr const int BASE_TEN = 10; constexpr const char SIGN_TERMINAL = '\0'; namespace { using namespace std::chrono_literals; -#ifdef ABILITY_COMMAND_FOR_TEST -static const int APP_MS_BLOCK = 65; -#endif constexpr const char* TASK_INIT_APPMGRSERVICEINNER = "InitAppMgrServiceInnerTask"; constexpr const char* TASK_ATTACH_APPLICATION = "AttachApplicationTask"; constexpr const char* TASK_APPLICATION_FOREGROUNDED = "ApplicationForegroundedTask"; @@ -1034,24 +1031,6 @@ int32_t AppMgrService::UnregisterConfigurationObserver(const sptrUnregisterConfigurationObserver(observer); } -#ifdef ABILITY_COMMAND_FOR_TEST -int AppMgrService::BlockAppService() -{ - TAG_LOGD(AAFwkTag::APPMGR, "begin"); - if (!IsReady()) { - return ERR_INVALID_OPERATION; - } - auto task = [=]() { - while (1) { - TAG_LOGD(AAFwkTag::APPMGR, "begin block app service"); - std::this_thread::sleep_for(APP_MS_BLOCK*1s); - } - }; - taskHandler_->SubmitTask(task); - return ERR_OK; -} -#endif - bool AppMgrService::GetAppRunningStateByBundleName(const std::string &bundleName) { if (!IsReady()) { diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 2f628ebfe9..111481c50c 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -240,9 +240,6 @@ group("fuzztest") { "attachabilitythread_fuzzer:fuzztest", "attachrenderprocess_fuzzer:fuzztest", "autostartupinfo_fuzzer:fuzztest", - "blockability_fuzzer:fuzztest", - "blockamsservice_fuzzer:fuzztest", - "blockappservice_fuzzer:fuzztest", "bundlemgrhelper_fuzzer:fuzztest", "cacheprocessmanagera_fuzzer:fuzztest", "cacheprocessmanagerb_fuzzer:fuzztest", diff --git a/test/fuzztest/abilityeventhandler_fuzzer/abilityeventhandler_fuzzer.cpp b/test/fuzztest/abilityeventhandler_fuzzer/abilityeventhandler_fuzzer.cpp index fa5c7459b5..1f5f46b041 100755 --- a/test/fuzztest/abilityeventhandler_fuzzer/abilityeventhandler_fuzzer.cpp +++ b/test/fuzztest/abilityeventhandler_fuzzer/abilityeventhandler_fuzzer.cpp @@ -160,9 +160,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) std::vector stringVector; abilitySchedulerProxy->DumpAbilityInfo(stringVector, stringVector); abilitySchedulerProxy->CallRequest(); -#ifdef ABILITY_COMMAND_FOR_TEST - abilitySchedulerProxy->BlockAbility(); -#endif // fuzz for AmsConfigurationParameter AmsConfigurationParameter::GetInstance().NonConfigFile(); AmsConfigurationParameter::GetInstance().GetMissionSaveTime(); diff --git a/test/fuzztest/abilityschedulerstub_fuzzer/abilityschedulerstub_fuzzer.cpp b/test/fuzztest/abilityschedulerstub_fuzzer/abilityschedulerstub_fuzzer.cpp index e2428f88cd..c6cd9e3112 100755 --- a/test/fuzztest/abilityschedulerstub_fuzzer/abilityschedulerstub_fuzzer.cpp +++ b/test/fuzztest/abilityschedulerstub_fuzzer/abilityschedulerstub_fuzzer.cpp @@ -145,10 +145,6 @@ public: {} void DumpAbilityInfo(const std::vector& params, std::vector& info) override {} - int BlockAbility() override - { - return 0; - } void CallRequest() override { return; diff --git a/test/fuzztest/appmgrclientrest_fuzzer/appmgrclientrest_fuzzer.cpp b/test/fuzztest/appmgrclientrest_fuzzer/appmgrclientrest_fuzzer.cpp index 72aca90399..3987eb3c38 100755 --- a/test/fuzztest/appmgrclientrest_fuzzer/appmgrclientrest_fuzzer.cpp +++ b/test/fuzztest/appmgrclientrest_fuzzer/appmgrclientrest_fuzzer.cpp @@ -59,9 +59,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) sptr response; appMgrClient->RegisterStartSpecifiedAbilityResponse(response); appMgrClient->GetRemoteObject(); -#if ABILITY_COMMAND_FOR_TEST - appMgrClient->BlockAppService(); -#endif return true; } } diff --git a/test/fuzztest/appmgrservicefirst_fuzzer/appmgrservicefirst_fuzzer.cpp b/test/fuzztest/appmgrservicefirst_fuzzer/appmgrservicefirst_fuzzer.cpp index 5bb18ed7f2..3937e70c53 100644 --- a/test/fuzztest/appmgrservicefirst_fuzzer/appmgrservicefirst_fuzzer.cpp +++ b/test/fuzztest/appmgrservicefirst_fuzzer/appmgrservicefirst_fuzzer.cpp @@ -130,9 +130,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) appMgrService->NotifyLoadRepairPatch(bundleName, callback); appMgrService->NotifyHotReloadPage(bundleName, callback); appMgrService->NotifyUnLoadRepairPatch(bundleName, callback); -#ifdef ABILITY_COMMAND_FOR_TEST - appMgrService->BlockAppService(); -#endif appMgrService->ApplicationBackgrounded(recordId); sptr token = GetFuzzAbilityToken(); appMgrService->AbilityCleaned(token); diff --git a/test/fuzztest/attachabilitythread_fuzzer/attachabilitythread_fuzzer.cpp b/test/fuzztest/attachabilitythread_fuzzer/attachabilitythread_fuzzer.cpp index 1c1cdcc7e5..deb9d5af34 100755 --- a/test/fuzztest/attachabilitythread_fuzzer/attachabilitythread_fuzzer.cpp +++ b/test/fuzztest/attachabilitythread_fuzzer/attachabilitythread_fuzzer.cpp @@ -150,12 +150,6 @@ public: { return 0; } -#ifdef ABILITY_COMMAND_FOR_TEST - int BlockAbility() override - { - return 0; - } -#endif void CallRequest() override { return; diff --git a/test/fuzztest/blockability_fuzzer/BUILD.gn b/test/fuzztest/blockability_fuzzer/BUILD.gn deleted file mode 100755 index 572a3e598d..0000000000 --- a/test/fuzztest/blockability_fuzzer/BUILD.gn +++ /dev/null @@ -1,80 +0,0 @@ -# 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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("//foundation/ability/ability_runtime/ability_runtime.gni") -module_output_path = "ability_runtime/abilitymgr" - -##############################fuzztest########################################## -ohos_fuzztest("BlockAbilityFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = "${ability_runtime_test_path}/fuzztest/blockability_fuzzer" - include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ] - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "blockability_fuzzer.cpp" ] - - configs = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config", - "${ability_runtime_services_path}/abilitymgr:abilityms_config", - ] - - deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", - "${ability_runtime_native_path}/ability/native:abilitykit_native", - "${ability_runtime_services_path}/abilitymgr:abilityms", - "//third_party/jsoncpp:jsoncpp", - ] - - external_deps = [ - "ability_base:want", - "ability_base:zuri", - "bundle_framework:appexecfwk_base", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", - "ffrt:libffrt", - "ipc:ipc_core", - "napi:ace_napi", - "relational_store:native_dataability", - "relational_store:native_rdb", - "samgr:samgr_proxy", - ] - - if (ability_runtime_graphics) { - deps += [] - external_deps += [ - "i18n:intl_util", - "window_manager:libwm", - ] - } -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [] - deps += [ - # deps file - ":BlockAbilityFuzzTest", - ] -} -############################################################################### diff --git a/test/fuzztest/blockability_fuzzer/blockability_fuzzer.cpp b/test/fuzztest/blockability_fuzzer/blockability_fuzzer.cpp deleted file mode 100755 index e056d33444..0000000000 --- a/test/fuzztest/blockability_fuzzer/blockability_fuzzer.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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 "blockability_fuzzer.h" - -#include -#include - -#include "ability_manager_client.h" -#include "ability_record.h" - -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace { -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; -} -uint32_t GetU32Data(const char* ptr) -{ - // convert fuzz input data to an integer - return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]; -} -bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) -{ - auto abilitymgr = AbilityManagerClient::GetInstance(); - if (!abilitymgr) { - return false; - } -#ifdef ABILITY_COMMAND_FOR_TEST - int32_t abilityRecordId = static_cast(GetU32Data(data)); - if (abilitymgr->BlockAbility(abilityRecordId) != 0) { - return false; - } -#endif - return true; -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - std::cout << "invalid data" << std::endl; - return 0; - } - - /* Validate the length of size */ - if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { - return 0; - } - - char* ch = (char*)malloc(size + 1); - if (ch == nullptr) { - std::cout << "malloc failed." << std::endl; - return 0; - } - - (void)memset_s(ch, size + 1, 0x00, size + 1); - if (memcpy_s(ch, size, data, size) != EOK) { - std::cout << "copy failed." << std::endl; - free(ch); - ch = nullptr; - return 0; - } - - OHOS::DoSomethingInterestingWithMyAPI(ch, size); - free(ch); - ch = nullptr; - return 0; -} - diff --git a/test/fuzztest/blockability_fuzzer/blockability_fuzzer.h b/test/fuzztest/blockability_fuzzer/blockability_fuzzer.h deleted file mode 100755 index fc6a0c524d..0000000000 --- a/test/fuzztest/blockability_fuzzer/blockability_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 FUZZTEST_OHOS_ABILITY_RUNTIME_BLOCKABILITY_FUZZER_H -#define FUZZTEST_OHOS_ABILITY_RUNTIME_BLOCKABILITY_FUZZER_H - -#define FUZZ_PROJECT_NAME "blockability_fuzzer" - -#endif diff --git a/test/fuzztest/blockability_fuzzer/corpus/init b/test/fuzztest/blockability_fuzzer/corpus/init deleted file mode 100755 index 6198079a28..0000000000 --- a/test/fuzztest/blockability_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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. - */ - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/blockability_fuzzer/project.xml b/test/fuzztest/blockability_fuzzer/project.xml deleted file mode 100755 index 7133b2b924..0000000000 --- a/test/fuzztest/blockability_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/fuzztest/blockamsservice_fuzzer/BUILD.gn b/test/fuzztest/blockamsservice_fuzzer/BUILD.gn deleted file mode 100755 index ee6e9b03dd..0000000000 --- a/test/fuzztest/blockamsservice_fuzzer/BUILD.gn +++ /dev/null @@ -1,82 +0,0 @@ -# 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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("//foundation/ability/ability_runtime/ability_runtime.gni") -module_output_path = "ability_runtime/abilitymgr" - -##############################fuzztest########################################## -ohos_fuzztest("BlockAmsServiceFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = - "${ability_runtime_test_path}/fuzztest/blockamsservice_fuzzer" - include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ] - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "blockamsservice_fuzzer.cpp" ] - - configs = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config", - "${ability_runtime_services_path}/abilitymgr:abilityms_config", - ] - - deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", - "${ability_runtime_native_path}/ability/native:abilitykit_native", - "${ability_runtime_services_path}/abilitymgr:abilityms", - "//third_party/jsoncpp:jsoncpp", - ] - - external_deps = [ - "ability_base:want", - "ability_base:zuri", - "ability_runtime:app_manager", - "bundle_framework:appexecfwk_base", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", - "ffrt:libffrt", - "ipc:ipc_core", - "napi:ace_napi", - "relational_store:native_dataability", - "relational_store:native_rdb", - "samgr:samgr_proxy", - ] - - if (ability_runtime_graphics) { - deps += [] - external_deps += [ - "i18n:intl_util", - "window_manager:libwm", - ] - } -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [] - deps += [ - # deps file - ":BlockAmsServiceFuzzTest", - ] -} -############################################################################### diff --git a/test/fuzztest/blockamsservice_fuzzer/blockamsservice_fuzzer.cpp b/test/fuzztest/blockamsservice_fuzzer/blockamsservice_fuzzer.cpp deleted file mode 100755 index ed70ef1b17..0000000000 --- a/test/fuzztest/blockamsservice_fuzzer/blockamsservice_fuzzer.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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 "blockamsservice_fuzzer.h" - -#include -#include - -#include "ability_manager_client.h" -#include "ability_record.h" - -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace { -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; -} -bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) -{ - auto abilitymgr = AbilityManagerClient::GetInstance(); - if (!abilitymgr) { - return false; - } -#ifdef ABILITY_COMMAND_FOR_TEST - if (abilitymgr->BlockAmsService() != 0) { - return false; - } -#endif - return true; -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - std::cout << "invalid data" << std::endl; - return 0; - } - - /* Validate the length of size */ - if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { - return 0; - } - - char* ch = (char*)malloc(size + 1); - if (ch == nullptr) { - std::cout << "malloc failed." << std::endl; - return 0; - } - - (void)memset_s(ch, size + 1, 0x00, size + 1); - if (memcpy_s(ch, size, data, size) != EOK) { - std::cout << "copy failed." << std::endl; - free(ch); - ch = nullptr; - return 0; - } - - OHOS::DoSomethingInterestingWithMyAPI(ch, size); - free(ch); - ch = nullptr; - return 0; -} - diff --git a/test/fuzztest/blockamsservice_fuzzer/blockamsservice_fuzzer.h b/test/fuzztest/blockamsservice_fuzzer/blockamsservice_fuzzer.h deleted file mode 100755 index d4ff13fbc1..0000000000 --- a/test/fuzztest/blockamsservice_fuzzer/blockamsservice_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 FUZZTEST_OHOS_ABILITY_RUNTIME_BLOCKAMSSERVICE_FUZZER_H -#define FUZZTEST_OHOS_ABILITY_RUNTIME_BLOCKAMSSERVICE_FUZZER_H - -#define FUZZ_PROJECT_NAME "blockamsservice_fuzzer" - -#endif diff --git a/test/fuzztest/blockamsservice_fuzzer/corpus/init b/test/fuzztest/blockamsservice_fuzzer/corpus/init deleted file mode 100755 index 6198079a28..0000000000 --- a/test/fuzztest/blockamsservice_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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. - */ - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/blockamsservice_fuzzer/project.xml b/test/fuzztest/blockamsservice_fuzzer/project.xml deleted file mode 100755 index 7133b2b924..0000000000 --- a/test/fuzztest/blockamsservice_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/fuzztest/blockappservice_fuzzer/BUILD.gn b/test/fuzztest/blockappservice_fuzzer/BUILD.gn deleted file mode 100755 index 1674b139a9..0000000000 --- a/test/fuzztest/blockappservice_fuzzer/BUILD.gn +++ /dev/null @@ -1,81 +0,0 @@ -# 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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("//foundation/ability/ability_runtime/ability_runtime.gni") -module_output_path = "ability_runtime/abilitymgr" - -##############################fuzztest########################################## -ohos_fuzztest("BlockAppServiceFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = - "${ability_runtime_test_path}/fuzztest/blockappservice_fuzzer" - include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ] - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "blockappservice_fuzzer.cpp" ] - - configs = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config", - "${ability_runtime_services_path}/abilitymgr:abilityms_config", - ] - - deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", - "${ability_runtime_native_path}/ability/native:abilitykit_native", - "${ability_runtime_services_path}/abilitymgr:abilityms", - "//third_party/jsoncpp:jsoncpp", - ] - - external_deps = [ - "ability_base:want", - "ability_base:zuri", - "bundle_framework:appexecfwk_base", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", - "ffrt:libffrt", - "ipc:ipc_core", - "napi:ace_napi", - "relational_store:native_dataability", - "relational_store:native_rdb", - "samgr:samgr_proxy", - ] - - if (ability_runtime_graphics) { - deps += [] - external_deps += [ - "i18n:intl_util", - "window_manager:libwm", - ] - } -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [] - deps += [ - # deps file - ":BlockAppServiceFuzzTest", - ] -} -############################################################################### diff --git a/test/fuzztest/blockappservice_fuzzer/blockappservice_fuzzer.cpp b/test/fuzztest/blockappservice_fuzzer/blockappservice_fuzzer.cpp deleted file mode 100755 index a7898802bb..0000000000 --- a/test/fuzztest/blockappservice_fuzzer/blockappservice_fuzzer.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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 "blockappservice_fuzzer.h" - -#include -#include - -#include "ability_manager_client.h" -#include "ability_record.h" - -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace { -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; -} -bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) -{ - auto abilitymgr = AbilityManagerClient::GetInstance(); - if (!abilitymgr) { - return false; - } -#ifdef ABILITY_COMMAND_FOR_TEST - if (abilitymgr->BlockAppService() != 0) { - return false; - } -#endif - - return true; -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - std::cout << "invalid data" << std::endl; - return 0; - } - - /* Validate the length of size */ - if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { - return 0; - } - - char* ch = (char*)malloc(size + 1); - if (ch == nullptr) { - std::cout << "malloc failed." << std::endl; - return 0; - } - - (void)memset_s(ch, size + 1, 0x00, size + 1); - if (memcpy_s(ch, size, data, size) != EOK) { - std::cout << "copy failed." << std::endl; - free(ch); - ch = nullptr; - return 0; - } - - OHOS::DoSomethingInterestingWithMyAPI(ch, size); - free(ch); - ch = nullptr; - return 0; -} - diff --git a/test/fuzztest/blockappservice_fuzzer/blockappservice_fuzzer.h b/test/fuzztest/blockappservice_fuzzer/blockappservice_fuzzer.h deleted file mode 100755 index 5502d07b00..0000000000 --- a/test/fuzztest/blockappservice_fuzzer/blockappservice_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 FUZZTEST_OHOS_ABILITY_RUNTIME_BLOCKAPPSERVICE_FUZZER_H -#define FUZZTEST_OHOS_ABILITY_RUNTIME_BLOCKAPPSERVICE_FUZZER_H - -#define FUZZ_PROJECT_NAME "blockappservice_fuzzer" - -#endif diff --git a/test/fuzztest/blockappservice_fuzzer/corpus/init b/test/fuzztest/blockappservice_fuzzer/corpus/init deleted file mode 100755 index 6198079a28..0000000000 --- a/test/fuzztest/blockappservice_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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. - */ - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/blockappservice_fuzzer/project.xml b/test/fuzztest/blockappservice_fuzzer/project.xml deleted file mode 100755 index 7133b2b924..0000000000 --- a/test/fuzztest/blockappservice_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/fuzztest/missionlistmanagersecond_fuzzer/missionlistmanagersecond_fuzzer.cpp b/test/fuzztest/missionlistmanagersecond_fuzzer/missionlistmanagersecond_fuzzer.cpp index 162be7bde3..66d9b42e4f 100644 --- a/test/fuzztest/missionlistmanagersecond_fuzzer/missionlistmanagersecond_fuzzer.cpp +++ b/test/fuzztest/missionlistmanagersecond_fuzzer/missionlistmanagersecond_fuzzer.cpp @@ -174,9 +174,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) missionListManager->GetAllForegroundAbilities(foregroundList); missionListManager->GetForegroundAbilities(missionList, foregroundList); missionListManager->IsExcludeFromMissions(mission); -#ifdef ABILITY_COMMAND_FOR_TEST - missionListManager->BlockAbility(int32Param); -#endif std::vector> tokens; missionListManager->SetMissionANRStateByTokens(tokens); missionListManager->listenerController_ = nullptr; diff --git a/test/fuzztest/uiabilitylifecyclemanagerb_fuzzer/uiabilitylifecyclemanagerb_fuzzer.cpp b/test/fuzztest/uiabilitylifecyclemanagerb_fuzzer/uiabilitylifecyclemanagerb_fuzzer.cpp index 3d039467c8..ad34e08566 100644 --- a/test/fuzztest/uiabilitylifecyclemanagerb_fuzzer/uiabilitylifecyclemanagerb_fuzzer.cpp +++ b/test/fuzztest/uiabilitylifecyclemanagerb_fuzzer/uiabilitylifecyclemanagerb_fuzzer.cpp @@ -106,10 +106,6 @@ bool DoSomethingInterestingWithMyAPI(const char *data, size_t size) uIAbilityLifecycleManager->GetAbilityRunningInfos(info, boolParam); int intParam = static_cast(GetU32Data(data)); - #ifdef ABILITY_COMMAND_FOR_TEST - uIAbilityLifecycleManager->BlockAbility(intParam); - #endif - std::vector info1; uIAbilityLifecycleManager->Dump(info1); uIAbilityLifecycleManager->DumpMissionList(info1, boolParam, strParam); diff --git a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h index 04bc819ac9..d1261649b5 100644 --- a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h @@ -162,11 +162,6 @@ public: MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); -#ifdef ABILITY_COMMAND_FOR_TEST - MOCK_METHOD0(BlockAppService, int()); - MOCK_METHOD0(BlockAmsService, int()); - MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); -#endif MOCK_METHOD2(GetWantSenderInfo, int(const sptr& target, std::shared_ptr& info)); diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_client.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_client.h index cd51b78392..d8eedb1507 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_client.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_client.h @@ -130,12 +130,6 @@ public: { return std::vector>(); }; -#ifdef ABILITY_COMMAND_FOR_TEST - virtual int BlockAbility() - { - return 0; - }; -#endif virtual void NotifyContinuationResult(int32_t result) {}; virtual void ContinueAbility(const std::string& deviceId, uint32_t versionCode) {}; virtual void DumpAbilityInfo(const std::vector& params, std::vector& info) {}; diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h index e102ae8b79..eff053310b 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h @@ -155,11 +155,6 @@ public: MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); -#ifdef ABILITY_COMMAND_FOR_TEST - MOCK_METHOD0(BlockAppService, int()); - MOCK_METHOD0(BlockAmsService, int()); - MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); -#endif sptr AcquireDataAbility( const Uri& uri, bool tryBind, const sptr& callerToken) override diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_scheduler_for_observer.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_scheduler_for_observer.h index afc6e07f28..3e4befc22b 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_scheduler_for_observer.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_scheduler_for_observer.h @@ -66,12 +66,6 @@ public: MOCK_METHOD1(NotifyContinuationResult, void(int32_t result)); MOCK_METHOD2(ContinueAbility, void(const std::string& deviceId, uint32_t versionCode)); MOCK_METHOD2(DumpAbilityInfo, void(const std::vector& params, std::vector& info)); -#ifdef ABILITY_COMMAND_FOR_TEST - virtual int BlockAbility() override - { - return 0; - } -#endif virtual void CallRequest() { return; diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp index f2444dc66f..cb6caaa539 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp @@ -209,21 +209,6 @@ void MockAbilityDelegatorStub::GetAbilityTokenByCalleeObj(const sptr& callerToken) { return 0; } -int MockAbilityDelegatorStub2::BlockAppService() -{ - return 0; -} - #ifdef ABILITY_COMMAND_FOR_TEST int MockAbilityDelegatorStub::ForceTimeoutForTest(const std::string& abilityName, const std::string& state) { diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h index 20ec0449fa..693f9feb11 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h @@ -157,9 +157,6 @@ public: int DoAbilityBackground(const sptr& token, uint32_t flag); int32_t GetMissionIdByToken(const sptr& token); void GetAbilityTokenByCalleeObj(const sptr &callStub, sptr &token); - int BlockAmsService(); - int BlockAbility(int32_t abilityRecordId); - int BlockAppService(); int32_t SetApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag) override { return 0; @@ -344,9 +341,6 @@ public: int DoAbilityBackground(const sptr& token, uint32_t flag); int32_t GetMissionIdByToken(const sptr& token); void GetAbilityTokenByCalleeObj(const sptr &callStub, sptr &token); - int BlockAmsService(); - int BlockAbility(int32_t abilityRecordId); - int BlockAppService(); int32_t SetApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag) override { return 0; diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h index d2e02b3e40..dcb4898672 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h @@ -50,9 +50,6 @@ public: MOCK_METHOD3(ScheduleAcceptWantDone, void(const int32_t recordId, const AAFwk::Want& want, const std::string& flag)); MOCK_METHOD2(GetAbilityRecordsByProcessID, int(const int pid, std::vector>& tokens)); -#ifdef ABILITY_COMMAND_FOR_TEST - MOCK_METHOD0(BlockAppService, int()); -#endif MOCK_METHOD0(PreStartNWebSpawnProcess, int()); MOCK_METHOD6(StartRenderProcess, int(const std::string &renderParam, int32_t ipcFd, diff --git a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h index b97c37b73f..d107915586 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h @@ -163,11 +163,6 @@ public: MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); -#ifdef ABILITY_COMMAND_FOR_TEST - MOCK_METHOD0(BlockAppService, int()); - MOCK_METHOD0(BlockAmsService, int()); - MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); -#endif int StartUser(int userId, sptr callback) override { diff --git a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h index 2cdbc50c89..729d28506d 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h @@ -166,12 +166,6 @@ public: MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); -#ifdef ABILITY_COMMAND_FOR_TEST - MOCK_METHOD0(BlockAppService, int()); - MOCK_METHOD0(BlockAmsService, int()); - MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); -#endif - sptr AcquireDataAbility( const Uri& uri, bool tryBind, const sptr& callerToken) override { diff --git a/test/mock/services_abilitymgr_test/libs/aakit/include/ability_scheduler.h b/test/mock/services_abilitymgr_test/libs/aakit/include/ability_scheduler.h index 0db18869ac..d9beef8a9a 100644 --- a/test/mock/services_abilitymgr_test/libs/aakit/include/ability_scheduler.h +++ b/test/mock/services_abilitymgr_test/libs/aakit/include/ability_scheduler.h @@ -115,12 +115,6 @@ public: return 0; }; virtual void UpdateSessionToken(sptr sessionToken) override {} -#ifdef ABILITY_COMMAND_FOR_TEST - virtual int BlockAbility() override - { - return 0; - }; -#endif private: AbilityResult result_; }; diff --git a/test/mock/services_abilitymgr_test/libs/ability_scheduler_mock/ability_scheduler_mock.h b/test/mock/services_abilitymgr_test/libs/ability_scheduler_mock/ability_scheduler_mock.h index a4cb4fc1c5..477ef3fb33 100644 --- a/test/mock/services_abilitymgr_test/libs/ability_scheduler_mock/ability_scheduler_mock.h +++ b/test/mock/services_abilitymgr_test/libs/ability_scheduler_mock/ability_scheduler_mock.h @@ -166,13 +166,6 @@ public: virtual void UpdateSessionToken(sptr sessionToken) override {} -#ifdef ABILITY_COMMAND_FOR_TEST - virtual int BlockAbility() - { - return 0; - } -#endif - int code_ = 0; }; } // namespace AAFwk diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h index a8bcb0ef63..27eb7e3e00 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h @@ -76,9 +76,6 @@ public: MOCK_METHOD2(UpdateConfigurationByBundleName, int32_t(const Configuration& config, const std::string &name)); MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr& observer)); MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr& observer)); -#ifdef ABILITY_COMMAND_FOR_TEST - MOCK_METHOD0(BlockAppService, int()); -#endif MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string& bundleName)); MOCK_METHOD2(NotifyLoadRepairPatch, int32_t(const std::string& bundleName, const sptr& callback)); diff --git a/test/moduletest/mock/include/mock_ability_mgr_service.h b/test/moduletest/mock/include/mock_ability_mgr_service.h index bdf9fa4195..5f2e3d1101 100644 --- a/test/moduletest/mock/include/mock_ability_mgr_service.h +++ b/test/moduletest/mock/include/mock_ability_mgr_service.h @@ -118,11 +118,6 @@ public: MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); -#ifdef ABILITY_COMMAND_FOR_TEST - MOCK_METHOD0(BlockAppService, int()); - MOCK_METHOD0(BlockAmsService, int()); - MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); -#endif virtual int StartAbility( const Want& want, diff --git a/test/moduletest/mock/include/mock_ability_scheduler.h b/test/moduletest/mock/include/mock_ability_scheduler.h index 571cab6fbf..453c2e2474 100644 --- a/test/moduletest/mock/include/mock_ability_scheduler.h +++ b/test/moduletest/mock/include/mock_ability_scheduler.h @@ -129,12 +129,6 @@ public: return 0; } virtual void UpdateSessionToken(sptr sessionToken) override {} -#ifdef ABILITY_COMMAND_FOR_TEST - virtual int BlockAbility() override - { - return 0; - } -#endif }; } // namespace AAFwk } // namespace OHOS diff --git a/test/moduletest/mock/include/mock_ability_scheduler_stub.h b/test/moduletest/mock/include/mock_ability_scheduler_stub.h index 17cffb695b..b18602cfd4 100644 --- a/test/moduletest/mock/include/mock_ability_scheduler_stub.h +++ b/test/moduletest/mock/include/mock_ability_scheduler_stub.h @@ -69,13 +69,6 @@ public: } virtual void UpdateSessionToken(sptr sessionToken) override {} - -#ifdef ABILITY_COMMAND_FOR_TEST - virtual int BlockAbility() override - { - return 0; - } -#endif }; } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_manager_client_branch_second_test/ability_manager_stub_mock_second_test.h b/test/unittest/ability_manager_client_branch_second_test/ability_manager_stub_mock_second_test.h index 611a902cce..0adbcac99c 100644 --- a/test/unittest/ability_manager_client_branch_second_test/ability_manager_stub_mock_second_test.h +++ b/test/unittest/ability_manager_client_branch_second_test/ability_manager_stub_mock_second_test.h @@ -343,11 +343,6 @@ public: MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); -#ifdef ABILITY_COMMAND_FOR_TEST - MOCK_METHOD0(BlockAppService, int()); - MOCK_METHOD0(BlockAmsService, int()); - MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); -#endif int SendResultToAbility(int requestCode, int resultCode, Want& resultWant) override { 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 ca71013d04..73554b6402 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 @@ -1095,61 +1095,6 @@ HWTEST_F(AbilityManagerClientBranchTest, SetAbilityController_0100, TestSize.Lev GTEST_LOG_(INFO) << "SetAbilityController_0100 end"; } - -#ifdef ABILITY_COMMAND_FOR_TEST -/** - * @tc.name: AbilityManagerClient_BlockAmsService_0100 - * @tc.desc: BlockAmsService - * @tc.type: FUNC - */ -HWTEST_F(AbilityManagerClientBranchTest, BlockAmsService_0100, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "BlockAmsService_0100 start"; - EXPECT_CALL(*mock_, BlockAmsService()) - .Times(1) - .WillOnce(Return(0)); - auto result = client_->BlockAmsService(); - - EXPECT_EQ(result, ERR_OK); - GTEST_LOG_(INFO) << "BlockAmsService_0100 end"; -} - -/** - * @tc.name: AbilityManagerClient_BlockAppService_0100 - * @tc.desc: BlockAppService - * @tc.type: FUNC - */ -HWTEST_F(AbilityManagerClientBranchTest, BlockAppService_0100, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "BlockAppService_0100 start"; - EXPECT_CALL(*mock_, BlockAppService()) - .Times(1) - .WillOnce(Return(0)); - auto result = client_->BlockAppService(info); - - EXPECT_EQ(result, ERR_OK); - GTEST_LOG_(INFO) << "BlockAppService_0100 end"; -} - -/** - * @tc.name: AbilityManagerClient_BlockAbility_0100 - * @tc.desc: BlockAbility - * @tc.type: FUNC - */ -HWTEST_F(AbilityManagerClientBranchTest, BlockAbility_0100, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "BlockAbility_0100 start"; - EXPECT_CALL(*mock_, BlockAbility(_)) - .Times(1) - .WillOnce(Return(0)); - int32_t abilityRecordId = 1; - auto result = client_->BlockAbility(abilityRecordId); - - EXPECT_EQ(result, ERR_OK); - GTEST_LOG_(INFO) << "BlockAbility_0100 end"; -} -#endif - /** * @tc.name: AbilityManagerClient_DumpAbilityInfoDone_0100 * @tc.desc: DumpAbilityInfoDone diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h index 40f7f781e2..3d2a46364b 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h @@ -343,11 +343,6 @@ public: MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); -#ifdef ABILITY_COMMAND_FOR_TEST - MOCK_METHOD0(BlockAppService, int()); - MOCK_METHOD0(BlockAmsService, int()); - MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); -#endif int SendResultToAbility(int requestCode, int resultCode, Want& resultWant) override { diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp index e2ccdb6cb4..d13d84a0a8 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp +++ b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp @@ -1964,67 +1964,6 @@ HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_GetMissionIdByToken_001, T EXPECT_EQ(res, NO_ERROR); } -#ifdef ABILITY_COMMAND_FOR_TEST -/* - * Feature: AbilityManagerService - * Function: BlockAmsService - * SubFunction: NA - * FunctionPoints: AbilityManagerService BlockAmsService - * EnvConditions: NA - * CaseDescription: Verify the normal process of BlockAmsService - */ -HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_BlockAmsService_001, TestSize.Level1) -{ - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeSendRequest)); - auto res = proxy_->BlockAmsService(); - EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::BLOCK_AMS_SERVICE), mock_->code_); - EXPECT_EQ(res, NO_ERROR); -} -#endif - -#ifdef ABILITY_COMMAND_FOR_TEST -/* - * Feature: AbilityManagerService - * Function: BlockAbility - * SubFunction: NA - * FunctionPoints: AbilityManagerService BlockAbility - * EnvConditions: NA - * CaseDescription: Verify the normal process of BlockAbility - */ -HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_BlockAbility_001, TestSize.Level1) -{ - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeSendRequest)); - int32_t abilityRecordId = 0; - auto res = proxy_->BlockAbility(abilityRecordId); - EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::BLOCK_ABILITY), mock_->code_); - EXPECT_EQ(res, NO_ERROR); -} -#endif - -#ifdef ABILITY_COMMAND_FOR_TEST -/* - * Feature: AbilityManagerService - * Function: BlockAppService - * SubFunction: NA - * FunctionPoints: AbilityManagerService BlockAppService - * EnvConditions: NA - * CaseDescription: Verify the normal process of BlockAppService - */ -HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_BlockAppService_001, TestSize.Level1) -{ - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeSendRequest)); - auto res = proxy_->BlockAppService(); - EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::BLOCK_APP_SERVICE), mock_->code_); - EXPECT_EQ(res, NO_ERROR); -} -#endif - /* * Feature: AbilityManagerService * Function: FreeInstallAbilityFromRemote diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h index 5eab1a21ea..39989ed670 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -361,12 +361,6 @@ public: const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); MOCK_METHOD1(MoveUIAbilityToBackground, int(const sptr token)); -#ifdef ABILITY_COMMAND_FOR_TEST - MOCK_METHOD0(BlockAppService, int()); - MOCK_METHOD0(BlockAmsService, int()); - MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); -#endif - int StartUserTest(const Want& want, const sptr& observer) override { return 0; diff --git a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp index 8d065bb563..3dcd397d80 100644 --- a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp +++ b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp @@ -760,62 +760,6 @@ HWTEST_F(AbilityManagerServiceThirdTest, GetDataAbilityUri_001, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest GetDataAbilityUri_001 end"); } -#ifdef ABILITY_COMMAND_FOR_TEST -/* - * Feature: AbilityManagerService - * Function: BlockAmsService - * SubFunction: NA - * FunctionPoints: AbilityManagerService BlockAmsService - */ -HWTEST_F(AbilityManagerServiceThirdTest, BlockAmsService_001, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest BlockAmsService_001 start"); - auto abilityMs_ = std::make_shared(); - auto temp = abilityMs_->taskHandler_; - abilityMs_->taskHandler_ = nullptr; - EXPECT_EQ(abilityMs_->BlockAmsService(), ERR_NO_INIT); - - abilityMs_->taskHandler_ = temp; - EXPECT_EQ(abilityMs_->BlockAmsService(), ERR_OK); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest BlockAmsService_001 end"); -} - -/* - * Feature: AbilityManagerService - * Function: BlockAbility - * SubFunction: NA - * FunctionPoints: AbilityManagerService BlockAbility - */ -HWTEST_F(AbilityManagerServiceThirdTest, BlockAbility_001, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest BlockAbility_001 start"); - auto abilityMs_ = std::make_shared(); - abilityMs_->subManagersHelper_ = std::make_shared(nullptr, nullptr); - abilityMs_->subManagersHelper_->currentUIAbilityManager_ = std::make_shared(); - auto temp = abilityMs_->subManagersHelper_->currentMissionListManager_; - abilityMs_->subManagersHelper_->currentMissionListManager_ = nullptr; - EXPECT_EQ(abilityMs_->BlockAbility(1), ERR_OK); - - abilityMs_->subManagersHelper_->currentMissionListManager_ = temp; - EXPECT_EQ(abilityMs_->BlockAbility(1), ERR_OK); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest BlockAbility_001 end"); -} - -/* - * Feature: AbilityManagerService - * Function: BlockAppService - * SubFunction: NA - * FunctionPoints: AbilityManagerService BlockAppService - */ -HWTEST_F(AbilityManagerServiceThirdTest, BlockAppService_001, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest BlockAppService_001 start"); - auto abilityMs_ = std::make_shared(); - EXPECT_EQ(abilityMs_->BlockAppService(1), ERR_OK); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest BlockAppService_001 end"); -} -#endif - /* * Feature: AbilityManagerService * Function: CreateVerificationInfo diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h index 51d44b36b9..c64012656f 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -73,11 +73,6 @@ public: MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); -#ifdef ABILITY_COMMAND_FOR_TEST - MOCK_METHOD0(BlockAppService, int()); - MOCK_METHOD0(BlockAmsService, int()); - MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); -#endif int InvokeSendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp b/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp index 6aa86ff97a..6af7f580c7 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp @@ -2388,60 +2388,6 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_ForceTimeoutForTestInner_001 } #endif -#ifdef ABILITY_COMMAND_FOR_TEST -/* - * Feature: AbilityManagerService - * Function: BlockAbilityInner - * SubFunction: NA - * FunctionPoints: AbilityManagerService BlockAbilityInner - * EnvConditions: NA - * CaseDescription: Verify the function BlockAbilityInner is normal flow. - */ -HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_BlockAbilityInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - auto res = stub_->BlockAbilityInner(data, reply); - EXPECT_EQ(res, NO_ERROR); -} -#endif - -#ifdef ABILITY_COMMAND_FOR_TEST -/* - * Feature: AbilityManagerService - * Function: BlockAmsServiceInner - * SubFunction: NA - * FunctionPoints: AbilityManagerService BlockAmsServiceInner - * EnvConditions: NA - * CaseDescription: Verify the function BlockAmsServiceInner is normal flow. - */ -HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_BlockAmsServiceInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - auto res = stub_->BlockAmsServiceInner(data, reply); - EXPECT_EQ(res, NO_ERROR); -} -#endif - -#ifdef ABILITY_COMMAND_FOR_TEST -/* - * Feature: AbilityManagerService - * Function: BlockAppServiceInner - * SubFunction: NA - * FunctionPoints: AbilityManagerService BlockAppServiceInner - * EnvConditions: NA - * CaseDescription: Verify the function BlockAppServiceInner is normal flow. - */ -HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_BlockAppServiceInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - auto res = stub_->BlockAppServiceInner(data, reply); - EXPECT_EQ(res, NO_ERROR); -} -#endif - /* * Feature: AbilityManagerService * Function: FreeInstallAbilityFromRemoteInner diff --git a/test/unittest/ability_manager_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_test/ability_manager_stub_mock.h index ba936e2a7d..b993572932 100644 --- a/test/unittest/ability_manager_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_test/ability_manager_stub_mock.h @@ -348,11 +348,6 @@ public: MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); -#ifdef ABILITY_COMMAND_FOR_TEST - MOCK_METHOD0(BlockAppService, int()); - MOCK_METHOD0(BlockAmsService, int()); - MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); -#endif int SendResultToAbility(int requestCode, int resultCode, Want& resultWant) override { diff --git a/test/unittest/ability_scheduler_proxy_test/ability_scheduler_proxy_test.cpp b/test/unittest/ability_scheduler_proxy_test/ability_scheduler_proxy_test.cpp index 16adf6629e..c32b3955a7 100644 --- a/test/unittest/ability_scheduler_proxy_test/ability_scheduler_proxy_test.cpp +++ b/test/unittest/ability_scheduler_proxy_test/ability_scheduler_proxy_test.cpp @@ -462,25 +462,6 @@ HWTEST_F(AbilitySchedulerProxyTest, ability_scheduler_proxy_operating_022, TestS EXPECT_EQ(IAbilityScheduler::CONTINUE_ABILITY, mock_->code_); } -#ifdef ABILITY_COMMAND_FOR_TEST -/* - * Feature: AbilitySchedulerProxy - * Function: BlockAbility - * SubFunction: NA - * FunctionPoints: AbilitySchedulerProxy BlockAbility - * EnvConditions: NA - * CaseDescription: verify BlockAbility Normal case - */ -HWTEST_F(AbilitySchedulerProxyTest, ability_scheduler_proxy_operating_023, TestSize.Level1) -{ - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &AbilitySchedulerMock::InvokeSendRequest)); - abilitySchedulerProxy_->BlockAbility(); - EXPECT_EQ(IAbilityScheduler::BLOCK_ABILITY_INNER, mock_->code_); -} -#endif - /* * Feature: AbilitySchedulerProxy * Function: ScheduleCommandAbilityWindow diff --git a/test/unittest/ability_scheduler_stub_test/ability_schedule_stub_mock.h b/test/unittest/ability_scheduler_stub_test/ability_schedule_stub_mock.h index 01de3f9891..d8ce11f5ec 100644 --- a/test/unittest/ability_scheduler_stub_test/ability_schedule_stub_mock.h +++ b/test/unittest/ability_scheduler_stub_test/ability_schedule_stub_mock.h @@ -158,12 +158,6 @@ public: return 0; } virtual void UpdateSessionToken(sptr sessionToken) override {} -#ifdef ABILITY_COMMAND_FOR_TEST - int BlockAbility() override - { - return 0; - } -#endif }; } // namespace AAFwk } // namespace OHOS 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 0ceac52c4b..3164f41a75 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 @@ -605,25 +605,6 @@ HWTEST_F(AppMgrClientTest, AppMgrClient_StartRenderProcess_001, TestSize.Level0) EXPECT_EQ(ret, ERROR_STATE); } -#ifdef ABILITY_COMMAND_FOR_TEST -/** - * @tc.name: AppMgrClient_BlockAppService_001 - * @tc.desc: block app service. - * @tc.type: FUNC - */ -HWTEST_F(AppMgrClientTest, AppMgrClient_BlockAppService_001, TestSize.Level0) -{ - auto appMgrClient = std::make_unique(); - EXPECT_NE(appMgrClient, nullptr); - - auto result = appMgrClient->ConnectAppMgrService(); - EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); - - int ret = appMgrClient->BlockAppService(); - EXPECT_EQ(ret, AppMgrResultCode::RESULT_OK); -} -#endif - /** * @tc.name: AppMgrClient_SetCurrentUserId_001 * @tc.desc: set current userId. 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 19da3c79df..f099c68ef4 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 @@ -998,42 +998,6 @@ HWTEST_F(AppMgrServiceTest, UnregisterConfigurationObserver_002, TestSize.Level0 EXPECT_NE(res, ERR_INVALID_OPERATION); } -#ifdef ABILITY_COMMAND_FOR_TEST -/* - * Feature: AppMgrService - * Function: BlockAppService - * SubFunction: NA - * FunctionPoints: AppMgrService BlockAppService - * EnvConditions: NA - * CaseDescription: Verify BlockAppService - */ -HWTEST_F(AppMgrServiceTest, BlockAppService_001, TestSize.Level0) -{ - auto appMgrService = std::make_shared(); - appMgrService->SetInnerService(nullptr); - int res = appMgrService->BlockAppService(); - EXPECT_EQ(res, ERR_INVALID_OPERATION); -} - -/* - * Feature: AppMgrService - * Function: BlockAppService - * SubFunction: NA - * FunctionPoints: AppMgrService BlockAppService - * EnvConditions: NA - * CaseDescription: Verify BlockAppService - */ -HWTEST_F(AppMgrServiceTest, BlockAppService_002, TestSize.Level0) -{ - auto appMgrService = std::make_shared(); - appMgrService->SetInnerService(std::make_shared()); - appMgrService->taskHandler_ = taskHandler_; - appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); - int res = appMgrService->BlockAppService(); - EXPECT_NE(res, ERR_INVALID_OPERATION); -} -#endif - /* * Feature: AppMgrService * Function: GetAppRunningStateByBundleName diff --git a/test/unittest/app_scheduler_test/app_mgr_client_mock.h b/test/unittest/app_scheduler_test/app_mgr_client_mock.h index 1a70c83c82..7921fee54d 100755 --- a/test/unittest/app_scheduler_test/app_mgr_client_mock.h +++ b/test/unittest/app_scheduler_test/app_mgr_client_mock.h @@ -54,7 +54,6 @@ public: MOCK_METHOD1(GetConfiguration, AppMgrResultCode(Configuration& config)); MOCK_METHOD2(GetAbilityRecordsByProcessID, int( const int pid, std::vector> &tokens)); - MOCK_METHOD0(BlockAppService, AppMgrResultCode()); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_scheduler_test/app_scheduler_test.cpp b/test/unittest/app_scheduler_test/app_scheduler_test.cpp index adcfe4b09f..4089a0ef4f 100644 --- a/test/unittest/app_scheduler_test/app_scheduler_test.cpp +++ b/test/unittest/app_scheduler_test/app_scheduler_test.cpp @@ -1075,50 +1075,6 @@ HWTEST_F(AppSchedulerTest, AppScheduler_GetAbilityRecordsByProcessID_002, TestSi DelayedSingleton::GetInstance()->appMgrClient_.reset(); } -/* - * Feature: AppScheduler - * Function: BlockAppService - * SubFunction: NA - * FunctionPoints: AppScheduler BlockAppService - * EnvConditions: NA - * CaseDescription: Verify BlockAppService - */ -#ifdef ABILITY_COMMAND_FOR_TEST -HWTEST_F(AppSchedulerTest, AppScheduler_BlockAppService_001, TestSize.Level1) -{ - clientMock_ = std::make_unique(); - EXPECT_CALL(*clientMock_, BlockAppService()).Times(1) - .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY)); - DelayedSingleton::GetInstance()->appMgrClient_ = std::move(clientMock_); - int res = DelayedSingleton::GetInstance()->BlockAppService(); - EXPECT_EQ(res, INNER_ERR); - clientMock_.reset(); - DelayedSingleton::GetInstance()->appMgrClient_.reset(); -} -#endif - -/* - * Feature: AppScheduler - * Function: BlockAppService - * SubFunction: NA - * FunctionPoints: AppScheduler BlockAppService - * EnvConditions: NA - * CaseDescription: Verify BlockAppService - */ -#ifdef ABILITY_COMMAND_FOR_TEST -HWTEST_F(AppSchedulerTest, AppScheduler_BlockAppService_002, TestSize.Level1) -{ - clientMock_ = std::make_unique(); - EXPECT_CALL(*clientMock_, BlockAppService()).Times(1) - .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY)); - DelayedSingleton::GetInstance()->appMgrClient_ = std::move(clientMock_); - int res = DelayedSingleton::GetInstance()->BlockAppService(); - EXPECT_EQ(res, INNER_ERR); - clientMock_.reset(); - DelayedSingleton::GetInstance()->appMgrClient_.reset(); -} -#endif - /** * @tc.name: SetCurrentUserId_001 * @tc.desc: set current userId. diff --git a/test/unittest/appkit/main_thread_test/main_thread_test.cpp b/test/unittest/appkit/main_thread_test/main_thread_test.cpp index 006e98ab0b..773d3d3698 100644 --- a/test/unittest/appkit/main_thread_test/main_thread_test.cpp +++ b/test/unittest/appkit/main_thread_test/main_thread_test.cpp @@ -184,13 +184,6 @@ class MockAppMgrStub : public AppMgrStub { return 0; } - #ifdef ABILITY_COMMAND_FOR_TEST - int BlockAppService() override - { - return 0; - } - #endif - int PreStartNWebSpawnProcess() override { return 0; 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 e6a5c3e490..ca66614b8d 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 @@ -5996,100 +5996,6 @@ HWTEST_F(MissionListManagerTest, GetForegroundAbilities_002, TestSize.Level1) missionListManager.reset(); } -#ifdef ABILITY_COMMAND_FOR_TEST -/* - * Feature: MissionListManager - * Function: BlockAbility - * SubFunction: NA - * FunctionPoints: MissionListManager BlockAbility - * EnvConditions: NA - * CaseDescription: Verify BlockAbility - */ -HWTEST_F(MissionListManagerTest, BlockAbility_001, TestSize.Level1) -{ - int userId = 3; - auto missionListManager = std::make_shared(userId); - EXPECT_NE(missionListManager, nullptr); - std::shared_ptr missionList = std::make_shared(); - std::shared_ptr missionList2 = std::make_shared(); - int32_t abilityRecordId = 1; - missionListManager->currentMissionLists_.push_back(missionList); - missionListManager->defaultStandardList_ = missionList; - missionListManager->defaultSingleList_ = missionList; - missionListManager->launcherList_ = missionList2; - int res = missionListManager->BlockAbility(abilityRecordId); - EXPECT_EQ(res, -1); - missionListManager.reset(); -} - -/* - * Feature: MissionListManager - * Function: BlockAbility - * SubFunction: NA - * FunctionPoints: MissionListManager BlockAbility - * EnvConditions: NA - * CaseDescription: Verify BlockAbility - */ -HWTEST_F(MissionListManagerTest, BlockAbility_002, TestSize.Level1) -{ - int userId = 3; - auto missionListManager = std::make_shared(userId); - std::shared_ptr missionList = std::make_shared(); - int32_t abilityRecordId = 1; - missionListManager->currentMissionLists_.push_back(missionList); - missionListManager->defaultStandardList_ = missionList; - missionListManager->defaultSingleList_ = missionList; - missionListManager->launcherList_ = missionList; - int res = missionListManager->BlockAbility(abilityRecordId); - EXPECT_EQ(res, -1); - missionListManager.reset(); -} - -/* - * Feature: MissionListManager - * Function: BlockAbility - * SubFunction: NA - * FunctionPoints: MissionListManager BlockAbility - * EnvConditions: NA - * CaseDescription: Verify BlockAbility - */ -HWTEST_F(MissionListManagerTest, BlockAbility_003, TestSize.Level1) -{ - int userId = 3; - auto missionListManager = std::make_shared(userId); - int32_t abilityRecordId = 1; - missionListManager->currentMissionLists_.push_back(nullptr); - missionListManager->defaultStandardList_ = nullptr; - missionListManager->defaultSingleList_ = nullptr; - missionListManager->launcherList_ = nullptr; - int res = missionListManager->BlockAbility(abilityRecordId); - EXPECT_EQ(res, -1); - missionListManager.reset(); -} - -/* - * Feature: MissionListManager - * Function: BlockAbility - * SubFunction: NA - * FunctionPoints: MissionListManager BlockAbility - * EnvConditions: NA - * CaseDescription: Verify BlockAbility - */ -HWTEST_F(MissionListManagerTest, BlockAbility_004, TestSize.Level1) -{ - int userId = 3; - auto missionListManager = std::make_shared(userId); - int32_t abilityRecordId = 1; - missionListManager->currentMissionLists_.clear(); - missionListManager->defaultStandardList_ = nullptr; - missionListManager->defaultSingleList_ = nullptr; - missionListManager->launcherList_ = nullptr; - int res = missionListManager->BlockAbility(abilityRecordId); - EXPECT_EQ(res, -1); - missionListManager.reset(); -} -#endif - /* * Feature: MissionListManager * Function: SetMissionANRStateByTokens diff --git a/test/unittest/mission_list_test/mission_list_test.cpp b/test/unittest/mission_list_test/mission_list_test.cpp index 74857787ec..9068e40013 100644 --- a/test/unittest/mission_list_test/mission_list_test.cpp +++ b/test/unittest/mission_list_test/mission_list_test.cpp @@ -951,37 +951,6 @@ HWTEST_F(MissionListTest, mission_list_dump_list_001, TestSize.Level1) missionList->DumpList(info, isClient); } -#ifdef ABILITY_COMMAND_FOR_TEST -/* - * Feature: MissionList - * Function: BlockAbilityByRecordId - * SubFunction: NA - * FunctionPoints: MissionList BlockAbilityByRecordId - * EnvConditions: NA - * CaseDescription: Verify BlockAbilityByRecordId - */ -HWTEST_F(MissionListTest, mission_block_ability_by_record_id_001, TestSize.Level1) -{ - Want want; - AppExecFwk::AbilityInfo abilityInfo; - AppExecFwk::ApplicationInfo applicationInfo; - std::shared_ptr abilityRecord = std::make_shared(want, abilityInfo, applicationInfo); - abilityRecord->recordId_ = 0; - auto mission1 = std::make_shared(1, abilityRecord, "name"); - auto mission2 = std::make_shared(1, nullptr, "name"); - auto missionList = std::make_shared(); - ASSERT_NE(missionList, nullptr); - std::vector info; - bool isClient = false; - std::vector params; - missionList->missions_.push_front(nullptr); - missionList->missions_.push_front(mission1); - missionList->missions_.push_front(mission2); - missionList->DumpStateByRecordId(info, isClient, 1, params); - missionList->DumpStateByRecordId(info, isClient, 0, params); -} -#endif - /* * Feature: MissionList * Function: GetMissionCountByUid diff --git a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h index d0de972f2b..4dde789fbd 100644 --- a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h +++ b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h @@ -320,12 +320,6 @@ public: MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); -#ifdef ABILITY_COMMAND_FOR_TEST - MOCK_METHOD0(BlockAppService, int()); - MOCK_METHOD0(BlockAmsService, int()); - MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); -#endif - int SendResultToAbility(int requestCode, int resultCode, Want& resultWant) override { return 0; diff --git a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h index 493fe7e4d4..39f25663d7 100644 --- a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h +++ b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h @@ -149,11 +149,6 @@ public: MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); -#ifdef ABILITY_COMMAND_FOR_TEST - MOCK_METHOD0(BlockAppService, int()); - MOCK_METHOD0(BlockAmsService, int()); - MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); -#endif int StartUser(int userId, sptr callback) override { diff --git a/tools/aa/include/ability_command.h b/tools/aa/include/ability_command.h index ea53f318e0..9c0c6825e5 100644 --- a/tools/aa/include/ability_command.h +++ b/tools/aa/include/ability_command.h @@ -44,9 +44,6 @@ const std::string HELP_MSG = "usage: aa \n" #ifdef ABILITY_COMMAND_FOR_TEST " test start the test framework with options\n" " ApplicationNotResponding Pass in pid with options\n" - " block-ability block ability with ability record id\n" - " block-ams-service block ams service\n" - " block-app-service block app service\n"; #else " test start the test framework with options\n" " appdebug set / cancel / get waiting debug status\n"; @@ -158,7 +155,6 @@ const std::string HELP_MSG_APPDEBUG_APP_DEBUG = " -g, --get get wait debug mode application bundle name and persist flag\n"; const std::string HELP_MSG_FORCE_STOP = "usage: aa force-stop [-p pid] [-r kill-reason]\n"; -const std::string HELP_MSG_BLOCK_ABILITY = "usage: aa block-ability \n"; const std::string HELP_MSG_FORCE_TIMEOUT = "usage: aa force-timeout \n" "usage: aa force-timeout clean."; @@ -186,15 +182,9 @@ const std::string STRING_START_USER_TEST_NG = "error: failed to start user test. const std::string STRING_USER_TEST_STARTED = "user test started."; const std::string STRING_USER_TEST_FINISHED = "user test finished."; -const std::string STRING_BLOCK_ABILITY_OK = "block ability successfully."; -const std::string STRING_BLOCK_ABILITY_NG = "error: failed to block stop ability."; - const std::string STRING_BLOCK_AMS_SERVICE_OK = "block ams service successfully."; const std::string STRING_BLOCK_AMS_SERVICE_NG = "error: failed to block ams service."; -const std::string STRING_BLOCK_APP_SERVICE_OK = "block app service successfully."; -const std::string STRING_BLOCK_APP_SERVICE_NG = "error: failed to block app service."; - const std::string STRING_APP_DEBUG_OK = "app debug successfully."; const std::string STRING_APP_DEBUG_NG = "error: failed to app debug."; @@ -259,9 +249,6 @@ private: #ifdef ABILITY_COMMAND_FOR_TEST ErrCode RunForceTimeoutForTest(); ErrCode RunAsSendAppNotRespondingProcessID(); - ErrCode RunAsBlockAbilityCommand(); - ErrCode RunAsBlockAmsServiceCommand(); - ErrCode RunAsBlockAppServiceCommand(); ErrCode RunAsSendAppNotRespondingWithUnknownOption(); ErrCode RunAsSendAppNotRespondingWithOption(int32_t option, std::string& pid); #endif diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index 5b28aaf867..2ed78c987f 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -170,9 +170,6 @@ ErrCode AbilityManagerShellCommand::CreateCommandMap() {"appdebug", [this]() { return this->RunAsAppDebugDebugCommand(); }}, #ifdef ABILITY_COMMAND_FOR_TEST {"force-timeout", [this]() { return this->RunForceTimeoutForTest(); }}, - {"block-ability", [this]() { return this->RunAsBlockAbilityCommand(); }}, - {"block-ams-service", [this]() { return this->RunAsBlockAmsServiceCommand(); }}, - {"block-app-service", [this]() { return this->RunAsBlockAppServiceCommand(); }}, #endif #ifdef ABILITY_FAULT_AND_EXIT_TEST {"forceexitapp", [this]() { return this->RunAsForceExitAppCommand(); }}, @@ -2168,59 +2165,6 @@ ErrCode AbilityManagerShellCommand::RunAsSendAppNotRespondingWithOption(int32_t } return result; } - -ErrCode AbilityManagerShellCommand::RunAsBlockAbilityCommand() -{ - TAG_LOGI(AAFwkTag::AA_TOOL, "called"); - ErrCode result = OHOS::ERR_OK; - if (argList_.size() > 0) { - result = AbilityManagerClient::GetInstance()->BlockAbility(atoi(argList_[0].c_str())); - } else { - result = OHOS::ERR_INVALID_VALUE; - } - - if (result == OHOS::ERR_OK) { - TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s", STRING_BLOCK_ABILITY_OK.c_str()); - resultReceiver_ = STRING_BLOCK_ABILITY_OK + "\n"; - } else { - TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s result: %{public}d", STRING_BLOCK_ABILITY_NG.c_str(), result); - resultReceiver_ = STRING_BLOCK_ABILITY_NG + "\n"; - resultReceiver_.append(GetMessageFromCode(result)); - } - return result; -} - -ErrCode AbilityManagerShellCommand::RunAsBlockAmsServiceCommand() -{ - TAG_LOGI(AAFwkTag::AA_TOOL, "called"); - ErrCode result = OHOS::ERR_OK; - result = AbilityManagerClient::GetInstance()->BlockAmsService(); - if (result == OHOS::ERR_OK) { - TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s", STRING_BLOCK_AMS_SERVICE_OK.c_str()); - resultReceiver_ = STRING_BLOCK_AMS_SERVICE_OK + "\n"; - } else { - TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s result: %{public}d", STRING_BLOCK_AMS_SERVICE_NG.c_str(), result); - resultReceiver_ = STRING_BLOCK_AMS_SERVICE_NG + "\n"; - resultReceiver_.append(GetMessageFromCode(result)); - } - return result; -} - -ErrCode AbilityManagerShellCommand::RunAsBlockAppServiceCommand() -{ - TAG_LOGI(AAFwkTag::AA_TOOL, "called"); - ErrCode result = OHOS::ERR_OK; - result = AbilityManagerClient::GetInstance()->BlockAppService(); - if (result == OHOS::ERR_OK) { - TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s", STRING_BLOCK_APP_SERVICE_OK.c_str()); - resultReceiver_ = STRING_BLOCK_APP_SERVICE_OK + "\n"; - } else { - TAG_LOGI(AAFwkTag::AA_TOOL, "%{public}s result: %{public}d", STRING_BLOCK_APP_SERVICE_NG.c_str(), result); - resultReceiver_ = STRING_BLOCK_APP_SERVICE_NG + "\n"; - resultReceiver_.append(GetMessageFromCode(result)); - } - return result; -} #endif #ifdef ABILITY_FAULT_AND_EXIT_TEST Reason CovertExitReason(std::string &cmd) diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index ef2d9159f9..ce9485a203 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -267,21 +267,6 @@ public: #ifdef ABILITY_COMMAND_FOR_TEST MOCK_METHOD2(ForceTimeoutForTest, int(const std::string& abilityName, const std::string& state)); - - virtual int BlockAmsService() - { - return 0; - } - - virtual int BlockAppService() - { - return 0; - } - - virtual int BlockAbility(int32_t abilityRecordId) - { - return 0; - } #endif MOCK_METHOD2(IsValidMissionIds, int32_t(const std::vector&, std::vector&)); MOCK_METHOD1(RegisterAppDebugListener, int32_t(sptr listener)); From 68d2e3b8edff7cc4147b8dc6c1be06be14abaac7 Mon Sep 17 00:00:00 2001 From: yuwenze Date: Thu, 22 Aug 2024 19:47:01 +0800 Subject: [PATCH 15/42] not kill Signed-off-by: yuwenze Change-Id: I511c26808db61a0be2e980229430b5f3f17d8187 --- services/abilitymgr/src/ability_connect_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 68e359469f..72107b656a 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -1607,7 +1607,7 @@ void AbilityConnectManager::HandleStartTimeoutTask(const std::shared_ptr &abilityRecord) { CHECK_POINTER(abilityRecord); - if (AppUtils::GetInstance().IsLauncherAbility(abilityRecord->GetAbilityInfo().name)) { + if (abilityRecord->GetAbilityInfo().name == AbilityConfig::LAUNCHER_ABILITY_NAME) { TAG_LOGD(AAFwkTag::ABILITYMGR, "Handle root launcher command timeout."); // terminate the timeout root launcher. DelayedSingleton::GetInstance()->AttachTimeOut(abilityRecord->GetToken()); @@ -2119,7 +2119,7 @@ void AbilityConnectManager::HandleInactiveTimeout(const std::shared_ptrGetAbilityInfo().name)) { + if (ability->GetAbilityInfo().name == AbilityConfig::LAUNCHER_ABILITY_NAME) { TAG_LOGD(AAFwkTag::ABILITYMGR, "Handle root launcher inactive timeout."); // terminate the timeout root launcher. DelayedSingleton::GetInstance()->AttachTimeOut(ability->GetToken()); From b835e6c64162500e6ca6a12ca8c115c7660cbb60 Mon Sep 17 00:00:00 2001 From: wangzhen Date: Thu, 22 Aug 2024 15:05:05 +0800 Subject: [PATCH 16/42] Add background condition for force-gc Signed-off-by: wangzhen --- frameworks/native/appkit/app/main_thread.cpp | 41 ++++++++----------- .../native/appkit/app/ohos_application.cpp | 9 ---- frameworks/native/runtime/js_runtime.cpp | 13 ------ .../inner_api/runtime/include/cj_runtime.h | 1 - .../inner_api/runtime/include/js_runtime.h | 1 - .../inner_api/runtime/include/runtime.h | 2 +- .../kits/native/appkit/app/application_impl.h | 2 +- .../kits/native/appkit/app/main_thread.h | 3 +- .../kits/native/appkit/app/ohos_application.h | 5 +-- services/abilitymgr/include/ability_util.h | 6 +++ .../mock_runtime.h | 1 - .../ohos_application_test.cpp | 6 +-- .../cj_runtime_test/cj_mock_runtime.h | 2 - .../cj_test_runner_test/cj_mock_runtime.h | 2 - .../unittest/runtime_test/js_runtime_test.cpp | 20 --------- 15 files changed, 31 insertions(+), 83 deletions(-) diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 118c11d8f1..91f3dc25b2 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -2093,17 +2093,10 @@ void MainThread::HandleCleanAbilityLocal(const sptr &token) } std::shared_ptr record = abilityRecordMgr_->GetAbilityItem(token); - if (record == nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "abilityRecord not found"); - return; - } + CHECK_POINTER_TAG_LOG(record, AAFwkTag::APPKIT, "abilityRecord not found"); std::shared_ptr abilityInfo = record->GetAbilityInfo(); - if (abilityInfo == nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "record->GetAbilityInfo() failed"); - return; - } + CHECK_POINTER_TAG_LOG(abilityInfo, AAFwkTag::APPKIT, "record->GetAbilityInfo() failed"); TAG_LOGD(AAFwkTag::APPKIT, "ability name: %{public}s", abilityInfo->name.c_str()); - abilityRecordMgr_->RemoveAbilityRecord(token); application_->CleanAbilityStage(token, abilityInfo, false); #ifdef APP_ABILITY_USE_TWO_RUNNER @@ -2119,6 +2112,7 @@ void MainThread::HandleCleanAbilityLocal(const sptr &token) TAG_LOGW(AAFwkTag::APPKIT, "runner not found"); } #endif + AfterCleanAbilityGC(); } /** @@ -2141,29 +2135,16 @@ void MainThread::HandleCleanAbility(const sptr &token, bool isCac TAG_LOGE(AAFwkTag::APPKIT, "should launch application first"); return; } - - if (token == nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "token is null"); - return; - } - + CHECK_POINTER_TAG_LOG(token, AAFwkTag::APPKIT, "token is null"); std::shared_ptr record = abilityRecordMgr_->GetAbilityItem(token); - if (record == nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "abilityRecord not found"); - return; - } + CHECK_POINTER_TAG_LOG(record, AAFwkTag::APPKIT, "abilityRecord not found"); std::shared_ptr abilityInfo = record->GetAbilityInfo(); - if (abilityInfo == nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "record->GetAbilityInfo() failed"); - return; - } - + CHECK_POINTER_TAG_LOG(abilityInfo, AAFwkTag::APPKIT, "record->GetAbilityInfo() failed"); #ifdef SUPPORT_GRAPHICS if (abilityInfo->type == AbilityType::PAGE && abilityInfo->isStageBasedModel) { AppRecovery::GetInstance().RemoveAbility(token); } #endif - abilityRecordMgr_->RemoveAbilityRecord(token); application_->CleanAbilityStage(token, abilityInfo, isCacheProcess); #ifdef APP_ABILITY_USE_TWO_RUNNER @@ -2180,10 +2161,20 @@ void MainThread::HandleCleanAbility(const sptr &token, bool isCac } #endif appMgr_->AbilityCleaned(token); + AfterCleanAbilityGC(); TAG_LOGD(AAFwkTag::APPKIT, "end. app: %{public}s, ability: %{public}s.", applicationInfo_->name.c_str(), abilityInfo->name.c_str()); } +void MainThread::AfterCleanAbilityGC() +{ + bool appBackground = applicationImpl_ ? + applicationImpl_->GetState() != ApplicationImpl::APP_STATE_FOREGROUND : false; + if (appBackground) { + ForceFullGC(); + } +} + /** * * @brief Foreground the application. diff --git a/frameworks/native/appkit/app/ohos_application.cpp b/frameworks/native/appkit/app/ohos_application.cpp index c7b9dd96cd..8dd0a120c5 100644 --- a/frameworks/native/appkit/app/ohos_application.cpp +++ b/frameworks/native/appkit/app/ohos_application.cpp @@ -812,15 +812,6 @@ void OHOSApplication::CleanAbilityStage(const sptr &token, abilityStage->OnDestroy(); abilityStages_.erase(moduleName); } - DoCleanWorkAfterStageCleaned(*abilityInfo); - } -} - -void OHOSApplication::DoCleanWorkAfterStageCleaned(const AbilityInfo &abilityInfo) -{ - TAG_LOGD(AAFwkTag::APPKIT, "language: %{public}s", abilityInfo.srcLanguage.c_str()); - if (runtime_) { - runtime_->DoCleanWorkAfterStageCleaned(); } } diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 620c811a83..bff65bfc14 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -79,7 +79,6 @@ constexpr size_t PARAM_TWO = 2; constexpr uint8_t SYSCAP_MAX_SIZE = 100; constexpr int64_t DEFAULT_GC_POOL_SIZE = 0x10000000; // 256MB constexpr int32_t DEFAULT_INTER_VAL = 500; -constexpr int32_t TRIGGER_GC_AFTER_CLEAR_STAGE_MS = 3000; constexpr int32_t API8 = 8; const std::string SANDBOX_ARK_CACHE_PATH = "/data/storage/ark-cache/"; const std::string SANDBOX_ARK_PROIFILE_PATH = "/data/storage/ark-profile"; @@ -914,18 +913,6 @@ void JsRuntime::ReloadFormComponent() #endif } -void JsRuntime::DoCleanWorkAfterStageCleaned() -{ - // Force gc. If the jsRuntime is destroyed, this task should not be executed. - TAG_LOGD(AAFwkTag::JSRUNTIME, "called"); - RemoveTask("ability_destruct_gc"); - auto gcTask = [this]() { - panda::JSNApi::TriggerGC(GetEcmaVm(), panda::ecmascript::GCReason::TRIGGER_BY_ABILITY, - panda::JSNApi::TRIGGER_GC_TYPE::FULL_GC); - }; - PostTask(gcTask, "ability_destruct_gc", TRIGGER_GC_AFTER_CLEAR_STAGE_MS); -} - bool JsRuntime::InitLoop(bool isStage) { CHECK_POINTER_AND_RETURN(jsEnv_, false); diff --git a/interfaces/inner_api/runtime/include/cj_runtime.h b/interfaces/inner_api/runtime/include/cj_runtime.h index 91575a953c..de2b588fd9 100644 --- a/interfaces/inner_api/runtime/include/cj_runtime.h +++ b/interfaces/inner_api/runtime/include/cj_runtime.h @@ -55,7 +55,6 @@ public: bool UnLoadRepairPatch(const std::string& patchFile) override { return false; } void RegisterQuickFixQueryFunc(const std::map& moduleAndPath) override {}; void StartProfiler(const DebugOption debugOption) override {}; - void DoCleanWorkAfterStageCleaned() override {}; void SetModuleLoadChecker(const std::shared_ptr moduleCheckerDelegate) const override {} void SetDeviceDisconnectCallback(const std::function &cb) override {}; bool IsAppLibLoaded() const { return appLibLoaded_; } diff --git a/interfaces/inner_api/runtime/include/js_runtime.h b/interfaces/inner_api/runtime/include/js_runtime.h index 7798fa28a8..0aaf1e8ca0 100644 --- a/interfaces/inner_api/runtime/include/js_runtime.h +++ b/interfaces/inner_api/runtime/include/js_runtime.h @@ -127,7 +127,6 @@ public: void DebuggerConnectionManager(bool isDebugApp, bool isStartWithDebug, const DebugOption dOption); void ReloadFormComponent(); // Reload ArkTS-Card component - void DoCleanWorkAfterStageCleaned() override; void SetModuleLoadChecker(const std::shared_ptr moduleCheckerDelegate) const override; static std::unique_ptr LoadSystemModuleByEngine(napi_env env, diff --git a/interfaces/inner_api/runtime/include/runtime.h b/interfaces/inner_api/runtime/include/runtime.h index 3ef3114825..5a30a11704 100644 --- a/interfaces/inner_api/runtime/include/runtime.h +++ b/interfaces/inner_api/runtime/include/runtime.h @@ -103,7 +103,7 @@ public: virtual bool UnLoadRepairPatch(const std::string& patchFile) = 0; virtual void RegisterQuickFixQueryFunc(const std::map& moduleAndPath) = 0; virtual void StartProfiler(const DebugOption debugOption) = 0; - virtual void DoCleanWorkAfterStageCleaned() = 0; + virtual void DoCleanWorkAfterStageCleaned() {} 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; diff --git a/interfaces/kits/native/appkit/app/application_impl.h b/interfaces/kits/native/appkit/app/application_impl.h index ad2df98b63..0b8cc681fe 100644 --- a/interfaces/kits/native/appkit/app/application_impl.h +++ b/interfaces/kits/native/appkit/app/application_impl.h @@ -131,7 +131,6 @@ public: */ void PerformConfigurationUpdated(const Configuration &config); -private: enum { APP_STATE_CREATE = 0, APP_STATE_READY = 1, @@ -139,6 +138,7 @@ private: APP_STATE_BACKGROUND = 3, APP_STATE_TERMINATED = 4 }; +private: int curState_; int recordId_; std::shared_ptr application_ = nullptr; diff --git a/interfaces/kits/native/appkit/app/main_thread.h b/interfaces/kits/native/appkit/app/main_thread.h index 9932b43894..996bc9af75 100644 --- a/interfaces/kits/native/appkit/app/main_thread.h +++ b/interfaces/kits/native/appkit/app/main_thread.h @@ -425,6 +425,7 @@ private: * */ void HandleCleanAbility(const sptr &token, bool isCacheProcess = false); + void AfterCleanAbilityGC(); /** * @@ -672,7 +673,7 @@ private: */ void LoadAbilityLibrary(const std::vector &libraryPaths); void LoadAceAbilityLibrary(); - + void CalcNativeLiabraryEntries(const BundleInfo &bundleInfo, std::string &nativeLibraryPath); void LoadNativeLiabrary(const BundleInfo &bundleInfo, std::string &nativeLibraryPath); diff --git a/interfaces/kits/native/appkit/app/ohos_application.h b/interfaces/kits/native/appkit/app/ohos_application.h index f7ee5b1dab..3ab26f5426 100644 --- a/interfaces/kits/native/appkit/app/ohos_application.h +++ b/interfaces/kits/native/appkit/app/ohos_application.h @@ -176,7 +176,7 @@ 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. @@ -255,7 +255,7 @@ public: * @param abilityInfo */ void CleanAbilityStage(const sptr &token, const std::shared_ptr &abilityInfo, - bool isCacheProcess = false); + bool isCacheProcess); /** * @brief return the application context @@ -318,7 +318,6 @@ public: void CleanEmptyAbilityStage(); private: - void DoCleanWorkAfterStageCleaned(const AbilityInfo &abilityInfo); void UpdateAppContextResMgr(const Configuration &config); bool isUpdateColor(Configuration &config, std::string colorMode, std::string globalColorMode, std::string globalColorModeIsSetBySa, std::string colorModeIsSetByApp, std::string colorModeIsSetBySa); diff --git a/services/abilitymgr/include/ability_util.h b/services/abilitymgr/include/ability_util.h index a247454029..3816fd9093 100644 --- a/services/abilitymgr/include/ability_util.h +++ b/services/abilitymgr/include/ability_util.h @@ -76,6 +76,12 @@ constexpr const char* JUMP_INTERCEPTOR_DIALOG_CALLER_PKG = "interceptor_callerPk return; \ } +#define CHECK_POINTER_TAG_LOG(object, tag, log) \ + if (!object) { \ + TAG_LOGE(tag, "%{public}s:", log); \ + return; \ + } + #define CHECK_POINTER_AND_RETURN(object, value) \ if (!object) { \ TAG_LOGE(AAFwkTag::ABILITYMGR, "nullptr"); \ diff --git a/test/mock/frameworks_kits_runtime_test/mock_runtime.h b/test/mock/frameworks_kits_runtime_test/mock_runtime.h index f8250b441e..eecc08bded 100644 --- a/test/mock/frameworks_kits_runtime_test/mock_runtime.h +++ b/test/mock/frameworks_kits_runtime_test/mock_runtime.h @@ -117,7 +117,6 @@ public: void StartProfiler(const DebugOption debugOption) override {} - void DoCleanWorkAfterStageCleaned() override {} void DumpHeapSnapshot(uint32_t tid, bool isFullGC) override {} void ForceFullGC(uint32_t tid) override {} void UpdatePkgContextInfoJson(std::string moduleName, std::string hapPath, std::string packageName) override {} diff --git a/test/unittest/appkit/ohos_application_test/ohos_application_test.cpp b/test/unittest/appkit/ohos_application_test/ohos_application_test.cpp index 257f537eb9..9d772e83a7 100644 --- a/test/unittest/appkit/ohos_application_test/ohos_application_test.cpp +++ b/test/unittest/appkit/ohos_application_test/ohos_application_test.cpp @@ -1087,7 +1087,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_CleanAbilityStage_0 GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_CleanAbilityStage_0100 start."; std::shared_ptr abilityInfo = nullptr; sptr token = new (std::nothrow) Notification::MockIRemoteObject(); - ohosApplication_->CleanAbilityStage(token, abilityInfo); + ohosApplication_->CleanAbilityStage(token, abilityInfo, false); EXPECT_TRUE(abilityInfo == nullptr); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_CleanAbilityStage_0100 end."; } @@ -1102,7 +1102,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_CleanAbilityStage_0 GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_CleanAbilityStage_0200 start."; std::shared_ptr abilityInfo = std::make_shared(); sptr token = nullptr; - ohosApplication_->CleanAbilityStage(token, abilityInfo); + ohosApplication_->CleanAbilityStage(token, abilityInfo, false); EXPECT_TRUE(token == nullptr); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_CleanAbilityStage_0200 end."; } @@ -1122,7 +1122,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_CleanAbilityStage_0 sptr token = new (std::nothrow) Notification::MockIRemoteObject(); ohosApplication_->abilityStages_.emplace(abilityInfo->moduleName, abilityStage); EXPECT_FALSE(ohosApplication_->abilityStages_.empty()); - ohosApplication_->CleanAbilityStage(token, abilityInfo); + ohosApplication_->CleanAbilityStage(token, abilityInfo, false); EXPECT_TRUE(ohosApplication_->abilityStages_.empty()); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_CleanAbilityStage_0300 end."; } diff --git a/test/unittest/cj_runtime_test/cj_mock_runtime.h b/test/unittest/cj_runtime_test/cj_mock_runtime.h index 6053d522f0..f3517b28b1 100644 --- a/test/unittest/cj_runtime_test/cj_mock_runtime.h +++ b/test/unittest/cj_runtime_test/cj_mock_runtime.h @@ -103,8 +103,6 @@ public: } void StartProfiler(const DebugOption debugOption) override {} - - void DoCleanWorkAfterStageCleaned() override {} public: Language language; }; diff --git a/test/unittest/cj_test_runner_test/cj_mock_runtime.h b/test/unittest/cj_test_runner_test/cj_mock_runtime.h index 626d20740f..b4e40340a7 100644 --- a/test/unittest/cj_test_runner_test/cj_mock_runtime.h +++ b/test/unittest/cj_test_runner_test/cj_mock_runtime.h @@ -99,8 +99,6 @@ public: { return; } - - void DoCleanWorkAfterStageCleaned() 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 ff22f943bc..386b206248 100755 --- a/test/unittest/runtime_test/js_runtime_test.cpp +++ b/test/unittest/runtime_test/js_runtime_test.cpp @@ -1130,26 +1130,6 @@ HWTEST_F(JsRuntimeTest, StartDebugger_0100, TestSize.Level0) TAG_LOGI(AAFwkTag::TEST, "StartDebugger_0100 end"); } -/** - * @tc.name: DoCleanWorkAfterStageCleaned_0100 - * @tc.desc: JsRuntime test for DoCleanWorkAfterStageCleaned. - * @tc.type: FUNC - */ -HWTEST_F(JsRuntimeTest, DoCleanWorkAfterStageCleaned_0100, TestSize.Level0) -{ - TAG_LOGI(AAFwkTag::TEST, "DoCleanWorkAfterStageCleaned_0100 start"); - - AbilityRuntime::Runtime::Options options; - options.preload = true; - auto jsRuntime = AbilityRuntime::JsRuntime::Create(options); - - ASSERT_NE(jsRuntime, nullptr); - - jsRuntime->DoCleanWorkAfterStageCleaned(); - jsRuntime.reset(); - TAG_LOGI(AAFwkTag::TEST, "DoCleanWorkAfterStageCleaned_0100 end"); -} - /** * @tc.name: ReloadFormComponent_0100 * @tc.desc: JsRuntime test for ReloadFormComponent. From f2ad42f2b487c3202b5309e1e4d1392ed3b8709d Mon Sep 17 00:00:00 2001 From: xia Date: Thu, 22 Aug 2024 22:07:44 +0800 Subject: [PATCH 17/42] =?UTF-8?q?=E4=BF=AE=E5=A4=8DserviceExtension?= =?UTF-8?q?=EF=BC=8CAppId=E8=A2=AB=E6=B8=85=E7=90=86=E8=BF=87=E6=97=A9?= =?UTF-8?q?=EF=BC=8ConRequest=E5=92=8ConConnect=E5=9B=9E=E8=B0=83=E7=9A=84?= =?UTF-8?q?want=E6=B2=A1=E6=9C=89AppId=E4=BF=A1=E6=81=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xia --- services/abilitymgr/src/ability_connect_manager.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index d505e991fd..f9bd1fcb5f 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -689,10 +689,12 @@ void AbilityConnectManager::HandleActiveAbility(std::shared_ptr & int connectRecordId = connectRecord->GetRecordId(); ConnectUIServiceExtAbility(targetService, connectRecordId, want); } + targetService->RemoveSignatureInfo(); return; } if (targetService->GetConnectRecordList().size() > 1) { + targetService->RemoveSignatureInfo(); if (taskHandler_ != nullptr && targetService->GetConnRemoteObject()) { auto task = [connectRecord]() { connectRecord->CompleteConnect(ERR_OK); }; taskHandler_->SubmitTask(task, TaskQoS::USER_INTERACTIVE); @@ -941,7 +943,6 @@ int AbilityConnectManager::AbilityTransitionDone(const sptr &toke } CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); - abilityRecord->RemoveSignatureInfo(); std::string element = abilityRecord->GetURI(); TAG_LOGI(AAFwkTag::ABILITYMGR, "Ability:%{public}s, state:%{public}s", element.c_str(), abilityState.c_str()); @@ -968,6 +969,7 @@ int AbilityConnectManager::AbilityTransitionDone(const sptr &toke return DispatchInactive(abilityRecord, state); } case AbilityState::FOREGROUND: { + abilityRecord->RemoveSignatureInfo(); return DispatchForeground(abilityRecord); } case AbilityState::BACKGROUND: { @@ -1032,6 +1034,7 @@ int AbilityConnectManager::ScheduleConnectAbilityDoneLocked( return INVALID_CONNECTION_STATE; } abilityRecord->RemoveConnectWant(); + abilityRecord->RemoveSignatureInfo(); if (abilityRecord->GetAbilityInfo().type == AbilityType::SERVICE) { DelayedSingleton::GetInstance()->UpdateAbilityState( @@ -1177,6 +1180,7 @@ int AbilityConnectManager::ScheduleCommandAbilityDoneLocked(const sptrRemoveSignatureInfo(); // complete command and pop waiting start ability from queue. CompleteCommandAbility(abilityRecord); From e43d6b31e7719035472cdb9d8e94da84604d43bc Mon Sep 17 00:00:00 2001 From: jsjzju Date: Thu, 22 Aug 2024 22:58:15 +0800 Subject: [PATCH 18/42] =?UTF-8?q?=E9=95=BF=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E7=BB=95=E8=BF=87=E5=90=8E=E5=8F=B0=E6=8B=89?= =?UTF-8?q?=E8=B5=B7=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jsjzju Change-Id: Icc8796248f884b33a036862e5bd2dd8a750d82c6 --- services/common/src/permission_verification.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/services/common/src/permission_verification.cpp b/services/common/src/permission_verification.cpp index 403f5ed918..1e9dbfb57f 100644 --- a/services/common/src/permission_verification.cpp +++ b/services/common/src/permission_verification.cpp @@ -364,11 +364,6 @@ bool PermissionVerification::JudgeStartAbilityFromBackground( return true; } - if (withContinuousTask) { - TAG_LOGD(AAFwkTag::DEFAULT, "continuousTask: true"); - return true; - } - // Temporarily supports permissions with two different spellings // PERMISSION_START_ABILIIES_FROM_BACKGROUND will be removed later due to misspelling if (VerifyCallingPermission(PermissionConstants::PERMISSION_START_ABILITIES_FROM_BACKGROUND) || From 292314160b90eb23950a9f1a3f01b3fdf5729747 Mon Sep 17 00:00:00 2001 From: chenzexin Date: Thu, 22 Aug 2024 23:00:53 +0800 Subject: [PATCH 19/42] =?UTF-8?q?=E2=80=9Cfix=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenzexin --- .../js_ui_extension_base.cpp | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp index d5f024de82..b280af73fb 100644 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp @@ -231,7 +231,7 @@ void JsUIExtensionBase::OnStop() HandleScope handleScope(jsRuntime_); CallObjectMethod("onDestroy"); OnStopCallBack(); - TAG_LOGD(AAFwkTag::UI_EXT, "JsUIExtension OnStop end."); + TAG_LOGD(AAFwkTag::UI_EXT, "end"); } void JsUIExtensionBase::OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, bool &isAsyncCallback) @@ -242,7 +242,7 @@ void JsUIExtensionBase::OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *cal return; } HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - TAG_LOGD(AAFwkTag::UI_EXT, "OnStop begin."); + TAG_LOGD(AAFwkTag::UI_EXT, "begin"); HandleScope handleScope(jsRuntime_); napi_value result = CallObjectMethod("onDestroy", nullptr, 0, true); if (!CheckPromise(result)) { @@ -251,11 +251,10 @@ void JsUIExtensionBase::OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *cal return; } - std::weak_ptr weakPtr = shared_from_this(); - auto asyncCallback = [extensionWeakPtr = weakPtr]() { + auto asyncCallback = [extensionWeakPtr = weak_from_this()]() { auto jsUIExtensionBase = extensionWeakPtr.lock(); if (jsUIExtensionBase == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "extension is nullptr."); + TAG_LOGE(AAFwkTag::UI_EXT, "extension is nullptr"); return; } jsUIExtensionBase->OnStopCallBack(); @@ -263,10 +262,10 @@ void JsUIExtensionBase::OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *cal callbackInfo->Push(asyncCallback); isAsyncCallback = CallPromise(result, callbackInfo); if (!isAsyncCallback) { - TAG_LOGE(AAFwkTag::UI_EXT, "Failed to call promise."); + TAG_LOGE(AAFwkTag::UI_EXT, "Failed to call promise"); OnStopCallBack(); } - TAG_LOGD(AAFwkTag::UI_EXT, "OnStop end."); + TAG_LOGD(AAFwkTag::UI_EXT, "end"); } void JsUIExtensionBase::OnStopCallBack() @@ -275,10 +274,10 @@ void JsUIExtensionBase::OnStopCallBack() TAG_LOGE(AAFwkTag::UI_EXT, "Failed to get context"); return; } - bool ret = ConnectionManager::GetInstance().DisconnectCaller(context_->GetToken()); + auto ret = ConnectionManager::GetInstance().DisconnectCaller(context_->GetToken()); if (ret) { ConnectionManager::GetInstance().ReportConnectionLeakEvent(getpid(), gettid()); - TAG_LOGD(AAFwkTag::UI_EXT, "The service connection is not disconnected."); + TAG_LOGD(AAFwkTag::UI_EXT, "service connection not disconnected"); } auto applicationContext = Context::GetApplicationContext(); @@ -290,14 +289,14 @@ void JsUIExtensionBase::OnStopCallBack() bool JsUIExtensionBase::CheckPromise(napi_value result) { if (result == nullptr) { - TAG_LOGD(AAFwkTag::UI_EXT, "result is null, no need to call promise."); + TAG_LOGD(AAFwkTag::UI_EXT, "result is nullptr"); return false; } napi_env env = jsRuntime_.GetNapiEnv(); bool isPromise = false; napi_is_promise(env, result, &isPromise); if (!isPromise) { - TAG_LOGD(AAFwkTag::UI_EXT, "result is not promise, no need to call promise."); + TAG_LOGD(AAFwkTag::UI_EXT, "result isn't promise"); return false; } return true; @@ -310,7 +309,7 @@ napi_value PromiseCallback(napi_env env, napi_callback_info info) NAPI_CALL_NO_THROW(napi_get_cb_info(env, info, nullptr, nullptr, nullptr, &data), nullptr); auto *callbackInfo = static_cast *>(data); if (callbackInfo == nullptr) { - TAG_LOGD(AAFwkTag::UI_EXT, "Invalid input info."); + TAG_LOGD(AAFwkTag::UI_EXT, "Invalid input"); return nullptr; } callbackInfo->Call(); @@ -324,27 +323,35 @@ bool JsUIExtensionBase::CallPromise(napi_value result, AppExecFwk::AbilityTransa { auto env = jsRuntime_.GetNapiEnv(); if (!CheckTypeForNapiValue(env, result, napi_object)) { - TAG_LOGE(AAFwkTag::UI_EXT, "Failed to convert native value to NativeObject."); + TAG_LOGE(AAFwkTag::UI_EXT, "Failed to convert native value to NativeObject"); return false; } napi_value then = nullptr; napi_get_named_property(env, result, "then", &then); if (then == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "Failed to get property: then."); + TAG_LOGE(AAFwkTag::UI_EXT, "Failed to get property: then"); return false; } bool isCallable = false; napi_is_callable(env, then, &isCallable); if (!isCallable) { - TAG_LOGE(AAFwkTag::UI_EXT, "property then is not callable."); + TAG_LOGE(AAFwkTag::UI_EXT, "property then is not callable"); return false; } HandleScope handleScope(jsRuntime_); napi_value promiseCallback = nullptr; - napi_create_function(env, "promiseCallback", strlen("promiseCallback"), PromiseCallback, + napi_status createStatus = napi_create_function(env, "promiseCallback", strlen("promiseCallback"), PromiseCallback, callbackInfo, &promiseCallback); + if(createStatus != napi_ok) { + TAG_LOGE("Failed to create promiseCallback, %{public}d", createStatus); + return false; + } napi_value argv[1] = { promiseCallback }; - napi_call_function(env, result, then, 1, argv, nullptr); + napi_status callStatus = napi_call_function(env, result, then, 1, argv, nullptr); + if(callStatus != napi_ok) { + TAG_LOGE("Failed to call promiseCallback, %{public}d", callStatus); + return false; + } TAG_LOGD(AAFwkTag::UI_EXT, "exit"); return true; } From 13829477ce55a19b633891cd6df94860408d6674 Mon Sep 17 00:00:00 2001 From: chenzexin Date: Thu, 22 Aug 2024 23:07:14 +0800 Subject: [PATCH 20/42] =?UTF-8?q?=E2=80=9Cfix=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenzexin --- .../native/ui_extension_ability/js_ui_extension_base.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp index b280af73fb..e0bbbacead 100644 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp @@ -230,6 +230,10 @@ void JsUIExtensionBase::OnStop() TAG_LOGD(AAFwkTag::UI_EXT, "called"); HandleScope handleScope(jsRuntime_); CallObjectMethod("onDestroy"); +#ifdef SUPPORT_GRAPHICS + UnregisterDisplayInfoChangedListener(); +#endif // SUPPORT_GRAPHICS + OnStopCallBack(); TAG_LOGD(AAFwkTag::UI_EXT, "end"); } From 6760c8173445d5d17fc11872cfd084b3fd4b154a Mon Sep 17 00:00:00 2001 From: "zhangyafei.echo" Date: Thu, 22 Aug 2024 22:00:28 +0800 Subject: [PATCH 21/42] Description: add uiextension ability background check. Sig:SIG_ApplicationFramework Feature or BugFix: Feature Binary Source: No Signed-off-by: zhangyafei.echo Change-Id: I5cf7c5cef6eec95445772c5608b6eca300b7e34f --- .../src/ability_manager_service.cpp | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 14b8e95c5d..83e8a69d3f 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -9427,15 +9427,19 @@ bool AbilityManagerService::CheckUIExtensionCallerIsForeground(const AbilityRequ return true; } - // Check caller ability firstly. + bool isBackgroundCall = true; + auto ret = IsCallFromBackground(abilityRequest, isBackgroundCall); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::UI_EXT, "start uea when background"); + return false; + } + + if (!isBackgroundCall) { + return true; + } + auto callerAbility = Token::GetAbilityRecordByToken(abilityRequest.callerToken); if (callerAbility != nullptr) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "Caller ability is %{public}s, state: %{public}d", - callerAbility->GetURI().c_str(), callerAbility->GetAbilityState()); - if (callerAbility->IsForeground() || callerAbility->GetAbilityForegroundingFlag()) { - return true; - } - if (UIExtensionUtils::IsUIExtension(callerAbility->GetAbilityInfo().extensionAbilityType)) { auto tokenId = callerAbility->GetApplicationInfo().accessTokenId; bool isFocused = false; @@ -9450,23 +9454,13 @@ bool AbilityManagerService::CheckUIExtensionCallerIsForeground(const AbilityRequ } } - // Check caller app. - auto callerPid = IPCSkeleton::GetCallingPid(); - AppExecFwk::RunningProcessInfo processInfo; - DelayedSingleton::GetInstance()->GetRunningProcessInfoByPid(callerPid, processInfo); - if (processInfo.isFocused || processInfo.isAbilityForegrounding || - processInfo.state_ == AppExecFwk::AppProcessState::APP_STATE_FOREGROUND) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "Caller app %{public}s is foreground", processInfo.processName_.c_str()); - return true; - } - if (PermissionVerification::GetInstance()->VerifyCallingPermission( PermissionConstants::PERMISSION_START_ABILITIES_FROM_BACKGROUND)) { return true; } - TAG_LOGE(AAFwkTag::ABILITYMGR, "Caller app %{public}s is not foreground, can't start %{public}s", - processInfo.processName_.c_str(), abilityRequest.want.GetElement().GetURI().c_str()); + TAG_LOGE(AAFwkTag::ABILITYMGR, "Caller app is not foreground, can't start %{public}s", + abilityRequest.want.GetElement().GetURI().c_str()); return false; } From 968a5a68a60da700e0382e6dea6e5462bb73b6d8 Mon Sep 17 00:00:00 2001 From: zhangyuhang72 Date: Fri, 23 Aug 2024 09:53:58 +0800 Subject: [PATCH 22/42] =?UTF-8?q?ProcessStartFailed=E6=89=93=E7=82=B9?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangyuhang72 Change-Id: I87024366f899fd45017efe16697480ee77371f2b --- services/common/src/event_report.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/common/src/event_report.cpp b/services/common/src/event_report.cpp index 0926b13cb6..4289fde613 100644 --- a/services/common/src/event_report.cpp +++ b/services/common/src/event_report.cpp @@ -489,7 +489,7 @@ void EventReport::SendProcessStartFailedEvent(const EventName &eventName, const HiSysEventWrite( HiSysEvent::Domain::AAFWK, name, - HiSysEventType::BEHAVIOR, + HiSysEventType::FAULT, EVENT_KEY_STARTUP_TIME, eventInfo.time, EVENT_KEY_STARTUP_ABILITY_TYPE, eventInfo.abilityType, EVENT_KEY_CALLER_BUNDLE_NAME, eventInfo.callerBundleName, @@ -505,7 +505,7 @@ void EventReport::SendProcessStartFailedEvent(const EventName &eventName, const HiSysEventWrite( HiSysEvent::Domain::AAFWK, name, - HiSysEventType::BEHAVIOR, + HiSysEventType::FAULT, EVENT_KEY_STARTUP_TIME, eventInfo.time, EVENT_KEY_STARTUP_ABILITY_TYPE, eventInfo.abilityType, EVENT_KEY_STARTUP_EXTENSION_TYPE, eventInfo.extensionType, From 7bcd27dc838430994db4797cdf11dc40880d2fab Mon Sep 17 00:00:00 2001 From: chenzexin Date: Fri, 23 Aug 2024 02:12:13 +0000 Subject: [PATCH 23/42] fix log Signed-off-by: chenzexin --- .../native/ui_extension_ability/js_ui_extension_base.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp index 14b9affd3e..d67caba6dd 100644 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp @@ -360,14 +360,14 @@ bool JsUIExtensionBase::CallPromise(napi_value result, AppExecFwk::AbilityTransa napi_value promiseCallback = nullptr; napi_status createStatus = napi_create_function(env, "promiseCallback", strlen("promiseCallback"), PromiseCallback, callbackInfo, &promiseCallback); - if(createStatus != napi_ok) { - TAG_LOGE("Failed to create promiseCallback, %{public}d", createStatus); + if (createStatus != napi_ok) { + TAG_LOGE(AAFwkTag::UI_EXT, "Failed to create promiseCallback, %{public}d", createStatus); return false; } napi_value argv[1] = { promiseCallback }; napi_status callStatus = napi_call_function(env, result, then, 1, argv, nullptr); - if(callStatus != napi_ok) { - TAG_LOGE("Failed to call promiseCallback, %{public}d", callStatus); + if (callStatus != napi_ok) { + TAG_LOGE(AAFwkTag::UI_EXT, "Failed to call promiseCallback, %{public}d", callStatus); return false; } TAG_LOGD(AAFwkTag::UI_EXT, "exit"); From d260036894782fb2ce37cc280f00b9d619baebf4 Mon Sep 17 00:00:00 2001 From: yangxuguang-huawei Date: Thu, 22 Aug 2024 16:14:32 +0800 Subject: [PATCH 24/42] feat: get all children processes Signed-off-by: yangxuguang-huawei --- .../include/appmgr/app_mgr_client.h | 9 ++ .../include/appmgr/app_mgr_interface.h | 9 ++ .../appmgr/app_mgr_ipc_interface_code.h | 1 + .../include/appmgr/app_mgr_proxy.h | 9 ++ .../app_manager/include/appmgr/app_mgr_stub.h | 1 + .../include/appmgr/child_process_info.h | 2 + .../app_manager/src/appmgr/app_mgr_client.cpp | 15 ++++ .../app_manager/src/appmgr/app_mgr_proxy.cpp | 20 +++++ .../app_manager/src/appmgr/app_mgr_stub.cpp | 21 +++++ .../src/appmgr/child_process_info.cpp | 10 +++ services/appmgr/include/app_mgr_service.h | 9 ++ .../appmgr/include/app_mgr_service_inner.h | 14 ++- services/appmgr/src/app_mgr_service.cpp | 8 ++ services/appmgr/src/app_mgr_service_inner.cpp | 86 ++++++++++++++++--- .../include/mock_app_mgr_service.h | 5 ++ .../include/mock_app_mgr_service_inner.h | 1 + .../include/mock_app_mgr_service.h | 1 + .../include/mock_app_mgr_service_inner.h | 1 + .../app_scheduler_test/app_mgr_client_mock.h | 1 + 19 files changed, 210 insertions(+), 13 deletions(-) diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h index e9d7879d0a..6ea877d7ff 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h @@ -257,6 +257,15 @@ public: */ virtual AppMgrResultCode GetAllRenderProcesses(std::vector &info); + /** + * GetAllChildrenProcesses, call GetAllChildrenProcesses() through proxy project. + * Obtains information about children processes that are running on the device. + * + * @param info, child process info. + * @return ERR_OK, return back success, others fail. + */ + virtual AppMgrResultCode GetAllChildrenProcesses(std::vector &info); + /** * NotifyMemoryLevel, call NotifyMemoryLevel() through proxy project. * Notify abilities background the current memory level. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index 3f0a18d704..c38614e7cf 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -177,6 +177,15 @@ public: */ virtual int GetAllRenderProcesses(std::vector &info) = 0; + /** + * GetAllChildrenProcesses, call GetAllChildrenProcesses() through proxy project. + * Obtains information about children processes that are running on the device. + * + * @param info, child process info. + * @return ERR_OK, return back success, others fail. + */ + virtual int GetAllChildrenProcesses(std::vector &info) = 0; + /** * JudgeSandboxByPid, call JudgeSandboxByPid() through proxy project. * Obtains information about application processes that are running on the device. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h index b2e5a4762c..43e7901517 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h @@ -112,6 +112,7 @@ enum class AppMgrInterfaceCode { KILL_PROCESS_DEPENDED_ON_WEB = 85, RESTART_RESIDENT_PROCESS_DEPENDED_ON_WEB = 86, GET_SUPPORTED_PROCESS_CACHE_PIDS = 87, + GET_ALL_CHILDREN_PROCESSES = 88, }; } // AppExecFwk } // OHOS diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h index 11a3a6f5fb..b2ef4400ba 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h @@ -155,6 +155,15 @@ public: */ virtual int32_t GetAllRenderProcesses(std::vector &info) override; + /** + * GetAllChildrenProcesses, call GetAllChildrenProcesses() through proxy project. + * Obtains information about children processes that are running on the device. + * + * @param info, child process info. + * @return ERR_OK, return back success, others fail. + */ + virtual int GetAllChildrenProcesses(std::vector &info) override; + /** * JudgeSandboxByPid, call JudgeSandboxByPid() through proxy project. * Obtains information about application processes that are running on the device. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h index 47ea448b15..b23b820ddc 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h @@ -78,6 +78,7 @@ private: int32_t HandleGetProcessRunningInfosByUserId(MessageParcel &data, MessageParcel &reply); int32_t HandleGetProcessRunningInformation(MessageParcel &data, MessageParcel &reply); int32_t HandleGetAllRenderProcesses(MessageParcel &data, MessageParcel &reply); + int32_t HandleGetAllChildrenProcesses(MessageParcel &data, MessageParcel &reply); int32_t HandleAddAbilityStageDone(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyMemoryLevel(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyProcMemoryLevel(MessageParcel &data, MessageParcel &reply); diff --git a/interfaces/inner_api/app_manager/include/appmgr/child_process_info.h b/interfaces/inner_api/app_manager/include/appmgr/child_process_info.h index a412eb2be6..da2d1de466 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/child_process_info.h +++ b/interfaces/inner_api/app_manager/include/appmgr/child_process_info.h @@ -33,6 +33,8 @@ struct ChildProcessInfo : public Parcelable { int32_t pid = 0; int32_t hostPid = 0; int32_t uid = -1; + int32_t hostUid = -1; + int32_t userId = -1; int32_t childProcessType = CHILD_PROCESS_TYPE_JS; std::string bundleName; std::string processName; diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp index 632839f147..254241dfd8 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp @@ -444,6 +444,21 @@ AppMgrResultCode AppMgrClient::GetAllRenderProcesses(std::vector &info) +{ + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr"); + return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; + } + int32_t result = service->GetAllChildrenProcesses(info); + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::APPMGR, "service->GetAllChildrenProcesses failed,result=%{public}d", result); + return AppMgrResultCode::ERROR_SERVICE_NOT_READY; + } + return AppMgrResultCode::RESULT_OK; +} + AppMgrResultCode AppMgrClient::NotifyMemoryLevel(MemoryLevel level) { sptr service = iface_cast(mgrHolder_->GetRemoteObject()); 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 c18a7d64ec..d9f8eefb26 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 @@ -262,6 +262,26 @@ int32_t AppMgrProxy::GetAllRenderProcesses(std::vector &info) return result; } +int AppMgrProxy::GetAllChildrenProcesses(std::vector &info) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!WriteInterfaceToken(data)) { + return ERR_FLATTEN_OBJECT; + } + if (!SendTransactCmd(AppMgrInterfaceCode::GET_ALL_CHILDREN_PROCESSES, data, reply)) { + return ERR_NULL_OBJECT; + } + auto error = GetParcelableInfos(reply, info); + if (error != NO_ERROR) { + TAG_LOGE(AAFwkTag::APPMGR, "GetParcelableInfos fail, error: %{public}d", error); + return error; + } + int result = reply.ReadInt32(); + return result; +} + int32_t AppMgrProxy::JudgeSandboxByPid(pid_t pid, bool &isSandbox) { MessageParcel data; diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp index c119136cfa..9651ad84f9 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp @@ -337,6 +337,8 @@ int32_t AppMgrStub::OnRemoteRequestInnerSeventh(uint32_t code, MessageParcel &da return HandleRestartResidentProcessDependedOnWeb(data, reply); case static_cast(AppMgrInterfaceCode::GET_SUPPORTED_PROCESS_CACHE_PIDS): return HandleGetSupportedProcessCachePids(data, reply); + case static_cast(AppMgrInterfaceCode::GET_ALL_CHILDREN_PROCESSES): + return HandleGetAllChildrenProcesses(data, reply); } return INVALID_FD; } @@ -521,6 +523,25 @@ int32_t AppMgrStub::HandleGetAllRenderProcesses(MessageParcel &data, MessageParc return NO_ERROR; } +int32_t AppMgrStub::HandleGetAllChildrenProcesses(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER(HITRACE_TAG_APP); + std::vector info; + auto result = GetAllChildrenProcesses(info); + reply.WriteInt32(info.size()); + for (auto &it : info) { + if (!reply.WriteParcelable(&it)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write ChildProcessInfo faild, child pid=%{public}d", it.pid); + return ERR_INVALID_VALUE; + } + } + if (!reply.WriteInt32(result)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write result faild"); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int32_t AppMgrStub::HandleJudgeSandboxByPid(MessageParcel &data, MessageParcel &reply) { HITRACE_METER(HITRACE_TAG_APP); diff --git a/interfaces/inner_api/app_manager/src/appmgr/child_process_info.cpp b/interfaces/inner_api/app_manager/src/appmgr/child_process_info.cpp index 49ad587876..eadf4b493b 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/child_process_info.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/child_process_info.cpp @@ -36,6 +36,14 @@ bool ChildProcessInfo::ReadFromParcel(Parcel &parcel) READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uidData); uid = static_cast(uidData); + int32_t hostUidData; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, hostUidData); + hostUid = static_cast(hostUidData); + + int32_t userIdData; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, userIdData); + userId = static_cast(userIdData); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, childProcessType); bundleName = Str16ToStr8(parcel.ReadString16()); @@ -67,6 +75,8 @@ bool ChildProcessInfo::Marshalling(Parcel &parcel) const WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast(pid)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast(hostPid)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast(uid)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast(hostUid)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast(userId)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast(childProcessType)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(processName)); diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index f990121573..66b753198d 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -180,6 +180,15 @@ public: */ virtual int32_t GetAllRenderProcesses(std::vector &info) override; + /** + * GetAllChildrenProcesses, call GetAllChildrenProcesses() through proxy project. + * Obtains information about children processes that are running on the device. + * + * @param info, child process info. + * @return ERR_OK, return back success, others fail. + */ + virtual int GetAllChildrenProcesses(std::vector &info) override; + /** * JudgeSandboxByPid, call JudgeSandboxByPid() through proxy project. * Obtains information about application processes that are running on the device. diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 67030b3263..c368faa9d9 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -388,6 +388,15 @@ public: */ virtual int32_t GetAllRenderProcesses(std::vector &info); + /** + * GetAllChildrenProcesses, call GetAllChildrenProcesses() through proxy project. + * Obtains information about children processes that are running on the device. + * + * @param info, child process info. + * @return ERR_OK, return back success, others fail. + */ + virtual int GetAllChildrenProcesses(std::vector &info); + /** * NotifyMemoryLevel, Notify applications background the current memory level. * @@ -1305,6 +1314,8 @@ private: void GetRenderProcesses(const std::shared_ptr &appRecord, std::vector &info); + void GetChildrenProcesses(const std::shared_ptr &appRecord, std::vector &info); + int StartRenderProcessImpl(const std::shared_ptr &renderRecord, const std::shared_ptr appRecord, pid_t &renderPid, bool isGPU = false); @@ -1339,7 +1350,8 @@ private: const ChildProcessOptions &options); int32_t GetChildProcessInfo(const std::shared_ptr childProcessRecord, - const std::shared_ptr appRecord, ChildProcessInfo &info); + const std::shared_ptr appRecord, ChildProcessInfo &info, + bool isCallFromGetChildrenProcesses = false); void OnChildProcessRemoteDied(const wptr &remote); diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 4b5f756de0..c9be492ee6 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -417,6 +417,14 @@ int32_t AppMgrService::GetAllRenderProcesses(std::vector &inf return appMgrServiceInner_->GetAllRenderProcesses(info); } +int AppMgrService::GetAllChildrenProcesses(std::vector &info) +{ + if (!IsReady()) { + return ERR_INVALID_OPERATION; + } + return appMgrServiceInner_->GetAllChildrenProcesses(info); +} + int32_t AppMgrService::JudgeSandboxByPid(pid_t pid, bool &isSandbox) { if (!IsReady()) { diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 30c0188868..ffcadf05e0 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -1779,6 +1779,29 @@ int32_t AppMgrServiceInner::GetAllRenderProcesses(std::vector return ERR_OK; } +int AppMgrServiceInner::GetAllChildrenProcesses(std::vector &info) +{ + auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm(); + // check permission + for (const auto &item : appRunningManager_->GetAppRunningRecordMap()) { + const auto &appRecord = item.second; + if (isPerm) { + GetChildrenProcesses(appRecord, info); + } else { + auto applicationInfo = appRecord->GetApplicationInfo(); + if (!applicationInfo) { + continue; + } + auto callingTokenId = IPCSkeleton::GetCallingTokenID(); + auto tokenId = applicationInfo->accessTokenId; + if (callingTokenId == tokenId) { + GetChildrenProcesses(appRecord, info); + } + } + } + return ERR_OK; +} + int32_t AppMgrServiceInner::NotifyMemoryLevel(int32_t level) { TAG_LOGI(AAFwkTag::APPMGR, "start"); @@ -1915,6 +1938,30 @@ void AppMgrServiceInner::GetRenderProcesses(const std::shared_ptr &appRecord, + std::vector &info) +{ + auto childProcessRecordMap = appRecord->GetChildProcessRecordMap(); + if (childProcessRecordMap.empty()) { + return; + } + int32_t retCode = ERR_OK; + for (auto iter : childProcessRecordMap) { + auto childProcessRecord = iter.second; + if (childProcessRecord != nullptr) { + ChildProcessInfo childProcessInfo; + retCode = GetChildProcessInfo(childProcessRecord, appRecord, childProcessInfo, true); + if (retCode != ERR_OK) { + TAG_LOGW( + AAFwkTag::APPMGR, "GetChildProcessInfo failed. host pid=%{public}d, child pid=%{public}d", + appRecord->GetPriorityObject()->GetPid(), childProcessRecord->GetPid()); + continue; + } + info.emplace_back(childProcessInfo); + } + } +} + int32_t AppMgrServiceInner::KillProcessByPid(const pid_t pid, const std::string& reason) { if (!ProcessExist(pid)) { @@ -6530,7 +6577,7 @@ int32_t AppMgrServiceInner::GetChildProcessInfoForSelf(ChildProcessInfo &info) } int32_t AppMgrServiceInner::GetChildProcessInfo(const std::shared_ptr childProcessRecord, - const std::shared_ptr appRecord, ChildProcessInfo &info) + const std::shared_ptr appRecord, ChildProcessInfo &info, bool isCallFromGetChildrenProcesses) { TAG_LOGD(AAFwkTag::APPMGR, "called"); if (!childProcessRecord) { @@ -6541,23 +6588,38 @@ int32_t AppMgrServiceInner::GetChildProcessInfo(const std::shared_ptr::GetInstance(); + if (osAccountMgr == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "osAccountMgr is nullptr"); + return ERR_INVALID_VALUE; + } + int32_t userId = -1; + int errCode = osAccountMgr->GetOsAccountLocalIdFromUid(appRecord->GetUid(), userId); + if (errCode != ERR_OK) { + TAG_LOGE(AAFwkTag::APPMGR, "GetOsAccountLocalIdFromUid failed,errcode=%{public}d", errCode); + return errCode; + } + info.userId = userId; info.pid = childProcessRecord->GetPid(); info.hostPid = childProcessRecord->GetHostPid(); info.uid = childProcessRecord->GetUid(); - info.childProcessType = childProcessRecord->GetChildProcessType(); + info.hostUid = appRecord->GetUid(); info.bundleName = appRecord->GetBundleName(); info.processName = childProcessRecord->GetProcessName(); - info.srcEntry = childProcessRecord->GetSrcEntry(); - info.entryFunc = childProcessRecord->GetEntryFunc(); - info.entryParams = childProcessRecord->GetEntryParams(); - info.jitEnabled = appRecord->IsJITEnabled(); - info.isStartWithDebug = childProcessRecord->isStartWithDebug(); - auto applicationInfo = appRecord->GetApplicationInfo(); - if (applicationInfo) { - TAG_LOGD(AAFwkTag::APPMGR, "applicationInfo is exist, debug:%{public}d", applicationInfo->debug); - info.isDebugApp = applicationInfo->debug; + if (!isCallFromGetChildrenProcesses) { + info.childProcessType = childProcessRecord->GetChildProcessType(); + info.srcEntry = childProcessRecord->GetSrcEntry(); + info.entryFunc = childProcessRecord->GetEntryFunc(); + info.entryParams = childProcessRecord->GetEntryParams(); + info.jitEnabled = appRecord->IsJITEnabled(); + info.isStartWithDebug = childProcessRecord->isStartWithDebug(); + auto applicationInfo = appRecord->GetApplicationInfo(); + if (applicationInfo) { + TAG_LOGD(AAFwkTag::APPMGR, "applicationInfo is exist, debug:%{public}d", applicationInfo->debug); + info.isDebugApp = applicationInfo->debug; + } + info.isStartWithNative = appRecord->isNativeStart(); } - info.isStartWithNative = appRecord->isNativeStart(); return ERR_OK; } diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h index d2e02b3e40..038afaedcf 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h @@ -170,6 +170,11 @@ public: return 0; } + virtual int GetAllChildrenProcesses(std::vector &info) override + { + return 0; + } + virtual int32_t StartNativeProcessForDebugger(const AAFwk::Want &want) override { return 0; diff --git a/test/mock/mock_appmgr_service/include/mock_app_mgr_service_inner.h b/test/mock/mock_appmgr_service/include/mock_app_mgr_service_inner.h index d065167a0c..1502a14325 100644 --- a/test/mock/mock_appmgr_service/include/mock_app_mgr_service_inner.h +++ b/test/mock/mock_appmgr_service/include/mock_app_mgr_service_inner.h @@ -47,6 +47,7 @@ public: MOCK_METHOD1(IsBackgroundRunningRestricted, int32_t(const std::string&)); MOCK_METHOD1(GetAllRunningProcesses, int32_t(std::vector&)); MOCK_METHOD1(GetAllRenderProcesses, int32_t(std::vector&)); + MOCK_METHOD1(GetAllChildrenProcesses, int(std::vector&)); MOCK_METHOD1(RegisterAppStateCallback, void(const sptr& callback)); MOCK_METHOD0(StopAllProcess, void()); MOCK_CONST_METHOD0(QueryAppSpawnConnectionState, SpawnConnectionState()); diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h index a8bcb0ef63..77287053f3 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h @@ -51,6 +51,7 @@ public: std::vector& info)); MOCK_METHOD2(GetProcessRunningInfosByUserId, int(std::vector& info, int32_t userId)); MOCK_METHOD1(GetAllRenderProcesses, int(std::vector& info)); + MOCK_METHOD1(GetAllChildrenProcesses, int(std::vector&)); MOCK_METHOD0(GetAmsMgr, sptr()); MOCK_METHOD1(GetAppFreezingTime, void(int& time)); MOCK_METHOD1(SetAppFreezingTime, void(int time)); diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h index e299c8514c..11867d35ac 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h @@ -50,6 +50,7 @@ public: MOCK_METHOD1(IsBackgroundRunningRestricted, int32_t(const std::string&)); MOCK_METHOD1(GetAllRunningProcesses, int32_t(std::vector&)); MOCK_METHOD1(GetAllRenderProcesses, int32_t(std::vector&)); + MOCK_METHOD1(GetAllChildrenProcesses, int(std::vector&)); MOCK_METHOD1(RegisterAppStateCallback, void(const sptr& callback)); MOCK_METHOD0(StopAllProcess, void()); MOCK_CONST_METHOD0(QueryAppSpawnConnectionState, SpawnConnectionState()); diff --git a/test/unittest/app_scheduler_test/app_mgr_client_mock.h b/test/unittest/app_scheduler_test/app_mgr_client_mock.h index 1a70c83c82..39d436d4f9 100755 --- a/test/unittest/app_scheduler_test/app_mgr_client_mock.h +++ b/test/unittest/app_scheduler_test/app_mgr_client_mock.h @@ -44,6 +44,7 @@ public: MOCK_METHOD3(StartSpecifiedAbility, void(const AAFwk::Want&, const AppExecFwk::AbilityInfo&, int32_t)); MOCK_METHOD1(GetAllRunningProcesses, AppMgrResultCode(std::vector &info)); MOCK_METHOD1(GetAllRenderProcesses, AppMgrResultCode(std::vector &info)); + MOCK_METHOD1(GetAllChildrenProcesses, AppMgrResultCode(std::vector &info)); MOCK_METHOD2(GetProcessRunningInfosByUserId, AppMgrResultCode( std::vector &info, int32_t userId)); MOCK_METHOD4(StartUserTestProcess, int( From b86e305c8c581187fedbebf698e9fe550ce2c390 Mon Sep 17 00:00:00 2001 From: yuwenze Date: Fri, 23 Aug 2024 16:43:49 +0800 Subject: [PATCH 25/42] add log Signed-off-by: yuwenze Change-Id: Ia529adaa6c736ba66c055288f829ecac027a008d --- .../app_manager/src/appmgr/app_mgr_stub.cpp | 22 +++++++++++++++++++ services/appmgr/src/app_lifecycle_deal.cpp | 7 ++++++ 2 files changed, 29 insertions(+) diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp index 665c8f8de1..7ade944c87 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp @@ -37,6 +37,22 @@ namespace OHOS { namespace AppExecFwk { constexpr int32_t CYCLE_LIMIT = 1000; +namespace { +#ifdef __aarch64__ +constexpr uint32_t OBJECT_MASK = 0xffffffff; +#else +constexpr uint32_t OBJECT_MASK = 0xffffff; +#endif + +uint32_t ConvertAddr(const void *ptr) +{ + if (ptr == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "ptr is null"); + return 0; + } + return static_cast((reinterpret_cast(ptr)) & OBJECT_MASK); +} +} AppMgrStub::AppMgrStub() {} @@ -348,6 +364,12 @@ int32_t AppMgrStub::HandleAttachApplication(MessageParcel &data, MessageParcel & if (client == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "remote object null"); } + TAG_LOGI(AAFwkTag::APPMGR, "remote: %{public}u", ConvertAddr(client.GetRefPtr())); + IPCObjectProxy *proxy = reinterpret_cast(client.GetRefPtr()); + if (proxy != nullptr) { + int32_t pid = static_cast(IPCSkeleton::GetCallingPid()); + TAG_LOGI(AAFwkTag::APPMGR, "handle:%{public}u, callingPid:%{public}d", proxy->GetHandle(), pid); + } AttachApplication(client); return NO_ERROR; } diff --git a/services/appmgr/src/app_lifecycle_deal.cpp b/services/appmgr/src/app_lifecycle_deal.cpp index 1cf2b928ce..2f7af91bff 100644 --- a/services/appmgr/src/app_lifecycle_deal.cpp +++ b/services/appmgr/src/app_lifecycle_deal.cpp @@ -18,6 +18,7 @@ #include "freeze_util.h" #include "hilog_tag_wrapper.h" #include "hitrace_meter.h" +#include "ipc_object_proxy.h" #include "time_util.h" #include "app_mgr_service_const.h" #include "app_mgr_service_dump_error_code.h" @@ -39,6 +40,12 @@ void AppLifeCycleDeal::LaunchApplication(const AppLaunchData &launchData, const TAG_LOGD(AAFwkTag::APPMGR, "called"); auto appThread = GetApplicationClient(); if (appThread) { + auto remoteObject = appThread->AsObject(); + IPCObjectProxy *proxy = reinterpret_cast(remoteObject.GetRefPtr()); + if (proxy != nullptr) { + int32_t pid = static_cast(launchData.GetProcessInfo().GetPid()); + TAG_LOGI(AAFwkTag::APPMGR, "handle:%{public}u, pid:%{public}d", proxy->GetHandle(), pid); + } appThread->ScheduleLaunchApplication(launchData, config); } } From 0df4bdeca45b5463e122e8c2bd47df3d8f5c51be Mon Sep 17 00:00:00 2001 From: LY Date: Wed, 21 Aug 2024 11:54:57 +0800 Subject: [PATCH 26/42] =?UTF-8?q?=E5=85=A8=E7=90=83=E5=8C=96=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=81=8F=E5=A5=BD=E8=AF=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: LY --- frameworks/native/appkit/app/main_thread.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index e5e26bc293..21a0c269b4 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -1075,12 +1075,13 @@ bool MainThread::InitResourceManager(std::shared_ptr resConfig(Global::Resource::CreateResConfig()); #if defined(SUPPORT_GRAPHICS) && defined(SUPPORT_APP_PREFERRED_LANGUAGE) UErrorCode status = U_ZERO_ERROR; - icu::Locale locale = icu::Locale::forLanguageTag(Global::I18n::PreferredLanguage::GetAppPreferredLanguage(), status); - resConfig->SetLocaleInfo(locale); - const icu::Locale *localeInfo = resConfig->GetLocaleInfo(); - if (localeInfo != nullptr) { - TAG_LOGD(AAFwkTag::APPKIT, "Language: %{public}s, script: %{public}s, region: %{public}s", - localeInfo->getLanguage(), localeInfo->getScript(), localeInfo->getCountry()); + icu::Locale systemLocale = icu::Locale::forLanguageTag(Global::I18n::LocaleConfig::GetSystemLanguage(), status); + resConfig->SetLocaleInfo(systemLocale); + + if (Global::I18n::PreferredLanguage::IsSetAppPreferredLanguage()) { + icu::Locale preferredLocale = + icu::Locale::forLanguageTag(Global::I18n::PreferredLanguage::GetAppPreferredLanguage(), status); + resConfig->SetPreferredLocaleInfo(preferredLocale); } #endif std::string colormode = config.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE); From eeca0a53c640ce610bd80ec6b3206f8da242ef93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ISS=5C=E5=90=B4=E7=BB=A7=E7=90=B4?= Date: Fri, 23 Aug 2024 16:56:46 +0800 Subject: [PATCH 27/42] =?UTF-8?q?tdd=E6=8E=A5=E5=8F=A3=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ISS\吴继琴 --- .../app_running_manager_test.cpp | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/unittest/app_running_manager_test/app_running_manager_test.cpp b/test/unittest/app_running_manager_test/app_running_manager_test.cpp index a7dee8c56d..74dd3b7247 100644 --- a/test/unittest/app_running_manager_test/app_running_manager_test.cpp +++ b/test/unittest/app_running_manager_test/app_running_manager_test.cpp @@ -687,5 +687,51 @@ HWTEST_F(AppRunningManagerTest, IsAppProcessesAllCached_0100, TestSize.Level1) appRunningManager->appRunningRecordMap_.insert(make_pair(recordId2, appRunningRecord2)); EXPECT_EQ(appRunningManager->IsAppProcessesAllCached(appInfo->bundleName, appInfo->uid, cachedSet), false); } + +/** + * @tc.name: CheckAppCloneRunningRecordIsExistByBundleName_0100 + * @tc.desc: MultiProcess application cache check test. + * @tc.type: FUNC + */ +HWTEST_F(AppRunningManagerTest, CheckAppCloneRunningRecordIsExistByBundleName_0100, TestSize.Level1) +{ + static std::shared_ptr appRunningManager = std::make_shared(); + ASSERT_NE(appRunningManager, nullptr); + + std::string bundleName = "bundleName"; + int32_t appCloneIndex = 1; + bool isRunning = true; + int32_t res = appRunningManager-> + CheckAppCloneRunningRecordIsExistByBundleName(bundleName, appCloneIndex, isRunning); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.name: GetAllAppRunningRecordCountByBundleName_0100 + * @tc.desc: MultiProcess application cache check test. + * @tc.type: FUNC + */ +HWTEST_F(AppRunningManagerTest, GetAllAppRunningRecordCountByBundleName_0100, TestSize.Level1) +{ + static std::shared_ptr appRunningManager = std::make_shared(); + ASSERT_NE(appRunningManager, nullptr); + + std::string bundleName = "bundleName"; + EXPECT_EQ(appRunningManager->GetAllAppRunningRecordCountByBundleName(bundleName), 0); +} + +/** + * @tc.name: ProcessUpdateApplicationInfoInstalled_0100 + * @tc.desc: MultiProcess application cache check test. + * @tc.type: FUNC + */ +HWTEST_F(AppRunningManagerTest, ProcessUpdateApplicationInfoInstalled_0100, TestSize.Level1) +{ + static std::shared_ptr appRunningManager = std::make_shared(); + ASSERT_NE(appRunningManager, nullptr); + + ApplicationInfo appInfo; + EXPECT_EQ(appRunningManager->ProcessUpdateApplicationInfoInstalled(appInfo), 0); +} } // namespace AppExecFwk } // namespace OHOS From ee24b5deba802c31fca9c746423af1a0fc3356db Mon Sep 17 00:00:00 2001 From: wangkailong Date: Fri, 23 Aug 2024 16:46:42 +0800 Subject: [PATCH 28/42] clear Signed-off-by: wangkailong Change-Id: If62a3d4a56787db76a2f2559140b47713bbe1027 --- services/abilitymgr/src/mission_info.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/abilitymgr/src/mission_info.cpp b/services/abilitymgr/src/mission_info.cpp index f33f3f07e8..5df164541f 100644 --- a/services/abilitymgr/src/mission_info.cpp +++ b/services/abilitymgr/src/mission_info.cpp @@ -31,6 +31,7 @@ bool MissionInfo::ReadFromParcel(Parcel &parcel) return false; } want = *parcelWant; + want.CloseAllFd(); abilityState = parcel.ReadInt32(); unclearable = parcel.ReadBool(); continueState = static_cast(parcel.ReadInt32()); From d93f1ac275e26862618dd5f8feec6f357276ddf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 23 Aug 2024 19:53:52 +0800 Subject: [PATCH 29/42] =?UTF-8?q?description:fuzz=E9=AB=98=E9=A3=8E?= =?UTF-8?q?=E9=99=A9=E6=8E=A5=E5=8F=A3=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- test/fuzztest/appmanager_fuzzer/appmanager_fuzzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fuzztest/appmanager_fuzzer/appmanager_fuzzer.cpp b/test/fuzztest/appmanager_fuzzer/appmanager_fuzzer.cpp index 495cd7e24c..275f16ee67 100644 --- a/test/fuzztest/appmanager_fuzzer/appmanager_fuzzer.cpp +++ b/test/fuzztest/appmanager_fuzzer/appmanager_fuzzer.cpp @@ -49,7 +49,7 @@ uint32_t GetU32Data(const char* ptr) bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) { for (uint32_t code = 0; - code <= static_cast(AppMgrInterfaceCode::RESTART_RESIDENT_PROCESS_DEPENDED_ON_WEB); ++code) { + code <= static_cast(AppMgrInterfaceCode::GET_ALL_CHILDREN_PROCESSES); ++code) { MessageParcel parcel; parcel.WriteInterfaceToken(APPMGR_INTERFACE_TOKEN); parcel.WriteBuffer(data, size); From 5702b249e973877bb8098bc5ecef991902df5b47 Mon Sep 17 00:00:00 2001 From: XKK Date: Thu, 22 Aug 2024 11:00:26 +0800 Subject: [PATCH 30/42] =?UTF-8?q?=E6=89=98=E7=9B=98=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E5=88=B0=E4=B8=BB=E8=BF=9B=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XKK --- services/abilitymgr/include/extension_record_factory.h | 2 ++ services/abilitymgr/src/extension_record_factory.cpp | 3 +++ services/abilitymgr/src/extension_record_manager.cpp | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/services/abilitymgr/include/extension_record_factory.h b/services/abilitymgr/include/extension_record_factory.h index 9ae7ba2be2..96c6f5de02 100644 --- a/services/abilitymgr/include/extension_record_factory.h +++ b/services/abilitymgr/include/extension_record_factory.h @@ -26,6 +26,8 @@ constexpr const char *PROCESS_MODE_HOST_INSTANCE_KEY = "ohos.extension.processMo constexpr uint32_t PROCESS_MODE_INSTANCE = 1 << static_cast(AppExecFwk::ExtensionProcessMode::INSTANCE); constexpr uint32_t PROCESS_MODE_TYPE = 1 << static_cast(AppExecFwk::ExtensionProcessMode::TYPE); constexpr uint32_t PROCESS_MODE_BUNDLE = 1 << static_cast(AppExecFwk::ExtensionProcessMode::BUNDLE); +constexpr uint32_t PROCESS_MODE_RUN_WITH_MAIN_PROCESS = + 1 << static_cast(AppExecFwk::ExtensionProcessMode::RUN_WITH_MAIN_PROCESS); constexpr uint32_t PROCESS_INNER_MODE_OFFSET = 16; constexpr uint32_t PROCESS_MODE_HOST_SPECIFIED = 1 << (PROCESS_INNER_MODE_OFFSET + 0); constexpr uint32_t PROCESS_MODE_HOST_INSTANCE = 1 << (PROCESS_INNER_MODE_OFFSET + 1); diff --git a/services/abilitymgr/src/extension_record_factory.cpp b/services/abilitymgr/src/extension_record_factory.cpp index b1c742ffa0..9990a946f0 100644 --- a/services/abilitymgr/src/extension_record_factory.cpp +++ b/services/abilitymgr/src/extension_record_factory.cpp @@ -26,6 +26,9 @@ const std::map EXTENSIO { AppExecFwk::ExtensionAbilityType::EMBEDDED_UI, { PROCESS_MODE_BUNDLE, PROCESS_MODE_SUPPORT_DEFAULT | PROCESS_MODE_HOST_SPECIFIED | PROCESS_MODE_HOST_INSTANCE, PRE_CHECK_FLAG_CALLED_WITHIN_THE_BUNDLE | PRE_CHECK_FLAG_MULTIPLE_PROCESSES }}, + { AppExecFwk::ExtensionAbilityType::STATUS_BAR_VIEW, + { PROCESS_MODE_BUNDLE, PROCESS_MODE_SUPPORT_DEFAULT | PROCESS_MODE_RUN_WITH_MAIN_PROCESS, + PRE_CHECK_FLAG_NONE }}, }; uint32_t GetPreCheckFlag(ExtensionAbilityType type) diff --git a/services/abilitymgr/src/extension_record_manager.cpp b/services/abilitymgr/src/extension_record_manager.cpp index 6a886f99d5..2de800fa28 100644 --- a/services/abilitymgr/src/extension_record_manager.cpp +++ b/services/abilitymgr/src/extension_record_manager.cpp @@ -265,6 +265,14 @@ int32_t ExtensionRecordManager::UpdateProcessName(const AAFwk::AbilityRequest &a abilityRecord->SetProcessName(process); break; } + case PROCESS_MODE_RUN_WITH_MAIN_PROCESS: { + if (!abilityRequest.appInfo.process.empty()) { + abilityRecord->SetProcessName(abilityRequest.appInfo.process); + } else { + abilityRecord->SetProcessName(abilityRequest.abilityInfo.bundleName); + } + break; + } default: // AppExecFwk::ExtensionProcessMode::UNDEFINED or AppExecFwk::ExtensionProcessMode::BUNDLE // no need to update break; From 7facbc2a92644b6bab485bdb7e18ae4a12084f29 Mon Sep 17 00:00:00 2001 From: yangxuguang-huawei Date: Sat, 24 Aug 2024 14:25:20 +0800 Subject: [PATCH 31/42] feat: add TDD for GetAllChildrenProcesses Signed-off-by: yangxuguang-huawei Change-Id: Ibd2bad71ea8dc874fb527233026c05d269eeeacd --- .../app_mgr_client_test.cpp | 17 +++++++++ .../app_mgr_proxy_test/app_mgr_proxy_test.cpp | 22 ++++++++++++ .../app_mgr_service_inner_test.cpp | 15 ++++++++ .../app_mgr_service_test.cpp | 36 +++++++++++++++++++ 4 files changed, 90 insertions(+) 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 3164f41a75..57ed2ffe28 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 @@ -285,6 +285,23 @@ HWTEST_F(AppMgrClientTest, AppMgrClient_GetAllRenderProcesses_001, TestSize.Leve TAG_LOGI(AAFwkTag::TEST, "GetAllRenderProcesses_001 end"); } +/** + * @tc.name: AppMgrClient_GetAllChildrenProcesses_001 + * @tc.desc: get all children processes. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrClientTest, AppMgrClient_GetAllChildrenProcesses_001, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "GetAllChildrenProcesses_001 start"); + auto appMgrClient = std::make_unique(); + EXPECT_NE(appMgrClient, nullptr); + + std::vector info; + auto result = appMgrClient->GetAllChildrenProcesses(info); + EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); + TAG_LOGI(AAFwkTag::TEST, "GetAllChildrenProcesses_001 end"); +} + /** * @tc.name: AppMgrClient_GetRenderProcessTerminationStatus_001 * @tc.desc: can not get render process termination status with error pid. 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 e9b3e9a69a..544ccc133b 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 @@ -144,6 +144,28 @@ HWTEST_F(AppMgrProxyTest, AppMgrProxy_GetAllRenderProcesses_0100, TestSize.Level GTEST_LOG_(INFO) << "AppMgrProxy_GetAllRenderProcesses_0100 end"; } +/** + * @tc.name: AppMgrProxy_GetAllChildrenProcesses_0100 + * @tc.desc: GetAllChildrenProcesses + * @tc.type: FUNC + */ +HWTEST_F(AppMgrProxyTest, AppMgrProxy_GetAllChildrenProcesses_0100, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "AppMgrProxy_GetAllChildrenProcesses_0100 start"; + + EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest)); + + std::vector info; + appMgrProxy_->GetAllChildrenProcesses(info); + + EXPECT_EQ( + mockAppMgrService_->code_, static_cast(AppMgrInterfaceCode::GET_ALL_CHILDREN_PROCESSES)); + + GTEST_LOG_(INFO) << "AppMgrProxy_GetAllChildrenProcesses_0100 end"; +} + /** * @tc.name: GetAppRunningStateByBundleName_0100 * @tc.desc: Get app running state by bundle name. 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 983084b41f..39b65c9c73 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 @@ -1022,6 +1022,21 @@ HWTEST_F(AppMgrServiceInnerTest, GetAllRenderProcesses_001, TestSize.Level0) appMgrServiceInner->GetAllRenderProcesses(info); } +/** + * @tc.name: GetAllChildrenProcesses_001 + * @tc.desc: get all children processes. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, GetAllChildrenProcesses_001, TestSize.Level0) +{ + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + std::vector info; + auto result = appMgrServiceInner->GetAllChildrenProcesses(info); + EXPECT_EQ(result, ERR_OK); +} + /** * @tc.name: NotifyMemoryLevel_001 * @tc.desc: notify memory level. 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 53b49fe00c..2af2d3c0c6 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 @@ -383,6 +383,42 @@ HWTEST_F(AppMgrServiceTest, GetAllRenderProcesses_002, TestSize.Level0) EXPECT_NE(res, ERR_INVALID_OPERATION); } +/* + * Feature: AppMgrService + * Function: GetAllChildrenProcesses + * SubFunction: NA + * FunctionPoints: AppMgrService GetAllChildrenProcesses + * EnvConditions: NA + * CaseDescription: Verify GetAllChildrenProcesses + */ +HWTEST_F(AppMgrServiceTest, GetAllChildrenProcesses_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::vector info; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->GetAllChildrenProcesses(info); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: GetAllChildrenProcesses + * SubFunction: NA + * FunctionPoints: AppMgrService GetAllChildrenProcesses + * EnvConditions: NA + * CaseDescription: Verify GetAllChildrenProcesses + */ +HWTEST_F(AppMgrServiceTest, GetAllChildrenProcesses_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::vector info; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->GetAllChildrenProcesses(info); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + /* * Feature: AppMgrService * Function: NotifyMemoryLevel From 55927e2c0c59bbfce36857db74ad76420d1d5c97 Mon Sep 17 00:00:00 2001 From: songjindian Date: Sat, 24 Aug 2024 15:47:16 +0800 Subject: [PATCH 32/42] =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=95=B4=E6=94=B9?= =?UTF-8?q?=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songjindian --- .../ability/native/ability_runtime/js_ability_context.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp index a2b392f519..bd09387eec 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp @@ -1425,7 +1425,7 @@ napi_value JsAbilityContext::OnTerminateSelfWithResult(napi_env env, NapiCallbac NapiAsyncTask::CompleteCallback complete = [weak = context_, want, resultCode](napi_env env, NapiAsyncTask& task, int32_t status) { - TAG_LOGI(AAFwkTag::CONTEXT, "async terminateSelfWithResult "); + TAG_LOGD(AAFwkTag::CONTEXT, "terminateSelfWithResult"); auto context = weak.lock(); if (!context) { TAG_LOGW(AAFwkTag::CONTEXT, "released context"); From 97e6df7cab783d14332ad0ad05a1c24c97d5c3dc Mon Sep 17 00:00:00 2001 From: XKK Date: Sat, 24 Aug 2024 16:25:46 +0800 Subject: [PATCH 33/42] =?UTF-8?q?=E9=AB=98=E9=A2=91=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BAdebug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XKK --- interfaces/inner_api/wantagent/src/pending_want.cpp | 2 +- .../inner_api/wantagent/src/want_agent_client.cpp | 2 +- .../inner_api/wantagent/src/want_agent_helper.cpp | 10 +++++----- services/abilitymgr/src/pending_want_manager.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/interfaces/inner_api/wantagent/src/pending_want.cpp b/interfaces/inner_api/wantagent/src/pending_want.cpp index 0a35fce631..c2b2e361c9 100644 --- a/interfaces/inner_api/wantagent/src/pending_want.cpp +++ b/interfaces/inner_api/wantagent/src/pending_want.cpp @@ -292,7 +292,7 @@ int PendingWant::SendAndReturnResult(int resultCode, const std::shared_ptr const std::shared_ptr &options, const std::shared_ptr &startOptions, const sptr &target) { - TAG_LOGI(AAFwkTag::WANTAGENT, "call"); + TAG_LOGD(AAFwkTag::WANTAGENT, "call"); SenderInfo senderInfo; senderInfo.resolvedType = want != nullptr ? want->GetType() : ""; if (want != nullptr) { diff --git a/interfaces/inner_api/wantagent/src/want_agent_client.cpp b/interfaces/inner_api/wantagent/src/want_agent_client.cpp index bdf8e0e47c..8ccccfc4c0 100644 --- a/interfaces/inner_api/wantagent/src/want_agent_client.cpp +++ b/interfaces/inner_api/wantagent/src/want_agent_client.cpp @@ -357,7 +357,7 @@ sptr WantAgentClient::GetAbilityManager() return nullptr; } if (!remoteObj->AddDeathRecipient(deathRecipient_)) { - TAG_LOGI(AAFwkTag::WANTAGENT, "Add death recipient to failed"); + TAG_LOGE(AAFwkTag::WANTAGENT, "Add death recipient to failed"); } proxy_ = remoteObj; } diff --git a/interfaces/inner_api/wantagent/src/want_agent_helper.cpp b/interfaces/inner_api/wantagent/src/want_agent_helper.cpp index ed0ac32123..f9e2c4bfe0 100644 --- a/interfaces/inner_api/wantagent/src/want_agent_helper.cpp +++ b/interfaces/inner_api/wantagent/src/want_agent_helper.cpp @@ -192,7 +192,7 @@ WantAgentConstant::OperationType WantAgentHelper::GetType(std::shared_ptr agent, const std::shared_ptr &callback, const TriggerInfo ¶msInfo) { - TAG_LOGI(AAFwkTag::WANTAGENT, "call"); + TAG_LOGD(AAFwkTag::WANTAGENT, "call"); if (agent == nullptr) { TAG_LOGE(AAFwkTag::WANTAGENT, "invalid input param"); return ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER; @@ -209,7 +209,7 @@ ErrCode WantAgentHelper::TriggerWantAgent(std::shared_ptr agent, ErrCode WantAgentHelper::Send(const std::shared_ptr &pendingWant, WantAgentConstant::OperationType type, const sptr &callBack, const TriggerInfo ¶msInfo) { - TAG_LOGI(AAFwkTag::WANTAGENT, "call"); + TAG_LOGD(AAFwkTag::WANTAGENT, "call"); if (pendingWant == nullptr) { TAG_LOGE(AAFwkTag::WANTAGENT, "invalid input param"); return ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER; @@ -340,19 +340,19 @@ void WantAgentHelper::UnregisterCancelListener( std::string WantAgentHelper::ToString(const std::shared_ptr &agent) { if (agent == nullptr) { - TAG_LOGE(AAFwkTag::WANTAGENT, "invalid input param"); + TAG_LOGE(AAFwkTag::WANTAGENT, "invalid param"); return ""; } std::shared_ptr pendingWant = agent->GetPendingWant(); if (pendingWant == nullptr) { - TAG_LOGE(AAFwkTag::WANTAGENT, "invalid input param"); + TAG_LOGE(AAFwkTag::WANTAGENT, "invalid param"); return ""; } std::shared_ptr info = pendingWant->GetWantSenderInfo(pendingWant->GetTarget()); if (info == nullptr) { - TAG_LOGE(AAFwkTag::WANTAGENT, "invalid input param"); + TAG_LOGE(AAFwkTag::WANTAGENT, "invalid param"); return ""; } nlohmann::json jsonObject; diff --git a/services/abilitymgr/src/pending_want_manager.cpp b/services/abilitymgr/src/pending_want_manager.cpp index d02ad99d98..94d5384d77 100644 --- a/services/abilitymgr/src/pending_want_manager.cpp +++ b/services/abilitymgr/src/pending_want_manager.cpp @@ -118,7 +118,7 @@ sptr PendingWantManager::GetWantSenderLocked(const int32_t callingU rec->SetCallerUid(callingUid); pendingKey->SetCode(PendingRecordIdCreate()); wantRecords_.insert(std::make_pair(pendingKey, rec)); - TAG_LOGI(AAFwkTag::WANTAGENT, "wantRecords_ size %{public}zu", wantRecords_.size()); + TAG_LOGD(AAFwkTag::WANTAGENT, "wantRecords_ size %{public}zu", wantRecords_.size()); return rec; } return nullptr; From 7a70442ace7e3f5ec15ab22284c00ae0d8b65ab6 Mon Sep 17 00:00:00 2001 From: c30051536 Date: Fri, 23 Aug 2024 17:52:49 +0800 Subject: [PATCH 34/42] add check Signed-off-by: c30051536 --- .../distributed_mission_manager.cpp | 2 + .../distributed_mission_manager.h | 4 ++ .../include/ability_manager_errors.h | 5 +++ .../abilitymgr/include/ability_manager_stub.h | 1 + .../abilitymgr/src/ability_manager_stub.cpp | 40 +++++++++++++++++++ 5 files changed, 52 insertions(+) diff --git a/frameworks/js/napi/mission_manager/distributed_mission_manager.cpp b/frameworks/js/napi/mission_manager/distributed_mission_manager.cpp index 484f346665..dfb88c42ca 100644 --- a/frameworks/js/napi/mission_manager/distributed_mission_manager.cpp +++ b/frameworks/js/napi/mission_manager/distributed_mission_manager.cpp @@ -74,6 +74,8 @@ static int32_t ErrorCodeReturn(int32_t code) return CONTINUE_ALREADY_IN_PROGRESS; case MISSION_FOR_CONTINUING_IS_NOT_ALIVE: return MISSION_FOR_CONTINUING_IS_NOT_ALIVE; + case ERR_NOT_SYSTEM_APP_CALL: + return NOT_SYSTEM_APP; default: return SYSTEM_WORK_ABNORMALLY; }; diff --git a/frameworks/js/napi/mission_manager/distributed_mission_manager.h b/frameworks/js/napi/mission_manager/distributed_mission_manager.h index dc27541829..4e62628996 100644 --- a/frameworks/js/napi/mission_manager/distributed_mission_manager.h +++ b/frameworks/js/napi/mission_manager/distributed_mission_manager.h @@ -226,6 +226,10 @@ enum ErrorCode { * Result(201) for permission denied. */ PERMISSION_DENIED = 201, + /** + * Result(202) for not syatem app call. + */ + NOT_SYSTEM_APP = 202, /** * Result(401) for parameter check failed. */ diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h index db8ff6241b..b6d3627d44 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -590,6 +590,11 @@ enum { */ ERR_NATIVE_ARGS_CHILD_PROCESS_REACH_LIMIT = 2097266, + /* + * Result (2097267) for not syatem app call. + */ + ERR_NOT_SYSTEM_APP_CALL = 2097267, + /** * Native error(3000000) for target bundle not exist. */ diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index a295d5967b..aef8e9a33e 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -193,6 +193,7 @@ private: int UpdateMissionSnapShotFromWMSInner(MessageParcel &data, MessageParcel &reply); int RegisterConnectionObserverInner(MessageParcel &data, MessageParcel &reply); int UnregisterConnectionObserverInner(MessageParcel &data, MessageParcel &reply); + bool IsSystemApp(); #ifdef WITH_DLP int GetDlpConnectionInfosInner(MessageParcel &data, MessageParcel &reply); #endif // WITH_DLP diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 269e0c12f3..1aa36d448a 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -19,7 +19,9 @@ #include "ability_manager_radar.h" #include "hilog_tag_wrapper.h" #include "hitrace_meter.h" +#include "ipc_skeleton.h" #include "status_bar_delegate_interface.h" +#include "tokenid_kit.h" #include namespace OHOS { @@ -1928,6 +1930,10 @@ int AbilityManagerStub::IsRamConstrainedDeviceInner(MessageParcel &data, Message int AbilityManagerStub::ContinueMissionInner(MessageParcel &data, MessageParcel &reply) { + if (!IsSystemApp()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Not system app."); + return ERR_NOT_SYSTEM_APP; + } TAG_LOGI(AAFwkTag::ABILITYMGR, "called"); std::string srcDeviceId = data.ReadString(); std::string dstDeviceId = data.ReadString(); @@ -1949,6 +1955,10 @@ int AbilityManagerStub::ContinueMissionInner(MessageParcel &data, MessageParcel int AbilityManagerStub::ContinueMissionOfBundleNameInner(MessageParcel &data, MessageParcel &reply) { + if (!IsSystemApp()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Not system app."); + return ERR_NOT_SYSTEM_APP; + } TAG_LOGI(AAFwkTag::ABILITYMGR, "amsStub %{public}s called!", __func__); ContinueMissionInfo continueMissionInfo; continueMissionInfo.srcDeviceId = data.ReadString(); @@ -2386,6 +2396,10 @@ int AbilityManagerStub::GetProcessRunningInfosInner(MessageParcel &data, Message int AbilityManagerStub::StartSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply) { + if (!IsSystemApp()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Not system app."); + return ERR_NOT_SYSTEM_APP; + } std::string deviceId = data.ReadString(); bool fixConflict = data.ReadBool(); int64_t tag = data.ReadInt64(); @@ -2399,6 +2413,10 @@ int AbilityManagerStub::StartSyncRemoteMissionsInner(MessageParcel &data, Messag int AbilityManagerStub::StopSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply) { + if (!IsSystemApp()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Not system app."); + return ERR_NOT_SYSTEM_APP; + } int result = StopSyncRemoteMissions(data.ReadString()); if (!reply.WriteInt32(result)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "StopSyncRemoteMissionsInner failed."); @@ -2409,6 +2427,10 @@ int AbilityManagerStub::StopSyncRemoteMissionsInner(MessageParcel &data, Message int AbilityManagerStub::RegisterRemoteMissionListenerInner(MessageParcel &data, MessageParcel &reply) { + if (!IsSystemApp()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Not system app."); + return ERR_NOT_SYSTEM_APP; + } std::string deviceId = data.ReadString(); if (deviceId.empty()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "AbilityManagerStub: RegisterRemoteMissionListenerInner deviceId empty!"); @@ -2428,6 +2450,10 @@ int AbilityManagerStub::RegisterRemoteMissionListenerInner(MessageParcel &data, int AbilityManagerStub::RegisterRemoteOnListenerInner(MessageParcel &data, MessageParcel &reply) { + if (!IsSystemApp()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Not system app."); + return ERR_NOT_SYSTEM_APP; + } std::string type = data.ReadString(); if (type.empty()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "AbilityManagerStub: RegisterRemoteOnListenerInner type empty!"); @@ -2446,6 +2472,10 @@ int AbilityManagerStub::RegisterRemoteOnListenerInner(MessageParcel &data, Messa int AbilityManagerStub::RegisterRemoteOffListenerInner(MessageParcel &data, MessageParcel &reply) { + if (!IsSystemApp()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Not system app."); + return ERR_NOT_SYSTEM_APP; + } std::string type = data.ReadString(); if (type.empty()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "AbilityManagerStub: RegisterRemoteOffListenerInner type empty!"); @@ -2464,6 +2494,10 @@ int AbilityManagerStub::RegisterRemoteOffListenerInner(MessageParcel &data, Mess int AbilityManagerStub::UnRegisterRemoteMissionListenerInner(MessageParcel &data, MessageParcel &reply) { + if (!IsSystemApp()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Not system app."); + return ERR_NOT_SYSTEM_APP; + } std::string deviceId = data.ReadString(); if (deviceId.empty()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "AbilityManagerStub: UnRegisterRemoteMissionListenerInner deviceId empty!"); @@ -2918,6 +2952,12 @@ int AbilityManagerStub::UnregisterConnectionObserverInner(MessageParcel &data, M return UnregisterObserver(observer); } +bool AbilityManagerStub::IsSystemApp() +{ + uint64_t accessTokenIDEx = IPCSkeleton::GetCallingFullTokenID(); + return OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(accessTokenIDEx); +} + #ifdef WITH_DLP int AbilityManagerStub::GetDlpConnectionInfosInner(MessageParcel &data, MessageParcel &reply) { From 369053e2607cc3431de5263631b37a48ae0939a9 Mon Sep 17 00:00:00 2001 From: donglin Date: Sat, 24 Aug 2024 12:16:25 +0000 Subject: [PATCH 35/42] =?UTF-8?q?=E9=9D=99=E6=80=81=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=85=A8=E5=AE=B9=E5=99=A8=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E6=8B=A6=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: donglin Change-Id: Ic99b3439b58eb8329b27c2ab35e926e9d4372d72 --- .../include/iability_manager_collaborator.h | 6 +++++ .../ability_manager_collaborator_proxy.h | 2 ++ .../ability_manager_collaborator_proxy.cpp | 22 +++++++++++++++++++ .../src/ability_manager_service.cpp | 15 +++++++++++++ 4 files changed, 45 insertions(+) diff --git a/interfaces/inner_api/ability_manager/include/iability_manager_collaborator.h b/interfaces/inner_api/ability_manager/include/iability_manager_collaborator.h index 8b6a7bc5e5..0618bf26fb 100644 --- a/interfaces/inner_api/ability_manager/include/iability_manager_collaborator.h +++ b/interfaces/inner_api/ability_manager/include/iability_manager_collaborator.h @@ -177,6 +177,11 @@ public: return; } + virtual int32_t CheckStaticCfgPermission(const Want &want) + { + return 0; + } + enum { NOTIFY_START_ABILITY = 1, NOTIFY_MISSION_CREATED, @@ -195,6 +200,7 @@ public: UPDATE_CONFIGURATION, OPEN_FILE, NOTIFY_MISSION_BIND_PID, + CHECK_STATIC_CFG_PERMISSION, }; }; } // namespace AAFwk diff --git a/services/abilitymgr/include/ability_manager_collaborator_proxy.h b/services/abilitymgr/include/ability_manager_collaborator_proxy.h index 9b2bd3ee57..27c3412f80 100644 --- a/services/abilitymgr/include/ability_manager_collaborator_proxy.h +++ b/services/abilitymgr/include/ability_manager_collaborator_proxy.h @@ -152,6 +152,8 @@ public: virtual int OpenFile(const Uri& uri, uint32_t flag) override; virtual void NotifyMissionBindPid(int32_t missionId, int32_t pid) override; + + virtual int32_t CheckStaticCfgPermission(const Want &want) override; private: static inline BrokerDelegator delegator_; int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); diff --git a/services/abilitymgr/src/ability_manager_collaborator_proxy.cpp b/services/abilitymgr/src/ability_manager_collaborator_proxy.cpp index f50ffc7ec4..fd8f150c49 100644 --- a/services/abilitymgr/src/ability_manager_collaborator_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_collaborator_proxy.cpp @@ -499,6 +499,28 @@ void AbilityManagerCollaboratorProxy::NotifyMissionBindPid(int32_t missionId, in } } +int32_t AbilityManagerCollaboratorProxy::CheckStaticCfgPermission(const Want &want) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed."); + return ERR_INVALID_OPERATION; + } + if (!data.WriteParcelable(&want)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed."); + return ERR_INVALID_OPERATION; + } + int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::CHECK_STATIC_CFG_PERMISSION, + data, reply, option); + if (ret != NO_ERROR) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", ret); + return ret; + } + return reply.ReadInt32(); +} + int32_t AbilityManagerCollaboratorProxy::SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 00f4c3402f..e357f0ba02 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -8261,6 +8261,21 @@ int AbilityManagerService::CheckStaticCfgPermission(const AppExecFwk::AbilityReq { auto abilityInfo = abilityRequest.abilityInfo; HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + if (AppUtils::GetInstance().IsSupportAncoApp() && + StartAbilityUtils::IsCallFromAncoShellOrBroker(abilityRequest.callerToken)) { + TAG_LOGD(AAFwkTag::ABILITYMGR, + "Check static permission, name is %{public}s.", abilityInfo.name.c_str()); + auto collaborator = GetCollaborator(CollaboratorType::RESERVE_TYPE); + if (collaborator == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Collaborator is nullptr."); + return AppExecFwk::Constants::PERMISSION_NOT_GRANTED; + } + int result = collaborator->CheckStaticCfgPermission(abilityRequest.want); + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Check permission failed from broker."); + return AppExecFwk::Constants::PERMISSION_NOT_GRANTED; + } + } if (!isData) { isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); } From d93801ff1d789e708bd07f3251938289f2078c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B8=9D=E4=BF=8A?= Date: Thu, 22 Aug 2024 11:20:03 +0800 Subject: [PATCH 36/42] =?UTF-8?q?0824=5Fability=5Fnumber=20=20Signed-off-b?= =?UTF-8?q?y:=20=E5=B8=9D=E4=BF=8A=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../abilitymgr/include/pending_want_record.h | 2 ++ services/abilitymgr/src/ability_record.cpp | 4 ++-- .../abilitymgr/src/pending_want_record.cpp | 20 ++++++++++++------- utils/server/startup/src/startup_util.cpp | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/services/abilitymgr/include/pending_want_record.h b/services/abilitymgr/include/pending_want_record.h index 11bce85380..d9fc782b97 100644 --- a/services/abilitymgr/include/pending_want_record.h +++ b/services/abilitymgr/include/pending_want_record.h @@ -54,6 +54,8 @@ public: private: void BuildSendWant(SenderInfo &senderInfo, Want &want); + int32_t ExecuteOperation( + std::shared_ptr pendingWantManager, SenderInfo &senderInfo, Want &want); private: std::weak_ptr pendingWantManager_ = {}; diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 508023aba8..73652159c1 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -504,13 +504,13 @@ void AbilityRecord::PostUIExtensionAbilityTimeoutTask(uint32_t messageId) switch (messageId) { case AbilityManagerService::LOAD_TIMEOUT_MSG: { uint32_t timeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * - LOAD_TIMEOUT_MULTIPLE; + static_cast(LOAD_TIMEOUT_MULTIPLE); SendEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, timeout / HALF_TIMEOUT, recordId_, true); break; } case AbilityManagerService::FOREGROUND_TIMEOUT_MSG: { uint32_t timeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * - FOREGROUND_TIMEOUT_MULTIPLE; + static_cast(FOREGROUND_TIMEOUT_MULTIPLE); SendEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, timeout / HALF_TIMEOUT, recordId_, true); break; } diff --git a/services/abilitymgr/src/pending_want_record.cpp b/services/abilitymgr/src/pending_want_record.cpp index dc2b1b4b69..e206559aaf 100644 --- a/services/abilitymgr/src/pending_want_record.cpp +++ b/services/abilitymgr/src/pending_want_record.cpp @@ -85,7 +85,19 @@ int32_t PendingWantRecord::SenderInner(SenderInfo &senderInfo) BuildSendWant(senderInfo, want); bool sendFinish = (senderInfo.finishedReceiver != nullptr); - int res = NO_ERROR; + int32_t res = ExecuteOperation(pendingWantManager, senderInfo, want); + if (sendFinish && res != START_CANCELED) { + WantParams wantParams = {}; + senderInfo.finishedReceiver->PerformReceive(want, senderInfo.code, "", wantParams, false, false, 0); + } + + return res; +} + +int32_t PendingWantRecord::ExecuteOperation( + std::shared_ptr pendingWantManager, SenderInfo &senderInfo, Want &want) +{ + int32_t res = NO_ERROR; switch (key_->GetType()) { case static_cast(OperationType::START_ABILITY): res = pendingWantManager->PendingWantStartAbility(want, senderInfo.startOptions, @@ -112,12 +124,6 @@ int32_t PendingWantRecord::SenderInner(SenderInfo &senderInfo) default: break; } - - if (sendFinish && res != START_CANCELED) { - WantParams wantParams = {}; - senderInfo.finishedReceiver->PerformReceive(want, senderInfo.code, "", wantParams, false, false, 0); - } - return res; } diff --git a/utils/server/startup/src/startup_util.cpp b/utils/server/startup/src/startup_util.cpp index 74e625129a..43ab840c7a 100644 --- a/utils/server/startup/src/startup_util.cpp +++ b/utils/server/startup/src/startup_util.cpp @@ -106,7 +106,7 @@ int64_t StartupUtil::GenerateFullRequestCode(int32_t pid, bool backFlag, int32_t return 0; } uint64_t fullRequestCode = static_cast(requestCode); - uint64_t tempNum = pid; + uint64_t tempNum = static_cast(pid); fullRequestCode |= (tempNum << REQUEST_CODE_LENGTH); if (backFlag) { tempNum = 1; From 8a789a2e9e88048cdc90438593e79900622f7efe Mon Sep 17 00:00:00 2001 From: c30051536 Date: Sun, 25 Aug 2024 13:22:57 +0800 Subject: [PATCH 37/42] add new check Signed-off-by: c30051536 --- .../distributed_mission_manager.cpp | 4 +- .../distributed_mission_manager.h | 2 +- .../include/ability_manager_errors.h | 5 --- .../abilitymgr/include/ability_manager_stub.h | 1 - .../src/ability_manager_service.cpp | 4 ++ .../abilitymgr/src/ability_manager_stub.cpp | 40 ------------------- 6 files changed, 8 insertions(+), 48 deletions(-) diff --git a/frameworks/js/napi/mission_manager/distributed_mission_manager.cpp b/frameworks/js/napi/mission_manager/distributed_mission_manager.cpp index dfb88c42ca..1e2a6b303a 100644 --- a/frameworks/js/napi/mission_manager/distributed_mission_manager.cpp +++ b/frameworks/js/napi/mission_manager/distributed_mission_manager.cpp @@ -74,7 +74,7 @@ static int32_t ErrorCodeReturn(int32_t code) return CONTINUE_ALREADY_IN_PROGRESS; case MISSION_FOR_CONTINUING_IS_NOT_ALIVE: return MISSION_FOR_CONTINUING_IS_NOT_ALIVE; - case ERR_NOT_SYSTEM_APP_CALL: + case ERR_NOT_SYSTEM_APP: return NOT_SYSTEM_APP; default: return SYSTEM_WORK_ABNORMALLY; @@ -117,6 +117,8 @@ static std::string ErrorMessageReturn(int32_t code) case ERR_BIND_REMOTE_IN_BUSY_LINK: return std::string("the remote device has been linked with other devices, try again when " "the remote device is idle."); + case NOT_SYSTEM_APP: + return std::string("The app is not system-app."); default: return std::string("the system ability work abnormally."); }; diff --git a/frameworks/js/napi/mission_manager/distributed_mission_manager.h b/frameworks/js/napi/mission_manager/distributed_mission_manager.h index 4e62628996..c5760591dd 100644 --- a/frameworks/js/napi/mission_manager/distributed_mission_manager.h +++ b/frameworks/js/napi/mission_manager/distributed_mission_manager.h @@ -227,7 +227,7 @@ enum ErrorCode { */ PERMISSION_DENIED = 201, /** - * Result(202) for not syatem app call. + * Result(202) for non-system-app use system-api. */ NOT_SYSTEM_APP = 202, /** diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h index b6d3627d44..db8ff6241b 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -590,11 +590,6 @@ enum { */ ERR_NATIVE_ARGS_CHILD_PROCESS_REACH_LIMIT = 2097266, - /* - * Result (2097267) for not syatem app call. - */ - ERR_NOT_SYSTEM_APP_CALL = 2097267, - /** * Native error(3000000) for target bundle not exist. */ diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index aef8e9a33e..a295d5967b 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -193,7 +193,6 @@ private: int UpdateMissionSnapShotFromWMSInner(MessageParcel &data, MessageParcel &reply); int RegisterConnectionObserverInner(MessageParcel &data, MessageParcel &reply); int UnregisterConnectionObserverInner(MessageParcel &data, MessageParcel &reply); - bool IsSystemApp(); #ifdef WITH_DLP int GetDlpConnectionInfosInner(MessageParcel &data, MessageParcel &reply); #endif // WITH_DLP diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 0e3dd49964..7d9bf136e5 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -4121,6 +4121,7 @@ int AbilityManagerService::DisconnectRemoteAbility(const sptr &co int AbilityManagerService::ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId, int32_t missionId, const sptr &callBack, AAFwk::WantParams &wantParams) { + CHECK_CALLER_IS_SYSTEM_APP; TAG_LOGI(AAFwkTag::ABILITYMGR, "ContinueMission missionId: %{public}d", missionId); if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: Permission verification failed", __func__); @@ -4134,6 +4135,7 @@ int AbilityManagerService::ContinueMission(const std::string &srcDeviceId, const int AbilityManagerService::ContinueMission(AAFwk::ContinueMissionInfo continueMissionInfo, const sptr &callback) { + CHECK_CALLER_IS_SYSTEM_APP; TAG_LOGI(AAFwkTag::ABILITYMGR, "called"); AAFWK::ContinueRadar::GetInstance().ClickIconContinue("ContinueMission"); if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) { @@ -4265,6 +4267,7 @@ int AbilityManagerService::NotifyContinuationResult(int32_t missionId, int32_t r int AbilityManagerService::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) { + CHECK_CALLER_IS_SYSTEM_APP; if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: Permission verification failed", __func__); return CHECK_PERMISSION_FAILED; @@ -4275,6 +4278,7 @@ int AbilityManagerService::StartSyncRemoteMissions(const std::string& devId, boo int AbilityManagerService::StopSyncRemoteMissions(const std::string& devId) { + CHECK_CALLER_IS_SYSTEM_APP; if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: Permission verification failed", __func__); return CHECK_PERMISSION_FAILED; diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 1aa36d448a..269e0c12f3 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -19,9 +19,7 @@ #include "ability_manager_radar.h" #include "hilog_tag_wrapper.h" #include "hitrace_meter.h" -#include "ipc_skeleton.h" #include "status_bar_delegate_interface.h" -#include "tokenid_kit.h" #include namespace OHOS { @@ -1930,10 +1928,6 @@ int AbilityManagerStub::IsRamConstrainedDeviceInner(MessageParcel &data, Message int AbilityManagerStub::ContinueMissionInner(MessageParcel &data, MessageParcel &reply) { - if (!IsSystemApp()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Not system app."); - return ERR_NOT_SYSTEM_APP; - } TAG_LOGI(AAFwkTag::ABILITYMGR, "called"); std::string srcDeviceId = data.ReadString(); std::string dstDeviceId = data.ReadString(); @@ -1955,10 +1949,6 @@ int AbilityManagerStub::ContinueMissionInner(MessageParcel &data, MessageParcel int AbilityManagerStub::ContinueMissionOfBundleNameInner(MessageParcel &data, MessageParcel &reply) { - if (!IsSystemApp()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Not system app."); - return ERR_NOT_SYSTEM_APP; - } TAG_LOGI(AAFwkTag::ABILITYMGR, "amsStub %{public}s called!", __func__); ContinueMissionInfo continueMissionInfo; continueMissionInfo.srcDeviceId = data.ReadString(); @@ -2396,10 +2386,6 @@ int AbilityManagerStub::GetProcessRunningInfosInner(MessageParcel &data, Message int AbilityManagerStub::StartSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply) { - if (!IsSystemApp()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Not system app."); - return ERR_NOT_SYSTEM_APP; - } std::string deviceId = data.ReadString(); bool fixConflict = data.ReadBool(); int64_t tag = data.ReadInt64(); @@ -2413,10 +2399,6 @@ int AbilityManagerStub::StartSyncRemoteMissionsInner(MessageParcel &data, Messag int AbilityManagerStub::StopSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply) { - if (!IsSystemApp()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Not system app."); - return ERR_NOT_SYSTEM_APP; - } int result = StopSyncRemoteMissions(data.ReadString()); if (!reply.WriteInt32(result)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "StopSyncRemoteMissionsInner failed."); @@ -2427,10 +2409,6 @@ int AbilityManagerStub::StopSyncRemoteMissionsInner(MessageParcel &data, Message int AbilityManagerStub::RegisterRemoteMissionListenerInner(MessageParcel &data, MessageParcel &reply) { - if (!IsSystemApp()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Not system app."); - return ERR_NOT_SYSTEM_APP; - } std::string deviceId = data.ReadString(); if (deviceId.empty()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "AbilityManagerStub: RegisterRemoteMissionListenerInner deviceId empty!"); @@ -2450,10 +2428,6 @@ int AbilityManagerStub::RegisterRemoteMissionListenerInner(MessageParcel &data, int AbilityManagerStub::RegisterRemoteOnListenerInner(MessageParcel &data, MessageParcel &reply) { - if (!IsSystemApp()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Not system app."); - return ERR_NOT_SYSTEM_APP; - } std::string type = data.ReadString(); if (type.empty()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "AbilityManagerStub: RegisterRemoteOnListenerInner type empty!"); @@ -2472,10 +2446,6 @@ int AbilityManagerStub::RegisterRemoteOnListenerInner(MessageParcel &data, Messa int AbilityManagerStub::RegisterRemoteOffListenerInner(MessageParcel &data, MessageParcel &reply) { - if (!IsSystemApp()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Not system app."); - return ERR_NOT_SYSTEM_APP; - } std::string type = data.ReadString(); if (type.empty()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "AbilityManagerStub: RegisterRemoteOffListenerInner type empty!"); @@ -2494,10 +2464,6 @@ int AbilityManagerStub::RegisterRemoteOffListenerInner(MessageParcel &data, Mess int AbilityManagerStub::UnRegisterRemoteMissionListenerInner(MessageParcel &data, MessageParcel &reply) { - if (!IsSystemApp()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Not system app."); - return ERR_NOT_SYSTEM_APP; - } std::string deviceId = data.ReadString(); if (deviceId.empty()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "AbilityManagerStub: UnRegisterRemoteMissionListenerInner deviceId empty!"); @@ -2952,12 +2918,6 @@ int AbilityManagerStub::UnregisterConnectionObserverInner(MessageParcel &data, M return UnregisterObserver(observer); } -bool AbilityManagerStub::IsSystemApp() -{ - uint64_t accessTokenIDEx = IPCSkeleton::GetCallingFullTokenID(); - return OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(accessTokenIDEx); -} - #ifdef WITH_DLP int AbilityManagerStub::GetDlpConnectionInfosInner(MessageParcel &data, MessageParcel &reply) { From 4f1ac4e0529956167309292675e52bc816eaef73 Mon Sep 17 00:00:00 2001 From: songjindian Date: Sat, 24 Aug 2024 18:09:23 +0800 Subject: [PATCH 38/42] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E6=80=A7=E4=BF=AE=E6=94=B9+=E6=97=A5=E5=BF=97=E4=B8=80?= =?UTF-8?q?=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songjindian --- .../inner_api/app_manager/include/appmgr/app_mgr_stub.h | 6 +++--- .../app_manager/include/appmgr/app_scheduler_host.h | 2 +- .../app_manager/include/appmgr/app_scheduler_interface.h | 4 ++-- .../app_manager/include/appmgr/app_scheduler_proxy.h | 4 ++-- .../inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp | 3 --- .../native/ability_business_error/ability_business_error.h | 2 +- services/abilitymgr/include/ability_manager_stub.h | 2 +- .../abilityappdebugmanager_fuzzer.cpp | 2 +- .../abilityappmgrevent_fuzzer/abilityappmgrevent_fuzzer.cpp | 4 ++-- .../abilitymemorylevelinfo_fuzzer.cpp | 2 ++ .../mock_ability_connect_callback_stub.h | 2 +- 11 files changed, 16 insertions(+), 17 deletions(-) diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h index 47ea448b15..6084462ec1 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h @@ -137,7 +137,7 @@ private: int32_t HandleGetChildProcessInfoForSelf(MessageParcel &data, MessageParcel &reply); int32_t HandleAttachChildProcess(MessageParcel &data, MessageParcel &reply); int32_t HandleExitChildProcessSafely(MessageParcel &data, MessageParcel &reply); - int32_t HandleClearUpApplicationDataBySelf(MessageParcel& data, MessageParcel& reply); + int32_t HandleClearUpApplicationDataBySelf(MessageParcel &data, MessageParcel& reply); int32_t HandleIsFinalAppProcess(MessageParcel &data, MessageParcel &reply); int32_t HandleRegisterRenderStateObserver(MessageParcel &data, MessageParcel &reply); int32_t HandleUnregisterRenderStateObserver(MessageParcel &data, MessageParcel &reply); @@ -147,11 +147,11 @@ private: int32_t HandleGetAllUIExtensionRootHostPid(MessageParcel &data, MessageParcel &reply); int32_t HandleGetAllUIExtensionProviderPid(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyMemorySizeStateChanged(MessageParcel &data, MessageParcel &reply); - int32_t HandleSetAppAssertionPauseState(MessageParcel& data, MessageParcel& reply); + int32_t HandleSetAppAssertionPauseState(MessageParcel &data, MessageParcel& reply); int32_t HandleSetSupportedProcessCacheSelf(MessageParcel &data, MessageParcel &reply); int32_t HandleSaveBrowserChannel(MessageParcel &data, MessageParcel &reply); int32_t HandleCheckCallingIsUserTestMode(MessageParcel &data, MessageParcel &reply); - int32_t HandleStartNativeChildProcess(MessageParcel& data, MessageParcel& reply); + int32_t HandleStartNativeChildProcess(MessageParcel &data, MessageParcel& reply); int32_t HandleNotifyProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply); int32_t HandleKillProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply); int32_t HandleRestartResidentProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply); 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 5f0a8d8a07..ccd75c0458 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 @@ -65,8 +65,8 @@ private: int32_t HandleScheduleDumpIpcStart(MessageParcel &data, MessageParcel &reply); 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); + int32_t HandleScheduleDumpFfrt(MessageParcel &data, MessageParcel &reply); int32_t OnRemoteRequestInner(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); int32_t OnRemoteRequestInnerFirst(uint32_t code, MessageParcel &data, 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 a4c47ffb44..3fe83c0cdb 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 @@ -264,6 +264,8 @@ public: */ virtual int32_t ScheduleDumpIpcStat(std::string& result) = 0; + virtual void ScheduleCacheProcess() = 0; + /** * ScheduleDumpFfrt, call ScheduleDumpFfrt(std::string& result) through proxy project, * Start querying the application's ffrt usage. @@ -274,8 +276,6 @@ 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, 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 e81152a5e8..d05892069e 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 @@ -224,6 +224,8 @@ public: */ virtual int32_t ScheduleDumpIpcStat(std::string& result) override; + virtual void ScheduleCacheProcess() override; + /** * ScheduleDumpFfrt, call ScheduleDumpFfrt(std::string& result) through proxy project, * Start querying the application's ffrt usage. @@ -234,8 +236,6 @@ 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/ams_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp index 9e9be3a337..a045a044c2 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp @@ -398,17 +398,14 @@ int32_t AmsMgrProxy::KillApplication(const std::string &bundleName, const bool c if (!WriteInterfaceToken(data)) { return ERR_INVALID_DATA; } - if (!data.WriteString(bundleName)) { TAG_LOGE(AAFwkTag::APPMGR, "parcel WriteString failed."); return ERR_FLATTEN_OBJECT; } - if (!data.WriteBool(clearPageStack)) { TAG_LOGE(AAFwkTag::APPMGR, "parcel bool failed"); return ERR_FLATTEN_OBJECT; } - int32_t ret = SendTransactCmd(static_cast(IAmsMgr::Message::KILL_APPLICATION), data, reply, option); if (ret != NO_ERROR) { diff --git a/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h b/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h index 1afe0885c0..d3a6717d8f 100644 --- a/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h +++ b/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h @@ -146,7 +146,7 @@ enum class AbilityErrorCode { // extension start service has been controlled. ERROR_CODE_EXTENSION_START_SERVICE_CONTROLLED = 16000070, - + // app is not Clone. ERROR_NOT_APP_CLONE = 16000071, diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index 0f40c5e63a..cad663f5ca 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -295,10 +295,10 @@ private: int32_t StartAbilityByInsightIntentInner(MessageParcel &data, MessageParcel &reply); int32_t ExecuteInsightIntentDoneInner(MessageParcel &data, MessageParcel &reply); int32_t GetForegroundUIAbilitiesInner(MessageParcel &data, MessageParcel &reply); + int32_t RestartAppInner(MessageParcel &data, MessageParcel &reply); int32_t GetUIExtensionRootHostInfoInner(MessageParcel &data, MessageParcel &reply); int32_t GetUIExtensionSessionInfoInner(MessageParcel &data, MessageParcel &reply); - int32_t RestartAppInner(MessageParcel &data, MessageParcel &reply); int32_t RequestAssertFaultDialogInner(MessageParcel &data, MessageParcel &reply); int32_t NotifyDebugAssertResultInner(MessageParcel &data, MessageParcel &reply); int32_t StartShortcutInner(MessageParcel &data, MessageParcel &reply); diff --git a/test/fuzztest/abilityappdebugmanager_fuzzer/abilityappdebugmanager_fuzzer.cpp b/test/fuzztest/abilityappdebugmanager_fuzzer/abilityappdebugmanager_fuzzer.cpp index 3819193eeb..57a31f3b02 100644 --- a/test/fuzztest/abilityappdebugmanager_fuzzer/abilityappdebugmanager_fuzzer.cpp +++ b/test/fuzztest/abilityappdebugmanager_fuzzer/abilityappdebugmanager_fuzzer.cpp @@ -48,7 +48,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) AppDebugInfo info; manager->RemoveAppDebugInfo(info); std::vector incrementInfos; - manager->GetIncrementAppDebugInfos(infos,incrementInfos); + manager->GetIncrementAppDebugInfos(infos, incrementInfos); return true; } } diff --git a/test/fuzztest/abilityappmgrevent_fuzzer/abilityappmgrevent_fuzzer.cpp b/test/fuzztest/abilityappmgrevent_fuzzer/abilityappmgrevent_fuzzer.cpp index a03cbe4687..3dd6eb315a 100644 --- a/test/fuzztest/abilityappmgrevent_fuzzer/abilityappmgrevent_fuzzer.cpp +++ b/test/fuzztest/abilityappmgrevent_fuzzer/abilityappmgrevent_fuzzer.cpp @@ -45,10 +45,10 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) AppMgrEventUtil::SendCreateAtomicServiceProcessEvent(callerAppRecord, appRecord, stringParam, stringParam); AAFwk::EventInfo eventInfo; - AppMgrEventUtil::SendProcessStartEvent(callerAppRecord, appRecord, eventInfo); + AppMgrEventUtil::SendProcessStartEvent(callerAppRecord, appRecord, eventInfo); int32_t appUid = static_cast(GetU32Data(data)); int64_t restartTime = static_cast(GetU32Data(data)); - AppMgrEventUtil::SendReStartProcessEvent(eventInfo, appUid, restartTime); + AppMgrEventUtil::SendReStartProcessEvent(eventInfo, appUid, restartTime); AppMgrEventUtil::GetCallerPid(callerAppRecord); std::shared_ptr abilityInfo; int32_t abilityType = static_cast(GetU32Data(data)); diff --git a/test/fuzztest/abilitymemorylevelinfo_fuzzer/abilitymemorylevelinfo_fuzzer.cpp b/test/fuzztest/abilitymemorylevelinfo_fuzzer/abilitymemorylevelinfo_fuzzer.cpp index 3163b806d3..af0c925e02 100644 --- a/test/fuzztest/abilitymemorylevelinfo_fuzzer/abilitymemorylevelinfo_fuzzer.cpp +++ b/test/fuzztest/abilitymemorylevelinfo_fuzzer/abilitymemorylevelinfo_fuzzer.cpp @@ -27,7 +27,9 @@ #include #include "securec.h" #include "configuration.h" + using namespace OHOS::AppExecFwk; + namespace OHOS { namespace { constexpr int INPUT_ZERO = 0; diff --git a/test/unittest/ability_connect_callback_stub_test/mock_ability_connect_callback_stub.h b/test/unittest/ability_connect_callback_stub_test/mock_ability_connect_callback_stub.h index 504e68a1a4..6a1dc870ff 100644 --- a/test/unittest/ability_connect_callback_stub_test/mock_ability_connect_callback_stub.h +++ b/test/unittest/ability_connect_callback_stub_test/mock_ability_connect_callback_stub.h @@ -16,8 +16,8 @@ #ifndef UNITTEST_OHOS_ABILITY_RUNTIME_MOCK_ABILITY_CONNECT_CALLBACK_STUB_H #define UNITTEST_OHOS_ABILITY_RUNTIME_MOCK_ABILITY_CONNECT_CALLBACK_STUB_H -#include "ability_connect_callback_stub.h" #include +#include "ability_connect_callback_stub.h" #include "semaphore_ex.h" namespace OHOS { From db2b4a394e540045e053f1acf7216a8f145887cf Mon Sep 17 00:00:00 2001 From: donglin Date: Mon, 26 Aug 2024 01:23:58 +0000 Subject: [PATCH 39/42] change proxy sync Signed-off-by: donglin Change-Id: I5cdfa68d87bdd85b8d42c927093b3c9ef4a20155 --- services/abilitymgr/src/ability_manager_collaborator_proxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/src/ability_manager_collaborator_proxy.cpp b/services/abilitymgr/src/ability_manager_collaborator_proxy.cpp index fd8f150c49..35e4626015 100644 --- a/services/abilitymgr/src/ability_manager_collaborator_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_collaborator_proxy.cpp @@ -503,7 +503,7 @@ int32_t AbilityManagerCollaboratorProxy::CheckStaticCfgPermission(const Want &wa { MessageParcel data; MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed."); return ERR_INVALID_OPERATION; From d2a2b30c3ab3f23867ba75d9a14530c03af0b950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Sat, 24 Aug 2024 20:08:45 +0800 Subject: [PATCH 40/42] =?UTF-8?q?description:=E4=BF=AE=E6=94=B9tdd?= =?UTF-8?q?=E7=94=A8=E4=BE=8Bcrash=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- test/unittest/ams_app_mgr_client_test/BUILD.gn | 6 ++++++ test/unittest/runtime_test/js_runtime_first_test.cpp | 3 +++ test/unittest/sender_info_test/BUILD.gn | 6 ++++++ .../ui_extension/extension_record_manager_test/BUILD.gn | 6 ++++++ test/unittest/want_receiver_stub_test/BUILD.gn | 6 ++++++ 5 files changed, 27 insertions(+) diff --git a/test/unittest/ams_app_mgr_client_test/BUILD.gn b/test/unittest/ams_app_mgr_client_test/BUILD.gn index d73f2c1e50..acc23a4e00 100644 --- a/test/unittest/ams_app_mgr_client_test/BUILD.gn +++ b/test/unittest/ams_app_mgr_client_test/BUILD.gn @@ -17,6 +17,12 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/appmgrservice" ohos_unittest("AmsAppMgrClientTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../../cfi_blocklist.txt" + } module_out_path = module_output_path cflags_cc = [] sources = [ diff --git a/test/unittest/runtime_test/js_runtime_first_test.cpp b/test/unittest/runtime_test/js_runtime_first_test.cpp index 706c369d23..ea5ebadf11 100644 --- a/test/unittest/runtime_test/js_runtime_first_test.cpp +++ b/test/unittest/runtime_test/js_runtime_first_test.cpp @@ -87,6 +87,7 @@ HWTEST_F(JsRuntimeTest, UpdatePkgContextInfoJson_0100, TestSize.Level1) ASSERT_NE(jsRuntime, nullptr); bool isDebugApp = true; bool isStartWithDebug = false; + jsRuntime->jsEnv_->vm_ = nullptr; jsRuntime->DebuggerConnectionHandler(isDebugApp, isStartWithDebug); jsRuntime.reset(); } @@ -123,6 +124,7 @@ HWTEST_F(JsRuntimeTest, GetSafeData_0100, TestSize.Level1) ASSERT_NE(jsRuntime, nullptr); std::string Path = ""; std::string fileFullName = ""; + jsRuntime->jsEnv_->vm_ = nullptr; jsRuntime->GetSafeData(Path, fileFullName); jsRuntime.reset(); std::this_thread::sleep_for(std::chrono::milliseconds(200)); @@ -149,6 +151,7 @@ HWTEST_F(JsRuntimeTest, DebuggerConnectionManager_0100, TestSize.Level1) dOption.processName = "test"; dOption.isDebugApp = true; dOption.isStartWithNative = false; + jsRuntime->jsEnv_->vm_ = nullptr; jsRuntime->DebuggerConnectionManager(isDebugApp, isStartWithDebug, dOption); jsRuntime.reset(); std::this_thread::sleep_for(std::chrono::milliseconds(200)); diff --git a/test/unittest/sender_info_test/BUILD.gn b/test/unittest/sender_info_test/BUILD.gn index 8f612b904d..9ea9ff36a2 100644 --- a/test/unittest/sender_info_test/BUILD.gn +++ b/test/unittest/sender_info_test/BUILD.gn @@ -17,6 +17,12 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/abilitymgr" ohos_unittest("sender_info_test") { + 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/ui_extension/extension_record_manager_test/BUILD.gn b/test/unittest/ui_extension/extension_record_manager_test/BUILD.gn index 30dd9c4ee1..7c2692bf65 100755 --- a/test/unittest/ui_extension/extension_record_manager_test/BUILD.gn +++ b/test/unittest/ui_extension/extension_record_manager_test/BUILD.gn @@ -16,6 +16,12 @@ import("//build/test.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") ohos_unittest("extension_record_manager_test") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../../../cfi_blocklist.txt" + } module_out_path = "ability_runtime/ui_extension" cflags_cc = [] diff --git a/test/unittest/want_receiver_stub_test/BUILD.gn b/test/unittest/want_receiver_stub_test/BUILD.gn index 415a4cd9f9..54b143d6eb 100644 --- a/test/unittest/want_receiver_stub_test/BUILD.gn +++ b/test/unittest/want_receiver_stub_test/BUILD.gn @@ -17,6 +17,12 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/abilitymgr" ohos_unittest("want_receiver_stub_test") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../../cfi_blocklist.txt" + } module_out_path = module_output_path include_dirs = [ From 40cd5e54df5d0847af0a39c43229a3916bfa0748 Mon Sep 17 00:00:00 2001 From: liuzongze Date: Mon, 26 Aug 2024 14:28:50 +0800 Subject: [PATCH 41/42] =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=B6=85=E9=99=90?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liuzongze Change-Id: If06a2e7aa54dcd24731ac4182309d2fcf507077f --- .../deps_wrapper/src/os_account_manager_wrapper.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/interfaces/inner_api/deps_wrapper/src/os_account_manager_wrapper.cpp b/interfaces/inner_api/deps_wrapper/src/os_account_manager_wrapper.cpp index ad25d833b7..cf5841e718 100644 --- a/interfaces/inner_api/deps_wrapper/src/os_account_manager_wrapper.cpp +++ b/interfaces/inner_api/deps_wrapper/src/os_account_manager_wrapper.cpp @@ -33,11 +33,11 @@ const int32_t UID_TRANSFORM_DIVISOR = 200000; ErrCode OsAccountManagerWrapper::QueryActiveOsAccountIds(std::vector& ids) { #ifndef OS_ACCOUNT_PART_ENABLED - TAG_LOGI(AAFwkTag::DEFAULT, "Without os account subsystem"); + TAG_LOGD(AAFwkTag::DEFAULT, "Without os account subsystem"); ids.emplace_back(DEFAULT_OS_ACCOUNT_ID); return ERR_OK; #else - TAG_LOGI(AAFwkTag::DEFAULT, "os account subsystem"); + TAG_LOGD(AAFwkTag::DEFAULT, "os account subsystem"); return AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids); #endif // OS_ACCOUNT_PART_ENABLED } @@ -45,11 +45,11 @@ ErrCode OsAccountManagerWrapper::QueryActiveOsAccountIds(std::vector& i ErrCode OsAccountManagerWrapper::GetOsAccountLocalIdFromUid(const int32_t uid, int32_t &id) { #ifndef OS_ACCOUNT_PART_ENABLED - TAG_LOGI(AAFwkTag::DEFAULT, "Without os account subsystem"); + TAG_LOGD(AAFwkTag::DEFAULT, "Without os account subsystem"); id = uid / UID_TRANSFORM_DIVISOR; return ERR_OK; #else - TAG_LOGI(AAFwkTag::DEFAULT, "os account subsystem"); + TAG_LOGD(AAFwkTag::DEFAULT, "os account subsystem"); return AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, id); #endif // OS_ACCOUNT_PART_ENABLED } @@ -100,7 +100,7 @@ ErrCode OsAccountManagerWrapper::RemoveOsAccount(const int id) TAG_LOGD(AAFwkTag::DEFAULT, "Without os account subsystem"); return ERR_OK; #else // OS_ACCOUNT_PART_ENABLED - TAG_LOGI(AAFwkTag::DEFAULT, "os account subsystem"); + TAG_LOGD(AAFwkTag::DEFAULT, "os account subsystem"); return AccountSA::OsAccountManager::RemoveOsAccount(id); #endif // OS_ACCOUNT_PART_ENABLED } From 2de775a3751c34880ead39a60e3f41ced7513df6 Mon Sep 17 00:00:00 2001 From: yuwenze Date: Mon, 26 Aug 2024 15:08:23 +0800 Subject: [PATCH 42/42] fixed Signed-off-by: yuwenze Change-Id: Id69b570e9e40f3fa4909d8e0b291a02158af1943 --- services/abilitymgr/src/ability_connect_manager.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 97f50ac18c..2ac6d1cbdc 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -1588,19 +1588,21 @@ void AbilityConnectManager::HandleStartTimeoutTask(const std::shared_ptrGetURI().c_str(), userId_); - RemoveServiceAbility(abilityRecord); if (abilityRecord->IsSceneBoard()) { auto isAttached = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->IsProcessAttached( abilityRecord->GetToken())); DelayedSingleton::GetInstance()->AttachTimeOut(abilityRecord->GetToken()); if (!isAttached) { + MoveToTerminatingMap(abilityRecord); + RemoveServiceAbility(abilityRecord); RestartAbility(abilityRecord, userId_); } return; } + MoveToTerminatingMap(abilityRecord); + RemoveServiceAbility(abilityRecord); DelayedSingleton::GetInstance()->AttachTimeOut(abilityRecord->GetToken()); if (IsAbilityNeedKeepAlive(abilityRecord)) { TAG_LOGW(AAFwkTag::ABILITYMGR, "Load time out, try to restart");