From bbb7018ee3e6517dce7481bdfff9e210e010baae Mon Sep 17 00:00:00 2001 From: jsjzju Date: Wed, 13 Nov 2024 01:55:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jsjzju Change-Id: I35d801626cc3665af4642016a9315a6a07de50ae --- .../include/appmgr/ams_mgr_interface.h | 6 ++ .../include/appmgr/ams_mgr_proxy.h | 2 + .../app_manager/include/appmgr/ams_mgr_stub.h | 1 + .../include/appmgr/app_mgr_client.h | 2 + .../app_manager/src/appmgr/ams_mgr_proxy.cpp | 22 +++++++ .../app_manager/src/appmgr/ams_mgr_stub.cpp | 14 ++++ .../app_manager/src/appmgr/app_mgr_client.cpp | 13 ++++ services/abilitymgr/include/app_scheduler.h | 2 + services/abilitymgr/src/app_scheduler.cpp | 9 +++ .../ui_ability_lifecycle_manager.cpp | 12 +++- services/appmgr/include/ams_mgr_scheduler.h | 2 + .../appmgr/include/app_mgr_service_inner.h | 11 +++- .../appmgr/include/killing_process_manager.h | 6 +- services/appmgr/src/ams_mgr_scheduler.cpp | 9 +++ services/appmgr/src/app_mgr_service_inner.cpp | 36 ++++++---- .../appmgr/src/killing_process_manager.cpp | 7 +- .../ams_mgr_scheduler_second_test.cpp | 65 +++++++++++++++++++ .../app_mgr_client_first_test.cpp | 14 ++++ .../app_mgr_service_inner_test.cpp | 19 +++--- 19 files changed, 218 insertions(+), 34 deletions(-) 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 bf24b2f8e6..b0adff0e71 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 @@ -449,6 +449,11 @@ public: return false; } + virtual bool IsCallerKilling(const std::string& callerKey) + { + return false; + } + virtual void SetAppExceptionCallback(sptr callback) {} enum class Message { @@ -502,6 +507,7 @@ public: CLEAN_UIABILITY_BY_USER_REQUEST, FORCE_KILL_APPLICATION_BY_ACCESS_TOKEN_ID = 49, IS_PROCESS_ATTACHED, + IS_CALLER_KILLING, ENABLE_START_PROCESS_FLAG_BY_USER_ID, SET_APP_EXCEPTION_CALLBACK, SET_KEEP_ALIVE_DKV, 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 7926689b46..1b25574e3a 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 @@ -400,6 +400,8 @@ public: */ virtual bool IsProcessAttached(sptr token) override; + virtual bool IsCallerKilling(const std::string& callerKey) override; + virtual void SetAppExceptionCallback(sptr callback) override; private: diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h index 7d39abdb23..7531a90964 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h @@ -102,6 +102,7 @@ private: int32_t HandleCleanAbilityByUserRequest(MessageParcel &data, MessageParcel &reply); int32_t HandleIsProcessContainsOnlyUIAbility(MessageParcel &data, MessageParcel &reply); int32_t HandleIsProcessAttached(MessageParcel &data, MessageParcel &reply); + int32_t HandleIsCallerKilling(MessageParcel &data, MessageParcel &reply); int32_t HandleSetAppExceptionCallback(MessageParcel &data, MessageParcel &reply); DISALLOW_COPY_AND_MOVE(AmsMgrStub); }; 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 53371d0f83..a65d1c50c5 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 @@ -899,6 +899,8 @@ public: */ bool IsProcessAttached(sptr token) const; + bool IsCallerKilling(const std::string& callerKey) const; + /** * Check whether the bundle is running. * 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 475d894d87..a485eb4a60 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 @@ -1344,6 +1344,28 @@ bool AmsMgrProxy::IsProcessAttached(sptr token) return reply.ReadBool(); } +bool AmsMgrProxy::IsCallerKilling(const std::string& callerKey) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); + return false; + } + if (!data.WriteString(callerKey)) { + TAG_LOGE(AAFwkTag::APPMGR, "Failed to write callerKey"); + return false; + } + + auto ret = SendTransactCmd(static_cast(IAmsMgr::Message::IS_CALLER_KILLING), data, reply, option); + if (ret != NO_ERROR) { + TAG_LOGE(AAFwkTag::APPMGR, "Send request failed, error code is %{public}d.", ret); + return false; + } + return reply.ReadBool(); +} + void AmsMgrProxy::SetAppExceptionCallback(sptr callback) { MessageParcel data; diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp index 5a99f7ecd0..354e16c250 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp @@ -213,6 +213,8 @@ int32_t AmsMgrStub::OnRemoteRequestInnerFourth(uint32_t code, MessageParcel &dat return HandleKillProcessesByAccessTokenId(data, reply); case static_cast(IAmsMgr::Message::IS_PROCESS_ATTACHED): return HandleIsProcessAttached(data, reply); + case static_cast(IAmsMgr::Message::IS_CALLER_KILLING): + return HandleIsCallerKilling(data, reply); case static_cast(IAmsMgr::Message::SET_KEEP_ALIVE_DKV): return HandleSetKeepAliveDkv(data, reply); } @@ -861,6 +863,18 @@ int32_t AmsMgrStub::HandleIsProcessAttached(MessageParcel &data, MessageParcel & return NO_ERROR; } +int32_t AmsMgrStub::HandleIsCallerKilling(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER(HITRACE_TAG_APP); + auto callerKey = data.ReadString(); + auto isCallerKilling = IsCallerKilling(callerKey); + if (!reply.WriteBool(isCallerKilling)) { + TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result"); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int32_t AmsMgrStub::HandleSetAppExceptionCallback(MessageParcel &data, MessageParcel &reply) { sptr callback = data.ReadRemoteObject(); 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 5927e9535e..14a90bb286 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 @@ -1399,6 +1399,19 @@ bool AppMgrClient::IsProcessAttached(sptr token) const return amsService->IsProcessAttached(token); } +bool AppMgrClient::IsCallerKilling(const std::string& callerKey) const +{ + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service == nullptr) { + return false; + } + sptr amsService = service->GetAmsMgr(); + if (amsService == nullptr) { + return false; + } + return amsService->IsCallerKilling(callerKey); +} + AppMgrResultCode AppMgrClient::IsAppRunning(const std::string &bundleName, int32_t appCloneIndex, bool &isRunning) { diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 0889a043aa..a811961224 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -568,6 +568,8 @@ public: bool IsProcessAttached(sptr token) const; + bool IsCallerKilling(const std::string& callerKey) const; + protected: /** * OnAbilityRequestDone, app manager service call this interface after ability request done. diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index ef1c86cd03..b69bda707f 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -655,6 +655,15 @@ bool AppScheduler::IsProcessAttached(sptr token) const return appMgrClient_->IsProcessAttached(token); } +bool AppScheduler::IsCallerKilling(const std::string& callerKey) const +{ + if (!appMgrClient_) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "appMgrClient is nullptr"); + return false; + } + return appMgrClient_->IsCallerKilling(callerKey); +} + void AppScheduler::SetProcessCacheStatus(int32_t pid, bool isSupport) { if (!appMgrClient_) { 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 17e708ff9c..8e50167a77 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -30,7 +30,6 @@ #include "session/host/include/zidl/session_interface.h" #include "startup_util.h" #include "ui_extension_utils.h" -#include "utils/ability_permission_util.h" #ifdef SUPPORT_GRAPHICS #include "ability_first_frame_state_observer_manager.h" #endif @@ -168,6 +167,12 @@ bool UIAbilityLifecycleManager::CheckSessionInfo(sptr sessionInfo) TAG_LOGE(AAFwkTag::ABILITYMGR, "token's Descriptor: %{public}s", descriptor.c_str()); return false; } + std::string callerKey = sessionInfo->want.GetStringParam(Want::PARAMS_REAL_CALLER_KEY); + bool isCallerKilling = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->IsCallerKilling(callerKey)); + if (isCallerKilling) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "caller is killing"); + return false; + } return true; } @@ -345,6 +350,11 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(AbilityRequest &ability abilityRequest.want.SetParam(IS_SHELL_CALL, AAFwk::PermissionVerification::GetInstance()->IsShellCall()); std::string callerKey = std::to_string(IPCSkeleton::GetCallingPid()) + ":" + std::to_string(IPCSkeleton::GetCallingUid()); + bool isCallerKilling = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->IsCallerKilling(callerKey)); + if (isCallerKilling) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "caller is killing"); + return ERR_INVALID_VALUE; + } abilityRequest.want.SetParam(Want::PARAMS_REAL_CALLER_KEY, callerKey); std::lock_guard guard(sessionLock_); // start ability with persistentId by dms diff --git a/services/appmgr/include/ams_mgr_scheduler.h b/services/appmgr/include/ams_mgr_scheduler.h index b6c82d2a06..2e9a39ef1d 100644 --- a/services/appmgr/include/ams_mgr_scheduler.h +++ b/services/appmgr/include/ams_mgr_scheduler.h @@ -427,6 +427,8 @@ public: */ virtual bool IsProcessAttached(sptr token) override; + virtual bool IsCallerKilling(const std::string& callerKey) override; + virtual void SetAppExceptionCallback(sptr callback) override; private: diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 9414f9d50c..b5184ce60b 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -1369,6 +1369,12 @@ public: */ bool IsProcessAttached(sptr token) const; + /** + * Is a process of a ability killing + * @param indicates the ability + */ + bool IsCallerKilling(const std::string& callerKey) const; + /** * @brief Notify abilityms app process pre cache * @param pid process pid. @@ -1423,9 +1429,8 @@ private: */ void RestartKeepAliveProcess(std::shared_ptr appRecord); - bool CheckLoadAbilityConditions(std::shared_ptr want, - std::shared_ptr loadParam, const std::shared_ptr &abilityInfo, - const std::shared_ptr &appInfo); + bool CheckLoadAbilityConditions(const sptr &token, + const std::shared_ptr &abilityInfo, const std::shared_ptr &appInfo); /** * query bundle info for the given bundleName diff --git a/services/appmgr/include/killing_process_manager.h b/services/appmgr/include/killing_process_manager.h index 684a8b3e3b..ab503aca82 100644 --- a/services/appmgr/include/killing_process_manager.h +++ b/services/appmgr/include/killing_process_manager.h @@ -28,9 +28,9 @@ class KillingProcessManager { public: static KillingProcessManager& GetInstance(); ~KillingProcessManager() = default; - bool IsCallerKilling(std::string callerKey) const; - void AddKillingCallerKey(std::string callerKey); - void RemoveKillingCallerKey(std::string callerKey); + bool IsCallerKilling(const std::string& callerKey) const; + void AddKillingCallerKey(const std::string& callerKey); + void RemoveKillingCallerKey(const std::string& callerKey); private: KillingProcessManager() = default; diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index 5628928d48..2035178888 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -752,6 +752,15 @@ bool AmsMgrScheduler::IsProcessAttached(sptr token) return amsMgrServiceInner_->IsProcessAttached(token); } +bool AmsMgrScheduler::IsCallerKilling(const std::string& callerKey) +{ + if (!IsReady()) { + TAG_LOGE(AAFwkTag::APPMGR, "AmsMgrService is not ready."); + return false; + } + return amsMgrServiceInner_->IsCallerKilling(callerKey); +} + void AmsMgrScheduler::SetAppExceptionCallback(sptr callback) { if (!IsReady()) { diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index d486694e4d..eba56e1625 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -623,9 +623,8 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, s TAG_LOGE(AAFwkTag::APPMGR, "null loadParam"); return; } - if (!CheckLoadAbilityConditions(want, loadParam, abilityInfo, appInfo)) { + if (!CheckLoadAbilityConditions(loadParam->token, abilityInfo, appInfo)) { TAG_LOGE(AAFwkTag::APPMGR, "checkLoadAbilityConditions fail"); - NotifyLoadAbilityFailed(loadParam->token); return; } if (abilityInfo->type == AbilityType::PAGE) { @@ -648,8 +647,11 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, s BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; int32_t appIndex = 0; + std::string callerKey; if (want != nullptr) { (void)AbilityRuntime::StartupUtil::GetAppIndex(*want, appIndex); + callerKey = want->GetStringParam(Want::PARAMS_REAL_CALLER_KEY); + want->RemoveParam(Want::PARAMS_REAL_CALLER_KEY); } if (!GetBundleAndHapInfo(*abilityInfo, appInfo, bundleInfo, hapModuleInfo, appIndex)) { TAG_LOGE(AAFwkTag::APPMGR, "getBundleAndHapInfo fail"); @@ -691,6 +693,11 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, s if (!appRecord) { TAG_LOGD(AAFwkTag::APPMGR, "appRecord null"); + if (KillingProcessManager::GetInstance().IsCallerKilling(callerKey)) { + TAG_LOGE(AAFwkTag::APPMGR, "caller is killing"); + NotifyLoadAbilityFailed(loadParam->token); + return; + } bool appExistFlag = appRunningManager_->CheckAppRunningRecordIsExistByBundleName(bundleInfo.name); bool appMultiUserExistFlag = appRunningManager_->CheckAppRunningRecordIsExistByUid(bundleInfo.uid); if (!appMultiUserExistFlag) { @@ -827,11 +834,10 @@ void AppMgrServiceInner::RemoveUIExtensionLauncherItem(std::shared_ptrRemoveUIExtensionLauncherItemById(uiExtensionAbilityId); } -bool AppMgrServiceInner::CheckLoadAbilityConditions(std::shared_ptr want, - std::shared_ptr loadParam, const std::shared_ptr &abilityInfo, - const std::shared_ptr &appInfo) +bool AppMgrServiceInner::CheckLoadAbilityConditions(const sptr &token, + const std::shared_ptr &abilityInfo, const std::shared_ptr &appInfo) { - if (!loadParam || !loadParam->token || !abilityInfo || !appInfo) { + if (!token || !abilityInfo || !appInfo) { TAG_LOGE(AAFwkTag::APPMGR, "param error"); return false; } @@ -843,14 +849,6 @@ bool AppMgrServiceInner::CheckLoadAbilityConditions(std::shared_ptr TAG_LOGE(AAFwkTag::APPMGR, "abilityInfo and appInfo have diff appName"); return false; } - if (want) { - std::string callerKey = want->GetStringParam(Want::PARAMS_REAL_CALLER_KEY); - want->RemoveParam(Want::PARAMS_REAL_CALLER_KEY); - if (!callerKey.empty() && KillingProcessManager::GetInstance().IsCallerKilling(callerKey)) { - TAG_LOGE(AAFwkTag::APPMGR, "caller is killing"); - return false; - } - } return true; } @@ -8430,6 +8428,16 @@ bool AppMgrServiceInner::IsProcessAttached(sptr token) const return appRecord->IsProcessAttached(); } +bool AppMgrServiceInner::IsCallerKilling(const std::string& callerKey) const +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + if (IPCSkeleton::GetCallingUid() != FOUNDATION_UID) { + TAG_LOGE(AAFwkTag::APPMGR, "Not foundation call."); + return false; + } + return KillingProcessManager::GetInstance().IsCallerKilling(callerKey); +} + int32_t AppMgrServiceInner::GetSupportedProcessCachePids(const std::string &bundleName, std::vector &pidList) { diff --git a/services/appmgr/src/killing_process_manager.cpp b/services/appmgr/src/killing_process_manager.cpp index e42ec469f5..96ff39a169 100644 --- a/services/appmgr/src/killing_process_manager.cpp +++ b/services/appmgr/src/killing_process_manager.cpp @@ -31,13 +31,13 @@ KillingProcessManager& KillingProcessManager::GetInstance() return instance; } -bool KillingProcessManager::IsCallerKilling(std::string callerKey) const +bool KillingProcessManager::IsCallerKilling(const std::string& callerKey) const { std::lock_guard lock(mutex_); return killingCallerKeySet_.find(callerKey) != killingCallerKeySet_.end(); } -void KillingProcessManager::AddKillingCallerKey(std::string callerKey) +void KillingProcessManager::AddKillingCallerKey(const std::string& callerKey) { auto taskHandler = AAFwk::TaskHandlerWrap::GetFfrtHandler(); if (taskHandler == nullptr) { @@ -54,6 +54,7 @@ void KillingProcessManager::AddKillingCallerKey(std::string callerKey) auto ret = killingCallerKeySet_.insert(callerKey); if (!ret.second) { TAG_LOGI(AAFwkTag::APPMGR, "already inserted"); + return; } } auto task = [callerKey] () { @@ -62,7 +63,7 @@ void KillingProcessManager::AddKillingCallerKey(std::string callerKey) taskHandler->SubmitTask(task, "clearCallerKey", CLEAR_CALLER_KEY_DELAY_TIME); } -void KillingProcessManager::RemoveKillingCallerKey(std::string callerKey) +void KillingProcessManager::RemoveKillingCallerKey(const std::string& callerKey) { if (callerKey.empty()) { TAG_LOGE(AAFwkTag::APPMGR, "invalid callerKey"); diff --git a/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp b/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp index e98fff9382..a498606bf0 100644 --- a/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp +++ b/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp @@ -2060,6 +2060,71 @@ HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_IsProcessAttached_ EXPECT_FALSE(ret); TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_IsProcessAttached_003 end"); } + +/* + * @tc.name: AmsMgrSchedulerSecondTest_IsCallerKilling_001 + * @tc.desc: Test IsCallerKilling + * @tc.type: FUNC + */ +HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_IsCallerKilling_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_IsCallerKilling_001 start"); + auto appMgrServiceInner = std::make_shared(); + std::shared_ptr amsMgrScheduler = + std::make_shared(appMgrServiceInner, nullptr); + + /** + * @tc.steps: step1. amsMgrScheduler isReady false + * @tc.expected: step1. expect ERR_INVALID_OPERATION + */ + auto ret = amsMgrScheduler->IsCallerKilling(""); + EXPECT_FALSE(ret); + TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_IsCallerKilling_001 end"); +} + +/* + * @tc.name: AmsMgrSchedulerSecondTest_IsCallerKilling_002 + * @tc.desc: Test IsCallerKilling + * @tc.type: FUNC + */ +HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_IsCallerKilling_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_IsCallerKilling_002 start"); + auto appMgrServiceInner = std::make_shared(); + std::shared_ptr amsMgrScheduler = + std::make_shared(appMgrServiceInner, taskHandler_); + + /** + * @tc.steps: step1. amsMgrScheduler isReady false + * @tc.expected: step1. expect ERR_INVALID_OPERATION + */ + IPCSkeleton::SetCallingUid(-1); + auto ret = amsMgrScheduler->IsCallerKilling(""); + EXPECT_FALSE(ret); + TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_IsCallerKilling_002 end"); +} + +/* + * @tc.name: AmsMgrSchedulerSecondTest_IsCallerKilling_003 + * @tc.desc: Test IsCallerKilling + * @tc.type: FUNC + */ +HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_IsCallerKilling_003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_IsCallerKilling_003 start"); + auto appMgrServiceInner = std::make_shared(); + std::shared_ptr amsMgrScheduler = + std::make_shared(appMgrServiceInner, taskHandler_); + + /** + * @tc.steps: step1. amsMgrScheduler isReady false + * @tc.expected: step1. expect ERR_INVALID_OPERATION + */ + IPCSkeleton::SetCallingUid(Constants::FOUNDATION_UID); + auto ret = amsMgrScheduler->IsCallerKilling(""); + EXPECT_FALSE(ret); + TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_IsCallerKilling_003 end"); +} } // AppExecFwk } // OHOS diff --git a/test/unittest/app_mgr_client_first_test/app_mgr_client_first_test.cpp b/test/unittest/app_mgr_client_first_test/app_mgr_client_first_test.cpp index fc433dacd1..a9d17cbac2 100644 --- a/test/unittest/app_mgr_client_first_test/app_mgr_client_first_test.cpp +++ b/test/unittest/app_mgr_client_first_test/app_mgr_client_first_test.cpp @@ -194,5 +194,19 @@ HWTEST_F(AppMgrClientFirstTest, CleanAbilityByUserRequest_001, TestSize.Level0) EXPECT_TRUE(result != true); TAG_LOGI(AAFwkTag::TEST, "CleanAbilityByUserRequest_001 end"); } + +/** + * @tc.name: IsCallerKilling_001 + * @tc.desc: AppMgrClient test for IsCallerKilling. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrClientFirstTest, IsCallerKilling_001, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "IsCallerKilling_001 start"); + auto appMgrClient = std::make_unique(); + auto result = appMgrClient->IsCallerKilling(""); + EXPECT_TRUE(result != true); + TAG_LOGI(AAFwkTag::TEST, "IsCallerKilling_001 end"); +} } // namespace AppExecFwk } // namespace OHOS 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 7d149e9953..fe86ff9464 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 @@ -434,24 +434,23 @@ HWTEST_F(AppMgrServiceInnerTest, CheckLoadAbilityConditions_001, TestSize.Level0 auto appMgrServiceInner = std::make_shared(); EXPECT_NE(appMgrServiceInner, nullptr); - auto loadParam = std::make_shared(); - loadParam->token = sptr(new (std::nothrow) MockAbilityToken()); + OHOS::sptr token = sptr(new (std::nothrow) MockAbilityToken()); - appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, nullptr, nullptr); + appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, nullptr); - appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, abilityInfo_, nullptr); + appMgrServiceInner->CheckLoadAbilityConditions(nullptr, abilityInfo_, nullptr); - appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, nullptr, applicationInfo_); + appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, applicationInfo_); - appMgrServiceInner->CheckLoadAbilityConditions(nullptr, loadParam, nullptr, nullptr); + appMgrServiceInner->CheckLoadAbilityConditions(token, nullptr, nullptr); - appMgrServiceInner->CheckLoadAbilityConditions(nullptr, loadParam, abilityInfo_, nullptr); + appMgrServiceInner->CheckLoadAbilityConditions(token, abilityInfo_, nullptr); - appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, abilityInfo_, applicationInfo_); + appMgrServiceInner->CheckLoadAbilityConditions(nullptr, abilityInfo_, applicationInfo_); - appMgrServiceInner->CheckLoadAbilityConditions(nullptr, loadParam, nullptr, applicationInfo_); + appMgrServiceInner->CheckLoadAbilityConditions(token, nullptr, applicationInfo_); - appMgrServiceInner->CheckLoadAbilityConditions(nullptr, loadParam, abilityInfo_, applicationInfo_); + appMgrServiceInner->CheckLoadAbilityConditions(token, abilityInfo_, applicationInfo_); EXPECT_NE(appMgrServiceInner, nullptr); TAG_LOGI(AAFwkTag::TEST, "CheckLoadAbilityConditions_001 end");