!645 Add new feature the application exit according to the user input

Merge pull request !645 from hunili/master
This commit is contained in:
openharmony_ci 2023-06-15 02:59:26 +00:00 committed by Gitee
commit ee29508a57
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 39 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -43,6 +43,8 @@ public:
int32_t NotifyMissionCenterResult(int32_t missionId, int32_t resultCode);
bool IsFreeInstall(int32_t missionId);
std::string GetTargetDevice(int32_t missionId);
bool IsCleanMission(int32_t missionId);
void SetCleanMissionFlag(int32_t missionId, bool isCleanMission);
private:
class ContinuationHandler : public AppExecFwk::EventHandler {
@ -65,6 +67,7 @@ private:
std::map<int32_t, sptr<IRemoteObject>> continuationMap_;
std::map<int32_t, sptr<IRemoteObject>> callbackMap_;
std::map<int32_t, bool> freeInstall_;
std::map<int32_t, bool> cleanMission_;
std::map<int32_t, std::string> continuationDevices_;
};
} // namespace DistributedSchedule

View File

@ -235,6 +235,7 @@ private:
int32_t CheckTargetPermission(const OHOS::AAFwk::Want& want, const CallerInfo& callerInfo,
const AccountInfo& accountInfo, int32_t flag, bool needQueryExtension);
int32_t SaveConnectToken(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect);
void SetCleanMissionFlag(const OHOS::AAFwk::Want& want, int32_t missionId);
std::shared_ptr<DSchedContinuation> dschedContinuation_;
std::map<sptr<IRemoteObject>, std::list<ConnectAbilitySession>> distributedConnectAbilityMap_;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -199,6 +199,7 @@ sptr<IRemoteObject> DSchedContinuation::PopCallback(int32_t missionId)
HILOGD("%{public}d need pop from freeInstall_", missionId);
(void)freeInstall_.erase(it);
}
(void)cleanMission_.erase(missionId);
(void)callbackMap_.erase(iter);
return callback;
}
@ -243,5 +244,22 @@ void DSchedContinuation::ContinuationHandler::ProcessEvent(const InnerEvent::Poi
contCallback_(sessionId);
}
}
void DSchedContinuation::SetCleanMissionFlag(int32_t missionId, bool isCleanMission)
{
std::lock_guard<std::mutex> autoLock(continuationLock_);
cleanMission_.emplace(missionId, isCleanMission);
}
bool DSchedContinuation::IsCleanMission(int32_t missionId)
{
std::lock_guard<std::mutex> autoLock(continuationLock_);
auto iter = cleanMission_.find(missionId);
if (iter != cleanMission_.end()) {
HILOGD("Application need not exit after continue, missionId:%{public}d exist!", missionId);
return iter->second;
}
return true;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -22,6 +22,7 @@
#include "ability_manager_client.h"
#include "ability_manager_errors.h"
#include "adapter/dnetwork_adapter.h"
#include "bool_wrapper.h"
#include "bundle/bundle_manager_internal.h"
#include "connect_death_recipient.h"
#include "datetime_ex.h"
@ -85,6 +86,7 @@ const std::string DMS_VERSION_ID = "dmsVersion";
const std::string DMS_CONNECT_TOKEN = "connectToken";
const std::string DMS_VERSION = "4.0.0";
const std::string DMS_MISSION_ID = "dmsMissionId";
const std::string SUPPORT_CONTINUE_SOURCE_EXIT_KEY = "ohos.extra.param.key.supportContinueSourceExit";
constexpr int32_t DEFAULT_DMS_MISSION_ID = -1;
constexpr int32_t DEFAULT_DMS_CONNECT_TOKEN = -1;
constexpr int32_t BIND_CONNECT_RETRY_TIMES = 3;
@ -542,6 +544,7 @@ int32_t DistributedSchedService::StartContinuation(const OHOS::AAFwk::Want& want
return result;
}
bool flag = dschedContinuation_->IsFreeInstall(missionId);
SetCleanMissionFlag(want, missionId);
if (flag) {
result = StartRemoteFreeInstall(newWant, callerUid, DEFAULT_REQUEST_CODE, accessToken, nullptr);
if (result != ERR_OK) {
@ -654,7 +657,7 @@ void DistributedSchedService::NotifyContinuationCallbackResult(int32_t missionId
int32_t result = 0;
if (dschedContinuation_->IsInContinuationProgress(missionId)) {
if (resultCode == ERR_OK) {
if (resultCode == ERR_OK && dschedContinuation_->IsCleanMission(missionId)) {
result = AbilityManagerClient::GetInstance()->CleanMission(missionId);
HILOGD("clean mission result:%{public}d", result);
}
@ -2486,5 +2489,16 @@ int32_t DistributedSchedService::StopExtensionAbilityFromRemote(const OHOS::AAFw
return AAFwk::AbilityManagerClient::GetInstance()->StopExtensionAbility(
want, callerToken, ids[0], static_cast<AppExecFwk::ExtensionAbilityType>(extensionType));
}
void DistributedSchedService::SetCleanMissionFlag(const OHOS::AAFwk::Want& want, int32_t missionId)
{
auto value = want.GetParams().GetParam(SUPPORT_CONTINUE_SOURCE_EXIT_KEY);
IBoolean *ao = IBoolean::Query(value);
bool isCleanMission = true;
if (ao != nullptr) {
isCleanMission = AAFwk::Boolean::Unbox(ao);
}
dschedContinuation_->SetCleanMissionFlag(missionId, isCleanMission);
}
} // namespace DistributedSchedule
} // namespace OHOS