mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-23 15:20:34 +00:00
!5535 UIAbility预关闭
Merge pull request !5535 from donglin/prepare_terminate
This commit is contained in:
commit
58b634897a
@ -25,6 +25,9 @@ class Ability {
|
||||
onWindowStageDestroy() { }
|
||||
onForeground(want) { }
|
||||
onBackground() { }
|
||||
onPrepareToTerminate() {
|
||||
return false;
|
||||
}
|
||||
onMemoryLevel(level) { }
|
||||
onWindowStageRestore(windowStage) { }
|
||||
onCallRequest() {
|
||||
|
@ -1596,6 +1596,12 @@ void Ability::OnBackground()
|
||||
HiSysEventType::BEHAVIOR, eventInfo);
|
||||
}
|
||||
|
||||
bool Ability::OnPrepareTerminate()
|
||||
{
|
||||
HILOG_DEBUG("call");
|
||||
return false;
|
||||
}
|
||||
|
||||
void Ability::OnKeyDown(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
|
||||
{
|
||||
HILOG_DEBUG("Ability::OnKeyDown called");
|
||||
|
@ -299,6 +299,18 @@ void AbilityImpl::CommandAbility(const Want &want, bool restart, int startId)
|
||||
HILOG_DEBUG("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
bool AbilityImpl::PrepareTerminateAbility()
|
||||
{
|
||||
HILOG_DEBUG("call");
|
||||
if (ability_ == nullptr) {
|
||||
HILOG_ERROR("ability_ is nullptr.");
|
||||
return false;
|
||||
}
|
||||
bool ret = ability_->OnPrepareTerminate();
|
||||
HILOG_DEBUG("end, ret = %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int AbilityImpl::GetCurrentState()
|
||||
{
|
||||
return lifecycleState_;
|
||||
|
@ -496,6 +496,23 @@ void JsAbility::OnBackground()
|
||||
HILOG_DEBUG("OnBackground end, ability is %{public}s.", GetAbilityName().c_str());
|
||||
}
|
||||
|
||||
bool JsAbility::OnPrepareTerminate()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("call, ability: %{public}s.", GetAbilityName().c_str());
|
||||
Ability::OnPrepareTerminate();
|
||||
|
||||
NativeValue *jsValue = CallObjectMethod("onPrepareToTerminate", nullptr, 0, true);
|
||||
auto numberValue = ConvertNativeValueTo<NativeBoolean>(jsValue);
|
||||
if (numberValue == nullptr) {
|
||||
HILOG_ERROR("numberValue is nullptr.");
|
||||
return false;
|
||||
}
|
||||
bool ret = (bool)(*numberValue);
|
||||
HILOG_DEBUG("end, ret = %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::unique_ptr<NativeReference> JsAbility::CreateAppWindowStage()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
|
@ -808,6 +808,18 @@ void AbilityThread::ScheduleCommandAbility(const Want &want, bool restart, int s
|
||||
HILOG_DEBUG("AbilityThread::ScheduleCommandAbility end");
|
||||
}
|
||||
|
||||
bool AbilityThread::SchedulePrepareTerminateAbility()
|
||||
{
|
||||
HILOG_DEBUG("call");
|
||||
if (abilityImpl_ == nullptr) {
|
||||
HILOG_ERROR("abilityImpl_ is nullptr.");
|
||||
return true;
|
||||
}
|
||||
bool ret = abilityImpl_->PrepareTerminateAbility();
|
||||
HILOG_DEBUG("end, ret = %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AbilityThread::SendResult(int requestCode, int resultCode, const Want &want)
|
||||
{
|
||||
HILOG_DEBUG("AbilityThread::SendResult begin");
|
||||
|
@ -32,6 +32,7 @@ config("ability_manager_public_config") {
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native",
|
||||
"${bundlefwk_inner_api_path}/appexecfwk_base/include",
|
||||
"${bundlefwk_inner_api_path}/appexecfwk_core/include/bundlemgr",
|
||||
"${ability_runtime_innerkits_path}/ability_manager/include",
|
||||
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit",
|
||||
@ -83,6 +84,8 @@ ohos_shared_library("ability_manager") {
|
||||
"${ability_runtime_services_path}/abilitymgr/src/mission_listener_proxy.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/mission_listener_stub.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/mission_snapshot.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/prepare_terminate_callback_proxy.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/prepare_terminate_callback_stub.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/remote_mission_listener_proxy.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/remote_mission_listener_stub.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/sender_info.cpp",
|
||||
|
@ -754,6 +754,14 @@ public:
|
||||
*/
|
||||
ErrCode RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler);
|
||||
|
||||
/**
|
||||
* PrepareTerminateAbility with want, if terminate, return want from ability manager service.
|
||||
*
|
||||
* @param token Ability token.
|
||||
* @param callback callback.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode PrepareTerminateAbility(const sptr<IRemoteObject> &token, sptr<IPrepareTerminateCallback> &callback);
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
/**
|
||||
* Set mission label of this ability.
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "iability_controller.h"
|
||||
#include "iacquire_share_data_callback_interface.h"
|
||||
#include "icomponent_interception.h"
|
||||
#include "iprepare_terminate_callback_interface.h"
|
||||
#include "mission_listener_interface.h"
|
||||
#include "mission_info.h"
|
||||
#include "mission_snapshot.h"
|
||||
@ -674,6 +675,18 @@ public:
|
||||
* @param abilityToken Indidate token of ability.
|
||||
*/
|
||||
virtual void CompleteFirstFrameDrawing(const sptr<IRemoteObject> &abilityToken) = 0;
|
||||
|
||||
/**
|
||||
* PrepareTerminateAbility, prepare terminate the special ability.
|
||||
*
|
||||
* @param token, the token of the ability to terminate.
|
||||
* @param callback callback.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int PrepareTerminateAbility(const sptr<IRemoteObject> &token, sptr<IPrepareTerminateCallback> &callback)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual int GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info) = 0;
|
||||
@ -1131,6 +1144,9 @@ public:
|
||||
// ipc id for set rootSceneSession (64)
|
||||
SET_ROOTSSCENESESSION,
|
||||
|
||||
// prepare terminate ability (65)
|
||||
PREPARE_TERMINATE_ABILITY,
|
||||
|
||||
// ipc id 1001-2000 for DMS
|
||||
// ipc id for starting ability (1001)
|
||||
START_ABILITY = 1001,
|
||||
|
@ -87,6 +87,11 @@ public:
|
||||
*/
|
||||
virtual void ScheduleCommandAbility(const Want &want, bool restart, int startId) = 0;
|
||||
|
||||
/**
|
||||
* SchedulePrepareTerminateAbility, schedule ability to prepare terminate.
|
||||
*/
|
||||
virtual bool SchedulePrepareTerminateAbility() = 0;
|
||||
|
||||
/*
|
||||
* ScheduleSaveAbilityState, scheduling save ability state.
|
||||
*/
|
||||
@ -377,7 +382,10 @@ public:
|
||||
|
||||
SCHEDULE_CALL,
|
||||
|
||||
SCHEDULE_SHARE_DATA
|
||||
SCHEDULE_SHARE_DATA,
|
||||
|
||||
// ipc id for scheduling service ability to prepare terminate (30)
|
||||
SCHEDULE_ABILITY_PREPARE_TERMINATE
|
||||
};
|
||||
};
|
||||
} // namespace AAFwk
|
||||
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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_PREPARE_TERMINATE_CALLBACK_INTERFACE_H
|
||||
#define OHOS_ABILITY_RUNTIME_PREPARE_TERMINATE_CALLBACK_INTERFACE_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
class IPrepareTerminateCallback : public OHOS::IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.aafwk.prepareTerminateCallback");
|
||||
virtual void DoPrepareTerminate() {};
|
||||
enum {
|
||||
// ipc id for DoPrepareTerminate (1)
|
||||
ON_DO_PREPARE_TERMINATE = 1,
|
||||
CODE_MAX
|
||||
};
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_PREPARE_TERMINATE_CALLBACK_INTERFACE_H
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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_PREPARE_TERMINATE_CALLBACK_PROXY_H
|
||||
#define OHOS_ABILITY_RUNTIME_PREPARE_TERMINATE_CALLBACK_PROXY_H
|
||||
|
||||
#include "iremote_proxy.h"
|
||||
#include "iprepare_terminate_callback_interface.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
class PrepareTerminateCallbackProxy : public IRemoteProxy<IPrepareTerminateCallback> {
|
||||
public:
|
||||
explicit PrepareTerminateCallbackProxy
|
||||
(const sptr<IRemoteObject> &impl) : IRemoteProxy<IPrepareTerminateCallback>(impl) {}
|
||||
|
||||
virtual ~PrepareTerminateCallbackProxy() {}
|
||||
|
||||
virtual void DoPrepareTerminate() override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<PrepareTerminateCallbackProxy> delegator_;
|
||||
};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_PREPARE_TERMINATE_CALLBACK_PROXY_H
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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_PREPARE_TERMINATE_CALLBACK_STUB_H
|
||||
#define OHOS_ABILITY_RUNTIME_PREPARE_TERMINATE_CALLBACK_STUB_H
|
||||
|
||||
#include <map>
|
||||
#include "iprepare_terminate_callback_interface.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "message_parcel.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
class PrepareTerminateCallbackStub : public IRemoteStub<IPrepareTerminateCallback> {
|
||||
public:
|
||||
PrepareTerminateCallbackStub();
|
||||
virtual ~PrepareTerminateCallbackStub();
|
||||
int OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
|
||||
private:
|
||||
int DoPrepareTerminateInner(MessageParcel &data, MessageParcel &reply);
|
||||
using RequestFuncType = int (PrepareTerminateCallbackStub::*)(MessageParcel &data, MessageParcel &reply);
|
||||
std::map<uint32_t, RequestFuncType> requestFuncMap_;
|
||||
};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_PREPARE_TERMINATE_CALLBACK_STUB_H
|
@ -878,6 +878,13 @@ public:
|
||||
*/
|
||||
virtual void OnBackground();
|
||||
|
||||
/**
|
||||
* @brief Called when ability prepare terminate.
|
||||
*
|
||||
* @return Return true if ability need to stop terminating; return false if ability need to terminate.
|
||||
*/
|
||||
virtual bool OnPrepareTerminate();
|
||||
|
||||
/**
|
||||
* @brief Called when a key is pressed. When any component in the Ability gains focus, the key-down event for
|
||||
* the component will be handled first. This callback will not be invoked if the callback triggered for the
|
||||
|
@ -71,6 +71,13 @@ public:
|
||||
*/
|
||||
void CommandAbility(const Want &want, bool restart, int startId);
|
||||
|
||||
/**
|
||||
* @brief Prepare terminate the ability.
|
||||
*
|
||||
* @return Return true if ability need be terminated; return false if ability need stop terminating.
|
||||
*/
|
||||
bool PrepareTerminateAbility();
|
||||
|
||||
/**
|
||||
* @brief Gets the current Ability status.
|
||||
*
|
||||
|
@ -78,6 +78,7 @@ public:
|
||||
|
||||
void OnForeground(const Want &want) override;
|
||||
void OnBackground() override;
|
||||
bool OnPrepareTerminate() override;
|
||||
|
||||
std::shared_ptr<NativeReference> GetJsWindowStage();
|
||||
const JsRuntime& GetJsRuntime();
|
||||
|
@ -154,6 +154,11 @@ public:
|
||||
*/
|
||||
void ScheduleCommandAbility(const Want &want, bool restart, int startId);
|
||||
|
||||
/**
|
||||
* @description: Provide operating system PrepareTerminateAbility information to the observer
|
||||
*/
|
||||
bool SchedulePrepareTerminateAbility();
|
||||
|
||||
/**
|
||||
* @description: Provide operating system SaveabilityState information to the observer
|
||||
*/
|
||||
|
@ -561,6 +561,9 @@ public:
|
||||
virtual int RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler) override;
|
||||
|
||||
virtual void CompleteFirstFrameDrawing(const sptr<IRemoteObject> &abilityToken) override;
|
||||
|
||||
virtual int PrepareTerminateAbility(
|
||||
const sptr<IRemoteObject> &token, sptr<IPrepareTerminateCallback> &callback) override;
|
||||
#endif
|
||||
|
||||
virtual int GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info) override;
|
||||
|
@ -768,6 +768,9 @@ public:
|
||||
|
||||
sptr<IWindowManagerServiceHandler> GetWMSHandler() const;
|
||||
|
||||
virtual int PrepareTerminateAbility(const sptr<IRemoteObject> &token,
|
||||
sptr<IPrepareTerminateCallback> &callback) override;
|
||||
|
||||
void HandleFocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo);
|
||||
|
||||
void HandleUnfocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo);
|
||||
|
@ -185,6 +185,7 @@ private:
|
||||
int SetMissionIconInner(MessageParcel &data, MessageParcel &reply);
|
||||
int RegisterWindowManagerServiceHandlerInner(MessageParcel &data, MessageParcel &reply);
|
||||
int CompleteFirstFrameDrawingInner(MessageParcel &data, MessageParcel &reply);
|
||||
int PrepareTerminateAbilityInner(MessageParcel &data, MessageParcel &reply);
|
||||
#endif
|
||||
|
||||
#ifdef ABILITY_COMMAND_FOR_TEST
|
||||
|
@ -329,6 +329,13 @@ public:
|
||||
*/
|
||||
void BackgroundAbility(const Closure &task);
|
||||
|
||||
/**
|
||||
* prepare terminate ability.
|
||||
*
|
||||
* @return Returns true on stop terminating; returns false on terminate.
|
||||
*/
|
||||
bool PrepareTerminateAbility();
|
||||
|
||||
/**
|
||||
* terminate ability.
|
||||
*
|
||||
|
@ -85,6 +85,11 @@ public:
|
||||
*/
|
||||
void ScheduleCommandAbility(const Want &want, bool restart, int startId) override;
|
||||
|
||||
/*
|
||||
* SchedulePrepareTerminateAbility, schedule service ability to prepare terminate.
|
||||
*/
|
||||
bool SchedulePrepareTerminateAbility() override;
|
||||
|
||||
/*
|
||||
* ScheduleSaveAbilityState, scheduling save ability state.
|
||||
*/
|
||||
|
@ -42,6 +42,7 @@ private:
|
||||
int ConnectAbilityInner(MessageParcel &data, MessageParcel &reply);
|
||||
int DisconnectAbilityInner(MessageParcel &data, MessageParcel &reply);
|
||||
int CommandAbilityInner(MessageParcel &data, MessageParcel &reply);
|
||||
int PrepareTerminateAbilityInner(MessageParcel &data, MessageParcel &reply);
|
||||
int SaveAbilityStateInner(MessageParcel &data, MessageParcel &reply);
|
||||
int RestoreAbilityStateInner(MessageParcel &data, MessageParcel &reply);
|
||||
int GetFileTypesInner(MessageParcel &data, MessageParcel &reply);
|
||||
|
@ -61,6 +61,7 @@ public:
|
||||
void ContinueAbility(const std::string& deviceId, uint32_t versionCode);
|
||||
void NotifyContinuationResult(int32_t result);
|
||||
void ShareData(const int32_t &uniqueId);
|
||||
bool PrepareTerminateAbility();
|
||||
|
||||
private:
|
||||
sptr<IAbilityScheduler> GetScheduler();
|
||||
|
@ -839,6 +839,21 @@ void AbilityManagerClient::CompleteFirstFrameDrawing(const sptr<IRemoteObject> &
|
||||
CHECK_POINTER_RETURN(abms);
|
||||
abms->CompleteFirstFrameDrawing(abilityToken);
|
||||
}
|
||||
|
||||
ErrCode AbilityManagerClient::PrepareTerminateAbility(const sptr<IRemoteObject> &token,
|
||||
sptr<IPrepareTerminateCallback> &callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
HILOG_ERROR("callback is nullptr.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
auto abms = GetAbilityManager();
|
||||
if (abms == nullptr) {
|
||||
HILOG_ERROR("abms is nullptr.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
return abms->PrepareTerminateAbility(token, callback);
|
||||
}
|
||||
#endif
|
||||
|
||||
ErrCode AbilityManagerClient::DoAbilityForeground(const sptr<IRemoteObject> &token, uint32_t flag)
|
||||
|
@ -2743,6 +2743,51 @@ void AbilityManagerProxy::CompleteFirstFrameDrawing(const sptr<IRemoteObject> &a
|
||||
HILOG_ERROR("%{public}s: send request error: %{public}d", __func__, error);
|
||||
}
|
||||
}
|
||||
|
||||
int AbilityManagerProxy::PrepareTerminateAbility(const sptr<IRemoteObject> &token,
|
||||
sptr<IPrepareTerminateCallback> &callback)
|
||||
{
|
||||
if (!callback) {
|
||||
HILOG_ERROR("callback is nullptr.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
int error = 0;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
HILOG_ERROR("write interface token failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
if (token) {
|
||||
if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
|
||||
HILOG_ERROR("write token failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
} else {
|
||||
if (!data.WriteBool(false)) {
|
||||
HILOG_ERROR("write token failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
HILOG_ERROR("weite callback failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
HILOG_ERROR("remote is nullptr.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
error = remote->SendRequest(IAbilityManager::PREPARE_TERMINATE_ABILITY, data, reply, option);
|
||||
if (error != NO_ERROR) {
|
||||
HILOG_ERROR("send request failed. error: %{public}d", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
#endif
|
||||
|
||||
int AbilityManagerProxy::GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info)
|
||||
|
@ -138,6 +138,7 @@ const int32_t GET_PARAMETER_OTHER = -1;
|
||||
const int32_t SIZE_10 = 10;
|
||||
const int32_t ACCOUNT_MGR_SERVICE_UID = 3058;
|
||||
const int32_t DMS_UID = 5522;
|
||||
const int32_t PREPARE_TERMINATE_TIMEOUT_MULTIPLE = 10;
|
||||
const std::string BUNDLE_NAME_KEY = "bundleName";
|
||||
const std::string DM_PKG_NAME = "ohos.distributedhardware.devicemanager";
|
||||
const std::string ACTION_CHOOSE = "ohos.want.action.select";
|
||||
@ -6232,6 +6233,53 @@ bool AbilityManagerService::CheckWindowMode(int32_t windowMode,
|
||||
return false;
|
||||
}
|
||||
|
||||
int AbilityManagerService::PrepareTerminateAbility(const sptr<IRemoteObject> &token,
|
||||
sptr<IPrepareTerminateCallback> &callback)
|
||||
{
|
||||
HILOG_DEBUG("call");
|
||||
if (callback == nullptr) {
|
||||
HILOG_ERROR("callback is nullptr.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
auto abilityRecord = Token::GetAbilityRecordByToken(token);
|
||||
if (abilityRecord == nullptr) {
|
||||
HILOG_ERROR("record is nullptr.");
|
||||
callback->DoPrepareTerminate();
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
if (!JudgeSelfCalled(abilityRecord)) {
|
||||
HILOG_ERROR("Not self call.");
|
||||
callback->DoPrepareTerminate();
|
||||
return CHECK_PERMISSION_FAILED;
|
||||
}
|
||||
|
||||
auto type = abilityRecord->GetAbilityInfo().type;
|
||||
if (type != AppExecFwk::AbilityType::PAGE) {
|
||||
HILOG_ERROR("Only support PAGE.");
|
||||
callback->DoPrepareTerminate();
|
||||
return RESOLVE_CALL_ABILITY_TYPE_ERR;
|
||||
}
|
||||
|
||||
auto timeoutTask = [&callback]() {
|
||||
callback->DoPrepareTerminate();
|
||||
};
|
||||
int prepareTerminateTimeout =
|
||||
AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * PREPARE_TERMINATE_TIMEOUT_MULTIPLE;
|
||||
if (handler_) {
|
||||
handler_->PostTask(timeoutTask, "PrepareTermiante_" + std::to_string(abilityRecord->GetAbilityRecordId()),
|
||||
prepareTerminateTimeout);
|
||||
}
|
||||
|
||||
bool res = abilityRecord->PrepareTerminateAbility();
|
||||
if (!res) {
|
||||
callback->DoPrepareTerminate();
|
||||
}
|
||||
handler_->RemoveTask("PrepareTermiante_" + std::to_string(abilityRecord->GetAbilityRecordId()));
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void AbilityManagerService::HandleFocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo)
|
||||
{
|
||||
HILOG_INFO("handle focused event");
|
||||
|
@ -167,6 +167,7 @@ void AbilityManagerStub::ThirdStepInit()
|
||||
requestFuncMap_[MINIMIZE_UI_EXTENSION_ABILITY] = &AbilityManagerStub::MinimizeUIExtensionAbilityInner;
|
||||
requestFuncMap_[TERMINATE_UI_EXTENSION_ABILITY] = &AbilityManagerStub::TerminateUIExtensionAbilityInner;
|
||||
requestFuncMap_[CONNECT_UI_EXTENSION_ABILITY] = &AbilityManagerStub::ConnectUIExtensionAbilityInner;
|
||||
requestFuncMap_[PREPARE_TERMINATE_ABILITY] = &AbilityManagerStub::PrepareTerminateAbilityInner;
|
||||
#endif
|
||||
requestFuncMap_[REQUEST_DIALOG_SERVICE] = &AbilityManagerStub::HandleRequestDialogService;
|
||||
requestFuncMap_[SET_COMPONENT_INTERCEPTION] = &AbilityManagerStub::SetComponentInterceptionInner;
|
||||
@ -1965,6 +1966,26 @@ int AbilityManagerStub::CompleteFirstFrameDrawingInner(MessageParcel &data, Mess
|
||||
CompleteFirstFrameDrawing(abilityToken);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AbilityManagerStub::PrepareTerminateAbilityInner(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
HILOG_DEBUG("call");
|
||||
sptr<IRemoteObject> token = nullptr;
|
||||
if (data.ReadBool()) {
|
||||
token = data.ReadRemoteObject();
|
||||
}
|
||||
sptr<IPrepareTerminateCallback> callback = iface_cast<IPrepareTerminateCallback>(data.ReadRemoteObject());
|
||||
if (callback == nullptr) {
|
||||
HILOG_ERROR("callback is nullptr");
|
||||
return ERR_NULL_OBJECT;
|
||||
}
|
||||
int result = PrepareTerminateAbility(token, callback);
|
||||
if (!reply.WriteInt32(result)) {
|
||||
HILOG_ERROR("end faild. err: %{public}d", result);
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t AbilityManagerStub::IsValidMissionIdsInner(MessageParcel &data, MessageParcel &reply)
|
||||
|
@ -1031,6 +1031,16 @@ void AbilityRecord::BackgroundAbility(const Closure &task)
|
||||
lifecycleDeal_->BackgroundNew(want_, lifeCycleStateInfo_, sessionInfo_);
|
||||
}
|
||||
|
||||
bool AbilityRecord::PrepareTerminateAbility()
|
||||
{
|
||||
HILOG_DEBUG("call");
|
||||
if (lifecycleDeal_ == nullptr) {
|
||||
HILOG_ERROR("lifecycleDeal_ is nullptr.");
|
||||
return false;
|
||||
}
|
||||
return lifecycleDeal_->PrepareTerminateAbility();
|
||||
}
|
||||
|
||||
int AbilityRecord::TerminateAbility()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
|
@ -174,6 +174,29 @@ void AbilitySchedulerProxy::ScheduleCommandAbility(const Want &want, bool restar
|
||||
}
|
||||
}
|
||||
|
||||
bool AbilitySchedulerProxy::SchedulePrepareTerminateAbility()
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
HILOG_ERROR("fail to write interface.");
|
||||
return false;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
HILOG_ERROR("Remote() is NULL");
|
||||
return false;
|
||||
}
|
||||
int32_t err = remote->SendRequest(IAbilityScheduler::SCHEDULE_ABILITY_PREPARE_TERMINATE, data, reply, option);
|
||||
if (err != NO_ERROR) {
|
||||
HILOG_ERROR("end failed. err: %{public}d", err);
|
||||
return false;
|
||||
}
|
||||
return reply.ReadBool();
|
||||
}
|
||||
|
||||
void AbilitySchedulerProxy::ScheduleSaveAbilityState()
|
||||
{
|
||||
MessageParcel data;
|
||||
|
@ -38,6 +38,7 @@ AbilitySchedulerStub::AbilitySchedulerStub()
|
||||
requestFuncMap_[SCHEDULE_ABILITY_CONNECT] = &AbilitySchedulerStub::ConnectAbilityInner;
|
||||
requestFuncMap_[SCHEDULE_ABILITY_DISCONNECT] = &AbilitySchedulerStub::DisconnectAbilityInner;
|
||||
requestFuncMap_[SCHEDULE_ABILITY_COMMAND] = &AbilitySchedulerStub::CommandAbilityInner;
|
||||
requestFuncMap_[SCHEDULE_ABILITY_PREPARE_TERMINATE] = &AbilitySchedulerStub::PrepareTerminateAbilityInner;
|
||||
requestFuncMap_[SCHEDULE_SAVE_ABILITY_STATE] = &AbilitySchedulerStub::SaveAbilityStateInner;
|
||||
requestFuncMap_[SCHEDULE_RESTORE_ABILITY_STATE] = &AbilitySchedulerStub::RestoreAbilityStateInner;
|
||||
requestFuncMap_[SCHEDULE_GETFILETYPES] = &AbilitySchedulerStub::GetFileTypesInner;
|
||||
@ -171,6 +172,16 @@ int AbilitySchedulerStub::CommandAbilityInner(MessageParcel &data, MessageParcel
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int AbilitySchedulerStub::PrepareTerminateAbilityInner(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
bool ret = SchedulePrepareTerminateAbility();
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("fail to write ret");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int AbilitySchedulerStub::SaveAbilityStateInner(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
ScheduleSaveAbilityState();
|
||||
|
@ -168,5 +168,15 @@ void LifecycleDeal::ShareData(const int32_t &uniqueId)
|
||||
abilityScheduler->ScheduleShareData(uniqueId);
|
||||
}
|
||||
|
||||
bool LifecycleDeal::PrepareTerminateAbility()
|
||||
{
|
||||
HILOG_DEBUG("call");
|
||||
auto abilityScheduler = GetScheduler();
|
||||
if (abilityScheduler == nullptr) {
|
||||
HILOG_ERROR("abilityScheduler is nullptr.");
|
||||
return false;
|
||||
}
|
||||
return abilityScheduler->SchedulePrepareTerminateAbility();
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
47
services/abilitymgr/src/prepare_terminate_callback_proxy.cpp
Normal file
47
services/abilitymgr/src/prepare_terminate_callback_proxy.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 "ability_manager_errors.h"
|
||||
#include "prepare_terminate_callback_proxy.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "iremote_object.h"
|
||||
#include "message_parcel.h"
|
||||
#include "peer_holder.h"
|
||||
#include "want_params.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
void PrepareTerminateCallbackProxy::DoPrepareTerminate()
|
||||
{
|
||||
HILOG_DEBUG("call");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(IPrepareTerminateCallback::GetDescriptor())) {
|
||||
HILOG_ERROR("Write interface token failed.");
|
||||
return;
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
HILOG_ERROR("Remote() is NULL");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(ON_DO_PREPARE_TERMINATE, data, reply, option);
|
||||
if (error != ERR_OK) {
|
||||
HILOG_ERROR("SendRequest fail, error: %{public}d", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
59
services/abilitymgr/src/prepare_terminate_callback_stub.cpp
Normal file
59
services/abilitymgr/src/prepare_terminate_callback_stub.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 "prepare_terminate_callback_stub.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
|
||||
PrepareTerminateCallbackStub::PrepareTerminateCallbackStub()
|
||||
{
|
||||
requestFuncMap_[ON_DO_PREPARE_TERMINATE] = &PrepareTerminateCallbackStub::DoPrepareTerminateInner;
|
||||
}
|
||||
|
||||
PrepareTerminateCallbackStub::~PrepareTerminateCallbackStub()
|
||||
{
|
||||
HILOG_INFO("call");
|
||||
requestFuncMap_.clear();
|
||||
}
|
||||
|
||||
int32_t PrepareTerminateCallbackStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
if (data.ReadInterfaceToken() != IPrepareTerminateCallback::GetDescriptor()) {
|
||||
HILOG_ERROR("InterfaceToken not equal IPrepareTerminateCallback's descriptor.");
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
auto itFunc = requestFuncMap_.find(code);
|
||||
if (itFunc != requestFuncMap_.end()) {
|
||||
auto requestFunc = itFunc->second;
|
||||
if (requestFunc != nullptr) {
|
||||
return (this->*requestFunc)(data, reply);
|
||||
}
|
||||
}
|
||||
HILOG_WARN("default case, need check.");
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
|
||||
int32_t PrepareTerminateCallbackStub::DoPrepareTerminateInner(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
HILOG_DEBUG("call");
|
||||
DoPrepareTerminate();
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
}
|
@ -48,6 +48,10 @@ public:
|
||||
{}
|
||||
void ScheduleCommandAbility(const Want& want, bool restart, int startId) override
|
||||
{}
|
||||
bool SchedulePrepareTerminateAbility() override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void ScheduleSaveAbilityState() override
|
||||
{}
|
||||
void ScheduleRestoreAbilityState(const PacMap& inState) override
|
||||
|
@ -52,6 +52,10 @@ public:
|
||||
{}
|
||||
void ScheduleCommandAbility(const Want& want, bool restart, int startId) override
|
||||
{}
|
||||
bool SchedulePrepareTerminateAbility() override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
void ScheduleSaveAbilityState() override
|
||||
{}
|
||||
void ScheduleRestoreAbilityState(const PacMap& inState) override
|
||||
|
@ -143,6 +143,10 @@ public:
|
||||
return;
|
||||
};
|
||||
virtual void ScheduleShareData(const int32_t &uniqueId) {};
|
||||
virtual bool SchedulePrepareTerminateAbility()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -35,6 +35,7 @@ public:
|
||||
MOCK_METHOD3(SendResult, void(int, int, const AAFwk::Want&));
|
||||
MOCK_METHOD1(ScheduleConnectAbility, void(const AAFwk::Want&));
|
||||
MOCK_METHOD1(ScheduleDisconnectAbility, void(const AAFwk::Want&));
|
||||
MOCK_METHOD0(SchedulePrepareTerminateAbility, bool());
|
||||
MOCK_METHOD3(ScheduleCommandAbility, void(const AAFwk::Want&, bool, int));
|
||||
MOCK_METHOD0(ScheduleSaveAbilityState, void());
|
||||
MOCK_METHOD1(ScheduleRestoreAbilityState, void(const PacMap&));
|
||||
|
@ -43,6 +43,8 @@ public:
|
||||
|
||||
void ScheduleDisconnectAbility(const Want& want) override;
|
||||
|
||||
bool SchedulePrepareTerminateAbility() override;
|
||||
|
||||
void ScheduleCommandAbility(const Want& want, bool restart, int startId) override;
|
||||
|
||||
void ScheduleSaveAbilityState() override;
|
||||
|
@ -54,6 +54,11 @@ void AbilityScheduler::ScheduleConnectAbility(const Want& want)
|
||||
void AbilityScheduler::ScheduleDisconnectAbility(const Want& want)
|
||||
{}
|
||||
|
||||
bool AbilityScheduler::SchedulePrepareTerminateAbility()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void AbilityScheduler::ScheduleCommandAbility(const Want& want, bool restart, int startId)
|
||||
{}
|
||||
|
||||
|
@ -42,6 +42,7 @@ public:
|
||||
MOCK_METHOD2(ContinueAbility, void(const std::string& deviceId, uint32_t versionCode));
|
||||
MOCK_METHOD2(DumpAbilityInfo, void(const std::vector<std::string>& params, std::vector<std::string>& info));
|
||||
MOCK_METHOD1(ScheduleShareData, void(const int32_t &uniqueId));
|
||||
MOCK_METHOD0(SchedulePrepareTerminateAbility, bool());
|
||||
int InvokeSendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
code_ = code;
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
MOCK_METHOD1(NotifyContinuationResult, void(int32_t result));
|
||||
MOCK_METHOD2(ContinueAbility, void(const std::string& deviceId, uint32_t versionCode));
|
||||
MOCK_METHOD2(DumpAbilityInfo, void(const std::vector<std::string>& params, std::vector<std::string>& info));
|
||||
MOCK_METHOD0(SchedulePrepareTerminateAbility, bool());
|
||||
std::vector<std::string> GetFileTypes(const Uri& uri, const std::string& mimeTypeFilter)
|
||||
{
|
||||
std::vector<std::string> types;
|
||||
|
@ -28,6 +28,7 @@ public:
|
||||
MOCK_METHOD1(ScheduleConnectAbility, void(const Want&));
|
||||
MOCK_METHOD1(ScheduleDisconnectAbility, void(const Want&));
|
||||
MOCK_METHOD3(ScheduleCommandAbility, void(const Want&, bool, int));
|
||||
MOCK_METHOD0(SchedulePrepareTerminateAbility, bool());
|
||||
MOCK_METHOD0(ScheduleSaveAbilityState, void());
|
||||
MOCK_METHOD1(ScheduleRestoreAbilityState, void(const PacMap&));
|
||||
MOCK_METHOD2(GetFileTypes, std::vector<std::string>(const Uri&, const std::string&));
|
||||
|
@ -36,6 +36,11 @@ public:
|
||||
void ScheduleDisconnectAbility(const Want& want) override
|
||||
{}
|
||||
|
||||
bool SchedulePrepareTerminateAbility() override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void ScheduleCommandAbility(const Want& want, bool restart, int startId) override
|
||||
{}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user