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