mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-23 07:10:19 +00:00
Signed-off-by: yuwenze <yuwenze1@huawei.com>
Change-Id: I1fdffc68d655e67aeecf2dd75d35d56dbb2aec41 Change-Id: Id7ac9b29a00018afd99082f858de7c5e619425e5
This commit is contained in:
parent
9403244b5d
commit
fd90eeedaf
@ -17,7 +17,6 @@
|
||||
|
||||
#include <mutex>
|
||||
#include "ability_delegator_registry.h"
|
||||
#include "ability_runtime/js_ability.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_ability_delegator_utils.h"
|
||||
#include "js_context_utils.h"
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "js_ability_delegator_utils.h"
|
||||
|
||||
#include <map>
|
||||
#include "ability_runtime/js_ability.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_ability_monitor.h"
|
||||
#include "napi/native_common.h"
|
||||
|
@ -186,6 +186,7 @@ ohos_shared_library("abilitykit_utils") {
|
||||
ohos_shared_library("abilitykit_native") {
|
||||
include_dirs = [
|
||||
"${ability_base_kits_path}/extractortool/include",
|
||||
"${ability_runtime_path}/utils/global/time/include",
|
||||
"${relational_store_napi_path}/rdb/include",
|
||||
"${relational_store_napi_path}/common/include",
|
||||
"${relational_store_napi_path}/dataability/include",
|
||||
@ -249,6 +250,7 @@ ohos_shared_library("abilitykit_native") {
|
||||
"${ability_runtime_native_path}/appkit:app_context",
|
||||
"${ability_runtime_native_path}/appkit:app_context_utils",
|
||||
"${ability_runtime_native_path}/appkit:appkit_delegator",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
]
|
||||
|
||||
@ -408,8 +410,10 @@ ohos_shared_library("extensionkit_native") {
|
||||
}
|
||||
|
||||
ohos_shared_library("ability_thread") {
|
||||
include_dirs =
|
||||
[ "${ability_runtime_path}/interfaces/kits/native/ability/native" ]
|
||||
include_dirs = [
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native",
|
||||
"${ability_runtime_path}/utils/global/time/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${ability_runtime_native_path}/ability/native/ability_thread.cpp",
|
||||
@ -424,6 +428,7 @@ ohos_shared_library("ability_thread") {
|
||||
"${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager",
|
||||
"${ability_runtime_native_path}/ability:ability_context_native",
|
||||
"${ability_runtime_native_path}/appkit:app_context",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
@ -18,13 +18,16 @@
|
||||
#include "ability_runtime/js_ability.h"
|
||||
#include "ability_transaction_callback_info.h"
|
||||
#include "data_ability_predicates.h"
|
||||
#include "freeze_util.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "ohos_application.h"
|
||||
#include "scene_board_judgement.h"
|
||||
#include "time_util.h"
|
||||
#include "values_bucket.h"
|
||||
|
||||
namespace OHOS {
|
||||
using AbilityRuntime::FreezeUtil;
|
||||
namespace AppExecFwk {
|
||||
namespace {
|
||||
const std::string PERMISSION_KEY = "ohos.user.grant.permission";
|
||||
@ -628,12 +631,17 @@ void AbilityImpl::AfterFocusedCommon(bool isFocused)
|
||||
void AbilityImpl::WindowLifeCycleImpl::AfterForeground()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_INFO("Call.");
|
||||
HILOG_INFO("Lifecycle: Call.");
|
||||
auto owner = owner_.lock();
|
||||
if (owner == nullptr || !owner->IsStageBasedModel()) {
|
||||
HILOG_ERROR("Not stage mode ability or abilityImpl is nullptr.");
|
||||
return;
|
||||
}
|
||||
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::FOREGROUND };
|
||||
std::string entry = std::to_string(AbilityRuntime::TimeUtil::SystemTimeMillisecond()) +
|
||||
"; AbilityImpl::WindowLifeCycleImpl::AfterForeground; the foreground lifecycle.";
|
||||
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
|
||||
|
||||
bool needNotifyAMS = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(owner->notifyForegroundLock_);
|
||||
@ -647,27 +655,36 @@ void AbilityImpl::WindowLifeCycleImpl::AfterForeground()
|
||||
}
|
||||
|
||||
if (needNotifyAMS) {
|
||||
HILOG_INFO("Stage mode ability, window after foreground, notify ability manager service.");
|
||||
HILOG_INFO("Lifecycle: window notify ability manager service.");
|
||||
PacMap restoreData;
|
||||
AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_,
|
||||
auto ret = AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_,
|
||||
AbilityLifeCycleState::ABILITY_STATE_FOREGROUND_NEW, restoreData);
|
||||
if (ret == ERR_OK) {
|
||||
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityImpl::WindowLifeCycleImpl::AfterBackground()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_INFO("Call.");
|
||||
auto owner = owner_.lock();
|
||||
if (owner && !owner->IsStageBasedModel()) {
|
||||
HILOG_WARN("Not stage.");
|
||||
return;
|
||||
}
|
||||
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::BACKGROUND };
|
||||
std::string entry = std::to_string(AbilityRuntime::TimeUtil::SystemTimeMillisecond()) +
|
||||
"; AbilityImpl::WindowLifeCycleImpl::AfterBackground; the background lifecycle.";
|
||||
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
|
||||
|
||||
HILOG_INFO("UIAbility, window after background.");
|
||||
HILOG_INFO("Lifecycle: window after background.");
|
||||
PacMap restoreData;
|
||||
AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_,
|
||||
auto ret = AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_,
|
||||
AbilityLifeCycleState::ABILITY_STATE_BACKGROUND_NEW, restoreData);
|
||||
if (ret == ERR_OK) {
|
||||
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityImpl::WindowLifeCycleImpl::AfterFocused()
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "napi_remote_object.h"
|
||||
#include "scene_board_judgement.h"
|
||||
#include "string_wrapper.h"
|
||||
#include "time_util.h"
|
||||
#include "context/context.h"
|
||||
#include "context/application_context.h"
|
||||
#include "hitrace_meter.h"
|
||||
@ -230,7 +231,10 @@ void JsAbility::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
|
||||
jsWant,
|
||||
CreateJsLaunchParam(env, GetLaunchParam()),
|
||||
};
|
||||
std::string methodName = "OnStart";
|
||||
AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
CallObjectMethod("onCreate", argv, ArraySize(argv));
|
||||
AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
|
||||
auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (delegator) {
|
||||
@ -240,6 +244,22 @@ void JsAbility::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
|
||||
HILOG_DEBUG("OnStart end, ability is %{public}s.", GetAbilityName().c_str());
|
||||
}
|
||||
|
||||
void JsAbility::AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const
|
||||
{
|
||||
FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, state };
|
||||
auto entry = std::to_string(TimeUtil::SystemTimeMillisecond()) + "; JsAbility::" + methodName +
|
||||
"; the " + methodName + " begin.";
|
||||
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
|
||||
}
|
||||
|
||||
void JsAbility::AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const
|
||||
{
|
||||
FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, state };
|
||||
auto entry = std::to_string(TimeUtil::SystemTimeMillisecond()) + "; JsAbility::" + methodName +
|
||||
"; the " + methodName + " end.";
|
||||
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
|
||||
}
|
||||
|
||||
int32_t JsAbility::OnShare(WantParams &wantParam)
|
||||
{
|
||||
HILOG_DEBUG("%{public}s begin", __func__);
|
||||
@ -361,7 +381,10 @@ void JsAbility::OnSceneCreated()
|
||||
napi_value argv[] = {jsAppWindowStage->GetNapiValue()};
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "onWindowStageCreate");
|
||||
std::string methodName = "OnSceneCreated";
|
||||
AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
CallObjectMethod("onWindowStageCreate", argv, ArraySize(argv));
|
||||
AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
}
|
||||
|
||||
auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
@ -457,8 +480,10 @@ void JsAbility::OnForeground(const Want &want)
|
||||
}
|
||||
|
||||
napi_set_named_property(env, obj, "lastRequestWant", jsWant);
|
||||
|
||||
std::string methodName = "OnForeground";
|
||||
AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
CallObjectMethod("onForeground", &jsWant, 1);
|
||||
AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
|
||||
auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (delegator) {
|
||||
@ -477,7 +502,10 @@ void JsAbility::OnBackground()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("OnBackground begin, ability is %{public}s.", GetAbilityName().c_str());
|
||||
std::string methodName = "OnBackground";
|
||||
AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState::BACKGROUND, methodName);
|
||||
CallObjectMethod("onBackground");
|
||||
AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState::BACKGROUND, methodName);
|
||||
|
||||
Ability::OnBackground();
|
||||
|
||||
@ -655,15 +683,16 @@ void JsAbility::DoOnForeground(const Want &want)
|
||||
window->SetSystemPrivacyMode(true);
|
||||
}
|
||||
|
||||
HILOG_DEBUG("%{public}s begin scene_->GoForeground, sceneFlag_:%{public}d.", __func__, Ability::sceneFlag_);
|
||||
HILOG_INFO("Move scene to foreground, sceneFlag_:%{public}d.", Ability::sceneFlag_);
|
||||
scene_->GoForeground(Ability::sceneFlag_);
|
||||
HILOG_DEBUG("%{public}s end scene_->GoForeground.", __func__);
|
||||
}
|
||||
|
||||
void JsAbility::RequestFocus(const Want &want)
|
||||
{
|
||||
HILOG_DEBUG("%{public}s called.", __func__);
|
||||
HILOG_INFO("Lifecycle: begin.");
|
||||
if (scene_ == nullptr) {
|
||||
HILOG_ERROR("scene_ is nullptr.");
|
||||
return;
|
||||
}
|
||||
auto window = scene_->GetMainWindow();
|
||||
@ -673,7 +702,11 @@ void JsAbility::RequestFocus(const Want &want)
|
||||
window->SetWindowMode(static_cast<Rosen::WindowMode>(windowMode));
|
||||
HILOG_DEBUG("set window mode = %{public}d.", windowMode);
|
||||
}
|
||||
std::string methodName = "RequestFocus";
|
||||
AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
scene_->GoForeground(Ability::sceneFlag_);
|
||||
AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
HILOG_INFO("Lifecycle: end.");
|
||||
}
|
||||
|
||||
void JsAbility::ContinuationRestore(const Want &want)
|
||||
@ -866,7 +899,10 @@ void JsAbility::OnNewWant(const Want &want)
|
||||
jsWant,
|
||||
CreateJsLaunchParam(env, GetLaunchParam()),
|
||||
};
|
||||
std::string methodName = "OnNewWant";
|
||||
AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
CallObjectMethod("onNewWant", argv, ArraySize(argv));
|
||||
AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
|
||||
HILOG_DEBUG("%{public}s end.", __func__);
|
||||
}
|
||||
@ -930,7 +966,7 @@ sptr<IRemoteObject> JsAbility::CallRequest()
|
||||
napi_value JsAbility::CallObjectMethod(const char *name, napi_value const *argv, size_t argc, bool withResult)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("JsAbility::CallObjectMethod(%{public}s", name);
|
||||
HILOG_INFO("Lifecycle: the begin of %{public}s", name);
|
||||
|
||||
if (!jsAbilityObj_) {
|
||||
HILOG_WARN("Not found Ability.js");
|
||||
@ -958,6 +994,7 @@ napi_value JsAbility::CallObjectMethod(const char *name, napi_value const *argv,
|
||||
return handleEscape.Escape(result);
|
||||
}
|
||||
napi_call_function(env, obj, methodOnCreate, argc, argv, nullptr);
|
||||
HILOG_INFO("Lifecycle: the end of %{public}s", name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -31,16 +31,19 @@
|
||||
#ifdef WITH_DLP
|
||||
#include "dlp_file_kits.h"
|
||||
#endif // WITH_DLP
|
||||
#include "freeze_util.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "ohos_application.h"
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
#include "page_ability_impl.h"
|
||||
#endif
|
||||
#include "time_util.h"
|
||||
#include "ui_extension_utils.h"
|
||||
#include "values_bucket.h"
|
||||
|
||||
namespace OHOS {
|
||||
using AbilityRuntime::FreezeUtil;
|
||||
namespace AbilityRuntime {
|
||||
using namespace std::chrono_literals;
|
||||
using AbilityManagerClient = OHOS::AAFwk::AbilityManagerClient;
|
||||
@ -308,10 +311,17 @@ void FAAbilityThread::AttachInner(const std::shared_ptr<AppExecFwk::OHOSApplicat
|
||||
}
|
||||
abilityImpl_->Init(application, abilityRecord, currentAbility_, abilityHandler_, token_);
|
||||
// 4. ability attach : ipc
|
||||
HILOG_INFO("LoadLifecycle: Attach ability.");
|
||||
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::LOAD };
|
||||
std::string entry = std::to_string(AbilityRuntime::TimeUtil::SystemTimeMillisecond()) +
|
||||
"; AbilityThread::Attach; the load lifecycle.";
|
||||
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
|
||||
ErrCode err = AbilityManagerClient::GetInstance()->AttachAbilityThread(this, token_);
|
||||
if (err != ERR_OK) {
|
||||
HILOG_ERROR("err = %{public}d", err);
|
||||
return;
|
||||
}
|
||||
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
|
||||
}
|
||||
|
||||
void FAAbilityThread::AttachExtension(const std::shared_ptr<AppExecFwk::OHOSApplication> &application,
|
||||
@ -472,11 +482,13 @@ void FAAbilityThread::HandleAbilityTransaction(
|
||||
std::string connector = "##";
|
||||
std::string traceName = __PRETTY_FUNCTION__ + connector + want.GetElement().GetAbilityName();
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, traceName);
|
||||
HILOG_DEBUG("begin, name is %{public}s", want.GetElement().GetAbilityName().c_str());
|
||||
HILOG_INFO("Lifecycle: name is %{public}s.", want.GetElement().GetAbilityName().c_str());
|
||||
if (abilityImpl_ == nullptr) {
|
||||
HILOG_ERROR("abilityImpl_ is nullptr");
|
||||
return;
|
||||
}
|
||||
std::string methodName = "HandleAbilityTransaction";
|
||||
AddLifecycleEvent(lifeCycleStateInfo.state, methodName);
|
||||
|
||||
abilityImpl_->SetCallingContext(lifeCycleStateInfo.caller.deviceId, lifeCycleStateInfo.caller.bundleName,
|
||||
lifeCycleStateInfo.caller.abilityName, lifeCycleStateInfo.caller.moduleName);
|
||||
@ -484,6 +496,25 @@ void FAAbilityThread::HandleAbilityTransaction(
|
||||
HILOG_DEBUG("end");
|
||||
}
|
||||
|
||||
void FAAbilityThread::AddLifecycleEvent(uint32_t state, std::string &methodName) const
|
||||
{
|
||||
if (!isUIAbility_) {
|
||||
return;
|
||||
}
|
||||
if (state == AAFwk::ABILITY_STATE_FOREGROUND_NEW) {
|
||||
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::FOREGROUND };
|
||||
std::string entry = std::to_string(AbilityRuntime::TimeUtil::SystemTimeMillisecond()) +
|
||||
"; AbilityThread::" + methodName + "; the foreground lifecycle.";
|
||||
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
|
||||
}
|
||||
if (state == AAFwk::ABILITY_STATE_BACKGROUND_NEW) {
|
||||
FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::BACKGROUND };
|
||||
std::string entry = std::to_string(AbilityRuntime::TimeUtil::SystemTimeMillisecond()) +
|
||||
"; AbilityThread::" + methodName + "; the background lifecycle.";
|
||||
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
|
||||
}
|
||||
}
|
||||
|
||||
void FAAbilityThread::HandleShareData(const int32_t &uniqueId)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
@ -710,10 +741,12 @@ void FAAbilityThread::ScheduleAbilityTransaction(
|
||||
const Want &want, const LifeCycleStateInfo &lifeCycleStateInfo, sptr<AppExecFwk::SessionInfo> sessionInfo)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("name:%{public}s,targeState:%{public}d,isNewWant:%{public}d",
|
||||
HILOG_INFO("Lifecycle: name:%{public}s,targeState:%{public}d,isNewWant:%{public}d",
|
||||
want.GetElement().GetAbilityName().c_str(),
|
||||
lifeCycleStateInfo.state,
|
||||
lifeCycleStateInfo.isNewWant);
|
||||
std::string methodName = "ScheduleAbilityTransaction";
|
||||
AddLifecycleEvent(lifeCycleStateInfo.state, methodName);
|
||||
|
||||
if (token_ == nullptr) {
|
||||
HILOG_ERROR("token_ is nullptr");
|
||||
@ -1148,6 +1181,10 @@ void FAAbilityThread::InitExtensionFlag(const std::shared_ptr<AppExecFwk::Abilit
|
||||
} else {
|
||||
isExtension_ = false;
|
||||
}
|
||||
if (abilityInfo->type == AppExecFwk::AbilityType::PAGE) {
|
||||
HILOG_DEBUG("isUIAbility_ is assigned true");
|
||||
isUIAbility_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
Uri FAAbilityThread::NormalizeUri(const Uri &uri)
|
||||
|
@ -14,11 +14,14 @@
|
||||
*/
|
||||
|
||||
#include "new_ability_impl.h"
|
||||
|
||||
#include "freeze_util.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "scene_board_judgement.h"
|
||||
|
||||
namespace OHOS {
|
||||
using AbilityRuntime::FreezeUtil;
|
||||
namespace AppExecFwk {
|
||||
using AbilityManagerClient = OHOS::AAFwk::AbilityManagerClient;
|
||||
/**
|
||||
@ -33,12 +36,8 @@ void NewAbilityImpl::HandleAbilityTransaction(const Want &want, const AAFwk::Lif
|
||||
sptr<AAFwk::SessionInfo> sessionInfo)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_INFO("NewAbilityImpl::HandleAbilityTransaction begin sourceState:%{public}d; targetState: %{public}d; "
|
||||
"isNewWant: %{public}d, sceneFlag: %{public}d",
|
||||
lifecycleState_,
|
||||
targetState.state,
|
||||
targetState.isNewWant,
|
||||
targetState.sceneFlag);
|
||||
HILOG_INFO("Lifecycle: srcState:%{public}d; targetState: %{public}d; isNewWant: %{public}d, sceneFlag: %{public}d",
|
||||
lifecycleState_, targetState.state, targetState.isNewWant, targetState.sceneFlag);
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
if (ability_ != nullptr) {
|
||||
ability_->sceneFlag_ = targetState.sceneFlag;
|
||||
@ -80,8 +79,12 @@ void NewAbilityImpl::HandleShareData(const int32_t &uniqueId)
|
||||
|
||||
void NewAbilityImpl::AbilityTransactionCallback(const AbilityLifeCycleState &state)
|
||||
{
|
||||
HILOG_INFO("Handle ability transaction done, notify ability manager service.");
|
||||
AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_, state, GetRestoreData());
|
||||
HILOG_INFO("Lifecycle: notify ability manager service.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,6 +90,7 @@ ohos_shared_library("appkit_native") {
|
||||
"${ability_runtime_services_path}/common/include",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native/recovery",
|
||||
"${ability_runtime_path}/utils/global/time/include",
|
||||
"${ability_runtime_services_path}/abilitymgr/include",
|
||||
"${ability_runtime_napi_path}/inner/napi_common",
|
||||
]
|
||||
@ -137,6 +138,7 @@ ohos_shared_library("appkit_native") {
|
||||
"${ability_runtime_native_path}/appkit:app_context",
|
||||
"${ability_runtime_native_path}/appkit:app_context_utils",
|
||||
"${ability_runtime_path}/js_environment/frameworks/js_environment:js_environment",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "ability_manager_client.h"
|
||||
#include "ability_state.h"
|
||||
#include "app_recovery.h"
|
||||
#include "freeze_util.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hisysevent.h"
|
||||
#include "mix_stack_dumper.h"
|
||||
@ -26,6 +27,7 @@
|
||||
#include "xcollie/watchdog.h"
|
||||
|
||||
namespace OHOS {
|
||||
using AbilityRuntime::FreezeUtil;
|
||||
namespace AppExecFwk {
|
||||
namespace {
|
||||
constexpr char EVENT_UID[] = "UID";
|
||||
@ -136,6 +138,10 @@ int AppfreezeInner::AcquireStack(const FaultData& faultInfo, bool onlyMainThread
|
||||
|
||||
HILOG_DEBUG("Start dump MainHandler message.");
|
||||
std::string msgContent = faultInfo.errorObject.message + "\n";
|
||||
if (faultInfo.state != 0) {
|
||||
FreezeUtil::LifecycleFlow flow = { faultInfo.token, static_cast<FreezeUtil::TimeoutState>(faultInfo.state) };
|
||||
msgContent = msgContent + "client:\n" + FreezeUtil::GetInstance().GetLifecycleEvent(flow) + "\n";
|
||||
}
|
||||
|
||||
auto mainHandler = appMainHandler_.lock();
|
||||
if (mainHandler == nullptr) {
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "extension_plugin_info.h"
|
||||
#include "extract_resource_manager.h"
|
||||
#include "file_path_utils.h"
|
||||
#include "freeze_util.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
#include "locale_config.h"
|
||||
@ -62,6 +63,7 @@
|
||||
#include "sys_mgr_client.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "task_handler_client.h"
|
||||
#include "time_util.h"
|
||||
#include "uncaught_exception_callback.h"
|
||||
#include "hisysevent.h"
|
||||
#include "js_runtime_utils.h"
|
||||
@ -83,6 +85,7 @@
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
namespace OHOS {
|
||||
using AbilityRuntime::FreezeUtil;
|
||||
namespace AppExecFwk {
|
||||
using namespace OHOS::AbilityBase::Constants;
|
||||
std::weak_ptr<OHOSApplication> MainThread::applicationForDump_;
|
||||
@ -372,6 +375,7 @@ bool MainThread::ConnectToAppMgr()
|
||||
HILOG_ERROR("failed to iface_cast object to appMgr_");
|
||||
return false;
|
||||
}
|
||||
HILOG_INFO("LoadLifecycle: attach to appMGR.");
|
||||
appMgr_->AttachApplication(this);
|
||||
HILOG_DEBUG("MainThread::connectToAppMgr end");
|
||||
return true;
|
||||
@ -613,7 +617,7 @@ void MainThread::ScheduleLowMemory()
|
||||
void MainThread::ScheduleLaunchApplication(const AppLaunchData &data, const Configuration &config)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("MainThread schedule launch application start.");
|
||||
HILOG_INFO("LoadLifecycle: schedule launch application start.");
|
||||
wptr<MainThread> weak = this;
|
||||
auto task = [weak, data, config]() {
|
||||
auto appThread = weak.promote();
|
||||
@ -673,7 +677,7 @@ void MainThread::ScheduleLaunchAbility(const AbilityInfo &info, const sptr<IRemo
|
||||
const std::shared_ptr<AAFwk::Want> &want)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("schedule launch ability %{public}s, type is %{public}d.", info.name.c_str(), info.type);
|
||||
HILOG_INFO("LoadLifecycle: schedule launch ability %{public}s, type is %{public}d.", info.name.c_str(), info.type);
|
||||
|
||||
AAFwk::Want newWant(*want);
|
||||
newWant.CloseAllFd();
|
||||
@ -681,6 +685,11 @@ void MainThread::ScheduleLaunchAbility(const AbilityInfo &info, const sptr<IRemo
|
||||
std::shared_ptr<AbilityLocalRecord> abilityRecord = std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
abilityRecord->SetWant(want);
|
||||
|
||||
FreezeUtil::LifecycleFlow flow = { token, FreezeUtil::TimeoutState::LOAD };
|
||||
std::string entry = std::to_string(AbilityRuntime::TimeUtil::SystemTimeMillisecond()) +
|
||||
"; MainThread::ScheduleLaunchAbility; the load lifecycle.";
|
||||
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
|
||||
|
||||
wptr<MainThread> weak = this;
|
||||
auto task = [weak, abilityRecord]() {
|
||||
auto appThread = weak.promote();
|
||||
@ -1158,7 +1167,7 @@ bool GetBundleForLaunchApplication(sptr<IBundleMgr> bundleMgr, const std::string
|
||||
void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, const Configuration &config)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("MainThread handle launch application start.");
|
||||
HILOG_INFO("LoadLifecycle: handle launch application start.");
|
||||
if (!CheckForHandleLaunchApplication(appLaunchData)) {
|
||||
HILOG_ERROR("MainThread::handleLaunchApplication CheckForHandleLaunchApplication failed");
|
||||
return;
|
||||
@ -1717,6 +1726,7 @@ bool MainThread::PrepareAbilityDelegator(const std::shared_ptr<UserTestRecord> &
|
||||
*/
|
||||
void MainThread::HandleLaunchAbility(const std::shared_ptr<AbilityLocalRecord> &abilityRecord)
|
||||
{
|
||||
HILOG_INFO("LoadLifecycle: called.");
|
||||
CHECK_POINTER_LOG(abilityRecord, "MainThread::HandleLaunchAbility parameter(abilityRecord) is null");
|
||||
std::string connector = "##";
|
||||
std::string traceName = __PRETTY_FUNCTION__ + connector;
|
||||
@ -1726,12 +1736,15 @@ void MainThread::HandleLaunchAbility(const std::shared_ptr<AbilityLocalRecord> &
|
||||
HILOG_ERROR("Want is nullptr, cant not get abilityName.");
|
||||
}
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, traceName);
|
||||
HILOG_DEBUG("HandleLaunchAbility called start.");
|
||||
CHECK_POINTER_LOG(applicationImpl_, "MainThread::HandleLaunchAbility applicationImpl_ is null");
|
||||
CHECK_POINTER_LOG(abilityRecordMgr_, "MainThread::HandleLaunchAbility abilityRecordMgr_ is null");
|
||||
|
||||
auto abilityToken = abilityRecord->GetToken();
|
||||
CHECK_POINTER_LOG(abilityToken, "MainThread::HandleLaunchAbility failed. abilityRecord->GetToken failed");
|
||||
FreezeUtil::LifecycleFlow flow = { abilityToken, FreezeUtil::TimeoutState::LOAD };
|
||||
std::string entry = std::to_string(AbilityRuntime::TimeUtil::SystemTimeMillisecond()) +
|
||||
"; MainThread::HandleLaunchAbility; the load lifecycle.";
|
||||
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
|
||||
|
||||
abilityRecordMgr_->SetToken(abilityToken);
|
||||
abilityRecordMgr_->AddAbilityRecord(abilityToken, abilityRecord);
|
||||
@ -2107,7 +2120,7 @@ void MainThread::HandleDumpHeap(bool isPrivate)
|
||||
void MainThread::Start()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("MainThread start come.");
|
||||
HILOG_INFO("LoadLifecycle: MainThread start come.");
|
||||
std::shared_ptr<EventRunner> runner = EventRunner::GetMainEventRunner();
|
||||
if (runner == nullptr) {
|
||||
HILOG_ERROR("MainThread::main failed, runner is nullptr");
|
||||
|
@ -108,7 +108,7 @@ ohos_shared_library("app_manager") {
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
deps = []
|
||||
deps = [ "${ability_runtime_path}/utils/global/freeze:freeze_util" ]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:configuration",
|
||||
|
@ -28,8 +28,10 @@
|
||||
#include "cpp/mutex.h"
|
||||
#include "cpp/condition_variable.h"
|
||||
#include "fault_data.h"
|
||||
#include "freeze_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
using AbilityRuntime::FreezeUtil;
|
||||
namespace AppExecFwk {
|
||||
class AppfreezeManager : public std::enable_shared_from_this<AppfreezeManager> {
|
||||
public:
|
||||
@ -45,6 +47,14 @@ public:
|
||||
CRITICAL_TIMEOUT = 1,
|
||||
};
|
||||
|
||||
struct ParamInfo {
|
||||
int typeId = TypeAttribute::NORMAL_TIMEOUT;
|
||||
int32_t pid = 0;
|
||||
std::string eventName;
|
||||
std::string bundleName;
|
||||
std::string msg;
|
||||
};
|
||||
|
||||
AppfreezeManager();
|
||||
~AppfreezeManager();
|
||||
|
||||
@ -52,8 +62,7 @@ public:
|
||||
static void DestroyInstance();
|
||||
int AppfreezeHandle(const FaultData& faultData, const AppfreezeManager::AppInfo& appInfo);
|
||||
int AppfreezeHandleWithStack(const FaultData& faultData, const AppfreezeManager::AppInfo& appInfo);
|
||||
int LifecycleTimeoutHandle(int typeId, int32_t pid, const std::string& eventName,
|
||||
const std::string& bundleName, const std::string& msg);
|
||||
int LifecycleTimeoutHandle(const ParamInfo& info, std::unique_ptr<FreezeUtil::LifecycleFlow> flow = nullptr);
|
||||
bool IsHandleAppfreeze(const std::string& bundleName);
|
||||
|
||||
private:
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "ierror_observer.h"
|
||||
#include "iremote_object.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -61,6 +62,8 @@ struct FaultData : public Parcelable {
|
||||
bool waitSaveState = false;
|
||||
bool notifyApp = false;
|
||||
bool forceExit = false;
|
||||
uint32_t state = 0;
|
||||
sptr<IRemoteObject> token = nullptr;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -79,6 +82,8 @@ struct AppFaultDataBySA : public Parcelable {
|
||||
bool waitSaveState = false;
|
||||
bool notifyApp = false;
|
||||
bool forceExit = false;
|
||||
uint32_t state = 0;
|
||||
sptr<IRemoteObject> token = nullptr;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -130,29 +130,32 @@ int AppfreezeManager::AppfreezeHandleWithStack(const FaultData& faultData, const
|
||||
return AppfreezeHandle(faultNotifyData, appInfo);
|
||||
}
|
||||
|
||||
int AppfreezeManager::LifecycleTimeoutHandle(int typeId, int32_t pid,
|
||||
const std::string& eventName, const std::string& bundleName, const std::string& msg)
|
||||
int AppfreezeManager::LifecycleTimeoutHandle(const ParamInfo& info, std::unique_ptr<FreezeUtil::LifecycleFlow> flow)
|
||||
{
|
||||
if (typeId != AppfreezeManager::TypeAttribute::CRITICAL_TIMEOUT) {
|
||||
if (info.typeId != AppfreezeManager::TypeAttribute::CRITICAL_TIMEOUT) {
|
||||
return -1;
|
||||
}
|
||||
if (!IsHandleAppfreeze(bundleName)) {
|
||||
if (!IsHandleAppfreeze(info.bundleName)) {
|
||||
return -1;
|
||||
}
|
||||
if (eventName != AppFreezeType::LIFECYCLE_TIMEOUT &&
|
||||
eventName != AppFreezeType::LIFECYCLE_HALF_TIMEOUT) {
|
||||
if (info.eventName != AppFreezeType::LIFECYCLE_TIMEOUT &&
|
||||
info.eventName != AppFreezeType::LIFECYCLE_HALF_TIMEOUT) {
|
||||
return -1;
|
||||
}
|
||||
HILOG_DEBUG("LifecycleTimeoutHandle called %{public}s, name_ %{public}s",
|
||||
bundleName.c_str(), name_.c_str());
|
||||
info.bundleName.c_str(), name_.c_str());
|
||||
AppFaultDataBySA faultDataSA;
|
||||
faultDataSA.errorObject.name = eventName;
|
||||
faultDataSA.errorObject.message = msg;
|
||||
faultDataSA.errorObject.name = info.eventName;
|
||||
faultDataSA.errorObject.message = info.msg;
|
||||
faultDataSA.faultType = FaultDataType::APP_FREEZE;
|
||||
faultDataSA.timeoutMarkers = "notifyFault" +
|
||||
std::to_string(pid) +
|
||||
std::to_string(info.pid) +
|
||||
"-" + std::to_string(GetMilliseconds());
|
||||
faultDataSA.pid = pid;
|
||||
faultDataSA.pid = info.pid;
|
||||
if (flow != nullptr && flow->state != AbilityRuntime::FreezeUtil::TimeoutState::UNKNOWN) {
|
||||
faultDataSA.token = flow->token;
|
||||
faultDataSA.state = static_cast<uint32_t>(flow->state);
|
||||
}
|
||||
DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance()->NotifyAppFaultBySA(faultDataSA);
|
||||
return 0;
|
||||
}
|
||||
|
@ -52,6 +52,10 @@ bool FaultData::ReadFromParcel(Parcel &parcel)
|
||||
waitSaveState = parcel.ReadBool();
|
||||
notifyApp = parcel.ReadBool();
|
||||
forceExit = parcel.ReadBool();
|
||||
state = parcel.ReadUint32();
|
||||
if (parcel.ReadBool()) {
|
||||
token = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -98,6 +102,20 @@ bool FaultData::Marshalling(Parcel &parcel) const
|
||||
if (!parcel.WriteBool(forceExit)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteUint32(state)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (token == nullptr) {
|
||||
if (!parcel.WriteBool(false)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!parcel.WriteBool(true) || !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(token)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -137,6 +155,10 @@ bool AppFaultDataBySA::ReadFromParcel(Parcel &parcel)
|
||||
waitSaveState = parcel.ReadBool();
|
||||
notifyApp = parcel.ReadBool();
|
||||
forceExit = parcel.ReadBool();
|
||||
state = parcel.ReadUint32();
|
||||
if (parcel.ReadBool()) {
|
||||
token = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -187,6 +209,20 @@ bool AppFaultDataBySA::Marshalling(Parcel &parcel) const
|
||||
if (!parcel.WriteBool(forceExit)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteUint32(state)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (token == nullptr) {
|
||||
if (!parcel.WriteBool(false)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!parcel.WriteBool(true) || !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(token)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "ability.h"
|
||||
#include "ability_delegator_infos.h"
|
||||
#include "freeze_util.h"
|
||||
|
||||
class NativeReference;
|
||||
class NativeValue;
|
||||
@ -105,6 +106,8 @@ private:
|
||||
std::unique_ptr<NativeReference> CreateAppWindowStage();
|
||||
std::shared_ptr<AppExecFwk::ADelegatorAbilityProperty> CreateADelegatorAbilityProperty();
|
||||
sptr<IRemoteObject> SetNewRuleFlagToCallee(napi_env env, napi_value remoteJsObj);
|
||||
void AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const;
|
||||
void AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const;
|
||||
|
||||
JsRuntime &jsRuntime_;
|
||||
std::shared_ptr<NativeReference> shellContextRef_;
|
||||
|
@ -551,12 +551,15 @@ private:
|
||||
std::shared_ptr<AbilityContext> BuildAbilityContext(const std::shared_ptr<AppExecFwk::AbilityInfo> &abilityInfo,
|
||||
const std::shared_ptr<AppExecFwk::OHOSApplication> &application, const sptr<IRemoteObject> &token,
|
||||
const std::shared_ptr<Context> &stageContext);
|
||||
|
||||
void AddLifecycleEvent(uint32_t state, std::string &methodName) const;
|
||||
|
||||
std::shared_ptr<AppExecFwk::AbilityImpl> abilityImpl_;
|
||||
std::shared_ptr<AppExecFwk::Ability> currentAbility_;
|
||||
std::shared_ptr<ExtensionImpl> extensionImpl_;
|
||||
std::shared_ptr<Extension> currentExtension_;
|
||||
bool isExtension_ = false;
|
||||
bool isUIAbility_ = false;
|
||||
bool isPrepareTerminate_ = false;
|
||||
std::atomic_bool isPrepareTerminateAbilityDone_ = false;
|
||||
std::mutex mutex_;
|
||||
|
@ -133,6 +133,7 @@ ohos_shared_library("abilityms") {
|
||||
"${ability_runtime_innerkits_path}/session_handler:session_handler",
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_native_path}/ability/native:abilitykit_native",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
|
@ -928,6 +928,7 @@ private:
|
||||
{
|
||||
callerAccessTokenId_ = callerAccessTokenId;
|
||||
}
|
||||
bool IsDebug() const;
|
||||
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
std::shared_ptr<Want> GetWantFromMission() const;
|
||||
|
@ -517,6 +517,7 @@ private:
|
||||
|
||||
void NotifyCollaboratorMissionCreated(const AbilityRequest &abilityRequest,
|
||||
const std::shared_ptr<Mission> &targetMission, InnerMissionInfo &info);
|
||||
bool GetContentAndTypeId(uint32_t msgId, std::string &msgContent, int &typeId) const;
|
||||
|
||||
int userId_;
|
||||
mutable ffrt::mutex managerLock_;
|
||||
|
@ -324,6 +324,7 @@ private:
|
||||
void SetRevicerInfo(const AbilityRequest &abilityRequest, std::shared_ptr<AbilityRecord> &abilityRecord) const;
|
||||
|
||||
bool CheckPrepareTerminateEnable(const std::shared_ptr<AbilityRecord> &abilityRecord);
|
||||
bool GetContentAndTypeId(uint32_t msgId, std::string &msgContent, int &typeId) const;
|
||||
|
||||
mutable ffrt::mutex sessionLock_;
|
||||
std::unordered_map<int32_t, std::shared_ptr<AbilityRecord>> sessionAbilityMap_;
|
||||
|
@ -1919,13 +1919,18 @@ void AbilityConnectManager::PrintTimeOutLog(const std::shared_ptr<AbilityRecord>
|
||||
default:
|
||||
return;
|
||||
}
|
||||
std::string eventName = AppExecFwk::AppFreezeType::LIFECYCLE_TIMEOUT;
|
||||
|
||||
HILOG_WARN("LIFECYCLE_TIMEOUT: uid: %{public}d, pid: %{public}d, bundleName: %{public}s, abilityName: %{public}s,"
|
||||
"msg: %{public}s", processInfo.uid_, processInfo.pid_, ability->GetAbilityInfo().bundleName.c_str(),
|
||||
ability->GetAbilityInfo().name.c_str(), msgContent.c_str());
|
||||
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(
|
||||
typeId, processInfo.pid_, eventName, ability->GetAbilityInfo().bundleName, msgContent);
|
||||
AppExecFwk::AppfreezeManager::ParamInfo info = {
|
||||
.typeId = typeId,
|
||||
.pid = processInfo.pid_,
|
||||
.eventName = AppExecFwk::AppFreezeType::LIFECYCLE_TIMEOUT,
|
||||
.bundleName = ability->GetAbilityInfo().bundleName,
|
||||
.msg = msgContent
|
||||
};
|
||||
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info);
|
||||
}
|
||||
|
||||
void AbilityConnectManager::MoveToTerminatingMap(const std::shared_ptr<AbilityRecord>& abilityRecord)
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "distributed_client.h"
|
||||
#include "dlp_utils.h"
|
||||
#include "errors.h"
|
||||
#include "freeze_util.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hisysevent.h"
|
||||
#include "hitrace_meter.h"
|
||||
@ -90,6 +91,7 @@ using OHOS::AppExecFwk::ElementName;
|
||||
using OHOS::Security::AccessToken::AccessTokenKit;
|
||||
|
||||
namespace OHOS {
|
||||
using AbilityRuntime::FreezeUtil;
|
||||
namespace AAFwk {
|
||||
namespace {
|
||||
#define CHECK_CALLER_IS_SYSTEM_APP \
|
||||
@ -3808,7 +3810,7 @@ int AbilityManagerService::AttachAbilityThread(
|
||||
const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_INFO("Attach ability thread.");
|
||||
HILOG_INFO("LoadLifecycle: Attach ability thread.");
|
||||
CHECK_POINTER_AND_RETURN(scheduler, ERR_INVALID_VALUE);
|
||||
if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && !VerificationAllToken(token)) {
|
||||
return ERR_INVALID_VALUE;
|
||||
@ -3824,39 +3826,39 @@ int AbilityManagerService::AttachAbilityThread(
|
||||
auto type = abilityInfo.type;
|
||||
// force timeout ability for test
|
||||
if (IsNeedTimeoutForTest(abilityInfo.name, AbilityRecord::ConvertAbilityState(AbilityState::INITIAL))) {
|
||||
HILOG_WARN("force timeout ability for test, state:INITIAL, ability: %{public}s",
|
||||
abilityInfo.name.c_str());
|
||||
HILOG_WARN("force timeout ability for test, state:INITIAL, ability: %{public}s", abilityInfo.name.c_str());
|
||||
return ERR_OK;
|
||||
}
|
||||
int returnCode = -1;
|
||||
if (type == AppExecFwk::AbilityType::SERVICE || type == AppExecFwk::AbilityType::EXTENSION) {
|
||||
auto connectManager = GetConnectManagerByUserId(userId);
|
||||
if (!connectManager) {
|
||||
HILOG_ERROR("connectManager is nullptr. userId=%{public}d", userId);
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
returnCode = connectManager->AttachAbilityThreadLocked(scheduler, token);
|
||||
return connectManager->AttachAbilityThreadLocked(scheduler, token);
|
||||
} else if (type == AppExecFwk::AbilityType::DATA) {
|
||||
auto dataAbilityManager = GetDataAbilityManagerByUserId(userId);
|
||||
if (!dataAbilityManager) {
|
||||
HILOG_ERROR("dataAbilityManager is Null. userId=%{public}d", userId);
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
returnCode = dataAbilityManager->AttachAbilityThread(scheduler, token);
|
||||
return dataAbilityManager->AttachAbilityThread(scheduler, token);
|
||||
} else {
|
||||
FreezeUtil::LifecycleFlow flow = { token, FreezeUtil::TimeoutState::LOAD };
|
||||
auto entry = std::to_string(AbilityUtil::SystemTimeMillis()) + "; AbilityManagerService::AttachAbilityThread;" +
|
||||
" the end of load lifecycle.";
|
||||
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
|
||||
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
|
||||
returnCode = uiAbilityLifecycleManager_->AttachAbilityThread(scheduler, token);
|
||||
} else {
|
||||
int32_t ownerMissionUserId = abilityRecord->GetOwnerMissionUserId();
|
||||
auto missionListManager = GetListManagerByUserId(ownerMissionUserId);
|
||||
if (!missionListManager) {
|
||||
HILOG_ERROR("missionListManager is Null. userId=%{public}d", ownerMissionUserId);
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
returnCode = missionListManager->AttachAbilityThread(scheduler, token);
|
||||
return uiAbilityLifecycleManager_->AttachAbilityThread(scheduler, token);
|
||||
}
|
||||
int32_t ownerMissionUserId = abilityRecord->GetOwnerMissionUserId();
|
||||
auto missionListManager = GetListManagerByUserId(ownerMissionUserId);
|
||||
if (!missionListManager) {
|
||||
HILOG_ERROR("missionListManager is Null. userId=%{public}d", ownerMissionUserId);
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
return missionListManager->AttachAbilityThread(scheduler, token);
|
||||
}
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
void AbilityManagerService::DumpFuncInit()
|
||||
@ -4341,7 +4343,7 @@ void AbilityManagerService::DumpSysState(
|
||||
int AbilityManagerService::AbilityTransitionDone(const sptr<IRemoteObject> &token, int state, const PacMap &saveData)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_INFO("Ability transition done come, state:%{public}d.", state);
|
||||
HILOG_INFO("Lifecycle: state:%{public}d.", state);
|
||||
if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && !VerificationAllToken(token)) {
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
@ -4352,7 +4354,8 @@ int AbilityManagerService::AbilityTransitionDone(const sptr<IRemoteObject> &toke
|
||||
}
|
||||
|
||||
auto abilityInfo = abilityRecord->GetAbilityInfo();
|
||||
HILOG_DEBUG("Ability transition done come, state:%{public}d, name:%{public}s", state, abilityInfo.name.c_str());
|
||||
HILOG_INFO("Lifecycle: bundle: %{public}s, ability: %{public}s.", abilityInfo.bundleName.c_str(),
|
||||
abilityInfo.name.c_str());
|
||||
auto type = abilityInfo.type;
|
||||
auto userId = abilityRecord->GetApplicationInfo().uid / BASE_USER_RANGE;
|
||||
// force timeout ability for test
|
||||
@ -4382,6 +4385,20 @@ int AbilityManagerService::AbilityTransitionDone(const sptr<IRemoteObject> &toke
|
||||
}
|
||||
return dataAbilityManager->AbilityTransitionDone(token, state);
|
||||
}
|
||||
|
||||
if (targetState == AbilityState::BACKGROUND) {
|
||||
FreezeUtil::LifecycleFlow flow = { token, FreezeUtil::TimeoutState::BACKGROUND };
|
||||
auto entry = std::to_string(AbilityUtil::SystemTimeMillis()) +
|
||||
"; AbilityManagerService::AbilityTransitionDone; the end of background lifecycle.";
|
||||
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
|
||||
} else if (targetState != AbilityState::INITIAL) {
|
||||
FreezeUtil::LifecycleFlow flow = { token, FreezeUtil::TimeoutState::FOREGROUND };
|
||||
auto entry = std::to_string(AbilityUtil::SystemTimeMillis()) +
|
||||
"; AbilityManagerService::AbilityTransitionDone; the end of foreground lifecycle.";
|
||||
entry += " the end of foreground lifecycle.";
|
||||
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
|
||||
}
|
||||
|
||||
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
|
||||
return uiAbilityLifecycleManager_->AbilityTransactionDone(token, state, saveData);
|
||||
} else {
|
||||
|
@ -24,11 +24,13 @@
|
||||
#include "ability_manager_service.h"
|
||||
#include "ability_scheduler_stub.h"
|
||||
#include "ability_util.h"
|
||||
#include "appfreeze_manager.h"
|
||||
#include "array_wrapper.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "bundle_mgr_client.h"
|
||||
#include "configuration_convertor.h"
|
||||
#include "connection_state_manager.h"
|
||||
#include "freeze_util.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "image_source.h"
|
||||
#include "in_process_call_wrapper.h"
|
||||
@ -52,6 +54,7 @@
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
using AbilityRuntime::FreezeUtil;
|
||||
namespace AAFwk {
|
||||
using namespace OHOS::Security;
|
||||
using namespace OHOS::AAFwk::PermissionConstants;
|
||||
@ -149,6 +152,14 @@ const std::map<AbilityLifeCycleState, AbilityState> AbilityRecord::convertStateM
|
||||
std::map<AbilityLifeCycleState, AbilityState>::value_type(ABILITY_STATE_BACKGROUND_FAILED, BACKGROUND_FAILED),
|
||||
};
|
||||
|
||||
auto g_addLifecycleEventTask = [](sptr<Token> token, FreezeUtil::TimeoutState state, std::string &methodName) {
|
||||
CHECK_POINTER_LOG(token, "token is nullptr");
|
||||
FreezeUtil::LifecycleFlow flow = { token->AsObject(), state };
|
||||
auto entry = std::to_string(AbilityUtil::SystemTimeMillis()) + "; AbilityRecord::" + methodName +
|
||||
"; the " + methodName + " lifecycle starts.";
|
||||
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
|
||||
};
|
||||
|
||||
Token::Token(std::weak_ptr<AbilityRecord> abilityRecord) : abilityRecord_(abilityRecord)
|
||||
{}
|
||||
|
||||
@ -272,21 +283,25 @@ int32_t AbilityRecord::GetPid()
|
||||
int AbilityRecord::LoadAbility()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("name:%{public}s.", abilityInfo_.name.c_str());
|
||||
int coldStartTimeout =
|
||||
AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * COLDSTART_TIMEOUT_MULTIPLE;
|
||||
int loadTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * LOAD_TIMEOUT_MULTIPLE;
|
||||
if (applicationInfo_.asanEnabled) {
|
||||
loadTimeout =
|
||||
AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * LOAD_TIMEOUT_ASANENABLED;
|
||||
SendEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, loadTimeout / HALF_TIMEOUT);
|
||||
} else if (abilityInfo_.type != AppExecFwk::AbilityType::DATA) {
|
||||
auto delayTime = want_.GetBoolParam("coldStart", false) ? coldStartTimeout : loadTimeout;
|
||||
SendEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, delayTime / HALF_TIMEOUT);
|
||||
}
|
||||
|
||||
HILOG_INFO("LoadLifecycle: abilityName:%{public}s.", abilityInfo_.name.c_str());
|
||||
startTime_ = AbilityUtil::SystemTimeMillis();
|
||||
CHECK_POINTER_AND_RETURN(token_, ERR_INVALID_VALUE);
|
||||
// only for UIAbility
|
||||
if (!IsDebug() && abilityInfo_.type != AppExecFwk::AbilityType::DATA) {
|
||||
int loadTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * LOAD_TIMEOUT_MULTIPLE;
|
||||
if (applicationInfo_.asanEnabled) {
|
||||
loadTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * LOAD_TIMEOUT_ASANENABLED;
|
||||
SendEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, loadTimeout / HALF_TIMEOUT);
|
||||
} else {
|
||||
int coldStartTimeout =
|
||||
AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * COLDSTART_TIMEOUT_MULTIPLE;
|
||||
auto delayTime = want_.GetBoolParam("coldStart", false) ? coldStartTimeout : loadTimeout;
|
||||
SendEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, delayTime / HALF_TIMEOUT);
|
||||
}
|
||||
std::string methodName = "LoadAbility";
|
||||
g_addLifecycleEventTask(token_, FreezeUtil::TimeoutState::LOAD, methodName);
|
||||
}
|
||||
|
||||
std::string appName = applicationInfo_.name;
|
||||
if (appName.empty()) {
|
||||
HILOG_ERROR("app name is empty");
|
||||
@ -352,16 +367,21 @@ bool AbilityRecord::CanRestartResident()
|
||||
return true;
|
||||
}
|
||||
|
||||
// only for UIAbility
|
||||
void AbilityRecord::ForegroundAbility(uint32_t sceneFlag)
|
||||
{
|
||||
isWindowStarted_ = true;
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_INFO("name:%{public}s.", abilityInfo_.name.c_str());
|
||||
HILOG_INFO("ForegroundLifecycle: name:%{public}s.", abilityInfo_.name.c_str());
|
||||
CHECK_POINTER(lifecycleDeal_);
|
||||
|
||||
int foregroundTimeout =
|
||||
AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * FOREGROUND_TIMEOUT_MULTIPLE;
|
||||
SendEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, foregroundTimeout / HALF_TIMEOUT);
|
||||
if (!IsDebug()) {
|
||||
int foregroundTimeout =
|
||||
AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * FOREGROUND_TIMEOUT_MULTIPLE;
|
||||
SendEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, foregroundTimeout / HALF_TIMEOUT);
|
||||
std::string methodName = "ForegroundAbility";
|
||||
g_addLifecycleEventTask(token_, FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
}
|
||||
|
||||
// schedule active after updating AbilityState and sending timeout message to avoid ability async callback
|
||||
// earlier than above actions.
|
||||
@ -771,10 +791,7 @@ void AbilityRecord::StartingWindowTask(bool isRecent, bool isCold, const Ability
|
||||
|
||||
void AbilityRecord::PostCancelStartingWindowHotTask()
|
||||
{
|
||||
if (want_.GetBoolParam(DEBUG_APP, false) ||
|
||||
want_.GetBoolParam(NATIVE_DEBUG, false) ||
|
||||
!want_.GetStringParam(PERF_CMD).empty() ||
|
||||
isAttachDebug_) {
|
||||
if (IsDebug()) {
|
||||
HILOG_INFO("PostCancelStartingWindowHotTask was called, debug mode, just return.");
|
||||
return;
|
||||
}
|
||||
@ -802,10 +819,7 @@ void AbilityRecord::PostCancelStartingWindowHotTask()
|
||||
|
||||
void AbilityRecord::PostCancelStartingWindowColdTask()
|
||||
{
|
||||
if (want_.GetBoolParam(DEBUG_APP, false) ||
|
||||
want_.GetBoolParam(NATIVE_DEBUG, false) ||
|
||||
!want_.GetStringParam(PERF_CMD).empty() ||
|
||||
isAttachDebug_) {
|
||||
if (IsDebug()) {
|
||||
HILOG_INFO("PostCancelStartingWindowColdTask was called, debug mode, just return.");
|
||||
return;
|
||||
}
|
||||
@ -1101,23 +1115,27 @@ bool AbilityRecord::IsCompleteFirstFrameDrawing() const
|
||||
void AbilityRecord::BackgroundAbility(const Closure &task)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_INFO("ability:%{public}s.", abilityInfo_.name.c_str());
|
||||
HILOG_INFO("BackgroundLifecycle: begin, bundle: %{public}s, ability: %{public}s.", abilityInfo_.bundleName.c_str(),
|
||||
abilityInfo_.name.c_str());
|
||||
if (lifecycleDeal_ == nullptr) {
|
||||
HILOG_ERROR("Move the ability to background fail, lifecycleDeal_ is null.");
|
||||
return;
|
||||
}
|
||||
auto handler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
|
||||
if (handler && task) {
|
||||
if (!want_.GetBoolParam(DEBUG_APP, false) &&
|
||||
!want_.GetBoolParam(NATIVE_DEBUG, false) &&
|
||||
want_.GetStringParam(PERF_CMD).empty() &&
|
||||
!isAttachDebug_) {
|
||||
|
||||
if (!IsDebug()) {
|
||||
auto handler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
|
||||
if (handler && task) {
|
||||
int backgroundTimeout =
|
||||
AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * BACKGROUND_TIMEOUT_MULTIPLE;
|
||||
handler->SubmitTask(task, "background_" + std::to_string(recordId_), backgroundTimeout, false);
|
||||
} else {
|
||||
HILOG_INFO("Is debug mode, no need to handle time out.");
|
||||
|
||||
if (abilityInfo_.type == AppExecFwk::AbilityType::PAGE) {
|
||||
std::string methodName = "BackgroundAbility";
|
||||
g_addLifecycleEventTask(token_, FreezeUtil::TimeoutState::BACKGROUND, methodName);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
HILOG_INFO("Is debug mode, no need to handle time out.");
|
||||
}
|
||||
|
||||
if (!IsTerminating() || IsRestarting()) {
|
||||
@ -1382,8 +1400,10 @@ void AbilityRecord::Activate()
|
||||
HILOG_INFO("Activate.");
|
||||
CHECK_POINTER(lifecycleDeal_);
|
||||
|
||||
int activeTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * ACTIVE_TIMEOUT_MULTIPLE;
|
||||
SendEvent(AbilityManagerService::ACTIVE_TIMEOUT_MSG, activeTimeout);
|
||||
if (!IsDebug()) {
|
||||
int activeTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * ACTIVE_TIMEOUT_MULTIPLE;
|
||||
SendEvent(AbilityManagerService::ACTIVE_TIMEOUT_MSG, activeTimeout);
|
||||
}
|
||||
|
||||
// schedule active after updating AbilityState and sending timeout message to avoid ability async callback
|
||||
// earlier than above actions.
|
||||
@ -1406,9 +1426,11 @@ void AbilityRecord::Inactivate()
|
||||
HILOG_INFO("ability:%{public}s.", abilityInfo_.name.c_str());
|
||||
CHECK_POINTER(lifecycleDeal_);
|
||||
|
||||
int inactiveTimeout =
|
||||
AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * INACTIVE_TIMEOUT_MULTIPLE;
|
||||
SendEvent(AbilityManagerService::INACTIVE_TIMEOUT_MSG, inactiveTimeout);
|
||||
if (!IsDebug()) {
|
||||
int inactiveTimeout =
|
||||
AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * INACTIVE_TIMEOUT_MULTIPLE;
|
||||
SendEvent(AbilityManagerService::INACTIVE_TIMEOUT_MSG, inactiveTimeout);
|
||||
}
|
||||
|
||||
// schedule inactive after updating AbilityState and sending timeout message to avoid ability async callback
|
||||
// earlier than above actions.
|
||||
@ -1421,22 +1443,21 @@ void AbilityRecord::Terminate(const Closure &task)
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_INFO("ability:%{public}s.", abilityInfo_.name.c_str());
|
||||
CHECK_POINTER(lifecycleDeal_);
|
||||
auto handler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
|
||||
if (handler && task) {
|
||||
if (!want_.GetBoolParam(DEBUG_APP, false) &&
|
||||
!want_.GetBoolParam(NATIVE_DEBUG, false) &&
|
||||
want_.GetStringParam(PERF_CMD).empty() &&
|
||||
!isAttachDebug_) {
|
||||
int terminateTimeout =
|
||||
AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * TERMINATE_TIMEOUT_MULTIPLE;
|
||||
handler->SubmitTask(task, "terminate_" + std::to_string(recordId_), terminateTimeout);
|
||||
} else if (applicationInfo_.asanEnabled) {
|
||||
int terminateTimeout =
|
||||
AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * TERMINATE_TIMEOUT_ASANENABLED;
|
||||
handler->SubmitTask(task, "terminate_" + std::to_string(recordId_), terminateTimeout);
|
||||
} else {
|
||||
HILOG_INFO("Is debug mode, no need to handle time out.");
|
||||
if (!IsDebug()) {
|
||||
auto handler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
|
||||
if (handler && task) {
|
||||
if (applicationInfo_.asanEnabled) {
|
||||
int terminateTimeout =
|
||||
AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * TERMINATE_TIMEOUT_ASANENABLED;
|
||||
handler->SubmitTask(task, "terminate_" + std::to_string(recordId_), terminateTimeout);
|
||||
} else {
|
||||
int terminateTimeout =
|
||||
AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * TERMINATE_TIMEOUT_MULTIPLE;
|
||||
handler->SubmitTask(task, "terminate_" + std::to_string(recordId_), terminateTimeout);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
HILOG_INFO("Is debug mode, no need to handle time out.");
|
||||
}
|
||||
// schedule background after updating AbilityState and sending timeout message to avoid ability async callback
|
||||
// earlier than above actions.
|
||||
@ -1448,9 +1469,12 @@ void AbilityRecord::ShareData(const int32_t &uniqueId)
|
||||
{
|
||||
HILOG_INFO("ability:%{public}s.", abilityInfo_.name.c_str());
|
||||
CHECK_POINTER(lifecycleDeal_);
|
||||
int loadTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * SHAREDATA_TIMEOUT_MULTIPLE;
|
||||
HILOG_DEBUG("loadTimeOut %{public}d.", loadTimeout);
|
||||
SendEvent(AbilityManagerService::SHAREDATA_TIMEOUT_MSG, loadTimeout, uniqueId);
|
||||
if (!IsDebug()) {
|
||||
int loadTimeout =
|
||||
AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * SHAREDATA_TIMEOUT_MULTIPLE;
|
||||
HILOG_DEBUG("loadTimeOut %{public}d.", loadTimeout);
|
||||
SendEvent(AbilityManagerService::SHAREDATA_TIMEOUT_MSG, loadTimeout, uniqueId);
|
||||
}
|
||||
lifecycleDeal_->ShareData(uniqueId);
|
||||
}
|
||||
|
||||
@ -2136,6 +2160,7 @@ void AbilityRecord::OnSchedulerDied(const wptr<IRemoteObject> &remote)
|
||||
HandleDlpClosed();
|
||||
NotifyRemoveShellProcess(CollaboratorType::RESERVE_TYPE);
|
||||
NotifyRemoveShellProcess(CollaboratorType::OTHERS_TYPE);
|
||||
FreezeUtil::GetInstance().DeleteLifecycleEvent(object);
|
||||
}
|
||||
|
||||
void AbilityRecord::NotifyAnimationAbilityDied()
|
||||
@ -2207,11 +2232,6 @@ bool AbilityRecord::IsActiveState() const
|
||||
|
||||
void AbilityRecord::SendEvent(uint32_t msg, uint32_t timeOut, int32_t param)
|
||||
{
|
||||
if (want_.GetBoolParam(DEBUG_APP, false) || want_.GetBoolParam(NATIVE_DEBUG, false) ||
|
||||
!want_.GetStringParam(PERF_CMD).empty() || isAttachDebug_) {
|
||||
HILOG_INFO("Is debug mode, no need to handle time out.");
|
||||
return;
|
||||
}
|
||||
auto handler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetEventHandler();
|
||||
CHECK_POINTER(handler);
|
||||
param = (param == -1) ? recordId_ : param;
|
||||
@ -2220,6 +2240,16 @@ void AbilityRecord::SendEvent(uint32_t msg, uint32_t timeOut, int32_t param)
|
||||
handler->SendEvent(eventWrap, timeOut);
|
||||
}
|
||||
|
||||
bool AbilityRecord::IsDebug() const
|
||||
{
|
||||
if (want_.GetBoolParam(DEBUG_APP, false) || want_.GetBoolParam(NATIVE_DEBUG, false) ||
|
||||
!want_.GetStringParam(PERF_CMD).empty() || isAttachDebug_) {
|
||||
HILOG_INFO("Is debug mode, no need to handle time out.");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void AbilityRecord::SetStartSetting(const std::shared_ptr<AbilityStartSetting> &setting)
|
||||
{
|
||||
lifeCycleStateInfo_.setting = setting;
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "in_process_call_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
using AbilityRuntime::FreezeUtil;
|
||||
namespace AAFwk {
|
||||
namespace {
|
||||
constexpr uint32_t DELAY_NOTIFY_LABEL_TIME = 30; // 30ms
|
||||
@ -67,6 +68,17 @@ std::string GetCurrentTime()
|
||||
static_cast<uint64_t>(tn.tv_nsec);
|
||||
return std::to_string(uTime);
|
||||
}
|
||||
const std::unordered_map<uint32_t, FreezeUtil::TimeoutState> stateMap = {
|
||||
{ AbilityManagerService::LOAD_TIMEOUT_MSG, FreezeUtil::TimeoutState::LOAD },
|
||||
{ AbilityManagerService::FOREGROUND_TIMEOUT_MSG, FreezeUtil::TimeoutState::FOREGROUND },
|
||||
{ AbilityManagerService::BACKGROUND_TIMEOUT_MSG, FreezeUtil::TimeoutState::BACKGROUND }
|
||||
};
|
||||
|
||||
auto g_deleteLifecycleEventTask = [](const sptr<Token> &token, FreezeUtil::TimeoutState state) {
|
||||
CHECK_POINTER_LOG(token, "token is nullptr.");
|
||||
FreezeUtil::LifecycleFlow flow = { token->AsObject(), state };
|
||||
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
|
||||
};
|
||||
} // namespace
|
||||
|
||||
MissionListManager::MissionListManager(int userId) : userId_(userId) {}
|
||||
@ -990,6 +1002,8 @@ int MissionListManager::AttachAbilityThread(const sptr<IAbilityScheduler> &sched
|
||||
auto eventHandler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetEventHandler();
|
||||
CHECK_POINTER_AND_RETURN_LOG(eventHandler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler.");
|
||||
eventHandler->RemoveEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, abilityRecord->GetAbilityRecordId());
|
||||
FreezeUtil::LifecycleFlow flow = { token, FreezeUtil::TimeoutState::LOAD };
|
||||
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
|
||||
|
||||
abilityRecord->SetScheduler(scheduler);
|
||||
|
||||
@ -1220,6 +1234,7 @@ int MissionListManager::DispatchForeground(const std::shared_ptr<AbilityRecord>
|
||||
auto eventHandler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetEventHandler();
|
||||
CHECK_POINTER_AND_RETURN_LOG(eventHandler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler.");
|
||||
eventHandler->RemoveEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, abilityRecord->GetAbilityRecordId());
|
||||
g_deleteLifecycleEventTask(abilityRecord->GetToken(), FreezeUtil::TimeoutState::FOREGROUND);
|
||||
auto self(weak_from_this());
|
||||
auto taskHandler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
|
||||
CHECK_POINTER_AND_RETURN_LOG(taskHandler, ERR_INVALID_VALUE, "Fail to get AbilityTaskHandler.");
|
||||
@ -1350,6 +1365,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);
|
||||
auto self(shared_from_this());
|
||||
auto task = [self, abilityRecord]() { self->CompleteBackground(abilityRecord); };
|
||||
handler->SubmitTask(task);
|
||||
@ -2074,6 +2090,48 @@ void MissionListManager::PrintTimeOutLog(const std::shared_ptr<AbilityRecord> &a
|
||||
}
|
||||
int typeId = AppExecFwk::AppfreezeManager::TypeAttribute::NORMAL_TIMEOUT;
|
||||
std::string msgContent = "ability:" + ability->GetAbilityInfo().name + " ";
|
||||
FreezeUtil::TimeoutState state = FreezeUtil::TimeoutState::UNKNOWN;
|
||||
auto search = stateMap.find(msgId);
|
||||
if (search != stateMap.end()) {
|
||||
state = search->second;
|
||||
}
|
||||
if (!GetContentAndTypeId(msgId, msgContent, typeId)) {
|
||||
HILOG_WARN("msgId is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string eventName = isHalf ?
|
||||
AppExecFwk::AppFreezeType::LIFECYCLE_HALF_TIMEOUT : AppExecFwk::AppFreezeType::LIFECYCLE_TIMEOUT;
|
||||
HILOG_WARN("%{public}s: uid: %{public}d, pid: %{public}d, bundleName: %{public}s, abilityName: %{public}s,"
|
||||
"msg: %{public}s", eventName.c_str(),
|
||||
processInfo.uid_, processInfo.pid_, ability->GetAbilityInfo().bundleName.c_str(),
|
||||
ability->GetAbilityInfo().name.c_str(), msgContent.c_str());
|
||||
|
||||
AppExecFwk::AppfreezeManager::ParamInfo info = {
|
||||
.typeId = typeId,
|
||||
.pid = processInfo.pid_,
|
||||
.eventName = eventName,
|
||||
.bundleName = ability->GetAbilityInfo().bundleName,
|
||||
};
|
||||
if (state != FreezeUtil::TimeoutState::UNKNOWN) {
|
||||
auto flow = std::make_unique<FreezeUtil::LifecycleFlow>();
|
||||
if (ability->GetToken() != nullptr) {
|
||||
flow->token = ability->GetToken()->AsObject();
|
||||
flow->state = state;
|
||||
}
|
||||
info.msg = msgContent + "\nserver:\n" + FreezeUtil::GetInstance().GetLifecycleEvent(*flow);
|
||||
if (!isHalf) {
|
||||
FreezeUtil::GetInstance().DeleteLifecycleEvent(*flow);
|
||||
}
|
||||
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info, std::move(flow));
|
||||
} else {
|
||||
info.msg = msgContent;
|
||||
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info);
|
||||
}
|
||||
}
|
||||
|
||||
bool MissionListManager::GetContentAndTypeId(uint32_t msgId, std::string &msgContent, int &typeId) const
|
||||
{
|
||||
switch (msgId) {
|
||||
case AbilityManagerService::LOAD_TIMEOUT_MSG:
|
||||
msgContent += "load timeout";
|
||||
@ -2096,18 +2154,9 @@ void MissionListManager::PrintTimeOutLog(const std::shared_ptr<AbilityRecord> &a
|
||||
msgContent += "terminate timeout";
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string eventName = isHalf ?
|
||||
AppExecFwk::AppFreezeType::LIFECYCLE_HALF_TIMEOUT : AppExecFwk::AppFreezeType::LIFECYCLE_TIMEOUT;
|
||||
HILOG_WARN("%{public}s: uid: %{public}d, pid: %{public}d, bundleName: %{public}s, abilityName: %{public}s,"
|
||||
"msg: %{public}s", eventName.c_str(),
|
||||
processInfo.uid_, processInfo.pid_, ability->GetAbilityInfo().bundleName.c_str(),
|
||||
ability->GetAbilityInfo().name.c_str(), msgContent.c_str());
|
||||
|
||||
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(
|
||||
typeId, processInfo.pid_, eventName, ability->GetAbilityInfo().bundleName, msgContent);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MissionListManager::UpdateMissionSnapshot(const std::shared_ptr<AbilityRecord>& abilityRecord) const
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "session_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
using AbilityRuntime::FreezeUtil;
|
||||
namespace AAFwk {
|
||||
namespace {
|
||||
constexpr char EVENT_KEY_UID[] = "UID";
|
||||
@ -47,7 +48,19 @@ const int KILL_TIMEOUT_MULTIPLE = 45;
|
||||
const int KILL_TIMEOUT_MULTIPLE = 3;
|
||||
#endif
|
||||
constexpr int32_t DEFAULT_USER_ID = 0;
|
||||
const std::unordered_map<uint32_t, FreezeUtil::TimeoutState> stateMap = {
|
||||
{ AbilityManagerService::LOAD_TIMEOUT_MSG, FreezeUtil::TimeoutState::LOAD },
|
||||
{ AbilityManagerService::FOREGROUND_TIMEOUT_MSG, FreezeUtil::TimeoutState::FOREGROUND },
|
||||
{ AbilityManagerService::BACKGROUND_TIMEOUT_MSG, FreezeUtil::TimeoutState::BACKGROUND }
|
||||
};
|
||||
|
||||
auto g_deleteLifecycleEventTask = [](const sptr<Token> &token, FreezeUtil::TimeoutState state) {
|
||||
CHECK_POINTER_LOG(token, "token is nullptr.");
|
||||
FreezeUtil::LifecycleFlow flow = { token->AsObject(), state };
|
||||
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
|
||||
};
|
||||
}
|
||||
|
||||
int UIAbilityLifecycleManager::StartUIAbility(AbilityRequest &abilityRequest, sptr<SessionInfo> sessionInfo)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
@ -136,11 +149,13 @@ int UIAbilityLifecycleManager::AttachAbilityThread(const sptr<IAbilityScheduler>
|
||||
}
|
||||
auto&& abilityRecord = Token::GetAbilityRecordByToken(token);
|
||||
CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE);
|
||||
HILOG_DEBUG("AbilityMS attach abilityThread, name is %{public}s.", abilityRecord->GetAbilityInfo().name.c_str());
|
||||
HILOG_INFO("Lifecycle: name is %{public}s.", abilityRecord->GetAbilityInfo().name.c_str());
|
||||
|
||||
auto handler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetEventHandler();
|
||||
CHECK_POINTER_AND_RETURN_LOG(handler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler.");
|
||||
handler->RemoveEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, abilityRecord->GetAbilityRecordId());
|
||||
FreezeUtil::LifecycleFlow flow = {token, FreezeUtil::TimeoutState::LOAD};
|
||||
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
|
||||
|
||||
abilityRecord->SetScheduler(scheduler);
|
||||
if (abilityRecord->IsStartedByCall()) {
|
||||
@ -257,7 +272,9 @@ int UIAbilityLifecycleManager::DispatchForeground(const std::shared_ptr<AbilityR
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
HILOG_INFO("ForegroundLifecycle: end.");
|
||||
handler->RemoveEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, abilityRecord->GetAbilityRecordId());
|
||||
g_deleteLifecycleEventTask(abilityRecord->GetToken(), FreezeUtil::TimeoutState::FOREGROUND);
|
||||
auto self(weak_from_this());
|
||||
if (success) {
|
||||
HILOG_INFO("foreground succeeded.");
|
||||
@ -303,8 +320,10 @@ int UIAbilityLifecycleManager::DispatchBackground(const std::shared_ptr<AbilityR
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
HILOG_INFO("BackgroundLifecycle: end.");
|
||||
// remove background timeout task.
|
||||
handler->CancelTask("background_" + std::to_string(abilityRecord->GetAbilityRecordId()));
|
||||
g_deleteLifecycleEventTask(abilityRecord->GetToken(), FreezeUtil::TimeoutState::BACKGROUND);
|
||||
auto self(shared_from_this());
|
||||
auto task = [self, abilityRecord]() { self->CompleteBackground(abilityRecord); };
|
||||
handler->SubmitTask(task);
|
||||
@ -738,6 +757,48 @@ void UIAbilityLifecycleManager::PrintTimeOutLog(const std::shared_ptr<AbilityRec
|
||||
}
|
||||
int typeId = AppExecFwk::AppfreezeManager::TypeAttribute::NORMAL_TIMEOUT;
|
||||
std::string msgContent = "ability:" + ability->GetAbilityInfo().name + " ";
|
||||
FreezeUtil::TimeoutState state = FreezeUtil::TimeoutState::UNKNOWN;
|
||||
auto search = stateMap.find(msgId);
|
||||
if (search != stateMap.end()) {
|
||||
state = search->second;
|
||||
}
|
||||
if (!GetContentAndTypeId(msgId, msgContent, typeId)) {
|
||||
HILOG_WARN("msgId is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string eventName = isHalf ?
|
||||
AppExecFwk::AppFreezeType::LIFECYCLE_HALF_TIMEOUT : AppExecFwk::AppFreezeType::LIFECYCLE_TIMEOUT;
|
||||
HILOG_WARN("%{public}s: uid: %{public}d, pid: %{public}d, bundleName: %{public}s, abilityName: %{public}s,"
|
||||
"msg: %{public}s", eventName.c_str(),
|
||||
processInfo.uid_, processInfo.pid_, ability->GetAbilityInfo().bundleName.c_str(),
|
||||
ability->GetAbilityInfo().name.c_str(), msgContent.c_str());
|
||||
|
||||
AppExecFwk::AppfreezeManager::ParamInfo info = {
|
||||
.typeId = typeId,
|
||||
.pid = processInfo.pid_,
|
||||
.eventName = eventName,
|
||||
.bundleName = ability->GetAbilityInfo().bundleName,
|
||||
};
|
||||
if (state != FreezeUtil::TimeoutState::UNKNOWN) {
|
||||
auto flow = std::make_unique<FreezeUtil::LifecycleFlow>();
|
||||
if (ability->GetToken() != nullptr) {
|
||||
flow->token = ability->GetToken()->AsObject();
|
||||
flow->state = state;
|
||||
}
|
||||
info.msg = msgContent + "\nserver:\n" + FreezeUtil::GetInstance().GetLifecycleEvent(*flow);
|
||||
if (!isHalf) {
|
||||
FreezeUtil::GetInstance().DeleteLifecycleEvent(*flow);
|
||||
}
|
||||
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info, std::move(flow));
|
||||
} else {
|
||||
info.msg = msgContent;
|
||||
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info);
|
||||
}
|
||||
}
|
||||
|
||||
bool UIAbilityLifecycleManager::GetContentAndTypeId(uint32_t msgId, std::string &msgContent, int &typeId) const
|
||||
{
|
||||
switch (msgId) {
|
||||
case AbilityManagerService::LOAD_TIMEOUT_MSG:
|
||||
msgContent += "load timeout";
|
||||
@ -754,18 +815,9 @@ void UIAbilityLifecycleManager::PrintTimeOutLog(const std::shared_ptr<AbilityRec
|
||||
msgContent += "terminate timeout";
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string eventName = isHalf ?
|
||||
AppExecFwk::AppFreezeType::LIFECYCLE_HALF_TIMEOUT : AppExecFwk::AppFreezeType::LIFECYCLE_TIMEOUT;
|
||||
HILOG_WARN("%{public}s: uid: %{public}d, pid: %{public}d, bundleName: %{public}s, abilityName: %{public}s,"
|
||||
"msg: %{public}s", eventName.c_str(),
|
||||
processInfo.uid_, processInfo.pid_, ability->GetAbilityInfo().bundleName.c_str(),
|
||||
ability->GetAbilityInfo().name.c_str(), msgContent.c_str());
|
||||
|
||||
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(
|
||||
typeId, processInfo.pid_, eventName, ability->GetAbilityInfo().bundleName, msgContent);
|
||||
return true;
|
||||
}
|
||||
|
||||
void UIAbilityLifecycleManager::CompleteBackground(const std::shared_ptr<AbilityRecord> &abilityRecord)
|
||||
|
@ -21,6 +21,7 @@ config("appmgr_config") {
|
||||
"${ability_runtime_services_path}/common/include",
|
||||
"${appspawn_path}/interfaces/innerkits/include",
|
||||
"${ability_runtime_path}/tools/aa/include",
|
||||
"${ability_runtime_path}/utils/global/time/include",
|
||||
"${distributeddatamgr_path}/kv_store/interfaces/innerkits/distributeddatamgr/include",
|
||||
]
|
||||
}
|
||||
@ -77,6 +78,7 @@ ohos_shared_library("libappms") {
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
|
@ -15,10 +15,13 @@
|
||||
|
||||
#include "app_lifecycle_deal.h"
|
||||
|
||||
#include "freeze_util.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "time_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
using AbilityRuntime::FreezeUtil;
|
||||
namespace AppExecFwk {
|
||||
AppLifeCycleDeal::AppLifeCycleDeal()
|
||||
{}
|
||||
@ -31,7 +34,7 @@ AppLifeCycleDeal::~AppLifeCycleDeal()
|
||||
void AppLifeCycleDeal::LaunchApplication(const AppLaunchData &launchData, const Configuration &config)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("AppLifeCycleDeal ScheduleLaunchApplication");
|
||||
HILOG_INFO("LoadLifecycle: Launch application");
|
||||
if (appThread_) {
|
||||
appThread_->ScheduleLaunchApplication(launchData, config);
|
||||
}
|
||||
@ -60,6 +63,14 @@ void AppLifeCycleDeal::AddAbilityStage(const HapModuleInfo &abilityStage)
|
||||
void AppLifeCycleDeal::LaunchAbility(const std::shared_ptr<AbilityRunningRecord> &ability)
|
||||
{
|
||||
if (appThread_ && ability) {
|
||||
auto &abilityInfo = ability->GetAbilityInfo();
|
||||
if (abilityInfo != nullptr && abilityInfo->type == AbilityType::PAGE) {
|
||||
FreezeUtil::LifecycleFlow flow = {ability->GetToken(), FreezeUtil::TimeoutState::LOAD};
|
||||
auto entry = std::to_string(AbilityRuntime::TimeUtil::SystemTimeMillisecond()) +
|
||||
"; AppLifeCycleDeal::LaunchAbility; the LoadAbility lifecycle.";
|
||||
FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
|
||||
}
|
||||
HILOG_INFO("LoadLifecycle: Launch ability.");
|
||||
appThread_->ScheduleLaunchAbility(*(ability->GetAbilityInfo()), ability->GetToken(),
|
||||
ability->GetWant());
|
||||
}
|
||||
|
@ -165,6 +165,7 @@ int32_t AppMgrService::CheckPermission(
|
||||
|
||||
void AppMgrService::AttachApplication(const sptr<IRemoteObject> &app)
|
||||
{
|
||||
HILOG_INFO("LoadLifecycle: appMGR receives a binding request.");
|
||||
if (!IsReady()) {
|
||||
HILOG_ERROR("AttachApplication failed, not ready.");
|
||||
return;
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "datetime_ex.h"
|
||||
#include "distributed_data_mgr.h"
|
||||
#include "event_report.h"
|
||||
#include "freeze_util.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hisysevent.h"
|
||||
#include "hitrace_meter.h"
|
||||
@ -56,6 +57,7 @@
|
||||
#include "permission_constants.h"
|
||||
#include "permission_verification.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "time_util.h"
|
||||
#include "ui_extension_utils.h"
|
||||
#include "uri_permission_manager_client.h"
|
||||
#ifdef APP_MGR_SERVICE_APPMS
|
||||
@ -177,11 +179,17 @@ void AppMgrServiceInner::LoadAbility(const sptr<IRemoteObject> &token, const spt
|
||||
const std::shared_ptr<AAFwk::Want> &want)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
HILOG_INFO("LoadLifecycle: name:%{public}s.", abilityInfo->name.c_str());
|
||||
if (!CheckLoadAbilityConditions(token, abilityInfo, appInfo)) {
|
||||
HILOG_ERROR("CheckLoadAbilityConditions failed");
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("load,name:%{public}s.", abilityInfo->name.c_str());
|
||||
if (abilityInfo->type == AbilityType::PAGE) {
|
||||
AbilityRuntime::FreezeUtil::LifecycleFlow flow = {token, AbilityRuntime::FreezeUtil::TimeoutState::LOAD};
|
||||
auto entry = std::to_string(AbilityRuntime::TimeUtil::SystemTimeMillisecond()) +
|
||||
"; AppMgrServiceInner::LoadAbility; the load lifecycle.";
|
||||
AbilityRuntime::FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry);
|
||||
}
|
||||
|
||||
if (!appRunningManager_) {
|
||||
HILOG_ERROR("appRunningManager_ is nullptr");
|
||||
@ -358,6 +366,7 @@ bool AppMgrServiceInner::GetBundleAndHapInfo(const AbilityInfo &abilityInfo,
|
||||
|
||||
void AppMgrServiceInner::AttachApplication(const pid_t pid, const sptr<IAppScheduler> &appScheduler)
|
||||
{
|
||||
HILOG_INFO("LoadLifecycle: attach task excutes.");
|
||||
if (pid <= 0) {
|
||||
HILOG_ERROR("invalid pid:%{public}d", pid);
|
||||
return;
|
||||
@ -1914,13 +1923,15 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str
|
||||
|
||||
PerfProfile::GetInstance().SetAppForkStartTime(GetTickCount());
|
||||
pid_t pid = 0;
|
||||
HILOG_INFO("LoadLifecycle: Start process, bundleName: %{public}s.", bundleName.c_str());
|
||||
ErrCode errCode = remoteClientManager_->GetSpawnClient()->StartProcess(startMsg, pid);
|
||||
if (FAILED(errCode)) {
|
||||
HILOG_ERROR("failed to spawn new app process, errCode %{public}08x", errCode);
|
||||
appRunningManager_->RemoveAppRunningRecordById(appRecord->GetRecordId());
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("Start process success, pid is %{public}d, processName is %{public}s.", pid, processName.c_str());
|
||||
HILOG_INFO("LoadLifecycle: Start process success, pid: %{public}d, processName: %{public}s.",
|
||||
pid, processName.c_str());
|
||||
SetRunningSharedBundleList(bundleName, hspList);
|
||||
appRecord->GetPriorityObject()->SetPid(pid);
|
||||
appRecord->SetUid(startMsg.uid);
|
||||
@ -3155,8 +3166,14 @@ void AppMgrServiceInner::SendHiSysEvent(const int32_t innerEventId, const int64_
|
||||
HILOG_WARN("LIFECYCLE_TIMEOUT, eventName = %{public}s, uid = %{public}d, pid = %{public}d, \
|
||||
packageName = %{public}s, processName = %{public}s, msg = %{public}s",
|
||||
eventName.c_str(), uid, pid, packageName.c_str(), processName.c_str(), msg.c_str());
|
||||
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(
|
||||
typeId, pid, eventName, packageName, msg);
|
||||
AppfreezeManager::ParamInfo info = {
|
||||
.typeId = typeId,
|
||||
.pid = pid,
|
||||
.eventName = eventName,
|
||||
.bundleName = packageName,
|
||||
.msg = msg
|
||||
};
|
||||
AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info);
|
||||
}
|
||||
|
||||
int AppMgrServiceInner::GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens)
|
||||
@ -4015,6 +4032,8 @@ FaultData AppMgrServiceInner::ConvertDataTypes(const AppFaultDataBySA &faultData
|
||||
newfaultData.waitSaveState = faultData.waitSaveState;
|
||||
newfaultData.notifyApp = faultData.notifyApp;
|
||||
newfaultData.forceExit = faultData.forceExit;
|
||||
newfaultData.token = faultData.token;
|
||||
newfaultData.state = faultData.state;
|
||||
return newfaultData;
|
||||
}
|
||||
|
||||
|
@ -190,6 +190,7 @@ ohos_source_set("abilityms_test_source") {
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_innerkits_path}/connectionobs_manager:connection_obs_manager",
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${ability_runtime_services_path}/abilitymgr:abilityms",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
]
|
||||
|
@ -43,6 +43,8 @@ ohos_unittest("ability_manager_stub_test") {
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/ability_manager:mission_info",
|
||||
"${ability_runtime_native_path}/ability/native:abilitykit_native",
|
||||
|
||||
# "${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
|
||||
|
@ -49,6 +49,7 @@ ohos_unittest("AmsAbilityRunningRecordTest") {
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
|
@ -52,6 +52,7 @@ ohos_unittest("AmsRecentAppListTest") {
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
|
@ -52,6 +52,7 @@ ohos_unittest("AmsServiceAppSpawnClientTest") {
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
|
@ -54,6 +54,7 @@ ohos_unittest("AmsServiceEventDriveTest") {
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
|
@ -52,6 +52,7 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") {
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
|
@ -51,6 +51,7 @@ ohos_unittest("AmsServiceStartupTest") {
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
|
@ -50,6 +50,7 @@ ohos_unittest("AMSEventHandlerTest") {
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
|
@ -39,6 +39,7 @@ ohos_unittest("AppRecoveryUnitTest") {
|
||||
"${ability_runtime_native_path}/appkit:app_context",
|
||||
"${ability_runtime_native_path}/appkit:app_context_utils",
|
||||
"${ability_runtime_native_path}/appkit:appkit_delegator",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
"${multimedia_path}/interfaces/innerkits:image_native",
|
||||
"${windowmanager_path}/dm:libdm",
|
||||
|
@ -50,6 +50,7 @@ ohos_unittest("AppRunningProcessesInfoTest") {
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
|
@ -1600,6 +1600,7 @@ ohos_unittest("new_ability_impl_test") {
|
||||
"${ability_runtime_native_path}/ability/native:abilitykit_native",
|
||||
"${ability_runtime_native_path}/appkit:app_context",
|
||||
"${ability_runtime_native_path}/appkit:appkit_native",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"${global_path}/resource_management/frameworks/resmgr:global_resmgr",
|
||||
"//third_party/googletest:gtest_main",
|
||||
@ -1672,6 +1673,7 @@ ohos_unittest("reserse_continuation_scheduler_primary_proxy_test") {
|
||||
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
|
||||
"${ability_runtime_native_path}/ability/native:abilitykit_native",
|
||||
"${ability_runtime_native_path}/appkit:app_context",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"${global_path}/resource_management/frameworks/resmgr:global_resmgr",
|
||||
"//third_party/googletest:gmock_main",
|
||||
|
@ -502,6 +502,7 @@ ohos_unittest("appfreeze_inner_test") {
|
||||
"${ability_runtime_native_path}/appkit:app_context_utils",
|
||||
"${ability_runtime_native_path}/appkit:appkit_native",
|
||||
"${ability_runtime_path}/js_environment/frameworks/js_environment:js_environment",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
45
utils/global/freeze/BUILD.gn
Normal file
45
utils/global/freeze/BUILD.gn
Normal file
@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
|
||||
config("freeze_util_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("freeze_util") {
|
||||
include_dirs = [ "${ability_runtime_services_path}/common/include" ]
|
||||
|
||||
sources = [ "src/freeze_util.cpp" ]
|
||||
|
||||
public_configs = [ ":freeze_util_config" ]
|
||||
|
||||
defines = [ "AMS_LOG_TAG = \"FreezeFlow\"" ]
|
||||
defines += [ "AMS_LOG_DOMAIN = 0xD001306" ]
|
||||
cflags = []
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
deps = []
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_single",
|
||||
]
|
||||
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
70
utils/global/freeze/include/freeze_util.h
Normal file
70
utils/global/freeze/include/freeze_util.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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_FREEZE_UTIL_H
|
||||
#define OHOS_ABILITY_RUNTIME_FREEZE_UTIL_H
|
||||
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "iremote_object.h"
|
||||
|
||||
namespace OHOS::AbilityRuntime {
|
||||
class FreezeUtil {
|
||||
public:
|
||||
enum class TimeoutState {
|
||||
UNKNOWN = 0,
|
||||
LOAD,
|
||||
FOREGROUND,
|
||||
BACKGROUND
|
||||
};
|
||||
|
||||
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;
|
||||
FreezeUtil(const FreezeUtil&) = delete;
|
||||
virtual ~FreezeUtil() = default;
|
||||
static FreezeUtil& GetInstance();
|
||||
|
||||
void AddLifecycleEvent(const LifecycleFlow &flow, const std::string &entry);
|
||||
std::string GetLifecycleEvent(const LifecycleFlow &flow);
|
||||
void DeleteLifecycleEvent(const LifecycleFlow &flow);
|
||||
void DeleteLifecycleEvent(sptr<IRemoteObject> token);
|
||||
|
||||
private:
|
||||
FreezeUtil() = default;
|
||||
void DeleteLifecycleEventInner(const LifecycleFlow &flow);
|
||||
|
||||
class LifecycleFlowObjHash {
|
||||
public:
|
||||
size_t operator() (const LifecycleFlow &flow) const
|
||||
{
|
||||
return reinterpret_cast<size_t>(flow.token.GetRefPtr()) + std::hash<int>()(static_cast<int>(flow.state));
|
||||
}
|
||||
};
|
||||
|
||||
std::mutex mutex_;
|
||||
std::unordered_map<LifecycleFlow, std::string, LifecycleFlowObjHash> lifecycleFolw_;
|
||||
};
|
||||
} // namespace OHOS::AbilityRuntime
|
||||
#endif // OHOS_ABILITY_RUNTIME_FREEZE_UTIL_H
|
73
utils/global/freeze/src/freeze_util.cpp
Normal file
73
utils/global/freeze/src/freeze_util.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "freeze_util.h"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS::AbilityRuntime {
|
||||
FreezeUtil& FreezeUtil::GetInstance()
|
||||
{
|
||||
static FreezeUtil instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void FreezeUtil::AddLifecycleEvent(const LifecycleFlow &flow, const std::string &entry)
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
if (lifecycleFolw_.count(flow)) {
|
||||
lifecycleFolw_[flow] = lifecycleFolw_[flow] + "\n" + entry;
|
||||
} else {
|
||||
lifecycleFolw_[flow] = entry;
|
||||
}
|
||||
}
|
||||
|
||||
std::string FreezeUtil::GetLifecycleEvent(const LifecycleFlow &flow)
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
auto search = lifecycleFolw_.find(flow);
|
||||
if (search != lifecycleFolw_.end()) {
|
||||
return search->second;
|
||||
}
|
||||
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 (lifecycleFolw_.empty()) {
|
||||
return;
|
||||
}
|
||||
LifecycleFlow foregroundFlow = { token, TimeoutState::FOREGROUND };
|
||||
DeleteLifecycleEventInner(foregroundFlow);
|
||||
|
||||
LifecycleFlow backgroundFlow = { token, TimeoutState::BACKGROUND };
|
||||
DeleteLifecycleEventInner(backgroundFlow);
|
||||
}
|
||||
|
||||
void FreezeUtil::DeleteLifecycleEventInner(const LifecycleFlow &flow)
|
||||
{
|
||||
if (lifecycleFolw_.count(flow)) {
|
||||
lifecycleFolw_.erase(flow);
|
||||
}
|
||||
HILOG_INFO("lifecycleFolw_ size: %{public}d", lifecycleFolw_.size());
|
||||
}
|
||||
} // namespace OHOS::AbilityRuntime
|
40
utils/global/time/include/time_util.h
Normal file
40
utils/global/time/include/time_util.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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_TIME_UTIL_H
|
||||
#define OHOS_ABILITY_RUNTIME_TIME_UTIL_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
namespace OHOS::AbilityRuntime {
|
||||
namespace TimeUtil {
|
||||
// NANOSECONDS mean 10^9 nano second
|
||||
constexpr int64_t NANOSECONDS = 1000000000;
|
||||
// MICROSECONDS mean 10^6 milli second
|
||||
constexpr int64_t MICROSECONDS = 1000000;
|
||||
|
||||
[[maybe_unused]] static int64_t SystemTimeMillisecond()
|
||||
{
|
||||
struct timespec t;
|
||||
t.tv_sec = 0;
|
||||
t.tv_nsec = 0;
|
||||
clock_gettime(CLOCK_MONOTONIC, &t);
|
||||
return (int64_t)((t.tv_sec) * NANOSECONDS + t.tv_nsec) / MICROSECONDS;
|
||||
}
|
||||
} // namespace TimeUtil
|
||||
} // namespace OHOS::AbilityRuntime
|
||||
#endif // OHOS_ABILITY_RUNTIME_TIME_UTIL_H
|
Loading…
Reference in New Issue
Block a user