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 #ifndef OHOS_ABILITY_RUNTIME_LIFECYCLE_DEAL_H 17 #define OHOS_ABILITY_RUNTIME_LIFECYCLE_DEAL_H 18 19 #include <memory> 20 #include <shared_mutex> 21 22 #include "ability_scheduler_interface.h" 23 #include "want.h" 24 #include "nocopyable.h" 25 26 namespace OHOS { 27 namespace AAFwk { 28 /** 29 * @class LifecycleDeal 30 * LifecycleDeal schedule ability life. 31 */ 32 class LifecycleDeal { 33 public: 34 LifecycleDeal(); 35 virtual ~LifecycleDeal(); 36 37 /** 38 * set scheduler for accessing ability 39 * 40 * @param scheduler, ability thread ipc proxy. 41 */ 42 void SetScheduler(const sptr<IAbilityScheduler> &scheduler); 43 44 /** 45 * schedule ability life 46 * 47 */ 48 void Activate(const Want &want, LifeCycleStateInfo &stateInfo); 49 void Inactivate(const Want &want, LifeCycleStateInfo &stateInfo); 50 void MoveToBackground(const Want &want, LifeCycleStateInfo &stateInfo); 51 void ConnectAbility(const Want &want); 52 void DisconnectAbility(const Want &want); 53 void Terminate(const Want &want, LifeCycleStateInfo &stateInfo); 54 void CommandAbility(const Want &want, bool reStart, int startId); 55 void SaveAbilityState(); 56 void RestoreAbilityState(const PacMap &inState); 57 void ForegroundNew(const Want &want, LifeCycleStateInfo &stateInfo); 58 void BackgroundNew(const Want &want, LifeCycleStateInfo &stateInfo); 59 void ContinueAbility(const std::string& deviceId, uint32_t versionCode); 60 void NotifyContinuationResult(int32_t result); 61 62 private: 63 sptr<IAbilityScheduler> GetScheduler(); 64 sptr<IAbilityScheduler> abilityScheduler_; // kit interface used to schedule ability life 65 std::shared_mutex schedulerMutex_; 66 67 DISALLOW_COPY_AND_MOVE(LifecycleDeal); 68 }; 69 } // namespace AAFwk 70 } // namespace OHOS 71 #endif // OHOS_ABILITY_RUNTIME_LIFECYCLE_DEAL_H 72