!11636 生命周期检测优化

Merge pull request !11636 from wangzhen/appfreeze2
This commit is contained in:
openharmony_ci 2024-11-21 06:09:40 +00:00 committed by Gitee
commit 3cffd53107
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
53 changed files with 454 additions and 907 deletions

View File

@ -617,9 +617,8 @@ void AbilityImpl::WindowLifeCycleImpl::AfterForeground()
TAG_LOGE(AAFwkTag::ABILITY, "null stage mode ability/abilityImpl");
return;
}
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::FOREGROUND };
std::string entry = "AbilityImpl::WindowLifeCycleImpl::AfterForeground; the foreground lifecycle";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
std::string entry = "AbilityImpl::WindowLifeCycleImpl::AfterForeground";
FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry);
bool needNotifyAMS = false;
{
@ -639,7 +638,7 @@ void AbilityImpl::WindowLifeCycleImpl::AfterForeground()
auto ret = AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_,
AbilityLifeCycleState::ABILITY_STATE_FOREGROUND_NEW, restoreData);
if (ret == ERR_OK) {
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
FreezeUtil::GetInstance().DeleteLifecycleEvent(token_);
FreezeUtil::GetInstance().DeleteAppLifecycleEvent(0);
}
}
@ -653,16 +652,15 @@ void AbilityImpl::WindowLifeCycleImpl::AfterBackground()
TAG_LOGW(AAFwkTag::ABILITY, "not stage");
return;
}
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::BACKGROUND };
std::string entry = "AbilityImpl::WindowLifeCycleImpl::AfterBackground; the background lifecycle";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
std::string entry = "AbilityImpl::WindowLifeCycleImpl::AfterBackground";
FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry);
TAG_LOGI(AAFwkTag::ABILITY, "window after background");
PacMap restoreData;
auto ret = AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_,
AbilityLifeCycleState::ABILITY_STATE_BACKGROUND_NEW, restoreData);
if (ret == ERR_OK) {
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
FreezeUtil::GetInstance().DeleteLifecycleEvent(token_);
FreezeUtil::GetInstance().DeleteAppLifecycleEvent(0);
}
}

View File

@ -181,16 +181,14 @@ void CJUIAbility::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo
void CJUIAbility::AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState state, const std::string &methodName) const
{
FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, state };
auto entry = std::string("CJUIAbility::") + methodName + "; the " + methodName + " begin";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
auto entry = std::string("CJUIAbility::") + methodName + " begin";
FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry);
}
void CJUIAbility::AddLifecycleEventAfterCall(FreezeUtil::TimeoutState state, const std::string &methodName) const
{
FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, state };
auto entry = std::string("CJUIAbility::") + methodName + "; the " + methodName + " end.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
auto entry = std::string("CJUIAbility::") + methodName + " end";
FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry);
}
int32_t CJUIAbility::OnShare(WantParams &wantParams)

View File

@ -271,16 +271,14 @@ void JsAbility::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
void JsAbility::AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const
{
FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, state };
auto entry = std::string("JsAbility::") + methodName + "; the " + methodName + " begin";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
auto entry = std::string("JsAbility::") + methodName + " begin";
FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry);
}
void JsAbility::AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const
{
FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, state };
auto entry = std::string("JsAbility::") + methodName + "; the " + methodName + " end";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
auto entry = std::string("JsAbility::") + methodName + " end";
FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry);
}
int32_t JsAbility::OnShare(WantParams &wantParam)

View File

@ -362,16 +362,14 @@ void JsUIAbility::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo
void JsUIAbility::AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const
{
FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, state };
auto entry = std::string("JsUIAbility::") + methodName + "; the " + methodName + " begin.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
auto entry = std::string("JsUIAbility::") + methodName + " begin";
FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry);
}
void JsUIAbility::AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const
{
FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, state };
auto entry = std::string("JsUIAbility::") + methodName + "; the " + methodName + " end.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
auto entry = std::string("JsUIAbility::") + methodName + " end";
FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry);
}
int32_t JsUIAbility::OnShare(WantParams &wantParam)
@ -878,9 +876,8 @@ void JsUIAbility::DoOnForegroundForSceneIsNull(const Want &want)
}
if (ret != Rosen::WMError::WM_OK) {
TAG_LOGE(AAFwkTag::UIABILITY, "init window scene failed");
FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, FreezeUtil::TimeoutState::FOREGROUND };
FreezeUtil::GetInstance().AppendLifecycleEvent(flow,
std::string("ERROR JsUIAbility::DoOnForegroundForSceneIsNull: ") + std::to_string(static_cast<int>(ret)));
FreezeUtil::GetInstance().AppendLifecycleEvent(AbilityContext::token_,
std::string("JsUIAbility::DoOnForegroundForSceneIsNull; error ") + std::to_string(static_cast<int>(ret)));
return;
}

View File

@ -315,15 +315,14 @@ void FAAbilityThread::AttachInner(const std::shared_ptr<AppExecFwk::OHOSApplicat
abilityImpl_->Init(application, abilityRecord, currentAbility_, abilityHandler_, token_);
// 4. ability attach : ipc
TAG_LOGD(AAFwkTag::FA, "attach ability");
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::LOAD };
std::string entry = "AbilityThread::Attach; the load lifecycle.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
std::string entry = "AbilityThread::Attach";
FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry);
ErrCode err = AbilityManagerClient::GetInstance()->AttachAbilityThread(this, token_);
if (err != ERR_OK) {
TAG_LOGE(AAFwkTag::FA, "err = %{public}d", err);
return;
}
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
FreezeUtil::GetInstance().DeleteLifecycleEvent(token_);
FreezeUtil::GetInstance().DeleteAppLifecycleEvent(0);
}
@ -496,14 +495,12 @@ void FAAbilityThread::AddLifecycleEvent(uint32_t state, std::string &methodName)
return;
}
if (state == AAFwk::ABILITY_STATE_FOREGROUND_NEW) {
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::FOREGROUND };
std::string entry = "AbilityThread::" + methodName + "; the foreground lifecycle.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
std::string entry = "AbilityThread::" + methodName;
FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry);
}
if (state == AAFwk::ABILITY_STATE_BACKGROUND_NEW) {
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::BACKGROUND };
std::string entry = "AbilityThread::" + methodName + "; the background lifecycle.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
std::string entry = "AbilityThread::" + methodName;
FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry);
}
}

View File

@ -77,8 +77,7 @@ void NewAbilityImpl::AbilityTransactionCallback(const AbilityLifeCycleState &sta
TAG_LOGI(AAFwkTag::ABILITY, "notify ams");
auto ret = AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_, state, GetRestoreData());
if (ret == ERR_OK && state == AAFwk::ABILITY_STATE_FOREGROUND_NEW) {
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::FOREGROUND };
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
FreezeUtil::GetInstance().DeleteLifecycleEvent(token_);
FreezeUtil::GetInstance().DeleteAppLifecycleEvent(0);
}
}

View File

@ -217,15 +217,14 @@ void UIAbilityImpl::HandleShareData(int32_t uniqueId)
void UIAbilityImpl::AbilityTransactionCallback(const AAFwk::AbilityLifeCycleState &state)
{
TAG_LOGD(AAFwkTag::UIABILITY, "called");
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::FOREGROUND };
if (state == AAFwk::ABILITY_STATE_FOREGROUND_NEW) {
lifecycleState_ = AAFwk::ABILITY_STATE_FOREGROUND_NEW;
std::string entry = "AbilityManagerClient::AbilityTransitionDone; the transaction start.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
std::string entry = "AbilityManagerClient::AbilityTransitionDone";
FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry);
}
auto ret = AAFwk::AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_, state, GetRestoreData());
if (ret == ERR_OK && state == AAFwk::ABILITY_STATE_FOREGROUND_NEW) {
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
FreezeUtil::GetInstance().DeleteLifecycleEvent(token_);
FreezeUtil::GetInstance().DeleteAppLifecycleEvent(0);
}
}
@ -419,9 +418,8 @@ void UIAbilityImpl::WindowLifeCycleImpl::AfterForeground()
TAG_LOGE(AAFwkTag::UIABILITY, "null owner");
return;
}
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::FOREGROUND };
std::string entry = "UIAbilityImpl::WindowLifeCycleImpl::AfterForeground; the foreground lifecycle.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
std::string entry = "UIAbilityImpl::WindowLifeCycleImpl::AfterForeground";
FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry);
bool needNotifyAMS = false;
{
@ -437,14 +435,14 @@ void UIAbilityImpl::WindowLifeCycleImpl::AfterForeground()
if (needNotifyAMS) {
TAG_LOGI(AAFwkTag::UIABILITY, "notify ability manager service");
entry = "AbilityManagerClient::AbilityTransitionDone; the transaction start.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
entry = "AbilityManagerClient::AbilityTransitionDone";
FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry);
owner->lifecycleState_ = AAFwk::ABILITY_STATE_BACKGROUND_NEW;
AppExecFwk::PacMap restoreData;
auto ret = AAFwk::AbilityManagerClient::GetInstance()->AbilityTransitionDone(
token_, AAFwk::AbilityLifeCycleState::ABILITY_STATE_FOREGROUND_NEW, restoreData);
if (ret == ERR_OK) {
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
FreezeUtil::GetInstance().DeleteLifecycleEvent(token_);
FreezeUtil::GetInstance().DeleteAppLifecycleEvent(0);
}
}
@ -454,15 +452,14 @@ void UIAbilityImpl::WindowLifeCycleImpl::AfterBackground()
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
TAG_LOGI(AAFwkTag::UIABILITY, "Lifecycle:call");
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::BACKGROUND };
std::string entry = "UIAbilityImpl::WindowLifeCycleImpl::AfterBackground; the background lifecycle.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
std::string entry = "UIAbilityImpl::WindowLifeCycleImpl::AfterBackground";
FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry);
AppExecFwk::PacMap restoreData;
auto ret = AAFwk::AbilityManagerClient::GetInstance()->AbilityTransitionDone(
token_, AAFwk::AbilityLifeCycleState::ABILITY_STATE_BACKGROUND_NEW, restoreData);
if (ret == ERR_OK) {
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
FreezeUtil::GetInstance().DeleteLifecycleEvent(token_);
FreezeUtil::GetInstance().DeleteAppLifecycleEvent(0);
}
}
@ -490,9 +487,8 @@ void UIAbilityImpl::WindowLifeCycleImpl::AfterUnfocused()
void UIAbilityImpl::WindowLifeCycleImpl::ForegroundFailed(int32_t type)
{
TAG_LOGE(AAFwkTag::UIABILITY, "scb call, ForegroundFailed");
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::FOREGROUND };
std::string entry = "ERROR UIAbilityImpl::WindowLifeCycleImpl::ForegroundFailed; GoForeground failed.";
FreezeUtil::GetInstance().AppendLifecycleEvent(flow, entry);
std::string entry = "UIAbilityImpl::WindowLifeCycleImpl::ForegroundFailed; GoForeground failed";
FreezeUtil::GetInstance().AppendLifecycleEvent(token_, entry);
AppExecFwk::PacMap restoreData;
switch (type) {
case static_cast<int32_t>(OHOS::Rosen::WMError::WM_ERROR_INVALID_OPERATION): {

View File

@ -167,17 +167,16 @@ void UIAbilityThread::AttachInner(const std::shared_ptr<AppExecFwk::OHOSApplicat
// ability attach : ipc
TAG_LOGI(AAFwkTag::UIABILITY, "Lifecycle:Attach");
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::LOAD };
std::string entry = "AbilityThread::Attach start; the load lifecycle.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
std::string entry = "AbilityThread::Attach";
FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry);
ErrCode err = AbilityManagerClient::GetInstance()->AttachAbilityThread(this, token_);
if (err != ERR_OK) {
entry = std::string("AbilityThread::Attach failed ipc error: ") + std::to_string(err);
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
entry = std::string("AbilityThread::Attach; error ") + std::to_string(err);
FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry);
TAG_LOGE(AAFwkTag::UIABILITY, "err: %{public}d", err);
return;
}
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
FreezeUtil::GetInstance().DeleteLifecycleEvent(token_);
FreezeUtil::GetInstance().DeleteAppLifecycleEvent(0);
}
@ -250,14 +249,12 @@ void UIAbilityThread::HandleAbilityTransaction(
void UIAbilityThread::AddLifecycleEvent(uint32_t state, std::string &methodName) const
{
if (state == AAFwk::ABILITY_STATE_FOREGROUND_NEW) {
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::FOREGROUND };
std::string entry = "AbilityThread::" + methodName + "; the foreground lifecycle.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
std::string entry = "AbilityThread::" + methodName;
FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry);
}
if (state == AAFwk::ABILITY_STATE_BACKGROUND_NEW) {
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::BACKGROUND };
std::string entry = "AbilityThread::" + methodName + "; the background lifecycle.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
std::string entry = "AbilityThread::" + methodName;
FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry);
}
}

View File

@ -16,6 +16,7 @@
#include "js_ability_stage.h"
#include "ability_delegator_registry.h"
#include "freeze_util.h"
#include "hilog_tag_wrapper.h"
#include "js_ability_stage_context.h"
#include "js_context_utils.h"
@ -72,6 +73,7 @@ std::shared_ptr<AbilityStage> JsAbilityStage::Create(
TAG_LOGW(AAFwkTag::APPKIT, "runtime is nullptr");
return nullptr;
}
FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "JsAbilityStage::Create");
auto& jsRuntime = static_cast<JsRuntime&>(*runtime);
std::string srcPath(hapModuleInfo.name);
std::string moduleName(hapModuleInfo.moduleName);
@ -169,8 +171,10 @@ void JsAbilityStage::OnCreate(const AAFwk::Want &want) const
TAG_LOGE(AAFwkTag::APPKIT, "Failed to get 'onCreate' from AbilityStage object");
return;
}
FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "JsAbilityStage::OnCreate begin");
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
napi_call_function(env, obj, methodOnCreate, 0, nullptr, nullptr);
FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "JsAbilityStage::OnCreate end");
auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator();
if (delegator) {

View File

@ -734,9 +734,8 @@ void MainThread::ScheduleLaunchAbility(const AbilityInfo &info, const sptr<IRemo
tmpWatchdog->SetBgWorkingThreadStatus(IsBgWorkingThread(info));
tmpWatchdog = nullptr;
}
FreezeUtil::LifecycleFlow flow = { token, FreezeUtil::TimeoutState::LOAD };
std::string entry = "MainThread::ScheduleLaunchAbility; the load lifecycle.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
std::string entry = "MainThread::ScheduleLaunchAbility";
FreezeUtil::GetInstance().AddLifecycleEvent(token, entry);
wptr<MainThread> weak = this;
auto task = [weak, abilityRecord]() {
@ -1297,7 +1296,7 @@ CJUncaughtExceptionInfo MainThread::CreateCjExceptionInfo(const std::string &bun
void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, const Configuration &config)
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "HandleLaunchApplication:begin");
FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "HandleLaunchApplication begin");
if (!CheckForHandleLaunchApplication(appLaunchData)) {
TAG_LOGE(AAFwkTag::APPKIT, "CheckForHandleLaunchApplication failed");
return;
@ -1748,7 +1747,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
TAG_LOGE(AAFwkTag::APPKIT, "applicationImpl_->PerformAppReady failed");
return;
}
FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "HandleLaunchApplication:end");
FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "HandleLaunchApplication end");
// L1 needs to add corresponding interface
ApplicationEnvImpl *pAppEvnIml = ApplicationEnvImpl::GetInstance();
@ -2159,9 +2158,8 @@ void MainThread::HandleLaunchAbility(const std::shared_ptr<AbilityLocalRecord> &
auto abilityToken = abilityRecord->GetToken();
CHECK_POINTER_LOG(abilityToken, "abilityRecord->GetToken failed");
FreezeUtil::LifecycleFlow flow = { abilityToken, FreezeUtil::TimeoutState::LOAD };
std::string entry = "MainThread::HandleLaunchAbility; the load lifecycle.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
std::string entry = "MainThread::HandleLaunchAbility";
FreezeUtil::GetInstance().AddLifecycleEvent(abilityToken, entry);
abilityRecordMgr_->SetToken(abilityToken);
abilityRecordMgr_->AddAbilityRecord(abilityToken, abilityRecord);
@ -2332,7 +2330,7 @@ void MainThread::HandleForegroundApplication()
}
if (!applicationImpl_->PerformForeground()) {
FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "HandleForegroundApplication fail");
FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "HandleForegroundApplication; fail");
TAG_LOGE(AAFwkTag::APPKIT, "applicationImpl_->PerformForeground() failed");
}

View File

@ -188,9 +188,8 @@ int AppfreezeInner::AcquireStack(const FaultData& info, bool onlyMainThread)
FaultData faultData;
faultData.errorObject.message = it->errorObject.message + "\n";
if (it->state != 0) {
FreezeUtil::LifecycleFlow flow = { it->token, static_cast<FreezeUtil::TimeoutState>(it->state) };
faultData.errorObject.message += "client:\n" +
FreezeUtil::GetInstance().GetLifecycleEvent(flow) + "\nclient app:\n" +
faultData.errorObject.message += "client actions for ability:\n" +
FreezeUtil::GetInstance().GetLifecycleEvent(it->token) + "\nclient actions for app:\n" +
FreezeUtil::GetInstance().GetAppLifecycleEvent(0) + "\n";
}
faultData.errorObject.stack = stack;

View File

@ -67,11 +67,6 @@ enum UserStatus {
ASSERT_CONTINUE,
ASSERT_RETRY,
};
enum class FreezeStrategy : uint8_t {
PRINT_FREEZE_LOG,
NOTIFY_FREEZE_MGR,
};
} // namespace AAFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_ABILITY_STATE_H

View File

@ -61,9 +61,6 @@ ohos_shared_library("app_manager") {
"src/appmgr/app_debug_info.cpp",
"src/appmgr/app_debug_listener_proxy.cpp",
"src/appmgr/app_debug_listener_stub.cpp",
"src/appmgr/app_exception_callback_proxy.cpp",
"src/appmgr/app_exception_callback_stub.cpp",
"src/appmgr/app_exception_manager.cpp",
"src/appmgr/app_foreground_state_observer_proxy.cpp",
"src/appmgr/app_foreground_state_observer_stub.cpp",
"src/appmgr/app_jsheap_mem_info.cpp",

View File

@ -463,8 +463,6 @@ public:
return false;
}
virtual void SetAppExceptionCallback(sptr<IRemoteObject> callback) {}
enum class Message {
LOAD_ABILITY = 0,
TERMINATE_ABILITY,
@ -518,7 +516,6 @@ public:
IS_PROCESS_ATTACHED,
IS_CALLER_KILLING,
ENABLE_START_PROCESS_FLAG_BY_USER_ID,
SET_APP_EXCEPTION_CALLBACK,
SET_KEEP_ALIVE_DKV,
KILL_PROCESSES_IN_BATCH,
// Add enumeration values above

View File

@ -411,8 +411,6 @@ public:
virtual bool IsCallerKilling(const std::string& callerKey) override;
virtual void SetAppExceptionCallback(sptr<IRemoteObject> callback) override;
private:
bool WriteInterfaceToken(MessageParcel &data);
int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);

View File

@ -104,7 +104,6 @@ private:
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);
};
} // namespace AppExecFwk

View File

@ -1,43 +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 OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_PROXY_H
#define OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_PROXY_H
#include "iapp_exception_callback.h"
#include "iremote_proxy.h"
namespace OHOS {
namespace AppExecFwk {
class AppExceptionCallbackProxy : public IRemoteProxy<IAppExceptionCallback> {
public:
explicit AppExceptionCallbackProxy(const sptr<IRemoteObject> &impl);
virtual ~AppExceptionCallbackProxy() = default;
/**
* Notify abilityManager lifecycle exception.
*
* @param type lifecycle failed type
* @param token associated ability
*/
virtual void OnLifecycleException(LifecycleException type, sptr<IRemoteObject> token);
private:
bool WriteInterfaceToken(MessageParcel &data);
static inline BrokerDelegator<AppExceptionCallbackProxy> delegator_;
int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_PROXY_H

View File

@ -1,39 +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 OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_STUB_H
#define OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_STUB_H
#include "iapp_exception_callback.h"
#include "iremote_stub.h"
#include "nocopyable.h"
namespace OHOS {
namespace AppExecFwk {
class AppExceptionCallbackStub : public IRemoteStub<IAppExceptionCallback> {
public:
AppExceptionCallbackStub() = default;
virtual ~AppExceptionCallbackStub() = default;
virtual int32_t OnRemoteRequest(
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
private:
int32_t HandleLifecycleException(MessageParcel &data, MessageParcel &reply);
DISALLOW_COPY_AND_MOVE(AppExceptionCallbackStub);
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_STUB_H

View File

@ -1,43 +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 OHOS_ABILITY_RUNTIME_APP_EXCEPTION_MANAGER_H
#define OHOS_ABILITY_RUNTIME_APP_EXCEPTION_MANAGER_H
#include "iapp_exception_callback.h"
namespace OHOS {
namespace AppExecFwk {
class AppExceptionManager {
public:
static AppExceptionManager &GetInstance();
AppExceptionManager(AppExceptionManager &) = delete;
void operator=(AppExceptionManager &) = delete;
void LaunchAbilityFailed(sptr<IRemoteObject> token, const std::string &msg);
void ForegroundAppFailed(sptr<IRemoteObject> token, const std::string &msg);
void ForegroundAppWait(sptr<IRemoteObject> token, const std::string &msg);
void NotifyLifecycleException(LifecycleException type, sptr<IRemoteObject> token);
void SetExceptionCallback(sptr<IAppExceptionCallback> exceptionCallback);
sptr<IAppExceptionCallback> GetExceptionCallback() const;
private:
AppExceptionManager() = default;
mutable std::mutex exceptionCallbackMutex_;
sptr<IAppExceptionCallback> exceptionCallback_;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_APP_EXCEPTION_MANAGER_H

View File

@ -1,49 +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 OHOS_ABILITY_RUNTIME_I_APP_EXCEPTION_CALLBACK_H
#define OHOS_ABILITY_RUNTIME_I_APP_EXCEPTION_CALLBACK_H
#include "iremote_broker.h"
#include "iremote_object.h"
namespace OHOS {
namespace AppExecFwk {
enum class LifecycleException {
LAUNCH_ABILITY_FAIL,
FOREGROUND_APP_FAIL,
FOREGROUND_APP_WAIT,
END
};
class IAppExceptionCallback : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.AppExceptionCallback");
/**
* Notify abilityManager lifecycle exception.
*
* @param type lifecycle failed type
* @param token associated ability
*/
virtual void OnLifecycleException(LifecycleException type, sptr<IRemoteObject> token) {}
enum class Message {
LIFECYCLE_EXCEPTION_MSG_ID = 0,
};
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_I_APP_EXCEPTION_CALLBACK_H

View File

@ -1395,27 +1395,5 @@ bool AmsMgrProxy::IsCallerKilling(const std::string& callerKey)
}
return reply.ReadBool();
}
void AmsMgrProxy::SetAppExceptionCallback(sptr<IRemoteObject> callback)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(data)) {
TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
return;
}
if (!data.WriteRemoteObject(callback.GetRefPtr())) {
TAG_LOGE(AAFwkTag::APPMGR, "Failed to write callback");
return;
}
auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::SET_APP_EXCEPTION_CALLBACK),
data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGE(AAFwkTag::APPMGR, "Send request failed, error code is %{public}d.", ret);
return;
}
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -901,12 +901,5 @@ int32_t AmsMgrStub::HandleIsCallerKilling(MessageParcel &data, MessageParcel &re
}
return NO_ERROR;
}
int32_t AmsMgrStub::HandleSetAppExceptionCallback(MessageParcel &data, MessageParcel &reply)
{
sptr<IRemoteObject> callback = data.ReadRemoteObject();
SetAppExceptionCallback(callback);
return NO_ERROR;
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -1,85 +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 "app_exception_callback_proxy.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
namespace AppExecFwk {
AppExceptionCallbackProxy::AppExceptionCallbackProxy(const sptr<IRemoteObject> &impl)
: IRemoteProxy<IAppExceptionCallback>(impl) {}
bool AppExceptionCallbackProxy::WriteInterfaceToken(MessageParcel &data)
{
if (!data.WriteInterfaceToken(AppExceptionCallbackProxy::GetDescriptor())) {
TAG_LOGE(AAFwkTag::APPMGR, "write interface token failed");
return false;
}
return true;
}
int32_t AppExceptionCallbackProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option)
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "Remote is nullptr.");
return ERR_NULL_OBJECT;
}
auto ret = remote->SendRequest(code, data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with error code: %{public}d", ret);
return ret;
}
return ret;
}
void AppExceptionCallbackProxy::OnLifecycleException(LifecycleException type, sptr<IRemoteObject> token)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_ASYNC);
if (!WriteInterfaceToken(data)) {
return;
}
int32_t exceptionType = static_cast<int32_t>(type);
if (!data.WriteInt32(exceptionType)) {
TAG_LOGE(AAFwkTag::APPMGR, "Failed to write exceptionType");
return;
}
if (token) {
if (!data.WriteBool(true) || !data.WriteRemoteObject(token.GetRefPtr())) {
TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag and token");
return;
}
} else {
if (!data.WriteBool(false)) {
TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag");
return;
}
}
int32_t ret = SendTransactCmd(
static_cast<uint32_t>(IAppExceptionCallback::Message::LIFECYCLE_EXCEPTION_MSG_ID), data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
}
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -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 "app_exception_callback_stub.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
namespace AppExecFwk {
int32_t AppExceptionCallbackStub::OnRemoteRequest(
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
std::u16string descriptor = AppExceptionCallbackStub::GetDescriptor();
std::u16string remoteDescriptor = data.ReadInterfaceToken();
if (descriptor != remoteDescriptor) {
TAG_LOGE(AAFwkTag::APPMGR, "local descriptor is not equal to remote");
return ERR_INVALID_STATE;
}
switch (code) {
case static_cast<uint32_t>(IAppExceptionCallback::Message::LIFECYCLE_EXCEPTION_MSG_ID):
return HandleLifecycleException(data, reply);
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
}
int32_t AppExceptionCallbackStub::HandleLifecycleException(MessageParcel &data, MessageParcel &reply)
{
auto type = data.ReadInt32();
if (type < 0 || type > static_cast<int32_t>(LifecycleException::END)) {
return ERR_INVALID_STATE;
}
auto lifecycleExceptType = static_cast<LifecycleException>(type);
sptr<IRemoteObject> token;
if (data.ReadBool()) {
token = data.ReadRemoteObject();
}
OnLifecycleException(lifecycleExceptType, token);
return ERR_OK;
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -1,78 +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 "app_exception_manager.h"
#include "freeze_util.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
using AbilityRuntime::FreezeUtil;
namespace AppExecFwk {
AppExceptionManager &AppExceptionManager::GetInstance()
{
static AppExceptionManager appExceptionMgr;
return appExceptionMgr;
}
void AppExceptionManager::LaunchAbilityFailed(sptr<IRemoteObject> token, const std::string &msg)
{
FreezeUtil::LifecycleFlow flow{token, FreezeUtil::TimeoutState::LOAD};
FreezeUtil::GetInstance().AppendLifecycleEvent(flow, std::string("LaunchAbilityFailed: " + msg));
NotifyLifecycleException(LifecycleException::LAUNCH_ABILITY_FAIL, token);
}
void AppExceptionManager::ForegroundAppFailed(sptr<IRemoteObject> token, const std::string &msg)
{
FreezeUtil::LifecycleFlow flow{token, FreezeUtil::TimeoutState::FOREGROUND};
FreezeUtil::GetInstance().AppendLifecycleEvent(flow, std::string("ForegroundAppFailed: " + msg));
NotifyLifecycleException(LifecycleException::FOREGROUND_APP_FAIL, token);
}
void AppExceptionManager::ForegroundAppWait(sptr<IRemoteObject> token, const std::string &msg)
{
FreezeUtil::LifecycleFlow flow{token, FreezeUtil::TimeoutState::FOREGROUND};
FreezeUtil::GetInstance().AppendLifecycleEvent(flow, std::string("ForegroundAppWait: " + msg));
NotifyLifecycleException(LifecycleException::FOREGROUND_APP_WAIT, token);
}
void AppExceptionManager::NotifyLifecycleException(LifecycleException type, sptr<IRemoteObject> token)
{
auto callback = GetExceptionCallback();
if (callback != nullptr) {
TAG_LOGI(AAFwkTag::APPMGR, "notify app exception");
callback->OnLifecycleException(type, token);
}
}
void AppExceptionManager::SetExceptionCallback(sptr<IAppExceptionCallback> exceptionCallback)
{
if (exceptionCallback == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "callback null");
}
std::lock_guard lock(exceptionCallbackMutex_);
if (exceptionCallback_ != nullptr) {
TAG_LOGI(AAFwkTag::APPMGR, "inner callback not null");
}
exceptionCallback_ = exceptionCallback;
}
sptr<IAppExceptionCallback> AppExceptionManager::GetExceptionCallback() const
{
std::lock_guard lock(exceptionCallbackMutex_);
return exceptionCallback_;
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -15,7 +15,7 @@
#include "app_scheduler_proxy.h"
#include "app_exception_manager.h"
#include "error_msg_util.h"
#include "freeze_util.h"
#include "hilog_tag_wrapper.h"
#include "hitrace_meter.h"
@ -46,6 +46,9 @@ bool AppSchedulerProxy::ScheduleForegroundApplication()
if (!WriteInterfaceToken(data)) {
return false;
}
auto msgKey = AbilityRuntime::ErrorMgsUtil::BuildErrorKey(reinterpret_cast<uintptr_t>(this),
"ScheduleForegroundRunning");
AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "AppScheduler::ScheduleForegroundApplication");
int32_t ret =
SendTransactCmd(static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_FOREGROUND_APPLICATION_TRANSACTION),
data,
@ -53,6 +56,8 @@ bool AppSchedulerProxy::ScheduleForegroundApplication()
option);
if (ret != NO_ERROR) {
TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey,
std::string("ScheduleForegroundApplication ipc error ") + std::to_string(ret));
return false;
}
return true;
@ -193,7 +198,6 @@ void AppSchedulerProxy::ScheduleLaunchAbility(const AbilityInfo &info, const spt
return;
}
data.WriteParcelable(&info);
AbilityRuntime::FreezeUtil::LifecycleFlow flow = {token, AbilityRuntime::FreezeUtil::TimeoutState::LOAD};
if (token) {
if (!data.WriteBool(true) || !data.WriteRemoteObject(token.GetRefPtr())) {
TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag and token");
@ -208,8 +212,8 @@ void AppSchedulerProxy::ScheduleLaunchAbility(const AbilityInfo &info, const spt
if (!data.WriteParcelable(want.get())) {
TAG_LOGE(AAFwkTag::APPMGR, "write want fail.");
AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(flow,
"ERROR AppLifeCycleDeal::LaunchAbility; write want fail");
AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token,
"AppLifeCycleDeal::LaunchAbility; write want fail");
return;
}
if (!data.WriteInt32(abilityRecordId)) {
@ -220,8 +224,8 @@ void AppSchedulerProxy::ScheduleLaunchAbility(const AbilityInfo &info, const spt
static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_LAUNCH_ABILITY_TRANSACTION), data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
AppExceptionManager::GetInstance().LaunchAbilityFailed(token, std::string("SendRequest failed") +
std::to_string(ret));
AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token,
"AppLifeCycleDeal::LaunchAbility; ipc error " + std::to_string(ret));
}
}
@ -258,13 +262,18 @@ void AppSchedulerProxy::ScheduleLaunchApplication(const AppLaunchData &launchDat
return;
}
auto msgKey = AbilityRuntime::ErrorMgsUtil::BuildErrorKey(reinterpret_cast<uintptr_t>(this),
"LaunchApplication");
AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "AppScheduler::ScheduleLaunchApplication");
if (!data.WriteParcelable(&launchData)) {
TAG_LOGE(AAFwkTag::APPMGR, "WriteParcelable launchData failed");
AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write launchData fail");
return;
}
if (!data.WriteParcelable(&config)) {
TAG_LOGE(AAFwkTag::APPMGR, "WriteParcelable config failed");
AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write config fail");
return ;
}
@ -272,6 +281,8 @@ void AppSchedulerProxy::ScheduleLaunchApplication(const AppLaunchData &launchDat
static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_LAUNCH_APPLICATION_TRANSACTION), data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey,
std::string("ScheduleLaunchApplication ipc error ") + std::to_string(ret));
}
}

View File

@ -27,7 +27,6 @@ abilityms_files = [
"src/ability_manager_xcollie.cpp",
"src/ability_scheduler_proxy.cpp",
"src/ability_token_stub.cpp",
"src/app_exception_handler.cpp",
"src/app_scheduler.cpp",
"src/app_exit_reason_helper.cpp",
"src/assert_fault_callback_death_mgr.cpp",

View File

@ -1128,16 +1128,6 @@ public:
return securityFlag_;
}
FreezeStrategy GetFreezeStrategy() const
{
return freezeStrategy_;
}
void SetFreezeStrategy(FreezeStrategy value)
{
freezeStrategy_ = value;
}
protected:
void SendEvent(uint32_t msg, uint32_t timeOut, int32_t param = -1, bool isExtension = false);
@ -1365,7 +1355,6 @@ private:
LaunchDebugInfo launchDebugInfo_;
std::string instanceKey_ = "";
bool securityFlag_ = false;
std::atomic<FreezeStrategy> freezeStrategy_{FreezeStrategy::NOTIFY_FREEZE_MGR};
};
} // namespace AAFwk
} // namespace OHOS

View File

@ -1,38 +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 OHOS_ABILITY_RUNTIME_APP_EXCEPTION_HANDLER_H
#define OHOS_ABILITY_RUNTIME_APP_EXCEPTION_HANDLER_H
#include <string>
#include "iremote_object.h"
namespace OHOS {
namespace AAFwk {
class AppExceptionHandler {
public:
static AppExceptionHandler &GetInstance();
AppExceptionHandler(AppExceptionHandler &) = delete;
void operator=(AppExceptionHandler &) = delete;
void RegisterAppExceptionCallback();
void AbilityForegroundFailed(sptr<IRemoteObject> token, const std::string &msg);
private:
AppExceptionHandler() = default;
};
} // namespace AAFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_APP_EXCEPTION_HANDLER_H

View File

@ -1336,7 +1336,6 @@ int AbilityManagerProxy::AttachAbilityThread(const sptr<IAbilityScheduler> &sche
MessageParcel data;
MessageParcel reply;
MessageOption option;
AbilityRuntime::FreezeUtil::LifecycleFlow flow = {token, AbilityRuntime::FreezeUtil::TimeoutState::LOAD};
if (scheduler == nullptr) {
return ERR_INVALID_VALUE;
}
@ -1351,8 +1350,8 @@ int AbilityManagerProxy::AttachAbilityThread(const sptr<IAbilityScheduler> &sche
error = SendRequest(AbilityManagerInterfaceCode::ATTACH_ABILITY_THREAD, data, reply, option);
if (error != NO_ERROR) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(flow,
std::string("ERROR AttachAbilityThread failed IPC error") + std::to_string(error));
AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token,
std::string("AttachAbilityThread; ipc error ") + std::to_string(error));
return error;
}
return reply.ReadInt32();
@ -1365,7 +1364,6 @@ int AbilityManagerProxy::AbilityTransitionDone(const sptr<IRemoteObject> &token,
MessageParcel reply;
MessageOption option;
AbilityRuntime::FreezeUtil::LifecycleFlow flow = {token, AbilityRuntime::FreezeUtil::TimeoutState::FOREGROUND};
if (!WriteInterfaceToken(data)) {
return INNER_ERR;
}
@ -1375,16 +1373,16 @@ int AbilityManagerProxy::AbilityTransitionDone(const sptr<IRemoteObject> &token,
}
if (!data.WriteParcelable(&saveData)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "saveData write fail");
AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(flow,
"write saveData failed");
AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token,
"AbilityTransitionDone; write saveData failed");
return INNER_ERR;
}
error = SendRequest(AbilityManagerInterfaceCode::ABILITY_TRANSITION_DONE, data, reply, option);
if (error != NO_ERROR) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(flow,
std::string("ERROR AbilityTransitionDone failed IPC error") + std::to_string(error));
AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token,
std::string("AbilityTransitionDone; ipc error ") + std::to_string(error));
return error;
}
return reply.ReadInt32();

View File

@ -20,7 +20,6 @@
#include "ability_manager_radar.h"
#include "accesstoken_kit.h"
#include "ability_manager_xcollie.h"
#include "app_exception_handler.h"
#include "app_utils.h"
#include "app_exit_reason_data_manager.h"
#include "application_util.h"
@ -5399,9 +5398,8 @@ int AbilityManagerService::AttachAbilityThread(
}
return dataAbilityManager->AttachAbilityThread(scheduler, token);
} else {
FreezeUtil::LifecycleFlow flow = { token, FreezeUtil::TimeoutState::LOAD };
std::string entry = "AbilityManagerService::AttachAbilityThread; the end of load lifecycle.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
FreezeUtil::GetInstance().AddLifecycleEvent(token, entry);
int32_t ownerMissionUserId = abilityRecord->GetOwnerMissionUserId();
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
auto uiAbilityManager = GetUIAbilityManagerByUserId(ownerMissionUserId);
@ -6003,14 +6001,12 @@ int AbilityManagerService::AbilityTransitionDone(const sptr<IRemoteObject> &toke
}
if (targetState == AbilityState::BACKGROUND) {
FreezeUtil::LifecycleFlow flow = { token, FreezeUtil::TimeoutState::BACKGROUND };
std::string entry = "AbilityManagerService::AbilityTransitionDone; the end of background lifecycle.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
FreezeUtil::GetInstance().AddLifecycleEvent(token, entry);
} else if (targetState != AbilityState::INITIAL) {
FreezeUtil::LifecycleFlow flow = { token, FreezeUtil::TimeoutState::FOREGROUND };
std::string entry = "AbilityManagerService::AbilityTransitionDone; the end of foreground lifecycle."
" the end of foreground lifecycle.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
FreezeUtil::GetInstance().AddLifecycleEvent(token, entry);
}
int32_t ownerMissionUserId = abilityRecord->GetOwnerMissionUserId();
@ -7268,7 +7264,6 @@ void AbilityManagerService::ConnectServices()
TAG_LOGE(AAFwkTag::ABILITYMGR, "failed init appScheduler");
usleep(REPOLL_TIME_MICRO_SECONDS);
}
AppExceptionHandler::GetInstance().RegisterAppExceptionCallback();
TAG_LOGI(AAFwkTag::ABILITYMGR, "waiting bundleMgr service run completed");
while (AbilityUtil::GetBundleManagerHelper() == nullptr) {

View File

@ -20,7 +20,6 @@
#include "ability_manager_service.h"
#include "ability_resident_process_rdb.h"
#include "ability_scheduler_stub.h"
#include "app_exception_handler.h"
#include "app_exit_reason_data_manager.h"
#include "app_utils.h"
#include "array_wrapper.h"
@ -28,6 +27,7 @@
#include "configuration_convertor.h"
#include "connection_state_manager.h"
#include "common_event_manager.h"
#include "error_msg_util.h"
#include "freeze_util.h"
#include "global_constant.h"
#include "hitrace_meter.h"
@ -108,11 +108,10 @@ const int MAX_URI_COUNT = 500;
const int RESTART_SCENEBOARD_DELAY = 500;
constexpr int32_t DMS_UID = 5522;
auto g_addLifecycleEventTask = [](sptr<Token> token, FreezeUtil::TimeoutState state, std::string &methodName) {
auto g_addLifecycleEventTask = [](sptr<Token> token, std::string &methodName) {
CHECK_POINTER_LOG(token, "token is nullptr");
FreezeUtil::LifecycleFlow flow = { token->AsObject(), state };
std::string entry = std::string("AbilityRecord::") + methodName + "; the " + methodName + " lifecycle starts.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
FreezeUtil::GetInstance().AddLifecycleEvent(token->AsObject(), entry);
};
Token::Token(std::weak_ptr<AbilityRecord> abilityRecord) : abilityRecord_(abilityRecord)
@ -308,7 +307,7 @@ void AbilityRecord::LoadUIAbility()
SendEvent(AbilityManagerService::LOAD_HALF_TIMEOUT_MSG, loadTimeout / HALF_TIMEOUT);
SendEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, loadTimeout);
std::string methodName = "LoadAbility";
g_addLifecycleEventTask(token_, FreezeUtil::TimeoutState::LOAD, methodName);
g_addLifecycleEventTask(token_, methodName);
}
int AbilityRecord::LoadAbility(bool isShellCall)
@ -410,9 +409,9 @@ void AbilityRecord::ForegroundAbility(uint32_t sceneFlag)
lifeCycleStateInfo_.sceneFlag = sceneFlag;
Want want = GetWant();
UpdateDmsCallerInfo(want);
if (!lifecycleDeal_->ForegroundNew(want, lifeCycleStateInfo_, GetSessionInfo()) && token_) {
AppExceptionHandler::GetInstance().AbilityForegroundFailed(token_->AsObject(), "ForegroundNew");
}
AbilityRuntime::ErrorMsgGuard errorMsgGuard(token_ ? token_->AsObject() : nullptr,
reinterpret_cast<uintptr_t>(GetScheduler().GetRefPtr()), "ScheduleAbilityTransaction");
lifecycleDeal_->ForegroundNew(want, lifeCycleStateInfo_, GetSessionInfo());
lifeCycleStateInfo_.sceneFlag = 0;
lifeCycleStateInfo_.sceneFlagBak = 0;
{
@ -501,7 +500,7 @@ void AbilityRecord::PostForegroundTimeoutTask()
SendEvent(AbilityManagerService::FOREGROUND_HALF_TIMEOUT_MSG, foregroundTimeout / HALF_TIMEOUT);
SendEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, foregroundTimeout);
std::string methodName = "ProcessForegroundAbility";
g_addLifecycleEventTask(token_, FreezeUtil::TimeoutState::FOREGROUND, methodName);
g_addLifecycleEventTask(token_, methodName);
ResSchedUtil::GetInstance().ReportLoadingEventToRss(LoadingStage::FOREGROUND_BEGIN, GetPid(), GetUid(),
foregroundTimeout, GetAbilityRecordId());
}
@ -512,7 +511,6 @@ void AbilityRecord::RemoveForegroundTimeoutTask()
CHECK_POINTER(handler);
handler->RemoveEvent(AbilityManagerService::FOREGROUND_HALF_TIMEOUT_MSG, GetAbilityRecordId());
handler->RemoveEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, GetAbilityRecordId());
SetFreezeStrategy(FreezeStrategy::NOTIFY_FREEZE_MGR);
}
void AbilityRecord::RemoveLoadTimeoutTask()
@ -521,7 +519,6 @@ void AbilityRecord::RemoveLoadTimeoutTask()
CHECK_POINTER(handler);
handler->RemoveEvent(AbilityManagerService::LOAD_HALF_TIMEOUT_MSG, GetAbilityRecordId());
handler->RemoveEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, GetAbilityRecordId());
SetFreezeStrategy(FreezeStrategy::NOTIFY_FREEZE_MGR);
}
void AbilityRecord::PostUIExtensionAbilityTimeoutTask(uint32_t messageId)
@ -1271,7 +1268,7 @@ void AbilityRecord::BackgroundAbility(const Closure &task)
if (abilityInfo_.type == AppExecFwk::AbilityType::PAGE) {
std::string methodName = "BackgroundAbility";
g_addLifecycleEventTask(token_, FreezeUtil::TimeoutState::BACKGROUND, methodName);
g_addLifecycleEventTask(token_, methodName);
}
}
} else {

View File

@ -19,6 +19,7 @@
#include "data_ability_operation.h"
#include "data_ability_predicates.h"
#include "data_ability_result.h"
#include "error_msg_util.h"
#include "hilog_tag_wrapper.h"
#include "hitrace_meter.h"
#include "ishared_result_set.h"
@ -52,14 +53,18 @@ bool AbilitySchedulerProxy::ScheduleAbilityTransaction(const Want &want, const L
if (!WriteInterfaceToken(data)) {
return false;
}
auto msgKey = AbilityRuntime::ErrorMgsUtil::BuildErrorKey(reinterpret_cast<uintptr_t>(this),
"ScheduleAbilityTransaction");
if (!data.WriteParcelable(&want)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "write want failed");
AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write want failed");
return false;
}
data.WriteParcelable(&stateInfo);
if (sessionInfo) {
if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "write sessionInfo failed");
AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write sessionInfo failed");
return false;
}
} else {
@ -70,6 +75,8 @@ bool AbilitySchedulerProxy::ScheduleAbilityTransaction(const Want &want, const L
int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_ABILITY_TRANSACTION, data, reply, option);
if (err != NO_ERROR) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey,
std::string("ScheduleAbilityTransaction ipc error " + std::to_string(err)));
return false;
}
int64_t cost = std::chrono::duration_cast<std::chrono::microseconds>(

View File

@ -1,88 +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 "app_exception_handler.h"
#include "ability_record.h"
#include "app_exception_callback_stub.h"
#include "app_mgr_util.h"
#include "freeze_util.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
using AppExecFwk::LifecycleException;
using AbilityRuntime::FreezeUtil;
namespace AAFwk {
namespace {
class AppExceptionCallback : public AppExecFwk::AppExceptionCallbackStub {
/**
* Notify abilityManager lifecycle exception.
*
* @param type lifecycle failed type
* @param token associated ability
*/
void OnLifecycleException(LifecycleException type, sptr<IRemoteObject> token) override
{
auto abilityRecord = Token::GetAbilityRecordByToken(token);
if (abilityRecord == nullptr) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "abilityRecord null");
return;
}
TAG_LOGI(AAFwkTag::ABILITYMGR, "lifecycle exception: %{public}s, %{public}d",
abilityRecord->GetURI().c_str(), type);
abilityRecord->SetFreezeStrategy(FreezeStrategy::NOTIFY_FREEZE_MGR);
}
};
}
AppExceptionHandler &AppExceptionHandler::GetInstance()
{
static AppExceptionHandler appExceptionHandler;
return appExceptionHandler;
}
void AppExceptionHandler::RegisterAppExceptionCallback()
{
auto appMgr = AppMgrUtil::GetAppMgr();
if (appMgr == nullptr) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "AppMgrUtil::GetAppMgr failed");
return;
}
auto service = appMgr->GetAmsMgr();
if (service == nullptr) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "GetAmsMgr failed");
return;
}
auto callback = sptr<AppExceptionCallback>(new AppExceptionCallback());
service->SetAppExceptionCallback(callback->AsObject());
}
void AppExceptionHandler::AbilityForegroundFailed(sptr<IRemoteObject> token, const std::string &msg)
{
auto abilityRecord = Token::GetAbilityRecordByToken(token);
if (abilityRecord == nullptr) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "abilityRecord null");
return;
}
FreezeUtil::LifecycleFlow flow{token, FreezeUtil::TimeoutState::FOREGROUND};
FreezeUtil::GetInstance().AppendLifecycleEvent(flow, std::string("AbilityForegroundFailed: " + msg));
TAG_LOGI(AAFwkTag::ABILITYMGR, "AbilityForegroundFailed: %{public}s", abilityRecord->GetURI().c_str());
abilityRecord->SetFreezeStrategy(FreezeStrategy::NOTIFY_FREEZE_MGR);
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -89,10 +89,9 @@ FreezeUtil::TimeoutState MsgId2State(uint32_t msgId)
return FreezeUtil::TimeoutState::UNKNOWN;
}
auto g_deleteLifecycleEventTask = [](const sptr<Token> &token, FreezeUtil::TimeoutState state) {
auto g_deleteLifecycleEventTask = [](const sptr<Token> &token) {
CHECK_POINTER_LOG(token, "token is nullptr.");
FreezeUtil::LifecycleFlow flow = { token->AsObject(), state };
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
FreezeUtil::GetInstance().DeleteLifecycleEvent(token->AsObject());
};
} // namespace
@ -1015,8 +1014,7 @@ int MissionListManager::AttachAbilityThread(const sptr<IAbilityScheduler> &sched
CHECK_POINTER_AND_RETURN_LOG(eventHandler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler.");
abilityRecord->RemoveLoadTimeoutTask();
abilityRecord->SetLoading(false);
FreezeUtil::LifecycleFlow flow = { token, FreezeUtil::TimeoutState::LOAD };
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
FreezeUtil::GetInstance().DeleteLifecycleEvent(token);
abilityRecord->SetScheduler(scheduler);
@ -1256,7 +1254,7 @@ int MissionListManager::DispatchForeground(const std::shared_ptr<AbilityRecord>
auto eventHandler = AbilityManagerService::GetPubInstance()->GetEventHandler();
CHECK_POINTER_AND_RETURN_LOG(eventHandler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler.");
abilityRecord->RemoveForegroundTimeoutTask();
g_deleteLifecycleEventTask(abilityRecord->GetToken(), FreezeUtil::TimeoutState::FOREGROUND);
g_deleteLifecycleEventTask(abilityRecord->GetToken());
FreezeUtil::GetInstance().DeleteAppLifecycleEvent(abilityRecord->GetPid());
auto self(weak_from_this());
auto taskHandler = AbilityManagerService::GetPubInstance()->GetTaskHandler();
@ -1394,7 +1392,7 @@ int MissionListManager::DispatchBackground(const std::shared_ptr<AbilityRecord>
// remove background timeout task.
handler->CancelTask("background_" + std::to_string(abilityRecord->GetAbilityRecordId()));
g_deleteLifecycleEventTask(abilityRecord->GetToken(), FreezeUtil::TimeoutState::BACKGROUND);
g_deleteLifecycleEventTask(abilityRecord->GetToken());
FreezeUtil::GetInstance().DeleteAppLifecycleEvent(abilityRecord->GetPid());
auto self(shared_from_this());
auto task = [self, abilityRecord]() { self->CompleteBackground(abilityRecord); };
@ -2249,20 +2247,17 @@ void MissionListManager::PrintTimeOutLog(const std::shared_ptr<AbilityRecord> &a
flow.token = ability->GetToken()->AsObject();
flow.state = state;
}
info.msg = msgContent + "\nserver:\n" + FreezeUtil::GetInstance().GetLifecycleEvent(flow)
+ "\nserver app:\n" + FreezeUtil::GetInstance().GetAppLifecycleEvent(processInfo.pid_);
info.msg = msgContent + "\nserver actions for ability:\n" +
FreezeUtil::GetInstance().GetLifecycleEvent(flow.token) +
"\nserver actions for app:\n" + FreezeUtil::GetInstance().GetAppLifecycleEvent(processInfo.pid_);
if (!isHalf) {
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow.token);
FreezeUtil::GetInstance().DeleteAppLifecycleEvent(ability->GetPid());
}
} else {
info.msg = msgContent;
}
if (ability->GetFreezeStrategy() == FreezeStrategy::NOTIFY_FREEZE_MGR) {
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info, flow);
} else {
TAG_LOGW(AAFwkTag::ABILITYMGR, "%{public}s", info.msg.c_str());
}
}
bool MissionListManager::GetContentAndTypeId(uint32_t msgId, std::string &msgContent, int &typeId) const

View File

@ -68,10 +68,9 @@ FreezeUtil::TimeoutState MsgId2State(uint32_t msgId)
return FreezeUtil::TimeoutState::UNKNOWN;
}
auto g_deleteLifecycleEventTask = [](const sptr<Token> &token, FreezeUtil::TimeoutState state) {
auto g_deleteLifecycleEventTask = [](const sptr<Token> &token) {
CHECK_POINTER_LOG(token, "token is nullptr.");
FreezeUtil::LifecycleFlow flow = { token->AsObject(), state };
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
FreezeUtil::GetInstance().DeleteLifecycleEvent(token->AsObject());
};
}
@ -294,8 +293,7 @@ int UIAbilityLifecycleManager::AttachAbilityThread(const sptr<IAbilityScheduler>
CHECK_POINTER_AND_RETURN_LOG(handler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler.");
abilityRecord->RemoveLoadTimeoutTask();
abilityRecord->SetLoading(false);
FreezeUtil::LifecycleFlow flow = {token, FreezeUtil::TimeoutState::LOAD};
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
FreezeUtil::GetInstance().DeleteLifecycleEvent(token);
abilityRecord->SetScheduler(scheduler);
if (DoProcessAttachment(abilityRecord) != ERR_OK) {
@ -551,7 +549,7 @@ int UIAbilityLifecycleManager::DispatchForeground(const std::shared_ptr<AbilityR
TAG_LOGD(AAFwkTag::ABILITYMGR, "ForegroundLifecycle: end.");
abilityRecord->RemoveForegroundTimeoutTask();
g_deleteLifecycleEventTask(abilityRecord->GetToken(), FreezeUtil::TimeoutState::FOREGROUND);
g_deleteLifecycleEventTask(abilityRecord->GetToken());
FreezeUtil::GetInstance().DeleteAppLifecycleEvent(abilityRecord->GetPid());
auto self(weak_from_this());
if (success) {
@ -602,7 +600,7 @@ int UIAbilityLifecycleManager::DispatchBackground(const std::shared_ptr<AbilityR
TAG_LOGD(AAFwkTag::ABILITYMGR, "end.");
// remove background timeout task.
handler->CancelTask("background_" + std::to_string(abilityRecord->GetAbilityRecordId()));
g_deleteLifecycleEventTask(abilityRecord->GetToken(), FreezeUtil::TimeoutState::BACKGROUND);
g_deleteLifecycleEventTask(abilityRecord->GetToken());
FreezeUtil::GetInstance().DeleteAppLifecycleEvent(abilityRecord->GetPid());
auto self(shared_from_this());
auto task = [self, abilityRecord]() { self->CompleteBackground(abilityRecord); };
@ -1214,20 +1212,17 @@ void UIAbilityLifecycleManager::PrintTimeOutLog(std::shared_ptr<AbilityRecord> a
flow.token = ability->GetToken()->AsObject();
flow.state = state;
}
info.msg = msgContent + "\nserver:\n" + FreezeUtil::GetInstance().GetLifecycleEvent(flow)
+ "\nserver app:\n" + FreezeUtil::GetInstance().GetAppLifecycleEvent(processInfo.pid_);
info.msg = msgContent + "\nserver actions for ability:\n" +
FreezeUtil::GetInstance().GetLifecycleEvent(flow.token)
+ "\nserver actions for app:\n" + FreezeUtil::GetInstance().GetAppLifecycleEvent(processInfo.pid_);
if (!isHalf) {
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow.token);
FreezeUtil::GetInstance().DeleteAppLifecycleEvent(processInfo.pid_);
}
} else {
info.msg = msgContent;
}
if (ability->GetFreezeStrategy() == FreezeStrategy::NOTIFY_FREEZE_MGR) {
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info, flow);
} else {
TAG_LOGW(AAFwkTag::ABILITYMGR, "%{public}s", info.msg.c_str());
}
}
bool UIAbilityLifecycleManager::GetContentAndTypeId(uint32_t msgId, std::string &msgContent, int &typeId) const

View File

@ -438,8 +438,6 @@ public:
virtual bool IsCallerKilling(const std::string& callerKey) override;
virtual void SetAppExceptionCallback(sptr<IRemoteObject> callback) override;
private:
/**
* @brief Judge whether the application service is ready.

View File

@ -938,6 +938,7 @@ public:
bool GetIsGPU();
void SetGPUPid(pid_t gpuPid);
pid_t GetGPUPid();
pid_t GetPid();
inline void SetStrictMode(bool strictMode)
{

View File

@ -22,7 +22,6 @@
#include "accesstoken_kit.h"
#include "app_death_recipient.h"
#include "app_exception_manager.h"
#include "app_mgr_constants.h"
#include "app_utils.h"
#include "hilog_tag_wrapper.h"
@ -769,25 +768,5 @@ bool AmsMgrScheduler::IsCallerKilling(const std::string& callerKey)
}
return amsMgrServiceInner_->IsCallerKilling(callerKey);
}
void AmsMgrScheduler::SetAppExceptionCallback(sptr<IRemoteObject> callback)
{
if (!IsReady()) {
TAG_LOGE(AAFwkTag::APPMGR, "AmsMgrService is not ready.");
return;
}
pid_t callingPid = IPCSkeleton::GetCallingPid();
pid_t procPid = getprocpid();
if (callingPid != procPid) {
TAG_LOGE(AAFwkTag::APPMGR, "not allow other process to call");
return;
}
if (callback == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "callback null");
}
auto exceptionCallback = iface_cast<IAppExceptionCallback>(callback);
return AppExceptionManager::GetInstance().SetExceptionCallback(exceptionCallback);
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -75,9 +75,8 @@ void AppLifeCycleDeal::LaunchAbility(const std::shared_ptr<AbilityRunningRecord>
return;
}
if (abilityInfo->type == AbilityType::PAGE) {
FreezeUtil::LifecycleFlow flow = {ability->GetToken(), FreezeUtil::TimeoutState::LOAD};
std::string entry = "AppLifeCycleDeal::LaunchAbility; the LoadAbility lifecycle.";
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
std::string entry = "AppLifeCycleDeal::LaunchAbility";
FreezeUtil::GetInstance().AddLifecycleEvent(ability->GetToken(), entry);
}
TAG_LOGD(AAFwkTag::APPMGR, "Launch");
appThread->ScheduleLaunchAbility(*abilityInfo, ability->GetToken(),

View File

@ -34,7 +34,7 @@ int32_t AppMgrEventUtil::GetCallerPid(const std::shared_ptr<AppRunningRecord> &c
return IPCSkeleton::GetCallingPid();
}
return callerAppRecord->GetPriorityObject()->GetPid();
return callerAppRecord->GetPid();
}
void AppMgrEventUtil::UpdateStartupType(const std::shared_ptr<AbilityInfo> &abilityInfo, int32_t &abilityType,
@ -125,7 +125,7 @@ bool AppMgrEventUtil::SendProcessStartEvent(const std::shared_ptr<AppRunningReco
if (!appRecord->GetPriorityObject()) {
TAG_LOGE(AAFwkTag::APPMGR, "null priorityObject");
} else {
eventInfo.pid = appRecord->GetPriorityObject()->GetPid();
eventInfo.pid = appRecord->GetPid();
}
AAFwk::EventReport::SendProcessStartEvent(AAFwk::EventName::PROCESS_START, eventInfo);
return true;
@ -165,7 +165,7 @@ bool AppMgrEventUtil::SendProcessStartFailedEvent(std::shared_ptr<AppRunningReco
if (!appRecord->GetPriorityObject()) {
TAG_LOGE(AAFwkTag::APPMGR, "null priorityObject");
} else {
eventInfo.pid = appRecord->GetPriorityObject()->GetPid();
eventInfo.pid = appRecord->GetPid();
}
AAFwk::EventReport::SendProcessStartFailedEvent(AAFwk::EventName::PROCESS_START_FAILED, eventInfo);
return true;
@ -213,7 +213,7 @@ bool AppMgrEventUtil::SendChildProcessStartFailedEvent(std::shared_ptr<ChildProc
}
eventInfo.time = currentTime;
eventInfo.callerUid = hostRecord->GetUid();
eventInfo.callerPid = hostRecord->GetPriorityObject() != nullptr ? hostRecord->GetPriorityObject()->GetPid() : -1;
eventInfo.callerPid = hostRecord->GetPriorityObject() != nullptr ? hostRecord->GetPid() : -1;
eventInfo.callerBundleName = hostRecord->GetBundleName();
eventInfo.callerProcessName = hostRecord->GetProcessName();
eventInfo.bundleName = hostRecord->GetBundleName();
@ -245,7 +245,7 @@ bool AppMgrEventUtil::SendRenderProcessStartFailedEvent(std::shared_ptr<RenderRe
}
eventInfo.time = currentTime;
eventInfo.callerUid = hostRecord->GetUid();
eventInfo.callerPid = hostRecord->GetPriorityObject() != nullptr ? hostRecord->GetPriorityObject()->GetPid() : -1;
eventInfo.callerPid = hostRecord->GetPriorityObject() != nullptr ? hostRecord->GetPid() : -1;
eventInfo.callerBundleName = hostRecord->GetBundleName();
eventInfo.callerProcessName = hostRecord->GetProcessName();
eventInfo.bundleName = hostRecord->GetBundleName();

View File

@ -599,14 +599,14 @@ int32_t AppMgrServiceInner::ProcessKia(bool isKia, std::shared_ptr<AppRunningRec
#ifdef SUPPORT_SCREEN
TAG_LOGI(AAFwkTag::APPMGR, "Openning KIA file, start setting watermark");
int32_t resultCode = static_cast<int32_t>(WindowManager::GetInstance().SetProcessWatermark(
appRecord->GetPriorityObject()->GetPid(), watermarkBusinessName, isWatermarkEnabled));
appRecord->GetPid(), watermarkBusinessName, isWatermarkEnabled));
if (resultCode != ERR_OK) {
TAG_LOGE(AAFwkTag::APPMGR, "setting watermark fails with result code:%{public}d", resultCode);
return resultCode;
}
TAG_LOGI(AAFwkTag::APPMGR, "setting watermark succeeds, start setting snapshot skip");
resultCode = static_cast<int32_t>(WindowManager::GetInstance().SkipSnapshotForAppProcess(
appRecord->GetPriorityObject()->GetPid(), isWatermarkEnabled));
appRecord->GetPid(), isWatermarkEnabled));
if (resultCode != ERR_OK) {
TAG_LOGE(AAFwkTag::APPMGR, "setting snapshot skip fails with result code:%{public}d", resultCode);
return resultCode;
@ -636,10 +636,8 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
}
}
if (abilityInfo->type == AbilityType::PAGE) {
AbilityRuntime::FreezeUtil::LifecycleFlow flow = {loadParam->token,
AbilityRuntime::FreezeUtil::TimeoutState::LOAD};
std::string entry = "AppMgrServiceInner::LoadAbility; the load lifecycle.";
AbilityRuntime::FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
std::string entry = "AppMgrServiceInner::LoadAbility";
AbilityRuntime::FreezeUtil::GetInstance().AddLifecycleEvent(loadParam->token, entry);
}
if (!appRunningManager_) {
@ -808,7 +806,7 @@ void AppMgrServiceInner::AddUIExtensionLauncherItem(std::shared_ptr<AAFwk::Want>
auto hostPid = want->GetIntParam(UIEXTENSION_ROOT_HOST_PID, -1);
pid_t providerPid = -1;
if (appRecord->GetPriorityObject() != nullptr) {
providerPid = appRecord->GetPriorityObject()->GetPid();
providerPid = appRecord->GetPid();
}
if (uiExtensionAbilityId == -1 || hostPid == -1 || providerPid == -1) {
TAG_LOGE(AAFwkTag::APPMGR, "invalid want params");
@ -1154,7 +1152,7 @@ void AppMgrServiceInner::AttachApplication(const pid_t pid, const sptr<IAppSched
sceneBoardAttachFlag_ = true;
SubmitCacheLoadAbilityTask();
}
eventInfo.pid = appRecord->GetPriorityObject()->GetPid();
eventInfo.pid = appRecord->GetPid();
eventInfo.processName = appRecord->GetProcessName();
AAFwk::EventReport::SendAppEvent(AAFwk::EventName::APP_ATTACH, HiSysEventType::BEHAVIOR, eventInfo);
}
@ -1352,7 +1350,7 @@ void AppMgrServiceInner::ApplicationBackgrounded(const int32_t recordId)
return;
}
// Prevent forged requests from changing the app's state.
appRecord->AddAppLifecycleEvent("ServiceInner::ForeForegrounded");
appRecord->AddAppLifecycleEvent("ServiceInner::AppBackgrounded");
if (appRecord->GetApplicationScheduleState() != ApplicationScheduleState::SCHEDULE_BACKGROUNDING) {
TAG_LOGE(AAFwkTag::APPMGR, "app is not scheduling to background");
return;
@ -1398,7 +1396,7 @@ AAFwk::EventInfo AppMgrServiceInner::BuildEventInfo(std::shared_ptr<AppRunningRe
eventInfo.bundleType = static_cast<int32_t>(applicationInfo->bundleType);
}
if (appRecord->GetPriorityObject() != nullptr) {
eventInfo.pid = appRecord->GetPriorityObject()->GetPid();
eventInfo.pid = appRecord->GetPid();
}
eventInfo.processName = appRecord->GetProcessName();
eventInfo.processType = static_cast<int32_t>(appRecord->GetProcessType());
@ -1441,7 +1439,7 @@ void AppMgrServiceInner::ApplicationTerminated(const int32_t recordId)
eventInfo.versionCode = applicationInfo->versionCode;
}
ClearAppRunningDataForKeepAlive(appRecord);
eventInfo.pid = appRecord->GetPriorityObject()->GetPid();
eventInfo.pid = appRecord->GetPid();
eventInfo.processName = appRecord->GetProcessName();
AAFwk::EventReport::SendAppEvent(AAFwk::EventName::APP_TERMINATE, HiSysEventType::BEHAVIOR, eventInfo);
@ -1648,7 +1646,7 @@ void AppMgrServiceInner::SendProcessExitEventTask(
TAG_LOGE(AAFwkTag::APPMGR, "priority object null");
return;
}
auto pid = appRecord->GetPriorityObject()->GetPid();
auto pid = appRecord->GetPid();
auto exitResult = !ProcessExist(pid);
constexpr int32_t EXIT_SUCESS = 0;
constexpr int32_t EXIT_FAILED = -1;
@ -2398,7 +2396,7 @@ void AppMgrServiceInner::GetRunningProcess(const std::shared_ptr<AppRunningRecor
RunningProcessInfo &info)
{
info.processName_ = appRecord->GetProcessName();
info.pid_ = appRecord->GetPriorityObject()->GetPid();
info.pid_ = appRecord->GetPid();
info.uid_ = appRecord->GetUid();
info.state_ = static_cast<AppProcessState>(appRecord->GetState());
info.isContinuousTask = appRecord->IsContinuousTask();
@ -2459,7 +2457,7 @@ void AppMgrServiceInner::GetChildrenProcesses(const std::shared_ptr<AppRunningRe
if (retCode != ERR_OK) {
TAG_LOGW(
AAFwkTag::APPMGR, "GetChildProcessInfo failed. host pid=%{public}d, child pid=%{public}d",
appRecord->GetPriorityObject()->GetPid(), childProcessRecord->GetPid());
appRecord->GetPid(), childProcessRecord->GetPid());
continue;
}
info.emplace_back(childProcessInfo);
@ -2518,7 +2516,7 @@ int32_t AppMgrServiceInner::KillProcessByPidInner(const pid_t pid, const std::st
killedProcessMap_.emplace(killTime, appRecord->GetProcessName());
}
DelayedSingleton<CacheProcessManager>::GetInstance()->OnProcessKilled(appRecord);
eventInfo.pid = appRecord->GetPriorityObject()->GetPid();
eventInfo.pid = appRecord->GetPid();
eventInfo.processName = appRecord->GetProcessName();
std::string newReason = appRecord->GetKillReason().empty() ? killReason : appRecord->GetKillReason();
bool foreground = appRecord->GetState() == ApplicationState::APP_STATE_FOREGROUND ||
@ -2692,8 +2690,9 @@ void AppMgrServiceInner::UpdateAbilityState(const sptr<IRemoteObject> &token, co
return;
}
AbilityRuntime::FreezeUtil::LifecycleFlow flow{token, AbilityRuntime::FreezeUtil::TimeoutState::FOREGROUND};
AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(flow, "ServiceInner::UpdateAbilityState");
if (state == AbilityState::ABILITY_STATE_BACKGROUND) {
AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token, "ServiceInner::UpdateAbilityState");
}
auto appRecord = GetAppRunningRecordByAbilityToken(token);
if (!appRecord) {
TAG_LOGE(AAFwkTag::APPMGR, "app unexist");
@ -2874,7 +2873,7 @@ void AppMgrServiceInner::KillProcessByAbilityToken(const sptr<IRemoteObject> &to
return;
}
pid_t pid = appRecord->GetPriorityObject()->GetPid();
pid_t pid = appRecord->GetPid();
if (pid > 0) {
std::list<pid_t> pids;
pids.push_back(pid);
@ -2972,7 +2971,7 @@ void AppMgrServiceInner::AttachPidToParent(const sptr<IRemoteObject> &token, con
TAG_LOGE(AAFwkTag::APPMGR, "abilityRecord null");
return;
}
auto pid = appRecord->GetPriorityObject()->GetPid();
auto pid = appRecord->GetPid();
if (pid <= 0) {
TAG_LOGE(AAFwkTag::APPMGR, "invalid pid");
return;
@ -3138,7 +3137,7 @@ void AppMgrServiceInner::OnAppStarted(const std::shared_ptr<AppRunningRecord> &a
}
TAG_LOGD(AAFwkTag::APPMGR, "OnAppStarted begin, bundleName is %{public}s, pid:%{public}d",
appRecord->GetBundleName().c_str(), appRecord->GetPriorityObject()->GetPid());
appRecord->GetBundleName().c_str(), appRecord->GetPid());
DelayedSingleton<AppStateObserverManager>::GetInstance()->OnAppStarted(appRecord);
}
@ -3158,7 +3157,7 @@ void AppMgrServiceInner::OnAppStopped(const std::shared_ptr<AppRunningRecord> &a
}
TAG_LOGD(AAFwkTag::APPMGR, "OnAppStopped begin, bundleName is %{public}s, pid:%{public}d",
appRecord->GetBundleName().c_str(), appRecord->GetPriorityObject()->GetPid());
appRecord->GetBundleName().c_str(), appRecord->GetPid());
DelayedSingleton<AppStateObserverManager>::GetInstance()->OnAppStopped(appRecord);
}
@ -3175,7 +3174,7 @@ AppProcessData AppMgrServiceInner::WrapAppProcessData(const std::shared_ptr<AppR
processData.appDatas.push_back(data);
}
processData.processName = appRecord->GetProcessName();
processData.pid = appRecord->GetPriorityObject()->GetPid();
processData.pid = appRecord->GetPid();
processData.appState = state;
processData.isFocused = appRecord->GetFocusFlag();
processData.appIndex = appRecord->GetAppIndex();
@ -3846,7 +3845,7 @@ void AppMgrServiceInner::SendAppStartupTypeEvent(const std::shared_ptr<AppRunnin
if (appRecord->GetPriorityObject() == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "priorityObject null");
} else {
eventInfo.pid = appRecord->GetPriorityObject()->GetPid();
eventInfo.pid = appRecord->GetPid();
}
eventInfo.startType = static_cast<int32_t>(startType);
AAFwk::EventReport::SendAppEvent(AAFwk::EventName::APP_STARTUP_TYPE, HiSysEventType::BEHAVIOR, eventInfo);
@ -4023,7 +4022,7 @@ void AppMgrServiceInner::TerminateApplication(const std::shared_ptr<AppRunningRe
appRecord->RemoveAppDeathRecipient();
appRecord->SetProcessChangeReason(ProcessChangeReason::REASON_APP_TERMINATED_TIMEOUT);
OnAppStateChanged(appRecord, ApplicationState::APP_STATE_TERMINATED, false, false);
pid_t pid = appRecord->GetPriorityObject()->GetPid();
pid_t pid = appRecord->GetPid();
int32_t uid = appRecord->GetUid();
if (pid > 0) {
auto timeoutTask = [appRecord, pid, uid, innerService = shared_from_this()]() {
@ -4227,7 +4226,7 @@ void AppMgrServiceInner::StartEmptyResidentProcess(
}
appRecord->AddModules(appInfo, hapModuleInfos);
TAG_LOGI(AAFwkTag::APPMGR, "StartEmptyResidentProcess of pid : [%{public}d], ",
appRecord->GetPriorityObject()->GetPid());
appRecord->GetPid());
}
bool AppMgrServiceInner::CheckRemoteClient()
@ -4554,7 +4553,7 @@ int AppMgrServiceInner::StartEmptyProcess(const AAFwk::Want &want, const sptr<IR
appRecord->SetTaskHandler(taskHandler_);
appRecord->SetEventHandler(eventHandler_);
appRecord->AddModules(appInfo, info.hapModuleInfos);
TAG_LOGI(AAFwkTag::APPMGR, "startEmptyProcess pid: [%{public}d]", appRecord->GetPriorityObject()->GetPid());
TAG_LOGI(AAFwkTag::APPMGR, "startEmptyProcess pid: [%{public}d]", appRecord->GetPid());
return ERR_OK;
}
@ -4994,7 +4993,7 @@ void AppMgrServiceInner::KillApplicationByRecord(const std::shared_ptr<AppRunnin
return;
}
auto pid = appRecord->GetPriorityObject()->GetPid();
auto pid = appRecord->GetPid();
appRecord->SetTerminating();
if (!appRunningManager_) {
TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ null");
@ -5040,7 +5039,7 @@ void AppMgrServiceInner::SendHiSysEvent(int32_t innerEventId, std::shared_ptr<Ap
}
std::string eventName = GetEventName(innerEventId);
int32_t pid = appRecord->GetPriorityObject()->GetPid();
int32_t pid = appRecord->GetPid();
int32_t uid = appRecord->GetUid();
std::string packageName = appRecord->GetBundleName();
std::string processName = appRecord->GetProcessName();
@ -7511,7 +7510,7 @@ void AppMgrServiceInner::KillAttachedChildProcess(const std::shared_ptr<AppRunni
}
auto parentAppRecord = appRecord->GetParentAppRecord();
if (parentAppRecord) {
parentAppRecord->RemoveChildAppRecord(appRecord->GetPriorityObject()->GetPid());
parentAppRecord->RemoveChildAppRecord(appRecord->GetPid());
}
std::vector<pid_t> pids;
std::queue<std::shared_ptr<AppRunningRecord>> queue;
@ -7653,7 +7652,7 @@ void AppMgrServiceInner::SendAppLaunchEvent(const std::shared_ptr<AppRunningReco
eventInfo.versionCode = applicationInfo->versionCode;
}
if (appRecord->GetPriorityObject() != nullptr) {
eventInfo.pid = appRecord->GetPriorityObject()->GetPid();
eventInfo.pid = appRecord->GetPid();
}
eventInfo.processName = appRecord->GetProcessName();
int32_t callerPid = appRecord->GetCallerPid() == -1 ?
@ -8141,7 +8140,7 @@ void AppMgrServiceInner::OnAppCacheStateChanged(const std::shared_ptr<AppRunning
}
TAG_LOGD(AAFwkTag::APPMGR, "OnAppCacheStateChanged begin, bundleName is %{public}s, pid:%{public}d",
appRecord->GetBundleName().c_str(), appRecord->GetPriorityObject()->GetPid());
appRecord->GetBundleName().c_str(), appRecord->GetPid());
DelayedSingleton<AppStateObserverManager>::GetInstance()->OnAppCacheStateChanged(appRecord, state);
}
@ -8263,7 +8262,7 @@ void AppMgrServiceInner::KillProcessDependedOnWeb()
}
std::string bundleName = appRecord->GetBundleName();
pid_t pid = appRecord->GetPriorityObject()->GetPid();
pid_t pid = appRecord->GetPid();
if (appRecord->IsKeepAliveApp()) {
ExitResidentProcessManager::GetInstance().RecordExitResidentBundleDependedOnWeb(bundleName,
appRecord->GetUid());
@ -8375,7 +8374,7 @@ void AppMgrServiceInner::CheckCleanAbilityByUserRequest(const std::shared_ptr<Ap
pid_t pid = 0;
if (appRecord->GetPriorityObject()) {
pid = appRecord->GetPriorityObject()->GetPid();
pid = appRecord->GetPid();
}
TAG_LOGI(AAFwkTag::APPMGR, "clean ability set up bg, force kill, pid:%{public}d", pid);
KillProcessByPid(pid, KILL_REASON_USER_REQUEST);
@ -8405,7 +8404,7 @@ void AppMgrServiceInner::GetPidsByAccessTokenId(const uint32_t accessTokenId, st
continue;
}
if (accessTokenId == applicationInfo->accessTokenId) {
pid_t curPid = appRecord->GetPriorityObject()->GetPid();
pid_t curPid = appRecord->GetPid();
if (appRecord->GetState() == ApplicationState::APP_STATE_FOREGROUND) {
foregroundPid = curPid;
continue;
@ -8518,7 +8517,7 @@ int32_t AppMgrServiceInner::GetSupportedProcessCachePids(const std::string &bund
osAccountMgr->GetOsAccountLocalIdFromUid(appRecord->GetUid(), procUserId) == 0 &&
procUserId == callderUserId && cachePrcoMgr->IsAppSupportProcessCache(appRecord) &&
appRecord->GetPriorityObject() != nullptr) {
pidList.push_back(appRecord->GetPriorityObject()->GetPid());
pidList.push_back(appRecord->GetPid());
}
}
return ERR_OK;

View File

@ -248,7 +248,7 @@ std::shared_ptr<AppRunningRecord> AppRunningManager::GetAppRunningRecordByPid(co
{
std::lock_guard guard(runningRecordMapMutex_);
auto iter = std::find_if(appRunningRecordMap_.begin(), appRunningRecordMap_.end(), [&pid](const auto &pair) {
return pair.second->GetPriorityObject()->GetPid() == pid;
return pair.second->GetPid() == pid;
});
return ((iter == appRunningRecordMap_.end()) ? nullptr : iter->second);
}
@ -277,7 +277,7 @@ bool AppRunningManager::ProcessExitByBundleName(
// Before using this method, consider whether you need.
if (appRecord && (!appRecord->IsKeepAliveApp() ||
!ExitResidentProcessManager::GetInstance().IsMemorySizeSufficient())) {
pid_t pid = appRecord->GetPriorityObject()->GetPid();
pid_t pid = appRecord->GetPid();
auto appInfoList = appRecord->GetAppInfoList();
auto isExist = [&bundleName](const std::shared_ptr<ApplicationInfo> &appInfo) {
return appInfo->bundleName == bundleName;
@ -306,7 +306,7 @@ bool AppRunningManager::GetPidsByUserId(int32_t userId, std::list<pid_t> &pids)
int32_t id = -1;
if ((DelayedSingleton<OsAccountManagerWrapper>::GetInstance()->
GetOsAccountLocalIdFromUid(appRecord->GetUid(), id) == 0) && (id == userId)) {
pid_t pid = appRecord->GetPriorityObject()->GetPid();
pid_t pid = appRecord->GetPid();
if (pid > 0) {
pids.push_back(pid);
appRecord->ScheduleProcessSecurityExit();
@ -352,7 +352,7 @@ bool AppRunningManager::ProcessExitByBundleNameAndUid(
return appInfo->bundleName == bundleName && appInfo->uid == uid;
};
auto iter = std::find_if(appInfoList.begin(), appInfoList.end(), isExist);
pid_t pid = appRecord->GetPriorityObject()->GetPid();
pid_t pid = appRecord->GetPid();
if (iter == appInfoList.end() || pid <= 0) {
continue;
}
@ -393,7 +393,7 @@ bool AppRunningManager::ProcessExitByBundleNameAndAppIndex(const std::string &bu
}
if (appInfo->bundleName == bundleName && appRecord->GetAppIndex() == appIndex) {
pid_t pid = appRecord->GetPriorityObject()->GetPid();
pid_t pid = appRecord->GetPid();
if (pid <= 0) {
continue;
}
@ -433,7 +433,7 @@ bool AppRunningManager::ProcessExitByTokenIdAndInstance(uint32_t accessTokenId,
if (appRecord->GetPriorityObject() == nullptr) {
continue;
}
pid_t pid = appRecord->GetPriorityObject()->GetPid();
pid_t pid = appRecord->GetPid();
if (pid <= 0) {
continue;
}
@ -463,7 +463,7 @@ bool AppRunningManager::GetPidsByBundleNameUserIdAndAppIndex(const std::string &
appInfo->appIndex == appIndex;
};
auto iter = std::find_if(appInfoList.begin(), appInfoList.end(), isExist);
pid_t pid = appRecord->GetPriorityObject()->GetPid();
pid_t pid = appRecord->GetPid();
if (iter == appInfoList.end() || pid <= 0) {
continue;
}
@ -523,7 +523,7 @@ std::shared_ptr<AppRunningRecord> AppRunningManager::OnRemoteDied(const wptr<IRe
}
}
if (appRecord != nullptr && appRecord->GetPriorityObject() != nullptr) {
RemoveUIExtensionLauncherItem(appRecord->GetPriorityObject()->GetPid());
RemoveUIExtensionLauncherItem(appRecord->GetPid());
}
return appRecord;
@ -552,8 +552,8 @@ void AppRunningManager::RemoveAppRunningRecordById(const int32_t recordId)
}
if (appRecord != nullptr && appRecord->GetPriorityObject() != nullptr) {
RemoveUIExtensionLauncherItem(appRecord->GetPriorityObject()->GetPid());
AbilityRuntime::FreezeUtil::GetInstance().DeleteAppLifecycleEvent(appRecord->GetPriorityObject()->GetPid());
RemoveUIExtensionLauncherItem(appRecord->GetPid());
AbilityRuntime::FreezeUtil::GetInstance().DeleteAppLifecycleEvent(appRecord->GetPid());
}
}
@ -782,7 +782,7 @@ void AppRunningManager::NotifyAppPreCache(const std::shared_ptr<AppRunningRecord
appRecord->GetPriorityObject() == nullptr) {
return;
}
int32_t pid = appRecord->GetPriorityObject()->GetPid();
int32_t pid = appRecord->GetPid();
int32_t userId = appRecord->GetUid() / BASE_USER_RANGE;
auto notifyAppPreCache = [pid, userId, inner = appMgrServiceInner]() {
if (inner == nullptr) {
@ -821,7 +821,7 @@ int32_t AppRunningManager::AssignRunningProcessInfoByAppRecord(
}
info.processName_ = appRecord->GetProcessName();
info.pid_ = appRecord->GetPriorityObject()->GetPid();
info.pid_ = appRecord->GetPid();
info.uid_ = appRecord->GetUid();
info.bundleNames.emplace_back(appRecord->GetBundleName());
info.state_ = static_cast<AppExecFwk::AppProcessState>(appRecord->GetState());
@ -877,7 +877,7 @@ void AppRunningManager::GetForegroundApplications(std::vector<AppStateData> &lis
AppStateData appData;
appData.bundleName = appRecord->GetBundleName();
appData.uid = appRecord->GetUid();
appData.pid = appRecord->GetPriorityObject()->GetPid();
appData.pid = appRecord->GetPid();
appData.state = static_cast<int32_t>(ApplicationState::APP_STATE_FOREGROUND);
auto appInfo = appRecord->GetApplicationInfo();
appData.accessTokenId = appInfo ? appInfo->accessTokenId : 0;
@ -1131,7 +1131,7 @@ bool AppRunningManager::GetAppRunningStateByBundleName(const std::string &bundle
TAG_LOGD(AAFwkTag::APPMGR, "Process of [%{public}s] is running, processName: %{public}s.",
bundleName.c_str(), appRecord->GetProcessName().c_str());
if (IPCSkeleton::GetCallingUid() == QUICKFIX_UID && appRecord->GetPriorityObject() != nullptr) {
TAG_LOGI(AAFwkTag::APPMGR, "pid: %{public}d", appRecord->GetPriorityObject()->GetPid());
TAG_LOGI(AAFwkTag::APPMGR, "pid: %{public}d", appRecord->GetPid());
}
return true;
}
@ -1575,7 +1575,7 @@ int AppRunningManager::DumpIpcAllStart(std::string& result)
for (const auto &item : GetAppRunningRecordMap()) {
const auto &appRecord = item.second;
TAG_LOGD(AAFwkTag::APPMGR, "AppRunningManager::DumpIpcAllStart::pid:%{public}d",
appRecord->GetPriorityObject()->GetPid());
appRecord->GetPid());
std::string currentResult;
errCode = appRecord->DumpIpcStart(currentResult);
result += currentResult + "\n";
@ -1593,7 +1593,7 @@ int AppRunningManager::DumpIpcAllStop(std::string& result)
for (const auto &item : GetAppRunningRecordMap()) {
const auto &appRecord = item.second;
TAG_LOGD(AAFwkTag::APPMGR, "AppRunningManager::DumpIpcAllStop::pid:%{public}d",
appRecord->GetPriorityObject()->GetPid());
appRecord->GetPid());
std::string currentResult;
errCode = appRecord->DumpIpcStop(currentResult);
result += currentResult + "\n";
@ -1611,7 +1611,7 @@ int AppRunningManager::DumpIpcAllStat(std::string& result)
for (const auto &item : GetAppRunningRecordMap()) {
const auto &appRecord = item.second;
TAG_LOGD(AAFwkTag::APPMGR, "AppRunningManager::DumpIpcAllStat::pid:%{public}d",
appRecord->GetPriorityObject()->GetPid());
appRecord->GetPid());
std::string currentResult;
errCode = appRecord->DumpIpcStat(currentResult);
result += currentResult + "\n";
@ -1725,7 +1725,7 @@ bool AppRunningManager::HandleUserRequestClean(const sptr<IRemoteObject> &abilit
appRecord->SetUserRequestCleaning();
if (appRecord->GetPriorityObject()) {
pid = appRecord->GetPriorityObject()->GetPid();
pid = appRecord->GetPid();
}
uid = appRecord->GetUid();
return true;

View File

@ -14,9 +14,9 @@
*/
#include "ability_window_configuration.h"
#include "app_exception_manager.h"
#include "app_running_record.h"
#include "app_mgr_service_inner.h"
#include "error_msg_util.h"
#include "event_report.h"
#include "exit_resident_process_manager.h"
#include "freeze_util.h"
@ -469,8 +469,10 @@ void AppRunningRecord::LaunchApplication(const Configuration &config)
TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_");
return;
}
if (!appLifeCycleDeal_->GetApplicationClient()) {
auto scheduler = appLifeCycleDeal_->GetApplicationClient();
if (!scheduler) {
TAG_LOGE(AAFwkTag::APPMGR, "null appThread");
AddAppLifecycleEvent("AppRunningRecord::LaunchApplication; null scheduler");
return;
}
AppLaunchData launchData;
@ -481,7 +483,7 @@ void AppRunningRecord::LaunchApplication(const Configuration &config)
launchData.SetApplicationInfo(*(moduleRecords->second));
}
}
ProcessInfo processInfo(processName_, GetPriorityObject()->GetPid());
ProcessInfo processInfo(processName_, GetPid());
processInfo.SetProcessType(processType_);
launchData.SetProcessInfo(processInfo);
launchData.SetRecordId(appRecordId_);
@ -501,6 +503,8 @@ void AppRunningRecord::LaunchApplication(const Configuration &config)
TAG_LOGD(AAFwkTag::APPMGR, "%{public}s called,app is %{public}s.", __func__, GetName().c_str());
AddAppLifecycleEvent("AppRunningRecord::LaunchApplication");
AbilityRuntime::ErrorMsgGuard errorMsgGuard(GetPid(), reinterpret_cast<uintptr_t>(scheduler.GetRefPtr()),
"LaunchApplication");
appLifeCycleDeal_->LaunchApplication(launchData, config);
}
@ -667,6 +671,13 @@ bool AppRunningRecord::ScheduleForegroundRunning()
SetApplicationScheduleState(ApplicationScheduleState::SCHEDULE_FOREGROUNDING);
if (appLifeCycleDeal_) {
AddAppLifecycleEvent("AppRunningRecord::ScheduleForegroundRunning");
auto scheduler = appLifeCycleDeal_->GetApplicationClient();
if (!scheduler) {
AddAppLifecycleEvent("AppRunningRecord::ScheduleForegroundRunning; null scheduler");
return false;
}
AbilityRuntime::ErrorMsgGuard errorMsgGuard(GetPid(), reinterpret_cast<uintptr_t>(scheduler.GetRefPtr()),
"ScheduleForegroundRunning");
return appLifeCycleDeal_->ScheduleForegroundRunning();
}
return false;
@ -845,7 +856,7 @@ void AppRunningRecord::StateChangedNotifyObserver(const std::shared_ptr<AbilityR
abilityStateData.bundleName = abilityInfo->applicationInfo.bundleName;
abilityStateData.moduleName = abilityInfo->moduleName;
abilityStateData.abilityName = ability->GetName();
abilityStateData.pid = GetPriorityObject()->GetPid();
abilityStateData.pid = GetPid();
abilityStateData.abilityState = state;
abilityStateData.uid = abilityInfo->applicationInfo.uid;
abilityStateData.token = ability->GetToken();
@ -1020,10 +1031,9 @@ void AppRunningRecord::AbilityForeground(const std::shared_ptr<AbilityRunningRec
SetApplicationPendingState(ApplicationPendingState::FOREGROUNDING);
if (pendingState == ApplicationPendingState::READY) {
if (!ScheduleForegroundRunning()) {
AppExceptionManager::GetInstance().ForegroundAppFailed(ability->GetToken(), "schedule failed");
AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(ability->GetToken(),
"ScheduleForegroundRunning fail");
}
} else {
AppExceptionManager::GetInstance().ForegroundAppWait(ability->GetToken(), "pendingState not ready");
}
foregroundingAbilityTokens_.insert(ability->GetToken());
TAG_LOGD(AAFwkTag::APPMGR, "foregroundingAbility size: %{public}d",
@ -1325,7 +1335,7 @@ void AppRunningRecord::SendAppStartupTypeEvent(const std::shared_ptr<AbilityRunn
if (GetPriorityObject() == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "null priorityObject");
} else {
eventInfo.pid = GetPriorityObject()->GetPid();
eventInfo.pid = GetPid();
}
eventInfo.startType = static_cast<int32_t>(startType);
AAFwk::EventReport::SendAppEvent(AAFwk::EventName::APP_STARTUP_TYPE, HiSysEventType::BEHAVIOR, eventInfo);
@ -2005,7 +2015,7 @@ void AppRunningRecord::ChangeWindowVisibility(const sptr<OHOS::Rosen::WindowVisi
TAG_LOGE(AAFwkTag::APPMGR, "null priorityObject");
return;
} else {
if (info->pid_ != GetPriorityObject()->GetPid()) {
if (info->pid_ != GetPid()) {
return;
}
}
@ -2039,7 +2049,7 @@ void AppRunningRecord::OnWindowVisibilityChanged(
TAG_LOGE(AAFwkTag::APPMGR, "null info");
continue;
}
if (info->pid_ != GetPriorityObject()->GetPid()) {
if (info->pid_ != GetPid()) {
continue;
}
std::lock_guard windowIdsLock(windowIdsLock_);
@ -2487,6 +2497,15 @@ pid_t AppRunningRecord::GetGPUPid()
return gpuPid_;
}
pid_t AppRunningRecord::GetPid()
{
auto prioObj = GetPriorityObject();
if (prioObj) {
return prioObj->GetPid();
}
return 0;
}
void AppRunningRecord::SetAttachedToStatusBar(bool isAttached)
{
isAttachedToStatusBar = isAttached;

View File

@ -816,7 +816,7 @@ ProcessData AppStateObserverManager::WrapProcessData(const std::shared_ptr<AppRu
{
ProcessData processData;
processData.bundleName = appRecord->GetBundleName();
processData.pid = appRecord->GetPriorityObject()->GetPid();
processData.pid = appRecord->GetPid();
processData.uid = appRecord->GetUid();
auto applicationInfo = appRecord->GetApplicationInfo();
if (applicationInfo) {
@ -1025,7 +1025,7 @@ AppStateData AppStateObserverManager::WrapAppStateData(const std::shared_ptr<App
const ApplicationState state)
{
AppStateData appStateData;
appStateData.pid = appRecord->GetPriorityObject()->GetPid();
appStateData.pid = appRecord->GetPid();
appStateData.bundleName = appRecord->GetBundleName();
appStateData.state = static_cast<int32_t>(state);
appStateData.uid = appRecord->GetUid();

View File

@ -144,7 +144,7 @@ bool CacheProcessManager::CheckAndCacheProcess(const std::shared_ptr<AppRunningR
};
std::string taskName = "DELAY_CACHED_STATE_NOTIFY";
if (appRecord->GetPriorityObject()) {
taskName += std::to_string(appRecord->GetPriorityObject()->GetPid());
taskName += std::to_string(appRecord->GetPid());
}
auto res = appRecord->CancelTask(taskName);
if (res) {
@ -301,7 +301,7 @@ void CacheProcessManager::CheckAndSetProcessCacheEnable(const std::shared_ptr<Ap
return;
}
bool forceKillProcess =
AAFwk::ResSchedUtil::GetInstance().CheckShouldForceKillProcess(appRecord->GetPriorityObject()->GetPid());
AAFwk::ResSchedUtil::GetInstance().CheckShouldForceKillProcess(appRecord->GetPid());
if (forceKillProcess) {
appRecord->SetProcessCacheBlocked(true);
return;

View File

@ -49,7 +49,6 @@ sptr<Token> GetFuzzAbilityToken()
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
{
FreezeUtil::LifecycleFlow flow;
std::string JsonStr(data, size);
FreezeUtil::GetInstance();
sptr<IRemoteObject> token = GetFuzzAbilityToken();
@ -57,11 +56,9 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
std::cout << "Get ability token failed." << std::endl;
return false;
};
FreezeUtil::GetInstance().AddLifecycleEvent(flow, JsonStr);
FreezeUtil::GetInstance().GetLifecycleEvent(flow);
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
FreezeUtil::GetInstance().AddLifecycleEvent(token, JsonStr);
FreezeUtil::GetInstance().GetLifecycleEvent(token);
FreezeUtil::GetInstance().DeleteLifecycleEvent(token);
FreezeUtil::GetInstance().DeleteLifecycleEventInner(flow);
return true;
}
}

View File

@ -51,15 +51,14 @@ void FreezeUtilTest::TearDown()
*/
HWTEST_F(FreezeUtilTest, FreezeUtilTest_001, TestSize.Level1)
{
FreezeUtil::LifecycleFlow flow;
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(flow), "");
flow.state = FreezeUtil::TimeoutState::FOREGROUND;
FreezeUtil::GetInstance().AddLifecycleEvent(flow, "firstEntry");
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(flow),
sptr<IPCObjectStub> token(new IPCObjectStub(u"testStub"));
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token), "");
FreezeUtil::GetInstance().AddLifecycleEvent(token, "firstEntry");
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token),
TimeUtil::DefaultCurrentTimeStr() + "; " + "firstEntry");
FreezeUtil::GetInstance().AddLifecycleEvent(flow, "secondEntry");
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(flow), TimeUtil::DefaultCurrentTimeStr() + "; " +
FreezeUtil::GetInstance().AddLifecycleEvent(token, "secondEntry");
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token), TimeUtil::DefaultCurrentTimeStr() + "; " +
"firstEntry\n" + TimeUtil::DefaultCurrentTimeStr() + "; " + "secondEntry");
TAG_LOGI(AAFwkTag::TEST, "FreezeUtilTest_001 is end");
}
@ -71,13 +70,12 @@ HWTEST_F(FreezeUtilTest, FreezeUtilTest_001, TestSize.Level1)
*/
HWTEST_F(FreezeUtilTest, FreezeUtilTest_002, TestSize.Level1)
{
FreezeUtil::LifecycleFlow flow;
flow.state = FreezeUtil::TimeoutState::LOAD;
FreezeUtil::GetInstance().AddLifecycleEvent(flow, "testDeleteEntry");
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(flow),
sptr<IPCObjectStub> token(new IPCObjectStub(u"testStub"));
FreezeUtil::GetInstance().AddLifecycleEvent(token, "testDeleteEntry");
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token),
TimeUtil::DefaultCurrentTimeStr() + "; " + "testDeleteEntry");
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(flow), "");
FreezeUtil::GetInstance().DeleteLifecycleEvent(token);
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token), "");
TAG_LOGI(AAFwkTag::TEST, "FreezeUtilTest_002 is end");
}
@ -88,20 +86,21 @@ HWTEST_F(FreezeUtilTest, FreezeUtilTest_002, TestSize.Level1)
*/
HWTEST_F(FreezeUtilTest, FreezeUtilTest_003, TestSize.Level1)
{
sptr<IRemoteObject> token_(new IPCObjectStub());
FreezeUtil::LifecycleFlow foregroundFlow = { token_, FreezeUtil::TimeoutState::FOREGROUND };
FreezeUtil::GetInstance().AddLifecycleEvent(foregroundFlow, "testDeleteLifecyleEventForground");
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(foregroundFlow),
sptr<IRemoteObject> token1(new IPCObjectStub());
FreezeUtil::GetInstance().AddLifecycleEvent(token1, "testDeleteLifecyleEventForground");
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token1),
TimeUtil::DefaultCurrentTimeStr() + "; " + "testDeleteLifecyleEventForground");
FreezeUtil::LifecycleFlow backgroundFlow = { token_, FreezeUtil::TimeoutState::BACKGROUND };
FreezeUtil::GetInstance().AddLifecycleEvent(backgroundFlow, "testDeleteLifecyleEventBackground");
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(backgroundFlow),
sptr<IRemoteObject> token2(new IPCObjectStub());
FreezeUtil::GetInstance().AddLifecycleEvent(token2, "testDeleteLifecyleEventBackground");
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token2),
TimeUtil::DefaultCurrentTimeStr() + "; " + "testDeleteLifecyleEventBackground");
FreezeUtil::GetInstance().DeleteLifecycleEvent(token_);
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(foregroundFlow), "");
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(backgroundFlow), "");
FreezeUtil::GetInstance().DeleteLifecycleEvent(token1);
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token1), "");
FreezeUtil::GetInstance().DeleteLifecycleEvent(token2);
EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token2), "");
TAG_LOGI(AAFwkTag::TEST, "FreezeUtilTest_003 is end");
}
}

View File

@ -26,7 +26,10 @@ ohos_shared_library("freeze_util") {
"${ability_runtime_services_path}/common/include",
]
sources = [ "src/freeze_util.cpp" ]
sources = [
"src/error_msg_util.cpp",
"src/freeze_util.cpp",
]
public_configs = [ ":freeze_util_config" ]

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_ERROR_MSG_UTIL_H
#define OHOS_ABILITY_RUNTIME_ERROR_MSG_UTIL_H
#include <mutex>
#include <string>
#include <unordered_map>
#include "iremote_object.h"
namespace OHOS::AbilityRuntime {
class ErrorMsgGuard {
public:
ErrorMsgGuard(sptr<IRemoteObject> token, uintptr_t scheduler, const std::string &name); // for ability
ErrorMsgGuard(pid_t pid, uintptr_t scheduler, const std::string &name); // for app
~ErrorMsgGuard();
ErrorMsgGuard(const ErrorMsgGuard &) = delete;
void operator=(const ErrorMsgGuard &) = delete;
private:
sptr<IRemoteObject> token_; // token, determines ability or app
pid_t pid_ = 0;
std::string errorKey_;
};
class ErrorMgsUtil {
public:
ErrorMgsUtil& operator=(const ErrorMgsUtil&) = delete;
ErrorMgsUtil(const ErrorMgsUtil&) = delete;
virtual ~ErrorMgsUtil() = default;
static ErrorMgsUtil& GetInstance();
static std::string BuildErrorKey(uintptr_t scheduler, const std::string &name);
void AddErrorMsg(const std::string &key, const std::string &errorMsg);
bool UpdateErrorMsg(const std::string &key, const std::string &errorMsg);
std::string DeleteErrorMsg(const std::string &key);
private:
ErrorMgsUtil() = default;
std::mutex errorMsgMapMutex_;
std::unordered_map<std::string, std::string> errorMsgMap_;
};
} // namespace OHOS::AbilityRuntime
#endif // OHOS_ABILITY_RUNTIME_ERROR_MSG_UTIL_H

View File

@ -16,6 +16,7 @@
#ifndef OHOS_ABILITY_RUNTIME_FREEZE_UTIL_H
#define OHOS_ABILITY_RUNTIME_FREEZE_UTIL_H
#include <list>
#include <mutex>
#include <unordered_map>
@ -34,11 +35,6 @@ public:
struct LifecycleFlow {
sptr<IRemoteObject> token;
TimeoutState state = TimeoutState::UNKNOWN;
bool operator==(const LifecycleFlow &other) const
{
return token == other.token && state == other.state;
}
};
FreezeUtil& operator=(const FreezeUtil&) = delete;
@ -46,10 +42,9 @@ public:
virtual ~FreezeUtil() = default;
static FreezeUtil& GetInstance();
void AddLifecycleEvent(const LifecycleFlow &flow, const std::string &entry);
bool AppendLifecycleEvent(const LifecycleFlow &flow, const std::string &entry);
std::string GetLifecycleEvent(const LifecycleFlow &flow);
void DeleteLifecycleEvent(const LifecycleFlow &flow);
void AddLifecycleEvent(sptr<IRemoteObject> token, const std::string &entry);
bool AppendLifecycleEvent(sptr<IRemoteObject> token, const std::string &entry);
std::string GetLifecycleEvent(sptr<IRemoteObject> token);
void DeleteLifecycleEvent(sptr<IRemoteObject> token);
void AddAppLifecycleEvent(pid_t pid, const std::string &entry);
@ -57,19 +52,18 @@ public:
std::string GetAppLifecycleEvent(pid_t pid);
private:
FreezeUtil() = default;
void DeleteLifecycleEventInner(const LifecycleFlow &flow);
class LifecycleFlowObjHash {
class RemoteObjHash {
public:
size_t operator() (const LifecycleFlow &flow) const
size_t operator() (const sptr<IRemoteObject> &obj) const
{
return reinterpret_cast<size_t>(flow.token.GetRefPtr()) + std::hash<int>()(static_cast<int>(flow.state));
return std::hash<IRemoteObject*>()(obj.GetRefPtr());
}
};
std::mutex mutex_;
std::unordered_map<LifecycleFlow, std::string, LifecycleFlowObjHash> lifecycleFlow_;
std::unordered_map<pid_t, std::string> appLifeCycleFlow_;
std::unordered_map<sptr<IRemoteObject>, std::list<std::string>, RemoteObjHash> lifecycleFlow_;
std::unordered_map<pid_t, std::list<std::string>> appLifeCycleFlow_;
};
} // namespace OHOS::AbilityRuntime
#endif // OHOS_ABILITY_RUNTIME_FREEZE_UTIL_H

View File

@ -0,0 +1,87 @@
/*
* 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 "error_msg_util.h"
#include "freeze_util.h"
namespace OHOS::AbilityRuntime {
ErrorMsgGuard::ErrorMsgGuard(sptr<IRemoteObject> token, uintptr_t scheduler, const std::string &name)
: token_(token), errorKey_(ErrorMgsUtil::BuildErrorKey(scheduler, name))
{
if (token != nullptr) {
ErrorMgsUtil::GetInstance().AddErrorMsg(errorKey_, "");
}
}
ErrorMsgGuard::ErrorMsgGuard(pid_t pid, uintptr_t scheduler, const std::string &name)
: pid_(pid), errorKey_(ErrorMgsUtil::BuildErrorKey(scheduler, name))
{
ErrorMgsUtil::GetInstance().AddErrorMsg(errorKey_, "");
}
ErrorMsgGuard::~ErrorMsgGuard()
{
auto errorMsg = ErrorMgsUtil::GetInstance().DeleteErrorMsg(errorKey_);
if (errorMsg.empty()) {
return;
}
if (token_) {
FreezeUtil::GetInstance().AppendLifecycleEvent(token_, errorMsg);
} else {
FreezeUtil::GetInstance().AddAppLifecycleEvent(pid_, errorMsg);
}
}
ErrorMgsUtil &ErrorMgsUtil::GetInstance()
{
static ErrorMgsUtil instance;
return instance;
}
std::string ErrorMgsUtil::BuildErrorKey(uintptr_t scheduler, const std::string &name)
{
return std::to_string(scheduler) + "#" + name;
}
void ErrorMgsUtil::AddErrorMsg(const std::string &key, const std::string &errorMsg)
{
std::lock_guard lock(errorMsgMapMutex_);
errorMsgMap_[key] = errorMsg;
}
bool ErrorMgsUtil::UpdateErrorMsg(const std::string &key, const std::string &errorMsg)
{
std::lock_guard lock(errorMsgMapMutex_);
auto it = errorMsgMap_.find(key);
if (it == errorMsgMap_.end()) {
return false;
}
it->second = errorMsg;
return true;
}
std::string ErrorMgsUtil::DeleteErrorMsg(const std::string &key)
{
std::lock_guard lock(errorMsgMapMutex_);
auto it = errorMsgMap_.find(key);
if (it == errorMsgMap_.end()) {
return "";
}
auto result = std::move(it->second);
errorMsgMap_.erase(it);
return result;
}
} // namespace OHOS::AbilityRuntime

View File

@ -19,82 +19,90 @@
#include "time_util.h"
namespace OHOS::AbilityRuntime {
namespace {
constexpr int32_t MAX_ENTRY_COUNT = 20;
std::string ConcatStr(const std::list<std::string> &strList, const std::string &split)
{
if (strList.empty()) {
return "";
}
if (strList.size() == 1) {
return strList.front();
}
int32_t reserveSize = 0;
for (const auto &item : strList) {
reserveSize += split.size() + item.size();
}
reserveSize -= split.size();
std::string result;
if (reserveSize > 0) {
result.reserve(reserveSize);
}
result.append(strList.front());
auto iter = strList.begin();
for (++iter; iter != strList.end(); ++iter) {
result.append(split).append(*iter);
}
return result;
}
}
FreezeUtil& FreezeUtil::GetInstance()
{
static FreezeUtil instance;
return instance;
}
void FreezeUtil::AddLifecycleEvent(const LifecycleFlow &flow, const std::string &entry)
void FreezeUtil::AddLifecycleEvent(sptr<IRemoteObject> token, const std::string &entry)
{
auto newEntry = TimeUtil::DefaultCurrentTimeStr() + "; " + entry;
std::lock_guard lock(mutex_);
auto iter = lifecycleFlow_.find(flow);
if (iter != lifecycleFlow_.end()) {
iter->second += "\n" + newEntry;
} else {
lifecycleFlow_.emplace(flow, newEntry);
auto &entryList = lifecycleFlow_[token];
entryList.emplace_back(TimeUtil::DefaultCurrentTimeStr() + "; " + entry);
if (entryList.size() > MAX_ENTRY_COUNT) {
entryList.pop_front();
}
}
bool FreezeUtil::AppendLifecycleEvent(const LifecycleFlow &flow, const std::string &entry)
bool FreezeUtil::AppendLifecycleEvent(sptr<IRemoteObject> token, const std::string &entry)
{
std::lock_guard lock(mutex_);
auto iter = lifecycleFlow_.find(flow);
auto iter = lifecycleFlow_.find(token);
if (iter == lifecycleFlow_.end()) {
return false;
}
auto newEntry = TimeUtil::DefaultCurrentTimeStr() + "; " + entry;
iter->second += "\n" + newEntry;
auto &entryList = iter->second;
entryList.emplace_back(TimeUtil::DefaultCurrentTimeStr() + "; " + entry);
if (entryList.size() > MAX_ENTRY_COUNT) {
entryList.pop_front();
}
return true;
}
std::string FreezeUtil::GetLifecycleEvent(const LifecycleFlow &flow)
std::string FreezeUtil::GetLifecycleEvent(sptr<IRemoteObject> token)
{
std::lock_guard lock(mutex_);
auto search = lifecycleFlow_.find(flow);
auto search = lifecycleFlow_.find(token);
if (search != lifecycleFlow_.end()) {
return search->second;
return ConcatStr(search->second, "\n");
}
return "";
}
void FreezeUtil::DeleteLifecycleEvent(const LifecycleFlow &flow)
{
std::lock_guard lock(mutex_);
DeleteLifecycleEventInner(flow);
}
void FreezeUtil::DeleteLifecycleEvent(sptr<IRemoteObject> token)
{
std::lock_guard lock(mutex_);
if (lifecycleFlow_.empty()) {
return;
}
LifecycleFlow foregroundFlow = { token, TimeoutState::FOREGROUND };
DeleteLifecycleEventInner(foregroundFlow);
LifecycleFlow backgroundFlow = { token, TimeoutState::BACKGROUND };
DeleteLifecycleEventInner(backgroundFlow);
}
void FreezeUtil::DeleteLifecycleEventInner(const LifecycleFlow &flow)
{
if (lifecycleFlow_.count(flow)) {
lifecycleFlow_.erase(flow);
}
TAG_LOGD(AAFwkTag::DEFAULT, "lifecycleFlow size: %{public}zu", lifecycleFlow_.size());
lifecycleFlow_.erase(token);
}
void FreezeUtil::AddAppLifecycleEvent(pid_t pid, const std::string &entry)
{
std::lock_guard lock(mutex_);
auto newEntry = TimeUtil::DefaultCurrentTimeStr() + "; " + entry;
auto iter = appLifeCycleFlow_.find(pid);
if (iter != appLifeCycleFlow_.end()) {
iter->second += "\n" + newEntry;
} else {
appLifeCycleFlow_.emplace(pid, newEntry);
auto &entryList = appLifeCycleFlow_[pid];
entryList.emplace_back(TimeUtil::DefaultCurrentTimeStr() + "; " + entry);
if (entryList.size() > MAX_ENTRY_COUNT) {
entryList.pop_front();
}
}
@ -109,7 +117,7 @@ std::string FreezeUtil::GetAppLifecycleEvent(pid_t pid)
std::lock_guard lock(mutex_);
auto search = appLifeCycleFlow_.find(pid);
if (search != appLifeCycleFlow_.end()) {
return search->second;
return ConcatStr(search->second, "\n");
}
return "";
}