mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-23 07:10:19 +00:00
Add app exception callback
Signed-off-by: wangzhen <wangzhen346@huawei.com> Change-Id: I78385dbb4d3012eee71a9eccb7d3185c296bf53d
This commit is contained in:
parent
a22d5a0ccf
commit
464c6b7c74
@ -88,10 +88,11 @@ void AbilityThread::AbilityThreadMain(const std::shared_ptr<OHOSApplication> &ap
|
||||
TAG_LOGD(AAFwkTag::ABILITY, "end");
|
||||
}
|
||||
|
||||
void AbilityThread::ScheduleAbilityTransaction(
|
||||
bool AbilityThread::ScheduleAbilityTransaction(
|
||||
const Want &want, const LifeCycleStateInfo &targetState, sptr<SessionInfo> sessionInfo)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::ABILITY, "called");
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbilityThread::ScheduleShareData(const int32_t &requestCode)
|
||||
|
@ -373,7 +373,7 @@ void ExtensionAbilityThread::HandleExtensionUpdateConfiguration(const AppExecFwk
|
||||
TAG_LOGD(AAFwkTag::EXT, "End");
|
||||
}
|
||||
|
||||
void ExtensionAbilityThread::ScheduleAbilityTransaction(
|
||||
bool ExtensionAbilityThread::ScheduleAbilityTransaction(
|
||||
const Want &want, const LifeCycleStateInfo &lifeCycleStateInfo, sptr<AAFwk::SessionInfo> sessionInfo)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
@ -381,11 +381,11 @@ void ExtensionAbilityThread::ScheduleAbilityTransaction(
|
||||
want.GetElement().GetAbilityName().c_str(), lifeCycleStateInfo.state, lifeCycleStateInfo.isNewWant);
|
||||
if (token_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::EXT, "null token_");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (abilityHandler_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::EXT, "null abilityHandler_");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
wptr<ExtensionAbilityThread> weak = this;
|
||||
auto task = [weak, want, lifeCycleStateInfo, sessionInfo]() {
|
||||
@ -399,7 +399,9 @@ void ExtensionAbilityThread::ScheduleAbilityTransaction(
|
||||
bool ret = abilityHandler_->PostTask(task, AppExecFwk::EventQueue::Priority::HIGH);
|
||||
if (!ret) {
|
||||
TAG_LOGE(AAFwkTag::EXT, "PostTask error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ExtensionAbilityThread::ScheduleConnectAbility(const Want &want)
|
||||
|
@ -710,7 +710,7 @@ void FAAbilityThread::HandleExtensionUpdateConfiguration(const AppExecFwk::Confi
|
||||
extensionImpl_->ScheduleUpdateConfiguration(config);
|
||||
}
|
||||
|
||||
void FAAbilityThread::ScheduleAbilityTransaction(
|
||||
bool FAAbilityThread::ScheduleAbilityTransaction(
|
||||
const Want &want, const LifeCycleStateInfo &lifeCycleStateInfo, sptr<AAFwk::SessionInfo> sessionInfo)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
@ -723,11 +723,11 @@ void FAAbilityThread::ScheduleAbilityTransaction(
|
||||
|
||||
if (token_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::FA, "null token_");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (abilityHandler_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::FA, "null abilityHandler_");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
wptr<FAAbilityThread> weak = this;
|
||||
auto task = [weak, want, lifeCycleStateInfo, sessionInfo]() {
|
||||
@ -747,7 +747,9 @@ void FAAbilityThread::ScheduleAbilityTransaction(
|
||||
bool ret = abilityHandler_->PostTask(task, "FAAbilityThread:AbilityTransaction");
|
||||
if (!ret) {
|
||||
TAG_LOGE(AAFwkTag::FA, "PostTask error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void FAAbilityThread::ScheduleShareData(const int32_t &uniqueId)
|
||||
|
@ -306,7 +306,7 @@ void UIAbilityThread::HandleUpdateConfiguration(const AppExecFwk::Configuration
|
||||
abilityImpl_->ScheduleUpdateConfiguration(config);
|
||||
}
|
||||
|
||||
void UIAbilityThread::ScheduleAbilityTransaction(
|
||||
bool UIAbilityThread::ScheduleAbilityTransaction(
|
||||
const Want &want, const LifeCycleStateInfo &lifeCycleStateInfo, sptr<AAFwk::SessionInfo> sessionInfo)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
@ -319,11 +319,11 @@ void UIAbilityThread::ScheduleAbilityTransaction(
|
||||
|
||||
if (token_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "null token_");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (abilityHandler_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "null abilityHandler_");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
wptr<UIAbilityThread> weak = this;
|
||||
auto task = [weak, want, lifeCycleStateInfo, sessionInfo]() {
|
||||
@ -338,7 +338,9 @@ void UIAbilityThread::ScheduleAbilityTransaction(
|
||||
bool ret = abilityHandler_->PostTask(task, "UIAbilityThread:AbilityTransaction");
|
||||
if (!ret) {
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "postTask error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void UIAbilityThread::ScheduleShareData(const int32_t &uniqueId)
|
||||
|
@ -410,7 +410,7 @@ std::shared_ptr<EventHandler> MainThread::GetMainHandler() const
|
||||
* @brief Schedule the foreground lifecycle of application.
|
||||
*
|
||||
*/
|
||||
void MainThread::ScheduleForegroundApplication()
|
||||
bool MainThread::ScheduleForegroundApplication()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "called");
|
||||
@ -429,10 +429,10 @@ void MainThread::ScheduleForegroundApplication()
|
||||
auto tmpWatchdog = watchdog_;
|
||||
if (tmpWatchdog == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "Watch dog is nullptr.");
|
||||
return;
|
||||
} else {
|
||||
tmpWatchdog->SetBackgroundStatus(false);
|
||||
}
|
||||
tmpWatchdog->SetBackgroundStatus(false);
|
||||
tmpWatchdog = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
* @param targetState, The lifecycle state to be transformed
|
||||
* @param sessionInfo, The session info
|
||||
*/
|
||||
virtual void ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
|
||||
virtual bool ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
|
||||
sptr<SessionInfo> sessionInfo = nullptr) = 0;
|
||||
|
||||
/*
|
||||
@ -389,7 +389,7 @@ public:
|
||||
DUMP_ABILITY_RUNNER_INNER,
|
||||
|
||||
SCHEDULE_CALL,
|
||||
|
||||
|
||||
SCHEDULE_SHARE_DATA,
|
||||
|
||||
// ipc id for scheduling service ability to prepare terminate (30)
|
||||
|
@ -74,6 +74,11 @@ enum class AbilityLoadState: uint8_t {
|
||||
LOADED,
|
||||
FAILED
|
||||
};
|
||||
|
||||
enum class FreezeStrategy : uint8_t {
|
||||
PRINT_FREEZE_LOG,
|
||||
NOTIFY_FREEZE_MGR,
|
||||
};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_ABILITY_STATE_H
|
||||
|
@ -61,6 +61,9 @@ ohos_shared_library("app_manager") {
|
||||
"src/appmgr/app_debug_info.cpp",
|
||||
"src/appmgr/app_debug_listener_proxy.cpp",
|
||||
"src/appmgr/app_debug_listener_stub.cpp",
|
||||
"src/appmgr/app_exception_callback_proxy.cpp",
|
||||
"src/appmgr/app_exception_callback_stub.cpp",
|
||||
"src/appmgr/app_exception_manager.cpp",
|
||||
"src/appmgr/app_foreground_state_observer_proxy.cpp",
|
||||
"src/appmgr/app_foreground_state_observer_stub.cpp",
|
||||
"src/appmgr/app_jsheap_mem_info.cpp",
|
||||
|
@ -443,6 +443,8 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void SetAppExceptionCallback(sptr<IRemoteObject> callback) {}
|
||||
|
||||
enum class Message {
|
||||
LOAD_ABILITY = 0,
|
||||
TERMINATE_ABILITY,
|
||||
@ -496,6 +498,7 @@ public:
|
||||
FORCE_KILL_APPLICATION_BY_ACCESS_TOKEN_ID = 49,
|
||||
IS_PROCESS_ATTACHED,
|
||||
IS_APP_KILLING,
|
||||
SET_APP_EXCEPTION_CALLBACK,
|
||||
// Add enumeration values above
|
||||
END
|
||||
};
|
||||
|
@ -390,6 +390,8 @@ public:
|
||||
|
||||
virtual bool IsAppKilling(sptr<IRemoteObject> token) override;
|
||||
|
||||
virtual void SetAppExceptionCallback(sptr<IRemoteObject> callback) override;
|
||||
|
||||
private:
|
||||
bool WriteInterfaceToken(MessageParcel &data);
|
||||
int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
|
@ -102,6 +102,7 @@ private:
|
||||
int32_t HandleIsProcessContainsOnlyUIAbility(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleIsProcessAttached(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleIsAppKilling(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleSetAppExceptionCallback(MessageParcel &data, MessageParcel &reply);
|
||||
DISALLOW_COPY_AND_MOVE(AmsMgrStub);
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_PROXY_H
|
||||
#define OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_PROXY_H
|
||||
|
||||
#include "iapp_exception_callback.h"
|
||||
#include "iremote_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class AppExceptionCallbackProxy : public IRemoteProxy<IAppExceptionCallback> {
|
||||
public:
|
||||
explicit AppExceptionCallbackProxy(const sptr<IRemoteObject> &impl);
|
||||
virtual ~AppExceptionCallbackProxy() = default;
|
||||
|
||||
/**
|
||||
* Notify abilityManager lifecycle exception.
|
||||
*
|
||||
* @param type lifecycle failed type
|
||||
* @param token associated ability
|
||||
*/
|
||||
virtual void OnLifecycleException(LifecycleException type, sptr<IRemoteObject> token);
|
||||
private:
|
||||
bool WriteInterfaceToken(MessageParcel &data);
|
||||
static inline BrokerDelegator<AppExceptionCallbackProxy> delegator_;
|
||||
int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_PROXY_H
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_STUB_H
|
||||
#define OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_STUB_H
|
||||
|
||||
#include "iapp_exception_callback.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class AppExceptionCallbackStub : public IRemoteStub<IAppExceptionCallback> {
|
||||
public:
|
||||
AppExceptionCallbackStub() = default;
|
||||
virtual ~AppExceptionCallbackStub() = default;
|
||||
|
||||
virtual int32_t OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
private:
|
||||
int32_t HandleLifecycleException(MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(AppExceptionCallbackStub);
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_STUB_H
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_APP_EXCEPTION_MANAGER_H
|
||||
#define OHOS_ABILITY_RUNTIME_APP_EXCEPTION_MANAGER_H
|
||||
|
||||
#include "iapp_exception_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class AppExceptionManager {
|
||||
public:
|
||||
static AppExceptionManager &GetInstance();
|
||||
AppExceptionManager(AppExceptionManager &) = delete;
|
||||
void operator=(AppExceptionManager &) = delete;
|
||||
|
||||
void LaunchAbilityFailed(sptr<IRemoteObject> token, const std::string &msg);
|
||||
void ForegroundAppFailed(sptr<IRemoteObject> token, const std::string &msg);
|
||||
void ForegroundAppWait(sptr<IRemoteObject> token, const std::string &msg);
|
||||
|
||||
void NotifyLifecycleException(LifecycleException type, sptr<IRemoteObject> token);
|
||||
void SetExceptionCallback(sptr<IAppExceptionCallback> exceptionCallback);
|
||||
sptr<IAppExceptionCallback> GetExceptionCallback() const;
|
||||
private:
|
||||
AppExceptionManager() = default;
|
||||
mutable std::mutex exceptionCallbackMutex_;
|
||||
sptr<IAppExceptionCallback> exceptionCallback_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_APP_EXCEPTION_MANAGER_H
|
@ -39,7 +39,7 @@ public:
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
virtual void ScheduleForegroundApplication() = 0;
|
||||
virtual bool ScheduleForegroundApplication() = 0;
|
||||
|
||||
/**
|
||||
* ScheduleBackgroundApplication, call ScheduleBackgroundApplication() through proxy project,
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
virtual void ScheduleForegroundApplication() override;
|
||||
virtual bool ScheduleForegroundApplication() override;
|
||||
|
||||
/**
|
||||
* ScheduleBackgroundApplication, call ScheduleBackgroundApplication() through proxy project,
|
||||
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_I_APP_EXCEPTION_CALLBACK_H
|
||||
#define OHOS_ABILITY_RUNTIME_I_APP_EXCEPTION_CALLBACK_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
enum class LifecycleException {
|
||||
LAUNCH_ABILITY_FAIL,
|
||||
FOREGROUND_APP_FAIL,
|
||||
FOREGROUND_APP_WAIT,
|
||||
END
|
||||
};
|
||||
|
||||
class IAppExceptionCallback : public IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.AppExceptionCallback");
|
||||
|
||||
/**
|
||||
* Notify abilityManager lifecycle exception.
|
||||
*
|
||||
* @param type lifecycle failed type
|
||||
* @param token associated ability
|
||||
*/
|
||||
virtual void OnLifecycleException(LifecycleException type, sptr<IRemoteObject> token) {}
|
||||
|
||||
enum class Message {
|
||||
LIFECYCLE_EXCEPTION_MSG_ID = 0,
|
||||
};
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_I_APP_EXCEPTION_CALLBACK_H
|
@ -1320,5 +1320,27 @@ bool AmsMgrProxy::IsAppKilling(sptr<IRemoteObject> token)
|
||||
}
|
||||
return reply.ReadBool();
|
||||
}
|
||||
|
||||
void AmsMgrProxy::SetAppExceptionCallback(sptr<IRemoteObject> callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback.GetRefPtr())) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Failed to write callback");
|
||||
return;
|
||||
}
|
||||
|
||||
auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::SET_APP_EXCEPTION_CALLBACK),
|
||||
data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Send request failed, error code is %{public}d.", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -855,5 +855,12 @@ int32_t AmsMgrStub::HandleIsAppKilling(MessageParcel &data, MessageParcel &reply
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t AmsMgrStub::HandleSetAppExceptionCallback(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<IRemoteObject> callback = data.ReadRemoteObject();
|
||||
SetAppExceptionCallback(callback);
|
||||
return NO_ERROR;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "app_exception_callback_proxy.h"
|
||||
|
||||
#include "hilog_tag_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
AppExceptionCallbackProxy::AppExceptionCallbackProxy(const sptr<IRemoteObject> &impl)
|
||||
: IRemoteProxy<IAppExceptionCallback>(impl) {}
|
||||
|
||||
bool AppExceptionCallbackProxy::WriteInterfaceToken(MessageParcel &data)
|
||||
{
|
||||
if (!data.WriteInterfaceToken(AppExceptionCallbackProxy::GetDescriptor())) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "write interface token failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t AppExceptionCallbackProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
|
||||
MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Remote is nullptr.");
|
||||
return ERR_NULL_OBJECT;
|
||||
}
|
||||
|
||||
auto ret = remote->SendRequest(code, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with error code: %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AppExceptionCallbackProxy::OnLifecycleException(LifecycleException type, sptr<IRemoteObject> token)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_ASYNC);
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t exceptionType = static_cast<int32_t>(type);
|
||||
if (!data.WriteInt32(exceptionType)) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Failed to write exceptionType");
|
||||
return;
|
||||
}
|
||||
|
||||
if (token) {
|
||||
if (!data.WriteBool(true) || !data.WriteRemoteObject(token.GetRefPtr())) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag and token");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!data.WriteBool(false)) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ret = SendTransactCmd(
|
||||
static_cast<uint32_t>(IAppExceptionCallback::Message::LIFECYCLE_EXCEPTION_MSG_ID), data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
|
||||
}
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "app_exception_callback_stub.h"
|
||||
|
||||
#include "hilog_tag_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
int32_t AppExceptionCallbackStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
std::u16string descriptor = AppExceptionCallbackStub::GetDescriptor();
|
||||
std::u16string remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (descriptor != remoteDescriptor) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "local descriptor is not equal to remote");
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
switch (code) {
|
||||
case static_cast<uint32_t>(IAppExceptionCallback::Message::LIFECYCLE_EXCEPTION_MSG_ID):
|
||||
return HandleLifecycleException(data, reply);
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t AppExceptionCallbackStub::HandleLifecycleException(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
auto type = data.ReadInt32();
|
||||
if (type < 0 || type > static_cast<int32_t>(LifecycleException::END)) {
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
auto lifecycleExceptType = static_cast<LifecycleException>(type);
|
||||
sptr<IRemoteObject> token;
|
||||
if (data.ReadBool()) {
|
||||
token = data.ReadRemoteObject();
|
||||
}
|
||||
OnLifecycleException(lifecycleExceptType, token);
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "app_exception_manager.h"
|
||||
|
||||
#include "freeze_util.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
using AbilityRuntime::FreezeUtil;
|
||||
namespace AppExecFwk {
|
||||
AppExceptionManager &AppExceptionManager::GetInstance()
|
||||
{
|
||||
static AppExceptionManager appExceptionMgr;
|
||||
return appExceptionMgr;
|
||||
}
|
||||
|
||||
void AppExceptionManager::LaunchAbilityFailed(sptr<IRemoteObject> token, const std::string &msg)
|
||||
{
|
||||
FreezeUtil::LifecycleFlow flow{token, FreezeUtil::TimeoutState::LOAD};
|
||||
FreezeUtil::GetInstance().AppendLifecycleEvent(flow, std::string("LaunchAbilityFailed: " + msg));
|
||||
NotifyLifecycleException(LifecycleException::LAUNCH_ABILITY_FAIL, token);
|
||||
}
|
||||
|
||||
void AppExceptionManager::ForegroundAppFailed(sptr<IRemoteObject> token, const std::string &msg)
|
||||
{
|
||||
FreezeUtil::LifecycleFlow flow{token, FreezeUtil::TimeoutState::FOREGROUND};
|
||||
FreezeUtil::GetInstance().AppendLifecycleEvent(flow, std::string("ForegroundAppFailed: " + msg));
|
||||
NotifyLifecycleException(LifecycleException::FOREGROUND_APP_FAIL, token);
|
||||
}
|
||||
|
||||
void AppExceptionManager::ForegroundAppWait(sptr<IRemoteObject> token, const std::string &msg)
|
||||
{
|
||||
FreezeUtil::LifecycleFlow flow{token, FreezeUtil::TimeoutState::FOREGROUND};
|
||||
FreezeUtil::GetInstance().AppendLifecycleEvent(flow, std::string("ForegroundAppWait: " + msg));
|
||||
NotifyLifecycleException(LifecycleException::FOREGROUND_APP_WAIT, token);
|
||||
}
|
||||
|
||||
void AppExceptionManager::NotifyLifecycleException(LifecycleException type, sptr<IRemoteObject> token)
|
||||
{
|
||||
auto callback = GetExceptionCallback();
|
||||
if (callback != nullptr) {
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "notify app exception");
|
||||
callback->OnLifecycleException(type, token);
|
||||
}
|
||||
}
|
||||
|
||||
void AppExceptionManager::SetExceptionCallback(sptr<IAppExceptionCallback> exceptionCallback)
|
||||
{
|
||||
if (exceptionCallback == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "callback null");
|
||||
}
|
||||
std::lock_guard lock(exceptionCallbackMutex_);
|
||||
if (exceptionCallback_ != nullptr) {
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "inner callback not null");
|
||||
}
|
||||
exceptionCallback_ = exceptionCallback;
|
||||
}
|
||||
|
||||
sptr<IAppExceptionCallback> AppExceptionManager::GetExceptionCallback() const
|
||||
{
|
||||
std::lock_guard lock(exceptionCallbackMutex_);
|
||||
return exceptionCallback_;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "app_scheduler_proxy.h"
|
||||
|
||||
#include "app_exception_manager.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "ipc_types.h"
|
||||
@ -35,14 +36,14 @@ bool AppSchedulerProxy::WriteInterfaceToken(MessageParcel &data)
|
||||
return true;
|
||||
}
|
||||
|
||||
void AppSchedulerProxy::ScheduleForegroundApplication()
|
||||
bool AppSchedulerProxy::ScheduleForegroundApplication()
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "AppSchedulerProxy::ScheduleForegroundApplication start");
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_ASYNC);
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
int32_t ret =
|
||||
SendTransactCmd(static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_FOREGROUND_APPLICATION_TRANSACTION),
|
||||
@ -51,7 +52,9 @@ void AppSchedulerProxy::ScheduleForegroundApplication()
|
||||
option);
|
||||
if (ret != NO_ERROR) {
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void AppSchedulerProxy::ScheduleBackgroundApplication()
|
||||
@ -214,6 +217,8 @@ void AppSchedulerProxy::ScheduleLaunchAbility(const AbilityInfo &info, const spt
|
||||
static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_LAUNCH_ABILITY_TRANSACTION), data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
|
||||
AppExceptionManager::GetInstance().LaunchAbilityFailed(token, std::string("SendRequest is failed") +
|
||||
std::to_string(ret));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ public:
|
||||
* @param targetState Indicates the lifecycle state.
|
||||
* @param sessionInfo Indicates the session info.
|
||||
*/
|
||||
void ScheduleAbilityTransaction(
|
||||
bool ScheduleAbilityTransaction(
|
||||
const Want &want, const LifeCycleStateInfo &targetState, sptr<SessionInfo> sessionInfo = nullptr) override;
|
||||
|
||||
/**
|
||||
|
@ -63,7 +63,7 @@ public:
|
||||
* @param targetState Indicates the lifecycle state.
|
||||
* @param sessionInfo Indicates the session info.
|
||||
*/
|
||||
void ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
|
||||
bool ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
|
||||
sptr<AAFwk::SessionInfo> sessionInfo = nullptr) override;
|
||||
|
||||
/**
|
||||
|
@ -71,7 +71,7 @@ public:
|
||||
* @param targetState Indicates the lifecycle state.
|
||||
* @param sessionInfo Indicates the session info.
|
||||
*/
|
||||
void ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
|
||||
bool ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
|
||||
sptr<AAFwk::SessionInfo> sessionInfo = nullptr) override;
|
||||
|
||||
/**
|
||||
@ -563,7 +563,7 @@ 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_;
|
||||
|
@ -76,7 +76,7 @@ public:
|
||||
* @param targetState Indicates the lifecycle state.
|
||||
* @param sessionInfo Indicates the session info.
|
||||
*/
|
||||
void ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
|
||||
bool ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
|
||||
sptr<AAFwk::SessionInfo> sessionInfo = nullptr) override;
|
||||
|
||||
/**
|
||||
|
@ -134,7 +134,7 @@ public:
|
||||
* @brief Schedule the foreground lifecycle of application.
|
||||
*
|
||||
*/
|
||||
void ScheduleForegroundApplication() override;
|
||||
bool ScheduleForegroundApplication() override;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -28,6 +28,7 @@ abilityms_files = [
|
||||
"src/ability_manager_xcollie.cpp",
|
||||
"src/ability_scheduler_proxy.cpp",
|
||||
"src/ability_token_stub.cpp",
|
||||
"src/app_exception_handler.cpp",
|
||||
"src/app_scheduler.cpp",
|
||||
"src/app_exit_reason_helper.cpp",
|
||||
"src/assert_fault_callback_death_mgr.cpp",
|
||||
|
@ -1118,6 +1118,16 @@ public:
|
||||
return securityFlag_;
|
||||
}
|
||||
|
||||
FreezeStrategy GetFreezeStrategy() const
|
||||
{
|
||||
return freezeStrategy_;
|
||||
}
|
||||
|
||||
void SetFreezeStrategy(FreezeStrategy value)
|
||||
{
|
||||
freezeStrategy_ = value;
|
||||
}
|
||||
|
||||
protected:
|
||||
void SendEvent(uint32_t msg, uint32_t timeOut, int32_t param = -1, bool isExtension = false);
|
||||
|
||||
@ -1343,6 +1353,7 @@ private:
|
||||
LaunchDebugInfo launchDebugInfo_;
|
||||
std::string instanceKey_ = "";
|
||||
bool securityFlag_ = false;
|
||||
std::atomic<FreezeStrategy> freezeStrategy_{FreezeStrategy::NOTIFY_FREEZE_MGR};
|
||||
};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
* @param Want, Special Want for service type's ability.
|
||||
* @param stateInfo, The lifecycle state to be transformed.
|
||||
*/
|
||||
void ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &stateInfo,
|
||||
bool ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &stateInfo,
|
||||
sptr<SessionInfo> sessionInfo = nullptr) override;
|
||||
|
||||
/*
|
||||
|
38
services/abilitymgr/include/app_exception_handler.h
Normal file
38
services/abilitymgr/include/app_exception_handler.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_APP_EXCEPTION_HANDLER_H
|
||||
#define OHOS_ABILITY_RUNTIME_APP_EXCEPTION_HANDLER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "iremote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
class AppExceptionHandler {
|
||||
public:
|
||||
static AppExceptionHandler &GetInstance();
|
||||
AppExceptionHandler(AppExceptionHandler &) = delete;
|
||||
void operator=(AppExceptionHandler &) = delete;
|
||||
|
||||
void RegisterAppExceptionCallback();
|
||||
void AbilityForegroundFailed(sptr<IRemoteObject> token, const std::string &msg);
|
||||
private:
|
||||
AppExceptionHandler() = default;
|
||||
};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_APP_EXCEPTION_HANDLER_H
|
@ -73,7 +73,7 @@ public:
|
||||
/**
|
||||
* schedule ability life cycle to foreground
|
||||
*/
|
||||
void ForegroundNew(const Want &want, LifeCycleStateInfo &stateInfo,
|
||||
bool ForegroundNew(const Want &want, LifeCycleStateInfo &stateInfo,
|
||||
sptr<SessionInfo> sessionInfo = nullptr);
|
||||
/**
|
||||
* schedule ability life cycle to background
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "ability_resident_process_rdb.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "ability_manager_xcollie.h"
|
||||
#include "app_exception_handler.h"
|
||||
#include "app_utils.h"
|
||||
#include "app_exit_reason_data_manager.h"
|
||||
#include "application_util.h"
|
||||
@ -3660,8 +3661,8 @@ int AbilityManagerService::CloseUIAbilityBySCB(const sptr<SessionInfo> &sessionI
|
||||
abilityRecord->GetPid(), true));
|
||||
} else {
|
||||
IN_PROCESS_CALL_WITHOUT_RET(DelayedSingleton<AppScheduler>::GetInstance()->SetProcessCacheStatus(
|
||||
abilityRecord->GetPid(), false));
|
||||
}
|
||||
abilityRecord->GetPid(), false));
|
||||
}
|
||||
EventInfo eventInfo;
|
||||
eventInfo.bundleName = abilityRecord->GetAbilityInfo().bundleName;
|
||||
eventInfo.abilityName = abilityRecord->GetAbilityInfo().name;
|
||||
@ -7119,6 +7120,7 @@ void AbilityManagerService::ConnectServices()
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "failed init appScheduler");
|
||||
usleep(REPOLL_TIME_MICRO_SECONDS);
|
||||
}
|
||||
AppExceptionHandler::GetInstance().RegisterAppExceptionCallback();
|
||||
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR, "waiting bundleMgr service run completed");
|
||||
while (AbilityUtil::GetBundleManagerHelper() == nullptr) {
|
||||
@ -12031,7 +12033,7 @@ int32_t AbilityManagerService::CleanUIAbilityBySCB(const sptr<SessionInfo> &sess
|
||||
abilityRecord->GetPid(), true));
|
||||
} else {
|
||||
IN_PROCESS_CALL_WITHOUT_RET(DelayedSingleton<AppScheduler>::GetInstance()->SetProcessCacheStatus(
|
||||
abilityRecord->GetPid(), false));
|
||||
abilityRecord->GetPid(), false));
|
||||
}
|
||||
int32_t errCode = uiAbilityManager->CleanUIAbility(abilityRecord, forceKillProcess);
|
||||
ReportCleanSession(sessionInfo, abilityRecord, errCode);
|
||||
@ -12134,7 +12136,7 @@ void AbilityManagerService::SetAbilityRequestSessionInfo(AbilityRequest &ability
|
||||
auto sceneSessionManager = Rosen::SessionManagerLite::GetInstance().
|
||||
GetSceneSessionManagerLiteProxy();
|
||||
CHECK_POINTER_LOG(sceneSessionManager, "sceneSessionManager is nullptr");
|
||||
auto err = sceneSessionManager->GetRootMainWindowId(static_cast<int32_t>(callerSessionInfo->hostWindowId),mainWindowId);
|
||||
auto err = sceneSessionManager->GetRootMainWindowId(static_cast<int32_t>(callerSessionInfo->hostWindowId),mainWindowId);
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR, "callerSessionInfo->hostWindowId = %{public}d, mainWindowId = %{public}d, err = %{public}d",
|
||||
callerSessionInfo->hostWindowId, mainWindowId, err);
|
||||
abilityRequest.want.SetParam(WANT_PARAMS_HOST_WINDOW_ID_KEY, mainWindowId);
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "ability_manager_service.h"
|
||||
#include "ability_resident_process_rdb.h"
|
||||
#include "ability_scheduler_stub.h"
|
||||
#include "app_exception_handler.h"
|
||||
#include "app_exit_reason_data_manager.h"
|
||||
#include "app_utils.h"
|
||||
#include "array_wrapper.h"
|
||||
@ -398,7 +399,9 @@ void AbilityRecord::ForegroundAbility(uint32_t sceneFlag)
|
||||
lifeCycleStateInfo_.sceneFlag = sceneFlag;
|
||||
Want want = GetWant();
|
||||
UpdateDmsCallerInfo(want);
|
||||
lifecycleDeal_->ForegroundNew(want, lifeCycleStateInfo_, GetSessionInfo());
|
||||
if (!lifecycleDeal_->ForegroundNew(want, lifeCycleStateInfo_, GetSessionInfo()) && token_) {
|
||||
AppExceptionHandler::GetInstance().AbilityForegroundFailed(token_->AsObject(), "ForegroundNew");
|
||||
}
|
||||
lifeCycleStateInfo_.sceneFlag = 0;
|
||||
lifeCycleStateInfo_.sceneFlagBak = 0;
|
||||
{
|
||||
@ -494,6 +497,7 @@ void AbilityRecord::RemoveForegroundTimeoutTask()
|
||||
CHECK_POINTER(handler);
|
||||
handler->RemoveEvent(AbilityManagerService::FOREGROUND_HALF_TIMEOUT_MSG, GetAbilityRecordId());
|
||||
handler->RemoveEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, GetAbilityRecordId());
|
||||
SetFreezeStrategy(FreezeStrategy::NOTIFY_FREEZE_MGR);
|
||||
}
|
||||
|
||||
void AbilityRecord::RemoveLoadTimeoutTask()
|
||||
@ -502,6 +506,7 @@ void AbilityRecord::RemoveLoadTimeoutTask()
|
||||
CHECK_POINTER(handler);
|
||||
handler->RemoveEvent(AbilityManagerService::LOAD_HALF_TIMEOUT_MSG, GetAbilityRecordId());
|
||||
handler->RemoveEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, GetAbilityRecordId());
|
||||
SetFreezeStrategy(FreezeStrategy::NOTIFY_FREEZE_MGR);
|
||||
}
|
||||
|
||||
void AbilityRecord::PostUIExtensionAbilityTimeoutTask(uint32_t messageId)
|
||||
|
@ -39,7 +39,7 @@ bool AbilitySchedulerProxy::WriteInterfaceToken(MessageParcel &data)
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbilitySchedulerProxy::ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &stateInfo,
|
||||
bool AbilitySchedulerProxy::ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &stateInfo,
|
||||
sptr<SessionInfo> sessionInfo)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
@ -50,26 +50,27 @@ void AbilitySchedulerProxy::ScheduleAbilityTransaction(const Want &want, const L
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_ASYNC);
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteParcelable(&want)) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "write want failed");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
data.WriteParcelable(&stateInfo);
|
||||
if (sessionInfo) {
|
||||
if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "write sessionInfo failed");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!data.WriteBool(false)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_ABILITY_TRANSACTION, data, reply, option);
|
||||
if (err != NO_ERROR) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
|
||||
return false;
|
||||
}
|
||||
int64_t cost = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch()).count() - start;
|
||||
@ -82,6 +83,7 @@ void AbilitySchedulerProxy::ScheduleAbilityTransaction(const Want &want, const L
|
||||
"ScheduleAbilityTransaction proxy cost %{public}" PRId64 "mirco seconds, data size: %{public}zu",
|
||||
cost, data.GetWritePosition());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbilitySchedulerProxy::ScheduleShareData(const int32_t &uniqueId)
|
||||
|
88
services/abilitymgr/src/app_exception_handler.cpp
Normal file
88
services/abilitymgr/src/app_exception_handler.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "app_exception_handler.h"
|
||||
|
||||
#include "ability_record.h"
|
||||
#include "app_exception_callback_stub.h"
|
||||
#include "app_mgr_util.h"
|
||||
#include "freeze_util.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
using AppExecFwk::LifecycleException;
|
||||
using AbilityRuntime::FreezeUtil;
|
||||
namespace AAFwk {
|
||||
namespace {
|
||||
class AppExceptionCallback : public AppExecFwk::AppExceptionCallbackStub {
|
||||
/**
|
||||
* Notify abilityManager lifecycle exception.
|
||||
*
|
||||
* @param type lifecycle failed type
|
||||
* @param token associated ability
|
||||
*/
|
||||
void OnLifecycleException(LifecycleException type, sptr<IRemoteObject> token) override
|
||||
{
|
||||
auto abilityRecord = Token::GetAbilityRecordByToken(token);
|
||||
if (abilityRecord == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR, "abilityRecord null");
|
||||
return;
|
||||
}
|
||||
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR, "lifecycle exception: %{public}s, %{public}d",
|
||||
abilityRecord->GetURI().c_str(), type);
|
||||
abilityRecord->SetFreezeStrategy(FreezeStrategy::NOTIFY_FREEZE_MGR);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
AppExceptionHandler &AppExceptionHandler::GetInstance()
|
||||
{
|
||||
static AppExceptionHandler appExceptionHandler;
|
||||
return appExceptionHandler;
|
||||
}
|
||||
|
||||
void AppExceptionHandler::RegisterAppExceptionCallback()
|
||||
{
|
||||
auto appMgr = AppMgrUtil::GetAppMgr();
|
||||
if (appMgr == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR, "AppMgrUtil::GetAppMgr failed");
|
||||
return;
|
||||
}
|
||||
|
||||
auto service = appMgr->GetAmsMgr();
|
||||
if (service == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR, "GetAmsMgr failed");
|
||||
return;
|
||||
}
|
||||
auto callback = sptr<AppExceptionCallback>(new AppExceptionCallback());
|
||||
service->SetAppExceptionCallback(callback->AsObject());
|
||||
}
|
||||
|
||||
void AppExceptionHandler::AbilityForegroundFailed(sptr<IRemoteObject> token, const std::string &msg)
|
||||
{
|
||||
auto abilityRecord = Token::GetAbilityRecordByToken(token);
|
||||
if (abilityRecord == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR, "abilityRecord null");
|
||||
return;
|
||||
}
|
||||
FreezeUtil::LifecycleFlow flow{token, FreezeUtil::TimeoutState::FOREGROUND};
|
||||
FreezeUtil::GetInstance().AppendLifecycleEvent(flow, std::string("AbilityForegroundFailed: " + msg));
|
||||
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR, "AbilityForegroundFailed: %{public}s", abilityRecord->GetURI().c_str());
|
||||
abilityRecord->SetFreezeStrategy(FreezeStrategy::NOTIFY_FREEZE_MGR);
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
@ -126,17 +126,17 @@ void LifecycleDeal::RestoreAbilityState(const PacMap &inState)
|
||||
abilityScheduler->ScheduleRestoreAbilityState(inState);
|
||||
}
|
||||
|
||||
void LifecycleDeal::ForegroundNew(const Want &want, LifeCycleStateInfo &stateInfo,
|
||||
bool LifecycleDeal::ForegroundNew(const Want &want, LifeCycleStateInfo &stateInfo,
|
||||
sptr<SessionInfo> sessionInfo)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR, "call");
|
||||
auto abilityScheduler = GetScheduler();
|
||||
CHECK_POINTER(abilityScheduler);
|
||||
CHECK_POINTER_AND_RETURN(abilityScheduler, false);
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR, "caller %{public}s, %{public}s",
|
||||
stateInfo.caller.bundleName.c_str(),
|
||||
stateInfo.caller.abilityName.c_str());
|
||||
stateInfo.state = AbilityLifeCycleState::ABILITY_STATE_FOREGROUND_NEW;
|
||||
abilityScheduler->ScheduleAbilityTransaction(want, stateInfo, sessionInfo);
|
||||
return abilityScheduler->ScheduleAbilityTransaction(want, stateInfo, sessionInfo);
|
||||
}
|
||||
|
||||
void LifecycleDeal::BackgroundNew(const Want &want, LifeCycleStateInfo &stateInfo,
|
||||
|
@ -2212,11 +2212,7 @@ void MissionListManager::PostMissionLabelUpdateTask(int missionId) const
|
||||
#endif // SUPPORT_SCREEN
|
||||
void MissionListManager::PrintTimeOutLog(const std::shared_ptr<AbilityRecord> &ability, uint32_t msgId, bool isHalf)
|
||||
{
|
||||
if (ability == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "ability null");
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK_POINTER_LOG(ability, "ability null");
|
||||
AppExecFwk::RunningProcessInfo processInfo = {};
|
||||
DelayedSingleton<AppScheduler>::GetInstance()->GetRunningProcessInfoByToken(ability->GetToken(), processInfo);
|
||||
if (processInfo.pid_ == 0) {
|
||||
@ -2234,9 +2230,8 @@ void MissionListManager::PrintTimeOutLog(const std::shared_ptr<AbilityRecord> &a
|
||||
|
||||
std::string eventName = isHalf ?
|
||||
AppExecFwk::AppFreezeType::LIFECYCLE_HALF_TIMEOUT : AppExecFwk::AppFreezeType::LIFECYCLE_TIMEOUT;
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR,
|
||||
"%{public}s: uid: %{public}d, pid: %{public}d, bundleName: %{public}s, abilityName: %{public}s,"
|
||||
"msg: %{public}s!",
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR, "%{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());
|
||||
|
||||
@ -2246,8 +2241,8 @@ void MissionListManager::PrintTimeOutLog(const std::shared_ptr<AbilityRecord> &a
|
||||
.eventName = eventName,
|
||||
.bundleName = ability->GetAbilityInfo().bundleName,
|
||||
};
|
||||
FreezeUtil::LifecycleFlow flow;
|
||||
if (state != FreezeUtil::TimeoutState::UNKNOWN) {
|
||||
FreezeUtil::LifecycleFlow flow;
|
||||
if (ability->GetToken() != nullptr) {
|
||||
flow.token = ability->GetToken()->AsObject();
|
||||
flow.state = state;
|
||||
@ -2256,10 +2251,13 @@ void MissionListManager::PrintTimeOutLog(const std::shared_ptr<AbilityRecord> &a
|
||||
if (!isHalf) {
|
||||
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
|
||||
}
|
||||
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info, flow);
|
||||
} else {
|
||||
info.msg = msgContent;
|
||||
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info);
|
||||
}
|
||||
if (ability->GetFreezeStrategy() == FreezeStrategy::NOTIFY_FREEZE_MGR) {
|
||||
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info, flow);
|
||||
} else {
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR, "%{public}s", info.msg.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1100,10 +1100,7 @@ void UIAbilityLifecycleManager::NotifyAbilityToken(const sptr<IRemoteObject> &to
|
||||
|
||||
void UIAbilityLifecycleManager::PrintTimeOutLog(std::shared_ptr<AbilityRecord> ability, uint32_t msgId, bool isHalf)
|
||||
{
|
||||
if (ability == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "null ability");
|
||||
return;
|
||||
}
|
||||
CHECK_POINTER_LOG(ability, "null ability");
|
||||
AppExecFwk::RunningProcessInfo processInfo = {};
|
||||
DelayedSingleton<AppScheduler>::GetInstance()->GetRunningProcessInfoByToken(ability->GetToken(), processInfo);
|
||||
if (processInfo.pid_ == 0) {
|
||||
@ -1120,9 +1117,8 @@ void UIAbilityLifecycleManager::PrintTimeOutLog(std::shared_ptr<AbilityRecord> a
|
||||
|
||||
std::string eventName = isHalf ?
|
||||
AppExecFwk::AppFreezeType::LIFECYCLE_HALF_TIMEOUT : AppExecFwk::AppFreezeType::LIFECYCLE_TIMEOUT;
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR,
|
||||
"%{public}s: uid: %{public}d, pid: %{public}d, bundleName: %{public}s, abilityName: %{public}s,"
|
||||
"msg: %{public}s",
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR, "%{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());
|
||||
|
||||
@ -1133,8 +1129,8 @@ void UIAbilityLifecycleManager::PrintTimeOutLog(std::shared_ptr<AbilityRecord> a
|
||||
.bundleName = ability->GetAbilityInfo().bundleName,
|
||||
};
|
||||
FreezeUtil::TimeoutState state = MsgId2State(msgId);
|
||||
FreezeUtil::LifecycleFlow flow;
|
||||
if (state != FreezeUtil::TimeoutState::UNKNOWN) {
|
||||
FreezeUtil::LifecycleFlow flow;
|
||||
if (ability->GetToken() != nullptr) {
|
||||
flow.token = ability->GetToken()->AsObject();
|
||||
flow.state = state;
|
||||
@ -1143,10 +1139,13 @@ void UIAbilityLifecycleManager::PrintTimeOutLog(std::shared_ptr<AbilityRecord> a
|
||||
if (!isHalf) {
|
||||
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
|
||||
}
|
||||
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info, flow);
|
||||
} else {
|
||||
info.msg = msgContent;
|
||||
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info);
|
||||
}
|
||||
if (ability->GetFreezeStrategy() == FreezeStrategy::NOTIFY_FREEZE_MGR) {
|
||||
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info, flow);
|
||||
} else {
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR, "%{public}s", info.msg.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -417,6 +417,8 @@ public:
|
||||
|
||||
virtual bool IsAppKilling(sptr<IRemoteObject> token) override;
|
||||
|
||||
virtual void SetAppExceptionCallback(sptr<IRemoteObject> callback) override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Judge whether the application service is ready.
|
||||
|
@ -84,9 +84,9 @@ public:
|
||||
* ScheduleForegroundRunning, call ScheduleForegroundApplication() through proxy project,
|
||||
* Notify application to switch to foreground.
|
||||
*
|
||||
* @return
|
||||
* @return bool operation status
|
||||
*/
|
||||
void ScheduleForegroundRunning();
|
||||
bool ScheduleForegroundRunning();
|
||||
|
||||
/**
|
||||
* ScheduleBackgroundRunning, call ScheduleBackgroundApplication() through proxy project,
|
||||
|
@ -944,9 +944,9 @@ public:
|
||||
/**
|
||||
* ScheduleForegroundRunning, Notify application to switch to foreground.
|
||||
*
|
||||
* @return
|
||||
* @return bool operation status
|
||||
*/
|
||||
void ScheduleForegroundRunning();
|
||||
bool ScheduleForegroundRunning();
|
||||
|
||||
/**
|
||||
* ScheduleBackgroundRunning, Notify application to switch to background.
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "accesstoken_kit.h"
|
||||
#include "app_death_recipient.h"
|
||||
#include "app_exception_manager.h"
|
||||
#include "app_mgr_constants.h"
|
||||
#include "app_utils.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
@ -734,5 +735,25 @@ bool AmsMgrScheduler::IsAppKilling(sptr<IRemoteObject> token)
|
||||
}
|
||||
return amsMgrServiceInner_->IsAppKilling(token);
|
||||
}
|
||||
|
||||
void AmsMgrScheduler::SetAppExceptionCallback(sptr<IRemoteObject> callback)
|
||||
{
|
||||
if (!IsReady()) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "AmsMgrService is not ready.");
|
||||
return;
|
||||
}
|
||||
pid_t callingPid = IPCSkeleton::GetCallingPid();
|
||||
pid_t procPid = getprocpid();
|
||||
if (callingPid != procPid) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "not allow other process to call");
|
||||
return;
|
||||
}
|
||||
|
||||
if (callback == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "callback null");
|
||||
}
|
||||
auto exceptionCallback = iface_cast<IAppExceptionCallback>(callback);
|
||||
return AppExceptionManager::GetInstance().SetExceptionCallback(exceptionCallback);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -98,16 +98,16 @@ void AppLifeCycleDeal::ScheduleTerminate(bool isLastProcess)
|
||||
appThread->ScheduleTerminateApplication(isLastProcess);
|
||||
}
|
||||
|
||||
void AppLifeCycleDeal::ScheduleForegroundRunning()
|
||||
bool AppLifeCycleDeal::ScheduleForegroundRunning()
|
||||
{
|
||||
auto appThread = GetApplicationClient();
|
||||
if (!appThread) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "null appThread");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
appThread->ScheduleForegroundApplication();
|
||||
return appThread->ScheduleForegroundApplication();
|
||||
}
|
||||
|
||||
void AppLifeCycleDeal::ScheduleBackgroundRunning()
|
||||
|
@ -1227,13 +1227,14 @@ void AppMgrServiceInner::ApplicationBackgrounded(const int32_t recordId)
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "app name(%{public}s), app state(%{public}d)",
|
||||
appRecord->GetName().c_str(), static_cast<ApplicationState>(appRecord->GetState()));
|
||||
}
|
||||
if (appRecord->GetApplicationPendingState() == ApplicationPendingState::FOREGROUNDING) {
|
||||
auto pendingState = appRecord->GetApplicationPendingState();
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "app backgrounded: %{public}s, pState: %{public}d", appRecord->GetBundleName().c_str(),
|
||||
pendingState);
|
||||
if (pendingState == ApplicationPendingState::FOREGROUNDING) {
|
||||
appRecord->ScheduleForegroundRunning();
|
||||
} else if (appRecord->GetApplicationPendingState() == ApplicationPendingState::BACKGROUNDING) {
|
||||
} else if (pendingState == ApplicationPendingState::BACKGROUNDING) {
|
||||
appRecord->SetApplicationPendingState(ApplicationPendingState::READY);
|
||||
}
|
||||
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "ApplicationBackgrounded, bundle: %{public}s", appRecord->GetBundleName().c_str());
|
||||
auto eventInfo = BuildEventInfo(appRecord);
|
||||
AAFwk::EventReport::SendAppBackgroundEvent(AAFwk::EventName::APP_BACKGROUND, eventInfo);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "ability_window_configuration.h"
|
||||
#include "app_exception_manager.h"
|
||||
#include "app_running_record.h"
|
||||
#include "app_mgr_service_inner.h"
|
||||
#include "event_report.h"
|
||||
@ -661,12 +662,13 @@ void AppRunningRecord::LaunchPendingAbilities()
|
||||
moduleRecord->LaunchPendingAbilities();
|
||||
}
|
||||
}
|
||||
void AppRunningRecord::ScheduleForegroundRunning()
|
||||
bool AppRunningRecord::ScheduleForegroundRunning()
|
||||
{
|
||||
SetApplicationScheduleState(ApplicationScheduleState::SCHEDULE_FOREGROUNDING);
|
||||
if (appLifeCycleDeal_) {
|
||||
appLifeCycleDeal_->ScheduleForegroundRunning();
|
||||
return appLifeCycleDeal_->ScheduleForegroundRunning();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void AppRunningRecord::ScheduleBackgroundRunning()
|
||||
@ -989,8 +991,8 @@ void AppRunningRecord::AbilityForeground(const std::shared_ptr<AbilityRunningRec
|
||||
return;
|
||||
}
|
||||
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "appState: %{public}d, bundle: %{public}s, ability: %{public}s",
|
||||
curState_, mainBundleName_.c_str(), ability->GetName().c_str());
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "appState: %{public}d, pState: %{public}d, bundle: %{public}s, ability: %{public}s",
|
||||
curState_, pendingState_, mainBundleName_.c_str(), ability->GetName().c_str());
|
||||
// We need schedule application to foregrounded when current application state is ready or background running.
|
||||
if (curState_ == ApplicationState::APP_STATE_FOREGROUND
|
||||
&& pendingState_ != ApplicationPendingState::BACKGROUNDING) {
|
||||
@ -1010,11 +1012,14 @@ void AppRunningRecord::AbilityForeground(const std::shared_ptr<AbilityRunningRec
|
||||
}
|
||||
if (curState_ == ApplicationState::APP_STATE_READY || curState_ == ApplicationState::APP_STATE_BACKGROUND
|
||||
|| curState_ == ApplicationState::APP_STATE_FOREGROUND) {
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "application foregrounding.");
|
||||
auto pendingState = pendingState_;
|
||||
SetApplicationPendingState(ApplicationPendingState::FOREGROUNDING);
|
||||
if (pendingState == ApplicationPendingState::READY) {
|
||||
ScheduleForegroundRunning();
|
||||
if (!ScheduleForegroundRunning()) {
|
||||
AppExceptionManager::GetInstance().ForegroundAppFailed(ability->GetToken(), "schedule failed");
|
||||
}
|
||||
} else {
|
||||
AppExceptionManager::GetInstance().ForegroundAppWait(ability->GetToken(), "pendingState not ready");
|
||||
}
|
||||
foregroundingAbilityTokens_.insert(ability->GetToken());
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "foregroundingAbility size: %{public}d",
|
||||
@ -2061,8 +2066,9 @@ void AppRunningRecord::OnWindowVisibilityChanged(
|
||||
}
|
||||
}
|
||||
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "window id empty: %{public}d, pState: %{public}d, cState: %{public}d",
|
||||
windowIds_.empty(), pendingState_, curState_);
|
||||
if (pendingState_ == ApplicationPendingState::READY) {
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "pending state is READY.");
|
||||
if (!windowIds_.empty() && curState_ != ApplicationState::APP_STATE_FOREGROUND) {
|
||||
SetApplicationPendingState(ApplicationPendingState::FOREGROUNDING);
|
||||
ScheduleForegroundRunning();
|
||||
@ -2072,7 +2078,6 @@ void AppRunningRecord::OnWindowVisibilityChanged(
|
||||
ScheduleBackgroundRunning();
|
||||
}
|
||||
} else {
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "not READY");
|
||||
if (!windowIds_.empty()) {
|
||||
SetApplicationPendingState(ApplicationPendingState::FOREGROUNDING);
|
||||
}
|
||||
|
@ -42,9 +42,11 @@ public:
|
||||
AbilitySchedulerStubFuzzTest() = default;
|
||||
virtual ~AbilitySchedulerStubFuzzTest()
|
||||
{};
|
||||
void ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
|
||||
bool ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
|
||||
sptr<SessionInfo> sessionInfo = nullptr) override
|
||||
{}
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void ScheduleShareData(const int32_t &uniqueId) override
|
||||
{}
|
||||
void SendResult(int requestCode, int resultCode, const Want& resultWant) override
|
||||
|
@ -39,9 +39,11 @@ public:
|
||||
AbilitySchedulerFuzzTest() = default;
|
||||
virtual ~AbilitySchedulerFuzzTest()
|
||||
{};
|
||||
void ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
|
||||
bool ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
|
||||
sptr<SessionInfo> sessionInfo = nullptr) override
|
||||
{}
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void ScheduleShareData(const int32_t &uniqueId) override
|
||||
{}
|
||||
void SendResult(int requestCode, int resultCode, const Want& resultWant) override
|
||||
|
@ -48,8 +48,11 @@ public:
|
||||
|
||||
class MockAbilityThread : public IRemoteStub<AAFwk::IAbilityScheduler> {
|
||||
public:
|
||||
virtual void ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
|
||||
sptr<SessionInfo> sessionInfo = nullptr) {};
|
||||
virtual bool ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
|
||||
sptr<SessionInfo> sessionInfo = nullptr)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
virtual void SendResult(int requestCode, int resultCode, const Want& resultWant) {};
|
||||
virtual void ScheduleConnectAbility(const Want& want) {};
|
||||
virtual void ScheduleDisconnectAbility(const Want& want) {};
|
||||
|
@ -29,7 +29,7 @@ class MockAbilitySchedulerStub : public AAFwk::AbilitySchedulerStub {
|
||||
public:
|
||||
MockAbilitySchedulerStub() = default;
|
||||
virtual ~MockAbilitySchedulerStub() = default;
|
||||
MOCK_METHOD3(ScheduleAbilityTransaction, void(const AAFwk::Want&, const AAFwk::LifeCycleStateInfo&,
|
||||
MOCK_METHOD3(ScheduleAbilityTransaction, bool(const AAFwk::Want&, const AAFwk::LifeCycleStateInfo&,
|
||||
sptr<AAFwk::SessionInfo>));
|
||||
MOCK_METHOD1(ScheduleShareData, void(const int32_t &uniqueId));
|
||||
MOCK_METHOD3(SendResult, void(int, int, const AAFwk::Want&));
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
AbilityScheduler();
|
||||
virtual ~AbilityScheduler();
|
||||
|
||||
void ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
|
||||
bool ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
|
||||
sptr<SessionInfo> sessionInfo = nullptr) override;
|
||||
|
||||
void ScheduleShareData(const int32_t &uniqueId) override;
|
||||
|
@ -25,11 +25,12 @@ AbilityScheduler::AbilityScheduler()
|
||||
AbilityScheduler::~AbilityScheduler()
|
||||
{}
|
||||
|
||||
void AbilityScheduler::ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
|
||||
bool AbilityScheduler::ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
|
||||
sptr<SessionInfo> sessionInfo)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "AbilityScheduler ScheduleAbilityTransaction %d", targetState.state);
|
||||
(void)want;
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbilityScheduler::ScheduleShareData(const int32_t &uniqueId)
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
virtual ~AbilitySchedulerMock()
|
||||
{}
|
||||
|
||||
MOCK_METHOD3(ScheduleAbilityTransaction, void(const Want&, const LifeCycleStateInfo&, sptr<SessionInfo>));
|
||||
MOCK_METHOD3(ScheduleAbilityTransaction, bool(const Want&, const LifeCycleStateInfo&, sptr<SessionInfo>));
|
||||
MOCK_METHOD3(SendResult, void(int, int, const Want&));
|
||||
MOCK_METHOD1(ScheduleConnectAbility, void(const Want&));
|
||||
MOCK_METHOD1(ScheduleDisconnectAbility, void(const Want&));
|
||||
|
@ -29,7 +29,7 @@ class MockAppScheduler : public AppSchedulerHost {
|
||||
public:
|
||||
MockAppScheduler() = default;
|
||||
virtual ~MockAppScheduler() = default;
|
||||
MOCK_METHOD0(ScheduleForegroundApplication, void());
|
||||
MOCK_METHOD0(ScheduleForegroundApplication, bool());
|
||||
MOCK_METHOD0(ScheduleBackgroundApplication, void());
|
||||
MOCK_METHOD1(ScheduleTerminateApplication, void(bool));
|
||||
MOCK_METHOD2(ScheduleLaunchApplication, void(const AppLaunchData&, const Configuration& config));
|
||||
|
@ -29,7 +29,7 @@ class MockAppSchedulerClient : public AppSchedulerProxy {
|
||||
public:
|
||||
MockAppSchedulerClient(const sptr<IRemoteObject> &impl) : AppSchedulerProxy(impl) {}
|
||||
virtual ~MockAppSchedulerClient() = default;
|
||||
MOCK_METHOD0(ScheduleForegroundApplication, void());
|
||||
MOCK_METHOD0(ScheduleForegroundApplication, bool());
|
||||
MOCK_METHOD0(ScheduleBackgroundApplication, void());
|
||||
MOCK_METHOD1(ScheduleTerminateApplication, void(bool));
|
||||
MOCK_METHOD2(ScheduleLaunchApplication, void(const AppLaunchData&, const Configuration& config));
|
||||
|
@ -24,7 +24,7 @@ namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class MockApplication : public AppSchedulerHost {
|
||||
public:
|
||||
MOCK_METHOD0(ScheduleForegroundApplication, void());
|
||||
MOCK_METHOD0(ScheduleForegroundApplication, bool());
|
||||
MOCK_METHOD0(ScheduleBackgroundApplication, void());
|
||||
MOCK_METHOD1(ScheduleTerminateApplication, void(bool));
|
||||
MOCK_METHOD1(ScheduleShrinkMemory, void(const int));
|
||||
|
@ -25,7 +25,7 @@ namespace AppExecFwk {
|
||||
class MockApplicationProxy : public AppSchedulerProxy {
|
||||
public:
|
||||
MockApplicationProxy(const sptr<IRemoteObject> &impl) : AppSchedulerProxy(impl) {}
|
||||
MOCK_METHOD0(ScheduleForegroundApplication, void());
|
||||
MOCK_METHOD0(ScheduleForegroundApplication, bool());
|
||||
MOCK_METHOD0(ScheduleBackgroundApplication, void());
|
||||
MOCK_METHOD1(ScheduleTerminateApplication, void(bool));
|
||||
MOCK_METHOD1(ScheduleShrinkMemory, void(const int));
|
||||
|
@ -273,7 +273,7 @@ HWTEST_F(AbilityRecordModuleTest, AbilityScheduler_001, TestSize.Level3)
|
||||
testResult = false;
|
||||
EXPECT_CALL(*mockAbilityScheduerStub, ScheduleAbilityTransaction(_, _, _))
|
||||
.Times(1)
|
||||
.WillOnce(Invoke(mockActivateHandler));
|
||||
.WillOnce(testing::DoAll(Invoke(mockActivateHandler), testing::Return(true)));
|
||||
|
||||
abilityRecord->Activate();
|
||||
EXPECT_TRUE(testResult);
|
||||
@ -287,7 +287,7 @@ HWTEST_F(AbilityRecordModuleTest, AbilityScheduler_001, TestSize.Level3)
|
||||
};
|
||||
EXPECT_CALL(*mockAbilityScheduerStub, ScheduleAbilityTransaction(_, _, _))
|
||||
.Times(1)
|
||||
.WillOnce(Invoke(mockInactivateHandler));
|
||||
.WillOnce(testing::DoAll(Invoke(mockInactivateHandler), testing::Return(true)));
|
||||
|
||||
abilityRecord->Inactivate();
|
||||
EXPECT_TRUE(testResult);
|
||||
|
@ -71,9 +71,10 @@ protected:
|
||||
|
||||
class MockedApplication : public AppSchedulerHost, public MockedSchedulerBase {
|
||||
public:
|
||||
void ScheduleForegroundApplication() override
|
||||
bool ScheduleForegroundApplication() override
|
||||
{
|
||||
scheduled_ |= FOREGROUND_SCHEDULED;
|
||||
return true;
|
||||
}
|
||||
void ScheduleBackgroundApplication() override
|
||||
{
|
||||
|
@ -41,8 +41,10 @@ namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class TestAppSchedulerImpl : public AppSchedulerHost {
|
||||
public:
|
||||
void ScheduleForegroundApplication() override
|
||||
{}
|
||||
bool ScheduleForegroundApplication() override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void ScheduleBackgroundApplication() override
|
||||
{}
|
||||
void ScheduleTerminateApplication(bool isLastProcess = false) override
|
||||
|
@ -218,7 +218,10 @@ HWTEST_F(AppRunningProcessesInfoModuleTest, ApplicationStart_001, TestSize.Level
|
||||
|
||||
EXPECT_CALL(*mockApplication, ScheduleForegroundApplication())
|
||||
.Times(1)
|
||||
.WillOnce(InvokeWithoutArgs(mockApplication.GetRefPtr(), &MockApplicationProxy::Post));
|
||||
.WillOnce([mockApplication]() {
|
||||
mockApplication->Post();
|
||||
return true;
|
||||
});
|
||||
// application enter in foreground and check the result
|
||||
record->ScheduleForegroundRunning();
|
||||
mockApplication->Wait();
|
||||
@ -280,7 +283,10 @@ HWTEST_F(AppRunningProcessesInfoModuleTest, ApplicationStart_002, TestSize.Level
|
||||
|
||||
EXPECT_CALL(*mockApplication, ScheduleForegroundApplication())
|
||||
.Times(1)
|
||||
.WillOnce(InvokeWithoutArgs(mockApplication.GetRefPtr(), &MockApplicationProxy::Post));
|
||||
.WillOnce([mockApplication]() {
|
||||
mockApplication->Post();
|
||||
return true;
|
||||
});
|
||||
// application enter in foreground and check the result
|
||||
record->ScheduleForegroundRunning();
|
||||
mockApplication->Wait();
|
||||
@ -344,7 +350,10 @@ HWTEST_F(AppRunningProcessesInfoModuleTest, ApplicationStart_003, TestSize.Level
|
||||
|
||||
EXPECT_CALL(*mockApplication, ScheduleForegroundApplication())
|
||||
.Times(1)
|
||||
.WillOnce(InvokeWithoutArgs(mockApplication.GetRefPtr(), &MockApplicationProxy::Post));
|
||||
.WillOnce([mockApplication]() {
|
||||
mockApplication->Post();
|
||||
return true;
|
||||
});
|
||||
// application enter in foreground and check the result
|
||||
record->ScheduleForegroundRunning();
|
||||
mockApplication->Wait();
|
||||
@ -424,7 +433,10 @@ HWTEST_F(AppRunningProcessesInfoModuleTest, ApplicationStart_004, TestSize.Level
|
||||
|
||||
EXPECT_CALL(*mockApplication, ScheduleForegroundApplication())
|
||||
.Times(1)
|
||||
.WillOnce(InvokeWithoutArgs(mockApplication.GetRefPtr(), &MockApplicationProxy::Post));
|
||||
.WillOnce([mockApplication]() {
|
||||
mockApplication->Post();
|
||||
return true;
|
||||
});
|
||||
// application enter in foreground and check the result
|
||||
record->ScheduleForegroundRunning();
|
||||
mockApplication->Wait();
|
||||
@ -488,7 +500,10 @@ HWTEST_F(AppRunningProcessesInfoModuleTest, ApplicationStart_005, TestSize.Level
|
||||
|
||||
EXPECT_CALL(*mockApplication, ScheduleForegroundApplication())
|
||||
.Times(1)
|
||||
.WillOnce(InvokeWithoutArgs(mockApplication.GetRefPtr(), &MockApplicationProxy::Post));
|
||||
.WillOnce([mockApplication]() {
|
||||
mockApplication->Post();
|
||||
return true;
|
||||
});
|
||||
// application enter in foreground and check the result
|
||||
record->ScheduleForegroundRunning();
|
||||
mockApplication->Wait();
|
||||
@ -550,7 +565,10 @@ HWTEST_F(AppRunningProcessesInfoModuleTest, ApplicationStart_006, TestSize.Level
|
||||
|
||||
EXPECT_CALL(*mockApplication, ScheduleForegroundApplication())
|
||||
.Times(1)
|
||||
.WillOnce(InvokeWithoutArgs(mockApplication.GetRefPtr(), &MockApplicationProxy::Post));
|
||||
.WillOnce([mockApplication]() {
|
||||
mockApplication->Post();
|
||||
return true;
|
||||
});
|
||||
// application enter in foreground and check the result
|
||||
record->ScheduleForegroundRunning();
|
||||
mockApplication->Wait();
|
||||
|
@ -212,7 +212,10 @@ HWTEST_F(AmsAppRunningRecordModuleTest, ApplicationStart_001, TestSize.Level1)
|
||||
|
||||
EXPECT_CALL(*mockApplication, ScheduleForegroundApplication())
|
||||
.Times(1)
|
||||
.WillOnce(InvokeWithoutArgs(mockApplication.GetRefPtr(), &MockApplication::Post));
|
||||
.WillOnce([mockApplication]() {
|
||||
mockApplication->Post();
|
||||
return true;
|
||||
});
|
||||
// application enter in foreground and check the result
|
||||
record->ScheduleForegroundRunning();
|
||||
mockApplication->Wait();
|
||||
@ -419,7 +422,10 @@ HWTEST_F(AmsAppRunningRecordModuleTest, ApplicationStartAndQuit_005, TestSize.Le
|
||||
|
||||
EXPECT_CALL(*mockApplication, ScheduleForegroundApplication())
|
||||
.Times(1)
|
||||
.WillOnce(InvokeWithoutArgs(mockApplication.GetRefPtr(), &MockApplication::Post));
|
||||
.WillOnce([mockApplication]() {
|
||||
mockApplication->Post();
|
||||
return true;
|
||||
});
|
||||
// set foreground and update foreground state
|
||||
record->ScheduleForegroundRunning();
|
||||
mockApplication->Wait();
|
||||
@ -490,7 +496,10 @@ HWTEST_F(AmsAppRunningRecordModuleTest, ApplicationStatusChange_006, TestSize.Le
|
||||
for (int i = 0; i < startCount; i++) {
|
||||
EXPECT_CALL(*mockApplication, ScheduleForegroundApplication())
|
||||
.Times(1)
|
||||
.WillOnce(InvokeWithoutArgs(mockApplication.GetRefPtr(), &MockApplication::Post));
|
||||
.WillOnce([mockApplication]() {
|
||||
mockApplication->Post();
|
||||
return true;
|
||||
});
|
||||
// set foreground and update foreground state
|
||||
record->ScheduleForegroundRunning();
|
||||
mockApplication->Wait();
|
||||
|
@ -76,7 +76,10 @@ HWTEST_F(AmsIpcAppSchedulerModuleTest, ExcuteApplicationIPCInterface_001, TestSi
|
||||
|
||||
EXPECT_CALL(*mockApplication, ScheduleForegroundApplication())
|
||||
.Times(1)
|
||||
.WillOnce(InvokeWithoutArgs(mockApplication.GetRefPtr(), &MockApplication::Post));
|
||||
.WillOnce([mockApplication]() {
|
||||
mockApplication->Post();
|
||||
return true;
|
||||
});
|
||||
client->ScheduleForegroundApplication();
|
||||
mockApplication->Wait();
|
||||
}
|
||||
|
@ -93,7 +93,8 @@ HWTEST_F(IpcAbilitySchedulerModuleTest, ScheduleAbilityTransaction_001, TestSize
|
||||
sem.Post();
|
||||
};
|
||||
|
||||
EXPECT_CALL(*stub, ScheduleAbilityTransaction(_, _, _)).Times(1).WillOnce(Invoke(stubHandler));
|
||||
EXPECT_CALL(*stub, ScheduleAbilityTransaction(_, _, _)).Times(1)
|
||||
.WillOnce(testing::DoAll(Invoke(stubHandler), testing::Return(true)));
|
||||
|
||||
proxy->ScheduleAbilityTransaction(proxyState.want, proxyState.lifeCycleStateInfo);
|
||||
|
||||
|
@ -25,7 +25,7 @@ namespace OHOS {
|
||||
namespace AAFwk {
|
||||
class MockAbilityScheduler : public IAbilityScheduler {
|
||||
public:
|
||||
MOCK_METHOD3(ScheduleAbilityTransaction, void(const Want& want, const LifeCycleStateInfo& targetState,
|
||||
MOCK_METHOD3(ScheduleAbilityTransaction, bool(const Want& want, const LifeCycleStateInfo& targetState,
|
||||
sptr<SessionInfo> sessionInfo));
|
||||
MOCK_METHOD1(ScheduleShareData, void(const int32_t &uniqueId));
|
||||
MOCK_METHOD3(SendResult, void(int requestCode, int resultCode, const Want& resultWant));
|
||||
|
@ -22,7 +22,7 @@ namespace OHOS {
|
||||
namespace AAFwk {
|
||||
class MockAbilitySchedulerStub : public AbilitySchedulerStub {
|
||||
public:
|
||||
MOCK_METHOD3(ScheduleAbilityTransaction, void(const Want&, const LifeCycleStateInfo&, sptr<SessionInfo>));
|
||||
MOCK_METHOD3(ScheduleAbilityTransaction, bool(const Want&, const LifeCycleStateInfo&, sptr<SessionInfo>));
|
||||
MOCK_METHOD1(ScheduleShareData, void(const int32_t &uniqueId));
|
||||
MOCK_METHOD3(SendResult, void(int, int, const Want&));
|
||||
MOCK_METHOD1(ScheduleConnectAbility, void(const Want&));
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
MockAppScheduler() = default;
|
||||
virtual ~MockAppScheduler() = default;
|
||||
|
||||
MOCK_METHOD0(ScheduleForegroundApplication, void());
|
||||
MOCK_METHOD0(ScheduleForegroundApplication, bool());
|
||||
MOCK_METHOD0(ScheduleBackgroundApplication, void());
|
||||
MOCK_METHOD1(ScheduleTerminateApplication, void(bool));
|
||||
MOCK_METHOD2(ScheduleLaunchApplication, void(const AppExecFwk::AppLaunchData&, const Configuration& config));
|
||||
|
@ -21,9 +21,11 @@ namespace OHOS {
|
||||
namespace AAFwk {
|
||||
class AbilitySchedulerStubMock : public AbilitySchedulerStub {
|
||||
public:
|
||||
void ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
|
||||
bool ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
|
||||
sptr<SessionInfo> sessionInfo = nullptr) override
|
||||
{}
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScheduleShareData(const int32_t &uniqueId) override
|
||||
{}
|
||||
|
@ -73,7 +73,10 @@ HWTEST_F(AmsIpcAppSchedulerInterfaceTest, Interface_001, TestSize.Level1)
|
||||
|
||||
EXPECT_CALL(*mockApplication, ScheduleForegroundApplication())
|
||||
.Times(1)
|
||||
.WillOnce(InvokeWithoutArgs(mockApplication.GetRefPtr(), &MockApplication::Post));
|
||||
.WillOnce([mockApplication]() {
|
||||
mockApplication->Post();
|
||||
return true;
|
||||
});
|
||||
client->ScheduleForegroundApplication();
|
||||
mockApplication->Wait();
|
||||
TAG_LOGD(AAFwkTag::TEST, "AppSchedulerInterfaceTest_001 end");
|
||||
|
@ -272,7 +272,10 @@ HWTEST_F(AppRunningProcessesInfoTest, UpdateAppRunningRecord_002, TestSize.Level
|
||||
|
||||
EXPECT_CALL(*mockApplication, ScheduleForegroundApplication())
|
||||
.Times(1)
|
||||
.WillOnce(InvokeWithoutArgs(mockApplication.GetRefPtr(), &MockApplicationProxy::Post));
|
||||
.WillOnce([mockApplication]() {
|
||||
mockApplication->Post();
|
||||
return true;
|
||||
});
|
||||
// application enter in foreground and check the result
|
||||
record->ScheduleForegroundRunning();
|
||||
mockApplication->Wait();
|
||||
|
@ -60,7 +60,7 @@ HWTEST_F(LifecycleDealTest, LifecycleDeal_oprator_001, TestSize.Level1)
|
||||
LifeCycleStateInfo val;
|
||||
EXPECT_CALL(*abilityScheduler_, ScheduleAbilityTransaction(::testing::_, ::testing::_, ::testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(testing::SaveArg<1>(&val));
|
||||
.WillOnce(testing::DoAll(testing::SaveArg<1>(&val), testing::Return(true)));
|
||||
|
||||
const Want want;
|
||||
CallerInfo caller;
|
||||
@ -92,7 +92,7 @@ HWTEST_F(LifecycleDealTest, LifecycleDeal_oprator_002, TestSize.Level1)
|
||||
LifeCycleStateInfo val;
|
||||
EXPECT_CALL(*abilityScheduler_, ScheduleAbilityTransaction(::testing::_, ::testing::_, ::testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(testing::SaveArg<1>(&val));
|
||||
.WillOnce(testing::DoAll(testing::SaveArg<1>(&val), testing::Return(true)));
|
||||
|
||||
const Want want;
|
||||
CallerInfo caller;
|
||||
@ -124,7 +124,7 @@ HWTEST_F(LifecycleDealTest, LifecycleDeal_oprator_003, TestSize.Level1)
|
||||
LifeCycleStateInfo val;
|
||||
EXPECT_CALL(*abilityScheduler_, ScheduleAbilityTransaction(::testing::_, ::testing::_, ::testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(testing::SaveArg<1>(&val));
|
||||
.WillOnce(testing::DoAll(testing::SaveArg<1>(&val), testing::Return(true)));
|
||||
|
||||
const Want want;
|
||||
CallerInfo caller;
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
static FreezeUtil& GetInstance();
|
||||
|
||||
void AddLifecycleEvent(const LifecycleFlow &flow, const std::string &entry);
|
||||
bool AppendLifecycleEvent(const LifecycleFlow &flow, const std::string &entry);
|
||||
std::string GetLifecycleEvent(const LifecycleFlow &flow);
|
||||
void DeleteLifecycleEvent(const LifecycleFlow &flow);
|
||||
void DeleteLifecycleEvent(sptr<IRemoteObject> token);
|
||||
|
@ -29,13 +29,26 @@ void FreezeUtil::AddLifecycleEvent(const LifecycleFlow &flow, const std::string
|
||||
{
|
||||
auto newEntry = TimeUtil::DefaultCurrentTimeStr() + "; " + entry;
|
||||
std::lock_guard lock(mutex_);
|
||||
if (lifecycleFlow_.count(flow)) {
|
||||
lifecycleFlow_[flow] = lifecycleFlow_[flow] + "\n" + newEntry;
|
||||
auto iter = lifecycleFlow_.find(flow);
|
||||
if (iter != lifecycleFlow_.end()) {
|
||||
iter->second += "\n" + newEntry;
|
||||
} else {
|
||||
lifecycleFlow_[flow] = newEntry;
|
||||
lifecycleFlow_.emplace(flow, newEntry);
|
||||
}
|
||||
}
|
||||
|
||||
bool FreezeUtil::AppendLifecycleEvent(const LifecycleFlow &flow, const std::string &entry)
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
auto iter = lifecycleFlow_.find(flow);
|
||||
if (iter == lifecycleFlow_.end()) {
|
||||
return false;
|
||||
}
|
||||
auto newEntry = TimeUtil::DefaultCurrentTimeStr() + "; " + entry;
|
||||
iter->second += "\n" + newEntry;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string FreezeUtil::GetLifecycleEvent(const LifecycleFlow &flow)
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
|
@ -28,6 +28,7 @@ constexpr int64_t NANOSECONDS = 1000000000;
|
||||
constexpr int64_t MICROSECONDS = 1000000;
|
||||
constexpr int64_t SEC_TO_MILLISEC = 1000;
|
||||
constexpr int64_t MAX_TIME_BUFF = 64; // 64 : for example 2021-05-27-01-01-01
|
||||
constexpr int32_t DECIMAL_BASE = 10;
|
||||
|
||||
[[maybe_unused]] static int64_t SystemTimeMillisecond()
|
||||
{
|
||||
@ -60,7 +61,13 @@ constexpr int64_t MAX_TIME_BUFF = 64; // 64 : for example 2021-05-27-01-01-01
|
||||
localtime_r(&tt, &t);
|
||||
char buffer[MAX_TIME_BUFF] = {0};
|
||||
std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &t);
|
||||
return std::string(buffer) + "." + std::to_string(timestamp % SEC_TO_MILLISEC);
|
||||
auto remainder = timestamp % SEC_TO_MILLISEC;
|
||||
std::string milliStr("000");
|
||||
for (int i = 2; i >= 0 && remainder > 0; i--) {
|
||||
milliStr[i] = '0' + remainder % DECIMAL_BASE;
|
||||
remainder /= DECIMAL_BASE;
|
||||
}
|
||||
return std::string(buffer) + "." + milliStr;
|
||||
}
|
||||
} // namespace TimeUtil
|
||||
} // namespace OHOS::AbilityRuntime
|
||||
|
Loading…
Reference in New Issue
Block a user