接续过程中监听到应用闪退终止接续流程

Signed-off-by: liuhongjie <liuhongjie3@huawei.com>
This commit is contained in:
liuhongjie 2024-06-27 22:13:18 +08:00
parent a985b2c4a4
commit 2458f7f6f6
9 changed files with 79 additions and 1 deletions

View File

@ -458,6 +458,10 @@ enum {
* Result(29360229) for calling StartAbility failed during continuation.
*/
CONTINUE_CALL_START_ABILITY_FAILED = 29360229,
/**
* Result(29360230) for sink Ability abnormal termination during continuation.
*/
CONTINUE_SINK_ABILITY_TERMINATED = 29360230,
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -92,6 +92,7 @@ public:
std::string sinkDeviceId_;
std::string sinkBundleName_;
std::string continueType_;
std::string sinkAbilityName_;
int32_t missionId_ = 0;
};

View File

@ -58,6 +58,7 @@ public:
int32_t GetContinueInfo(std::string &srcDeviceId, std::string &dstDeviceId);
std::shared_ptr<DSchedContinue> GetDSchedContinueByWant(const OHOS::AAFwk::Want& want, int32_t missionId);
std::shared_ptr<DSchedContinue> GetDSchedContinueByDevId(const std::u16string& devId, int32_t missionId);
void NotifyTerminateContinuation(const int32_t missionId);
private:
void StartEvent();

View File

@ -46,6 +46,11 @@ struct lastUnfoInfo {
std::string abilityName;
};
struct AliveMissionInfo {
std::string bundleName;
std::string abilityName;
};
enum class FocusedReason {
MIN = -1,
NORMAL,
@ -115,6 +120,8 @@ public:
void OnDeviceScreenOn();
uint32_t NotifyDeviceOnline();
int32_t SendScreenOffEvent(uint8_t type);
void DeleteAliveMissionInfo(const int32_t missionId);
int32_t GetAliveMissionInfo(const int32_t missionId, AliveMissionInfo& missionInfo);
private:
int32_t GetCurrentMissionId();
@ -150,6 +157,7 @@ private:
std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_;
std::shared_ptr<ScreenOffHandler> screenOffHandler_;
int32_t mmiMonitorId_ = INVALID_MISSION_ID;
std::map<int32_t, AliveMissionInfo> aliveMission_;
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -930,6 +930,7 @@ int32_t DSchedContinue::StartAbility(const OHOS::AAFwk::Want& want, int32_t requ
HILOGI("ExecuteContinueData StartAbility start, flag is %{public}d", want.GetFlags());
DmsRadar::GetInstance().ClickIconDmsStartAbility("StartAbility", ret);
continueInfo_.sinkAbilityName_ = want.GetElement().GetAbilityName();
ret = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, DEFAULT_REQUEST_CODE, activeAccountId);
if (ret != ERR_OK) {
HILOGE("StartAbility failed %{public}d", ret);

View File

@ -25,6 +25,7 @@
#include "dsched_transport_softbus_adapter.h"
#include "dtbschedmgr_device_info_storage.h"
#include "dtbschedmgr_log.h"
#include "mission/dms_continue_send_manager.h"
namespace OHOS {
namespace DistributedSchedule {
@ -325,6 +326,43 @@ std::shared_ptr<DSchedContinue> DSchedContinueManager::GetDSchedContinueByDevId(
return nullptr;
}
void DSchedContinueManager::NotifyTerminateContinuation(const int32_t missionId)
{
HILOGI("begin, missionId %{public}d", missionId);
{
std::lock_guard<std::mutex> continueLock(continueMutex_);
if (continues_.empty()) {
HILOGW("No continuation in progress.");
return;
}
AliveMissionInfo missionInfo;
int32_t ret = DMSContinueSendMgr::GetInstance().GetAliveMissionInfo(missionId, missionInfo);
if (ret != ERR_OK) {
HILOGE("get aliveMissionInfo failed, missionId %{public}d", missionId);
return;
}
HILOGI("alive missionInfo bundleName is %{public}s, abilityName is %{public}s",
missionInfo.bundleName.c_str(), missionInfo.abilityName.c_str());
for (auto iter = continues_.begin(); iter != continues_.end(); iter++) {
if (iter->second == nullptr) {
break;
}
auto continueInfo = iter->second->GetContinueInfo();
HILOGI("continueInfo bundleName is %{public}s, abilityName is %{public}s",
continueInfo.sinkBundleName_.c_str(), continueInfo.sinkAbilityName_.c_str());
if (missionInfo.bundleName == continueInfo.sinkBundleName_
&& missionInfo.abilityName == continueInfo.sinkAbilityName_) {
HILOGE("Excute onContinueEnd");
iter->second->OnContinueEnd(CONTINUE_SINK_ABILITY_TERMINATED);
return;
}
}
}
HILOGW("doesn't match an existing continuation.");
}
int32_t DSchedContinueManager::OnContinueEnd(const DSchedContinueInfo& info)
{
auto func = [this, info]() {

View File

@ -255,9 +255,9 @@ bool DistributedSchedService::Init()
DistributedSchedMissionManager::GetInstance().Init();
DistributedSchedMissionManager::GetInstance().InitDataStorage();
InitCommonEventListener();
InitWifiStateListener();
DMSContinueSendMgr::GetInstance().Init();
DMSContinueRecvMgr::GetInstance().Init();
InitWifiStateListener();
#endif
DistributedSchedAdapter::GetInstance().Init();
if (SwitchStatusDependency::GetInstance().IsContinueSwitchOn()) {

View File

@ -15,6 +15,7 @@
#include "mission/distributed_mission_focused_listener.h"
#include "continue/dsched_continue_manager.h"
#include "distributed_radar.h"
#include "dtbschedmgr_log.h"
#include "mission/dms_continue_send_manager.h"
@ -33,6 +34,8 @@ void DistributedMissionFocusedListener::OnMissionDestroyed(int32_t missionId)
{
HILOGD("OnMissionDestroyed, missionId = %{public}d", missionId);
DMSContinueSendMgr::GetInstance().NotifyMissionUnfocused(missionId, UnfocusedReason::DESTORY);
DSchedContinueManager::GetInstance().NotifyTerminateContinuation(missionId);
DMSContinueSendMgr::GetInstance().DeleteAliveMissionInfo(missionId);
}
void DistributedMissionFocusedListener::OnMissionSnapshotChanged(int32_t missionId)

View File

@ -285,6 +285,7 @@ int32_t DMSContinueSendMgr::DealFocusedBusiness(const int32_t missionId)
std::string abilityName = info.want.GetElement().GetAbilityName();
focusedMissionAbility_[missionId] = abilityName;
aliveMission_[missionId] = { bundleName, abilityName };
if (info.continueState != AAFwk::ContinueState::CONTINUESTATE_ACTIVE) {
HILOGE("Mission continue state set to INACTIVE. Broadcast task abort.");
@ -762,5 +763,26 @@ int32_t DMSContinueSendMgr::SetStateSendEvent(const uint16_t bundleNameId, const
}
return ret;
}
void DMSContinueSendMgr::DeleteAliveMissionInfo(const int32_t missionId)
{
HILOGI("called");
std::lock_guard<std::mutex> aliveMissionMapLock(eventMutex_);
aliveMission_.erase(missionId);
}
int32_t DMSContinueSendMgr::GetAliveMissionInfo(const int32_t missionId, AliveMissionInfo& missionInfo)
{
HILOGI("start, missionId: %{public}d", missionId);
std::lock_guard<std::mutex> aliveMissionMapLock(eventMutex_);
auto iterItem = aliveMission_.find(missionId);
if (iterItem != aliveMission_.end()) {
missionInfo = iterItem->second;
HILOGI("get missionIdInfo end, missionId: %{public}d", missionId);
return ERR_OK;
}
HILOGE("get iterItem failed from aliveMission_");
return INVALID_PARAMETERS_ERR;
}
} // namespace DistributedSchedule
} // namespace OHOS