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 8a165a5523..458f6475bf 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 @@ -812,6 +812,13 @@ public: */ bool IsMainProcessDebug(int32_t uid); + /** + * @brief Query whether the corresponding process of the app (identified by abilityInfo) is in attach debug mode. + * @param abilityInfo The ability info used to locate the corresponding process. + * @return Returns true if the corresponding process is in attach debug mode, false otherwise. + */ + bool IsCorrespondingProcessAttachDebug(const AbilityInfo &abilityInfo); + /** * @brief Set resident process enable status. * @param bundleName The application bundle name. 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 9658893377..9c88d94dcd 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 @@ -701,6 +701,16 @@ public: return false; } + /** + * @brief Query whether the corresponding process of the app (identified by abilityInfo) is in attach debug mode. + * @param abilityInfo The ability info used to locate the corresponding process. + * @return Returns true if the corresponding process is in attach debug mode, false otherwise. + */ + virtual bool IsCorrespondingProcessAttachDebug(const AbilityInfo &abilityInfo) + { + return false; + } + /** * start native process for debugger. * 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 900014e5dd..58e75cf249 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 @@ -163,6 +163,7 @@ enum class AppMgrInterfaceCode { REPORT_DUMP_MEM_RESULT = 138, IS_MAIN_PROCESS_DEBUG = 139, DUMP_JSHANDLE_MAP_PROCESS = 140, + IS_CORRESPONDING_PROCESS_ATTACH_DEBUG = 141, }; } // 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 71ed867801..c414a40a7e 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 @@ -551,6 +551,13 @@ public: */ virtual bool IsMainProcessDebug(int32_t uid) override; + /** + * @brief Query whether the corresponding process of the app (identified by abilityInfo) is in attach debug mode. + * @param abilityInfo The ability info used to locate the corresponding process. + * @return Returns true if the corresponding process is in attach debug mode, false otherwise. + */ + virtual bool IsCorrespondingProcessAttachDebug(const AbilityInfo &abilityInfo) override; + /** * start native process for debugger. * 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 1d09434a9a..c68fb1a8c8 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,6 +137,7 @@ private: #endif int32_t HandleIsSharedBundleRunning(MessageParcel &data, MessageParcel &reply); int32_t HandleIsMainProcessDebug(MessageParcel &data, MessageParcel &reply); + int32_t HandleIsCorrespondingProcessAttachDebug(MessageParcel &data, MessageParcel &reply); int32_t HandleStartNativeProcessForDebugger(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyFault(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyFaultBySA(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 d9ca4e778c..12a245d187 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 @@ -540,6 +540,15 @@ bool AppMgrClient::IsMainProcessDebug(int32_t uid) return service->IsMainProcessDebug(uid); } +bool AppMgrClient::IsCorrespondingProcessAttachDebug(const AbilityInfo &abilityInfo) +{ + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service == nullptr) { + return false; + } + return service->IsCorrespondingProcessAttachDebug(abilityInfo); +} + AppMgrResultCode AppMgrClient::GetProcessRunningInfosByAccessTokenId(uint32_t accessTokenId, std::vector &info) { 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 fe295c3385..4787261956 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 @@ -1609,6 +1609,27 @@ bool AppMgrProxy::IsMainProcessDebug(int32_t uid) return reply.ReadBool(); } +bool AppMgrProxy::IsCorrespondingProcessAttachDebug(const AbilityInfo &abilityInfo) +{ + MessageParcel data; + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); + return false; + } + if (!data.WriteParcelable(&abilityInfo)) { + TAG_LOGE(AAFwkTag::APPMGR, "abilityInfo write failed."); + return false; + } + MessageParcel reply; + MessageOption option; + auto ret = SendRequest(AppMgrInterfaceCode::IS_CORRESPONDING_PROCESS_ATTACH_DEBUG, data, reply, option); + if (ret != NO_ERROR) { + TAG_LOGW(AAFwkTag::APPMGR, "SendRequest failed, error code: %{public}d", ret); + return false; + } + return reply.ReadBool(); +} + int32_t AppMgrProxy::StartNativeProcessForDebugger(const AAFwk::Want &want) { 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 08a0f6446b..83302bcfc5 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 @@ -475,6 +475,8 @@ int32_t AppMgrStub::OnRemoteRequestInnerNinth(uint32_t code, MessageParcel &data return HandleEnableDelayedProcessExit(data, reply); case static_cast(AppMgrInterfaceCode::CANCEL_DELAYED_EXIT_TASK): return HandleCancelDelayedExitTask(data, reply); + case static_cast(AppMgrInterfaceCode::IS_CORRESPONDING_PROCESS_ATTACH_DEBUG): + return HandleIsCorrespondingProcessAttachDebug(data, reply); } return INVALID_FD; } @@ -1503,6 +1505,21 @@ int32_t AppMgrStub::HandleIsMainProcessDebug(MessageParcel &data, MessageParcel return NO_ERROR; } +int32_t AppMgrStub::HandleIsCorrespondingProcessAttachDebug(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER(HITRACE_TAG_APP); + std::unique_ptr abilityInfo(data.ReadParcelable()); + if (abilityInfo == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "abilityInfo is nullptr"); + return ERR_INVALID_VALUE; + } + bool result = IsCorrespondingProcessAttachDebug(*abilityInfo); + if (!reply.WriteBool(result)) { + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int32_t AppMgrStub::HandleStartNativeProcessForDebugger(MessageParcel &data, MessageParcel &reply) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 48b3645907..73117c94cb 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -667,6 +667,13 @@ public: */ bool IsMainProcessDebug(int32_t uid); + /** + * @brief Query whether the corresponding process of the app (identified by abilityInfo) is in attach debug mode. + * @param abilityInfo The ability info used to locate the corresponding process. + * @return Returns true if the corresponding process is in attach debug mode, false otherwise. + */ + bool IsCorrespondingProcessAttachDebug(const AppExecFwk::AbilityInfo &abilityInfo); + /** * To clear the process by ability token. * diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index cf4f8f5a10..7404ff7934 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -1322,7 +1322,7 @@ void AbilityConnectManager::LoadAbility(const std::shared_ptrIsDebugApp()) { + if (!abilityRecord->IsDebug()) { TAG_LOGD(AAFwkTag::EXT, "IsDebug is false, here is not debug app"); PostLoadTimeoutTask(abilityRecord, loadTimeoutFinal); } @@ -1573,7 +1573,11 @@ void AbilityConnectManager::PostTimeOutTask(const std::shared_ptrIsDebug()) { + TAG_LOGD(AAFwkTag::EXT, "Debug task: %{public}s/%{public}s" PRId64, + abilityRecord->GetAbilityInfo().bundleName.c_str(), abilityRecord->GetAbilityInfo().name.c_str()); + return; + } std::string taskName; auto recordId = abilityRecord->GetAbilityRecordId(); TAG_LOGD(AAFwkTag::EXT, "task: %{public}s/%{public}s, %{public}d, %{public}" PRId64, @@ -3422,6 +3426,13 @@ void AbilityConnectManager::GetOrCreateServiceRecord(const AbilityRequest &abili TAG_LOGD(AAFwkTag::EXT, "AGENT extension inherit debug from main process, ability:%{public}s", abilityRequest.abilityInfo.name.c_str()); } + bool isAttachDebug = IN_PROCESS_CALL( + DelayedSingleton::GetInstance()->IsCorrespondingProcessAttachDebug( + abilityRequest.abilityInfo)); + targetService->SetAttachDebug(isAttachDebug); + TAG_LOGD(AAFwkTag::EXT, "AGENT extension sync attach debug from corresponding process, " + "ability:%{public}s, isAttachDebug:%{public}d", + abilityRequest.abilityInfo.name.c_str(), isAttachDebug); } isLoadedAbility = false; diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index 6b7c5251ab..febf7bdce1 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -722,6 +722,12 @@ bool AppScheduler::IsMainProcessDebug(int32_t uid) return appMgrClient_->IsMainProcessDebug(uid); } +bool AppScheduler::IsCorrespondingProcessAttachDebug(const AppExecFwk::AbilityInfo &abilityInfo) +{ + CHECK_POINTER_AND_RETURN(appMgrClient_, false); + return appMgrClient_->IsCorrespondingProcessAttachDebug(abilityInfo); +} + void AppScheduler::ClearProcessByToken(sptr token) const { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 13a7a445fe..d0f7ec9579 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -602,6 +602,13 @@ public: */ virtual bool IsMainProcessDebug(int32_t uid) override; + /** + * @brief Query whether the corresponding process of the app (identified by abilityInfo) is in attach debug mode. + * @param abilityInfo The ability info used to locate the corresponding process. + * @return Returns true if the corresponding process is in attach debug mode, false otherwise. + */ + virtual bool IsCorrespondingProcessAttachDebug(const AbilityInfo &abilityInfo) override; + /** * start native process for debugger. * diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 38ffed0f66..785b3ae3c2 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -1226,6 +1226,8 @@ public: bool IsMainProcessDebug(int32_t uid); + bool IsCorrespondingProcessAttachDebug(const AbilityInfo &abilityInfo); + /** * Notify Fault Data * diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 0981255224..d20467ac65 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -1512,6 +1512,15 @@ bool AppMgrService::IsMainProcessDebug(int32_t uid) return appMgrServiceInner_->IsMainProcessDebug(uid); } +bool AppMgrService::IsCorrespondingProcessAttachDebug(const AbilityInfo &abilityInfo) +{ + if (!IsReady()) { + TAG_LOGE(AAFwkTag::APPMGR, "not ready"); + return false; + } + return appMgrServiceInner_->IsCorrespondingProcessAttachDebug(abilityInfo); +} + int32_t AppMgrService::GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) { if (!IsReady()) { diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 68327289e2..e8d51d5486 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -9975,6 +9975,43 @@ bool AppMgrServiceInner::IsMainProcessDebug(int32_t uid) return false; } +bool AppMgrServiceInner::IsCorrespondingProcessAttachDebug(const AbilityInfo &abilityInfo) +{ + if (IPCSkeleton::GetCallingUid() != FOUNDATION_UID) { + TAG_LOGW(AAFwkTag::APPMGR, "not foundation call"); + return false; + } + bool isAgentUI = AAFwk::UIExtensionWrapper::IsAgentUIExtension(abilityInfo.extensionAbilityType); + if (!isAgentUI && abilityInfo.extensionAbilityType != AppExecFwk::ExtensionAbilityType::AGENT) { + TAG_LOGD(AAFwkTag::APPMGR, "Not agentUI or agent extension"); + return false; + } + if (!CheckRemoteClient() || !appRunningManager_) { + TAG_LOGE(AAFwkTag::APPMGR, "nullptr"); + return false; + } + auto appInfo = std::make_shared(abilityInfo.applicationInfo); + int32_t appIndex = abilityInfo.appIndex; + BundleInfo bundleInfo; + HapModuleInfo hapModuleInfo; + if (!GetBundleAndHapInfo(abilityInfo, appInfo, bundleInfo, hapModuleInfo, appIndex)) { + TAG_LOGE(AAFwkTag::APPMGR, "GetBundleAndHapInfo failed"); + return false; + } + auto abilityInfoPtr = std::make_shared(abilityInfo); + std::string processName = appInfo->bundleName + ":" + AGENT_EXTENSION_TYPE;; + std::string customProcessFlag = ""; + TAG_LOGD(AAFwkTag::APPMGR, "processName: %{public}s, customProcessFlag: %{public}s", + processName.c_str(), customProcessFlag.c_str()); + auto appRecord = appRunningManager_->CheckAppRunningRecordIsExist(appInfo->name, + processName, appInfo->uid, bundleInfo, "", nullptr, "", customProcessFlag); + if (appRecord == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "appRecord nullptr"); + return false; + } + return appRecord->IsAttachDebug(); +} + void AppMgrServiceInner::KillRenderProcess(const std::shared_ptr &appRecord) { if (appRecord == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "appRecord null"); diff --git a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_app_scheduler.cpp b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_app_scheduler.cpp index 3632127a65..5f7da718f0 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_app_scheduler.cpp +++ b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_app_scheduler.cpp @@ -359,6 +359,11 @@ bool AppScheduler::IsMainProcessDebug(int32_t uid) return false; } +bool AppScheduler::IsCorrespondingProcessAttachDebug(const AppExecFwk::AbilityInfo &abilityInfo) +{ + return false; +} + void AppScheduler::OnCacheExitInfo(uint32_t accessTokenId, const AppExecFwk::RunningProcessInfo &exitInfo, const std::string &bundleName, const std::vector &abilityNames, const std::vector &uiExtensionNames) {} diff --git a/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp b/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp index de3cbf78e1..161a0a393b 100644 --- a/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp +++ b/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp @@ -2941,5 +2941,135 @@ HWTEST_F(AppMgrServiceInnerSecondTest, IsMainProcessDebug_006, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "IsMainProcessDebug_006 end"); } +/** + * @tc.name: IsCorrespondingProcessAttachDebug_001 + * @tc.desc: Test IsCorrespondingProcessAttachDebug when caller is not foundation process, should return false. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerSecondTest, IsCorrespondingProcessAttachDebug_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "IsCorrespondingProcessAttachDebug_001 start"); + auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->appRunningManager_ = std::make_shared(); + IPCSkeleton::SetCallingUid(0); // not foundation uid + AbilityInfo abilityInfo; + abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::AGENT; + EXPECT_FALSE(appMgrServiceInner->IsCorrespondingProcessAttachDebug(abilityInfo)); + TAG_LOGI(AAFwkTag::TEST, "IsCorrespondingProcessAttachDebug_001 end"); +} + +/** + * @tc.name: IsCorrespondingProcessAttachDebug_002 + * @tc.desc: Test IsCorrespondingProcessAttachDebug when extension type is not agent, should return false. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerSecondTest, IsCorrespondingProcessAttachDebug_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "IsCorrespondingProcessAttachDebug_002 start"); + auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->appRunningManager_ = std::make_shared(); + IPCSkeleton::SetCallingUid(FOUNDATION_UID); // foundation call + AbilityInfo abilityInfo; + // default extensionAbilityType is not AGENT or AgentUI + EXPECT_FALSE(appMgrServiceInner->IsCorrespondingProcessAttachDebug(abilityInfo)); + TAG_LOGI(AAFwkTag::TEST, "IsCorrespondingProcessAttachDebug_002 end"); +} + +/** + * @tc.name: IsCorrespondingProcessAttachDebug_003 + * @tc.desc: Test IsCorrespondingProcessAttachDebug when remoteClientManager_ is nullptr, should return false. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerSecondTest, IsCorrespondingProcessAttachDebug_003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "IsCorrespondingProcessAttachDebug_003 start"); + auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->remoteClientManager_ = nullptr; + appMgrServiceInner->appRunningManager_ = std::make_shared(); + IPCSkeleton::SetCallingUid(FOUNDATION_UID); // foundation call + AbilityInfo abilityInfo; + abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::AGENT; + EXPECT_FALSE(appMgrServiceInner->IsCorrespondingProcessAttachDebug(abilityInfo)); + TAG_LOGI(AAFwkTag::TEST, "IsCorrespondingProcessAttachDebug_003 end"); +} + +/** + * @tc.name: IsCorrespondingProcessAttachDebug_004 + * @tc.desc: Test IsCorrespondingProcessAttachDebug when spawn client is nullptr, should return false. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerSecondTest, IsCorrespondingProcessAttachDebug_004, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "IsCorrespondingProcessAttachDebug_004 start"); + auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->remoteClientManager_ = std::make_shared(); + appMgrServiceInner->remoteClientManager_->SetSpawnClient(nullptr); + appMgrServiceInner->appRunningManager_ = std::make_shared(); + IPCSkeleton::SetCallingUid(FOUNDATION_UID); // foundation call + AbilityInfo abilityInfo; + abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::AGENT; + EXPECT_FALSE(appMgrServiceInner->IsCorrespondingProcessAttachDebug(abilityInfo)); + TAG_LOGI(AAFwkTag::TEST, "IsCorrespondingProcessAttachDebug_004 end"); +} + +/** + * @tc.name: IsCorrespondingProcessAttachDebug_005 + * @tc.desc: Test IsCorrespondingProcessAttachDebug when bundle manager helper is nullptr, should return false. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerSecondTest, IsCorrespondingProcessAttachDebug_005, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "IsCorrespondingProcessAttachDebug_005 start"); + auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->remoteClientManager_ = std::make_shared(); + // spawn client is created by RemoteClientManager constructor, but bundle manager helper is not set + appMgrServiceInner->appRunningManager_ = std::make_shared(); + IPCSkeleton::SetCallingUid(FOUNDATION_UID); // foundation call + AbilityInfo abilityInfo; + abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::AGENT; + EXPECT_FALSE(appMgrServiceInner->IsCorrespondingProcessAttachDebug(abilityInfo)); + TAG_LOGI(AAFwkTag::TEST, "IsCorrespondingProcessAttachDebug_005 end"); +} + +/** + * @tc.name: IsCorrespondingProcessAttachDebug_006 + * @tc.desc: Test IsCorrespondingProcessAttachDebug when appRunningManager_ is nullptr, should return false. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerSecondTest, IsCorrespondingProcessAttachDebug_006, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "IsCorrespondingProcessAttachDebug_006 start"); + auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->remoteClientManager_ = std::make_shared(); + appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(bundleMgrHelper_); + appMgrServiceInner->appRunningManager_ = nullptr; + IPCSkeleton::SetCallingUid(FOUNDATION_UID); // foundation call + AbilityInfo abilityInfo; + abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::AGENT; + EXPECT_FALSE(appMgrServiceInner->IsCorrespondingProcessAttachDebug(abilityInfo)); + TAG_LOGI(AAFwkTag::TEST, "IsCorrespondingProcessAttachDebug_006 end"); +} + +/** + * @tc.name: IsCorrespondingProcessAttachDebug_007 + * @tc.desc: Test IsCorrespondingProcessAttachDebug when GetBundleAndHapInfo fails, should return false. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerSecondTest, IsCorrespondingProcessAttachDebug_007, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "IsCorrespondingProcessAttachDebug_007 start"); + auto appMgrServiceInner = std::make_shared(); + appMgrServiceInner->remoteClientManager_ = std::make_shared(); + appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(bundleMgrHelper_); + appMgrServiceInner->appRunningManager_ = std::make_shared(); + IPCSkeleton::SetCallingUid(FOUNDATION_UID); // foundation call + AbilityInfo abilityInfo; + abilityInfo.bundleName = "com.test.attachdebug"; + abilityInfo.applicationInfo.bundleName = "com.test.attachdebug"; + abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::AGENT; + EXPECT_FALSE(appMgrServiceInner->IsCorrespondingProcessAttachDebug(abilityInfo)); + TAG_LOGI(AAFwkTag::TEST, "IsCorrespondingProcessAttachDebug_007 end"); +} + } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file