1686862fbSopenharmony_ci/*
2686862fbSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3686862fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4686862fbSopenharmony_ci * you may not use this file except in compliance with the License.
5686862fbSopenharmony_ci * You may obtain a copy of the License at
6686862fbSopenharmony_ci *
7686862fbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8686862fbSopenharmony_ci *
9686862fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10686862fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11686862fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12686862fbSopenharmony_ci * See the License for the specific language governing permissions and
13686862fbSopenharmony_ci * limitations under the License.
14686862fbSopenharmony_ci */
15686862fbSopenharmony_ci
16686862fbSopenharmony_ci#include "distributed_sched_continuation.h"
17686862fbSopenharmony_ci#include "dtbschedmgr_log.h"
18686862fbSopenharmony_ci#include "parcel_helper.h"
19686862fbSopenharmony_ci
20686862fbSopenharmony_ciusing namespace OHOS::AppExecFwk;
21686862fbSopenharmony_ci
22686862fbSopenharmony_cinamespace OHOS {
23686862fbSopenharmony_cinamespace DistributedSchedule {
24686862fbSopenharmony_cinamespace {
25686862fbSopenharmony_ciconstexpr int64_t CONTINUATION_DELAY_TIME = 20000;
26686862fbSopenharmony_ciconst std::string TAG = "DSchedContinuation";
27686862fbSopenharmony_ciconst std::u16string NAPI_MISSION_CENTER_INTERFACE_TOKEN = u"ohos.DistributedSchedule.IMissionCallback";
28686862fbSopenharmony_ciconstexpr int32_t NOTIFY_MISSION_CENTER_RESULT = 4;
29686862fbSopenharmony_ciconst std::u16string DSCHED_EVENT_TOKEN = u"ohos.distributedSchedule.dschedeventlistener";
30686862fbSopenharmony_ciconstexpr int32_t DSCHED_EVENT_CALLBACK = 0;
31686862fbSopenharmony_ci}
32686862fbSopenharmony_ci
33686862fbSopenharmony_civoid DSchedContinuation::Init(const FuncContinuationCallback& contCallback)
34686862fbSopenharmony_ci{
35686862fbSopenharmony_ci    auto runner = EventRunner::Create("dsched_continuation");
36686862fbSopenharmony_ci    continuationHandler_ = std::make_shared<ContinuationHandler>(runner, shared_from_this(), contCallback);
37686862fbSopenharmony_ci    diedListener_ = new DistributedEventDiedListener();
38686862fbSopenharmony_ci}
39686862fbSopenharmony_ci
40686862fbSopenharmony_cibool DSchedContinuation::PushAbilityToken(int32_t sessionId, const sptr<IRemoteObject>& abilityToken)
41686862fbSopenharmony_ci{
42686862fbSopenharmony_ci    if (abilityToken == nullptr) {
43686862fbSopenharmony_ci        HILOGE("PushAbilityToken abilityToken null!");
44686862fbSopenharmony_ci        return false;
45686862fbSopenharmony_ci    }
46686862fbSopenharmony_ci
47686862fbSopenharmony_ci    if (sessionId <= 0) {
48686862fbSopenharmony_ci        HILOGE("PushAbilityToken sessionId invalid!");
49686862fbSopenharmony_ci        return false;
50686862fbSopenharmony_ci    }
51686862fbSopenharmony_ci
52686862fbSopenharmony_ci    if (continuationHandler_ == nullptr) {
53686862fbSopenharmony_ci        HILOGE("PushAbilityToken not initialized!");
54686862fbSopenharmony_ci        return false;
55686862fbSopenharmony_ci    }
56686862fbSopenharmony_ci
57686862fbSopenharmony_ci    std::lock_guard<std::mutex> autoLock(continuationLock_);
58686862fbSopenharmony_ci    bool ret = true;
59686862fbSopenharmony_ci    ret = continuationHandler_->SendEvent(sessionId, 0, CONTINUATION_DELAY_TIME);
60686862fbSopenharmony_ci    if (!ret) {
61686862fbSopenharmony_ci        HILOGE("PushAbilityToken SendEvent failed!");
62686862fbSopenharmony_ci        return false;
63686862fbSopenharmony_ci    }
64686862fbSopenharmony_ci
65686862fbSopenharmony_ci    auto iterSession = continuationMap_.find(sessionId);
66686862fbSopenharmony_ci    if (iterSession != continuationMap_.end()) {
67686862fbSopenharmony_ci        HILOGE("PushAbilityToken sessionId:%{public}d exist!", sessionId);
68686862fbSopenharmony_ci        return false;
69686862fbSopenharmony_ci    }
70686862fbSopenharmony_ci    (void)continuationMap_.emplace(sessionId, abilityToken);
71686862fbSopenharmony_ci    return true;
72686862fbSopenharmony_ci}
73686862fbSopenharmony_ci
74686862fbSopenharmony_cisptr<IRemoteObject> DSchedContinuation::PopAbilityToken(int32_t sessionId)
75686862fbSopenharmony_ci{
76686862fbSopenharmony_ci    if (sessionId <= 0) {
77686862fbSopenharmony_ci        HILOGE("PopAbilityToken sessionId invalid");
78686862fbSopenharmony_ci        return nullptr;
79686862fbSopenharmony_ci    }
80686862fbSopenharmony_ci
81686862fbSopenharmony_ci    std::lock_guard<std::mutex> autoLock(continuationLock_);
82686862fbSopenharmony_ci    auto iter = continuationMap_.find(sessionId);
83686862fbSopenharmony_ci    if (iter == continuationMap_.end()) {
84686862fbSopenharmony_ci        HILOGW("PopAbilityToken not found sessionId:%{public}d", sessionId);
85686862fbSopenharmony_ci        return nullptr;
86686862fbSopenharmony_ci    }
87686862fbSopenharmony_ci    sptr<IRemoteObject> abilityToken = iter->second;
88686862fbSopenharmony_ci    (void)continuationMap_.erase(iter);
89686862fbSopenharmony_ci    if (continuationHandler_ != nullptr) {
90686862fbSopenharmony_ci        continuationHandler_->RemoveEvent(sessionId);
91686862fbSopenharmony_ci    }
92686862fbSopenharmony_ci    return abilityToken;
93686862fbSopenharmony_ci}
94686862fbSopenharmony_ci
95686862fbSopenharmony_ciint32_t DSchedContinuation::GenerateSessionId()
96686862fbSopenharmony_ci{
97686862fbSopenharmony_ci    std::lock_guard<std::mutex> autoLock(continuationLock_);
98686862fbSopenharmony_ci    int32_t currValue = currSessionId_;
99686862fbSopenharmony_ci    if (++currSessionId_ <= 0) {
100686862fbSopenharmony_ci        currSessionId_ = 1;
101686862fbSopenharmony_ci    }
102686862fbSopenharmony_ci    return currValue;
103686862fbSopenharmony_ci}
104686862fbSopenharmony_ci
105686862fbSopenharmony_civoid DSchedContinuation::SetTimeOut(int32_t missionId, int32_t timeout)
106686862fbSopenharmony_ci{
107686862fbSopenharmony_ci    if (continuationHandler_ == nullptr) {
108686862fbSopenharmony_ci        HILOGE("continuationHandler not initialized!");
109686862fbSopenharmony_ci        return;
110686862fbSopenharmony_ci    }
111686862fbSopenharmony_ci    continuationHandler_->SendEvent(missionId, 0, timeout);
112686862fbSopenharmony_ci}
113686862fbSopenharmony_ci
114686862fbSopenharmony_civoid DSchedContinuation::RemoveTimeOut(int32_t missionId)
115686862fbSopenharmony_ci{
116686862fbSopenharmony_ci    if (continuationHandler_ == nullptr) {
117686862fbSopenharmony_ci        HILOGE("continuationHandler not initialized!");
118686862fbSopenharmony_ci        return;
119686862fbSopenharmony_ci    }
120686862fbSopenharmony_ci    continuationHandler_->RemoveEvent(missionId);
121686862fbSopenharmony_ci}
122686862fbSopenharmony_ci
123686862fbSopenharmony_cibool DSchedContinuation::IsFreeInstall(int32_t missionId)
124686862fbSopenharmony_ci{
125686862fbSopenharmony_ci    std::lock_guard<std::mutex> autoLock(continuationLock_);
126686862fbSopenharmony_ci    auto iter = freeInstall_.find(missionId);
127686862fbSopenharmony_ci    if (iter != freeInstall_.end()) {
128686862fbSopenharmony_ci        HILOGD("continue free install, missionId:%{public}d exist!", missionId);
129686862fbSopenharmony_ci        return iter->second;
130686862fbSopenharmony_ci    }
131686862fbSopenharmony_ci    return false;
132686862fbSopenharmony_ci}
133686862fbSopenharmony_ci
134686862fbSopenharmony_cibool DSchedContinuation::IsInContinuationProgress(int32_t missionId)
135686862fbSopenharmony_ci{
136686862fbSopenharmony_ci    std::lock_guard<std::mutex> autoLock(continuationLock_);
137686862fbSopenharmony_ci    auto iterSession = callbackMap_.find(missionId);
138686862fbSopenharmony_ci    if (iterSession != callbackMap_.end()) {
139686862fbSopenharmony_ci        HILOGD("Continuation in progress, missionId:%{public}d exist!", missionId);
140686862fbSopenharmony_ci        return true;
141686862fbSopenharmony_ci    }
142686862fbSopenharmony_ci    return false;
143686862fbSopenharmony_ci}
144686862fbSopenharmony_ci
145686862fbSopenharmony_cistd::string DSchedContinuation::GetTargetDevice(int32_t missionId)
146686862fbSopenharmony_ci{
147686862fbSopenharmony_ci    std::lock_guard<std::mutex> autoLock(continuationLock_);
148686862fbSopenharmony_ci    auto iter = continuationDevices_.find(missionId);
149686862fbSopenharmony_ci    if (iter != continuationDevices_.end()) {
150686862fbSopenharmony_ci        HILOGD("missionId:%{public}d exist!", missionId);
151686862fbSopenharmony_ci        return iter->second;
152686862fbSopenharmony_ci    }
153686862fbSopenharmony_ci    return "";
154686862fbSopenharmony_ci}
155686862fbSopenharmony_ci
156686862fbSopenharmony_cibool DSchedContinuation::PushCallback(const sptr<IRemoteObject>& callback)
157686862fbSopenharmony_ci{
158686862fbSopenharmony_ci    if (continuationHandler_ == nullptr) {
159686862fbSopenharmony_ci        HILOGE("not initialized!");
160686862fbSopenharmony_ci        return false;
161686862fbSopenharmony_ci    }
162686862fbSopenharmony_ci    HILOGI("DSchedContinuation PushCallback start!");
163686862fbSopenharmony_ci    if (callback == nullptr) {
164686862fbSopenharmony_ci        HILOGE("callback null!");
165686862fbSopenharmony_ci        return false;
166686862fbSopenharmony_ci    }
167686862fbSopenharmony_ci    std::lock_guard<std::mutex> autoLock(continuationLock_);
168686862fbSopenharmony_ci    std::vector<sptr<IRemoteObject>> vecCallback = continuationCallbackArr_;
169686862fbSopenharmony_ci    for (auto ele = continuationCallbackArr_.begin(); ele != continuationCallbackArr_.end(); ++ele) {
170686862fbSopenharmony_ci        if ((*ele) == callback) {
171686862fbSopenharmony_ci            HILOGW("callback already  exists!");
172686862fbSopenharmony_ci            return false;
173686862fbSopenharmony_ci        }
174686862fbSopenharmony_ci    }
175686862fbSopenharmony_ci    continuationCallbackArr_.push_back(callback);
176686862fbSopenharmony_ci    callback->AddDeathRecipient(diedListener_);
177686862fbSopenharmony_ci
178686862fbSopenharmony_ci    int dSchedEventresult = NotifyDSchedEventForOneCB(callback, ERR_OK);
179686862fbSopenharmony_ci    if (dSchedEventresult != ERR_OK) {
180686862fbSopenharmony_ci        HILOGE("Push continuation success, notify dms event result: %{public}d.", dSchedEventresult);
181686862fbSopenharmony_ci    }
182686862fbSopenharmony_ci    return true;
183686862fbSopenharmony_ci}
184686862fbSopenharmony_ci
185686862fbSopenharmony_cibool DSchedContinuation::PushCallback(int32_t missionId, const sptr<IRemoteObject>& callback,
186686862fbSopenharmony_ci    std::string deviceId, bool isFreeInstall)
187686862fbSopenharmony_ci{
188686862fbSopenharmony_ci    HILOGI("DSchedContinuation PushCallback start!");
189686862fbSopenharmony_ci    if (callback == nullptr) {
190686862fbSopenharmony_ci        HILOGE("callback null!");
191686862fbSopenharmony_ci        return false;
192686862fbSopenharmony_ci    }
193686862fbSopenharmony_ci
194686862fbSopenharmony_ci    if (continuationHandler_ == nullptr) {
195686862fbSopenharmony_ci        HILOGE("not initialized!");
196686862fbSopenharmony_ci        return false;
197686862fbSopenharmony_ci    }
198686862fbSopenharmony_ci
199686862fbSopenharmony_ci    std::lock_guard<std::mutex> autoLock(continuationLock_);
200686862fbSopenharmony_ci    auto iterSession = callbackMap_.find(missionId);
201686862fbSopenharmony_ci    if (iterSession != callbackMap_.end()) {
202686862fbSopenharmony_ci        HILOGE("missionId:%{public}d exist!", missionId);
203686862fbSopenharmony_ci        return false;
204686862fbSopenharmony_ci    }
205686862fbSopenharmony_ci    (void)callbackMap_.emplace(missionId, callback);
206686862fbSopenharmony_ci    (void)continuationDevices_.emplace(missionId, deviceId);
207686862fbSopenharmony_ci    if (isFreeInstall) {
208686862fbSopenharmony_ci        freeInstall_[missionId] = isFreeInstall;
209686862fbSopenharmony_ci    }
210686862fbSopenharmony_ci    return true;
211686862fbSopenharmony_ci}
212686862fbSopenharmony_ci
213686862fbSopenharmony_cistd::vector<sptr<IRemoteObject>> DSchedContinuation::GetCallback()
214686862fbSopenharmony_ci{
215686862fbSopenharmony_ci    std::lock_guard<std::mutex> autoLock(continuationLock_);
216686862fbSopenharmony_ci    return continuationCallbackArr_;
217686862fbSopenharmony_ci}
218686862fbSopenharmony_ci
219686862fbSopenharmony_cibool DSchedContinuation::CleanupCallback(const sptr<IRemoteObject>& callback)
220686862fbSopenharmony_ci{
221686862fbSopenharmony_ci    std::lock_guard<std::mutex> autoLock(continuationLock_);
222686862fbSopenharmony_ci    if (continuationCallbackArr_.empty()) {
223686862fbSopenharmony_ci        HILOGE("No need for cleaning!");
224686862fbSopenharmony_ci        return false;
225686862fbSopenharmony_ci    }
226686862fbSopenharmony_ci    for (auto ele = continuationCallbackArr_.begin(); ele != continuationCallbackArr_.end(); ++ele) {
227686862fbSopenharmony_ci        if ((*ele) == callback) {
228686862fbSopenharmony_ci            continuationCallbackArr_.erase(ele);
229686862fbSopenharmony_ci            HILOGI("callback is exists, cleared successfully.");
230686862fbSopenharmony_ci            return true;
231686862fbSopenharmony_ci        }
232686862fbSopenharmony_ci    }
233686862fbSopenharmony_ci    HILOGI("callback is not exists!");
234686862fbSopenharmony_ci    return false;
235686862fbSopenharmony_ci}
236686862fbSopenharmony_ci
237686862fbSopenharmony_cisptr<IRemoteObject> DSchedContinuation::PopCallback(int32_t missionId)
238686862fbSopenharmony_ci{
239686862fbSopenharmony_ci    std::lock_guard<std::mutex> autoLock(continuationLock_);
240686862fbSopenharmony_ci    auto iter = callbackMap_.find(missionId);
241686862fbSopenharmony_ci    if (iter == callbackMap_.end()) {
242686862fbSopenharmony_ci        HILOGW("PopCallback not found missionId:%{public}d", missionId);
243686862fbSopenharmony_ci        return nullptr;
244686862fbSopenharmony_ci    }
245686862fbSopenharmony_ci    sptr<IRemoteObject> callback = iter->second;
246686862fbSopenharmony_ci
247686862fbSopenharmony_ci    auto iteration = continuationDevices_.find(missionId);
248686862fbSopenharmony_ci    if (iteration != continuationDevices_.end()) {
249686862fbSopenharmony_ci        HILOGD("%{public}d need pop from continuationDevices_", missionId);
250686862fbSopenharmony_ci        (void)continuationDevices_.erase(iteration);
251686862fbSopenharmony_ci    }
252686862fbSopenharmony_ci
253686862fbSopenharmony_ci    auto it = freeInstall_.find(missionId);
254686862fbSopenharmony_ci    if (it != freeInstall_.end()) {
255686862fbSopenharmony_ci        HILOGD("%{public}d need pop from freeInstall_", missionId);
256686862fbSopenharmony_ci        (void)freeInstall_.erase(it);
257686862fbSopenharmony_ci    }
258686862fbSopenharmony_ci    (void)cleanMission_.erase(missionId);
259686862fbSopenharmony_ci    (void)callbackMap_.erase(iter);
260686862fbSopenharmony_ci    return callback;
261686862fbSopenharmony_ci}
262686862fbSopenharmony_ci
263686862fbSopenharmony_ciint32_t DSchedContinuation::NotifyDSchedEventForOneCB(const sptr<IRemoteObject> &cb, int32_t resultCode)
264686862fbSopenharmony_ci{
265686862fbSopenharmony_ci    if (cb == nullptr) {
266686862fbSopenharmony_ci        HILOGE("NotifyDSchedEventForOneCB input callback is null.");
267686862fbSopenharmony_ci        return INVALID_PARAMETERS_ERR;
268686862fbSopenharmony_ci    }
269686862fbSopenharmony_ci
270686862fbSopenharmony_ci    MessageParcel data;
271686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DSCHED_EVENT_TOKEN)) {
272686862fbSopenharmony_ci        HILOGE("NotifyDSchedEventForOneCB write token failed");
273686862fbSopenharmony_ci        return SEND_REQUEST_DEF_FAIL;
274686862fbSopenharmony_ci    }
275686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, Int32, resultCode, SEND_REQUEST_DEF_FAIL);
276686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.srcNetworkId_, SEND_REQUEST_DEF_FAIL);
277686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.dstNetworkId_, SEND_REQUEST_DEF_FAIL);
278686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.srcBundleName_, SEND_REQUEST_DEF_FAIL);
279686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.srcModuleName_, SEND_REQUEST_DEF_FAIL);
280686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.srcAbilityName_, SEND_REQUEST_DEF_FAIL);
281686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.destBundleName_, SEND_REQUEST_DEF_FAIL);
282686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.destModuleName_, SEND_REQUEST_DEF_FAIL);
283686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.destAbilityName_, SEND_REQUEST_DEF_FAIL);
284686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.developerId_, SEND_REQUEST_DEF_FAIL);
285686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, Int32, continueEvent_.dSchedEventType_, SEND_REQUEST_DEF_FAIL);
286686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, Int32, continueEvent_.state_, SEND_REQUEST_DEF_FAIL);
287686862fbSopenharmony_ci
288686862fbSopenharmony_ci    MessageParcel reply;
289686862fbSopenharmony_ci    MessageOption option;
290686862fbSopenharmony_ci    int32_t ret = cb->SendRequest(DSCHED_EVENT_CALLBACK, data, reply, option);
291686862fbSopenharmony_ci    HILOGI("NotifyDSchedEventForOneCB transact end, ret: %{public}d.", ret);
292686862fbSopenharmony_ci    return ret;
293686862fbSopenharmony_ci}
294686862fbSopenharmony_ci
295686862fbSopenharmony_ciint32_t DSchedContinuation::NotifyDSchedEventResult(int32_t resultCode)
296686862fbSopenharmony_ci{
297686862fbSopenharmony_ci    HILOGI("NotifyDSchedEventResult GetCallback IDSchedEventListener");
298686862fbSopenharmony_ci    std::vector<sptr<IRemoteObject>> vecCallback = GetCallback();
299686862fbSopenharmony_ci    if (vecCallback.empty()) {
300686862fbSopenharmony_ci        HILOGD("No listening has been registered, no need to report events");
301686862fbSopenharmony_ci        return INVALID_PARAMETERS_ERR;
302686862fbSopenharmony_ci    }
303686862fbSopenharmony_ci    bool isAllSuc = true;
304686862fbSopenharmony_ci    for (auto callback = vecCallback.begin(); callback != vecCallback.end(); ++callback) {
305686862fbSopenharmony_ci        int32_t ret = NotifyDSchedEventForOneCB(*callback, resultCode);
306686862fbSopenharmony_ci        if (ret != ERR_OK) {
307686862fbSopenharmony_ci            HILOGE("NotifyDSchedEventResult transact fail, ret: %{public}d", ret);
308686862fbSopenharmony_ci            isAllSuc = isAllSuc && false;
309686862fbSopenharmony_ci        }
310686862fbSopenharmony_ci    }
311686862fbSopenharmony_ci    if (!isAllSuc) {
312686862fbSopenharmony_ci        HILOGE("NotifyDSchedEventListenerResult transact fail, isAllSuc: %{public}d", isAllSuc);
313686862fbSopenharmony_ci        return SEND_REQUEST_DEF_FAIL;
314686862fbSopenharmony_ci    }
315686862fbSopenharmony_ci    HILOGI("NotifyDSchedEventResult transact ok.");
316686862fbSopenharmony_ci    return ERR_OK;
317686862fbSopenharmony_ci}
318686862fbSopenharmony_ci
319686862fbSopenharmony_ciint32_t DSchedContinuation::NotifyMissionCenterResult(int32_t missionId, int32_t resultCode)
320686862fbSopenharmony_ci{
321686862fbSopenharmony_ci    sptr<IRemoteObject> callback = PopCallback(missionId);
322686862fbSopenharmony_ci    RemoveTimeOut(missionId);
323686862fbSopenharmony_ci    if (callback == nullptr) {
324686862fbSopenharmony_ci        HILOGE("NotifyMissionCenterResult callback is null");
325686862fbSopenharmony_ci        return INVALID_PARAMETERS_ERR;
326686862fbSopenharmony_ci    }
327686862fbSopenharmony_ci
328686862fbSopenharmony_ci    MessageParcel data;
329686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(NAPI_MISSION_CENTER_INTERFACE_TOKEN)) {
330686862fbSopenharmony_ci        HILOGE("NotifyMissionCenterResult write token failed");
331686862fbSopenharmony_ci        return INVALID_PARAMETERS_ERR;
332686862fbSopenharmony_ci    }
333686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, Int32, resultCode, INVALID_PARAMETERS_ERR);
334686862fbSopenharmony_ci    MessageParcel reply;
335686862fbSopenharmony_ci    MessageOption option;
336686862fbSopenharmony_ci    int32_t error = callback->SendRequest(NOTIFY_MISSION_CENTER_RESULT, data, reply, option);
337686862fbSopenharmony_ci    HILOGI("NotifyMissionCenterResult transact result: %{public}d", error);
338686862fbSopenharmony_ci    return error;
339686862fbSopenharmony_ci}
340686862fbSopenharmony_ci
341686862fbSopenharmony_civoid DSchedContinuation::ContinuationHandler::ProcessEvent(const InnerEvent::Pointer& event)
342686862fbSopenharmony_ci{
343686862fbSopenharmony_ci    if (event == nullptr) {
344686862fbSopenharmony_ci        HILOGE("ProcessEvent event nullptr!");
345686862fbSopenharmony_ci        return;
346686862fbSopenharmony_ci    }
347686862fbSopenharmony_ci
348686862fbSopenharmony_ci    auto eventId = event->GetInnerEventId();
349686862fbSopenharmony_ci    int32_t sessionId = static_cast<int32_t>(eventId);
350686862fbSopenharmony_ci    if (sessionId <= 0) {
351686862fbSopenharmony_ci        HILOGW("ProcessEvent sessionId invalid!");
352686862fbSopenharmony_ci        return;
353686862fbSopenharmony_ci    }
354686862fbSopenharmony_ci
355686862fbSopenharmony_ci    if (contCallback_ != nullptr) {
356686862fbSopenharmony_ci        contCallback_(sessionId);
357686862fbSopenharmony_ci    }
358686862fbSopenharmony_ci}
359686862fbSopenharmony_ci
360686862fbSopenharmony_civoid DSchedContinuation::SetCleanMissionFlag(int32_t missionId, bool isCleanMission)
361686862fbSopenharmony_ci{
362686862fbSopenharmony_ci    std::lock_guard<std::mutex> autoLock(continuationLock_);
363686862fbSopenharmony_ci    cleanMission_.emplace(missionId, isCleanMission);
364686862fbSopenharmony_ci}
365686862fbSopenharmony_ci
366686862fbSopenharmony_cibool DSchedContinuation::IsCleanMission(int32_t missionId)
367686862fbSopenharmony_ci{
368686862fbSopenharmony_ci    std::lock_guard<std::mutex> autoLock(continuationLock_);
369686862fbSopenharmony_ci    auto iter = cleanMission_.find(missionId);
370686862fbSopenharmony_ci    if (iter != cleanMission_.end()) {
371686862fbSopenharmony_ci        HILOGD("Application need not exit after continue, missionId:%{public}d exist!", missionId);
372686862fbSopenharmony_ci        return iter->second;
373686862fbSopenharmony_ci    }
374686862fbSopenharmony_ci    return true;
375686862fbSopenharmony_ci}
376686862fbSopenharmony_ci} // namespace DistributedSchedule
377686862fbSopenharmony_ci} // namespace OHOS
378