From cf93811eb99912aa4faee7bc901a4fe5e4b9c8cd Mon Sep 17 00:00:00 2001 From: xlw Date: Fri, 28 Jun 2024 11:32:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BB=B4=E6=B5=8B=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xlw Change-Id: Icaae9a715bc8f65fc39d02c353d61a42e4641b35 --- frameworks/native/ability/native/BUILD.gn | 1 + .../native/ability/native/extension_impl.cpp | 28 +++++++++++++++++++ .../ability_runtime/context/context_impl.cpp | 22 +++++++++++++++ .../service_extension_context.cpp | 3 ++ .../native/ability/native/extension_base.inl | 2 +- .../native/ability/native/extension_impl.h | 4 ++- .../ability_runtime/context/context_impl.h | 2 ++ services/abilitymgr/include/ability_config.h | 1 + .../src/ability_connect_manager.cpp | 8 ++++-- 9 files changed, 67 insertions(+), 4 deletions(-) diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 5d3898ed6e..4adfe8744f 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -462,6 +462,7 @@ ohos_shared_library("extensionkit_native") { "eventhandler:libeventhandler", "hilog:libhilog", "hitrace:hitrace_meter", + "ipc:ipc_core", "json:nlohmann_json_static", "napi:ace_napi", ] diff --git a/frameworks/native/ability/native/extension_impl.cpp b/frameworks/native/ability/native/extension_impl.cpp index 631b48815c..d51a0f2ffe 100644 --- a/frameworks/native/ability/native/extension_impl.cpp +++ b/frameworks/native/ability/native/extension_impl.cpp @@ -19,13 +19,20 @@ #include "ability_local_record.h" #include "ability_transaction_callback_info.h" #include "hitrace_meter.h" +#include "ipc_object_proxy.h" #include "extension_context.h" #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "ui_extension_utils.h" + namespace OHOS { namespace AbilityRuntime { +ExtensionImpl::~ExtensionImpl() +{ + TAG_LOGI(AAFwkTag::EXT, "~ExtensionImpl"); +} + void ExtensionImpl::Init(const std::shared_ptr &application, const std::shared_ptr &record, std::shared_ptr &extension, @@ -48,12 +55,33 @@ void ExtensionImpl::Init(const std::shared_ptr &app extension_->SetExtensionWindowLifeCycleListener( sptr(new ExtensionWindowLifeCycleImpl(token_, shared_from_this()))); } + if (record->GetAbilityInfo()->name == "com.ohos.callui.ServiceAbility") { + PrintTokenInfo(); + } } extension_->Init(record, application, handler, token); lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; skipCommandExtensionWithIntent_ = false; } +void ExtensionImpl::PrintTokenInfo() const +{ + if (token_ == nullptr) { + TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility token is null"); + return; + } + if (!token_->IsProxyObject()) { + TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility token is not proxy"); + return; + } + IPCObjectProxy *tokenProxyObject = reinterpret_cast(token_.GetRefPtr()); + if (tokenProxyObject != nullptr) { + std::string remoteDescriptor = Str16ToStr8(tokenProxyObject->GetInterfaceDescriptor()); + TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility handle: %{public}d, descriptor: %{public}s", + tokenProxyObject->GetHandle(), remoteDescriptor.c_str()); + } +} + /** * @brief Handling the life cycle switching of Extension. * diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index cc2aec0eee..7881b0b2b1 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -31,6 +31,7 @@ #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "hitrace_meter.h" +#include "ipc_object_proxy.h" #include "ipc_singleton.h" #include "js_runtime_utils.h" #ifdef SUPPORT_SCREEN @@ -1000,6 +1001,9 @@ void ContextImpl::SetToken(const sptr &token) return; } token_ = token; + if (GetBundleName() == "com.ohos.callui") { + PrintTokenInfo(); + } } sptr ContextImpl::GetToken() @@ -1248,5 +1252,23 @@ int32_t ContextImpl::SetSupportedProcessCacheSelf(bool isSupport) } return appMgrClient->SetSupportedProcessCacheSelf(isSupport); } + +void ContextImpl::PrintTokenInfo() const +{ + if (token_ == nullptr) { + TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility token is null"); + return; + } + if (!token_->IsProxyObject()) { + TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility token is not proxy"); + return; + } + IPCObjectProxy *tokenProxyObject = reinterpret_cast(token_.GetRefPtr()); + if (tokenProxyObject != nullptr) { + std::string remoteDescriptor = Str16ToStr8(tokenProxyObject->GetInterfaceDescriptor()); + TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility handle: %{public}d, descriptor: %{public}s", + tokenProxyObject->GetHandle(), remoteDescriptor.c_str()); + } +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/native/appkit/ability_runtime/service_extension_context.cpp b/frameworks/native/appkit/ability_runtime/service_extension_context.cpp index e3649d0694..7f5344f134 100644 --- a/frameworks/native/appkit/ability_runtime/service_extension_context.cpp +++ b/frameworks/native/appkit/ability_runtime/service_extension_context.cpp @@ -132,6 +132,9 @@ ErrCode ServiceExtensionContext::StartAbilityWithAccount(const AAFwk::Want &want TAG_LOGI(AAFwkTag::APPKIT, "accountId: %{public}d, ability: %{public}s, caller: %{public}s", accountId, want.GetElement().GetURI().c_str(), callerName.c_str()); (const_cast(want)).SetParam(START_ABILITY_TYPE, true); + if (callerName == "com.ohos.callui.ServiceAbility") { + PrintTokenInfo(); + } ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility( want, token_, ILLEGAL_REQUEST_CODE, accountId); TAG_LOGD(AAFwkTag::APPKIT, "%{public}s. End calling StartAbilityWithAccount. ret=%{public}d", __func__, err); diff --git a/interfaces/kits/native/ability/native/extension_base.inl b/interfaces/kits/native/ability/native/extension_base.inl index 440300077b..218c9ddd00 100644 --- a/interfaces/kits/native/ability/native/extension_base.inl +++ b/interfaces/kits/native/ability/native/extension_base.inl @@ -39,7 +39,6 @@ std::shared_ptr ExtensionBase::CreateAndInitContext(const std::shared_ptr< { TAG_LOGD(AAFwkTag::EXT, "begin init base"); std::shared_ptr context = std::make_shared(); - context->SetToken(token); auto appContext = Context::GetApplicationContext(); if (appContext == nullptr) { TAG_LOGE(AAFwkTag::EXT, "ServiceExtension::CreateAndInitContext appContext is nullptr"); @@ -48,6 +47,7 @@ std::shared_ptr ExtensionBase::CreateAndInitContext(const std::shared_ptr< context->SetApplicationInfo(appContext->GetApplicationInfo()); context->SetResourceManager(appContext->GetResourceManager()); context->SetParentContext(appContext); + context->SetToken(token); if (record == nullptr) { TAG_LOGE(AAFwkTag::EXT, "ServiceExtension::CreateAndInitContext record is nullptr"); return context; diff --git a/interfaces/kits/native/ability/native/extension_impl.h b/interfaces/kits/native/ability/native/extension_impl.h index 56d52ff761..e1cae8cf56 100644 --- a/interfaces/kits/native/ability/native/extension_impl.h +++ b/interfaces/kits/native/ability/native/extension_impl.h @@ -38,7 +38,7 @@ namespace AbilityRuntime { class ExtensionImpl : public std::enable_shared_from_this { public: ExtensionImpl() = default; - virtual ~ExtensionImpl() = default; + virtual ~ExtensionImpl(); /** * @brief Init the object. @@ -205,6 +205,8 @@ protected: private: inline bool UIExtensionAbilityExecuteInsightIntent(const Want &want); + void PrintTokenInfo() const; + int lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; sptr token_; std::shared_ptr extension_; 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 71c8043dd5..bd1b9939fd 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h @@ -364,6 +364,8 @@ public: int32_t SetSupportedProcessCacheSelf(bool isSupport); + void PrintTokenInfo() const; + static const int EL_DEFAULT = 1; protected: diff --git a/services/abilitymgr/include/ability_config.h b/services/abilitymgr/include/ability_config.h index 65f393f128..ad41abbb48 100644 --- a/services/abilitymgr/include/ability_config.h +++ b/services/abilitymgr/include/ability_config.h @@ -38,6 +38,7 @@ constexpr const char* SCENEBOARD_ABILITY_NAME = "com.ohos.sceneboard.MainAbility constexpr const char* GRANT_ABILITY_BUNDLE_NAME = "com.ohos.permissionmanager"; constexpr const char* GRANT_ABILITY_ABILITY_NAME = "com.ohos.permissionmanager.GrantAbility"; constexpr const char* PARAMS_STREAM = "ability.params.stream"; +constexpr const char* CALLUI_ABILITY_NAME = "com.ohos.callui.ServiceAbility"; constexpr const char* MISSION_NAME_MARK_HEAD = "#"; constexpr const char* MISSION_NAME_SEPARATOR = ":"; } // namespace AbilityConfig diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 2c9af82570..269ec90ad0 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -764,6 +764,7 @@ int AbilityConnectManager::DisconnectAbilityLocked(const sptr abilityRecord) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "terminate record called."); if (!GetAbilityRecordById(abilityRecord->GetRecordId())) { return; } @@ -2011,15 +2012,18 @@ void AbilityConnectManager::OnTimeOut(uint32_t msgId, int64_t abilityRecordId) void AbilityConnectManager::HandleInactiveTimeout(const std::shared_ptr &ability) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "HandleInactiveTimeout start"); + TAG_LOGI(AAFwkTag::ABILITYMGR, "HandleInactiveTimeout start"); CHECK_POINTER(ability); 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()); } + if (ability->GetAbilityInfo().name == AbilityConfig::CALLUI_ABILITY_NAME && ability->GetStartId() == 0) { + HandleConnectTimeoutTask(ability); + } - TAG_LOGD(AAFwkTag::ABILITYMGR, "HandleInactiveTimeout end"); + TAG_LOGI(AAFwkTag::ABILITYMGR, "HandleInactiveTimeout end"); } bool AbilityConnectManager::IsAbilityNeedKeepAlive(const std::shared_ptr &abilityRecord)