• 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 "resume_mission_container.h"
17 
18 #include "ability_manager_service.h"
19 #include "ability_util.h"
20 #include "hilog_wrapper.h"
21 
22 namespace OHOS {
23 namespace AAFwk {
ResumeMissionContainer(const std::shared_ptr<AbilityEventHandler> & handler)24 ResumeMissionContainer::ResumeMissionContainer(const std::shared_ptr<AbilityEventHandler> &handler) : handler_(handler)
25 {}
26 
Save(const std::shared_ptr<MissionRecord> & mission)27 void ResumeMissionContainer::Save(const std::shared_ptr<MissionRecord> &mission)
28 {
29     HILOG_INFO("Save.");
30     CHECK_POINTER(mission);
31 
32     auto missionId = mission->GetMissionRecordId();
33     auto finder = missionMaps_.find(missionId);
34     std::shared_ptr<MissionRecord> backup;
35     if (finder == missionMaps_.end()) {
36         HILOG_INFO("Backup");
37         backup = std::make_shared<MissionRecord>(mission);
38         missionMaps_.emplace(missionId, backup);
39     }
40 
41     auto missionSaveTime = DelayedSingleton<AbilityManagerService>::GetInstance()->GetMissionSaveTime();
42     HILOG_INFO("mission save time : %{public}d", missionSaveTime);
43     if (backup) {
44         HILOG_INFO("start save time...");
45         handler_->PostTask(
46             [this, missionId]() { Remove(missionId); }, taskName_ + std::to_string(missionId), missionSaveTime);
47     }
48 }
49 
Resume(const std::shared_ptr<MissionRecord> & mission)50 void ResumeMissionContainer::Resume(const std::shared_ptr<MissionRecord> &mission)
51 {
52     HILOG_INFO("Resume.");
53     CHECK_POINTER(mission);
54 
55     auto backup = missionMaps_.find(mission->GetMissionRecordId());
56     mission->Resume(backup->second);
57     missionMaps_.erase(mission->GetMissionRecordId());
58 }
59 
Remove(int missionId)60 void ResumeMissionContainer::Remove(int missionId)
61 {
62     HILOG_INFO("Remove.");
63     missionMaps_.erase(missionId);
64     handler_->RemoveTask(taskName_ + std::to_string(missionId));
65 }
66 
IsResume(int missionId)67 bool ResumeMissionContainer::IsResume(int missionId)
68 {
69     return (missionMaps_.find(missionId) != missionMaps_.end());
70 }
71 }  // namespace AAFwk
72 }  // namespace OHOS