• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "continuation_manager.h"
17 
18 #include "ability.h"
19 #include "ability_continuation_interface.h"
20 #include "ability_manager_client.h"
21 #include "continuation_handler.h"
22 #include "distributed_client.h"
23 #include "distributed_objectstore.h"
24 #include "hilog_wrapper.h"
25 #include "operation_builder.h"
26 #include "string_ex.h"
27 #include "string_wrapper.h"
28 #include "want.h"
29 
30 namespace OHOS {
31 namespace AppExecFwk {
32 const int ContinuationManager::TIMEOUT_MS_WAIT_DMS_NOTIFY_CONTINUATION_COMPLETE = 25000;
33 const int ContinuationManager::TIMEOUT_MS_WAIT_REMOTE_NOTIFY_BACK = 6000;
34 const std::string PAGE_STACK_PROPERTY_NAME = "pageStack";
35 const int32_t CONTINUE_ABILITY_REJECTED = 29360197;
36 const int32_t CONTINUE_SAVE_DATA_FAILED = 29360198;
37 const int32_t CONTINUE_ON_CONTINUE_FAILED = 29360199;
38 #ifdef SUPPORT_GRAPHICS
39 const int32_t CONTINUE_GET_CONTENT_FAILED = 29360200;
40 #endif
ContinuationManager()41 ContinuationManager::ContinuationManager()
42 {
43     progressState_ = ProgressState::INITIAL;
44 }
45 
Init(const std::shared_ptr<Ability> & ability,const sptr<IRemoteObject> & continueToken,const std::shared_ptr<AbilityInfo> & abilityInfo,const std::shared_ptr<ContinuationHandler> & continuationHandler)46 bool ContinuationManager::Init(const std::shared_ptr<Ability> &ability, const sptr<IRemoteObject> &continueToken,
47     const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<ContinuationHandler> &continuationHandler)
48 {
49     HILOG_INFO("%{public}s called begin", __func__);
50     if (ability == nullptr) {
51         HILOG_ERROR("ContinuationManager::Init failed. ability is nullptr");
52         return false;
53     }
54     ability_ = ability;
55 
56     std::shared_ptr<Ability> abilityTmp = nullptr;
57     abilityTmp = ability_.lock();
58     if (abilityTmp == nullptr) {
59         HILOG_ERROR("ContinuationManager::Init failed. get ability is nullptr");
60         return false;
61     }
62 
63     if (abilityTmp->GetAbilityInfo() == nullptr) {
64         HILOG_ERROR("ContinuationManager::Init failed. abilityInfo is nullptr");
65         return false;
66     }
67     abilityInfo_ = abilityTmp->GetAbilityInfo();
68 
69     if (continueToken == nullptr) {
70         HILOG_ERROR("ContinuationManager::Init failed. continueToken is nullptr");
71         return false;
72     }
73     continueToken_ = continueToken;
74 
75     continuationHandler_ = continuationHandler;
76     HILOG_INFO("%{public}s called end", __func__);
77     return true;
78 }
79 
GetContinuationState()80 ContinuationState ContinuationManager::GetContinuationState()
81 {
82     return continuationState_;
83 }
84 
GetOriginalDeviceId()85 std::string ContinuationManager::GetOriginalDeviceId()
86 {
87     return originalDeviceId_;
88 }
89 
ContinueAbilityWithStack(const std::string & deviceId)90 void ContinuationManager::ContinueAbilityWithStack(const std::string &deviceId)
91 {
92     HILOG_INFO("%{public}s called begin", __func__);
93 
94     HandleContinueAbilityWithStack(deviceId);
95     HILOG_INFO("%{public}s called end", __func__);
96 }
97 
HandleContinueAbilityWithStack(const std::string & deviceId)98 bool ContinuationManager::HandleContinueAbilityWithStack(const std::string &deviceId)
99 {
100     HILOG_INFO("%{public}s called begin", __func__);
101 
102     if (!CheckAbilityToken()) {
103         HILOG_ERROR("HandleContinueAbilityWithStack checkAbilityToken failed");
104         return false;
105     }
106 
107     sptr<IRemoteObject> continueToken = continueToken_;
108     std::shared_ptr<ContinuationHandler> continuationHandler = continuationHandler_.lock();
109     if (continuationHandler == nullptr) {
110         HILOG_ERROR("HandleContinueAbilityWithStack continuationHandler is nullptr");
111         return false;
112     }
113 
114     InitMainHandlerIfNeed();
115     auto task = [continuationHandler, continueToken, deviceId]() {
116         continuationHandler->HandleStartContinuationWithStack(continueToken, deviceId);
117     };
118     if (!mainHandler_->PostTask(task)) {
119         HILOG_ERROR("HandleContinueAbilityWithStack postTask failed");
120         return false;
121     }
122 
123     HILOG_INFO("%{public}s called end", __func__);
124     return true;
125 }
126 
OnStartAndSaveData(WantParams & wantParams)127 int32_t ContinuationManager::OnStartAndSaveData(WantParams &wantParams)
128 {
129     HILOG_INFO("%{public}s called begin", __func__);
130     std::shared_ptr<Ability> ability = nullptr;
131     ability = ability_.lock();
132     if (ability == nullptr) {
133         HILOG_ERROR("ability is nullptr");
134         return ERR_INVALID_VALUE;
135     }
136 
137     if (!ability->OnStartContinuation()) {
138         HILOG_ERROR("Ability rejected.");
139         return CONTINUE_ABILITY_REJECTED;
140     }
141     if (!ability->OnSaveData(wantParams)) {
142         HILOG_ERROR("SaveData failed.");
143         return CONTINUE_SAVE_DATA_FAILED;
144     }
145     HILOG_INFO("%{public}s called end", __func__);
146     return ERR_OK;
147 }
148 
OnContinueAndGetContent(WantParams & wantParams)149 int32_t ContinuationManager::OnContinueAndGetContent(WantParams &wantParams)
150 {
151     HILOG_INFO("%{public}s called begin", __func__);
152     std::shared_ptr<Ability> ability = nullptr;
153     ability = ability_.lock();
154     if (ability == nullptr) {
155         HILOG_ERROR("ability is nullptr");
156         return ERR_INVALID_VALUE;
157     }
158 
159     HILOG_INFO("OnContinue begin");
160     int32_t status = ability->OnContinue(wantParams);
161     HILOG_INFO("OnContinue end, status: %{public}d", status);
162     if (status != OnContinueResult::AGREE) {
163         HILOG_ERROR("OnContinue failed.");
164         return CONTINUE_ON_CONTINUE_FAILED;
165     }
166 #ifdef DISTRIBUTED_DATA_OBJECT_ENABLE
167     auto abilityInfo = abilityInfo_.lock();
168     std::string &bundleName = abilityInfo->bundleName;
169     ObjectStore::DistributedObjectStore::GetInstance(bundleName)->TriggerSync();
170 #endif
171 
172 #ifdef SUPPORT_GRAPHICS
173     bool ret = GetContentInfo(wantParams);
174     if (!ret) {
175         HILOG_ERROR("GetContentInfo failed.");
176         return CONTINUE_GET_CONTENT_FAILED;
177     }
178 #endif
179     HILOG_INFO("%{public}s called end", __func__);
180     return ERR_OK;
181 }
182 
OnContinue(WantParams & wantParams)183 int32_t ContinuationManager::OnContinue(WantParams &wantParams)
184 {
185     HILOG_INFO("%{public}s called begin", __func__);
186     auto ability = ability_.lock();
187     auto abilityInfo = abilityInfo_.lock();
188     if (ability == nullptr || abilityInfo == nullptr) {
189         HILOG_ERROR("ability or abilityInfo is nullptr");
190         return ERR_INVALID_VALUE;
191     }
192 
193     bool stageBased = abilityInfo->isStageBasedModel;
194     HILOG_INFO("ability isStageBasedModel %{public}d", stageBased);
195     if (!stageBased) {
196         return OnStartAndSaveData(wantParams);
197     } else {
198         return OnContinueAndGetContent(wantParams);
199     }
200 }
201 
202 #ifdef SUPPORT_GRAPHICS
GetContentInfo(WantParams & wantParams)203 bool ContinuationManager::GetContentInfo(WantParams &wantParams)
204 {
205     HILOG_INFO("%{public}s called begin", __func__);
206     std::shared_ptr<Ability> ability = nullptr;
207     ability = ability_.lock();
208     if (ability == nullptr) {
209         HILOG_ERROR("ability is nullptr");
210         return false;
211     }
212 
213     std::string pageStack = ability->GetContentInfo();
214     if (pageStack.empty()) {
215         HILOG_ERROR("GetContentInfo failed.");
216         return false;
217     }
218     HILOG_INFO("ability pageStack: %{public}s", pageStack.c_str());
219     wantParams.SetParam(PAGE_STACK_PROPERTY_NAME, String::Box(pageStack));
220 
221     HILOG_INFO("%{public}s called end", __func__);
222     return true;
223 }
224 #endif
225 
ContinueAbility(bool reversible,const std::string & deviceId)226 void ContinuationManager::ContinueAbility(bool reversible, const std::string &deviceId)
227 {
228     HILOG_INFO("%{public}s called begin", __func__);
229     if (CheckContinuationIllegal()) {
230         HILOG_ERROR("ContinuationManager::ContinueAbility failed. Ability not available to continueAbility.");
231         return;
232     }
233 
234     if (progressState_ != ProgressState::INITIAL) {
235         HILOG_ERROR(
236             "ContinuationManager::ContinueAbility failed. Another request in progress. progressState_: %{public}d",
237             progressState_);
238         return;
239     }
240 
241     if (continuationState_ != ContinuationState::LOCAL_RUNNING) {
242         HILOG_ERROR(
243             "ContinuationManager::ContinueAbility failed. Illegal continuation state. Current state is %{public}d",
244             continuationState_);
245         return;
246     }
247 
248     if (HandleContinueAbility(reversible, deviceId)) {
249         reversible_ = reversible;
250         ChangeProcessState(ProgressState::WAITING_SCHEDULE);
251     }
252     HILOG_INFO("%{public}s called end", __func__);
253 }
254 
ReverseContinueAbility()255 bool ContinuationManager::ReverseContinueAbility()
256 {
257     HILOG_INFO("%{public}s called begin", __func__);
258     if (progressState_ != ProgressState::INITIAL) {
259         HILOG_ERROR(
260             "ContinuationManager::ReverseContinueAbility failed. progressState_ is %{public}d.", progressState_);
261         return false;
262     }
263 
264     if (continuationState_ != ContinuationState::REMOTE_RUNNING) {
265         HILOG_ERROR("ContinuationManager::ReverseContinueAbility failed. continuationState_ is %{public}d.",
266             continuationState_);
267         return false;
268     }
269 
270     std::shared_ptr<ContinuationHandler> continuationHandler = continuationHandler_.lock();
271     if (continuationHandler == nullptr) {
272         HILOG_ERROR("ContinuationManager::ReverseContinueAbility failed. continuationHandler_ is nullptr.");
273         return false;
274     }
275 
276     bool requestSuccess = continuationHandler->ReverseContinueAbility();
277     if (requestSuccess) {
278         ChangeProcessState(ProgressState::WAITING_SCHEDULE);
279         RestoreStateWhenTimeout(TIMEOUT_MS_WAIT_REMOTE_NOTIFY_BACK, ProgressState::WAITING_SCHEDULE);
280     }
281     HILOG_INFO("%{public}s called end", __func__);
282     return requestSuccess;
283 }
284 
StartContinuation()285 bool ContinuationManager::StartContinuation()
286 {
287     HILOG_INFO("%{public}s called begin", __func__);
288     ChangeProcessState(ProgressState::IN_PROGRESS);
289     bool result = DoScheduleStartContinuation();
290     if (!result) {
291         ChangeProcessState(ProgressState::INITIAL);
292     }
293     HILOG_INFO("%{public}s called end", __func__);
294     return result;
295 }
296 
SaveData(WantParams & saveData)297 bool ContinuationManager::SaveData(WantParams &saveData)
298 {
299     HILOG_INFO("%{public}s called begin", __func__);
300     bool result = DoScheduleSaveData(saveData);
301     if (!result) {
302         ChangeProcessState(ProgressState::INITIAL);
303     } else {
304         RestoreStateWhenTimeout(TIMEOUT_MS_WAIT_DMS_NOTIFY_CONTINUATION_COMPLETE, ProgressState::IN_PROGRESS);
305     }
306     HILOG_INFO("%{public}s called end", __func__);
307     return result;
308 }
309 
RestoreData(const WantParams & restoreData,bool reversible,const std::string & originalDeviceId)310 bool ContinuationManager::RestoreData(
311     const WantParams &restoreData, bool reversible, const std::string &originalDeviceId)
312 {
313     HILOG_INFO("%{public}s called begin", __func__);
314     ChangeProcessState(ProgressState::IN_PROGRESS);
315     bool result = DoScheduleRestoreData(restoreData);
316     if (reversible) {
317         continuationState_ = ContinuationState::REPLICA_RUNNING;
318     }
319     originalDeviceId_ = originalDeviceId;
320     ChangeProcessState(ProgressState::INITIAL);
321     HILOG_INFO("%{public}s called end", __func__);
322     return result;
323 }
324 
NotifyCompleteContinuation(const std::string & originDeviceId,int sessionId,bool success,const sptr<IRemoteObject> & reverseScheduler)325 void ContinuationManager::NotifyCompleteContinuation(
326     const std::string &originDeviceId, int sessionId, bool success, const sptr<IRemoteObject> &reverseScheduler)
327 {
328     HILOG_INFO("%{public}s called begin", __func__);
329     AAFwk::AbilityManagerClient::GetInstance()->NotifyCompleteContinuation(
330         originDeviceId, sessionId, success);
331     HILOG_INFO("%{public}s called end", __func__);
332 }
333 
CompleteContinuation(int result)334 void ContinuationManager::CompleteContinuation(int result)
335 {
336     HILOG_INFO("%{public}s called begin", __func__);
337     if (CheckContinuationIllegal()) {
338         HILOG_ERROR(
339             "ContinuationManager::CompleteContinuation failed. Ability not available to complete continuation.");
340         return;
341     }
342 
343     std::shared_ptr<Ability> ability = nullptr;
344     ability = ability_.lock();
345     if (ability == nullptr) {
346         HILOG_ERROR("ContinuationManager::CheckContinuationIllegal failed. ability is nullptr");
347         return;
348     }
349 
350     if (result == 0 && reversible_) {
351         continuationState_ = ContinuationState::REMOTE_RUNNING;
352     }
353     ChangeProcessState(ProgressState::INITIAL);
354 
355     ability->OnCompleteContinuation(result);
356 
357     if (!reversible_) {
358         ability->TerminateAbility();
359     }
360     HILOG_INFO("%{public}s called end", __func__);
361 }
362 
RestoreFromRemote(const WantParams & restoreData)363 bool ContinuationManager::RestoreFromRemote(const WantParams &restoreData)
364 {
365     HILOG_INFO("%{public}s called begin", __func__);
366     ChangeProcessState(ProgressState::IN_PROGRESS);
367     bool result = DoRestoreFromRemote(restoreData);
368     /*
369      * No matter what the result is, we should reset the status. Because even it fail, we can do
370      * nothing but let the user send another reverse continuation request again.
371      */
372     ChangeProcessState(ProgressState::INITIAL);
373     if (result) {
374         continuationState_ = ContinuationState::LOCAL_RUNNING;
375     }
376     HILOG_INFO("%{public}s called end", __func__);
377     return result;
378 }
379 
NotifyRemoteTerminated()380 bool ContinuationManager::NotifyRemoteTerminated()
381 {
382     HILOG_INFO("%{public}s called begin", __func__);
383     continuationState_ = ContinuationState::LOCAL_RUNNING;
384     ChangeProcessState(ProgressState::INITIAL);
385 
386     std::shared_ptr<Ability> ability = nullptr;
387     ability = ability_.lock();
388     if (ability == nullptr) {
389         HILOG_ERROR("ContinuationManager::NotifyRemoteTerminated failed. ability is nullptr");
390         return false;
391     }
392 
393     ability->OnRemoteTerminated();
394     HILOG_INFO("%{public}s called end", __func__);
395     return true;
396 }
397 
CheckContinuationIllegal()398 bool ContinuationManager::CheckContinuationIllegal()
399 {
400     HILOG_INFO("%{public}s called begin", __func__);
401     std::shared_ptr<Ability> ability = nullptr;
402     ability = ability_.lock();
403     if (ability == nullptr) {
404         HILOG_ERROR("ContinuationManager::CheckContinuationIllegal failed. ability is nullptr");
405         return false;
406     }
407 
408     if (ability->GetState() >= AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED) {
409         HILOG_ERROR("ContinuationManager::CheckContinuationIllegal failed. ability state is wrong: %{public}d",
410             ability->GetState());
411         return true;
412     }
413     HILOG_INFO("%{public}s called end", __func__);
414     return false;
415 }
416 
HandleContinueAbility(bool reversible,const std::string & deviceId)417 bool ContinuationManager::HandleContinueAbility(bool reversible, const std::string &deviceId)
418 {
419     HILOG_INFO("%{public}s called begin", __func__);
420 
421     if (!CheckAbilityToken()) {
422         HILOG_ERROR("ContinuationManager::HandleContinueAbility failed. CheckAbilityToken failed");
423         return false;
424     }
425 
426     sptr<IRemoteObject> continueToken = continueToken_;
427     std::shared_ptr<ContinuationHandler> continuationHandler = continuationHandler_.lock();
428     if (continuationHandler == nullptr) {
429         HILOG_ERROR("ContinuationManager::HandleContinueAbility failed. continuationHandler is nullptr");
430         return false;
431     }
432     continuationHandler->SetReversible(reversible);
433 
434     InitMainHandlerIfNeed();
435     auto task = [continuationHandler, continueToken, deviceId]() {
436         continuationHandler->HandleStartContinuation(continueToken, deviceId);
437     };
438 
439     if (!mainHandler_->PostTask(task)) {
440         HILOG_ERROR("ContinuationManager::HandleContinueAbility failed.PostTask failed");
441         return false;
442     }
443 
444     HILOG_INFO("%{public}s called end", __func__);
445     return true;
446 }
447 
GetProcessState()448 ContinuationManager::ProgressState ContinuationManager::GetProcessState()
449 {
450     return progressState_;
451 }
452 
ChangeProcessState(const ProgressState & newState)453 void ContinuationManager::ChangeProcessState(const ProgressState &newState)
454 {
455     HILOG_INFO("%{public}s called begin. progressState_: %{public}d, newState: %{public}d",
456         __func__,
457         progressState_,
458         newState);
459 
460     progressState_ = newState;
461 }
462 
463 
ChangeProcessStateToInit()464 void ContinuationManager::ChangeProcessStateToInit()
465 {
466     if (mainHandler_ != nullptr) {
467         mainHandler_->RemoveTask("Restore_State_When_Timeout");
468         HILOG_INFO("Restore_State_When_Timeout task removed");
469     }
470     ChangeProcessState(ProgressState::INITIAL);
471 }
472 
RestoreStateWhenTimeout(long timeoutInMs,const ProgressState & preState)473 void ContinuationManager::RestoreStateWhenTimeout(long timeoutInMs, const ProgressState &preState)
474 {
475     HILOG_INFO("%{public}s called begin", __func__);
476     InitMainHandlerIfNeed();
477 
478     auto timeoutTask = [continuationManager = shared_from_this(), preState]() {
479         HILOG_INFO(
480             "ContinuationManager::RestoreStateWhenTimeout called. preState = %{public}d, currentState = %{public}d.",
481             preState,
482             continuationManager->GetProcessState());
483         if (preState == continuationManager->GetProcessState()) {
484             continuationManager->ChangeProcessState(ProgressState::INITIAL);
485         }
486     };
487     mainHandler_->PostTask(timeoutTask, "Restore_State_When_Timeout", timeoutInMs);
488     HILOG_INFO("%{public}s called end", __func__);
489 }
490 
InitMainHandlerIfNeed()491 void ContinuationManager::InitMainHandlerIfNeed()
492 {
493     HILOG_INFO("%{public}s called begin", __func__);
494     if (mainHandler_ == nullptr) {
495         HILOG_INFO("Try to init main handler.");
496         std::lock_guard<std::mutex> lock_l(lock_);
497         if ((mainHandler_ == nullptr) && (EventRunner::GetMainEventRunner() != nullptr)) {
498             mainHandler_ = std::make_shared<EventHandler>(EventRunner::GetMainEventRunner());
499         }
500     }
501     HILOG_INFO("%{public}s called end", __func__);
502 }
503 
CheckAbilityToken()504 bool ContinuationManager::CheckAbilityToken()
505 {
506     HILOG_INFO("%{public}s called", __func__);
507     if (continueToken_ == nullptr) {
508         HILOG_INFO("%{public}s called failed", __func__);
509         return false;
510     }
511     HILOG_INFO("%{public}s called success", __func__);
512     return true;
513 }
514 
CheckDmsInterfaceResult(int result,const std::string & interfaceName)515 void ContinuationManager::CheckDmsInterfaceResult(int result, const std::string &interfaceName)
516 {
517     HILOG_INFO("ContinuationManager::CheckDmsInterfaceResult called. interfaceName: %{public}s, result: %{public}d.",
518         interfaceName.c_str(),
519         result);
520 }
521 
DoScheduleStartContinuation()522 bool ContinuationManager::DoScheduleStartContinuation()
523 {
524     HILOG_INFO("%{public}s called begin", __func__);
525     if (CheckContinuationIllegal()) {
526         HILOG_ERROR(
527             "ContinuationManager::DoScheduleStartContinuation called. Ability not available to startContinuation.");
528         return false;
529     }
530 
531     std::shared_ptr<Ability> ability = nullptr;
532     ability = ability_.lock();
533     if (ability == nullptr) {
534         HILOG_ERROR("ContinuationManager::DoScheduleStartContinuation failed. ability is nullptr");
535         return false;
536     }
537     if (!ability->OnStartContinuation()) {
538         HILOG_INFO("%{public}s called failed to StartContinuation", __func__);
539         return false;
540     }
541     HILOG_INFO("%{public}s called end", __func__);
542     return true;
543 }
544 
DoScheduleSaveData(WantParams & saveData)545 bool ContinuationManager::DoScheduleSaveData(WantParams &saveData)
546 {
547     HILOG_INFO("%{public}s called begin", __func__);
548     if (CheckContinuationIllegal()) {
549         HILOG_ERROR("ContinuationManager::DoScheduleSaveData failed. Ability not available to save data.");
550         return false;
551     }
552 
553     std::shared_ptr<Ability> ability = nullptr;
554     ability = ability_.lock();
555     if (ability == nullptr) {
556         HILOG_ERROR("ContinuationManager::DoScheduleSaveData failed. ability is nullptr");
557         return false;
558     }
559 
560     WantParams abilitySaveData;
561     bool ret = ability->OnSaveData(abilitySaveData);
562     for (std::string key : abilitySaveData.KeySet()) {
563         saveData.SetParam(key, abilitySaveData.GetParam(key).GetRefPtr());
564     }
565 
566     if (!ret) {
567         HILOG_ERROR("ContinuationManager::DoScheduleSaveData failed. Ability save data failed.");
568     }
569     HILOG_INFO("%{public}s called end", __func__);
570     return ret;
571 }
572 
DoScheduleRestoreData(const WantParams & restoreData)573 bool ContinuationManager::DoScheduleRestoreData(const WantParams &restoreData)
574 {
575     HILOG_INFO("%{public}s called begin", __func__);
576     if (CheckContinuationIllegal()) {
577         HILOG_ERROR("ContinuationManager::DoScheduleRestoreData failed. Ability not available to restore data.");
578         return false;
579     }
580 
581     std::shared_ptr<Ability> ability = nullptr;
582     ability = ability_.lock();
583     if (ability == nullptr) {
584         HILOG_ERROR("ContinuationManager::DoScheduleRestoreData failed. ability is nullptr");
585         return false;
586     }
587 
588     WantParams abilityRestoreData;
589     for (std::string key : restoreData.KeySet()) {
590         abilityRestoreData.SetParam(key, restoreData.GetParam(key).GetRefPtr());
591     }
592 
593     bool ret = ability->OnRestoreData(abilityRestoreData);
594     if (!ret) {
595         HILOG_ERROR("ContinuationManager::DoScheduleRestoreData failed. Ability restore data failed.");
596     }
597     HILOG_INFO("%{public}s called end", __func__);
598     return ret;
599 }
600 
DoRestoreFromRemote(const WantParams & restoreData)601 bool ContinuationManager::DoRestoreFromRemote(const WantParams &restoreData)
602 {
603     HILOG_INFO("%{public}s called begin", __func__);
604     std::shared_ptr<Ability> ability = nullptr;
605     ability = ability_.lock();
606     if (ability == nullptr) {
607         HILOG_ERROR("ContinuationManager::DoRestoreFromRemote failed. ability is nullptr");
608         return false;
609     }
610 
611     WantParams abilityRestoreData;
612     for (std::string key : restoreData.KeySet()) {
613         abilityRestoreData.SetParam(key, restoreData.GetParam(key).GetRefPtr());
614     }
615 
616     bool ret = ability->OnRestoreData(abilityRestoreData);
617     if (!ret) {
618         HILOG_ERROR("ContinuationManager::DoRestoreFromRemote failed. Ability restore data failed.");
619     }
620     HILOG_INFO("%{public}s called end", __func__);
621     return ret;
622 }
623 }  // namespace AppExecFwk
624 }  // namespace OHOS
625